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 if (win
->GetWindowStyle() & wxSYSTEM_MENU
) x
= 18;
93 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
94 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
98 font
->ascent
+ font
->descent
+1 );
100 gdk_gc_set_foreground( gc
, &widget
->style
->white
);
101 gdk_draw_string( pizza
->bin_window
, font
, gc
,
104 win
->m_title
.mb_str() );
110 //-----------------------------------------------------------------------------
111 // "draw" of m_mainWidget
112 //-----------------------------------------------------------------------------
114 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxFrame
*win
)
116 if (g_isIdle
) wxapp_install_idle_handler();
118 if (!win
->m_hasVMT
) return;
120 GtkPizza
*pizza
= GTK_PIZZA(widget
);
122 gtk_draw_shadow( widget
->style
,
127 win
->m_width
, win
->m_height
);
129 if (!win
->m_title
.IsEmpty() &&
130 ((win
->GetWindowStyle() & wxCAPTION
) ||
131 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
132 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
134 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
135 GdkFont
*font
= wxSMALL_FONT
->GetInternalFont(1.0);
137 if (win
->GetWindowStyle() & wxSYSTEM_MENU
) x
= 17;
139 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
140 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
143 win
->m_width
- 4 - x
,
144 font
->ascent
+ font
->descent
+1 );
146 gdk_gc_set_foreground( gc
, &widget
->style
->white
);
147 gdk_draw_string( pizza
->bin_window
, font
, gc
,
150 win
->m_title
.mb_str() );
156 //-----------------------------------------------------------------------------
157 // "button_press_event" of m_mainWidget
158 //-----------------------------------------------------------------------------
160 static gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
162 if (g_isIdle
) wxapp_install_idle_handler();
164 if (!win
->m_hasVMT
) return FALSE
;
165 if (g_blockEventsOnDrag
) return TRUE
;
166 if (g_blockEventsOnScroll
) return TRUE
;
168 if (win
->m_isDragging
) return TRUE
;
170 gdk_window_raise( win
->m_widget
->window
);
172 gdk_pointer_grab( widget
->window
, FALSE
,
174 (GDK_BUTTON_PRESS_MASK
|
175 GDK_BUTTON_RELEASE_MASK
|
176 GDK_POINTER_MOTION_MASK
|
177 GDK_POINTER_MOTION_HINT_MASK
|
178 GDK_BUTTON_MOTION_MASK
|
179 GDK_BUTTON1_MOTION_MASK
),
184 win
->m_diffX
= (int)gdk_event
->x
;
185 win
->m_diffY
= (int)gdk_event
->y
;
186 DrawFrame( widget
, 0, 0, win
->m_width
, win
->m_height
);
190 win
->m_isDragging
= TRUE
;
195 //-----------------------------------------------------------------------------
196 // "button_release_event" of m_mainWidget
197 //-----------------------------------------------------------------------------
199 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
201 if (g_isIdle
) wxapp_install_idle_handler();
203 if (!win
->m_hasVMT
) return FALSE
;
204 if (g_blockEventsOnDrag
) return TRUE
;
205 if (g_blockEventsOnScroll
) return TRUE
;
207 if (!win
->m_isDragging
) return TRUE
;
209 win
->m_isDragging
= FALSE
;
211 int x
= (int)gdk_event
->x
;
212 int y
= (int)gdk_event
->y
;
214 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
215 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
218 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
219 x
+= org_x
- win
->m_diffX
;
220 y
+= org_y
- win
->m_diffY
;
223 gtk_widget_set_uposition( win
->m_widget
, x
, y
);
228 //-----------------------------------------------------------------------------
229 // "motion_notify_event" of m_mainWidget
230 //-----------------------------------------------------------------------------
232 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxMiniFrame
*win
)
234 if (g_isIdle
) wxapp_install_idle_handler();
236 if (!win
->m_hasVMT
) return FALSE
;
237 if (g_blockEventsOnDrag
) return TRUE
;
238 if (g_blockEventsOnScroll
) return TRUE
;
240 if (!win
->m_isDragging
) return TRUE
;
242 if (gdk_event
->is_hint
)
246 GdkModifierType state
;
247 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
250 gdk_event
->state
= state
;
253 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
254 win
->m_oldX
= (int)gdk_event
->x
- win
->m_diffX
;
255 win
->m_oldY
= (int)gdk_event
->y
- win
->m_diffY
;
256 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
261 //-----------------------------------------------------------------------------
262 // "clicked" of X system button
263 //-----------------------------------------------------------------------------
265 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxMiniFrame
*mf
)
267 if (g_isIdle
) wxapp_install_idle_handler();
272 //-----------------------------------------------------------------------------
274 //-----------------------------------------------------------------------------
276 IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame
,wxFrame
)
278 bool wxMiniFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
279 const wxPoint
&pos
, const wxSize
&size
,
280 long style
, const wxString
&name
)
282 style
= style
| wxSIMPLE_BORDER
;
283 style
= style
| wxCAPTION
;
285 if ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
))
289 m_isDragging
= FALSE
;
295 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
297 if ((style
& wxSYSTEM_MENU
) &&
298 ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
)))
300 GtkWidget
*close_button
= gtk_button_new_with_label( "x" );
302 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
306 gtk_widget_show( close_button
);
308 gtk_signal_connect( GTK_OBJECT(close_button
), "clicked",
309 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
312 /* these are called when the borders are drawn */
313 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "expose_event",
314 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
316 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "draw",
317 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
319 /* these are required for dragging the mini frame around */
320 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_press_event",
321 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
323 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_release_event",
324 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
326 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "motion_notify_event",
327 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );