18dcb2a10SAndre Fischer /************************************************************** 28dcb2a10SAndre Fischer * 38dcb2a10SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 48dcb2a10SAndre Fischer * or more contributor license agreements. See the NOTICE file 58dcb2a10SAndre Fischer * distributed with this work for additional information 68dcb2a10SAndre Fischer * regarding copyright ownership. The ASF licenses this file 78dcb2a10SAndre Fischer * to you under the Apache License, Version 2.0 (the 88dcb2a10SAndre Fischer * "License"); you may not use this file except in compliance 98dcb2a10SAndre Fischer * with the License. You may obtain a copy of the License at 108dcb2a10SAndre Fischer * 118dcb2a10SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 128dcb2a10SAndre Fischer * 138dcb2a10SAndre Fischer * Unless required by applicable law or agreed to in writing, 148dcb2a10SAndre Fischer * software distributed under the License is distributed on an 158dcb2a10SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 168dcb2a10SAndre Fischer * KIND, either express or implied. See the License for the 178dcb2a10SAndre Fischer * specific language governing permissions and limitations 188dcb2a10SAndre Fischer * under the License. 198dcb2a10SAndre Fischer * 208dcb2a10SAndre Fischer *************************************************************/ 218dcb2a10SAndre Fischer 228dcb2a10SAndre Fischer #include "svx/sidebar/Popup.hxx" 238dcb2a10SAndre Fischer #include "svx/sidebar/PopupContainer.hxx" 248dcb2a10SAndre Fischer #include "svx/sidebar/PopupControl.hxx" 258dcb2a10SAndre Fischer 268dcb2a10SAndre Fischer #include <vcl/toolbox.hxx> 278dcb2a10SAndre Fischer 288dcb2a10SAndre Fischer 298dcb2a10SAndre Fischer namespace svx { namespace sidebar { 308dcb2a10SAndre Fischer 318dcb2a10SAndre Fischer Popup::Popup ( 328dcb2a10SAndre Fischer Window* pParent, 338dcb2a10SAndre Fischer const ::boost::function<PopupControl*(PopupContainer*)>& rControlCreator, 348dcb2a10SAndre Fischer const ::rtl::OUString& rsAccessibleName) 358dcb2a10SAndre Fischer : mpControl(), 368dcb2a10SAndre Fischer mpParent(pParent), 378dcb2a10SAndre Fischer maControlCreator(rControlCreator), 388dcb2a10SAndre Fischer maPopupModeEndCallback(), 398dcb2a10SAndre Fischer msAccessibleName(rsAccessibleName), 408dcb2a10SAndre Fischer mpContainer() 418dcb2a10SAndre Fischer { 428dcb2a10SAndre Fischer OSL_ASSERT(mpParent!=NULL); 438dcb2a10SAndre Fischer OSL_ASSERT(maControlCreator); 448dcb2a10SAndre Fischer } 458dcb2a10SAndre Fischer 468dcb2a10SAndre Fischer 478dcb2a10SAndre Fischer 488dcb2a10SAndre Fischer 498dcb2a10SAndre Fischer Popup::~Popup (void) 508dcb2a10SAndre Fischer { 518dcb2a10SAndre Fischer mpControl.reset(); 528dcb2a10SAndre Fischer mpContainer.reset(); 538dcb2a10SAndre Fischer } 548dcb2a10SAndre Fischer 558dcb2a10SAndre Fischer 568dcb2a10SAndre Fischer 578dcb2a10SAndre Fischer 588dcb2a10SAndre Fischer void Popup::Show (ToolBox& rToolBox) 598dcb2a10SAndre Fischer { 608dcb2a10SAndre Fischer rToolBox.SetItemDown(rToolBox.GetCurItemId(), true); 618dcb2a10SAndre Fischer 628dcb2a10SAndre Fischer ProvideContainerAndControl(); 638dcb2a10SAndre Fischer if ( ! (mpContainer && mpControl)) 648dcb2a10SAndre Fischer { 658dcb2a10SAndre Fischer OSL_ASSERT(mpContainer); 668dcb2a10SAndre Fischer OSL_ASSERT(mpControl); 678dcb2a10SAndre Fischer return; 688dcb2a10SAndre Fischer } 698dcb2a10SAndre Fischer 70778b1054SOliver-Rainer Wittmann if ( !mpContainer->IsInPopupMode() ) 71778b1054SOliver-Rainer Wittmann { 728dcb2a10SAndre Fischer mpContainer->SetSizePixel(mpControl->GetOutputSizePixel()); 738dcb2a10SAndre Fischer 748dcb2a10SAndre Fischer const Point aPos (mpParent->OutputToScreenPixel(rToolBox.GetPosPixel())); 758dcb2a10SAndre Fischer const Size aSize (rToolBox.GetSizePixel()); 768dcb2a10SAndre Fischer const Rectangle aRect (aPos, aSize); 778dcb2a10SAndre Fischer 788dcb2a10SAndre Fischer mpContainer->StartPopupMode( 798dcb2a10SAndre Fischer aRect, 808dcb2a10SAndre Fischer FLOATWIN_POPUPMODE_NOFOCUSCLOSE|FLOATWIN_POPUPMODE_DOWN); 818dcb2a10SAndre Fischer mpContainer->SetPopupModeFlags( 828dcb2a10SAndre Fischer mpContainer->GetPopupModeFlags() 838dcb2a10SAndre Fischer | FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE); 848dcb2a10SAndre Fischer 858dcb2a10SAndre Fischer mpControl->GetFocus(); 868dcb2a10SAndre Fischer } 87778b1054SOliver-Rainer Wittmann } 888dcb2a10SAndre Fischer 898dcb2a10SAndre Fischer 908dcb2a10SAndre Fischer 918dcb2a10SAndre Fischer 928dcb2a10SAndre Fischer void Popup::Hide (void) 938dcb2a10SAndre Fischer { 948dcb2a10SAndre Fischer if (mpContainer) 958dcb2a10SAndre Fischer if (mpContainer->IsInPopupMode()) 968dcb2a10SAndre Fischer mpContainer->EndPopupMode(); 978dcb2a10SAndre Fischer } 988dcb2a10SAndre Fischer 998dcb2a10SAndre Fischer 1008dcb2a10SAndre Fischer 1018dcb2a10SAndre Fischer 1028dcb2a10SAndre Fischer void Popup::SetPopupModeEndHandler (const ::boost::function<void(void)>& rCallback) 1038dcb2a10SAndre Fischer { 1048dcb2a10SAndre Fischer maPopupModeEndCallback = rCallback; 1058dcb2a10SAndre Fischer if (mpContainer) 1068dcb2a10SAndre Fischer mpContainer->SetPopupModeEndHdl(LINK(this, Popup, PopupModeEndHandler)); 1078dcb2a10SAndre Fischer } 1088dcb2a10SAndre Fischer 1098dcb2a10SAndre Fischer 1108dcb2a10SAndre Fischer 1118dcb2a10SAndre Fischer 1128dcb2a10SAndre Fischer void Popup::ProvideContainerAndControl (void) 1138dcb2a10SAndre Fischer { 1148dcb2a10SAndre Fischer if ( ! (mpContainer && mpControl) 1158dcb2a10SAndre Fischer && mpParent!=NULL 1168dcb2a10SAndre Fischer && maControlCreator) 1178dcb2a10SAndre Fischer { 1188dcb2a10SAndre Fischer CreateContainerAndControl(); 1198dcb2a10SAndre Fischer } 1208dcb2a10SAndre Fischer } 1218dcb2a10SAndre Fischer 1228dcb2a10SAndre Fischer 1238dcb2a10SAndre Fischer 1248dcb2a10SAndre Fischer 1258dcb2a10SAndre Fischer void Popup::CreateContainerAndControl (void) 1268dcb2a10SAndre Fischer { 1278dcb2a10SAndre Fischer mpContainer.reset(new PopupContainer(mpParent)); 1288dcb2a10SAndre Fischer mpContainer->SetAccessibleName(msAccessibleName); 1298dcb2a10SAndre Fischer mpContainer->SetPopupModeEndHdl(LINK(this, Popup, PopupModeEndHandler)); 1308dcb2a10SAndre Fischer mpContainer->SetBorderStyle(mpContainer->GetBorderStyle() | WINDOW_BORDER_MENU); 1318dcb2a10SAndre Fischer 1328dcb2a10SAndre Fischer mpControl.reset(maControlCreator(mpContainer.get())); 1338dcb2a10SAndre Fischer } 1348dcb2a10SAndre Fischer 1358dcb2a10SAndre Fischer 1368dcb2a10SAndre Fischer 1378dcb2a10SAndre Fischer 1388dcb2a10SAndre Fischer IMPL_LINK(Popup, PopupModeEndHandler, void*, EMPTYARG) 1398dcb2a10SAndre Fischer { 1408dcb2a10SAndre Fischer if (maPopupModeEndCallback) 1418dcb2a10SAndre Fischer maPopupModeEndCallback(); 142*550fbbbdSOliver-Rainer Wittmann 143*550fbbbdSOliver-Rainer Wittmann // Popup control is no longer needed and can be destroyed. 144*550fbbbdSOliver-Rainer Wittmann mpControl.reset(); 145*550fbbbdSOliver-Rainer Wittmann mpContainer.reset(); 146*550fbbbdSOliver-Rainer Wittmann 1478dcb2a10SAndre Fischer return 0; 1488dcb2a10SAndre Fischer } 1498dcb2a10SAndre Fischer 1508dcb2a10SAndre Fischer 1518dcb2a10SAndre Fischer 1528dcb2a10SAndre Fischer } } // end of namespace svx::sidebar 153