merged tag ooo/OOO330_m14
[LibreOffice.git] / extensions / source / bibliography / bibcont.cxx
blob2666a1a69199bdc444c4089c68e6281b31747011
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
31 #include <osl/mutex.hxx>
32 #include <tools/urlobj.hxx>
33 #include <cppuhelper/weak.hxx>
34 #include <unotools/processfactory.hxx>
35 #include <toolkit/helper/vclunohelper.hxx>
36 #include <com/sun/star/awt/XWindow.hpp>
37 #include <com/sun/star/awt/XWindowPeer.hpp>
38 #include <com/sun/star/frame/XDispatchProvider.hpp>
39 #include <com/sun/star/frame/FrameSearchFlag.hpp>
40 #include <com/sun/star/util/XURLTransformer.hpp>
41 #include "bibconfig.hxx"
44 #include "datman.hxx"
45 #include "bibcont.hxx"
48 BibShortCutHandler::~BibShortCutHandler()
52 sal_Bool BibShortCutHandler::HandleShortCutKey( const KeyEvent& )
54 return sal_False;
58 BibWindow::BibWindow( Window* pParent, WinBits nStyle ) : Window( pParent, nStyle ), BibShortCutHandler( this )
62 BibWindow::~BibWindow()
67 BibSplitWindow::BibSplitWindow( Window* pParent, WinBits nStyle ) : SplitWindow( pParent, nStyle ), BibShortCutHandler( this )
71 BibSplitWindow::~BibSplitWindow()
76 BibTabPage::BibTabPage( Window* pParent, const ResId& rResId ) : TabPage( pParent, rResId ), BibShortCutHandler( this )
80 BibTabPage::~BibTabPage()
85 using namespace osl;
86 using namespace ::com::sun::star;
87 using namespace ::com::sun::star::uno;
88 using namespace ::com::sun::star::frame;
89 using namespace ::rtl;
91 #define C2U(cChar) OUString::createFromAscii(cChar)
92 #define PROPERTY_FRAME 1
93 //split window size is a percent value
94 #define WIN_MIN_HEIGHT 10
95 #define WIN_STEP_SIZE 5
97 BibWindowContainer::BibWindowContainer( Window* pParent, BibShortCutHandler* pChildWin, WinBits nStyle ) :
98 BibWindow( pParent, nStyle ),
99 pChild( pChildWin )
101 if(pChild!=NULL)
103 Window* pChildWindow = GetChild();
104 pChildWindow->SetParent(this);
105 pChildWindow->Show();
106 pChildWindow->SetPosPixel(Point(0,0));
110 BibWindowContainer::~BibWindowContainer()
112 if( pChild )
114 Window* pDel = GetChild();
115 pChild = NULL; // prevents GetFocus for child while deleting!
116 delete pDel;
120 void BibWindowContainer::Resize()
122 if( pChild )
123 GetChild()->SetSizePixel( GetOutputSizePixel() );
126 void BibWindowContainer::GetFocus()
128 if( pChild )
129 GetChild()->GrabFocus();
132 sal_Bool BibWindowContainer::HandleShortCutKey( const KeyEvent& rKeyEvent )
134 return pChild? pChild->HandleShortCutKey( rKeyEvent ) : sal_False;
138 BibBookContainer::BibBookContainer(Window* pParent,BibDataManager* pDtMn, WinBits nStyle):
139 BibSplitWindow(pParent,nStyle),
140 pDatMan(pDtMn),
141 pTopWin(NULL),
142 pBottomWin(NULL),
143 bFirstTime(sal_True)
145 pBibMod = OpenBibModul();
146 aTimer.SetTimeoutHdl(LINK( this, BibBookContainer, SplitHdl));
147 aTimer.SetTimeout(400);
150 BibBookContainer::~BibBookContainer()
152 if( xTopFrameRef.is() )
153 xTopFrameRef->dispose();
154 if( xBottomFrameRef.is() )
155 xBottomFrameRef->dispose();
157 if( pTopWin )
159 Window* pDel = pTopWin;
160 pTopWin = NULL; // prevents GetFocus for child while deleting!
161 delete pDel;
164 if( pBottomWin )
166 Window* pDel = pBottomWin;
167 pBottomWin = NULL; // prevents GetFocus for child while deleting!
168 delete pDel;
171 CloseBibModul( pBibMod );
174 void BibBookContainer::Split()
176 aTimer.Start();
178 IMPL_LINK( BibBookContainer, SplitHdl, Timer*,/*pT*/)
180 long nSize= GetItemSize( TOP_WINDOW);
181 BibConfig* pConfig = BibModul::GetConfig();
182 pConfig->setBeamerSize(nSize);
183 nSize = GetItemSize( BOTTOM_WINDOW);
184 pConfig->setViewSize(nSize);
185 return 0;
188 void BibBookContainer::createTopFrame( BibShortCutHandler* pWin )
190 if ( xTopFrameRef.is() ) xTopFrameRef->dispose();
192 if(pTopWin)
194 RemoveItem(TOP_WINDOW);
195 delete pTopWin;
197 pTopWin=new BibWindowContainer(this,pWin);
198 pTopWin->Show();
199 BibConfig* pConfig = BibModul::GetConfig();
200 long nSize = pConfig->getBeamerSize();
201 InsertItem(TOP_WINDOW, pTopWin, nSize, 1, 0, SWIB_PERCENTSIZE );
205 void BibBookContainer::createBottomFrame( BibShortCutHandler* pWin )
207 if ( xBottomFrameRef.is() ) xBottomFrameRef->dispose();
209 if(pBottomWin)
211 RemoveItem(BOTTOM_WINDOW);
212 delete pBottomWin;
215 pBottomWin=new BibWindowContainer(this,pWin);
217 BibConfig* pConfig = BibModul::GetConfig();
218 long nSize = pConfig->getViewSize();
219 InsertItem(BOTTOM_WINDOW, pBottomWin, nSize, 1, 0, SWIB_PERCENTSIZE );
223 void BibBookContainer::GetFocus()
225 if( pBottomWin )
226 pBottomWin->GrabFocus();
229 long BibBookContainer::PreNotify( NotifyEvent& rNEvt )
231 long nHandled = 0;
232 if( EVENT_KEYINPUT == rNEvt.GetType() )
234 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
235 const KeyCode aKeyCode = pKEvt->GetKeyCode();
236 USHORT nKey = aKeyCode.GetCode();
237 const USHORT nModifier = aKeyCode.GetModifier();
239 if( KEY_MOD2 == nModifier )
241 if( KEY_UP == nKey || KEY_DOWN == nKey )
243 if(pTopWin && pBottomWin)
245 USHORT nFirstWinId = KEY_UP == nKey ? TOP_WINDOW : BOTTOM_WINDOW;
246 USHORT nSecondWinId = KEY_UP == nKey ? BOTTOM_WINDOW : TOP_WINDOW;
247 long nHeight = GetItemSize( nFirstWinId );
248 nHeight -= WIN_STEP_SIZE;
249 if(nHeight < WIN_MIN_HEIGHT)
250 nHeight = WIN_MIN_HEIGHT;
251 SetItemSize( nFirstWinId, nHeight );
252 SetItemSize( nSecondWinId, 100 - nHeight );
254 nHandled = 1;
256 else if( pKEvt->GetCharCode() && HandleShortCutKey( *pKEvt ) )
257 nHandled = 1;
261 return nHandled;
264 sal_Bool BibBookContainer::HandleShortCutKey( const KeyEvent& rKeyEvent )
266 sal_Bool bRet = sal_False;
268 if( pTopWin )
269 bRet = pTopWin->HandleShortCutKey( rKeyEvent );
271 if( !bRet && pBottomWin )
272 bRet = pBottomWin->HandleShortCutKey( rKeyEvent );
274 return bRet;