bump product version to 4.1.6.2
[LibreOffice.git] / extensions / source / bibliography / bibcont.cxx
blob123c146d51e0a7740d56bf7351d81af2a939d145
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"
36 BibShortCutHandler::~BibShortCutHandler()
40 sal_Bool BibShortCutHandler::HandleShortCutKey( const KeyEvent& )
42 return sal_False;
46 BibWindow::BibWindow( Window* pParent, WinBits nStyle ) : Window( pParent, nStyle ), BibShortCutHandler( this )
50 BibWindow::~BibWindow()
55 BibSplitWindow::BibSplitWindow( Window* pParent, WinBits nStyle ) : SplitWindow( pParent, nStyle ), BibShortCutHandler( this )
59 BibSplitWindow::~BibSplitWindow()
64 BibTabPage::BibTabPage( Window* pParent, const ResId& rResId ) : TabPage( pParent, rResId ), BibShortCutHandler( this )
68 BibTabPage::~BibTabPage()
73 using namespace osl;
74 using namespace ::com::sun::star;
75 using namespace ::com::sun::star::uno;
76 using namespace ::com::sun::star::frame;
77 using namespace ::rtl;
79 //split window size is a percent value
80 #define WIN_MIN_HEIGHT 10
81 #define WIN_STEP_SIZE 5
83 BibWindowContainer::BibWindowContainer( Window* pParent, BibShortCutHandler* pChildWin, WinBits nStyle ) :
84 BibWindow( pParent, nStyle ),
85 pChild( pChildWin )
87 if(pChild!=NULL)
89 Window* pChildWindow = GetChild();
90 pChildWindow->SetParent(this);
91 pChildWindow->Show();
92 pChildWindow->SetPosPixel(Point(0,0));
96 BibWindowContainer::~BibWindowContainer()
98 if( pChild )
100 Window* pDel = GetChild();
101 pChild = NULL; // prevents GetFocus for child while deleting!
102 delete pDel;
106 void BibWindowContainer::Resize()
108 if( pChild )
109 GetChild()->SetSizePixel( GetOutputSizePixel() );
112 void BibWindowContainer::GetFocus()
114 if( pChild )
115 GetChild()->GrabFocus();
118 sal_Bool BibWindowContainer::HandleShortCutKey( const KeyEvent& rKeyEvent )
120 return pChild? pChild->HandleShortCutKey( rKeyEvent ) : sal_False;
124 BibBookContainer::BibBookContainer(Window* pParent, WinBits nStyle):
125 BibSplitWindow(pParent,nStyle),
126 pTopWin(NULL),
127 pBottomWin(NULL)
129 pBibMod = OpenBibModul();
130 aTimer.SetTimeoutHdl(LINK( this, BibBookContainer, SplitHdl));
131 aTimer.SetTimeout(400);
134 BibBookContainer::~BibBookContainer()
136 if( xTopFrameRef.is() )
137 xTopFrameRef->dispose();
138 if( xBottomFrameRef.is() )
139 xBottomFrameRef->dispose();
141 if( pTopWin )
143 Window* pDel = pTopWin;
144 pTopWin = NULL; // prevents GetFocus for child while deleting!
145 delete pDel;
148 if( pBottomWin )
150 Window* pDel = pBottomWin;
151 pBottomWin = NULL; // prevents GetFocus for child while deleting!
152 delete pDel;
155 CloseBibModul( pBibMod );
158 void BibBookContainer::Split()
160 aTimer.Start();
162 IMPL_LINK( BibBookContainer, SplitHdl, Timer*,/*pT*/)
164 long nSize= GetItemSize( TOP_WINDOW);
165 BibConfig* pConfig = BibModul::GetConfig();
166 pConfig->setBeamerSize(nSize);
167 nSize = GetItemSize( BOTTOM_WINDOW);
168 pConfig->setViewSize(nSize);
169 return 0;
172 void BibBookContainer::createTopFrame( BibShortCutHandler* pWin )
174 if ( xTopFrameRef.is() ) xTopFrameRef->dispose();
176 if(pTopWin)
178 RemoveItem(TOP_WINDOW);
179 delete pTopWin;
181 pTopWin=new BibWindowContainer(this,pWin);
182 pTopWin->Show();
183 BibConfig* pConfig = BibModul::GetConfig();
184 long nSize = pConfig->getBeamerSize();
185 InsertItem(TOP_WINDOW, pTopWin, nSize, 1, 0, SWIB_PERCENTSIZE );
189 void BibBookContainer::createBottomFrame( BibShortCutHandler* pWin )
191 if ( xBottomFrameRef.is() ) xBottomFrameRef->dispose();
193 if(pBottomWin)
195 RemoveItem(BOTTOM_WINDOW);
196 delete pBottomWin;
199 pBottomWin=new BibWindowContainer(this,pWin);
201 BibConfig* pConfig = BibModul::GetConfig();
202 long nSize = pConfig->getViewSize();
203 InsertItem(BOTTOM_WINDOW, pBottomWin, nSize, 1, 0, SWIB_PERCENTSIZE );
207 void BibBookContainer::GetFocus()
209 if( pBottomWin )
210 pBottomWin->GrabFocus();
213 long BibBookContainer::PreNotify( NotifyEvent& rNEvt )
215 long nHandled = 0;
216 if( EVENT_KEYINPUT == rNEvt.GetType() )
218 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
219 const 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 nHandled = 1;
240 else if( pKEvt->GetCharCode() && HandleShortCutKey( *pKEvt ) )
241 nHandled = 1;
245 return nHandled;
248 sal_Bool BibBookContainer::HandleShortCutKey( const KeyEvent& rKeyEvent )
250 sal_Bool bRet = sal_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: */