widget.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: zip.cpp
  3. // Purpose: wxHtml sample: Demonstrates embedded controls
  4. // Author: ?
  5. // Modified by:
  6. // Created: ?
  7. // Copyright: (c) wxWidgets team
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. // For compilers that support precompilation, includes "wx/wx.h".
  11. #include "wx/wxprec.h"
  12. #ifdef __BORLANDC__
  13. #pragma hdrstop
  14. #endif
  15. // for all others, include the necessary headers (this file is usually all you
  16. // need because it includes almost all "standard" wxWidgets headers
  17. #ifndef WX_PRECOMP
  18. #include "wx/wx.h"
  19. #endif
  20. #include "wx/html/htmlwin.h"
  21. #include "../../sample.xpm"
  22. // ----------------------------------------------------------------------------
  23. // TAG HANDER FOR 'MYBIND' TAG
  24. // ----------------------------------------------------------------------------
  25. #include "wx/html/m_templ.h"
  26. TAG_HANDLER_BEGIN(MYBIND, "MYBIND")
  27. TAG_HANDLER_PROC(tag)
  28. {
  29. wxWindow *wnd;
  30. int ax, ay;
  31. int fl = 0;
  32. tag.ScanParam(wxT("X"), wxT("%i"), &ax);
  33. tag.ScanParam(wxT("Y"), wxT("%i"), &ay);
  34. if (tag.HasParam(wxT("FLOAT"))) fl = ax;
  35. wnd = new wxTextCtrl
  36. (
  37. m_WParser->GetWindowInterface()->GetHTMLWindow(),
  38. wxID_ANY,
  39. tag.GetParam(wxT("NAME")),
  40. wxPoint(0,0),
  41. wxSize(ax, ay),
  42. wxTE_MULTILINE
  43. );
  44. wnd->Show(true);
  45. m_WParser->GetContainer()->InsertCell(new wxHtmlWidgetCell(wnd, fl));
  46. return false;
  47. }
  48. TAG_HANDLER_END(MYBIND)
  49. TAGS_MODULE_BEGIN(MyBind)
  50. TAGS_MODULE_ADD(MYBIND)
  51. TAGS_MODULE_END(MyBind)
  52. // ----------------------------------------------------------------------------
  53. // private classes
  54. // ----------------------------------------------------------------------------
  55. // Define a new application type, each program should derive a class from wxApp
  56. class MyApp : public wxApp
  57. {
  58. public:
  59. // override base class virtuals
  60. // ----------------------------
  61. // this one is called on application startup and is a good place for the app
  62. // initialization (doing it here and not in the ctor allows to have an error
  63. // return: if OnInit() returns false, the application terminates)
  64. virtual bool OnInit();
  65. };
  66. // Define a new frame type: this is going to be our main frame
  67. class MyFrame : public wxFrame
  68. {
  69. public:
  70. // ctor(s)
  71. MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
  72. // event handlers (these functions should _not_ be virtual)
  73. void OnQuit(wxCommandEvent& event);
  74. void OnBack(wxCommandEvent& event);
  75. void OnForward(wxCommandEvent& event);
  76. private:
  77. // any class wishing to process wxWidgets events must use this macro
  78. wxDECLARE_EVENT_TABLE();
  79. };
  80. // ----------------------------------------------------------------------------
  81. // constants
  82. // ----------------------------------------------------------------------------
  83. // IDs for the controls and the menu commands
  84. enum
  85. {
  86. // menu items
  87. Minimal_Quit = 1,
  88. Minimal_Back,
  89. Minimal_Forward,
  90. // controls start here (the numbers are, of course, arbitrary)
  91. Minimal_Text = 1000
  92. };
  93. // ----------------------------------------------------------------------------
  94. // event tables and other macros for wxWidgets
  95. // ----------------------------------------------------------------------------
  96. // the event tables connect the wxWidgets events with the functions (event
  97. // handlers) which process them. It can be also done at run-time, but for the
  98. // simple menu events like this the static method is much simpler.
  99. wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
  100. EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
  101. EVT_MENU(Minimal_Back, MyFrame::OnBack)
  102. EVT_MENU(Minimal_Forward, MyFrame::OnForward)
  103. wxEND_EVENT_TABLE()
  104. // Create a new application object: this macro will allow wxWidgets to create
  105. // the application object during program execution (it's better than using a
  106. // static object for many reasons) and also declares the accessor function
  107. // wxGetApp() which will return the reference of the right type (i.e. MyApp and
  108. // not wxApp)
  109. IMPLEMENT_APP(MyApp)
  110. // ============================================================================
  111. // implementation
  112. // ============================================================================
  113. // ----------------------------------------------------------------------------
  114. // the application class
  115. // ----------------------------------------------------------------------------
  116. // `Main program' equivalent: the program execution "starts" here
  117. bool MyApp::OnInit()
  118. {
  119. if ( !wxApp::OnInit() )
  120. return false;
  121. // Create the main application window
  122. MyFrame *frame = new MyFrame( _("wxHtmlWindow testing application"),
  123. wxDefaultPosition, wxSize(640, 480) );
  124. // Show it
  125. frame->Show(true);
  126. // success: wxApp::OnRun() will be called which will enter the main message
  127. // loop and the application will run. If we returned false here, the
  128. // application would exit immediately.
  129. return true;
  130. }
  131. // ----------------------------------------------------------------------------
  132. // main frame
  133. // ----------------------------------------------------------------------------
  134. wxHtmlWindow *html;
  135. // frame constructor
  136. MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
  137. : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
  138. {
  139. SetIcon(wxICON(sample));
  140. // create a menu bar
  141. wxMenu *menuFile = new wxMenu;
  142. wxMenu *menuNav = new wxMenu;
  143. menuFile->Append(Minimal_Quit, _("E&xit"));
  144. menuNav->Append(Minimal_Back, _("Go &BACK"));
  145. menuNav->Append(Minimal_Forward, _("Go &FORWARD"));
  146. // now append the freshly created menu to the menu bar...
  147. wxMenuBar *menuBar = new wxMenuBar;
  148. menuBar->Append(menuFile, _("&File"));
  149. menuBar->Append(menuNav, _("&Navigate"));
  150. // ... and attach this menu bar to the frame
  151. SetMenuBar(menuBar);
  152. SetIcon(wxIcon(sample_xpm));
  153. #if wxUSE_STATUSBAR
  154. CreateStatusBar(2);
  155. #endif // wxUSE_STATUSBAR
  156. html = new wxHtmlWindow(this);
  157. html -> SetRelatedFrame(this, _("wxHTML Demo: '%s'"));
  158. #if wxUSE_STATUSBAR
  159. html -> SetRelatedStatusBar(1);
  160. #endif // wxUSE_STATUSBAR
  161. html -> LoadPage(wxT("start.htm"));
  162. }
  163. // event handlers
  164. void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
  165. {
  166. // true is to force the frame to close
  167. Close(true);
  168. }
  169. void MyFrame::OnBack(wxCommandEvent& WXUNUSED(event))
  170. {
  171. if (!html -> HistoryBack()) wxMessageBox(_("You reached prehistory era!"));
  172. }
  173. void MyFrame::OnForward(wxCommandEvent& WXUNUSED(event))
  174. {
  175. if (!html -> HistoryForward()) wxMessageBox(_("No more items in history!"));
  176. }