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