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