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 )
61 using namespace ::com::sun::star
;
62 using namespace ::com::sun::star::uno
;
63 using namespace ::com::sun::star::frame
;
65 //split window size is a percent value
66 #define WIN_MIN_HEIGHT 10
67 #define WIN_STEP_SIZE 5
69 BibWindowContainer::BibWindowContainer( vcl::Window
* pParent
, BibShortCutHandler
* pChildWin
) :
70 BibWindow( pParent
, WB_3DLOOK
),
75 vcl::Window
* pChildWindow
= GetChild();
76 pChildWindow
->SetParent(this);
78 pChildWindow
->SetPosPixel(Point(0,0));
82 BibWindowContainer::~BibWindowContainer()
87 void BibWindowContainer::dispose()
91 VclPtr
<vcl::Window
> pDel
= GetChild();
92 pChild
= nullptr; // prevents GetFocus for child while deleting!
93 pDel
.disposeAndClear();
95 vcl::Window::dispose();
98 void BibWindowContainer::Resize()
101 GetChild()->SetSizePixel( GetOutputSizePixel() );
104 void BibWindowContainer::GetFocus()
107 GetChild()->GrabFocus();
110 bool BibWindowContainer::HandleShortCutKey( const KeyEvent
& rKeyEvent
)
112 return pChild
&& pChild
->HandleShortCutKey( rKeyEvent
);
116 BibBookContainer::BibBookContainer(vcl::Window
* pParent
):
117 BibSplitWindow(pParent
,WB_3DLOOK
),
120 aIdle("extensions BibBookContainer Split Idle")
122 pBibMod
= OpenBibModul();
123 aIdle
.SetInvokeHandler(LINK( this, BibBookContainer
, SplitHdl
));
124 aIdle
.SetPriority(TaskPriority::LOWEST
);
127 BibBookContainer::~BibBookContainer()
132 void BibBookContainer::dispose()
134 if( xTopFrameRef
.is() )
135 xTopFrameRef
->dispose();
136 if( xBottomFrameRef
.is() )
137 xBottomFrameRef
->dispose();
141 VclPtr
<vcl::Window
> pDel
= pTopWin
;
142 pTopWin
= nullptr; // prevents GetFocus for child while deleting!
143 pDel
.disposeAndClear();
148 VclPtr
<vcl::Window
> pDel
= pBottomWin
;
149 pBottomWin
= nullptr; // prevents GetFocus for child while deleting!
150 pDel
.disposeAndClear();
153 CloseBibModul( pBibMod
);
156 BibSplitWindow::dispose();
159 void BibBookContainer::Split()
163 IMPL_LINK_NOARG( BibBookContainer
, SplitHdl
, Timer
*, void)
165 long nSize
= GetItemSize( TOP_WINDOW
);
166 BibConfig
* pConfig
= BibModul::GetConfig();
167 pConfig
->setBeamerSize(nSize
);
168 nSize
= GetItemSize( BOTTOM_WINDOW
);
169 pConfig
->setViewSize(nSize
);
172 void BibBookContainer::createTopFrame( BibShortCutHandler
* pWin
)
174 if ( xTopFrameRef
.is() ) xTopFrameRef
->dispose();
178 RemoveItem(TOP_WINDOW
);
179 pTopWin
.disposeAndClear();
181 pTopWin
=VclPtr
<BibWindowContainer
>::Create(this,pWin
);
183 BibConfig
* pConfig
= BibModul::GetConfig();
184 long nSize
= pConfig
->getBeamerSize();
185 InsertItem(TOP_WINDOW
, pTopWin
, nSize
, 1, 0, SplitWindowItemFlags::PercentSize
);
189 void BibBookContainer::createBottomFrame( BibShortCutHandler
* pWin
)
191 if ( xBottomFrameRef
.is() ) xBottomFrameRef
->dispose();
195 RemoveItem(BOTTOM_WINDOW
);
196 pBottomWin
.disposeAndClear();
199 pBottomWin
=VclPtr
<BibWindowContainer
>::Create(this,pWin
);
201 BibConfig
* pConfig
= BibModul::GetConfig();
202 long nSize
= pConfig
->getViewSize();
203 InsertItem(BOTTOM_WINDOW
, pBottomWin
, nSize
, 1, 0, SplitWindowItemFlags::PercentSize
);
207 void BibBookContainer::GetFocus()
210 pBottomWin
->GrabFocus();
213 bool BibBookContainer::PreNotify( NotifyEvent
& rNEvt
)
215 bool bHandled
= false;
216 if( MouseNotifyEvent::KEYINPUT
== rNEvt
.GetType() )
218 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
219 const vcl::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 bool BibBookContainer::HandleShortCutKey( const KeyEvent
& rKeyEvent
)
253 bRet
= pTopWin
->HandleShortCutKey( rKeyEvent
);
255 if( !bRet
&& pBottomWin
)
256 bRet
= pBottomWin
->HandleShortCutKey( rKeyEvent
);
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */