1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/popupwin.cpp
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
14 #include "wx/popupwin.h"
21 #include "wx/gtk/private/win_gtk.h"
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
28 static gint
gtk_popup_button_press (GtkWidget
*widget
, GdkEvent
*gdk_event
, wxPopupWindow
* win
)
30 GtkWidget
*child
= gtk_get_event_widget (gdk_event
);
32 /* Ignore events sent out before we connected to the signal */
33 if (win
->m_time
>= ((GdkEventButton
*)gdk_event
)->time
)
36 /* We don't ask for button press events on the grab widget, so
37 * if an event is reported directly to the grab widget, it must
38 * be on a window outside the application (and thus we remove
39 * the popup window). Otherwise, we check if the widget is a child
40 * of the grab widget, and only remove the popup window if it
48 child
= gtk_widget_get_parent(child
);
52 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
53 event
.SetEventObject( win
);
55 (void)win
->HandleWindowEvent( event
);
61 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
66 bool gtk_dialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxPopupWindow
*win
)
75 //-----------------------------------------------------------------------------
77 //-----------------------------------------------------------------------------
79 #ifdef __WXUNIVERSAL__
80 BEGIN_EVENT_TABLE(wxPopupWindow
,wxPopupWindowBase
)
81 EVT_SIZE(wxPopupWindow::OnSize
)
85 wxPopupWindow::~wxPopupWindow()
89 bool wxPopupWindow::Create( wxWindow
*parent
, int style
)
91 if (!PreCreation( parent
, wxDefaultPosition
, wxDefaultSize
) ||
92 !CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("popup") ))
94 wxFAIL_MSG( wxT("wxPopupWindow creation failed") );
98 // Unlike windows, top level windows are created hidden by default.
101 // All dialogs should really have this style
102 m_windowStyle
|= wxTAB_TRAVERSAL
;
104 m_widget
= gtk_window_new( GTK_WINDOW_POPUP
);
105 g_object_ref( m_widget
);
107 gtk_widget_set_name( m_widget
, "wxPopupWindow" );
108 // wxPopupWindow is used for different windows as well
109 // gtk_window_set_type_hint( GTK_WINDOW(m_widget), GDK_WINDOW_TYPE_HINT_COMBO );
111 // Popup windows can be created without parent, so handle this correctly.
114 GtkWidget
*toplevel
= gtk_widget_get_toplevel( parent
->m_widget
);
115 if (GTK_IS_WINDOW (toplevel
))
117 #if GTK_CHECK_VERSION(2,10,0)
119 if (!gtk_check_version(2,10,0))
122 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel
)), GTK_WINDOW (m_widget
));
125 gtk_window_set_transient_for (GTK_WINDOW (m_widget
), GTK_WINDOW (toplevel
));
127 gtk_window_set_screen (GTK_WINDOW (m_widget
), gtk_widget_get_screen (GTK_WIDGET (parent
->m_widget
)));
130 gtk_window_set_resizable (GTK_WINDOW (m_widget
), FALSE
);
132 g_signal_connect (m_widget
, "delete_event",
133 G_CALLBACK (gtk_dialog_delete_callback
), this);
135 m_wxwindow
= wxPizza::New();
136 gtk_widget_show( m_wxwindow
);
138 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
140 if (m_parent
) m_parent
->AddChild( this );
144 m_time
= gtk_get_current_event_time();
146 g_signal_connect (m_widget
, "button_press_event",
147 G_CALLBACK (gtk_popup_button_press
), this);
152 void wxPopupWindow::DoMoveWindow(int WXUNUSED(x
), int WXUNUSED(y
), int WXUNUSED(width
), int WXUNUSED(height
) )
154 wxFAIL_MSG( wxT("DoMoveWindow called for wxPopupWindow") );
157 void wxPopupWindow::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
159 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid dialog") );
160 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid dialog") );
165 int old_width
= m_width
;
166 int old_height
= m_height
;
168 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
170 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
179 if ((m_x
!= -1) || (m_y
!= -1))
181 if ((m_x
!= old_x
) || (m_y
!= old_y
))
183 gtk_window_move( GTK_WINDOW(m_widget
), m_x
, m_y
);
187 if ((m_width
!= old_width
) || (m_height
!= old_height
))
189 // gtk_window_resize does not work for GTK_WINDOW_POPUP
190 gtk_widget_set_size_request( m_widget
, m_width
, m_height
);
191 wxSizeEvent
event(GetSize(), GetId());
192 event
.SetEventObject(this);
193 HandleWindowEvent(event
);
197 void wxPopupWindow::SetFocus()
199 // set the focus to the first child who wants it
200 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
203 wxWindow
*child
= node
->GetData();
204 node
= node
->GetNext();
206 if ( child
->CanAcceptFocus() && !child
->IsTopLevel() )
213 wxPopupWindowBase::SetFocus();
216 bool wxPopupWindow::Show( bool show
)
218 if (show
&& !IsShown())
220 wxSizeEvent
event(GetSize(), GetId());
221 event
.SetEventObject(this);
222 HandleWindowEvent(event
);
225 bool ret
= wxWindow::Show( show
);
230 #endif // wxUSE_POPUPWIN