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