1*2a97ec55SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2a97ec55SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2a97ec55SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2a97ec55SAndrew Rist  * distributed with this work for additional information
6*2a97ec55SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2a97ec55SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2a97ec55SAndrew Rist  * "License"); you may not use this file except in compliance
9*2a97ec55SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2a97ec55SAndrew Rist  *
11*2a97ec55SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2a97ec55SAndrew Rist  *
13*2a97ec55SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2a97ec55SAndrew Rist  * software distributed under the License is distributed on an
15*2a97ec55SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2a97ec55SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2a97ec55SAndrew Rist  * specific language governing permissions and limitations
18*2a97ec55SAndrew Rist  * under the License.
19*2a97ec55SAndrew Rist  *
20*2a97ec55SAndrew Rist  *************************************************************/
21*2a97ec55SAndrew Rist 
22*2a97ec55SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_extensions.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <osl/mutex.hxx>
28cdf0e10cSrcweir #include <tools/urlobj.hxx>
29cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
30cdf0e10cSrcweir #include <unotools/processfactory.hxx>
31cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
32cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp>
33cdf0e10cSrcweir #include <com/sun/star/awt/XWindowPeer.hpp>
34cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
35cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
36cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
37cdf0e10cSrcweir #include "bibconfig.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include "datman.hxx"
41cdf0e10cSrcweir #include "bibcont.hxx"
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 
~BibShortCutHandler()44cdf0e10cSrcweir BibShortCutHandler::~BibShortCutHandler()
45cdf0e10cSrcweir {
46cdf0e10cSrcweir }
47cdf0e10cSrcweir 
HandleShortCutKey(const KeyEvent &)48cdf0e10cSrcweir sal_Bool BibShortCutHandler::HandleShortCutKey( const KeyEvent& )
49cdf0e10cSrcweir {
50cdf0e10cSrcweir 	return sal_False;
51cdf0e10cSrcweir }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 
BibWindow(Window * pParent,WinBits nStyle)54cdf0e10cSrcweir BibWindow::BibWindow( Window* pParent, WinBits nStyle ) : Window( pParent, nStyle ), BibShortCutHandler( this )
55cdf0e10cSrcweir {
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
~BibWindow()58cdf0e10cSrcweir BibWindow::~BibWindow()
59cdf0e10cSrcweir {
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 
BibSplitWindow(Window * pParent,WinBits nStyle)63cdf0e10cSrcweir BibSplitWindow::BibSplitWindow( Window* pParent, WinBits nStyle ) : SplitWindow( pParent, nStyle ), BibShortCutHandler( this )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
~BibSplitWindow()67cdf0e10cSrcweir BibSplitWindow::~BibSplitWindow()
68cdf0e10cSrcweir {
69cdf0e10cSrcweir }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 
BibTabPage(Window * pParent,const ResId & rResId)72cdf0e10cSrcweir BibTabPage::BibTabPage( Window* pParent, const ResId& rResId ) : TabPage( pParent, rResId ), BibShortCutHandler( this )
73cdf0e10cSrcweir {
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
~BibTabPage()76cdf0e10cSrcweir BibTabPage::~BibTabPage()
77cdf0e10cSrcweir {
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 
81cdf0e10cSrcweir using namespace osl;
82cdf0e10cSrcweir using namespace ::com::sun::star;
83cdf0e10cSrcweir using namespace ::com::sun::star::uno;
84cdf0e10cSrcweir using namespace ::com::sun::star::frame;
85cdf0e10cSrcweir using namespace ::rtl;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir #define C2U(cChar) OUString::createFromAscii(cChar)
88cdf0e10cSrcweir #define PROPERTY_FRAME						1
89cdf0e10cSrcweir //split window size is a percent value
90cdf0e10cSrcweir #define WIN_MIN_HEIGHT 10
91cdf0e10cSrcweir #define WIN_STEP_SIZE 5
92cdf0e10cSrcweir 
BibWindowContainer(Window * pParent,BibShortCutHandler * pChildWin,WinBits nStyle)93cdf0e10cSrcweir BibWindowContainer::BibWindowContainer( Window* pParent, BibShortCutHandler* pChildWin, WinBits nStyle ) :
94cdf0e10cSrcweir 		BibWindow( pParent, nStyle ),
95cdf0e10cSrcweir 		pChild( pChildWin )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir 	if(pChild!=NULL)
98cdf0e10cSrcweir 	{
99cdf0e10cSrcweir 		Window*	pChildWindow = GetChild();
100cdf0e10cSrcweir 		pChildWindow->SetParent(this);
101cdf0e10cSrcweir 		pChildWindow->Show();
102cdf0e10cSrcweir 		pChildWindow->SetPosPixel(Point(0,0));
103cdf0e10cSrcweir 	}
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
~BibWindowContainer()106cdf0e10cSrcweir BibWindowContainer::~BibWindowContainer()
107cdf0e10cSrcweir {
108cdf0e10cSrcweir 	if( pChild )
109cdf0e10cSrcweir 	{
110cdf0e10cSrcweir 		Window* pDel = GetChild();
111cdf0e10cSrcweir 		pChild = NULL;			// prevents GetFocus for child while deleting!
112cdf0e10cSrcweir 		delete pDel;
113cdf0e10cSrcweir 	}
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
Resize()116cdf0e10cSrcweir void BibWindowContainer::Resize()
117cdf0e10cSrcweir {
118cdf0e10cSrcweir 	if( pChild )
119cdf0e10cSrcweir 		GetChild()->SetSizePixel( GetOutputSizePixel() );
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
GetFocus()122cdf0e10cSrcweir void BibWindowContainer::GetFocus()
123cdf0e10cSrcweir {
124cdf0e10cSrcweir 	if( pChild )
125cdf0e10cSrcweir 		GetChild()->GrabFocus();
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
HandleShortCutKey(const KeyEvent & rKeyEvent)128cdf0e10cSrcweir sal_Bool BibWindowContainer::HandleShortCutKey( const KeyEvent& rKeyEvent )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir 	return pChild? pChild->HandleShortCutKey( rKeyEvent ) : sal_False;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 
BibBookContainer(Window * pParent,BibDataManager * pDtMn,WinBits nStyle)134cdf0e10cSrcweir BibBookContainer::BibBookContainer(Window* pParent,BibDataManager* pDtMn, WinBits nStyle):
135cdf0e10cSrcweir 	BibSplitWindow(pParent,nStyle),
136cdf0e10cSrcweir 	pDatMan(pDtMn),
137cdf0e10cSrcweir 	pTopWin(NULL),
138cdf0e10cSrcweir 	pBottomWin(NULL),
139cdf0e10cSrcweir 	bFirstTime(sal_True)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir 	pBibMod = OpenBibModul();
142cdf0e10cSrcweir 	aTimer.SetTimeoutHdl(LINK( this, BibBookContainer, SplitHdl));
143cdf0e10cSrcweir 	aTimer.SetTimeout(400);
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
~BibBookContainer()146cdf0e10cSrcweir BibBookContainer::~BibBookContainer()
147cdf0e10cSrcweir {
148cdf0e10cSrcweir 	if( xTopFrameRef.is() )
149cdf0e10cSrcweir 		xTopFrameRef->dispose();
150cdf0e10cSrcweir 	if( xBottomFrameRef.is() )
151cdf0e10cSrcweir 		xBottomFrameRef->dispose();
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	if( pTopWin )
154cdf0e10cSrcweir 	{
155cdf0e10cSrcweir 		Window* pDel = pTopWin;
156cdf0e10cSrcweir 		pTopWin = NULL;			// prevents GetFocus for child while deleting!
157cdf0e10cSrcweir 		delete pDel;
158cdf0e10cSrcweir 	}
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 	if( pBottomWin )
161cdf0e10cSrcweir 	{
162cdf0e10cSrcweir 		Window* pDel = pBottomWin;
163cdf0e10cSrcweir 		pBottomWin = NULL;		// prevents GetFocus for child while deleting!
164cdf0e10cSrcweir 		delete pDel;
165cdf0e10cSrcweir 	}
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 	CloseBibModul( pBibMod );
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
Split()170cdf0e10cSrcweir void BibBookContainer::Split()
171cdf0e10cSrcweir {
172cdf0e10cSrcweir 	aTimer.Start();
173cdf0e10cSrcweir }
174cdf0e10cSrcweir IMPL_LINK( BibBookContainer, SplitHdl, Timer*,/*pT*/)
175cdf0e10cSrcweir {
176cdf0e10cSrcweir 	long nSize=	GetItemSize( TOP_WINDOW);
177cdf0e10cSrcweir 	BibConfig* pConfig = BibModul::GetConfig();
178cdf0e10cSrcweir 	pConfig->setBeamerSize(nSize);
179cdf0e10cSrcweir 	nSize =	GetItemSize( BOTTOM_WINDOW);
180cdf0e10cSrcweir 	pConfig->setViewSize(nSize);
181cdf0e10cSrcweir 	return 0;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
createTopFrame(BibShortCutHandler * pWin)184cdf0e10cSrcweir void BibBookContainer::createTopFrame( BibShortCutHandler* pWin )
185cdf0e10cSrcweir {
186cdf0e10cSrcweir 	if ( xTopFrameRef.is() ) xTopFrameRef->dispose();
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 	if(pTopWin)
189cdf0e10cSrcweir 	{
190cdf0e10cSrcweir 		RemoveItem(TOP_WINDOW);
191cdf0e10cSrcweir 		delete pTopWin;
192cdf0e10cSrcweir 	}
193cdf0e10cSrcweir 	pTopWin=new BibWindowContainer(this,pWin);
194cdf0e10cSrcweir 	pTopWin->Show();
195cdf0e10cSrcweir 	BibConfig* pConfig = BibModul::GetConfig();
196cdf0e10cSrcweir 	long nSize = pConfig->getBeamerSize();
197cdf0e10cSrcweir 	InsertItem(TOP_WINDOW, pTopWin, nSize, 1, 0, SWIB_PERCENTSIZE  );
198cdf0e10cSrcweir 
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
createBottomFrame(BibShortCutHandler * pWin)201cdf0e10cSrcweir void BibBookContainer::createBottomFrame( BibShortCutHandler* pWin )
202cdf0e10cSrcweir {
203cdf0e10cSrcweir 	if ( xBottomFrameRef.is() ) xBottomFrameRef->dispose();
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 	if(pBottomWin)
206cdf0e10cSrcweir 	{
207cdf0e10cSrcweir 		RemoveItem(BOTTOM_WINDOW);
208cdf0e10cSrcweir 		delete pBottomWin;
209cdf0e10cSrcweir 	}
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 	pBottomWin=new BibWindowContainer(this,pWin);
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 	BibConfig* pConfig = BibModul::GetConfig();
214cdf0e10cSrcweir 	long nSize = pConfig->getViewSize();
215cdf0e10cSrcweir 	InsertItem(BOTTOM_WINDOW, pBottomWin, nSize, 1, 0, SWIB_PERCENTSIZE  );
216cdf0e10cSrcweir 
217cdf0e10cSrcweir }
218cdf0e10cSrcweir 
GetFocus()219cdf0e10cSrcweir void BibBookContainer::GetFocus()
220cdf0e10cSrcweir {
221cdf0e10cSrcweir 	if( pBottomWin )
222cdf0e10cSrcweir 		pBottomWin->GrabFocus();
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
PreNotify(NotifyEvent & rNEvt)225cdf0e10cSrcweir long BibBookContainer::PreNotify( NotifyEvent& rNEvt )
226cdf0e10cSrcweir {
227cdf0e10cSrcweir     long nHandled = 0;
228cdf0e10cSrcweir     if( EVENT_KEYINPUT == rNEvt.GetType()  )
229cdf0e10cSrcweir     {
230cdf0e10cSrcweir         const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
231cdf0e10cSrcweir         const KeyCode aKeyCode = pKEvt->GetKeyCode();
232cdf0e10cSrcweir         sal_uInt16 nKey = aKeyCode.GetCode();
233cdf0e10cSrcweir         const sal_uInt16 nModifier = aKeyCode.GetModifier();
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 		if( KEY_MOD2 == nModifier )
236cdf0e10cSrcweir 		{
237cdf0e10cSrcweir 			if( KEY_UP == nKey || KEY_DOWN == nKey )
238cdf0e10cSrcweir 			{
239cdf0e10cSrcweir 				if(pTopWin && pBottomWin)
240cdf0e10cSrcweir 				{
241cdf0e10cSrcweir 					sal_uInt16 nFirstWinId = KEY_UP == nKey ? TOP_WINDOW : BOTTOM_WINDOW;
242cdf0e10cSrcweir 					sal_uInt16 nSecondWinId = KEY_UP == nKey ? BOTTOM_WINDOW : TOP_WINDOW;
243cdf0e10cSrcweir 					long nHeight = GetItemSize( nFirstWinId );
244cdf0e10cSrcweir 					nHeight -= WIN_STEP_SIZE;
245cdf0e10cSrcweir 					if(nHeight < WIN_MIN_HEIGHT)
246cdf0e10cSrcweir 						nHeight = WIN_MIN_HEIGHT;
247cdf0e10cSrcweir 					SetItemSize( nFirstWinId, nHeight );
248cdf0e10cSrcweir 					SetItemSize( nSecondWinId, 100 - nHeight );
249cdf0e10cSrcweir 				}
250cdf0e10cSrcweir 				nHandled = 1;
251cdf0e10cSrcweir 			}
252cdf0e10cSrcweir 			else if( pKEvt->GetCharCode() && HandleShortCutKey( *pKEvt ) )
253cdf0e10cSrcweir 				nHandled = 1;
254cdf0e10cSrcweir 		}
255cdf0e10cSrcweir     }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     return nHandled;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir 
HandleShortCutKey(const KeyEvent & rKeyEvent)260cdf0e10cSrcweir sal_Bool BibBookContainer::HandleShortCutKey( const KeyEvent& rKeyEvent )
261cdf0e10cSrcweir {
262cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 	if( pTopWin )
265cdf0e10cSrcweir 		bRet = pTopWin->HandleShortCutKey( rKeyEvent );
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 	if( !bRet && pBottomWin )
268cdf0e10cSrcweir 		bRet = pBottomWin->HandleShortCutKey( rKeyEvent );
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 	return bRet;
271cdf0e10cSrcweir }
272