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"
34 #include "bibview.hxx"
37 BibShortCutHandler::~BibShortCutHandler()
41 bool BibShortCutHandler::HandleShortCutKey( const KeyEvent
& )
47 BibWindow::BibWindow( vcl::Window
* pParent
, WinBits nStyle
) : Window( pParent
, nStyle
), BibShortCutHandler( this )
51 BibWindow::~BibWindow()
56 BibSplitWindow::BibSplitWindow( vcl::Window
* pParent
, WinBits nStyle
) : SplitWindow( pParent
, nStyle
), BibShortCutHandler( this )
60 BibTabPage::BibTabPage( vcl::Window
* pParent
, const OString
& rID
, const OUString
& rUIXMLDescription
) :
61 TabPage( pParent
, rID
, rUIXMLDescription
), BibShortCutHandler( this )
66 using namespace ::com::sun::star
;
67 using namespace ::com::sun::star::uno
;
68 using namespace ::com::sun::star::frame
;
70 //split window size is a percent value
71 #define WIN_MIN_HEIGHT 10
72 #define WIN_STEP_SIZE 5
74 BibWindowContainer::BibWindowContainer( vcl::Window
* pParent
, BibShortCutHandler
* pChildWin
, WinBits nStyle
) :
75 BibWindow( pParent
, nStyle
),
80 vcl::Window
* pChildWindow
= GetChild();
81 pChildWindow
->SetParent(this);
83 pChildWindow
->SetPosPixel(Point(0,0));
87 BibWindowContainer::~BibWindowContainer()
92 void BibWindowContainer::dispose()
96 VclPtr
<vcl::Window
> pDel
= GetChild();
97 pChild
= NULL
; // prevents GetFocus for child while deleting!
98 pDel
.disposeAndClear();
100 vcl::Window::dispose();
103 void BibWindowContainer::Resize()
106 GetChild()->SetSizePixel( GetOutputSizePixel() );
109 void BibWindowContainer::GetFocus()
112 GetChild()->GrabFocus();
115 bool BibWindowContainer::HandleShortCutKey( const KeyEvent
& rKeyEvent
)
117 return pChild
&& pChild
->HandleShortCutKey( rKeyEvent
);
121 BibBookContainer::BibBookContainer(vcl::Window
* pParent
, WinBits nStyle
):
122 BibSplitWindow(pParent
,nStyle
),
126 pBibMod
= OpenBibModul();
127 aIdle
.SetIdleHdl(LINK( this, BibBookContainer
, SplitHdl
));
128 aIdle
.SetPriority(SchedulerPriority::LOWEST
);
131 BibBookContainer::~BibBookContainer()
136 void BibBookContainer::dispose()
138 if( xTopFrameRef
.is() )
139 xTopFrameRef
->dispose();
140 if( xBottomFrameRef
.is() )
141 xBottomFrameRef
->dispose();
145 VclPtr
<vcl::Window
> pDel
= pTopWin
;
146 pTopWin
= NULL
; // prevents GetFocus for child while deleting!
147 pDel
.disposeAndClear();
152 VclPtr
<vcl::Window
> pDel
= pBottomWin
;
153 pBottomWin
= NULL
; // prevents GetFocus for child while deleting!
154 pDel
.disposeAndClear();
157 CloseBibModul( pBibMod
);
160 BibSplitWindow::dispose();
163 void BibBookContainer::Split()
167 IMPL_LINK_NOARG_TYPED( BibBookContainer
, SplitHdl
, Idle
*, void)
169 long nSize
= GetItemSize( TOP_WINDOW
);
170 BibConfig
* pConfig
= BibModul::GetConfig();
171 pConfig
->setBeamerSize(nSize
);
172 nSize
= GetItemSize( BOTTOM_WINDOW
);
173 pConfig
->setViewSize(nSize
);
176 void BibBookContainer::createTopFrame( BibShortCutHandler
* pWin
)
178 if ( xTopFrameRef
.is() ) xTopFrameRef
->dispose();
182 RemoveItem(TOP_WINDOW
);
183 pTopWin
.disposeAndClear();
185 pTopWin
=VclPtr
<BibWindowContainer
>::Create(this,pWin
);
187 BibConfig
* pConfig
= BibModul::GetConfig();
188 long nSize
= pConfig
->getBeamerSize();
189 InsertItem(TOP_WINDOW
, pTopWin
, nSize
, 1, 0, SWIB_PERCENTSIZE
);
193 void BibBookContainer::createBottomFrame( BibShortCutHandler
* pWin
)
195 if ( xBottomFrameRef
.is() ) xBottomFrameRef
->dispose();
199 RemoveItem(BOTTOM_WINDOW
);
200 pBottomWin
.disposeAndClear();
203 pBottomWin
=VclPtr
<BibWindowContainer
>::Create(this,pWin
);
205 BibConfig
* pConfig
= BibModul::GetConfig();
206 long nSize
= pConfig
->getViewSize();
207 InsertItem(BOTTOM_WINDOW
, pBottomWin
, nSize
, 1, 0, SWIB_PERCENTSIZE
);
211 void BibBookContainer::GetFocus()
214 pBottomWin
->GrabFocus();
217 bool BibBookContainer::PreNotify( NotifyEvent
& rNEvt
)
219 bool nHandled
= false;
220 if( MouseNotifyEvent::KEYINPUT
== rNEvt
.GetType() )
222 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
223 const vcl::KeyCode aKeyCode
= pKEvt
->GetKeyCode();
224 sal_uInt16 nKey
= aKeyCode
.GetCode();
225 const sal_uInt16 nModifier
= aKeyCode
.GetModifier();
227 if( KEY_MOD2
== nModifier
)
229 if( KEY_UP
== nKey
|| KEY_DOWN
== nKey
)
231 if(pTopWin
&& pBottomWin
)
233 sal_uInt16 nFirstWinId
= KEY_UP
== nKey
? TOP_WINDOW
: BOTTOM_WINDOW
;
234 sal_uInt16 nSecondWinId
= KEY_UP
== nKey
? BOTTOM_WINDOW
: TOP_WINDOW
;
235 long nHeight
= GetItemSize( nFirstWinId
);
236 nHeight
-= WIN_STEP_SIZE
;
237 if(nHeight
< WIN_MIN_HEIGHT
)
238 nHeight
= WIN_MIN_HEIGHT
;
239 SetItemSize( nFirstWinId
, nHeight
);
240 SetItemSize( nSecondWinId
, 100 - nHeight
);
244 else if( pKEvt
->GetCharCode() && HandleShortCutKey( *pKEvt
) )
252 bool BibBookContainer::HandleShortCutKey( const KeyEvent
& rKeyEvent
)
257 bRet
= pTopWin
->HandleShortCutKey( rKeyEvent
);
259 if( !bRet
&& pBottomWin
)
260 bRet
= pBottomWin
->HandleShortCutKey( rKeyEvent
);
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */