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:
@@ -36,30 +36,48 @@
|
|||||||
#include "bitmaps/help.xpm"
|
#include "bitmaps/help.xpm"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// start wxWindows
|
||||||
|
|
||||||
IMPLEMENT_APP(MyApp)
|
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
|
// The `main program' equivalent, creating the windows and returning the
|
||||||
// main frame
|
// main frame
|
||||||
bool MyApp::OnInit(void)
|
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
|
// Create the main frame window
|
||||||
MyFrame* frame = new MyFrame((wxFrame *) NULL, -1, (const wxString) "wxMiniFrame sample",
|
main_frame = new MyMainFrame((wxFrame *) NULL, -1, "wxFrame sample",
|
||||||
wxPoint(100, 100), wxSize(205, 45));
|
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__
|
#ifdef __WXMSW__
|
||||||
frame->SetIcon(wxIcon("mondrian"));
|
main_frame->SetIcon(wxIcon("mondrian"));
|
||||||
|
mini_frame->SetIcon(wxIcon("mondrian"));
|
||||||
#else
|
#else
|
||||||
frame->SetIcon( wxIcon(mondrian_xpm) );
|
main_frame->SetIcon( wxIcon(mondrian_xpm) );
|
||||||
|
mini_frame->SetIcon( wxIcon(mondrian_xpm) );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Create the toolbar
|
SetTopWindow(main_frame);
|
||||||
frame->CreateToolBar(wxNO_BORDER|wxHORIZONTAL|wxTB_FLAT, ID_TOOLBAR);
|
|
||||||
|
|
||||||
InitToolbar(frame->GetToolBar());
|
main_frame->Show(TRUE);
|
||||||
|
mini_frame->Show(TRUE);
|
||||||
frame->Show(TRUE);
|
|
||||||
SetTopWindow(frame);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -130,20 +148,50 @@ bool MyApp::InitToolbar(wxToolBar* toolBar)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(MyFrame, wxMiniFrame)
|
// MyMiniFrame
|
||||||
EVT_CLOSE(MyFrame::OnCloseWindow)
|
|
||||||
|
BEGIN_EVENT_TABLE(MyMiniFrame, wxMiniFrame)
|
||||||
|
EVT_CLOSE ( MyMiniFrame::OnCloseWindow)
|
||||||
|
EVT_BUTTON (ID_REPARENT, MyMiniFrame::OnReparent)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
// Define my frame constructor
|
MyMiniFrame::MyMiniFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos,
|
||||||
MyFrame::MyFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos,
|
|
||||||
const wxSize& size ) :
|
const wxSize& size ) :
|
||||||
wxMiniFrame(parent, id, title, pos, size )
|
wxMiniFrame(parent, id, title, pos, size )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// - must delete all frames except for the main one.
|
void MyMiniFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
|
||||||
void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
|
|
||||||
{
|
{
|
||||||
Destroy();
|
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);
|
bool InitToolbar(wxToolBar* toolBar);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define a new frame
|
// Define a new mini frame
|
||||||
class MyFrame: public wxMiniFrame
|
class MyMiniFrame: public wxMiniFrame
|
||||||
{
|
{
|
||||||
public:
|
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 );
|
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize );
|
||||||
|
|
||||||
void OnCloseWindow(wxCloseEvent& event);
|
void OnCloseWindow(wxCloseEvent& event);
|
||||||
|
void OnReparent(wxCommandEvent& event);
|
||||||
|
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
|
};
|
||||||
|
|
||||||
|
// 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()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ID_TOOLBAR 500
|
#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 */
|
/* always wrap words */
|
||||||
gtk_text_set_word_wrap( GTK_TEXT(m_text), TRUE );
|
gtk_text_set_word_wrap( GTK_TEXT(m_text), TRUE );
|
||||||
|
|
||||||
/* put the horizontal scrollbar in the lower left hand corner */
|
/* put the horizontal scrollbar in the lower left hand corner */
|
||||||
if (bHasHScrollbar)
|
if (bHasHScrollbar)
|
||||||
{
|
{
|
||||||
GtkWidget *hscrollbar = gtk_hscrollbar_new(GTK_TEXT(m_text)->hadj);
|
GtkWidget *hscrollbar = gtk_hscrollbar_new(GTK_TEXT(m_text)->hadj);
|
||||||
GTK_WIDGET_UNSET_FLAGS( hscrollbar, GTK_CAN_FOCUS );
|
GTK_WIDGET_UNSET_FLAGS( hscrollbar, GTK_CAN_FOCUS );
|
||||||
gtk_table_attach(GTK_TABLE(m_widget), hscrollbar, 0, 1, 1, 2,
|
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,
|
GTK_FILL,
|
||||||
0, 0);
|
0, 0);
|
||||||
gtk_widget_show(hscrollbar);
|
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 );
|
gtk_text_set_line_wrap( GTK_TEXT(m_text), FALSE );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* finally, put the vertical scrollbar in the upper right corner */
|
/* finally, put the vertical scrollbar in the upper right corner */
|
||||||
m_vScrollbar = gtk_vscrollbar_new( GTK_TEXT(m_text)->vadj );
|
m_vScrollbar = gtk_vscrollbar_new( GTK_TEXT(m_text)->vadj );
|
||||||
GTK_WIDGET_UNSET_FLAGS( m_vScrollbar, GTK_CAN_FOCUS );
|
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") );
|
wxCHECK_MSG( (m_widget != NULL), (wxWindow*) NULL, _T("invalid window") );
|
||||||
|
|
||||||
gtk_widget_unparent( m_widget );
|
wxWindow *oldParent = m_parent;
|
||||||
|
|
||||||
if ( !wxWindowBase::Reparent(newParent) )
|
if ( !wxWindowBase::Reparent(newParent) )
|
||||||
return FALSE;
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -161,13 +161,14 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
|
|||||||
|
|
||||||
/* always wrap words */
|
/* always wrap words */
|
||||||
gtk_text_set_word_wrap( GTK_TEXT(m_text), TRUE );
|
gtk_text_set_word_wrap( GTK_TEXT(m_text), TRUE );
|
||||||
|
|
||||||
/* put the horizontal scrollbar in the lower left hand corner */
|
/* put the horizontal scrollbar in the lower left hand corner */
|
||||||
if (bHasHScrollbar)
|
if (bHasHScrollbar)
|
||||||
{
|
{
|
||||||
GtkWidget *hscrollbar = gtk_hscrollbar_new(GTK_TEXT(m_text)->hadj);
|
GtkWidget *hscrollbar = gtk_hscrollbar_new(GTK_TEXT(m_text)->hadj);
|
||||||
GTK_WIDGET_UNSET_FLAGS( hscrollbar, GTK_CAN_FOCUS );
|
GTK_WIDGET_UNSET_FLAGS( hscrollbar, GTK_CAN_FOCUS );
|
||||||
gtk_table_attach(GTK_TABLE(m_widget), hscrollbar, 0, 1, 1, 2,
|
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,
|
GTK_FILL,
|
||||||
0, 0);
|
0, 0);
|
||||||
gtk_widget_show(hscrollbar);
|
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 );
|
gtk_text_set_line_wrap( GTK_TEXT(m_text), FALSE );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* finally, put the vertical scrollbar in the upper right corner */
|
/* finally, put the vertical scrollbar in the upper right corner */
|
||||||
m_vScrollbar = gtk_vscrollbar_new( GTK_TEXT(m_text)->vadj );
|
m_vScrollbar = gtk_vscrollbar_new( GTK_TEXT(m_text)->vadj );
|
||||||
GTK_WIDGET_UNSET_FLAGS( m_vScrollbar, GTK_CAN_FOCUS );
|
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") );
|
wxCHECK_MSG( (m_widget != NULL), (wxWindow*) NULL, _T("invalid window") );
|
||||||
|
|
||||||
gtk_widget_unparent( m_widget );
|
wxWindow *oldParent = m_parent;
|
||||||
|
|
||||||
if ( !wxWindowBase::Reparent(newParent) )
|
if ( !wxWindowBase::Reparent(newParent) )
|
||||||
return FALSE;
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user