]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/toplevel.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
23 #include "wx/toplevel.h"
24 #include "wx/settings.h"
32 #pragma message disable nosimpint
36 #include <X11/Shell.h>
45 #pragma message enable nosimpint
48 #include "wx/motif/private.h"
50 wxList wxModelessWindows
; // Frames and modeless dialogs
52 // ---------------------------------------------------------------------------
54 // ---------------------------------------------------------------------------
56 static void wxCloseTLWCallback( Widget widget
, XtPointer client_data
,
57 XmAnyCallbackStruct
*cbs
);
58 static void wxTLWEventHandler( Widget wid
,
59 XtPointer client_data
,
61 Boolean
*continueToDispatch
);
63 // ===========================================================================
64 // wxTopLevelWindowMotif implementation
65 // ===========================================================================
67 void wxTopLevelWindowMotif::PreDestroy()
69 wxModelessWindows
.DeleteObject(this);
73 // MessageDialog and FileDialog do not have a client widget
74 if( GetClientWidget() )
76 XtRemoveEventHandler( (Widget
)GetClientWidget(),
77 ButtonPressMask
| ButtonReleaseMask
|
78 PointerMotionMask
| KeyPressMask
,
85 wxTopLevelWindowMotif::~wxTopLevelWindowMotif()
87 SetMainWidget( (WXWidget
)0 );
90 void wxTopLevelWindowMotif::Init()
95 bool wxTopLevelWindowMotif::Create( wxWindow
*parent
, wxWindowID id
,
96 const wxString
& title
,
100 const wxString
& name
)
103 m_windowStyle
= style
;
106 parent
->AddChild(this);
108 wxTopLevelWindows
.Append(this);
110 m_windowId
= ( id
> -1 ) ? id
: NewControlId();
111 // MBN: More backward compatible, but uglier
112 m_font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
113 m_inheritFont
= true;
115 bool retval
= XmDoCreateTLW( parent
, id
, title
, pos
, size
, style
, name
);
117 if( !retval
) return false;
119 // Intercept CLOSE messages from the window manager
120 Widget shell
= (Widget
)GetShellWidget();
121 Atom WM_DELETE_WINDOW
= XmInternAtom( XtDisplay( shell
),
122 "WM_DELETE_WINDOW", False
);
124 // Remove and add WM_DELETE_WINDOW so ours is only handler
125 // This only appears to be necessary for wxDialog, but does not hurt
127 XmRemoveWMProtocols( shell
, &WM_DELETE_WINDOW
, 1 );
128 XmAddWMProtocols( shell
, &WM_DELETE_WINDOW
, 1 );
129 XmActivateWMProtocol( shell
, WM_DELETE_WINDOW
);
131 // Modified Steve Hammes for Motif 2.0
132 #if (XmREVISION > 1 || XmVERSION > 1)
133 XmAddWMProtocolCallback( shell
, WM_DELETE_WINDOW
,
134 (XtCallbackProc
)wxCloseTLWCallback
,
136 #elif XmREVISION == 1
137 XmAddWMProtocolCallback( shell
, WM_DELETE_WINDOW
,
138 (XtCallbackProc
)wxCloseTLWCallback
,
141 XmAddWMProtocolCallback( shell
, WM_DELETE_WINDOW
,
142 (void (*)())wxCloseTLWCallback
, (caddr_t
)this );
145 // This patch come from Torsten Liermann lier@lier1.muc.de
146 if( XmIsMotifWMRunning( shell
) )
149 if( !(m_windowStyle
& wxNO_BORDER
) )
150 decor
|= MWM_DECOR_BORDER
;
151 if( m_windowStyle
& wxRESIZE_BORDER
)
152 decor
|= MWM_DECOR_RESIZEH
;
153 if( m_windowStyle
& wxSYSTEM_MENU
)
154 decor
|= MWM_DECOR_MENU
;
155 if( ( m_windowStyle
& wxCAPTION
) ||
156 ( m_windowStyle
& wxTINY_CAPTION_HORIZ
) ||
157 ( m_windowStyle
& wxTINY_CAPTION_VERT
) )
158 decor
|= MWM_DECOR_TITLE
;
159 if( m_windowStyle
& wxRESIZE_BORDER
)
160 decor
|= MWM_DECOR_BORDER
;
161 if( m_windowStyle
& wxMINIMIZE_BOX
)
162 decor
|= MWM_DECOR_MINIMIZE
;
163 if( m_windowStyle
& wxMAXIMIZE_BOX
)
164 decor
|= MWM_DECOR_MAXIMIZE
;
166 XtVaSetValues( shell
,
167 XmNmwmDecorations
, decor
,
172 // This allows non-Motif window managers to support at least the
173 // no-decorations case.
174 if( ( m_windowStyle
& wxCAPTION
) != wxCAPTION
)
175 XtVaSetValues( shell
,
176 XmNoverrideRedirect
, True
,
180 XtAddEventHandler( (Widget
)GetClientWidget(),
181 ButtonPressMask
| ButtonReleaseMask
|
182 PointerMotionMask
| KeyPressMask
,
190 void wxTopLevelWindowMotif::DoGetPosition(int *x
, int *y
) const
192 Widget top
= (Widget
) GetTopWidget();
193 Window parent_window
= XtWindow((Widget
) top
),
194 next_parent
= XtWindow((Widget
) top
),
195 root
= RootWindowOfScreen(XtScreen((Widget
) top
));
197 // search for the parent that is child of ROOT, because the WM may
198 // reparent twice and notify only the next parent (like FVWM)
199 while (next_parent
!= root
) {
200 Window
*theChildren
; unsigned int n
;
201 parent_window
= next_parent
;
202 XQueryTree(XtDisplay((Widget
) top
), parent_window
, &root
,
203 &next_parent
, &theChildren
, &n
);
204 XFree(theChildren
); // not needed
206 int xx
, yy
; unsigned int dummy
;
207 XGetGeometry(XtDisplay((Widget
) top
), parent_window
, &root
,
208 &xx
, &yy
, &dummy
, &dummy
, &dummy
, &dummy
);
213 void wxTopLevelWindowMotif::Raise()
215 Widget top
= (Widget
) GetTopWidget();
216 Window parent_window
= XtWindow( top
),
217 next_parent
= XtWindow( top
),
218 root
= RootWindowOfScreen( XtScreen( top
) );
219 // search for the parent that is child of ROOT, because the WM may
220 // reparent twice and notify only the next parent (like FVWM)
221 while( next_parent
!= root
)
226 parent_window
= next_parent
;
227 XQueryTree( XtDisplay( top
), parent_window
, &root
,
228 &next_parent
, &theChildren
, &n
);
229 XFree( theChildren
); // not needed
231 XRaiseWindow( XtDisplay( top
), parent_window
);
234 void wxTopLevelWindowMotif::Lower()
236 Widget top
= (Widget
) GetTopWidget();
237 Window parent_window
= XtWindow( top
),
238 next_parent
= XtWindow( top
),
239 root
= RootWindowOfScreen( XtScreen( top
) );
240 // search for the parent that is child of ROOT, because the WM may
241 // reparent twice and notify only the next parent (like FVWM)
242 while( next_parent
!= root
)
247 parent_window
= next_parent
;
248 XQueryTree( XtDisplay( top
), parent_window
, &root
,
249 &next_parent
, &theChildren
, &n
);
250 XFree( theChildren
); // not needed
252 XLowerWindow( XtDisplay( top
), parent_window
);
255 static inline Widget
GetShell( const wxTopLevelWindowMotif
* tlw
)
257 Widget main
= (Widget
) tlw
->GetMainWidget();
258 if( !main
) return (Widget
) NULL
;
260 return XtParent( main
);
263 WXWidget
wxTopLevelWindowMotif::GetShellWidget() const
265 return (WXWidget
) GetShell( this );
268 bool wxTopLevelWindowMotif::ShowFullScreen( bool WXUNUSED(show
),
269 long WXUNUSED(style
) )
275 bool wxTopLevelWindowMotif::IsFullScreen() const
281 void wxTopLevelWindowMotif::Restore()
283 Widget shell
= GetShell( this );
286 XtVaSetValues( shell
,
291 void wxTopLevelWindowMotif::Iconize( bool iconize
)
293 Widget shell
= GetShell( this );
299 XtVaSetValues( shell
,
300 XmNiconic
, (Boolean
)iconize
,
304 bool wxTopLevelWindowMotif::IsIconized() const
306 Widget shell
= GetShell( this );
312 XtVaGetValues( shell
,
316 return (iconic
== True
);
319 void wxTopLevelWindowMotif::Maximize( bool maximize
)
327 bool wxTopLevelWindowMotif::IsMaximized() const
332 void wxTopLevelWindowMotif::DoSetSizeHints( int minW
, int minH
,
336 wxTopLevelWindowBase::DoSetSizeHints( minW
, minH
, maxW
, maxH
, incW
, incH
);
341 if( minW
> -1 ) { XtSetArg( args
[count
], XmNminWidth
, minW
); ++count
; }
342 if( minH
> -1 ) { XtSetArg( args
[count
], XmNminHeight
, minH
); ++count
; }
343 if( maxW
> -1 ) { XtSetArg( args
[count
], XmNmaxWidth
, maxW
); ++count
; }
344 if( maxH
> -1 ) { XtSetArg( args
[count
], XmNmaxHeight
, maxH
); ++count
; }
345 if( incW
> -1 ) { XtSetArg( args
[count
], XmNwidthInc
, incW
); ++count
; }
346 if( incH
> -1 ) { XtSetArg( args
[count
], XmNheightInc
, incH
); ++count
; }
348 XtSetValues( (Widget
)GetShellWidget(), args
, count
);
351 bool wxTopLevelWindowMotif::SetShape( const wxRegion
& region
)
353 return wxDoSetShape( (Display
*)GetXDisplay(),
354 XtWindow( (Widget
)GetShellWidget() ),
358 // ---------------------------------------------------------------------------
359 // Callback definition
360 // ---------------------------------------------------------------------------
362 // Handle a close event from the window manager
363 static void wxCloseTLWCallback( Widget
WXUNUSED(widget
), XtPointer client_data
,
364 XmAnyCallbackStruct
*WXUNUSED(cbs
) )
366 wxTopLevelWindowMotif
* tlw
= (wxTopLevelWindowMotif
*)client_data
;
367 wxCloseEvent
closeEvent( wxEVT_CLOSE_WINDOW
, tlw
->GetId() );
368 closeEvent
.SetEventObject( tlw
);
370 // May delete the dialog (with delayed deletion)
371 tlw
->HandleWindowEvent(closeEvent
);
374 void wxTLWEventHandler( Widget wid
,
375 XtPointer
WXUNUSED(client_data
),
377 Boolean
* continueToDispatch
)
379 wxTopLevelWindowMotif
* tlw
=
380 (wxTopLevelWindowMotif
*)wxGetWindowFromTable( wid
);
384 wxMouseEvent
wxevent( wxEVT_NULL
);
386 if( wxTranslateMouseEvent( wxevent
, tlw
, wid
, event
) )
388 wxevent
.SetEventObject( tlw
);
389 wxevent
.SetId( tlw
->GetId() );
390 tlw
->HandleWindowEvent( wxevent
);
394 // An attempt to implement OnCharHook by calling OnCharHook first;
395 // if this returns true, set continueToDispatch to False
396 // (don't continue processing).
397 // Otherwise set it to True and call OnChar.
398 wxKeyEvent
keyEvent( wxEVT_CHAR
);
399 if( wxTranslateKeyEvent( keyEvent
, tlw
, wid
, event
))
401 keyEvent
.SetEventObject( tlw
);
402 keyEvent
.SetId( tlw
->GetId() );
403 keyEvent
.SetEventType( wxEVT_CHAR_HOOK
);
404 if( tlw
->HandleWindowEvent( keyEvent
) )
406 *continueToDispatch
= False
;
411 // For simplicity, OnKeyDown is the same as OnChar
412 // TODO: filter modifier key presses from OnChar
413 keyEvent
.SetEventType( wxEVT_KEY_DOWN
);
415 // Only process OnChar if OnKeyDown didn't swallow it
416 if( !tlw
->HandleWindowEvent( keyEvent
) )
418 keyEvent
.SetEventType( wxEVT_CHAR
);
419 tlw
->HandleWindowEvent( keyEvent
);
426 *continueToDispatch
= True
;