// Name: window.cpp
// Purpose:
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling, Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/msgdlg.h"
#include "wx/dcclient.h"
#include "wx/dnd.h"
-#include "wx/mdi.h"
#include "wx/menu.h"
-#include "wx/notebook.h"
#include "wx/statusbr.h"
#include "wx/intl.h"
-#include "wx/gtk/win_gtk.h"
#include "gdk/gdkprivate.h"
#include "gdk/gdkkeysyms.h"
static void gtk_window_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExpose *gdk_event, wxWindow *win )
{
- if (!win->HasVMT()) return;
- if (g_blockEventsOnDrag) return;
+ if (!win->HasVMT()) return;
+ if (g_blockEventsOnDrag) return;
- win->m_updateRegion.Union( gdk_event->area.x,
- gdk_event->area.y,
- gdk_event->area.width,
- gdk_event->area.height );
+ win->m_updateRegion.Union( gdk_event->area.x,
+ gdk_event->area.y,
+ gdk_event->area.width,
+ gdk_event->area.height );
- if (gdk_event->count > 0) return;
+ if (gdk_event->count > 0) return;
/*
- printf( "OnExpose from " );
- if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
- printf( win->GetClassInfo()->GetClassName() );
- printf( ".\n" );
+ printf( "OnExpose from " );
+ if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
+ printf( win->GetClassInfo()->GetClassName() );
+ printf( ".\n" );
*/
- wxPaintEvent event( win->GetId() );
- event.SetEventObject( win );
- win->GetEventHandler()->ProcessEvent( event );
+ wxPaintEvent event( win->GetId() );
+ event.SetEventObject( win );
+ win->GetEventHandler()->ProcessEvent( event );
- win->m_updateRegion.Clear();
+ win->m_updateRegion.Clear();
}
//-----------------------------------------------------------------------------
static void gtk_window_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxWindow *win )
{
- if (!win->HasVMT()) return;
- if (g_blockEventsOnDrag) return;
+ if (!win->HasVMT()) return;
+ if (g_blockEventsOnDrag) return;
- win->m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height );
+ win->m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height );
- wxPaintEvent event( win->GetId() );
- event.SetEventObject( win );
- win->GetEventHandler()->ProcessEvent( event );
+ wxPaintEvent event( win->GetId() );
+ event.SetEventObject( win );
+ win->GetEventHandler()->ProcessEvent( event );
- win->m_updateRegion.Clear();
+ win->m_updateRegion.Clear();
}
//-----------------------------------------------------------------------------
static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxWindow *win )
{
- if (!win->HasVMT()) return FALSE;
- if (g_blockEventsOnDrag) return FALSE;
+ if (!win->HasVMT()) return FALSE;
+ if (g_blockEventsOnDrag) return FALSE;
/*
- printf( "OnKeyPress from " );
- if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
- printf( win->GetClassInfo()->GetClassName() );
- printf( ".\n" );
+ printf( "OnKeyPress from " );
+ if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
+ printf( win->GetClassInfo()->GetClassName() );
+ printf( ".\n" );
*/
- long key_code = 0;
- switch (gdk_event->keyval)
- {
- case GDK_BackSpace: key_code = WXK_BACK; break;
- case GDK_Tab: key_code = WXK_TAB; break;
- case GDK_Linefeed: key_code = WXK_RETURN; break;
- case GDK_Clear: key_code = WXK_CLEAR; break;
- case GDK_Return: key_code = WXK_RETURN; break;
- case GDK_Pause: key_code = WXK_PAUSE; break;
- case GDK_Scroll_Lock: key_code = WXK_SCROLL; break;
- case GDK_Escape: key_code = WXK_ESCAPE; break;
- case GDK_Delete: key_code = WXK_DELETE; break;
- case GDK_Home: key_code = WXK_HOME; break;
- case GDK_Left: key_code = WXK_LEFT; break;
- case GDK_Up: key_code = WXK_UP; break;
- case GDK_Right: key_code = WXK_RIGHT; break;
- case GDK_Down: key_code = WXK_DOWN; break;
- case GDK_Prior: key_code = WXK_PRIOR; break;
-// case GDK_Page_Up: key_code = WXK_PAGEUP; break;
- case GDK_Next: key_code = WXK_NEXT; break;
-// case GDK_Page_Down: key_code = WXK_PAGEDOWN; break;
- case GDK_End: key_code = WXK_END; break;
- case GDK_Begin: key_code = WXK_HOME; break;
- case GDK_Select: key_code = WXK_SELECT; break;
- case GDK_Print: key_code = WXK_PRINT; break;
- case GDK_Execute: key_code = WXK_EXECUTE; break;
- case GDK_Insert: key_code = WXK_INSERT; break;
- case GDK_Num_Lock: key_code = WXK_NUMLOCK; break;
- case GDK_KP_Tab: key_code = WXK_TAB; break;
- case GDK_KP_Enter: key_code = WXK_RETURN; break;
- case GDK_KP_Home: key_code = WXK_HOME; break;
- case GDK_KP_Left: key_code = WXK_LEFT; break;
- case GDK_KP_Up: key_code = WXK_UP; break;
- case GDK_KP_Right: key_code = WXK_RIGHT; break;
- case GDK_KP_Down: key_code = WXK_DOWN; break;
- case GDK_KP_Prior: key_code = WXK_PRIOR; break;
-// case GDK_KP_Page_Up: key_code = WXK_PAGEUP; break;
- case GDK_KP_Next: key_code = WXK_NEXT; break;
-// case GDK_KP_Page_Down: key_code = WXK_PAGEDOWN; break;
- case GDK_KP_End: key_code = WXK_END; break;
- case GDK_KP_Begin: key_code = WXK_HOME; break;
- case GDK_KP_Insert: key_code = WXK_INSERT; break;
- case GDK_KP_Delete: key_code = WXK_DELETE; break;
- case GDK_KP_Multiply: key_code = WXK_MULTIPLY; break;
- case GDK_KP_Add: key_code = WXK_ADD; break;
- case GDK_KP_Separator: key_code = WXK_SEPARATOR; break;
- case GDK_KP_Subtract: key_code = WXK_SUBTRACT; break;
- case GDK_KP_Decimal: key_code = WXK_DECIMAL; break;
- case GDK_KP_Divide: key_code = WXK_DIVIDE; break;
- case GDK_KP_0: key_code = WXK_NUMPAD0; break;
- case GDK_KP_1: key_code = WXK_NUMPAD1; break;
- case GDK_KP_2: key_code = WXK_NUMPAD2; break;
- case GDK_KP_3: key_code = WXK_NUMPAD3; break;
- case GDK_KP_4: key_code = WXK_NUMPAD4; break;
- case GDK_KP_5: key_code = WXK_NUMPAD5; break;
- case GDK_KP_6: key_code = WXK_NUMPAD6; break;
- case GDK_KP_7: key_code = WXK_NUMPAD7; break;
- case GDK_KP_8: key_code = WXK_NUMPAD7; break;
- case GDK_KP_9: key_code = WXK_NUMPAD9; break;
- case GDK_F1: key_code = WXK_F1; break;
- case GDK_F2: key_code = WXK_F2; break;
- case GDK_F3: key_code = WXK_F3; break;
- case GDK_F4: key_code = WXK_F4; break;
- case GDK_F5: key_code = WXK_F5; break;
- case GDK_F6: key_code = WXK_F6; break;
- case GDK_F7: key_code = WXK_F7; break;
- case GDK_F8: key_code = WXK_F8; break;
- case GDK_F9: key_code = WXK_F9; break;
- case GDK_F10: key_code = WXK_F10; break;
- case GDK_F11: key_code = WXK_F11; break;
- case GDK_F12: key_code = WXK_F12; break;
- default:
+ long key_code = 0;
+ switch (gdk_event->keyval)
{
- if ((gdk_event->keyval >= 0x20) && (gdk_event->keyval <= 0xFF))
- key_code = gdk_event->keyval;
+ case GDK_BackSpace: key_code = WXK_BACK; break;
+ case GDK_Tab: key_code = WXK_TAB; break;
+ case GDK_Linefeed: key_code = WXK_RETURN; break;
+ case GDK_Clear: key_code = WXK_CLEAR; break;
+ case GDK_Return: key_code = WXK_RETURN; break;
+ case GDK_Pause: key_code = WXK_PAUSE; break;
+ case GDK_Scroll_Lock: key_code = WXK_SCROLL; break;
+ case GDK_Escape: key_code = WXK_ESCAPE; break;
+ case GDK_Delete: key_code = WXK_DELETE; break;
+ case GDK_Home: key_code = WXK_HOME; break;
+ case GDK_Left: key_code = WXK_LEFT; break;
+ case GDK_Up: key_code = WXK_UP; break;
+ case GDK_Right: key_code = WXK_RIGHT; break;
+ case GDK_Down: key_code = WXK_DOWN; break;
+ case GDK_Prior: key_code = WXK_PRIOR; break;
+// case GDK_Page_Up: key_code = WXK_PAGEUP; break;
+ case GDK_Next: key_code = WXK_NEXT; break;
+// case GDK_Page_Down: key_code = WXK_PAGEDOWN; break;
+ case GDK_End: key_code = WXK_END; break;
+ case GDK_Begin: key_code = WXK_HOME; break;
+ case GDK_Select: key_code = WXK_SELECT; break;
+ case GDK_Print: key_code = WXK_PRINT; break;
+ case GDK_Execute: key_code = WXK_EXECUTE; break;
+ case GDK_Insert: key_code = WXK_INSERT; break;
+ case GDK_Num_Lock: key_code = WXK_NUMLOCK; break;
+ case GDK_KP_Tab: key_code = WXK_TAB; break;
+ case GDK_KP_Enter: key_code = WXK_RETURN; break;
+ case GDK_KP_Home: key_code = WXK_HOME; break;
+ case GDK_KP_Left: key_code = WXK_LEFT; break;
+ case GDK_KP_Up: key_code = WXK_UP; break;
+ case GDK_KP_Right: key_code = WXK_RIGHT; break;
+ case GDK_KP_Down: key_code = WXK_DOWN; break;
+ case GDK_KP_Prior: key_code = WXK_PRIOR; break;
+// case GDK_KP_Page_Up: key_code = WXK_PAGEUP; break;
+ case GDK_KP_Next: key_code = WXK_NEXT; break;
+// case GDK_KP_Page_Down: key_code = WXK_PAGEDOWN; break;
+ case GDK_KP_End: key_code = WXK_END; break;
+ case GDK_KP_Begin: key_code = WXK_HOME; break;
+ case GDK_KP_Insert: key_code = WXK_INSERT; break;
+ case GDK_KP_Delete: key_code = WXK_DELETE; break;
+ case GDK_KP_Multiply: key_code = WXK_MULTIPLY; break;
+ case GDK_KP_Add: key_code = WXK_ADD; break;
+ case GDK_KP_Separator: key_code = WXK_SEPARATOR; break;
+ case GDK_KP_Subtract: key_code = WXK_SUBTRACT; break;
+ case GDK_KP_Decimal: key_code = WXK_DECIMAL; break;
+ case GDK_KP_Divide: key_code = WXK_DIVIDE; break;
+ case GDK_KP_0: key_code = WXK_NUMPAD0; break;
+ case GDK_KP_1: key_code = WXK_NUMPAD1; break;
+ case GDK_KP_2: key_code = WXK_NUMPAD2; break;
+ case GDK_KP_3: key_code = WXK_NUMPAD3; break;
+ case GDK_KP_4: key_code = WXK_NUMPAD4; break;
+ case GDK_KP_5: key_code = WXK_NUMPAD5; break;
+ case GDK_KP_6: key_code = WXK_NUMPAD6; break;
+ case GDK_KP_7: key_code = WXK_NUMPAD7; break;
+ case GDK_KP_8: key_code = WXK_NUMPAD7; break;
+ case GDK_KP_9: key_code = WXK_NUMPAD9; break;
+ case GDK_F1: key_code = WXK_F1; break;
+ case GDK_F2: key_code = WXK_F2; break;
+ case GDK_F3: key_code = WXK_F3; break;
+ case GDK_F4: key_code = WXK_F4; break;
+ case GDK_F5: key_code = WXK_F5; break;
+ case GDK_F6: key_code = WXK_F6; break;
+ case GDK_F7: key_code = WXK_F7; break;
+ case GDK_F8: key_code = WXK_F8; break;
+ case GDK_F9: key_code = WXK_F9; break;
+ case GDK_F10: key_code = WXK_F10; break;
+ case GDK_F11: key_code = WXK_F11; break;
+ case GDK_F12: key_code = WXK_F12; break;
+ default:
+ {
+ if ((gdk_event->keyval >= 0x20) && (gdk_event->keyval <= 0xFF))
+ key_code = gdk_event->keyval;
+ }
}
- }
- if (!key_code) return FALSE;
+ if (!key_code) return FALSE;
- wxKeyEvent event( wxEVT_CHAR );
- event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
- event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
- event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
- event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
- event.m_keyCode = key_code;
- event.m_x = 0;
- event.m_y = 0;
- event.SetEventObject( win );
+ wxKeyEvent event( wxEVT_CHAR );
+ event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
+ event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
+ event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
+ event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
+ event.m_keyCode = key_code;
+ event.m_x = 0;
+ event.m_y = 0;
+ event.SetEventObject( win );
- bool ret = win->GetEventHandler()->ProcessEvent( event );
+ bool ret = win->GetEventHandler()->ProcessEvent( event );
- if (!ret)
- {
- wxWindow *ancestor = win;
- while (ancestor)
+ if (!ret)
{
- int command = ancestor->GetAcceleratorTable()->GetCommand( event );
- if (command != -1)
- {
- wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
- ret = ancestor->GetEventHandler()->ProcessEvent( command_event );
- break;
- }
- ancestor = ancestor->GetParent();
+ wxWindow *ancestor = win;
+ while (ancestor)
+ {
+ int command = ancestor->GetAcceleratorTable()->GetCommand( event );
+ if (command != -1)
+ {
+ wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
+ ret = ancestor->GetEventHandler()->ProcessEvent( command_event );
+ break;
+ }
+ ancestor = ancestor->GetParent();
+ }
}
- }
- if (ret)
- {
- if ((gdk_event->keyval >= 0x20) && (gdk_event->keyval <= 0xFF))
- gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
- }
+ if (ret)
+ {
+ if ((gdk_event->keyval >= 0x20) && (gdk_event->keyval <= 0xFF))
+ gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
+ }
- return ret;
+ return ret;
}
//-----------------------------------------------------------------------------
static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win )
{
- if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE;
+ if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE;
- if (g_blockEventsOnDrag) return TRUE;
+ if (g_blockEventsOnDrag) return TRUE;
- if (win->m_wxwindow)
- {
- if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow) && !GTK_WIDGET_HAS_FOCUS (win->m_wxwindow) )
+ if (win->m_wxwindow)
{
- gtk_widget_grab_focus (win->m_wxwindow);
+ if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow) && !GTK_WIDGET_HAS_FOCUS (win->m_wxwindow) )
+ {
+ gtk_widget_grab_focus (win->m_wxwindow);
/*
- printf( "GrabFocus from " );
- if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
- printf( win->GetClassInfo()->GetClassName() );
- printf( ".\n" );
+ printf( "GrabFocus from " );
+ if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
+ printf( win->GetClassInfo()->GetClassName() );
+ printf( ".\n" );
*/
+ }
}
- }
- if (!win->HasVMT()) return TRUE;
+ if (!win->HasVMT()) return TRUE;
/*
- printf( "OnButtonPress from " );
- if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
- printf( win->GetClassInfo()->GetClassName() );
- printf( ".\n" );
+ printf( "OnButtonPress from " );
+ if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
+ printf( win->GetClassInfo()->GetClassName() );
+ printf( ".\n" );
*/
- wxEventType event_type = wxEVT_LEFT_DOWN;
+ wxEventType event_type = wxEVT_LEFT_DOWN;
- if (gdk_event->button == 1)
- {
- switch (gdk_event->type)
+ if (gdk_event->button == 1)
{
- case GDK_BUTTON_PRESS: event_type = wxEVT_LEFT_DOWN; break;
- case GDK_2BUTTON_PRESS: event_type = wxEVT_LEFT_DCLICK; break;
- default: break;
+ switch (gdk_event->type)
+ {
+ case GDK_BUTTON_PRESS: event_type = wxEVT_LEFT_DOWN; break;
+ case GDK_2BUTTON_PRESS: event_type = wxEVT_LEFT_DCLICK; break;
+ default: break;
+ }
}
- }
- else if (gdk_event->button == 2)
- {
- switch (gdk_event->type)
+ else if (gdk_event->button == 2)
{
- case GDK_BUTTON_PRESS: event_type = wxEVT_MIDDLE_DOWN; break;
- case GDK_2BUTTON_PRESS: event_type = wxEVT_MIDDLE_DCLICK; break;
- default: break;
+ switch (gdk_event->type)
+ {
+ case GDK_BUTTON_PRESS: event_type = wxEVT_MIDDLE_DOWN; break;
+ case GDK_2BUTTON_PRESS: event_type = wxEVT_MIDDLE_DCLICK; break;
+ default: break;
+ }
}
- }
- else if (gdk_event->button == 3)
- {
- switch (gdk_event->type)
+ else if (gdk_event->button == 3)
{
- case GDK_BUTTON_PRESS: event_type = wxEVT_RIGHT_DOWN; break;
- case GDK_2BUTTON_PRESS: event_type = wxEVT_RIGHT_DCLICK; break;
- default: break;
+ switch (gdk_event->type)
+ {
+ case GDK_BUTTON_PRESS: event_type = wxEVT_RIGHT_DOWN; break;
+ case GDK_2BUTTON_PRESS: event_type = wxEVT_RIGHT_DCLICK; break;
+ default: break;
+ }
}
- }
- wxMouseEvent event( event_type );
- event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
- event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
- event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
- event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
- event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK);
- event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK);
- event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK);
+ wxMouseEvent event( event_type );
+ event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
+ event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
+ event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
+ event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
+ event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK);
+ event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK);
+ event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK);
- event.m_x = (long)gdk_event->x;
- event.m_y = (long)gdk_event->y;
+ event.m_x = (long)gdk_event->x;
+ event.m_y = (long)gdk_event->y;
- // Some control don't have their own X window and thus cannot get
- // any events.
+ // Some control don't have their own X window and thus cannot get
+ // any events.
- if (!g_capturing)
- {
- wxNode *node = win->GetChildren()->First();
- while (node)
+ if (!g_capturing)
{
- wxWindow *child = (wxWindow*)node->Data();
- if ((child->m_x <= event.m_x) &&
- (child->m_y <= event.m_y) &&
- (child->m_x+child->m_width >= event.m_x) &&
- (child->m_y+child->m_height >= event.m_y))
- {
- win = child;
- event.m_x -= child->m_x;
- event.m_y -= child->m_y;
- break;
- }
- node = node->Next();
+ wxNode *node = win->GetChildren()->First();
+ while (node)
+ {
+ wxWindow *child = (wxWindow*)node->Data();
+ if ((child->m_x <= event.m_x) &&
+ (child->m_y <= event.m_y) &&
+ (child->m_x+child->m_width >= event.m_x) &&
+ (child->m_y+child->m_height >= event.m_y))
+ {
+ win = child;
+ event.m_x -= child->m_x;
+ event.m_y -= child->m_y;
+ break;
+ }
+ node = node->Next();
+ }
}
- }
- event.SetEventObject( win );
+ event.SetEventObject( win );
- gs_timeLastClick = gdk_event->time;
+ gs_timeLastClick = gdk_event->time;
- if (win->GetEventHandler()->ProcessEvent( event ))
- gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_press_event" );
+ if (win->GetEventHandler()->ProcessEvent( event ))
+ gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_press_event" );
- return TRUE;
+ return TRUE;
}
//-----------------------------------------------------------------------------
static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win )
{
- if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE;
+ if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE;
- if (g_blockEventsOnDrag) return TRUE;
+ if (g_blockEventsOnDrag) return TRUE;
- if (!win->HasVMT()) return TRUE;
+ if (!win->HasVMT()) return TRUE;
/*
- printf( "OnButtonRelease from " );
- if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
- printf( win->GetClassInfo()->GetClassName() );
- printf( ".\n" );
+ printf( "OnButtonRelease from " );
+ if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
+ printf( win->GetClassInfo()->GetClassName() );
+ printf( ".\n" );
*/
- wxEventType event_type = wxEVT_NULL;
+ wxEventType event_type = wxEVT_NULL;
- switch (gdk_event->button)
- {
- case 1: event_type = wxEVT_LEFT_UP; break;
- case 2: event_type = wxEVT_MIDDLE_UP; break;
- case 3: event_type = wxEVT_RIGHT_UP; break;
- }
-
- wxMouseEvent event( event_type );
- event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
- event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
- event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
- event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
- event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK);
- event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK);
- event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK);
- event.m_x = (long)gdk_event->x;
- event.m_y = (long)gdk_event->y;
-
- // Some control don't have their own X window and thus cannot get
- // any events.
+ switch (gdk_event->button)
+ {
+ case 1: event_type = wxEVT_LEFT_UP; break;
+ case 2: event_type = wxEVT_MIDDLE_UP; break;
+ case 3: event_type = wxEVT_RIGHT_UP; break;
+ }
- if (!g_capturing)
- {
- wxNode *node = win->GetChildren()->First();
- while (node)
+ wxMouseEvent event( event_type );
+ event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
+ event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
+ event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
+ event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
+ event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK);
+ event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK);
+ event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK);
+ event.m_x = (long)gdk_event->x;
+ event.m_y = (long)gdk_event->y;
+
+ // Some control don't have their own X window and thus cannot get
+ // any events.
+
+ if (!g_capturing)
{
- wxWindow *child = (wxWindow*)node->Data();
- if ((child->m_x <= event.m_x) &&
- (child->m_y <= event.m_y) &&
- (child->m_x+child->m_width >= event.m_x) &&
- (child->m_y+child->m_height >= event.m_y))
- {
- win = child;
- event.m_x -= child->m_x;
- event.m_y -= child->m_y;
- break;
- }
- node = node->Next();
+ wxNode *node = win->GetChildren()->First();
+ while (node)
+ {
+ wxWindow *child = (wxWindow*)node->Data();
+ if ((child->m_x <= event.m_x) &&
+ (child->m_y <= event.m_y) &&
+ (child->m_x+child->m_width >= event.m_x) &&
+ (child->m_y+child->m_height >= event.m_y))
+ {
+ win = child;
+ event.m_x -= child->m_x;
+ event.m_y -= child->m_y;
+ break;
+ }
+ node = node->Next();
+ }
}
- }
- event.SetEventObject( win );
+ event.SetEventObject( win );
- if (win->GetEventHandler()->ProcessEvent( event ))
- gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_release_event" );
+ if (win->GetEventHandler()->ProcessEvent( event ))
+ gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_release_event" );
- return TRUE;
+ return TRUE;
}
//-----------------------------------------------------------------------------
// "drop_data_available_event"
//-----------------------------------------------------------------------------
-static void gtk_window_drop_callback( GtkWidget *widget, GdkEvent *event, wxWindow *win )
+static void gtk_window_drop_callback( GtkWidget *widget, GdkEventDropDataAvailable *event, wxWindow *win )
{
if (!win->HasVMT()) return;
int x = 0;
int y = 0;
gdk_window_get_pointer( widget->window, &x, &y, (GdkModifierType *) NULL );
- win->GetDropTarget()->Drop( event, x, y );
+
+ printf( "Drop data is of type %s.\n", event->data_type );
+
+ win->GetDropTarget()->OnDrop( x, y, (const void*)event->data, (size_t)event->data_numbytes );
}
/*
*/
}
+//-----------------------------------------------------------------------------
+// InsertChild for wxWindow.
+//-----------------------------------------------------------------------------
+
+// Callback for wxWindow. This very strange beast has to be used because
+// C++ has no virtual methods in a constructor. We have to emulate a
+// virtual function here as wxNotebook requires a different way to insert
+// a child in it. I had opted for creating a wxNotebookPage window class
+// which would have made this superflouus (such in the MDI window system),
+// but no-one is listening to me...
+
+static void wxInsertChildInWindow( wxWindow* parent, wxWindow* child )
+{
+ gtk_myfixed_put( GTK_MYFIXED(parent->m_wxwindow),
+ GTK_WIDGET(child->m_widget),
+ child->m_x,
+ child->m_y );
+
+ gtk_widget_set_usize( GTK_WIDGET(child->m_widget),
+ child->m_width,
+ child->m_height );
+}
+
//-----------------------------------------------------------------------------
// wxWindow
//-----------------------------------------------------------------------------
m_wxwindow = (GtkWidget *) NULL;
m_parent = (wxWindow *) NULL;
m_children.DeleteContents( FALSE );
+
m_x = 0;
m_y = 0;
m_width = 0;
m_minHeight = -1;
m_maxWidth = -1;
m_maxHeight = -1;
+
m_retCode = 0;
+
m_eventHandler = this;
m_windowValidator = (wxValidator *) NULL;
+
m_windowId = -1;
+
m_cursor = (wxCursor *) NULL;
m_font = *wxSWISS_FONT;
m_windowStyle = 0;
m_windowName = "noname";
+
m_constraints = (wxLayoutConstraints *) NULL;
m_constraintsInvolvedIn = (wxList *) NULL;
m_windowSizer = (wxSizer *) NULL;
m_sizerParent = (wxWindow *) NULL;
m_autoLayout = FALSE;
+
m_sizeSet = FALSE;
m_hasVMT = FALSE;
m_needParent = TRUE;
+
m_hasScrolling = FALSE;
m_isScrolling = FALSE;
- m_hAdjust = (GtkAdjustment *) NULL;
- m_vAdjust = (GtkAdjustment *) NULL;
+ m_hAdjust = (GtkAdjustment*) NULL;
+ m_vAdjust = (GtkAdjustment*) NULL;
m_oldHorizontalPos = 0.0;
m_oldVerticalPos = 0.0;
+
m_isShown = FALSE;
m_isEnabled = TRUE;
- m_pDropTarget = (wxDropTarget *) NULL;
+
+ m_dropTarget = (wxDropTarget*) NULL;
m_resizing = FALSE;
m_scrollGC = (GdkGC*) NULL;
m_widgetStyle = (GtkStyle*) NULL;
+
+ m_insertCallback = wxInsertChildInWindow;
+
+ m_clientObject = (wxClientData*) NULL;
+ m_clientData = NULL;
}
+wxWindow::wxWindow( wxWindow *parent, wxWindowID id,
+ const wxPoint &pos, const wxSize &size,
+ long style, const wxString &name )
+{
+ m_insertCallback = wxInsertChildInWindow;
+ Create( parent, id, pos, size, style, name );
+}
+
bool wxWindow::Create( wxWindow *parent, wxWindowID id,
const wxPoint &pos, const wxSize &size,
long style, const wxString &name )
m_isEnabled = TRUE;
m_needParent = TRUE;
- m_cursor = (wxCursor *) NULL;
-
PreCreation( parent, id, pos, size, style, name );
m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL );
gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );
gtk_widget_show( m_wxwindow );
+
+ if (m_parent) m_parent->AddChild( this );
+ (m_parent->m_insertCallback)( m_parent, this );
+
PostCreation();
Show( TRUE );
{
m_hasVMT = FALSE;
- if (m_pDropTarget) delete m_pDropTarget;
+ if (m_dropTarget) delete m_dropTarget;
if (m_parent) m_parent->RemoveChild( this );
if (m_widget) Show( FALSE );
wxTopLevelWindows.DeleteObject(this);
if (m_windowValidator) delete m_windowValidator;
+
+ if (m_clientObject) delete m_clientObject;
}
void wxWindow::PreCreation( wxWindow *parent, wxWindowID id,
{
if (m_needParent && (parent == NULL))
wxFatalError( "Need complete parent.", name );
-
- m_widget = (GtkWidget *) NULL;
+
+ m_widget = (GtkWidget*) NULL;
+ m_wxwindow = (GtkWidget*) NULL;
m_hasVMT = FALSE;
m_parent = parent;
m_children.DeleteContents( FALSE );
- m_x = (int)pos.x;
- m_y = (int)pos.y;
+
m_width = size.x;
if (m_width == -1) m_width = 20;
m_height = size.y;
if (m_height == -1) m_height = 20;
+
+ m_x = (int)pos.x;
+ m_y = (int)pos.y;
+
+ if (!m_needParent) // some reasonable defaults
+ {
+ if (m_x == -1)
+ {
+ m_x = (gdk_screen_width () - m_width) / 2;
+ if (m_x < 10) m_x = 10;
+ }
+ if (m_y == -1)
+ {
+ m_y = (gdk_screen_height () - m_height) / 2;
+ if (m_y < 10) m_y = 10;
+ }
+ }
+
m_minWidth = -1;
m_minHeight = -1;
m_maxWidth = -1;
m_maxHeight = -1;
+
m_retCode = 0;
+
m_eventHandler = this;
+
m_windowId = id;
+
m_sizeSet = FALSE;
- if (m_cursor == NULL)
- m_cursor = new wxCursor( wxCURSOR_ARROW );
+
+ m_cursor = new wxCursor( wxCURSOR_ARROW );
m_font = *wxSWISS_FONT;
// m_backgroundColour = wxWHITE;
- m_foregroundColour = wxBLACK;
+// m_foregroundColour = wxBLACK;
m_windowStyle = style;
m_windowName = name;
+
m_constraints = (wxLayoutConstraints *) NULL;
m_constraintsInvolvedIn = (wxList *) NULL;
m_windowSizer = (wxSizer *) NULL;
m_sizerParent = (wxWindow *) NULL;
m_autoLayout = FALSE;
+
m_hasScrolling = FALSE;
m_isScrolling = FALSE;
- m_pDropTarget = (wxDropTarget *) NULL;
+ m_hAdjust = (GtkAdjustment *) NULL;
+ m_vAdjust = (GtkAdjustment *) NULL;
+ m_oldHorizontalPos = 0.0;
+ m_oldVerticalPos = 0.0;
+
+ m_isShown = FALSE;
+ m_isEnabled = TRUE;
+
+ m_dropTarget = (wxDropTarget *) NULL;
m_resizing = FALSE;
m_windowValidator = (wxValidator *) NULL;
m_scrollGC = (GdkGC*) NULL;
m_widgetStyle = (GtkStyle*) NULL;
+
+ m_clientObject = (wxClientData*)NULL;
+ m_clientData = NULL;
}
void wxWindow::PostCreation()
{
- if (m_parent) m_parent->AddChild( this );
-
if (m_wxwindow)
{
gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event",
// are we to set fonts here ?
}
+wxPoint wxWindow::GetClientAreaOrigin() const
+{
+ return wxPoint(0,0);
+}
+
+void wxWindow::AdjustForParentClientOrigin( int& x, int& y, int sizeFlags )
+{
+ if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent())
+ {
+ wxPoint pt(GetParent()->GetClientAreaOrigin());
+ x += pt.x;
+ y += pt.y;
+ }
+}
+
void wxWindow::ImplementSetSize()
{
if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth;
void wxWindow::ImplementSetPosition()
{
- if (IS_KIND_OF(this,wxFrame) || IS_KIND_OF(this,wxDialog))
- {
- if ((m_x != -1) || (m_y != -1))
- gtk_widget_set_uposition( m_widget, m_x, m_y );
- return;
- }
-
if (!m_parent)
{
wxFAIL_MSG( "wxWindow::SetSize error.\n" );
if (newH == -1) newH = 26;
}
+ AdjustForParentClientOrigin( newX, newY, sizeFlags );
+
if ((m_x != newX) || (m_y != newY) || (!m_sizeSet))
{
m_x = newX;
m_y = newY;
ImplementSetPosition();
}
+
if ((m_width != newW) || (m_height != newH) || (!m_sizeSet))
{
m_width = newW;
{
wxASSERT_MSG( (m_widget != NULL), "invalid window" );
- if (x) (*x) = m_x;
- if (y) (*y) = m_y;
+ int xx = m_x;
+ int yy = m_y;
+
+ if (GetParent())
+ {
+ wxPoint pt(GetParent()->GetClientAreaOrigin());
+ xx -= pt.x;
+ yy -= pt.y;
+ }
+
+ if (x) (*x) = xx;
+ if (y) (*y) = yy;
}
void wxWindow::ClientToScreen( int *x, int *y )
}
}
+ wxPoint pt(GetClientAreaOrigin());
+ org_x += pt.x;
+ org_y += pt.y;
+
if (x) *x += org_x;
if (y) *y += org_y;
}
}
}
+ wxPoint pt(GetClientAreaOrigin());
+ org_x -= pt.x;
+ org_y -= pt.y;
+
if (x) *x -= org_x;
if (y) *y -= org_y;
}
void wxWindow::AddChild( wxWindow *child )
{
wxASSERT_MSG( (m_widget != NULL), "invalid window" );
- wxASSERT_MSG( (m_wxwindow != NULL), "window need client area" );
wxASSERT_MSG( (child != NULL), "invalid child" );
- wxASSERT_MSG( (child->m_widget != NULL), "invalid child" );
-
- // Addchild is (often) called before the program
- // has left the parents constructor so that no
- // virtual tables work yet. The approach below
- // practically imitates virtual tables, i.e. it
- // implements a different AddChild() behaviour
- // for wxFrame, wxDialog, wxWindow and
- // wxMDIParentFrame.
-
- // wxFrame and wxDialog as children aren't placed into the parents
-
- if (( IS_KIND_OF(child,wxFrame) || IS_KIND_OF(child,wxDialog) ) &&
- (!IS_KIND_OF(child,wxMDIChildFrame)))
- {
- m_children.Append( child );
-
- if ((child->m_x != -1) && (child->m_y != -1))
- gtk_widget_set_uposition( child->m_widget, child->m_x, child->m_y );
-
- return;
- }
-
- // In the case of an wxMDIChildFrame descendant, we use the
- // client windows's AddChild()
-
- if (IS_KIND_OF(this,wxMDIParentFrame))
- {
- if (IS_KIND_OF(child,wxMDIChildFrame))
- {
- wxMDIClientWindow *client = ((wxMDIParentFrame*)this)->GetClientWindow();
- if (client)
- {
- client->AddChild( child );
- return;
- }
- }
- }
-
- // wxNotebook is very special, so it has a private AddChild()
-
- if (IS_KIND_OF(this,wxNotebook))
- {
- wxNotebook *tab = (wxNotebook*)this;
- tab->AddChild( child );
- return;
- }
-
- // wxFrame has a private AddChild
-
- if (IS_KIND_OF(this,wxFrame) && !IS_KIND_OF(this,wxMDIChildFrame))
- {
- wxFrame *frame = (wxFrame*)this;
- frame->AddChild( child );
- return;
- }
-
- // All the rest
m_children.Append( child );
- if (m_wxwindow) gtk_myfixed_put( GTK_MYFIXED(m_wxwindow), child->m_widget,
- child->m_x, child->m_y );
-
- gtk_widget_set_usize( child->m_widget, child->m_width, child->m_height );
}
wxList *wxWindow::GetChildren()
void wxWindow::RemoveChild( wxWindow *child )
{
- if (GetChildren())
- GetChildren()->DeleteObject( child );
+ if (GetChildren()) GetChildren()->DeleteObject( child );
child->m_parent = (wxWindow *) NULL;
}
if (m_windowValidator) m_windowValidator->SetWindow(this);
}
+void wxWindow::SetClientObject( wxClientData *data )
+{
+ if (m_clientObject) delete m_clientObject;
+ m_clientObject = data;
+}
+
+wxClientData *wxWindow::GetClientObject()
+{
+ return m_clientObject;
+}
+
+void wxWindow::SetClientData( void *data )
+{
+ m_clientData = data;
+}
+
+void *wxWindow::GetClientData()
+{
+ return m_clientData;
+}
+
bool wxWindow::IsBeingDeleted()
{
return FALSE;
gdk_window_set_background( window, m_backgroundColour.GetColor() );
gdk_window_clear( window );
}
- else
- {
- GtkStyle *style = GetWidgetStyle();
- m_backgroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) );
- style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
- style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
- style->bg[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor();
- style->base[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor();
- style->bg[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor();
- style->base[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor();
- style->bg[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor();
- style->base[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor();
- }
+
+ ApplyWidgetStyle();
}
wxColour wxWindow::GetForegroundColour() const
m_foregroundColour = colour;
if (!m_foregroundColour.Ok()) return;
- if (!m_wxwindow)
+ ApplyWidgetStyle();
+}
+
+GtkStyle *wxWindow::GetWidgetStyle()
+{
+ if (m_widgetStyle) gtk_style_unref( m_widgetStyle );
+
+ m_widgetStyle =
+ gtk_style_copy(
+ gtk_widget_get_style( m_widget ) );
+
+ return m_widgetStyle;
+}
+
+void wxWindow::SetWidgetStyle()
+{
+ GtkStyle *style = GetWidgetStyle();
+
+ gdk_font_unref( style->font );
+ style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
+
+ if (m_foregroundColour.Ok())
{
- GtkStyle *style = GetWidgetStyle();
m_foregroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) );
style->fg[GTK_STATE_NORMAL] = *m_foregroundColour.GetColor();
style->fg[GTK_STATE_PRELIGHT] = *m_foregroundColour.GetColor();
style->fg[GTK_STATE_ACTIVE] = *m_foregroundColour.GetColor();
}
+
+ if (m_backgroundColour.Ok())
+ {
+ m_backgroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) );
+ style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
+ style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
+ style->bg[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor();
+ style->base[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor();
+ style->bg[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor();
+ style->base[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor();
+ style->bg[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor();
+ style->base[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor();
+ }
}
-GtkStyle *wxWindow::GetWidgetStyle()
+void wxWindow::ApplyWidgetStyle()
{
- if (!m_widgetStyle)
- m_widgetStyle =
- gtk_style_copy(
- gtk_widget_get_style( m_widget ) );
- return m_widgetStyle;
}
bool wxWindow::Validate()
void wxWindow::InitDialog()
{
- wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+ wxCHECK_RET( m_widget != NULL, "invalid window" );
wxInitDialogEvent event(GetId());
event.SetEventObject( this );
bool wxWindow::PopupMenu( wxMenu *menu, int WXUNUSED(x), int WXUNUSED(y) )
{
- wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+ wxCHECK_MSG( m_widget != NULL, FALSE, "invalid window" );
+ wxCHECK_MSG( menu != NULL, FALSE, "invalid popup-menu" );
+
SetInvokingWindow( menu, this );
gtk_menu_popup(
GTK_MENU(menu->m_menu),
void wxWindow::SetDropTarget( wxDropTarget *dropTarget )
{
- wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+ wxCHECK_RET( m_widget != NULL, "invalid window" );
GtkWidget *dnd_widget = GetConnectWidget();
DisconnectDnDWidget( dnd_widget );
- if (m_pDropTarget) delete m_pDropTarget;
- m_pDropTarget = dropTarget;
+ if (m_dropTarget) delete m_dropTarget;
+ m_dropTarget = dropTarget;
ConnectDnDWidget( dnd_widget );
}
wxDropTarget *wxWindow::GetDropTarget() const
{
- return m_pDropTarget;
+ return m_dropTarget;
}
void wxWindow::ConnectDnDWidget( GtkWidget *widget )
{
- if (!m_pDropTarget) return;
+ if (!m_dropTarget) return;
- m_pDropTarget->RegisterWidget( widget );
+ m_dropTarget->RegisterWidget( widget );
gtk_signal_connect( GTK_OBJECT(widget), "drop_data_available_event",
GTK_SIGNAL_FUNC(gtk_window_drop_callback), (gpointer)this );
void wxWindow::DisconnectDnDWidget( GtkWidget *widget )
{
- if (!m_pDropTarget) return;
+ if (!m_dropTarget) return;
gtk_signal_disconnect_by_func( GTK_OBJECT(widget),
GTK_SIGNAL_FUNC(gtk_window_drop_callback), (gpointer)this );
- m_pDropTarget->UnregisterWidget( widget );
+ m_dropTarget->UnregisterWidget( widget );
}
GtkWidget* wxWindow::GetConnectWidget()
void wxWindow::SetFont( const wxFont &font )
{
- wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+ wxCHECK_RET( m_widget != NULL, "invalid window" );
if (((wxFont*)&font)->Ok())
m_font = font;
else
m_font = *wxSWISS_FONT;
-
- GtkStyle *style = GetWidgetStyle();
- gdk_font_unref( style->font );
- style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
+
+ ApplyWidgetStyle();
}
wxFont *wxWindow::GetFont()
void wxWindow::CaptureMouse()
{
- wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+ wxCHECK_RET( m_widget != NULL, "invalid window" );
- wxASSERT_MSG( (g_capturing == FALSE), "CaptureMouse called twice" );
+ wxCHECK_RET( g_capturing == FALSE, "CaptureMouse called twice" );
GtkWidget *connect_widget = GetConnectWidget();
gtk_grab_add( connect_widget );
void wxWindow::ReleaseMouse()
{
- wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+ wxCHECK_RET( m_widget != NULL, "invalid window" );
- wxASSERT_MSG( (g_capturing == TRUE), "ReleaseMouse called twice" );
+ wxCHECK_RET( g_capturing == TRUE, "ReleaseMouse called twice" );
GtkWidget *connect_widget = GetConnectWidget();
gtk_grab_remove( connect_widget );