]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/minifram.cpp
use own mutex for region iterator locking, not gui one
[wxWidgets.git] / src / gtk1 / 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 #include "wx/gtk/private.h"
23
24 #include <gdk/gdk.h>
25 #include <gdk/gdkprivate.h>
26 #include <gdk/gdkx.h>
27
28 //-----------------------------------------------------------------------------
29 // idle system
30 //-----------------------------------------------------------------------------
31
32 extern void wxapp_install_idle_handler();
33 extern bool g_isIdle;
34
35 //-----------------------------------------------------------------------------
36 // data
37 //-----------------------------------------------------------------------------
38
39 extern bool g_blockEventsOnDrag;
40 extern bool g_blockEventsOnScroll;
41 extern GtkWidget *wxGetRootWindow();
42
43 //-----------------------------------------------------------------------------
44 // local functions
45 //-----------------------------------------------------------------------------
46
47 /* draw XOR rectangle when moving mine frame around */
48
49 static void DrawFrame( GtkWidget *widget, int x, int y, int w, int h )
50 {
51 int org_x = 0;
52 int org_y = 0;
53 gdk_window_get_origin( widget->window, &org_x, &org_y );
54 x += org_x;
55 y += org_y;
56
57 GdkGC *gc = gdk_gc_new( GDK_ROOT_PARENT() );
58 gdk_gc_set_subwindow( gc, GDK_INCLUDE_INFERIORS );
59 gdk_gc_set_function( gc, GDK_INVERT );
60
61 gdk_draw_rectangle( GDK_ROOT_PARENT(), gc, FALSE, x, y, w, h );
62 gdk_gc_unref( gc );
63 }
64
65 //-----------------------------------------------------------------------------
66 // "expose_event" of m_mainWidget
67 //-----------------------------------------------------------------------------
68
69 static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *gdk_event, wxFrame *win )
70 {
71 if (g_isIdle) wxapp_install_idle_handler();
72
73 if (!win->m_hasVMT) return;
74 if (gdk_event->count > 0) return;
75
76 GtkPizza *pizza = GTK_PIZZA(widget);
77
78 gtk_draw_shadow( widget->style,
79 pizza->bin_window,
80 GTK_STATE_NORMAL,
81 GTK_SHADOW_OUT,
82 0, 0,
83 win->m_width, win->m_height );
84
85 if (!win->m_title.IsEmpty() &&
86 ((win->GetWindowStyle() & wxCAPTION) ||
87 (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) ||
88 (win->GetWindowStyle() & wxTINY_CAPTION_VERT)))
89 {
90 GdkGC *gc = gdk_gc_new( pizza->bin_window );
91 GdkFont *font = wxSMALL_FONT->GetInternalFont(1.0);
92
93 gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] );
94 gdk_draw_rectangle( pizza->bin_window, gc, TRUE,
95 3,
96 3,
97 win->m_width - 7,
98 font->ascent + font->descent+1 );
99
100 gdk_gc_set_foreground( gc, &widget->style->fg[GTK_STATE_SELECTED] );
101 gdk_draw_string( pizza->bin_window, font, gc,
102 6,
103 3+font->ascent,
104 wxGTK_CONV( win->m_title ) );
105
106 gdk_gc_unref( gc );
107 }
108 }
109
110 //-----------------------------------------------------------------------------
111 // "draw" of m_mainWidget
112 //-----------------------------------------------------------------------------
113
114 static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNUSED(rect), wxFrame *win )
115 {
116 if (g_isIdle) wxapp_install_idle_handler();
117
118 if (!win->m_hasVMT) return;
119
120 GtkPizza *pizza = GTK_PIZZA(widget);
121
122 gtk_draw_shadow( widget->style,
123 pizza->bin_window,
124 GTK_STATE_NORMAL,
125 GTK_SHADOW_OUT,
126 0, 0,
127 win->m_width, win->m_height );
128
129 if (!win->m_title.IsEmpty() &&
130 ((win->GetWindowStyle() & wxCAPTION) ||
131 (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) ||
132 (win->GetWindowStyle() & wxTINY_CAPTION_VERT)))
133 {
134 GdkGC *gc = gdk_gc_new( pizza->bin_window );
135 GdkFont *font = wxSMALL_FONT->GetInternalFont(1.0);
136
137 gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] );
138 gdk_draw_rectangle( pizza->bin_window, gc, TRUE,
139 3,
140 3,
141 win->m_width - 7,
142 font->ascent + font->descent+1 );
143
144 gdk_gc_set_foreground( gc, &widget->style->fg[GTK_STATE_SELECTED] );
145 gdk_draw_string( pizza->bin_window, font, gc,
146 6,
147 3+font->ascent,
148 wxGTK_CONV( win->m_title ) );
149
150 gdk_gc_unref( gc );
151 }
152 }
153
154 //-----------------------------------------------------------------------------
155 // "button_press_event" of m_mainWidget
156 //-----------------------------------------------------------------------------
157
158 static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win )
159 {
160 if (g_isIdle) wxapp_install_idle_handler();
161
162 if (!win->m_hasVMT) return FALSE;
163 if (g_blockEventsOnDrag) return TRUE;
164 if (g_blockEventsOnScroll) return TRUE;
165
166 if (win->m_isDragging) return TRUE;
167
168 GtkPizza *pizza = GTK_PIZZA(widget);
169 if (gdk_event->window != pizza->bin_window) return TRUE;
170
171 GdkFont *font = wxSMALL_FONT->GetInternalFont(1.0);
172 int height = font->ascent + font->descent+1;
173 if (gdk_event->y > height) return TRUE;
174
175 gdk_window_raise( win->m_widget->window );
176
177 gdk_pointer_grab( widget->window, FALSE,
178 (GdkEventMask)
179 (GDK_BUTTON_PRESS_MASK |
180 GDK_BUTTON_RELEASE_MASK |
181 GDK_POINTER_MOTION_MASK |
182 GDK_POINTER_MOTION_HINT_MASK |
183 GDK_BUTTON_MOTION_MASK |
184 GDK_BUTTON1_MOTION_MASK),
185 (GdkWindow *) NULL,
186 (GdkCursor *) NULL,
187 (unsigned int) GDK_CURRENT_TIME );
188
189 win->m_diffX = (int)gdk_event->x;
190 win->m_diffY = (int)gdk_event->y;
191 DrawFrame( widget, 0, 0, win->m_width, win->m_height );
192 win->m_oldX = 0;
193 win->m_oldY = 0;
194
195 win->m_isDragging = TRUE;
196
197 return TRUE;
198 }
199
200 //-----------------------------------------------------------------------------
201 // "button_release_event" of m_mainWidget
202 //-----------------------------------------------------------------------------
203
204 static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win )
205 {
206 if (g_isIdle) wxapp_install_idle_handler();
207
208 if (!win->m_hasVMT) return FALSE;
209 if (g_blockEventsOnDrag) return TRUE;
210 if (g_blockEventsOnScroll) return TRUE;
211
212 if (!win->m_isDragging) return TRUE;
213
214 win->m_isDragging = FALSE;
215
216 int x = (int)gdk_event->x;
217 int y = (int)gdk_event->y;
218
219 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
220 gdk_pointer_ungrab ( (guint32)GDK_CURRENT_TIME );
221 int org_x = 0;
222 int org_y = 0;
223 gdk_window_get_origin( widget->window, &org_x, &org_y );
224 x += org_x - win->m_diffX;
225 y += org_y - win->m_diffY;
226 win->m_x = x;
227 win->m_y = y;
228 gtk_widget_set_uposition( win->m_widget, x, y );
229
230 return TRUE;
231 }
232
233 //-----------------------------------------------------------------------------
234 // "motion_notify_event" of m_mainWidget
235 //-----------------------------------------------------------------------------
236
237 static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxMiniFrame *win )
238 {
239 if (g_isIdle) wxapp_install_idle_handler();
240
241 if (!win->m_hasVMT) return FALSE;
242 if (g_blockEventsOnDrag) return TRUE;
243 if (g_blockEventsOnScroll) return TRUE;
244
245 if (!win->m_isDragging) return TRUE;
246
247 if (gdk_event->is_hint)
248 {
249 int x = 0;
250 int y = 0;
251 GdkModifierType state;
252 gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
253 gdk_event->x = x;
254 gdk_event->y = y;
255 gdk_event->state = state;
256 }
257
258 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
259 win->m_oldX = (int)gdk_event->x - win->m_diffX;
260 win->m_oldY = (int)gdk_event->y - win->m_diffY;
261 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
262
263 return TRUE;
264 }
265
266 //-----------------------------------------------------------------------------
267 // "clicked" of X system button
268 //-----------------------------------------------------------------------------
269
270 static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxMiniFrame *mf )
271 {
272 if (g_isIdle) wxapp_install_idle_handler();
273
274 mf->Close();
275 }
276
277 //-----------------------------------------------------------------------------
278 // wxMiniFrame
279 //-----------------------------------------------------------------------------
280
281 static const char *cross_xpm[] = {
282 /* columns rows colors chars-per-pixel */
283 "5 5 16 1",
284 " c Gray0",
285 ". c #bf0000",
286 "X c #00bf00",
287 "o c #bfbf00",
288 "O c #0000bf",
289 "+ c #bf00bf",
290 "@ c #00bfbf",
291 "# c None",
292 "$ c #808080",
293 "% c Red",
294 "& c Green",
295 "* c Yellow",
296 "= c Blue",
297 "- c Magenta",
298 "; c Cyan",
299 ": c Gray100",
300 /* pixels */
301 " ### ",
302 "# # #",
303 "## ##",
304 "# # #",
305 " ### ",
306 };
307
308 IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame,wxFrame)
309
310 bool wxMiniFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
311 const wxPoint &pos, const wxSize &size,
312 long style, const wxString &name )
313 {
314 style = style | wxCAPTION;
315
316 if ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT))
317 m_miniTitle = 13;
318
319 m_miniEdge = 3;
320 m_isDragging = FALSE;
321 m_oldX = -1;
322 m_oldY = -1;
323 m_diffX = 0;
324 m_diffY = 0;
325
326 wxFrame::Create( parent, id, title, pos, size, style, name );
327
328 if (m_parent && (GTK_IS_WINDOW(m_parent->m_widget)))
329 {
330 gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(m_parent->m_widget) );
331 }
332
333 if ((style & wxSYSTEM_MENU) &&
334 ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT)))
335 {
336 GdkBitmap *mask = (GdkBitmap*) NULL;
337 GdkPixmap *pixmap = gdk_pixmap_create_from_xpm_d
338 (
339 wxGetRootWindow()->window,
340 &mask,
341 NULL,
342 (char **)cross_xpm
343 );
344
345 GtkWidget *pw = gtk_pixmap_new( pixmap, mask );
346 gdk_bitmap_unref( mask );
347 gdk_pixmap_unref( pixmap );
348 gtk_widget_show( pw );
349
350 GtkWidget *close_button = gtk_button_new();
351 gtk_container_add( GTK_CONTAINER(close_button), pw );
352
353 gtk_pizza_put( GTK_PIZZA(m_mainWidget),
354 close_button,
355 size.x-16, 4, 11, 11 );
356
357 gtk_widget_show( close_button );
358
359 gtk_signal_connect( GTK_OBJECT(close_button), "clicked",
360 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
361 }
362
363 /* these are called when the borders are drawn */
364 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "expose_event",
365 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this );
366
367 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "draw",
368 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this );
369
370 /* these are required for dragging the mini frame around */
371 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_press_event",
372 GTK_SIGNAL_FUNC(gtk_window_button_press_callback), (gpointer)this );
373
374 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_release_event",
375 GTK_SIGNAL_FUNC(gtk_window_button_release_callback), (gpointer)this );
376
377 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "motion_notify_event",
378 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback), (gpointer)this );
379
380 return TRUE;
381 }
382
383 #endif