]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/minifram.cpp
Implement alternating row colours
[wxWidgets.git] / src / gtk1 / minifram.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/gtk1/minifram.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#if wxUSE_MINIFRAME
14
15#include "wx/minifram.h"
16
17#ifndef WX_PRECOMP
18 #include "wx/dcscreen.h"
19#endif
20
21#include "gtk/gtk.h"
22#include "wx/gtk1/win_gtk.h"
23#include "wx/gtk1/private.h"
24#include "wx/gtk1/dcclient.h"
25
26#include <gdk/gdk.h>
27#include <gdk/gdkprivate.h>
28#include <gdk/gdkx.h>
29
30//-----------------------------------------------------------------------------
31// idle system
32//-----------------------------------------------------------------------------
33
34extern void wxapp_install_idle_handler();
35extern bool g_isIdle;
36
37//-----------------------------------------------------------------------------
38// data
39//-----------------------------------------------------------------------------
40
41extern bool g_blockEventsOnDrag;
42extern bool g_blockEventsOnScroll;
43extern GtkWidget *wxGetRootWindow();
44
45//-----------------------------------------------------------------------------
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{
53 int org_x = 0;
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 );
62
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
71extern "C" {
72static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *gdk_event, wxFrame *win )
73{
74 if (g_isIdle) wxapp_install_idle_handler();
75
76 if (!win->m_hasVMT) return;
77 if (gdk_event->count > 0) return;
78
79 GtkPizza *pizza = GTK_PIZZA(widget);
80
81 gtk_draw_shadow( widget->style,
82 pizza->bin_window,
83 GTK_STATE_NORMAL,
84 GTK_SHADOW_OUT,
85 0, 0,
86 win->m_width, win->m_height );
87
88 if (!win->GetTitle().empty() &&
89 ((win->GetWindowStyle() & wxCAPTION) ||
90 (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) ||
91 (win->GetWindowStyle() & wxTINY_CAPTION_VERT)))
92 {
93 wxClientDC dc(win);
94 dc.SetFont( *wxSMALL_FONT );
95 int height = dc.GetCharHeight();
96
97 GdkGC *gc = gdk_gc_new( pizza->bin_window );
98 gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] );
99 gdk_draw_rectangle( pizza->bin_window, gc, TRUE,
100 3,
101 3,
102 win->m_width - 7,
103 height+1 );
104 gdk_gc_unref( gc );
105
106 // Hack alert
107 wx_static_cast(wxClientDCImpl *, dc.GetImpl())->m_window = pizza->bin_window;
108 dc.SetTextForeground( *wxWHITE );
109 dc.DrawText( win->GetTitle(), 6, 3 );
110 }
111}
112}
113
114//-----------------------------------------------------------------------------
115// "draw" of m_mainWidget
116//-----------------------------------------------------------------------------
117
118extern "C" {
119static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNUSED(rect), wxFrame *win )
120{
121 if (g_isIdle) wxapp_install_idle_handler();
122
123 if (!win->m_hasVMT) return;
124
125 GtkPizza *pizza = GTK_PIZZA(widget);
126
127 gtk_draw_shadow( widget->style,
128 pizza->bin_window,
129 GTK_STATE_NORMAL,
130 GTK_SHADOW_OUT,
131 0, 0,
132 win->m_width, win->m_height );
133
134 if (!win->GetTitle().empty() &&
135 ((win->GetWindowStyle() & wxCAPTION) ||
136 (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) ||
137 (win->GetWindowStyle() & wxTINY_CAPTION_VERT)))
138 {
139 wxClientDC dc(win);
140 dc.SetFont( *wxSMALL_FONT );
141 int height = dc.GetCharHeight();
142
143 GdkGC *gc = gdk_gc_new( pizza->bin_window );
144 gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] );
145 gdk_draw_rectangle( pizza->bin_window, gc, TRUE,
146 3,
147 3,
148 win->m_width - 7,
149 height+1 );
150 gdk_gc_unref( gc );
151
152 // Hack alert
153 wx_static_cast(wxClientDCImpl *, dc.GetImpl())->m_window = pizza->bin_window;
154 dc.SetTextForeground( *wxWHITE );
155 dc.DrawText( win->GetTitle(), 6, 3 );
156 }
157}
158}
159
160//-----------------------------------------------------------------------------
161// "button_press_event" of m_mainWidget
162//-----------------------------------------------------------------------------
163
164extern "C" {
165static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win )
166{
167 if (g_isIdle) wxapp_install_idle_handler();
168
169 if (!win->m_hasVMT) return FALSE;
170 if (g_blockEventsOnDrag) return TRUE;
171 if (g_blockEventsOnScroll) return TRUE;
172
173 if (win->m_isDragging) return TRUE;
174
175 GtkPizza *pizza = GTK_PIZZA(widget);
176 if (gdk_event->window != pizza->bin_window) return TRUE;
177
178 wxClientDC dc(win);
179 dc.SetFont( *wxSMALL_FONT );
180 int height = dc.GetCharHeight() + 1;
181
182 if (gdk_event->y > height) return TRUE;
183
184 gdk_window_raise( win->m_widget->window );
185
186 gdk_pointer_grab( widget->window, FALSE,
187 (GdkEventMask)
188 (GDK_BUTTON_PRESS_MASK |
189 GDK_BUTTON_RELEASE_MASK |
190 GDK_POINTER_MOTION_MASK |
191 GDK_POINTER_MOTION_HINT_MASK |
192 GDK_BUTTON_MOTION_MASK |
193 GDK_BUTTON1_MOTION_MASK),
194 (GdkWindow *) NULL,
195 (GdkCursor *) NULL,
196 (unsigned int) GDK_CURRENT_TIME );
197
198 win->m_diffX = (int)gdk_event->x;
199 win->m_diffY = (int)gdk_event->y;
200 DrawFrame( widget, 0, 0, win->m_width, win->m_height );
201 win->m_oldX = 0;
202 win->m_oldY = 0;
203
204 win->m_isDragging = true;
205
206 return TRUE;
207}
208}
209
210//-----------------------------------------------------------------------------
211// "button_release_event" of m_mainWidget
212//-----------------------------------------------------------------------------
213
214extern "C" {
215static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win )
216{
217 if (g_isIdle) wxapp_install_idle_handler();
218
219 if (!win->m_hasVMT) return FALSE;
220 if (g_blockEventsOnDrag) return TRUE;
221 if (g_blockEventsOnScroll) return TRUE;
222
223 if (!win->m_isDragging) return TRUE;
224
225 win->m_isDragging = false;
226
227 int x = (int)gdk_event->x;
228 int y = (int)gdk_event->y;
229
230 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
231 gdk_pointer_ungrab ( (guint32)GDK_CURRENT_TIME );
232 int org_x = 0;
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;
237 win->m_x = x;
238 win->m_y = y;
239 gtk_widget_set_uposition( win->m_widget, x, y );
240
241 return TRUE;
242}
243}
244
245//-----------------------------------------------------------------------------
246// "motion_notify_event" of m_mainWidget
247//-----------------------------------------------------------------------------
248
249extern "C" {
250static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxMiniFrame *win )
251{
252 if (g_isIdle) wxapp_install_idle_handler();
253
254 if (!win->m_hasVMT) return FALSE;
255 if (g_blockEventsOnDrag) return TRUE;
256 if (g_blockEventsOnScroll) return TRUE;
257
258 if (!win->m_isDragging) return TRUE;
259
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
271 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
272 win->m_oldX = (int)gdk_event->x - win->m_diffX;
273 win->m_oldY = (int)gdk_event->y - win->m_diffY;
274 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
275
276 return TRUE;
277}
278}
279
280//-----------------------------------------------------------------------------
281// "clicked" of X system button
282//-----------------------------------------------------------------------------
283
284extern "C" {
285static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxMiniFrame *mf )
286{
287 if (g_isIdle) wxapp_install_idle_handler();
288
289 mf->Close();
290}
291}
292
293//-----------------------------------------------------------------------------
294// wxMiniFrame
295//-----------------------------------------------------------------------------
296
297static const char *cross_xpm[] = {
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
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{
330 style = style | wxCAPTION;
331
332 if ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT))
333 m_miniTitle = 13;
334
335 m_miniEdge = 3;
336 m_isDragging = false;
337 m_oldX = -1;
338 m_oldY = -1;
339 m_diffX = 0;
340 m_diffY = 0;
341
342 wxFrame::Create( parent, id, title, pos, size, style, name );
343
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 }
348
349 if ((style & wxSYSTEM_MENU) &&
350 ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT)))
351 {
352 GdkBitmap *mask = (GdkBitmap*) NULL;
353 GdkPixmap *pixmap = gdk_pixmap_create_from_xpm_d
354 (
355 wxGetRootWindow()->window,
356 &mask,
357 NULL,
358 (char **)cross_xpm
359 );
360
361 GtkWidget *pw = gtk_pixmap_new( pixmap, mask );
362 gdk_bitmap_unref( mask );
363 gdk_pixmap_unref( pixmap );
364 gtk_widget_show( pw );
365
366 GtkWidget *close_button = gtk_button_new();
367 gtk_container_add( GTK_CONTAINER(close_button), pw );
368
369 gtk_pizza_put( GTK_PIZZA(m_mainWidget),
370 close_button,
371 size.x-16, 4, 11, 11 );
372
373 gtk_widget_show( close_button );
374
375 gtk_signal_connect( GTK_OBJECT(close_button), "clicked",
376 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
377 }
378
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 );
382
383 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "draw",
384 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this );
385
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 );
389
390 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_release_event",
391 GTK_SIGNAL_FUNC(gtk_window_button_release_callback), (gpointer)this );
392
393 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "motion_notify_event",
394 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback), (gpointer)this );
395
396 return true;
397}
398
399void wxMiniFrame::SetTitle( const wxString &title )
400{
401 wxFrame::SetTitle( title );
402
403 gtk_widget_draw( m_mainWidget, (GdkRectangle*) NULL );
404}
405
406#endif // wxUSE_MINIFRAME