1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "svx/sidebar/Popup.hxx"
20 #include "svx/sidebar/PopupContainer.hxx"
21 #include "svx/sidebar/PopupControl.hxx"
23 #include <vcl/toolbox.hxx>
26 namespace svx
{ namespace sidebar
{
30 const ::boost::function
<PopupControl
*(PopupContainer
*)>& rControlCreator
,
31 const ::rtl::OUString
& rsAccessibleName
)
34 maControlCreator(rControlCreator
),
35 maPopupModeEndCallback(),
36 msAccessibleName(rsAccessibleName
),
39 OSL_ASSERT(mpParent
!=NULL
);
40 OSL_ASSERT(maControlCreator
);
55 void Popup::Show (ToolBox
& rToolBox
)
57 rToolBox
.SetItemDown(rToolBox
.GetCurItemId(), true);
59 ProvideContainerAndControl();
60 if ( ! (mpContainer
&& mpControl
))
62 OSL_ASSERT(mpContainer
);
63 OSL_ASSERT(mpControl
);
67 if ( !mpContainer
->IsInPopupMode() )
69 mpContainer
->SetSizePixel(mpControl
->GetOutputSizePixel());
71 const Point
aPos (rToolBox
.GetParent()->OutputToScreenPixel(rToolBox
.GetPosPixel()));
72 const Size
aSize (rToolBox
.GetSizePixel());
73 const Rectangle
aRect (aPos
, aSize
);
75 mpContainer
->StartPopupMode(
77 FLOATWIN_POPUPMODE_NOFOCUSCLOSE
|FLOATWIN_POPUPMODE_DOWN
);
78 mpContainer
->SetPopupModeFlags(
79 mpContainer
->GetPopupModeFlags()
80 | FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE
);
82 mpControl
->GetFocus();
89 void Popup::Hide (void)
92 if (mpContainer
->IsInPopupMode())
93 mpContainer
->EndPopupMode();
99 void Popup::SetPopupModeEndHandler (const ::boost::function
<void(void)>& rCallback
)
101 maPopupModeEndCallback
= rCallback
;
103 mpContainer
->SetPopupModeEndHdl(LINK(this, Popup
, PopupModeEndHandler
));
109 void Popup::ProvideContainerAndControl (void)
111 if ( ! (mpContainer
&& mpControl
)
115 CreateContainerAndControl();
122 void Popup::CreateContainerAndControl (void)
124 mpContainer
.reset(new PopupContainer(mpParent
));
125 mpContainer
->SetAccessibleName(msAccessibleName
);
126 mpContainer
->SetPopupModeEndHdl(LINK(this, Popup
, PopupModeEndHandler
));
127 mpContainer
->SetBorderStyle(mpContainer
->GetBorderStyle() | WINDOW_BORDER_MENU
);
129 mpControl
.reset(maControlCreator(mpContainer
.get()));
135 IMPL_LINK(Popup
, PopupModeEndHandler
, void*, EMPTYARG
)
137 if (maPopupModeEndCallback
)
138 maPopupModeEndCallback();
140 // Popup control is no longer needed and can be destroyed.
149 } } // end of namespace svx::sidebar
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */