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"
15 #include "wx/dcscreen.h"
18 #include "wx/gtk/win_gtk.h"
21 #include "gdk/gdkprivate.h"
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 extern void wxapp_install_idle_handler();
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 extern bool g_blockEventsOnDrag
;
36 extern bool g_blockEventsOnScroll
;
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 /* draw XOR rectangle when moving mine frame around */
44 static void DrawFrame( GtkWidget
*widget
, int x
, int y
, int w
, int h
)
48 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
52 GdkGC
*gc
= gdk_gc_new( GDK_ROOT_PARENT() );
53 gdk_gc_set_subwindow( gc
, GDK_INCLUDE_INFERIORS
);
54 gdk_gc_set_function( gc
, GDK_INVERT
);
56 gdk_draw_rectangle( GDK_ROOT_PARENT(), gc
, FALSE
, x
, y
, w
, h
);
60 //-----------------------------------------------------------------------------
61 // "expose_event" of m_mainWidget
62 //-----------------------------------------------------------------------------
64 static void gtk_window_own_expose_callback( GtkWidget
*widget
, GdkEventExpose
*gdk_event
, wxFrame
*win
)
66 if (g_isIdle
) wxapp_install_idle_handler();
68 if (!win
->m_hasVMT
) return;
69 if (gdk_event
->count
> 0) return;
71 gtk_draw_shadow( widget
->style
,
76 win
->m_width
, win
->m_height
);
78 if (!win
->m_title
.IsEmpty() &&
79 ((win
->GetWindowStyle() & wxCAPTION
) ||
80 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
81 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
83 GdkGC
*gc
= gdk_gc_new( widget
->window
);
84 GdkFont
*font
= wxSMALL_FONT
->GetInternalFont(1.0);
86 if (win
->GetWindowStyle() & wxSYSTEM_MENU
) x
= 18;
88 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
89 gdk_draw_rectangle( widget
->window
, gc
, TRUE
,
93 font
->ascent
+ font
->descent
+1 );
95 gdk_gc_set_foreground( gc
, &widget
->style
->white
);
96 gdk_draw_string( widget
->window
, font
, gc
,
99 win
->m_title
.mb_str() );
105 //-----------------------------------------------------------------------------
106 // "draw" of m_mainWidget
107 //-----------------------------------------------------------------------------
109 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxFrame
*win
)
111 if (g_isIdle
) wxapp_install_idle_handler();
113 if (!win
->m_hasVMT
) return;
115 gtk_draw_shadow( widget
->style
,
120 win
->m_width
, win
->m_height
);
122 if (!win
->m_title
.IsEmpty() &&
123 ((win
->GetWindowStyle() & wxCAPTION
) ||
124 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
125 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
127 GdkGC
*gc
= gdk_gc_new( widget
->window
);
128 GdkFont
*font
= wxSMALL_FONT
->GetInternalFont(1.0);
130 if (win
->GetWindowStyle() & wxSYSTEM_MENU
) x
= 17;
132 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
133 gdk_draw_rectangle( widget
->window
, gc
, TRUE
,
136 win
->m_width
- 4 - x
,
137 font
->ascent
+ font
->descent
+1 );
139 gdk_gc_set_foreground( gc
, &widget
->style
->white
);
140 gdk_draw_string( widget
->window
, font
, gc
,
143 win
->m_title
.mb_str() );
149 //-----------------------------------------------------------------------------
150 // "button_press_event" of m_mainWidget
151 //-----------------------------------------------------------------------------
153 static gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
155 if (g_isIdle
) wxapp_install_idle_handler();
157 if (!win
->m_hasVMT
) return FALSE
;
158 if (g_blockEventsOnDrag
) return TRUE
;
159 if (g_blockEventsOnScroll
) return TRUE
;
161 if (win
->m_isDragging
) return TRUE
;
163 gdk_pointer_grab( widget
->window
, FALSE
,
165 (GDK_BUTTON_PRESS_MASK
|
166 GDK_BUTTON_RELEASE_MASK
|
167 GDK_POINTER_MOTION_MASK
|
168 GDK_POINTER_MOTION_HINT_MASK
|
169 GDK_BUTTON_MOTION_MASK
|
170 GDK_BUTTON1_MOTION_MASK
),
175 win
->m_diffX
= (int)gdk_event
->x
;
176 win
->m_diffY
= (int)gdk_event
->y
;
177 DrawFrame( widget
, 0, 0, win
->m_width
, win
->m_height
);
181 win
->m_isDragging
= TRUE
;
186 //-----------------------------------------------------------------------------
187 // "button_release_event" of m_mainWidget
188 //-----------------------------------------------------------------------------
190 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
192 if (g_isIdle
) wxapp_install_idle_handler();
194 if (!win
->m_hasVMT
) return FALSE
;
195 if (g_blockEventsOnDrag
) return TRUE
;
196 if (g_blockEventsOnScroll
) return TRUE
;
198 if (!win
->m_isDragging
) return TRUE
;
200 win
->m_isDragging
= FALSE
;
202 int x
= (int)gdk_event
->x
;
203 int y
= (int)gdk_event
->y
;
205 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
206 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
209 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
210 x
+= org_x
- win
->m_diffX
;
211 y
+= org_y
- win
->m_diffY
;
214 gtk_widget_set_uposition( win
->m_widget
, x
, y
);
219 //-----------------------------------------------------------------------------
220 // "motion_notify_event" of m_mainWidget
221 //-----------------------------------------------------------------------------
223 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxMiniFrame
*win
)
225 if (g_isIdle
) wxapp_install_idle_handler();
227 if (!win
->m_hasVMT
) return FALSE
;
228 if (g_blockEventsOnDrag
) return TRUE
;
229 if (g_blockEventsOnScroll
) return TRUE
;
231 if (!win
->m_isDragging
) return TRUE
;
233 if (gdk_event
->is_hint
)
237 GdkModifierType state
;
238 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
241 gdk_event
->state
= state
;
244 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
245 win
->m_oldX
= (int)gdk_event
->x
- win
->m_diffX
;
246 win
->m_oldY
= (int)gdk_event
->y
- win
->m_diffY
;
247 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
252 //-----------------------------------------------------------------------------
253 // "clicked" of X system button
254 //-----------------------------------------------------------------------------
256 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxMiniFrame
*mf
)
258 if (g_isIdle
) wxapp_install_idle_handler();
263 //-----------------------------------------------------------------------------
265 //-----------------------------------------------------------------------------
267 IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame
,wxFrame
)
269 bool wxMiniFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
270 const wxPoint
&pos
, const wxSize
&size
,
271 long style
, const wxString
&name
)
273 style
= style
| wxSIMPLE_BORDER
;
275 if ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
))
279 m_isDragging
= FALSE
;
285 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
287 if ((style
& wxSYSTEM_MENU
) &&
288 ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
)))
290 GtkWidget
*close_button
= gtk_button_new_with_label( "x" );
292 gtk_myfixed_put( GTK_MYFIXED(m_mainWidget
),
296 gtk_widget_show( close_button
);
298 gtk_signal_connect( GTK_OBJECT(close_button
), "clicked",
299 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
302 /* these are called when the borders are drawn */
303 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "expose_event",
304 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
306 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "draw",
307 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
309 /* these are required for dragging the mini frame around */
310 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_press_event",
311 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
313 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_release_event",
314 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
316 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "motion_notify_event",
317 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );