1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "minifram.h"
14 #include "wx/minifram.h"
18 #include "wx/dcscreen.h"
21 #include "wx/gtk/win_gtk.h"
24 #include <gdk/gdkprivate.h>
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 extern void wxapp_install_idle_handler();
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 extern bool g_blockEventsOnDrag
;
39 extern bool g_blockEventsOnScroll
;
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 /* draw XOR rectangle when moving mine frame around */
47 static void DrawFrame( GtkWidget
*widget
, int x
, int y
, int w
, int h
)
51 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
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
);
59 gdk_draw_rectangle( GDK_ROOT_PARENT(), gc
, FALSE
, x
, y
, w
, h
);
63 //-----------------------------------------------------------------------------
64 // "expose_event" of m_mainWidget
65 //-----------------------------------------------------------------------------
67 static void gtk_window_own_expose_callback( GtkWidget
*widget
, GdkEventExpose
*gdk_event
, wxFrame
*win
)
69 if (g_isIdle
) wxapp_install_idle_handler();
71 if (!win
->m_hasVMT
) return;
72 if (gdk_event
->count
> 0) return;
74 GtkPizza
*pizza
= GTK_PIZZA(widget
);
76 gtk_draw_shadow( widget
->style
,
81 win
->m_width
, win
->m_height
);
83 if (!win
->m_title
.IsEmpty() &&
84 ((win
->GetWindowStyle() & wxCAPTION
) ||
85 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
86 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
88 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
89 GdkFont
*font
= wxSMALL_FONT
->GetInternalFont(1.0);
91 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
92 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
96 font
->ascent
+ font
->descent
+1 );
98 gdk_gc_set_foreground( gc
, &widget
->style
->white
);
99 gdk_draw_string( pizza
->bin_window
, font
, gc
,
102 win
->m_title
.mb_str() );
108 //-----------------------------------------------------------------------------
109 // "draw" of m_mainWidget
110 //-----------------------------------------------------------------------------
112 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxFrame
*win
)
114 if (g_isIdle
) wxapp_install_idle_handler();
116 if (!win
->m_hasVMT
) return;
118 GtkPizza
*pizza
= GTK_PIZZA(widget
);
120 gtk_draw_shadow( widget
->style
,
125 win
->m_width
, win
->m_height
);
127 if (!win
->m_title
.IsEmpty() &&
128 ((win
->GetWindowStyle() & wxCAPTION
) ||
129 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
130 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
132 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
133 GdkFont
*font
= wxSMALL_FONT
->GetInternalFont(1.0);
135 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
136 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
140 font
->ascent
+ font
->descent
+1 );
142 gdk_gc_set_foreground( gc
, &widget
->style
->white
);
143 gdk_draw_string( pizza
->bin_window
, font
, gc
,
146 win
->m_title
.mb_str() );
152 //-----------------------------------------------------------------------------
153 // "button_press_event" of m_mainWidget
154 //-----------------------------------------------------------------------------
156 static gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
158 if (g_isIdle
) wxapp_install_idle_handler();
160 if (!win
->m_hasVMT
) return FALSE
;
161 if (g_blockEventsOnDrag
) return TRUE
;
162 if (g_blockEventsOnScroll
) return TRUE
;
164 if (win
->m_isDragging
) return TRUE
;
166 gdk_window_raise( win
->m_widget
->window
);
168 gdk_pointer_grab( widget
->window
, FALSE
,
170 (GDK_BUTTON_PRESS_MASK
|
171 GDK_BUTTON_RELEASE_MASK
|
172 GDK_POINTER_MOTION_MASK
|
173 GDK_POINTER_MOTION_HINT_MASK
|
174 GDK_BUTTON_MOTION_MASK
|
175 GDK_BUTTON1_MOTION_MASK
),
178 (unsigned int) GDK_CURRENT_TIME
);
180 win
->m_diffX
= (int)gdk_event
->x
;
181 win
->m_diffY
= (int)gdk_event
->y
;
182 DrawFrame( widget
, 0, 0, win
->m_width
, win
->m_height
);
186 win
->m_isDragging
= TRUE
;
191 //-----------------------------------------------------------------------------
192 // "button_release_event" of m_mainWidget
193 //-----------------------------------------------------------------------------
195 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
197 if (g_isIdle
) wxapp_install_idle_handler();
199 if (!win
->m_hasVMT
) return FALSE
;
200 if (g_blockEventsOnDrag
) return TRUE
;
201 if (g_blockEventsOnScroll
) return TRUE
;
203 if (!win
->m_isDragging
) return TRUE
;
205 win
->m_isDragging
= FALSE
;
207 int x
= (int)gdk_event
->x
;
208 int y
= (int)gdk_event
->y
;
210 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
211 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
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
;
219 gtk_widget_set_uposition( win
->m_widget
, x
, y
);
224 //-----------------------------------------------------------------------------
225 // "motion_notify_event" of m_mainWidget
226 //-----------------------------------------------------------------------------
228 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxMiniFrame
*win
)
230 if (g_isIdle
) wxapp_install_idle_handler();
232 if (!win
->m_hasVMT
) return FALSE
;
233 if (g_blockEventsOnDrag
) return TRUE
;
234 if (g_blockEventsOnScroll
) return TRUE
;
236 if (!win
->m_isDragging
) return TRUE
;
238 if (gdk_event
->is_hint
)
242 GdkModifierType state
;
243 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
246 gdk_event
->state
= state
;
249 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
250 win
->m_oldX
= (int)gdk_event
->x
- win
->m_diffX
;
251 win
->m_oldY
= (int)gdk_event
->y
- win
->m_diffY
;
252 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
257 //-----------------------------------------------------------------------------
258 // "clicked" of X system button
259 //-----------------------------------------------------------------------------
261 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxMiniFrame
*mf
)
263 if (g_isIdle
) wxapp_install_idle_handler();
268 //-----------------------------------------------------------------------------
270 //-----------------------------------------------------------------------------
272 static char *cross_xpm
[] = {
273 /* columns rows colors chars-per-pixel */
299 IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame
,wxFrame
)
301 bool wxMiniFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
302 const wxPoint
&pos
, const wxSize
&size
,
303 long style
, const wxString
&name
)
305 style
= style
| wxSIMPLE_BORDER
;
306 style
= style
| wxCAPTION
;
308 if ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
))
312 m_isDragging
= FALSE
;
318 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
320 if ((style
& wxSYSTEM_MENU
) &&
321 ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
)))
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
);
327 GtkWidget
*pw
= gtk_pixmap_new( pixmap
, mask
);
328 gdk_bitmap_unref( mask
);
329 gdk_pixmap_unref( pixmap
);
330 gtk_widget_show( pw
);
332 GtkWidget
*close_button
= gtk_button_new();
333 gtk_container_add( GTK_CONTAINER(close_button
), pw
);
335 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
337 size
.x
-16, 4, 11, 11 );
339 gtk_widget_show( close_button
);
341 gtk_signal_connect( GTK_OBJECT(close_button
), "clicked",
342 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
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 );
349 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "draw",
350 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
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 );
356 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_release_event",
357 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
359 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "motion_notify_event",
360 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );