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 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 49 Popup::~Popup (void) 50 { 51 mpControl.reset(); 52 mpContainer.reset(); 53 } 54 55 56 57 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 mpContainer->SetSizePixel(mpControl->GetOutputSizePixel()); 71 72 const Point aPos (mpParent->OutputToScreenPixel(rToolBox.GetPosPixel())); 73 const Size aSize (rToolBox.GetSizePixel()); 74 const Rectangle aRect (aPos, aSize); 75 76 mpContainer->StartPopupMode( 77 aRect, 78 FLOATWIN_POPUPMODE_NOFOCUSCLOSE|FLOATWIN_POPUPMODE_DOWN); 79 mpContainer->SetPopupModeFlags( 80 mpContainer->GetPopupModeFlags() 81 | FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE); 82 83 mpControl->GetFocus(); 84 } 85 86 87 88 89 void Popup::Hide (void) 90 { 91 if (mpContainer) 92 if (mpContainer->IsInPopupMode()) 93 mpContainer->EndPopupMode(); 94 } 95 96 97 98 99 void Popup::SetPopupModeEndHandler (const ::boost::function<void(void)>& rCallback) 100 { 101 maPopupModeEndCallback = rCallback; 102 if (mpContainer) 103 mpContainer->SetPopupModeEndHdl(LINK(this, Popup, PopupModeEndHandler)); 104 } 105 106 107 108 109 void Popup::ProvideContainerAndControl (void) 110 { 111 if ( ! (mpContainer && mpControl) 112 && mpParent!=NULL 113 && maControlCreator) 114 { 115 CreateContainerAndControl(); 116 } 117 } 118 119 120 121 122 void Popup::CreateContainerAndControl (void) 123 { 124 mpContainer.reset(new PopupContainer(mpParent)); 125 mpContainer->SetAccessibleName(msAccessibleName); 126 if (maPopupModeEndCallback) 127 mpContainer->SetPopupModeEndHdl(LINK(this, Popup, PopupModeEndHandler)); 128 mpContainer->SetBorderStyle(mpContainer->GetBorderStyle() | WINDOW_BORDER_MENU); 129 130 mpControl.reset(maControlCreator(mpContainer.get())); 131 } 132 133 134 135 136 IMPL_LINK(Popup, PopupModeEndHandler, void*, EMPTYARG) 137 { 138 if (maPopupModeEndCallback) 139 maPopupModeEndCallback(); 140 return 0; 141 } 142 143 144 145 } } // end of namespace svx::sidebar 146