Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / extensions / source / bibliography / bibcont.cxx
blobcf0c2625c7c2e01c082c7b4335af378e84ac704f
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 <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"
32 #include "datman.hxx"
33 #include "bibcont.hxx"
34 #include "bibview.hxx"
37 BibShortCutHandler::~BibShortCutHandler()
41 bool BibShortCutHandler::HandleShortCutKey( const KeyEvent& )
43 return false;
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 )
60 using namespace osl;
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 ),
71 pChild( pChildWin )
73 if(pChild!=nullptr)
75 vcl::Window* pChildWindow = GetChild();
76 pChildWindow->SetParent(this);
77 pChildWindow->Show();
78 pChildWindow->SetPosPixel(Point(0,0));
82 BibWindowContainer::~BibWindowContainer()
84 disposeOnce();
87 void BibWindowContainer::dispose()
89 if( pChild )
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()
100 if( pChild )
101 GetChild()->SetSizePixel( GetOutputSizePixel() );
104 void BibWindowContainer::GetFocus()
106 if( pChild )
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),
118 pTopWin(nullptr),
119 pBottomWin(nullptr),
120 aIdle("extensions BibBookContainer Split Idle")
122 pBibMod = OpenBibModul();
123 aIdle.SetInvokeHandler(LINK( this, BibBookContainer, SplitHdl));
124 aIdle.SetPriority(TaskPriority::LOWEST);
127 BibBookContainer::~BibBookContainer()
129 disposeOnce();
132 void BibBookContainer::dispose()
134 if( xTopFrameRef.is() )
135 xTopFrameRef->dispose();
136 if( xBottomFrameRef.is() )
137 xBottomFrameRef->dispose();
139 if( pTopWin )
141 VclPtr<vcl::Window> pDel = pTopWin;
142 pTopWin = nullptr; // prevents GetFocus for child while deleting!
143 pDel.disposeAndClear();
146 if( pBottomWin )
148 VclPtr<vcl::Window> pDel = pBottomWin;
149 pBottomWin = nullptr; // prevents GetFocus for child while deleting!
150 pDel.disposeAndClear();
153 CloseBibModul( pBibMod );
154 pTopWin.clear();
155 pBottomWin.clear();
156 BibSplitWindow::dispose();
159 void BibBookContainer::Split()
161 aIdle.Start();
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();
176 if(pTopWin)
178 RemoveItem(TOP_WINDOW);
179 pTopWin.disposeAndClear();
181 pTopWin=VclPtr<BibWindowContainer>::Create(this,pWin);
182 pTopWin->Show();
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();
193 if(pBottomWin)
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()
209 if( pBottomWin )
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 );
238 bHandled = true;
240 else if( pKEvt->GetCharCode() && HandleShortCutKey( *pKEvt ) )
241 bHandled = true;
245 return bHandled;
248 bool BibBookContainer::HandleShortCutKey( const KeyEvent& rKeyEvent )
250 bool bRet = false;
252 if( pTopWin )
253 bRet = pTopWin->HandleShortCutKey( rKeyEvent );
255 if( !bRet && pBottomWin )
256 bRet = pBottomWin->HandleShortCutKey( rKeyEvent );
258 return bRet;
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */