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 #include "svpframe.hxx"
25 #include "svpinst.hxx"
26 #include "svpgdi.hxx"
27
28 #include <basebmp/scanlineformats.hxx>
29 #include <basegfx/vector/b2ivector.hxx>
30
31 using namespace basebmp;
32 using namespace basegfx;
33
34 SvpSalFrame* SvpSalFrame::s_pFocusFrame = NULL;
35
SvpSalFrame(SvpSalInstance * pInstance,SalFrame * pParent,sal_uLong nSalFrameStyle,SystemParentData *)36 SvpSalFrame::SvpSalFrame( SvpSalInstance* pInstance,
37 SalFrame* pParent,
38 sal_uLong nSalFrameStyle,
39 SystemParentData* ) :
40 m_pInstance( pInstance ),
41 m_pParent( static_cast<SvpSalFrame*>(pParent) ),
42 m_nStyle( nSalFrameStyle ),
43 m_bVisible( false ),
44 m_nMinWidth( 0 ),
45 m_nMinHeight( 0 ),
46 m_nMaxWidth( 0 ),
47 m_nMaxHeight( 0 )
48 {
49 m_aSystemChildData.nSize = sizeof( SystemChildData );
50 m_aSystemChildData.pDisplay = NULL;
51 m_aSystemChildData.aWindow = 0;
52 m_aSystemChildData.pSalFrame = this;
53 m_aSystemChildData.pWidget = NULL;
54 m_aSystemChildData.pVisual = NULL;
55 m_aSystemChildData.nDepth = 24;
56 m_aSystemChildData.aColormap = 0;
57 m_aSystemChildData.pAppContext = NULL;
58 m_aSystemChildData.aShellWindow = 0;
59 m_aSystemChildData.pShellWidget = NULL;
60
61 if( m_pParent )
62 m_pParent->m_aChildren.push_back( this );
63
64 if( m_pInstance )
65 m_pInstance->registerFrame( this );
66
67 SetPosSize( 0, 0, 800, 600, SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
68 }
69
~SvpSalFrame()70 SvpSalFrame::~SvpSalFrame()
71 {
72 if( m_pInstance )
73 m_pInstance->deregisterFrame( this );
74
75 std::list<SvpSalFrame*> Children = m_aChildren;
76 for( std::list<SvpSalFrame*>::iterator it = Children.begin();
77 it != Children.end(); ++it )
78 (*it)->SetParent( m_pParent );
79 if( m_pParent )
80 m_pParent->m_aChildren.remove( this );
81
82 if( s_pFocusFrame == this )
83 {
84 s_pFocusFrame = NULL;
85 // call directly here, else an event for a destroyed frame would be dispatched
86 CallCallback( SALEVENT_LOSEFOCUS, NULL );
87 // if the handler has not set a new focus frame
88 // pass focus to another frame, preferably a document style window
89 if( s_pFocusFrame == NULL )
90 {
91 const std::list< SalFrame* >& rFrames( m_pInstance->getFrames() );
92 for( std::list< SalFrame* >::const_iterator it = rFrames.begin(); it != rFrames.end(); ++it )
93 {
94 SvpSalFrame* pFrame = const_cast<SvpSalFrame*>(static_cast<const SvpSalFrame*>(*it));
95 if( pFrame->m_bVisible &&
96 pFrame->m_pParent == NULL &&
97 (pFrame->m_nStyle & (SAL_FRAME_STYLE_MOVEABLE |
98 SAL_FRAME_STYLE_SIZEABLE |
99 SAL_FRAME_STYLE_CLOSEABLE) ) != 0
100 )
101 {
102 pFrame->GetFocus();
103 break;
104 }
105 }
106 }
107 }
108 }
109
GetFocus()110 void SvpSalFrame::GetFocus()
111 {
112 if( (m_nStyle & (SAL_FRAME_STYLE_OWNERDRAWDECORATION | SAL_FRAME_STYLE_FLOAT)) == 0 )
113 {
114 if( s_pFocusFrame )
115 s_pFocusFrame->LoseFocus();
116 s_pFocusFrame = this;
117 m_pInstance->PostEvent( this, NULL, SALEVENT_GETFOCUS );
118 }
119 }
120
LoseFocus()121 void SvpSalFrame::LoseFocus()
122 {
123 if( s_pFocusFrame == this )
124 {
125 m_pInstance->PostEvent( this, NULL, SALEVENT_LOSEFOCUS );
126 s_pFocusFrame = NULL;
127 }
128 }
129
GetGraphics()130 SalGraphics* SvpSalFrame::GetGraphics()
131 {
132 SvpSalGraphics* pGraphics = new SvpSalGraphics();
133 pGraphics->setDevice( m_aFrame );
134 m_aGraphics.push_back( pGraphics );
135 return pGraphics;
136 }
137
ReleaseGraphics(SalGraphics * pGraphics)138 void SvpSalFrame::ReleaseGraphics( SalGraphics* pGraphics )
139 {
140 SvpSalGraphics* pSvpGraphics = dynamic_cast<SvpSalGraphics*>(pGraphics);
141 m_aGraphics.remove( pSvpGraphics );
142 delete pSvpGraphics;
143 }
144
PostEvent(void * pData)145 sal_Bool SvpSalFrame::PostEvent( void* pData )
146 {
147 m_pInstance->PostEvent( this, pData, SALEVENT_USEREVENT );
148 return sal_True;
149 }
150
PostPaint() const151 void SvpSalFrame::PostPaint() const
152 {
153 if( m_bVisible )
154 {
155 SalPaintEvent aPEvt(0, 0, maGeometry.nWidth, maGeometry.nHeight);
156 CallCallback( SALEVENT_PAINT, &aPEvt );
157 }
158 }
159
SetTitle(const XubString &)160 void SvpSalFrame::SetTitle( const XubString& )
161 {
162 }
163
SetIcon(sal_uInt16)164 void SvpSalFrame::SetIcon( sal_uInt16 )
165 {
166 }
167
SetMenu(SalMenu *)168 void SvpSalFrame::SetMenu( SalMenu* )
169 {
170 }
171
DrawMenuBar()172 void SvpSalFrame::DrawMenuBar()
173 {
174 }
175
SetExtendedFrameStyle(SalExtStyle)176 void SvpSalFrame::SetExtendedFrameStyle( SalExtStyle )
177 {
178 }
179
Show(sal_Bool bVisible,sal_Bool bNoActivate)180 void SvpSalFrame::Show( sal_Bool bVisible, sal_Bool bNoActivate )
181 {
182 if( bVisible && ! m_bVisible )
183 {
184 m_bVisible = true;
185 m_pInstance->PostEvent( this, NULL, SALEVENT_RESIZE );
186 if( ! bNoActivate )
187 GetFocus();
188 }
189 else if( ! bVisible && m_bVisible )
190 {
191 m_bVisible = false;
192 m_pInstance->PostEvent( this, NULL, SALEVENT_RESIZE );
193 LoseFocus();
194 }
195 }
196
Enable(sal_Bool)197 void SvpSalFrame::Enable( sal_Bool )
198 {
199 }
200
SetMinClientSize(long nWidth,long nHeight)201 void SvpSalFrame::SetMinClientSize( long nWidth, long nHeight )
202 {
203 m_nMinWidth = nWidth;
204 m_nMinHeight = nHeight;
205 }
206
SetMaxClientSize(long nWidth,long nHeight)207 void SvpSalFrame::SetMaxClientSize( long nWidth, long nHeight )
208 {
209 m_nMaxWidth = nWidth;
210 m_nMaxHeight = nHeight;
211 }
212
SetPosSize(long nX,long nY,long nWidth,long nHeight,sal_uInt16 nFlags)213 void SvpSalFrame::SetPosSize( long nX, long nY, long nWidth, long nHeight, sal_uInt16 nFlags )
214 {
215 if( (nFlags & SAL_FRAME_POSSIZE_X) != 0 )
216 maGeometry.nX = nX;
217 if( (nFlags & SAL_FRAME_POSSIZE_Y) != 0 )
218 maGeometry.nY = nY;
219 if( (nFlags & SAL_FRAME_POSSIZE_WIDTH) != 0 )
220 {
221 maGeometry.nWidth = nWidth;
222 if( m_nMaxWidth > 0 && maGeometry.nWidth > (unsigned int)m_nMaxWidth )
223 maGeometry.nWidth = m_nMaxWidth;
224 if( m_nMinWidth > 0 && maGeometry.nWidth < (unsigned int)m_nMinWidth )
225 maGeometry.nWidth = m_nMinWidth;
226 }
227 if( (nFlags & SAL_FRAME_POSSIZE_HEIGHT) != 0 )
228 {
229 maGeometry.nHeight = nHeight;
230 if( m_nMaxHeight > 0 && maGeometry.nHeight > (unsigned int)m_nMaxHeight )
231 maGeometry.nHeight = m_nMaxHeight;
232 if( m_nMinHeight > 0 && maGeometry.nHeight < (unsigned int)m_nMinHeight )
233 maGeometry.nHeight = m_nMinHeight;
234 }
235 B2IVector aFrameSize( maGeometry.nWidth, maGeometry.nHeight );
236 if( ! m_aFrame.get() || m_aFrame->getSize() != aFrameSize )
237 {
238 if( aFrameSize.getX() == 0 )
239 aFrameSize.setX( 1 );
240 if( aFrameSize.getY() == 0 )
241 aFrameSize.setY( 1 );
242 m_aFrame = createBitmapDevice( aFrameSize, false, SVP_DEFAULT_BITMAP_FORMAT );
243 // update device in existing graphics
244 for( std::list< SvpSalGraphics* >::iterator it = m_aGraphics.begin();
245 it != m_aGraphics.end(); ++it )
246 (*it)->setDevice( m_aFrame );
247 }
248 if( m_bVisible )
249 m_pInstance->PostEvent( this, NULL, SALEVENT_RESIZE );
250 }
251
GetClientSize(long & rWidth,long & rHeight)252 void SvpSalFrame::GetClientSize( long& rWidth, long& rHeight )
253 {
254 if( m_bVisible )
255 {
256 rWidth = maGeometry.nWidth;
257 rHeight = maGeometry.nHeight;
258 }
259 else
260 rWidth = rHeight = 0;
261 }
262
GetWorkArea(Rectangle & rRect)263 void SvpSalFrame::GetWorkArea( Rectangle& rRect )
264 {
265 rRect = Rectangle( Point( 0, 0 ),
266 Size( VIRTUAL_DESKTOP_WIDTH, VIRTUAL_DESKTOP_HEIGHT ) );
267 }
268
GetParent() const269 SalFrame* SvpSalFrame::GetParent() const
270 {
271 return m_pParent;
272 }
273
274 #define _FRAMESTATE_MASK_GEOMETRY \
275 (SAL_FRAMESTATE_MASK_X | SAL_FRAMESTATE_MASK_Y | \
276 SAL_FRAMESTATE_MASK_WIDTH | SAL_FRAMESTATE_MASK_HEIGHT)
277 #define _FRAMESTATE_MASK_MAXIMIZED_GEOMETRY \
278 (SAL_FRAMESTATE_MASK_MAXIMIZED_X | SAL_FRAMESTATE_MASK_MAXIMIZED_Y | \
279 SAL_FRAMESTATE_MASK_MAXIMIZED_WIDTH | SAL_FRAMESTATE_MASK_MAXIMIZED_HEIGHT)
280
SetWindowState(const SalFrameState * pState)281 void SvpSalFrame::SetWindowState( const SalFrameState *pState )
282 {
283 if (pState == NULL)
284 return;
285
286 // Request for position or size change
287 if (pState->mnMask & _FRAMESTATE_MASK_GEOMETRY)
288 {
289 long nX = maGeometry.nX;
290 long nY = maGeometry.nY;
291 long nWidth = maGeometry.nWidth;
292 long nHeight = maGeometry.nHeight;
293
294 // change requested properties
295 if (pState->mnMask & SAL_FRAMESTATE_MASK_X)
296 nX = pState->mnX;
297 if (pState->mnMask & SAL_FRAMESTATE_MASK_Y)
298 nY = pState->mnY;
299 if (pState->mnMask & SAL_FRAMESTATE_MASK_WIDTH)
300 nWidth = pState->mnWidth;
301 if (pState->mnMask & SAL_FRAMESTATE_MASK_HEIGHT)
302 nHeight = pState->mnHeight;
303
304 SetPosSize( nX, nY, nWidth, nHeight,
305 SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y |
306 SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
307 }
308 }
309
GetWindowState(SalFrameState * pState)310 sal_Bool SvpSalFrame::GetWindowState( SalFrameState* pState )
311 {
312 pState->mnState = SAL_FRAMESTATE_NORMAL;
313 pState->mnX = maGeometry.nX;
314 pState->mnY = maGeometry.nY;
315 pState->mnWidth = maGeometry.nWidth;
316 pState->mnHeight = maGeometry.nHeight;
317 pState->mnMask = _FRAMESTATE_MASK_GEOMETRY | SAL_FRAMESTATE_MASK_STATE;
318
319 return sal_True;
320 }
321
ShowFullScreen(sal_Bool,sal_Int32)322 void SvpSalFrame::ShowFullScreen( sal_Bool, sal_Int32 )
323 {
324 SetPosSize( 0, 0, VIRTUAL_DESKTOP_WIDTH, VIRTUAL_DESKTOP_HEIGHT,
325 SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
326 }
327
StartPresentation(sal_Bool)328 void SvpSalFrame::StartPresentation( sal_Bool )
329 {
330 }
331
SetAlwaysOnTop(sal_Bool)332 void SvpSalFrame::SetAlwaysOnTop( sal_Bool )
333 {
334 }
335
ToTop(sal_uInt16)336 void SvpSalFrame::ToTop( sal_uInt16 )
337 {
338 GetFocus();
339 }
340
SetPointer(PointerStyle)341 void SvpSalFrame::SetPointer( PointerStyle )
342 {
343 }
344
CaptureMouse(sal_Bool)345 void SvpSalFrame::CaptureMouse( sal_Bool )
346 {
347 }
348
SetPointerPos(long,long)349 void SvpSalFrame::SetPointerPos( long, long )
350 {
351 }
352
Flush()353 void SvpSalFrame::Flush()
354 {
355 }
356
Sync()357 void SvpSalFrame::Sync()
358 {
359 }
360
SetInputContext(SalInputContext *)361 void SvpSalFrame::SetInputContext( SalInputContext* )
362 {
363 }
364
EndExtTextInput(sal_uInt16)365 void SvpSalFrame::EndExtTextInput( sal_uInt16 )
366 {
367 }
368
GetKeyName(sal_uInt16)369 String SvpSalFrame::GetKeyName( sal_uInt16 )
370 {
371 return String();
372 }
373
GetSymbolKeyName(const XubString &,sal_uInt16)374 String SvpSalFrame::GetSymbolKeyName( const XubString&, sal_uInt16 )
375 {
376 return String();
377 }
378
MapUnicodeToKeyCode(sal_Unicode,LanguageType,KeyCode &)379 sal_Bool SvpSalFrame::MapUnicodeToKeyCode( sal_Unicode, LanguageType, KeyCode& )
380 {
381 return sal_False;
382 }
383
GetInputLanguage()384 LanguageType SvpSalFrame::GetInputLanguage()
385 {
386 return LANGUAGE_DONTKNOW;
387 }
388
SnapShot()389 SalBitmap* SvpSalFrame::SnapShot()
390 {
391 return NULL;
392 }
393
UpdateSettings(AllSettings &)394 void SvpSalFrame::UpdateSettings( AllSettings& )
395 {
396 }
397
Beep(SoundType)398 void SvpSalFrame::Beep( SoundType )
399 {
400 }
401
GetSystemData() const402 const SystemEnvData* SvpSalFrame::GetSystemData() const
403 {
404 return &m_aSystemChildData;
405 }
406
GetPointerState()407 SalFrame::SalPointerState SvpSalFrame::GetPointerState()
408 {
409 SalPointerState aState;
410 aState.mnState = 0;
411 return aState;
412 }
413
SetParent(SalFrame * pNewParent)414 void SvpSalFrame::SetParent( SalFrame* pNewParent )
415 {
416 if( m_pParent )
417 m_pParent->m_aChildren.remove( this );
418 m_pParent = static_cast<SvpSalFrame*>(pNewParent);
419 }
420
SetPluginParent(SystemParentData *)421 bool SvpSalFrame::SetPluginParent( SystemParentData* )
422 {
423 return true;
424 }
425
SetBackgroundBitmap(SalBitmap *)426 void SvpSalFrame::SetBackgroundBitmap( SalBitmap* )
427 {
428 }
429
ResetClipRegion()430 void SvpSalFrame::ResetClipRegion()
431 {
432 }
433
BeginSetClipRegion(sal_uLong)434 void SvpSalFrame::BeginSetClipRegion( sal_uLong )
435 {
436 }
437
UnionClipRegion(long,long,long,long)438 void SvpSalFrame::UnionClipRegion( long, long, long, long )
439 {
440 }
441
EndSetClipRegion()442 void SvpSalFrame::EndSetClipRegion()
443 {
444 }
445
446