]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/popupwin.cpp
Option for variable line heights (MSW and GTK+ sofar)
[wxWidgets.git] / src / gtk / popupwin.cpp
CommitLineData
9f41d601 1/////////////////////////////////////////////////////////////////////////////
670f9935 2// Name: src/gtk/popupwin.cpp
9f41d601
RR
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
9f41d601
RR
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
f3ecfad1
VS
12
13#if wxUSE_POPUPWIN
14
9f41d601 15#include "wx/popupwin.h"
670f9935
WS
16
17#ifndef WX_PRECOMP
670f9935
WS
18#endif // WX_PRECOMP
19
9f41d601 20#include <gtk/gtk.h>
9f41d601 21
bbd92d1d 22#include "wx/gtk/private/win_gtk.h"
9f41d601 23
f7204798
RR
24//-----------------------------------------------------------------------------
25// "button_press"
26//-----------------------------------------------------------------------------
27
865bb325 28extern "C" {
f7204798
RR
29static gint gtk_popup_button_press (GtkWidget *widget, GdkEvent *gdk_event, wxPopupWindow* win )
30{
31 GtkWidget *child = gtk_get_event_widget (gdk_event);
32
33c0d0ed
RR
33 /* Ignore events sent out before we connected to the signal */
34 if (win->m_time >= ((GdkEventButton*)gdk_event)->time)
35 return FALSE;
36
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
42 * is not. */
f7204798
RR
43 if (child != widget)
44 {
45 while (child)
88d19775
MR
46 {
47 if (child == widget)
48 return FALSE;
f7204798
RR
49 child = child->parent;
50 }
51 }
52
53 wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() );
54 event.SetEventObject( win );
55
937013e0 56 (void)win->HandleWindowEvent( event );
f7204798
RR
57
58 return TRUE;
59}
865bb325 60}
f7204798 61
9f41d601
RR
62//-----------------------------------------------------------------------------
63// "delete_event"
64//-----------------------------------------------------------------------------
65
865bb325 66extern "C" {
9f41d601
RR
67bool gtk_dialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxPopupWindow *win )
68{
9f41d601
RR
69 if (win->IsEnabled())
70 win->Close();
71
72 return TRUE;
73}
865bb325 74}
9f41d601 75
9f41d601
RR
76//-----------------------------------------------------------------------------
77// "realize" from m_widget
78//-----------------------------------------------------------------------------
79
80/* we cannot MWM hints and icons before the widget has been realized,
81 so we do this directly after realization */
82
865bb325 83extern "C" {
9f41d601
RR
84static gint
85gtk_dialog_realized_callback( GtkWidget * WXUNUSED(widget), wxPopupWindow *win )
86{
9f41d601
RR
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 ;
91
92 gdk_window_set_decorations( win->m_widget->window, (GdkWMDecoration)decor);
93 gdk_window_set_functions( win->m_widget->window, (GdkWMFunction)func);
94
43a52404 95 gtk_window_set_resizable(GTK_WINDOW(win->m_widget), FALSE);
9f41d601
RR
96
97 return FALSE;
98}
865bb325 99}
9f41d601
RR
100
101//-----------------------------------------------------------------------------
102// InsertChild for wxPopupWindow
103//-----------------------------------------------------------------------------
104
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
77ffb593 107 * virtual function here as wxWidgets requires different ways to insert
9f41d601
RR
108 * a child in container classes. */
109
7a3ba5af 110static void wxInsertChildInPopupWin(wxWindowGTK* parent, wxWindowGTK* child)
9f41d601 111{
08f53168
PC
112 gtk_widget_set_size_request(
113 child->m_widget, child->m_width, child->m_height);
114 gtk_fixed_put(
115 GTK_FIXED(parent->m_wxwindow), child->m_widget, child->m_x, child->m_y);
9f41d601
RR
116
117 if (parent->HasFlag(wxTAB_TRAVERSAL))
118 {
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 );
122 }
123}
124
125//-----------------------------------------------------------------------------
126// wxPopupWindow
127//-----------------------------------------------------------------------------
128
8f0db49c 129#ifdef __WXUNIVERSAL__
cca410b3 130BEGIN_EVENT_TABLE(wxPopupWindow,wxPopupWindowBase)
6522713c 131 EVT_SIZE(wxPopupWindow::OnSize)
9f41d601 132END_EVENT_TABLE()
cca410b3 133#endif
9f41d601 134
ad9fb033
RR
135wxPopupWindow::~wxPopupWindow()
136{
ad9fb033
RR
137}
138
9f41d601
RR
139bool wxPopupWindow::Create( wxWindow *parent, int style )
140{
9f41d601 141 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
2b5f62a0 142 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("popup") ))
9f41d601
RR
143 {
144 wxFAIL_MSG( wxT("wxPopupWindow creation failed") );
670f9935 145 return false;
9f41d601
RR
146 }
147
da19de36
RR
148 // Unlike windows, top level windows are created hidden by default.
149 m_isShown = false;
88d19775 150
9f41d601
RR
151 // All dialogs should really have this style
152 m_windowStyle |= wxTAB_TRAVERSAL;
153
c821db16 154 m_insertCallback = wxInsertChildInPopupWin;
9f41d601
RR
155
156 m_widget = gtk_window_new( GTK_WINDOW_POPUP );
157
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) );
160
161 GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
162
9fa72bd2
MR
163 g_signal_connect (m_widget, "delete_event",
164 G_CALLBACK (gtk_dialog_delete_callback), this);
9f41d601 165
08f53168 166 m_wxwindow = wxPizza::New(m_windowStyle);
9f41d601
RR
167 gtk_widget_show( m_wxwindow );
168 GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
169
170 gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
171
172 if (m_parent) m_parent->AddChild( this );
173
174 PostCreation();
175
176 /* we cannot set MWM hints before the widget has
177 been realized, so we do this directly after realization */
9fa72bd2
MR
178 g_signal_connect (m_widget, "realize",
179 G_CALLBACK (gtk_dialog_realized_callback), this);
9f41d601 180
33c0d0ed
RR
181 m_time = gtk_get_current_event_time();
182
9fa72bd2
MR
183 g_signal_connect (m_widget, "button_press_event",
184 G_CALLBACK (gtk_popup_button_press), this);
88d19775 185
670f9935 186 return true;
9f41d601
RR
187}
188
189void wxPopupWindow::DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(width), int WXUNUSED(height) )
190{
191 wxFAIL_MSG( wxT("DoMoveWindow called for wxPopupWindow") );
192}
193
194void wxPopupWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags )
195{
196 wxASSERT_MSG( (m_widget != NULL), wxT("invalid dialog") );
197 wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid dialog") );
198
9f41d601
RR
199 int old_x = m_x;
200 int old_y = m_y;
201
202 int old_width = m_width;
203 int old_height = m_height;
204
cca410b3 205 if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
9f41d601 206 m_x = x;
cca410b3 207 if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
9f41d601 208 m_y = y;
cca410b3 209 if (width != -1)
9f41d601 210 m_width = width;
cca410b3 211 if (height != -1)
9f41d601 212 m_height = height;
9f41d601 213
82008f15 214 ConstrainSize();
9f41d601
RR
215
216 if ((m_x != -1) || (m_y != -1))
217 {
218 if ((m_x != old_x) || (m_y != old_y))
219 {
cd6645a2 220 gtk_window_move( GTK_WINDOW(m_widget), m_x, m_y );
9f41d601
RR
221 }
222 }
223
224 if ((m_width != old_width) || (m_height != old_height))
225 {
cca410b3 226 // gtk_window_resize does not work for GTK_WINDOW_POPUP
370dc79c 227 gtk_widget_set_size_request( m_widget, m_width, m_height );
cca410b3
PC
228 wxSizeEvent event(GetSize(), GetId());
229 event.SetEventObject(this);
937013e0 230 HandleWindowEvent(event);
9f41d601 231 }
9f41d601
RR
232}
233
234bool wxPopupWindow::Show( bool show )
235{
cca410b3 236 if (show && !IsShown())
9f41d601 237 {
cca410b3
PC
238 wxSizeEvent event(GetSize(), GetId());
239 event.SetEventObject(this);
937013e0 240 HandleWindowEvent(event);
9f41d601 241 }
88d19775 242
9f41d601 243 bool ret = wxWindow::Show( show );
88d19775 244
9f41d601
RR
245 return ret;
246}
247
f3ecfad1 248#endif // wxUSE_POPUPWIN