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"
22 #include "wx/gtk/private.h"
25 #include <gdk/gdkprivate.h>
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 extern void wxapp_install_idle_handler();
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 extern bool g_blockEventsOnDrag
;
40 extern bool g_blockEventsOnScroll
;
41 extern GtkWidget
*wxGetRootWindow();
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
47 /* draw XOR rectangle when moving mine frame around */
49 static void DrawFrame( GtkWidget
*widget
, int x
, int y
, int w
, int h
)
53 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
57 GdkGC
*gc
= gdk_gc_new( GDK_ROOT_PARENT() );
58 gdk_gc_set_subwindow( gc
, GDK_INCLUDE_INFERIORS
);
59 gdk_gc_set_function( gc
, GDK_INVERT
);
61 gdk_draw_rectangle( GDK_ROOT_PARENT(), gc
, FALSE
, x
, y
, w
, h
);
65 //-----------------------------------------------------------------------------
66 // "expose_event" of m_mainWidget
67 //-----------------------------------------------------------------------------
69 static void gtk_window_own_expose_callback( GtkWidget
*widget
, GdkEventExpose
*gdk_event
, wxFrame
*win
)
71 if (g_isIdle
) wxapp_install_idle_handler();
73 if (!win
->m_hasVMT
) return;
74 if (gdk_event
->count
> 0) return;
76 GtkPizza
*pizza
= GTK_PIZZA(widget
);
78 gtk_draw_shadow( widget
->style
,
83 win
->m_width
, win
->m_height
);
85 if (!win
->GetTitle().IsEmpty() &&
86 ((win
->GetWindowStyle() & wxCAPTION
) ||
87 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
88 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
91 dc
.SetFont( *wxSMALL_FONT
);
92 int height
= dc
.GetCharHeight();
94 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
95 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
96 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
104 dc
.m_window
= pizza
->bin_window
;
105 dc
.SetTextForeground( *wxWHITE
);
106 dc
.DrawText( win
->GetTitle(), 6, 3 );
110 //-----------------------------------------------------------------------------
111 // "draw" of m_mainWidget
112 //-----------------------------------------------------------------------------
115 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxFrame
*win
)
117 if (g_isIdle
) wxapp_install_idle_handler();
119 if (!win
->m_hasVMT
) return;
121 GtkPizza
*pizza
= GTK_PIZZA(widget
);
123 gtk_draw_shadow( widget
->style
,
128 win
->m_width
, win
->m_height
);
130 if (!win
->m_title
.IsEmpty() &&
131 ((win
->GetWindowStyle() & wxCAPTION
) ||
132 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
133 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
136 dc
.SetFont( *wxSMALL_FONT
);
137 int height
= dc
.GetCharHeight();
139 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
140 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
141 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
149 dc
.m_window
= pizza
->bin_window
;
150 dc
.SetTextForeground( *wxWHITE
);
151 dc
.DrawText( win
->GetTitle(), 6, 3 );
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 GtkPizza
*pizza
= GTK_PIZZA(widget
);
171 if (gdk_event
->window
!= pizza
->bin_window
) return TRUE
;
174 dc
.SetFont( *wxSMALL_FONT
);
175 int height
= dc
.GetCharHeight() + 1;
177 if (gdk_event
->y
> height
) return TRUE
;
179 gdk_window_raise( win
->m_widget
->window
);
181 gdk_pointer_grab( widget
->window
, FALSE
,
183 (GDK_BUTTON_PRESS_MASK
|
184 GDK_BUTTON_RELEASE_MASK
|
185 GDK_POINTER_MOTION_MASK
|
186 GDK_POINTER_MOTION_HINT_MASK
|
187 GDK_BUTTON_MOTION_MASK
|
188 GDK_BUTTON1_MOTION_MASK
),
191 (unsigned int) GDK_CURRENT_TIME
);
193 win
->m_diffX
= (int)gdk_event
->x
;
194 win
->m_diffY
= (int)gdk_event
->y
;
195 DrawFrame( widget
, 0, 0, win
->m_width
, win
->m_height
);
199 win
->m_isDragging
= TRUE
;
204 //-----------------------------------------------------------------------------
205 // "button_release_event" of m_mainWidget
206 //-----------------------------------------------------------------------------
208 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
210 if (g_isIdle
) wxapp_install_idle_handler();
212 if (!win
->m_hasVMT
) return FALSE
;
213 if (g_blockEventsOnDrag
) return TRUE
;
214 if (g_blockEventsOnScroll
) return TRUE
;
216 if (!win
->m_isDragging
) return TRUE
;
218 win
->m_isDragging
= FALSE
;
220 int x
= (int)gdk_event
->x
;
221 int y
= (int)gdk_event
->y
;
223 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
224 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
227 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
228 x
+= org_x
- win
->m_diffX
;
229 y
+= org_y
- win
->m_diffY
;
232 gtk_widget_set_uposition( win
->m_widget
, x
, y
);
237 //-----------------------------------------------------------------------------
238 // "motion_notify_event" of m_mainWidget
239 //-----------------------------------------------------------------------------
241 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxMiniFrame
*win
)
243 if (g_isIdle
) wxapp_install_idle_handler();
245 if (!win
->m_hasVMT
) return FALSE
;
246 if (g_blockEventsOnDrag
) return TRUE
;
247 if (g_blockEventsOnScroll
) return TRUE
;
249 if (!win
->m_isDragging
) return TRUE
;
251 if (gdk_event
->is_hint
)
255 GdkModifierType state
;
256 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
259 gdk_event
->state
= state
;
262 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
263 win
->m_oldX
= (int)gdk_event
->x
- win
->m_diffX
;
264 win
->m_oldY
= (int)gdk_event
->y
- win
->m_diffY
;
265 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
270 //-----------------------------------------------------------------------------
271 // "clicked" of X system button
272 //-----------------------------------------------------------------------------
274 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxMiniFrame
*mf
)
276 if (g_isIdle
) wxapp_install_idle_handler();
281 //-----------------------------------------------------------------------------
283 //-----------------------------------------------------------------------------
285 static const char *cross_xpm
[] = {
286 /* columns rows colors chars-per-pixel */
312 IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame
,wxFrame
)
314 bool wxMiniFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
315 const wxPoint
&pos
, const wxSize
&size
,
316 long style
, const wxString
&name
)
318 style
= style
| wxCAPTION
;
320 if ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
))
324 m_isDragging
= FALSE
;
330 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
332 if (m_parent
&& (GTK_IS_WINDOW(m_parent
->m_widget
)))
334 gtk_window_set_transient_for( GTK_WINDOW(m_widget
), GTK_WINDOW(m_parent
->m_widget
) );
337 if ((style
& wxSYSTEM_MENU
) &&
338 ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
)))
340 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
341 GdkPixmap
*pixmap
= gdk_pixmap_create_from_xpm_d
343 wxGetRootWindow()->window
,
349 GtkWidget
*pw
= gtk_pixmap_new( pixmap
, mask
);
350 gdk_bitmap_unref( mask
);
351 gdk_pixmap_unref( pixmap
);
352 gtk_widget_show( pw
);
354 GtkWidget
*close_button
= gtk_button_new();
355 gtk_container_add( GTK_CONTAINER(close_button
), pw
);
357 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
359 size
.x
-16, 4, 11, 11 );
361 gtk_widget_show( close_button
);
363 gtk_signal_connect( GTK_OBJECT(close_button
), "clicked",
364 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
367 /* these are called when the borders are drawn */
368 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "expose_event",
369 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
372 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "draw",
373 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
376 /* these are required for dragging the mini frame around */
377 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_press_event",
378 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
380 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_release_event",
381 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
383 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "motion_notify_event",
384 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );