From 97d7bfb8b470d62d8b2f142d5287b8217d9f3e8b Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Thu, 18 Nov 1999 15:58:35 +0000 Subject: [PATCH] Added wxEvtHandler::Disconect() Added wxToolBar::DeleteTool() Removed the WXWIN_COMP... defines from the common setup.h Some tests, git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4615 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/event.h | 10 ++++++++++ include/wx/gtk/tbargtk.h | 5 +++++ include/wx/gtk1/tbargtk.h | 5 +++++ include/wx/setup.h | 40 --------------------------------------- samples/toolbar/test.cpp | 27 ++++++++++++++++---------- src/common/event.cpp | 28 +++++++++++++++++++++++++++ src/common/tbarbase.cpp | 1 + src/generic/treectrl.cpp | 34 ++++++++++++++++----------------- src/gtk/stattext.cpp | 4 +++- src/gtk/tbargtk.cpp | 23 ++++++++++++++++++++++ src/gtk1/stattext.cpp | 4 +++- src/gtk1/tbargtk.cpp | 23 ++++++++++++++++++++++ 12 files changed, 135 insertions(+), 69 deletions(-) diff --git a/include/wx/event.h b/include/wx/event.h index 0d90ca6b44..93e2619606 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -1380,6 +1380,16 @@ public: wxObject *userData = (wxObject *) NULL ) { Connect(id, -1, eventType, func, userData); } + bool Disconnect( int id, int lastId = -1, wxEventType eventType = wxEVT_NULL, + wxObjectEventFunction func = NULL, + wxObject *userData = (wxObject *) NULL ); + + // Convenience function: take just one id + bool Disconnect( int id, wxEventType eventType = wxEVT_NULL, + wxObjectEventFunction func = NULL, + wxObject *userData = (wxObject *) NULL ) + { return Disconnect(id, -1, eventType, func, userData); } + // implementation from now on virtual bool SearchEventTable(wxEventTable& table, wxEvent& event); bool SearchDynamicEventTable( wxEvent& event ); diff --git a/include/wx/gtk/tbargtk.h b/include/wx/gtk/tbargtk.h index beb2e04416..3d7c30d434 100644 --- a/include/wx/gtk/tbargtk.h +++ b/include/wx/gtk/tbargtk.h @@ -83,8 +83,13 @@ public: // Add space virtual void AddSeparator(); + // Delete tool by index (=id) + virtual bool DeleteTool(int toolIndex); + + // Delete all tools virtual void ClearTools(); + // Has to be called after adding tools or changing something virtual bool Realize(); virtual void EnableTool(int toolIndex, bool enable); diff --git a/include/wx/gtk1/tbargtk.h b/include/wx/gtk1/tbargtk.h index beb2e04416..3d7c30d434 100644 --- a/include/wx/gtk1/tbargtk.h +++ b/include/wx/gtk1/tbargtk.h @@ -83,8 +83,13 @@ public: // Add space virtual void AddSeparator(); + // Delete tool by index (=id) + virtual bool DeleteTool(int toolIndex); + + // Delete all tools virtual void ClearTools(); + // Has to be called after adding tools or changing something virtual bool Realize(); virtual void EnableTool(int toolIndex, bool enable); diff --git a/include/wx/setup.h b/include/wx/setup.h index 0969a450ea..226b2d3ed6 100644 --- a/include/wx/setup.h +++ b/include/wx/setup.h @@ -33,45 +33,5 @@ #include "wx/gtk/setup.h" #endif -/* - * Compatibility defines: note that, in general, there is a a reason for not - * compatible changes, so you should try to avoid defining WXWIN_COMPATIBILITY - * and do so only if your program really can't be compiled otherwise. - */ - -/* - * Compatibility with 1.66 API. - * Level 0: no backward compatibility, all new features - * Level 1: wxDC, OnSize (etc.) compatibility, but - * some new features such as event tables - */ -#define WXWIN_COMPATIBILITY 0 - -/* - * wxWindows 2.0 API compatibility. Possible values are: - * 0: no backwards compatibility - * 1: some backwards compatibility, but if it conflicts with the new - * features, use the new code, not the old one - * 2: maximum backwards compatiblity: even if compatibility can only be - * achieved by disabling new features, do it. - */ -#define WXWIN_COMPATIBILITY_2 1 - -/* - * wxWindows 2.0 uses long for wxPoint/wxRect/wxSize member fields and wxDC - * method arguments, wxWindows 2.1 and later uses wxCoord typedef which is - * usually int. Using long leads to (justified) warnings about long to int - * conversions from some compilers and is, generally speaking, unneeded. - */ -#define wxUSE_COMPATIBLE_COORD_TYPES 0 - -/* - * Maximum compatibility with 2.0 API - */ -#if WXWIN_COMPATIBILITY_2 == 2 -#undef wxUSE_COMPATIBLE_COORD_TYPES -#define wxUSE_COMPATIBLE_COORD_TYPES 1 -#endif /* WXWIN_COMPATIBILITY_2_MAX */ - #endif /* _WX_SETUP_H_BASE_ */ diff --git a/samples/toolbar/test.cpp b/samples/toolbar/test.cpp index f6278e43a8..e28ab14981 100644 --- a/samples/toolbar/test.cpp +++ b/samples/toolbar/test.cpp @@ -76,12 +76,9 @@ public: void OnToggleToolbar(wxCommandEvent& event); void OnEnablePrint(wxCommandEvent& event) { DoEnablePrint(); } + void OnDeletePrint(wxCommandEvent& event) { DoDeletePrint(); } void OnToggleHelp(wxCommandEvent& event) { DoToggleHelp(); } - void OnAppendMenu(wxCommandEvent& event); - void OnDeleteMenu(wxCommandEvent& event); - void OnToggleMenu(wxCommandEvent& event); - void OnToolLeftClick(wxCommandEvent& event); void OnToolEnter(wxCommandEvent& event); @@ -89,6 +86,7 @@ public: private: void DoEnablePrint(); + void DoDeletePrint(); void DoToggleHelp(); bool m_smallToolbar; @@ -107,6 +105,7 @@ enum { IDM_TOOLBAR_TOGGLETOOLBAR = 200, IDM_TOOLBAR_ENABLEPRINT, + IDM_TOOLBAR_DELETEPRINT, IDM_TOOLBAR_TOGGLEHELP, ID_COMBO = 1000 @@ -125,6 +124,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBAR, MyFrame::OnToggleToolbar) EVT_MENU(IDM_TOOLBAR_ENABLEPRINT, MyFrame::OnEnablePrint) + EVT_MENU(IDM_TOOLBAR_DELETEPRINT, MyFrame::OnDeletePrint) EVT_MENU(IDM_TOOLBAR_TOGGLEHELP, MyFrame::OnToggleHelp) EVT_MENU(-1, MyFrame::OnToolLeftClick) @@ -214,8 +214,6 @@ bool MyApp::InitToolbar(wxToolBar* toolBar, bool smallicons) currentX += width + 5; toolBar->AddTool(wxID_SAVE, *(toolBarBitmaps[2]), wxNullBitmap, TRUE, currentX, -1, (wxObject *) NULL, "Toggle button 1"); - toolBar->AddSeparator(); - wxComboBox *combo = new wxComboBox(toolBar, ID_COMBO); combo->Append("This"); combo->Append("is a"); @@ -224,8 +222,6 @@ bool MyApp::InitToolbar(wxToolBar* toolBar, bool smallicons) combo->Append("toolbar"); toolBar->AddControl(combo); - toolBar->AddSeparator(); - if ( !smallicons ) { currentX += width + 5; @@ -235,8 +231,7 @@ bool MyApp::InitToolbar(wxToolBar* toolBar, bool smallicons) currentX += width + 5; toolBar->AddTool(wxID_PASTE, *(toolBarBitmaps[5]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Paste"); currentX += width + 5; - toolBar->AddSeparator(); - toolBar->AddTool(wxID_PRINT, *(toolBarBitmaps[6]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Print"); + toolBar->AddTool(wxID_PRINT, *(toolBarBitmaps[6]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Delete this tool"); currentX += width + 5; toolBar->AddSeparator(); toolBar->AddTool(wxID_HELP, *(toolBarBitmaps[7]), wxNullBitmap, TRUE, currentX, -1, (wxObject *) NULL, "Help button"); @@ -278,6 +273,7 @@ MyFrame::MyFrame(wxFrame* parent, wxMenu *tbarMenu = new wxMenu; tbarMenu->Append(IDM_TOOLBAR_TOGGLETOOLBAR, "&Toggle toolbar", "Change the toolbar kind"); tbarMenu->Append(IDM_TOOLBAR_ENABLEPRINT, "&Enable print button", ""); + tbarMenu->Append(IDM_TOOLBAR_DELETEPRINT, "&Delete print button", ""); tbarMenu->Append(IDM_TOOLBAR_TOGGLEHELP, "Toggle &help button", ""); wxMenu *fileMenu = new wxMenu; @@ -353,6 +349,11 @@ void MyFrame::OnToolLeftClick(wxCommandEvent& event) { DoToggleHelp(); } + + if (event.GetId() == wxID_PRINT) + { + DoDeletePrint(); + } } void MyFrame::OnCombo(wxCommandEvent& event) @@ -369,6 +370,12 @@ void MyFrame::DoEnablePrint() tb->EnableTool( wxID_PRINT, TRUE ); } +void MyFrame::DoDeletePrint() +{ + wxToolBar *tb = GetToolBar(); + tb->DeleteTool( wxID_PRINT ); +} + void MyFrame::DoToggleHelp() { wxToolBar *tb = GetToolBar(); diff --git a/src/common/event.cpp b/src/common/event.cpp index b41f00363a..d3abd577ab 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -760,6 +760,7 @@ bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event) } return FALSE; } + void wxEvtHandler::Connect( int id, int lastId, wxEventType eventType, wxObjectEventFunction func, @@ -778,6 +779,33 @@ void wxEvtHandler::Connect( int id, int lastId, m_dynamicEvents->Append( (wxObject*) entry ); } +bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType, + wxObjectEventFunction func, + wxObject *userData ) +{ + if (!m_dynamicEvents) + return FALSE; + + wxNode *node = m_dynamicEvents->First(); + while (node) + { + wxEventTableEntry *entry = (wxEventTableEntry*)node->Data(); + if ((entry->m_id == id) && + ((entry->m_lastId == lastId) || (lastId == -1)) && + ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) && + ((entry->m_fn == func) || (func == (wxObjectEventFunction)NULL)) && + ((entry->m_callbackUserData == userData) || (userData == (wxObject*)NULL))) + { + if (entry->m_callbackUserData) delete entry->m_callbackUserData; + m_dynamicEvents->DeleteNode( node ); + delete entry; + return TRUE; + } + node = node->Next(); + } + return FALSE; +} + bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event ) { wxCHECK_MSG( m_dynamicEvents, FALSE, diff --git a/src/common/tbarbase.cpp b/src/common/tbarbase.cpp index 98eed8bbd5..615d76c560 100644 --- a/src/common/tbarbase.cpp +++ b/src/common/tbarbase.cpp @@ -90,6 +90,7 @@ wxToolBarTool::wxToolBarTool(int theIndex, } m_shortHelpString = helpS1; m_longHelpString = helpS2; + m_control = (wxControl*) NULL; } wxToolBarTool::wxToolBarTool(wxControl *control) diff --git a/src/generic/treectrl.cpp b/src/generic/treectrl.cpp index bd47f172a7..aaaeeed06b 100644 --- a/src/generic/treectrl.cpp +++ b/src/generic/treectrl.cpp @@ -945,32 +945,32 @@ void wxTreeCtrl::DeleteChildren(const wxTreeItemId& itemId) void wxTreeCtrl::Delete(const wxTreeItemId& itemId) { - wxGenericTreeItem *item = itemId.m_pItem; - wxGenericTreeItem *parent = item->GetParent(); + wxGenericTreeItem *item = itemId.m_pItem; + wxGenericTreeItem *parent = item->GetParent(); - if ( parent ) - { - parent->GetChildren().Remove(item); - } + if ( parent ) + { + parent->GetChildren().Remove( item ); // remove by value + } - item->DeleteChildren(this); - SendDeleteEvent(item); - delete item; + item->DeleteChildren(this); + SendDeleteEvent(item); + delete item; - m_dirty = TRUE; + m_dirty = TRUE; } void wxTreeCtrl::DeleteAllItems() { - if ( m_anchor ) - { - m_anchor->DeleteChildren(this); - delete m_anchor; + if ( m_anchor ) + { + m_anchor->DeleteChildren(this); + delete m_anchor; - m_anchor = NULL; + m_anchor = NULL; - m_dirty = TRUE; - } + m_dirty = TRUE; + } } void wxTreeCtrl::Expand(const wxTreeItemId& itemId) diff --git a/src/gtk/stattext.cpp b/src/gtk/stattext.cpp index 011b4b21a6..6816895a37 100644 --- a/src/gtk/stattext.cpp +++ b/src/gtk/stattext.cpp @@ -61,6 +61,8 @@ bool wxStaticText::Create(wxWindow *parent, // effect of changing the control size which might not be desirable wxControl::SetLabel(label); m_widget = gtk_label_new( m_label.mbc_str() ); + + gtk_label_set_line_wrap( GTK_LABEL(m_widget), FALSE ); SetFont( parent->GetFont() ); @@ -79,7 +81,7 @@ bool wxStaticText::Create(wxWindow *parent, GtkRequisition req; (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req ); - + wxSize newSize = size; if (newSize.x == -1) newSize.x = req.width; if (newSize.y == -1) newSize.y = req.height; diff --git a/src/gtk/tbargtk.cpp b/src/gtk/tbargtk.cpp index 9ee4df2deb..970873c7e2 100644 --- a/src/gtk/tbargtk.cpp +++ b/src/gtk/tbargtk.cpp @@ -178,6 +178,7 @@ bool wxToolBar::Create( wxWindow *parent, wxWindowID id, m_toolbar = GTK_TOOLBAR( gtk_toolbar_new( GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_ICONS ) ); +// gtk_toolbar_set_space_style( m_toolbar, GTK_TOOLBAR_SPACE_LINE ); m_separation = 5; gtk_toolbar_set_space_size( m_toolbar, m_separation ); m_hasToolAlready = FALSE; @@ -370,6 +371,28 @@ void wxToolBar::AddSeparator() gtk_toolbar_append_space( m_toolbar ); } +bool wxToolBar::DeleteTool(int toolIndex) +{ + wxNode *node = m_tools.First(); + while (node) + { + wxToolBarTool *tool = (wxToolBarTool*)node->Data(); + if (tool->m_index == toolIndex) + { + if (tool->m_control) + tool->m_control->Destroy(); + else + gtk_widget_destroy( tool->m_item ); + m_tools.DeleteNode( node ); + + return TRUE; + } + node = node->Next(); + } + + return FALSE; +} + void wxToolBar::ClearTools() { wxFAIL_MSG( wxT("wxToolBar::ClearTools not implemented") ); diff --git a/src/gtk1/stattext.cpp b/src/gtk1/stattext.cpp index 011b4b21a6..6816895a37 100644 --- a/src/gtk1/stattext.cpp +++ b/src/gtk1/stattext.cpp @@ -61,6 +61,8 @@ bool wxStaticText::Create(wxWindow *parent, // effect of changing the control size which might not be desirable wxControl::SetLabel(label); m_widget = gtk_label_new( m_label.mbc_str() ); + + gtk_label_set_line_wrap( GTK_LABEL(m_widget), FALSE ); SetFont( parent->GetFont() ); @@ -79,7 +81,7 @@ bool wxStaticText::Create(wxWindow *parent, GtkRequisition req; (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req ); - + wxSize newSize = size; if (newSize.x == -1) newSize.x = req.width; if (newSize.y == -1) newSize.y = req.height; diff --git a/src/gtk1/tbargtk.cpp b/src/gtk1/tbargtk.cpp index 9ee4df2deb..970873c7e2 100644 --- a/src/gtk1/tbargtk.cpp +++ b/src/gtk1/tbargtk.cpp @@ -178,6 +178,7 @@ bool wxToolBar::Create( wxWindow *parent, wxWindowID id, m_toolbar = GTK_TOOLBAR( gtk_toolbar_new( GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_ICONS ) ); +// gtk_toolbar_set_space_style( m_toolbar, GTK_TOOLBAR_SPACE_LINE ); m_separation = 5; gtk_toolbar_set_space_size( m_toolbar, m_separation ); m_hasToolAlready = FALSE; @@ -370,6 +371,28 @@ void wxToolBar::AddSeparator() gtk_toolbar_append_space( m_toolbar ); } +bool wxToolBar::DeleteTool(int toolIndex) +{ + wxNode *node = m_tools.First(); + while (node) + { + wxToolBarTool *tool = (wxToolBarTool*)node->Data(); + if (tool->m_index == toolIndex) + { + if (tool->m_control) + tool->m_control->Destroy(); + else + gtk_widget_destroy( tool->m_item ); + m_tools.DeleteNode( node ); + + return TRUE; + } + node = node->Next(); + } + + return FALSE; +} + void wxToolBar::ClearTools() { wxFAIL_MSG( wxT("wxToolBar::ClearTools not implemented") );