X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f03fc89fff2d6e823e7d4d14fbe14822ad6777b1..dfc3d7e025e919d9cf0d2e59d3c74bfab0b07e55:/src/gtk/frame.cpp diff --git a/src/gtk/frame.cpp b/src/gtk/frame.cpp index 1a01040022..258bf92514 100644 --- a/src/gtk/frame.cpp +++ b/src/gtk/frame.cpp @@ -24,6 +24,7 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" #include "wx/gtk/win_gtk.h" +#include "gdk/gdkkeysyms.h" //----------------------------------------------------------------------------- // constants @@ -62,21 +63,17 @@ extern void debug_focus_in( GtkWidget* widget, const wxChar* name, const wxChar static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxFrame *win ) { - if (g_isIdle) wxapp_install_idle_handler(); + if (g_isIdle) + wxapp_install_idle_handler(); - if (!win->HasVMT()) return; + if (!win->m_hasVMT) return; -/* - printf( "OnFrameResize from " ); - if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - printf( win->GetClassInfo()->GetClassName() ); - printf( ".\n" ); -*/ - - if ((win->GetWidth() != alloc->width) || (win->GetHeight() != alloc->height)) - { - win->InternalSetSize( alloc->width, alloc->height ); - } + if ((win->m_width != alloc->width) || (win->m_height != alloc->height)) + { + win->m_width = alloc->width; + win->m_height = alloc->height; + win->UpdateSize(); + } } //----------------------------------------------------------------------------- @@ -85,14 +82,8 @@ static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxFrame *win ) { - if (g_isIdle) wxapp_install_idle_handler(); - -/* - printf( "OnDelete from " ); - if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - printf( win->GetClassInfo()->GetClassName() ); - printf( ".\n" ); -*/ + if (g_isIdle) + wxapp_install_idle_handler(); win->Close(); @@ -105,9 +96,7 @@ static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WX static void gtk_menu_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) { - if (g_isIdle) wxapp_install_idle_handler(); - - if (!win->HasVMT()) return; + if (!win->m_hasVMT) return; win->m_menuBarDetached = FALSE; win->UpdateSize(); @@ -119,9 +108,7 @@ static void gtk_menu_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget * static void gtk_menu_detached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) { - if (g_isIdle) wxapp_install_idle_handler(); - - if (!win->HasVMT()) return; + if (!win->m_hasVMT) return; win->m_menuBarDetached = TRUE; win->UpdateSize(); @@ -133,11 +120,10 @@ static void gtk_menu_detached_callback( GtkWidget *WXUNUSED(widget), GtkWidget * static void gtk_toolbar_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) { - if (g_isIdle) wxapp_install_idle_handler(); - - if (!win->HasVMT()) return; + if (!win->m_hasVMT) return; win->m_toolBarDetached = FALSE; + win->UpdateSize(); } @@ -147,9 +133,10 @@ static void gtk_toolbar_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidge static void gtk_toolbar_detached_callback( GtkWidget *widget, GtkWidget *WXUNUSED(child), wxFrame *win ) { - if (g_isIdle) wxapp_install_idle_handler(); + if (g_isIdle) + wxapp_install_idle_handler(); - if (!win->HasVMT()) return; + if (!win->m_hasVMT) return; win->m_toolBarDetached = TRUE; win->UpdateSize(); @@ -159,15 +146,21 @@ static void gtk_toolbar_detached_callback( GtkWidget *widget, GtkWidget *WXUNUSE // "configure_event" //----------------------------------------------------------------------------- -static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxFrame *win ) +static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *WXUNUSED(event), wxFrame *win ) { - if (g_isIdle) wxapp_install_idle_handler(); - - if (!win->HasVMT()) return FALSE; + if (g_isIdle) + wxapp_install_idle_handler(); - win->InternalSetPosition(event->x, event->y); + if (!win->m_hasVMT) return FALSE; + + int x = 0; + int y = 0; + gdk_window_get_root_origin( win->m_widget->window, &x, &y ); + + win->m_x = x; + win->m_y = y; - wxMoveEvent mevent( wxPoint(win->GetX(),win->GetY()), win->GetId() ); + wxMoveEvent mevent( wxPoint(win->m_x,win->m_y), win->GetId() ); mevent.SetEventObject( win ); win->GetEventHandler()->ProcessEvent( mevent ); @@ -184,7 +177,8 @@ static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventC static gint gtk_frame_realized_callback( GtkWidget *widget, wxFrame *win ) { - if (g_isIdle) wxapp_install_idle_handler(); + if (g_isIdle) + wxapp_install_idle_handler(); /* all this is for Motif Window Manager "hints" and is supposed to be recognized by other WM as well. not tested. */ @@ -215,14 +209,14 @@ gtk_frame_realized_callback( GtkWidget *widget, wxFrame *win ) } - gdk_window_set_decorations( win->GetHandle()->window, (GdkWMDecoration)decor); - gdk_window_set_functions( win->GetHandle()->window, (GdkWMFunction)func); + gdk_window_set_decorations( win->m_widget->window, (GdkWMDecoration)decor); + gdk_window_set_functions( win->m_widget->window, (GdkWMFunction)func); /* GTK's shrinking/growing policy */ if ((win->GetWindowStyle() & wxRESIZE_BORDER) == 0) - gtk_window_set_policy(GTK_WINDOW(win->GetHandle()), 0, 0, 1); + gtk_window_set_policy(GTK_WINDOW(win->m_widget), 0, 0, 1); else - gtk_window_set_policy(GTK_WINDOW(win->GetHandle()), 1, 1, 1); + gtk_window_set_policy(GTK_WINDOW(win->m_widget), 1, 1, 1); /* reset the icon */ if (win->m_icon != wxNullIcon) @@ -259,21 +253,18 @@ gtk_frame_realized_callback( GtkWidget *widget, wxFrame *win ) * virtual function here as wxWindows requires different ways to insert * a child in container classes. */ -static void wxInsertChildInFrame( wxWindow* parent, wxWindow* child ) +static void wxInsertChildInFrame( wxFrame* parent, wxWindow* child ) { - if (wxIS_KIND_OF(child,wxToolBar) || wxIS_KIND_OF(child,wxMenuBar)) + if (!parent->m_insertInClientArea) { - /* actually, menubars are never inserted here, but this - may change one day */ - /* these are outside the client area */ wxFrame* frame = (wxFrame*) parent; gtk_myfixed_put( GTK_MYFIXED(frame->m_mainWidget), - GTK_WIDGET(child->GetHandle()), - child->GetX(), - child->GetY(), - child->GetWidth(), - child->GetHeight() ); + GTK_WIDGET(child->m_widget), + child->m_x, + child->m_y, + child->m_width, + child->m_height ); /* we connect to these events for recalculating the client area space when the toolbar is floating */ @@ -282,10 +273,10 @@ static void wxInsertChildInFrame( wxWindow* parent, wxWindow* child ) wxToolBar *toolBar = (wxToolBar*) child; if (toolBar->GetWindowStyle() & wxTB_DOCKABLE) { - gtk_signal_connect( GTK_OBJECT(toolBar->GetHandle()), "child_attached", + gtk_signal_connect( GTK_OBJECT(toolBar->m_widget), "child_attached", GTK_SIGNAL_FUNC(gtk_toolbar_attached_callback), (gpointer)parent ); - gtk_signal_connect( GTK_OBJECT(toolBar->GetHandle()), "child_detached", + gtk_signal_connect( GTK_OBJECT(toolBar->m_widget), "child_detached", GTK_SIGNAL_FUNC(gtk_toolbar_detached_callback), (gpointer)parent ); } } @@ -293,12 +284,12 @@ static void wxInsertChildInFrame( wxWindow* parent, wxWindow* child ) else { /* these are inside the client area */ - gtk_myfixed_put( GTK_MYFIXED(parent->GetWxWindow()), - GTK_WIDGET(child->GetHandle()), - child->GetX(), - child->GetY(), - child->GetWidth(), - child->GetHeight() ); + gtk_myfixed_put( GTK_MYFIXED(parent->m_wxwindow), + GTK_WIDGET(child->m_widget), + child->m_x, + child->m_y, + child->m_width, + child->m_height ); } /* resize on OnInternalIdle */ @@ -317,7 +308,7 @@ END_EVENT_TABLE() IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow) -wxFrame::wxFrame() +void wxFrame::Init() { m_frameMenuBar = (wxMenuBar *) NULL; m_frameStatusBar = (wxStatusBar *) NULL; @@ -328,23 +319,15 @@ wxFrame::wxFrame() m_mainWidget = (GtkWidget*) NULL; m_menuBarDetached = FALSE; m_toolBarDetached = FALSE; - m_insertCallback = wxInsertChildInFrame; + m_insertInClientArea = TRUE; } wxFrame::wxFrame( wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos, const wxSize &size, long style, const wxString &name ) { - m_frameMenuBar = (wxMenuBar *) NULL; - m_frameStatusBar = (wxStatusBar *) NULL; - m_frameToolBar = (wxToolBar *) NULL; - m_sizeSet = FALSE; - m_miniEdge = 0; - m_miniTitle = 0; - m_mainWidget = (GtkWidget*) NULL; - m_menuBarDetached = FALSE; - m_toolBarDetached = FALSE; - m_insertCallback = wxInsertChildInFrame; + Init(); + Create( parent, id, title, pos, size, style, name ); } @@ -360,7 +343,7 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, m_title = title; - m_insertCallback = wxInsertChildInFrame; + m_insertCallback = (wxInsertChildFunction) wxInsertChildInFrame; GtkWindowType win_type = GTK_WINDOW_TOPLEVEL; if (style & wxSIMPLE_BORDER) win_type = GTK_WINDOW_POPUP; @@ -425,6 +408,8 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, wxFrame::~wxFrame() { + m_isBeingDeleted = TRUE; + if (m_frameMenuBar) delete m_frameMenuBar; m_frameMenuBar = (wxMenuBar *) NULL; @@ -519,7 +504,6 @@ void wxFrame::DoSetSize( int x, int y, int width, int height, int sizeFlags ) { if ((m_x != old_x) || (m_y != old_y)) { - /* we set the size here and in gtk_frame_map_callback */ gtk_widget_set_uposition( m_widget, m_x, m_y ); } } @@ -548,11 +532,11 @@ void wxFrame::Centre( int direction ) Move( x, y ); } -void wxFrame::GetClientSize( int *width, int *height ) const +void wxFrame::DoGetClientSize( int *width, int *height ) const { wxASSERT_MSG( (m_widget != NULL), _T("invalid frame") ); - wxWindow::GetClientSize( width, height ); + wxWindow::DoGetClientSize( width, height ); if (height) { /* menu bar */ @@ -668,10 +652,12 @@ void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height int ww = m_width - 2*m_miniEdge; int hh = wxMENU_HEIGHT; if (m_menuBarDetached) hh = wxPLACE_HOLDER; - m_frameMenuBar->InternalSetPosition(xx, yy); - m_frameMenuBar->InternalSetSize(ww, hh); + m_frameMenuBar->m_x = xx; + m_frameMenuBar->m_y = yy; + m_frameMenuBar->m_width = ww; + m_frameMenuBar->m_height = hh; gtk_myfixed_set_size( GTK_MYFIXED(m_mainWidget), - m_frameMenuBar->GetHandle(), + m_frameMenuBar->m_widget, xx, yy, ww, hh ); client_area_y_offset += hh; } @@ -688,17 +674,14 @@ void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height yy += wxPLACE_HOLDER; } int ww = m_width - 2*m_miniEdge; - int hh = m_frameToolBar->GetHeight(); - // VZ: according to earlier comments in this file, the tbar height - // shouldn't be changed, so I comment out the next line - // (09.05.99) - //if (m_toolBarDetached) hh = wxPLACE_HOLDER; - - m_frameToolBar->InternalSetPosition(xx, yy); - m_frameToolBar->InternalSetSize(ww, hh); - + int hh = m_frameToolBar->m_height; + if (m_toolBarDetached) hh = wxPLACE_HOLDER; + m_frameToolBar->m_x = xx; + m_frameToolBar->m_y = yy; + /* m_frameToolBar->m_height = hh; don't change the toolbar's height */ + m_frameToolBar->m_width = ww; gtk_myfixed_set_size( GTK_MYFIXED(m_mainWidget), - m_frameToolBar->GetHandle(), + m_frameToolBar->m_widget, xx, yy, ww, hh ); client_area_y_offset += hh; } @@ -723,10 +706,12 @@ void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height int yy = m_height - wxSTATUS_HEIGHT - m_miniEdge - client_area_y_offset; int ww = m_width - 2*m_miniEdge; int hh = wxSTATUS_HEIGHT; - m_frameStatusBar->InternalSetPosition(xx, yy); - m_frameStatusBar->InternalSetSize(ww, hh); + m_frameStatusBar->m_x = xx; + m_frameStatusBar->m_y = yy; + m_frameStatusBar->m_width = ww; + m_frameStatusBar->m_height = hh; gtk_myfixed_set_size( GTK_MYFIXED(m_wxwindow), - m_frameStatusBar->GetHandle(), + m_frameStatusBar->m_widget, xx, yy, ww, hh ); } @@ -743,7 +728,7 @@ void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height /* send size event to status bar */ if (m_frameStatusBar) { - wxSizeEvent event2( wxSize(m_frameStatusBar->GetWidth(),m_frameStatusBar->GetHeight()), m_frameStatusBar->GetId() ); + wxSizeEvent event2( wxSize(m_frameStatusBar->m_width,m_frameStatusBar->m_height), m_frameStatusBar->GetId() ); event2.SetEventObject( m_frameStatusBar ); m_frameStatusBar->GetEventHandler()->ProcessEvent( event2 ); } @@ -751,15 +736,27 @@ void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height m_resizing = FALSE; } +void wxFrame::MakeModal( bool modal ) +{ + if (modal) + gtk_grab_add( m_widget ); + else + gtk_grab_remove( m_widget ); +} + void wxFrame::OnInternalIdle() { if (!m_sizeSet && GTK_WIDGET_REALIZED(m_wxwindow)) GtkOnSize( m_x, m_y, m_width, m_height ); DoMenuUpdates(); + + if (m_frameMenuBar) m_frameMenuBar->OnInternalIdle(); + if (m_frameToolBar) m_frameToolBar->OnInternalIdle(); + if (m_frameStatusBar) m_frameStatusBar->OnInternalIdle(); } -void wxFrame::OnCloseWindow( wxCloseEvent& event ) +void wxFrame::OnCloseWindow( wxCloseEvent& WXUNUSED(event) ) { Destroy(); } @@ -796,7 +793,7 @@ void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) ) { /* yes: set it's size to fill all the frame */ int client_x, client_y; - GetClientSize( &client_x, &client_y ); + DoGetClientSize( &client_x, &client_y ); child->SetSize( 1, 1, client_x-2, client_y-2 ); } } @@ -808,7 +805,7 @@ static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) #if (GTK_MINOR_VERSION > 0) /* support for native hot keys */ - gtk_accel_group_attach( menu->m_accel, GTK_OBJECT(win->GetHandle())); + gtk_accel_group_attach( menu->m_accel, GTK_OBJECT(win->m_widget)); #endif wxNode *node = menu->GetItems().First(); @@ -847,18 +844,18 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar ) { m_frameMenuBar->SetParent(this); gtk_myfixed_put( GTK_MYFIXED(m_mainWidget), - m_frameMenuBar->GetHandle(), - m_frameMenuBar->GetX(), - m_frameMenuBar->GetY(), - m_frameMenuBar->GetWidth(), - m_frameMenuBar->GetHeight() ); + m_frameMenuBar->m_widget, + m_frameMenuBar->m_x, + m_frameMenuBar->m_y, + m_frameMenuBar->m_width, + m_frameMenuBar->m_height ); if (menuBar->GetWindowStyle() & wxMB_DOCKABLE) { - gtk_signal_connect( GTK_OBJECT(menuBar->GetHandle()), "child_attached", + gtk_signal_connect( GTK_OBJECT(menuBar->m_widget), "child_attached", GTK_SIGNAL_FUNC(gtk_menu_attached_callback), (gpointer)this ); - gtk_signal_connect( GTK_OBJECT(menuBar->GetHandle()), "child_detached", + gtk_signal_connect( GTK_OBJECT(menuBar->m_widget), "child_detached", GTK_SIGNAL_FUNC(gtk_menu_detached_callback), (gpointer)this ); } } @@ -894,15 +891,19 @@ void wxFrame::OnMenuHighlight(wxMenuEvent& event) } } -wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) +wxToolBar* wxFrame::CreateToolBar( long style, wxWindowID id, const wxString& name ) { wxASSERT_MSG( (m_widget != NULL), _T("invalid frame") ); wxCHECK_MSG( m_frameToolBar == NULL, FALSE, _T("recreating toolbar in wxFrame") ); + m_insertInClientArea = FALSE; + m_frameToolBar = OnCreateToolBar( style, id, name ); - GetChildren().DeleteObject( m_frameToolBar ); + if (m_frameToolBar) GetChildren().DeleteObject( m_frameToolBar ); + + m_insertInClientArea = TRUE; m_sizeSet = FALSE;