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/private/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
= gtk_widget_get_parent(child
);
53 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
54 event
.SetEventObject( win
);
56 (void)win
->HandleWindowEvent( event
);
62 //-----------------------------------------------------------------------------
64 //-----------------------------------------------------------------------------
67 bool gtk_dialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxPopupWindow
*win
)
76 //-----------------------------------------------------------------------------
78 //-----------------------------------------------------------------------------
80 #ifdef __WXUNIVERSAL__
81 BEGIN_EVENT_TABLE(wxPopupWindow
,wxPopupWindowBase
)
82 EVT_SIZE(wxPopupWindow::OnSize
)
86 wxPopupWindow::~wxPopupWindow()
90 bool wxPopupWindow::Create( wxWindow
*parent
, int style
)
92 if (!PreCreation( parent
, wxDefaultPosition
, wxDefaultSize
) ||
93 !CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("popup") ))
95 wxFAIL_MSG( wxT("wxPopupWindow creation failed") );
99 // Unlike windows, top level windows are created hidden by default.
102 // All dialogs should really have this style
103 m_windowStyle
|= wxTAB_TRAVERSAL
;
105 m_widget
= gtk_window_new( GTK_WINDOW_POPUP
);
106 g_object_ref( m_widget
);
108 gtk_widget_set_name( m_widget
, "wxPopupWindow" );
109 // wxPopupWindow is used for different windows as well
110 // gtk_window_set_type_hint( GTK_WINDOW(m_widget), GDK_WINDOW_TYPE_HINT_COMBO );
112 GtkWidget
*toplevel
= gtk_widget_get_toplevel( parent
->m_widget
);
113 if (GTK_IS_WINDOW (toplevel
))
115 #if GTK_CHECK_VERSION(2,10,0)
117 if (!gtk_check_version(2,10,0))
120 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel
)), GTK_WINDOW (m_widget
));
123 gtk_window_set_transient_for (GTK_WINDOW (m_widget
), GTK_WINDOW (toplevel
));
125 gtk_window_set_resizable (GTK_WINDOW (m_widget
), FALSE
);
126 gtk_window_set_screen (GTK_WINDOW (m_widget
), gtk_widget_get_screen (GTK_WIDGET (parent
->m_widget
)));
128 g_signal_connect (m_widget
, "delete_event",
129 G_CALLBACK (gtk_dialog_delete_callback
), this);
131 m_wxwindow
= wxPizza::New();
132 gtk_widget_show( m_wxwindow
);
134 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
136 if (m_parent
) m_parent
->AddChild( this );
140 m_time
= gtk_get_current_event_time();
142 g_signal_connect (m_widget
, "button_press_event",
143 G_CALLBACK (gtk_popup_button_press
), this);
148 void wxPopupWindow::DoMoveWindow(int WXUNUSED(x
), int WXUNUSED(y
), int WXUNUSED(width
), int WXUNUSED(height
) )
150 wxFAIL_MSG( wxT("DoMoveWindow called for wxPopupWindow") );
153 void wxPopupWindow::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
155 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid dialog") );
156 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid dialog") );
161 int old_width
= m_width
;
162 int old_height
= m_height
;
164 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
166 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
175 if ((m_x
!= -1) || (m_y
!= -1))
177 if ((m_x
!= old_x
) || (m_y
!= old_y
))
179 gtk_window_move( GTK_WINDOW(m_widget
), m_x
, m_y
);
183 if ((m_width
!= old_width
) || (m_height
!= old_height
))
185 // gtk_window_resize does not work for GTK_WINDOW_POPUP
186 gtk_widget_set_size_request( m_widget
, m_width
, m_height
);
187 wxSizeEvent
event(GetSize(), GetId());
188 event
.SetEventObject(this);
189 HandleWindowEvent(event
);
193 void wxPopupWindow::SetFocus()
195 // set the focus to the first child who wants it
196 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
199 wxWindow
*child
= node
->GetData();
200 node
= node
->GetNext();
202 if ( child
->CanAcceptFocus() && !child
->IsTopLevel() )
209 wxPopupWindowBase::SetFocus();
212 bool wxPopupWindow::Show( bool show
)
214 if (show
&& !IsShown())
216 wxSizeEvent
event(GetSize(), GetId());
217 event
.SetEventObject(this);
218 HandleWindowEvent(event
);
221 bool ret
= wxWindow::Show( show
);
226 #endif // wxUSE_POPUPWIN