xref: /aoo4110/main/svx/inc/svx/sidebar/Popup.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef _SVX_SIDEBAR_POPUP_HXX_
23 #define _SVX_SIDEBAR_POPUP_HXX_
24 
25 #include "svx/svxdllapi.h"
26 #include <rtl/ustring.hxx>
27 #include <tools/link.hxx>
28 
29 #include <boost/function.hpp>
30 #include <boost/scoped_ptr.hpp>
31 
32 class Window;
33 class ToolBox;
34 
35 namespace svx { namespace sidebar {
36 
37 class PopupContainer;
38 class PopupControl;
39 
40 /** A wrapper around a PopupContainer and a PopupControl object.
41     Usually used as drop down for a toolbox.  Use Show() to start
42     drop down mode and Hide() to end it.
43 */
44 class SVX_DLLPUBLIC Popup
45 {
46 public :
47     /** Create a Popup wrapper object.
48         @param pParent
49             Parent window of the PopupContainer, which in turn is the
50             parent of the PopupControl.
51         @param rControlCreator
52             A functor that is called to create the PopupControl object
53             (usually an instance of a class derived from
54             PopupControl).
55     */
56     Popup (
57         Window* pParent,
58         const ::boost::function<PopupControl*(PopupContainer*)>& rControlCreator,
59         const ::rtl::OUString& rsAccessibleName);
60     virtual ~Popup (void);
61 
62     /** Show the popup.
63         @rToolBox
64             The tool box is used to determine the position at which
65             the popup is displayed.
66     */
67     void Show (ToolBox& rToolBox);
68 
69     /** Hide the popup.
70         This method is called automatically when eg. the user clicks
71         outside the popup or when the ESC-key is pressed.  The
72         application can call Hide() when the popup should be closed
73         for other, non-standard reasons.
74     */
75     void Hide (void);
76 
77     /** If you want to be informed when the popup closes then add a
78         callback that is called after that.
79     */
80     void SetPopupModeEndHandler (const ::boost::function<void(void)>& rCallback);
81 
82 protected:
83     ::boost::scoped_ptr<PopupControl> mpControl;
84 
85     /** Make sure that both PopupContainer and PopupControl objects
86         exist.  Calls the maControlCreator functor if necessary.
87     */
88     void ProvideContainerAndControl (void);
89 
90     /** A derived specialisation class can override this method to do
91         additional work.
92     */
93     virtual void CreateContainerAndControl (void);
94 
95 private:
96     Window* mpParent;
97     ::boost::function<PopupControl*(PopupContainer*)> maControlCreator;
98     ::boost::function<void(void)> maPopupModeEndCallback;
99     const ::rtl::OUString msAccessibleName;
100     ::boost::scoped_ptr<PopupContainer> mpContainer;
101 
102     DECL_LINK(PopupModeEndHandler, void*);
103 };
104 
105 } } // end of namespace svx::sidebar
106 
107 #endif
108