]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/minifram.cpp
pasting text from xterm works, finally
[wxWidgets.git] / src / gtk1 / minifram.cpp
CommitLineData
b2b3ccc5
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: minifram.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "minifram.h"
12#endif
13
14#include "wx/minifram.h"
dcf924a3
RR
15
16#if wxUSE_MINIFRAME
17
b2b3ccc5
RR
18#include "wx/dcscreen.h"
19
83624f79
RR
20#include "gtk/gtk.h"
21#include "wx/gtk/win_gtk.h"
22
32a95f9f
RR
23#include "gdk/gdk.h"
24#include "gdk/gdkprivate.h"
25#include "gdk/gdkx.h"
26
acfd422a
RR
27//-----------------------------------------------------------------------------
28// idle system
29//-----------------------------------------------------------------------------
30
31extern void wxapp_install_idle_handler();
32extern bool g_isIdle;
33
32a95f9f
RR
34//-----------------------------------------------------------------------------
35// data
36//-----------------------------------------------------------------------------
37
38extern bool g_blockEventsOnDrag;
39extern bool g_blockEventsOnScroll;
40
b2b3ccc5 41//-----------------------------------------------------------------------------
32a95f9f
RR
42// local functions
43//-----------------------------------------------------------------------------
44
45/* draw XOR rectangle when moving mine frame around */
46
47static void DrawFrame( GtkWidget *widget, int x, int y, int w, int h )
48{
49 int org_x = 0;
50 int org_y = 0;
51 gdk_window_get_origin( widget->window, &org_x, &org_y );
52 x += org_x;
53 y += org_y;
54
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 );
58
59 gdk_draw_rectangle( GDK_ROOT_PARENT(), gc, FALSE, x, y, w, h );
60 gdk_gc_unref( gc );
61}
62
63//-----------------------------------------------------------------------------
64// "expose_event" of m_mainWidget
65//-----------------------------------------------------------------------------
66
67static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *gdk_event, wxFrame *win )
68{
acfd422a
RR
69 if (g_isIdle) wxapp_install_idle_handler();
70
a2053b27 71 if (!win->m_hasVMT) return;
32a95f9f
RR
72 if (gdk_event->count > 0) return;
73
da048e3d 74 GtkPizza *pizza = GTK_PIZZA(widget);
54517652 75
32a95f9f 76 gtk_draw_shadow( widget->style,
da048e3d 77 pizza->bin_window,
f03fc89f
VZ
78 GTK_STATE_NORMAL,
79 GTK_SHADOW_OUT,
80 0, 0,
a2053b27 81 win->m_width, win->m_height );
b9a535f5
RR
82
83 if (!win->m_title.IsEmpty() &&
f03fc89f
VZ
84 ((win->GetWindowStyle() & wxCAPTION) ||
85 (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) ||
86 (win->GetWindowStyle() & wxTINY_CAPTION_VERT)))
b9a535f5 87 {
da048e3d 88 GdkGC *gc = gdk_gc_new( pizza->bin_window );
f03fc89f
VZ
89 GdkFont *font = wxSMALL_FONT->GetInternalFont(1.0);
90 int x = 2;
91 if (win->GetWindowStyle() & wxSYSTEM_MENU) x = 18;
92
b9a535f5 93 gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] );
da048e3d 94 gdk_draw_rectangle( pizza->bin_window, gc, TRUE,
f03fc89f
VZ
95 x,
96 3,
a2053b27 97 win->m_width - 4 - x,
f03fc89f
VZ
98 font->ascent + font->descent+1 );
99
b9a535f5 100 gdk_gc_set_foreground( gc, &widget->style->white );
da048e3d 101 gdk_draw_string( pizza->bin_window, font, gc,
f03fc89f
VZ
102 x+2,
103 3+font->ascent,
104 win->m_title.mb_str() );
105
b9a535f5
RR
106 gdk_gc_unref( gc );
107 }
32a95f9f
RR
108}
109
110//-----------------------------------------------------------------------------
111// "draw" of m_mainWidget
112//-----------------------------------------------------------------------------
113
114static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNUSED(rect), wxFrame *win )
115{
acfd422a
RR
116 if (g_isIdle) wxapp_install_idle_handler();
117
a2053b27 118 if (!win->m_hasVMT) return;
32a95f9f 119
da048e3d 120 GtkPizza *pizza = GTK_PIZZA(widget);
54517652 121
32a95f9f 122 gtk_draw_shadow( widget->style,
da048e3d 123 pizza->bin_window,
f03fc89f
VZ
124 GTK_STATE_NORMAL,
125 GTK_SHADOW_OUT,
126 0, 0,
a2053b27 127 win->m_width, win->m_height );
f03fc89f 128
b9a535f5 129 if (!win->m_title.IsEmpty() &&
f03fc89f
VZ
130 ((win->GetWindowStyle() & wxCAPTION) ||
131 (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) ||
132 (win->GetWindowStyle() & wxTINY_CAPTION_VERT)))
b9a535f5 133 {
da048e3d 134 GdkGC *gc = gdk_gc_new( pizza->bin_window );
f03fc89f
VZ
135 GdkFont *font = wxSMALL_FONT->GetInternalFont(1.0);
136 int x = 2;
137 if (win->GetWindowStyle() & wxSYSTEM_MENU) x = 17;
138
b9a535f5 139 gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] );
da048e3d 140 gdk_draw_rectangle( pizza->bin_window, gc, TRUE,
f03fc89f
VZ
141 x,
142 3,
a2053b27 143 win->m_width - 4 - x,
f03fc89f
VZ
144 font->ascent + font->descent+1 );
145
b9a535f5 146 gdk_gc_set_foreground( gc, &widget->style->white );
da048e3d 147 gdk_draw_string( pizza->bin_window, font, gc,
f03fc89f
VZ
148 x+2,
149 3+font->ascent,
150 win->m_title.mb_str() );
151
b9a535f5
RR
152 gdk_gc_unref( gc );
153 }
32a95f9f
RR
154}
155
156//-----------------------------------------------------------------------------
157// "button_press_event" of m_mainWidget
158//-----------------------------------------------------------------------------
159
160static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win )
161{
acfd422a
RR
162 if (g_isIdle) wxapp_install_idle_handler();
163
a2053b27 164 if (!win->m_hasVMT) return FALSE;
32a95f9f
RR
165 if (g_blockEventsOnDrag) return TRUE;
166 if (g_blockEventsOnScroll) return TRUE;
167
168 if (win->m_isDragging) return TRUE;
169
4dcaf11a
RR
170 gdk_window_raise( win->m_widget->window );
171
32a95f9f
RR
172 gdk_pointer_grab( widget->window, FALSE,
173 (GdkEventMask)
174 (GDK_BUTTON_PRESS_MASK |
175 GDK_BUTTON_RELEASE_MASK |
f03fc89f 176 GDK_POINTER_MOTION_MASK |
32a95f9f 177 GDK_POINTER_MOTION_HINT_MASK |
f03fc89f 178 GDK_BUTTON_MOTION_MASK |
32a95f9f
RR
179 GDK_BUTTON1_MOTION_MASK),
180 (GdkWindow *) NULL,
181 (GdkCursor *) NULL,
182 GDK_CURRENT_TIME );
f03fc89f 183
32a95f9f
RR
184 win->m_diffX = (int)gdk_event->x;
185 win->m_diffY = (int)gdk_event->y;
a2053b27 186 DrawFrame( widget, 0, 0, win->m_width, win->m_height );
32a95f9f
RR
187 win->m_oldX = 0;
188 win->m_oldY = 0;
189
190 win->m_isDragging = TRUE;
191
192 return TRUE;
193}
194
195//-----------------------------------------------------------------------------
196// "button_release_event" of m_mainWidget
197//-----------------------------------------------------------------------------
198
199static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win )
200{
acfd422a
RR
201 if (g_isIdle) wxapp_install_idle_handler();
202
a2053b27 203 if (!win->m_hasVMT) return FALSE;
32a95f9f
RR
204 if (g_blockEventsOnDrag) return TRUE;
205 if (g_blockEventsOnScroll) return TRUE;
206
207 if (!win->m_isDragging) return TRUE;
208
209 win->m_isDragging = FALSE;
210
211 int x = (int)gdk_event->x;
212 int y = (int)gdk_event->y;
213
a2053b27 214 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
32a95f9f
RR
215 gdk_pointer_ungrab ( GDK_CURRENT_TIME );
216 int org_x = 0;
217 int org_y = 0;
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;
121a3581
RR
221 win->m_x = x;
222 win->m_y = y;
a2053b27 223 gtk_widget_set_uposition( win->m_widget, x, y );
32a95f9f
RR
224
225 return TRUE;
226}
227
228//-----------------------------------------------------------------------------
229// "motion_notify_event" of m_mainWidget
230//-----------------------------------------------------------------------------
231
232static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxMiniFrame *win )
233{
acfd422a
RR
234 if (g_isIdle) wxapp_install_idle_handler();
235
a2053b27 236 if (!win->m_hasVMT) return FALSE;
32a95f9f
RR
237 if (g_blockEventsOnDrag) return TRUE;
238 if (g_blockEventsOnScroll) return TRUE;
239
240 if (!win->m_isDragging) return TRUE;
241
242 if (gdk_event->is_hint)
243 {
244 int x = 0;
245 int y = 0;
246 GdkModifierType state;
247 gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
248 gdk_event->x = x;
249 gdk_event->y = y;
250 gdk_event->state = state;
251 }
252
a2053b27 253 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
32a95f9f
RR
254 win->m_oldX = (int)gdk_event->x - win->m_diffX;
255 win->m_oldY = (int)gdk_event->y - win->m_diffY;
a2053b27 256 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
32a95f9f
RR
257
258 return TRUE;
259}
260
261//-----------------------------------------------------------------------------
262// "clicked" of X system button
b2b3ccc5
RR
263//-----------------------------------------------------------------------------
264
265static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxMiniFrame *mf )
266{
acfd422a
RR
267 if (g_isIdle) wxapp_install_idle_handler();
268
b2b3ccc5
RR
269 mf->Close();
270}
271
272//-----------------------------------------------------------------------------
273// wxMiniFrame
274//-----------------------------------------------------------------------------
275
b2b3ccc5
RR
276IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame,wxFrame)
277
278bool wxMiniFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
279 const wxPoint &pos, const wxSize &size,
280 long style, const wxString &name )
281{
282 style = style | wxSIMPLE_BORDER;
3017f78d 283 style = style | wxCAPTION;
b9a535f5
RR
284
285 if ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT))
286 m_miniTitle = 13;
f03fc89f 287
b2b3ccc5 288 m_miniEdge = 3;
b2b3ccc5
RR
289 m_isDragging = FALSE;
290 m_oldX = -1;
291 m_oldY = -1;
292 m_diffX = 0;
293 m_diffY = 0;
294
295 wxFrame::Create( parent, id, title, pos, size, style, name );
296
b9a535f5
RR
297 if ((style & wxSYSTEM_MENU) &&
298 ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT)))
299 {
300 GtkWidget *close_button = gtk_button_new_with_label( "x" );
b2b3ccc5 301
da048e3d 302 gtk_pizza_put( GTK_PIZZA(m_mainWidget),
f03fc89f
VZ
303 close_button,
304 4, 4, 12, 11 );
b2b3ccc5 305
b9a535f5 306 gtk_widget_show( close_button );
b2b3ccc5 307
b9a535f5
RR
308 gtk_signal_connect( GTK_OBJECT(close_button), "clicked",
309 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
310 }
b2b3ccc5 311
32a95f9f
RR
312 /* these are called when the borders are drawn */
313 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "expose_event",
314 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this );
b2b3ccc5 315
32a95f9f
RR
316 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "draw",
317 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this );
318
319 /* these are required for dragging the mini frame around */
320 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_press_event",
321 GTK_SIGNAL_FUNC(gtk_window_button_press_callback), (gpointer)this );
b2b3ccc5 322
32a95f9f
RR
323 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_release_event",
324 GTK_SIGNAL_FUNC(gtk_window_button_release_callback), (gpointer)this );
b2b3ccc5 325
32a95f9f
RR
326 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "motion_notify_event",
327 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback), (gpointer)this );
b2b3ccc5 328
32a95f9f 329 return TRUE;
b2b3ccc5 330}
dcf924a3
RR
331
332#endif