Completed wxBox,

Changed a few defines in defs.h, most importantly,
    wxCENTRE is now 1


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3324 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 1999-08-09 11:27:37 +00:00
parent 447a039fa3
commit d597fcb781
4 changed files with 261 additions and 259 deletions

View File

@ -443,7 +443,8 @@ enum
wxMOTIF_X, // OSF Motif 1.x.x
wxCOSE_X, // OSF Common Desktop Environment
wxNEXTSTEP, // NeXTStep
wxMACINTOSH, // Apple System 7
wxMACINTOSH, // Apple System 7 and 8
wxBEOS, // BeOS
wxGTK, // GTK on X
wxGTK_WIN32, // GTK on Win32
wxGTK_OS2, // GTK on OS/2
@ -578,6 +579,67 @@ enum
#define wxINT32_SWAP_ON_BE(val) (val)
#endif
// ----------------------------------------------------------------------------
// Geometric flags
// ----------------------------------------------------------------------------
enum wxGeometryCentre
{
wxCENTRE = 0x0001,
wxCENTER = wxCENTRE
};
// centering into frame rather than screen (obsolete)
#define wxCENTER_FRAME 0x0000
// centre on screen rather than parent
#define wxCENTRE_ON_SCREEN 0x0002
#define wxCENTER_ON_SCREEN wxCENTRE_ON_SCREEN
enum wxOrientation
{
wxHORIZONTAL = 0x0004,
wxVERTICAL = 0x0008,
wxBOTH = (wxVERTICAL | wxHORIZONTAL)
};
enum wxDirection
{
wxLEFT = 0x0010,
wxRIGHT = 0x0020,
wxUP = 0x0040,
wxDOWN = 0x0080,
wxTOP = wxUP,
wxBOTTOM = wxDOWN,
wxNORTH = wxUP,
wxSOUTH = wxDOWN,
wxWEST = wxLEFT,
wxEAST = wxRIGHT,
wxALL = (wxUP | wxDOWN | wxRIGHT | wxLEFT)
};
enum wxAlignment
{
wxALIGN_NOT = 0x0000,
wxALIGN_CENTER = 0x0100,
wxALIGN_CENTRE = wxALIGN_CENTER,
wxALIGN_LEFT = wxALIGN_NOT,
wxALIGN_TOP = wxALIGN_NOT,
wxALIGN_RIGHT = 0x0200,
wxALIGN_BOTTOM = 0x0400
};
enum wxStretch
{
wxSTRETCH_NOT = 0x0000,
wxSHRINK = 0x1000,
wxGROW = 0x2000,
wxEXPAND = wxGROW
};
// ----------------------------------------------------------------------------
// Window style flags
// ----------------------------------------------------------------------------
@ -715,13 +777,7 @@ enum
* Apply to all panel items
*/
#define wxCOLOURED 0x0800
// Alignment for panel item labels: replaces characters with zeros
// when creating label, so spaces can be included in string for alignment.
#define wxFIXED_LENGTH 0x0400
#define wxALIGN_LEFT 0x0000
#define wxALIGN_CENTER 0x0100
#define wxALIGN_CENTRE 0x0100
#define wxALIGN_RIGHT 0x0200
/*
* Styles for wxListBox
@ -920,33 +976,32 @@ enum
* values do not correspond to the return values of the dialogs (for
* those values, look at the wxID_XXX defines).
*/
#define wxOK 0x00000001
#define wxYES_NO 0x00000002
#define wxCANCEL 0x00000004
#define wxYES 0x00000008
#define wxNO 0x00000010
#define wxNO_DEFAULT 0x00000020
// wxCENTRE already defined as 0x00000001
#define wxOK 0x00000004
#define wxYES_NO 0x00000008
#define wxCANCEL 0x00000010
#define wxYES 0x00000020
#define wxNO 0x00000040
#define wxNO_DEFAULT 0x00000080
#define wxYES_DEFAULT 0x00000000 // has no effect
#define wxICON_EXCLAMATION 0x00000040
#define wxICON_HAND 0x00000080
#define wxICON_EXCLAMATION 0x00000100
#define wxICON_HAND 0x00000200
#define wxICON_WARNING wxICON_EXCLAMATION
#define wxICON_ERROR wxICON_HAND
#define wxICON_QUESTION 0x00000100
#define wxICON_INFORMATION 0x00000200
#define wxICON_QUESTION 0x00000400
#define wxICON_INFORMATION 0x00000800
#define wxICON_STOP wxICON_HAND
#define wxICON_ASTERISK wxICON_INFORMATION
#define wxICON_MASK (0x00000040|0x00000080|0x00000100|0x00000200)
#define wxICON_MASK (0x00000100|0x00000200|0x00000400|0x00000800)
#define wxCENTRE 0x00000400
#define wxCENTER wxCENTRE
#define wxFORWARD 0x00000800
#define wxBACKWARD 0x00001000
#define wxRESET 0x00002000
#define wxHELP 0x00004000
#define wxMORE 0x00008000
#define wxSETUP 0x00010000
#define wxFORWARD 0x00001000
#define wxBACKWARD 0x00002000
#define wxRESET 0x00004000
#define wxHELP 0x00008000
#define wxMORE 0x00010000
#define wxSETUP 0x00020000
// ----------------------------------------------------------------------------
// standard IDs
@ -1008,33 +1063,6 @@ enum
#define wxID_HIGHEST 5999
// ----------------------------------------------------------------------------
// Orientations and directions
// ----------------------------------------------------------------------------
enum wxOrientation
{
wxHORIZONTAL = 0x0001,
wxVERTICAL = 0x0002,
wxBOTH = (wxVERTICAL | wxHORIZONTAL)
};
enum wxDirection
{
wxLEFT = 0x0010,
wxRIGHT = 0x0020,
wxUP = 0x0040,
wxDOWN = 0x0080
};
// wxCENTRE = 0x0400 (defined above)
// centering into frame rather than screen (obsolete)
#define wxCENTER_FRAME 0x0000
// centre on screen rather than parent
#define wxCENTRE_ON_SCREEN 0x0004
#define wxCENTER_ON_SCREEN wxCENTRE_ON_SCREEN
// ----------------------------------------------------------------------------
// Possible SetSize flags
// ----------------------------------------------------------------------------

View File

@ -39,13 +39,13 @@ class WXDLLEXPORT wxNewSizerItem: public wxObject
{
public:
// spacer
wxNewSizerItem( int width, int height, int option );
wxNewSizerItem( int width, int height, int option, int flag, int border );
// window
wxNewSizerItem( wxWindow *window, int option );
wxNewSizerItem( wxWindow *window, int option, int flag, int border );
// subsizer
wxNewSizerItem( wxNewSizer *sizer, int option );
wxNewSizerItem( wxNewSizer *sizer, int option, int flag, int border );
virtual wxSize GetSize();
virtual wxSize CalcMin();
@ -61,12 +61,19 @@ public:
{ return m_sizer; }
int GetOption() const
{ return m_option; }
int GetFlag() const
{ return m_flag; }
int GetBorder() const
{ return m_border; }
protected:
wxWindow *m_window;
wxNewSizer *m_sizer;
wxSize m_size;
wxSize m_minSize;
int m_option;
int m_border;
int m_flag;
};
//---------------------------------------------------------------------------
@ -79,9 +86,9 @@ public:
wxNewSizer();
~wxNewSizer();
virtual void Add( wxWindow *window, int option = 0 );
virtual void Add( wxNewSizer *sizer, int option = 0 );
virtual void Add( int width, int height, int option = 0 );
virtual void Add( wxWindow *window, int option = 0, int flag = 0, int border = 0 );
virtual void Add( wxNewSizer *sizer, int option = 0, int flag = 0, int border = 0 );
virtual void Add( int width, int height, int option = 0, int flag = 0, int border = 0 );
void SetDimension( int x, int y, int width, int height );
@ -109,42 +116,13 @@ protected:
};
//---------------------------------------------------------------------------
// wxBorderNewSizer
// wxBox
//---------------------------------------------------------------------------
#define wxWEST wxLEFT
#define wxEAST wxRIGHT
#define wxNORTH wxUP
#define wxSOUTH wxDOWN
#define wxALL_DIRECTIONS (wxNORTH | wxSOUTH | wxEAST | wxWEST)
class WXDLLEXPORT wxBorderNewSizer: public wxNewSizer
class WXDLLEXPORT wxBox: public wxNewSizer
{
public:
wxBorderNewSizer( int sides = wxALL_DIRECTIONS );
virtual void Add( wxWindow *window, int option = 10 );
virtual void Add( wxNewSizer *sizer, int option = 10 );
virtual void Add( int width, int height, int option = 10 );
void RecalcSizes();
wxSize CalcMin();
int GetSides()
{ return m_sides; }
protected:
int m_sides;
};
//---------------------------------------------------------------------------
// wxBoxNewSizer
//---------------------------------------------------------------------------
class WXDLLEXPORT wxBoxNewSizer: public wxNewSizer
{
public:
wxBoxNewSizer( int orient );
wxBox( int orient );
void RecalcSizes();
wxSize CalcMin();

View File

@ -370,56 +370,53 @@ NewSizerFrame::NewSizerFrame(wxFrame *frame, char *title, int x, int y ):
{
// we want to get a dialog that is stretchable because it
// has a text ctrl in the middle. at the bottom, we have
// two buttons which are not supposed to get stretched
// and therefore we insert two spacers next to them
// two buttons which.
topsizer = new wxBoxNewSizer( wxVERTICAL );
topsizer = new wxBox( wxVERTICAL );
// 1) top: create wxStaticText with minimum size equal to its default size
topsizer->Add(
new wxStaticText( this, -1, "An explanation (wxALIGN_RIGHT)." ),
0, // make vertically unstretchable
wxALIGN_RIGHT | // right align text
wxTOP | wxLEFT | wxRIGHT, // make border all around except wxBOTTOM
5 ); // set border width to 5
// 1) upper part: text ctrl
// make border around textctrl in all directions
wxBorderNewSizer *text_border = new wxBorderNewSizer();
// make border around text ctrl 20 pixels wide
// minimum size for the text ctrl is 60x30
text_border->Add( new wxTextCtrl( this, -1, "My text.", wxDefaultPosition, wxSize(170,30), wxTE_MULTILINE), 5 );
// add text ctrl with border to top sizer
// a value of more than zero indicates that it's stretchable
topsizer->Add( text_border, 1 );
// 2) top: create wxTextCtrl with minimum size (100x60)
topsizer->Add(
new wxTextCtrl( this, -1, "My text (wxEXPAND).", wxDefaultPosition, wxSize(100,60), wxTE_MULTILINE),
1, // make vertically stretchable
wxEXPAND | // make horizontally stretchable
wxALL, // and make border all around
5 ); // set border width to 5
// 2) middle part: static line
// make border for beauty static line
wxBorderNewSizer *line_border = new wxBorderNewSizer();
// make border around static line 2 pixels wide
// minimum size for the static line is 3x3
line_border->Add( new wxStaticLine( this, -1, wxDefaultPosition, wxSize(170,3), wxHORIZONTAL), 5 );
// add text ctrl with border to top sizer
topsizer->Add( line_border );
// 3) middle: create wxStaticLine with minimum size (3x3)
topsizer->Add(
new wxStaticLine( this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL),
0, // make vertically unstretchable
wxEXPAND | // make horizontally stretchable
wxALL, // and make border all around
5 ); // set border width to 5
// 3) bottom: buttons
// 4) bottom: create two centred wxButtons
wxBox *button_box = new wxBox( wxHORIZONTAL );
button_box->Add(
new wxButton( this, -1, "Two buttons in a box" ),
0, // make horizontally unstretchable
wxALL, // make border all around
7 ); // set border width to 7
button_box->Add(
new wxButton( this, -1, "(wxCENTER)" ),
0, // make horizontally unstretchable
wxALL, // make border all around
7 ); // set border width to 7
// make border around button in all directions
wxBoxNewSizer *button_sizer = new wxBoxNewSizer( wxHORIZONTAL );
// make border around buttons 5 pixels wide
// minimum size for the button is its default size
wxBorderNewSizer *button1_border = new wxBorderNewSizer();
button1_border->Add( new wxButton( this, -1, "Hello 1", wxDefaultPosition, wxSize(80,30) ), 5 );
button_sizer->Add( button1_border );
wxBorderNewSizer *button2_border = new wxBorderNewSizer();
button2_border->Add( new wxButton( this, -1, "Hello 2", wxDefaultPosition, wxSize(80,30) ), 5 );
button_sizer->Add( button2_border );
// add buttons with border to top sizer
topsizer->Add( button_sizer );
topsizer->Add(
button_box,
0, // make vertically unstretchable
wxCENTER ); // no border and centre horizontally
// set frame to minimum size

View File

@ -27,62 +27,130 @@
// wxNewSizerItem
//---------------------------------------------------------------------------
wxNewSizerItem::wxNewSizerItem( int width, int height, int option )
wxNewSizerItem::wxNewSizerItem( int width, int height, int option, int flag, int border )
{
m_window = (wxWindow *) NULL;
m_sizer = (wxNewSizer *) NULL;
m_option = option;
m_border = border;
m_flag = flag;
// minimal size is the initial size
m_minSize.x = width;
m_minSize.y = height;
m_option = option;
// size is set directly
m_size = m_minSize;
}
wxNewSizerItem::wxNewSizerItem( wxWindow *window, int option )
wxNewSizerItem::wxNewSizerItem( wxWindow *window, int option, int flag, int border )
{
m_window = window;
m_sizer = (wxNewSizer *) NULL;
m_minSize = window->GetSize();
m_option = option;
m_border = border;
m_flag = flag;
// minimal size is the initial size
m_minSize = window->GetSize();
// size is calculated later
// m_size = ...
}
wxNewSizerItem::wxNewSizerItem( wxNewSizer *sizer, int option )
wxNewSizerItem::wxNewSizerItem( wxNewSizer *sizer, int option, int flag, int border )
{
m_window = (wxWindow *) NULL;
m_sizer = sizer;
m_minSize = sizer->GetSize();
m_option = option;
m_border = border;
m_flag = flag;
// minimal size is calculated later
// m_minSize = ...
// size is calculated later
// m_size = ...
}
wxSize wxNewSizerItem::GetSize()
{
wxSize ret;
if (IsNewSizer())
return m_sizer->GetSize();
ret = m_sizer->GetSize();
else
if (IsWindow())
return m_window->GetSize();
return m_minSize;
ret = m_window->GetSize();
else ret = m_size;
if (m_flag & wxWEST)
ret.x += m_border;
if (m_flag & wxEAST)
ret.x += m_border;
if (m_flag & wxNORTH)
ret.y += m_border;
if (m_flag & wxSOUTH)
ret.y += m_border;
return ret;
}
wxSize wxNewSizerItem::CalcMin()
{
wxSize ret;
if (IsNewSizer())
return m_sizer->CalcMin();
ret = m_sizer->CalcMin();
/*
The minimum size of a window should be the
initial size, as saved in m_minSize, not the
current size.
else
if (IsWindow())
return m_window->GetSize();
return m_minSize;
ret = m_window->GetSize();
*/
else ret = m_minSize;
if (m_flag & wxWEST)
ret.x += m_border;
if (m_flag & wxEAST)
ret.x += m_border;
if (m_flag & wxNORTH)
ret.y += m_border;
if (m_flag & wxSOUTH)
ret.y += m_border;
return ret;
}
void wxNewSizerItem::SetDimension( wxPoint pos, wxSize size )
{
if (m_flag & wxWEST)
{
pos.x += m_border;
size.x -= m_border;
}
if (m_flag & wxEAST)
{
size.x -= m_border;
}
if (m_flag & wxNORTH)
{
pos.y += m_border;
size.y -= m_border;
}
if (m_flag & wxSOUTH)
{
size.y -= m_border;
}
if (IsNewSizer())
m_sizer->SetDimension( pos.x, pos.y, size.x, size.y );
if (IsWindow())
m_window->SetSize( pos.x, pos.y, size.x, size.y );
m_minSize = size;
m_size = size;
}
bool wxNewSizerItem::IsWindow()
@ -113,19 +181,19 @@ wxNewSizer::~wxNewSizer()
{
}
void wxNewSizer::Add( wxWindow *window, int option )
void wxNewSizer::Add( wxWindow *window, int option, int flag, int border )
{
m_children.Append( new wxNewSizerItem( window, option ) );
m_children.Append( new wxNewSizerItem( window, option, flag, border ) );
}
void wxNewSizer::Add( wxNewSizer *sizer, int option )
void wxNewSizer::Add( wxNewSizer *sizer, int option, int flag, int border )
{
m_children.Append( new wxNewSizerItem( sizer, option ) );
m_children.Append( new wxNewSizerItem( sizer, option, flag, border ) );
}
void wxNewSizer::Add( int width, int height, int option )
void wxNewSizer::Add( int width, int height, int option, int flag, int border )
{
m_children.Append( new wxNewSizerItem( width, height, option ) );
m_children.Append( new wxNewSizerItem( width, height, option, flag, border ) );
}
void wxNewSizer::Fit( wxWindow *window )
@ -164,108 +232,15 @@ void wxNewSizer::SetDimension( int x, int y, int width, int height )
}
//---------------------------------------------------------------------------
// wxBorderNewSizer
// wxBox
//---------------------------------------------------------------------------
wxBorderNewSizer::wxBorderNewSizer( int sides )
{
m_sides = sides;
}
void wxBorderNewSizer::Add( wxWindow *window, int option )
{
wxCHECK_RET( m_children.GetCount() == 0, _T("border sizer can only hold one child") );
wxNewSizer::Add( window, option );
}
void wxBorderNewSizer::Add( wxNewSizer *sizer, int option )
{
wxCHECK_RET( m_children.GetCount() == 0, _T("border sizer can only hold one child") );
wxNewSizer::Add( sizer, option );
}
void wxBorderNewSizer::Add( int width, int height, int option )
{
wxCHECK_RET( m_children.GetCount() == 0, _T("border sizer can only hold one child") );
wxNewSizer::Add( width, height, option );
}
void wxBorderNewSizer::RecalcSizes()
{
wxNode *node = m_children.GetFirst();
if (!node)
{
SetDimension( m_position.x, m_position.y, 2, 2 );
return;
}
wxNewSizerItem *item = (wxNewSizerItem*) node->Data();
wxSize size( m_size );
wxPoint pt( m_position );
int borderSize = item->GetOption();
if (m_sides & wxWEST)
{
size.x -= borderSize;
pt.x += borderSize;
}
if (m_sides & wxEAST)
{
size.x -= borderSize;
}
if (m_sides & wxNORTH)
{
size.y -= borderSize;
pt.y += borderSize;
}
if (m_sides & wxSOUTH)
{
size.y -= borderSize;
}
item->SetDimension( pt, size );
}
wxSize wxBorderNewSizer::CalcMin()
{
wxNode *node = m_children.GetFirst();
if (!node)
return wxSize(2,2);
wxNewSizerItem *item = (wxNewSizerItem*) node->Data();
wxSize size( item->CalcMin() );
int borderSize = item->GetOption();
if (m_sides & wxWEST)
size.x += borderSize;
if (m_sides & wxEAST)
size.x += borderSize;
if (m_sides & wxNORTH)
size.y += borderSize;
if (m_sides & wxSOUTH)
size.y += borderSize;
return size;
}
//---------------------------------------------------------------------------
// wxBoxNewSizer
//---------------------------------------------------------------------------
wxBoxNewSizer::wxBoxNewSizer( int orient )
wxBox::wxBox( int orient )
{
m_orient = orient;
}
void wxBoxNewSizer::RecalcSizes()
void wxBox::RecalcSizes()
{
if (m_children.GetCount() == 0)
{
@ -310,7 +285,19 @@ void wxBoxNewSizer::RecalcSizes()
height = (delta * weight) + extra;
extra = 0; // only the first item will get the remainder as extra size
}
item->SetDimension( pt, wxSize( size.x, height) );
wxPoint child_pos( pt );
wxSize child_size( wxSize( size.x, height) );
if (item->GetFlag() & wxALIGN_RIGHT)
child_pos.x += m_size.x - size.x;
else if (item->GetFlag() & wxCENTER)
child_pos.x += (m_size.x - size.x) / 2;
else if (item->GetFlag() & wxEXPAND)
child_size.x = m_size.x;
item->SetDimension( child_pos, child_size );
pt.y += height;
}
else
@ -321,7 +308,19 @@ void wxBoxNewSizer::RecalcSizes()
width = (delta * weight) + extra;
extra = 0; // only the first item will get the remainder as extra size
}
item->SetDimension( pt, wxSize(width, size.y) );
wxPoint child_pos( pt );
wxSize child_size( wxSize(width, size.y) );
if (item->GetFlag() & wxALIGN_BOTTOM)
child_pos.y += m_size.y - size.y;
else if (item->GetFlag() & wxCENTER)
child_pos.y += (m_size.y - size.y) / 2;
else if (item->GetFlag() & wxEXPAND)
child_size.y = m_size.y;
item->SetDimension( child_pos, child_size );
pt.x += width;
}
@ -329,7 +328,7 @@ void wxBoxNewSizer::RecalcSizes()
}
}
wxSize wxBoxNewSizer::CalcMin()
wxSize wxBox::CalcMin()
{
if (m_children.GetCount() == 0)
return wxSize(2,2);