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
;
40 extern GtkWidget
*wxGetRootWindow();
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
46 /* draw XOR rectangle when moving mine frame around */
48 static void DrawFrame( GtkWidget
*widget
, int x
, int y
, int w
, int h
)
52 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
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
);
60 gdk_draw_rectangle( GDK_ROOT_PARENT(), gc
, FALSE
, x
, y
, w
, h
);
64 //-----------------------------------------------------------------------------
65 // "expose_event" of m_mainWidget
66 //-----------------------------------------------------------------------------
68 static void gtk_window_own_expose_callback( GtkWidget
*widget
, GdkEventExpose
*gdk_event
, wxFrame
*win
)
70 if (g_isIdle
) wxapp_install_idle_handler();
72 if (!win
->m_hasVMT
) return;
73 if (gdk_event
->count
> 0) return;
75 GtkPizza
*pizza
= GTK_PIZZA(widget
);
77 gtk_draw_shadow( widget
->style
,
82 win
->m_width
, win
->m_height
);
84 if (!win
->m_title
.IsEmpty() &&
85 ((win
->GetWindowStyle() & wxCAPTION
) ||
86 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
87 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
89 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
90 GdkFont
*font
= wxSMALL_FONT
->GetInternalFont(1.0);
92 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
93 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
97 font
->ascent
+ font
->descent
+1 );
99 gdk_gc_set_foreground( gc
, &widget
->style
->fg
[GTK_STATE_SELECTED
] );
100 gdk_draw_string( pizza
->bin_window
, font
, gc
,
103 win
->m_title
.mb_str() );
109 //-----------------------------------------------------------------------------
110 // "draw" of m_mainWidget
111 //-----------------------------------------------------------------------------
113 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxFrame
*win
)
115 if (g_isIdle
) wxapp_install_idle_handler();
117 if (!win
->m_hasVMT
) return;
119 GtkPizza
*pizza
= GTK_PIZZA(widget
);
121 gtk_draw_shadow( widget
->style
,
126 win
->m_width
, win
->m_height
);
128 if (!win
->m_title
.IsEmpty() &&
129 ((win
->GetWindowStyle() & wxCAPTION
) ||
130 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
131 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
133 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
134 GdkFont
*font
= wxSMALL_FONT
->GetInternalFont(1.0);
136 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
137 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
141 font
->ascent
+ font
->descent
+1 );
143 gdk_gc_set_foreground( gc
, &widget
->style
->fg
[GTK_STATE_SELECTED
] );
144 gdk_draw_string( pizza
->bin_window
, font
, gc
,
147 win
->m_title
.mb_str() );
153 //-----------------------------------------------------------------------------
154 // "button_press_event" of m_mainWidget
155 //-----------------------------------------------------------------------------
157 static gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
159 if (g_isIdle
) wxapp_install_idle_handler();
161 if (!win
->m_hasVMT
) return FALSE
;
162 if (g_blockEventsOnDrag
) return TRUE
;
163 if (g_blockEventsOnScroll
) return TRUE
;
165 if (win
->m_isDragging
) return TRUE
;
167 GtkPizza
*pizza
= GTK_PIZZA(widget
);
168 if (gdk_event
->window
!= pizza
->bin_window
) return TRUE
;
170 GdkFont
*font
= wxSMALL_FONT
->GetInternalFont(1.0);
171 int height
= font
->ascent
+ font
->descent
+1;
172 if (gdk_event
->y
> height
) return TRUE
;
174 gdk_window_raise( win
->m_widget
->window
);
176 gdk_pointer_grab( widget
->window
, FALSE
,
178 (GDK_BUTTON_PRESS_MASK
|
179 GDK_BUTTON_RELEASE_MASK
|
180 GDK_POINTER_MOTION_MASK
|
181 GDK_POINTER_MOTION_HINT_MASK
|
182 GDK_BUTTON_MOTION_MASK
|
183 GDK_BUTTON1_MOTION_MASK
),
186 (unsigned int) GDK_CURRENT_TIME
);
188 win
->m_diffX
= (int)gdk_event
->x
;
189 win
->m_diffY
= (int)gdk_event
->y
;
190 DrawFrame( widget
, 0, 0, win
->m_width
, win
->m_height
);
194 win
->m_isDragging
= TRUE
;
199 //-----------------------------------------------------------------------------
200 // "button_release_event" of m_mainWidget
201 //-----------------------------------------------------------------------------
203 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
205 if (g_isIdle
) wxapp_install_idle_handler();
207 if (!win
->m_hasVMT
) return FALSE
;
208 if (g_blockEventsOnDrag
) return TRUE
;
209 if (g_blockEventsOnScroll
) return TRUE
;
211 if (!win
->m_isDragging
) return TRUE
;
213 win
->m_isDragging
= FALSE
;
215 int x
= (int)gdk_event
->x
;
216 int y
= (int)gdk_event
->y
;
218 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
219 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
222 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
223 x
+= org_x
- win
->m_diffX
;
224 y
+= org_y
- win
->m_diffY
;
227 gtk_widget_set_uposition( win
->m_widget
, x
, y
);
232 //-----------------------------------------------------------------------------
233 // "motion_notify_event" of m_mainWidget
234 //-----------------------------------------------------------------------------
236 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxMiniFrame
*win
)
238 if (g_isIdle
) wxapp_install_idle_handler();
240 if (!win
->m_hasVMT
) return FALSE
;
241 if (g_blockEventsOnDrag
) return TRUE
;
242 if (g_blockEventsOnScroll
) return TRUE
;
244 if (!win
->m_isDragging
) return TRUE
;
246 if (gdk_event
->is_hint
)
250 GdkModifierType state
;
251 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
254 gdk_event
->state
= state
;
257 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
258 win
->m_oldX
= (int)gdk_event
->x
- win
->m_diffX
;
259 win
->m_oldY
= (int)gdk_event
->y
- win
->m_diffY
;
260 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
265 //-----------------------------------------------------------------------------
266 // "clicked" of X system button
267 //-----------------------------------------------------------------------------
269 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxMiniFrame
*mf
)
271 if (g_isIdle
) wxapp_install_idle_handler();
276 //-----------------------------------------------------------------------------
278 //-----------------------------------------------------------------------------
280 static const char *cross_xpm
[] = {
281 /* columns rows colors chars-per-pixel */
307 IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame
,wxFrame
)
309 bool wxMiniFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
310 const wxPoint
&pos
, const wxSize
&size
,
311 long style
, const wxString
&name
)
313 style
= style
| wxCAPTION
;
315 if ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
))
319 m_isDragging
= FALSE
;
325 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
327 if (m_parent
&& (GTK_IS_WINDOW(m_parent
->m_widget
)))
329 gtk_window_set_transient_for( GTK_WINDOW(m_widget
), GTK_WINDOW(m_parent
->m_widget
) );
332 if ((style
& wxSYSTEM_MENU
) &&
333 ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
)))
335 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
336 GdkPixmap
*pixmap
= gdk_pixmap_create_from_xpm_d
338 wxGetRootWindow()->window
,
344 GtkWidget
*pw
= gtk_pixmap_new( pixmap
, mask
);
345 gdk_bitmap_unref( mask
);
346 gdk_pixmap_unref( pixmap
);
347 gtk_widget_show( pw
);
349 GtkWidget
*close_button
= gtk_button_new();
350 gtk_container_add( GTK_CONTAINER(close_button
), pw
);
352 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
354 size
.x
-16, 4, 11, 11 );
356 gtk_widget_show( close_button
);
358 gtk_signal_connect( GTK_OBJECT(close_button
), "clicked",
359 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
362 /* these are called when the borders are drawn */
363 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "expose_event",
364 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
366 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "draw",
367 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
369 /* these are required for dragging the mini frame around */
370 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_press_event",
371 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
373 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_release_event",
374 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
376 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "motion_notify_event",
377 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );