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 gtk_draw_shadow( widget
->style
,
79 win
->m_width
, win
->m_height
);
81 if (!win
->m_title
.IsEmpty() &&
82 ((win
->GetWindowStyle() & wxCAPTION
) ||
83 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
84 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
86 GdkGC
*gc
= gdk_gc_new( widget
->window
);
87 GdkFont
*font
= wxSMALL_FONT
->GetInternalFont(1.0);
89 if (win
->GetWindowStyle() & wxSYSTEM_MENU
) x
= 18;
91 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
92 gdk_draw_rectangle( widget
->window
, gc
, TRUE
,
96 font
->ascent
+ font
->descent
+1 );
98 gdk_gc_set_foreground( gc
, &widget
->style
->white
);
99 gdk_draw_string( widget
->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 gtk_draw_shadow( widget
->style
,
123 win
->m_width
, win
->m_height
);
125 if (!win
->m_title
.IsEmpty() &&
126 ((win
->GetWindowStyle() & wxCAPTION
) ||
127 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
128 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
130 GdkGC
*gc
= gdk_gc_new( widget
->window
);
131 GdkFont
*font
= wxSMALL_FONT
->GetInternalFont(1.0);
133 if (win
->GetWindowStyle() & wxSYSTEM_MENU
) x
= 17;
135 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
136 gdk_draw_rectangle( widget
->window
, gc
, TRUE
,
139 win
->m_width
- 4 - x
,
140 font
->ascent
+ font
->descent
+1 );
142 gdk_gc_set_foreground( gc
, &widget
->style
->white
);
143 gdk_draw_string( widget
->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_pointer_grab( widget
->window
, FALSE
,
168 (GDK_BUTTON_PRESS_MASK
|
169 GDK_BUTTON_RELEASE_MASK
|
170 GDK_POINTER_MOTION_MASK
|
171 GDK_POINTER_MOTION_HINT_MASK
|
172 GDK_BUTTON_MOTION_MASK
|
173 GDK_BUTTON1_MOTION_MASK
),
178 win
->m_diffX
= (int)gdk_event
->x
;
179 win
->m_diffY
= (int)gdk_event
->y
;
180 DrawFrame( widget
, 0, 0, win
->m_width
, win
->m_height
);
184 win
->m_isDragging
= TRUE
;
189 //-----------------------------------------------------------------------------
190 // "button_release_event" of m_mainWidget
191 //-----------------------------------------------------------------------------
193 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
195 if (g_isIdle
) wxapp_install_idle_handler();
197 if (!win
->m_hasVMT
) return FALSE
;
198 if (g_blockEventsOnDrag
) return TRUE
;
199 if (g_blockEventsOnScroll
) return TRUE
;
201 if (!win
->m_isDragging
) return TRUE
;
203 win
->m_isDragging
= FALSE
;
205 int x
= (int)gdk_event
->x
;
206 int y
= (int)gdk_event
->y
;
208 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
209 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
212 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
213 x
+= org_x
- win
->m_diffX
;
214 y
+= org_y
- win
->m_diffY
;
217 gtk_widget_set_uposition( win
->m_widget
, x
, y
);
222 //-----------------------------------------------------------------------------
223 // "motion_notify_event" of m_mainWidget
224 //-----------------------------------------------------------------------------
226 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxMiniFrame
*win
)
228 if (g_isIdle
) wxapp_install_idle_handler();
230 if (!win
->m_hasVMT
) return FALSE
;
231 if (g_blockEventsOnDrag
) return TRUE
;
232 if (g_blockEventsOnScroll
) return TRUE
;
234 if (!win
->m_isDragging
) return TRUE
;
236 if (gdk_event
->is_hint
)
240 GdkModifierType state
;
241 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
244 gdk_event
->state
= state
;
247 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
248 win
->m_oldX
= (int)gdk_event
->x
- win
->m_diffX
;
249 win
->m_oldY
= (int)gdk_event
->y
- win
->m_diffY
;
250 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
255 //-----------------------------------------------------------------------------
256 // "clicked" of X system button
257 //-----------------------------------------------------------------------------
259 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxMiniFrame
*mf
)
261 if (g_isIdle
) wxapp_install_idle_handler();
266 //-----------------------------------------------------------------------------
268 //-----------------------------------------------------------------------------
270 IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame
,wxFrame
)
272 bool wxMiniFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
273 const wxPoint
&pos
, const wxSize
&size
,
274 long style
, const wxString
&name
)
276 style
= style
| wxSIMPLE_BORDER
;
278 if ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
))
282 m_isDragging
= FALSE
;
288 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
290 if ((style
& wxSYSTEM_MENU
) &&
291 ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
)))
293 GtkWidget
*close_button
= gtk_button_new_with_label( "x" );
295 gtk_myfixed_put( GTK_MYFIXED(m_mainWidget
),
299 gtk_widget_show( close_button
);
301 gtk_signal_connect( GTK_OBJECT(close_button
), "clicked",
302 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
305 /* these are called when the borders are drawn */
306 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "expose_event",
307 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
309 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "draw",
310 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
312 /* these are required for dragging the mini frame around */
313 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_press_event",
314 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
316 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_release_event",
317 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
319 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "motion_notify_event",
320 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );