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
This commit is contained in:
parent
02e8b87f6f
commit
8ce63e9d66
@ -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);
|
||||
SetTopWindow(main_frame);
|
||||
|
||||
InitToolbar(frame->GetToolBar());
|
||||
|
||||
frame->Show(TRUE);
|
||||
SetTopWindow(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 );
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,17 +19,32 @@ class MyApp: public wxApp
|
||||
bool InitToolbar(wxToolBar* toolBar);
|
||||
};
|
||||
|
||||
// Define a new frame
|
||||
class MyFrame: public wxMiniFrame
|
||||
// Define a new mini frame
|
||||
class MyMiniFrame: public wxMiniFrame
|
||||
{
|
||||
public:
|
||||
MyFrame(wxFrame *parent, wxWindowID id = -1, const wxString& title = "wxToolBar Sample",
|
||||
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 ID_TOOLBAR 500
|
||||
// Define a new frame
|
||||
class MyMainFrame: public wxFrame
|
||||
{
|
||||
public:
|
||||
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_REPARENT 501
|
||||
|
||||
|
@ -161,13 +161,14 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
|
||||
|
||||
/* 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 );
|
||||
|
@ -2384,11 +2384,22 @@ 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;
|
||||
}
|
||||
|
||||
|
@ -161,13 +161,14 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
|
||||
|
||||
/* 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 );
|
||||
|
@ -2384,11 +2384,22 @@ 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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user