]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/minifram.cpp
wxMenu ctor made compatible again
[wxWidgets.git] / src / gtk1 / minifram.cpp
CommitLineData
b2b3ccc5
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: minifram.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "minifram.h"
12#endif
13
14#include "wx/minifram.h"
dcf924a3
RR
15
16#if wxUSE_MINIFRAME
17
b2b3ccc5
RR
18#include "wx/dcscreen.h"
19
83624f79
RR
20#include "gtk/gtk.h"
21#include "wx/gtk/win_gtk.h"
22
32a95f9f
RR
23#include "gdk/gdk.h"
24#include "gdk/gdkprivate.h"
25#include "gdk/gdkx.h"
26
acfd422a
RR
27//-----------------------------------------------------------------------------
28// idle system
29//-----------------------------------------------------------------------------
30
31extern void wxapp_install_idle_handler();
32extern bool g_isIdle;
33
32a95f9f
RR
34//-----------------------------------------------------------------------------
35// data
36//-----------------------------------------------------------------------------
37
38extern bool g_blockEventsOnDrag;
39extern bool g_blockEventsOnScroll;
40
b2b3ccc5 41//-----------------------------------------------------------------------------
32a95f9f
RR
42// local functions
43//-----------------------------------------------------------------------------
44
45/* draw XOR rectangle when moving mine frame around */
46
47static void DrawFrame( GtkWidget *widget, int x, int y, int w, int h )
48{
49 int org_x = 0;
50 int org_y = 0;
51 gdk_window_get_origin( widget->window, &org_x, &org_y );
52 x += org_x;
53 y += org_y;
54
55 GdkGC *gc = gdk_gc_new( GDK_ROOT_PARENT() );
56 gdk_gc_set_subwindow( gc, GDK_INCLUDE_INFERIORS );
57 gdk_gc_set_function( gc, GDK_INVERT );
58
59 gdk_draw_rectangle( GDK_ROOT_PARENT(), gc, FALSE, x, y, w, h );
60 gdk_gc_unref( gc );
61}
62
63//-----------------------------------------------------------------------------
64// "expose_event" of m_mainWidget
65//-----------------------------------------------------------------------------
66
67static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *gdk_event, wxFrame *win )
68{
acfd422a
RR
69 if (g_isIdle) wxapp_install_idle_handler();
70
a2053b27 71 if (!win->m_hasVMT) return;
32a95f9f
RR
72 if (gdk_event->count > 0) return;
73
74 gtk_draw_shadow( widget->style,
75 widget->window,
f03fc89f
VZ
76 GTK_STATE_NORMAL,
77 GTK_SHADOW_OUT,
78 0, 0,
a2053b27 79 win->m_width, win->m_height );
b9a535f5
RR
80
81 if (!win->m_title.IsEmpty() &&
f03fc89f
VZ
82 ((win->GetWindowStyle() & wxCAPTION) ||
83 (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) ||
84 (win->GetWindowStyle() & wxTINY_CAPTION_VERT)))
b9a535f5
RR
85 {
86 GdkGC *gc = gdk_gc_new( widget->window );
f03fc89f
VZ
87 GdkFont *font = wxSMALL_FONT->GetInternalFont(1.0);
88 int x = 2;
89 if (win->GetWindowStyle() & wxSYSTEM_MENU) x = 18;
90
b9a535f5 91 gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] );
f03fc89f
VZ
92 gdk_draw_rectangle( widget->window, gc, TRUE,
93 x,
94 3,
a2053b27 95 win->m_width - 4 - x,
f03fc89f
VZ
96 font->ascent + font->descent+1 );
97
b9a535f5
RR
98 gdk_gc_set_foreground( gc, &widget->style->white );
99 gdk_draw_string( widget->window, font, gc,
f03fc89f
VZ
100 x+2,
101 3+font->ascent,
102 win->m_title.mb_str() );
103
b9a535f5
RR
104 gdk_gc_unref( gc );
105 }
32a95f9f
RR
106}
107
108//-----------------------------------------------------------------------------
109// "draw" of m_mainWidget
110//-----------------------------------------------------------------------------
111
112static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNUSED(rect), wxFrame *win )
113{
acfd422a
RR
114 if (g_isIdle) wxapp_install_idle_handler();
115
a2053b27 116 if (!win->m_hasVMT) return;
32a95f9f
RR
117
118 gtk_draw_shadow( widget->style,
119 widget->window,
f03fc89f
VZ
120 GTK_STATE_NORMAL,
121 GTK_SHADOW_OUT,
122 0, 0,
a2053b27 123 win->m_width, win->m_height );
f03fc89f 124
b9a535f5 125 if (!win->m_title.IsEmpty() &&
f03fc89f
VZ
126 ((win->GetWindowStyle() & wxCAPTION) ||
127 (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) ||
128 (win->GetWindowStyle() & wxTINY_CAPTION_VERT)))
b9a535f5
RR
129 {
130 GdkGC *gc = gdk_gc_new( widget->window );
f03fc89f
VZ
131 GdkFont *font = wxSMALL_FONT->GetInternalFont(1.0);
132 int x = 2;
133 if (win->GetWindowStyle() & wxSYSTEM_MENU) x = 17;
134
b9a535f5 135 gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] );
f03fc89f
VZ
136 gdk_draw_rectangle( widget->window, gc, TRUE,
137 x,
138 3,
a2053b27 139 win->m_width - 4 - x,
f03fc89f
VZ
140 font->ascent + font->descent+1 );
141
b9a535f5
RR
142 gdk_gc_set_foreground( gc, &widget->style->white );
143 gdk_draw_string( widget->window, font, gc,
f03fc89f
VZ
144 x+2,
145 3+font->ascent,
146 win->m_title.mb_str() );
147
b9a535f5
RR
148 gdk_gc_unref( gc );
149 }
32a95f9f
RR
150}
151
152//-----------------------------------------------------------------------------
153// "button_press_event" of m_mainWidget
154//-----------------------------------------------------------------------------
155
156static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win )
157{
acfd422a
RR
158 if (g_isIdle) wxapp_install_idle_handler();
159
a2053b27 160 if (!win->m_hasVMT) return FALSE;
32a95f9f
RR
161 if (g_blockEventsOnDrag) return TRUE;
162 if (g_blockEventsOnScroll) return TRUE;
163
164 if (win->m_isDragging) return TRUE;
165
166 gdk_pointer_grab( widget->window, FALSE,
167 (GdkEventMask)
168 (GDK_BUTTON_PRESS_MASK |
169 GDK_BUTTON_RELEASE_MASK |
f03fc89f 170 GDK_POINTER_MOTION_MASK |
32a95f9f 171 GDK_POINTER_MOTION_HINT_MASK |
f03fc89f 172 GDK_BUTTON_MOTION_MASK |
32a95f9f
RR
173 GDK_BUTTON1_MOTION_MASK),
174 (GdkWindow *) NULL,
175 (GdkCursor *) NULL,
176 GDK_CURRENT_TIME );
f03fc89f 177
32a95f9f
RR
178 win->m_diffX = (int)gdk_event->x;
179 win->m_diffY = (int)gdk_event->y;
a2053b27 180 DrawFrame( widget, 0, 0, win->m_width, win->m_height );
32a95f9f
RR
181 win->m_oldX = 0;
182 win->m_oldY = 0;
183
184 win->m_isDragging = TRUE;
185
186 return TRUE;
187}
188
189//-----------------------------------------------------------------------------
190// "button_release_event" of m_mainWidget
191//-----------------------------------------------------------------------------
192
193static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win )
194{
acfd422a
RR
195 if (g_isIdle) wxapp_install_idle_handler();
196
a2053b27 197 if (!win->m_hasVMT) return FALSE;
32a95f9f
RR
198 if (g_blockEventsOnDrag) return TRUE;
199 if (g_blockEventsOnScroll) return TRUE;
200
201 if (!win->m_isDragging) return TRUE;
202
203 win->m_isDragging = FALSE;
204
205 int x = (int)gdk_event->x;
206 int y = (int)gdk_event->y;
207
a2053b27 208 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
32a95f9f
RR
209 gdk_pointer_ungrab ( GDK_CURRENT_TIME );
210 int org_x = 0;
211 int org_y = 0;
212 gdk_window_get_origin( widget->window, &org_x, &org_y );
213 x += org_x - win->m_diffX;
214 y += org_y - win->m_diffY;
121a3581
RR
215 win->m_x = x;
216 win->m_y = y;
a2053b27 217 gtk_widget_set_uposition( win->m_widget, x, y );
32a95f9f
RR
218
219 return TRUE;
220}
221
222//-----------------------------------------------------------------------------
223// "motion_notify_event" of m_mainWidget
224//-----------------------------------------------------------------------------
225
226static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxMiniFrame *win )
227{
acfd422a
RR
228 if (g_isIdle) wxapp_install_idle_handler();
229
a2053b27 230 if (!win->m_hasVMT) return FALSE;
32a95f9f
RR
231 if (g_blockEventsOnDrag) return TRUE;
232 if (g_blockEventsOnScroll) return TRUE;
233
234 if (!win->m_isDragging) return TRUE;
235
236 if (gdk_event->is_hint)
237 {
238 int x = 0;
239 int y = 0;
240 GdkModifierType state;
241 gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
242 gdk_event->x = x;
243 gdk_event->y = y;
244 gdk_event->state = state;
245 }
246
a2053b27 247 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
32a95f9f
RR
248 win->m_oldX = (int)gdk_event->x - win->m_diffX;
249 win->m_oldY = (int)gdk_event->y - win->m_diffY;
a2053b27 250 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
32a95f9f
RR
251
252 return TRUE;
253}
254
255//-----------------------------------------------------------------------------
256// "clicked" of X system button
b2b3ccc5
RR
257//-----------------------------------------------------------------------------
258
259static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxMiniFrame *mf )
260{
acfd422a
RR
261 if (g_isIdle) wxapp_install_idle_handler();
262
b2b3ccc5
RR
263 mf->Close();
264}
265
266//-----------------------------------------------------------------------------
267// wxMiniFrame
268//-----------------------------------------------------------------------------
269
b2b3ccc5
RR
270IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame,wxFrame)
271
272bool wxMiniFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
273 const wxPoint &pos, const wxSize &size,
274 long style, const wxString &name )
275{
276 style = style | wxSIMPLE_BORDER;
b9a535f5
RR
277
278 if ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT))
279 m_miniTitle = 13;
f03fc89f 280
b2b3ccc5 281 m_miniEdge = 3;
b2b3ccc5
RR
282 m_isDragging = FALSE;
283 m_oldX = -1;
284 m_oldY = -1;
285 m_diffX = 0;
286 m_diffY = 0;
287
288 wxFrame::Create( parent, id, title, pos, size, style, name );
289
b9a535f5
RR
290 if ((style & wxSYSTEM_MENU) &&
291 ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT)))
292 {
293 GtkWidget *close_button = gtk_button_new_with_label( "x" );
b2b3ccc5 294
fdd3ed7a 295 gtk_myfixed_put( GTK_MYFIXED(m_mainWidget),
f03fc89f
VZ
296 close_button,
297 4, 4, 12, 11 );
b2b3ccc5 298
b9a535f5 299 gtk_widget_show( close_button );
b2b3ccc5 300
b9a535f5
RR
301 gtk_signal_connect( GTK_OBJECT(close_button), "clicked",
302 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
303 }
b2b3ccc5 304
32a95f9f
RR
305 /* these are called when the borders are drawn */
306 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "expose_event",
307 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this );
b2b3ccc5 308
32a95f9f
RR
309 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "draw",
310 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this );
311
312 /* these are required for dragging the mini frame around */
313 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_press_event",
314 GTK_SIGNAL_FUNC(gtk_window_button_press_callback), (gpointer)this );
b2b3ccc5 315
32a95f9f
RR
316 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_release_event",
317 GTK_SIGNAL_FUNC(gtk_window_button_release_callback), (gpointer)this );
b2b3ccc5 318
32a95f9f
RR
319 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "motion_notify_event",
320 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback), (gpointer)this );
b2b3ccc5 321
32a95f9f 322 return TRUE;
b2b3ccc5 323}
dcf924a3
RR
324
325#endif