Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <signal.h>
31 : : #include <string.h>
32 : : #include <stdio.h>
33 : : #include <stdlib.h>
34 : : #include <unistd.h>
35 : :
36 : : #include "tools/debug.hxx"
37 : :
38 : : #include "sal/alloca.h"
39 : :
40 : : #include "vcl/floatwin.hxx"
41 : : #include "vcl/svapp.hxx"
42 : : #include "vcl/keycodes.hxx"
43 : : #include "vcl/printerinfomanager.hxx"
44 : : #include "vcl/settings.hxx"
45 : :
46 : : #include <tools/prex.h>
47 : : #include <X11/Xatom.h>
48 : : #include <X11/keysym.h>
49 : : #include "FWS.hxx"
50 : : #include <X11/extensions/shape.h>
51 : : #if !defined(SOLARIS) && !defined(AIX)
52 : : #include <X11/extensions/dpms.h>
53 : : #endif
54 : : #include <tools/postx.h>
55 : :
56 : : #include "unx/salunx.h"
57 : : #include "unx/saldata.hxx"
58 : : #include "unx/saldisp.hxx"
59 : : #include "unx/salgdi.h"
60 : : #include "unx/salframe.h"
61 : : #include "unx/soicon.hxx"
62 : : #include "unx/sm.hxx"
63 : : #include "unx/wmadaptor.hxx"
64 : : #include "generic/genprn.h"
65 : : #include "unx/salbmp.h"
66 : : #include "unx/i18n_ic.hxx"
67 : : #include "unx/i18n_keysym.hxx"
68 : : #include "unx/i18n_status.hxx"
69 : : #include <unx/x11/xlimits.hxx>
70 : :
71 : : #include "generic/gensys.h"
72 : : #include "sallayout.hxx"
73 : :
74 : : #include <sal/macros.h>
75 : : #include <com/sun/star/uno/Exception.hpp>
76 : :
77 : : #include <algorithm>
78 : :
79 : : #ifndef Button6
80 : : # define Button6 6
81 : : #endif
82 : : #ifndef Button7
83 : : # define Button7 7
84 : : #endif
85 : :
86 : : using namespace vcl_sal;
87 : : using namespace vcl;
88 : :
89 : : // -=-= #defines -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
90 : : #define CLIENT_EVENTS StructureNotifyMask \
91 : : | SubstructureNotifyMask \
92 : : | KeyPressMask \
93 : : | KeyReleaseMask \
94 : : | ButtonPressMask \
95 : : | ButtonReleaseMask \
96 : : | PointerMotionMask \
97 : : | EnterWindowMask \
98 : : | LeaveWindowMask \
99 : : | FocusChangeMask \
100 : : | ExposureMask \
101 : : | VisibilityChangeMask \
102 : : | PropertyChangeMask \
103 : : | ColormapChangeMask
104 : :
105 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
106 : :
107 : : static XLIB_Window hPresentationWindow = None, hPresFocusWindow = None;
108 : 0 : static ::std::list< XLIB_Window > aPresentationReparentList;
109 : : static int nVisibleFloats = 0;
110 : :
111 : : // -=-= C++ statics =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
112 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
113 : 0 : static void doReparentPresentationDialogues( SalDisplay* pDisplay )
114 : : {
115 : 0 : GetGenericData()->ErrorTrapPush();
116 : 0 : while( aPresentationReparentList.begin() != aPresentationReparentList.end() )
117 : : {
118 : : int x, y;
119 : : XLIB_Window aRoot, aChild;
120 : : unsigned int w, h, bw, d;
121 : : XGetGeometry( pDisplay->GetDisplay(),
122 : 0 : aPresentationReparentList.front(),
123 : : &aRoot,
124 : 0 : &x, &y, &w, &h, &bw, &d );
125 : : XTranslateCoordinates( pDisplay->GetDisplay(),
126 : : hPresentationWindow,
127 : : aRoot,
128 : : x, y,
129 : : &x, &y,
130 : 0 : &aChild );
131 : : XReparentWindow( pDisplay->GetDisplay(),
132 : 0 : aPresentationReparentList.front(),
133 : : aRoot,
134 : 0 : x, y );
135 : 0 : aPresentationReparentList.pop_front();
136 : : }
137 : 0 : if( hPresFocusWindow )
138 : 0 : XSetInputFocus( pDisplay->GetDisplay(), hPresFocusWindow, PointerRoot, CurrentTime );
139 : 0 : XSync( pDisplay->GetDisplay(), False );
140 : 0 : GetGenericData()->ErrorTrapPop();
141 : 0 : }
142 : :
143 : : // -=-= SalFrame / X11SalFrame =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
144 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
145 : :
146 : 0 : bool X11SalFrame::IsOverrideRedirect() const
147 : : {
148 : : return
149 : 0 : ((nStyle_ & SAL_FRAME_STYLE_INTRO) && !pDisplay_->getWMAdaptor()->supportsSplash())
150 : : ||
151 : 0 : (!( nStyle_ & ~SAL_FRAME_STYLE_DEFAULT ) && !pDisplay_->getWMAdaptor()->supportsFullScreen())
152 : : ;
153 : : }
154 : :
155 : 0 : bool X11SalFrame::IsFloatGrabWindow() const
156 : : {
157 : 0 : static const char* pDisableGrab = getenv( "SAL_DISABLE_FLOATGRAB" );
158 : :
159 : : return
160 : 0 : ( ( !pDisableGrab || !*pDisableGrab ) &&
161 : : (
162 : : (nStyle_ & SAL_FRAME_STYLE_FLOAT) &&
163 : 0 : ! (nStyle_ & SAL_FRAME_STYLE_TOOLTIP) &&
164 : 0 : ! (nStyle_ & SAL_FRAME_STYLE_OWNERDRAWDECORATION)
165 : : )
166 : 0 : );
167 : : }
168 : :
169 : 0 : void X11SalFrame::setXEmbedInfo()
170 : : {
171 : 0 : if( m_bXEmbed )
172 : : {
173 : : long aInfo[2];
174 : 0 : aInfo[0] = 1; // XEMBED protocol version
175 : 0 : aInfo[1] = (bMapped_ ? 1 : 0); // XEMBED_MAPPED
176 : : XChangeProperty( pDisplay_->GetDisplay(),
177 : : mhWindow,
178 : : pDisplay_->getWMAdaptor()->getAtom( WMAdaptor::XEMBED_INFO ),
179 : : pDisplay_->getWMAdaptor()->getAtom( WMAdaptor::XEMBED_INFO ),
180 : : 32,
181 : : PropModeReplace,
182 : : reinterpret_cast<unsigned char*>(aInfo),
183 : 0 : SAL_N_ELEMENTS(aInfo) );
184 : : }
185 : 0 : }
186 : :
187 : 0 : void X11SalFrame::askForXEmbedFocus( sal_Int32 i_nTimeCode )
188 : : {
189 : : XEvent aEvent;
190 : :
191 : 0 : memset( &aEvent, 0, sizeof(aEvent) );
192 : 0 : aEvent.xclient.window = mhForeignParent;
193 : 0 : aEvent.xclient.type = ClientMessage;
194 : 0 : aEvent.xclient.message_type = pDisplay_->getWMAdaptor()->getAtom( WMAdaptor::XEMBED );
195 : 0 : aEvent.xclient.format = 32;
196 : 0 : aEvent.xclient.data.l[0] = i_nTimeCode ? i_nTimeCode : CurrentTime;
197 : 0 : aEvent.xclient.data.l[1] = 3; // XEMBED_REQUEST_FOCUS
198 : 0 : aEvent.xclient.data.l[2] = 0;
199 : 0 : aEvent.xclient.data.l[3] = 0;
200 : 0 : aEvent.xclient.data.l[4] = 0;
201 : :
202 : 0 : GetGenericData()->ErrorTrapPush();
203 : : XSendEvent( pDisplay_->GetDisplay(),
204 : : mhForeignParent,
205 : 0 : False, NoEventMask, &aEvent );
206 : 0 : XSync( pDisplay_->GetDisplay(), False );
207 : 0 : GetGenericData()->ErrorTrapPop();
208 : 0 : }
209 : :
210 : :
211 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
212 : :
213 : 0 : void X11SalFrame::Init( sal_uLong nSalFrameStyle, SalX11Screen nXScreen, SystemParentData* pParentData, bool bUseGeometry )
214 : : {
215 : 0 : if( nXScreen.getXScreen() >= GetDisplay()->GetXScreenCount() )
216 : 0 : nXScreen = GetDisplay()->GetDefaultXScreen();
217 : 0 : if( mpParent )
218 : 0 : nXScreen = mpParent->m_nXScreen;
219 : :
220 : 0 : m_nXScreen = nXScreen;
221 : 0 : nStyle_ = nSalFrameStyle;
222 : : XWMHints Hints;
223 : 0 : Hints.flags = InputHint;
224 : 0 : Hints.input = (nSalFrameStyle & SAL_FRAME_STYLE_OWNERDRAWDECORATION) ? False : True;
225 : :
226 : 0 : int x = 0, y = 0;
227 : 0 : unsigned int w = 500, h = 500;
228 : : XSetWindowAttributes Attributes;
229 : :
230 : : int nAttrMask = CWBorderPixel
231 : : | CWBackPixmap
232 : : | CWColormap
233 : : | CWOverrideRedirect
234 : 0 : | CWEventMask
235 : : ;
236 : 0 : Attributes.border_pixel = 0;
237 : 0 : Attributes.background_pixmap = None;
238 : 0 : Attributes.colormap = GetDisplay()->GetColormap( m_nXScreen ).GetXColormap();
239 : 0 : Attributes.override_redirect = False;
240 : 0 : Attributes.event_mask = CLIENT_EVENTS;
241 : :
242 : 0 : const SalVisual& rVis = GetDisplay()->GetVisual( m_nXScreen );
243 : 0 : XLIB_Window aFrameParent = pParentData ? pParentData->aWindow : GetDisplay()->GetRootWindow( m_nXScreen );
244 : 0 : XLIB_Window aClientLeader = None;
245 : :
246 : 0 : if( bUseGeometry )
247 : : {
248 : 0 : x = maGeometry.nX;
249 : 0 : y = maGeometry.nY;
250 : 0 : w = maGeometry.nWidth;
251 : 0 : h = maGeometry.nHeight;
252 : : }
253 : :
254 : 0 : if( (nSalFrameStyle & SAL_FRAME_STYLE_FLOAT) &&
255 : 0 : ! (nSalFrameStyle & SAL_FRAME_STYLE_OWNERDRAWDECORATION)
256 : : )
257 : : {
258 : 0 : if( nShowState_ == SHOWSTATE_UNKNOWN )
259 : : {
260 : 0 : w = 10;
261 : 0 : h = 10;
262 : : }
263 : 0 : Attributes.override_redirect = True;
264 : : }
265 : 0 : else if( (nSalFrameStyle & SAL_FRAME_STYLE_SYSTEMCHILD ) )
266 : : {
267 : : DBG_ASSERT( mpParent, "SAL_FRAME_STYLE_SYSTEMCHILD window without parent" );
268 : 0 : if( mpParent )
269 : : {
270 : 0 : aFrameParent = mpParent->mhWindow;
271 : : // FIXME: since with SAL_FRAME_STYLE_SYSTEMCHILD
272 : : // multiple X11SalFrame objects can have the same shell window
273 : : // dispatching events in saldisp.cxx is unclear (the first frame)
274 : : // wins. HTH this correctly is unclear yet
275 : : // for the time being, treat set the shell window to own window
276 : : // like for a normal frame
277 : : // mhShellWindow = mpParent->GetShellWindow();
278 : : }
279 : : }
280 : 0 : else if( pParentData )
281 : : {
282 : : // plugin parent may be killed unexpectedly by plugging
283 : : // process; start permanantly ignoring X errors ...
284 : 0 : GetGenericData()->ErrorTrapPush();
285 : :
286 : 0 : nStyle_ |= SAL_FRAME_STYLE_PLUG;
287 : 0 : Attributes.override_redirect = True;
288 : 0 : if( pParentData->nSize >= sizeof(SystemParentData) )
289 : 0 : m_bXEmbed = pParentData->bXEmbedSupport;
290 : :
291 : : int x_ret, y_ret;
292 : : unsigned int bw, d;
293 : : XLIB_Window aRoot, aParent;
294 : :
295 : : XGetGeometry( GetXDisplay(), pParentData->aWindow,
296 : 0 : &aRoot, &x_ret, &y_ret, &w, &h, &bw, &d );
297 : 0 : mhForeignParent = pParentData->aWindow;
298 : :
299 : 0 : mhShellWindow = aParent = mhForeignParent;
300 : : XLIB_Window* pChildren;
301 : : unsigned int nChildren;
302 : 0 : bool bBreak = false;
303 : 0 : do
304 : : {
305 : : XQueryTree( GetDisplay()->GetDisplay(), mhShellWindow,
306 : 0 : &aRoot, &aParent, &pChildren, &nChildren );
307 : 0 : XFree( pChildren );
308 : 0 : if( aParent != aRoot )
309 : 0 : mhShellWindow = aParent;
310 : 0 : int nCount = 0;
311 : : Atom* pProps = XListProperties( GetDisplay()->GetDisplay(),
312 : : mhShellWindow,
313 : 0 : &nCount );
314 : 0 : for( int i = 0; i < nCount && ! bBreak; ++i )
315 : 0 : bBreak = (pProps[i] == XA_WM_HINTS);
316 : 0 : if( pProps )
317 : 0 : XFree( pProps );
318 : 0 : } while( aParent != aRoot && ! bBreak );
319 : :
320 : : // check if this is really one of our own frames
321 : : // do not change the input mask in that case
322 : 0 : const std::list< SalFrame* >& rFrames = GetDisplay()->getFrames();
323 : 0 : std::list< SalFrame* >::const_iterator it = rFrames.begin();
324 : 0 : while( it != rFrames.end() && mhForeignParent != static_cast<const X11SalFrame*>(*it)->GetWindow() )
325 : 0 : ++it;
326 : :
327 : 0 : if( it == rFrames.end() )
328 : : {
329 : 0 : XSelectInput( GetDisplay()->GetDisplay(), mhForeignParent, StructureNotifyMask | FocusChangeMask );
330 : 0 : XSelectInput( GetDisplay()->GetDisplay(), mhShellWindow, StructureNotifyMask | FocusChangeMask );
331 : : }
332 : : }
333 : : else
334 : : {
335 : 0 : if( ! bUseGeometry )
336 : : {
337 : 0 : Size aScreenSize( GetDisplay()->getDataForScreen( m_nXScreen ).m_aSize );
338 : 0 : w = aScreenSize.Width();
339 : 0 : h = aScreenSize.Height();
340 : 0 : if( nSalFrameStyle & SAL_FRAME_STYLE_SIZEABLE &&
341 : : nSalFrameStyle & SAL_FRAME_STYLE_MOVEABLE )
342 : : {
343 : : // fill in holy default values brought to us by product management
344 : 0 : if( aScreenSize.Width() >= 800 )
345 : 0 : w = 785;
346 : 0 : if( aScreenSize.Width() >= 1024 )
347 : 0 : w = 920;
348 : 0 : if( aScreenSize.Width() >= 1280 )
349 : 0 : w = 1050;
350 : :
351 : 0 : if( aScreenSize.Height() >= 600 )
352 : 0 : h = 550;
353 : 0 : if( aScreenSize.Height() >= 768 )
354 : 0 : h = 630;
355 : 0 : if( aScreenSize.Height() >= 1024 )
356 : 0 : h = 875;
357 : : }
358 : 0 : if( ! mpParent )
359 : : {
360 : : // find the last document window (if any)
361 : 0 : const X11SalFrame* pFrame = NULL;
362 : 0 : const std::list< SalFrame* >& rFrames = GetDisplay()->getFrames();
363 : 0 : std::list< SalFrame* >::const_iterator it = rFrames.begin();
364 : 0 : while( it != rFrames.end() )
365 : : {
366 : 0 : pFrame = static_cast< const X11SalFrame* >(*it);
367 : 0 : if( ! ( pFrame->mpParent
368 : : || pFrame->mbFullScreen
369 : 0 : || ! ( pFrame->nStyle_ & SAL_FRAME_STYLE_SIZEABLE )
370 : 0 : || ! pFrame->GetUnmirroredGeometry().nWidth
371 : 0 : || ! pFrame->GetUnmirroredGeometry().nHeight
372 : 0 : )
373 : : )
374 : 0 : break;
375 : 0 : ++it;
376 : : }
377 : :
378 : 0 : if( it != rFrames.end() )
379 : : {
380 : : // set a document position and size
381 : : // the first frame gets positioned by the window manager
382 : 0 : const SalFrameGeometry& rGeom( pFrame->GetUnmirroredGeometry() );
383 : 0 : x = rGeom.nX;
384 : 0 : y = rGeom.nY;
385 : 0 : if( x+(int)w+40 <= (int)aScreenSize.Width() &&
386 : 0 : y+(int)h+40 <= (int)aScreenSize.Height()
387 : : )
388 : : {
389 : 0 : y += 40;
390 : 0 : x += 40;
391 : : }
392 : : else
393 : : {
394 : 0 : x = 10; // leave some space for decoration
395 : 0 : y = 20;
396 : : }
397 : : }
398 : 0 : else if( GetDisplay()->IsXinerama() )
399 : : {
400 : : // place frame on same screen as mouse pointer
401 : : XLIB_Window aRoot, aChild;
402 : 0 : int root_x = 0, root_y = 0, lx, ly;
403 : : unsigned int mask;
404 : : XQueryPointer( GetXDisplay(),
405 : : GetDisplay()->GetRootWindow( m_nXScreen ),
406 : : &aRoot, &aChild,
407 : 0 : &root_x, &root_y, &lx, &ly, &mask );
408 : 0 : const std::vector< Rectangle >& rScreens = GetDisplay()->GetXineramaScreens();
409 : 0 : for( unsigned int i = 0; i < rScreens.size(); i++ )
410 : 0 : if( rScreens[i].IsInside( Point( root_x, root_y ) ) )
411 : : {
412 : 0 : x = rScreens[i].Left();
413 : 0 : y = rScreens[i].Top();
414 : 0 : break;
415 : : }
416 : : }
417 : : }
418 : : }
419 : 0 : Attributes.win_gravity = pDisplay_->getWMAdaptor()->getInitWinGravity();
420 : 0 : nAttrMask |= CWWinGravity;
421 : 0 : if( mpParent )
422 : : {
423 : 0 : Attributes.save_under = True;
424 : 0 : nAttrMask |= CWSaveUnder;
425 : : }
426 : 0 : if( IsOverrideRedirect() )
427 : 0 : Attributes.override_redirect = True;
428 : : // default icon
429 : 0 : if( (nStyle_ & SAL_FRAME_STYLE_INTRO) == 0 )
430 : : {
431 : 0 : bool bOk=false;
432 : : try
433 : : {
434 : : bOk=SelectAppIconPixmap( pDisplay_, m_nXScreen,
435 : : mnIconID != 1 ? mnIconID :
436 : : (mpParent ? mpParent->mnIconID : 1), 32,
437 : 0 : Hints.icon_pixmap, Hints.icon_mask );
438 : : }
439 : 0 : catch( com::sun::star::uno::Exception& )
440 : : {
441 : : // can happen - no ucb during early startup
442 : : }
443 : 0 : if( bOk )
444 : : {
445 : 0 : Hints.flags |= IconPixmapHint;
446 : 0 : if( Hints.icon_mask )
447 : 0 : Hints.flags |= IconMaskHint;
448 : : }
449 : : }
450 : :
451 : : // find the top level frame of the transience hierarchy
452 : 0 : X11SalFrame* pFrame = this;
453 : 0 : while( pFrame->mpParent )
454 : 0 : pFrame = pFrame->mpParent;
455 : 0 : if( (pFrame->nStyle_ & SAL_FRAME_STYLE_PLUG ) )
456 : : {
457 : : // if the top level window is a plugin window,
458 : : // then we should place us in the same window group as
459 : : // the parent application (or none if there is no window group
460 : : // hint in the parent).
461 : 0 : if( pFrame->GetShellWindow() )
462 : : {
463 : : XWMHints* pWMHints = XGetWMHints( pDisplay_->GetDisplay(),
464 : 0 : pFrame->GetShellWindow() );
465 : 0 : if( pWMHints )
466 : : {
467 : 0 : if( (pWMHints->flags & WindowGroupHint) )
468 : : {
469 : 0 : Hints.flags |= WindowGroupHint;
470 : 0 : Hints.window_group = pWMHints->window_group;
471 : : }
472 : 0 : XFree( pWMHints );
473 : : }
474 : : }
475 : : }
476 : : else
477 : : {
478 : 0 : Hints.flags |= WindowGroupHint;
479 : 0 : Hints.window_group = pFrame->GetShellWindow();
480 : : // note: for a normal document window this will produce None
481 : : // as the window is not yet created and the shell window is
482 : : // initialized to None. This must be corrected after window creation.
483 : 0 : aClientLeader = GetDisplay()->GetDrawable( m_nXScreen );
484 : : }
485 : : }
486 : :
487 : 0 : nShowState_ = SHOWSTATE_UNKNOWN;
488 : 0 : bViewable_ = sal_True;
489 : 0 : bMapped_ = sal_False;
490 : 0 : nVisibility_ = VisibilityFullyObscured;
491 : : mhWindow = XCreateWindow( GetXDisplay(),
492 : : aFrameParent,
493 : : x, y,
494 : : w, h,
495 : : 0,
496 : : rVis.GetDepth(),
497 : : InputOutput,
498 : : rVis.GetVisual(),
499 : : nAttrMask,
500 : 0 : &Attributes );
501 : : // FIXME: see above: fake shell window for now to own window
502 : 0 : if( pParentData == NULL )
503 : : {
504 : 0 : mhShellWindow = mhWindow;
505 : : }
506 : :
507 : : // correct window group if necessary
508 : 0 : if( (Hints.flags & WindowGroupHint) == WindowGroupHint )
509 : : {
510 : 0 : if( Hints.window_group == None )
511 : 0 : Hints.window_group = GetShellWindow();
512 : : }
513 : :
514 : 0 : maGeometry.nX = x;
515 : 0 : maGeometry.nY = y;
516 : 0 : maGeometry.nWidth = w;
517 : 0 : maGeometry.nHeight = h;
518 : 0 : updateScreenNumber();
519 : :
520 : 0 : XSync( GetXDisplay(), False );
521 : 0 : setXEmbedInfo();
522 : :
523 : : XLIB_Time nUserTime = (nStyle_ & (SAL_FRAME_STYLE_OWNERDRAWDECORATION | SAL_FRAME_STYLE_TOOLWINDOW) ) == 0 ?
524 : 0 : pDisplay_->GetLastUserEventTime() : 0;
525 : 0 : pDisplay_->getWMAdaptor()->setUserTime( this, nUserTime );
526 : :
527 : 0 : if( ! pParentData && ! IsChildWindow() && ! Attributes.override_redirect )
528 : : {
529 : 0 : XSetWMHints( GetXDisplay(), mhWindow, &Hints );
530 : : // WM Protocols && internals
531 : : Atom a[3];
532 : 0 : int n = 0;
533 : 0 : a[n++] = pDisplay_->getWMAdaptor()->getAtom( WMAdaptor::WM_DELETE_WINDOW );
534 : 0 : if( pDisplay_->getWMAdaptor()->getAtom( WMAdaptor::NET_WM_PING ) )
535 : 0 : a[n++] = pDisplay_->getWMAdaptor()->getAtom( WMAdaptor::NET_WM_PING );
536 : 0 : if( (nSalFrameStyle & SAL_FRAME_STYLE_OWNERDRAWDECORATION) )
537 : 0 : a[n++] = pDisplay_->getWMAdaptor()->getAtom( WMAdaptor::WM_TAKE_FOCUS );
538 : 0 : XSetWMProtocols( GetXDisplay(), GetShellWindow(), a, n );
539 : :
540 : : // force wm class hint
541 : 0 : mnExtStyle = ~0;
542 : 0 : if (mpParent)
543 : 0 : m_sWMClass = mpParent->m_sWMClass;
544 : 0 : SetExtendedFrameStyle( 0 );
545 : :
546 : 0 : XSizeHints* pHints = XAllocSizeHints();
547 : 0 : pHints->flags = PWinGravity | PPosition;
548 : 0 : pHints->win_gravity = GetDisplay()->getWMAdaptor()->getPositionWinGravity();
549 : 0 : pHints->x = 0;
550 : 0 : pHints->y = 0;
551 : 0 : if( mbFullScreen )
552 : : {
553 : 0 : pHints->flags |= PMaxSize | PMinSize;
554 : 0 : pHints->max_width = w+100;
555 : 0 : pHints->max_height = h+100;
556 : 0 : pHints->min_width = w;
557 : 0 : pHints->min_height = h;
558 : : }
559 : : XSetWMNormalHints( GetXDisplay(),
560 : : GetShellWindow(),
561 : 0 : pHints );
562 : 0 : XFree (pHints);
563 : :
564 : : // set PID and WM_CLIENT_MACHINE
565 : 0 : pDisplay_->getWMAdaptor()->setClientMachine( this );
566 : 0 : pDisplay_->getWMAdaptor()->setPID( this );
567 : :
568 : : // set client leader
569 : 0 : if( aClientLeader )
570 : : {
571 : : XChangeProperty( GetXDisplay(),
572 : : mhWindow,
573 : : pDisplay_->getWMAdaptor()->getAtom( WMAdaptor::WM_CLIENT_LEADER),
574 : : XA_WINDOW,
575 : : 32,
576 : : PropModeReplace,
577 : : (unsigned char*)&aClientLeader,
578 : : 1
579 : 0 : );
580 : : }
581 : : #define DECOFLAGS (SAL_FRAME_STYLE_MOVEABLE | SAL_FRAME_STYLE_SIZEABLE | SAL_FRAME_STYLE_CLOSEABLE)
582 : 0 : int nDecoFlags = WMAdaptor::decoration_All;
583 : 0 : if( (nStyle_ & SAL_FRAME_STYLE_PARTIAL_FULLSCREEN) ||
584 : : (nStyle_ & SAL_FRAME_STYLE_OWNERDRAWDECORATION)
585 : : )
586 : 0 : nDecoFlags = 0;
587 : 0 : else if( (nStyle_ & DECOFLAGS ) != DECOFLAGS || (nStyle_ & SAL_FRAME_STYLE_TOOLWINDOW) )
588 : : {
589 : 0 : if( nStyle_ & DECOFLAGS )
590 : : // if any decoration, then show a border
591 : 0 : nDecoFlags = WMAdaptor::decoration_Border;
592 : : else
593 : 0 : nDecoFlags = 0;
594 : :
595 : 0 : if( ! mpParent && (nStyle_ & DECOFLAGS) )
596 : : // don't add a min button if window should be decorationless
597 : 0 : nDecoFlags |= WMAdaptor::decoration_MinimizeBtn;
598 : 0 : if( nStyle_ & SAL_FRAME_STYLE_CLOSEABLE )
599 : 0 : nDecoFlags |= WMAdaptor::decoration_CloseBtn;
600 : 0 : if( nStyle_ & SAL_FRAME_STYLE_SIZEABLE )
601 : : {
602 : 0 : nDecoFlags |= WMAdaptor::decoration_Resize;
603 : 0 : if( ! (nStyle_ & SAL_FRAME_STYLE_TOOLWINDOW) )
604 : 0 : nDecoFlags |= WMAdaptor::decoration_MaximizeBtn;
605 : : }
606 : 0 : if( nStyle_ & SAL_FRAME_STYLE_MOVEABLE )
607 : 0 : nDecoFlags |= WMAdaptor::decoration_Title;
608 : : }
609 : :
610 : 0 : WMAdaptor::WMWindowType eType = WMAdaptor::windowType_Normal;
611 : 0 : if( nStyle_ & SAL_FRAME_STYLE_INTRO )
612 : 0 : eType = WMAdaptor::windowType_Splash;
613 : 0 : if( (nStyle_ & SAL_FRAME_STYLE_DIALOG) && hPresentationWindow == None )
614 : 0 : eType = WMAdaptor::windowType_ModelessDialogue;
615 : 0 : if( nStyle_ & SAL_FRAME_STYLE_TOOLWINDOW )
616 : 0 : eType = WMAdaptor::windowType_Utility;
617 : 0 : if( nStyle_ & SAL_FRAME_STYLE_OWNERDRAWDECORATION )
618 : 0 : eType = WMAdaptor::windowType_Toolbar;
619 : 0 : if( (nStyle_ & SAL_FRAME_STYLE_PARTIAL_FULLSCREEN)
620 : 0 : && GetDisplay()->getWMAdaptor()->isLegacyPartialFullscreen() )
621 : 0 : eType = WMAdaptor::windowType_Dock;
622 : :
623 : 0 : GetDisplay()->getWMAdaptor()->
624 : : setFrameTypeAndDecoration( this,
625 : : eType,
626 : : nDecoFlags,
627 : 0 : hPresentationWindow ? NULL : mpParent );
628 : :
629 : 0 : if( (nStyle_ & (SAL_FRAME_STYLE_DEFAULT |
630 : : SAL_FRAME_STYLE_OWNERDRAWDECORATION|
631 : : SAL_FRAME_STYLE_FLOAT |
632 : : SAL_FRAME_STYLE_INTRO |
633 : : SAL_FRAME_STYLE_PARTIAL_FULLSCREEN) )
634 : : == SAL_FRAME_STYLE_DEFAULT )
635 : 0 : pDisplay_->getWMAdaptor()->maximizeFrame( this, true, true );
636 : : }
637 : :
638 : 0 : m_nWorkArea = GetDisplay()->getWMAdaptor()->getCurrentWorkArea();
639 : :
640 : : // Pointer
641 : 0 : SetPointer( POINTER_ARROW );
642 : 0 : }
643 : :
644 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
645 : 0 : X11SalFrame::X11SalFrame( SalFrame *pParent, sal_uLong nSalFrameStyle,
646 : : SystemParentData* pSystemParent ) :
647 : 0 : m_nXScreen( 0 )
648 : : {
649 : 0 : SalGenericData *pData = GetGenericData();
650 : :
651 : : // initialize frame geometry
652 : 0 : memset( &maGeometry, 0, sizeof(maGeometry) );
653 : :
654 : 0 : mpParent = static_cast< X11SalFrame* >( pParent );
655 : :
656 : 0 : mbTransientForRoot = false;
657 : :
658 : 0 : pDisplay_ = pData->GetSalDisplay();
659 : : // insert frame in framelist
660 : 0 : pDisplay_->registerFrame( this );
661 : :
662 : 0 : mhWindow = None;
663 : 0 : mhShellWindow = None;
664 : 0 : mhStackingWindow = None;
665 : 0 : mhForeignParent = None;
666 : 0 : mhBackgroundPixmap = None;
667 : 0 : m_bSetFocusOnMap = false;
668 : :
669 : 0 : pGraphics_ = NULL;
670 : 0 : pFreeGraphics_ = NULL;
671 : :
672 : 0 : hCursor_ = None;
673 : 0 : nCaptured_ = 0;
674 : :
675 : 0 : nReleaseTime_ = 0;
676 : 0 : nKeyCode_ = 0;
677 : 0 : nKeyState_ = 0;
678 : 0 : nCompose_ = -1;
679 : 0 : mbSendExtKeyModChange = false;
680 : 0 : mnExtKeyMod = 0;
681 : :
682 : 0 : nShowState_ = SHOWSTATE_UNKNOWN;
683 : 0 : nWidth_ = 0;
684 : 0 : nHeight_ = 0;
685 : 0 : nStyle_ = 0;
686 : 0 : mnExtStyle = 0;
687 : 0 : bAlwaysOnTop_ = sal_False;
688 : :
689 : : // set bViewable_ to sal_True: hack GetClientSize to report something
690 : : // different to 0/0 before first map
691 : 0 : bViewable_ = sal_True;
692 : 0 : bMapped_ = sal_False;
693 : 0 : bDefaultPosition_ = sal_True;
694 : 0 : nVisibility_ = VisibilityFullyObscured;
695 : 0 : m_nWorkArea = 0;
696 : 0 : mbInShow = sal_False;
697 : 0 : m_bXEmbed = false;
698 : :
699 : 0 : nScreenSaversTimeout_ = 0;
700 : :
701 : 0 : mpInputContext = NULL;
702 : 0 : mbInputFocus = False;
703 : :
704 : 0 : maAlwaysOnTopRaiseTimer.SetTimeoutHdl( LINK( this, X11SalFrame, HandleAlwaysOnTopRaise ) );
705 : 0 : maAlwaysOnTopRaiseTimer.SetTimeout( 100 );
706 : :
707 : 0 : meWindowType = WMAdaptor::windowType_Normal;
708 : 0 : mnDecorationFlags = WMAdaptor::decoration_All;
709 : 0 : mbMaximizedVert = false;
710 : 0 : mbMaximizedHorz = false;
711 : 0 : mbShaded = false;
712 : 0 : mbFullScreen = false;
713 : :
714 : 0 : mnIconID = 1; // ICON_LO_DEFAULT
715 : :
716 : 0 : m_pClipRectangles = NULL;
717 : 0 : m_nCurClipRect = 0;
718 : 0 : m_nMaxClipRect = 0;
719 : :
720 : 0 : if( mpParent )
721 : 0 : mpParent->maChildren.push_back( this );
722 : :
723 : 0 : Init( nSalFrameStyle, GetDisplay()->GetDefaultXScreen(), pSystemParent );
724 : 0 : }
725 : :
726 : 0 : X11SalFrame::~X11SalFrame()
727 : : {
728 : 0 : notifyDelete();
729 : :
730 : 0 : if( m_pClipRectangles )
731 : : {
732 : 0 : delete [] m_pClipRectangles;
733 : 0 : m_pClipRectangles = NULL;
734 : 0 : m_nCurClipRect = m_nMaxClipRect = 0;
735 : : }
736 : :
737 : 0 : if( mhBackgroundPixmap )
738 : : {
739 : 0 : XSetWindowBackgroundPixmap( GetXDisplay(), GetWindow(), None );
740 : 0 : XFreePixmap( GetXDisplay(), mhBackgroundPixmap );
741 : : }
742 : :
743 : 0 : if( mhStackingWindow )
744 : 0 : aPresentationReparentList.remove( mhStackingWindow );
745 : :
746 : : // remove from parent's list
747 : 0 : if( mpParent )
748 : 0 : mpParent->maChildren.remove( this );
749 : :
750 : : // deregister on SalDisplay
751 : 0 : pDisplay_->deregisterFrame( this );
752 : :
753 : : // unselect all events, some may be still in the queue anyway
754 : 0 : if( ! IsSysChildWindow() )
755 : 0 : XSelectInput( GetXDisplay(), GetShellWindow(), 0 );
756 : 0 : XSelectInput( GetXDisplay(), GetWindow(), 0 );
757 : :
758 : 0 : ShowFullScreen( sal_False, 0 );
759 : :
760 : 0 : if( bMapped_ )
761 : 0 : Show( sal_False );
762 : :
763 : 0 : if( mpInputContext )
764 : : {
765 : 0 : mpInputContext->UnsetICFocus( this );
766 : 0 : mpInputContext->Unmap( this );
767 : 0 : delete mpInputContext;
768 : : }
769 : :
770 : 0 : if( GetWindow() == hPresentationWindow )
771 : : {
772 : 0 : hPresentationWindow = None;
773 : 0 : doReparentPresentationDialogues( GetDisplay() );
774 : : }
775 : :
776 : 0 : if( pGraphics_ )
777 : : {
778 : 0 : pGraphics_->DeInit();
779 : 0 : delete pGraphics_;
780 : : }
781 : :
782 : 0 : if( pFreeGraphics_ )
783 : : {
784 : 0 : pFreeGraphics_->DeInit();
785 : 0 : delete pFreeGraphics_;
786 : : }
787 : :
788 : :
789 : 0 : XDestroyWindow( GetXDisplay(), mhWindow );
790 : :
791 : : /*
792 : : * check if there is only the status frame left
793 : : * if so, free it
794 : : */
795 : 0 : if( ! GetDisplay()->getFrames().empty() && I18NStatus::exists() )
796 : : {
797 : 0 : SalFrame* pStatusFrame = I18NStatus::get().getStatusFrame();
798 : 0 : std::list< SalFrame* >::const_iterator sit = GetDisplay()->getFrames().begin();
799 : 0 : if( pStatusFrame
800 : 0 : && *sit == pStatusFrame
801 : 0 : && ++sit == GetDisplay()->getFrames().end() )
802 : 0 : vcl::I18NStatus::free();
803 : : }
804 : 0 : }
805 : :
806 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
807 : :
808 : 0 : void X11SalFrame::SetExtendedFrameStyle( SalExtStyle nStyle )
809 : : {
810 : 0 : if( nStyle != mnExtStyle && ! IsChildWindow() )
811 : : {
812 : 0 : mnExtStyle = nStyle;
813 : 0 : updateWMClass();
814 : : }
815 : 0 : }
816 : :
817 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
818 : :
819 : 0 : void X11SalFrame::SetBackgroundBitmap( SalBitmap* pBitmap )
820 : : {
821 : 0 : if( mhBackgroundPixmap )
822 : : {
823 : 0 : XSetWindowBackgroundPixmap( GetXDisplay(), GetWindow(), None );
824 : 0 : XFreePixmap( GetXDisplay(), mhBackgroundPixmap );
825 : 0 : mhBackgroundPixmap = None;
826 : : }
827 : 0 : if( pBitmap )
828 : : {
829 : 0 : X11SalBitmap* pBM = static_cast<X11SalBitmap*>(pBitmap);
830 : 0 : Size aSize = pBM->GetSize();
831 : 0 : if( aSize.Width() && aSize.Height() )
832 : : {
833 : : mhBackgroundPixmap =
834 : : limitXCreatePixmap( GetXDisplay(),
835 : : GetWindow(),
836 : 0 : aSize.Width(),
837 : 0 : aSize.Height(),
838 : 0 : GetDisplay()->GetVisual( m_nXScreen ).GetDepth() );
839 : 0 : if( mhBackgroundPixmap )
840 : : {
841 : : SalTwoRect aTwoRect;
842 : 0 : aTwoRect.mnSrcX = aTwoRect.mnSrcY = aTwoRect.mnDestX = aTwoRect.mnDestY = 0;
843 : 0 : aTwoRect.mnSrcWidth = aTwoRect.mnDestWidth = aSize.Width();
844 : 0 : aTwoRect.mnSrcHeight = aTwoRect.mnDestHeight = aSize.Height();
845 : : pBM->ImplDraw( mhBackgroundPixmap,
846 : : m_nXScreen,
847 : 0 : GetDisplay()->GetVisual( m_nXScreen ).GetDepth(),
848 : 0 : aTwoRect, GetDisplay()->GetCopyGC( m_nXScreen ) );
849 : 0 : XSetWindowBackgroundPixmap( GetXDisplay(), GetWindow(), mhBackgroundPixmap );
850 : : }
851 : : }
852 : : }
853 : 0 : }
854 : :
855 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
856 : :
857 : 0 : const SystemChildData* X11SalFrame::GetSystemData() const
858 : : {
859 : 0 : X11SalFrame *pFrame = const_cast<X11SalFrame*>(this);
860 : 0 : pFrame->maSystemChildData.nSize = sizeof( SystemChildData );
861 : 0 : pFrame->maSystemChildData.pDisplay = GetXDisplay();
862 : 0 : pFrame->maSystemChildData.aWindow = pFrame->GetWindow();
863 : 0 : pFrame->maSystemChildData.pSalFrame = pFrame;
864 : 0 : pFrame->maSystemChildData.pWidget = NULL;
865 : 0 : pFrame->maSystemChildData.pVisual = GetDisplay()->GetVisual( m_nXScreen ).GetVisual();
866 : 0 : pFrame->maSystemChildData.nScreen = m_nXScreen.getXScreen();
867 : 0 : pFrame->maSystemChildData.nDepth = GetDisplay()->GetVisual( m_nXScreen ).GetDepth();
868 : 0 : pFrame->maSystemChildData.aColormap = GetDisplay()->GetColormap( m_nXScreen ).GetXColormap();
869 : 0 : pFrame->maSystemChildData.pAppContext = NULL;
870 : 0 : pFrame->maSystemChildData.aShellWindow = pFrame->GetShellWindow();
871 : 0 : pFrame->maSystemChildData.pShellWidget = NULL;
872 : 0 : return &maSystemChildData;
873 : : }
874 : :
875 : 0 : SalGraphics *X11SalFrame::GetGraphics()
876 : : {
877 : 0 : if( pGraphics_ )
878 : 0 : return NULL;
879 : :
880 : 0 : if( pFreeGraphics_ )
881 : : {
882 : 0 : pGraphics_ = pFreeGraphics_;
883 : 0 : pFreeGraphics_ = NULL;
884 : : }
885 : : else
886 : : {
887 : 0 : pGraphics_ = new X11SalGraphics();
888 : 0 : pGraphics_->Init( this, GetWindow(), m_nXScreen );
889 : : }
890 : :
891 : 0 : return pGraphics_;
892 : : }
893 : :
894 : 0 : void X11SalFrame::ReleaseGraphics( SalGraphics *pGraphics )
895 : : {
896 : : DBG_ASSERT( pGraphics == pGraphics_, "SalFrame::ReleaseGraphics pGraphics!=pGraphics_" );
897 : :
898 : 0 : if( pGraphics != pGraphics_ )
899 : 0 : return;
900 : :
901 : 0 : pFreeGraphics_ = pGraphics_;
902 : 0 : pGraphics_ = NULL;
903 : : }
904 : :
905 : 0 : void X11SalFrame::updateGraphics( bool bClear )
906 : : {
907 : 0 : Drawable aDrawable = bClear ? None : GetWindow();
908 : 0 : if( pGraphics_ )
909 : 0 : pGraphics_->SetDrawable( aDrawable, m_nXScreen );
910 : 0 : if( pFreeGraphics_ )
911 : 0 : pFreeGraphics_->SetDrawable( aDrawable, m_nXScreen );
912 : 0 : }
913 : :
914 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
915 : :
916 : 0 : void X11SalFrame::Enable( sal_Bool /*bEnable*/ )
917 : : {
918 : : // NYI: enable/disable frame
919 : 0 : }
920 : :
921 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
922 : :
923 : 0 : void X11SalFrame::SetIcon( sal_uInt16 nIcon )
924 : : {
925 : 0 : if ( ! IsChildWindow() )
926 : : {
927 : : // 0 == default icon -> #1
928 : 0 : if ( nIcon == 0 )
929 : 0 : nIcon = 1;
930 : :
931 : 0 : mnIconID = nIcon;
932 : :
933 : 0 : XIconSize *pIconSize = NULL;
934 : 0 : int nSizes = 0;
935 : 0 : int iconSize = 32;
936 : 0 : if ( XGetIconSizes( GetXDisplay(), GetDisplay()->GetRootWindow( m_nXScreen ), &pIconSize, &nSizes ) )
937 : : {
938 : : #if OSL_DEBUG_LEVEL > 1
939 : : fprintf(stderr, "X11SalFrame::SetIcon(): found %d IconSizes:\n", nSizes);
940 : : #endif
941 : :
942 : 0 : const int ourLargestIconSize = 48;
943 : :
944 : : int i;
945 : 0 : for( i=0; i<nSizes; i++)
946 : : {
947 : : // select largest supported icon
948 : :
949 : : // Note: olwm/olvwm reports a huge max icon size of
950 : : // 160x160 pixels; always choosing the max as the
951 : : // preferred icon size is apparently wrong under olvwm
952 : : // - so we keep the safe default |iconSize| when we see
953 : : // unreasonable large max icon sizes (> twice of our
954 : : // largest available icon) reported by XGetIconSizes.
955 : 0 : if( pIconSize[i].max_width > iconSize
956 : 0 : && pIconSize[i].max_width <= 2*ourLargestIconSize )
957 : : {
958 : 0 : iconSize = pIconSize[i].max_width;
959 : : }
960 : 0 : iconSize = pIconSize[i].max_width;
961 : :
962 : : #if OSL_DEBUG_LEVEL > 1
963 : : fprintf(stderr, "min: %d, %d\nmax: %d, %d\ninc: %d, %d\n\n",
964 : : pIconSize[i].min_width, pIconSize[i].min_height,
965 : : pIconSize[i].max_width, pIconSize[i].max_height,
966 : : pIconSize[i].width_inc, pIconSize[i].height_inc);
967 : : #endif
968 : : }
969 : :
970 : 0 : XFree( pIconSize );
971 : : }
972 : : else
973 : : {
974 : 0 : const String& rWM( pDisplay_->getWMAdaptor()->getWindowManagerName() );
975 : 0 : if( rWM.EqualsAscii( "KWin" ) ) // assume KDE is running
976 : 0 : iconSize = 48;
977 : : static bool bGnomeIconSize = false;
978 : : static bool bGnomeChecked = false;
979 : 0 : if( ! bGnomeChecked )
980 : : {
981 : 0 : bGnomeChecked=true;
982 : 0 : int nCount = 0;
983 : : Atom* pProps = XListProperties( GetXDisplay(),
984 : : GetDisplay()->GetRootWindow( m_nXScreen ),
985 : 0 : &nCount );
986 : 0 : for( int i = 0; i < nCount && !bGnomeIconSize; i++ )
987 : : {
988 : 0 : char* pName = XGetAtomName( GetXDisplay(), pProps[i] );
989 : 0 : if( !strcmp( pName, "GNOME_PANEL_DESKTOP_AREA" ) )
990 : 0 : bGnomeIconSize = true;
991 : 0 : if( pName )
992 : 0 : XFree( pName );
993 : : }
994 : 0 : if( pProps )
995 : 0 : XFree( pProps );
996 : : }
997 : 0 : if( bGnomeIconSize )
998 : 0 : iconSize = 48;
999 : : }
1000 : :
1001 : : XWMHints Hints;
1002 : 0 : Hints.flags = 0;
1003 : 0 : XWMHints *pHints = XGetWMHints( GetXDisplay(), GetShellWindow() );
1004 : 0 : if( pHints )
1005 : : {
1006 : 0 : memcpy(&Hints, pHints, sizeof( XWMHints ));
1007 : 0 : XFree( pHints );
1008 : : }
1009 : 0 : pHints = &Hints;
1010 : :
1011 : : sal_Bool bOk = SelectAppIconPixmap( GetDisplay(), m_nXScreen,
1012 : : nIcon, iconSize,
1013 : 0 : pHints->icon_pixmap, pHints->icon_mask );
1014 : 0 : if ( !bOk )
1015 : : {
1016 : : // load default icon (0)
1017 : : bOk = SelectAppIconPixmap( GetDisplay(), m_nXScreen,
1018 : : 0, iconSize,
1019 : 0 : pHints->icon_pixmap, pHints->icon_mask );
1020 : : }
1021 : 0 : if( bOk )
1022 : : {
1023 : 0 : pHints->flags |= IconPixmapHint;
1024 : 0 : if( pHints->icon_mask )
1025 : 0 : pHints->flags |= IconMaskHint;
1026 : :
1027 : 0 : XSetWMHints( GetXDisplay(), GetShellWindow(), pHints );
1028 : : }
1029 : : }
1030 : 0 : }
1031 : :
1032 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1033 : :
1034 : 0 : void X11SalFrame::SetMaxClientSize( long nWidth, long nHeight )
1035 : : {
1036 : 0 : if( ! IsChildWindow() )
1037 : : {
1038 : 0 : if( GetShellWindow() && (nStyle_ & (SAL_FRAME_STYLE_FLOAT|SAL_FRAME_STYLE_OWNERDRAWDECORATION) ) != SAL_FRAME_STYLE_FLOAT )
1039 : : {
1040 : 0 : XSizeHints* pHints = XAllocSizeHints();
1041 : 0 : long nSupplied = 0;
1042 : : XGetWMNormalHints( GetXDisplay(),
1043 : : GetShellWindow(),
1044 : : pHints,
1045 : : &nSupplied
1046 : 0 : );
1047 : 0 : pHints->max_width = nWidth;
1048 : 0 : pHints->max_height = nHeight;
1049 : 0 : pHints->flags |= PMaxSize;
1050 : : XSetWMNormalHints( GetXDisplay(),
1051 : : GetShellWindow(),
1052 : 0 : pHints );
1053 : 0 : XFree( pHints );
1054 : : }
1055 : : }
1056 : 0 : }
1057 : :
1058 : 0 : void X11SalFrame::SetMinClientSize( long nWidth, long nHeight )
1059 : : {
1060 : 0 : if( ! IsChildWindow() )
1061 : : {
1062 : 0 : if( GetShellWindow() && (nStyle_ & (SAL_FRAME_STYLE_FLOAT|SAL_FRAME_STYLE_OWNERDRAWDECORATION) ) != SAL_FRAME_STYLE_FLOAT )
1063 : : {
1064 : 0 : XSizeHints* pHints = XAllocSizeHints();
1065 : 0 : long nSupplied = 0;
1066 : : XGetWMNormalHints( GetXDisplay(),
1067 : : GetShellWindow(),
1068 : : pHints,
1069 : : &nSupplied
1070 : 0 : );
1071 : 0 : pHints->min_width = nWidth;
1072 : 0 : pHints->min_height = nHeight;
1073 : 0 : pHints->flags |= PMinSize;
1074 : : XSetWMNormalHints( GetXDisplay(),
1075 : : GetShellWindow(),
1076 : 0 : pHints );
1077 : 0 : XFree( pHints );
1078 : : }
1079 : : }
1080 : 0 : }
1081 : :
1082 : : // Show + Pos (x,y,z) + Size (width,height)
1083 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1084 : 0 : void X11SalFrame::Show( sal_Bool bVisible, sal_Bool bNoActivate )
1085 : : {
1086 : 0 : if( ( bVisible && bMapped_ )
1087 : 0 : || ( !bVisible && !bMapped_ ) )
1088 : 0 : return;
1089 : :
1090 : : // HACK: this is a workaround for (at least) kwin
1091 : : // even though transient frames should be kept above their parent
1092 : : // this does not necessarily hold true for DOCK type windows
1093 : : // so artificially set ABOVE and remove it again on hide
1094 : 0 : if( mpParent && (mpParent->nStyle_ & SAL_FRAME_STYLE_PARTIAL_FULLSCREEN ) && pDisplay_->getWMAdaptor()->isLegacyPartialFullscreen())
1095 : 0 : pDisplay_->getWMAdaptor()->enableAlwaysOnTop( this, bVisible );
1096 : :
1097 : 0 : bMapped_ = bVisible;
1098 : 0 : bViewable_ = bVisible;
1099 : 0 : setXEmbedInfo();
1100 : 0 : if( bVisible )
1101 : : {
1102 : 0 : mbInShow = sal_True;
1103 : 0 : if( ! (nStyle_ & SAL_FRAME_STYLE_INTRO) )
1104 : : {
1105 : : // hide all INTRO frames
1106 : 0 : const std::list< SalFrame* >& rFrames = GetDisplay()->getFrames();
1107 : 0 : for( std::list< SalFrame* >::const_iterator it = rFrames.begin(); it != rFrames.end(); ++it )
1108 : : {
1109 : 0 : const X11SalFrame* pFrame = static_cast< const X11SalFrame* >(*it);
1110 : : // look for intro bit map; if present, hide it
1111 : 0 : if( pFrame->nStyle_ & SAL_FRAME_STYLE_INTRO )
1112 : : {
1113 : 0 : if( pFrame->bMapped_ )
1114 : 0 : const_cast<X11SalFrame*>(pFrame)->Show( sal_False );
1115 : : }
1116 : : }
1117 : : }
1118 : :
1119 : : // update NET_WM_STATE which may have been deleted due to earlier Show(sal_False)
1120 : 0 : if( nShowState_ == SHOWSTATE_HIDDEN )
1121 : 0 : GetDisplay()->getWMAdaptor()->frameIsMapping( this );
1122 : :
1123 : : /*
1124 : : * Actually this is rather exotic and currently happens only in conjunction
1125 : : * with the basic dialogue editor,
1126 : : * which shows a frame and instantly hides it again. After that the
1127 : : * editor window is shown and the WM takes this as an opportunity
1128 : : * to show our hidden transient frame also. So Show( sal_False ) must
1129 : : * withdraw the frame AND delete the WM_TRANSIENT_FOR property.
1130 : : * In case the frame is shown again, the transient hint must be restored here.
1131 : : */
1132 : 0 : if( ! IsChildWindow()
1133 : 0 : && ! IsOverrideRedirect()
1134 : 0 : && ! IsFloatGrabWindow()
1135 : : && mpParent
1136 : : )
1137 : : {
1138 : 0 : GetDisplay()->getWMAdaptor()->changeReferenceFrame( this, mpParent );
1139 : : }
1140 : :
1141 : : // #i45160# switch to desktop where a dialog with parent will appear
1142 : 0 : if( mpParent && mpParent->m_nWorkArea != m_nWorkArea )
1143 : 0 : GetDisplay()->getWMAdaptor()->switchToWorkArea( mpParent->m_nWorkArea );
1144 : :
1145 : 0 : if( IsFloatGrabWindow() &&
1146 : : mpParent &&
1147 : : nVisibleFloats == 0 &&
1148 : 0 : ! GetDisplay()->GetCaptureFrame() )
1149 : : {
1150 : : /* #i39420#
1151 : : * outsmart KWin's "focus strictly under mouse" mode
1152 : : * which insists on taking the focus from the document
1153 : : * to the new float. Grab focus to parent frame BEFORE
1154 : : * showing the float (cannot grab it to the float
1155 : : * before show).
1156 : : */
1157 : : XGrabPointer( GetXDisplay(),
1158 : : mpParent->GetWindow(),
1159 : : True,
1160 : : PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1161 : : GrabModeAsync,
1162 : : GrabModeAsync,
1163 : : None,
1164 : 0 : mpParent ? mpParent->GetCursor() : None,
1165 : : CurrentTime
1166 : 0 : );
1167 : : }
1168 : :
1169 : 0 : XLIB_Time nUserTime = 0;
1170 : 0 : if( ! bNoActivate && (nStyle_ & (SAL_FRAME_STYLE_OWNERDRAWDECORATION)) == 0 )
1171 : 0 : nUserTime = pDisplay_->GetLastUserEventTime( true );
1172 : 0 : GetDisplay()->getWMAdaptor()->setUserTime( this, nUserTime );
1173 : 0 : if( ! bNoActivate && (nStyle_ & SAL_FRAME_STYLE_TOOLWINDOW) )
1174 : 0 : m_bSetFocusOnMap = true;
1175 : :
1176 : : // actually map the window
1177 : 0 : if( m_bXEmbed )
1178 : 0 : askForXEmbedFocus( 0 );
1179 : : else
1180 : : {
1181 : 0 : if( GetWindow() != GetShellWindow() && ! IsSysChildWindow() )
1182 : : {
1183 : 0 : if( IsChildWindow() )
1184 : 0 : XMapWindow( GetXDisplay(), GetShellWindow() );
1185 : 0 : XSelectInput( GetXDisplay(), GetShellWindow(), CLIENT_EVENTS );
1186 : : }
1187 : 0 : if( nStyle_ & SAL_FRAME_STYLE_FLOAT )
1188 : 0 : XMapRaised( GetXDisplay(), GetWindow() );
1189 : : else
1190 : 0 : XMapWindow( GetXDisplay(), GetWindow() );
1191 : : }
1192 : 0 : XSelectInput( GetXDisplay(), GetWindow(), CLIENT_EVENTS );
1193 : :
1194 : 0 : if( maGeometry.nWidth > 0
1195 : : && maGeometry.nHeight > 0
1196 : : && ( nWidth_ != (int)maGeometry.nWidth
1197 : : || nHeight_ != (int)maGeometry.nHeight ) )
1198 : : {
1199 : 0 : nWidth_ = maGeometry.nWidth;
1200 : 0 : nHeight_ = maGeometry.nHeight;
1201 : : }
1202 : :
1203 : 0 : XSync( GetXDisplay(), False );
1204 : :
1205 : 0 : if( IsFloatGrabWindow() )
1206 : : {
1207 : : /*
1208 : : * Sawfish and twm can be switched to enter-exit focus behaviour. In this case
1209 : : * we must grab the pointer else the dumb WM will put the focus to the
1210 : : * override-redirect float window. The application window will be deactivated
1211 : : * which causes that the floats are destroyed, so the user can never click on
1212 : : * a menu because it vanishes as soon as he enters it.
1213 : : */
1214 : 0 : nVisibleFloats++;
1215 : 0 : if( nVisibleFloats == 1 && ! GetDisplay()->GetCaptureFrame() )
1216 : : {
1217 : : /* #i39420# now move grab to the new float window */
1218 : : XGrabPointer( GetXDisplay(),
1219 : : GetWindow(),
1220 : : True,
1221 : : PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1222 : : GrabModeAsync,
1223 : : GrabModeAsync,
1224 : : None,
1225 : 0 : mpParent ? mpParent->GetCursor() : None,
1226 : : CurrentTime
1227 : 0 : );
1228 : : }
1229 : : }
1230 : 0 : CallCallback( SALEVENT_RESIZE, NULL );
1231 : :
1232 : : /*
1233 : : * sometimes a message box/dialogue is brought up when a frame is not mapped
1234 : : * the corresponding TRANSIENT_FOR hint is then set to the root window
1235 : : * so that the dialogue shows in all cases. Correct it here if the
1236 : : * frame is shown afterwards.
1237 : : */
1238 : 0 : if( ! IsChildWindow()
1239 : 0 : && ! IsOverrideRedirect()
1240 : 0 : && ! IsFloatGrabWindow()
1241 : : )
1242 : : {
1243 : 0 : for( std::list< X11SalFrame* >::const_iterator it = maChildren.begin();
1244 : 0 : it != maChildren.end(); ++it )
1245 : : {
1246 : 0 : if( (*it)->mbTransientForRoot )
1247 : 0 : GetDisplay()->getWMAdaptor()->changeReferenceFrame( *it, this );
1248 : : }
1249 : : }
1250 : : /*
1251 : : * leave SHOWSTATE_UNKNOWN as this indicates first mapping
1252 : : * and is only reset int HandleSizeEvent
1253 : : */
1254 : 0 : if( nShowState_ != SHOWSTATE_UNKNOWN )
1255 : 0 : nShowState_ = SHOWSTATE_NORMAL;
1256 : :
1257 : : /*
1258 : : * plugged windows don't necessarily get the
1259 : : * focus on show because the parent may already be mapped
1260 : : * and have the focus. So try to set the focus
1261 : : * to the child on Show(sal_True)
1262 : : */
1263 : 0 : if( (nStyle_ & SAL_FRAME_STYLE_PLUG) && ! m_bXEmbed )
1264 : : XSetInputFocus( GetXDisplay(),
1265 : : GetWindow(),
1266 : : RevertToParent,
1267 : 0 : CurrentTime );
1268 : :
1269 : 0 : if( mpParent )
1270 : : {
1271 : : // push this frame so it will be in front of its siblings
1272 : : // only necessary for insane transient behaviour of Dtwm/olwm
1273 : 0 : mpParent->maChildren.remove( this );
1274 : 0 : mpParent->maChildren.push_front(this);
1275 : : }
1276 : : }
1277 : : else
1278 : : {
1279 : 0 : if( getInputContext() )
1280 : 0 : getInputContext()->Unmap( this );
1281 : :
1282 : 0 : if( ! IsChildWindow() )
1283 : : {
1284 : : /* FIXME: Is deleting the property really necessary ? It hurts
1285 : : * owner drawn windows at least.
1286 : : */
1287 : 0 : if( mpParent && ! (nStyle_ & SAL_FRAME_STYLE_OWNERDRAWDECORATION) )
1288 : 0 : XDeleteProperty( GetXDisplay(), GetShellWindow(), GetDisplay()->getWMAdaptor()->getAtom( WMAdaptor::WM_TRANSIENT_FOR ) );
1289 : 0 : XWithdrawWindow( GetXDisplay(), GetShellWindow(), m_nXScreen.getXScreen() );
1290 : : }
1291 : 0 : else if( ! m_bXEmbed )
1292 : 0 : XUnmapWindow( GetXDisplay(), GetWindow() );
1293 : :
1294 : 0 : nShowState_ = SHOWSTATE_HIDDEN;
1295 : 0 : if( IsFloatGrabWindow() && nVisibleFloats )
1296 : : {
1297 : 0 : nVisibleFloats--;
1298 : 0 : if( nVisibleFloats == 0 && ! GetDisplay()->GetCaptureFrame() )
1299 : : XUngrabPointer( GetXDisplay(),
1300 : 0 : CurrentTime );
1301 : : }
1302 : : // flush here; there may be a very seldom race between
1303 : : // the display connection used for clipboard and our connection
1304 : 0 : Flush();
1305 : : }
1306 : : }
1307 : :
1308 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1309 : 0 : void X11SalFrame::ToTop( sal_uInt16 nFlags )
1310 : : {
1311 : 0 : if( ( nFlags & SAL_FRAME_TOTOP_RESTOREWHENMIN )
1312 : 0 : && ! ( nStyle_ & SAL_FRAME_STYLE_FLOAT )
1313 : : && nShowState_ != SHOWSTATE_HIDDEN
1314 : : && nShowState_ != SHOWSTATE_UNKNOWN
1315 : : )
1316 : : {
1317 : 0 : GetDisplay()->getWMAdaptor()->frameIsMapping( this );
1318 : 0 : if( GetWindow() != GetShellWindow() && ! IsSysChildWindow() )
1319 : 0 : XMapWindow( GetXDisplay(), GetShellWindow() );
1320 : 0 : XMapWindow( GetXDisplay(), GetWindow() );
1321 : : }
1322 : :
1323 : 0 : XLIB_Window aToTopWindow = IsSysChildWindow() ? GetWindow() : GetShellWindow();
1324 : 0 : if( ! (nFlags & SAL_FRAME_TOTOP_GRABFOCUS_ONLY) )
1325 : : {
1326 : 0 : XRaiseWindow( GetXDisplay(), aToTopWindow );
1327 : 0 : if( ! GetDisplay()->getWMAdaptor()->isTransientBehaviourAsExpected() )
1328 : 0 : for( std::list< X11SalFrame* >::const_iterator it = maChildren.begin();
1329 : 0 : it != maChildren.end(); ++it )
1330 : 0 : (*it)->ToTop( nFlags & ~SAL_FRAME_TOTOP_GRABFOCUS );
1331 : : }
1332 : :
1333 : 0 : if( ( ( nFlags & SAL_FRAME_TOTOP_GRABFOCUS ) || ( nFlags & SAL_FRAME_TOTOP_GRABFOCUS_ONLY ) )
1334 : : && bMapped_ )
1335 : : {
1336 : 0 : if( m_bXEmbed )
1337 : 0 : askForXEmbedFocus( 0 );
1338 : : else
1339 : 0 : XSetInputFocus( GetXDisplay(), aToTopWindow, RevertToParent, CurrentTime );
1340 : : }
1341 : 0 : }
1342 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1343 : 0 : void X11SalFrame::GetWorkArea( Rectangle& rWorkArea )
1344 : : {
1345 : 0 : rWorkArea = pDisplay_->getWMAdaptor()->getWorkArea( 0 );
1346 : 0 : }
1347 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1348 : 0 : void X11SalFrame::GetClientSize( long &rWidth, long &rHeight )
1349 : : {
1350 : 0 : if( ! bViewable_ )
1351 : : {
1352 : 0 : rWidth = rHeight = 0;
1353 : 0 : return;
1354 : : }
1355 : :
1356 : 0 : rWidth = maGeometry.nWidth;
1357 : 0 : rHeight = maGeometry.nHeight;
1358 : :
1359 : 0 : if( !rWidth || !rHeight )
1360 : : {
1361 : : XWindowAttributes aAttrib;
1362 : :
1363 : 0 : XGetWindowAttributes( GetXDisplay(), GetWindow(), &aAttrib );
1364 : :
1365 : 0 : maGeometry.nWidth = rWidth = aAttrib.width;
1366 : 0 : maGeometry.nHeight = rHeight = aAttrib.height;
1367 : : }
1368 : : }
1369 : :
1370 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1371 : :
1372 : 0 : void X11SalFrame::Center( )
1373 : : {
1374 : : int nX, nY, nScreenWidth, nScreenHeight;
1375 : : int nRealScreenWidth, nRealScreenHeight;
1376 : 0 : int nScreenX = 0, nScreenY = 0;
1377 : :
1378 : 0 : const Size& aScreenSize = GetDisplay()->getDataForScreen( m_nXScreen ).m_aSize;
1379 : 0 : nScreenWidth = aScreenSize.Width();
1380 : 0 : nScreenHeight = aScreenSize.Height();
1381 : 0 : nRealScreenWidth = nScreenWidth;
1382 : 0 : nRealScreenHeight = nScreenHeight;
1383 : :
1384 : 0 : if( GetDisplay()->IsXinerama() )
1385 : : {
1386 : : // get xinerama screen we are on
1387 : : // if there is a parent, use its center for screen determination
1388 : : // else use the pointer
1389 : : XLIB_Window aRoot, aChild;
1390 : : int root_x, root_y, x, y;
1391 : : unsigned int mask;
1392 : 0 : if( mpParent )
1393 : : {
1394 : 0 : root_x = mpParent->maGeometry.nX + mpParent->maGeometry.nWidth/2;
1395 : 0 : root_y = mpParent->maGeometry.nY + mpParent->maGeometry.nHeight/2;
1396 : : }
1397 : : else
1398 : : XQueryPointer( GetXDisplay(),
1399 : : GetShellWindow(),
1400 : : &aRoot, &aChild,
1401 : : &root_x, &root_y,
1402 : : &x, &y,
1403 : 0 : &mask );
1404 : 0 : const std::vector< Rectangle >& rScreens = GetDisplay()->GetXineramaScreens();
1405 : 0 : for( unsigned int i = 0; i < rScreens.size(); i++ )
1406 : 0 : if( rScreens[i].IsInside( Point( root_x, root_y ) ) )
1407 : : {
1408 : 0 : nScreenX = rScreens[i].Left();
1409 : 0 : nScreenY = rScreens[i].Top();
1410 : 0 : nRealScreenWidth = rScreens[i].GetWidth();
1411 : 0 : nRealScreenHeight = rScreens[i].GetHeight();
1412 : 0 : break;
1413 : : }
1414 : : }
1415 : :
1416 : 0 : if( mpParent )
1417 : : {
1418 : 0 : X11SalFrame* pFrame = mpParent;
1419 : 0 : while( pFrame->mpParent )
1420 : 0 : pFrame = pFrame->mpParent;
1421 : 0 : if( pFrame->maGeometry.nWidth < 1 || pFrame->maGeometry.nHeight < 1 )
1422 : : {
1423 : 0 : Rectangle aRect;
1424 : 0 : pFrame->GetPosSize( aRect );
1425 : 0 : pFrame->maGeometry.nX = aRect.Left();
1426 : 0 : pFrame->maGeometry.nY = aRect.Top();
1427 : 0 : pFrame->maGeometry.nWidth = aRect.GetWidth();
1428 : 0 : pFrame->maGeometry.nHeight = aRect.GetHeight();
1429 : : }
1430 : :
1431 : 0 : if( pFrame->nStyle_ & SAL_FRAME_STYLE_PLUG )
1432 : : {
1433 : : XLIB_Window aRoot;
1434 : : unsigned int bw, depth;
1435 : : XGetGeometry( GetXDisplay(),
1436 : : pFrame->GetShellWindow(),
1437 : : &aRoot,
1438 : : &nScreenX, &nScreenY,
1439 : : (unsigned int*)&nScreenWidth,
1440 : : (unsigned int*)&nScreenHeight,
1441 : 0 : &bw, &depth );
1442 : : }
1443 : : else
1444 : : {
1445 : 0 : nScreenX = pFrame->maGeometry.nX;
1446 : 0 : nScreenY = pFrame->maGeometry.nY;
1447 : 0 : nScreenWidth = pFrame->maGeometry.nWidth;
1448 : 0 : nScreenHeight = pFrame->maGeometry.nHeight;
1449 : : }
1450 : : }
1451 : :
1452 : 0 : if( mpParent && mpParent->nShowState_ == SHOWSTATE_NORMAL )
1453 : : {
1454 : 0 : if( maGeometry.nWidth >= mpParent->maGeometry.nWidth &&
1455 : : maGeometry.nHeight >= mpParent->maGeometry.nHeight )
1456 : : {
1457 : 0 : nX = nScreenX + 40;
1458 : 0 : nY = nScreenY + 40;
1459 : : }
1460 : : else
1461 : : {
1462 : : // center the window relative to the top level frame
1463 : 0 : nX = (nScreenWidth - (int)maGeometry.nWidth ) / 2 + nScreenX;
1464 : 0 : nY = (nScreenHeight - (int)maGeometry.nHeight) / 2 + nScreenY;
1465 : : }
1466 : : }
1467 : : else
1468 : : {
1469 : : // center the window relative to screen
1470 : 0 : nX = (nRealScreenWidth - (int)maGeometry.nWidth ) / 2 + nScreenX;
1471 : 0 : nY = (nRealScreenHeight - (int)maGeometry.nHeight) / 2 + nScreenY;
1472 : : }
1473 : 0 : nX = nX < 0 ? 0 : nX;
1474 : 0 : nY = nY < 0 ? 0 : nY;
1475 : :
1476 : 0 : bDefaultPosition_ = False;
1477 : 0 : if( mpParent )
1478 : : {
1479 : 0 : nX -= mpParent->maGeometry.nX;
1480 : 0 : nY -= mpParent->maGeometry.nY;
1481 : : }
1482 : :
1483 : 0 : Point aPoint(nX, nY);
1484 : 0 : SetPosSize( Rectangle( aPoint, Size( maGeometry.nWidth, maGeometry.nHeight ) ) );
1485 : 0 : }
1486 : :
1487 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1488 : 0 : void X11SalFrame::updateScreenNumber()
1489 : : {
1490 : 0 : if( GetDisplay()->IsXinerama() && GetDisplay()->GetXineramaScreens().size() > 1 )
1491 : : {
1492 : 0 : Point aPoint( maGeometry.nX, maGeometry.nY );
1493 : 0 : const std::vector<Rectangle>& rScreenRects( GetDisplay()->GetXineramaScreens() );
1494 : 0 : size_t nScreens = rScreenRects.size();
1495 : 0 : for( size_t i = 0; i < nScreens; i++ )
1496 : : {
1497 : 0 : if( rScreenRects[i].IsInside( aPoint ) )
1498 : : {
1499 : 0 : maGeometry.nDisplayScreenNumber = static_cast<unsigned int>(i);
1500 : 0 : break;
1501 : : }
1502 : : }
1503 : : }
1504 : : else
1505 : 0 : maGeometry.nDisplayScreenNumber = m_nXScreen.getXScreen();
1506 : 0 : }
1507 : :
1508 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1509 : 0 : void X11SalFrame::SetPosSize( long nX, long nY, long nWidth, long nHeight, sal_uInt16 nFlags )
1510 : : {
1511 : 0 : if( nStyle_ & SAL_FRAME_STYLE_PLUG )
1512 : 0 : return;
1513 : :
1514 : : // relative positioning in X11SalFrame::SetPosSize
1515 : 0 : Rectangle aPosSize( Point( maGeometry.nX, maGeometry.nY ), Size( maGeometry.nWidth, maGeometry.nHeight ) );
1516 : 0 : aPosSize.Justify();
1517 : :
1518 : 0 : if( ! ( nFlags & SAL_FRAME_POSSIZE_X ) )
1519 : : {
1520 : 0 : nX = aPosSize.Left();
1521 : 0 : if( mpParent )
1522 : 0 : nX -= mpParent->maGeometry.nX;
1523 : : }
1524 : 0 : if( ! ( nFlags & SAL_FRAME_POSSIZE_Y ) )
1525 : : {
1526 : 0 : nY = aPosSize.Top();
1527 : 0 : if( mpParent )
1528 : 0 : nY -= mpParent->maGeometry.nY;
1529 : : }
1530 : 0 : if( ! ( nFlags & SAL_FRAME_POSSIZE_WIDTH ) )
1531 : 0 : nWidth = aPosSize.GetWidth();
1532 : 0 : if( ! ( nFlags & SAL_FRAME_POSSIZE_HEIGHT ) )
1533 : 0 : nHeight = aPosSize.GetHeight();
1534 : :
1535 : 0 : aPosSize = Rectangle( Point( nX, nY ), Size( nWidth, nHeight ) );
1536 : :
1537 : 0 : if( ! ( nFlags & ( SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y ) ) )
1538 : : {
1539 : 0 : if( bDefaultPosition_ )
1540 : : {
1541 : 0 : maGeometry.nWidth = aPosSize.GetWidth();
1542 : 0 : maGeometry.nHeight = aPosSize.GetHeight();
1543 : 0 : Center();
1544 : : }
1545 : : else
1546 : 0 : SetSize( Size( nWidth, nHeight ) );
1547 : : }
1548 : : else
1549 : 0 : SetPosSize( aPosSize );
1550 : :
1551 : 0 : bDefaultPosition_ = False;
1552 : : }
1553 : :
1554 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1555 : 0 : void X11SalFrame::SetAlwaysOnTop( sal_Bool bOnTop )
1556 : : {
1557 : 0 : if( ! IsOverrideRedirect() )
1558 : : {
1559 : 0 : bAlwaysOnTop_ = bOnTop;
1560 : 0 : pDisplay_->getWMAdaptor()->enableAlwaysOnTop( this, bOnTop );
1561 : : }
1562 : 0 : }
1563 : :
1564 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1565 : :
1566 : : #define _FRAMESTATE_MASK_GEOMETRY \
1567 : : (SAL_FRAMESTATE_MASK_X | SAL_FRAMESTATE_MASK_Y | \
1568 : : SAL_FRAMESTATE_MASK_WIDTH | SAL_FRAMESTATE_MASK_HEIGHT)
1569 : : #define _FRAMESTATE_MASK_MAXIMIZED_GEOMETRY \
1570 : : (SAL_FRAMESTATE_MASK_MAXIMIZED_X | SAL_FRAMESTATE_MASK_MAXIMIZED_Y | \
1571 : : SAL_FRAMESTATE_MASK_MAXIMIZED_WIDTH | SAL_FRAMESTATE_MASK_MAXIMIZED_HEIGHT)
1572 : :
1573 : 0 : void X11SalFrame::SetWindowState( const SalFrameState *pState )
1574 : : {
1575 : 0 : if (pState == NULL)
1576 : 0 : return;
1577 : :
1578 : : // Request for position or size change
1579 : 0 : if (pState->mnMask & _FRAMESTATE_MASK_GEOMETRY)
1580 : : {
1581 : 0 : Rectangle aPosSize;
1582 : 0 : bool bDoAdjust = false;
1583 : :
1584 : : /* #i44325#
1585 : : * if maximized, set restore size and guess maximized size from last time
1586 : : * in state change below maximize window
1587 : : */
1588 : 0 : if( ! IsChildWindow() &&
1589 : : (pState->mnMask & SAL_FRAMESTATE_MASK_STATE) &&
1590 : : (pState->mnState & SAL_FRAMESTATE_MAXIMIZED) &&
1591 : : (pState->mnMask & _FRAMESTATE_MASK_GEOMETRY) == _FRAMESTATE_MASK_GEOMETRY &&
1592 : : (pState->mnMask & _FRAMESTATE_MASK_MAXIMIZED_GEOMETRY) == _FRAMESTATE_MASK_MAXIMIZED_GEOMETRY
1593 : : )
1594 : : {
1595 : 0 : XSizeHints* pHints = XAllocSizeHints();
1596 : 0 : long nSupplied = 0;
1597 : : XGetWMNormalHints( GetXDisplay(),
1598 : : GetShellWindow(),
1599 : : pHints,
1600 : 0 : &nSupplied );
1601 : 0 : pHints->flags |= PPosition | PWinGravity;
1602 : 0 : pHints->x = pState->mnX;
1603 : 0 : pHints->y = pState->mnY;
1604 : 0 : pHints->win_gravity = pDisplay_->getWMAdaptor()->getPositionWinGravity();
1605 : : XSetWMNormalHints( GetXDisplay(),
1606 : : GetShellWindow(),
1607 : 0 : pHints );
1608 : 0 : XFree( pHints );
1609 : :
1610 : : XMoveResizeWindow( GetXDisplay(), GetShellWindow(),
1611 : : pState->mnX, pState->mnY,
1612 : 0 : pState->mnWidth, pState->mnHeight );
1613 : : // guess maximized geometry from last time
1614 : 0 : maGeometry.nX = pState->mnMaximizedX;
1615 : 0 : maGeometry.nY = pState->mnMaximizedY;
1616 : 0 : maGeometry.nWidth = pState->mnMaximizedWidth;
1617 : 0 : maGeometry.nHeight = pState->mnMaximizedHeight;
1618 : 0 : updateScreenNumber();
1619 : : }
1620 : : else
1621 : : {
1622 : : // initialize with current geometry
1623 : 0 : if ((pState->mnMask & _FRAMESTATE_MASK_GEOMETRY) != _FRAMESTATE_MASK_GEOMETRY)
1624 : 0 : GetPosSize (aPosSize);
1625 : :
1626 : : // change requested properties
1627 : 0 : if (pState->mnMask & SAL_FRAMESTATE_MASK_X)
1628 : : {
1629 : 0 : aPosSize.setX (pState->mnX);
1630 : : }
1631 : 0 : if (pState->mnMask & SAL_FRAMESTATE_MASK_Y)
1632 : : {
1633 : 0 : aPosSize.setY (pState->mnY);
1634 : : }
1635 : 0 : if (pState->mnMask & SAL_FRAMESTATE_MASK_WIDTH)
1636 : : {
1637 : 0 : long nWidth = pState->mnWidth > 0 ? pState->mnWidth - 1 : 0;
1638 : 0 : aPosSize.setWidth (nWidth);
1639 : 0 : bDoAdjust = true;
1640 : : }
1641 : 0 : if (pState->mnMask & SAL_FRAMESTATE_MASK_HEIGHT)
1642 : : {
1643 : 0 : int nHeight = pState->mnHeight > 0 ? pState->mnHeight - 1 : 0;
1644 : 0 : aPosSize.setHeight (nHeight);
1645 : 0 : bDoAdjust = true;
1646 : : }
1647 : :
1648 : 0 : const Size& aScreenSize = pDisplay_->getDataForScreen( m_nXScreen ).m_aSize;
1649 : :
1650 : 0 : if( bDoAdjust && aPosSize.GetWidth() <= aScreenSize.Width()
1651 : 0 : && aPosSize.GetHeight() <= aScreenSize.Height() )
1652 : : {
1653 : 0 : SalFrameGeometry aGeom = maGeometry;
1654 : :
1655 : 0 : if( ! (nStyle_ & ( SAL_FRAME_STYLE_FLOAT | SAL_FRAME_STYLE_PLUG ) ) &&
1656 : : mpParent &&
1657 : : aGeom.nLeftDecoration == 0 &&
1658 : : aGeom.nTopDecoration == 0 )
1659 : : {
1660 : 0 : aGeom = mpParent->maGeometry;
1661 : 0 : if( aGeom.nLeftDecoration == 0 &&
1662 : : aGeom.nTopDecoration == 0 )
1663 : : {
1664 : 0 : aGeom.nLeftDecoration = 5;
1665 : 0 : aGeom.nTopDecoration = 20;
1666 : 0 : aGeom.nRightDecoration = 5;
1667 : 0 : aGeom.nBottomDecoration = 5;
1668 : : }
1669 : : }
1670 : :
1671 : : // adjust position so that frame fits onto screen
1672 : 0 : if( aPosSize.Right()+(long)aGeom.nRightDecoration > aScreenSize.Width()-1 )
1673 : 0 : aPosSize.Move( (long)aScreenSize.Width() - (long)aPosSize.Right() - (long)aGeom.nRightDecoration, 0 );
1674 : 0 : if( aPosSize.Bottom()+(long)aGeom.nBottomDecoration > aScreenSize.Height()-1 )
1675 : 0 : aPosSize.Move( 0, (long)aScreenSize.Height() - (long)aPosSize.Bottom() - (long)aGeom.nBottomDecoration );
1676 : 0 : if( aPosSize.Left() < (long)aGeom.nLeftDecoration )
1677 : 0 : aPosSize.Move( (long)aGeom.nLeftDecoration - (long)aPosSize.Left(), 0 );
1678 : 0 : if( aPosSize.Top() < (long)aGeom.nTopDecoration )
1679 : 0 : aPosSize.Move( 0, (long)aGeom.nTopDecoration - (long)aPosSize.Top() );
1680 : : }
1681 : :
1682 : 0 : SetPosSize( 0, 0, aPosSize.GetWidth(), aPosSize.GetHeight(), SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
1683 : : }
1684 : : }
1685 : :
1686 : : // request for status change
1687 : 0 : if (pState->mnMask & SAL_FRAMESTATE_MASK_STATE)
1688 : : {
1689 : 0 : if (pState->mnState & SAL_FRAMESTATE_MAXIMIZED)
1690 : : {
1691 : 0 : nShowState_ = SHOWSTATE_NORMAL;
1692 : 0 : if( ! (pState->mnState & (SAL_FRAMESTATE_MAXIMIZED_HORZ|SAL_FRAMESTATE_MAXIMIZED_VERT) ) )
1693 : 0 : Maximize();
1694 : : else
1695 : : {
1696 : 0 : bool bHorz = (pState->mnState & SAL_FRAMESTATE_MAXIMIZED_HORZ) ? true : false;
1697 : 0 : bool bVert = (pState->mnState & SAL_FRAMESTATE_MAXIMIZED_VERT) ? true : false;
1698 : 0 : GetDisplay()->getWMAdaptor()->maximizeFrame( this, bHorz, bVert );
1699 : : }
1700 : 0 : maRestorePosSize.Left() = pState->mnX;
1701 : 0 : maRestorePosSize.Top() = pState->mnY;
1702 : 0 : maRestorePosSize.Right() = maRestorePosSize.Left() + pState->mnWidth;
1703 : 0 : maRestorePosSize.Right() = maRestorePosSize.Left() + pState->mnHeight;
1704 : : }
1705 : 0 : else if( mbMaximizedHorz || mbMaximizedVert )
1706 : 0 : GetDisplay()->getWMAdaptor()->maximizeFrame( this, false, false );
1707 : :
1708 : 0 : if (pState->mnState & SAL_FRAMESTATE_MINIMIZED)
1709 : : {
1710 : 0 : if (nShowState_ == SHOWSTATE_UNKNOWN)
1711 : 0 : nShowState_ = SHOWSTATE_NORMAL;
1712 : 0 : Minimize();
1713 : : }
1714 : 0 : if (pState->mnState & SAL_FRAMESTATE_NORMAL)
1715 : : {
1716 : 0 : if (nShowState_ != SHOWSTATE_NORMAL)
1717 : 0 : Restore();
1718 : : }
1719 : 0 : if (pState->mnState & SAL_FRAMESTATE_ROLLUP)
1720 : 0 : GetDisplay()->getWMAdaptor()->shade( this, true );
1721 : : }
1722 : : }
1723 : :
1724 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1725 : 0 : sal_Bool X11SalFrame::GetWindowState( SalFrameState* pState )
1726 : : {
1727 : 0 : if( SHOWSTATE_MINIMIZED == nShowState_ )
1728 : 0 : pState->mnState = SAL_FRAMESTATE_MINIMIZED;
1729 : : else
1730 : 0 : pState->mnState = SAL_FRAMESTATE_NORMAL;
1731 : :
1732 : 0 : Rectangle aPosSize;
1733 : 0 : if( maRestorePosSize.IsEmpty() )
1734 : 0 : GetPosSize( aPosSize );
1735 : : else
1736 : 0 : aPosSize = maRestorePosSize;
1737 : :
1738 : 0 : if( mbMaximizedHorz )
1739 : 0 : pState->mnState |= SAL_FRAMESTATE_MAXIMIZED_HORZ;
1740 : 0 : if( mbMaximizedVert )
1741 : 0 : pState->mnState |= SAL_FRAMESTATE_MAXIMIZED_VERT;
1742 : 0 : if( mbShaded )
1743 : 0 : pState->mnState |= SAL_FRAMESTATE_ROLLUP;
1744 : :
1745 : 0 : pState->mnX = aPosSize.Left();
1746 : 0 : pState->mnY = aPosSize.Top();
1747 : 0 : pState->mnWidth = aPosSize.GetWidth();
1748 : 0 : pState->mnHeight = aPosSize.GetHeight();
1749 : :
1750 : 0 : pState->mnMask = _FRAMESTATE_MASK_GEOMETRY | SAL_FRAMESTATE_MASK_STATE;
1751 : :
1752 : :
1753 : 0 : if (! maRestorePosSize.IsEmpty() )
1754 : : {
1755 : 0 : GetPosSize( aPosSize );
1756 : 0 : pState->mnState |= SAL_FRAMESTATE_MAXIMIZED;
1757 : 0 : pState->mnMaximizedX = aPosSize.Left();
1758 : 0 : pState->mnMaximizedY = aPosSize.Top();
1759 : 0 : pState->mnMaximizedWidth = aPosSize.GetWidth();
1760 : 0 : pState->mnMaximizedHeight = aPosSize.GetHeight();
1761 : 0 : pState->mnMask |= _FRAMESTATE_MASK_MAXIMIZED_GEOMETRY;
1762 : : }
1763 : :
1764 : 0 : return sal_True;
1765 : : }
1766 : :
1767 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1768 : :
1769 : : // native menu implementation - currently empty
1770 : 0 : void X11SalFrame::DrawMenuBar()
1771 : : {
1772 : 0 : }
1773 : :
1774 : 0 : void X11SalFrame::SetMenu( SalMenu* )
1775 : : {
1776 : 0 : }
1777 : :
1778 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1779 : 0 : void X11SalFrame::GetPosSize( Rectangle &rPosSize )
1780 : : {
1781 : 0 : if( maGeometry.nWidth < 1 || maGeometry.nHeight < 1 )
1782 : : {
1783 : 0 : const Size& aScreenSize = pDisplay_->getDataForScreen( m_nXScreen ).m_aSize;
1784 : 0 : long w = aScreenSize.Width() - maGeometry.nLeftDecoration - maGeometry.nRightDecoration;
1785 : 0 : long h = aScreenSize.Height() - maGeometry.nTopDecoration - maGeometry.nBottomDecoration;
1786 : :
1787 : 0 : rPosSize = Rectangle( Point( maGeometry.nX, maGeometry.nY ), Size( w, h ) );
1788 : : }
1789 : : else
1790 : : rPosSize = Rectangle( Point( maGeometry.nX, maGeometry.nY ),
1791 : 0 : Size( maGeometry.nWidth, maGeometry.nHeight ) );
1792 : 0 : }
1793 : :
1794 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1795 : 0 : void X11SalFrame::SetSize( const Size &rSize )
1796 : : {
1797 : 0 : if( rSize.Width() > 0 && rSize.Height() > 0 )
1798 : : {
1799 : 0 : if( ! ( nStyle_ & SAL_FRAME_STYLE_SIZEABLE )
1800 : 0 : && ! IsChildWindow()
1801 : : && ( nStyle_ & (SAL_FRAME_STYLE_FLOAT|SAL_FRAME_STYLE_OWNERDRAWDECORATION) ) != SAL_FRAME_STYLE_FLOAT )
1802 : : {
1803 : 0 : XSizeHints* pHints = XAllocSizeHints();
1804 : 0 : long nSupplied = 0;
1805 : : XGetWMNormalHints( GetXDisplay(),
1806 : : GetShellWindow(),
1807 : : pHints,
1808 : : &nSupplied
1809 : 0 : );
1810 : 0 : pHints->min_width = rSize.Width();
1811 : 0 : pHints->min_height = rSize.Height();
1812 : 0 : pHints->max_width = rSize.Width();
1813 : 0 : pHints->max_height = rSize.Height();
1814 : 0 : pHints->flags |= PMinSize | PMaxSize;
1815 : : XSetWMNormalHints( GetXDisplay(),
1816 : : GetShellWindow(),
1817 : 0 : pHints );
1818 : 0 : XFree( pHints );
1819 : : }
1820 : 0 : XResizeWindow( GetXDisplay(), IsSysChildWindow() ? GetWindow() : GetShellWindow(), rSize.Width(), rSize.Height() );
1821 : 0 : if( GetWindow() != GetShellWindow() )
1822 : : {
1823 : 0 : if( (nStyle_ & SAL_FRAME_STYLE_PLUG ) )
1824 : 0 : XMoveResizeWindow( GetXDisplay(), GetWindow(), 0, 0, rSize.Width(), rSize.Height() );
1825 : : else
1826 : 0 : XResizeWindow( GetXDisplay(), GetWindow(), rSize.Width(), rSize.Height() );
1827 : : }
1828 : :
1829 : 0 : maGeometry.nWidth = rSize.Width();
1830 : 0 : maGeometry.nHeight = rSize.Height();
1831 : :
1832 : : // allow the external status window to reposition
1833 : 0 : if (mbInputFocus && mpInputContext != NULL)
1834 : 0 : mpInputContext->SetICFocus ( this );
1835 : : }
1836 : 0 : }
1837 : :
1838 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1839 : :
1840 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1841 : :
1842 : 0 : void X11SalFrame::SetPosSize( const Rectangle &rPosSize )
1843 : : {
1844 : : XWindowChanges values;
1845 : 0 : values.x = rPosSize.Left();
1846 : 0 : values.y = rPosSize.Top();
1847 : 0 : values.width = rPosSize.GetWidth();
1848 : 0 : values.height = rPosSize.GetHeight();
1849 : :
1850 : 0 : if( !values.width || !values.height )
1851 : 0 : return;
1852 : :
1853 : 0 : if( mpParent && ! IsSysChildWindow() )
1854 : : {
1855 : : // --- RTL --- (mirror window pos)
1856 : 0 : if( Application::GetSettings().GetLayoutRTL() )
1857 : 0 : values.x = mpParent->maGeometry.nWidth-values.width-1-values.x;
1858 : :
1859 : : XLIB_Window aChild;
1860 : : // coordinates are relative to parent, so translate to root coordinates
1861 : : XTranslateCoordinates( GetDisplay()->GetDisplay(),
1862 : : mpParent->GetWindow(),
1863 : : GetDisplay()->GetRootWindow( m_nXScreen ),
1864 : : values.x, values.y,
1865 : : &values.x, &values.y,
1866 : 0 : & aChild );
1867 : : }
1868 : :
1869 : 0 : bool bMoved = false;
1870 : 0 : bool bSized = false;
1871 : 0 : if( values.x != maGeometry.nX || values.y != maGeometry.nY )
1872 : 0 : bMoved = true;
1873 : 0 : if( values.width != (int)maGeometry.nWidth || values.height != (int)maGeometry.nHeight )
1874 : 0 : bSized = true;
1875 : :
1876 : 0 : if( ! ( nStyle_ & ( SAL_FRAME_STYLE_PLUG | SAL_FRAME_STYLE_FLOAT ) )
1877 : 0 : && !(pDisplay_->GetProperties() & PROPERTY_SUPPORT_WM_ClientPos) )
1878 : : {
1879 : 0 : values.x -= maGeometry.nLeftDecoration;
1880 : 0 : values.y -= maGeometry.nTopDecoration;
1881 : : }
1882 : :
1883 : : // do net set WMNormalHints for ..
1884 : 0 : if(
1885 : : // child windows
1886 : 0 : ! IsChildWindow()
1887 : : // popups (menu, help window, etc.)
1888 : : && (nStyle_ & (SAL_FRAME_STYLE_FLOAT|SAL_FRAME_STYLE_OWNERDRAWDECORATION) ) != SAL_FRAME_STYLE_FLOAT
1889 : : // shown, sizeable windows
1890 : : && ( nShowState_ == SHOWSTATE_UNKNOWN ||
1891 : : nShowState_ == SHOWSTATE_HIDDEN ||
1892 : 0 : ! ( nStyle_ & SAL_FRAME_STYLE_SIZEABLE )
1893 : : )
1894 : : )
1895 : : {
1896 : 0 : XSizeHints* pHints = XAllocSizeHints();
1897 : 0 : long nSupplied = 0;
1898 : : XGetWMNormalHints( GetXDisplay(),
1899 : : GetShellWindow(),
1900 : : pHints,
1901 : : &nSupplied
1902 : 0 : );
1903 : 0 : if( ! ( nStyle_ & SAL_FRAME_STYLE_SIZEABLE ) )
1904 : : {
1905 : 0 : pHints->min_width = rPosSize.GetWidth();
1906 : 0 : pHints->min_height = rPosSize.GetHeight();
1907 : 0 : pHints->max_width = rPosSize.GetWidth();
1908 : 0 : pHints->max_height = rPosSize.GetHeight();
1909 : 0 : pHints->flags |= PMinSize | PMaxSize;
1910 : : }
1911 : 0 : if( nShowState_ == SHOWSTATE_UNKNOWN || nShowState_ == SHOWSTATE_HIDDEN )
1912 : : {
1913 : 0 : pHints->flags |= PPosition | PWinGravity;
1914 : 0 : pHints->x = values.x;
1915 : 0 : pHints->y = values.y;
1916 : 0 : pHints->win_gravity = pDisplay_->getWMAdaptor()->getPositionWinGravity();
1917 : : }
1918 : 0 : if( mbFullScreen )
1919 : : {
1920 : 0 : pHints->max_width = 10000;
1921 : 0 : pHints->max_height = 10000;
1922 : 0 : pHints->flags |= PMaxSize;
1923 : : }
1924 : : XSetWMNormalHints( GetXDisplay(),
1925 : : GetShellWindow(),
1926 : 0 : pHints );
1927 : 0 : XFree( pHints );
1928 : : }
1929 : :
1930 : 0 : XMoveResizeWindow( GetXDisplay(), IsSysChildWindow() ? GetWindow() : GetShellWindow(), values.x, values.y, values.width, values.height );
1931 : 0 : if( GetShellWindow() != GetWindow() )
1932 : : {
1933 : 0 : if( (nStyle_ & SAL_FRAME_STYLE_PLUG ) )
1934 : 0 : XMoveResizeWindow( GetXDisplay(), GetWindow(), 0, 0, values.width, values.height );
1935 : : else
1936 : 0 : XMoveResizeWindow( GetXDisplay(), GetWindow(), values.x, values.y, values.width, values.height );
1937 : : }
1938 : :
1939 : 0 : maGeometry.nX = values.x;
1940 : 0 : maGeometry.nY = values.y;
1941 : 0 : maGeometry.nWidth = values.width;
1942 : 0 : maGeometry.nHeight = values.height;
1943 : 0 : if( IsSysChildWindow() && mpParent )
1944 : : {
1945 : : // translate back to root coordinates
1946 : 0 : maGeometry.nX += mpParent->maGeometry.nX;
1947 : 0 : maGeometry.nY += mpParent->maGeometry.nY;
1948 : : }
1949 : :
1950 : 0 : updateScreenNumber();
1951 : 0 : if( bSized && ! bMoved )
1952 : 0 : CallCallback( SALEVENT_RESIZE, NULL );
1953 : 0 : else if( bMoved && ! bSized )
1954 : 0 : CallCallback( SALEVENT_MOVE, NULL );
1955 : : else
1956 : 0 : CallCallback( SALEVENT_MOVERESIZE, NULL );
1957 : :
1958 : : // allow the external status window to reposition
1959 : 0 : if (mbInputFocus && mpInputContext != NULL)
1960 : 0 : mpInputContext->SetICFocus ( this );
1961 : : }
1962 : :
1963 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1964 : 0 : void X11SalFrame::Minimize()
1965 : : {
1966 : 0 : if( IsSysChildWindow() )
1967 : 0 : return;
1968 : :
1969 : 0 : if( SHOWSTATE_UNKNOWN == nShowState_ || SHOWSTATE_HIDDEN == nShowState_ )
1970 : : {
1971 : : stderr0( "X11SalFrame::Minimize on withdrawn window\n" );
1972 : 0 : return;
1973 : : }
1974 : :
1975 : 0 : if( XIconifyWindow( GetXDisplay(),
1976 : : GetShellWindow(),
1977 : 0 : pDisplay_->GetDefaultXScreen().getXScreen() ) )
1978 : 0 : nShowState_ = SHOWSTATE_MINIMIZED;
1979 : : }
1980 : :
1981 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1982 : 0 : void X11SalFrame::Maximize()
1983 : : {
1984 : 0 : if( IsSysChildWindow() )
1985 : 0 : return;
1986 : :
1987 : 0 : if( SHOWSTATE_MINIMIZED == nShowState_ )
1988 : : {
1989 : 0 : GetDisplay()->getWMAdaptor()->frameIsMapping( this );
1990 : 0 : XMapWindow( GetXDisplay(), GetShellWindow() );
1991 : 0 : nShowState_ = SHOWSTATE_NORMAL;
1992 : : }
1993 : :
1994 : 0 : pDisplay_->getWMAdaptor()->maximizeFrame( this, true, true );
1995 : : }
1996 : :
1997 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1998 : 0 : void X11SalFrame::Restore()
1999 : : {
2000 : 0 : if( IsSysChildWindow() )
2001 : 0 : return;
2002 : :
2003 : 0 : if( SHOWSTATE_UNKNOWN == nShowState_ || SHOWSTATE_HIDDEN == nShowState_ )
2004 : : {
2005 : : stderr0( "X11SalFrame::Restore on withdrawn window\n" );
2006 : 0 : return;
2007 : : }
2008 : :
2009 : 0 : if( SHOWSTATE_MINIMIZED == nShowState_ )
2010 : : {
2011 : 0 : GetDisplay()->getWMAdaptor()->frameIsMapping( this );
2012 : 0 : XMapWindow( GetXDisplay(), GetShellWindow() );
2013 : 0 : nShowState_ = SHOWSTATE_NORMAL;
2014 : : }
2015 : :
2016 : 0 : pDisplay_->getWMAdaptor()->maximizeFrame( this, false, false );
2017 : : }
2018 : :
2019 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2020 : :
2021 : 0 : void X11SalFrame::SetScreenNumber( unsigned int nNewScreen )
2022 : : {
2023 : 0 : if( nNewScreen == maGeometry.nDisplayScreenNumber )
2024 : 0 : return;
2025 : :
2026 : 0 : if( GetDisplay()->IsXinerama() && GetDisplay()->GetXineramaScreens().size() > 1 )
2027 : : {
2028 : 0 : if( nNewScreen >= GetDisplay()->GetXineramaScreens().size() )
2029 : : return;
2030 : :
2031 : 0 : Rectangle aOldScreenRect( GetDisplay()->GetXineramaScreens()[maGeometry.nDisplayScreenNumber] );
2032 : 0 : Rectangle aNewScreenRect( GetDisplay()->GetXineramaScreens()[nNewScreen] );
2033 : 0 : bool bVisible = bMapped_;
2034 : 0 : if( bVisible )
2035 : 0 : Show( sal_False );
2036 : 0 : maGeometry.nX = aNewScreenRect.Left() + (maGeometry.nX - aOldScreenRect.Left());
2037 : 0 : maGeometry.nY = aNewScreenRect.Top() + (maGeometry.nY - aOldScreenRect.Top());
2038 : 0 : createNewWindow( None, m_nXScreen );
2039 : 0 : if( bVisible )
2040 : 0 : Show( sal_True );
2041 : 0 : maGeometry.nDisplayScreenNumber = nNewScreen;
2042 : : }
2043 : 0 : else if( nNewScreen < GetDisplay()->GetXScreenCount() )
2044 : : {
2045 : 0 : bool bVisible = bMapped_;
2046 : 0 : if( bVisible )
2047 : 0 : Show( sal_False );
2048 : 0 : createNewWindow( None, SalX11Screen( nNewScreen ) );
2049 : 0 : if( bVisible )
2050 : 0 : Show( sal_True );
2051 : 0 : maGeometry.nDisplayScreenNumber = nNewScreen;
2052 : : }
2053 : : }
2054 : :
2055 : 0 : void X11SalFrame::SetApplicationID( const rtl::OUString &rWMClass )
2056 : : {
2057 : 0 : if( rWMClass != m_sWMClass && ! IsChildWindow() )
2058 : : {
2059 : 0 : m_sWMClass = rWMClass;
2060 : 0 : updateWMClass();
2061 : 0 : std::list< X11SalFrame* >::const_iterator it;
2062 : 0 : for( it = maChildren.begin(); it != maChildren.end(); ++it )
2063 : 0 : (*it)->SetApplicationID(rWMClass);
2064 : : }
2065 : 0 : }
2066 : :
2067 : 0 : void X11SalFrame::updateWMClass()
2068 : : {
2069 : 0 : XClassHint* pClass = XAllocClassHint();
2070 : 0 : rtl::OString aResName = SalGenericSystem::getFrameResName( mnExtStyle );
2071 : 0 : pClass->res_name = const_cast<char*>(aResName.getStr());
2072 : :
2073 : 0 : rtl::OString aResClass = rtl::OUStringToOString(m_sWMClass, RTL_TEXTENCODING_ASCII_US);
2074 : 0 : const char *pResClass = !aResClass.isEmpty() ? aResClass.getStr() :
2075 : 0 : SalGenericSystem::getFrameClassName();
2076 : :
2077 : 0 : pClass->res_class = const_cast<char*>(pResClass);
2078 : 0 : XSetClassHint( GetXDisplay(), GetShellWindow(), pClass );
2079 : 0 : XFree( pClass );
2080 : 0 : }
2081 : :
2082 : :
2083 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2084 : :
2085 : 0 : void X11SalFrame::ShowFullScreen( sal_Bool bFullScreen, sal_Int32 nScreen )
2086 : : {
2087 : 0 : if( GetDisplay()->IsXinerama() && GetDisplay()->GetXineramaScreens().size() > 1 )
2088 : : {
2089 : 0 : if( mbFullScreen == (bool)bFullScreen )
2090 : 0 : return;
2091 : 0 : if( bFullScreen )
2092 : : {
2093 : : maRestorePosSize = Rectangle( Point( maGeometry.nX, maGeometry.nY ),
2094 : 0 : Size( maGeometry.nWidth, maGeometry.nHeight ) );
2095 : 0 : Rectangle aRect;
2096 : 0 : if( nScreen < 0 || nScreen >= static_cast<int>(GetDisplay()->GetXineramaScreens().size()) )
2097 : 0 : aRect = Rectangle( Point(0,0), GetDisplay()->GetScreenSize( m_nXScreen ) );
2098 : : else
2099 : 0 : aRect = GetDisplay()->GetXineramaScreens()[nScreen];
2100 : 0 : nStyle_ |= SAL_FRAME_STYLE_PARTIAL_FULLSCREEN;
2101 : 0 : bool bVisible = bMapped_;
2102 : 0 : if( bVisible )
2103 : 0 : Show( sal_False );
2104 : 0 : maGeometry.nX = aRect.Left();
2105 : 0 : maGeometry.nY = aRect.Top();
2106 : 0 : maGeometry.nWidth = aRect.GetWidth();
2107 : 0 : maGeometry.nHeight = aRect.GetHeight();
2108 : 0 : mbMaximizedHorz = mbMaximizedVert = false;
2109 : 0 : mbFullScreen = true;
2110 : 0 : createNewWindow( None, m_nXScreen );
2111 : 0 : if( GetDisplay()->getWMAdaptor()->isLegacyPartialFullscreen() )
2112 : 0 : GetDisplay()->getWMAdaptor()->enableAlwaysOnTop( this, true );
2113 : : else
2114 : 0 : GetDisplay()->getWMAdaptor()->showFullScreen( this, true );
2115 : 0 : if( bVisible )
2116 : 0 : Show(sal_True);
2117 : :
2118 : : }
2119 : : else
2120 : : {
2121 : 0 : mbFullScreen = false;
2122 : 0 : nStyle_ &= ~SAL_FRAME_STYLE_PARTIAL_FULLSCREEN;
2123 : 0 : bool bVisible = bMapped_;
2124 : 0 : Rectangle aRect = maRestorePosSize;
2125 : 0 : maRestorePosSize = Rectangle();
2126 : 0 : if( bVisible )
2127 : 0 : Show( sal_False );
2128 : 0 : createNewWindow( None, m_nXScreen );
2129 : 0 : if( !aRect.IsEmpty() )
2130 : 0 : SetPosSize( aRect.Left(), aRect.Top(), aRect.GetWidth(), aRect.GetHeight(),
2131 : : SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y |
2132 : 0 : SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
2133 : 0 : if( bVisible )
2134 : 0 : Show( sal_True );
2135 : : }
2136 : : }
2137 : : else
2138 : : {
2139 : 0 : if( nScreen < 0 || nScreen >= (int)GetDisplay()->GetXScreenCount() )
2140 : 0 : nScreen = m_nXScreen.getXScreen();
2141 : 0 : if( nScreen != (int)m_nXScreen.getXScreen() )
2142 : : {
2143 : 0 : bool bVisible = bMapped_;
2144 : 0 : if( mbFullScreen )
2145 : 0 : pDisplay_->getWMAdaptor()->showFullScreen( this, false );
2146 : 0 : if( bVisible )
2147 : 0 : Show( sal_False );
2148 : 0 : createNewWindow( None, SalX11Screen( nScreen ) );
2149 : 0 : if( mbFullScreen )
2150 : 0 : pDisplay_->getWMAdaptor()->showFullScreen( this, true );
2151 : 0 : if( bVisible )
2152 : 0 : Show( sal_True );
2153 : : }
2154 : 0 : if( mbFullScreen == (bool)bFullScreen )
2155 : 0 : return;
2156 : :
2157 : 0 : pDisplay_->getWMAdaptor()->showFullScreen( this, bFullScreen );
2158 : 0 : if( IsOverrideRedirect()
2159 : 0 : && WMSupportsFWS( GetXDisplay(), GetDisplay()->GetRootWindow( m_nXScreen ) ) )
2160 : : {
2161 : 0 : AddFwsProtocols( GetXDisplay(), GetShellWindow() );
2162 : 0 : RegisterFwsWindow( GetXDisplay(), GetShellWindow() );
2163 : : }
2164 : : }
2165 : : }
2166 : :
2167 : : /* ---------------------------------------------------------------------
2168 : : the xautolock pseudo screen saver needs special treatment since it
2169 : : doesn't cooperate with XxxxScreenSaver settings
2170 : : ------------------------------------------------------------------- */
2171 : :
2172 : : static Bool
2173 : 0 : IsRunningXAutoLock( Display *p_display, XLIB_Window a_window )
2174 : : {
2175 : 0 : const char *p_atomname = "XAUTOLOCK_SEMAPHORE_PID";
2176 : : Atom a_pidatom;
2177 : :
2178 : : // xautolock interns this atom
2179 : 0 : a_pidatom = XInternAtom( p_display, p_atomname, True );
2180 : 0 : if ( a_pidatom == None )
2181 : 0 : return False;
2182 : :
2183 : : Atom a_type;
2184 : : int n_format;
2185 : : unsigned long n_items;
2186 : : unsigned long n_bytes_after;
2187 : : pid_t *p_pid;
2188 : : pid_t n_pid;
2189 : : // get pid of running xautolock
2190 : : XGetWindowProperty (p_display, a_window, a_pidatom, 0L, 2L, False,
2191 : : AnyPropertyType, &a_type, &n_format, &n_items, &n_bytes_after,
2192 : 0 : (unsigned char**) &p_pid );
2193 : 0 : n_pid = *p_pid;
2194 : 0 : XFree( p_pid );
2195 : :
2196 : 0 : if ( a_type == XA_INTEGER )
2197 : : {
2198 : : // check if xautolock pid points to a running process
2199 : 0 : if ( kill(n_pid, 0) == -1 )
2200 : 0 : return False;
2201 : : else
2202 : 0 : return True;
2203 : : }
2204 : :
2205 : 0 : return False;
2206 : : }
2207 : :
2208 : : /* definitions from xautolock.c (pl15) */
2209 : : #define XAUTOLOCK_DISABLE 1
2210 : : #define XAUTOLOCK_ENABLE 2
2211 : :
2212 : : static Bool
2213 : 0 : MessageToXAutoLock( Display *p_display, int n_message )
2214 : : {
2215 : 0 : const char *p_atomname = "XAUTOLOCK_MESSAGE" ;
2216 : : Atom a_messageatom;
2217 : : XLIB_Window a_rootwindow;
2218 : :
2219 : 0 : a_rootwindow = RootWindowOfScreen( ScreenOfDisplay(p_display, 0) );
2220 : 0 : if ( ! IsRunningXAutoLock(p_display, a_rootwindow) )
2221 : : {
2222 : : // remove any pending messages
2223 : 0 : a_messageatom = XInternAtom( p_display, p_atomname, True );
2224 : 0 : if ( a_messageatom != None )
2225 : 0 : XDeleteProperty( p_display, a_rootwindow, a_messageatom );
2226 : 0 : return False;
2227 : : }
2228 : :
2229 : 0 : a_messageatom = XInternAtom( p_display, p_atomname, False );
2230 : : XChangeProperty (p_display, a_rootwindow, a_messageatom, XA_INTEGER,
2231 : 0 : 8, PropModeReplace, (unsigned char*)&n_message, sizeof(n_message) );
2232 : :
2233 : 0 : return True;
2234 : : }
2235 : :
2236 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2237 : 0 : void X11SalFrame::StartPresentation( sal_Bool bStart )
2238 : : {
2239 : 0 : I18NStatus::get().show( !bStart, I18NStatus::presentation );
2240 : 0 : if ( bStart )
2241 : 0 : MessageToXAutoLock( GetXDisplay(), XAUTOLOCK_DISABLE );
2242 : : else
2243 : 0 : MessageToXAutoLock( GetXDisplay(), XAUTOLOCK_ENABLE );
2244 : :
2245 : 0 : if( ! bStart && hPresentationWindow != None )
2246 : 0 : doReparentPresentationDialogues( GetDisplay() );
2247 : 0 : hPresentationWindow = (bStart && IsOverrideRedirect() ) ? GetWindow() : None;
2248 : :
2249 : :
2250 : : // needs static here to save DPMS settings
2251 : : int dummy;
2252 : : static bool DPMSExtensionAvailable =
2253 : : #if !defined(SOLARIS) && !defined(AIX)
2254 : 0 : (DPMSQueryExtension(GetXDisplay(), &dummy, &dummy) != 0);
2255 : : static sal_Bool DPMSEnabled = false;
2256 : : #else
2257 : : false;
2258 : : bool DPMSEnabled = false;
2259 : : (void)dummy;
2260 : : #define CARD16 unsigned short
2261 : : #endif
2262 : : static CARD16 dpms_standby_timeout=0;
2263 : : static CARD16 dpms_suspend_timeout=0;
2264 : : static CARD16 dpms_off_timeout=0;
2265 : :
2266 : :
2267 : 0 : if( bStart || nScreenSaversTimeout_ || DPMSEnabled)
2268 : : {
2269 : 0 : if( hPresentationWindow )
2270 : : {
2271 : : /* #i10559# workaround for WindowMaker: try to restore
2272 : : * current focus after presentation window is gone
2273 : : */
2274 : 0 : int revert_to = 0;
2275 : 0 : XGetInputFocus( GetXDisplay(), &hPresFocusWindow, &revert_to );
2276 : : }
2277 : : int timeout, interval, prefer_blanking, allow_exposures;
2278 : : XGetScreenSaver( GetXDisplay(),
2279 : : &timeout,
2280 : : &interval,
2281 : : &prefer_blanking,
2282 : 0 : &allow_exposures );
2283 : :
2284 : :
2285 : : // get the DPMS state right before the start
2286 : 0 : if (DPMSExtensionAvailable)
2287 : : {
2288 : : #if !defined(SOLARIS) && !defined(AIX)
2289 : : CARD16 state; // card16 is defined in Xdm.h
2290 : : DPMSInfo( GetXDisplay(),
2291 : : &state,
2292 : 0 : &DPMSEnabled);
2293 : : #endif
2294 : : }
2295 : 0 : if( bStart ) // start show
2296 : : {
2297 : 0 : if ( timeout )
2298 : : {
2299 : 0 : nScreenSaversTimeout_ = timeout;
2300 : 0 : XResetScreenSaver( GetXDisplay() );
2301 : : XSetScreenSaver( GetXDisplay(),
2302 : : 0,
2303 : : interval,
2304 : : prefer_blanking,
2305 : 0 : allow_exposures );
2306 : : }
2307 : : #if !defined(SOLARIS) && !defined(AIX)
2308 : 0 : if( DPMSEnabled )
2309 : : {
2310 : 0 : if ( DPMSExtensionAvailable )
2311 : : {
2312 : : DPMSGetTimeouts( GetXDisplay(),
2313 : : &dpms_standby_timeout,
2314 : : &dpms_suspend_timeout,
2315 : 0 : &dpms_off_timeout);
2316 : 0 : DPMSSetTimeouts(GetXDisplay(), 0,0,0);
2317 : : }
2318 : : }
2319 : : #endif
2320 : : }
2321 : : else
2322 : : {
2323 : 0 : if( nScreenSaversTimeout_ )
2324 : : {
2325 : : XSetScreenSaver( GetXDisplay(),
2326 : : nScreenSaversTimeout_,
2327 : : interval,
2328 : : prefer_blanking,
2329 : 0 : allow_exposures );
2330 : 0 : nScreenSaversTimeout_ = 0;
2331 : : }
2332 : : #if !defined(SOLARIS) && !defined(AIX)
2333 : 0 : if ( DPMSEnabled )
2334 : : {
2335 : 0 : if ( DPMSExtensionAvailable )
2336 : : {
2337 : : // restore timeouts
2338 : : DPMSSetTimeouts(GetXDisplay(), dpms_standby_timeout,
2339 : 0 : dpms_suspend_timeout, dpms_off_timeout);
2340 : : }
2341 : : }
2342 : : #endif
2343 : : }
2344 : : }
2345 : 0 : }
2346 : :
2347 : : // Pointer
2348 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2349 : 0 : void X11SalFrame::SetPointer( PointerStyle ePointerStyle )
2350 : : {
2351 : 0 : hCursor_ = pDisplay_->GetPointer( ePointerStyle );
2352 : 0 : XDefineCursor( GetXDisplay(), GetWindow(), hCursor_ );
2353 : :
2354 : 0 : if( IsCaptured() || nVisibleFloats > 0 )
2355 : : XChangeActivePointerGrab( GetXDisplay(),
2356 : : PointerMotionMask|ButtonPressMask|ButtonReleaseMask,
2357 : : hCursor_,
2358 : 0 : CurrentTime );
2359 : 0 : }
2360 : :
2361 : 0 : void X11SalFrame::SetPointerPos(long nX, long nY)
2362 : : {
2363 : : /* when the application tries to center the mouse in the dialog the
2364 : : * window isn't mapped already. So use coordinates relative to the root window.
2365 : : */
2366 : 0 : unsigned int nWindowLeft = maGeometry.nX + nX;
2367 : 0 : unsigned int nWindowTop = maGeometry.nY + nY;
2368 : :
2369 : : XWarpPointer( GetXDisplay(), None, pDisplay_->GetRootWindow( pDisplay_->GetDefaultXScreen() ),
2370 : 0 : 0, 0, 0, 0, nWindowLeft, nWindowTop);
2371 : 0 : }
2372 : :
2373 : : // delay handling of extended text input
2374 : : #if !defined(__synchronous_extinput__)
2375 : : void
2376 : 0 : X11SalFrame::HandleExtTextEvent (XClientMessageEvent *pEvent)
2377 : : {
2378 : : #if SAL_TYPES_SIZEOFLONG > 4
2379 : : void* pExtTextEvent = (void*)( (pEvent->data.l[0] & 0xffffffff)
2380 : : | (pEvent->data.l[1] << 32) );
2381 : : #else
2382 : 0 : void* pExtTextEvent = (void*)(pEvent->data.l[0]);
2383 : : #endif
2384 : 0 : sal_uInt16 nExtTextEventType = sal_uInt16(pEvent->data.l[2]);
2385 : :
2386 : 0 : CallCallback(nExtTextEventType, pExtTextEvent);
2387 : :
2388 : 0 : switch (nExtTextEventType)
2389 : : {
2390 : : case SALEVENT_ENDEXTTEXTINPUT:
2391 : 0 : break;
2392 : :
2393 : : case SALEVENT_EXTTEXTINPUT:
2394 : 0 : break;
2395 : :
2396 : : default:
2397 : :
2398 : 0 : fprintf(stderr, "X11SalFrame::HandleExtTextEvent: invalid extended input\n");
2399 : : }
2400 : 0 : }
2401 : : #endif /* defined(__synchronous_extinput__) */
2402 : :
2403 : : // PostEvent
2404 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2405 : 0 : sal_Bool X11SalFrame::PostEvent( void *pData )
2406 : : {
2407 : 0 : GetDisplay()->SendInternalEvent( this, pData );
2408 : 0 : return sal_True;
2409 : : }
2410 : :
2411 : : // Title
2412 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2413 : 0 : void X11SalFrame::SetTitle( const rtl::OUString& rTitle )
2414 : : {
2415 : 0 : if( ! ( IsChildWindow() || (nStyle_ & SAL_FRAME_STYLE_FLOAT ) ) )
2416 : : {
2417 : 0 : m_aTitle = rTitle;
2418 : 0 : GetDisplay()->getWMAdaptor()->setWMName( this, rTitle );
2419 : : }
2420 : 0 : }
2421 : :
2422 : : // -----------------------------------------------------------------------
2423 : :
2424 : 0 : void X11SalFrame::Flush()
2425 : : {
2426 : 0 : XFlush( GetDisplay()->GetDisplay() );
2427 : 0 : }
2428 : :
2429 : : // -----------------------------------------------------------------------
2430 : :
2431 : 0 : void X11SalFrame::Sync()
2432 : : {
2433 : 0 : XSync( GetDisplay()->GetDisplay(), False );
2434 : 0 : }
2435 : :
2436 : : // Keyboard
2437 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2438 : :
2439 : : // -----------------------------------------------------------------------
2440 : :
2441 : 0 : void X11SalFrame::SetInputContext( SalInputContext* pContext )
2442 : : {
2443 : 0 : if (pContext == NULL)
2444 : 0 : return;
2445 : :
2446 : : // 1. We should create an input context for this frame
2447 : : // only when SAL_INPUTCONTEXT_TEXT is set.
2448 : :
2449 : 0 : if (!(pContext->mnOptions & SAL_INPUTCONTEXT_TEXT))
2450 : : {
2451 : 0 : if( mpInputContext )
2452 : 0 : mpInputContext->Unmap( this );
2453 : 0 : return;
2454 : : }
2455 : :
2456 : : // 2. We should use on-the-spot inputstyle
2457 : : // only when SAL_INPUTCONTEXT_EXTTEXTINPUT is set.
2458 : :
2459 : 0 : if (mpInputContext == NULL)
2460 : : {
2461 : 0 : I18NStatus& rStatus( I18NStatus::get() );
2462 : 0 : rStatus.setParent( this );
2463 : 0 : mpInputContext = new SalI18N_InputContext( this );
2464 : 0 : if (mpInputContext->UseContext())
2465 : : {
2466 : 0 : mpInputContext->ExtendEventMask( GetShellWindow() );
2467 : 0 : if (pContext->mnOptions & SAL_INPUTCONTEXT_CHANGELANGUAGE)
2468 : 0 : mpInputContext->SetLanguage(pContext->meLanguage);
2469 : 0 : if (mbInputFocus)
2470 : 0 : mpInputContext->SetICFocus( this );
2471 : : }
2472 : : }
2473 : : else
2474 : 0 : mpInputContext->Map( this );
2475 : 0 : return;
2476 : : }
2477 : :
2478 : : // -----------------------------------------------------------------------
2479 : :
2480 : 0 : void X11SalFrame::EndExtTextInput( sal_uInt16 nFlags )
2481 : : {
2482 : 0 : if (mpInputContext != NULL)
2483 : 0 : mpInputContext->EndExtTextInput( nFlags );
2484 : 0 : }
2485 : :
2486 : : // -----------------------------------------------------------------------
2487 : :
2488 : 0 : rtl::OUString X11SalFrame::GetKeyName( sal_uInt16 nKeyCode )
2489 : : {
2490 : 0 : return GetDisplay()->GetKeyName( nKeyCode );
2491 : : }
2492 : :
2493 : 0 : sal_Bool X11SalFrame::MapUnicodeToKeyCode( sal_Unicode , LanguageType , KeyCode& )
2494 : : {
2495 : : // not supported yet
2496 : 0 : return sal_False;
2497 : : }
2498 : :
2499 : 0 : LanguageType X11SalFrame::GetInputLanguage()
2500 : : {
2501 : : // could be improved by checking unicode ranges of the last input
2502 : 0 : return LANGUAGE_DONTKNOW;
2503 : : }
2504 : :
2505 : : // Settings
2506 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2507 : :
2508 : : inline Color getColorFromLong( long nColor )
2509 : : {
2510 : : return Color( (nColor & 0xff), (nColor & 0xff00)>>8, (nColor & 0xff0000)>>16);
2511 : : }
2512 : :
2513 : 0 : void X11SalFrame::UpdateSettings( AllSettings& rSettings )
2514 : : {
2515 : 0 : StyleSettings aStyleSettings = rSettings.GetStyleSettings();
2516 : 0 : aStyleSettings.SetCursorBlinkTime( 500 );
2517 : 0 : rSettings.SetStyleSettings( aStyleSettings );
2518 : 0 : }
2519 : :
2520 : 0 : void X11SalFrame::CaptureMouse( sal_Bool bCapture )
2521 : : {
2522 : 0 : nCaptured_ = pDisplay_->CaptureMouse( bCapture ? this : NULL );
2523 : 0 : }
2524 : :
2525 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2526 : :
2527 : 0 : void X11SalFrame::SetParent( SalFrame* pNewParent )
2528 : : {
2529 : 0 : if( mpParent != pNewParent )
2530 : : {
2531 : 0 : if( mpParent )
2532 : 0 : mpParent->maChildren.remove( this );
2533 : :
2534 : 0 : mpParent = static_cast<X11SalFrame*>(pNewParent);
2535 : 0 : mpParent->maChildren.push_back( this );
2536 : 0 : if( mpParent->m_nXScreen != m_nXScreen )
2537 : 0 : createNewWindow( None, mpParent->m_nXScreen );
2538 : 0 : GetDisplay()->getWMAdaptor()->changeReferenceFrame( this, mpParent );
2539 : : }
2540 : 0 : }
2541 : :
2542 : 0 : SalFrame* X11SalFrame::GetParent() const
2543 : : {
2544 : 0 : return mpParent;
2545 : : }
2546 : :
2547 : 0 : void X11SalFrame::createNewWindow( XLIB_Window aNewParent, SalX11Screen nXScreen )
2548 : : {
2549 : 0 : bool bWasVisible = bMapped_;
2550 : 0 : if( bWasVisible )
2551 : 0 : Show( sal_False );
2552 : :
2553 : 0 : if( nXScreen.getXScreen() >= GetDisplay()->GetXScreenCount() )
2554 : 0 : nXScreen = m_nXScreen;
2555 : :
2556 : : SystemParentData aParentData;
2557 : 0 : aParentData.aWindow = aNewParent;
2558 : 0 : aParentData.bXEmbedSupport = (aNewParent != None && m_bXEmbed); // caution: this is guesswork
2559 : 0 : if( aNewParent == None )
2560 : : {
2561 : 0 : aNewParent = GetDisplay()->GetRootWindow(nXScreen);
2562 : 0 : aParentData.aWindow = None;
2563 : 0 : m_bXEmbed = false;
2564 : : }
2565 : : else
2566 : : {
2567 : : // is new parent a root window ?
2568 : 0 : Display* pDisp = GetDisplay()->GetDisplay();
2569 : 0 : int nScreens = GetDisplay()->GetXScreenCount();
2570 : 0 : for( int i = 0; i < nScreens; i++ )
2571 : : {
2572 : 0 : if( aNewParent == RootWindow( pDisp, i ) )
2573 : : {
2574 : 0 : nXScreen = SalX11Screen( i );
2575 : 0 : aParentData.aWindow = None;
2576 : 0 : m_bXEmbed = false;
2577 : 0 : break;
2578 : : }
2579 : : }
2580 : : }
2581 : :
2582 : : // first deinit frame
2583 : 0 : updateGraphics(true);
2584 : 0 : if( mpInputContext )
2585 : : {
2586 : 0 : mpInputContext->UnsetICFocus( this );
2587 : 0 : mpInputContext->Unmap( this );
2588 : : }
2589 : 0 : if( GetWindow() == hPresentationWindow )
2590 : : {
2591 : 0 : hPresentationWindow = None;
2592 : 0 : doReparentPresentationDialogues( GetDisplay() );
2593 : : }
2594 : 0 : XDestroyWindow( GetXDisplay(), mhWindow );
2595 : 0 : mhWindow = None;
2596 : :
2597 : : // now init with new parent again
2598 : 0 : if ( aParentData.aWindow != None )
2599 : 0 : Init( nStyle_ | SAL_FRAME_STYLE_PLUG, nXScreen, &aParentData );
2600 : : else
2601 : 0 : Init( nStyle_ & ~SAL_FRAME_STYLE_PLUG, nXScreen, NULL, true );
2602 : :
2603 : : // update graphics if necessary
2604 : 0 : updateGraphics(false);
2605 : :
2606 : 0 : if( ! m_aTitle.isEmpty() )
2607 : 0 : SetTitle( m_aTitle );
2608 : :
2609 : 0 : if( mpParent )
2610 : : {
2611 : 0 : if( mpParent->m_nXScreen != m_nXScreen )
2612 : 0 : SetParent( NULL );
2613 : : else
2614 : 0 : pDisplay_->getWMAdaptor()->changeReferenceFrame( this, mpParent );
2615 : : }
2616 : :
2617 : 0 : if( bWasVisible )
2618 : 0 : Show( sal_True );
2619 : :
2620 : 0 : std::list< X11SalFrame* > aChildren = maChildren;
2621 : 0 : for( std::list< X11SalFrame* >::iterator it = aChildren.begin(); it != aChildren.end(); ++it )
2622 : 0 : (*it)->createNewWindow( None, m_nXScreen );
2623 : :
2624 : : // FIXME: SalObjects
2625 : 0 : }
2626 : :
2627 : 0 : bool X11SalFrame::SetPluginParent( SystemParentData* pNewParent )
2628 : : {
2629 : 0 : if( pNewParent->nSize >= sizeof(SystemParentData) )
2630 : 0 : m_bXEmbed = pNewParent->aWindow != None && pNewParent->bXEmbedSupport;
2631 : 0 : createNewWindow( pNewParent ? pNewParent->aWindow : None );
2632 : :
2633 : 0 : return true;
2634 : : }
2635 : :
2636 : : // Event Handling
2637 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2638 : 0 : static sal_uInt16 sal_GetCode( int state )
2639 : : {
2640 : 0 : sal_uInt16 nCode = 0;
2641 : :
2642 : 0 : if( state & Button1Mask )
2643 : 0 : nCode |= MOUSE_LEFT;
2644 : 0 : if( state & Button2Mask )
2645 : 0 : nCode |= MOUSE_MIDDLE;
2646 : 0 : if( state & Button3Mask )
2647 : 0 : nCode |= MOUSE_RIGHT;
2648 : :
2649 : 0 : if( state & ShiftMask )
2650 : 0 : nCode |= KEY_SHIFT;
2651 : 0 : if( state & ControlMask )
2652 : 0 : nCode |= KEY_MOD1;
2653 : 0 : if( state & Mod1Mask )
2654 : 0 : nCode |= KEY_MOD2;
2655 : :
2656 : : // Map Meta/Super modifier to MOD3 on all Unix systems
2657 : : // except Mac OS X
2658 : 0 : if( (state & Mod3Mask) )
2659 : 0 : nCode |= KEY_MOD3;
2660 : :
2661 : 0 : return nCode;
2662 : : }
2663 : :
2664 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2665 : :
2666 : 0 : SalFrame::SalPointerState X11SalFrame::GetPointerState()
2667 : : {
2668 : 0 : SalPointerState aState;
2669 : : XLIB_Window aRoot, aChild;
2670 : : int rx, ry, wx, wy;
2671 : 0 : unsigned int nMask = 0;
2672 : : XQueryPointer( GetXDisplay(),
2673 : : GetShellWindow(),
2674 : : &aRoot,
2675 : : &aChild,
2676 : : &rx, &ry,
2677 : : &wx, &wy,
2678 : : &nMask
2679 : 0 : );
2680 : :
2681 : 0 : aState.maPos = Point(wx, wy);
2682 : 0 : aState.mnState = sal_GetCode( nMask );
2683 : 0 : return aState;
2684 : : }
2685 : :
2686 : 0 : SalFrame::SalIndicatorState X11SalFrame::GetIndicatorState()
2687 : : {
2688 : : SalIndicatorState aState;
2689 : 0 : aState.mnState = GetGenericData()->GetSalDisplay()->GetIndicatorState();
2690 : 0 : return aState;
2691 : : }
2692 : :
2693 : 0 : void X11SalFrame::SimulateKeyPress( sal_uInt16 nKeyCode )
2694 : : {
2695 : 0 : GetGenericData()->GetSalDisplay()->SimulateKeyPress(nKeyCode);
2696 : 0 : }
2697 : :
2698 : 0 : long X11SalFrame::HandleMouseEvent( XEvent *pEvent )
2699 : : {
2700 : : SalMouseEvent aMouseEvt;
2701 : 0 : sal_uInt16 nEvent = 0;
2702 : 0 : bool bClosePopups = false;
2703 : :
2704 : 0 : if( nVisibleFloats && pEvent->type == EnterNotify )
2705 : 0 : return 0;
2706 : :
2707 : : // Solaris X86: clicking the right button on a two-button mouse
2708 : : // generates a button2 event not a button3 event
2709 : 0 : if (pDisplay_->GetProperties() & PROPERTY_SUPPORT_3ButtonMouse )
2710 : : {
2711 : 0 : switch (pEvent->type)
2712 : : {
2713 : : case EnterNotify:
2714 : : case LeaveNotify:
2715 : 0 : if ( pEvent->xcrossing.state & Button2Mask )
2716 : : {
2717 : 0 : pEvent->xcrossing.state &= ~Button2Mask;
2718 : 0 : pEvent->xcrossing.state |= Button3Mask;
2719 : : }
2720 : 0 : break;
2721 : :
2722 : : case MotionNotify:
2723 : 0 : if ( pEvent->xmotion.state & Button2Mask )
2724 : : {
2725 : 0 : pEvent->xmotion.state &= ~Button2Mask;
2726 : 0 : pEvent->xmotion.state |= Button3Mask;
2727 : : }
2728 : 0 : break;
2729 : :
2730 : : default:
2731 : 0 : if ( Button2 == pEvent->xbutton.button )
2732 : : {
2733 : 0 : pEvent->xbutton.state &= ~Button2Mask;
2734 : 0 : pEvent->xbutton.state |= Button3Mask;
2735 : 0 : pEvent->xbutton.button = Button3;
2736 : : }
2737 : 0 : break;
2738 : : }
2739 : : }
2740 : :
2741 : :
2742 : 0 : if( LeaveNotify == pEvent->type || EnterNotify == pEvent->type )
2743 : : {
2744 : : /*
2745 : : * some WMs (and/or) applications have a passive grab on
2746 : : * mouse buttons (XGrabButton). This leads to enter/leave notifies
2747 : : * with mouse buttons pressed in the state mask before the actual
2748 : : * ButtonPress event gets dispatched. But EnterNotify
2749 : : * is reported in vcl as MouseMove event. Some office code
2750 : : * decides that a pressed button in a MouseMove belongs to
2751 : : * a drag operation which leads to doing things differently.
2752 : : *
2753 : : * ignore Enter/LeaveNotify resulting from grabs so that
2754 : : * help windows do not disappear just after appearing
2755 : : *
2756 : : * hopefully this workaround will not break anything.
2757 : : */
2758 : 0 : if( pEvent->xcrossing.mode == NotifyGrab || pEvent->xcrossing.mode == NotifyUngrab )
2759 : 0 : return 0;
2760 : :
2761 : 0 : aMouseEvt.mnX = pEvent->xcrossing.x;
2762 : 0 : aMouseEvt.mnY = pEvent->xcrossing.y;
2763 : 0 : aMouseEvt.mnTime = pEvent->xcrossing.time;
2764 : 0 : aMouseEvt.mnCode = sal_GetCode( pEvent->xcrossing.state );
2765 : 0 : aMouseEvt.mnButton = 0;
2766 : :
2767 : : nEvent = LeaveNotify == pEvent->type
2768 : : ? SALEVENT_MOUSELEAVE
2769 : 0 : : SALEVENT_MOUSEMOVE;
2770 : : }
2771 : 0 : else if( pEvent->type == MotionNotify )
2772 : : {
2773 : 0 : aMouseEvt.mnX = pEvent->xmotion.x;
2774 : 0 : aMouseEvt.mnY = pEvent->xmotion.y;
2775 : 0 : aMouseEvt.mnTime = pEvent->xmotion.time;
2776 : 0 : aMouseEvt.mnCode = sal_GetCode( pEvent->xmotion.state );
2777 : :
2778 : 0 : aMouseEvt.mnButton = 0;
2779 : :
2780 : 0 : nEvent = SALEVENT_MOUSEMOVE;
2781 : 0 : if( nVisibleFloats > 0 && mpParent )
2782 : : {
2783 : 0 : XLIB_Cursor aCursor = mpParent->GetCursor();
2784 : 0 : if( pEvent->xmotion.x >= 0 && pEvent->xmotion.x < (int)maGeometry.nWidth &&
2785 : : pEvent->xmotion.y >= 0 && pEvent->xmotion.y < (int)maGeometry.nHeight )
2786 : 0 : aCursor = None;
2787 : :
2788 : : XChangeActivePointerGrab( GetXDisplay(),
2789 : : PointerMotionMask|ButtonPressMask|ButtonReleaseMask,
2790 : : aCursor,
2791 : 0 : CurrentTime );
2792 : : }
2793 : : }
2794 : : else
2795 : : {
2796 : : // let mouse events reach the correct window
2797 : 0 : if( nVisibleFloats < 1 )
2798 : : {
2799 : 0 : if( ! (nStyle_ & SAL_FRAME_STYLE_OWNERDRAWDECORATION) )
2800 : 0 : XUngrabPointer( GetXDisplay(), CurrentTime );
2801 : : }
2802 : 0 : else if( pEvent->type == ButtonPress )
2803 : : {
2804 : : // see if the user clicks outside all of the floats
2805 : : // if yes release the grab
2806 : 0 : bool bInside = false;
2807 : 0 : const std::list< SalFrame* >& rFrames = GetDisplay()->getFrames();
2808 : 0 : for( std::list< SalFrame* >::const_iterator it = rFrames.begin(); it != rFrames.end(); ++it )
2809 : : {
2810 : 0 : const X11SalFrame* pFrame = static_cast< const X11SalFrame* >(*it);
2811 : 0 : if( pFrame->IsFloatGrabWindow() &&
2812 : : pFrame->bMapped_ &&
2813 : : pEvent->xbutton.x_root >= pFrame->maGeometry.nX &&
2814 : : pEvent->xbutton.x_root < pFrame->maGeometry.nX + (int)pFrame->maGeometry.nWidth &&
2815 : : pEvent->xbutton.y_root >= pFrame->maGeometry.nY &&
2816 : : pEvent->xbutton.y_root < pFrame->maGeometry.nY + (int)pFrame->maGeometry.nHeight )
2817 : : {
2818 : 0 : bInside = true;
2819 : 0 : break;
2820 : : }
2821 : : }
2822 : 0 : if( ! bInside )
2823 : : {
2824 : : // need not take care of the XUngrabPointer in Show( sal_False )
2825 : : // because XUngrabPointer does not produce errors if pointer
2826 : : // is not grabbed
2827 : 0 : XUngrabPointer( GetXDisplay(), CurrentTime );
2828 : 0 : bClosePopups = true;
2829 : :
2830 : : /* #i15246# only close popups if pointer is outside all our frames
2831 : : * cannot use our own geometry data here because stacking
2832 : : * is unknown (the above case implicitly assumes
2833 : : * that floats are on top which should be true)
2834 : : */
2835 : : XLIB_Window aRoot, aChild;
2836 : : int root_x, root_y, win_x, win_y;
2837 : : unsigned int mask_return;
2838 : 0 : if( XQueryPointer( GetXDisplay(),
2839 : : GetDisplay()->GetRootWindow( m_nXScreen ),
2840 : : &aRoot, &aChild,
2841 : : &root_x, &root_y,
2842 : : &win_x, &win_y,
2843 : 0 : &mask_return )
2844 : : && aChild // pointer may not be in any child
2845 : : )
2846 : : {
2847 : 0 : for( std::list< SalFrame* >::const_iterator it = rFrames.begin(); it != rFrames.end(); ++it )
2848 : : {
2849 : 0 : const X11SalFrame* pFrame = static_cast< const X11SalFrame* >(*it);
2850 : 0 : if( ! pFrame->IsFloatGrabWindow()
2851 : 0 : && ( pFrame->GetWindow() == aChild ||
2852 : 0 : pFrame->GetShellWindow() == aChild ||
2853 : 0 : pFrame->GetStackingWindow() == aChild )
2854 : : )
2855 : : {
2856 : : // #i63638# check that pointer is inside window, not
2857 : : // only inside stacking window
2858 : 0 : if( root_x >= pFrame->maGeometry.nX && root_x < sal::static_int_cast< int >(pFrame->maGeometry.nX+pFrame->maGeometry.nWidth) &&
2859 : 0 : root_y >= pFrame->maGeometry.nY && root_y < sal::static_int_cast< int >(pFrame->maGeometry.nX+pFrame->maGeometry.nHeight) )
2860 : : {
2861 : 0 : bClosePopups = false;
2862 : : }
2863 : 0 : break;
2864 : : }
2865 : : }
2866 : : }
2867 : : }
2868 : : }
2869 : :
2870 : 0 : if( m_bXEmbed && pEvent->xbutton.button == Button1 )
2871 : 0 : askForXEmbedFocus( pEvent->xbutton.time );
2872 : :
2873 : 0 : if( pEvent->xbutton.button == Button1 ||
2874 : : pEvent->xbutton.button == Button2 ||
2875 : : pEvent->xbutton.button == Button3 )
2876 : : {
2877 : 0 : aMouseEvt.mnX = pEvent->xbutton.x;
2878 : 0 : aMouseEvt.mnY = pEvent->xbutton.y;
2879 : 0 : aMouseEvt.mnTime = pEvent->xbutton.time;
2880 : 0 : aMouseEvt.mnCode = sal_GetCode( pEvent->xbutton.state );
2881 : :
2882 : 0 : if( Button1 == pEvent->xbutton.button )
2883 : 0 : aMouseEvt.mnButton = MOUSE_LEFT;
2884 : 0 : else if( Button2 == pEvent->xbutton.button )
2885 : 0 : aMouseEvt.mnButton = MOUSE_MIDDLE;
2886 : 0 : else if( Button3 == pEvent->xbutton.button )
2887 : 0 : aMouseEvt.mnButton = MOUSE_RIGHT;
2888 : :
2889 : : nEvent = ButtonPress == pEvent->type
2890 : : ? SALEVENT_MOUSEBUTTONDOWN
2891 : 0 : : SALEVENT_MOUSEBUTTONUP;
2892 : : }
2893 : 0 : else if( pEvent->xbutton.button == Button4 ||
2894 : : pEvent->xbutton.button == Button5 ||
2895 : : pEvent->xbutton.button == Button6 ||
2896 : : pEvent->xbutton.button == Button7 )
2897 : : {
2898 : : const bool bIncrement(
2899 : : pEvent->xbutton.button == Button4 ||
2900 : 0 : pEvent->xbutton.button == Button6 );
2901 : : const bool bHoriz(
2902 : : pEvent->xbutton.button == Button6 ||
2903 : 0 : pEvent->xbutton.button == Button7 );
2904 : :
2905 : 0 : if( pEvent->type == ButtonRelease )
2906 : 0 : return 0;
2907 : :
2908 : : static sal_uLong nLines = 0;
2909 : 0 : if( ! nLines )
2910 : : {
2911 : 0 : char* pEnv = getenv( "SAL_WHEELLINES" );
2912 : 0 : nLines = pEnv ? atoi( pEnv ) : 3;
2913 : 0 : if( nLines > 10 )
2914 : 0 : nLines = SAL_WHEELMOUSE_EVENT_PAGESCROLL;
2915 : : }
2916 : :
2917 : 0 : SalWheelMouseEvent aWheelEvt;
2918 : 0 : aWheelEvt.mnTime = pEvent->xbutton.time;
2919 : 0 : aWheelEvt.mnX = pEvent->xbutton.x;
2920 : 0 : aWheelEvt.mnY = pEvent->xbutton.y;
2921 : 0 : aWheelEvt.mnDelta = bIncrement ? 120 : -120;
2922 : 0 : aWheelEvt.mnNotchDelta = bIncrement ? 1 : -1;
2923 : 0 : aWheelEvt.mnScrollLines = nLines;
2924 : 0 : aWheelEvt.mnCode = sal_GetCode( pEvent->xbutton.state );
2925 : 0 : aWheelEvt.mbHorz = bHoriz;
2926 : :
2927 : 0 : nEvent = SALEVENT_WHEELMOUSE;
2928 : :
2929 : : // --- RTL --- (mirror mouse pos)
2930 : 0 : if( Application::GetSettings().GetLayoutRTL() )
2931 : 0 : aWheelEvt.mnX = nWidth_-1-aWheelEvt.mnX;
2932 : 0 : return CallCallback( nEvent, &aWheelEvt );
2933 : : }
2934 : : }
2935 : :
2936 : 0 : int nRet = 0;
2937 : 0 : if( nEvent == SALEVENT_MOUSELEAVE
2938 : : || ( aMouseEvt.mnX < nWidth_ && aMouseEvt.mnX > -1 &&
2939 : : aMouseEvt.mnY < nHeight_ && aMouseEvt.mnY > -1 )
2940 : 0 : || pDisplay_->MouseCaptured( this )
2941 : : )
2942 : : {
2943 : : // --- RTL --- (mirror mouse pos)
2944 : 0 : if( Application::GetSettings().GetLayoutRTL() )
2945 : 0 : aMouseEvt.mnX = nWidth_-1-aMouseEvt.mnX;
2946 : 0 : nRet = CallCallback( nEvent, &aMouseEvt );
2947 : : }
2948 : :
2949 : 0 : if( bClosePopups )
2950 : : {
2951 : : /* #108213# close popups after dispatching the event outside the popup;
2952 : : * applications do weird things.
2953 : : */
2954 : 0 : ImplSVData* pSVData = ImplGetSVData();
2955 : 0 : if ( pSVData->maWinData.mpFirstFloat )
2956 : : {
2957 : 0 : static const char* pEnv = getenv( "SAL_FLOATWIN_NOAPPFOCUSCLOSE" );
2958 : 0 : if ( !(pSVData->maWinData.mpFirstFloat->GetPopupModeFlags() & FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE) && !(pEnv && *pEnv) )
2959 : 0 : pSVData->maWinData.mpFirstFloat->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL | FLOATWIN_POPUPMODEEND_CLOSEALL );
2960 : : }
2961 : : }
2962 : :
2963 : 0 : return nRet;
2964 : : }
2965 : :
2966 : : // F10 means either KEY_F10 or KEY_MENU, which has to be decided
2967 : : // in the independent part.
2968 : : struct KeyAlternate
2969 : : {
2970 : : sal_uInt16 nKeyCode;
2971 : : sal_Unicode nCharCode;
2972 : 0 : KeyAlternate() : nKeyCode( 0 ), nCharCode( 0 ) {}
2973 : 0 : KeyAlternate( sal_uInt16 nKey, sal_Unicode nChar = 0 ) : nKeyCode( nKey ), nCharCode( nChar ) {}
2974 : : };
2975 : :
2976 : : inline KeyAlternate
2977 : 0 : GetAlternateKeyCode( const sal_uInt16 nKeyCode )
2978 : : {
2979 : 0 : KeyAlternate aAlternate;
2980 : :
2981 : 0 : switch( nKeyCode )
2982 : : {
2983 : 0 : case KEY_F10: aAlternate = KeyAlternate( KEY_MENU );break;
2984 : 0 : case KEY_F24: aAlternate = KeyAlternate( KEY_SUBTRACT, '-' );break;
2985 : : }
2986 : :
2987 : 0 : return aAlternate;
2988 : : }
2989 : :
2990 : 0 : void X11SalFrame::beginUnicodeSequence()
2991 : : {
2992 : 0 : rtl::OUString& rSeq( GetGenericData()->GetUnicodeCommand() );
2993 : 0 : DeletionListener aDeleteWatch( this );
2994 : :
2995 : 0 : if( !rSeq.isEmpty() )
2996 : 0 : endUnicodeSequence();
2997 : :
2998 : 0 : rSeq = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "u" ) );
2999 : :
3000 : 0 : if( ! aDeleteWatch.isDeleted() )
3001 : : {
3002 : 0 : sal_uInt16 nTextAttr = SAL_EXTTEXTINPUT_ATTR_UNDERLINE;
3003 : 0 : SalExtTextInputEvent aEv;
3004 : 0 : aEv.mnTime = 0;
3005 : 0 : aEv.maText = rSeq;
3006 : 0 : aEv.mpTextAttr = &nTextAttr;
3007 : 0 : aEv.mnCursorPos = 0;
3008 : 0 : aEv.mnDeltaStart = 0;
3009 : 0 : aEv.mnCursorFlags = 0;
3010 : 0 : aEv.mbOnlyCursor = sal_False;
3011 : :
3012 : 0 : CallCallback(SALEVENT_EXTTEXTINPUT, (void*)&aEv);
3013 : 0 : }
3014 : 0 : }
3015 : :
3016 : 0 : bool X11SalFrame::appendUnicodeSequence( sal_Unicode c )
3017 : : {
3018 : 0 : bool bRet = false;
3019 : 0 : rtl::OUString& rSeq( GetGenericData()->GetUnicodeCommand() );
3020 : 0 : if( !rSeq.isEmpty() )
3021 : : {
3022 : : // range check
3023 : 0 : if( (c >= sal_Unicode('0') && c <= sal_Unicode('9')) ||
3024 : : (c >= sal_Unicode('a') && c <= sal_Unicode('f')) ||
3025 : : (c >= sal_Unicode('A') && c <= sal_Unicode('F')) )
3026 : : {
3027 : 0 : rtl::OUStringBuffer aBuf( rSeq.getLength() + 1 );
3028 : 0 : aBuf.append( rSeq );
3029 : 0 : aBuf.append( c );
3030 : 0 : rSeq = aBuf.makeStringAndClear();
3031 : 0 : std::vector<sal_uInt16> attribs( rSeq.getLength(), SAL_EXTTEXTINPUT_ATTR_UNDERLINE );
3032 : :
3033 : 0 : SalExtTextInputEvent aEv;
3034 : 0 : aEv.mnTime = 0;
3035 : 0 : aEv.maText = rSeq;
3036 : 0 : aEv.mpTextAttr = &attribs[0];
3037 : 0 : aEv.mnCursorPos = 0;
3038 : 0 : aEv.mnDeltaStart = 0;
3039 : 0 : aEv.mnCursorFlags = 0;
3040 : 0 : aEv.mbOnlyCursor = sal_False;
3041 : :
3042 : 0 : CallCallback(SALEVENT_EXTTEXTINPUT, (void*)&aEv);
3043 : 0 : bRet = true;
3044 : : }
3045 : : else
3046 : 0 : bRet = endUnicodeSequence();
3047 : : }
3048 : : else
3049 : 0 : endUnicodeSequence();
3050 : 0 : return bRet;
3051 : : }
3052 : :
3053 : 0 : bool X11SalFrame::endUnicodeSequence()
3054 : : {
3055 : 0 : rtl::OUString& rSeq( GetGenericData()->GetUnicodeCommand() );
3056 : :
3057 : 0 : DeletionListener aDeleteWatch( this );
3058 : 0 : if( rSeq.getLength() > 1 && rSeq.getLength() < 6 )
3059 : : {
3060 : : // cut the "u"
3061 : 0 : rtl::OUString aNumbers( rSeq.copy( 1 ) );
3062 : 0 : sal_Int32 nValue = aNumbers.toInt32( 16 );
3063 : 0 : if( nValue >= 32 )
3064 : : {
3065 : 0 : sal_uInt16 nTextAttr = SAL_EXTTEXTINPUT_ATTR_UNDERLINE;
3066 : 0 : SalExtTextInputEvent aEv;
3067 : 0 : aEv.mnTime = 0;
3068 : 0 : aEv.maText = rtl::OUString( sal_Unicode(nValue) );
3069 : 0 : aEv.mpTextAttr = &nTextAttr;
3070 : 0 : aEv.mnCursorPos = 0;
3071 : 0 : aEv.mnDeltaStart = 0;
3072 : 0 : aEv.mnCursorFlags = 0;
3073 : 0 : aEv.mbOnlyCursor = sal_False;
3074 : 0 : CallCallback(SALEVENT_EXTTEXTINPUT, (void*)&aEv);
3075 : 0 : }
3076 : : }
3077 : 0 : bool bWasInput = !rSeq.isEmpty();
3078 : 0 : rSeq = rtl::OUString();
3079 : 0 : if( bWasInput && ! aDeleteWatch.isDeleted() )
3080 : 0 : CallCallback(SALEVENT_ENDEXTTEXTINPUT, NULL);
3081 : 0 : return bWasInput;
3082 : : }
3083 : :
3084 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
3085 : 0 : long X11SalFrame::HandleKeyEvent( XKeyEvent *pEvent )
3086 : : {
3087 : : KeySym nKeySym;
3088 : : KeySym nUnmodifiedKeySym;
3089 : 0 : int nLen = 2048;
3090 : 0 : unsigned char *pPrintable = (unsigned char*)alloca( nLen );
3091 : :
3092 : : // singlebyte code composed by input method, the new default
3093 : 0 : if (mpInputContext != NULL && mpInputContext->UseContext())
3094 : : {
3095 : : // returns a keysym as well as the pPrintable (in system encoding)
3096 : : // printable may be empty.
3097 : : Status nStatus;
3098 : : nKeySym = pDisplay_->GetKeySym( pEvent, pPrintable, &nLen,
3099 : : &nUnmodifiedKeySym,
3100 : 0 : &nStatus, mpInputContext->GetContext() );
3101 : 0 : if ( nStatus == XBufferOverflow )
3102 : : {
3103 : 0 : nLen *= 2;
3104 : 0 : pPrintable = (unsigned char*)alloca( nLen );
3105 : : nKeySym = pDisplay_->GetKeySym( pEvent, pPrintable, &nLen,
3106 : : &nUnmodifiedKeySym,
3107 : 0 : &nStatus, mpInputContext->GetContext() );
3108 : : }
3109 : : }
3110 : : else
3111 : : {
3112 : : // fallback, this should never ever be called
3113 : 0 : Status nStatus = 0;
3114 : 0 : nKeySym = pDisplay_->GetKeySym( pEvent, pPrintable, &nLen, &nUnmodifiedKeySym, &nStatus );
3115 : : }
3116 : :
3117 : : SalKeyEvent aKeyEvt;
3118 : : sal_uInt16 nKeyCode;
3119 : 0 : sal_uInt16 nModCode = 0;
3120 : : char aDummy;
3121 : :
3122 : 0 : if( pEvent->state & ShiftMask )
3123 : 0 : nModCode |= KEY_SHIFT;
3124 : 0 : if( pEvent->state & ControlMask )
3125 : 0 : nModCode |= KEY_MOD1;
3126 : 0 : if( pEvent->state & Mod1Mask )
3127 : 0 : nModCode |= KEY_MOD2;
3128 : :
3129 : 0 : if( nModCode != (KEY_SHIFT|KEY_MOD1) )
3130 : 0 : endUnicodeSequence();
3131 : :
3132 : 0 : if( nKeySym == XK_Shift_L || nKeySym == XK_Shift_R
3133 : : || nKeySym == XK_Control_L || nKeySym == XK_Control_R
3134 : : || nKeySym == XK_Alt_L || nKeySym == XK_Alt_R
3135 : : || nKeySym == XK_Meta_L || nKeySym == XK_Meta_R
3136 : : || nKeySym == XK_Super_L || nKeySym == XK_Super_R )
3137 : : {
3138 : : SalKeyModEvent aModEvt;
3139 : 0 : aModEvt.mnModKeyCode = 0;
3140 : 0 : if( pEvent->type == XLIB_KeyPress && mnExtKeyMod == 0 )
3141 : 0 : mbSendExtKeyModChange = true;
3142 : 0 : else if( pEvent->type == KeyRelease && mbSendExtKeyModChange )
3143 : : {
3144 : 0 : aModEvt.mnModKeyCode = mnExtKeyMod;
3145 : 0 : mnExtKeyMod = 0;
3146 : : }
3147 : :
3148 : : // pressing just the ctrl key leads to a keysym of XK_Control but
3149 : : // the event state does not contain ControlMask. In the release
3150 : : // event its the other way round: it does contain the Control mask.
3151 : : // The modifier mode therefore has to be adapted manually.
3152 : 0 : sal_uInt16 nExtModMask = 0;
3153 : 0 : sal_uInt16 nModMask = 0;
3154 : 0 : switch( nKeySym )
3155 : : {
3156 : : case XK_Control_L:
3157 : 0 : nExtModMask = MODKEY_LMOD1;
3158 : 0 : nModMask = KEY_MOD1;
3159 : 0 : break;
3160 : : case XK_Control_R:
3161 : 0 : nExtModMask = MODKEY_RMOD1;
3162 : 0 : nModMask = KEY_MOD1;
3163 : 0 : break;
3164 : : case XK_Alt_L:
3165 : 0 : nExtModMask = MODKEY_LMOD2;
3166 : 0 : nModMask = KEY_MOD2;
3167 : 0 : break;
3168 : : case XK_Alt_R:
3169 : 0 : nExtModMask = MODKEY_RMOD2;
3170 : 0 : nModMask = KEY_MOD2;
3171 : 0 : break;
3172 : : case XK_Shift_L:
3173 : 0 : nExtModMask = MODKEY_LSHIFT;
3174 : 0 : nModMask = KEY_SHIFT;
3175 : 0 : break;
3176 : : case XK_Shift_R:
3177 : 0 : nExtModMask = MODKEY_RSHIFT;
3178 : 0 : nModMask = KEY_SHIFT;
3179 : 0 : break;
3180 : : // Map Meta/Super keys to MOD3 modifier on all Unix systems
3181 : : // except Mac OS X
3182 : : case XK_Meta_L:
3183 : : case XK_Super_L:
3184 : 0 : nExtModMask = MODKEY_LMOD3;
3185 : 0 : nModMask = KEY_MOD3;
3186 : 0 : break;
3187 : : case XK_Meta_R:
3188 : : case XK_Super_R:
3189 : 0 : nExtModMask = MODKEY_RMOD3;
3190 : 0 : nModMask = KEY_MOD3;
3191 : 0 : break;
3192 : : }
3193 : 0 : if( pEvent->type == KeyRelease )
3194 : : {
3195 : 0 : nModCode &= ~nModMask;
3196 : 0 : mnExtKeyMod &= ~nExtModMask;
3197 : : }
3198 : : else
3199 : : {
3200 : 0 : nModCode |= nModMask;
3201 : 0 : mnExtKeyMod |= nExtModMask;
3202 : : }
3203 : :
3204 : 0 : aModEvt.mnCode = nModCode;
3205 : 0 : aModEvt.mnTime = pEvent->time;
3206 : :
3207 : 0 : int nRet = CallCallback( SALEVENT_KEYMODCHANGE, &aModEvt );
3208 : :
3209 : 0 : return nRet;
3210 : : }
3211 : :
3212 : 0 : mbSendExtKeyModChange = false;
3213 : :
3214 : : // try to figure out the vcl code for the keysym
3215 : : // #i52338# use the unmodified KeySym if there is none for the real KeySym
3216 : : // because the independent part has only keycodes for unshifted keys
3217 : 0 : nKeyCode = pDisplay_->GetKeyCode( nKeySym, &aDummy );
3218 : 0 : if( nKeyCode == 0 )
3219 : 0 : nKeyCode = pDisplay_->GetKeyCode( nUnmodifiedKeySym, &aDummy );
3220 : :
3221 : : // try to figure out a printable if XmbLookupString returns only a keysym
3222 : : // and NOT a printable. Do not store it in pPrintable[0] since it is expected to
3223 : : // be in system encoding, not unicode.
3224 : : // #i8988##, if KeySym and printable look equally promising then prefer KeySym
3225 : : // the printable is bound to the encoding so the KeySym might contain more
3226 : : // information (in et_EE locale: "Compose + Z + <" delivers "," in printable and
3227 : : // (the desired) Zcaron in KeySym
3228 : 0 : sal_Unicode nKeyString = 0x0;
3229 : 0 : if ( (nLen == 0)
3230 : : || ((nLen == 1) && (nKeySym > 0)) )
3231 : 0 : nKeyString = KeysymToUnicode (nKeySym);
3232 : : // if we have nothing we give up
3233 : 0 : if( !nKeyCode && !nLen && !nKeyString)
3234 : 0 : return 0;
3235 : :
3236 : 0 : DeletionListener aDeleteWatch( this );
3237 : :
3238 : 0 : if( nModCode == (KEY_SHIFT | KEY_MOD1) && pEvent->type == XLIB_KeyPress )
3239 : : {
3240 : 0 : sal_uInt16 nSeqKeyCode = pDisplay_->GetKeyCode( nUnmodifiedKeySym, &aDummy );
3241 : 0 : if( nSeqKeyCode == KEY_U )
3242 : : {
3243 : 0 : beginUnicodeSequence();
3244 : 0 : return 1;
3245 : : }
3246 : 0 : else if( nSeqKeyCode >= KEY_0 && nSeqKeyCode <= KEY_9 )
3247 : : {
3248 : 0 : if( appendUnicodeSequence( sal_Unicode( '0' ) + sal_Unicode(nSeqKeyCode - KEY_0) ) )
3249 : 0 : return 1;
3250 : : }
3251 : 0 : else if( nSeqKeyCode >= KEY_A && nSeqKeyCode <= KEY_F )
3252 : : {
3253 : 0 : if( appendUnicodeSequence( sal_Unicode( 'a' ) + sal_Unicode(nSeqKeyCode - KEY_A) ) )
3254 : 0 : return 1;
3255 : : }
3256 : : else
3257 : 0 : endUnicodeSequence();
3258 : : }
3259 : :
3260 : 0 : if( aDeleteWatch.isDeleted() )
3261 : 0 : return 0;
3262 : :
3263 : 0 : rtl_TextEncoding nEncoding = osl_getThreadTextEncoding();
3264 : :
3265 : : sal_Unicode *pBuffer;
3266 : : sal_Unicode *pString;
3267 : 0 : sal_Size nBufferSize = nLen * 2;
3268 : : sal_Size nSize;
3269 : 0 : pBuffer = (sal_Unicode*) malloc( nBufferSize + 2 );
3270 : 0 : pBuffer[ 0 ] = 0;
3271 : :
3272 : 0 : if (nKeyString != 0)
3273 : : {
3274 : 0 : pString = &nKeyString;
3275 : 0 : nSize = 1;
3276 : : }
3277 : : else
3278 : 0 : if (nLen > 0 && nEncoding != RTL_TEXTENCODING_UNICODE)
3279 : : {
3280 : : // create text converter
3281 : : rtl_TextToUnicodeConverter aConverter =
3282 : 0 : rtl_createTextToUnicodeConverter( nEncoding );
3283 : : rtl_TextToUnicodeContext aContext =
3284 : 0 : rtl_createTextToUnicodeContext( aConverter );
3285 : :
3286 : : sal_uInt32 nConversionInfo;
3287 : : sal_Size nConvertedChars;
3288 : :
3289 : : // convert to single byte text stream
3290 : : nSize = rtl_convertTextToUnicode(
3291 : : aConverter, aContext,
3292 : : (char*)pPrintable, nLen,
3293 : : pBuffer, nBufferSize,
3294 : : RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_IGNORE |
3295 : : RTL_TEXTTOUNICODE_FLAGS_INVALID_IGNORE,
3296 : 0 : &nConversionInfo, &nConvertedChars );
3297 : :
3298 : : // destroy converter
3299 : 0 : rtl_destroyTextToUnicodeContext( aConverter, aContext );
3300 : 0 : rtl_destroyTextToUnicodeConverter( aConverter );
3301 : :
3302 : 0 : pString = pBuffer;
3303 : : }
3304 : : else
3305 : 0 : if (nLen > 0 /* nEncoding == RTL_TEXTENCODING_UNICODE */)
3306 : : {
3307 : 0 : pString = (sal_Unicode*)pPrintable;
3308 : 0 : nSize = nLen;
3309 : : }
3310 : : else
3311 : : {
3312 : 0 : pString = pBuffer;
3313 : 0 : nSize = 0;
3314 : : }
3315 : :
3316 : 0 : if ( mpInputContext != NULL
3317 : 0 : && mpInputContext->UseContext()
3318 : : && KeyRelease != pEvent->type
3319 : : && ( (nSize > 1)
3320 : 0 : || (nSize > 0 && mpInputContext->IsPreeditMode())) )
3321 : : {
3322 : 0 : mpInputContext->CommitKeyEvent(pString, nSize);
3323 : : }
3324 : : else
3325 : : // normal single character keyinput
3326 : : {
3327 : 0 : aKeyEvt.mnCode = nKeyCode | nModCode;
3328 : 0 : aKeyEvt.mnRepeat = 0;
3329 : 0 : aKeyEvt.mnTime = pEvent->time;
3330 : 0 : aKeyEvt.mnCharCode = pString[ 0 ];
3331 : :
3332 : 0 : if( KeyRelease == pEvent->type )
3333 : : {
3334 : 0 : CallCallback( SALEVENT_KEYUP, &aKeyEvt );
3335 : : }
3336 : : else
3337 : : {
3338 : 0 : if ( ! CallCallback(SALEVENT_KEYINPUT, &aKeyEvt) )
3339 : : {
3340 : : // independent layer doesnt want to handle key-event, so check
3341 : : // whether the keycode may have an alternate meaning
3342 : 0 : KeyAlternate aAlternate = GetAlternateKeyCode( nKeyCode );
3343 : 0 : if ( aAlternate.nKeyCode != 0 )
3344 : : {
3345 : 0 : aKeyEvt.mnCode = aAlternate.nKeyCode | nModCode;
3346 : 0 : if( aAlternate.nCharCode )
3347 : 0 : aKeyEvt.mnCharCode = aAlternate.nCharCode;
3348 : 0 : CallCallback(SALEVENT_KEYINPUT, &aKeyEvt);
3349 : : }
3350 : : }
3351 : : }
3352 : : }
3353 : :
3354 : : //
3355 : : // update the spot location for PreeditPosition IME style
3356 : : //
3357 : 0 : if (! aDeleteWatch.isDeleted())
3358 : : {
3359 : 0 : if (mpInputContext != NULL && mpInputContext->UseContext())
3360 : 0 : mpInputContext->UpdateSpotLocation();
3361 : : }
3362 : :
3363 : 0 : free (pBuffer);
3364 : 0 : return True;
3365 : : }
3366 : :
3367 : :
3368 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
3369 : 0 : long X11SalFrame::HandleFocusEvent( XFocusChangeEvent *pEvent )
3370 : : {
3371 : : // ReflectionX in Windows mode changes focus while mouse is grabbed
3372 : 0 : if( nVisibleFloats > 0 && GetDisplay()->getWMAdaptor()->getWindowManagerName().EqualsAscii( "ReflectionX Windows" ) )
3373 : 0 : return 1;
3374 : :
3375 : : /* ignore focusout resulting from keyboard grabs
3376 : : * we do not grab it and are not interested when
3377 : : * someone else does CDE e.g. does a XGrabKey on arrow keys
3378 : : * handle focus events with mode NotifyWhileGrabbed
3379 : : * because with CDE alt-tab focus changing we do not get
3380 : : * normal focus events
3381 : : * cast focus event to the input context, otherwise the
3382 : : * status window does not follow the application frame
3383 : : */
3384 : :
3385 : 0 : if ( mpInputContext != NULL )
3386 : : {
3387 : 0 : if( FocusIn == pEvent->type )
3388 : 0 : mpInputContext->SetICFocus( this );
3389 : : else
3390 : : {
3391 : : /*
3392 : : * do not unset the IC focuse here because would kill
3393 : : * a lookup choice windows that might have the focus now
3394 : : * mpInputContext->UnsetICFocus( this );
3395 : : */
3396 : 0 : I18NStatus::get().show( false, I18NStatus::focus );
3397 : : }
3398 : : }
3399 : :
3400 : :
3401 : 0 : if ( pEvent->mode == NotifyNormal || pEvent->mode == NotifyWhileGrabbed ||
3402 : 0 : ( ( nStyle_ & SAL_FRAME_STYLE_PLUG ) && pEvent->window == GetShellWindow() )
3403 : : )
3404 : : {
3405 : 0 : if( hPresentationWindow != None && hPresentationWindow != GetShellWindow() )
3406 : 0 : return 0;
3407 : :
3408 : 0 : if( FocusIn == pEvent->type )
3409 : : {
3410 : 0 : GetSalData()->m_pInstance->updatePrinterUpdate();
3411 : 0 : mbInputFocus = True;
3412 : 0 : ImplSVData* pSVData = ImplGetSVData();
3413 : :
3414 : :
3415 : :
3416 : 0 : long nRet = CallCallback( SALEVENT_GETFOCUS, 0 );
3417 : 0 : if ((mpParent != NULL && nStyle_ == 0)
3418 : : && pSVData->maWinData.mpFirstFloat )
3419 : : {
3420 : 0 : sal_uLong nMode = pSVData->maWinData.mpFirstFloat->GetPopupModeFlags();
3421 : : pSVData->maWinData.mpFirstFloat->SetPopupModeFlags(
3422 : 0 : nMode & ~(FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE));
3423 : : }
3424 : 0 : return nRet;
3425 : : }
3426 : : else
3427 : : {
3428 : 0 : mbInputFocus = False;
3429 : 0 : mbSendExtKeyModChange = false;
3430 : 0 : mnExtKeyMod = 0;
3431 : 0 : return CallCallback( SALEVENT_LOSEFOCUS, 0 );
3432 : : }
3433 : : }
3434 : :
3435 : 0 : return 0;
3436 : : }
3437 : :
3438 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
3439 : :
3440 : 0 : long X11SalFrame::HandleExposeEvent( XEvent *pEvent )
3441 : : {
3442 : 0 : XRectangle aRect = { 0, 0, 0, 0 };
3443 : 0 : sal_uInt16 nCount = 0;
3444 : :
3445 : 0 : if( pEvent->type == Expose )
3446 : : {
3447 : 0 : aRect.x = pEvent->xexpose.x;
3448 : 0 : aRect.y = pEvent->xexpose.y;
3449 : 0 : aRect.width = pEvent->xexpose.width;
3450 : 0 : aRect.height = pEvent->xexpose.height;
3451 : 0 : nCount = pEvent->xexpose.count;
3452 : : }
3453 : 0 : else if( pEvent->type == GraphicsExpose )
3454 : : {
3455 : 0 : aRect.x = pEvent->xgraphicsexpose.x;
3456 : 0 : aRect.y = pEvent->xgraphicsexpose.y;
3457 : 0 : aRect.width = pEvent->xgraphicsexpose.width;
3458 : 0 : aRect.height = pEvent->xgraphicsexpose.height;
3459 : 0 : nCount = pEvent->xgraphicsexpose.count;
3460 : : }
3461 : :
3462 : 0 : if( IsOverrideRedirect() && mbFullScreen &&
3463 : 0 : aPresentationReparentList.begin() == aPresentationReparentList.end() )
3464 : : // we are in fullscreen mode -> override redirect
3465 : : // focus is possibly lost, so reget it
3466 : 0 : XSetInputFocus( GetXDisplay(), GetShellWindow(), RevertToNone, CurrentTime );
3467 : :
3468 : : // width and height are extents, so they are of by one for rectangle
3469 : 0 : maPaintRegion.Union( Rectangle( Point(aRect.x, aRect.y), Size(aRect.width+1, aRect.height+1) ) );
3470 : :
3471 : 0 : if( nCount )
3472 : : // wait for last expose rectangle, do not wait for resize timer
3473 : : // if a completed graphics expose sequence is available
3474 : 0 : return 1;
3475 : :
3476 : 0 : SalPaintEvent aPEvt( maPaintRegion.Left(), maPaintRegion.Top(), maPaintRegion.GetWidth(), maPaintRegion.GetHeight() );
3477 : :
3478 : 0 : CallCallback( SALEVENT_PAINT, &aPEvt );
3479 : 0 : maPaintRegion = Rectangle();
3480 : :
3481 : 0 : return 1;
3482 : : }
3483 : :
3484 : 0 : void X11SalFrame::RestackChildren( XLIB_Window* pTopLevelWindows, int nTopLevelWindows )
3485 : : {
3486 : 0 : if( maChildren.begin() != maChildren.end() )
3487 : : {
3488 : 0 : int nWindow = nTopLevelWindows;
3489 : 0 : while( nWindow-- )
3490 : 0 : if( pTopLevelWindows[nWindow] == GetStackingWindow() )
3491 : 0 : break;
3492 : 0 : if( nWindow < 0 )
3493 : 0 : return;
3494 : :
3495 : 0 : std::list< X11SalFrame* >::const_iterator it;
3496 : 0 : for( it = maChildren.begin(); it != maChildren.end(); ++it )
3497 : : {
3498 : 0 : X11SalFrame* pData = *it;
3499 : 0 : if( pData->bMapped_ )
3500 : : {
3501 : 0 : int nChild = nWindow;
3502 : 0 : while( nChild-- )
3503 : : {
3504 : 0 : if( pTopLevelWindows[nChild] == pData->GetStackingWindow() )
3505 : : {
3506 : : // if a child is behind its parent, place it above the
3507 : : // parent (for insane WMs like Dtwm and olwm)
3508 : : XWindowChanges aCfg;
3509 : 0 : aCfg.sibling = GetStackingWindow();
3510 : 0 : aCfg.stack_mode = Above;
3511 : 0 : XConfigureWindow( GetXDisplay(), pData->GetStackingWindow(), CWSibling|CWStackMode, &aCfg );
3512 : : break;
3513 : : }
3514 : : }
3515 : : }
3516 : : }
3517 : 0 : for( it = maChildren.begin(); it != maChildren.end(); ++it )
3518 : : {
3519 : 0 : X11SalFrame* pData = *it;
3520 : 0 : pData->RestackChildren( pTopLevelWindows, nTopLevelWindows );
3521 : : }
3522 : : }
3523 : : }
3524 : :
3525 : 0 : void X11SalFrame::RestackChildren()
3526 : : {
3527 : 0 : if( ! GetDisplay()->getWMAdaptor()->isTransientBehaviourAsExpected()
3528 : 0 : && maChildren.begin() != maChildren.end() )
3529 : : {
3530 : 0 : XLIB_Window aRoot, aParent, *pChildren = NULL;
3531 : : unsigned int nChildren;
3532 : 0 : if( XQueryTree( GetXDisplay(),
3533 : : GetDisplay()->GetRootWindow( m_nXScreen ),
3534 : : &aRoot,
3535 : : &aParent,
3536 : : &pChildren,
3537 : 0 : &nChildren ) )
3538 : : {
3539 : 0 : RestackChildren( pChildren, nChildren );
3540 : 0 : XFree( pChildren );
3541 : : }
3542 : : }
3543 : 0 : }
3544 : :
3545 : 0 : static Bool size_event_predicate( Display*, XEvent* event, XPointer arg )
3546 : : {
3547 : 0 : if( event->type != ConfigureNotify )
3548 : 0 : return False;
3549 : 0 : X11SalFrame* frame = reinterpret_cast< X11SalFrame* >( arg );
3550 : 0 : XConfigureEvent* pEvent = &event->xconfigure;
3551 : 0 : if( pEvent->window != frame->GetShellWindow()
3552 : 0 : && pEvent->window != frame->GetWindow()
3553 : 0 : && pEvent->window != frame->GetForeignParent()
3554 : 0 : && pEvent->window != frame->GetStackingWindow())
3555 : : { // ignored at top of HandleSizeEvent()
3556 : 0 : return False;
3557 : : }
3558 : 0 : if( pEvent->window == frame->GetStackingWindow())
3559 : 0 : return False; // filtered later in HandleSizeEvent()
3560 : : // at this point we know that there is another similar event in the queue
3561 : 0 : frame->setPendingSizeEvent();
3562 : 0 : return False; // but do not process the new event out of order
3563 : : }
3564 : :
3565 : 0 : void X11SalFrame::setPendingSizeEvent()
3566 : : {
3567 : 0 : mPendingSizeEvent = true;
3568 : 0 : }
3569 : :
3570 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
3571 : 0 : long X11SalFrame::HandleSizeEvent( XConfigureEvent *pEvent )
3572 : : {
3573 : : // NOTE: if you add more tests in this function, make sure to update size_event_predicate()
3574 : : // so that it finds exactly the same events
3575 : :
3576 : 0 : if ( pEvent->window != GetShellWindow()
3577 : 0 : && pEvent->window != GetWindow()
3578 : 0 : && pEvent->window != GetForeignParent()
3579 : 0 : && pEvent->window != GetStackingWindow()
3580 : : )
3581 : : {
3582 : : // could be as well a sys-child window (aka SalObject)
3583 : 0 : return 1;
3584 : : }
3585 : :
3586 : :
3587 : 0 : if( ( nStyle_ & SAL_FRAME_STYLE_PLUG ) && pEvent->window == GetShellWindow() )
3588 : : {
3589 : : // just update the children's positions
3590 : 0 : RestackChildren();
3591 : 0 : return 1;
3592 : : }
3593 : :
3594 : 0 : if( pEvent->window == GetForeignParent() )
3595 : : XResizeWindow( GetXDisplay(),
3596 : : GetWindow(),
3597 : : pEvent->width,
3598 : 0 : pEvent->height );
3599 : :
3600 : : XLIB_Window hDummy;
3601 : : XTranslateCoordinates( GetXDisplay(),
3602 : : GetWindow(),
3603 : : pDisplay_->GetRootWindow( pDisplay_->GetDefaultXScreen() ),
3604 : : 0, 0,
3605 : : &pEvent->x, &pEvent->y,
3606 : 0 : &hDummy );
3607 : :
3608 : 0 : if( pEvent->window == GetStackingWindow() )
3609 : : {
3610 : 0 : if( maGeometry.nX != pEvent->x || maGeometry.nY != pEvent->y )
3611 : : {
3612 : 0 : maGeometry.nX = pEvent->x;
3613 : 0 : maGeometry.nY = pEvent->y;
3614 : 0 : CallCallback( SALEVENT_MOVE, NULL );
3615 : : }
3616 : 0 : return 1;
3617 : : }
3618 : :
3619 : : // check size hints in first time SalFrame::Show
3620 : 0 : if( SHOWSTATE_UNKNOWN == nShowState_ && bMapped_ )
3621 : 0 : nShowState_ = SHOWSTATE_NORMAL;
3622 : :
3623 : : // Avoid a race condition where resizing this window to one size and shortly after that
3624 : : // to another size generates first size event with the old size and only after that
3625 : : // with the new size, temporarily making us think the old size is valid (bnc#674806).
3626 : : // So if there is another size event for this window pending, ignore this one.
3627 : 0 : mPendingSizeEvent = false;
3628 : : XEvent dummy;
3629 : 0 : XCheckIfEvent( GetXDisplay(), &dummy, size_event_predicate, reinterpret_cast< XPointer >( this ));
3630 : 0 : if( mPendingSizeEvent )
3631 : 0 : return 1;
3632 : :
3633 : 0 : nWidth_ = pEvent->width;
3634 : 0 : nHeight_ = pEvent->height;
3635 : :
3636 : 0 : bool bMoved = ( pEvent->x != maGeometry.nX || pEvent->y != maGeometry.nY );
3637 : 0 : bool bSized = ( pEvent->width != (int)maGeometry.nWidth || pEvent->height != (int)maGeometry.nHeight );
3638 : :
3639 : 0 : maGeometry.nX = pEvent->x;
3640 : 0 : maGeometry.nY = pEvent->y;
3641 : 0 : maGeometry.nWidth = pEvent->width;
3642 : 0 : maGeometry.nHeight = pEvent->height;
3643 : 0 : updateScreenNumber();
3644 : :
3645 : : // update children's position
3646 : 0 : RestackChildren();
3647 : :
3648 : 0 : if( bSized && ! bMoved )
3649 : 0 : CallCallback( SALEVENT_RESIZE, NULL );
3650 : 0 : else if( bMoved && ! bSized )
3651 : 0 : CallCallback( SALEVENT_MOVE, NULL );
3652 : 0 : else if( bMoved && bSized )
3653 : 0 : CallCallback( SALEVENT_MOVERESIZE, NULL );
3654 : :
3655 : 0 : return 1;
3656 : : }
3657 : :
3658 : 0 : IMPL_LINK_NOARG(X11SalFrame, HandleAlwaysOnTopRaise)
3659 : : {
3660 : 0 : if( bMapped_ )
3661 : 0 : ToTop( 0 );
3662 : 0 : return 0;
3663 : : }
3664 : :
3665 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
3666 : 0 : long X11SalFrame::HandleReparentEvent( XReparentEvent *pEvent )
3667 : : {
3668 : 0 : Display *pDisplay = pEvent->display;
3669 : : XLIB_Window hWM_Parent;
3670 : : XLIB_Window hRoot, *Children, hDummy;
3671 : : unsigned int nChildren;
3672 : 0 : sal_Bool bNone = pDisplay_->GetProperties()
3673 : 0 : & PROPERTY_SUPPORT_WM_Parent_Pixmap_None;
3674 : 0 : sal_Bool bAccessParentWindow = ! (pDisplay_->GetProperties()
3675 : 0 : & PROPERTY_FEATURE_TrustedSolaris);
3676 : :
3677 : 0 : static const char* pDisableStackingCheck = getenv( "SAL_DISABLE_STACKING_CHECK" );
3678 : :
3679 : 0 : GetGenericData()->ErrorTrapPush();
3680 : :
3681 : : /*
3682 : : * don't rely on the new parent from the event.
3683 : : * the event may be "out of date", that is the window manager
3684 : : * window may not exist anymore. This can happen if someone
3685 : : * shows a frame and hides it again quickly (not that that would
3686 : : * be very sensible)
3687 : : */
3688 : 0 : hWM_Parent = GetShellWindow();
3689 : 0 : do
3690 : : {
3691 : 0 : Children = NULL;
3692 : : XQueryTree( pDisplay,
3693 : : hWM_Parent,
3694 : : &hRoot,
3695 : : &hDummy,
3696 : : &Children,
3697 : 0 : &nChildren );
3698 : :
3699 : 0 : bool bError = GetGenericData()->ErrorTrapPop( false );
3700 : 0 : GetGenericData()->ErrorTrapPush();
3701 : :
3702 : 0 : if( bError )
3703 : : {
3704 : 0 : hWM_Parent = GetShellWindow();
3705 : 0 : break;
3706 : : }
3707 : : /* this sometimes happens if a Show(sal_True) is
3708 : : * immediately followed by Show(sal_False) (which is braindead anyway)
3709 : : */
3710 : 0 : if( hDummy == hWM_Parent )
3711 : 0 : hDummy = hRoot;
3712 : 0 : if( hDummy != hRoot )
3713 : : {
3714 : 0 : hWM_Parent = hDummy;
3715 : 0 : if( bAccessParentWindow && bNone )
3716 : 0 : XSetWindowBackgroundPixmap( pDisplay, hWM_Parent, None );
3717 : : }
3718 : 0 : if( Children )
3719 : 0 : XFree( Children );
3720 : : } while( hDummy != hRoot );
3721 : :
3722 : 0 : if( GetStackingWindow() == None
3723 : : && hWM_Parent != hPresentationWindow
3724 : 0 : && hWM_Parent != GetShellWindow()
3725 : 0 : && ( ! pDisableStackingCheck || ! *pDisableStackingCheck )
3726 : : )
3727 : : {
3728 : 0 : mhStackingWindow = hWM_Parent;
3729 : 0 : if (bAccessParentWindow)
3730 : 0 : XSelectInput( pDisplay, GetStackingWindow(), StructureNotifyMask );
3731 : : }
3732 : :
3733 : 0 : if( hWM_Parent == pDisplay_->GetRootWindow( pDisplay_->GetDefaultXScreen() )
3734 : 0 : || hWM_Parent == GetForeignParent()
3735 : 0 : || pEvent->parent == pDisplay_->GetRootWindow( pDisplay_->GetDefaultXScreen() )
3736 : : || ( nStyle_ & SAL_FRAME_STYLE_FLOAT ) )
3737 : : {
3738 : : // Reparenting before Destroy
3739 : 0 : aPresentationReparentList.remove( GetStackingWindow() );
3740 : 0 : mhStackingWindow = None;
3741 : 0 : GetGenericData()->ErrorTrapPop();
3742 : 0 : return 0;
3743 : : }
3744 : :
3745 : : /*
3746 : : * evil hack to show decorated windows on top
3747 : : * of override redirect presentation windows:
3748 : : * reparent the window manager window to the presentation window
3749 : : * does not work with non-reparenting WMs
3750 : : * in future this should not be necessary anymore with
3751 : : * _NET_WM_STATE_FULLSCREEN available
3752 : : */
3753 : 0 : if( hPresentationWindow != None
3754 : 0 : && hPresentationWindow != GetWindow()
3755 : 0 : && GetStackingWindow() != None
3756 : 0 : && GetStackingWindow() != GetDisplay()->GetRootWindow( m_nXScreen )
3757 : : )
3758 : : {
3759 : 0 : int x = 0, y = 0;
3760 : : XLIB_Window aChild;
3761 : : XTranslateCoordinates( GetXDisplay(),
3762 : : GetStackingWindow(),
3763 : : GetDisplay()->GetRootWindow( m_nXScreen ),
3764 : : 0, 0,
3765 : : &x, &y,
3766 : : &aChild
3767 : 0 : );
3768 : : XReparentWindow( GetXDisplay(),
3769 : : GetStackingWindow(),
3770 : : hPresentationWindow,
3771 : : x, y
3772 : 0 : );
3773 : 0 : aPresentationReparentList.push_back( GetStackingWindow() );
3774 : : }
3775 : :
3776 : 0 : int nLeft = 0, nTop = 0;
3777 : : XTranslateCoordinates( GetXDisplay(),
3778 : : GetShellWindow(),
3779 : : hWM_Parent,
3780 : : 0, 0,
3781 : : &nLeft,
3782 : : &nTop,
3783 : 0 : &hDummy );
3784 : 0 : maGeometry.nLeftDecoration = nLeft > 0 ? nLeft-1 : 0;
3785 : 0 : maGeometry.nTopDecoration = nTop > 0 ? nTop-1 : 0;
3786 : :
3787 : : /*
3788 : : * decorations are not symmetric,
3789 : : * so need real geometries here
3790 : : * (this will fail with virtual roots ?)
3791 : : */
3792 : :
3793 : : // reset error occurred
3794 : 0 : GetGenericData()->ErrorTrapPop();
3795 : 0 : GetGenericData()->ErrorTrapPush();
3796 : :
3797 : : int xp, yp, x, y;
3798 : : unsigned int wp, w, hp, h, bw, d;
3799 : : XGetGeometry( GetXDisplay(),
3800 : : GetShellWindow(),
3801 : : &hRoot,
3802 : 0 : &x, &y, &w, &h, &bw, &d );
3803 : : XGetGeometry( GetXDisplay(),
3804 : : hWM_Parent,
3805 : : &hRoot,
3806 : 0 : &xp, &yp, &wp, &hp, &bw, &d );
3807 : 0 : bool bResized = false;
3808 : 0 : bool bError = GetGenericData()->ErrorTrapPop( false );
3809 : 0 : GetGenericData()->ErrorTrapPush();
3810 : :
3811 : 0 : if( ! bError )
3812 : : {
3813 : 0 : maGeometry.nRightDecoration = wp - w - maGeometry.nLeftDecoration;
3814 : 0 : maGeometry.nBottomDecoration = hp - h - maGeometry.nTopDecoration;
3815 : : /*
3816 : : * note: this works because hWM_Parent is direct child of root,
3817 : : * not necessarily parent of GetShellWindow()
3818 : : */
3819 : 0 : maGeometry.nX = xp + nLeft;
3820 : 0 : maGeometry.nY = yp + nTop;
3821 : 0 : bResized = w != maGeometry.nWidth || h != maGeometry.nHeight;
3822 : 0 : maGeometry.nWidth = w;
3823 : 0 : maGeometry.nHeight = h;
3824 : : }
3825 : :
3826 : : // limit width and height if we are too large: #47757
3827 : : // olwm and fvwm need this, it doesnt harm the rest
3828 : :
3829 : : // #i81311# do this only for sizable frames
3830 : 0 : if( (nStyle_ & SAL_FRAME_STYLE_SIZEABLE) != 0 )
3831 : : {
3832 : 0 : Size aScreenSize = GetDisplay()->GetScreenSize( m_nXScreen );
3833 : 0 : int nScreenWidth = aScreenSize.Width();
3834 : 0 : int nScreenHeight = aScreenSize.Height();
3835 : 0 : int nFrameWidth = maGeometry.nWidth + maGeometry.nLeftDecoration + maGeometry.nRightDecoration;
3836 : 0 : int nFrameHeight = maGeometry.nHeight + maGeometry.nTopDecoration + maGeometry.nBottomDecoration;
3837 : :
3838 : 0 : if ((nFrameWidth > nScreenWidth) || (nFrameHeight > nScreenHeight))
3839 : : {
3840 : 0 : Size aSize(maGeometry.nWidth, maGeometry.nHeight);
3841 : :
3842 : 0 : if (nFrameWidth > nScreenWidth)
3843 : 0 : aSize.Width() = nScreenWidth - maGeometry.nRightDecoration - maGeometry.nLeftDecoration;
3844 : 0 : if (nFrameHeight > nScreenHeight)
3845 : 0 : aSize.Height() = nScreenHeight - maGeometry.nBottomDecoration - maGeometry.nTopDecoration;
3846 : :
3847 : 0 : SetSize( aSize );
3848 : 0 : bResized = false;
3849 : : }
3850 : : }
3851 : 0 : if( bResized )
3852 : 0 : CallCallback( SALEVENT_RESIZE, NULL );
3853 : :
3854 : 0 : GetGenericData()->ErrorTrapPop();
3855 : :
3856 : 0 : return 1;
3857 : : }
3858 : :
3859 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
3860 : 0 : long X11SalFrame::HandleColormapEvent( XColormapEvent* )
3861 : : {
3862 : 0 : return 0;
3863 : : }
3864 : :
3865 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
3866 : 0 : long X11SalFrame::HandleStateEvent( XPropertyEvent *pEvent )
3867 : : {
3868 : : Atom actual_type;
3869 : : int actual_format;
3870 : : unsigned long nitems, bytes_after;
3871 : 0 : unsigned char *prop = NULL;
3872 : :
3873 : 0 : if( 0 != XGetWindowProperty( GetXDisplay(),
3874 : : GetShellWindow(),
3875 : : pEvent->atom, // property
3876 : : 0, // long_offset (32bit)
3877 : : 2, // long_length (32bit)
3878 : : False, // delete
3879 : : pEvent->atom, // req_type
3880 : : &actual_type,
3881 : : &actual_format,
3882 : : &nitems,
3883 : : &bytes_after,
3884 : 0 : &prop )
3885 : 0 : || ! prop
3886 : : )
3887 : 0 : return 0;
3888 : :
3889 : : DBG_ASSERT( actual_type = pEvent->atom
3890 : : && 32 == actual_format
3891 : : && 2 == nitems
3892 : : && 0 == bytes_after, "HandleStateEvent" );
3893 : :
3894 : 0 : if( *(unsigned long*)prop == NormalState )
3895 : 0 : nShowState_ = SHOWSTATE_NORMAL;
3896 : 0 : else if( *(unsigned long*)prop == IconicState )
3897 : 0 : nShowState_ = SHOWSTATE_MINIMIZED;
3898 : :
3899 : 0 : XFree( prop );
3900 : 0 : return 1;
3901 : : }
3902 : :
3903 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
3904 : 0 : long X11SalFrame::HandleClientMessage( XClientMessageEvent *pEvent )
3905 : : {
3906 : 0 : const WMAdaptor& rWMAdaptor( *pDisplay_->getWMAdaptor() );
3907 : :
3908 : : #if !defined(__synchronous_extinput__)
3909 : 0 : if( pEvent->message_type == rWMAdaptor.getAtom( WMAdaptor::SAL_EXTTEXTEVENT ) )
3910 : : {
3911 : 0 : HandleExtTextEvent (pEvent);
3912 : 0 : return 1;
3913 : : }
3914 : : #endif
3915 : 0 : else if( pEvent->message_type == rWMAdaptor.getAtom( WMAdaptor::SAL_QUITEVENT ) )
3916 : : {
3917 : : stderr0( "X11SalFrame::Dispatch Quit\n" );
3918 : 0 : Close(); // ???
3919 : 0 : return 1;
3920 : : }
3921 : 0 : else if( pEvent->message_type == rWMAdaptor.getAtom( WMAdaptor::WM_PROTOCOLS ) )
3922 : : {
3923 : 0 : if( (Atom)pEvent->data.l[0] == rWMAdaptor.getAtom( WMAdaptor::NET_WM_PING ) )
3924 : 0 : rWMAdaptor.answerPing( this, pEvent );
3925 : 0 : else if( ! ( nStyle_ & SAL_FRAME_STYLE_PLUG )
3926 : 0 : && ! (( nStyle_ & SAL_FRAME_STYLE_FLOAT ) && (nStyle_ & SAL_FRAME_STYLE_OWNERDRAWDECORATION))
3927 : : )
3928 : : {
3929 : 0 : if( (Atom)pEvent->data.l[0] == rWMAdaptor.getAtom( WMAdaptor::WM_DELETE_WINDOW ) )
3930 : : {
3931 : 0 : Close();
3932 : 0 : return 1;
3933 : : }
3934 : 0 : else if( (Atom)pEvent->data.l[0] == rWMAdaptor.getAtom( WMAdaptor::WM_TAKE_FOCUS ) )
3935 : : {
3936 : : // do nothing, we set the input focus in ToTop() if necessary
3937 : : #if OSL_DEBUG_LEVEL > 1
3938 : : fprintf( stderr, "got WM_TAKE_FOCUS on %s window\n",
3939 : : (nStyle_&SAL_FRAME_STYLE_OWNERDRAWDECORATION) ?
3940 : : "ownerdraw" : "NON OWNERDRAW" );
3941 : : #endif
3942 : : }
3943 : : }
3944 : : }
3945 : 0 : else if( pEvent->message_type == rWMAdaptor.getAtom( WMAdaptor::XEMBED ) &&
3946 : 0 : pEvent->window == GetWindow() )
3947 : : {
3948 : 0 : if( pEvent->data.l[1] == 1 || // XEMBED_WINDOW_ACTIVATE
3949 : 0 : pEvent->data.l[1] == 2 ) // XEMBED_WINDOW_DEACTIVATE
3950 : : {
3951 : : XFocusChangeEvent aEvent;
3952 : 0 : aEvent.type = (pEvent->data.l[1] == 1 ? FocusIn : FocusOut);
3953 : 0 : aEvent.serial = pEvent->serial;
3954 : 0 : aEvent.send_event = True;
3955 : 0 : aEvent.display = pEvent->display;
3956 : 0 : aEvent.window = pEvent->window;
3957 : 0 : aEvent.mode = NotifyNormal;
3958 : 0 : aEvent.detail = NotifyDetailNone;
3959 : 0 : HandleFocusEvent( &aEvent );
3960 : : }
3961 : : }
3962 : 0 : return 0;
3963 : : }
3964 : :
3965 : : // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
3966 : :
3967 : : extern "C"
3968 : : {
3969 : 0 : Bool call_checkKeyReleaseForRepeat( Display* pDisplay, XEvent* pCheck, XPointer pX11SalFrame )
3970 : : {
3971 : 0 : return X11SalFrame::checkKeyReleaseForRepeat( pDisplay, pCheck, pX11SalFrame );
3972 : : }
3973 : : }
3974 : :
3975 : 0 : Bool X11SalFrame::checkKeyReleaseForRepeat( Display*, XEvent* pCheck, XPointer pX11SalFrame )
3976 : : {
3977 : 0 : X11SalFrame* pThis = (X11SalFrame*)pX11SalFrame;
3978 : : return
3979 : : pCheck->type == XLIB_KeyPress &&
3980 : : pCheck->xkey.state == pThis->nKeyState_ &&
3981 : : pCheck->xkey.keycode == pThis->nKeyCode_ &&
3982 : 0 : pCheck->xkey.time == pThis->nReleaseTime_ ? True : False;
3983 : : }
3984 : :
3985 : 0 : long X11SalFrame::Dispatch( XEvent *pEvent )
3986 : : {
3987 : 0 : long nRet = 0;
3988 : :
3989 : 0 : if( -1 == nCaptured_ )
3990 : : {
3991 : 0 : CaptureMouse( sal_True );
3992 : : #ifdef DBG_UTIL
3993 : : if( -1 != nCaptured_ )
3994 : : pDisplay_->DbgPrintDisplayEvent("Captured", pEvent);
3995 : : #endif
3996 : : }
3997 : :
3998 : 0 : if( pEvent->xany.window == GetShellWindow() || pEvent->xany.window == GetWindow() )
3999 : : {
4000 : 0 : switch( pEvent->type )
4001 : : {
4002 : : case XLIB_KeyPress:
4003 : 0 : nKeyCode_ = pEvent->xkey.keycode;
4004 : 0 : nKeyState_ = pEvent->xkey.state;
4005 : 0 : nRet = HandleKeyEvent( &pEvent->xkey );
4006 : 0 : break;
4007 : :
4008 : : case KeyRelease:
4009 : 0 : if( -1 == nCompose_ )
4010 : : {
4011 : 0 : nReleaseTime_ = pEvent->xkey.time;
4012 : : XEvent aEvent;
4013 : 0 : if( XCheckIfEvent( pEvent->xkey.display, &aEvent, call_checkKeyReleaseForRepeat, (XPointer)this ) )
4014 : 0 : XPutBackEvent( pEvent->xkey.display, &aEvent );
4015 : : else
4016 : 0 : nRet = HandleKeyEvent( &pEvent->xkey );
4017 : : }
4018 : 0 : break;
4019 : :
4020 : : case ButtonPress:
4021 : : // if we loose the focus in presentation mode
4022 : : // there are good chances that we never get it back
4023 : : // since the WM ignores us
4024 : 0 : if( IsOverrideRedirect() )
4025 : : {
4026 : : XSetInputFocus( GetXDisplay(), GetShellWindow(),
4027 : 0 : RevertToNone, CurrentTime );
4028 : : }
4029 : :
4030 : : case ButtonRelease:
4031 : : case MotionNotify:
4032 : : case EnterNotify:
4033 : : case LeaveNotify:
4034 : 0 : nRet = HandleMouseEvent( pEvent );
4035 : 0 : break;
4036 : :
4037 : : case FocusIn:
4038 : : case FocusOut:
4039 : 0 : nRet = HandleFocusEvent( &pEvent->xfocus );
4040 : 0 : break;
4041 : :
4042 : : case Expose:
4043 : : case GraphicsExpose:
4044 : 0 : nRet = HandleExposeEvent( pEvent );
4045 : 0 : break;
4046 : :
4047 : : case MapNotify:
4048 : 0 : if( pEvent->xmap.window == GetShellWindow() )
4049 : : {
4050 : 0 : if( nShowState_ == SHOWSTATE_HIDDEN )
4051 : : {
4052 : : /*
4053 : : * workaround for (at least) KWin 2.2.2
4054 : : * which will map windows that were once transient
4055 : : * even if they are withdrawn when the respective
4056 : : * document is mapped.
4057 : : */
4058 : 0 : if( ! (nStyle_ & SAL_FRAME_STYLE_PLUG) )
4059 : 0 : XUnmapWindow( GetXDisplay(), GetShellWindow() );
4060 : 0 : break;
4061 : : }
4062 : 0 : bMapped_ = sal_True;
4063 : 0 : bViewable_ = sal_True;
4064 : 0 : nRet = sal_True;
4065 : 0 : if ( mpInputContext != NULL )
4066 : 0 : mpInputContext->Map( this );
4067 : 0 : CallCallback( SALEVENT_RESIZE, NULL );
4068 : :
4069 : 0 : bool bSetFocus = m_bSetFocusOnMap;
4070 : : /* another workaround for sawfish: if a transient window for the same parent is shown
4071 : : * sawfish does not set the focus to it. Applies only for click to focus mode.
4072 : : */
4073 : 0 : if( ! (nStyle_ & SAL_FRAME_STYLE_FLOAT ) && mbInShow && GetDisplay()->getWMAdaptor()->getWindowManagerName().EqualsAscii( "Sawfish" ) )
4074 : : {
4075 : : // don't set the focus into the IME status window
4076 : : // since this will lead to a parent loose-focus, close status,
4077 : : // reget focus, open status, .... flicker loop
4078 : 0 : if ( (I18NStatus::get().getStatusFrame() != this) )
4079 : 0 : bSetFocus = true;
4080 : : }
4081 : :
4082 : : /*
4083 : : * sometimes a message box/dialogue is brought up when a frame is not mapped
4084 : : * the corresponding TRANSIENT_FOR hint is then set to the root window
4085 : : * so that the dialogue shows in all cases. Correct it here if the
4086 : : * frame is shown afterwards.
4087 : : */
4088 : 0 : if( ! IsChildWindow()
4089 : 0 : && ! IsOverrideRedirect()
4090 : 0 : && ! IsFloatGrabWindow()
4091 : : )
4092 : : {
4093 : 0 : for( std::list< X11SalFrame* >::const_iterator it = maChildren.begin();
4094 : 0 : it != maChildren.end(); ++it )
4095 : : {
4096 : 0 : if( (*it)->mbTransientForRoot )
4097 : 0 : pDisplay_->getWMAdaptor()->changeReferenceFrame( *it, this );
4098 : : }
4099 : : }
4100 : :
4101 : 0 : if( hPresentationWindow != None && GetShellWindow() == hPresentationWindow )
4102 : 0 : XSetInputFocus( GetXDisplay(), GetShellWindow(), RevertToParent, CurrentTime );
4103 : :
4104 : 0 : if( bSetFocus )
4105 : : {
4106 : : XSetInputFocus( GetXDisplay(),
4107 : : GetShellWindow(),
4108 : : RevertToParent,
4109 : 0 : CurrentTime );
4110 : : }
4111 : :
4112 : :
4113 : 0 : RestackChildren();
4114 : 0 : mbInShow = sal_False;
4115 : 0 : m_bSetFocusOnMap = false;
4116 : : }
4117 : 0 : break;
4118 : :
4119 : : case UnmapNotify:
4120 : 0 : if( pEvent->xunmap.window == GetShellWindow() )
4121 : : {
4122 : 0 : bMapped_ = sal_False;
4123 : 0 : bViewable_ = sal_False;
4124 : 0 : nRet = sal_True;
4125 : 0 : if ( mpInputContext != NULL )
4126 : 0 : mpInputContext->Unmap( this );
4127 : 0 : CallCallback( SALEVENT_RESIZE, NULL );
4128 : : }
4129 : 0 : break;
4130 : :
4131 : : case ConfigureNotify:
4132 : 0 : if( pEvent->xconfigure.window == GetShellWindow()
4133 : 0 : || pEvent->xconfigure.window == GetWindow() )
4134 : 0 : nRet = HandleSizeEvent( &pEvent->xconfigure );
4135 : 0 : break;
4136 : :
4137 : : case VisibilityNotify:
4138 : 0 : nVisibility_ = pEvent->xvisibility.state;
4139 : 0 : nRet = sal_True;
4140 : 0 : if( bAlwaysOnTop_
4141 : : && bMapped_
4142 : 0 : && ! GetDisplay()->getWMAdaptor()->isAlwaysOnTopOK()
4143 : : && nVisibility_ != VisibilityUnobscured )
4144 : 0 : maAlwaysOnTopRaiseTimer.Start();
4145 : 0 : break;
4146 : :
4147 : : case ReparentNotify:
4148 : 0 : nRet = HandleReparentEvent( &pEvent->xreparent );
4149 : 0 : break;
4150 : :
4151 : : case MappingNotify:
4152 : 0 : if( MappingPointer != pEvent->xmapping.request )
4153 : 0 : nRet = CallCallback( SALEVENT_KEYBOARDCHANGED, 0 );
4154 : 0 : break;
4155 : :
4156 : : case ColormapNotify:
4157 : 0 : nRet = HandleColormapEvent( &pEvent->xcolormap );
4158 : 0 : break;
4159 : :
4160 : : case PropertyNotify:
4161 : : {
4162 : 0 : if( pEvent->xproperty.atom == pDisplay_->getWMAdaptor()->getAtom( WMAdaptor::WM_STATE ) )
4163 : 0 : nRet = HandleStateEvent( &pEvent->xproperty );
4164 : : else
4165 : 0 : nRet = pDisplay_->getWMAdaptor()->handlePropertyNotify( this, &pEvent->xproperty );
4166 : 0 : break;
4167 : : }
4168 : :
4169 : : case ClientMessage:
4170 : 0 : nRet = HandleClientMessage( &pEvent->xclient );
4171 : 0 : break;
4172 : : }
4173 : : }
4174 : : else
4175 : : {
4176 : 0 : switch( pEvent->type )
4177 : : {
4178 : : case FocusIn:
4179 : : case FocusOut:
4180 : 0 : if( ( nStyle_ & SAL_FRAME_STYLE_PLUG )
4181 : 0 : && ( pEvent->xfocus.window == GetShellWindow()
4182 : 0 : || pEvent->xfocus.window == GetForeignParent() )
4183 : : )
4184 : : {
4185 : 0 : nRet = HandleFocusEvent( &pEvent->xfocus );
4186 : : }
4187 : 0 : break;
4188 : :
4189 : : case ConfigureNotify:
4190 : 0 : if( pEvent->xconfigure.window == GetForeignParent() ||
4191 : 0 : pEvent->xconfigure.window == GetShellWindow() )
4192 : 0 : nRet = HandleSizeEvent( &pEvent->xconfigure );
4193 : :
4194 : 0 : if( pEvent->xconfigure.window == GetStackingWindow() )
4195 : 0 : nRet = HandleSizeEvent( &pEvent->xconfigure );
4196 : :
4197 : 0 : RestackChildren();
4198 : 0 : break;
4199 : : }
4200 : : }
4201 : :
4202 : 0 : return nRet;
4203 : : }
4204 : :
4205 : 0 : void X11SalFrame::ResetClipRegion()
4206 : : {
4207 : 0 : delete [] m_pClipRectangles;
4208 : 0 : m_pClipRectangles = NULL;
4209 : 0 : m_nCurClipRect = m_nMaxClipRect = 0;
4210 : :
4211 : 0 : const int dest_kind = ShapeBounding;
4212 : 0 : const int op = ShapeSet;
4213 : 0 : const int ordering = YSorted;
4214 : :
4215 : : XWindowAttributes win_attrib;
4216 : : XRectangle win_size;
4217 : :
4218 : 0 : XLIB_Window aShapeWindow = mhShellWindow;
4219 : :
4220 : : XGetWindowAttributes ( GetDisplay()->GetDisplay(),
4221 : : aShapeWindow,
4222 : 0 : &win_attrib );
4223 : :
4224 : 0 : win_size.x = 0;
4225 : 0 : win_size.y = 0;
4226 : 0 : win_size.width = win_attrib.width;
4227 : 0 : win_size.height = win_attrib.height;
4228 : :
4229 : : XShapeCombineRectangles ( GetDisplay()->GetDisplay(),
4230 : : aShapeWindow,
4231 : : dest_kind,
4232 : : 0, 0, // x_off, y_off
4233 : : &win_size, // list of rectangles
4234 : : 1, // number of rectangles
4235 : 0 : op, ordering );
4236 : 0 : }
4237 : :
4238 : 0 : void X11SalFrame::BeginSetClipRegion( sal_uLong nRects )
4239 : : {
4240 : 0 : if( m_pClipRectangles )
4241 : 0 : delete [] m_pClipRectangles;
4242 : 0 : if( nRects )
4243 : 0 : m_pClipRectangles = new XRectangle[nRects];
4244 : : else
4245 : 0 : m_pClipRectangles = NULL;
4246 : 0 : m_nMaxClipRect = static_cast<int>(nRects);
4247 : 0 : m_nCurClipRect = 0;
4248 : 0 : }
4249 : :
4250 : 0 : void X11SalFrame::UnionClipRegion( long nX, long nY, long nWidth, long nHeight )
4251 : : {
4252 : 0 : if( m_pClipRectangles && m_nCurClipRect < m_nMaxClipRect )
4253 : : {
4254 : 0 : m_pClipRectangles[m_nCurClipRect].x = nX;
4255 : 0 : m_pClipRectangles[m_nCurClipRect].y = nY;
4256 : 0 : m_pClipRectangles[m_nCurClipRect].width = nWidth;
4257 : 0 : m_pClipRectangles[m_nCurClipRect].height = nHeight;
4258 : 0 : m_nCurClipRect++;
4259 : : }
4260 : 0 : }
4261 : :
4262 : 0 : void X11SalFrame::EndSetClipRegion()
4263 : : {
4264 : 0 : const int dest_kind = ShapeBounding;
4265 : 0 : const int ordering = YSorted;
4266 : 0 : const int op = ShapeSet;
4267 : :
4268 : 0 : XLIB_Window aShapeWindow = mhShellWindow;
4269 : : XShapeCombineRectangles ( GetDisplay()->GetDisplay(),
4270 : : aShapeWindow,
4271 : : dest_kind,
4272 : : 0, 0, // x_off, y_off
4273 : : m_pClipRectangles,
4274 : : m_nCurClipRect,
4275 : 0 : op, ordering );
4276 : :
4277 : 0 : }
4278 : :
4279 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|