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