1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/popupwin.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
15 #include "wx/popupwin.h"
22 #include "wx/gtk/win_gtk.h"
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
29 static gint
gtk_popup_button_press (GtkWidget
*widget
, GdkEvent
*gdk_event
, wxPopupWindow
* win
)
31 GtkWidget
*child
= gtk_get_event_widget (gdk_event
);
33 /* Ignore events sent out before we connected to the signal */
34 if (win
->m_time
>= ((GdkEventButton
*)gdk_event
)->time
)
37 /* We don't ask for button press events on the grab widget, so
38 * if an event is reported directly to the grab widget, it must
39 * be on a window outside the application (and thus we remove
40 * the popup window). Otherwise, we check if the widget is a child
41 * of the grab widget, and only remove the popup window if it
49 child
= child
->parent
;
53 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
54 event
.SetEventObject( win
);
56 (void)win
->GetEventHandler()->ProcessEvent( event
);
62 //-----------------------------------------------------------------------------
64 //-----------------------------------------------------------------------------
67 bool gtk_dialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxPopupWindow
*win
)
76 //-----------------------------------------------------------------------------
77 // "realize" from m_widget
78 //-----------------------------------------------------------------------------
80 /* we cannot MWM hints and icons before the widget has been realized,
81 so we do this directly after realization */
85 gtk_dialog_realized_callback( GtkWidget
* WXUNUSED(widget
), wxPopupWindow
*win
)
87 /* all this is for Motif Window Manager "hints" and is supposed to be
88 recognized by other WM as well. not tested. */
89 long decor
= (long) GDK_DECOR_BORDER
;
90 long func
= (long) GDK_FUNC_MOVE
;
92 gdk_window_set_decorations( win
->m_widget
->window
, (GdkWMDecoration
)decor
);
93 gdk_window_set_functions( win
->m_widget
->window
, (GdkWMFunction
)func
);
95 gtk_window_set_resizable(GTK_WINDOW(win
->m_widget
), FALSE
);
101 //-----------------------------------------------------------------------------
102 // InsertChild for wxPopupWindow
103 //-----------------------------------------------------------------------------
105 /* Callback for wxFrame. This very strange beast has to be used because
106 * C++ has no virtual methods in a constructor. We have to emulate a
107 * virtual function here as wxWidgets requires different ways to insert
108 * a child in container classes. */
110 static void wxInsertChildInPopupWin(wxWindowGTK
* parent
, wxWindowGTK
* child
)
112 gtk_widget_set_size_request(
113 child
->m_widget
, child
->m_width
, child
->m_height
);
115 GTK_FIXED(parent
->m_wxwindow
), child
->m_widget
, child
->m_x
, child
->m_y
);
117 if (parent
->HasFlag(wxTAB_TRAVERSAL
))
119 /* we now allow a window to get the focus as long as it
120 doesn't have any children. */
121 GTK_WIDGET_UNSET_FLAGS( parent
->m_wxwindow
, GTK_CAN_FOCUS
);
125 //-----------------------------------------------------------------------------
127 //-----------------------------------------------------------------------------
129 #ifdef __WXUNIVERSAL__
130 BEGIN_EVENT_TABLE(wxPopupWindow
,wxPopupWindowBase
)
131 EVT_SIZE(wxPopupWindow::OnSize
)
135 wxPopupWindow::~wxPopupWindow()
139 bool wxPopupWindow::Create( wxWindow
*parent
, int style
)
141 if (!PreCreation( parent
, wxDefaultPosition
, wxDefaultSize
) ||
142 !CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("popup") ))
144 wxFAIL_MSG( wxT("wxPopupWindow creation failed") );
148 // Unlike windows, top level windows are created hidden by default.
151 // All dialogs should really have this style
152 m_windowStyle
|= wxTAB_TRAVERSAL
;
154 m_insertCallback
= wxInsertChildInPopupWin
;
156 m_widget
= gtk_window_new( GTK_WINDOW_POPUP
);
158 if ((m_parent
) && (GTK_IS_WINDOW(m_parent
->m_widget
)))
159 gtk_window_set_transient_for( GTK_WINDOW(m_widget
), GTK_WINDOW(m_parent
->m_widget
) );
161 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
163 g_signal_connect (m_widget
, "delete_event",
164 G_CALLBACK (gtk_dialog_delete_callback
), this);
166 m_wxwindow
= wxPizza::New(m_windowStyle
);
167 gtk_widget_show( m_wxwindow
);
168 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
170 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
172 if (m_parent
) m_parent
->AddChild( this );
176 /* we cannot set MWM hints before the widget has
177 been realized, so we do this directly after realization */
178 g_signal_connect (m_widget
, "realize",
179 G_CALLBACK (gtk_dialog_realized_callback
), this);
181 m_time
= gtk_get_current_event_time();
183 g_signal_connect (m_widget
, "button_press_event",
184 G_CALLBACK (gtk_popup_button_press
), this);
189 void wxPopupWindow::DoMoveWindow(int WXUNUSED(x
), int WXUNUSED(y
), int WXUNUSED(width
), int WXUNUSED(height
) )
191 wxFAIL_MSG( wxT("DoMoveWindow called for wxPopupWindow") );
194 void wxPopupWindow::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
196 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid dialog") );
197 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid dialog") );
202 int old_width
= m_width
;
203 int old_height
= m_height
;
205 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
207 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
216 if ((m_x
!= -1) || (m_y
!= -1))
218 if ((m_x
!= old_x
) || (m_y
!= old_y
))
220 gtk_window_move( GTK_WINDOW(m_widget
), m_x
, m_y
);
224 if ((m_width
!= old_width
) || (m_height
!= old_height
))
226 // gtk_window_resize does not work for GTK_WINDOW_POPUP
227 gtk_widget_set_size_request( m_widget
, m_width
, m_height
);
228 wxSizeEvent
event(GetSize(), GetId());
229 event
.SetEventObject(this);
230 GetEventHandler()->ProcessEvent(event
);
234 bool wxPopupWindow::Show( bool show
)
236 if (show
&& !IsShown())
238 wxSizeEvent
event(GetSize(), GetId());
239 event
.SetEventObject(this);
240 GetEventHandler()->ProcessEvent(event
);
243 bool ret
= wxWindow::Show( show
);
248 #endif // wxUSE_POPUPWIN