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