]>
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(__APPLE__)
21 #pragma implementation "toplevel.h"
24 #include "wx/toplevel.h"
28 #define XtDisplay XTDISPLAY
29 #define XtParent XTPARENT
30 #define XtScreen XTSCREEN
31 #define XtWindow XTWINDOW
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 wxTopLevelWindowMotif::~wxTopLevelWindowMotif()
69 wxTopLevelWindows
.DeleteObject(this);
71 if ( (GetWindowStyleFlag() & wxDIALOG_MODAL
) != wxDIALOG_MODAL
)
72 wxModelessWindows
.DeleteObject(this);
74 m_icons
.m_icons
.Empty();
78 // MessageDialog and FileDialog do not have a client widget
79 if( GetClientWidget() )
81 XtRemoveEventHandler( (Widget
)GetClientWidget(),
82 ButtonPressMask
| ButtonReleaseMask
|
83 PointerMotionMask
| KeyPressMask
,
91 SetMainWidget( (WXWidget
)0 );
93 // If this is the last top-level window, exit.
94 if (wxTheApp
&& (wxTopLevelWindows
.GetCount() == 0))
96 wxTheApp
->SetTopWindow(NULL
);
98 if (wxTheApp
->GetExitOnFrameDelete())
100 wxTheApp
->ExitMainLoop();
105 void wxTopLevelWindowMotif::Init()
110 bool wxTopLevelWindowMotif::Create( wxWindow
*parent
, wxWindowID id
,
111 const wxString
& title
,
115 const wxString
& name
)
118 m_windowStyle
= style
;
121 parent
->AddChild(this);
123 wxTopLevelWindows
.Append(this);
125 m_windowId
= ( id
> -1 ) ? id
: NewControlId();
127 bool retval
= DoCreate( parent
, id
, title
, pos
, size
, style
, name
);
129 if( !retval
) return FALSE
;
131 // Intercept CLOSE messages from the window manager
132 Widget shell
= (Widget
)GetShellWidget();
133 Atom WM_DELETE_WINDOW
= XmInternAtom( XtDisplay( shell
),
134 "WM_DELETE_WINDOW", False
);
136 // Remove and add WM_DELETE_WINDOW so ours is only handler
137 // This only appears to be necessary for wxDialog, but does not hurt
139 XmRemoveWMProtocols( shell
, &WM_DELETE_WINDOW
, 1 );
140 XmAddWMProtocols( shell
, &WM_DELETE_WINDOW
, 1 );
141 XmActivateWMProtocol( shell
, WM_DELETE_WINDOW
);
143 // Modified Steve Hammes for Motif 2.0
144 #if (XmREVISION > 1 || XmVERSION > 1)
145 XmAddWMProtocolCallback( shell
, WM_DELETE_WINDOW
,
146 (XtCallbackProc
)wxCloseTLWCallback
,
148 #elif XmREVISION == 1
149 XmAddWMProtocolCallback( shell
, WM_DELETE_WINDOW
,
150 (XtCallbackProc
)wxCloseTLWCallback
,
153 XmAddWMProtocolCallback( shell
, WM_DELETE_WINDOW
,
154 (void (*)())wxCloseTLWCallback
, (caddr_t
)this );
157 // This patch come from Torsten Liermann lier@lier1.muc.de
158 if( XmIsMotifWMRunning( shell
) )
161 if( m_windowStyle
& wxRESIZE_BORDER
)
162 decor
|= MWM_DECOR_RESIZEH
;
163 if( m_windowStyle
& wxSYSTEM_MENU
)
164 decor
|= MWM_DECOR_MENU
;
165 if( ( m_windowStyle
& wxCAPTION
) ||
166 ( m_windowStyle
& wxTINY_CAPTION_HORIZ
) ||
167 ( m_windowStyle
& wxTINY_CAPTION_VERT
) )
168 decor
|= MWM_DECOR_TITLE
;
169 if( m_windowStyle
& wxTHICK_FRAME
)
170 decor
|= MWM_DECOR_BORDER
;
171 if( m_windowStyle
& wxMINIMIZE_BOX
)
172 decor
|= MWM_DECOR_MINIMIZE
;
173 if( m_windowStyle
& wxMAXIMIZE_BOX
)
174 decor
|= MWM_DECOR_MAXIMIZE
;
176 XtVaSetValues( shell
,
177 XmNmwmDecorations
, decor
,
182 // This allows non-Motif window managers to support at least the
183 // no-decorations case.
184 if( ( m_windowStyle
& wxCAPTION
) != wxCAPTION
)
185 XtVaSetValues( shell
,
186 XmNoverrideRedirect
, TRUE
,
190 XtAddEventHandler( (Widget
)GetClientWidget(),
191 ButtonPressMask
| ButtonReleaseMask
|
192 PointerMotionMask
| KeyPressMask
,
200 void wxTopLevelWindowMotif::Raise()
202 Widget top
= (Widget
) GetTopWidget();
203 Window parent_window
= XtWindow( top
),
204 next_parent
= XtWindow( top
),
205 root
= RootWindowOfScreen( XtScreen( top
) );
206 // search for the parent that is child of ROOT, because the WM may
207 // reparent twice and notify only the next parent (like FVWM)
208 while( next_parent
!= root
)
213 parent_window
= next_parent
;
214 XQueryTree( XtDisplay( top
), parent_window
, &root
,
215 &next_parent
, &theChildren
, &n
);
216 XFree( theChildren
); // not needed
218 XRaiseWindow( XtDisplay( top
), parent_window
);
221 void wxTopLevelWindowMotif::Lower()
223 Widget top
= (Widget
) GetTopWidget();
224 Window parent_window
= XtWindow( top
),
225 next_parent
= XtWindow( top
),
226 root
= RootWindowOfScreen( XtScreen( top
) );
227 // search for the parent that is child of ROOT, because the WM may
228 // reparent twice and notify only the next parent (like FVWM)
229 while( next_parent
!= root
)
234 parent_window
= next_parent
;
235 XQueryTree( XtDisplay( top
), parent_window
, &root
,
236 &next_parent
, &theChildren
, &n
);
237 XFree( theChildren
); // not needed
239 XLowerWindow( XtDisplay( top
), parent_window
);
242 static inline Widget
GetShell( const wxTopLevelWindowMotif
* tlw
)
244 Widget main
= (Widget
) tlw
->GetMainWidget();
245 if( !main
) return (Widget
) NULL
;
247 return XtParent( main
);
250 WXWidget
wxTopLevelWindowMotif::GetShellWidget() const
252 return (WXWidget
) GetShell( this );
255 bool wxTopLevelWindowMotif::ShowFullScreen( bool show
,
262 bool wxTopLevelWindowMotif::IsFullScreen() const
268 void wxTopLevelWindowMotif::Restore()
270 Widget shell
= GetShell( this );
273 XtVaSetValues( shell
,
278 void wxTopLevelWindowMotif::Iconize( bool iconize
)
280 Widget shell
= GetShell( this );
286 XtVaSetValues( shell
,
287 XmNiconic
, (Boolean
)iconize
,
291 bool wxTopLevelWindowMotif::IsIconized() const
293 Widget shell
= GetShell( this );
299 XtVaGetValues( shell
,
306 void wxTopLevelWindowMotif::Maximize( bool maximize
)
314 bool wxTopLevelWindowMotif::IsMaximized() const
319 // ---------------------------------------------------------------------------
320 // Callback definition
321 // ---------------------------------------------------------------------------
323 // Handle a close event from the window manager
324 static void wxCloseTLWCallback( Widget
WXUNUSED(widget
), XtPointer client_data
,
325 XmAnyCallbackStruct
*WXUNUSED(cbs
) )
327 wxTopLevelWindowMotif
* tlw
= (wxTopLevelWindowMotif
*)client_data
;
328 wxCloseEvent
closeEvent( wxEVT_CLOSE_WINDOW
, tlw
->GetId() );
329 closeEvent
.SetEventObject( tlw
);
331 // May delete the dialog (with delayed deletion)
332 tlw
->GetEventHandler()->ProcessEvent(closeEvent
);
335 void wxTLWEventHandler( Widget wid
,
336 XtPointer
WXUNUSED(client_data
),
338 Boolean
* continueToDispatch
)
340 wxTopLevelWindowMotif
* tlw
=
341 (wxTopLevelWindowMotif
*)wxGetWindowFromTable( wid
);
345 wxMouseEvent
wxevent( wxEVT_NULL
);
347 if( wxTranslateMouseEvent( wxevent
, tlw
, wid
, event
) )
349 wxevent
.SetEventObject( tlw
);
350 wxevent
.SetId( tlw
->GetId() );
351 tlw
->GetEventHandler()->ProcessEvent( wxevent
);
355 // An attempt to implement OnCharHook by calling OnCharHook first;
356 // if this returns TRUE, set continueToDispatch to False
357 // (don't continue processing).
358 // Otherwise set it to True and call OnChar.
359 wxKeyEvent
keyEvent( wxEVT_CHAR
);
360 if( wxTranslateKeyEvent( keyEvent
, tlw
, wid
, event
))
362 keyEvent
.SetEventObject( tlw
);
363 keyEvent
.SetId( tlw
->GetId() );
364 keyEvent
.SetEventType( wxEVT_CHAR_HOOK
);
365 if( tlw
->GetEventHandler()->ProcessEvent( keyEvent
) )
367 *continueToDispatch
= False
;
372 // For simplicity, OnKeyDown is the same as OnChar
373 // TODO: filter modifier key presses from OnChar
374 keyEvent
.SetEventType( wxEVT_KEY_DOWN
);
376 // Only process OnChar if OnKeyDown didn't swallow it
377 if( !tlw
->GetEventHandler()->ProcessEvent( keyEvent
) )
379 keyEvent
.SetEventType( wxEVT_CHAR
);
380 tlw
->GetEventHandler()->ProcessEvent( keyEvent
);
387 *continueToDispatch
= True
;