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 bool g_blockEventsOnDrag
;
29 extern bool g_blockEventsOnScroll
;
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 /* draw XOR rectangle when moving mine frame around */
37 static void DrawFrame( GtkWidget
*widget
, int x
, int y
, int w
, int h
)
41 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
45 GdkGC
*gc
= gdk_gc_new( GDK_ROOT_PARENT() );
46 gdk_gc_set_subwindow( gc
, GDK_INCLUDE_INFERIORS
);
47 gdk_gc_set_function( gc
, GDK_INVERT
);
49 gdk_draw_rectangle( GDK_ROOT_PARENT(), gc
, FALSE
, x
, y
, w
, h
);
53 //-----------------------------------------------------------------------------
54 // "expose_event" of m_mainWidget
55 //-----------------------------------------------------------------------------
57 static void gtk_window_own_expose_callback( GtkWidget
*widget
, GdkEventExpose
*gdk_event
, wxFrame
*win
)
59 if (!win
->HasVMT()) return;
60 if (gdk_event
->count
> 0) return;
62 gtk_draw_shadow( widget
->style
,
67 win
->m_width
, win
->m_height
);
70 //-----------------------------------------------------------------------------
71 // "draw" of m_mainWidget
72 //-----------------------------------------------------------------------------
74 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxFrame
*win
)
76 if (!win
->HasVMT()) return;
78 gtk_draw_shadow( widget
->style
,
83 win
->m_width
, win
->m_height
);
86 //-----------------------------------------------------------------------------
87 // "button_press_event" of m_mainWidget
88 //-----------------------------------------------------------------------------
90 static gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
92 if (!win
->HasVMT()) return FALSE
;
93 if (g_blockEventsOnDrag
) return TRUE
;
94 if (g_blockEventsOnScroll
) return TRUE
;
96 if (win
->m_isDragging
) return TRUE
;
98 gdk_pointer_grab( widget
->window
, FALSE
,
100 (GDK_BUTTON_PRESS_MASK
|
101 GDK_BUTTON_RELEASE_MASK
|
102 GDK_POINTER_MOTION_MASK
|
103 GDK_POINTER_MOTION_HINT_MASK
|
104 GDK_BUTTON_MOTION_MASK
|
105 GDK_BUTTON1_MOTION_MASK
),
110 win
->m_diffX
= (int)gdk_event
->x
;
111 win
->m_diffY
= (int)gdk_event
->y
;
112 DrawFrame( widget
, 0, 0, win
->m_width
, win
->m_height
);
116 win
->m_isDragging
= TRUE
;
121 //-----------------------------------------------------------------------------
122 // "button_release_event" of m_mainWidget
123 //-----------------------------------------------------------------------------
125 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
127 if (!win
->HasVMT()) return FALSE
;
128 if (g_blockEventsOnDrag
) return TRUE
;
129 if (g_blockEventsOnScroll
) return TRUE
;
131 if (!win
->m_isDragging
) return TRUE
;
133 win
->m_isDragging
= FALSE
;
135 int x
= (int)gdk_event
->x
;
136 int y
= (int)gdk_event
->y
;
138 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
139 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
142 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
143 x
+= org_x
- win
->m_diffX
;
144 y
+= org_y
- win
->m_diffY
;
147 gtk_widget_set_uposition( win
->m_widget
, x
, y
);
152 //-----------------------------------------------------------------------------
153 // "motion_notify_event" of m_mainWidget
154 //-----------------------------------------------------------------------------
156 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxMiniFrame
*win
)
158 if (!win
->HasVMT()) return FALSE
;
159 if (g_blockEventsOnDrag
) return TRUE
;
160 if (g_blockEventsOnScroll
) return TRUE
;
162 if (!win
->m_isDragging
) return TRUE
;
164 if (gdk_event
->is_hint
)
168 GdkModifierType state
;
169 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
172 gdk_event
->state
= state
;
175 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
176 win
->m_oldX
= (int)gdk_event
->x
- win
->m_diffX
;
177 win
->m_oldY
= (int)gdk_event
->y
- win
->m_diffY
;
178 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
183 //-----------------------------------------------------------------------------
184 // "clicked" of X system button
185 //-----------------------------------------------------------------------------
187 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxMiniFrame
*mf
)
192 //-----------------------------------------------------------------------------
194 //-----------------------------------------------------------------------------
196 IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame
,wxFrame
)
198 bool wxMiniFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
199 const wxPoint
&pos
, const wxSize
&size
,
200 long style
, const wxString
&name
)
202 style
= style
| wxSIMPLE_BORDER
;
206 m_isDragging
= FALSE
;
212 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
214 GtkWidget
*close_button
= gtk_button_new_with_label( "x" );
216 gtk_myfixed_put( GTK_MYFIXED(m_mainWidget
), close_button
, 4, 4 );
217 gtk_widget_set_usize( close_button
, 12, 11 );
219 gtk_widget_show( close_button
);
221 gtk_signal_connect( GTK_OBJECT(close_button
), "clicked",
222 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
224 /* these are called when the borders are drawn */
225 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "expose_event",
226 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
228 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "draw",
229 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
231 /* these are required for dragging the mini frame around */
232 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_press_event",
233 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
235 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_release_event",
236 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
238 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "motion_notify_event",
239 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );