]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/minifram.cpp
ConvertToImage: Check !Ok() (we may not have any ref data at all) and if
[wxWidgets.git] / src / gtk1 / 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
14f355c2
VS
10#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "minifram.h"
b2b3ccc5
RR
12#endif
13
14f355c2
VS
14// For compilers that support precompilation, includes "wx.h".
15#include "wx/wxprec.h"
16
b2b3ccc5 17#include "wx/minifram.h"
dcf924a3
RR
18
19#if wxUSE_MINIFRAME
20
b2b3ccc5
RR
21#include "wx/dcscreen.h"
22
83624f79
RR
23#include "gtk/gtk.h"
24#include "wx/gtk/win_gtk.h"
fab591c5 25#include "wx/gtk/private.h"
83624f79 26
5e7e9e1b
RR
27#include <gdk/gdk.h>
28#include <gdk/gdkprivate.h>
29#include <gdk/gdkx.h>
32a95f9f 30
acfd422a
RR
31//-----------------------------------------------------------------------------
32// idle system
33//-----------------------------------------------------------------------------
34
35extern void wxapp_install_idle_handler();
36extern bool g_isIdle;
37
32a95f9f
RR
38//-----------------------------------------------------------------------------
39// data
40//-----------------------------------------------------------------------------
41
8480b297
RR
42extern bool g_blockEventsOnDrag;
43extern bool g_blockEventsOnScroll;
c2fa61e8 44extern GtkWidget *wxGetRootWindow();
32a95f9f 45
b2b3ccc5 46//-----------------------------------------------------------------------------
32a95f9f
RR
47// local functions
48//-----------------------------------------------------------------------------
49
50/* draw XOR rectangle when moving mine frame around */
51
52static void DrawFrame( GtkWidget *widget, int x, int y, int w, int h )
53{
c2fa61e8 54 int org_x = 0;
32a95f9f
RR
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 );
c2fa61e8 63
32a95f9f
RR
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
72static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *gdk_event, wxFrame *win )
73{
acfd422a
RR
74 if (g_isIdle) wxapp_install_idle_handler();
75
a2053b27 76 if (!win->m_hasVMT) return;
32a95f9f 77 if (gdk_event->count > 0) return;
c2fa61e8 78
da048e3d 79 GtkPizza *pizza = GTK_PIZZA(widget);
c2fa61e8
RD
80
81 gtk_draw_shadow( widget->style,
da048e3d 82 pizza->bin_window,
f03fc89f
VZ
83 GTK_STATE_NORMAL,
84 GTK_SHADOW_OUT,
85 0, 0,
a2053b27 86 win->m_width, win->m_height );
b9a535f5 87
ba718523 88 if (!win->GetTitle().IsEmpty() &&
c2fa61e8
RD
89 ((win->GetWindowStyle() & wxCAPTION) ||
90 (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) ||
f03fc89f 91 (win->GetWindowStyle() & wxTINY_CAPTION_VERT)))
b9a535f5 92 {
ba718523
RR
93 wxClientDC dc(win);
94 dc.SetFont( *wxSMALL_FONT );
95 int height = dc.GetCharHeight();
96
da048e3d 97 GdkGC *gc = gdk_gc_new( pizza->bin_window );
b9a535f5 98 gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] );
c2fa61e8
RD
99 gdk_draw_rectangle( pizza->bin_window, gc, TRUE,
100 3,
101 3,
5d5b3a40 102 win->m_width - 7,
ba718523 103 height+1 );
b9a535f5 104 gdk_gc_unref( gc );
ba718523
RR
105
106 // Hack alert
107 dc.m_window = pizza->bin_window;
108 dc.SetTextForeground( *wxWHITE );
109 dc.DrawText( win->GetTitle(), 6, 3 );
b9a535f5 110 }
32a95f9f
RR
111}
112
113//-----------------------------------------------------------------------------
114// "draw" of m_mainWidget
115//-----------------------------------------------------------------------------
116
ba718523 117#ifndef __WXGTK20__
32a95f9f
RR
118static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNUSED(rect), wxFrame *win )
119{
acfd422a
RR
120 if (g_isIdle) wxapp_install_idle_handler();
121
a2053b27 122 if (!win->m_hasVMT) return;
c2fa61e8 123
da048e3d 124 GtkPizza *pizza = GTK_PIZZA(widget);
c2fa61e8
RD
125
126 gtk_draw_shadow( widget->style,
da048e3d 127 pizza->bin_window,
f03fc89f
VZ
128 GTK_STATE_NORMAL,
129 GTK_SHADOW_OUT,
130 0, 0,
a2053b27 131 win->m_width, win->m_height );
c2fa61e8 132
b9a535f5 133 if (!win->m_title.IsEmpty() &&
c2fa61e8
RD
134 ((win->GetWindowStyle() & wxCAPTION) ||
135 (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) ||
f03fc89f 136 (win->GetWindowStyle() & wxTINY_CAPTION_VERT)))
b9a535f5 137 {
ba718523
RR
138 wxClientDC dc(win);
139 dc.SetFont( *wxSMALL_FONT );
140 int height = dc.GetCharHeight();
141
da048e3d 142 GdkGC *gc = gdk_gc_new( pizza->bin_window );
b9a535f5 143 gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] );
c2fa61e8
RD
144 gdk_draw_rectangle( pizza->bin_window, gc, TRUE,
145 3,
5d5b3a40
RR
146 3,
147 win->m_width - 7,
ba718523 148 height+1 );
b9a535f5 149 gdk_gc_unref( gc );
ba718523
RR
150
151 // Hack alert
152 dc.m_window = pizza->bin_window;
153 dc.SetTextForeground( *wxWHITE );
154 dc.DrawText( win->GetTitle(), 6, 3 );
b9a535f5 155 }
32a95f9f 156}
ba718523 157#endif
32a95f9f
RR
158
159//-----------------------------------------------------------------------------
160// "button_press_event" of m_mainWidget
161//-----------------------------------------------------------------------------
162
163static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win )
164{
acfd422a
RR
165 if (g_isIdle) wxapp_install_idle_handler();
166
a2053b27 167 if (!win->m_hasVMT) return FALSE;
32a95f9f
RR
168 if (g_blockEventsOnDrag) return TRUE;
169 if (g_blockEventsOnScroll) return TRUE;
170
171 if (win->m_isDragging) return TRUE;
172
2c990ec0
RR
173 GtkPizza *pizza = GTK_PIZZA(widget);
174 if (gdk_event->window != pizza->bin_window) return TRUE;
ba718523
RR
175
176 wxClientDC dc(win);
177 dc.SetFont( *wxSMALL_FONT );
178 int height = dc.GetCharHeight() + 1;
2c990ec0 179
2c990ec0
RR
180 if (gdk_event->y > height) return TRUE;
181
4dcaf11a 182 gdk_window_raise( win->m_widget->window );
c2fa61e8 183
32a95f9f
RR
184 gdk_pointer_grab( widget->window, FALSE,
185 (GdkEventMask)
186 (GDK_BUTTON_PRESS_MASK |
187 GDK_BUTTON_RELEASE_MASK |
f03fc89f 188 GDK_POINTER_MOTION_MASK |
32a95f9f 189 GDK_POINTER_MOTION_HINT_MASK |
f03fc89f 190 GDK_BUTTON_MOTION_MASK |
32a95f9f
RR
191 GDK_BUTTON1_MOTION_MASK),
192 (GdkWindow *) NULL,
193 (GdkCursor *) NULL,
7941ba11 194 (unsigned int) GDK_CURRENT_TIME );
c2fa61e8 195
32a95f9f
RR
196 win->m_diffX = (int)gdk_event->x;
197 win->m_diffY = (int)gdk_event->y;
a2053b27 198 DrawFrame( widget, 0, 0, win->m_width, win->m_height );
32a95f9f
RR
199 win->m_oldX = 0;
200 win->m_oldY = 0;
c2fa61e8 201
32a95f9f
RR
202 win->m_isDragging = TRUE;
203
204 return TRUE;
205}
206
207//-----------------------------------------------------------------------------
208// "button_release_event" of m_mainWidget
209//-----------------------------------------------------------------------------
210
211static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win )
212{
acfd422a
RR
213 if (g_isIdle) wxapp_install_idle_handler();
214
a2053b27 215 if (!win->m_hasVMT) return FALSE;
32a95f9f
RR
216 if (g_blockEventsOnDrag) return TRUE;
217 if (g_blockEventsOnScroll) return TRUE;
218
219 if (!win->m_isDragging) return TRUE;
c2fa61e8 220
32a95f9f 221 win->m_isDragging = FALSE;
c2fa61e8 222
32a95f9f
RR
223 int x = (int)gdk_event->x;
224 int y = (int)gdk_event->y;
c2fa61e8 225
a2053b27 226 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
13111b2a 227 gdk_pointer_ungrab ( (guint32)GDK_CURRENT_TIME );
c2fa61e8 228 int org_x = 0;
32a95f9f
RR
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;
121a3581
RR
233 win->m_x = x;
234 win->m_y = y;
a2053b27 235 gtk_widget_set_uposition( win->m_widget, x, y );
32a95f9f
RR
236
237 return TRUE;
238}
239
240//-----------------------------------------------------------------------------
241// "motion_notify_event" of m_mainWidget
242//-----------------------------------------------------------------------------
243
244static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxMiniFrame *win )
245{
acfd422a
RR
246 if (g_isIdle) wxapp_install_idle_handler();
247
a2053b27 248 if (!win->m_hasVMT) return FALSE;
32a95f9f
RR
249 if (g_blockEventsOnDrag) return TRUE;
250 if (g_blockEventsOnScroll) return TRUE;
251
252 if (!win->m_isDragging) return TRUE;
c2fa61e8 253
32a95f9f
RR
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
a2053b27 265 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
32a95f9f
RR
266 win->m_oldX = (int)gdk_event->x - win->m_diffX;
267 win->m_oldY = (int)gdk_event->y - win->m_diffY;
a2053b27 268 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
c2fa61e8 269
32a95f9f
RR
270 return TRUE;
271}
272
273//-----------------------------------------------------------------------------
274// "clicked" of X system button
b2b3ccc5
RR
275//-----------------------------------------------------------------------------
276
277static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxMiniFrame *mf )
278{
acfd422a
RR
279 if (g_isIdle) wxapp_install_idle_handler();
280
b2b3ccc5
RR
281 mf->Close();
282}
283
284//-----------------------------------------------------------------------------
285// wxMiniFrame
286//-----------------------------------------------------------------------------
287
90350682 288static const char *cross_xpm[] = {
5d5b3a40
RR
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
b2b3ccc5
RR
315IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame,wxFrame)
316
317bool wxMiniFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
318 const wxPoint &pos, const wxSize &size,
319 long style, const wxString &name )
320{
2c990ec0 321 style = style | wxCAPTION;
b9a535f5
RR
322
323 if ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT))
324 m_miniTitle = 13;
c2fa61e8 325
b2b3ccc5 326 m_miniEdge = 3;
b2b3ccc5
RR
327 m_isDragging = FALSE;
328 m_oldX = -1;
329 m_oldY = -1;
330 m_diffX = 0;
331 m_diffY = 0;
c2fa61e8 332
b2b3ccc5
RR
333 wxFrame::Create( parent, id, title, pos, size, style, name );
334
2c990ec0
RR
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
b9a535f5
RR
340 if ((style & wxSYSTEM_MENU) &&
341 ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT)))
342 {
5d5b3a40 343 GdkBitmap *mask = (GdkBitmap*) NULL;
90350682
VZ
344 GdkPixmap *pixmap = gdk_pixmap_create_from_xpm_d
345 (
346 wxGetRootWindow()->window,
347 &mask,
348 NULL,
349 (char **)cross_xpm
350 );
c2fa61e8 351
5d5b3a40
RR
352 GtkWidget *pw = gtk_pixmap_new( pixmap, mask );
353 gdk_bitmap_unref( mask );
354 gdk_pixmap_unref( pixmap );
355 gtk_widget_show( pw );
c2fa61e8 356
5d5b3a40
RR
357 GtkWidget *close_button = gtk_button_new();
358 gtk_container_add( GTK_CONTAINER(close_button), pw );
c2fa61e8
RD
359
360 gtk_pizza_put( GTK_PIZZA(m_mainWidget),
361 close_button,
5d5b3a40 362 size.x-16, 4, 11, 11 );
c2fa61e8 363
b9a535f5 364 gtk_widget_show( close_button );
c2fa61e8 365
b9a535f5
RR
366 gtk_signal_connect( GTK_OBJECT(close_button), "clicked",
367 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
368 }
c2fa61e8 369
32a95f9f
RR
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 );
b2b3ccc5 373
ba718523 374#ifndef __WXGTK20__
32a95f9f
RR
375 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "draw",
376 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this );
ba718523 377#endif
c2fa61e8 378
32a95f9f
RR
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 );
b2b3ccc5 382
32a95f9f
RR
383 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_release_event",
384 GTK_SIGNAL_FUNC(gtk_window_button_release_callback), (gpointer)this );
b2b3ccc5 385
32a95f9f
RR
386 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "motion_notify_event",
387 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback), (gpointer)this );
b2b3ccc5 388
32a95f9f 389 return TRUE;
b2b3ccc5 390}
dcf924a3
RR
391
392#endif