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 GtkMyFixed
*myfixed
= GTK_MYFIXED(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( myfixed
->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( myfixed
->bin_window
, gc
, TRUE
,
98 font
->ascent
+ font
->descent
+1 );
100 gdk_gc_set_foreground( gc
, &widget
->style
->white
);
101 gdk_draw_string( myfixed
->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 GtkMyFixed
*myfixed
= GTK_MYFIXED(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( myfixed
->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( myfixed
->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( myfixed
->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
;
284 style
= style
| wxSYSTEM_MENU
;
286 if ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
))
290 m_isDragging
= FALSE
;
296 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
298 if ((style
& wxSYSTEM_MENU
) &&
299 ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
)))
301 GtkWidget
*close_button
= gtk_button_new_with_label( "x" );
303 gtk_myfixed_put( GTK_MYFIXED(m_mainWidget
),
307 gtk_widget_show( close_button
);
309 gtk_signal_connect( GTK_OBJECT(close_button
), "clicked",
310 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
313 /* these are called when the borders are drawn */
314 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "expose_event",
315 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
317 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "draw",
318 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
320 /* these are required for dragging the mini frame around */
321 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_press_event",
322 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
324 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_release_event",
325 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
327 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "motion_notify_event",
328 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );