adding new files for xti merge
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66544 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
204
samples/xti/Makefile.in
Normal file
204
samples/xti/Makefile.in
Normal file
@@ -0,0 +1,204 @@
|
||||
# =========================================================================
|
||||
# This makefile was generated by
|
||||
# Bakefile 0.2.2 (http://www.bakefile.org)
|
||||
# Do not modify, all changes will be overwritten!
|
||||
# =========================================================================
|
||||
|
||||
|
||||
@MAKE_SET@
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
INSTALL = @INSTALL@
|
||||
EXEEXT = @EXEEXT@
|
||||
WINDRES = @WINDRES@
|
||||
REZ = @REZ@
|
||||
SETFILE = @SETFILE@
|
||||
NM = @NM@
|
||||
BK_DEPS = @BK_DEPS@
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
LIBS = @LIBS@
|
||||
LDFLAGS_GUI = @LDFLAGS_GUI@
|
||||
CXX = @CXX@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
WX_LIB_FLAVOUR = @WX_LIB_FLAVOUR@
|
||||
TOOLKIT = @TOOLKIT@
|
||||
TOOLKIT_LOWERCASE = @TOOLKIT_LOWERCASE@
|
||||
TOOLKIT_VERSION = @TOOLKIT_VERSION@
|
||||
TOOLCHAIN_FULLNAME = @TOOLCHAIN_FULLNAME@
|
||||
EXTRALIBS = @EXTRALIBS@
|
||||
EXTRALIBS_XML = @EXTRALIBS_XML@
|
||||
EXTRALIBS_GUI = @EXTRALIBS_GUI@
|
||||
CXXWARNINGS = @CXXWARNINGS@
|
||||
HOST_SUFFIX = @HOST_SUFFIX@
|
||||
SAMPLES_RPATH_FLAG = @SAMPLES_RPATH_FLAG@
|
||||
SAMPLES_RPATH_POSTLINK = @SAMPLES_RPATH_POSTLINK@
|
||||
wx_top_builddir = @wx_top_builddir@
|
||||
|
||||
### Variables: ###
|
||||
|
||||
DESTDIR =
|
||||
WX_RELEASE = 2.9
|
||||
WX_VERSION = $(WX_RELEASE).0
|
||||
LIBDIRNAME = $(wx_top_builddir)/lib
|
||||
XTI_CXXFLAGS = -D__WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p) \
|
||||
$(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) $(__THREAD_DEFINE_p) \
|
||||
-I$(srcdir) $(__DLLFLAG_p) -I$(srcdir)/../../samples $(CXXWARNINGS) \
|
||||
$(CPPFLAGS) $(CXXFLAGS)
|
||||
XTI_OBJECTS = \
|
||||
$(__xti___win32rc) \
|
||||
$(__xti_os2_lib_res) \
|
||||
xti_xti.o \
|
||||
xti_classlist.o \
|
||||
xti_codereadercallback.o
|
||||
|
||||
### Conditionally set variables: ###
|
||||
|
||||
@COND_DEPS_TRACKING_0@CXXC = $(CXX)
|
||||
@COND_DEPS_TRACKING_1@CXXC = $(BK_DEPS) $(CXX)
|
||||
@COND_USE_GUI_0@PORTNAME = base
|
||||
@COND_USE_GUI_1@PORTNAME = $(TOOLKIT_LOWERCASE)$(TOOLKIT_VERSION)
|
||||
@COND_TOOLKIT_MAC@WXBASEPORT = _carbon
|
||||
@COND_BUILD_DEBUG_DEBUG_FLAG_DEFAULT@WXDEBUGFLAG = d
|
||||
@COND_DEBUG_FLAG_1@WXDEBUGFLAG = d
|
||||
@COND_UNICODE_1@WXUNICODEFLAG = u
|
||||
@COND_WXUNIV_1@WXUNIVNAME = univ
|
||||
@COND_MONOLITHIC_0@EXTRALIBS_FOR_BASE = $(EXTRALIBS)
|
||||
@COND_MONOLITHIC_1@EXTRALIBS_FOR_BASE = $(EXTRALIBS) $(EXTRALIBS_GUI)
|
||||
@COND_MONOLITHIC_0@EXTRALIBS_FOR_GUI = $(EXTRALIBS_GUI)
|
||||
@COND_MONOLITHIC_1@EXTRALIBS_FOR_GUI =
|
||||
@COND_PLATFORM_MAC_1@__xti___mac_setfilecmd = $(SETFILE) -a C xti$(EXEEXT)
|
||||
@COND_PLATFORM_MAC_1@__xti___mac_rezcmd = $(__MACOSX_RESOURCES_p_1)
|
||||
@COND_WXUNIV_1@__WXUNIV_DEFINE_p = -D__WXUNIVERSAL__
|
||||
@COND_WXUNIV_1@__WXUNIV_DEFINE_p_1 = -d __WXUNIVERSAL__
|
||||
@COND_WXUNIV_1@__WXUNIV_DEFINE_p_2 = --define __WXUNIVERSAL__
|
||||
@COND_USE_EXCEPTIONS_0@__EXCEPTIONS_DEFINE_p = -DwxNO_EXCEPTIONS
|
||||
@COND_USE_EXCEPTIONS_0@__EXCEPTIONS_DEFINE_p_1 = -d wxNO_EXCEPTIONS
|
||||
@COND_USE_EXCEPTIONS_0@__EXCEPTIONS_DEFINE_p_2 = --define wxNO_EXCEPTIONS
|
||||
@COND_USE_RTTI_0@__RTTI_DEFINE_p = -DwxNO_RTTI
|
||||
@COND_USE_RTTI_0@__RTTI_DEFINE_p_1 = -d wxNO_RTTI
|
||||
@COND_USE_RTTI_0@__RTTI_DEFINE_p_2 = --define wxNO_RTTI
|
||||
@COND_USE_THREADS_0@__THREAD_DEFINE_p = -DwxNO_THREADS
|
||||
@COND_USE_THREADS_0@__THREAD_DEFINE_p_1 = -d wxNO_THREADS
|
||||
@COND_USE_THREADS_0@__THREAD_DEFINE_p_2 = --define wxNO_THREADS
|
||||
@COND_SHARED_1@__DLLFLAG_p = -DWXUSINGDLL
|
||||
@COND_SHARED_1@__DLLFLAG_p_1 = -d WXUSINGDLL
|
||||
@COND_SHARED_1@__DLLFLAG_p_2 = --define WXUSINGDLL
|
||||
COND_PLATFORM_OS2_1___xti___os2_emxbindcmd = $(NM) xti$(EXEEXT) | if grep -q \
|
||||
pmwin.763 ; then emxbind -ep xti$(EXEEXT) ; fi
|
||||
@COND_PLATFORM_OS2_1@__xti___os2_emxbindcmd = $(COND_PLATFORM_OS2_1___xti___os2_emxbindcmd)
|
||||
@COND_TOOLKIT_MSW@__RCDEFDIR_p = -i \
|
||||
@COND_TOOLKIT_MSW@ $(LIBDIRNAME)/wx/include/$(TOOLCHAIN_FULLNAME)
|
||||
@COND_TOOLKIT_MSW@__RCDEFDIR_p_1 = --include-dir \
|
||||
@COND_TOOLKIT_MSW@ $(LIBDIRNAME)/wx/include/$(TOOLCHAIN_FULLNAME)
|
||||
@COND_PLATFORM_WIN32_1@__xti___win32rc = xti_sample_rc.o
|
||||
@COND_PLATFORM_OS2_1@__xti_os2_lib_res = \
|
||||
@COND_PLATFORM_OS2_1@ $(top_srcdir)/include/wx/os2/wx.res
|
||||
@COND_PLATFORM_MACOSX_1@__xti_bundle___depname = xti_bundle
|
||||
@COND_TOOLKIT_COCOA@____xti_BUNDLE_TGT_REF_DEP = xti.app/Contents/PkgInfo
|
||||
@COND_TOOLKIT_MAC@____xti_BUNDLE_TGT_REF_DEP = xti.app/Contents/PkgInfo
|
||||
COND_MONOLITHIC_0___WXLIB_CORE_p = \
|
||||
-lwx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_core-$(WX_RELEASE)$(HOST_SUFFIX)
|
||||
@COND_MONOLITHIC_0@__WXLIB_CORE_p = $(COND_MONOLITHIC_0___WXLIB_CORE_p)
|
||||
COND_MONOLITHIC_0___WXLIB_XML_p = \
|
||||
-lwx_base$(WXBASEPORT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_xml-$(WX_RELEASE)$(HOST_SUFFIX)
|
||||
@COND_MONOLITHIC_0@__WXLIB_XML_p = $(COND_MONOLITHIC_0___WXLIB_XML_p)
|
||||
COND_MONOLITHIC_0___WXLIB_BASE_p = \
|
||||
-lwx_base$(WXBASEPORT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)-$(WX_RELEASE)$(HOST_SUFFIX)
|
||||
@COND_MONOLITHIC_0@__WXLIB_BASE_p = $(COND_MONOLITHIC_0___WXLIB_BASE_p)
|
||||
COND_MONOLITHIC_1___WXLIB_MONO_p = \
|
||||
-lwx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)-$(WX_RELEASE)$(HOST_SUFFIX)
|
||||
@COND_MONOLITHIC_1@__WXLIB_MONO_p = $(COND_MONOLITHIC_1___WXLIB_MONO_p)
|
||||
@COND_USE_GUI_1_WXUSE_LIBTIFF_BUILTIN@__LIB_TIFF_p \
|
||||
@COND_USE_GUI_1_WXUSE_LIBTIFF_BUILTIN@ = \
|
||||
@COND_USE_GUI_1_WXUSE_LIBTIFF_BUILTIN@ -lwxtiff$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)-$(WX_RELEASE)$(HOST_SUFFIX)
|
||||
@COND_USE_GUI_1_WXUSE_LIBJPEG_BUILTIN@__LIB_JPEG_p \
|
||||
@COND_USE_GUI_1_WXUSE_LIBJPEG_BUILTIN@ = \
|
||||
@COND_USE_GUI_1_WXUSE_LIBJPEG_BUILTIN@ -lwxjpeg$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)-$(WX_RELEASE)$(HOST_SUFFIX)
|
||||
@COND_USE_GUI_1_WXUSE_LIBPNG_BUILTIN@__LIB_PNG_p \
|
||||
@COND_USE_GUI_1_WXUSE_LIBPNG_BUILTIN@ = \
|
||||
@COND_USE_GUI_1_WXUSE_LIBPNG_BUILTIN@ -lwxpng$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)-$(WX_RELEASE)$(HOST_SUFFIX)
|
||||
@COND_WXUSE_ZLIB_BUILTIN@__LIB_ZLIB_p = \
|
||||
@COND_WXUSE_ZLIB_BUILTIN@ -lwxzlib$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)-$(WX_RELEASE)$(HOST_SUFFIX)
|
||||
@COND_WXUSE_ODBC_BUILTIN@__LIB_ODBC_p = \
|
||||
@COND_WXUSE_ODBC_BUILTIN@ -lwxodbc$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)-$(WX_RELEASE)$(HOST_SUFFIX)
|
||||
COND_WXUSE_REGEX_BUILTIN___LIB_REGEX_p = \
|
||||
-lwxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)-$(WX_RELEASE)$(HOST_SUFFIX)
|
||||
@COND_WXUSE_REGEX_BUILTIN@__LIB_REGEX_p = $(COND_WXUSE_REGEX_BUILTIN___LIB_REGEX_p)
|
||||
@COND_WXUSE_EXPAT_BUILTIN@__LIB_EXPAT_p = \
|
||||
@COND_WXUSE_EXPAT_BUILTIN@ -lwxexpat$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)-$(WX_RELEASE)$(HOST_SUFFIX)
|
||||
COND_TOOLKIT_MAC___MACOSX_RESOURCES_p_1 = $(REZ) -d __DARWIN__ -t APPL -d \
|
||||
__WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p_1) $(__EXCEPTIONS_DEFINE_p_1) \
|
||||
$(__RTTI_DEFINE_p_1) $(__THREAD_DEFINE_p_1) -i $(srcdir) $(__DLLFLAG_p_1) -i \
|
||||
$(srcdir)/../../samples $(__RCDEFDIR_p) -i $(top_srcdir)/include -o \
|
||||
xti$(EXEEXT) Carbon.r sample.r
|
||||
@COND_TOOLKIT_MAC@__MACOSX_RESOURCES_p_1 = $(COND_TOOLKIT_MAC___MACOSX_RESOURCES_p_1)
|
||||
|
||||
### Targets: ###
|
||||
|
||||
all: xti$(EXEEXT) $(__xti_bundle___depname)
|
||||
|
||||
install: all
|
||||
|
||||
uninstall:
|
||||
|
||||
install-strip: install
|
||||
|
||||
clean:
|
||||
rm -rf ./.deps ./.pch
|
||||
rm -f ./*.o
|
||||
rm -f xti$(EXEEXT)
|
||||
rm -rf xti.app
|
||||
|
||||
distclean: clean
|
||||
rm -f config.cache config.log config.status bk-deps bk-make-pch shared-ld-sh Makefile
|
||||
|
||||
xti$(EXEEXT): $(XTI_OBJECTS) $(__xti___win32rc)
|
||||
$(CXX) -o $@ $(XTI_OBJECTS) $(LDFLAGS) -L$(LIBDIRNAME) $(LDFLAGS_GUI) $(SAMPLES_RPATH_FLAG) $(LIBS) $(__WXLIB_CORE_p) $(__WXLIB_XML_p) $(EXTRALIBS_XML) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) $(EXTRALIBS_FOR_GUI) $(__LIB_ZLIB_p) $(__LIB_ODBC_p) $(__LIB_REGEX_p) $(__LIB_EXPAT_p) $(EXTRALIBS_FOR_BASE)
|
||||
$(__xti___mac_rezcmd)
|
||||
$(__xti___mac_setfilecmd)
|
||||
$(__xti___os2_emxbindcmd)
|
||||
$(SAMPLES_RPATH_POSTLINK)
|
||||
|
||||
xti.app/Contents/PkgInfo: xti$(EXEEXT) $(top_srcdir)/src/mac/carbon/Info.plist.in $(top_srcdir)/src/mac/carbon/wxmac.icns
|
||||
mkdir -p xti.app/Contents
|
||||
mkdir -p xti.app/Contents/MacOS
|
||||
mkdir -p xti.app/Contents/Resources
|
||||
|
||||
|
||||
sed -e "s/IDENTIFIER/`echo $(srcdir) | sed -e 's,\.\./,,g' | sed -e 's,/,.,g'`/" \
|
||||
-e "s/EXECUTABLE/xti/" \
|
||||
-e "s/VERSION/$(WX_VERSION)/" \
|
||||
$(top_srcdir)/src/mac/carbon/Info.plist.in >xti.app/Contents/Info.plist
|
||||
|
||||
|
||||
echo -n "APPL????" >xti.app/Contents/PkgInfo
|
||||
|
||||
|
||||
ln -f xti$(EXEEXT) xti.app/Contents/MacOS/xti
|
||||
|
||||
|
||||
cp -f $(top_srcdir)/src/mac/carbon/wxmac.icns xti.app/Contents/Resources/wxmac.icns
|
||||
|
||||
@COND_PLATFORM_MACOSX_1@xti_bundle: $(____xti_BUNDLE_TGT_REF_DEP)
|
||||
|
||||
xti_sample_rc.o: $(srcdir)/../../samples/sample.rc
|
||||
$(WINDRES) -i$< -o$@ --define __WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p_2) $(__EXCEPTIONS_DEFINE_p_2) $(__RTTI_DEFINE_p_2) $(__THREAD_DEFINE_p_2) --include-dir $(srcdir) $(__DLLFLAG_p_2) --include-dir $(srcdir)/../../samples $(__RCDEFDIR_p_1) --include-dir $(top_srcdir)/include
|
||||
|
||||
xti_xti.o: $(srcdir)/xti.cpp
|
||||
$(CXXC) -c -o $@ $(XTI_CXXFLAGS) $(srcdir)/xti.cpp
|
||||
|
||||
xti_classlist.o: $(srcdir)/classlist.cpp
|
||||
$(CXXC) -c -o $@ $(XTI_CXXFLAGS) $(srcdir)/classlist.cpp
|
||||
|
||||
xti_codereadercallback.o: $(srcdir)/codereadercallback.cpp
|
||||
$(CXXC) -c -o $@ $(XTI_CXXFLAGS) $(srcdir)/codereadercallback.cpp
|
||||
|
||||
|
||||
# Include dependency info, if present:
|
||||
@IF_GNU_MAKE@-include .deps/*.d
|
||||
|
||||
.PHONY: all install uninstall clean distclean xti_bundle
|
560
samples/xti/classlist.cpp
Normal file
560
samples/xti/classlist.cpp
Normal file
@@ -0,0 +1,560 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: classlist.cpp
|
||||
// Purpose: ClassListDialog implementation
|
||||
// Author: Francesco Montorsi
|
||||
// Modified by:
|
||||
// Created: 03/06/2007 14:49:55
|
||||
// RCS-ID: $Id: classlist.cpp 48186 2007-08-19 19:59:54Z FM $
|
||||
// Copyright: (c) 2007 Francesco Montorsi
|
||||
// Licence: wxWidgets license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx/wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
|
||||
#include "classlist.h"
|
||||
|
||||
#if !wxUSE_EXTENDED_RTTI
|
||||
#error This sample requires XTI (eXtended RTTI) enabled
|
||||
#endif
|
||||
|
||||
// IMPLEMENT_DYNAMIC_CLASS( ClassListDialog, wxDialog ) -- see the header
|
||||
BEGIN_EVENT_TABLE( ClassListDialog, wxDialog )
|
||||
EVT_LISTBOX( ID_LISTBOX, ClassListDialog::OnListboxSelected )
|
||||
EVT_TREE_SEL_CHANGED( ID_TREECTRL, ClassListDialog::OnTreectrlSelChanged )
|
||||
EVT_CHOICEBOOK_PAGE_CHANGED( ID_LISTMODE, ClassListDialog::OnChoiceBookPageChange )
|
||||
|
||||
EVT_CHECKBOX( ID_SHOW_ONLY_XTI, ClassListDialog::OnShowOnlyXTICheckbox )
|
||||
EVT_CHECKBOX( ID_SHOW_PROPERTIES_RECURSIVELY, ClassListDialog::OnShowRecursiveInfoCheckbox )
|
||||
END_EVENT_TABLE()
|
||||
|
||||
// defined later
|
||||
wxString DumpClassInfo(const wxClassInfo*, bool recursive);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ClassListDialog
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
ClassListDialog::ClassListDialog()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
ClassListDialog::ClassListDialog( wxWindow* parent, wxWindowID id,
|
||||
const wxString& caption, const wxPoint& pos,
|
||||
const wxSize& size, long style )
|
||||
{
|
||||
Init();
|
||||
Create(parent, id, caption, pos, size, style);
|
||||
}
|
||||
|
||||
bool ClassListDialog::Create( wxWindow* parent, wxWindowID id, const wxString& caption,
|
||||
const wxPoint& pos, const wxSize& size, long style )
|
||||
{
|
||||
SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
|
||||
wxDialog::Create( parent, id, caption, pos, size, style );
|
||||
|
||||
CreateControls();
|
||||
if (GetSizer())
|
||||
{
|
||||
GetSizer()->SetSizeHints(this);
|
||||
}
|
||||
Centre();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ClassListDialog::~ClassListDialog()
|
||||
{
|
||||
}
|
||||
|
||||
void ClassListDialog::Init()
|
||||
{
|
||||
m_pClassCountText = NULL;
|
||||
m_pRawListBox = NULL;
|
||||
m_pParentTreeCtrl = NULL;
|
||||
m_pSizeListBox = NULL;
|
||||
m_pTextCtrl = NULL;
|
||||
}
|
||||
|
||||
void ClassListDialog::CreateControls()
|
||||
{
|
||||
wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
|
||||
this->SetSizer(itemBoxSizer2);
|
||||
|
||||
wxStaticText* itemStaticText3 = new wxStaticText( this, wxID_STATIC, _("This is the list of wxWidgets classes registered in the XTI system.\nNote that not all wxWidgets classes are registered nor all registered classes are completely _described_ using XTI metadata."), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
itemBoxSizer2->Add(itemStaticText3, 0, wxALIGN_LEFT|wxALL, 5);
|
||||
|
||||
// filters
|
||||
wxBoxSizer* filters = new wxBoxSizer(wxHORIZONTAL);
|
||||
itemBoxSizer2->Add(filters, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);
|
||||
filters->Add(new wxCheckBox(this, ID_SHOW_ONLY_XTI,
|
||||
wxT("Show only classes with eXtended infos")));
|
||||
filters->AddSpacer(10);
|
||||
filters->Add(new wxCheckBox(this, ID_SHOW_PROPERTIES_RECURSIVELY,
|
||||
wxT("Show properties of parent classes")));
|
||||
|
||||
// show how many have we filtered out
|
||||
m_pClassCountText = new wxStaticText( this, wxID_STATIC,
|
||||
wxT("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"),
|
||||
wxDefaultPosition, wxDefaultSize, 0 );
|
||||
m_pClassCountText->SetFont(wxFont(8, wxSWISS, wxNORMAL, wxBOLD, false, wxT("Tahoma")));
|
||||
itemBoxSizer2->Add(m_pClassCountText, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxBOTTOM, 5);
|
||||
|
||||
wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
|
||||
itemBoxSizer2->Add(itemBoxSizer5, 1, wxGROW, 5);
|
||||
|
||||
m_pChoiceBook = new wxChoicebook( this, ID_LISTMODE, wxDefaultPosition, wxDefaultSize, wxCHB_DEFAULT );
|
||||
|
||||
// raw-list page
|
||||
wxPanel* itemPanel7 = new wxPanel( m_pChoiceBook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
|
||||
wxBoxSizer* itemBoxSizer8 = new wxBoxSizer(wxHORIZONTAL);
|
||||
itemPanel7->SetSizer(itemBoxSizer8);
|
||||
|
||||
wxArrayString m_pRawListBoxStrings;
|
||||
m_pRawListBox = new wxListBox( itemPanel7, ID_LISTBOX, wxDefaultPosition, wxDefaultSize, m_pRawListBoxStrings, wxLB_SINGLE );
|
||||
itemBoxSizer8->Add(m_pRawListBox, 1, wxGROW, 5);
|
||||
|
||||
m_pChoiceBook->AddPage(itemPanel7, _("Raw list"));
|
||||
|
||||
// by-size page
|
||||
wxPanel* itemPanel13 = new wxPanel( m_pChoiceBook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
|
||||
wxBoxSizer* itemBoxSizer14 = new wxBoxSizer(wxHORIZONTAL);
|
||||
itemPanel13->SetSizer(itemBoxSizer14);
|
||||
|
||||
wxArrayString m_pSizeListBoxStrings;
|
||||
m_pSizeListBox = new wxListBox( itemPanel13, ID_LISTBOX, wxDefaultPosition, wxDefaultSize, m_pSizeListBoxStrings, wxLB_SINGLE );
|
||||
itemBoxSizer14->Add(m_pSizeListBox, 1, wxGROW, 5);
|
||||
|
||||
m_pChoiceBook->AddPage(itemPanel13, _("Classes by size"));
|
||||
|
||||
// tree page
|
||||
wxPanel* itemPanel10 = new wxPanel( m_pChoiceBook, ID_PANEL, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
|
||||
wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxVERTICAL);
|
||||
itemPanel10->SetSizer(itemBoxSizer11);
|
||||
|
||||
m_pParentTreeCtrl = new wxTreeCtrl( itemPanel10, ID_TREECTRL, wxDefaultPosition, wxSize(100, 100), wxTR_HAS_BUTTONS |wxTR_SINGLE );
|
||||
itemBoxSizer11->Add(m_pParentTreeCtrl, 1, wxGROW, 5);
|
||||
|
||||
m_pChoiceBook->AddPage(itemPanel10, _("Classes by parent"));
|
||||
|
||||
|
||||
itemBoxSizer5->Add(m_pChoiceBook, 0, wxGROW|wxALL, 5);
|
||||
|
||||
m_pTextCtrl = new wxTextCtrl( this, ID_TEXTCTRL, _T(""), wxDefaultPosition, wxSize(500, -1), wxTE_MULTILINE|wxTE_READONLY );
|
||||
itemBoxSizer5->Add(m_pTextCtrl, 3, wxGROW|wxALL, 5);
|
||||
|
||||
wxStdDialogButtonSizer* itemStdDialogButtonSizer17 = new wxStdDialogButtonSizer;
|
||||
|
||||
itemBoxSizer2->Add(itemStdDialogButtonSizer17, 0, wxGROW|wxALL, 5);
|
||||
wxButton* itemButton18 = new wxButton( this, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
itemStdDialogButtonSizer17->AddButton(itemButton18);
|
||||
|
||||
wxButton* itemButton19 = new wxButton( this, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
itemStdDialogButtonSizer17->AddButton(itemButton19);
|
||||
|
||||
itemStdDialogButtonSizer17->Realize();
|
||||
|
||||
InitControls();
|
||||
}
|
||||
|
||||
int ClassListDialog::AddClassesWithParent(const wxClassInfo *parent, const wxTreeItemId &id)
|
||||
{
|
||||
const wxClassInfo *ci = wxClassInfo::GetFirst();
|
||||
int count = 0;
|
||||
while (ci)
|
||||
{
|
||||
// is this class derived from the given parent?
|
||||
if (wxString(ci->GetBaseClassName1()) == parent->GetClassName() ||
|
||||
wxString(ci->GetBaseClassName2()) == parent->GetClassName())
|
||||
{
|
||||
wxTreeItemId child = m_pParentTreeCtrl->AppendItem(id, ci->GetClassName());
|
||||
|
||||
// update the name of this child with the count of the children classes
|
||||
int ret = AddClassesWithParent(ci, child);
|
||||
m_pParentTreeCtrl->SetItemText(child,
|
||||
m_pParentTreeCtrl->GetItemText(child) +
|
||||
wxString::Format(wxT(" [%d]"), ret));
|
||||
count += ret+1;
|
||||
}
|
||||
|
||||
ci = ci->GetNext();
|
||||
}
|
||||
|
||||
// reorder all the children we've just added
|
||||
m_pParentTreeCtrl->SortChildren(id);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int GetSizeOfClass(const wxString &cn)
|
||||
{
|
||||
const wxClassInfo *ci = wxClassInfo::FindClass(cn);
|
||||
if (ci)
|
||||
return ci->GetSize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CompareClassSizes(const wxString &class1, const wxString &class2)
|
||||
{
|
||||
return GetSizeOfClass(class1) - GetSizeOfClass(class2);
|
||||
}
|
||||
|
||||
void ClassListDialog::InitControls()
|
||||
{
|
||||
// create a wxArrayString with the names of all classes:
|
||||
const wxClassInfo *ci = wxClassInfo::GetFirst();
|
||||
wxArrayString arr;
|
||||
while (ci)
|
||||
{
|
||||
arr.Add(ci->GetClassName());
|
||||
ci = ci->GetNext();
|
||||
}
|
||||
|
||||
arr.Sort(); // sort alphabetically
|
||||
|
||||
// now add it to the raw-mode listbox
|
||||
for (unsigned int i=0; i<arr.GetCount(); i++)
|
||||
if (!IsToDiscard(arr[i]))
|
||||
m_pRawListBox->Append(arr[i]);
|
||||
m_nCount = m_pRawListBox->GetCount();
|
||||
|
||||
// sort again using size as sortkey
|
||||
arr.Sort((wxArrayString::CompareFunction)CompareClassSizes);
|
||||
|
||||
// now add it to the size-mode listbox
|
||||
for (unsigned int i=0; i<arr.GetCount(); i++)
|
||||
if (!IsToDiscard(arr[i]))
|
||||
m_pSizeListBox->Append(arr[i]);
|
||||
|
||||
// add root item to parent-mode treectrl
|
||||
wxTreeItemId id = m_pParentTreeCtrl->AddRoot(_T("wxObject"));
|
||||
|
||||
// recursively add all leaves to the treectrl
|
||||
int count = AddClassesWithParent(CLASSINFO(wxObject), id);
|
||||
m_pParentTreeCtrl->SetItemText(id, m_pParentTreeCtrl->GetItemText(id) +
|
||||
wxString::Format(wxT(" [%d]"), count));
|
||||
|
||||
// initially expand the root item
|
||||
m_pParentTreeCtrl->Expand(id);
|
||||
|
||||
m_nTotalCount = arr.GetCount();
|
||||
UpdateFilterText();
|
||||
|
||||
// don't leave blank the XTI info display
|
||||
m_pChoiceBook->ChangeSelection(0);
|
||||
m_pRawListBox->Select(0);
|
||||
UpdateClassInfo(m_pRawListBox->GetStringSelection());
|
||||
}
|
||||
|
||||
bool ClassListDialog::IsToDiscard(const wxString &classname) const
|
||||
{
|
||||
wxCheckBox *cb = wx_static_cast(wxCheckBox*, FindWindow(ID_SHOW_ONLY_XTI));
|
||||
if (!cb || !cb->IsChecked())
|
||||
return false;
|
||||
|
||||
// check if this class has XTI infos
|
||||
wxClassInfo *info = wxClassInfo::FindClass(classname);
|
||||
if (!info)
|
||||
return false;
|
||||
if (info->GetFirstProperty() != NULL || info->GetFirstHandler() != NULL)
|
||||
return false; // has XTI info
|
||||
return true; // no XTI info
|
||||
}
|
||||
|
||||
void ClassListDialog::UpdateFilterText()
|
||||
{
|
||||
// tell the user how many registered classes are present and
|
||||
// how many are we showing
|
||||
m_pClassCountText->SetLabel(
|
||||
wxString::Format(
|
||||
wxT("Showing %d classes on a total of %d registered classes in wxXTI."),
|
||||
m_nCount, m_nTotalCount));
|
||||
}
|
||||
|
||||
void ClassListDialog::UpdateClassInfo(const wxString &itemName)
|
||||
{
|
||||
wxString classname = itemName.BeforeFirst(_T(' '));
|
||||
wxCheckBox *cb = wx_static_cast(wxCheckBox*, FindWindow(ID_SHOW_PROPERTIES_RECURSIVELY));
|
||||
|
||||
m_pTextCtrl->SetValue(
|
||||
DumpClassInfo(wxClassInfo::FindClass(classname), cb->IsChecked()));
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ClassListDialog - event handlers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ClassListDialog::OnShowOnlyXTICheckbox( wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
m_pRawListBox->Clear();
|
||||
m_pParentTreeCtrl->DeleteAllItems();
|
||||
m_pSizeListBox->Clear();
|
||||
|
||||
InitControls();
|
||||
}
|
||||
|
||||
void ClassListDialog::OnShowRecursiveInfoCheckbox( wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
m_pRawListBox->Clear();
|
||||
m_pParentTreeCtrl->DeleteAllItems();
|
||||
m_pSizeListBox->Clear();
|
||||
|
||||
InitControls();
|
||||
}
|
||||
|
||||
void ClassListDialog::OnListboxSelected( wxCommandEvent& event )
|
||||
{
|
||||
UpdateClassInfo(event.GetString());
|
||||
}
|
||||
|
||||
void ClassListDialog::OnTreectrlSelChanged( wxTreeEvent& event )
|
||||
{
|
||||
UpdateClassInfo(m_pParentTreeCtrl->GetItemText(event.GetItem()));
|
||||
}
|
||||
|
||||
void ClassListDialog::OnChoiceBookPageChange( wxChoicebookEvent& event )
|
||||
{
|
||||
switch (event.GetSelection())
|
||||
{
|
||||
case 0:
|
||||
if (m_pRawListBox->GetCount())
|
||||
{
|
||||
m_pRawListBox->Select(0);
|
||||
UpdateClassInfo(m_pRawListBox->GetStringSelection());
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (m_pSizeListBox->GetCount())
|
||||
{
|
||||
m_pSizeListBox->Select(0);
|
||||
UpdateClassInfo(m_pSizeListBox->GetStringSelection());
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
wxTreeItemId root = m_pParentTreeCtrl->GetRootItem();
|
||||
if (root.IsOk())
|
||||
{
|
||||
m_pParentTreeCtrl->SelectItem(root);
|
||||
UpdateClassInfo(m_pParentTreeCtrl->GetItemText(root));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// dump functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxString DumpStr(const wxString &str)
|
||||
{
|
||||
if (str.empty())
|
||||
return wxT("none");
|
||||
return str;
|
||||
}
|
||||
|
||||
wxString DumpTypeInfo(const wxTypeInfo *ti)
|
||||
{
|
||||
if (!ti)
|
||||
return _T("none");
|
||||
|
||||
return DumpStr(ti->GetTypeName());
|
||||
}
|
||||
|
||||
wxString DumpPropertyAccessor(const wxPropertyAccessor *acc, int indent)
|
||||
{
|
||||
wxString ind = _T("\n") + wxString(indent, wxT(' '));
|
||||
wxString infostr;
|
||||
|
||||
if (!acc)
|
||||
return ind + _T("no property accessors");
|
||||
|
||||
if (acc->HasSetter())
|
||||
infostr << ind << _T("setter name: ") << acc->GetSetterName();
|
||||
if (acc->HasCollectionGetter())
|
||||
infostr << ind << _T("collection getter name: ") << acc->GetCollectionGetterName();
|
||||
if (acc->HasGetter())
|
||||
infostr << ind << _T("getter name: ") << acc->GetGetterName();
|
||||
if (acc->HasAdder())
|
||||
infostr << ind << _T("adder name: ") << acc->GetAdderName();
|
||||
|
||||
return infostr;
|
||||
}
|
||||
|
||||
wxString DumpPropertyInfo(const wxPropertyInfo *prop, int indent)
|
||||
{
|
||||
wxString ind = _T("\n") + wxString(indent, wxT(' '));
|
||||
wxString infostr;
|
||||
|
||||
if (!prop)
|
||||
return ind + _T("none");
|
||||
|
||||
infostr << ind << _T("flags: ");
|
||||
if (prop->GetFlags() & wxPROP_DEPRECATED)
|
||||
infostr << _T("wxPROP_DEPRECATED,");
|
||||
if (prop->GetFlags() & wxPROP_OBJECT_GRAPH)
|
||||
infostr << _T("wxPROP_OBJECT_GRAPH,");
|
||||
if (prop->GetFlags() & wxPROP_ENUM_STORE_LONG)
|
||||
infostr << _T("wxPROP_ENUM_STORE_LONG,");
|
||||
if (prop->GetFlags() & wxPROP_DONT_STREAM)
|
||||
infostr << _T("wxPROP_DONT_STREAM,");
|
||||
|
||||
if (prop->GetFlags() == 0)
|
||||
infostr << _T("none");
|
||||
else
|
||||
infostr.RemoveLast(); // remove last comma
|
||||
|
||||
infostr << ind << _T("help string: ") << DumpStr(prop->GetHelpString());
|
||||
infostr << ind << _T("group string: ") << DumpStr(prop->GetGroupString());
|
||||
|
||||
infostr << ind << _T("collection element type: ") << DumpTypeInfo(prop->GetCollectionElementTypeInfo());
|
||||
infostr << ind << _T("type: ") << DumpTypeInfo(prop->GetTypeInfo());
|
||||
|
||||
infostr << ind << _T("default value: ") << DumpStr(prop->GetDefaultValue().GetAsString());
|
||||
infostr << DumpPropertyAccessor(prop->GetAccessor(), indent+1);
|
||||
|
||||
return infostr;
|
||||
}
|
||||
|
||||
wxString DumpHandlerInfo(const wxHandlerInfo *phdlr, int indent)
|
||||
{
|
||||
wxString ind = _T("\n") + wxString(indent, wxT(' '));
|
||||
wxString infostr;
|
||||
|
||||
if (!phdlr)
|
||||
return ind + _T("none");
|
||||
|
||||
infostr << ind << _T("event class: ") <<
|
||||
(phdlr->GetEventClassInfo() ? phdlr->GetEventClassInfo()->GetClassName() : wxT("none"));
|
||||
|
||||
return infostr;
|
||||
}
|
||||
|
||||
int DumpProperties(const wxClassInfo *info, wxString& infostr, bool recursive)
|
||||
{
|
||||
const wxPropertyInfo *prop;
|
||||
int pcount;
|
||||
for (prop = info->GetFirstProperty(), pcount = 0;
|
||||
prop;
|
||||
prop = prop->GetNext(), pcount++)
|
||||
{
|
||||
infostr << _T("\n\n [") << pcount+1 << _T("] Property: ") << prop->GetName();
|
||||
infostr << DumpPropertyInfo(prop, 4);
|
||||
}
|
||||
|
||||
if (pcount == 0)
|
||||
infostr << _T("\n None");
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
const wxClassInfo **parent = info->GetParents();
|
||||
wxString str;
|
||||
|
||||
for (int i=0; parent[i] != NULL; i++)
|
||||
{
|
||||
int ppcount = DumpProperties(parent[i], str, recursive);
|
||||
if (ppcount)
|
||||
{
|
||||
pcount += ppcount;
|
||||
infostr << _T("\n\n ") << parent[i]->GetClassName() << _T(" PARENT'S PROPERTIES:");
|
||||
infostr << str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pcount;
|
||||
}
|
||||
|
||||
int DumpHandlers(const wxClassInfo *info, wxString& infostr, bool recursive)
|
||||
{
|
||||
const wxHandlerInfo *h;
|
||||
int hcount;
|
||||
for (h = info->GetFirstHandler(), hcount = 0;
|
||||
h;
|
||||
h = h->GetNext(), hcount++)
|
||||
{
|
||||
infostr << _T("\n\n [") << hcount+1 << _T("] Handler: ") << h->GetName();
|
||||
infostr << DumpHandlerInfo(h, 4);
|
||||
}
|
||||
|
||||
if (hcount == 0)
|
||||
infostr << _T("\n None");
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
const wxClassInfo **parent = info->GetParents();
|
||||
wxString str;
|
||||
|
||||
for (int i=0; parent[i] != NULL; i++)
|
||||
{
|
||||
int hhcount = DumpHandlers(parent[i], str, recursive);
|
||||
if (hhcount)
|
||||
{
|
||||
hcount += hhcount;
|
||||
infostr << _T("\n\n ") << parent[i]->GetClassName() << _T(" PARENT'S HANDLERS:");
|
||||
infostr << str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hcount;
|
||||
}
|
||||
|
||||
wxString DumpClassInfo(const wxClassInfo *info, bool recursive)
|
||||
{
|
||||
wxString infostr;
|
||||
|
||||
if (!info)
|
||||
return wxEmptyString;
|
||||
|
||||
// basic stuff:
|
||||
|
||||
infostr << _T("\n BASIC RTTI INFO ABOUT ") << info->GetClassName();
|
||||
infostr << _T("\n =================================================");
|
||||
infostr << _T("\n Base class #1: ") << DumpStr(info->GetBaseClassName1());
|
||||
infostr << _T("\n Base class #2: ") << DumpStr(info->GetBaseClassName2());
|
||||
infostr << _T("\n Include file: ") << DumpStr(info->GetIncludeName());
|
||||
infostr << _T("\n Size: ") << info->GetSize();
|
||||
infostr << _T("\n Dynamic: ") << (info->IsDynamic() ? _T("true") : _T("false"));
|
||||
|
||||
|
||||
// advanced stuff:
|
||||
|
||||
infostr << _T("\n\n\n ADVANCED RTTI INFO ABOUT ") << info->GetClassName();
|
||||
infostr << _T("\n =================================================\n");
|
||||
infostr << _T("\n PROPERTIES");
|
||||
infostr << _T("\n -----------------------------------------");
|
||||
int pcount = DumpProperties(info, infostr, recursive);
|
||||
infostr << _T("\n\n HANDLERS");
|
||||
infostr << _T("\n -----------------------------------------");
|
||||
int hcount = DumpHandlers(info, infostr, recursive);
|
||||
|
||||
if (pcount+hcount == 0)
|
||||
infostr << _T("\n\n no advanced info\n");
|
||||
else
|
||||
{
|
||||
infostr << _T("\n\n Total count of properties: ") << pcount;
|
||||
infostr << _T("\n Total count of handlers: ") << hcount << _T("\n");
|
||||
}
|
||||
|
||||
return infostr;
|
||||
}
|
108
samples/xti/classlist.h
Normal file
108
samples/xti/classlist.h
Normal file
@@ -0,0 +1,108 @@
|
||||
////////////////////////////////////////////////////
|
||||
// Name: classlist.h
|
||||
// Purpose: ClassListDialog definition
|
||||
// Author: Francesco Montorsi
|
||||
// Modified by:
|
||||
// Created: 03/06/2007 14:49:55
|
||||
// RCS-ID: $Id: classlist.h 47845 2007-08-01 12:53:50Z FM $
|
||||
// Copyright: (c) 2007 Francesco Montorsi
|
||||
// Licence: wxWidgets license
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _CLASSLIST_H_
|
||||
#define _CLASSLIST_H_
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// includes
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "wx/choicebk.h"
|
||||
#include "wx/treectrl.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// IDs
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#define ID_LISTMODE 10006
|
||||
#define ID_LISTBOX 10003
|
||||
#define ID_PANEL 10007
|
||||
#define ID_TREECTRL 10008
|
||||
#define ID_TEXTCTRL 10004
|
||||
#define ID_SHOW_ONLY_XTI 10005
|
||||
#define ID_SHOW_PROPERTIES_RECURSIVELY 10002
|
||||
#define SYMBOL_CLASSLISTDIALOG_STYLE wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX
|
||||
#define SYMBOL_CLASSLISTDIALOG_TITLE _("wxWidgets class list")
|
||||
#define SYMBOL_CLASSLISTDIALOG_IDNAME wxID_ANY
|
||||
#define SYMBOL_CLASSLISTDIALOG_SIZE wxSize(400, 300)
|
||||
#define SYMBOL_CLASSLISTDIALOG_POSITION wxDefaultPosition
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ClassListDialog
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class ClassListDialog: public wxDialog
|
||||
{
|
||||
// we explicitely don't want to use the following macro:
|
||||
// DECLARE_DYNAMIC_CLASS( ClassListDialog )
|
||||
// as otherwise the ClassListDialog class would appear in the list
|
||||
// shown by this dialog!
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
public:
|
||||
// Constructors
|
||||
ClassListDialog();
|
||||
ClassListDialog( wxWindow* parent, wxWindowID id = SYMBOL_CLASSLISTDIALOG_IDNAME,
|
||||
const wxString& caption = SYMBOL_CLASSLISTDIALOG_TITLE,
|
||||
const wxPoint& pos = SYMBOL_CLASSLISTDIALOG_POSITION,
|
||||
const wxSize& size = SYMBOL_CLASSLISTDIALOG_SIZE,
|
||||
long style = SYMBOL_CLASSLISTDIALOG_STYLE );
|
||||
|
||||
// Creation
|
||||
bool Create( wxWindow* parent, wxWindowID id = SYMBOL_CLASSLISTDIALOG_IDNAME,
|
||||
const wxString& caption = SYMBOL_CLASSLISTDIALOG_TITLE,
|
||||
const wxPoint& pos = SYMBOL_CLASSLISTDIALOG_POSITION,
|
||||
const wxSize& size = SYMBOL_CLASSLISTDIALOG_SIZE,
|
||||
long style = SYMBOL_CLASSLISTDIALOG_STYLE );
|
||||
|
||||
// Destructor
|
||||
~ClassListDialog();
|
||||
|
||||
public: // misc
|
||||
|
||||
void Init();
|
||||
void CreateControls();
|
||||
void InitControls();
|
||||
|
||||
void UpdateClassInfo(const wxString &itemName);
|
||||
void UpdateFilterText();
|
||||
bool IsToDiscard(const wxString &classname) const;
|
||||
|
||||
int AddClassesWithParent(const wxClassInfo *parent, const wxTreeItemId &id);
|
||||
|
||||
public: // event handlers
|
||||
|
||||
void OnListboxSelected( wxCommandEvent& event );
|
||||
void OnTreectrlSelChanged( wxTreeEvent& event );
|
||||
void OnChoiceBookPageChange( wxChoicebookEvent& event );
|
||||
void OnShowOnlyXTICheckbox( wxCommandEvent& event );
|
||||
void OnShowRecursiveInfoCheckbox( wxCommandEvent& event );
|
||||
|
||||
// Should we show tooltips?
|
||||
static bool ShowToolTips();
|
||||
|
||||
protected:
|
||||
wxChoicebook* m_pChoiceBook;
|
||||
wxStaticText* m_pClassCountText;
|
||||
wxListBox* m_pRawListBox;
|
||||
wxTreeCtrl* m_pParentTreeCtrl;
|
||||
wxListBox* m_pSizeListBox;
|
||||
wxTextCtrl* m_pTextCtrl;
|
||||
|
||||
int m_nTotalCount; // number of classes in wxXTI system
|
||||
int m_nCount; // number of shown classes
|
||||
};
|
||||
|
||||
#endif
|
||||
// _CLASSLIST_H_
|
276
samples/xti/codereadercallback.cpp
Normal file
276
samples/xti/codereadercallback.cpp
Normal file
@@ -0,0 +1,276 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/xtistrm.cpp
|
||||
// Purpose: streaming runtime metadata information
|
||||
// Author: Stefan Csomor
|
||||
// Modified by:
|
||||
// Created: 27/07/03
|
||||
// RCS-ID: $Id: xtistrm.cpp 47828 2007-07-31 19:26:56Z FM $
|
||||
// Copyright: (c) 2003 Stefan Csomor
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xtistrm.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/object.h"
|
||||
#include "wx/hash.h"
|
||||
#include "wx/event.h"
|
||||
#endif
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
#include "wx/tokenzr.h"
|
||||
#include "wx/txtstrm.h"
|
||||
#include "codereadercallback.h"
|
||||
|
||||
#if !wxUSE_EXTENDED_RTTI
|
||||
#error This sample requires XTI (eXtended RTTI) enabled
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxObjectCodeReaderCallback - depersisting to code
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
struct wxObjectCodeReaderCallback::wxObjectCodeReaderCallbackInternal
|
||||
{
|
||||
#if wxUSE_UNICODE
|
||||
map<int,wstring> m_objectNames;
|
||||
#else
|
||||
map<int,string> m_objectNames;
|
||||
#endif
|
||||
|
||||
void SetObjectName(int objectID, const wxString &name )
|
||||
{
|
||||
if ( m_objectNames.find(objectID) != m_objectNames.end() )
|
||||
{
|
||||
wxLogError( _("Passing a already registered object to SetObjectName") );
|
||||
return ;
|
||||
}
|
||||
m_objectNames[objectID] = (const wxChar *)name;
|
||||
}
|
||||
|
||||
wxString GetObjectName( int objectID )
|
||||
{
|
||||
if ( objectID == wxNullObjectID )
|
||||
return wxT("NULL");
|
||||
|
||||
if ( m_objectNames.find(objectID) == m_objectNames.end() )
|
||||
{
|
||||
wxLogError( _("Passing an unkown object to GetObject") );
|
||||
return wxEmptyString;
|
||||
}
|
||||
return wxString( m_objectNames[objectID].c_str() );
|
||||
}
|
||||
};
|
||||
|
||||
wxObjectCodeReaderCallback::wxObjectCodeReaderCallback(wxTextOutputStream *out)
|
||||
: m_fp(out)
|
||||
{
|
||||
m_data = new wxObjectCodeReaderCallbackInternal;
|
||||
}
|
||||
|
||||
wxObjectCodeReaderCallback::~wxObjectCodeReaderCallback()
|
||||
{
|
||||
delete m_data;
|
||||
}
|
||||
|
||||
void wxObjectCodeReaderCallback::AllocateObject(int objectID, wxClassInfo *classInfo,
|
||||
wxVariantBaseArray &WXUNUSED(metadata))
|
||||
{
|
||||
wxString objectName = wxString::Format( wxT("LocalObject_%d"), objectID );
|
||||
m_fp->WriteString( wxString::Format( wxT("\t%s *%s = new %s;\n"),
|
||||
classInfo->GetClassName(),
|
||||
objectName.c_str(),
|
||||
classInfo->GetClassName()) );
|
||||
m_data->SetObjectName( objectID, objectName );
|
||||
}
|
||||
|
||||
void wxObjectCodeReaderCallback::DestroyObject(int objectID, wxClassInfo *WXUNUSED(classInfo))
|
||||
{
|
||||
m_fp->WriteString( wxString::Format( wxT("\tdelete %s;\n"),
|
||||
m_data->GetObjectName( objectID).c_str() ) );
|
||||
}
|
||||
|
||||
wxString wxObjectCodeReaderCallback::ValueAsCode( const wxVariantBase ¶m )
|
||||
{
|
||||
wxString value;
|
||||
const wxTypeInfo* type = param.GetTypeInfo();
|
||||
if ( type->GetKind() == wxT_CUSTOM )
|
||||
{
|
||||
const wxCustomTypeInfo* cti = wx_dynamic_cast(const wxCustomTypeInfo*, type);
|
||||
if ( cti )
|
||||
{
|
||||
value.Printf( wxT("%s(%s)"), cti->GetTypeName().c_str(),
|
||||
param.GetAsString().c_str() );
|
||||
}
|
||||
else
|
||||
{
|
||||
wxLogError ( _("Internal error, illegal wxCustomTypeInfo") );
|
||||
}
|
||||
}
|
||||
else if ( type->GetKind() == wxT_STRING )
|
||||
{
|
||||
value.Printf( wxT("\"%s\""),param.GetAsString().c_str() );
|
||||
}
|
||||
else
|
||||
{
|
||||
value.Printf( wxT("%s"), param.GetAsString().c_str() );
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void wxObjectCodeReaderCallback::CreateObject(int objectID,
|
||||
const wxClassInfo *WXUNUSED(classInfo),
|
||||
int paramCount,
|
||||
wxVariantBase *params,
|
||||
int *objectIDValues,
|
||||
const wxClassInfo **WXUNUSED(objectClassInfos),
|
||||
wxVariantBaseArray &WXUNUSED(metadata)
|
||||
)
|
||||
{
|
||||
int i;
|
||||
m_fp->WriteString( wxString::Format( wxT("\t%s->Create("),
|
||||
m_data->GetObjectName(objectID).c_str() ) );
|
||||
for (i = 0; i < paramCount; i++)
|
||||
{
|
||||
if ( objectIDValues[i] != wxInvalidObjectID )
|
||||
{
|
||||
wxString str =
|
||||
wxString::Format( wxT("%s"),
|
||||
m_data->GetObjectName( objectIDValues[i] ).c_str() );
|
||||
m_fp->WriteString( str );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_fp->WriteString(
|
||||
wxString::Format( wxT("%s"), ValueAsCode(params[i]).c_str() ) );
|
||||
}
|
||||
if (i < paramCount - 1)
|
||||
m_fp->WriteString( wxT(", "));
|
||||
}
|
||||
m_fp->WriteString( wxT(");\n") );
|
||||
}
|
||||
|
||||
void wxObjectCodeReaderCallback::ConstructObject(int objectID,
|
||||
const wxClassInfo *classInfo,
|
||||
int paramCount,
|
||||
wxVariantBase *params,
|
||||
int *objectIDValues,
|
||||
const wxClassInfo **WXUNUSED(objectClassInfos),
|
||||
wxVariantBaseArray &WXUNUSED(metadata)
|
||||
)
|
||||
{
|
||||
wxString objectName = wxString::Format( wxT("LocalObject_%d"), objectID );
|
||||
m_fp->WriteString( wxString::Format( wxT("\t%s *%s = new %s("),
|
||||
classInfo->GetClassName(),
|
||||
objectName.c_str(),
|
||||
classInfo->GetClassName()) );
|
||||
m_data->SetObjectName( objectID, objectName );
|
||||
|
||||
int i;
|
||||
for (i = 0; i < paramCount; i++)
|
||||
{
|
||||
if ( objectIDValues[i] != wxInvalidObjectID )
|
||||
m_fp->WriteString( wxString::Format( wxT("%s"),
|
||||
m_data->GetObjectName( objectIDValues[i] ).c_str() ) );
|
||||
else
|
||||
{
|
||||
m_fp->WriteString(
|
||||
wxString::Format( wxT("%s"), ValueAsCode(params[i]).c_str() ) );
|
||||
}
|
||||
if (i < paramCount - 1)
|
||||
m_fp->WriteString( wxT(", ") );
|
||||
}
|
||||
m_fp->WriteString( wxT(");\n") );
|
||||
}
|
||||
|
||||
void wxObjectCodeReaderCallback::SetProperty(int objectID,
|
||||
const wxClassInfo *WXUNUSED(classInfo),
|
||||
const wxPropertyInfo* propertyInfo,
|
||||
const wxVariantBase &value)
|
||||
{
|
||||
m_fp->WriteString( wxString::Format( wxT("\t%s->%s(%s);\n"),
|
||||
m_data->GetObjectName(objectID).c_str(),
|
||||
propertyInfo->GetAccessor()->GetSetterName().c_str(),
|
||||
ValueAsCode(value).c_str()) );
|
||||
}
|
||||
|
||||
void wxObjectCodeReaderCallback::SetPropertyAsObject(int objectID,
|
||||
const wxClassInfo *WXUNUSED(classInfo),
|
||||
const wxPropertyInfo* propertyInfo,
|
||||
int valueObjectId)
|
||||
{
|
||||
if ( propertyInfo->GetTypeInfo()->GetKind() == wxT_OBJECT )
|
||||
m_fp->WriteString( wxString::Format( wxT("\t%s->%s(*%s);\n"),
|
||||
m_data->GetObjectName(objectID).c_str(),
|
||||
propertyInfo->GetAccessor()->GetSetterName().c_str(),
|
||||
m_data->GetObjectName( valueObjectId).c_str() ) );
|
||||
else
|
||||
m_fp->WriteString( wxString::Format( wxT("\t%s->%s(%s);\n"),
|
||||
m_data->GetObjectName(objectID).c_str(),
|
||||
propertyInfo->GetAccessor()->GetSetterName().c_str(),
|
||||
m_data->GetObjectName( valueObjectId).c_str() ) );
|
||||
}
|
||||
|
||||
void wxObjectCodeReaderCallback::AddToPropertyCollection( int objectID,
|
||||
const wxClassInfo *WXUNUSED(classInfo),
|
||||
const wxPropertyInfo* propertyInfo,
|
||||
const wxVariantBase &value)
|
||||
{
|
||||
m_fp->WriteString( wxString::Format( wxT("\t%s->%s(%s);\n"),
|
||||
m_data->GetObjectName(objectID).c_str(),
|
||||
propertyInfo->GetAccessor()->GetAdderName().c_str(),
|
||||
ValueAsCode(value).c_str()) );
|
||||
}
|
||||
|
||||
// sets the corresponding property (value is an object)
|
||||
void wxObjectCodeReaderCallback::
|
||||
AddToPropertyCollectionAsObject(int WXUNUSED(objectID),
|
||||
const wxClassInfo *WXUNUSED(classInfo),
|
||||
const wxPropertyInfo* WXUNUSED(propertyInfo),
|
||||
int WXUNUSED(valueObjectId))
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
void wxObjectCodeReaderCallback::SetConnect(int eventSourceObjectID,
|
||||
const wxClassInfo *WXUNUSED(eventSourceClassInfo),
|
||||
const wxPropertyInfo *delegateInfo,
|
||||
const wxClassInfo *eventSinkClassInfo,
|
||||
const wxHandlerInfo* handlerInfo,
|
||||
int eventSinkObjectID )
|
||||
{
|
||||
wxString ehsource = m_data->GetObjectName( eventSourceObjectID );
|
||||
wxString ehsink = m_data->GetObjectName(eventSinkObjectID);
|
||||
wxString ehsinkClass = eventSinkClassInfo->GetClassName();
|
||||
const wxEventSourceTypeInfo *delegateTypeInfo =
|
||||
wx_dynamic_cast(const wxEventSourceTypeInfo*, delegateInfo->GetTypeInfo());
|
||||
if ( delegateTypeInfo )
|
||||
{
|
||||
int eventType = delegateTypeInfo->GetEventType();
|
||||
wxString handlerName = handlerInfo->GetName();
|
||||
|
||||
wxString code =
|
||||
wxString::Format(
|
||||
wxT("\t%s->Connect( %s->GetId(), %d, ")
|
||||
wxT("(wxObjectEventFunction)(wxEventFunction) & %s::%s, NULL, %s );"),
|
||||
ehsource.c_str(), ehsource.c_str(), eventType, ehsinkClass.c_str(),
|
||||
handlerName.c_str(), ehsink.c_str() );
|
||||
|
||||
m_fp->WriteString( code );
|
||||
}
|
||||
else
|
||||
{
|
||||
wxLogError(_("delegate has no type info"));
|
||||
}
|
||||
}
|
104
samples/xti/codereadercallback.h
Normal file
104
samples/xti/codereadercallback.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/xtistrm.h
|
||||
// Purpose: streaming runtime metadata information (extended class info)
|
||||
// Author: Stefan Csomor
|
||||
// Modified by:
|
||||
// Created: 27/07/03
|
||||
// RCS-ID: $Id: xtistrm.h 47827 2007-07-31 19:25:09Z FM $
|
||||
// Copyright: (c) 2003 Stefan Csomor
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _CODEDEPERSISTER_
|
||||
#define _CODEDEPERSISTER_
|
||||
|
||||
#include "wx/defs.h"
|
||||
|
||||
/*
|
||||
wxObjectCodeReaderCallback implements the callbacks that will depersist
|
||||
an object into a C++ initialization function.
|
||||
*/
|
||||
|
||||
class WXDLLIMPEXP_BASE wxTextOutputStream;
|
||||
|
||||
class WXDLLIMPEXP_BASE wxObjectCodeReaderCallback: public wxObjectWriterCallback
|
||||
{
|
||||
private:
|
||||
struct wxObjectCodeReaderCallbackInternal;
|
||||
wxObjectCodeReaderCallbackInternal * m_data;
|
||||
wxTextOutputStream *m_fp;
|
||||
wxString ValueAsCode( const wxVariantBase ¶m );
|
||||
|
||||
public:
|
||||
wxObjectCodeReaderCallback(wxTextOutputStream *out);
|
||||
virtual ~wxObjectCodeReaderCallback();
|
||||
|
||||
// allocate the new object on the heap, that object will have the passed in ID
|
||||
virtual void AllocateObject(int objectID, wxClassInfo *classInfo,
|
||||
wxVariantBaseArray &metadata);
|
||||
|
||||
// initialize the already allocated object having the ID objectID
|
||||
// with the Create method creation parameters which are objects are
|
||||
// having their Ids passed in objectIDValues having objectId <> wxInvalidObjectID
|
||||
|
||||
virtual void CreateObject(int objectID,
|
||||
const wxClassInfo *classInfo,
|
||||
int paramCount,
|
||||
wxVariantBase *variantValues,
|
||||
int *objectIDValues,
|
||||
const wxClassInfo **objectClassInfos,
|
||||
wxVariantBaseArray &metadata
|
||||
);
|
||||
|
||||
// construct the new object on the heap, that object will have the
|
||||
// passed in ID (for objects that don't support allocate-create type
|
||||
// of creation) creation parameters which are objects are having their
|
||||
// Ids passed in objectIDValues having objectId <> wxInvalidObjectID
|
||||
|
||||
virtual void ConstructObject(int objectID,
|
||||
const wxClassInfo *classInfo,
|
||||
int paramCount,
|
||||
wxVariantBase *VariantValues,
|
||||
int *objectIDValues,
|
||||
const wxClassInfo **objectClassInfos,
|
||||
wxVariantBaseArray &metadata);
|
||||
|
||||
// destroy the heap-allocated object having the ID objectID, this may
|
||||
// be used if an object is embedded in another object and set via value
|
||||
// semantics, so the intermediate object can be destroyed after safely
|
||||
virtual void DestroyObject(int objectID, wxClassInfo *classInfo);
|
||||
|
||||
// set the corresponding property
|
||||
virtual void SetProperty(int objectID,
|
||||
const wxClassInfo *classInfo,
|
||||
const wxPropertyInfo* propertyInfo,
|
||||
const wxVariantBase &variantValue);
|
||||
|
||||
// sets the corresponding property (value is an object)
|
||||
virtual void SetPropertyAsObject(int objectId,
|
||||
const wxClassInfo *classInfo,
|
||||
const wxPropertyInfo* propertyInfo,
|
||||
int valueObjectId);
|
||||
|
||||
// adds an element to a property collection
|
||||
virtual void AddToPropertyCollection( int objectID,
|
||||
const wxClassInfo *classInfo,
|
||||
const wxPropertyInfo* propertyInfo,
|
||||
const wxVariantBase &VariantValue);
|
||||
|
||||
// sets the corresponding property (value is an object)
|
||||
virtual void AddToPropertyCollectionAsObject(int objectID,
|
||||
const wxClassInfo *classInfo,
|
||||
const wxPropertyInfo* propertyInfo,
|
||||
int valueObjectId);
|
||||
|
||||
// sets the corresponding event handler
|
||||
virtual void SetConnect(int eventSourceObjectID,
|
||||
const wxClassInfo *eventSourceClassInfo,
|
||||
const wxPropertyInfo *delegateInfo,
|
||||
const wxClassInfo *eventSinkClassInfo,
|
||||
const wxHandlerInfo* handlerInfo,
|
||||
int eventSinkObjectID );
|
||||
};
|
||||
|
||||
#endif
|
16
samples/xti/xti.bkl
Normal file
16
samples/xti/xti.bkl
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" ?>
|
||||
<!-- $Id: xti.bkl 48186 2007-08-19 19:59:54Z FM $ -->
|
||||
|
||||
<makefile>
|
||||
|
||||
<include file="../../build/bakefiles/common_samples.bkl"/>
|
||||
|
||||
<exe id="xti" template="wx_sample" template_append="wx_append">
|
||||
<sources>xti.cpp classlist.cpp codereadercallback.cpp</sources>
|
||||
|
||||
<wx-lib>core</wx-lib>
|
||||
<wx-lib>xml</wx-lib>
|
||||
<wx-lib>base</wx-lib>
|
||||
</exe>
|
||||
|
||||
</makefile>
|
735
samples/xti/xti.cpp
Normal file
735
samples/xti/xti.cpp
Normal file
@@ -0,0 +1,735 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xti.cpp
|
||||
// Purpose: eXtended RTTI support sample
|
||||
// Author: Stefan Csomor, Francesco Montorsi
|
||||
// Modified by:
|
||||
// Created: 13/5/2007
|
||||
// RCS-ID: $Id: xti.cpp 48407 2007-08-26 23:17:23Z FM $
|
||||
// Copyright: (c) Stefan Csomor, Francesco Montorsi
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx/wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
// for all others, include the necessary headers (this file is usually all you
|
||||
// need because it includes almost all "standard" wxWidgets headers)
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
|
||||
#include "wx/wx.h"
|
||||
#include "wx/variant.h"
|
||||
#include "wx/xml/xml.h"
|
||||
#include "wx/frame.h"
|
||||
#include "wx/notebook.h"
|
||||
#include "wx/event.h"
|
||||
#include "wx/spinbutt.h"
|
||||
#include "wx/spinctrl.h"
|
||||
|
||||
#include "wx/xtistrm.h"
|
||||
#include "wx/xtixml.h"
|
||||
#include "wx/txtstrm.h"
|
||||
#include "wx/wfstream.h"
|
||||
#include "wx/sstream.h"
|
||||
#include "wx/spinctrl.h"
|
||||
|
||||
#include "classlist.h"
|
||||
#include "codereadercallback.h"
|
||||
|
||||
#if !wxUSE_EXTENDED_RTTI
|
||||
#error This sample requires XTI (eXtended RTTI) enabled
|
||||
#endif
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// resources
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if !defined(__WXMSW__) && !defined(__WXPM__)
|
||||
#include "../sample.xpm"
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// private classes
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Define a new application type, each program should derive a class from wxApp
|
||||
class MyApp : public wxApp
|
||||
{
|
||||
public:
|
||||
virtual bool OnInit();
|
||||
};
|
||||
|
||||
// Define a new frame type: this is going to be our main frame
|
||||
class MyFrame : public wxFrame
|
||||
{
|
||||
public:
|
||||
// ctor(s)
|
||||
MyFrame(const wxString& title);
|
||||
|
||||
void OnPersist(wxCommandEvent& event);
|
||||
void OnDepersist(wxCommandEvent& event);
|
||||
void OnGenerateCode(wxCommandEvent& event);
|
||||
void OnDumpClasses(wxCommandEvent& event);
|
||||
void OnQuit(wxCommandEvent& event);
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
|
||||
private:
|
||||
// any class wishing to process wxWidgets events must use this macro
|
||||
wxDECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// constants
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// IDs for the controls and the menu commands
|
||||
enum
|
||||
{
|
||||
// menu items
|
||||
Minimal_Persist = wxID_HIGHEST,
|
||||
Minimal_Depersist,
|
||||
Minimal_GenerateCode,
|
||||
Minimal_DumpClasses,
|
||||
Minimal_Quit = wxID_EXIT,
|
||||
Minimal_About = wxID_ABOUT
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// event tables and other macros for wxWidgets
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MENU(Minimal_Persist, MyFrame::OnPersist)
|
||||
EVT_MENU(Minimal_Depersist, MyFrame::OnDepersist)
|
||||
EVT_MENU(Minimal_GenerateCode, MyFrame::OnGenerateCode)
|
||||
EVT_MENU(Minimal_DumpClasses, MyFrame::OnDumpClasses)
|
||||
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
|
||||
EVT_MENU(Minimal_About, MyFrame::OnAbout)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
wxIMPLEMENT_APP(MyApp)
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
void RegisterFrameRTTI();
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// the application class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool MyApp::OnInit()
|
||||
{
|
||||
if ( !wxApp::OnInit() )
|
||||
return false;
|
||||
|
||||
RegisterFrameRTTI();
|
||||
|
||||
// create the main application window
|
||||
MyFrame *frame = new MyFrame(_T("Extended RTTI sample"));
|
||||
|
||||
// and show it (the frames, unlike simple controls, are not shown when
|
||||
// created initially)
|
||||
frame->Show(true);
|
||||
|
||||
// success: wxApp::OnRun() will be called which will enter the main message
|
||||
// loop and the application will run. If we returned false here, the
|
||||
// application would exit immediately.
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// main frame
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
MyFrame::MyFrame(const wxString& title)
|
||||
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(300, 200))
|
||||
{
|
||||
// set the frame icon
|
||||
SetIcon(wxICON(sample));
|
||||
|
||||
#if wxUSE_MENUS
|
||||
// create a menu bar
|
||||
wxMenu *fileMenu = new wxMenu;
|
||||
|
||||
// the "About" item should be in the help menu
|
||||
wxMenu *helpMenu = new wxMenu;
|
||||
helpMenu->Append(Minimal_About, _T("&About...\tF1"), _T("Show about dialog"));
|
||||
|
||||
fileMenu->Append(Minimal_Persist, _T("Persist a wxFrame to XML..."),
|
||||
_T("Creates a wxFrame using wxXTI and saves its description as XML"));
|
||||
fileMenu->Append(Minimal_Depersist, _T("Depersist XML file..."),
|
||||
_T("Loads the description of wxFrame from XML"));
|
||||
fileMenu->Append(Minimal_GenerateCode, _T("Generate code for a wxFrame saved to XML..."),
|
||||
_T("Generates the C++ code which belong to a persisted wxFrame"));
|
||||
fileMenu->AppendSeparator();
|
||||
fileMenu->Append(Minimal_DumpClasses, _T("Dump registered classes..."),
|
||||
_T("Dumps the description of all wxWidgets classes registered in XTI"));
|
||||
fileMenu->AppendSeparator();
|
||||
fileMenu->Append(Minimal_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
|
||||
|
||||
// now append the freshly created menu to the menu bar...
|
||||
wxMenuBar *menuBar = new wxMenuBar();
|
||||
menuBar->Append(fileMenu, _T("&File"));
|
||||
menuBar->Append(helpMenu, _T("&Help"));
|
||||
|
||||
// ... and attach this menu bar to the frame
|
||||
SetMenuBar(menuBar);
|
||||
#endif // wxUSE_MENUS
|
||||
|
||||
#if wxUSE_STATUSBAR
|
||||
// create a status bar just for fun (by default with 1 pane only)
|
||||
CreateStatusBar(2);
|
||||
SetStatusText(_T("Welcome to wxWidgets!"));
|
||||
#endif // wxUSE_STATUSBAR
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// XTI sample code
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// this is the kind of source code that would end up being generated by a
|
||||
// designer corresponding to the information we are setting up via RTTI
|
||||
// in the CreateFrameRTTI function:
|
||||
//
|
||||
// class MyXTIFrame : public wxFrame
|
||||
// {
|
||||
// public:
|
||||
// // construction
|
||||
// MyXTIFrame()
|
||||
// {
|
||||
// Init();
|
||||
// m_button = NULL;
|
||||
// }
|
||||
//
|
||||
// bool Create(wxWindow *parent,
|
||||
// wxWindowID id,
|
||||
// const wxString& title,
|
||||
// const wxPoint& pos = wxDefaultPosition,
|
||||
// const wxSize& size = wxDefaultSize,
|
||||
// long style = wxDEFAULT_FRAME_STYLE,
|
||||
// const wxString& name = wxFrameNameStr)
|
||||
// {
|
||||
// return wxFrame::Create( parent, id, title, pos, size, style, name );
|
||||
// }
|
||||
//
|
||||
// void SetButton( wxButton * button ) { m_button = button; }
|
||||
// wxButton* GetButton() const { return m_button; }
|
||||
//
|
||||
// void ButtonClickHandler( wxEvent & WXUNUSED(event) )
|
||||
// {
|
||||
// wxMessageBox( "Button Clicked ", "Hi!", wxOK );
|
||||
// }
|
||||
//
|
||||
// protected:
|
||||
// wxButton* m_button;
|
||||
//
|
||||
// DECLARE_EVENT_TABLE()
|
||||
// DECLARE_DYNAMIC_CLASS_NO_COPY(MyXTIFrame)
|
||||
// };
|
||||
//
|
||||
// IMPLEMENT_DYNAMIC_CLASS_XTI(MyXTIFrame, MyXTIFrame, "x.h")
|
||||
//
|
||||
// WX_BEGIN_PROPERTIES_TABLE(MyXTIFrame)
|
||||
// WX_PROPERTY( Button, wxButton*, SetButton, GetButton, )
|
||||
// WX_END_PROPERTIES_TABLE()
|
||||
//
|
||||
// WX_BEGIN_HANDLERS_TABLE(MyXTIFrame)
|
||||
// WX_HANDLER( ButtonClickHandler, wxCommandEvent )
|
||||
// WX_END_HANDLERS_TABLE()
|
||||
//
|
||||
// WX_CONSTRUCTOR_5( MyXTIFrame, wxWindow*, Parent, wxWindowID, Id,
|
||||
// wxString, Title, wxPoint, Position, wxSize, Size )
|
||||
//
|
||||
// BEGIN_EVENT_TABLE(MyXTIFrame, wxFrame)
|
||||
// END_EVENT_TABLE()
|
||||
|
||||
// the following class "persists" (i.e. saves) a wxFrame into a wxObjectWriter
|
||||
|
||||
class MyDesignerPersister : public wxObjectReaderCallback
|
||||
{
|
||||
public:
|
||||
MyDesignerPersister( wxDynamicObject * frame)
|
||||
{
|
||||
m_frame = frame;
|
||||
}
|
||||
|
||||
virtual bool BeforeWriteDelegate( wxObjectWriter *WXUNUSED(writer),
|
||||
const wxObject *object,
|
||||
const wxClassInfo* WXUNUSED(classInfo),
|
||||
const wxPropertyInfo *propInfo,
|
||||
const wxObject *&eventSink,
|
||||
const wxHandlerInfo* &handlerInfo )
|
||||
{
|
||||
// this approach would be used it the handler would not
|
||||
// be connected really in the designer, so we have to supply
|
||||
// the information
|
||||
if ( object == m_frame->GetProperty(wxT("Button")).GetAsObject() &&
|
||||
propInfo == wxCLASSINFO( wxButton )->FindPropertyInfo("OnClick") )
|
||||
{
|
||||
eventSink = m_frame;
|
||||
handlerInfo = m_frame->GetClassInfo()->
|
||||
FindHandlerInfo("ButtonClickHandler");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
wxDynamicObject *m_frame;
|
||||
};
|
||||
|
||||
// sometimes linkers (at least MSVC and GCC ones) optimize the final EXE
|
||||
// even in debug mode pruning the object files which he "thinks" are useless;
|
||||
// thus the classes defined in those files won't be available in the XTI
|
||||
// table and the program will fail to allocate them.
|
||||
// The following macro implements a simple hack to ensure that a given
|
||||
// class is linked in.
|
||||
//
|
||||
// TODO: in wx/link.h there are already similar macros (also more "optimized":
|
||||
// don't need the creation of fake object) which however require to use
|
||||
// the wxFORCE_LINK_THIS_MODULE() macro inside the source files corresponding
|
||||
// to the class being discarded.
|
||||
//
|
||||
#define wxENSURE_CLASS_IS_LINKED(x) { x test; }
|
||||
|
||||
void RegisterFrameRTTI()
|
||||
{
|
||||
// set up the RTTI info for a class (MyXTIFrame) which
|
||||
// is not defined anywhere in this program
|
||||
wxDynamicClassInfo *dyninfo =
|
||||
wx_dynamic_cast( wxDynamicClassInfo *, wxClassInfo::FindClass(wxT("MyXTIFrame")));
|
||||
if ( dyninfo == NULL )
|
||||
{
|
||||
dyninfo = new wxDynamicClassInfo(wxT("myxtiframe.h"),
|
||||
wxT("MyXTIFrame"),
|
||||
CLASSINFO(wxFrame) );
|
||||
|
||||
// this class has a property named "Button" and the relative handler:
|
||||
dyninfo->AddProperty("Button", wxGetTypeInfo((wxButton**) NULL));
|
||||
dyninfo->AddHandler("ButtonClickHandler",
|
||||
NULL /* no instance of the handler method */, CLASSINFO( wxEvent ) );
|
||||
}
|
||||
}
|
||||
|
||||
wxDynamicObject* CreateFrameRTTI()
|
||||
{
|
||||
int baseID = 100;
|
||||
wxVariantBase Params[10];
|
||||
|
||||
// the class is now part of XTI internal table so that we can
|
||||
// get a pointer to it just searching it like any other class:
|
||||
wxFrame* frame;
|
||||
wxClassInfo *info = wxClassInfo::FindClass(wxT("MyXTIFrame"));
|
||||
wxASSERT( info );
|
||||
wxDynamicObject* frameWrapper =
|
||||
wx_dynamic_cast(wxDynamicObject*, info->CreateObject() );
|
||||
Params[0] = wxVariantBase((wxWindow*)(NULL));
|
||||
Params[1] = wxVariantBase(wxWindowID(baseID++));
|
||||
Params[2] = wxVariantBase(wxString(wxT("This is a frame created from XTI")));
|
||||
Params[3] = wxVariantBase(wxPoint(-1,-1));
|
||||
Params[4] = wxVariantBase(wxSize(400,300));
|
||||
Params[5] = wxVariantBase((long)wxDEFAULT_FRAME_STYLE);
|
||||
wxASSERT( info->Create(frameWrapper, 6, Params ));
|
||||
frame = wx_dynamic_cast(wxFrame*, frameWrapper->GetSuperClassInstance());
|
||||
|
||||
// now build a notebook inside it:
|
||||
wxNotebook* notebook;
|
||||
info = wxClassInfo::FindClass("wxNotebook");
|
||||
wxASSERT( info );
|
||||
notebook = wxDynamicCast( info->CreateObject(), wxNotebook );
|
||||
Params[0] = wxVariantBase((wxWindow*)frame);
|
||||
Params[1] = wxVariantBase(wxWindowID(baseID++));
|
||||
Params[2] = wxVariantBase(wxPoint( 10, 10 ));
|
||||
Params[3] = wxVariantBase(wxDefaultSize);
|
||||
Params[4] = wxVariantBase((long)0);
|
||||
wxASSERT( info->Create(notebook, 5, Params ));
|
||||
|
||||
// button page
|
||||
|
||||
wxPanel* panel;
|
||||
info = wxClassInfo::FindClass("wxPanel");
|
||||
wxASSERT( info );
|
||||
panel = wxDynamicCast( info->CreateObject(), wxPanel );
|
||||
Params[0] = wxVariantBase((wxWindow*)(notebook));
|
||||
Params[1] = wxVariantBase(wxWindowID(baseID++));
|
||||
Params[2] = wxVariantBase(wxPoint(-1,-1));
|
||||
Params[3] = wxVariantBase(wxSize(-1,-1));
|
||||
Params[4] = wxVariantBase((long)0);
|
||||
Params[5] = wxVariantBase(wxString(wxT("Hello")));
|
||||
wxASSERT( info->Create(panel, 6, Params ));
|
||||
notebook->AddPage( panel, "Buttons" );
|
||||
|
||||
wxButton* button;
|
||||
info = wxClassInfo::FindClass("wxButton");
|
||||
wxASSERT( info );
|
||||
button = wxDynamicCast( info->CreateObject(), wxButton );
|
||||
Params[0] = wxVariantBase((wxWindow*)(panel));
|
||||
Params[1] = wxVariantBase(wxWindowID(baseID++));
|
||||
Params[2] = wxVariantBase(wxString(wxT("Click Me!")));
|
||||
Params[3] = wxVariantBase(wxPoint( 10, 10 ));
|
||||
Params[4] = wxVariantBase(wxSize(-1,-1));
|
||||
Params[5] = wxVariantBase((long)0);
|
||||
wxASSERT( info->Create(button, 6, Params ));
|
||||
frameWrapper->SetProperty( "Button", wxVariantBase( button ) );
|
||||
|
||||
// other controls page
|
||||
|
||||
info = wxClassInfo::FindClass("wxPanel");
|
||||
wxASSERT( info );
|
||||
panel = wxDynamicCast( info->CreateObject(), wxPanel );
|
||||
Params[0] = wxVariantBase((wxWindow*)(notebook));
|
||||
Params[1] = wxVariantBase(wxWindowID(baseID++));
|
||||
Params[2] = wxVariantBase(wxPoint(-1,-1));
|
||||
Params[3] = wxVariantBase(wxSize(-1,-1));
|
||||
Params[4] = wxVariantBase((long)0);
|
||||
Params[5] = wxVariantBase(wxString(wxT("Hello")));
|
||||
wxASSERT( info->Create(panel, 6, Params ));
|
||||
notebook->AddPage( panel, "Other Standard controls" );
|
||||
|
||||
wxControl* control;
|
||||
info = wxClassInfo::FindClass("wxCheckBox");
|
||||
wxASSERT( info );
|
||||
control = wxDynamicCast( info->CreateObject(), wxControl );
|
||||
Params[0] = wxVariantBase((wxWindow*)(panel));
|
||||
Params[1] = wxVariantBase(wxWindowID(baseID++));
|
||||
Params[2] = wxVariantBase(wxString(wxT("A Checkbox")));
|
||||
Params[3] = wxVariantBase(wxPoint( 10, 10 ));
|
||||
Params[4] = wxVariantBase(wxSize(-1,-1));
|
||||
Params[5] = wxVariantBase((long)0);
|
||||
wxASSERT( info->Create(control, 6, Params ));
|
||||
|
||||
info = wxClassInfo::FindClass("wxRadioButton");
|
||||
wxASSERT( info );
|
||||
control = wxDynamicCast( info->CreateObject(), wxControl );
|
||||
Params[0] = wxVariantBase((wxWindow*)(panel));
|
||||
Params[1] = wxVariantBase(wxWindowID(baseID++));
|
||||
Params[2] = wxVariantBase(wxString(wxT("A Radiobutton")));
|
||||
Params[3] = wxVariantBase(wxPoint( 10, 30 ));
|
||||
Params[4] = wxVariantBase(wxSize(-1,-1));
|
||||
Params[5] = wxVariantBase((long)0);
|
||||
wxASSERT( info->Create(control, 6, Params ));
|
||||
|
||||
control = wxDynamicCast( info->CreateObject(), wxControl );
|
||||
Params[1] = wxVariantBase(wxWindowID(baseID++));
|
||||
Params[2] = wxVariantBase(wxString(wxT("Another One")));
|
||||
Params[3] = wxVariantBase(wxPoint( 10, 50 ));
|
||||
wxASSERT( info->Create(control, 6, Params ));
|
||||
|
||||
info = wxClassInfo::FindClass("wxStaticText");
|
||||
wxASSERT( info );
|
||||
control = wxDynamicCast( info->CreateObject(), wxControl );
|
||||
Params[0] = wxVariantBase((wxWindow*)(panel));
|
||||
Params[1] = wxVariantBase(wxWindowID(baseID++));
|
||||
Params[2] = wxVariantBase(wxString(wxT("A Static Text!")));
|
||||
Params[3] = wxVariantBase(wxPoint( 10, 70 ));
|
||||
Params[4] = wxVariantBase(wxSize(-1,-1));
|
||||
Params[5] = wxVariantBase((long)0);
|
||||
wxASSERT( info->Create(control, 6, Params ));
|
||||
|
||||
info = wxClassInfo::FindClass("wxStaticBox");
|
||||
wxASSERT( info );
|
||||
control = wxDynamicCast( info->CreateObject(), wxControl );
|
||||
Params[0] = wxVariantBase((wxWindow*)(panel));
|
||||
Params[1] = wxVariantBase(wxWindowID(baseID++));
|
||||
Params[2] = wxVariantBase(wxString(wxT("A Static Box")));
|
||||
Params[3] = wxVariantBase(wxPoint( 10, 90 ));
|
||||
Params[4] = wxVariantBase(wxSize(100,80));
|
||||
Params[5] = wxVariantBase((long)0);
|
||||
wxASSERT( info->Create(control, 6, Params ));
|
||||
|
||||
info = wxClassInfo::FindClass("wxTextCtrl");
|
||||
wxASSERT( info );
|
||||
control = wxDynamicCast( info->CreateObject(), wxControl );
|
||||
Params[0] = wxVariantBase((wxWindow*)(panel));
|
||||
Params[1] = wxVariantBase(wxWindowID(baseID++));
|
||||
Params[2] = wxVariantBase(wxString(wxT("A Text Control")));
|
||||
Params[3] = wxVariantBase(wxPoint( 10, 200 ));
|
||||
Params[4] = wxVariantBase(wxSize(-1,-1));
|
||||
Params[5] = wxVariantBase((long)0);
|
||||
wxASSERT( info->Create(control, 6, Params ));
|
||||
|
||||
// spins and gauges page
|
||||
|
||||
info = wxClassInfo::FindClass("wxPanel");
|
||||
wxASSERT( info );
|
||||
panel = wxDynamicCast( info->CreateObject(), wxPanel );
|
||||
Params[0] = wxVariantBase((wxWindow*)(notebook));
|
||||
Params[1] = wxVariantBase(wxWindowID(baseID++));
|
||||
Params[2] = wxVariantBase(wxPoint(-1,-1));
|
||||
Params[3] = wxVariantBase(wxSize(-1,-1));
|
||||
Params[4] = wxVariantBase((long)0);
|
||||
Params[5] = wxVariantBase(wxString(wxT("Hello")));
|
||||
wxASSERT( info->Create(panel, 6, Params ));
|
||||
notebook->AddPage( panel, "Spins and Sliders" );
|
||||
|
||||
wxENSURE_CLASS_IS_LINKED(wxSpinButton);
|
||||
|
||||
info = wxClassInfo::FindClass("wxSpinButton");
|
||||
wxASSERT( info );
|
||||
control = wxDynamicCast( info->CreateObject(), wxControl );
|
||||
Params[0] = wxVariantBase((wxWindow*)(panel));
|
||||
Params[1] = wxVariantBase(wxWindowID(baseID++));
|
||||
Params[2] = wxVariantBase(wxPoint( 10, 10 ));
|
||||
Params[3] = wxVariantBase(wxSize(-1,-1));
|
||||
Params[4] = wxVariantBase((long)wxSP_VERTICAL | wxSP_ARROW_KEYS);
|
||||
wxASSERT( info->Create(control, 5, Params ));
|
||||
|
||||
wxENSURE_CLASS_IS_LINKED(wxSpinCtrl);
|
||||
|
||||
info = wxClassInfo::FindClass("wxSpinCtrl");
|
||||
wxASSERT( info );
|
||||
control = wxDynamicCast( info->CreateObject(), wxControl );
|
||||
Params[0] = wxVariantBase((wxWindow*)(panel));
|
||||
Params[1] = wxVariantBase(wxWindowID(baseID++));
|
||||
Params[2] = wxVariantBase(wxString("20"));
|
||||
Params[3] = wxVariantBase(wxPoint( 40, 10 ));
|
||||
Params[4] = wxVariantBase(wxSize(40,-1));
|
||||
Params[5] = wxVariantBase((long) wxSP_ARROW_KEYS);
|
||||
wxASSERT( info->Create(control, 6, Params ));
|
||||
|
||||
// MSVC likes to exclude from link wxGauge...
|
||||
wxENSURE_CLASS_IS_LINKED(wxGauge)
|
||||
wxENSURE_CLASS_IS_LINKED(wxCheckBox)
|
||||
wxENSURE_CLASS_IS_LINKED(wxSpinCtrl)
|
||||
|
||||
#ifdef __WXMSW__
|
||||
// under wxMSW wxGauge is simply #defined to wxGauge95
|
||||
info = wxClassInfo::FindClass("wxGauge95");
|
||||
#else
|
||||
info = wxClassInfo::FindClass("wxGauge");
|
||||
#endif
|
||||
wxASSERT( info );
|
||||
control = wxDynamicCast( info->CreateObject(), wxControl );
|
||||
Params[0] = wxVariantBase((wxWindow*)(panel));
|
||||
Params[1] = wxVariantBase(wxWindowID(baseID++));
|
||||
Params[2] = wxVariantBase((int) 100);
|
||||
Params[3] = wxVariantBase(wxPoint( 10, 50 ));
|
||||
Params[4] = wxVariantBase(wxSize(-1,-1));
|
||||
Params[5] = wxVariantBase((long) wxGA_HORIZONTAL);
|
||||
wxASSERT( info->Create(control, 6, Params ));
|
||||
wx_dynamic_cast(wxGauge*, control)->SetValue(20);
|
||||
|
||||
return frameWrapper;
|
||||
}
|
||||
|
||||
bool SaveFrameRTTI(const wxString &testFileName, wxDynamicObject *frame)
|
||||
{
|
||||
// setup the XML document
|
||||
wxXmlDocument xml;
|
||||
wxXmlNode *root = new wxXmlNode(wxXML_ELEMENT_NODE,
|
||||
"TestXTI", "This is the content");
|
||||
xml.SetRoot(root);
|
||||
|
||||
// setup the XTI writer and persister
|
||||
wxObjectXmlWriter writer(root);
|
||||
MyDesignerPersister persister(frame);
|
||||
|
||||
// write the given wxObject into the XML document
|
||||
wxVariantBaseArray empty;
|
||||
writer.WriteObject( frame, frame->GetClassInfo(), &persister,
|
||||
wxString("myTestFrame"), empty );
|
||||
|
||||
return xml.Save(testFileName);
|
||||
}
|
||||
|
||||
wxDynamicObject* LoadFrameRTTI(const wxString &fileName)
|
||||
{
|
||||
// load the XML document
|
||||
wxXmlDocument xml;
|
||||
if (!xml.Load(fileName))
|
||||
return NULL;
|
||||
|
||||
wxXmlNode *root = xml.GetRoot();
|
||||
if (root->GetName() != "TestXTI")
|
||||
return NULL;
|
||||
|
||||
// now depersist the wxFrame we saved into it using wxObjectRuntimeReaderCallback
|
||||
wxObjectRuntimeReaderCallback Callbacks;
|
||||
wxObjectXmlReader Reader( root );
|
||||
int obj = Reader.ReadObject( wxString("myTestFrame"), &Callbacks );
|
||||
return (wxDynamicObject*)Callbacks.GetObject( obj );
|
||||
}
|
||||
|
||||
bool GenerateFrameRTTICode(const wxString &inFileName, const wxString &outFileName)
|
||||
{
|
||||
// is loading the streamed out component from xml and writing code that
|
||||
// will create the same component
|
||||
|
||||
wxFFileOutputStream fos( outFileName );
|
||||
wxTextOutputStream tos( fos );
|
||||
if (!fos.IsOk())
|
||||
return false;
|
||||
|
||||
wxXmlDocument xml;
|
||||
if (!xml.Load(inFileName))
|
||||
return false;
|
||||
|
||||
wxXmlNode *root = xml.GetRoot();
|
||||
if (root->GetName() != "TestXTI")
|
||||
return false;
|
||||
|
||||
// read the XML file using the wxObjectCodeReaderCallback
|
||||
wxObjectCodeReaderCallback Callbacks(&tos);
|
||||
wxObjectXmlReader Reader(root);
|
||||
|
||||
// ReadObject will return the ID of the object read??
|
||||
Reader.ReadObject( wxString("myTestFrame"), &Callbacks );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// MyFrame event handlers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void MyFrame::OnPersist(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
// first create a frame using XTI calls
|
||||
wxDynamicObject *frame = CreateFrameRTTI();
|
||||
if (!frame)
|
||||
{
|
||||
wxLogError(wxT("Cannot create the XTI frame!"));
|
||||
return;
|
||||
}
|
||||
|
||||
// show the frame we're going to save to the user
|
||||
wxFrame *trueFrame = wx_dynamic_cast(wxFrame *, frame->GetSuperClassInstance() );
|
||||
trueFrame->Show();
|
||||
|
||||
// ask the user where to save it
|
||||
wxFileDialog dlg(this, wxT("Where should the frame be saved?"),
|
||||
wxEmptyString, wxT("test.xml"), wxT("XML files (*.xml)|*.xml"),
|
||||
wxFD_SAVE);
|
||||
if (dlg.ShowModal() == wxID_CANCEL)
|
||||
return;
|
||||
|
||||
// then save it to a test XML file
|
||||
if (!SaveFrameRTTI(dlg.GetPath(), frame))
|
||||
{
|
||||
wxLogError(wxT("Cannot save the XTI frame into '%s'"), dlg.GetPath());
|
||||
return;
|
||||
}
|
||||
|
||||
// now simply delete it
|
||||
delete frame;
|
||||
}
|
||||
|
||||
void MyFrame::OnDepersist(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
// ask the user which file to load
|
||||
wxFileDialog dlg(this, wxT("Which file contains the frame to depersist?"),
|
||||
wxEmptyString, wxT("test.xml"), wxT("XML files (*.xml)|*.xml"),
|
||||
wxFD_OPEN);
|
||||
if (dlg.ShowModal() == wxID_CANCEL)
|
||||
return;
|
||||
|
||||
wxObject *frame = LoadFrameRTTI(dlg.GetPath());
|
||||
if (!frame)
|
||||
{
|
||||
wxLogError(wxT("Could not depersist the wxFrame from '%s'"), dlg.GetPath());
|
||||
return;
|
||||
}
|
||||
|
||||
wxFrame *trueFrame = wx_dynamic_cast(wxFrame*, frame );
|
||||
if ( !trueFrame )
|
||||
{
|
||||
wxDynamicObject* dyno = wx_dynamic_cast(wxDynamicObject*, frame );
|
||||
if ( dyno )
|
||||
trueFrame = wx_dynamic_cast(wxFrame *, dyno->GetSuperClassInstance() );
|
||||
}
|
||||
|
||||
if ( trueFrame )
|
||||
trueFrame->Show();
|
||||
else
|
||||
wxLogError(wxT("Could not show the frame"));
|
||||
}
|
||||
|
||||
void MyFrame::OnGenerateCode(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
// ask the user which file to load
|
||||
wxFileDialog dlg(this, wxT("Which file contains the frame to work on?"),
|
||||
wxEmptyString, wxT("test.xml"), wxT("XML files (*.xml)|*.xml"),
|
||||
wxFD_OPEN);
|
||||
if (dlg.ShowModal() == wxID_CANCEL)
|
||||
return;
|
||||
|
||||
// ask the user which file to load
|
||||
wxFileDialog dlg2(this, wxT("Where should the C++ code be saved?"),
|
||||
wxEmptyString, wxT("test.cpp"), wxT("Source files (*.cpp)|*.cpp"),
|
||||
wxFD_SAVE);
|
||||
if (dlg2.ShowModal() == wxID_CANCEL)
|
||||
return;
|
||||
|
||||
// do generate code
|
||||
if (!GenerateFrameRTTICode(dlg.GetPath(), dlg2.GetPath()))
|
||||
{
|
||||
wxLogError(wxT("Could not generate the code for the frame!"));
|
||||
return;
|
||||
}
|
||||
|
||||
// show the generated code
|
||||
{
|
||||
wxFileInputStream f(dlg2.GetPath());
|
||||
wxStringOutputStream str;
|
||||
f.Read(str);
|
||||
|
||||
wxDialog dlg(this, wxID_ANY, wxT("Generated code"),
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE);
|
||||
wxPanel *panel = new wxPanel(&dlg);
|
||||
wxSizer *sz = new wxBoxSizer(wxVERTICAL);
|
||||
sz->Add(new wxTextCtrl(panel, wxID_ANY, str.GetString(),
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxTE_MULTILINE|wxTE_READONLY|wxTE_DONTWRAP),
|
||||
1, wxGROW|wxALL, 5);
|
||||
sz->Add(new wxButton(panel, wxID_OK), 0, wxALIGN_RIGHT|wxALL, 5);
|
||||
panel->SetSizerAndFit(sz);
|
||||
dlg.ShowModal();
|
||||
}
|
||||
}
|
||||
|
||||
void MyFrame::OnDumpClasses(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
ClassListDialog dlg(this);
|
||||
dlg.ShowModal();
|
||||
}
|
||||
|
||||
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
// true is to force the frame to close
|
||||
Close(true);
|
||||
}
|
||||
|
||||
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxMessageBox(wxString::Format(
|
||||
_T("Welcome to %s!\n")
|
||||
_T("\n")
|
||||
_T("This sample demonstrates wxWidgets eXtended RTTI (XTI) system."),
|
||||
wxVERSION_STRING
|
||||
),
|
||||
_T("About wxWidgets XTI sample"),
|
||||
wxOK | wxICON_INFORMATION,
|
||||
this);
|
||||
}
|
3
samples/xti/xti.rc
Normal file
3
samples/xti/xti.rc
Normal file
@@ -0,0 +1,3 @@
|
||||
mondrian ICON "sample.ico"
|
||||
#include "wx/msw/wx.rc"
|
||||
|
Reference in New Issue
Block a user