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