zip.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: zip.cpp
  3. // Purpose: wxHtml sample
  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/image.h"
  21. #include "wx/html/htmlwin.h"
  22. #include "wx/fs_zip.h"
  23. #ifndef wxHAS_IMAGES_IN_RESOURCES
  24. #include "../../sample.xpm"
  25. #endif
  26. // ----------------------------------------------------------------------------
  27. // private classes
  28. // ----------------------------------------------------------------------------
  29. // Define a new application type, each program should derive a class from wxApp
  30. class MyApp : public wxApp
  31. {
  32. public:
  33. // override base class virtuals
  34. // ----------------------------
  35. // this one is called on application startup and is a good place for the app
  36. // initialization (doing it here and not in the ctor allows to have an error
  37. // return: if OnInit() returns false, the application terminates)
  38. virtual bool OnInit();
  39. };
  40. // Define a new frame type: this is going to be our main frame
  41. class MyFrame : public wxFrame
  42. {
  43. public:
  44. // ctor(s)
  45. MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
  46. // event handlers (these functions should _not_ be virtual)
  47. void OnQuit(wxCommandEvent& event);
  48. void OnBack(wxCommandEvent& event);
  49. void OnForward(wxCommandEvent& event);
  50. private:
  51. // any class wishing to process wxWidgets events must use this macro
  52. wxDECLARE_EVENT_TABLE();
  53. };
  54. // ----------------------------------------------------------------------------
  55. // constants
  56. // ----------------------------------------------------------------------------
  57. // IDs for the controls and the menu commands
  58. enum
  59. {
  60. // menu items
  61. Minimal_Quit = 1,
  62. Minimal_Back,
  63. Minimal_Forward
  64. };
  65. // ----------------------------------------------------------------------------
  66. // event tables and other macros for wxWidgets
  67. // ----------------------------------------------------------------------------
  68. // the event tables connect the wxWidgets events with the functions (event
  69. // handlers) which process them. It can be also done at run-time, but for the
  70. // simple menu events like this the static method is much simpler.
  71. wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
  72. EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
  73. EVT_MENU(Minimal_Back, MyFrame::OnBack)
  74. EVT_MENU(Minimal_Forward, MyFrame::OnForward)
  75. wxEND_EVENT_TABLE()
  76. // Create a new application object: this macro will allow wxWidgets to create
  77. // the application object during program execution (it's better than using a
  78. // static object for many reasons) and also declares the accessor function
  79. // wxGetApp() which will return the reference of the right type (i.e. MyApp and
  80. // not wxApp)
  81. IMPLEMENT_APP(MyApp)
  82. // ============================================================================
  83. // implementation
  84. // ============================================================================
  85. // ----------------------------------------------------------------------------
  86. // the application class
  87. // ----------------------------------------------------------------------------
  88. // `Main program' equivalent: the program execution "starts" here
  89. bool MyApp::OnInit()
  90. {
  91. if ( !wxApp::OnInit() )
  92. return false;
  93. #if wxUSE_LIBPNG
  94. wxImage::AddHandler(new wxPNGHandler);
  95. #endif
  96. #if wxUSE_LIBJPEG
  97. wxImage::AddHandler(new wxJPEGHandler);
  98. #endif
  99. wxFileSystem::AddHandler(new wxZipFSHandler);
  100. // Create the main application window
  101. MyFrame *frame = new MyFrame(_("wxHtmlWindow testing application"),
  102. wxDefaultPosition, wxSize(640, 480) );
  103. // Show it
  104. frame->Show(true);
  105. // success: wxApp::OnRun() will be called which will enter the main message
  106. // loop and the application will run. If we returned false here, the
  107. // application would exit immediately.
  108. return true;
  109. }
  110. // ----------------------------------------------------------------------------
  111. // main frame
  112. // ----------------------------------------------------------------------------
  113. wxHtmlWindow *html;
  114. // frame constructor
  115. MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
  116. : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
  117. {
  118. SetIcon(wxICON(sample));
  119. // create a menu bar
  120. wxMenu *menuFile = new wxMenu;
  121. wxMenu *menuNav = new wxMenu;
  122. menuFile->Append(Minimal_Quit, _("E&xit"));
  123. menuNav->Append(Minimal_Back, _("Go &BACK"));
  124. menuNav->Append(Minimal_Forward, _("Go &FORWARD"));
  125. // now append the freshly created menu to the menu bar...
  126. wxMenuBar *menuBar = new wxMenuBar;
  127. menuBar->Append(menuFile, _("&File"));
  128. menuBar->Append(menuNav, _("&Navigate"));
  129. // ... and attach this menu bar to the frame
  130. SetMenuBar(menuBar);
  131. #if wxUSE_STATUSBAR
  132. CreateStatusBar(1);
  133. #endif // wxUSE_STATUSBAR
  134. html = new wxHtmlWindow(this);
  135. html -> SetRelatedFrame(this, _("HTML : %s"));
  136. #if wxUSE_STATUSBAR
  137. html -> SetRelatedStatusBar(0);
  138. #endif // wxUSE_STATUSBAR
  139. html -> LoadPage(wxT("start.htm"));
  140. }
  141. // event handlers
  142. void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
  143. {
  144. // true is to force the frame to close
  145. Close(true);
  146. }
  147. void MyFrame::OnBack(wxCommandEvent& WXUNUSED(event))
  148. {
  149. if (!html -> HistoryBack()) wxMessageBox(_("You reached prehistory era!"));
  150. }
  151. void MyFrame::OnForward(wxCommandEvent& WXUNUSED(event))
  152. {
  153. if (!html -> HistoryForward()) wxMessageBox(_("No more items in history!"));
  154. }