Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / extensions / source / bibliography / bibcont.cxx
blob8d65c0015b7a7391815028e353ee08b125a30a07
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
29 #include "datman.hxx"
30 #include "bibcont.hxx"
31 #include "bibview.hxx"
34 BibShortCutHandler::~BibShortCutHandler()
38 bool BibShortCutHandler::HandleShortCutKey( const KeyEvent& )
40 return false;
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 ),
66 pChild( pChildWin )
68 if(pChild!=nullptr)
70 vcl::Window* pChildWindow = GetChild();
71 pChildWindow->SetParent(this);
72 pChildWindow->Show();
73 pChildWindow->SetPosPixel(Point(0,0));
77 BibWindowContainer::~BibWindowContainer()
79 disposeOnce();
82 void BibWindowContainer::dispose()
84 if( pChild )
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()
95 if( pChild )
96 GetChild()->SetSizePixel( GetOutputSizePixel() );
99 void BibWindowContainer::GetFocus()
101 if( pChild )
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),
113 pTopWin(nullptr),
114 pBottomWin(nullptr),
115 aIdle("extensions BibBookContainer Split Idle")
117 pBibMod = OpenBibModul();
118 aIdle.SetInvokeHandler(LINK( this, BibBookContainer, SplitHdl));
119 aIdle.SetPriority(TaskPriority::LOWEST);
122 BibBookContainer::~BibBookContainer()
124 disposeOnce();
127 void BibBookContainer::dispose()
129 if( pTopWin )
131 VclPtr<vcl::Window> pDel = pTopWin;
132 pTopWin = nullptr; // prevents GetFocus for child while deleting!
133 pDel.disposeAndClear();
136 if( pBottomWin )
138 VclPtr<vcl::Window> pDel = pBottomWin;
139 pBottomWin = nullptr; // prevents GetFocus for child while deleting!
140 pDel.disposeAndClear();
143 CloseBibModul( pBibMod );
144 pTopWin.clear();
145 pBottomWin.clear();
146 BibSplitWindow::dispose();
149 void BibBookContainer::Split()
151 aIdle.Start();
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 )
164 if(pTopWin)
166 RemoveItem(TOP_WINDOW);
167 pTopWin.disposeAndClear();
169 pTopWin=VclPtr<BibWindowContainer>::Create(this,pWin);
170 pTopWin->Show();
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 )
179 if(pBottomWin)
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()
195 if( pBottomWin )
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 );
224 bHandled = true;
226 else if( pKEvt->GetCharCode() && HandleShortCutKey( *pKEvt ) )
227 bHandled = true;
231 return bHandled;
234 bool BibBookContainer::HandleShortCutKey( const KeyEvent& rKeyEvent )
236 bool bRet = false;
238 if( pTopWin )
239 bRet = pTopWin->HandleShortCutKey( rKeyEvent );
241 if( !bRet && pBottomWin )
242 bRet = pBottomWin->HandleShortCutKey( rKeyEvent );
244 return bRet;
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */