xref: /AOO41X/main/extensions/source/bibliography/bibcont.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 
31 #include <osl/mutex.hxx>
32 #include <tools/urlobj.hxx>
33 #include <cppuhelper/weak.hxx>
34 #include <unotools/processfactory.hxx>
35 #include <toolkit/helper/vclunohelper.hxx>
36 #include <com/sun/star/awt/XWindow.hpp>
37 #include <com/sun/star/awt/XWindowPeer.hpp>
38 #include <com/sun/star/frame/XDispatchProvider.hpp>
39 #include <com/sun/star/frame/FrameSearchFlag.hpp>
40 #include <com/sun/star/util/XURLTransformer.hpp>
41 #include "bibconfig.hxx"
42 
43 
44 #include "datman.hxx"
45 #include "bibcont.hxx"
46 
47 
48 BibShortCutHandler::~BibShortCutHandler()
49 {
50 }
51 
52 sal_Bool BibShortCutHandler::HandleShortCutKey( const KeyEvent& )
53 {
54 	return sal_False;
55 }
56 
57 
58 BibWindow::BibWindow( Window* pParent, WinBits nStyle ) : Window( pParent, nStyle ), BibShortCutHandler( this )
59 {
60 }
61 
62 BibWindow::~BibWindow()
63 {
64 }
65 
66 
67 BibSplitWindow::BibSplitWindow( Window* pParent, WinBits nStyle ) : SplitWindow( pParent, nStyle ), BibShortCutHandler( this )
68 {
69 }
70 
71 BibSplitWindow::~BibSplitWindow()
72 {
73 }
74 
75 
76 BibTabPage::BibTabPage( Window* pParent, const ResId& rResId ) : TabPage( pParent, rResId ), BibShortCutHandler( this )
77 {
78 }
79 
80 BibTabPage::~BibTabPage()
81 {
82 }
83 
84 
85 using namespace osl;
86 using namespace ::com::sun::star;
87 using namespace ::com::sun::star::uno;
88 using namespace ::com::sun::star::frame;
89 using namespace ::rtl;
90 
91 #define C2U(cChar) OUString::createFromAscii(cChar)
92 #define PROPERTY_FRAME						1
93 //split window size is a percent value
94 #define WIN_MIN_HEIGHT 10
95 #define WIN_STEP_SIZE 5
96 
97 BibWindowContainer::BibWindowContainer( Window* pParent, BibShortCutHandler* pChildWin, WinBits nStyle ) :
98 		BibWindow( pParent, nStyle ),
99 		pChild( pChildWin )
100 {
101 	if(pChild!=NULL)
102 	{
103 		Window*	pChildWindow = GetChild();
104 		pChildWindow->SetParent(this);
105 		pChildWindow->Show();
106 		pChildWindow->SetPosPixel(Point(0,0));
107 	}
108 }
109 
110 BibWindowContainer::~BibWindowContainer()
111 {
112 	if( pChild )
113 	{
114 		Window* pDel = GetChild();
115 		pChild = NULL;			// prevents GetFocus for child while deleting!
116 		delete pDel;
117 	}
118 }
119 
120 void BibWindowContainer::Resize()
121 {
122 	if( pChild )
123 		GetChild()->SetSizePixel( GetOutputSizePixel() );
124 }
125 
126 void BibWindowContainer::GetFocus()
127 {
128 	if( pChild )
129 		GetChild()->GrabFocus();
130 }
131 
132 sal_Bool BibWindowContainer::HandleShortCutKey( const KeyEvent& rKeyEvent )
133 {
134 	return pChild? pChild->HandleShortCutKey( rKeyEvent ) : sal_False;
135 }
136 
137 
138 BibBookContainer::BibBookContainer(Window* pParent,BibDataManager* pDtMn, WinBits nStyle):
139 	BibSplitWindow(pParent,nStyle),
140 	pDatMan(pDtMn),
141 	pTopWin(NULL),
142 	pBottomWin(NULL),
143 	bFirstTime(sal_True)
144 {
145 	pBibMod = OpenBibModul();
146 	aTimer.SetTimeoutHdl(LINK( this, BibBookContainer, SplitHdl));
147 	aTimer.SetTimeout(400);
148 }
149 
150 BibBookContainer::~BibBookContainer()
151 {
152 	if( xTopFrameRef.is() )
153 		xTopFrameRef->dispose();
154 	if( xBottomFrameRef.is() )
155 		xBottomFrameRef->dispose();
156 
157 	if( pTopWin )
158 	{
159 		Window* pDel = pTopWin;
160 		pTopWin = NULL;			// prevents GetFocus for child while deleting!
161 		delete pDel;
162 	}
163 
164 	if( pBottomWin )
165 	{
166 		Window* pDel = pBottomWin;
167 		pBottomWin = NULL;		// prevents GetFocus for child while deleting!
168 		delete pDel;
169 	}
170 
171 	CloseBibModul( pBibMod );
172 }
173 
174 void BibBookContainer::Split()
175 {
176 	aTimer.Start();
177 }
178 IMPL_LINK( BibBookContainer, SplitHdl, Timer*,/*pT*/)
179 {
180 	long nSize=	GetItemSize( TOP_WINDOW);
181 	BibConfig* pConfig = BibModul::GetConfig();
182 	pConfig->setBeamerSize(nSize);
183 	nSize =	GetItemSize( BOTTOM_WINDOW);
184 	pConfig->setViewSize(nSize);
185 	return 0;
186 }
187 
188 void BibBookContainer::createTopFrame( BibShortCutHandler* pWin )
189 {
190 	if ( xTopFrameRef.is() ) xTopFrameRef->dispose();
191 
192 	if(pTopWin)
193 	{
194 		RemoveItem(TOP_WINDOW);
195 		delete pTopWin;
196 	}
197 	pTopWin=new BibWindowContainer(this,pWin);
198 	pTopWin->Show();
199 	BibConfig* pConfig = BibModul::GetConfig();
200 	long nSize = pConfig->getBeamerSize();
201 	InsertItem(TOP_WINDOW, pTopWin, nSize, 1, 0, SWIB_PERCENTSIZE  );
202 
203 }
204 
205 void BibBookContainer::createBottomFrame( BibShortCutHandler* pWin )
206 {
207 	if ( xBottomFrameRef.is() ) xBottomFrameRef->dispose();
208 
209 	if(pBottomWin)
210 	{
211 		RemoveItem(BOTTOM_WINDOW);
212 		delete pBottomWin;
213 	}
214 
215 	pBottomWin=new BibWindowContainer(this,pWin);
216 
217 	BibConfig* pConfig = BibModul::GetConfig();
218 	long nSize = pConfig->getViewSize();
219 	InsertItem(BOTTOM_WINDOW, pBottomWin, nSize, 1, 0, SWIB_PERCENTSIZE  );
220 
221 }
222 
223 void BibBookContainer::GetFocus()
224 {
225 	if( pBottomWin )
226 		pBottomWin->GrabFocus();
227 }
228 
229 long BibBookContainer::PreNotify( NotifyEvent& rNEvt )
230 {
231     long nHandled = 0;
232     if( EVENT_KEYINPUT == rNEvt.GetType()  )
233     {
234         const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
235         const KeyCode aKeyCode = pKEvt->GetKeyCode();
236         sal_uInt16 nKey = aKeyCode.GetCode();
237         const sal_uInt16 nModifier = aKeyCode.GetModifier();
238 
239 		if( KEY_MOD2 == nModifier )
240 		{
241 			if( KEY_UP == nKey || KEY_DOWN == nKey )
242 			{
243 				if(pTopWin && pBottomWin)
244 				{
245 					sal_uInt16 nFirstWinId = KEY_UP == nKey ? TOP_WINDOW : BOTTOM_WINDOW;
246 					sal_uInt16 nSecondWinId = KEY_UP == nKey ? BOTTOM_WINDOW : TOP_WINDOW;
247 					long nHeight = GetItemSize( nFirstWinId );
248 					nHeight -= WIN_STEP_SIZE;
249 					if(nHeight < WIN_MIN_HEIGHT)
250 						nHeight = WIN_MIN_HEIGHT;
251 					SetItemSize( nFirstWinId, nHeight );
252 					SetItemSize( nSecondWinId, 100 - nHeight );
253 				}
254 				nHandled = 1;
255 			}
256 			else if( pKEvt->GetCharCode() && HandleShortCutKey( *pKEvt ) )
257 				nHandled = 1;
258 		}
259     }
260 
261     return nHandled;
262 }
263 
264 sal_Bool BibBookContainer::HandleShortCutKey( const KeyEvent& rKeyEvent )
265 {
266 	sal_Bool bRet = sal_False;
267 
268 	if( pTopWin )
269 		bRet = pTopWin->HandleShortCutKey( rKeyEvent );
270 
271 	if( !bRet && pBottomWin )
272 		bRet = pBottomWin->HandleShortCutKey( rKeyEvent );
273 
274 	return bRet;
275 }
276