1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: eXtended RTTI support sample
4 // Author: Stefan Csomor, Francesco Montorsi
8 // Copyright: (c) Stefan Csomor, Francesco Montorsi
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 // for all others, include the necessary headers (this file is usually all you
28 // need because it includes almost all "standard" wxWidgets headers)
34 #include "wx/variant.h"
35 #include "wx/xml/xml.h"
37 #include "wx/notebook.h"
39 #include "wx/spinbutt.h"
40 #include "wx/spinctrl.h"
42 #include "wx/xtistrm.h"
43 #include "wx/xtixml.h"
44 #include "wx/txtstrm.h"
45 #include "wx/wfstream.h"
46 #include "wx/sstream.h"
47 #include "wx/spinctrl.h"
49 #include "classlist.h"
50 #include "codereadercallback.h"
52 #if !wxUSE_EXTENDED_RTTI
53 #error This sample requires XTI (eXtended RTTI) enabled
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 #ifndef wxHAS_IMAGES_IN_RESOURCES
62 #include "../sample.xpm"
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 // Define a new application type, each program should derive a class from wxApp
70 class MyApp
: public wxApp
73 virtual bool OnInit();
76 // Define a new frame type: this is going to be our main frame
77 class MyFrame
: public wxFrame
81 MyFrame(const wxString
& title
);
83 void OnPersist(wxCommandEvent
& event
);
84 void OnDepersist(wxCommandEvent
& event
);
85 void OnGenerateCode(wxCommandEvent
& event
);
86 void OnDumpClasses(wxCommandEvent
& event
);
87 void OnQuit(wxCommandEvent
& event
);
88 void OnAbout(wxCommandEvent
& event
);
91 // any class wishing to process wxWidgets events must use this macro
92 wxDECLARE_EVENT_TABLE();
95 // ----------------------------------------------------------------------------
97 // ----------------------------------------------------------------------------
99 // IDs for the controls and the menu commands
103 Minimal_Persist
= wxID_HIGHEST
,
105 Minimal_GenerateCode
,
107 Minimal_Quit
= wxID_EXIT
,
108 Minimal_About
= wxID_ABOUT
111 // ----------------------------------------------------------------------------
112 // event tables and other macros for wxWidgets
113 // ----------------------------------------------------------------------------
115 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
116 EVT_MENU(Minimal_Persist
, MyFrame::OnPersist
)
117 EVT_MENU(Minimal_Depersist
, MyFrame::OnDepersist
)
118 EVT_MENU(Minimal_GenerateCode
, MyFrame::OnGenerateCode
)
119 EVT_MENU(Minimal_DumpClasses
, MyFrame::OnDumpClasses
)
120 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
121 EVT_MENU(Minimal_About
, MyFrame::OnAbout
)
124 wxIMPLEMENT_APP(MyApp
);
126 // ============================================================================
128 // ============================================================================
130 void RegisterFrameRTTI();
132 // ----------------------------------------------------------------------------
133 // the application class
134 // ----------------------------------------------------------------------------
138 if ( !wxApp::OnInit() )
143 // create the main application window
144 MyFrame
*frame
= new MyFrame(wxT("Extended RTTI sample"));
146 // and show it (the frames, unlike simple controls, are not shown when
147 // created initially)
150 // success: wxApp::OnRun() will be called which will enter the main message
151 // loop and the application will run. If we returned false here, the
152 // application would exit immediately.
156 // ----------------------------------------------------------------------------
158 // ----------------------------------------------------------------------------
160 MyFrame::MyFrame(const wxString
& title
)
161 : wxFrame(NULL
, wxID_ANY
, title
, wxDefaultPosition
, wxSize(300, 200))
163 // set the frame icon
164 SetIcon(wxICON(sample
));
168 wxMenu
*fileMenu
= new wxMenu
;
170 // the "About" item should be in the help menu
171 wxMenu
*helpMenu
= new wxMenu
;
172 helpMenu
->Append(Minimal_About
, wxT("&About\tF1"), wxT("Show about dialog"));
174 fileMenu
->Append(Minimal_Persist
, wxT("Persist a wxFrame to XML..."),
175 wxT("Creates a wxFrame using wxXTI and saves its description as XML"));
176 fileMenu
->Append(Minimal_Depersist
, wxT("Depersist XML file..."),
177 wxT("Loads the description of wxFrame from XML"));
178 fileMenu
->Append(Minimal_GenerateCode
, wxT("Generate code for a wxFrame saved to XML..."),
179 wxT("Generates the C++ code which belong to a persisted wxFrame"));
180 fileMenu
->AppendSeparator();
181 fileMenu
->Append(Minimal_DumpClasses
, wxT("Dump registered classes..."),
182 wxT("Dumps the description of all wxWidgets classes registered in XTI"));
183 fileMenu
->AppendSeparator();
184 fileMenu
->Append(Minimal_Quit
, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
186 // now append the freshly created menu to the menu bar...
187 wxMenuBar
*menuBar
= new wxMenuBar();
188 menuBar
->Append(fileMenu
, wxT("&File"));
189 menuBar
->Append(helpMenu
, wxT("&Help"));
191 // ... and attach this menu bar to the frame
193 #endif // wxUSE_MENUS
196 // create a status bar just for fun (by default with 1 pane only)
198 SetStatusText(wxT("Welcome to wxWidgets!"));
199 #endif // wxUSE_STATUSBAR
204 // ----------------------------------------------------------------------------
206 // ----------------------------------------------------------------------------
208 // this is the kind of source code that would end up being generated by a
209 // designer corresponding to the information we are setting up via RTTI
210 // in the CreateFrameRTTI function:
212 // class MyXTIFrame : public wxFrame
222 // bool Create(wxWindow *parent,
224 // const wxString& title,
225 // const wxPoint& pos = wxDefaultPosition,
226 // const wxSize& size = wxDefaultSize,
227 // long style = wxDEFAULT_FRAME_STYLE,
228 // const wxString& name = wxFrameNameStr)
230 // return wxFrame::Create( parent, id, title, pos, size, style, name );
233 // void SetButton( wxButton * button ) { m_button = button; }
234 // wxButton* GetButton() const { return m_button; }
236 // void ButtonClickHandler( wxEvent & WXUNUSED(event) )
238 // wxMessageBox( "Button Clicked ", "Hi!", wxOK );
242 // wxButton* m_button;
244 // DECLARE_EVENT_TABLE()
245 // DECLARE_DYNAMIC_CLASS_NO_COPY(MyXTIFrame)
248 // IMPLEMENT_DYNAMIC_CLASS_XTI(MyXTIFrame, MyXTIFrame, "x.h")
250 // WX_BEGIN_PROPERTIES_TABLE(MyXTIFrame)
251 // WX_PROPERTY( Button, wxButton*, SetButton, GetButton, )
252 // WX_END_PROPERTIES_TABLE()
254 // WX_BEGIN_HANDLERS_TABLE(MyXTIFrame)
255 // WX_HANDLER( ButtonClickHandler, wxCommandEvent )
256 // WX_END_HANDLERS_TABLE()
258 // WX_CONSTRUCTOR_5( MyXTIFrame, wxWindow*, Parent, wxWindowID, Id,
259 // wxString, Title, wxPoint, Position, wxSize, Size )
261 // BEGIN_EVENT_TABLE(MyXTIFrame, wxFrame)
264 // the following class "persists" (i.e. saves) a wxFrame into a wxObjectWriter
266 class MyDesignerPersister
: public wxObjectWriterCallback
269 MyDesignerPersister( wxDynamicObject
* frame
)
274 virtual bool BeforeWriteDelegate( wxObjectWriter
*WXUNUSED(writer
),
275 const wxObject
*object
,
276 const wxClassInfo
* WXUNUSED(classInfo
),
277 const wxPropertyInfo
*propInfo
,
278 const wxObject
*&eventSink
,
279 const wxHandlerInfo
* &handlerInfo
)
281 // this approach would be used if the handler would not
282 // be connected really in the designer, so we have to supply
284 const wxObject
* but
= wxAnyGetAsObjectPtr( m_frame
->GetProperty(wxT("Button")) );
285 if ( object
== but
&&
286 propInfo
== wxCLASSINFO( wxButton
)->FindPropertyInfo(wxT("OnClick")) )
289 handlerInfo
= m_frame
->GetClassInfo()->
290 FindHandlerInfo(wxT("ButtonClickHandler"));
297 wxDynamicObject
*m_frame
;
300 // sometimes linkers (at least MSVC and GCC ones) optimize the final EXE
301 // even in debug mode pruning the object files which he "thinks" are useless;
302 // thus the classes defined in those files won't be available in the XTI
303 // table and the program will fail to allocate them.
304 // The following macro implements a simple hack to ensure that a given
305 // class is linked in.
307 // TODO: in wx/link.h there are already similar macros (also more "optimized":
308 // don't need the creation of fake object) which however require to use
309 // the wxFORCE_LINK_THIS_MODULE() macro inside the source files corresponding
310 // to the class being discarded.
312 #define wxENSURE_CLASS_IS_LINKED(x) { x test; }
314 void RegisterFrameRTTI()
316 // set up the RTTI info for a class (MyXTIFrame) which
317 // is not defined anywhere in this program
318 wxDynamicClassInfo
*dyninfo
=
319 wx_dynamic_cast( wxDynamicClassInfo
*, wxClassInfo::FindClass(wxT("MyXTIFrame")));
320 if ( dyninfo
== NULL
)
322 dyninfo
= new wxDynamicClassInfo(wxT("myxtiframe.h"),
324 CLASSINFO(wxFrame
) );
326 // this class has a property named "Button" and the relative handler:
327 dyninfo
->AddProperty(wxT("Button"), wxGetTypeInfo((wxButton
**) NULL
));
328 dyninfo
->AddHandler(wxT("ButtonClickHandler"),
329 NULL
/* no instance of the handler method */, CLASSINFO( wxEvent
) );
333 wxDynamicObject
* CreateFrameRTTI()
338 // the class is now part of XTI internal table so that we can
339 // get a pointer to it just searching it like any other class:
341 wxClassInfo
*info
= wxClassInfo::FindClass(wxT("MyXTIFrame"));
343 wxDynamicObject
* frameWrapper
=
344 wx_dynamic_cast(wxDynamicObject
*, info
->CreateObject() );
345 Params
[0] = wxAny((wxWindow
*)(NULL
));
346 Params
[1] = wxAny(wxWindowID(baseID
++));
347 Params
[2] = wxAny(wxString(wxT("This is a frame created from XTI")));
348 Params
[3] = wxAny(wxPoint(-1,-1));
349 Params
[4] = wxAny(wxSize(400,300));
350 Params
[5] = wxAny((long)wxDEFAULT_FRAME_STYLE
);
351 wxASSERT( info
->Create(frameWrapper
, 6, Params
));
352 frame
= wx_dynamic_cast(wxFrame
*, frameWrapper
->GetSuperClassInstance());
355 // now build a notebook inside it:
356 wxNotebook
* notebook
;
357 info
= wxClassInfo::FindClass("wxNotebook");
359 notebook
= wxDynamicCast( info
->CreateObject(), wxNotebook
);
360 Params
[0] = wxAny((wxWindow
*)frame
);
361 Params
[1] = wxAny(wxWindowID(baseID
++));
362 Params
[2] = wxAny(wxPoint( 10, 10 ));
363 Params
[3] = wxAny(wxDefaultSize
);
364 Params
[4] = wxAny((long)0);
365 wxASSERT( info
->Create(notebook
, 5, Params
));
370 info
= wxClassInfo::FindClass("wxPanel");
372 panel
= wxDynamicCast( info
->CreateObject(), wxPanel
);
373 Params
[0] = wxAny((wxWindow
*)(notebook
));
374 Params
[1] = wxAny(wxWindowID(baseID
++));
375 Params
[2] = wxAny(wxPoint(-1,-1));
376 Params
[3] = wxAny(wxSize(-1,-1));
377 Params
[4] = wxAny((long)0);
378 Params
[5] = wxAny(wxString(wxT("Hello")));
379 wxASSERT( info
->Create(panel
, 6, Params
));
380 notebook
->AddPage( panel
, "Buttons" );
383 info
= wxClassInfo::FindClass("wxButton");
385 button
= wxDynamicCast( info
->CreateObject(), wxButton
);
386 Params
[0] = wxAny((wxWindow
*)(panel
));
387 Params
[1] = wxAny(wxWindowID(baseID
++));
388 Params
[2] = wxAny(wxString(wxT("Click Me!")));
389 Params
[3] = wxAny(wxPoint( 10, 10 ));
390 Params
[4] = wxAny(wxSize(-1,-1));
391 Params
[5] = wxAny((long)0);
392 wxASSERT( info
->Create(button
, 6, Params
));
393 frameWrapper
->SetProperty( wxT("Button"), wxAny( button
) );
395 // other controls page
397 info
= wxClassInfo::FindClass("wxPanel");
399 panel
= wxDynamicCast( info
->CreateObject(), wxPanel
);
400 Params
[0] = wxAny((wxWindow
*)(notebook
));
401 Params
[1] = wxAny(wxWindowID(baseID
++));
402 Params
[2] = wxAny(wxPoint(-1,-1));
403 Params
[3] = wxAny(wxSize(-1,-1));
404 Params
[4] = wxAny((long)0);
405 Params
[5] = wxAny(wxString(wxT("Hello")));
406 wxASSERT( info
->Create(panel
, 6, Params
));
407 notebook
->AddPage( panel
, "Other Standard controls" );
410 info
= wxClassInfo::FindClass("wxCheckBox");
412 control
= wxDynamicCast( info
->CreateObject(), wxControl
);
413 Params
[0] = wxAny((wxWindow
*)(panel
));
414 Params
[1] = wxAny(wxWindowID(baseID
++));
415 Params
[2] = wxAny(wxString(wxT("A Checkbox")));
416 Params
[3] = wxAny(wxPoint( 10, 10 ));
417 Params
[4] = wxAny(wxSize(-1,-1));
418 Params
[5] = wxAny((long)0);
419 wxASSERT( info
->Create(control
, 6, Params
));
421 info
= wxClassInfo::FindClass("wxRadioButton");
423 control
= wxDynamicCast( info
->CreateObject(), wxControl
);
424 Params
[0] = wxAny((wxWindow
*)(panel
));
425 Params
[1] = wxAny(wxWindowID(baseID
++));
426 Params
[2] = wxAny(wxString(wxT("A Radiobutton")));
427 Params
[3] = wxAny(wxPoint( 10, 30 ));
428 Params
[4] = wxAny(wxSize(-1,-1));
429 Params
[5] = wxAny((long)0);
430 wxASSERT( info
->Create(control
, 6, Params
));
432 control
= wxDynamicCast( info
->CreateObject(), wxControl
);
433 Params
[1] = wxAny(wxWindowID(baseID
++));
434 Params
[2] = wxAny(wxString(wxT("Another One")));
435 Params
[3] = wxAny(wxPoint( 10, 50 ));
436 wxASSERT( info
->Create(control
, 6, Params
));
438 info
= wxClassInfo::FindClass("wxStaticText");
440 control
= wxDynamicCast( info
->CreateObject(), wxControl
);
441 Params
[0] = wxAny((wxWindow
*)(panel
));
442 Params
[1] = wxAny(wxWindowID(baseID
++));
443 Params
[2] = wxAny(wxString(wxT("A Static Text!")));
444 Params
[3] = wxAny(wxPoint( 10, 70 ));
445 Params
[4] = wxAny(wxSize(-1,-1));
446 Params
[5] = wxAny((long)0);
447 wxASSERT( info
->Create(control
, 6, Params
));
449 info
= wxClassInfo::FindClass("wxStaticBox");
451 control
= wxDynamicCast( info
->CreateObject(), wxControl
);
452 Params
[0] = wxAny((wxWindow
*)(panel
));
453 Params
[1] = wxAny(wxWindowID(baseID
++));
454 Params
[2] = wxAny(wxString(wxT("A Static Box")));
455 Params
[3] = wxAny(wxPoint( 10, 90 ));
456 Params
[4] = wxAny(wxSize(100,80));
457 Params
[5] = wxAny((long)0);
458 wxASSERT( info
->Create(control
, 6, Params
));
460 info
= wxClassInfo::FindClass("wxTextCtrl");
462 control
= wxDynamicCast( info
->CreateObject(), wxControl
);
463 Params
[0] = wxAny((wxWindow
*)(panel
));
464 Params
[1] = wxAny(wxWindowID(baseID
++));
465 Params
[2] = wxAny(wxString(wxT("A Text Control")));
466 Params
[3] = wxAny(wxPoint( 10, 200 ));
467 Params
[4] = wxAny(wxSize(-1,-1));
468 Params
[5] = wxAny((long)0);
469 wxASSERT( info
->Create(control
, 6, Params
));
471 // spins and gauges page
473 info
= wxClassInfo::FindClass("wxPanel");
475 panel
= wxDynamicCast( info
->CreateObject(), wxPanel
);
476 Params
[0] = wxAny((wxWindow
*)(notebook
));
477 Params
[1] = wxAny(wxWindowID(baseID
++));
478 Params
[2] = wxAny(wxPoint(-1,-1));
479 Params
[3] = wxAny(wxSize(-1,-1));
480 Params
[4] = wxAny((long)0);
481 Params
[5] = wxAny(wxString(wxT("Hello")));
482 wxASSERT( info
->Create(panel
, 6, Params
));
483 notebook
->AddPage( panel
, "Spins and Sliders" );
485 wxENSURE_CLASS_IS_LINKED(wxSpinButton
);
487 info
= wxClassInfo::FindClass("wxSpinButton");
489 control
= wxDynamicCast( info
->CreateObject(), wxControl
);
490 Params
[0] = wxAny((wxWindow
*)(panel
));
491 Params
[1] = wxAny(wxWindowID(baseID
++));
492 Params
[2] = wxAny(wxPoint( 10, 10 ));
493 Params
[3] = wxAny(wxSize(-1,-1));
494 Params
[4] = wxAny((long)wxSP_VERTICAL
| wxSP_ARROW_KEYS
);
495 wxASSERT( info
->Create(control
, 5, Params
));
497 wxENSURE_CLASS_IS_LINKED(wxSpinCtrl
);
499 info
= wxClassInfo::FindClass("wxSpinCtrl");
501 control
= wxDynamicCast( info
->CreateObject(), wxControl
);
502 Params
[0] = wxAny((wxWindow
*)(panel
));
503 Params
[1] = wxAny(wxWindowID(baseID
++));
504 Params
[2] = wxAny(wxString("20"));
505 Params
[3] = wxAny(wxPoint( 40, 10 ));
506 Params
[4] = wxAny(wxSize(40,-1));
507 Params
[5] = wxAny((long) wxSP_ARROW_KEYS
);
508 wxASSERT( info
->Create(control
, 6, Params
));
510 // MSVC likes to exclude from link wxGauge...
511 wxENSURE_CLASS_IS_LINKED(wxGauge
)
512 wxENSURE_CLASS_IS_LINKED(wxCheckBox
)
513 wxENSURE_CLASS_IS_LINKED(wxSpinCtrl
)
515 info
= wxClassInfo::FindClass("wxGauge");
518 control
= wxDynamicCast( info
->CreateObject(), wxControl
);
519 Params
[0] = wxAny((wxWindow
*)(panel
));
520 Params
[1] = wxAny(wxWindowID(baseID
++));
521 Params
[2] = wxAny((int) 100);
522 Params
[3] = wxAny(wxPoint( 10, 50 ));
523 Params
[4] = wxAny(wxSize(-1,-1));
524 Params
[5] = wxAny((long) wxGA_HORIZONTAL
);
525 wxASSERT( info
->Create(control
, 6, Params
));
526 wx_dynamic_cast(wxGauge
*, control
)->SetValue(20);
532 bool SaveFrameRTTI(const wxString
&testFileName
, wxDynamicObject
*frame
)
534 // setup the XML document
536 wxXmlNode
*root
= new wxXmlNode(wxXML_ELEMENT_NODE
,
537 "TestXTI", "This is the content");
540 // setup the XTI writer and persister
541 wxObjectXmlWriter
writer(root
);
542 MyDesignerPersister
persister(frame
);
544 // write the given wxObject into the XML document
545 wxStringToAnyHashMap empty
;
546 writer
.WriteObject( frame
, frame
->GetClassInfo(), &persister
,
547 wxString("myTestFrame"), empty
);
549 return xml
.Save(testFileName
);
552 wxDynamicObject
* LoadFrameRTTI(const wxString
&fileName
)
554 // load the XML document
556 if (!xml
.Load(fileName
))
559 wxXmlNode
*root
= xml
.GetRoot();
560 if (root
->GetName() != "TestXTI")
563 // now depersist the wxFrame we saved into it using wxObjectRuntimeReaderCallback
564 wxObjectRuntimeReaderCallback Callbacks
;
565 wxObjectXmlReader
Reader( root
);
566 int obj
= Reader
.ReadObject( wxString("myTestFrame"), &Callbacks
);
567 return (wxDynamicObject
*)Callbacks
.GetObject( obj
);
570 bool GenerateFrameRTTICode(const wxString
&inFileName
, const wxString
&outFileName
)
572 // is loading the streamed out component from xml and writing code that
573 // will create the same component
575 wxFFileOutputStream
fos( outFileName
);
576 wxTextOutputStream
tos( fos
);
581 if (!xml
.Load(inFileName
))
584 wxXmlNode
*root
= xml
.GetRoot();
585 if (root
->GetName() != "TestXTI")
588 // read the XML file using the wxObjectCodeReaderCallback
590 wxString headerincludes
;
592 wxObjectCodeReaderCallback
Callbacks(headerincludes
,sourcecode
);
593 wxObjectXmlReader
Reader(root
);
595 // ReadObject will return the ID of the object read??
596 Reader
.ReadObject( wxString("myTestFrame"), &Callbacks
);
600 "#include \"wx/wxprec.h\" \n#ifdef __BORLANDC__\n#pragma hdrstop\n#endif\n#ifndef WX_PRECOMP\n#include \"wx/wx.h\" \n#endif\n\n";
601 // add object includes
602 tos
.WriteString( headerincludes
);
604 tos
<< "\n\nvoid test()\n{";
605 tos
.WriteString( sourcecode
);
613 // ----------------------------------------------------------------------------
614 // MyFrame event handlers
615 // ----------------------------------------------------------------------------
617 void MyFrame::OnPersist(wxCommandEvent
& WXUNUSED(event
))
619 // first create a frame using XTI calls
620 wxDynamicObject
*frame
= CreateFrameRTTI();
623 wxLogError(wxT("Cannot create the XTI frame!"));
627 // show the frame we're going to save to the user
628 wxFrame
*trueFrame
= wx_dynamic_cast(wxFrame
*, frame
->GetSuperClassInstance() );
631 // ask the user where to save it
632 wxFileDialog
dlg(this, wxT("Where should the frame be saved?"),
633 wxEmptyString
, wxT("test.xml"), wxT("XML files (*.xml)|*.xml"),
635 if (dlg
.ShowModal() == wxID_CANCEL
)
638 // then save it to a test XML file
639 if (!SaveFrameRTTI(dlg
.GetPath(), frame
))
641 wxLogError(wxT("Cannot save the XTI frame into '%s'"), dlg
.GetPath());
645 // now simply delete it
649 void MyFrame::OnDepersist(wxCommandEvent
& WXUNUSED(event
))
651 // ask the user which file to load
652 wxFileDialog
dlg(this, wxT("Which file contains the frame to depersist?"),
653 wxEmptyString
, wxT("test.xml"), wxT("XML files (*.xml)|*.xml"),
655 if (dlg
.ShowModal() == wxID_CANCEL
)
658 wxObject
*frame
= LoadFrameRTTI(dlg
.GetPath());
661 wxLogError(wxT("Could not depersist the wxFrame from '%s'"), dlg
.GetPath());
665 wxFrame
*trueFrame
= wx_dynamic_cast(wxFrame
*, frame
);
668 wxDynamicObject
* dyno
= wx_dynamic_cast(wxDynamicObject
*, frame
);
670 trueFrame
= wx_dynamic_cast(wxFrame
*, dyno
->GetSuperClassInstance() );
676 wxLogError(wxT("Could not show the frame"));
679 void MyFrame::OnGenerateCode(wxCommandEvent
& WXUNUSED(event
))
681 // ask the user which file to load
682 wxFileDialog
dlg(this, wxT("Which file contains the frame to work on?"),
683 wxEmptyString
, wxT("test.xml"), wxT("XML files (*.xml)|*.xml"),
685 if (dlg
.ShowModal() == wxID_CANCEL
)
688 // ask the user which file to load
689 wxFileDialog
dlg2(this, wxT("Where should the C++ code be saved?"),
690 wxEmptyString
, wxT("test.cpp"), wxT("Source files (*.cpp)|*.cpp"),
692 if (dlg2
.ShowModal() == wxID_CANCEL
)
696 if (!GenerateFrameRTTICode(dlg
.GetPath(), dlg2
.GetPath()))
698 wxLogError(wxT("Could not generate the code for the frame!"));
702 // show the generated code
704 wxFileInputStream
f(dlg2
.GetPath());
705 wxStringOutputStream str
;
708 wxDialog
dlg(this, wxID_ANY
, wxT("Generated code"),
709 wxDefaultPosition
, wxDefaultSize
,
710 wxRESIZE_BORDER
|wxDEFAULT_DIALOG_STYLE
);
711 wxPanel
*panel
= new wxPanel(&dlg
);
712 wxSizer
*sz
= new wxBoxSizer(wxVERTICAL
);
713 sz
->Add(new wxTextCtrl(panel
, wxID_ANY
, str
.GetString(),
714 wxDefaultPosition
, wxDefaultSize
,
715 wxTE_MULTILINE
|wxTE_READONLY
|wxTE_DONTWRAP
),
717 sz
->Add(new wxButton(panel
, wxID_OK
), 0, wxALIGN_RIGHT
|wxALL
, 5);
718 panel
->SetSizerAndFit(sz
);
723 void MyFrame::OnDumpClasses(wxCommandEvent
& WXUNUSED(event
))
725 ClassListDialog
dlg(this);
729 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
731 // true is to force the frame to close
735 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
737 wxMessageBox(wxString::Format(
738 wxT("Welcome to %s!\n")
740 wxT("This sample demonstrates wxWidgets eXtended RTTI (XTI) system."),
743 wxT("About wxWidgets XTI sample"),
744 wxOK
| wxICON_INFORMATION
,