1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sd.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "FormShellManager.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "EventMultiplexer.hxx" 34*cdf0e10cSrcweir #include "ViewShell.hxx" 35*cdf0e10cSrcweir #include "ViewShellBase.hxx" 36*cdf0e10cSrcweir #include "ViewShellManager.hxx" 37*cdf0e10cSrcweir #include "Window.hxx" 38*cdf0e10cSrcweir #include <svx/fmshell.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir namespace sd { 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir namespace { 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir /** This factory is responsible for creating and deleting the FmFormShell. 45*cdf0e10cSrcweir */ 46*cdf0e10cSrcweir class FormShellManagerFactory 47*cdf0e10cSrcweir : public ::sd::ShellFactory<SfxShell> 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir public: 50*cdf0e10cSrcweir FormShellManagerFactory (ViewShell& rViewShell, FormShellManager& rManager); 51*cdf0e10cSrcweir virtual FmFormShell* CreateShell (ShellId nId, ::Window* pParentWindow, FrameView* pFrameView); 52*cdf0e10cSrcweir virtual void ReleaseShell (SfxShell* pShell); 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir private: 55*cdf0e10cSrcweir ::sd::ViewShell& mrViewShell; 56*cdf0e10cSrcweir FormShellManager& mrFormShellManager; 57*cdf0e10cSrcweir }; 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir } // end of anonymous namespace 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir FormShellManager::FormShellManager (ViewShellBase& rBase) 63*cdf0e10cSrcweir : mrBase(rBase), 64*cdf0e10cSrcweir mpFormShell(NULL), 65*cdf0e10cSrcweir mbFormShellAboveViewShell(false), 66*cdf0e10cSrcweir mpSubShellFactory(), 67*cdf0e10cSrcweir mbIsMainViewChangePending(false), 68*cdf0e10cSrcweir mpMainViewShellWindow(NULL) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir // Register at the EventMultiplexer to be informed about changes in the 71*cdf0e10cSrcweir // center pane. 72*cdf0e10cSrcweir Link aLink (LINK(this, FormShellManager, ConfigurationUpdateHandler)); 73*cdf0e10cSrcweir mrBase.GetEventMultiplexer()->AddEventListener( 74*cdf0e10cSrcweir aLink, 75*cdf0e10cSrcweir sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED 76*cdf0e10cSrcweir | sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED 77*cdf0e10cSrcweir | sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED); 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir RegisterAtCenterPane(); 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir FormShellManager::~FormShellManager (void) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir SetFormShell(NULL); 88*cdf0e10cSrcweir UnregisterAtCenterPane(); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir // Unregister from the EventMultiplexer. 91*cdf0e10cSrcweir Link aLink (LINK(this, FormShellManager, ConfigurationUpdateHandler)); 92*cdf0e10cSrcweir mrBase.GetEventMultiplexer()->RemoveEventListener(aLink); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir if (mpSubShellFactory.get() != NULL) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir ViewShell* pShell = mrBase.GetMainViewShell().get(); 97*cdf0e10cSrcweir if (pShell != NULL) 98*cdf0e10cSrcweir mrBase.GetViewShellManager()->RemoveSubShellFactory(pShell,mpSubShellFactory); 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir void FormShellManager::SetFormShell (FmFormShell* pFormShell) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir if (mpFormShell != pFormShell) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir // Disconnect from the old form shell. 110*cdf0e10cSrcweir if (mpFormShell != NULL) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir mpFormShell->SetControlActivationHandler(Link()); 113*cdf0e10cSrcweir EndListening(*mpFormShell); 114*cdf0e10cSrcweir mpFormShell->SetView(NULL); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir mpFormShell = pFormShell; 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir // Connect to the new form shell. 120*cdf0e10cSrcweir if (mpFormShell != NULL) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir mpFormShell->SetControlActivationHandler( 123*cdf0e10cSrcweir LINK( 124*cdf0e10cSrcweir this, 125*cdf0e10cSrcweir FormShellManager, 126*cdf0e10cSrcweir FormControlActivated)); 127*cdf0e10cSrcweir StartListening(*mpFormShell); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir ViewShell* pMainViewShell = mrBase.GetMainViewShell().get(); 130*cdf0e10cSrcweir if (pMainViewShell != NULL) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir // Prevent setting the view twice at the FmFormShell. 133*cdf0e10cSrcweir FmFormView* pFormView = static_cast<FmFormView*>(pMainViewShell->GetView()); 134*cdf0e10cSrcweir if (mpFormShell->GetFormView() != pFormView) 135*cdf0e10cSrcweir mpFormShell->SetView(pFormView); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir // Tell the ViewShellManager where on the stack to place the form shell. 140*cdf0e10cSrcweir mrBase.GetViewShellManager()->SetFormShell( 141*cdf0e10cSrcweir mrBase.GetMainViewShell().get(), 142*cdf0e10cSrcweir mpFormShell, 143*cdf0e10cSrcweir mbFormShellAboveViewShell); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir FmFormShell* FormShellManager::GetFormShell (void) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir return mpFormShell; 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir void FormShellManager::RegisterAtCenterPane (void) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir do 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir ViewShell* pShell = mrBase.GetMainViewShell().get(); 163*cdf0e10cSrcweir if (pShell == NULL) 164*cdf0e10cSrcweir break; 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir // No form shell for the slide sorter. Besides that it is not 167*cdf0e10cSrcweir // necessary, using both together results in crashes. 168*cdf0e10cSrcweir if (pShell->GetShellType() == ViewShell::ST_SLIDE_SORTER) 169*cdf0e10cSrcweir break; 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir mpMainViewShellWindow = pShell->GetActiveWindow(); 172*cdf0e10cSrcweir if (mpMainViewShellWindow == NULL) 173*cdf0e10cSrcweir break; 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir // Register at the window to get informed when to move the form 176*cdf0e10cSrcweir // shell to the bottom of the shell stack. 177*cdf0e10cSrcweir mpMainViewShellWindow->AddEventListener( 178*cdf0e10cSrcweir LINK( 179*cdf0e10cSrcweir this, 180*cdf0e10cSrcweir FormShellManager, 181*cdf0e10cSrcweir WindowEventHandler)); 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir // Create a shell factory and with it activate the form shell. 184*cdf0e10cSrcweir OSL_ASSERT(mpSubShellFactory.get()==NULL); 185*cdf0e10cSrcweir mpSubShellFactory.reset(new FormShellManagerFactory(*pShell, *this)); 186*cdf0e10cSrcweir mrBase.GetViewShellManager()->AddSubShellFactory(pShell,mpSubShellFactory); 187*cdf0e10cSrcweir mrBase.GetViewShellManager()->ActivateSubShell(*pShell, RID_FORMLAYER_TOOLBOX); 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir while (false); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir void FormShellManager::UnregisterAtCenterPane (void) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir do 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir if (mpMainViewShellWindow != NULL) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir // Unregister from the window. 202*cdf0e10cSrcweir mpMainViewShellWindow->RemoveEventListener( 203*cdf0e10cSrcweir LINK( 204*cdf0e10cSrcweir this, 205*cdf0e10cSrcweir FormShellManager, 206*cdf0e10cSrcweir WindowEventHandler)); 207*cdf0e10cSrcweir mpMainViewShellWindow = NULL; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir // Unregister form at the form shell. 211*cdf0e10cSrcweir SetFormShell(NULL); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir // Deactivate the form shell and destroy the shell factory. 214*cdf0e10cSrcweir ViewShell* pShell = mrBase.GetMainViewShell().get(); 215*cdf0e10cSrcweir if (pShell != NULL) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir mrBase.GetViewShellManager()->DeactivateSubShell(*pShell, RID_FORMLAYER_TOOLBOX); 218*cdf0e10cSrcweir mrBase.GetViewShellManager()->RemoveSubShellFactory(pShell, mpSubShellFactory); 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir mpSubShellFactory.reset(); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir while (false); 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir IMPL_LINK(FormShellManager, FormControlActivated, FmFormShell*, EMPTYARG) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir // The form shell has been actived. To give it priority in reacting to 232*cdf0e10cSrcweir // slot calls the form shell is moved to the top of the object bar shell 233*cdf0e10cSrcweir // stack. 234*cdf0e10cSrcweir ViewShell* pShell = mrBase.GetMainViewShell().get(); 235*cdf0e10cSrcweir if (pShell!=NULL && !mbFormShellAboveViewShell) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir mbFormShellAboveViewShell = true; 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir ViewShellManager::UpdateLock aLock (mrBase.GetViewShellManager()); 240*cdf0e10cSrcweir mrBase.GetViewShellManager()->SetFormShell(pShell,mpFormShell,mbFormShellAboveViewShell); 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir return 0; 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir IMPL_LINK(FormShellManager, ConfigurationUpdateHandler, sd::tools::EventMultiplexerEvent*, pEvent) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir switch (pEvent->meEventId) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir case sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED: 254*cdf0e10cSrcweir UnregisterAtCenterPane(); 255*cdf0e10cSrcweir break; 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir case sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED: 258*cdf0e10cSrcweir mbIsMainViewChangePending = true; 259*cdf0e10cSrcweir break; 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir case sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED: 262*cdf0e10cSrcweir if (mbIsMainViewChangePending) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir mbIsMainViewChangePending = false; 265*cdf0e10cSrcweir RegisterAtCenterPane(); 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir break; 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir default: 270*cdf0e10cSrcweir break; 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir return 0; 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir IMPL_LINK(FormShellManager, WindowEventHandler, VclWindowEvent*, pEvent) 280*cdf0e10cSrcweir { 281*cdf0e10cSrcweir if (pEvent != NULL) 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir switch (pEvent->GetId()) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir case VCLEVENT_WINDOW_GETFOCUS: 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir // The window of the center pane got the focus. Therefore 288*cdf0e10cSrcweir // the form shell is moved to the bottom of the object bar 289*cdf0e10cSrcweir // stack. 290*cdf0e10cSrcweir ViewShell* pShell = mrBase.GetMainViewShell().get(); 291*cdf0e10cSrcweir if (pShell!=NULL && mbFormShellAboveViewShell) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir mbFormShellAboveViewShell = false; 294*cdf0e10cSrcweir ViewShellManager::UpdateLock aLock (mrBase.GetViewShellManager()); 295*cdf0e10cSrcweir mrBase.GetViewShellManager()->SetFormShell( 296*cdf0e10cSrcweir pShell, 297*cdf0e10cSrcweir mpFormShell, 298*cdf0e10cSrcweir mbFormShellAboveViewShell); 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir break; 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir case VCLEVENT_WINDOW_LOSEFOCUS: 304*cdf0e10cSrcweir // We follow the sloppy focus policy. Losing the focus is 305*cdf0e10cSrcweir // ignored. We wait for the focus to be placed either in 306*cdf0e10cSrcweir // the window or the form shell. The later, however, is 307*cdf0e10cSrcweir // notified over the FormControlActivated handler, not this 308*cdf0e10cSrcweir // one. 309*cdf0e10cSrcweir break; 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir case VCLEVENT_OBJECT_DYING: 312*cdf0e10cSrcweir mpMainViewShellWindow = NULL; 313*cdf0e10cSrcweir break; 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir return 0; 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir void FormShellManager::Notify(SfxBroadcaster&, const SfxHint& rHint) 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint); 326*cdf0e10cSrcweir if (pSimpleHint!=NULL && pSimpleHint->GetId()==SFX_HINT_DYING) 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir // If all goes well this listener is called after the 329*cdf0e10cSrcweir // FormShellManager was notified about the dying form shell by the 330*cdf0e10cSrcweir // FormShellManagerFactory. 331*cdf0e10cSrcweir OSL_ASSERT(mpFormShell==NULL); 332*cdf0e10cSrcweir if (mpFormShell != NULL) 333*cdf0e10cSrcweir { 334*cdf0e10cSrcweir mpFormShell = NULL; 335*cdf0e10cSrcweir mrBase.GetViewShellManager()->SetFormShell( 336*cdf0e10cSrcweir mrBase.GetMainViewShell().get(), 337*cdf0e10cSrcweir NULL, 338*cdf0e10cSrcweir false); 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir } 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir //===== FormShellManagerFactory =============================================== 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir namespace { 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir FormShellManagerFactory::FormShellManagerFactory ( 352*cdf0e10cSrcweir ::sd::ViewShell& rViewShell, 353*cdf0e10cSrcweir FormShellManager& rManager) 354*cdf0e10cSrcweir : mrViewShell(rViewShell), 355*cdf0e10cSrcweir mrFormShellManager(rManager) 356*cdf0e10cSrcweir { 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir FmFormShell* FormShellManagerFactory::CreateShell ( 363*cdf0e10cSrcweir ::sd::ShellId nId, 364*cdf0e10cSrcweir ::Window*, 365*cdf0e10cSrcweir ::sd::FrameView*) 366*cdf0e10cSrcweir { 367*cdf0e10cSrcweir FmFormShell* pShell = NULL; 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir ::sd::View* pView = mrViewShell.GetView(); 370*cdf0e10cSrcweir if (nId == RID_FORMLAYER_TOOLBOX) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir pShell = new FmFormShell(&mrViewShell.GetViewShellBase(), pView); 373*cdf0e10cSrcweir mrFormShellManager.SetFormShell(pShell); 374*cdf0e10cSrcweir } 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir return pShell; 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir void FormShellManagerFactory::ReleaseShell (SfxShell* pShell) 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir if (pShell != NULL) 385*cdf0e10cSrcweir { 386*cdf0e10cSrcweir mrFormShellManager.SetFormShell(NULL); 387*cdf0e10cSrcweir delete pShell; 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir } // end of anonymous namespace 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir } // end of namespace sd 394