home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / wxwin140 / utils / wxhelp / src / test.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  3.8 KB  |  139 lines

  1. /*
  2.  * File:     test.cc
  3.  * Purpose:  Test wxWindows app to demonstrate use of wxHelp API
  4.  *
  5.  *                       wxWindows 1.40
  6.  * Copyright (c) 1993 Artificial Intelligence Applications Institute,
  7.  *                   The University of Edinburgh
  8.  *
  9.  *                     Author: Julian Smart
  10.  *                        Date: 18-4-93
  11.  *
  12.  * Permission to use, copy, modify, and distribute this software and its
  13.  * documentation for any purpose is hereby granted without fee, provided
  14.  * that the above copyright notice, author statement and this permission
  15.  * notice appear in all copies of this software and related documentation.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
  18.  * IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
  19.  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  * IN NO EVENT SHALL THE ARTIFICIAL INTELLIGENCE APPLICATIONS INSTITUTE OR THE
  22.  * UNIVERSITY OF EDINBURGH BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR
  23.  * CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM
  24.  * LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF
  25.  * DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
  26.  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  */
  28.  
  29. #include <windows.h> // Included only for benefit of MSC7 precompiled headers
  30. #include "wx.h"
  31. #include "wx_help.h"
  32.  
  33. // Define a new application type
  34. class MyApp: public wxApp
  35. { public:
  36.     wxFrame *OnInit(void);
  37. };
  38.  
  39. // Define a new frame type
  40. class MyFrame: public wxFrame
  41. { public:
  42.     MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
  43.     void OnMenuCommand(int id);
  44.     Bool OnClose(void);
  45. };
  46.  
  47. // ID for the menu quit command
  48. #define TEST_QUIT 1
  49. #define TEST_HELP_ON_HELP 2
  50. #define TEST_HELP_ON_EDITING 3
  51. #define TEST_KEYWORD 4
  52.  
  53. // This statement initializes the whole application and calls OnInit
  54. MyApp myApp;
  55.  
  56. // Help instance
  57. wxHelpInstance *HelpInstance = NULL;
  58.  
  59. // `Main program' equivalent, creating windows and returning main app frame
  60. wxFrame *MyApp::OnInit(void)
  61. {
  62.   // Create the main frame window
  63.   MyFrame *frame = new MyFrame(NULL, "Test wxWindows App", 0, 0, 400, 300);
  64.  
  65.   // Give it an icon
  66.   frame->SetIcon(new wxIcon("aiai_icn"));
  67.  
  68.   // Make a menubar
  69.   wxMenu *file_menu = new wxMenu;
  70.   file_menu->Append(TEST_QUIT, "Quit");
  71.  
  72.   wxMenu *help_menu = new wxMenu;
  73.   help_menu->Append(TEST_HELP_ON_HELP, "Help on  wxHelp");
  74.   help_menu->Append(TEST_HELP_ON_EDITING, "Help on  wxHelp Editing");
  75.   help_menu->Append(TEST_KEYWORD, "Keyword search");
  76.  
  77.   wxMenuBar *menu_bar = new wxMenuBar;
  78.   menu_bar->Append(file_menu, "File");
  79.   menu_bar->Append(help_menu, "Help");
  80.   frame->SetMenuBar(menu_bar);
  81.  
  82.   // Make a panel with a message
  83.   wxPanel *panel = new wxPanel(frame, 0, 0, 400, 300);
  84.   (void)new wxMessage(panel, "Hello, this is a test wxWindows program!");
  85.  
  86.   HelpInstance = new wxHelpInstance;
  87.   HelpInstance->Initialize("help.xlp");
  88.  
  89.   frame->Show(TRUE);
  90.  
  91.   // Return the main frame window
  92.   return frame;
  93. }
  94.  
  95. // My frame constructor
  96. MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
  97.   wxFrame(frame, title, x, y, w, h)
  98. {}
  99.  
  100. // Intercept menu commands
  101. void MyFrame::OnMenuCommand(int id)
  102. {
  103.   switch (id) {
  104.     case TEST_QUIT:
  105.       OnClose();
  106.       delete this;
  107.       break;
  108.     case TEST_HELP_ON_HELP:
  109.     {
  110.       HelpInstance->LoadFile();
  111.       HelpInstance->DisplayContents();
  112.       break;
  113.     }
  114.     case TEST_HELP_ON_EDITING:
  115.     {
  116.       HelpInstance->LoadFile();
  117.       HelpInstance->DisplaySection(9);
  118.       break;
  119.     }
  120.     case TEST_KEYWORD:
  121.     {
  122.       char *s = wxGetTextFromUser("Enter keyword");
  123.       if (s)
  124.       {
  125.         HelpInstance->LoadFile();
  126.         HelpInstance->KeywordSearch(s);
  127.       }
  128.       break;
  129.     }
  130.   }
  131. }
  132.  
  133. Bool MyFrame::OnClose(void)
  134. {
  135.   HelpInstance->Quit();
  136.   return TRUE;
  137. }
  138.  
  139.