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