1. wxWindow::IsTopLevel() added and documented

2. wxDynamicClass() added and documented
3. first Motif fixes (doesn't compile yet)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2693 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-06-07 18:26:42 +00:00
parent 6a2dd3f958
commit 34636400a0
13 changed files with 1849 additions and 3084 deletions
+51 -17
View File
@@ -1596,23 +1596,6 @@ Returns a pointer to the wxClassInfo object associated with this class.
<wx/object.h>
\membersection{WXDEBUG\_NEW}\label{debugnew}
\func{}{WXDEBUG\_NEW}{arg}
This is defined in debug mode to be call the redefined new operator
with filename and line number arguments. The definition is:
\begin{verbatim}
#define WXDEBUG_NEW new(__FILE__,__LINE__)
\end{verbatim}
In non-debug mode, this is defined as the normal new operator.
\wxheading{Include files}
<wx/object.h>
\membersection{DECLARE\_ABSTRACT\_CLASS}
\func{}{DECLARE\_ABSTRACT\_CLASS}{className}
@@ -1810,8 +1793,59 @@ base classes.
<wx/object.h>
\membersection{WXDEBUG\_NEW}\label{debugnew}
\func{}{WXDEBUG\_NEW}{arg}
This is defined in debug mode to be call the redefined new operator
with filename and line number arguments. The definition is:
\begin{verbatim}
#define WXDEBUG_NEW new(__FILE__,__LINE__)
\end{verbatim}
In non-debug mode, this is defined as the normal new operator.
\wxheading{Include files}
<wx/object.h>
\membersection{wxDynamicCast}\label{wxdynamiccast}
\func{}{wxDynamicCast}{ptr, classname}
This macro returns the pointer {\it ptr} cast to the type {\it classname *} if
the pointer is of this type (the check is done during the run-time) or NULL
otherwise. Usage of this macro is prefered over obsoleted wxObject::IsKindOf()
function.
The {\it ptr} argument may be NULL, in which case NULL will be returned.
Example:
\begin{verbatim}
wxWindow *win = wxWindow::FindFocus();
wxTextCtrl *text = wxDynamicCast(win, wxTextCtrl);
if ( text )
{
// a text control has the focus...
}
else
{
// no window has the focus or it's not a text control
}
\end{verbatim}
\wxheading{See also}
\helpref{RTTI overview}{runtimeclassoverview}
\membersection{WXTRACE}\label{trace}
\wxheading{Include files}
<wx/object.h>
\func{}{WXTRACE}{formatString, ...}
Calls wxTrace with printf-style variable argument syntax. Output
+29 -16
View File
@@ -2,13 +2,25 @@
Classes: \helpref{wxObject}{wxobject}, \helpref{wxClassInfo}{wxclassinfo}.
One of the failings of C++ is that no run-time information is provided
One of the failings of C++ used to be that no run-time information was provided
about a class and its position in the inheritance hierarchy.
Another is that instances of a class cannot be created just by knowing the name of a class,
which makes facilities such as persistent storage hard to implement.
Another, which still persists, is that instances of a class cannot be created
just by knowing the name of a class, which makes facilities such as persistent
storage hard to implement.
Most C++ GUI frameworks overcome these limitations by means of a set of
macros and functions and wxWindows is no exception.
macros and functions and wxWindows is no exception. As it originated before the
addition of RTTI to the standard C++ and as support for it still missing from
some (albeit old) compilers, wxWindows doesn't (yet) use it, but provides its
own macro-based RTTI system.
In the future, the standard C++ RTTI will be used though and you're encouraged
to use whenever possible \helpref{wxDynamicCast()}{wxdynamiccast} macro which,
for the implementations that support it, is defined just as dynamic\_cast<> and
uses wxWindows RTTI for all the others. This macro is limited to wxWindows
classes only and only works with pointers (unlike the real dynamic\_cast<> which
also accepts referencies).
Each class that you wish to be known the type system should have
a macro such as DECLARE\_DYNAMIC\_CLASS just inside the class declaration.
The macro IMPLEMENT\_DYNAMIC\_CLASS should be in the implementation file.
@@ -31,9 +43,9 @@ dynamic object of the class in question. A pointer to this function is
stored in wxClassInfo, and is used when an object should be created
dynamically.
wxObject::IsKindOf uses the linked list of wxClassInfo. It takes
a wxClassInfo argument, so use CLASSINFO(className) to return an
appropriate wxClassInfo pointer to use in this function.
\helpref{wxObject::IsKindOf}{wxobjectiskindof} uses the linked list of
wxClassInfo. It takes a wxClassInfo argument, so use CLASSINFO(className)
to return an appropriate wxClassInfo pointer to use in this function.
The function \helpref{wxCreateDynamicObject}{wxcreatedynamicobject} can be used
to construct a new object of a given type, by supplying a string name.
@@ -68,26 +80,27 @@ See also \helpref{wxObject}{wxobject} and \helpref{wxCreateDynamicObject}{wxcrea
\subsection{Example}
In a header file wx\_frame.h:
In a header file frame.h:
\begin{verbatim}
class wxFrame: public wxWindow
class wxFrame : public wxWindow
{
DECLARE_DYNAMIC_CLASS(wxFrame)
DECLARE_DYNAMIC_CLASS(wxFrame)
private:
char *frameTitle;
public:
...
private:
wxString m_title;
public:
...
};
\end{verbatim}
In a C++ file wx\_frame.cc:
In a C++ file frame.cpp:
\begin{verbatim}
IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
wxFrame::wxFrame(void)
wxFrame::wxFrame()
{
...
}
+10 -2
View File
@@ -253,9 +253,9 @@ implements the following methods:\par
Additionally, the following helper functions are defined:\par
\indented{2cm}{\begin{twocollist}
\twocolitem{\bf{wxDLG_PNT(win, point)}}{Converts a wxPoint from dialog
\twocolitem{\bf{wxDLG\_PNT(win, point)}}{Converts a wxPoint from dialog
units to pixels}
\twocolitem{\bf{wxDLG_SZE(win, size)}}{Converts a wxSize from dialog
\twocolitem{\bf{wxDLG\_SZE(win, size)}}{Converts a wxSize from dialog
units to pixels}
\end{twocollist}}
}
@@ -757,6 +757,14 @@ Retained windows are only available on X platforms.
Returns TRUE if the window is shown, FALSE if it has been hidden.
\membersection{wxWindow::IsTopLevel}\label{wxwindowistoplevel}
\constfunc{bool}{IsTopLevel}{\void}
Returns TRUE if the given window is a top-level one. Currently all frames and
dialogs are considered to be top-level windows (even if they have a parent
window).
\membersection{wxWindow::Layout}\label{wxwindowlayout}
\func{void}{Layout}{\void}
+7 -3
View File
@@ -523,9 +523,13 @@ typedef wxUint16 wxWord;
#define wxWANTS_CHARS 0x00040000
// Orientations
#define wxHORIZONTAL 0x01
#define wxVERTICAL 0x02
#define wxBOTH (wxVERTICAL|wxHORIZONTAL)
enum wxOrientation
{
wxHORIZONTAL = 0x01,
wxVERTICAL = 0x02,
wxBOTH = (wxVERTICAL | wxHORIZONTAL)
};
#define wxCENTER_FRAME 0x04 /* centering into frame rather than screen */
/*
+29 -13
View File
@@ -1,12 +1,12 @@
/////////////////////////////////////////////////////////////////////////////
// Name: private.h
// Purpose: Private declarations
// Purpose: Private declarations for wxMotif port
// Author: Julian Smart
// Modified by:
// Created: 17/09/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PRIVATE_H_
@@ -14,37 +14,53 @@
#include "wx/defs.h"
class WXDLLEXPORT wxMouseEvent;
class WXDLLEXPORT wxKeyEvent;
class wxMouseEvent;
class wxKeyEvent;
/* Put any private declarations here.
*/
// Put any private declarations here: native Motif types may be used because
// this header is included after Xm/Xm.h
// ----------------------------------------------------------------------------
// common callbacks
// ----------------------------------------------------------------------------
// All widgets should have this as their resize proc.
extern void wxWidgetResizeProc(Widget w, XConfigureEvent *event, String args[], int *num_args);
extern wxHashTable *wxWidgetHashTable;
// For repainting arbitrary windows
void wxUniversalRepaintProc(Widget w, XtPointer WXUNUSED(c_data), XEvent *event, char *);
// ----------------------------------------------------------------------------
// we maintain a hash table which contains the mapping from Widget to wxWindow
// corresponding to the window for this widget
// ----------------------------------------------------------------------------
extern void wxDeleteWindowFromTable(Widget w);
extern wxWindow *wxGetWindowFromTable(Widget w);
extern bool wxAddWindowToTable(Widget w, wxWindow *win);
extern char wxFindMnemonic(const char* s);
extern char * wxFindAccelerator (char *s);
extern XmString wxFindAcceleratorText (char *s);
extern int wxCharCodeXToWX(KeySym keySym);
extern KeySym wxCharCodeWXToX(int id);
bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent);
bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent);
// ----------------------------------------------------------------------------
// TranslateXXXEvent() functions - translate Motif event to wxWindow one
// ----------------------------------------------------------------------------
extern bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent);
extern bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent);
int wxGetBestMatchingPixel(Display *display, XColor *desiredColor, Colormap cmap);
Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap );
extern XColor g_itemColors[];
extern int wxComputeColours (Display *display, wxColour * back, wxColour * fore);
extern void wxDoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour);
extern void wxDoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, bool changeArmColour = FALSE);
// For repainting arbitrary windows
void wxUniversalRepaintProc(Widget w, XtPointer WXUNUSED(c_data), XEvent *event, char *);
#define wxNO_COLORS 0x00
#define wxNO_COLORS 0x00
#define wxBACK_COLORS 0x01
#define wxFORE_COLORS 0x02
+1 -1
View File
@@ -64,7 +64,7 @@ class WXDLLEXPORT wxToolBar: public wxToolBarBase
// Add all the buttons
virtual bool CreateTools();
virtual void Layout() {}
virtual void LayoutTools() {}
// The post-tool-addition call. TODO: do here whatever's
// necessary for completing the toolbar construction.
+152 -628
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -144,7 +144,7 @@ public:
virtual void OnDefaultAction(wxControl * WXUNUSED(initiatingItem)) { }
#endif // WXWIN_COMPATIBILITY
#if wxUSE_CARET
#if wxUSE_CARET && WXWIN_COMPATIBILITY
// caret manipulation (old MSW only functions, see wxCaret class for the
// new API)
void CreateCaret(int w, int h);
+15 -9
View File
@@ -138,19 +138,19 @@ wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
// Single inheritance with one base class
#define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
wxClassInfo name::sm_class##name((wxChar *) _T(#name), (wxChar *) _T(#basename), \
(wxChar *) NULL, (int) sizeof(name), (wxObjectConstructorFn) NULL);
(wxChar *) NULL, (int) sizeof(name), (wxObjectConstructorFn) NULL);
// Multiple inheritance with two base classes
#define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
wxClassInfo name::sm_class##name((wxChar *) _T(#name), (wxChar *) _T(#basename1), \
(wxChar *) _T(#basename2), (int) sizeof(name), (wxObjectConstructorFn) NULL);
(wxChar *) _T(#basename2), (int) sizeof(name), (wxObjectConstructorFn) NULL);
#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
#define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
#define CLASSINFO(name) (&name::sm_class##name)
#else
#else // !wxUSE_DYNAMIC_CLASSES
// No dynamic class system: so stub out the macros
#define DECLARE_DYNAMIC_CLASS(name)
@@ -163,20 +163,26 @@ wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
#define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
#endif
#endif // wxUSE_DYNAMIC_CLASSES/!wxUSE_DYNAMIC_CLASSES
#define wxIS_KIND_OF(obj, className) obj->IsKindOf(&className::sm_class##className)
// Just seems a bit nicer-looking (pretend it's not a macro)
#define wxIsKindOf(obj, className) obj->IsKindOf(&className::sm_class##className)
// to be replaced by dynamic_cast<> in the future
#define wxDynamicCast(obj, className) \
((obj) && ((obj)->IsKindOf(&className::sm_class##className)) \
? (className *)(obj) \
: (className *)0)
// Unfortunately Borland seems to need this include.
#ifdef __BORLANDC__
#if wxUSE_IOSTREAMH
#include <iostream.h>
#else
#include <iostream>
#endif
#if wxUSE_IOSTREAMH
#include <iostream.h>
#else
#include <iostream>
#endif
#endif
class WXDLLEXPORT wxObjectRefData;
+1 -1
View File
@@ -324,7 +324,7 @@ public:
inline wxWindow *GetGrandParent() const;
// is this window a top level one?
bool IsTopLevel() const { return m_parent != 0; }
bool IsTopLevel() const;
// it doesn't really change parent, use ReParent() instead
void SetParent( wxWindowBase *parent ) { m_parent = (wxWindow *)parent; }
+40 -16
View File
@@ -326,10 +326,9 @@ void wxWindowBase::Fit()
while ( node )
{
wxWindow *win = node->GetData();
if ( win->IsKindOf(CLASSINFO(wxFrame)) ||
win->IsKindOf(CLASSINFO(wxDialog)) )
if ( win->IsTopLevel() )
{
// dialogs and frames line in different top level windows - don't
// dialogs and frames lie in different top level windows - don't
// deal with them here
continue;
}
@@ -392,6 +391,14 @@ bool wxWindowBase::Enable(bool enable)
return FALSE;
}
}
// ----------------------------------------------------------------------------
// RTTI
// ----------------------------------------------------------------------------
bool wxWindowBase::IsTopLevel() const
{
return wxDynamicCast(this, wxFrame) || wxDynamicCast(this, wxDialog);
}
// ----------------------------------------------------------------------------
// reparenting the window
@@ -618,9 +625,21 @@ wxWindow *wxWindowBase::FindWindow( const wxString& name )
// dialog oriented functions
// ----------------------------------------------------------------------------
void wxWindowBase::MakeModal(bool WXUNUSED(modal))
void wxWindowBase::MakeModal(bool modal)
{
wxFAIL_MSG(_T("TODO"));
// Disable all other windows
if ( IsTopLevel() )
{
wxWindowList::Node *node = wxTopLevelWindows.GetFirst();
while (node)
{
wxWindow *win = node->GetData();
if (win != this)
win->Enable(!modal);
node = node->GetNext();
}
}
}
bool wxWindowBase::Validate()
@@ -914,7 +933,7 @@ bool wxWindowBase::DoPhase(int phase)
while (node)
{
wxWindow *child = node->GetData();
if ( !child->IsKindOf(CLASSINFO(wxFrame)) && !child->IsKindOf(CLASSINFO(wxDialog)) )
if ( !child->IsTopLevel() )
{
wxLayoutConstraints *constr = child->GetConstraints();
if ( constr )
@@ -958,7 +977,7 @@ void wxWindowBase::ResetConstraints()
while (node)
{
wxWindow *win = node->GetData();
if ( !win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)) )
if ( !win->IsTopLevel() )
win->ResetConstraints();
node = node->GetNext();
}
@@ -1015,7 +1034,7 @@ void wxWindowBase::SetConstraintSizes(bool recurse)
while (node)
{
wxWindow *win = node->GetData();
if ( !win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)) )
if ( !win->IsTopLevel() )
win->SetConstraintSizes();
node = node->GetNext();
}
@@ -1026,8 +1045,7 @@ void wxWindowBase::SetConstraintSizes(bool recurse)
// this window.
void wxWindowBase::TransformSizerToActual(int *x, int *y) const
{
if ( !m_sizerParent || m_sizerParent->IsKindOf(CLASSINFO(wxDialog) ) ||
m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) )
if ( !m_sizerParent || m_sizerParent->IsTopLevel() )
return;
int xp, yp;
@@ -1159,22 +1177,28 @@ void wxWindowBase::UpdateWindowUI()
if ( event.GetSetEnabled() )
Enable(event.GetEnabled());
if ( event.GetSetText() && IsKindOf(CLASSINFO(wxControl)) )
((wxControl*)this)->SetLabel(event.GetText());
if ( event.GetSetText() )
{
wxControl *control = wxDynamicCast(this, wxControl);
if ( control )
control->SetLabel(event.GetText());
}
#if wxUSE_CHECKBOX
if ( IsKindOf(CLASSINFO(wxCheckBox)) )
wxCheckBox *checkbox = wxDynamicCast(this, wxCheckBox);
if ( checkbox )
{
if ( event.GetSetChecked() )
((wxCheckBox *)this)->SetValue(event.GetChecked());
checkbox->SetValue(event.GetChecked());
}
#endif // wxUSE_CHECKBOX
#if wxUSE_RADIOBUTTON
if ( IsKindOf(CLASSINFO(wxRadioButton)) )
wxRadioButton *radiobtn = wxDynamicCast(this, wxRadioButton);
if ( radiobtn )
{
if ( event.GetSetChecked() )
((wxRadioButton *) this)->SetValue(event.GetChecked());
radiobtn->SetValue(event.GetChecked());
}
#endif // wxUSE_RADIOBUTTON
}
+1510 -2375
View File
File diff suppressed because it is too large Load Diff
+3 -2
View File
@@ -1018,7 +1018,7 @@ void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
// drag and drop
// ---------------------------------------------------------------------------
#if wxUSE_DRAG_AND_DROP
#if wxUSE_DRAG_AND_DROP
void wxWindow::SetDropTarget(wxDropTarget *pDropTarget)
{
@@ -1272,7 +1272,8 @@ int wxWindow::GetCharWidth() const
return lpTextMetric.tmAveCharWidth;
}
void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
void wxWindow::GetTextExtent(const wxString& string,
int *x, int *y,
int *descent, int *externalLeading,
const wxFont *theFont) const
{