Applied patch [ 614042 ] Add wxSizer::Hide() & Show()
By Carl Godkin Also documented wxSizer::Show. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17615 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -254,9 +254,18 @@ see sample in the description of \helpref{wxBoxSizer}{wxboxsizer} if the window
|
||||
\func{void}{SetVirtualSizeHints}{\param{wxWindow* }{window}}
|
||||
|
||||
Tell the sizer to set the minimal size of the {\it window} virtual area to match the sizer's
|
||||
minimal size. For windows with managed scrollbars this will set them appropriately.
|
||||
minimal size. For windows with managed scrollbars this will set them appropriately.
|
||||
|
||||
\wxheading{See also}
|
||||
|
||||
\helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars}
|
||||
|
||||
\membersection{wxSizer::Show}\label{wxsizershow}
|
||||
|
||||
\func{void}{Show}{\param{wxWindow* }{window}, \param{bool }{show = TRUE}}
|
||||
|
||||
\func{void}{Show}{\param{wxSizer* }{sizer}, \param{bool }{show = TRUE}}
|
||||
|
||||
Shows or hides a window or sizer. To make a sizer item disappear or
|
||||
reappear, use Show() followed by Layout().
|
||||
|
||||
|
@@ -20,8 +20,8 @@ functions that take a wxTreeEvent argument.
|
||||
|
||||
\twocolwidtha{9cm}
|
||||
\begin{twocollist}\itemsep=0pt
|
||||
\twocolitem{{\bf EVT\_TREE\_BEGIN\_DRAG(id, func)}}{The user has started dragging an item with the left mouse button.}
|
||||
\twocolitem{{\bf EVT\_TREE\_BEGIN\_RDRAG(id, func)}}{The user has started dragging an item with the right mouse button.}
|
||||
\twocolitem{{\bf EVT\_TREE\_BEGIN\_DRAG(id, func)}}{The user has started dragging an item with the left mouse button. The event handler must call {\bf wxTreeEvent::Allow()} for the drag operation to continue.}
|
||||
\twocolitem{{\bf EVT\_TREE\_BEGIN\_RDRAG(id, func)}}{The user has started dragging an item with the right mouse button. The event handler must call {\bf wxTreeEvent::Allow()} for the drag operation to continue.}
|
||||
\twocolitem{{\bf EVT\_TREE\_BEGIN\_LABEL\_EDIT(id, func)}}{Begin editing a label. This can be prevented by calling \helpref{Veto()}{wxnotifyeventveto}.}
|
||||
\twocolitem{{\bf EVT\_TREE\_END\_DRAG(id, func)}}{The user has released the mouse after dragging an item.}
|
||||
\twocolitem{{\bf EVT\_TREE\_END\_LABEL\_EDIT(id, func)}}{The user has finished editing a label. This can be prevented by calling \helpref{Veto()}{wxnotifyeventveto}.}
|
||||
|
@@ -660,7 +660,7 @@ If {\it fromEnd} is TRUE, reverse search direction.
|
||||
|
||||
If {\bf caseSensitive}, comparison is case sensitive (the default).
|
||||
|
||||
Returns the index of the first item matched, or NOT\_FOUND.
|
||||
Returns the index of the first item matched, or wxNOT\_FOUND.
|
||||
|
||||
% TODO
|
||||
%\membersection{wxString::insert}\label{wxstringinsert}
|
||||
|
@@ -80,6 +80,8 @@ public:
|
||||
{ m_flag = flag; }
|
||||
void SetBorder( int border )
|
||||
{ m_border = border; }
|
||||
void Show ( bool show )
|
||||
{ m_show = show; }
|
||||
|
||||
wxWindow *GetWindow() const
|
||||
{ return m_window; }
|
||||
@@ -95,6 +97,8 @@ public:
|
||||
{ return m_flag; }
|
||||
int GetBorder() const
|
||||
{ return m_border; }
|
||||
bool IsShown() const
|
||||
{ return m_show; }
|
||||
wxObject* GetUserData()
|
||||
{ return m_userData; }
|
||||
wxPoint GetPosition()
|
||||
@@ -109,10 +113,15 @@ protected:
|
||||
int m_option;
|
||||
int m_border;
|
||||
int m_flag;
|
||||
|
||||
// If TRUE, then this item is considered in the layout
|
||||
// calculation. Otherwise, it is skipped over.
|
||||
bool m_show;
|
||||
// als: aspect ratio can always be calculated from m_size,
|
||||
// but this would cause precision loss when the window
|
||||
// is shrinked. it is safer to preserve initial value.
|
||||
float m_ratio;
|
||||
|
||||
wxObject *m_userData;
|
||||
|
||||
private:
|
||||
@@ -194,6 +203,21 @@ public:
|
||||
|
||||
void SetDimension( int x, int y, int width, int height );
|
||||
|
||||
// Manage whether individual windows or sub-sizers are considered
|
||||
// in the layout calculations or not.
|
||||
void Show( wxWindow *window, bool show = TRUE );
|
||||
void Hide( wxWindow *window )
|
||||
{ Show (window, FALSE); }
|
||||
void Show( wxSizer *sizer, bool show = TRUE );
|
||||
void Hide( wxSizer *sizer )
|
||||
{ Show (sizer, FALSE); }
|
||||
|
||||
bool IsShown( wxWindow *window );
|
||||
bool IsShown( wxSizer *sizer );
|
||||
|
||||
// Recursively call wxWindow::Show () on all sizer items.
|
||||
void ShowItems (bool show);
|
||||
|
||||
protected:
|
||||
wxSize m_size;
|
||||
wxSize m_minSize;
|
||||
|
@@ -122,6 +122,8 @@ public:
|
||||
void OnTestButton(wxCommandEvent& event);
|
||||
void OnBmpButton(wxCommandEvent& event);
|
||||
|
||||
void OnSizerCheck (wxCommandEvent &event);
|
||||
|
||||
wxListBox *m_listbox,
|
||||
*m_listboxSorted;
|
||||
#if wxUSE_CHOICE
|
||||
@@ -153,6 +155,14 @@ public:
|
||||
|
||||
wxStaticText *m_label;
|
||||
|
||||
wxBoxSizer *m_buttonSizer;
|
||||
wxButton *m_sizerBtn1;
|
||||
wxButton *m_sizerBtn2;
|
||||
wxButton *m_sizerBtn3;
|
||||
wxButton *m_sizerBtn4;
|
||||
wxBoxSizer *m_hsizer;
|
||||
wxButton *m_bigBtn;
|
||||
|
||||
private:
|
||||
wxLog *m_logTargetOld;
|
||||
|
||||
@@ -403,6 +413,13 @@ const int ID_BITMAP_BTN = 192;
|
||||
|
||||
const int ID_CHANGE_COLOUR = 200;
|
||||
|
||||
const int ID_SIZER_CHECK1 = 201;
|
||||
const int ID_SIZER_CHECK2 = 202;
|
||||
const int ID_SIZER_CHECK3 = 203;
|
||||
const int ID_SIZER_CHECK4 = 204;
|
||||
const int ID_SIZER_CHECK14 = 205;
|
||||
const int ID_SIZER_CHECKBIG = 206;
|
||||
|
||||
BEGIN_EVENT_TABLE(MyPanel, wxPanel)
|
||||
EVT_SIZE ( MyPanel::OnSize)
|
||||
EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, MyPanel::OnPageChanging)
|
||||
@@ -465,6 +482,14 @@ EVT_CHECKBOX (ID_CHANGE_COLOUR, MyPanel::OnChangeColour)
|
||||
EVT_BUTTON (ID_BUTTON_TEST1, MyPanel::OnTestButton)
|
||||
EVT_BUTTON (ID_BUTTON_TEST2, MyPanel::OnTestButton)
|
||||
EVT_BUTTON (ID_BITMAP_BTN, MyPanel::OnBmpButton)
|
||||
|
||||
EVT_CHECKBOX (ID_SIZER_CHECK1, MyPanel::OnSizerCheck)
|
||||
EVT_CHECKBOX (ID_SIZER_CHECK2, MyPanel::OnSizerCheck)
|
||||
EVT_CHECKBOX (ID_SIZER_CHECK3, MyPanel::OnSizerCheck)
|
||||
EVT_CHECKBOX (ID_SIZER_CHECK4, MyPanel::OnSizerCheck)
|
||||
EVT_CHECKBOX (ID_SIZER_CHECK14, MyPanel::OnSizerCheck)
|
||||
EVT_CHECKBOX (ID_SIZER_CHECKBIG, MyPanel::OnSizerCheck)
|
||||
|
||||
END_EVENT_TABLE()
|
||||
|
||||
BEGIN_EVENT_TABLE(MyButton, wxButton)
|
||||
@@ -849,11 +874,53 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
|
||||
panel = new wxPanel(m_notebook);
|
||||
panel->SetAutoLayout( TRUE );
|
||||
|
||||
wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
|
||||
wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
sizer->Add( new wxButton(panel, -1, "Test Button &1" ), 3, wxALL, 10 );
|
||||
sizer->Add( 20,20, 1 );
|
||||
sizer->Add( new wxButton(panel, -1, "Multiline\nbutton" ), 3, wxGROW|wxALL, 10 );
|
||||
wxStaticBoxSizer *csizer =
|
||||
new wxStaticBoxSizer (new wxStaticBox (panel, -1, "Show Buttons"),
|
||||
wxHORIZONTAL );
|
||||
|
||||
wxCheckBox *check1, *check2, *check3, *check4, *check14, *checkBig;
|
||||
check1 = new wxCheckBox (panel, ID_SIZER_CHECK1, "1");
|
||||
check1->SetValue (TRUE);
|
||||
csizer->Add (check1);
|
||||
check2 = new wxCheckBox (panel, ID_SIZER_CHECK2, "2");
|
||||
check2->SetValue (TRUE);
|
||||
csizer->Add (check2);
|
||||
check3 = new wxCheckBox (panel, ID_SIZER_CHECK3, "3");
|
||||
check3->SetValue (TRUE);
|
||||
csizer->Add (check3);
|
||||
check4 = new wxCheckBox (panel, ID_SIZER_CHECK4, "4");
|
||||
check4->SetValue (TRUE);
|
||||
csizer->Add (check4);
|
||||
check14 = new wxCheckBox (panel, ID_SIZER_CHECK14, "1-4");
|
||||
check14->SetValue (TRUE);
|
||||
csizer->Add (check14);
|
||||
checkBig = new wxCheckBox (panel, ID_SIZER_CHECKBIG, "Big");
|
||||
checkBig->SetValue (TRUE);
|
||||
csizer->Add (checkBig);
|
||||
|
||||
sizer->Add (csizer);
|
||||
|
||||
m_hsizer = new wxBoxSizer( wxHORIZONTAL );
|
||||
|
||||
m_buttonSizer = new wxBoxSizer (wxVERTICAL);
|
||||
|
||||
m_sizerBtn1 = new wxButton(panel, -1, "Test Button &1" );
|
||||
m_buttonSizer->Add( m_sizerBtn1, 0, wxALL, 10 );
|
||||
m_sizerBtn2 = new wxButton(panel, -1, "Test Button &2" );
|
||||
m_buttonSizer->Add( m_sizerBtn2, 0, wxALL, 10 );
|
||||
m_sizerBtn3 = new wxButton(panel, -1, "Test Button &3" );
|
||||
m_buttonSizer->Add( m_sizerBtn3, 0, wxALL, 10 );
|
||||
m_sizerBtn4 = new wxButton(panel, -1, "Test Button &4" );
|
||||
m_buttonSizer->Add( m_sizerBtn4, 0, wxALL, 10 );
|
||||
|
||||
m_hsizer->Add (m_buttonSizer);
|
||||
m_hsizer->Add( 20,20, 1 );
|
||||
m_bigBtn = new wxButton(panel, -1, "Multiline\nbutton" );
|
||||
m_hsizer->Add( m_bigBtn , 3, wxGROW|wxALL, 10 );
|
||||
|
||||
sizer->Add (m_hsizer, 1, wxGROW);
|
||||
|
||||
panel->SetSizer( sizer );
|
||||
|
||||
@@ -1404,6 +1471,37 @@ void MyPanel::OnShowProgress( wxCommandEvent& WXUNUSED(event) )
|
||||
|
||||
#endif // wxUSE_SPINBTN
|
||||
|
||||
void MyPanel::OnSizerCheck( wxCommandEvent &event)
|
||||
{
|
||||
switch (event.GetId ()) {
|
||||
case ID_SIZER_CHECK1:
|
||||
m_buttonSizer->Show (m_sizerBtn1, event.IsChecked ());
|
||||
m_buttonSizer->Layout ();
|
||||
break;
|
||||
case ID_SIZER_CHECK2:
|
||||
m_buttonSizer->Show (m_sizerBtn2, event.IsChecked ());
|
||||
m_buttonSizer->Layout ();
|
||||
break;
|
||||
case ID_SIZER_CHECK3:
|
||||
m_buttonSizer->Show (m_sizerBtn3, event.IsChecked ());
|
||||
m_buttonSizer->Layout ();
|
||||
break;
|
||||
case ID_SIZER_CHECK4:
|
||||
m_buttonSizer->Show (m_sizerBtn4, event.IsChecked ());
|
||||
m_buttonSizer->Layout ();
|
||||
break;
|
||||
case ID_SIZER_CHECK14:
|
||||
m_hsizer->Show (m_buttonSizer, event.IsChecked ());
|
||||
m_hsizer->Layout ();
|
||||
break;
|
||||
case ID_SIZER_CHECKBIG:
|
||||
m_hsizer->Show (m_bigBtn, event.IsChecked ());
|
||||
m_hsizer->Layout ();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MyPanel::~MyPanel()
|
||||
{
|
||||
//wxLog::RemoveTraceMask(_T("focus"));
|
||||
|
@@ -50,6 +50,7 @@ wxSizerItem::wxSizerItem( int width, int height, int option, int flag, int borde
|
||||
m_option = option;
|
||||
m_border = border;
|
||||
m_flag = flag;
|
||||
m_show = TRUE; // Cannot be changed
|
||||
m_userData = userData;
|
||||
|
||||
// minimal size is the initial size
|
||||
@@ -69,6 +70,7 @@ wxSizerItem::wxSizerItem( wxWindow *window, int option, int flag, int border, wx
|
||||
m_option = option;
|
||||
m_border = border;
|
||||
m_flag = flag;
|
||||
m_show = TRUE;
|
||||
m_userData = userData;
|
||||
|
||||
// minimal size is the initial size
|
||||
@@ -88,6 +90,7 @@ wxSizerItem::wxSizerItem( wxSizer *sizer, int option, int flag, int border, wxOb
|
||||
m_option = option;
|
||||
m_border = border;
|
||||
m_flag = flag;
|
||||
m_show = TRUE;
|
||||
m_userData = userData;
|
||||
|
||||
// minimal size is calculated later
|
||||
@@ -638,6 +641,81 @@ bool wxSizer::DoSetItemMinSize( int pos, int width, int height )
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxSizer::Show (wxWindow *window, bool show)
|
||||
{
|
||||
wxNode *node = m_children.GetFirst();
|
||||
while (node) {
|
||||
wxSizerItem *item = (wxSizerItem*) node->Data();
|
||||
|
||||
if (item->IsWindow () && item->GetWindow () == window) {
|
||||
item->Show (show);
|
||||
window->Show (show);
|
||||
return;
|
||||
}
|
||||
node = node->Next();
|
||||
}
|
||||
}
|
||||
|
||||
void wxSizer::Show (wxSizer *sizer, bool show)
|
||||
{
|
||||
wxNode *node = m_children.GetFirst();
|
||||
while (node) {
|
||||
wxSizerItem *item = (wxSizerItem*) node->Data();
|
||||
|
||||
if (item->IsSizer () && item->GetSizer () == sizer) {
|
||||
item->Show (show);
|
||||
sizer->ShowItems (show);
|
||||
return;
|
||||
}
|
||||
node = node->Next();
|
||||
}
|
||||
}
|
||||
|
||||
void wxSizer::ShowItems (bool show)
|
||||
{
|
||||
wxNode *node = m_children.GetFirst();
|
||||
while (node) {
|
||||
wxSizerItem *item = (wxSizerItem*) node->Data();
|
||||
|
||||
if (item->IsWindow ())
|
||||
item->GetWindow()->Show (show);
|
||||
else if (item->IsSizer ())
|
||||
item->GetSizer ()->ShowItems (show);
|
||||
|
||||
node = node->Next();
|
||||
}
|
||||
}
|
||||
|
||||
bool wxSizer::IsShown (wxWindow *window)
|
||||
{
|
||||
wxNode *node = m_children.GetFirst();
|
||||
while (node) {
|
||||
wxSizerItem *item = (wxSizerItem*) node->Data();
|
||||
|
||||
if (item->IsWindow () && item->GetWindow () == window) {
|
||||
return item->IsShown ();
|
||||
}
|
||||
node = node->Next();
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxSizer::IsShown (wxSizer *sizer)
|
||||
{
|
||||
wxNode *node = m_children.GetFirst();
|
||||
while (node) {
|
||||
wxSizerItem *item = (wxSizerItem*) node->Data();
|
||||
|
||||
if (item->IsSizer () && item->GetSizer () == sizer) {
|
||||
return item->IsShown ();
|
||||
}
|
||||
node = node->Next();
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// wxGridSizer
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -980,6 +1058,7 @@ void wxBoxSizer::RecalcSizes()
|
||||
while (node)
|
||||
{
|
||||
wxSizerItem *item = (wxSizerItem*) node->Data();
|
||||
if (item->IsShown ()) {
|
||||
|
||||
int weight = 1;
|
||||
if (item->GetOption())
|
||||
@@ -1037,6 +1116,7 @@ void wxBoxSizer::RecalcSizes()
|
||||
|
||||
pt.x += width;
|
||||
}
|
||||
}
|
||||
|
||||
node = node->Next();
|
||||
}
|
||||
@@ -1059,7 +1139,7 @@ wxSize wxBoxSizer::CalcMin()
|
||||
while (node)
|
||||
{
|
||||
wxSizerItem *item = (wxSizerItem*) node->Data();
|
||||
if (item->GetOption() != 0)
|
||||
if (item->IsShown () && item->GetOption() != 0)
|
||||
{
|
||||
int stretch = item->GetOption();
|
||||
wxSize size( item->CalcMin() );
|
||||
@@ -1079,7 +1159,7 @@ wxSize wxBoxSizer::CalcMin()
|
||||
while (node)
|
||||
{
|
||||
wxSizerItem *item = (wxSizerItem*) node->Data();
|
||||
|
||||
if (item->IsShown ()) {
|
||||
m_stretchable += item->GetOption();
|
||||
|
||||
wxSize size( item->CalcMin() );
|
||||
@@ -1115,7 +1195,7 @@ wxSize wxBoxSizer::CalcMin()
|
||||
m_fixedHeight = wxMax( m_fixedHeight, size.y );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
node = node->Next();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user