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 <vcl/event.hxx>
22 #include "bibconfig.hxx"
25 #include "bibcont.hxx"
28 BibShortCutHandler::~BibShortCutHandler()
32 bool BibShortCutHandler::HandleShortCutKey( const KeyEvent
& )
38 BibWindow::BibWindow( vcl::Window
* pParent
, WinBits nStyle
) : Window( pParent
, nStyle
), BibShortCutHandler( this )
42 BibWindow::~BibWindow()
47 BibSplitWindow::BibSplitWindow( vcl::Window
* pParent
, WinBits nStyle
) : SplitWindow( pParent
, nStyle
), BibShortCutHandler( this )
51 using namespace ::com::sun::star
;
53 //split window size is a percent value
54 #define WIN_MIN_HEIGHT 10
55 #define WIN_STEP_SIZE 5
57 BibWindowContainer::BibWindowContainer( vcl::Window
* pParent
, BibShortCutHandler
* pChildWin
) :
58 BibWindow( pParent
, WB_3DLOOK
),
63 vcl::Window
* pChildWindow
= GetChild();
64 pChildWindow
->SetParent(this);
66 pChildWindow
->SetPosPixel(Point(0,0));
70 BibWindowContainer::~BibWindowContainer()
75 void BibWindowContainer::dispose()
79 VclPtr
<vcl::Window
> pDel
= GetChild();
80 pChild
= nullptr; // prevents GetFocus for child while deleting!
81 pDel
.disposeAndClear();
83 vcl::Window::dispose();
86 void BibWindowContainer::Resize()
89 GetChild()->SetSizePixel( GetOutputSizePixel() );
92 void BibWindowContainer::GetFocus()
95 GetChild()->GrabFocus();
98 bool BibWindowContainer::HandleShortCutKey( const KeyEvent
& rKeyEvent
)
100 return pChild
&& pChild
->HandleShortCutKey( rKeyEvent
);
104 BibBookContainer::BibBookContainer(vcl::Window
* pParent
):
105 BibSplitWindow(pParent
,WB_3DLOOK
),
108 aIdle("extensions BibBookContainer Split Idle")
110 pBibMod
= OpenBibModul();
111 aIdle
.SetInvokeHandler(LINK( this, BibBookContainer
, SplitHdl
));
112 aIdle
.SetPriority(TaskPriority::LOWEST
);
115 BibBookContainer::~BibBookContainer()
120 void BibBookContainer::dispose()
124 VclPtr
<vcl::Window
> pDel
= pTopWin
;
125 pTopWin
= nullptr; // prevents GetFocus for child while deleting!
126 pDel
.disposeAndClear();
131 VclPtr
<vcl::Window
> pDel
= pBottomWin
;
132 pBottomWin
= nullptr; // prevents GetFocus for child while deleting!
133 pDel
.disposeAndClear();
136 CloseBibModul( pBibMod
);
139 BibSplitWindow::dispose();
142 void BibBookContainer::Split()
146 IMPL_LINK_NOARG( BibBookContainer
, SplitHdl
, Timer
*, void)
148 tools::Long nSize
= GetItemSize( TOP_WINDOW
);
149 BibConfig
* pConfig
= BibModul::GetConfig();
150 pConfig
->setBeamerSize(nSize
);
151 nSize
= GetItemSize( BOTTOM_WINDOW
);
152 pConfig
->setViewSize(nSize
);
155 void BibBookContainer::createTopFrame( BibShortCutHandler
* pWin
)
159 RemoveItem(TOP_WINDOW
);
160 pTopWin
.disposeAndClear();
162 pTopWin
=VclPtr
<BibWindowContainer
>::Create(this,pWin
);
164 BibConfig
* pConfig
= BibModul::GetConfig();
165 tools::Long nSize
= pConfig
->getBeamerSize();
166 InsertItem(TOP_WINDOW
, pTopWin
, nSize
, 1, 0, SplitWindowItemFlags::PercentSize
);
170 void BibBookContainer::createBottomFrame( BibShortCutHandler
* pWin
)
174 RemoveItem(BOTTOM_WINDOW
);
175 pBottomWin
.disposeAndClear();
178 pBottomWin
=VclPtr
<BibWindowContainer
>::Create(this,pWin
);
180 BibConfig
* pConfig
= BibModul::GetConfig();
181 tools::Long nSize
= pConfig
->getViewSize();
182 InsertItem(BOTTOM_WINDOW
, pBottomWin
, nSize
, 1, 0, SplitWindowItemFlags::PercentSize
);
186 void BibBookContainer::GetFocus()
189 pBottomWin
->GrabFocus();
192 bool BibBookContainer::PreNotify( NotifyEvent
& rNEvt
)
194 bool bHandled
= false;
195 if( NotifyEventType::KEYINPUT
== rNEvt
.GetType() )
197 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
198 const vcl::KeyCode aKeyCode
= pKEvt
->GetKeyCode();
199 sal_uInt16 nKey
= aKeyCode
.GetCode();
200 const sal_uInt16 nModifier
= aKeyCode
.GetModifier();
202 if( KEY_MOD2
== nModifier
)
204 if( KEY_UP
== nKey
|| KEY_DOWN
== nKey
)
206 if(pTopWin
&& pBottomWin
)
208 sal_uInt16 nFirstWinId
= KEY_UP
== nKey
? TOP_WINDOW
: BOTTOM_WINDOW
;
209 sal_uInt16 nSecondWinId
= KEY_UP
== nKey
? BOTTOM_WINDOW
: TOP_WINDOW
;
210 tools::Long nHeight
= GetItemSize( nFirstWinId
);
211 nHeight
-= WIN_STEP_SIZE
;
212 if(nHeight
< WIN_MIN_HEIGHT
)
213 nHeight
= WIN_MIN_HEIGHT
;
214 SetItemSize( nFirstWinId
, nHeight
);
215 SetItemSize( nSecondWinId
, 100 - nHeight
);
219 else if( pKEvt
->GetCharCode() && HandleShortCutKey( *pKEvt
) )
227 bool BibBookContainer::HandleShortCutKey( const KeyEvent
& rKeyEvent
)
232 bRet
= pTopWin
->HandleShortCutKey( rKeyEvent
);
234 if( !bRet
&& pBottomWin
)
235 bRet
= pBottomWin
->HandleShortCutKey( rKeyEvent
);
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */