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
->HasVMT()) return;
69 if (gdk_event
->count
> 0) return;
71 gtk_draw_shadow( widget
->style
,
76 win
->m_width
, win
->m_height
);
79 //-----------------------------------------------------------------------------
80 // "draw" of m_mainWidget
81 //-----------------------------------------------------------------------------
83 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxFrame
*win
)
85 if (g_isIdle
) wxapp_install_idle_handler();
87 if (!win
->HasVMT()) return;
89 gtk_draw_shadow( widget
->style
,
94 win
->m_width
, win
->m_height
);
97 //-----------------------------------------------------------------------------
98 // "button_press_event" of m_mainWidget
99 //-----------------------------------------------------------------------------
101 static gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
103 if (g_isIdle
) wxapp_install_idle_handler();
105 if (!win
->HasVMT()) return FALSE
;
106 if (g_blockEventsOnDrag
) return TRUE
;
107 if (g_blockEventsOnScroll
) return TRUE
;
109 if (win
->m_isDragging
) return TRUE
;
111 gdk_pointer_grab( widget
->window
, FALSE
,
113 (GDK_BUTTON_PRESS_MASK
|
114 GDK_BUTTON_RELEASE_MASK
|
115 GDK_POINTER_MOTION_MASK
|
116 GDK_POINTER_MOTION_HINT_MASK
|
117 GDK_BUTTON_MOTION_MASK
|
118 GDK_BUTTON1_MOTION_MASK
),
123 win
->m_diffX
= (int)gdk_event
->x
;
124 win
->m_diffY
= (int)gdk_event
->y
;
125 DrawFrame( widget
, 0, 0, win
->m_width
, win
->m_height
);
129 win
->m_isDragging
= TRUE
;
134 //-----------------------------------------------------------------------------
135 // "button_release_event" of m_mainWidget
136 //-----------------------------------------------------------------------------
138 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
140 if (g_isIdle
) wxapp_install_idle_handler();
142 if (!win
->HasVMT()) return FALSE
;
143 if (g_blockEventsOnDrag
) return TRUE
;
144 if (g_blockEventsOnScroll
) return TRUE
;
146 if (!win
->m_isDragging
) return TRUE
;
148 win
->m_isDragging
= FALSE
;
150 int x
= (int)gdk_event
->x
;
151 int y
= (int)gdk_event
->y
;
153 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
154 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
157 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
158 x
+= org_x
- win
->m_diffX
;
159 y
+= org_y
- win
->m_diffY
;
162 gtk_widget_set_uposition( win
->m_widget
, x
, y
);
167 //-----------------------------------------------------------------------------
168 // "motion_notify_event" of m_mainWidget
169 //-----------------------------------------------------------------------------
171 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxMiniFrame
*win
)
173 if (g_isIdle
) wxapp_install_idle_handler();
175 if (!win
->HasVMT()) return FALSE
;
176 if (g_blockEventsOnDrag
) return TRUE
;
177 if (g_blockEventsOnScroll
) return TRUE
;
179 if (!win
->m_isDragging
) return TRUE
;
181 if (gdk_event
->is_hint
)
185 GdkModifierType state
;
186 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
189 gdk_event
->state
= state
;
192 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
193 win
->m_oldX
= (int)gdk_event
->x
- win
->m_diffX
;
194 win
->m_oldY
= (int)gdk_event
->y
- win
->m_diffY
;
195 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
200 //-----------------------------------------------------------------------------
201 // "clicked" of X system button
202 //-----------------------------------------------------------------------------
204 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxMiniFrame
*mf
)
206 if (g_isIdle
) wxapp_install_idle_handler();
211 //-----------------------------------------------------------------------------
213 //-----------------------------------------------------------------------------
215 IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame
,wxFrame
)
217 bool wxMiniFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
218 const wxPoint
&pos
, const wxSize
&size
,
219 long style
, const wxString
&name
)
221 style
= style
| wxSIMPLE_BORDER
;
225 m_isDragging
= FALSE
;
231 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
233 GtkWidget
*close_button
= gtk_button_new_with_label( "x" );
235 gtk_myfixed_put( GTK_MYFIXED(m_mainWidget
), close_button
, 4, 4 );
236 gtk_widget_set_usize( close_button
, 12, 11 );
238 gtk_widget_show( close_button
);
240 gtk_signal_connect( GTK_OBJECT(close_button
), "clicked",
241 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
243 /* these are called when the borders are drawn */
244 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "expose_event",
245 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
247 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "draw",
248 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
250 /* these are required for dragging the mini frame around */
251 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_press_event",
252 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
254 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_release_event",
255 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
257 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "motion_notify_event",
258 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );