xref: /trunk/main/svx/source/sidebar/tools/Popup.cxx (revision 8dcb2a100eb78f12871a9e67d867e1bc0c7bdb07)
1*8dcb2a10SAndre Fischer /**************************************************************
2*8dcb2a10SAndre Fischer  *
3*8dcb2a10SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
4*8dcb2a10SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
5*8dcb2a10SAndre Fischer  * distributed with this work for additional information
6*8dcb2a10SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
7*8dcb2a10SAndre Fischer  * to you under the Apache License, Version 2.0 (the
8*8dcb2a10SAndre Fischer  * "License"); you may not use this file except in compliance
9*8dcb2a10SAndre Fischer  * with the License.  You may obtain a copy of the License at
10*8dcb2a10SAndre Fischer  *
11*8dcb2a10SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
12*8dcb2a10SAndre Fischer  *
13*8dcb2a10SAndre Fischer  * Unless required by applicable law or agreed to in writing,
14*8dcb2a10SAndre Fischer  * software distributed under the License is distributed on an
15*8dcb2a10SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*8dcb2a10SAndre Fischer  * KIND, either express or implied.  See the License for the
17*8dcb2a10SAndre Fischer  * specific language governing permissions and limitations
18*8dcb2a10SAndre Fischer  * under the License.
19*8dcb2a10SAndre Fischer  *
20*8dcb2a10SAndre Fischer  *************************************************************/
21*8dcb2a10SAndre Fischer 
22*8dcb2a10SAndre Fischer #include "svx/sidebar/Popup.hxx"
23*8dcb2a10SAndre Fischer #include "svx/sidebar/PopupContainer.hxx"
24*8dcb2a10SAndre Fischer #include "svx/sidebar/PopupControl.hxx"
25*8dcb2a10SAndre Fischer 
26*8dcb2a10SAndre Fischer #include <vcl/toolbox.hxx>
27*8dcb2a10SAndre Fischer 
28*8dcb2a10SAndre Fischer 
29*8dcb2a10SAndre Fischer namespace svx { namespace sidebar {
30*8dcb2a10SAndre Fischer 
31*8dcb2a10SAndre Fischer Popup::Popup (
32*8dcb2a10SAndre Fischer     Window* pParent,
33*8dcb2a10SAndre Fischer     const ::boost::function<PopupControl*(PopupContainer*)>& rControlCreator,
34*8dcb2a10SAndre Fischer     const ::rtl::OUString& rsAccessibleName)
35*8dcb2a10SAndre Fischer     : mpControl(),
36*8dcb2a10SAndre Fischer       mpParent(pParent),
37*8dcb2a10SAndre Fischer       maControlCreator(rControlCreator),
38*8dcb2a10SAndre Fischer       maPopupModeEndCallback(),
39*8dcb2a10SAndre Fischer       msAccessibleName(rsAccessibleName),
40*8dcb2a10SAndre Fischer       mpContainer()
41*8dcb2a10SAndre Fischer {
42*8dcb2a10SAndre Fischer     OSL_ASSERT(mpParent!=NULL);
43*8dcb2a10SAndre Fischer     OSL_ASSERT(maControlCreator);
44*8dcb2a10SAndre Fischer }
45*8dcb2a10SAndre Fischer 
46*8dcb2a10SAndre Fischer 
47*8dcb2a10SAndre Fischer 
48*8dcb2a10SAndre Fischer 
49*8dcb2a10SAndre Fischer Popup::~Popup (void)
50*8dcb2a10SAndre Fischer {
51*8dcb2a10SAndre Fischer     mpControl.reset();
52*8dcb2a10SAndre Fischer     mpContainer.reset();
53*8dcb2a10SAndre Fischer }
54*8dcb2a10SAndre Fischer 
55*8dcb2a10SAndre Fischer 
56*8dcb2a10SAndre Fischer 
57*8dcb2a10SAndre Fischer 
58*8dcb2a10SAndre Fischer void Popup::Show (ToolBox& rToolBox)
59*8dcb2a10SAndre Fischer {
60*8dcb2a10SAndre Fischer     rToolBox.SetItemDown(rToolBox.GetCurItemId(), true);
61*8dcb2a10SAndre Fischer 
62*8dcb2a10SAndre Fischer     ProvideContainerAndControl();
63*8dcb2a10SAndre Fischer     if ( ! (mpContainer && mpControl))
64*8dcb2a10SAndre Fischer     {
65*8dcb2a10SAndre Fischer         OSL_ASSERT(mpContainer);
66*8dcb2a10SAndre Fischer         OSL_ASSERT(mpControl);
67*8dcb2a10SAndre Fischer         return;
68*8dcb2a10SAndre Fischer     }
69*8dcb2a10SAndre Fischer 
70*8dcb2a10SAndre Fischer     mpContainer->SetSizePixel(mpControl->GetOutputSizePixel());
71*8dcb2a10SAndre Fischer 
72*8dcb2a10SAndre Fischer     const Point aPos (mpParent->OutputToScreenPixel(rToolBox.GetPosPixel()));
73*8dcb2a10SAndre Fischer     const Size aSize (rToolBox.GetSizePixel());
74*8dcb2a10SAndre Fischer     const Rectangle aRect (aPos, aSize);
75*8dcb2a10SAndre Fischer 
76*8dcb2a10SAndre Fischer     mpContainer->StartPopupMode(
77*8dcb2a10SAndre Fischer         aRect,
78*8dcb2a10SAndre Fischer         FLOATWIN_POPUPMODE_NOFOCUSCLOSE|FLOATWIN_POPUPMODE_DOWN);
79*8dcb2a10SAndre Fischer     mpContainer->SetPopupModeFlags(
80*8dcb2a10SAndre Fischer         mpContainer->GetPopupModeFlags()
81*8dcb2a10SAndre Fischer             | FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE);
82*8dcb2a10SAndre Fischer 
83*8dcb2a10SAndre Fischer     mpControl->GetFocus();
84*8dcb2a10SAndre Fischer }
85*8dcb2a10SAndre Fischer 
86*8dcb2a10SAndre Fischer 
87*8dcb2a10SAndre Fischer 
88*8dcb2a10SAndre Fischer 
89*8dcb2a10SAndre Fischer void Popup::Hide (void)
90*8dcb2a10SAndre Fischer {
91*8dcb2a10SAndre Fischer     if (mpContainer)
92*8dcb2a10SAndre Fischer         if (mpContainer->IsInPopupMode())
93*8dcb2a10SAndre Fischer             mpContainer->EndPopupMode();
94*8dcb2a10SAndre Fischer }
95*8dcb2a10SAndre Fischer 
96*8dcb2a10SAndre Fischer 
97*8dcb2a10SAndre Fischer 
98*8dcb2a10SAndre Fischer 
99*8dcb2a10SAndre Fischer void Popup::SetPopupModeEndHandler (const ::boost::function<void(void)>& rCallback)
100*8dcb2a10SAndre Fischer {
101*8dcb2a10SAndre Fischer     maPopupModeEndCallback = rCallback;
102*8dcb2a10SAndre Fischer     if (mpContainer)
103*8dcb2a10SAndre Fischer         mpContainer->SetPopupModeEndHdl(LINK(this, Popup, PopupModeEndHandler));
104*8dcb2a10SAndre Fischer }
105*8dcb2a10SAndre Fischer 
106*8dcb2a10SAndre Fischer 
107*8dcb2a10SAndre Fischer 
108*8dcb2a10SAndre Fischer 
109*8dcb2a10SAndre Fischer void Popup::ProvideContainerAndControl (void)
110*8dcb2a10SAndre Fischer {
111*8dcb2a10SAndre Fischer     if ( ! (mpContainer && mpControl)
112*8dcb2a10SAndre Fischer         && mpParent!=NULL
113*8dcb2a10SAndre Fischer         && maControlCreator)
114*8dcb2a10SAndre Fischer     {
115*8dcb2a10SAndre Fischer         CreateContainerAndControl();
116*8dcb2a10SAndre Fischer     }
117*8dcb2a10SAndre Fischer }
118*8dcb2a10SAndre Fischer 
119*8dcb2a10SAndre Fischer 
120*8dcb2a10SAndre Fischer 
121*8dcb2a10SAndre Fischer 
122*8dcb2a10SAndre Fischer void Popup::CreateContainerAndControl (void)
123*8dcb2a10SAndre Fischer {
124*8dcb2a10SAndre Fischer     mpContainer.reset(new PopupContainer(mpParent));
125*8dcb2a10SAndre Fischer     mpContainer->SetAccessibleName(msAccessibleName);
126*8dcb2a10SAndre Fischer     if (maPopupModeEndCallback)
127*8dcb2a10SAndre Fischer         mpContainer->SetPopupModeEndHdl(LINK(this, Popup, PopupModeEndHandler));
128*8dcb2a10SAndre Fischer     mpContainer->SetBorderStyle(mpContainer->GetBorderStyle() | WINDOW_BORDER_MENU);
129*8dcb2a10SAndre Fischer 
130*8dcb2a10SAndre Fischer     mpControl.reset(maControlCreator(mpContainer.get()));
131*8dcb2a10SAndre Fischer }
132*8dcb2a10SAndre Fischer 
133*8dcb2a10SAndre Fischer 
134*8dcb2a10SAndre Fischer 
135*8dcb2a10SAndre Fischer 
136*8dcb2a10SAndre Fischer IMPL_LINK(Popup, PopupModeEndHandler, void*, EMPTYARG)
137*8dcb2a10SAndre Fischer {
138*8dcb2a10SAndre Fischer     if (maPopupModeEndCallback)
139*8dcb2a10SAndre Fischer         maPopupModeEndCallback();
140*8dcb2a10SAndre Fischer     return 0;
141*8dcb2a10SAndre Fischer }
142*8dcb2a10SAndre Fischer 
143*8dcb2a10SAndre Fischer 
144*8dcb2a10SAndre Fischer 
145*8dcb2a10SAndre Fischer } } // end of namespace svx::sidebar
146