wxWindow::GetBestSize() added

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4633 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-11-19 21:01:20 +00:00
parent 33879bb218
commit f68586e51b
61 changed files with 378 additions and 221 deletions

View File

@@ -1051,7 +1051,7 @@ See also \helpref{wxDDEServer}{wxddeserver}, \helpref{wxDDEClient}{wxddeclient},
\func{void}{wxDebugMsg}{\param{const wxString\& }{fmt}, \param{...}{}}
{\bf This function is deprecated, use \helpref{wxLogDebug}{wxlogoverview} instead!}
{\bf This function is deprecated, use \helpref{wxLogDebug}{wxlogdebug} instead!}
Display a debugging message; under Windows, this will appear on the
debugger command window, and under Unix, it will be written to standard
@@ -2285,7 +2285,9 @@ Another name for \helpref{wxResourceRegisterBitmapData}{registerbitmapdata}.
\section{Log functions}\label{logfunctions}
These functions provide a variety of logging functions: see \helpref{Log classes overview}{wxlogoverview} for
further information.
further information. The functions use (implicitly) the currently active log
target, so their descriptions here may not apply if the log target is not the
standard one (installed by wxWindows in the beginning of the program).
\wxheading{Include files}
@@ -2295,9 +2297,9 @@ further information.
\func{void}{wxLogError}{\param{const char*}{ formatString}, \param{...}{}}
The function to use for error messages, i.e. the
messages that must be shown to the user. The default processing is to pop up a
message box to inform the user about it.
The function to use for error messages, i.e. the messages that must be shown
to the user. The default processing is to pop up a message box to inform the
user about it.
\membersection{::wxLogFatalError}\label{wxlogfatalerror}
@@ -2311,18 +2313,18 @@ function also terminates the program with this exit code.
\func{void}{wxLogWarning}{\param{const char*}{ formatString}, \param{...}{}}
For warnings - they are also normally shown to the
user, but don't interrupt the program work.
For warnings - they are also normally shown to the user, but don't interrupt
the program work.
\membersection{::wxLogMessage}\label{wxlogmessage}
\func{void}{wxLogMessage}{\param{const char*}{ formatString}, \param{...}{}}
for all normal, informational messages. They also
appear in a message box by default (but it can be changed). Notice
that the standard behaviour is to not show informational messages if there are
any errors later - the logic being that the later error messages make the
informational messages preceding them meaningless.
for all normal, informational messages. They also appear in a message box by
default (but it can be changed). Notice that the standard behaviour is to not
show informational messages if there are any errors later - the logic being
that the later error messages make the informational messages preceding them
meaningless.
\membersection{::wxLogVerbose}\label{wxlogverbose}
@@ -2334,48 +2336,79 @@ progress (another, but possibly confusing name for the same function is {\bf wxL
\membersection{::wxLogStatus}\label{wxlogstatus}
\func{void}{wxLogStatus}{\param{wxFrame *}{frame}, \param{const char*}{ formatString}, \param{...}{}}
\func{void}{wxLogStatus}{\param{const char*}{ formatString}, \param{...}{}}
For status messages - they will go into the status
bar of the active or specified (as the first argument) \helpref{wxFrame}{wxframe} if it has one.
Messages logged by this function will appear in the statusbar of the {\it
frame} or of the top level application window by default (i.e. when using
the second version of the function).
If the target frame doesn't have a statusbar, the message will be lost.
\membersection{::wxLogSysError}\label{wxlogsyserror}
\func{void}{wxLogSysError}{\param{const char*}{ formatString}, \param{...}{}}
Mostly used by wxWindows itself, but might be
handy for logging errors after system call (API function) failure. It logs the
specified message text as well as the last system error code ({\it errno} or {\it ::GetLastError()} depending
on the platform) and the corresponding error
message. The second form of this function takes the error code explitly as the
first argument.
Mostly used by wxWindows itself, but might be handy for logging errors after
system call (API function) failure. It logs the specified message text as well
as the last system error code ({\it errno} or {\it ::GetLastError()} depending
on the platform) and the corresponding error message. The second form
of this function takes the error code explitly as the first argument.
\membersection{::wxLogDebug}\label{wxlogdebug}
\func{void}{wxLogDebug}{\param{const char*}{ formatString}, \param{...}{}}
The right function for debug output. It only
does anything at all in the debug mode (when the preprocessor symbol \_\_WXDEBUG\_\_ is defined)
and expands to nothing in release mode (otherwise).
The right function for debug output. It only does anything at all in the debug
mode (when the preprocessor symbol \_\_WXDEBUG\_\_ is defined) and expands to
nothing in release mode (otherwise).
\membersection{::wxLogTrace}\label{wxlogtrace}
\func{void}{wxLogTrace}{\param{const char*}{ formatString}, \param{...}{}}
\func{void}{wxLogTrace}{\param{const char *}{mask}, \param{const char *}{formatString}, \param{...}{}}
\func{void}{wxLogTrace}{\param{wxTraceMask}{ mask}, \param{const char *}{formatString}, \param{...}{}}
As {\bf wxLogDebug}, only does something in debug
build. The reason for making it a separate function from it is that usually
there are a lot of trace messages, so it might make sense to separate them
from other debug messages which would be flooded in them. Moreover, the second
version of this function takes a trace mask as the first argument which allows
to further restrict the amount of messages generated. The value of {\it mask} can be:
As {\bf wxLogDebug}, trace functions only do something in debug build and
expand to nothing in the release one. The reason for making
it a separate function from it is that usually there are a lot of trace
messages, so it might make sense to separate them from other debug messages.
The trace messages also usually can be separated into different categories and
the second and third versions of this function only log the message if the
{\it mask} which it has is currently enabled in \helpref{wxLog}{wxlog}. This
allows to selectively trace only some operations and not others by changing
the value of the trace mask (possible during the run-time).
For the second function (taking a string mask), the message is logged only if
the mask has been previously enabled by the call to
\helpref{AddTraceMask}{wxlogaddtracemask}. The predefined string trace masks
used by wxWindows are:
\begin{itemize}\itemsep=0pt
\item wxTRACE\_MemAlloc: trace memory allocation (new/delete)
\item wxTRACE\_Messages: trace window messages/X callbacks
\item wxTRACE\_ResAlloc: trace GDI resource allocation
\item wxTRACE\_RefCount: trace various ref counting operations
\item wxTRACE\_OleCalls: trace OLE method calls (Win32 only)
\end{itemize}
The third version of the function only logs the message if all the bit
corresponding to the {\it mask} are set in the wxLog trace mask which can be
set by \helpref{SetTraceMask}{wxlogsettracemask}. This version is less
flexible than the previous one because it doesn't allow defining the user
trace masks easily - this is why it is deprecated in favour of using string
trace masks.
\begin{itemize}\itemsep=0pt
\item wxTraceMemAlloc: trace memory allocation (new/delete)
\item wxTraceMessages: trace window messages/X callbacks
\item wxTraceResAlloc: trace GDI resource allocation
\item wxTraceRefCount: trace various ref counting operations
\item wxTraceOleCalls: trace OLE method calls (Win32 only)
\end{itemize}
\section{Debugging macros and functions}\label{debugmacros}

View File

@@ -430,7 +430,8 @@ implements the following methods:\par
\func{virtual void}{Fit}{\void}
Sizes the window so that it fits around its subwindows.
Sizes the window so that it fits around its subwindows. This function won't do
anything if there are no subwindows.
\membersection{wxWindow::GetBackgroundColour}\label{wxwindowgetbackgroundcolour}
@@ -445,6 +446,17 @@ Returns the background colour of the window.
\helpref{wxWindow::GetForegroundColour}{wxwindowgetforegroundcolour},\rtfsp
\helpref{wxWindow::OnEraseBackground}{wxwindowonerasebackground}
\membersection{wxWindow::GetBestSize}{wxwindowgetbestsize}
\constfunc{virtual wxSize}{GetBestSize}{\void}
This functions returns the best acceptable minimal size for the window. For
example, for a static control, it will be the minimal size such that the
control label is not truncated. For windows containing subwindows (typically
\helpref{wxPanel}wxpanel}), the size returned by this function will be the
same as the size the window would have had after calling
\helpref{Fit}{wxwindowfit}.
\membersection{wxWindow::GetCharHeight}
\constfunc{virtual int}{GetCharHeight}{\void}

View File

@@ -73,6 +73,9 @@ public:
GtkWidget *m_widgetCheckbox;
GtkWidget *m_widgetLabel;
protected:
virtual wxSize DoGetBestSize() const;
private:
DECLARE_DYNAMIC_CLASS(wxCheckBox)
};

View File

@@ -71,6 +71,8 @@ protected:
virtual void DoSetItemClientObject( int n, wxClientData* clientData );
virtual wxClientData* DoGetItemClientObject( int n ) const;
virtual wxSize DoGetBestSize() const;
private:
// common part of Create() and DoAppend()
size_t AppendHelper(GtkWidget *menu, const wxString& item);

View File

@@ -121,6 +121,9 @@ public:
bool IsOwnGtkWindow( GdkWindow *window );
void ApplyWidgetStyle();
protected:
virtual wxSize DoGetBestSize() const;
private:
DECLARE_DYNAMIC_CLASS(wxComboBox)
DECLARE_EVENT_TABLE()

View File

@@ -46,6 +46,8 @@ public:
virtual wxString GetLabel() const;
protected:
virtual wxSize DoGetBestSize() const;
wxString m_label;
char m_chAccel; // enabled to avoid breaking binary compatibility later on

View File

@@ -96,6 +96,9 @@ public:
bool m_hasCheckBoxes;
#endif // wxUSE_CHECKLISTBOX
protected:
virtual wxSize DoGetBestSize() const;
private:
// this array is only used for controls with wxCB_SORT style, so only
// allocate it if it's needed (hence using pointer)

View File

@@ -80,6 +80,9 @@ public:
SetBitmap( icon );
}
protected:
virtual wxSize DoGetBestSize() const;
private:
// creates the new pixmap widget
void CreatePixmapWidget();

View File

@@ -38,23 +38,33 @@ extern const wxChar *wxStaticTextNameStr;
class wxStaticText : public wxControl
{
DECLARE_DYNAMIC_CLASS(wxStaticText)
public:
wxStaticText(void);
wxStaticText( wxWindow *parent, wxWindowID id, const wxString &label,
const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
long style = 0, const wxString &name = wxStaticTextNameStr );
bool Create( wxWindow *parent, wxWindowID id, const wxString &label,
const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
long style = 0, const wxString &name = wxStaticTextNameStr );
wxString GetLabel(void) const;
wxStaticText();
wxStaticText(wxWindow *parent,
wxWindowID id,
const wxString &label,
const wxPoint &pos = wxDefaultPosition,
const wxSize &size = wxDefaultSize,
long style = 0,
const wxString &name = wxStaticTextNameStr );
bool Create(wxWindow *parent,
wxWindowID id,
const wxString &label,
const wxPoint &pos = wxDefaultPosition,
const wxSize &size = wxDefaultSize,
long style = 0,
const wxString &name = wxStaticTextNameStr );
wxString GetLabel() const;
void SetLabel( const wxString &label );
// implementation
void ApplyWidgetStyle();
protected:
DECLARE_DYNAMIC_CLASS(wxStaticText)
};
#endif // __GTKSTATICTEXTH__

View File

@@ -131,6 +131,9 @@ public:
void SetModified() { m_modified = TRUE; }
protected:
virtual wxSize DoGetBestSize() const;
private:
bool m_modified;
GtkWidget *m_text;

View File

@@ -73,6 +73,9 @@ public:
GtkWidget *m_widgetCheckbox;
GtkWidget *m_widgetLabel;
protected:
virtual wxSize DoGetBestSize() const;
private:
DECLARE_DYNAMIC_CLASS(wxCheckBox)
};

View File

@@ -71,6 +71,8 @@ protected:
virtual void DoSetItemClientObject( int n, wxClientData* clientData );
virtual wxClientData* DoGetItemClientObject( int n ) const;
virtual wxSize DoGetBestSize() const;
private:
// common part of Create() and DoAppend()
size_t AppendHelper(GtkWidget *menu, const wxString& item);

View File

@@ -121,6 +121,9 @@ public:
bool IsOwnGtkWindow( GdkWindow *window );
void ApplyWidgetStyle();
protected:
virtual wxSize DoGetBestSize() const;
private:
DECLARE_DYNAMIC_CLASS(wxComboBox)
DECLARE_EVENT_TABLE()

View File

@@ -46,6 +46,8 @@ public:
virtual wxString GetLabel() const;
protected:
virtual wxSize DoGetBestSize() const;
wxString m_label;
char m_chAccel; // enabled to avoid breaking binary compatibility later on

View File

@@ -96,6 +96,9 @@ public:
bool m_hasCheckBoxes;
#endif // wxUSE_CHECKLISTBOX
protected:
virtual wxSize DoGetBestSize() const;
private:
// this array is only used for controls with wxCB_SORT style, so only
// allocate it if it's needed (hence using pointer)

View File

@@ -80,6 +80,9 @@ public:
SetBitmap( icon );
}
protected:
virtual wxSize DoGetBestSize() const;
private:
// creates the new pixmap widget
void CreatePixmapWidget();

View File

@@ -38,23 +38,33 @@ extern const wxChar *wxStaticTextNameStr;
class wxStaticText : public wxControl
{
DECLARE_DYNAMIC_CLASS(wxStaticText)
public:
wxStaticText(void);
wxStaticText( wxWindow *parent, wxWindowID id, const wxString &label,
const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
long style = 0, const wxString &name = wxStaticTextNameStr );
bool Create( wxWindow *parent, wxWindowID id, const wxString &label,
const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
long style = 0, const wxString &name = wxStaticTextNameStr );
wxString GetLabel(void) const;
wxStaticText();
wxStaticText(wxWindow *parent,
wxWindowID id,
const wxString &label,
const wxPoint &pos = wxDefaultPosition,
const wxSize &size = wxDefaultSize,
long style = 0,
const wxString &name = wxStaticTextNameStr );
bool Create(wxWindow *parent,
wxWindowID id,
const wxString &label,
const wxPoint &pos = wxDefaultPosition,
const wxSize &size = wxDefaultSize,
long style = 0,
const wxString &name = wxStaticTextNameStr );
wxString GetLabel() const;
void SetLabel( const wxString &label );
// implementation
void ApplyWidgetStyle();
protected:
DECLARE_DYNAMIC_CLASS(wxStaticText)
};
#endif // __GTKSTATICTEXTH__

View File

@@ -131,6 +131,9 @@ public:
void SetModified() { m_modified = TRUE; }
protected:
virtual wxSize DoGetBestSize() const;
private:
bool m_modified;
GtkWidget *m_text;

View File

@@ -66,7 +66,7 @@ protected:
// send a notification event, return TRUE if processed
bool SendClickEvent();
virtual wxSize DoGetBestSize();
virtual wxSize DoGetBestSize() const;
};
#endif

View File

@@ -53,7 +53,7 @@ public:
WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
protected:
virtual wxSize DoGetBestSize();
virtual wxSize DoGetBestSize() const;
};
class WXDLLEXPORT wxBitmapCheckBox: public wxCheckBox

View File

@@ -69,7 +69,7 @@ protected:
// For controls like radiobuttons which are really composite
wxList m_subControls;
virtual wxSize DoGetBestSize();
virtual wxSize DoGetBestSize() const;
// create the control of the given class with the given style, returns FALSE
// if creation failed

View File

@@ -126,7 +126,7 @@ protected:
int m_noItems;
int m_selected;
virtual wxSize DoGetBestSize();
virtual wxSize DoGetBestSize() const;
#if wxUSE_OWNER_DRAWN
// control items

View File

@@ -269,7 +269,7 @@ WXDLLEXPORT void wxSetInstance(HINSTANCE hInst);
WXDLLEXPORT wxWindow* wxFindWinFromHandle(WXHWND hWnd);
WXDLLEXPORT void wxGetCharSize(WXHWND wnd, int *x, int *y,wxFont *the_font);
WXDLLEXPORT void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont *the_font);
WXDLLEXPORT void wxFillLogFont(LOGFONT *logFont, const wxFont *font);
WXDLLEXPORT wxFont wxCreateFontFromLogFont(const LOGFONT *logFont);

View File

@@ -59,7 +59,7 @@ public:
WXWORD pos, WXHWND control);
protected:
virtual wxSize DoGetBestSize();
virtual wxSize DoGetBestSize() const;
private:
DECLARE_DYNAMIC_CLASS(wxSpinButton)

View File

@@ -61,7 +61,7 @@ public:
protected:
virtual void DoMoveWindow(int x, int y, int width, int height);
virtual wxSize DoGetBestSize();
virtual wxSize DoGetBestSize() const;
WXHWND m_hwndBuddy;

View File

@@ -84,7 +84,7 @@ protected:
wxBitmap *bitmap;
} m_image;
virtual wxSize DoGetBestSize();
virtual wxSize DoGetBestSize() const;
};
#endif

View File

@@ -57,7 +57,7 @@ public:
virtual bool AcceptsFocus() const { return FALSE; }
protected:
virtual wxSize DoGetBestSize();
virtual wxSize DoGetBestSize() const;
};
#endif

View File

@@ -56,7 +56,7 @@ public:
virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
protected:
virtual wxSize DoGetBestSize();
virtual wxSize DoGetBestSize() const;
};
#endif

View File

@@ -162,7 +162,7 @@ protected:
// limit is big enough)
void AdjustSpaceLimit();
virtual wxSize DoGetBestSize();
virtual wxSize DoGetBestSize() const;
private:
DECLARE_EVENT_TABLE()

View File

@@ -401,10 +401,6 @@ protected:
int sizeFlags = wxSIZE_AUTO);
virtual void DoSetClientSize(int width, int height);
// get the size which best suits the window: e.g., for a static text it
// will be the width and height of the text
virtual wxSize DoGetBestSize();
// move the window to the specified location and resize it: this is called
// from both DoSetSize() and DoSetClientSize() and would usually just call
// ::MoveWindow() except for composite controls which will want to arrange

View File

@@ -267,6 +267,18 @@ public:
return wxSize(w, h);
}
// get the size best suited for the window (in fact, minimal
// acceptable size using which it will still look "nice")
wxSize GetBestSize() const { return DoGetBestSize(); }
void GetBestSize(int *w, int *h) const
{
wxSize s = DoGetBestSize();
if ( w )
*w = s.x;
if ( h )
*h = s.y;
}
// centre with respect to the the parent window
void Centre( int direction = wxBOTH );
void Center( int direction = wxBOTH ) { Centre(direction); }
@@ -752,6 +764,26 @@ protected:
static int WidthDefault(int w) { return w == -1 ? 20 : w; }
static int HeightDefault(int h) { return h == -1 ? 20 : h; }
// sets the size to be size but take width and/or height from
// DoGetBestSize() if width/height of size is -1
//
// NB: when calling this function from the ctor, the DoGetBestSize() of
// the class with the same name as the ctor, not the real (most
// derived) one - but this is what we usually want
void SetSizeOrDefault(const wxSize& size = wxDefaultSize)
{
if ( size.x == -1 || size.y == -1 )
{
wxSize sizeDef = GetBestSize();
SetSize( size.x == -1 ? sizeDef.x : size.x,
size.y == -1 ? sizeDef.y : size.y);
}
else
{
SetSize(size);
}
}
// more pure virtual functions
// ---------------------------
@@ -773,6 +805,11 @@ protected:
virtual void DoGetSize( int *width, int *height ) const = 0;
virtual void DoGetClientSize( int *width, int *height ) const = 0;
// get the size which best suits the window: for a control, it would be
// the minimal size which doesn't truncate the control, for a panel - the
// same size as it would have after a call to Fit()
virtual wxSize DoGetBestSize() const;
// this is the virtual function to be overriden in any derived class which
// wants to change how SetSize() or Move() works - it is called by all
// versions of these functions in the base class
@@ -845,6 +882,8 @@ inline wxWindow *wxWindowBase::GetGrandParent() const
// ----------------------------------------------------------------------------
WXDLLEXPORT extern wxWindow* wxGetActiveWindow();
// deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
inline WXDLLEXPORT int NewControlId() { return wxWindowBase::NewControlId(); }
#endif

View File

@@ -302,7 +302,7 @@ bool wxWindowBase::DestroyChildren()
}
// ----------------------------------------------------------------------------
// centre/fit the window
// size/position related methods
// ----------------------------------------------------------------------------
// centre the window with respect to its parent in either (or both) directions
@@ -361,6 +361,19 @@ void wxWindowBase::Centre(int direction)
// fits the window around the children
void wxWindowBase::Fit()
{
if ( GetChildren().GetCount() > 0 )
{
SetClientSize(DoGetBestSize());
}
//else: do nothing if we have no children
}
// return the size best suited for the current window
wxSize wxWindowBase::DoGetBestSize() const
{
if ( GetChildren().GetCount() > 0 )
{
// our minimal acceptable size is such that all our windows fit inside
int maxX = 0,
maxY = 0;
@@ -371,8 +384,8 @@ void wxWindowBase::Fit()
wxWindow *win = node->GetData();
if ( win->IsTopLevel() )
{
// dialogs and frames lie in different top level windows - don't
// deal with them here
// dialogs and frames lie in different top level windows -
// don't deal with them here
continue;
}
@@ -386,11 +399,17 @@ void wxWindowBase::Fit()
}
// leave a margin
SetClientSize(maxX + 7, maxY + 14);
return wxSize(maxX + 7, maxY + 14);
}
else
{
// for a generic window there is no natural best size - just use the
// current one
return GetSize();
}
}
// set the min/max size of the window
void wxWindowBase::SetSizeHints(int minW, int minH,
int maxW, int maxH,
int WXUNUSED(incW), int WXUNUSED(incH))

View File

@@ -106,16 +106,7 @@ bool wxCheckBox::Create(wxWindow *parent,
m_widget = m_widgetCheckbox;
}
wxSize newSize(size);
if (newSize.x == -1)
{
newSize.x = 25 + gdk_string_measure( m_widgetCheckbox->style->font,
m_label.mbc_str() );
}
if (newSize.y == -1)
newSize.y = 26;
SetSize( newSize.x, newSize.y );
SetSizeOrDefault( size );
gtk_signal_connect( GTK_OBJECT(m_widgetCheckbox),
"clicked",
@@ -210,4 +201,10 @@ void wxCheckBox::OnInternalIdle()
UpdateWindowUI();
}
wxSize wxCheckBox::DoGetBestSize() const
{
return wxSize( 25 + gdk_string_measure( m_widgetCheckbox->style->font,
m_label.mbc_str() ), 26 );
}
#endif

View File

@@ -90,12 +90,7 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id,
m_widget = gtk_option_menu_new();
wxSize newSize(size);
if (newSize.x == -1)
newSize.x = 80;
if (newSize.y == -1)
newSize.y = 26;
SetSize( newSize.x, newSize.y );
SetSizeOrDefault( size );
if ( style & wxCB_SORT )
{
@@ -429,4 +424,9 @@ size_t wxChoice::AppendHelper(GtkWidget *menu, const wxString& item)
return index;
}
wxSize wxChoice::DoGetBestSize() const
{
return wxSize(80, 26);
}
#endif

View File

@@ -113,12 +113,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
// make it more useable
gtk_combo_set_use_arrows_always(GTK_COMBO(m_widget), TRUE);
wxSize newSize = size;
if (newSize.x == -1)
newSize.x = 100;
if (newSize.y == -1)
newSize.y = 26;
SetSize( newSize.x, newSize.y );
SetSizeOrDefault( size );
GtkWidget *list = GTK_COMBO(m_widget)->list;
@@ -660,4 +655,9 @@ bool wxComboBox::IsOwnGtkWindow( GdkWindow *window )
(window == GTK_COMBO(m_widget)->button->window ) );
}
wxSize wxComboBox::DoGetBestSize() const
{
return wxSize(100, 26);
}
#endif

View File

@@ -13,7 +13,7 @@
#include "wx/control.h"
#include "gtk/gtkfeatures.h"
#include "gtk/gtk.h"
//-----------------------------------------------------------------------------
// wxControl
@@ -58,3 +58,12 @@ wxString wxControl::GetLabel() const
}
wxSize wxControl::DoGetBestSize() const
{
GtkRequisition req;
(* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request )
(m_widget, &req );
return wxSize(req.width, req.height);
}

View File

@@ -327,12 +327,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
gtk_widget_show( GTK_WIDGET(m_list) );
wxSize newSize = size;
if (newSize.x == -1)
newSize.x = 100;
if (newSize.y == -1)
newSize.y = 110;
SetSize( newSize.x, newSize.y );
SetSizeOrDefault( size );
if ( style & wxLB_SORT )
{
@@ -939,4 +934,9 @@ void wxListBox::OnInternalIdle()
UpdateWindowUI();
}
wxSize wxListBox::DoGetBestSize() const
{
return wxSize(100, 110);
}
#endif

View File

@@ -69,16 +69,12 @@ bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi
if (m_bitmap.Ok())
{
wxSize newSize = size;
GdkBitmap *mask = (GdkBitmap *) NULL;
if ( m_bitmap.GetMask() )
mask = m_bitmap.GetMask()->GetBitmap();
m_widget = gtk_pixmap_new( m_bitmap.GetPixmap(), mask );
if (newSize.x == -1) newSize.x = m_bitmap.GetWidth();
if (newSize.y == -1) newSize.y = m_bitmap.GetHeight();
SetSize( newSize.x, newSize.y );
SetSizeOrDefault( size );
}
else
{
@@ -116,8 +112,16 @@ void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap )
gtk_pixmap_set( GTK_PIXMAP(m_widget), m_bitmap.GetPixmap(), mask );
}
SetSize( m_bitmap.GetWidth(), m_bitmap.GetHeight() );
SetSizeOrDefault();
}
}
wxSize wxStaticBitmap::DoGetBestSize() const
{
if ( m_bitmap.Ok() )
return wxSize(m_bitmap.GetWidth(), m_bitmap.GetHeight());
else
return wxSize(16, 16); // completely arbitrary
}
#endif

View File

@@ -79,13 +79,7 @@ bool wxStaticText::Create(wxWindow *parent,
static const float labelAlignments[] = { 0.0, 1.0, 0.5 };
gtk_misc_set_alignment(GTK_MISC(m_widget), labelAlignments[justify], 0.0);
GtkRequisition req;
(* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req );
wxSize newSize = size;
if (newSize.x == -1) newSize.x = req.width;
if (newSize.y == -1) newSize.y = req.height;
SetSize( newSize.x, newSize.y );
SetSizeOrDefault( size );
m_parent->DoAddChild( this );
@@ -115,11 +109,7 @@ void wxStaticText::SetLabel( const wxString &label )
// adjust the label size to the new label unless disabled
if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
{
GtkRequisition req;
(* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request )
(m_widget, &req );
SetSize( req.width, req.height );
SetSize( GetBestSize() );
}
}
@@ -128,4 +118,3 @@ void wxStaticText::ApplyWidgetStyle()
SetWidgetStyle();
gtk_widget_set_style( m_widget, m_widgetStyle );
}

View File

@@ -182,10 +182,7 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
m_text = gtk_entry_new();
}
wxSize newSize = size;
if (newSize.x == -1) newSize.x = 80;
if (newSize.y == -1) newSize.y = 26;
SetSize( newSize.x, newSize.y );
SetSizeOrDefault( size );
m_parent->DoAddChild( this );
@@ -966,3 +963,9 @@ void wxTextCtrl::OnInternalIdle()
UpdateWindowUI();
}
wxSize wxTextCtrl::DoGetBestSize() const
{
// FIXME should be different for multi-line controls...
return wxSize(80, 26);
}

View File

@@ -185,7 +185,8 @@ extern bool g_blockEventsOnDrag;
extern bool g_blockEventsOnScroll;
extern wxCursor g_globalCursor;
static wxWindow *g_captureWindow = (wxWindow*) NULL;
extern wxWindow *g_focusWindow = (wxWindow*) NULL;
/* extern */ wxWindow *g_focusWindow = (wxWindow*) NULL;
// if we detect that the app has got/lost the focus, we set this variable to
// either TRUE or FALSE and an activate event will be sent during the next

View File

@@ -106,16 +106,7 @@ bool wxCheckBox::Create(wxWindow *parent,
m_widget = m_widgetCheckbox;
}
wxSize newSize(size);
if (newSize.x == -1)
{
newSize.x = 25 + gdk_string_measure( m_widgetCheckbox->style->font,
m_label.mbc_str() );
}
if (newSize.y == -1)
newSize.y = 26;
SetSize( newSize.x, newSize.y );
SetSizeOrDefault( size );
gtk_signal_connect( GTK_OBJECT(m_widgetCheckbox),
"clicked",
@@ -210,4 +201,10 @@ void wxCheckBox::OnInternalIdle()
UpdateWindowUI();
}
wxSize wxCheckBox::DoGetBestSize() const
{
return wxSize( 25 + gdk_string_measure( m_widgetCheckbox->style->font,
m_label.mbc_str() ), 26 );
}
#endif

View File

@@ -90,12 +90,7 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id,
m_widget = gtk_option_menu_new();
wxSize newSize(size);
if (newSize.x == -1)
newSize.x = 80;
if (newSize.y == -1)
newSize.y = 26;
SetSize( newSize.x, newSize.y );
SetSizeOrDefault( size );
if ( style & wxCB_SORT )
{
@@ -429,4 +424,9 @@ size_t wxChoice::AppendHelper(GtkWidget *menu, const wxString& item)
return index;
}
wxSize wxChoice::DoGetBestSize() const
{
return wxSize(80, 26);
}
#endif

View File

@@ -113,12 +113,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
// make it more useable
gtk_combo_set_use_arrows_always(GTK_COMBO(m_widget), TRUE);
wxSize newSize = size;
if (newSize.x == -1)
newSize.x = 100;
if (newSize.y == -1)
newSize.y = 26;
SetSize( newSize.x, newSize.y );
SetSizeOrDefault( size );
GtkWidget *list = GTK_COMBO(m_widget)->list;
@@ -660,4 +655,9 @@ bool wxComboBox::IsOwnGtkWindow( GdkWindow *window )
(window == GTK_COMBO(m_widget)->button->window ) );
}
wxSize wxComboBox::DoGetBestSize() const
{
return wxSize(100, 26);
}
#endif

View File

@@ -13,7 +13,7 @@
#include "wx/control.h"
#include "gtk/gtkfeatures.h"
#include "gtk/gtk.h"
//-----------------------------------------------------------------------------
// wxControl
@@ -58,3 +58,12 @@ wxString wxControl::GetLabel() const
}
wxSize wxControl::DoGetBestSize() const
{
GtkRequisition req;
(* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request )
(m_widget, &req );
return wxSize(req.width, req.height);
}

View File

@@ -327,12 +327,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
gtk_widget_show( GTK_WIDGET(m_list) );
wxSize newSize = size;
if (newSize.x == -1)
newSize.x = 100;
if (newSize.y == -1)
newSize.y = 110;
SetSize( newSize.x, newSize.y );
SetSizeOrDefault( size );
if ( style & wxLB_SORT )
{
@@ -939,4 +934,9 @@ void wxListBox::OnInternalIdle()
UpdateWindowUI();
}
wxSize wxListBox::DoGetBestSize() const
{
return wxSize(100, 110);
}
#endif

View File

@@ -69,16 +69,12 @@ bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi
if (m_bitmap.Ok())
{
wxSize newSize = size;
GdkBitmap *mask = (GdkBitmap *) NULL;
if ( m_bitmap.GetMask() )
mask = m_bitmap.GetMask()->GetBitmap();
m_widget = gtk_pixmap_new( m_bitmap.GetPixmap(), mask );
if (newSize.x == -1) newSize.x = m_bitmap.GetWidth();
if (newSize.y == -1) newSize.y = m_bitmap.GetHeight();
SetSize( newSize.x, newSize.y );
SetSizeOrDefault( size );
}
else
{
@@ -116,8 +112,16 @@ void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap )
gtk_pixmap_set( GTK_PIXMAP(m_widget), m_bitmap.GetPixmap(), mask );
}
SetSize( m_bitmap.GetWidth(), m_bitmap.GetHeight() );
SetSizeOrDefault();
}
}
wxSize wxStaticBitmap::DoGetBestSize() const
{
if ( m_bitmap.Ok() )
return wxSize(m_bitmap.GetWidth(), m_bitmap.GetHeight());
else
return wxSize(16, 16); // completely arbitrary
}
#endif

View File

@@ -79,13 +79,7 @@ bool wxStaticText::Create(wxWindow *parent,
static const float labelAlignments[] = { 0.0, 1.0, 0.5 };
gtk_misc_set_alignment(GTK_MISC(m_widget), labelAlignments[justify], 0.0);
GtkRequisition req;
(* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req );
wxSize newSize = size;
if (newSize.x == -1) newSize.x = req.width;
if (newSize.y == -1) newSize.y = req.height;
SetSize( newSize.x, newSize.y );
SetSizeOrDefault( size );
m_parent->DoAddChild( this );
@@ -115,11 +109,7 @@ void wxStaticText::SetLabel( const wxString &label )
// adjust the label size to the new label unless disabled
if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
{
GtkRequisition req;
(* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request )
(m_widget, &req );
SetSize( req.width, req.height );
SetSize( GetBestSize() );
}
}
@@ -128,4 +118,3 @@ void wxStaticText::ApplyWidgetStyle()
SetWidgetStyle();
gtk_widget_set_style( m_widget, m_widgetStyle );
}

View File

@@ -182,10 +182,7 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
m_text = gtk_entry_new();
}
wxSize newSize = size;
if (newSize.x == -1) newSize.x = 80;
if (newSize.y == -1) newSize.y = 26;
SetSize( newSize.x, newSize.y );
SetSizeOrDefault( size );
m_parent->DoAddChild( this );
@@ -966,3 +963,9 @@ void wxTextCtrl::OnInternalIdle()
UpdateWindowUI();
}
wxSize wxTextCtrl::DoGetBestSize() const
{
// FIXME should be different for multi-line controls...
return wxSize(80, 26);
}

View File

@@ -185,7 +185,8 @@ extern bool g_blockEventsOnDrag;
extern bool g_blockEventsOnScroll;
extern wxCursor g_globalCursor;
static wxWindow *g_captureWindow = (wxWindow*) NULL;
extern wxWindow *g_focusWindow = (wxWindow*) NULL;
/* extern */ wxWindow *g_focusWindow = (wxWindow*) NULL;
// if we detect that the app has got/lost the focus, we set this variable to
// either TRUE or FALSE and an activate event will be sent during the next

View File

@@ -128,7 +128,7 @@ wxButton::~wxButton()
// size management including autosizing
// ----------------------------------------------------------------------------
wxSize wxButton::DoGetBestSize()
wxSize wxButton::DoGetBestSize() const
{
wxString label = wxGetWindowText(GetHWND());
int wBtn;

View File

@@ -138,7 +138,7 @@ void wxCheckBox::SetLabel(const wxString& label)
SetWindowText(GetHwnd(), label);
}
wxSize wxCheckBox::DoGetBestSize()
wxSize wxCheckBox::DoGetBestSize() const
{
int wCheckbox, hCheckbox;

View File

@@ -119,7 +119,7 @@ bool wxControl::MSWCreateControl(const wxChar *classname,
return TRUE;
}
wxSize wxControl::DoGetBestSize()
wxSize wxControl::DoGetBestSize() const
{
return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
}

View File

@@ -623,7 +623,7 @@ void wxListBox::SetHorizontalExtent(const wxString& s)
}
}
wxSize wxListBox::DoGetBestSize()
wxSize wxListBox::DoGetBestSize() const
{
// find the widest string
int wLine;

View File

@@ -153,7 +153,7 @@ wxSpinButton::~wxSpinButton()
// size calculation
// ----------------------------------------------------------------------------
wxSize wxSpinButton::DoGetBestSize()
wxSize wxSpinButton::DoGetBestSize() const
{
if ( (GetWindowStyle() & wxSP_VERTICAL) != 0 )
{

View File

@@ -207,7 +207,7 @@ bool wxSpinCtrl::SetFont(const wxFont& font)
// size calculations
// ----------------------------------------------------------------------------
wxSize wxSpinCtrl::DoGetBestSize()
wxSize wxSpinCtrl::DoGetBestSize() const
{
wxSize sizeBtn = wxSpinButton::DoGetBestSize();
sizeBtn.x += DEFAULT_ITEM_WIDTH + MARGIN_BETWEEN;

View File

@@ -140,7 +140,7 @@ void wxStaticBitmap::Free()
m_image.icon = NULL;
}
wxSize wxStaticBitmap::DoGetBestSize()
wxSize wxStaticBitmap::DoGetBestSize() const
{
// reuse the current size (as wxWindow does) instead of using some
// arbitrary default size (as wxControl, our immediate base class, does)

View File

@@ -70,7 +70,7 @@ bool wxStaticBox::Create(wxWindow *parent,
return TRUE;
}
wxSize wxStaticBox::DoGetBestSize()
wxSize wxStaticBox::DoGetBestSize() const
{
int cx, cy;
wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());

View File

@@ -94,7 +94,7 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
return TRUE;
}
wxSize wxStaticText::DoGetBestSize()
wxSize wxStaticText::DoGetBestSize() const
{
wxString text(wxGetWindowText(GetHWND()));

View File

@@ -886,7 +886,7 @@ bool wxTextCtrl::AcceptsFocus() const
return IsEditable() && wxControl::AcceptsFocus();
}
wxSize wxTextCtrl::DoGetBestSize()
wxSize wxTextCtrl::DoGetBestSize() const
{
int cx, cy;
wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());

View File

@@ -1257,12 +1257,6 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
DoMoveWindow(x, y, width, height);
}
// for a generic window there is no natural best size - just use the current one
wxSize wxWindow::DoGetBestSize()
{
return GetSize();
}
void wxWindow::DoSetClientSize(int width, int height)
{
wxWindow *parent = GetParent();
@@ -3353,7 +3347,7 @@ bool wxWindow::MSWOnScroll(int orientation, WXWORD wParam,
// global functions
// ===========================================================================
void wxGetCharSize(WXHWND wnd, int *x, int *y,wxFont *the_font)
void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont *the_font)
{
TEXTMETRIC tm;
HDC dc = ::GetDC((HWND) wnd);
@@ -3363,7 +3357,7 @@ void wxGetCharSize(WXHWND wnd, int *x, int *y,wxFont *the_font)
{
// the_font->UseResource();
// the_font->RealizeResource();
fnt = (HFONT)the_font->GetResourceHandle();
fnt = (HFONT)((wxFont *)the_font)->GetResourceHandle(); // const_cast
if ( fnt )
was = (HFONT) SelectObject(dc,fnt);
}