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