1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <osl/mutex.hxx>
22 #include <cppuhelper/weak.hxx>
23 #include <toolkit/helper/vclunohelper.hxx>
24 #include <com/sun/star/awt/XWindow.hpp>
25 #include <com/sun/star/awt/XWindowPeer.hpp>
26 #include <com/sun/star/frame/XDispatchProvider.hpp>
27 #include <com/sun/star/frame/FrameSearchFlag.hpp>
28 #include <com/sun/star/util/XURLTransformer.hpp>
29 #include "bibconfig.hxx"
33 #include "bibcont.hxx"
36 BibShortCutHandler::~BibShortCutHandler()
40 sal_Bool
BibShortCutHandler::HandleShortCutKey( const KeyEvent
& )
46 BibWindow::BibWindow( Window
* pParent
, WinBits nStyle
) : Window( pParent
, nStyle
), BibShortCutHandler( this )
50 BibWindow::~BibWindow()
55 BibSplitWindow::BibSplitWindow( Window
* pParent
, WinBits nStyle
) : SplitWindow( pParent
, nStyle
), BibShortCutHandler( this )
59 BibSplitWindow::~BibSplitWindow()
64 BibTabPage::BibTabPage( Window
* pParent
, const ResId
& rResId
) : TabPage( pParent
, rResId
), BibShortCutHandler( this )
68 BibTabPage::~BibTabPage()
74 using namespace ::com::sun::star
;
75 using namespace ::com::sun::star::uno
;
76 using namespace ::com::sun::star::frame
;
77 using namespace ::rtl
;
79 //split window size is a percent value
80 #define WIN_MIN_HEIGHT 10
81 #define WIN_STEP_SIZE 5
83 BibWindowContainer::BibWindowContainer( Window
* pParent
, BibShortCutHandler
* pChildWin
, WinBits nStyle
) :
84 BibWindow( pParent
, nStyle
),
89 Window
* pChildWindow
= GetChild();
90 pChildWindow
->SetParent(this);
92 pChildWindow
->SetPosPixel(Point(0,0));
96 BibWindowContainer::~BibWindowContainer()
100 Window
* pDel
= GetChild();
101 pChild
= NULL
; // prevents GetFocus for child while deleting!
106 void BibWindowContainer::Resize()
109 GetChild()->SetSizePixel( GetOutputSizePixel() );
112 void BibWindowContainer::GetFocus()
115 GetChild()->GrabFocus();
118 sal_Bool
BibWindowContainer::HandleShortCutKey( const KeyEvent
& rKeyEvent
)
120 return pChild
? pChild
->HandleShortCutKey( rKeyEvent
) : sal_False
;
124 BibBookContainer::BibBookContainer(Window
* pParent
, WinBits nStyle
):
125 BibSplitWindow(pParent
,nStyle
),
129 pBibMod
= OpenBibModul();
130 aTimer
.SetTimeoutHdl(LINK( this, BibBookContainer
, SplitHdl
));
131 aTimer
.SetTimeout(400);
134 BibBookContainer::~BibBookContainer()
136 if( xTopFrameRef
.is() )
137 xTopFrameRef
->dispose();
138 if( xBottomFrameRef
.is() )
139 xBottomFrameRef
->dispose();
143 Window
* pDel
= pTopWin
;
144 pTopWin
= NULL
; // prevents GetFocus for child while deleting!
150 Window
* pDel
= pBottomWin
;
151 pBottomWin
= NULL
; // prevents GetFocus for child while deleting!
155 CloseBibModul( pBibMod
);
158 void BibBookContainer::Split()
162 IMPL_LINK( BibBookContainer
, SplitHdl
, Timer
*,/*pT*/)
164 long nSize
= GetItemSize( TOP_WINDOW
);
165 BibConfig
* pConfig
= BibModul::GetConfig();
166 pConfig
->setBeamerSize(nSize
);
167 nSize
= GetItemSize( BOTTOM_WINDOW
);
168 pConfig
->setViewSize(nSize
);
172 void BibBookContainer::createTopFrame( BibShortCutHandler
* pWin
)
174 if ( xTopFrameRef
.is() ) xTopFrameRef
->dispose();
178 RemoveItem(TOP_WINDOW
);
181 pTopWin
=new BibWindowContainer(this,pWin
);
183 BibConfig
* pConfig
= BibModul::GetConfig();
184 long nSize
= pConfig
->getBeamerSize();
185 InsertItem(TOP_WINDOW
, pTopWin
, nSize
, 1, 0, SWIB_PERCENTSIZE
);
189 void BibBookContainer::createBottomFrame( BibShortCutHandler
* pWin
)
191 if ( xBottomFrameRef
.is() ) xBottomFrameRef
->dispose();
195 RemoveItem(BOTTOM_WINDOW
);
199 pBottomWin
=new BibWindowContainer(this,pWin
);
201 BibConfig
* pConfig
= BibModul::GetConfig();
202 long nSize
= pConfig
->getViewSize();
203 InsertItem(BOTTOM_WINDOW
, pBottomWin
, nSize
, 1, 0, SWIB_PERCENTSIZE
);
207 void BibBookContainer::GetFocus()
210 pBottomWin
->GrabFocus();
213 long BibBookContainer::PreNotify( NotifyEvent
& rNEvt
)
216 if( EVENT_KEYINPUT
== rNEvt
.GetType() )
218 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
219 const KeyCode aKeyCode
= pKEvt
->GetKeyCode();
220 sal_uInt16 nKey
= aKeyCode
.GetCode();
221 const sal_uInt16 nModifier
= aKeyCode
.GetModifier();
223 if( KEY_MOD2
== nModifier
)
225 if( KEY_UP
== nKey
|| KEY_DOWN
== nKey
)
227 if(pTopWin
&& pBottomWin
)
229 sal_uInt16 nFirstWinId
= KEY_UP
== nKey
? TOP_WINDOW
: BOTTOM_WINDOW
;
230 sal_uInt16 nSecondWinId
= KEY_UP
== nKey
? BOTTOM_WINDOW
: TOP_WINDOW
;
231 long nHeight
= GetItemSize( nFirstWinId
);
232 nHeight
-= WIN_STEP_SIZE
;
233 if(nHeight
< WIN_MIN_HEIGHT
)
234 nHeight
= WIN_MIN_HEIGHT
;
235 SetItemSize( nFirstWinId
, nHeight
);
236 SetItemSize( nSecondWinId
, 100 - nHeight
);
240 else if( pKEvt
->GetCharCode() && HandleShortCutKey( *pKEvt
) )
248 sal_Bool
BibBookContainer::HandleShortCutKey( const KeyEvent
& rKeyEvent
)
250 sal_Bool bRet
= sal_False
;
253 bRet
= pTopWin
->HandleShortCutKey( rKeyEvent
);
255 if( !bRet
&& pBottomWin
)
256 bRet
= pBottomWin
->HandleShortCutKey( rKeyEvent
);
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */