home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / samples / sample17 / sample17.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-22  |  5.0 KB  |  185 lines

  1. #define DEBUG
  2. #define INCL_OOL
  3. #include "sample17.h"
  4. #include <stdlib.h>
  5. #include "dialog.h"
  6.  
  7.  
  8. class MyWizard: public XWizard
  9. {
  10.    public:
  11.       BOOL DoCommand(LONG);
  12.       BOOL DoSysCommand( USHORT com);
  13.       MyWizard(XWindow*, const XRect& rect=(200,200,300,300), char * test = "test");
  14. };
  15.  
  16.  
  17. BOOL MyWizard :: DoSysCommand( USHORT com)
  18. {
  19.    if(com == SC_CLOSE)
  20.    {
  21.       if( XShowMessage("Are you shure to exit the assistant?", MB_YESNO|MB_ICONQUESTION|MB_MOVEABLE, this) == MBID_NO)
  22.          return FALSE;
  23.       debugMessage("wizzard closed");
  24.    } /* end if */
  25.    return TRUE;
  26. }
  27.  
  28.  
  29. BOOL MyWizard :: DoCommand(LONG com)
  30. {
  31.    if(com == IDP_NEXT)
  32.       ShowNextPage();
  33.    else if(com == IDP_PREV)
  34.       ShowPrevPage();
  35.    else if(com == IDP_CREATE)
  36.    {
  37.       XMessageBox msb("Ready?", "MyAssistant", MB_YESNO|MB_ICONQUESTION|MB_MOVEABLE, this);
  38.       if(msb.GetCommand() == MBID_YES)
  39.          Close();
  40.    }
  41.    return FALSE;
  42. }
  43.  
  44.  
  45. MyWizard :: MyWizard(XWindow*w, const XRect& rect, char*): XWizard(w, 100)
  46. {
  47.    XWizClientWindow * w1 = new XWizClientWindow(this, DLG_START);
  48.    SetStartPage(w1);
  49.    XWizClientWindow * w2 = new XWizClientWindow(this, IDD_SET);
  50.    w1->SetNextPage(w2);
  51.    XWizClientWindow * w3 = new XWizClientWindow(this, IDD_FINISH);
  52.    w2->SetNextPage(w3);
  53. }
  54.  
  55.  
  56. //create a window out of the resource-file, the last parameter tells the library to
  57. //build the window with the ID IDM_MENU.
  58. SampleWindow :: SampleWindow( ): XFrameWindow( IDM_MENU, "Sample", XFrameWindow::defaultStyle | FRM_ICON | FRM_TASKLIST | FRM_CENTER       | FRM_MENU | FRM_ACCELTABLE     )
  59. {
  60.    //Set background-color
  61.    XColor color( COL_WHITE);
  62.    SetBackgroundColor( &color );
  63.  
  64.    //Set size
  65.    XRect rect( 100,100, 400, 300);
  66.    SetSize(&rect);
  67.  
  68.    //create a helpinstance
  69.    help = new XHelpInstance( "Sample17.hlp", "Sample - Help");
  70.    //associate the help with this function
  71.    help->AssociateWindow( this );
  72.  
  73.    MyWizard * w = new MyWizard(this);
  74.    help->AssociateWindow( w );
  75.    w->Init();
  76.  
  77.    Invalidate(TRUE);
  78. }
  79.  
  80.  
  81. SampleWindow :: ~SampleWindow()
  82. {
  83.    debugMessage("main window closed");
  84. }
  85.  
  86.  
  87. //draw the window-content
  88. void SampleWindow :: Draw( void )
  89. {
  90.    //fill the background
  91.    FillBackground( );
  92. }
  93.  
  94.  
  95. /* here the commands of the menu are posted */
  96. BOOL SampleWindow :: DoCommand( LONG command)
  97. {
  98.    switch( command )
  99.    {
  100.       //which menuitem was selected?
  101.       case IDM_OPEN:
  102.            {
  103.          /*File/Open selected */
  104.          /* display the file-dialog defined by the system */
  105.          /* set the file-suffix and title of the dialog */
  106.          XFileDialog fileDlg(this, "*.TXT", NULL, NULL, FD_OPEN | FD_CENTER | FD_MULTIPLESEL);
  107.  
  108.          /* the user selected a file */
  109.          if( fileDlg.GetCommand() == USER_OK)
  110.          {
  111.             XString fileName;
  112.             SHORT i, files = fileDlg.GetFileCount();  //how much files are selected?
  113.             for(i=0; i < files; i++)
  114.             {
  115.                fileDlg.GetFileName( &fileName, i );  //get filename and path for every file
  116.                //perfor your loading of the selected file(s) here
  117.             }
  118.          }
  119.       }
  120.       break;
  121.       case IDM_SAVEAS:
  122.            {
  123.                /*File/Open selected */
  124.                /* display the file-dialog defined by the system */
  125.                /* set the file-suffix and title of the dialog */
  126.                XFileDialog fileDlg(this, "*.TXT", NULL, NULL, FD_SAVEAS | FD_CENTER );
  127.  
  128.                /* the user selected a file */
  129.                if( fileDlg.GetCommand() == USER_OK)
  130.                  {
  131.                     XString fileName;
  132.                     fileDlg.GetFileName( &fileName);  //get filename and path where to save
  133.                     //perfor your save_as code here
  134.                  }
  135.             }
  136.             break;
  137.          case IDM_HELP_HELP:
  138.             help->ShowHelpForHelp();
  139.             break;
  140.          case IDM_HELP_INDEX:
  141.             help->ShowHelpIndex();
  142.             break;
  143.          case IDM_HELP_GENERAL:
  144.             help->ShowHelpForId( 100 );
  145.             break;
  146.       }
  147.    return TRUE;
  148. }
  149.  
  150.  
  151. //here the control-events of our window-contents are posted
  152. void SampleWindow :: DoControl( XControlEvent * event)
  153. {
  154.    switch( event->GetEventID())              //what type of event?
  155.       {
  156.          case WIN_CHANGED:                   //window-content changed!
  157.             {
  158.                switch( event->GetWindowID()) //which window posted the event?
  159.                   {
  160.                      default:
  161.                         break;
  162.                   }
  163.             }
  164.       }
  165. }
  166.  
  167.  
  168. int main ( int argc, void ** argv)
  169. {
  170.    //create the window
  171.    try
  172.    {
  173.       XConsole::CheckConsole(argc, argv);
  174.       debugMessage("start window init");
  175.       SampleWindow * window = new SampleWindow( );
  176.       debugMessage("end window init");
  177.    } /* end try */
  178.    catch( XException e)
  179.    {
  180.       e.ShowError();
  181.    } /* end catch */
  182.    char * s = (char*) malloc(20);
  183.    XApplication::GetApplication()->Start();
  184. }
  185.