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
;
52 using namespace ::com::sun::star::uno
;
54 //split window size is a percent value
55 #define WIN_MIN_HEIGHT 10
56 #define WIN_STEP_SIZE 5
58 BibWindowContainer::BibWindowContainer( vcl::Window
* pParent
, BibShortCutHandler
* pChildWin
) :
59 BibWindow( pParent
, WB_3DLOOK
),
64 vcl::Window
* pChildWindow
= GetChild();
65 pChildWindow
->SetParent(this);
67 pChildWindow
->SetPosPixel(Point(0,0));
71 BibWindowContainer::~BibWindowContainer()
76 void BibWindowContainer::dispose()
80 VclPtr
<vcl::Window
> pDel
= GetChild();
81 pChild
= nullptr; // prevents GetFocus for child while deleting!
82 pDel
.disposeAndClear();
84 vcl::Window::dispose();
87 void BibWindowContainer::Resize()
90 GetChild()->SetSizePixel( GetOutputSizePixel() );
93 void BibWindowContainer::GetFocus()
96 GetChild()->GrabFocus();
99 bool BibWindowContainer::HandleShortCutKey( const KeyEvent
& rKeyEvent
)
101 return pChild
&& pChild
->HandleShortCutKey( rKeyEvent
);
105 BibBookContainer::BibBookContainer(vcl::Window
* pParent
):
106 BibSplitWindow(pParent
,WB_3DLOOK
),
109 aIdle("extensions BibBookContainer Split Idle")
111 pBibMod
= OpenBibModul();
112 aIdle
.SetInvokeHandler(LINK( this, BibBookContainer
, SplitHdl
));
113 aIdle
.SetPriority(TaskPriority::LOWEST
);
116 BibBookContainer::~BibBookContainer()
121 void BibBookContainer::dispose()
125 VclPtr
<vcl::Window
> pDel
= pTopWin
;
126 pTopWin
= nullptr; // prevents GetFocus for child while deleting!
127 pDel
.disposeAndClear();
132 VclPtr
<vcl::Window
> pDel
= pBottomWin
;
133 pBottomWin
= nullptr; // prevents GetFocus for child while deleting!
134 pDel
.disposeAndClear();
137 CloseBibModul( pBibMod
);
140 BibSplitWindow::dispose();
143 void BibBookContainer::Split()
147 IMPL_LINK_NOARG( BibBookContainer
, SplitHdl
, Timer
*, void)
149 tools::Long nSize
= GetItemSize( TOP_WINDOW
);
150 BibConfig
* pConfig
= BibModul::GetConfig();
151 pConfig
->setBeamerSize(nSize
);
152 nSize
= GetItemSize( BOTTOM_WINDOW
);
153 pConfig
->setViewSize(nSize
);
156 void BibBookContainer::createTopFrame( BibShortCutHandler
* pWin
)
160 RemoveItem(TOP_WINDOW
);
161 pTopWin
.disposeAndClear();
163 pTopWin
=VclPtr
<BibWindowContainer
>::Create(this,pWin
);
165 BibConfig
* pConfig
= BibModul::GetConfig();
166 tools::Long nSize
= pConfig
->getBeamerSize();
167 InsertItem(TOP_WINDOW
, pTopWin
, nSize
, 1, 0, SplitWindowItemFlags::PercentSize
);
171 void BibBookContainer::createBottomFrame( BibShortCutHandler
* pWin
)
175 RemoveItem(BOTTOM_WINDOW
);
176 pBottomWin
.disposeAndClear();
179 pBottomWin
=VclPtr
<BibWindowContainer
>::Create(this,pWin
);
181 BibConfig
* pConfig
= BibModul::GetConfig();
182 tools::Long nSize
= pConfig
->getViewSize();
183 InsertItem(BOTTOM_WINDOW
, pBottomWin
, nSize
, 1, 0, SplitWindowItemFlags::PercentSize
);
187 void BibBookContainer::GetFocus()
190 pBottomWin
->GrabFocus();
193 bool BibBookContainer::PreNotify( NotifyEvent
& rNEvt
)
195 bool bHandled
= false;
196 if( NotifyEventType::KEYINPUT
== rNEvt
.GetType() )
198 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
199 const vcl::KeyCode aKeyCode
= pKEvt
->GetKeyCode();
200 sal_uInt16 nKey
= aKeyCode
.GetCode();
201 const sal_uInt16 nModifier
= aKeyCode
.GetModifier();
203 if( KEY_MOD2
== nModifier
)
205 if( KEY_UP
== nKey
|| KEY_DOWN
== nKey
)
207 if(pTopWin
&& pBottomWin
)
209 sal_uInt16 nFirstWinId
= KEY_UP
== nKey
? TOP_WINDOW
: BOTTOM_WINDOW
;
210 sal_uInt16 nSecondWinId
= KEY_UP
== nKey
? BOTTOM_WINDOW
: TOP_WINDOW
;
211 tools::Long nHeight
= GetItemSize( nFirstWinId
);
212 nHeight
-= WIN_STEP_SIZE
;
213 if(nHeight
< WIN_MIN_HEIGHT
)
214 nHeight
= WIN_MIN_HEIGHT
;
215 SetItemSize( nFirstWinId
, nHeight
);
216 SetItemSize( nSecondWinId
, 100 - nHeight
);
220 else if( pKEvt
->GetCharCode() && HandleShortCutKey( *pKEvt
) )
228 bool BibBookContainer::HandleShortCutKey( const KeyEvent
& rKeyEvent
)
233 bRet
= pTopWin
->HandleShortCutKey( rKeyEvent
);
235 if( !bRet
&& pBottomWin
)
236 bRet
= pBottomWin
->HandleShortCutKey( rKeyEvent
);
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */