From 5fd11f09718445c5795526c393f2b2a1875f6870 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sat, 2 Oct 1999 19:43:56 +0000 Subject: [PATCH] Added test for wxTreeCtrl::GetChildrenCount() Fixed Reparent (added heaps of debug code for this) Small mods to glcanvas git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3799 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/minifram/test.cpp | 4 +++- samples/treectrl/treetest.cpp | 27 +++++++++++++++++++++++++++ samples/treectrl/treetest.h | 5 +++++ src/gtk/frame.cpp | 2 ++ src/gtk/win_gtk.c | 6 ++++++ src/gtk/window.cpp | 12 ++++++++++++ src/gtk1/frame.cpp | 2 ++ src/gtk1/win_gtk.c | 6 ++++++ src/gtk1/window.cpp | 12 ++++++++++++ utils/glcanvas/gtk/glcanvas.cpp | 4 +--- utils/glcanvas/gtk/glcanvas.h | 19 +++++++++---------- 11 files changed, 85 insertions(+), 14 deletions(-) diff --git a/samples/minifram/test.cpp b/samples/minifram/test.cpp index a6d0889355..1470996901 100644 --- a/samples/minifram/test.cpp +++ b/samples/minifram/test.cpp @@ -133,7 +133,7 @@ bool MyApp::InitToolbar(wxToolBar* toolBar) 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, "Reparent the button"); currentX += width + 5; toolBar->AddSeparator(); toolBar->AddTool(wxID_HELP, *(toolBarBitmaps[7]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Help"); @@ -155,6 +155,7 @@ bool MyApp::InitToolbar(wxToolBar* toolBar) BEGIN_EVENT_TABLE(MyMiniFrame, wxMiniFrame) EVT_CLOSE ( MyMiniFrame::OnCloseWindow) EVT_BUTTON (ID_REPARENT, MyMiniFrame::OnReparent) + EVT_MENU (wxID_PRINT, MyMiniFrame::OnReparent) END_EVENT_TABLE() MyMiniFrame::MyMiniFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos, @@ -180,6 +181,7 @@ void MyMiniFrame::OnReparent(wxCommandEvent& WXUNUSED(event)) BEGIN_EVENT_TABLE(MyMainFrame, wxFrame) EVT_CLOSE ( MyMainFrame::OnCloseWindow) EVT_BUTTON (ID_REPARENT, MyMainFrame::OnReparent) + EVT_MENU (wxID_PRINT, MyMainFrame::OnReparent) END_EVENT_TABLE() MyMainFrame::MyMainFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos, diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index 600751294e..6e8dc94fd0 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -72,6 +72,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(TreeTest_Unselect, MyFrame::OnUnselect) #endif // NO_MULTIPLE_SELECTION EVT_MENU(TreeTest_Rename, MyFrame::OnRename) + EVT_MENU(TreeTest_Count, MyFrame::OnCount) + EVT_MENU(TreeTest_CountRec, MyFrame::OnCountRec) EVT_MENU(TreeTest_Sort, MyFrame::OnSort) EVT_MENU(TreeTest_SortRev, MyFrame::OnSortRev) EVT_MENU(TreeTest_Bold, MyFrame::OnSetBold) @@ -155,6 +157,9 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) tree_menu->Append(TreeTest_DeleteChildren, "Delete &children"); tree_menu->Append(TreeTest_DeleteAll, "Delete &all items"); tree_menu->AppendSeparator(); + tree_menu->Append(TreeTest_Count, "Count children of current item"); + tree_menu->Append(TreeTest_CountRec, "Recursively count children of current item"); + tree_menu->AppendSeparator(); tree_menu->Append(TreeTest_Sort, "Sort children of current item"); tree_menu->Append(TreeTest_SortRev, "Sort in reversed order"); tree_menu->AppendSeparator(); @@ -272,6 +277,28 @@ void MyFrame::OnRename(wxCommandEvent& WXUNUSED(event)) (void)m_treeCtrl->EditLabel(item); } +void MyFrame::OnCount(wxCommandEvent& WXUNUSED(event)) +{ + wxTreeItemId item = m_treeCtrl->GetSelection(); + + CHECK_ITEM( item ); + + int i = m_treeCtrl->GetChildrenCount( item, FALSE ); + + wxLogMessage(_T("%d children"), i); +} + +void MyFrame::OnCountRec(wxCommandEvent& WXUNUSED(event)) +{ + wxTreeItemId item = m_treeCtrl->GetSelection(); + + CHECK_ITEM( item ); + + int i = m_treeCtrl->GetChildrenCount( item ); + + wxLogMessage(_T("%d children"), i); +} + void MyFrame::DoSort(bool reverse) { wxTreeItemId item = m_treeCtrl->GetSelection(); diff --git a/samples/treectrl/treetest.h b/samples/treectrl/treetest.h index 67562e087b..dc193c2954 100644 --- a/samples/treectrl/treetest.h +++ b/samples/treectrl/treetest.h @@ -130,6 +130,9 @@ public: void OnEnsureVisible(wxCommandEvent& event); + void OnCount(wxCommandEvent& event); + void OnCountRec(wxCommandEvent& event); + void OnRename(wxCommandEvent& event); void OnSort(wxCommandEvent& event) { DoSort(); } void OnSortRev(wxCommandEvent& event) { DoSort(TRUE); } @@ -161,6 +164,8 @@ enum TreeTest_About, TreeTest_Dump, TreeTest_DumpSelected, + TreeTest_Count, + TreeTest_CountRec, TreeTest_Sort, TreeTest_SortRev, TreeTest_Bold, diff --git a/src/gtk/frame.cpp b/src/gtk/frame.cpp index 3e87057d4a..20ea85ac9f 100644 --- a/src/gtk/frame.cpp +++ b/src/gtk/frame.cpp @@ -270,6 +270,8 @@ gtk_frame_realized_callback( GtkWidget *widget, wxFrame *win ) static void wxInsertChildInFrame( wxFrame* parent, wxWindow* child ) { + wxASSERT( GTK_IS_WIDGET(child->m_widget) ); + if (!parent->m_insertInClientArea) { /* these are outside the client area */ diff --git a/src/gtk/win_gtk.c b/src/gtk/win_gtk.c index 5f683d50c7..dc60934c39 100644 --- a/src/gtk/win_gtk.c +++ b/src/gtk/win_gtk.c @@ -695,6 +695,9 @@ gtk_myfixed_remove (GtkContainer *container, gtk_widget_unparent (widget); + /* security checks */ + g_return_if_fail (GTK_IS_WIDGET (widget)); + myfixed->children = g_list_remove_link (myfixed->children, children); g_list_free (children); g_free (child); @@ -702,6 +705,9 @@ gtk_myfixed_remove (GtkContainer *container, if (was_visible && GTK_WIDGET_VISIBLE (container)) gtk_widget_queue_resize (GTK_WIDGET (container)); + /* security checks */ + g_return_if_fail (GTK_IS_WIDGET (widget)); + break; } diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 67fea2e151..ade2fa716a 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -2564,20 +2564,32 @@ bool wxWindow::Reparent( wxWindowBase *newParentBase ) wxWindow *oldParent = m_parent, *newParent = (wxWindow *)newParentBase; + wxASSERT( GTK_IS_WIDGET(m_widget) ); + if ( !wxWindowBase::Reparent(newParent) ) return FALSE; + wxASSERT( GTK_IS_WIDGET(m_widget) ); + + /* prevent GTK from deleting the widget arbitrarily */ + gtk_widget_ref( m_widget ); + if (oldParent) { gtk_container_remove( GTK_CONTAINER(oldParent->m_wxwindow), m_widget ); } + wxASSERT( GTK_IS_WIDGET(m_widget) ); + if (newParent) { /* insert GTK representation */ (*(newParent->m_insertCallback))(newParent, this); } + /* reverse: prevent GTK from deleting the widget arbitrarily */ + gtk_widget_unref( m_widget ); + return TRUE; } diff --git a/src/gtk1/frame.cpp b/src/gtk1/frame.cpp index 3e87057d4a..20ea85ac9f 100644 --- a/src/gtk1/frame.cpp +++ b/src/gtk1/frame.cpp @@ -270,6 +270,8 @@ gtk_frame_realized_callback( GtkWidget *widget, wxFrame *win ) static void wxInsertChildInFrame( wxFrame* parent, wxWindow* child ) { + wxASSERT( GTK_IS_WIDGET(child->m_widget) ); + if (!parent->m_insertInClientArea) { /* these are outside the client area */ diff --git a/src/gtk1/win_gtk.c b/src/gtk1/win_gtk.c index 5f683d50c7..dc60934c39 100644 --- a/src/gtk1/win_gtk.c +++ b/src/gtk1/win_gtk.c @@ -695,6 +695,9 @@ gtk_myfixed_remove (GtkContainer *container, gtk_widget_unparent (widget); + /* security checks */ + g_return_if_fail (GTK_IS_WIDGET (widget)); + myfixed->children = g_list_remove_link (myfixed->children, children); g_list_free (children); g_free (child); @@ -702,6 +705,9 @@ gtk_myfixed_remove (GtkContainer *container, if (was_visible && GTK_WIDGET_VISIBLE (container)) gtk_widget_queue_resize (GTK_WIDGET (container)); + /* security checks */ + g_return_if_fail (GTK_IS_WIDGET (widget)); + break; } diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 67fea2e151..ade2fa716a 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -2564,20 +2564,32 @@ bool wxWindow::Reparent( wxWindowBase *newParentBase ) wxWindow *oldParent = m_parent, *newParent = (wxWindow *)newParentBase; + wxASSERT( GTK_IS_WIDGET(m_widget) ); + if ( !wxWindowBase::Reparent(newParent) ) return FALSE; + wxASSERT( GTK_IS_WIDGET(m_widget) ); + + /* prevent GTK from deleting the widget arbitrarily */ + gtk_widget_ref( m_widget ); + if (oldParent) { gtk_container_remove( GTK_CONTAINER(oldParent->m_wxwindow), m_widget ); } + wxASSERT( GTK_IS_WIDGET(m_widget) ); + if (newParent) { /* insert GTK representation */ (*(newParent->m_insertCallback))(newParent, this); } + /* reverse: prevent GTK from deleting the widget arbitrarily */ + gtk_widget_unref( m_widget ); + return TRUE; } diff --git a/utils/glcanvas/gtk/glcanvas.cpp b/utils/glcanvas/gtk/glcanvas.cpp index 6021bcec7d..a4b55c539e 100644 --- a/utils/glcanvas/gtk/glcanvas.cpp +++ b/utils/glcanvas/gtk/glcanvas.cpp @@ -242,8 +242,6 @@ bool wxGLCanvas::Create( wxWindow *parent, XFree( g_vi ); g_vi = (XVisualInfo*) NULL; -// gdk_window_set_back_pixmap( m_glWidget->window, None, 0 ); - /* we pretend to have a m_wxwindow so that PostCreation hooks up the events for expose and draw */ m_wxwindow = m_glWidget; @@ -269,10 +267,10 @@ void wxGLCanvas::OnSize(wxSizeEvent& WXUNUSED(event)) { int width, height; GetClientSize( &width, &height ); + if (m_glContext && GTK_WIDGET_REALIZED(m_glWidget) ) { SetCurrent(); -// gdk_window_set_back_pixmap( gtk_widget_get_parent_window(m_glWidget), None, 0 ); glViewport(0, 0, (GLint)width, (GLint)height ); glMatrixMode(GL_PROJECTION); diff --git a/utils/glcanvas/gtk/glcanvas.h b/utils/glcanvas/gtk/glcanvas.h index 985fb626b6..fc0d51561e 100644 --- a/utils/glcanvas/gtk/glcanvas.h +++ b/utils/glcanvas/gtk/glcanvas.h @@ -54,10 +54,7 @@ class wxGLCanvas; class wxGLContext: public wxObject { - DECLARE_CLASS(wxGLContext) - - public: - +public: wxGLContext( bool isRGB, wxWindow *win, const wxPalette& palette = wxNullPalette ); wxGLContext( bool WXUNUSED(isRGB), wxWindow *win, @@ -79,13 +76,15 @@ class wxGLContext: public wxObject inline GtkWidget* GetWidget() const { return m_widget; } inline GLXContext GetContext() const { return m_glContext; } - public: - +public: GLXContext m_glContext; GtkWidget *m_widget; wxPalette m_palette; wxWindow* m_window; + +private: + DECLARE_CLASS(wxGLContext) }; //--------------------------------------------------------------------------- @@ -94,9 +93,7 @@ class wxGLContext: public wxObject class wxGLCanvas: public wxScrolledWindow { - DECLARE_CLASS(wxGLCanvas) - - public: +public: wxGLCanvas( wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, @@ -137,7 +134,9 @@ class wxGLCanvas: public wxScrolledWindow wxGLContext *m_glContext; GtkWidget *m_glWidget; - DECLARE_EVENT_TABLE() +private: + DECLARE_EVENT_TABLE() + DECLARE_CLASS(wxGLCanvas) }; #endif -- 2.45.2