bump product version to 5.0.4.1
[LibreOffice.git] / extensions / source / bibliography / bibcont.cxx
blob5c75e528b515c05587e00b7f20b52d41db6ca30a
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 BibTabPage::BibTabPage( vcl::Window* pParent, const OString& rID, const OUString& rUIXMLDescription ) :
61 TabPage( pParent, rID, rUIXMLDescription ), BibShortCutHandler( this )
65 using namespace osl;
66 using namespace ::com::sun::star;
67 using namespace ::com::sun::star::uno;
68 using namespace ::com::sun::star::frame;
70 //split window size is a percent value
71 #define WIN_MIN_HEIGHT 10
72 #define WIN_STEP_SIZE 5
74 BibWindowContainer::BibWindowContainer( vcl::Window* pParent, BibShortCutHandler* pChildWin, WinBits nStyle ) :
75 BibWindow( pParent, nStyle ),
76 pChild( pChildWin )
78 if(pChild!=NULL)
80 vcl::Window* pChildWindow = GetChild();
81 pChildWindow->SetParent(this);
82 pChildWindow->Show();
83 pChildWindow->SetPosPixel(Point(0,0));
87 BibWindowContainer::~BibWindowContainer()
89 disposeOnce();
92 void BibWindowContainer::dispose()
94 if( pChild )
96 VclPtr<vcl::Window> pDel = GetChild();
97 pChild = NULL; // prevents GetFocus for child while deleting!
98 pDel.disposeAndClear();
100 vcl::Window::dispose();
103 void BibWindowContainer::Resize()
105 if( pChild )
106 GetChild()->SetSizePixel( GetOutputSizePixel() );
109 void BibWindowContainer::GetFocus()
111 if( pChild )
112 GetChild()->GrabFocus();
115 bool BibWindowContainer::HandleShortCutKey( const KeyEvent& rKeyEvent )
117 return pChild && pChild->HandleShortCutKey( rKeyEvent );
121 BibBookContainer::BibBookContainer(vcl::Window* pParent, WinBits nStyle):
122 BibSplitWindow(pParent,nStyle),
123 pTopWin(NULL),
124 pBottomWin(NULL)
126 pBibMod = OpenBibModul();
127 aIdle.SetIdleHdl(LINK( this, BibBookContainer, SplitHdl));
128 aIdle.SetPriority(SchedulerPriority::LOWEST);
131 BibBookContainer::~BibBookContainer()
133 disposeOnce();
136 void BibBookContainer::dispose()
138 if( xTopFrameRef.is() )
139 xTopFrameRef->dispose();
140 if( xBottomFrameRef.is() )
141 xBottomFrameRef->dispose();
143 if( pTopWin )
145 VclPtr<vcl::Window> pDel = pTopWin;
146 pTopWin = NULL; // prevents GetFocus for child while deleting!
147 pDel.disposeAndClear();
150 if( pBottomWin )
152 VclPtr<vcl::Window> pDel = pBottomWin;
153 pBottomWin = NULL; // prevents GetFocus for child while deleting!
154 pDel.disposeAndClear();
157 CloseBibModul( pBibMod );
158 pTopWin.clear();
159 pBottomWin.clear();
160 BibSplitWindow::dispose();
163 void BibBookContainer::Split()
165 aIdle.Start();
167 IMPL_LINK_NOARG_TYPED( BibBookContainer, SplitHdl, Idle*, void)
169 long nSize= GetItemSize( TOP_WINDOW);
170 BibConfig* pConfig = BibModul::GetConfig();
171 pConfig->setBeamerSize(nSize);
172 nSize = GetItemSize( BOTTOM_WINDOW);
173 pConfig->setViewSize(nSize);
176 void BibBookContainer::createTopFrame( BibShortCutHandler* pWin )
178 if ( xTopFrameRef.is() ) xTopFrameRef->dispose();
180 if(pTopWin)
182 RemoveItem(TOP_WINDOW);
183 pTopWin.disposeAndClear();
185 pTopWin=VclPtr<BibWindowContainer>::Create(this,pWin);
186 pTopWin->Show();
187 BibConfig* pConfig = BibModul::GetConfig();
188 long nSize = pConfig->getBeamerSize();
189 InsertItem(TOP_WINDOW, pTopWin, nSize, 1, 0, SWIB_PERCENTSIZE );
193 void BibBookContainer::createBottomFrame( BibShortCutHandler* pWin )
195 if ( xBottomFrameRef.is() ) xBottomFrameRef->dispose();
197 if(pBottomWin)
199 RemoveItem(BOTTOM_WINDOW);
200 pBottomWin.disposeAndClear();
203 pBottomWin=VclPtr<BibWindowContainer>::Create(this,pWin);
205 BibConfig* pConfig = BibModul::GetConfig();
206 long nSize = pConfig->getViewSize();
207 InsertItem(BOTTOM_WINDOW, pBottomWin, nSize, 1, 0, SWIB_PERCENTSIZE );
211 void BibBookContainer::GetFocus()
213 if( pBottomWin )
214 pBottomWin->GrabFocus();
217 bool BibBookContainer::PreNotify( NotifyEvent& rNEvt )
219 bool nHandled = false;
220 if( MouseNotifyEvent::KEYINPUT == rNEvt.GetType() )
222 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
223 const vcl::KeyCode aKeyCode = pKEvt->GetKeyCode();
224 sal_uInt16 nKey = aKeyCode.GetCode();
225 const sal_uInt16 nModifier = aKeyCode.GetModifier();
227 if( KEY_MOD2 == nModifier )
229 if( KEY_UP == nKey || KEY_DOWN == nKey )
231 if(pTopWin && pBottomWin)
233 sal_uInt16 nFirstWinId = KEY_UP == nKey ? TOP_WINDOW : BOTTOM_WINDOW;
234 sal_uInt16 nSecondWinId = KEY_UP == nKey ? BOTTOM_WINDOW : TOP_WINDOW;
235 long nHeight = GetItemSize( nFirstWinId );
236 nHeight -= WIN_STEP_SIZE;
237 if(nHeight < WIN_MIN_HEIGHT)
238 nHeight = WIN_MIN_HEIGHT;
239 SetItemSize( nFirstWinId, nHeight );
240 SetItemSize( nSecondWinId, 100 - nHeight );
242 nHandled = true;
244 else if( pKEvt->GetCharCode() && HandleShortCutKey( *pKEvt ) )
245 nHandled = true;
249 return nHandled;
252 bool BibBookContainer::HandleShortCutKey( const KeyEvent& rKeyEvent )
254 bool bRet = false;
256 if( pTopWin )
257 bRet = pTopWin->HandleShortCutKey( rKeyEvent );
259 if( !bRet && pBottomWin )
260 bRet = pBottomWin->HandleShortCutKey( rKeyEvent );
262 return bRet;
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */