home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / frame1 / dialog / dialog.cpp next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  3.0 KB  |  123 lines

  1. //*********************************************************
  2. // Frame Window Basics - Loading a Dialog Template
  3. //
  4. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  5. // Copyright (c) 1997 John Wiley & Sons, Inc. 
  6. // All Rights Reserved.
  7. //*********************************************************
  8. #include <iapp.hpp>
  9. #include <icmdhdr.hpp>
  10. #include <iframe.hpp>
  11. #include <imenubar.hpp>
  12. #include "dialog.h"
  13.  
  14. class PrimaryCmdHandler : public ICommandHandler {
  15. protected:
  16. virtual Boolean
  17.   command ( ICommandEvent& event );
  18. }; // PrimaryCmdHandler
  19.  
  20. class DialogCmdHandler : public ICommandHandler {
  21. protected:
  22. virtual Boolean
  23.   command ( ICommandEvent& event );
  24. }; // DialogCmdHandler
  25.  
  26. class DialogFrameWindow : public IFrameWindow {
  27. public:
  28.   DialogFrameWindow ( unsigned long identifier,
  29.                       IWindow*      owner );
  30.  ~DialogFrameWindow ( );
  31.  
  32. private:
  33.   DialogFrameWindow ( const DialogFrameWindow& );
  34. DialogFrameWindow
  35.  &operator=         ( const DialogFrameWindow& );
  36. DialogCmdHandler
  37.   cmdHandler;
  38. }; // DialogFrameWindow
  39.  
  40. void main ( )
  41. {
  42.   // Create a primary frame window.
  43.   IFrameWindow
  44.     primary( "Primary Frame That Loads a Dialog Template" );
  45.  
  46.   // Create a menu bar and add a choice to open a dialog.
  47.   IMenuBar 
  48.     menuBar( &primary );
  49.   menuBar
  50. #ifdef IC_PM
  51.    .addText( ID_FILE, "~File" )
  52. #else
  53.    .addText( ID_FILE, "&File" )
  54. #endif
  55.    .addSubmenu( ID_FILE )
  56.    .addText( ID_DIALOG_CMD, "Hello...", ID_FILE );
  57.  
  58.   // Create the command handler for the primary window.
  59.   PrimaryCmdHandler
  60.     cmdHandler;
  61.   cmdHandler
  62.    .handleEventsFor( &primary );
  63.  
  64.   // Set the focus and show the frame window.
  65.   primary
  66.    .setFocus()
  67.    .show();
  68.  
  69.   IApplication::current().run();
  70. }
  71.  
  72. IBase::Boolean
  73.   PrimaryCmdHandler::command ( ICommandEvent& event )
  74. {
  75.   Boolean
  76.     stopProcessingEvent = false;
  77.   // Check for the "Hello..." menu choice.
  78.   if ( event.commandId() == ID_DIALOG_CMD )
  79.   {
  80.      DialogFrameWindow *dialog = 
  81.        new DialogFrameWindow( ID_DIALOG,
  82.                               event.dispatchingWindow() );
  83.      (*dialog)
  84.       .setAutoDeleteObject()
  85.       .setFocus()
  86.       .show();
  87.      stopProcessingEvent = true;
  88.   }
  89.   return stopProcessingEvent;
  90. }
  91.  
  92. IBase::Boolean
  93.   DialogCmdHandler::command ( ICommandEvent& event )
  94. {
  95.   Boolean
  96.     stopProcessingEvent = false;
  97.   if ( event.commandId() == ID_OK )
  98.   {
  99.      DialogFrameWindow *dialog = 
  100.        (DialogFrameWindow*)( event.dispatchingWindow() );
  101.      (*dialog)
  102.       .setResult( event.commandId() )
  103.       .close();
  104.      stopProcessingEvent = true;
  105.   }
  106.   return stopProcessingEvent;
  107. }
  108.  
  109. DialogFrameWindow::DialogFrameWindow ( unsigned long identifer,
  110.                                        IWindow*      owner )
  111.  : IFrameWindow( identifer, owner ),
  112.    cmdHandler( )
  113. {
  114.    cmdHandler
  115.     .handleEventsFor( this );
  116. }
  117.  
  118. DialogFrameWindow::~DialogFrameWindow ( )
  119. {
  120.    cmdHandler
  121.     .stopHandlingEventsFor( this );
  122. }
  123.