]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/toplevel.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: motif/toplevel.cpp
3 // Purpose: wxTopLevelWindow Motif implementation
4 // Author: Mattia Barbon
8 // Copyright: (c) Mattia Barbon
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "toplevel.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
27 #include "wx/toplevel.h"
31 #define XtDisplay XTDISPLAY
32 #define XtParent XTPARENT
33 #define XtScreen XTSCREEN
34 #define XtWindow XTWINDOW
35 #pragma message disable nosimpint
39 #include <X11/Shell.h>
48 #pragma message enable nosimpint
51 #include "wx/motif/private.h"
53 wxList wxModelessWindows
; // Frames and modeless dialogs
55 // ---------------------------------------------------------------------------
57 // ---------------------------------------------------------------------------
59 static void wxCloseTLWCallback( Widget widget
, XtPointer client_data
,
60 XmAnyCallbackStruct
*cbs
);
61 static void wxTLWEventHandler( Widget wid
,
62 XtPointer client_data
,
64 Boolean
*continueToDispatch
);
66 // ===========================================================================
67 // wxTopLevelWindowMotif implementation
68 // ===========================================================================
70 void wxTopLevelWindowMotif::PreDestroy()
73 #pragma message disable codcauunr
75 if ( (GetWindowStyleFlag() & wxDIALOG_MODAL
) != wxDIALOG_MODAL
)
76 wxModelessWindows
.DeleteObject(this);
78 #pragma message enable codcauunr
81 m_icons
.m_icons
.Empty();
85 // MessageDialog and FileDialog do not have a client widget
86 if( GetClientWidget() )
88 XtRemoveEventHandler( (Widget
)GetClientWidget(),
89 ButtonPressMask
| ButtonReleaseMask
|
90 PointerMotionMask
| KeyPressMask
,
97 wxTopLevelWindowMotif::~wxTopLevelWindowMotif()
99 SetMainWidget( (WXWidget
)0 );
102 void wxTopLevelWindowMotif::Init()
107 bool wxTopLevelWindowMotif::Create( wxWindow
*parent
, wxWindowID id
,
108 const wxString
& title
,
112 const wxString
& name
)
115 m_windowStyle
= style
;
118 parent
->AddChild(this);
120 wxTopLevelWindows
.Append(this);
122 m_windowId
= ( id
> -1 ) ? id
: NewControlId();
124 bool retval
= DoCreate( parent
, id
, title
, pos
, size
, style
, name
);
126 if( !retval
) return FALSE
;
128 // Intercept CLOSE messages from the window manager
129 Widget shell
= (Widget
)GetShellWidget();
130 Atom WM_DELETE_WINDOW
= XmInternAtom( XtDisplay( shell
),
131 "WM_DELETE_WINDOW", False
);
133 // Remove and add WM_DELETE_WINDOW so ours is only handler
134 // This only appears to be necessary for wxDialog, but does not hurt
136 XmRemoveWMProtocols( shell
, &WM_DELETE_WINDOW
, 1 );
137 XmAddWMProtocols( shell
, &WM_DELETE_WINDOW
, 1 );
138 XmActivateWMProtocol( shell
, WM_DELETE_WINDOW
);
140 // Modified Steve Hammes for Motif 2.0
141 #if (XmREVISION > 1 || XmVERSION > 1)
142 XmAddWMProtocolCallback( shell
, WM_DELETE_WINDOW
,
143 (XtCallbackProc
)wxCloseTLWCallback
,
145 #elif XmREVISION == 1
146 XmAddWMProtocolCallback( shell
, WM_DELETE_WINDOW
,
147 (XtCallbackProc
)wxCloseTLWCallback
,
150 XmAddWMProtocolCallback( shell
, WM_DELETE_WINDOW
,
151 (void (*)())wxCloseTLWCallback
, (caddr_t
)this );
154 // This patch come from Torsten Liermann lier@lier1.muc.de
155 if( XmIsMotifWMRunning( shell
) )
158 if( m_windowStyle
& wxRESIZE_BORDER
)
159 decor
|= MWM_DECOR_RESIZEH
;
160 if( m_windowStyle
& wxSYSTEM_MENU
)
161 decor
|= MWM_DECOR_MENU
;
162 if( ( m_windowStyle
& wxCAPTION
) ||
163 ( m_windowStyle
& wxTINY_CAPTION_HORIZ
) ||
164 ( m_windowStyle
& wxTINY_CAPTION_VERT
) )
165 decor
|= MWM_DECOR_TITLE
;
166 if( m_windowStyle
& wxTHICK_FRAME
)
167 decor
|= MWM_DECOR_BORDER
;
168 if( m_windowStyle
& wxMINIMIZE_BOX
)
169 decor
|= MWM_DECOR_MINIMIZE
;
170 if( m_windowStyle
& wxMAXIMIZE_BOX
)
171 decor
|= MWM_DECOR_MAXIMIZE
;
173 XtVaSetValues( shell
,
174 XmNmwmDecorations
, decor
,
179 // This allows non-Motif window managers to support at least the
180 // no-decorations case.
181 if( ( m_windowStyle
& wxCAPTION
) != wxCAPTION
)
182 XtVaSetValues( shell
,
183 XmNoverrideRedirect
, TRUE
,
187 XtAddEventHandler( (Widget
)GetClientWidget(),
188 ButtonPressMask
| ButtonReleaseMask
|
189 PointerMotionMask
| KeyPressMask
,
197 void wxTopLevelWindowMotif::DoGetPosition(int *x
, int *y
) const
199 Widget top
= (Widget
) GetTopWidget();
200 Window parent_window
= XtWindow((Widget
) top
),
201 next_parent
= XtWindow((Widget
) top
),
202 root
= RootWindowOfScreen(XtScreen((Widget
) top
));
204 // search for the parent that is child of ROOT, because the WM may
205 // reparent twice and notify only the next parent (like FVWM)
206 while (next_parent
!= root
) {
207 Window
*theChildren
; unsigned int n
;
208 parent_window
= next_parent
;
209 XQueryTree(XtDisplay((Widget
) top
), parent_window
, &root
,
210 &next_parent
, &theChildren
, &n
);
211 XFree(theChildren
); // not needed
213 int xx
, yy
; unsigned int dummy
;
214 XGetGeometry(XtDisplay((Widget
) top
), parent_window
, &root
,
215 &xx
, &yy
, &dummy
, &dummy
, &dummy
, &dummy
);
220 void wxTopLevelWindowMotif::Raise()
222 Widget top
= (Widget
) GetTopWidget();
223 Window parent_window
= XtWindow( top
),
224 next_parent
= XtWindow( top
),
225 root
= RootWindowOfScreen( XtScreen( top
) );
226 // search for the parent that is child of ROOT, because the WM may
227 // reparent twice and notify only the next parent (like FVWM)
228 while( next_parent
!= root
)
233 parent_window
= next_parent
;
234 XQueryTree( XtDisplay( top
), parent_window
, &root
,
235 &next_parent
, &theChildren
, &n
);
236 XFree( theChildren
); // not needed
238 XRaiseWindow( XtDisplay( top
), parent_window
);
241 void wxTopLevelWindowMotif::Lower()
243 Widget top
= (Widget
) GetTopWidget();
244 Window parent_window
= XtWindow( top
),
245 next_parent
= XtWindow( top
),
246 root
= RootWindowOfScreen( XtScreen( top
) );
247 // search for the parent that is child of ROOT, because the WM may
248 // reparent twice and notify only the next parent (like FVWM)
249 while( next_parent
!= root
)
254 parent_window
= next_parent
;
255 XQueryTree( XtDisplay( top
), parent_window
, &root
,
256 &next_parent
, &theChildren
, &n
);
257 XFree( theChildren
); // not needed
259 XLowerWindow( XtDisplay( top
), parent_window
);
262 static inline Widget
GetShell( const wxTopLevelWindowMotif
* tlw
)
264 Widget main
= (Widget
) tlw
->GetMainWidget();
265 if( !main
) return (Widget
) NULL
;
267 return XtParent( main
);
270 WXWidget
wxTopLevelWindowMotif::GetShellWidget() const
272 return (WXWidget
) GetShell( this );
275 bool wxTopLevelWindowMotif::ShowFullScreen( bool show
,
282 bool wxTopLevelWindowMotif::IsFullScreen() const
288 void wxTopLevelWindowMotif::Restore()
290 Widget shell
= GetShell( this );
293 XtVaSetValues( shell
,
298 void wxTopLevelWindowMotif::Iconize( bool iconize
)
300 Widget shell
= GetShell( this );
306 XtVaSetValues( shell
,
307 XmNiconic
, (Boolean
)iconize
,
311 bool wxTopLevelWindowMotif::IsIconized() const
313 Widget shell
= GetShell( this );
319 XtVaGetValues( shell
,
326 void wxTopLevelWindowMotif::Maximize( bool maximize
)
334 bool wxTopLevelWindowMotif::IsMaximized() const
339 void wxTopLevelWindowMotif::SetSizeHints( int minW
, int minH
,
343 wxTopLevelWindowBase::SetSizeHints( minW
, minH
, maxW
, maxH
, incW
, incH
);
348 if( minW
> -1 ) { XtSetArg( args
[count
], XmNminWidth
, minW
); ++count
; }
349 if( minH
> -1 ) { XtSetArg( args
[count
], XmNminHeight
, minH
); ++count
; }
350 if( maxW
> -1 ) { XtSetArg( args
[count
], XmNmaxWidth
, maxW
); ++count
; }
351 if( maxH
> -1 ) { XtSetArg( args
[count
], XmNmaxHeight
, maxH
); ++count
; }
352 if( incW
> -1 ) { XtSetArg( args
[count
], XmNwidthInc
, incW
); ++count
; }
353 if( incH
> -1 ) { XtSetArg( args
[count
], XmNheightInc
, incH
); ++count
; }
355 XtSetValues( (Widget
)GetShellWidget(), args
, count
);
358 bool wxTopLevelWindowMotif::SetShape( const wxRegion
& region
)
360 return wxDoSetShape( (Display
*)GetXDisplay(),
361 XtWindow( (Widget
)GetShellWidget() ),
365 // ---------------------------------------------------------------------------
366 // Callback definition
367 // ---------------------------------------------------------------------------
369 // Handle a close event from the window manager
370 static void wxCloseTLWCallback( Widget
WXUNUSED(widget
), XtPointer client_data
,
371 XmAnyCallbackStruct
*WXUNUSED(cbs
) )
373 wxTopLevelWindowMotif
* tlw
= (wxTopLevelWindowMotif
*)client_data
;
374 wxCloseEvent
closeEvent( wxEVT_CLOSE_WINDOW
, tlw
->GetId() );
375 closeEvent
.SetEventObject( tlw
);
377 // May delete the dialog (with delayed deletion)
378 tlw
->GetEventHandler()->ProcessEvent(closeEvent
);
381 void wxTLWEventHandler( Widget wid
,
382 XtPointer
WXUNUSED(client_data
),
384 Boolean
* continueToDispatch
)
386 wxTopLevelWindowMotif
* tlw
=
387 (wxTopLevelWindowMotif
*)wxGetWindowFromTable( wid
);
391 wxMouseEvent
wxevent( wxEVT_NULL
);
393 if( wxTranslateMouseEvent( wxevent
, tlw
, wid
, event
) )
395 wxevent
.SetEventObject( tlw
);
396 wxevent
.SetId( tlw
->GetId() );
397 tlw
->GetEventHandler()->ProcessEvent( wxevent
);
401 // An attempt to implement OnCharHook by calling OnCharHook first;
402 // if this returns TRUE, set continueToDispatch to False
403 // (don't continue processing).
404 // Otherwise set it to True and call OnChar.
405 wxKeyEvent
keyEvent( wxEVT_CHAR
);
406 if( wxTranslateKeyEvent( keyEvent
, tlw
, wid
, event
))
408 keyEvent
.SetEventObject( tlw
);
409 keyEvent
.SetId( tlw
->GetId() );
410 keyEvent
.SetEventType( wxEVT_CHAR_HOOK
);
411 if( tlw
->GetEventHandler()->ProcessEvent( keyEvent
) )
413 *continueToDispatch
= False
;
418 // For simplicity, OnKeyDown is the same as OnChar
419 // TODO: filter modifier key presses from OnChar
420 keyEvent
.SetEventType( wxEVT_KEY_DOWN
);
422 // Only process OnChar if OnKeyDown didn't swallow it
423 if( !tlw
->GetEventHandler()->ProcessEvent( keyEvent
) )
425 keyEvent
.SetEventType( wxEVT_CHAR
);
426 tlw
->GetEventHandler()->ProcessEvent( keyEvent
);
433 *continueToDispatch
= True
;