1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bibcont.cxx,v $
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"
48 #include "bibcont.hxx"
51 BibShortCutHandler::~BibShortCutHandler()
55 sal_Bool
BibShortCutHandler::HandleShortCutKey( const KeyEvent
& )
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()
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
),
106 Window
* pChildWindow
= GetChild();
107 pChildWindow
->SetParent(this);
108 pChildWindow
->Show();
109 pChildWindow
->SetPosPixel(Point(0,0));
113 BibWindowContainer::~BibWindowContainer()
117 Window
* pDel
= GetChild();
118 pChild
= NULL
; // prevents GetFocus for child while deleting!
123 void BibWindowContainer::Resize()
126 GetChild()->SetSizePixel( GetOutputSizePixel() );
129 void BibWindowContainer::GetFocus()
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
),
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();
162 Window
* pDel
= pTopWin
;
163 pTopWin
= NULL
; // prevents GetFocus for child while deleting!
169 Window
* pDel
= pBottomWin
;
170 pBottomWin
= NULL
; // prevents GetFocus for child while deleting!
174 CloseBibModul( pBibMod
);
177 void BibBookContainer::Split()
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
);
191 void BibBookContainer::createTopFrame( BibShortCutHandler
* pWin
)
193 if ( xTopFrameRef
.is() ) xTopFrameRef
->dispose();
197 RemoveItem(TOP_WINDOW
);
200 pTopWin
=new BibWindowContainer(this,pWin
);
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();
214 RemoveItem(BOTTOM_WINDOW
);
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()
229 pBottomWin
->GrabFocus();
232 long BibBookContainer::PreNotify( NotifyEvent
& rNEvt
)
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
);
259 else if( pKEvt
->GetCharCode() && HandleShortCutKey( *pKEvt
) )
267 sal_Bool
BibBookContainer::HandleShortCutKey( const KeyEvent
& rKeyEvent
)
269 sal_Bool bRet
= sal_False
;
272 bRet
= pTopWin
->HandleShortCutKey( rKeyEvent
);
274 if( !bRet
&& pBottomWin
)
275 bRet
= pBottomWin
->HandleShortCutKey( rKeyEvent
);