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 <cppuhelper/weak.hxx>
22 #include <vcl/event.hxx>
23 #include <com/sun/star/awt/XWindow.hpp>
24 #include <com/sun/star/awt/XWindowPeer.hpp>
25 #include <com/sun/star/util/XURLTransformer.hpp>
26 #include "bibconfig.hxx"
30 #include "bibcont.hxx"
31 #include "bibview.hxx"
34 BibShortCutHandler::~BibShortCutHandler()
38 bool BibShortCutHandler::HandleShortCutKey( const KeyEvent
& )
44 BibWindow::BibWindow( vcl::Window
* pParent
, WinBits nStyle
) : Window( pParent
, nStyle
), BibShortCutHandler( this )
48 BibWindow::~BibWindow()
53 BibSplitWindow::BibSplitWindow( vcl::Window
* pParent
, WinBits nStyle
) : SplitWindow( pParent
, nStyle
), BibShortCutHandler( this )
57 using namespace ::com::sun::star
;
58 using namespace ::com::sun::star::uno
;
60 //split window size is a percent value
61 #define WIN_MIN_HEIGHT 10
62 #define WIN_STEP_SIZE 5
64 BibWindowContainer::BibWindowContainer( vcl::Window
* pParent
, BibShortCutHandler
* pChildWin
) :
65 BibWindow( pParent
, WB_3DLOOK
),
70 vcl::Window
* pChildWindow
= GetChild();
71 pChildWindow
->SetParent(this);
73 pChildWindow
->SetPosPixel(Point(0,0));
77 BibWindowContainer::~BibWindowContainer()
82 void BibWindowContainer::dispose()
86 VclPtr
<vcl::Window
> pDel
= GetChild();
87 pChild
= nullptr; // prevents GetFocus for child while deleting!
88 pDel
.disposeAndClear();
90 vcl::Window::dispose();
93 void BibWindowContainer::Resize()
96 GetChild()->SetSizePixel( GetOutputSizePixel() );
99 void BibWindowContainer::GetFocus()
102 GetChild()->GrabFocus();
105 bool BibWindowContainer::HandleShortCutKey( const KeyEvent
& rKeyEvent
)
107 return pChild
&& pChild
->HandleShortCutKey( rKeyEvent
);
111 BibBookContainer::BibBookContainer(vcl::Window
* pParent
):
112 BibSplitWindow(pParent
,WB_3DLOOK
),
115 aIdle("extensions BibBookContainer Split Idle")
117 pBibMod
= OpenBibModul();
118 aIdle
.SetInvokeHandler(LINK( this, BibBookContainer
, SplitHdl
));
119 aIdle
.SetPriority(TaskPriority::LOWEST
);
122 BibBookContainer::~BibBookContainer()
127 void BibBookContainer::dispose()
131 VclPtr
<vcl::Window
> pDel
= pTopWin
;
132 pTopWin
= nullptr; // prevents GetFocus for child while deleting!
133 pDel
.disposeAndClear();
138 VclPtr
<vcl::Window
> pDel
= pBottomWin
;
139 pBottomWin
= nullptr; // prevents GetFocus for child while deleting!
140 pDel
.disposeAndClear();
143 CloseBibModul( pBibMod
);
146 BibSplitWindow::dispose();
149 void BibBookContainer::Split()
153 IMPL_LINK_NOARG( BibBookContainer
, SplitHdl
, Timer
*, void)
155 long nSize
= GetItemSize( TOP_WINDOW
);
156 BibConfig
* pConfig
= BibModul::GetConfig();
157 pConfig
->setBeamerSize(nSize
);
158 nSize
= GetItemSize( BOTTOM_WINDOW
);
159 pConfig
->setViewSize(nSize
);
162 void BibBookContainer::createTopFrame( BibShortCutHandler
* pWin
)
166 RemoveItem(TOP_WINDOW
);
167 pTopWin
.disposeAndClear();
169 pTopWin
=VclPtr
<BibWindowContainer
>::Create(this,pWin
);
171 BibConfig
* pConfig
= BibModul::GetConfig();
172 long nSize
= pConfig
->getBeamerSize();
173 InsertItem(TOP_WINDOW
, pTopWin
, nSize
, 1, 0, SplitWindowItemFlags::PercentSize
);
177 void BibBookContainer::createBottomFrame( BibShortCutHandler
* pWin
)
181 RemoveItem(BOTTOM_WINDOW
);
182 pBottomWin
.disposeAndClear();
185 pBottomWin
=VclPtr
<BibWindowContainer
>::Create(this,pWin
);
187 BibConfig
* pConfig
= BibModul::GetConfig();
188 long nSize
= pConfig
->getViewSize();
189 InsertItem(BOTTOM_WINDOW
, pBottomWin
, nSize
, 1, 0, SplitWindowItemFlags::PercentSize
);
193 void BibBookContainer::GetFocus()
196 pBottomWin
->GrabFocus();
199 bool BibBookContainer::PreNotify( NotifyEvent
& rNEvt
)
201 bool bHandled
= false;
202 if( MouseNotifyEvent::KEYINPUT
== rNEvt
.GetType() )
204 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
205 const vcl::KeyCode aKeyCode
= pKEvt
->GetKeyCode();
206 sal_uInt16 nKey
= aKeyCode
.GetCode();
207 const sal_uInt16 nModifier
= aKeyCode
.GetModifier();
209 if( KEY_MOD2
== nModifier
)
211 if( KEY_UP
== nKey
|| KEY_DOWN
== nKey
)
213 if(pTopWin
&& pBottomWin
)
215 sal_uInt16 nFirstWinId
= KEY_UP
== nKey
? TOP_WINDOW
: BOTTOM_WINDOW
;
216 sal_uInt16 nSecondWinId
= KEY_UP
== nKey
? BOTTOM_WINDOW
: TOP_WINDOW
;
217 long nHeight
= GetItemSize( nFirstWinId
);
218 nHeight
-= WIN_STEP_SIZE
;
219 if(nHeight
< WIN_MIN_HEIGHT
)
220 nHeight
= WIN_MIN_HEIGHT
;
221 SetItemSize( nFirstWinId
, nHeight
);
222 SetItemSize( nSecondWinId
, 100 - nHeight
);
226 else if( pKEvt
->GetCharCode() && HandleShortCutKey( *pKEvt
) )
234 bool BibBookContainer::HandleShortCutKey( const KeyEvent
& rKeyEvent
)
239 bRet
= pTopWin
->HandleShortCutKey( rKeyEvent
);
241 if( !bRet
&& pBottomWin
)
242 bRet
= pBottomWin
->HandleShortCutKey( rKeyEvent
);
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */