From 8ce63e9d6604178f8c13e6a0e9bb33c3800a0c28 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Mon, 31 May 1999 17:04:50 +0000 Subject: [PATCH] Implemented Reparent() and added test for it to minifram sample. Fixed one out of two window resizing bugs in multi-line text ctrl. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2602 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/minifram/test.cpp | 82 +++++++++++++++++++++++++++++++-------- samples/minifram/test.h | 21 ++++++++-- src/gtk/textctrl.cpp | 6 ++- src/gtk/window.cpp | 15 ++++++- src/gtk1/textctrl.cpp | 6 ++- src/gtk1/window.cpp | 15 ++++++- 6 files changed, 117 insertions(+), 28 deletions(-) diff --git a/samples/minifram/test.cpp b/samples/minifram/test.cpp index 5fe386612a..e7ee047849 100644 --- a/samples/minifram/test.cpp +++ b/samples/minifram/test.cpp @@ -36,30 +36,48 @@ #include "bitmaps/help.xpm" #endif +// start wxWindows + IMPLEMENT_APP(MyApp) +// globas + +MyMainFrame *main_frame = (MyMainFrame*) NULL; +MyMiniFrame *mini_frame = (MyMiniFrame*) NULL; +wxButton *button = (wxButton*) NULL; // The `main program' equivalent, creating the windows and returning the // main frame bool MyApp::OnInit(void) { + // Create the mini frame window + mini_frame = new MyMiniFrame((wxFrame *) NULL, -1, "wxMiniFrame sample", + wxPoint(100, 100), wxSize(205, 100)); + + mini_frame->CreateToolBar(wxNO_BORDER|wxHORIZONTAL|wxTB_FLAT, ID_TOOLBAR); + InitToolbar(mini_frame->GetToolBar()); + // Create the main frame window - MyFrame* frame = new MyFrame((wxFrame *) NULL, -1, (const wxString) "wxMiniFrame sample", - wxPoint(100, 100), wxSize(205, 45)); + main_frame = new MyMainFrame((wxFrame *) NULL, -1, "wxFrame sample", + wxPoint(100, 100), wxSize(300, 200)); + + main_frame->CreateToolBar(wxNO_BORDER|wxHORIZONTAL, ID_TOOLBAR); + InitToolbar(main_frame->GetToolBar()); + + button = new wxButton( main_frame, ID_REPARENT, "Press to reparent!" ); #ifdef __WXMSW__ - frame->SetIcon(wxIcon("mondrian")); + main_frame->SetIcon(wxIcon("mondrian")); + mini_frame->SetIcon(wxIcon("mondrian")); #else - frame->SetIcon( wxIcon(mondrian_xpm) ); + main_frame->SetIcon( wxIcon(mondrian_xpm) ); + mini_frame->SetIcon( wxIcon(mondrian_xpm) ); #endif - // Create the toolbar - frame->CreateToolBar(wxNO_BORDER|wxHORIZONTAL|wxTB_FLAT, ID_TOOLBAR); - - InitToolbar(frame->GetToolBar()); - - frame->Show(TRUE); - SetTopWindow(frame); + SetTopWindow(main_frame); + + main_frame->Show(TRUE); + mini_frame->Show(TRUE); return TRUE; } @@ -130,20 +148,50 @@ bool MyApp::InitToolbar(wxToolBar* toolBar) return TRUE; } -BEGIN_EVENT_TABLE(MyFrame, wxMiniFrame) - EVT_CLOSE(MyFrame::OnCloseWindow) +// MyMiniFrame + +BEGIN_EVENT_TABLE(MyMiniFrame, wxMiniFrame) + EVT_CLOSE ( MyMiniFrame::OnCloseWindow) + EVT_BUTTON (ID_REPARENT, MyMiniFrame::OnReparent) END_EVENT_TABLE() -// Define my frame constructor -MyFrame::MyFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos, +MyMiniFrame::MyMiniFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size ) : wxMiniFrame(parent, id, title, pos, size ) { } -// - must delete all frames except for the main one. -void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) +void MyMiniFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) { Destroy(); } +void MyMiniFrame::OnReparent(wxCommandEvent& WXUNUSED(event)) +{ + button->Reparent( main_frame ); +} + +// MyMainFrame + +BEGIN_EVENT_TABLE(MyMainFrame, wxFrame) + EVT_CLOSE ( MyMainFrame::OnCloseWindow) + EVT_BUTTON (ID_REPARENT, MyMainFrame::OnReparent) +END_EVENT_TABLE() + +MyMainFrame::MyMainFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos, + const wxSize& size ) : + wxFrame(parent, id, title, pos, size ) +{ +} + +void MyMainFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) +{ + Destroy(); +} + +void MyMainFrame::OnReparent(wxCommandEvent& WXUNUSED(event)) +{ + button->Reparent( mini_frame ); +} + + diff --git a/samples/minifram/test.h b/samples/minifram/test.h index db0f7dc5da..f228439556 100644 --- a/samples/minifram/test.h +++ b/samples/minifram/test.h @@ -19,17 +19,32 @@ class MyApp: public wxApp bool InitToolbar(wxToolBar* toolBar); }; +// Define a new mini frame +class MyMiniFrame: public wxMiniFrame +{ +public: + MyMiniFrame(wxFrame *parent, wxWindowID id = -1, const wxString& title = "wxToolBar Sample", + const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize ); + + void OnCloseWindow(wxCloseEvent& event); + void OnReparent(wxCommandEvent& event); + +DECLARE_EVENT_TABLE() +}; + // Define a new frame -class MyFrame: public wxMiniFrame +class MyMainFrame: public wxFrame { public: - MyFrame(wxFrame *parent, wxWindowID id = -1, const wxString& title = "wxToolBar Sample", + MyMainFrame(wxFrame *parent, wxWindowID id = -1, const wxString& title = "wxToolBar Sample", const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize ); void OnCloseWindow(wxCloseEvent& event); + void OnReparent(wxCommandEvent& event); DECLARE_EVENT_TABLE() }; -#define ID_TOOLBAR 500 +#define ID_TOOLBAR 500 +#define ID_REPARENT 501 diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index e5c9c881a2..73293accf3 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -158,16 +158,17 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK), (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK), 0, 0); - + /* always wrap words */ gtk_text_set_word_wrap( GTK_TEXT(m_text), TRUE ); + /* put the horizontal scrollbar in the lower left hand corner */ if (bHasHScrollbar) { GtkWidget *hscrollbar = gtk_hscrollbar_new(GTK_TEXT(m_text)->hadj); GTK_WIDGET_UNSET_FLAGS( hscrollbar, GTK_CAN_FOCUS ); gtk_table_attach(GTK_TABLE(m_widget), hscrollbar, 0, 1, 1, 2, - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), + (GtkAttachOptions)(GTK_EXPAND | GTK_FILL | GTK_SHRINK), GTK_FILL, 0, 0); gtk_widget_show(hscrollbar); @@ -177,6 +178,7 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, gtk_text_set_line_wrap( GTK_TEXT(m_text), FALSE ); #endif } + /* finally, put the vertical scrollbar in the upper right corner */ m_vScrollbar = gtk_vscrollbar_new( GTK_TEXT(m_text)->vadj ); GTK_WIDGET_UNSET_FLAGS( m_vScrollbar, GTK_CAN_FOCUS ); diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 71396ae3b4..01bf2f6a9b 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -2383,12 +2383,23 @@ bool wxWindow::AcceptsFocus() const bool wxWindow::Reparent( wxWindow *newParent ) { wxCHECK_MSG( (m_widget != NULL), (wxWindow*) NULL, _T("invalid window") ); - - gtk_widget_unparent( m_widget ); + + wxWindow *oldParent = m_parent; if ( !wxWindowBase::Reparent(newParent) ) return FALSE; + if (oldParent) + { + gtk_container_remove( GTK_CONTAINER(oldParent->m_wxwindow), m_widget ); + } + + if (newParent) + { + /* insert GTK representation */ + (*(newParent->m_insertCallback))(newParent, this); + } + return TRUE; } diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index e5c9c881a2..73293accf3 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -158,16 +158,17 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK), (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK), 0, 0); - + /* always wrap words */ gtk_text_set_word_wrap( GTK_TEXT(m_text), TRUE ); + /* put the horizontal scrollbar in the lower left hand corner */ if (bHasHScrollbar) { GtkWidget *hscrollbar = gtk_hscrollbar_new(GTK_TEXT(m_text)->hadj); GTK_WIDGET_UNSET_FLAGS( hscrollbar, GTK_CAN_FOCUS ); gtk_table_attach(GTK_TABLE(m_widget), hscrollbar, 0, 1, 1, 2, - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), + (GtkAttachOptions)(GTK_EXPAND | GTK_FILL | GTK_SHRINK), GTK_FILL, 0, 0); gtk_widget_show(hscrollbar); @@ -177,6 +178,7 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, gtk_text_set_line_wrap( GTK_TEXT(m_text), FALSE ); #endif } + /* finally, put the vertical scrollbar in the upper right corner */ m_vScrollbar = gtk_vscrollbar_new( GTK_TEXT(m_text)->vadj ); GTK_WIDGET_UNSET_FLAGS( m_vScrollbar, GTK_CAN_FOCUS ); diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 71396ae3b4..01bf2f6a9b 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -2383,12 +2383,23 @@ bool wxWindow::AcceptsFocus() const bool wxWindow::Reparent( wxWindow *newParent ) { wxCHECK_MSG( (m_widget != NULL), (wxWindow*) NULL, _T("invalid window") ); - - gtk_widget_unparent( m_widget ); + + wxWindow *oldParent = m_parent; if ( !wxWindowBase::Reparent(newParent) ) return FALSE; + if (oldParent) + { + gtk_container_remove( GTK_CONTAINER(oldParent->m_wxwindow), m_widget ); + } + + if (newParent) + { + /* insert GTK representation */ + (*(newParent->m_insertCallback))(newParent, this); + } + return TRUE; } -- 2.45.2