merge the formfield patch from ooo-build
[ooovba.git] / extensions / source / bibliography / bibcont.cxx
blob9545d17f32a0f34fb6471f2fbf529030376a6b66
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bibcont.cxx,v $
10 * $Revision: 1.17 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
34 #include <osl/mutex.hxx>
35 #include <tools/urlobj.hxx>
36 #include <cppuhelper/weak.hxx>
37 #include <unotools/processfactory.hxx>
38 #include <toolkit/helper/vclunohelper.hxx>
39 #include <com/sun/star/awt/XWindow.hpp>
40 #include <com/sun/star/awt/XWindowPeer.hpp>
41 #include <com/sun/star/frame/XDispatchProvider.hpp>
42 #include <com/sun/star/frame/FrameSearchFlag.hpp>
43 #include <com/sun/star/util/XURLTransformer.hpp>
44 #include "bibconfig.hxx"
47 #include "datman.hxx"
48 #include "bibcont.hxx"
51 BibShortCutHandler::~BibShortCutHandler()
55 sal_Bool BibShortCutHandler::HandleShortCutKey( const KeyEvent& )
57 return sal_False;
61 BibWindow::BibWindow( Window* pParent, WinBits nStyle ) : Window( pParent, nStyle ), BibShortCutHandler( this )
65 BibWindow::~BibWindow()
70 BibSplitWindow::BibSplitWindow( Window* pParent, WinBits nStyle ) : SplitWindow( pParent, nStyle ), BibShortCutHandler( this )
74 BibSplitWindow::~BibSplitWindow()
79 BibTabPage::BibTabPage( Window* pParent, const ResId& rResId ) : TabPage( pParent, rResId ), BibShortCutHandler( this )
83 BibTabPage::~BibTabPage()
88 using namespace osl;
89 using namespace ::com::sun::star;
90 using namespace ::com::sun::star::uno;
91 using namespace ::com::sun::star::frame;
92 using namespace ::rtl;
94 #define C2U(cChar) OUString::createFromAscii(cChar)
95 #define PROPERTY_FRAME 1
96 //split window size is a percent value
97 #define WIN_MIN_HEIGHT 10
98 #define WIN_STEP_SIZE 5
100 BibWindowContainer::BibWindowContainer( Window* pParent, BibShortCutHandler* pChildWin, WinBits nStyle ) :
101 BibWindow( pParent, nStyle ),
102 pChild( pChildWin )
104 if(pChild!=NULL)
106 Window* pChildWindow = GetChild();
107 pChildWindow->SetParent(this);
108 pChildWindow->Show();
109 pChildWindow->SetPosPixel(Point(0,0));
113 BibWindowContainer::~BibWindowContainer()
115 if( pChild )
117 Window* pDel = GetChild();
118 pChild = NULL; // prevents GetFocus for child while deleting!
119 delete pDel;
123 void BibWindowContainer::Resize()
125 if( pChild )
126 GetChild()->SetSizePixel( GetOutputSizePixel() );
129 void BibWindowContainer::GetFocus()
131 if( pChild )
132 GetChild()->GrabFocus();
135 sal_Bool BibWindowContainer::HandleShortCutKey( const KeyEvent& rKeyEvent )
137 return pChild? pChild->HandleShortCutKey( rKeyEvent ) : sal_False;
141 BibBookContainer::BibBookContainer(Window* pParent,BibDataManager* pDtMn, WinBits nStyle):
142 BibSplitWindow(pParent,nStyle),
143 pDatMan(pDtMn),
144 pTopWin(NULL),
145 pBottomWin(NULL),
146 bFirstTime(sal_True)
148 pBibMod = OpenBibModul();
149 aTimer.SetTimeoutHdl(LINK( this, BibBookContainer, SplitHdl));
150 aTimer.SetTimeout(400);
153 BibBookContainer::~BibBookContainer()
155 if( xTopFrameRef.is() )
156 xTopFrameRef->dispose();
157 if( xBottomFrameRef.is() )
158 xBottomFrameRef->dispose();
160 if( pTopWin )
162 Window* pDel = pTopWin;
163 pTopWin = NULL; // prevents GetFocus for child while deleting!
164 delete pDel;
167 if( pBottomWin )
169 Window* pDel = pBottomWin;
170 pBottomWin = NULL; // prevents GetFocus for child while deleting!
171 delete pDel;
174 CloseBibModul( pBibMod );
177 void BibBookContainer::Split()
179 aTimer.Start();
181 IMPL_LINK( BibBookContainer, SplitHdl, Timer*,/*pT*/)
183 long nSize= GetItemSize( TOP_WINDOW);
184 BibConfig* pConfig = BibModul::GetConfig();
185 pConfig->setBeamerSize(nSize);
186 nSize = GetItemSize( BOTTOM_WINDOW);
187 pConfig->setViewSize(nSize);
188 return 0;
191 void BibBookContainer::createTopFrame( BibShortCutHandler* pWin )
193 if ( xTopFrameRef.is() ) xTopFrameRef->dispose();
195 if(pTopWin)
197 RemoveItem(TOP_WINDOW);
198 delete pTopWin;
200 pTopWin=new BibWindowContainer(this,pWin);
201 pTopWin->Show();
202 BibConfig* pConfig = BibModul::GetConfig();
203 long nSize = pConfig->getBeamerSize();
204 InsertItem(TOP_WINDOW, pTopWin, nSize, 1, 0, SWIB_PERCENTSIZE );
208 void BibBookContainer::createBottomFrame( BibShortCutHandler* pWin )
210 if ( xBottomFrameRef.is() ) xBottomFrameRef->dispose();
212 if(pBottomWin)
214 RemoveItem(BOTTOM_WINDOW);
215 delete pBottomWin;
218 pBottomWin=new BibWindowContainer(this,pWin);
220 BibConfig* pConfig = BibModul::GetConfig();
221 long nSize = pConfig->getViewSize();
222 InsertItem(BOTTOM_WINDOW, pBottomWin, nSize, 1, 0, SWIB_PERCENTSIZE );
226 void BibBookContainer::GetFocus()
228 if( pBottomWin )
229 pBottomWin->GrabFocus();
232 long BibBookContainer::PreNotify( NotifyEvent& rNEvt )
234 long nHandled = 0;
235 if( EVENT_KEYINPUT == rNEvt.GetType() )
237 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
238 const KeyCode aKeyCode = pKEvt->GetKeyCode();
239 USHORT nKey = aKeyCode.GetCode();
240 const USHORT nModifier = aKeyCode.GetModifier();
242 if( KEY_MOD2 == nModifier )
244 if( KEY_UP == nKey || KEY_DOWN == nKey )
246 if(pTopWin && pBottomWin)
248 USHORT nFirstWinId = KEY_UP == nKey ? TOP_WINDOW : BOTTOM_WINDOW;
249 USHORT nSecondWinId = KEY_UP == nKey ? BOTTOM_WINDOW : TOP_WINDOW;
250 long nHeight = GetItemSize( nFirstWinId );
251 nHeight -= WIN_STEP_SIZE;
252 if(nHeight < WIN_MIN_HEIGHT)
253 nHeight = WIN_MIN_HEIGHT;
254 SetItemSize( nFirstWinId, nHeight );
255 SetItemSize( nSecondWinId, 100 - nHeight );
257 nHandled = 1;
259 else if( pKEvt->GetCharCode() && HandleShortCutKey( *pKEvt ) )
260 nHandled = 1;
264 return nHandled;
267 sal_Bool BibBookContainer::HandleShortCutKey( const KeyEvent& rKeyEvent )
269 sal_Bool bRet = sal_False;
271 if( pTopWin )
272 bRet = pTopWin->HandleShortCutKey( rKeyEvent );
274 if( !bRet && pBottomWin )
275 bRet = pBottomWin->HandleShortCutKey( rKeyEvent );
277 return bRet;