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_extensions.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <osl/mutex.hxx> 32*cdf0e10cSrcweir #include <tools/urlobj.hxx> 33*cdf0e10cSrcweir #include <cppuhelper/weak.hxx> 34*cdf0e10cSrcweir #include <unotools/processfactory.hxx> 35*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 36*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/awt/XWindowPeer.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp> 41*cdf0e10cSrcweir #include "bibconfig.hxx" 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include "datman.hxx" 45*cdf0e10cSrcweir #include "bibcont.hxx" 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir BibShortCutHandler::~BibShortCutHandler() 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir } 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir sal_Bool BibShortCutHandler::HandleShortCutKey( const KeyEvent& ) 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir return sal_False; 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir BibWindow::BibWindow( Window* pParent, WinBits nStyle ) : Window( pParent, nStyle ), BibShortCutHandler( this ) 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir BibWindow::~BibWindow() 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir BibSplitWindow::BibSplitWindow( Window* pParent, WinBits nStyle ) : SplitWindow( pParent, nStyle ), BibShortCutHandler( this ) 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir BibSplitWindow::~BibSplitWindow() 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir BibTabPage::BibTabPage( Window* pParent, const ResId& rResId ) : TabPage( pParent, rResId ), BibShortCutHandler( this ) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir BibTabPage::~BibTabPage() 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir using namespace osl; 86*cdf0e10cSrcweir using namespace ::com::sun::star; 87*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 88*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 89*cdf0e10cSrcweir using namespace ::rtl; 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir #define C2U(cChar) OUString::createFromAscii(cChar) 92*cdf0e10cSrcweir #define PROPERTY_FRAME 1 93*cdf0e10cSrcweir //split window size is a percent value 94*cdf0e10cSrcweir #define WIN_MIN_HEIGHT 10 95*cdf0e10cSrcweir #define WIN_STEP_SIZE 5 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir BibWindowContainer::BibWindowContainer( Window* pParent, BibShortCutHandler* pChildWin, WinBits nStyle ) : 98*cdf0e10cSrcweir BibWindow( pParent, nStyle ), 99*cdf0e10cSrcweir pChild( pChildWin ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir if(pChild!=NULL) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir Window* pChildWindow = GetChild(); 104*cdf0e10cSrcweir pChildWindow->SetParent(this); 105*cdf0e10cSrcweir pChildWindow->Show(); 106*cdf0e10cSrcweir pChildWindow->SetPosPixel(Point(0,0)); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir BibWindowContainer::~BibWindowContainer() 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir if( pChild ) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir Window* pDel = GetChild(); 115*cdf0e10cSrcweir pChild = NULL; // prevents GetFocus for child while deleting! 116*cdf0e10cSrcweir delete pDel; 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir void BibWindowContainer::Resize() 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir if( pChild ) 123*cdf0e10cSrcweir GetChild()->SetSizePixel( GetOutputSizePixel() ); 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir void BibWindowContainer::GetFocus() 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir if( pChild ) 129*cdf0e10cSrcweir GetChild()->GrabFocus(); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir sal_Bool BibWindowContainer::HandleShortCutKey( const KeyEvent& rKeyEvent ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir return pChild? pChild->HandleShortCutKey( rKeyEvent ) : sal_False; 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir BibBookContainer::BibBookContainer(Window* pParent,BibDataManager* pDtMn, WinBits nStyle): 139*cdf0e10cSrcweir BibSplitWindow(pParent,nStyle), 140*cdf0e10cSrcweir pDatMan(pDtMn), 141*cdf0e10cSrcweir pTopWin(NULL), 142*cdf0e10cSrcweir pBottomWin(NULL), 143*cdf0e10cSrcweir bFirstTime(sal_True) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir pBibMod = OpenBibModul(); 146*cdf0e10cSrcweir aTimer.SetTimeoutHdl(LINK( this, BibBookContainer, SplitHdl)); 147*cdf0e10cSrcweir aTimer.SetTimeout(400); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir BibBookContainer::~BibBookContainer() 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir if( xTopFrameRef.is() ) 153*cdf0e10cSrcweir xTopFrameRef->dispose(); 154*cdf0e10cSrcweir if( xBottomFrameRef.is() ) 155*cdf0e10cSrcweir xBottomFrameRef->dispose(); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir if( pTopWin ) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir Window* pDel = pTopWin; 160*cdf0e10cSrcweir pTopWin = NULL; // prevents GetFocus for child while deleting! 161*cdf0e10cSrcweir delete pDel; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir if( pBottomWin ) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir Window* pDel = pBottomWin; 167*cdf0e10cSrcweir pBottomWin = NULL; // prevents GetFocus for child while deleting! 168*cdf0e10cSrcweir delete pDel; 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir CloseBibModul( pBibMod ); 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir void BibBookContainer::Split() 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir aTimer.Start(); 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir IMPL_LINK( BibBookContainer, SplitHdl, Timer*,/*pT*/) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir long nSize= GetItemSize( TOP_WINDOW); 181*cdf0e10cSrcweir BibConfig* pConfig = BibModul::GetConfig(); 182*cdf0e10cSrcweir pConfig->setBeamerSize(nSize); 183*cdf0e10cSrcweir nSize = GetItemSize( BOTTOM_WINDOW); 184*cdf0e10cSrcweir pConfig->setViewSize(nSize); 185*cdf0e10cSrcweir return 0; 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir void BibBookContainer::createTopFrame( BibShortCutHandler* pWin ) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir if ( xTopFrameRef.is() ) xTopFrameRef->dispose(); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir if(pTopWin) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir RemoveItem(TOP_WINDOW); 195*cdf0e10cSrcweir delete pTopWin; 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir pTopWin=new BibWindowContainer(this,pWin); 198*cdf0e10cSrcweir pTopWin->Show(); 199*cdf0e10cSrcweir BibConfig* pConfig = BibModul::GetConfig(); 200*cdf0e10cSrcweir long nSize = pConfig->getBeamerSize(); 201*cdf0e10cSrcweir InsertItem(TOP_WINDOW, pTopWin, nSize, 1, 0, SWIB_PERCENTSIZE ); 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir void BibBookContainer::createBottomFrame( BibShortCutHandler* pWin ) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir if ( xBottomFrameRef.is() ) xBottomFrameRef->dispose(); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir if(pBottomWin) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir RemoveItem(BOTTOM_WINDOW); 212*cdf0e10cSrcweir delete pBottomWin; 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir pBottomWin=new BibWindowContainer(this,pWin); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir BibConfig* pConfig = BibModul::GetConfig(); 218*cdf0e10cSrcweir long nSize = pConfig->getViewSize(); 219*cdf0e10cSrcweir InsertItem(BOTTOM_WINDOW, pBottomWin, nSize, 1, 0, SWIB_PERCENTSIZE ); 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir void BibBookContainer::GetFocus() 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir if( pBottomWin ) 226*cdf0e10cSrcweir pBottomWin->GrabFocus(); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir long BibBookContainer::PreNotify( NotifyEvent& rNEvt ) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir long nHandled = 0; 232*cdf0e10cSrcweir if( EVENT_KEYINPUT == rNEvt.GetType() ) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir const KeyEvent* pKEvt = rNEvt.GetKeyEvent(); 235*cdf0e10cSrcweir const KeyCode aKeyCode = pKEvt->GetKeyCode(); 236*cdf0e10cSrcweir sal_uInt16 nKey = aKeyCode.GetCode(); 237*cdf0e10cSrcweir const sal_uInt16 nModifier = aKeyCode.GetModifier(); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir if( KEY_MOD2 == nModifier ) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir if( KEY_UP == nKey || KEY_DOWN == nKey ) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir if(pTopWin && pBottomWin) 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir sal_uInt16 nFirstWinId = KEY_UP == nKey ? TOP_WINDOW : BOTTOM_WINDOW; 246*cdf0e10cSrcweir sal_uInt16 nSecondWinId = KEY_UP == nKey ? BOTTOM_WINDOW : TOP_WINDOW; 247*cdf0e10cSrcweir long nHeight = GetItemSize( nFirstWinId ); 248*cdf0e10cSrcweir nHeight -= WIN_STEP_SIZE; 249*cdf0e10cSrcweir if(nHeight < WIN_MIN_HEIGHT) 250*cdf0e10cSrcweir nHeight = WIN_MIN_HEIGHT; 251*cdf0e10cSrcweir SetItemSize( nFirstWinId, nHeight ); 252*cdf0e10cSrcweir SetItemSize( nSecondWinId, 100 - nHeight ); 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir nHandled = 1; 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir else if( pKEvt->GetCharCode() && HandleShortCutKey( *pKEvt ) ) 257*cdf0e10cSrcweir nHandled = 1; 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir return nHandled; 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir sal_Bool BibBookContainer::HandleShortCutKey( const KeyEvent& rKeyEvent ) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir sal_Bool bRet = sal_False; 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir if( pTopWin ) 269*cdf0e10cSrcweir bRet = pTopWin->HandleShortCutKey( rKeyEvent ); 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir if( !bRet && pBottomWin ) 272*cdf0e10cSrcweir bRet = pBottomWin->HandleShortCutKey( rKeyEvent ); 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir return bRet; 275*cdf0e10cSrcweir } 276