From 66c135f346165a716b91a77df96805193dcf1a30 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Fri, 4 Sep 1998 12:43:41 +0000 Subject: [PATCH] Corrected wxWindow::GetExtent s econd attempt at accelerators (mdi sample works) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@666 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/bitmap.h | 1 + include/wx/gtk1/bitmap.h | 1 + samples/mdi/mdi.cpp | 2 -- src/gtk.inc | 1 + src/gtk/accel.cpp | 22 +++++++++++++++++++--- src/gtk/window.cpp | 18 ++++++++++++------ src/gtk1/accel.cpp | 22 +++++++++++++++++++--- src/gtk1/window.cpp | 18 ++++++++++++------ 8 files changed, 65 insertions(+), 20 deletions(-) diff --git a/include/wx/gtk/bitmap.h b/include/wx/gtk/bitmap.h index b14cb20955..61f2bb2708 100644 --- a/include/wx/gtk/bitmap.h +++ b/include/wx/gtk/bitmap.h @@ -130,6 +130,7 @@ class wxBitmap: public wxObject friend wxFrame; friend wxDialog; friend wxTreeCtrl; + friend wxNotebook; GdkPixmap *GetPixmap() const; GdkBitmap *GetBitmap() const; diff --git a/include/wx/gtk1/bitmap.h b/include/wx/gtk1/bitmap.h index b14cb20955..61f2bb2708 100644 --- a/include/wx/gtk1/bitmap.h +++ b/include/wx/gtk1/bitmap.h @@ -130,6 +130,7 @@ class wxBitmap: public wxObject friend wxFrame; friend wxDialog; friend wxTreeCtrl; + friend wxNotebook; GdkPixmap *GetPixmap() const; GdkBitmap *GetBitmap() const; diff --git a/samples/mdi/mdi.cpp b/samples/mdi/mdi.cpp index 94b4fc302b..f94ac448f8 100644 --- a/samples/mdi/mdi.cpp +++ b/samples/mdi/mdi.cpp @@ -109,7 +109,6 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, c CreateToolBar(wxNO_BORDER|wxTB_FLAT|wxTB_HORIZONTAL); InitToolBar(GetToolBar()); -#ifdef __WXMSW__ // Accelerators wxAcceleratorEntry entries[3]; entries[0].Set(wxACCEL_CTRL, (int) 'N', MDI_NEW_WINDOW); @@ -117,7 +116,6 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, c entries[2].Set(wxACCEL_CTRL, (int) 'A', MDI_ABOUT); wxAcceleratorTable accel(3, entries); SetAcceleratorTable(accel); -#endif } void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) ) diff --git a/src/gtk.inc b/src/gtk.inc index 26c2accec9..76e934d2ce 100644 --- a/src/gtk.inc +++ b/src/gtk.inc @@ -33,6 +33,7 @@ LIB_CPP_SRC=\ common/memory.cpp \ common/module.cpp \ common/object.cpp \ + common/odbc.cpp \ common/postscrp.cpp \ common/prntbase.cpp \ common/resource.cpp \ diff --git a/src/gtk/accel.cpp b/src/gtk/accel.cpp index 08b5436b34..8288d870da 100644 --- a/src/gtk/accel.cpp +++ b/src/gtk/accel.cpp @@ -13,6 +13,8 @@ #include "wx/accel.h" +#include + //----------------------------------------------------------------------------- // wxAcceleratorTable //----------------------------------------------------------------------------- @@ -22,13 +24,24 @@ class wxAccelRefData: public wxObjectRefData public: wxAccelRefData(void); + ~wxAccelRefData(void); wxList m_accels; }; wxAccelRefData::wxAccelRefData(void) { - m_accels.DeleteContents( TRUE ); +} + +wxAccelRefData::~wxAccelRefData(void) +{ + wxNode *node = m_accels.First(); + while (node) + { + wxAcceleratorEntry *entry = (wxAcceleratorEntry *)node->Data(); + delete entry; + node = node->Next(); + } } //----------------------------------------------------------------------------- @@ -47,8 +60,11 @@ wxAcceleratorTable::wxAcceleratorTable( int n, wxAcceleratorEntry entries[] ) m_refData = new wxAccelRefData(); for (int i = 0; i < n; i++) { - M_ACCELDATA->m_accels.Append( (wxObject*) - new wxAcceleratorEntry( entries[n].GetFlags(), entries[n].GetKeyCode(), entries[n].GetCommand() ) ); + int flag = entries[i].GetFlags(); + int keycode = entries[i].GetKeyCode(); + int command = entries[i].GetCommand(); + if ((keycode >= (int)'A') && (keycode <= (int)'Z')) keycode = (int)tolower( (char)keycode ); + M_ACCELDATA->m_accels.Append( (wxObject*) new wxAcceleratorEntry( flag, keycode, command ) ); } } diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index dba832d740..2ca9ce464e 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -193,11 +193,17 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e if (!ret) { - int command = win->GetAcceleratorTable()->GetCommand( event ); - if (command != -1) - { - wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command ); - ret = win->GetEventHandler()->ProcessEvent( command_event ); + 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(); } } @@ -1404,7 +1410,7 @@ void wxWindow::GetTextExtent( const wxString& string, int *x, int *y, if (theFont) fontToUse = *theFont; GdkFont *font = fontToUse.GetInternalFont( 1.0 ); - if (x) (*y) = gdk_string_width( font, string ); + if (x) (*x) = gdk_string_width( font, string ); if (y) (*y) = font->ascent + font->descent; if (descent) (*descent) = font->descent; if (externalLeading) (*externalLeading) = 0; // ?? diff --git a/src/gtk1/accel.cpp b/src/gtk1/accel.cpp index 08b5436b34..8288d870da 100644 --- a/src/gtk1/accel.cpp +++ b/src/gtk1/accel.cpp @@ -13,6 +13,8 @@ #include "wx/accel.h" +#include + //----------------------------------------------------------------------------- // wxAcceleratorTable //----------------------------------------------------------------------------- @@ -22,13 +24,24 @@ class wxAccelRefData: public wxObjectRefData public: wxAccelRefData(void); + ~wxAccelRefData(void); wxList m_accels; }; wxAccelRefData::wxAccelRefData(void) { - m_accels.DeleteContents( TRUE ); +} + +wxAccelRefData::~wxAccelRefData(void) +{ + wxNode *node = m_accels.First(); + while (node) + { + wxAcceleratorEntry *entry = (wxAcceleratorEntry *)node->Data(); + delete entry; + node = node->Next(); + } } //----------------------------------------------------------------------------- @@ -47,8 +60,11 @@ wxAcceleratorTable::wxAcceleratorTable( int n, wxAcceleratorEntry entries[] ) m_refData = new wxAccelRefData(); for (int i = 0; i < n; i++) { - M_ACCELDATA->m_accels.Append( (wxObject*) - new wxAcceleratorEntry( entries[n].GetFlags(), entries[n].GetKeyCode(), entries[n].GetCommand() ) ); + int flag = entries[i].GetFlags(); + int keycode = entries[i].GetKeyCode(); + int command = entries[i].GetCommand(); + if ((keycode >= (int)'A') && (keycode <= (int)'Z')) keycode = (int)tolower( (char)keycode ); + M_ACCELDATA->m_accels.Append( (wxObject*) new wxAcceleratorEntry( flag, keycode, command ) ); } } diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index dba832d740..2ca9ce464e 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -193,11 +193,17 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e if (!ret) { - int command = win->GetAcceleratorTable()->GetCommand( event ); - if (command != -1) - { - wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command ); - ret = win->GetEventHandler()->ProcessEvent( command_event ); + 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(); } } @@ -1404,7 +1410,7 @@ void wxWindow::GetTextExtent( const wxString& string, int *x, int *y, if (theFont) fontToUse = *theFont; GdkFont *font = fontToUse.GetInternalFont( 1.0 ); - if (x) (*y) = gdk_string_width( font, string ); + if (x) (*x) = gdk_string_width( font, string ); if (y) (*y) = font->ascent + font->descent; if (descent) (*descent) = font->descent; if (externalLeading) (*externalLeading) = 0; // ?? -- 2.45.2