xref: /trunk/main/svx/source/sidebar/tools/Popup.cxx (revision 550fbbbd)
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 #include "svx/sidebar/Popup.hxx"
23 #include "svx/sidebar/PopupContainer.hxx"
24 #include "svx/sidebar/PopupControl.hxx"
25 
26 #include <vcl/toolbox.hxx>
27 
28 
29 namespace svx { namespace sidebar {
30 
Popup(Window * pParent,const::boost::function<PopupControl * (PopupContainer *)> & rControlCreator,const::rtl::OUString & rsAccessibleName)31 Popup::Popup (
32     Window* pParent,
33     const ::boost::function<PopupControl*(PopupContainer*)>& rControlCreator,
34     const ::rtl::OUString& rsAccessibleName)
35     : mpControl(),
36       mpParent(pParent),
37       maControlCreator(rControlCreator),
38       maPopupModeEndCallback(),
39       msAccessibleName(rsAccessibleName),
40       mpContainer()
41 {
42     OSL_ASSERT(mpParent!=NULL);
43     OSL_ASSERT(maControlCreator);
44 }
45 
46 
47 
48 
~Popup(void)49 Popup::~Popup (void)
50 {
51     mpControl.reset();
52     mpContainer.reset();
53 }
54 
55 
56 
57 
Show(ToolBox & rToolBox)58 void Popup::Show (ToolBox& rToolBox)
59 {
60     rToolBox.SetItemDown(rToolBox.GetCurItemId(), true);
61 
62     ProvideContainerAndControl();
63     if ( ! (mpContainer && mpControl))
64     {
65         OSL_ASSERT(mpContainer);
66         OSL_ASSERT(mpControl);
67         return;
68     }
69 
70     if ( !mpContainer->IsInPopupMode() )
71     {
72         mpContainer->SetSizePixel(mpControl->GetOutputSizePixel());
73 
74         const Point aPos (mpParent->OutputToScreenPixel(rToolBox.GetPosPixel()));
75         const Size aSize (rToolBox.GetSizePixel());
76         const Rectangle aRect (aPos, aSize);
77 
78         mpContainer->StartPopupMode(
79             aRect,
80             FLOATWIN_POPUPMODE_NOFOCUSCLOSE|FLOATWIN_POPUPMODE_DOWN);
81         mpContainer->SetPopupModeFlags(
82             mpContainer->GetPopupModeFlags()
83                 | FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE);
84 
85         mpControl->GetFocus();
86     }
87 }
88 
89 
90 
91 
Hide(void)92 void Popup::Hide (void)
93 {
94     if (mpContainer)
95         if (mpContainer->IsInPopupMode())
96 			mpContainer->EndPopupMode();
97 }
98 
99 
100 
101 
SetPopupModeEndHandler(const::boost::function<void (void)> & rCallback)102 void Popup::SetPopupModeEndHandler (const ::boost::function<void(void)>& rCallback)
103 {
104     maPopupModeEndCallback = rCallback;
105     if (mpContainer)
106         mpContainer->SetPopupModeEndHdl(LINK(this, Popup, PopupModeEndHandler));
107 }
108 
109 
110 
111 
ProvideContainerAndControl(void)112 void Popup::ProvideContainerAndControl (void)
113 {
114     if ( ! (mpContainer && mpControl)
115         && mpParent!=NULL
116         && maControlCreator)
117     {
118         CreateContainerAndControl();
119     }
120 }
121 
122 
123 
124 
CreateContainerAndControl(void)125 void Popup::CreateContainerAndControl (void)
126 {
127     mpContainer.reset(new PopupContainer(mpParent));
128     mpContainer->SetAccessibleName(msAccessibleName);
129     mpContainer->SetPopupModeEndHdl(LINK(this, Popup, PopupModeEndHandler));
130     mpContainer->SetBorderStyle(mpContainer->GetBorderStyle() | WINDOW_BORDER_MENU);
131 
132     mpControl.reset(maControlCreator(mpContainer.get()));
133 }
134 
135 
136 
137 
IMPL_LINK(Popup,PopupModeEndHandler,void *,EMPTYARG)138 IMPL_LINK(Popup, PopupModeEndHandler, void*, EMPTYARG)
139 {
140     if (maPopupModeEndCallback)
141         maPopupModeEndCallback();
142 
143     // Popup control is no longer needed and can be destroyed.
144     mpControl.reset();
145     mpContainer.reset();
146 
147     return 0;
148 }
149 
150 
151 
152 } } // end of namespace svx::sidebar
153