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