1998-05-20 10:01:55 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: layout.h
|
|
|
|
// Purpose: Layout classes
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 29/01/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1998 Julian Smart
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-14 20:23:28 -04:00
|
|
|
#ifndef _WX_LAYOUTH__
|
|
|
|
#define _WX_LAYOUTH__
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface "layout.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxWindow;
|
|
|
|
|
|
|
|
// X stupidly defines these in X.h
|
|
|
|
#ifdef Above
|
|
|
|
#undef Above
|
|
|
|
#endif
|
|
|
|
#ifdef Below
|
|
|
|
#undef Below
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define wxLAYOUT_DEFAULT_MARGIN 0
|
|
|
|
|
|
|
|
enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
|
|
|
|
wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY };
|
|
|
|
enum wxRelationship { wxUnconstrained = 0,
|
|
|
|
wxAsIs,
|
|
|
|
wxPercentOf,
|
|
|
|
wxAbove,
|
|
|
|
wxBelow,
|
|
|
|
wxLeftOf,
|
|
|
|
wxRightOf,
|
|
|
|
wxSameAs,
|
|
|
|
wxAbsolute };
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxLayoutConstraints;
|
|
|
|
class WXDLLEXPORT wxIndividualLayoutConstraint: public wxObject
|
|
|
|
{
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxIndividualLayoutConstraint)
|
|
|
|
|
|
|
|
protected:
|
1998-08-18 13:22:15 -04:00
|
|
|
// To be allowed to modify the internal variables
|
|
|
|
friend class wxIndividualLayoutConstraint_Serialize;
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
// 'This' window is the parent or sibling of otherWin
|
|
|
|
wxWindow *otherWin;
|
|
|
|
|
|
|
|
wxEdge myEdge;
|
|
|
|
wxRelationship relationship;
|
|
|
|
int margin;
|
|
|
|
int value;
|
|
|
|
int percent;
|
|
|
|
wxEdge otherEdge;
|
|
|
|
bool done;
|
|
|
|
|
|
|
|
public:
|
1998-08-07 11:09:04 -04:00
|
|
|
wxIndividualLayoutConstraint();
|
|
|
|
~wxIndividualLayoutConstraint();
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
void Set(wxRelationship rel, wxWindow *otherW, wxEdge otherE, int val = 0, int marg = wxLAYOUT_DEFAULT_MARGIN);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Sibling relationships
|
|
|
|
//
|
|
|
|
void LeftOf(wxWindow *sibling, int marg = wxLAYOUT_DEFAULT_MARGIN);
|
|
|
|
void RightOf(wxWindow *sibling, int marg = wxLAYOUT_DEFAULT_MARGIN);
|
|
|
|
void Above(wxWindow *sibling, int marg = wxLAYOUT_DEFAULT_MARGIN);
|
|
|
|
void Below(wxWindow *sibling, int marg = wxLAYOUT_DEFAULT_MARGIN);
|
|
|
|
|
|
|
|
//
|
|
|
|
// 'Same edge' alignment
|
|
|
|
//
|
|
|
|
void SameAs(wxWindow *otherW, wxEdge edge, int marg = wxLAYOUT_DEFAULT_MARGIN);
|
|
|
|
|
|
|
|
// The edge is a percentage of the other window's edge
|
|
|
|
void PercentOf(wxWindow *otherW, wxEdge wh, int per);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Edge has absolute value
|
|
|
|
//
|
|
|
|
void Absolute(int val);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Dimension is unconstrained
|
|
|
|
//
|
1998-08-07 11:09:04 -04:00
|
|
|
inline void Unconstrained() { relationship = wxUnconstrained; }
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Dimension is 'as is' (use current size settings)
|
|
|
|
//
|
1998-08-07 11:09:04 -04:00
|
|
|
inline void AsIs() { relationship = wxAsIs; }
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Accessors
|
|
|
|
//
|
1998-08-07 11:09:04 -04:00
|
|
|
inline wxWindow *GetOtherWindow() { return otherWin; }
|
|
|
|
inline wxEdge GetMyEdge() const { return myEdge; }
|
1998-05-20 10:01:55 -04:00
|
|
|
inline void SetEdge(wxEdge which) { myEdge = which; }
|
|
|
|
inline void SetValue(int v) { value = v; }
|
1998-08-07 11:09:04 -04:00
|
|
|
inline int GetMargin() { return margin; }
|
1998-05-20 10:01:55 -04:00
|
|
|
inline void SetMargin(int m) { margin = m; }
|
1998-08-07 11:09:04 -04:00
|
|
|
inline int GetValue() const { return value; }
|
|
|
|
inline int GetPercent() const { return percent; }
|
|
|
|
inline int GetOtherEdge() const { return otherEdge; }
|
|
|
|
inline bool GetDone() const { return done; }
|
1998-05-20 10:01:55 -04:00
|
|
|
inline void SetDone(bool d) { done = d; }
|
1998-08-07 11:09:04 -04:00
|
|
|
inline wxRelationship GetRelationship() { return relationship; }
|
1998-05-20 10:01:55 -04:00
|
|
|
inline void SetRelationship(wxRelationship r) { relationship = r; }
|
|
|
|
|
|
|
|
// Reset constraint if it mentions otherWin
|
|
|
|
bool ResetIfWin(wxWindow *otherW);
|
|
|
|
|
|
|
|
// Try to satisfy constraint
|
|
|
|
bool SatisfyConstraint(wxLayoutConstraints *constraints, wxWindow *win);
|
|
|
|
|
|
|
|
// Get the value of this edge or dimension, or if this
|
|
|
|
// is not determinable, -1.
|
1998-08-07 11:09:04 -04:00
|
|
|
int GetEdge(wxEdge which, wxWindow *thisWin, wxWindow *other) const;
|
1998-05-20 10:01:55 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxLayoutConstraints: public wxObject
|
|
|
|
{
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxLayoutConstraints)
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Edge constraints
|
|
|
|
wxIndividualLayoutConstraint left;
|
|
|
|
wxIndividualLayoutConstraint top;
|
|
|
|
wxIndividualLayoutConstraint right;
|
|
|
|
wxIndividualLayoutConstraint bottom;
|
|
|
|
// Size constraints
|
|
|
|
wxIndividualLayoutConstraint width;
|
|
|
|
wxIndividualLayoutConstraint height;
|
|
|
|
// Centre constraints
|
|
|
|
wxIndividualLayoutConstraint centreX;
|
|
|
|
wxIndividualLayoutConstraint centreY;
|
|
|
|
|
1998-08-07 11:09:04 -04:00
|
|
|
wxLayoutConstraints();
|
|
|
|
~wxLayoutConstraints();
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
bool SatisfyConstraints(wxWindow *win, int *noChanges);
|
1998-08-07 11:09:04 -04:00
|
|
|
bool AreSatisfied() const
|
|
|
|
{
|
|
|
|
return left.GetDone() && top.GetDone() && right.GetDone() &&
|
|
|
|
bottom.GetDone() && centreX.GetDone() && centreY.GetDone();
|
|
|
|
}
|
1998-05-20 10:01:55 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
bool WXDLLEXPORT wxOldDoLayout(wxWindow *win);
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Algorithm:
|
|
|
|
|
|
|
|
Each sizer has a Layout function.
|
|
|
|
|
|
|
|
wxExpandSizer::Layout ; E.g. for resizeable windows
|
|
|
|
|
|
|
|
- parent size must be known (i.e. called
|
|
|
|
from OnSize or explicitly)
|
|
|
|
- call Layout on each child to give it a chance to resize
|
|
|
|
(e.g. child shrinks around its own children):
|
|
|
|
stop when all children return TRUE, or no change
|
|
|
|
- evaluate constraints on self to set size
|
|
|
|
|
|
|
|
wxShrinkSizer::Layout ; E.g. fit-to-contents windows
|
|
|
|
; Perhaps 2 rowcols, one above other.
|
|
|
|
|
|
|
|
- call Layout on each child to give it a chance to resize
|
|
|
|
(e.g. child shrinks around its own children):
|
|
|
|
stop when each returns TRUE, or no change
|
|
|
|
- fit around children
|
|
|
|
(what if some want to be centred? E.g. OK/Cancel rowcol.
|
|
|
|
- done by centring e.g. bottom sizer w.r.t. top sizer.
|
|
|
|
(sibling relationship only))
|
|
|
|
- evaluate own constraints (e.g. may be below another window)
|
|
|
|
- IF parent is a real window (remember: a real window can
|
|
|
|
have only one child sizer, although a sizer can have several child
|
|
|
|
(real) windows), then resize this parent WITHOUT invoking Layout
|
|
|
|
again.
|
|
|
|
Frame and dialog box OnSizes can check if the sizer is a shrink
|
|
|
|
sizer; if not, can call layout. Maybe have virtual bool AutoSizeLayout()
|
|
|
|
to determine this.
|
|
|
|
|
|
|
|
How to relayout if a child sizer/window changes? Need to go all the way
|
|
|
|
to the top of the hierarchy and call Layout() again.
|
|
|
|
|
|
|
|
wxRowColSizer::Layout
|
|
|
|
|
|
|
|
- Similar to wxShrinkSizer only instead of shrinking to fit
|
|
|
|
contents, more sophisticated layout of contents, and THEN
|
|
|
|
shrinking (possibly).
|
|
|
|
- Do the same parent window check/setsize as for wxShrinkSizer.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
wxSizerShrink,
|
|
|
|
wxSizerExpand,
|
|
|
|
wxSizerNone
|
|
|
|
} wxSizerBehaviour;
|
|
|
|
|
|
|
|
#define wxTYPE_SIZER 90
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxSizer: public wxWindow
|
|
|
|
{
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxSizer)
|
|
|
|
|
|
|
|
private:
|
|
|
|
protected:
|
|
|
|
wxSizerBehaviour sizerBehaviour;
|
|
|
|
int borderX;
|
|
|
|
int borderY;
|
|
|
|
int sizerWidth;
|
|
|
|
int sizerHeight;
|
|
|
|
int sizerX;
|
|
|
|
int sizerY;
|
|
|
|
public:
|
1998-08-07 11:09:04 -04:00
|
|
|
wxSizer();
|
1998-05-20 10:01:55 -04:00
|
|
|
wxSizer(wxWindow *parent, wxSizerBehaviour behav = wxSizerNone);
|
1998-08-07 11:09:04 -04:00
|
|
|
~wxSizer();
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
bool Create(wxWindow *parent, wxSizerBehaviour behav = wxSizerNone);
|
1999-02-04 06:14:41 -05:00
|
|
|
|
1998-07-04 11:17:59 -04:00
|
|
|
virtual void SetSize(int x, int y, int w, int h, int flags = wxSIZE_AUTO);
|
1999-02-04 06:14:41 -05:00
|
|
|
virtual void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO)
|
|
|
|
{ wxWindow::SetSize(rect, sizeFlags); }
|
|
|
|
virtual void SetSize(const wxSize& size) { wxWindow::SetSize(size); }
|
|
|
|
virtual void SetSize(int width, int height) { SetSize(-1, -1, width, height, wxSIZE_USE_EXISTING); }
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
virtual void GetSize(int *w, int *h) const;
|
1999-02-04 06:14:41 -05:00
|
|
|
wxSize GetSize() const { return wxWindow::GetSize(); }
|
1998-12-13 17:01:50 -05:00
|
|
|
|
|
|
|
virtual void GetClientSize(int *w, int *h) const { GetSize(w, h); }
|
1999-02-04 06:14:41 -05:00
|
|
|
wxSize GetClientSize() const { return wxWindow::GetClientSize(); }
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
virtual void GetPosition(int *x, int *y) const;
|
1999-02-04 06:14:41 -05:00
|
|
|
wxPoint GetPosition() const { return wxWindow::GetPosition(); }
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-07-04 11:17:59 -04:00
|
|
|
inline void SizerSetSize(int x, int y, int w, int h)
|
1998-05-20 10:01:55 -04:00
|
|
|
{ SetSize(x, y, w, h); }
|
1998-07-04 11:17:59 -04:00
|
|
|
inline void SizerMove(int x, int y)
|
1998-05-20 10:01:55 -04:00
|
|
|
{ Move(x, y); }
|
|
|
|
|
|
|
|
virtual void SetBorder(int w, int h);
|
1998-08-07 11:09:04 -04:00
|
|
|
inline int GetBorderX() { return borderX ; }
|
|
|
|
inline int GetBorderY() { return borderY ; }
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
virtual void AddSizerChild(wxWindow *child);
|
|
|
|
virtual void RemoveSizerChild(wxWindow *child);
|
|
|
|
|
|
|
|
inline virtual void SetBehaviour(wxSizerBehaviour b) { sizerBehaviour = b; }
|
1998-08-07 11:09:04 -04:00
|
|
|
inline virtual wxSizerBehaviour GetBehaviour() { return sizerBehaviour; }
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
virtual bool LayoutPhase1(int *);
|
|
|
|
virtual bool LayoutPhase2(int *);
|
|
|
|
};
|
|
|
|
|
|
|
|
#define wxSIZER_ROWS TRUE
|
|
|
|
#define wxSIZER_COLS FALSE
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxRowColSizer: public wxSizer
|
|
|
|
{
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxRowColSizer)
|
|
|
|
|
|
|
|
private:
|
|
|
|
protected:
|
|
|
|
bool rowOrCol;
|
|
|
|
int rowOrColSize;
|
|
|
|
int xSpacing;
|
|
|
|
int ySpacing;
|
|
|
|
public:
|
|
|
|
// rowOrCol = TRUE to be laid out in rows, otherwise in columns.
|
1998-08-07 11:09:04 -04:00
|
|
|
wxRowColSizer();
|
1998-05-20 10:01:55 -04:00
|
|
|
wxRowColSizer(wxWindow *parent, bool rowOrCol = wxSIZER_ROWS, int rowsOrColSize = 20, wxSizerBehaviour = wxSizerShrink);
|
1998-08-07 11:09:04 -04:00
|
|
|
~wxRowColSizer();
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
bool Create(wxWindow *parent, bool rowOrCol = wxSIZER_ROWS, int rowsOrColSize = 20, wxSizerBehaviour = wxSizerShrink);
|
1998-12-13 17:01:50 -05:00
|
|
|
virtual void SetSize(int x, int y, int w, int h, int flags = wxSIZE_AUTO);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
inline virtual void SetRowOrCol(bool rc) { rowOrCol = rc; }
|
1998-08-07 11:09:04 -04:00
|
|
|
inline virtual bool GetRowOrCol() { return rowOrCol; }
|
1998-05-20 10:01:55 -04:00
|
|
|
inline virtual void SetRowOrColSize(int n) { rowOrColSize = n; }
|
1998-08-07 11:09:04 -04:00
|
|
|
inline virtual int GetRowOrColSize() { return rowOrColSize; }
|
1998-05-20 10:01:55 -04:00
|
|
|
inline virtual void SetSpacing(int x, int y) { xSpacing = x; ySpacing = y; }
|
|
|
|
inline virtual void GetSpacing(int *x, int *y) { *x = xSpacing; *y = ySpacing; }
|
|
|
|
|
|
|
|
bool LayoutPhase1(int *);
|
|
|
|
bool LayoutPhase2(int *);
|
|
|
|
};
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxSpacingSizer: public wxSizer
|
|
|
|
{
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxSpacingSizer)
|
|
|
|
|
|
|
|
private:
|
|
|
|
protected:
|
|
|
|
public:
|
1998-08-07 11:09:04 -04:00
|
|
|
wxSpacingSizer();
|
1998-05-20 10:01:55 -04:00
|
|
|
wxSpacingSizer(wxWindow *parent, wxRelationship rel, wxWindow *other, int spacing);
|
|
|
|
wxSpacingSizer(wxWindow *parent);
|
1998-08-07 11:09:04 -04:00
|
|
|
~wxSpacingSizer();
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
bool Create(wxWindow *parent, wxRelationship rel, wxWindow *other, int sp);
|
|
|
|
bool Create(wxWindow *parent);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
1998-08-14 20:23:28 -04:00
|
|
|
// _WX_LAYOUTH__
|