home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / acdf6 / acdfdlg6.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  4.7 KB  |  116 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //                      SAMPLE CODE
  3. //
  4. // FileName: ACDFDlg6.cpp
  5. //
  6. // ClassName: ATextDialog
  7. //
  8. // Description: Conversion of the Hello World 5 Sample
  9. //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #include <ibase.hpp>   
  12. #include <istring.hpp> 
  13. #include <ireslib.hpp> 
  14.  
  15. #include "acdfres6.h"
  16. #include "acdfdlg6.hpp"
  17.  
  18. ATextDialog :: ATextDialog(IString & textString, IWindow * ownerWnd):
  19.      IFrameWindow(IResourceId(WND_TEXTDIALOG),
  20.                   IWindow::desktopWindow(),
  21.                   ownerWnd,
  22.                   IRectangle(29,50,313,290).moveBy(ownerWnd->rect().bottomLeft()),
  23.                   IWindow::synchPaint
  24.                   |IWindow::clipSiblings
  25.                   |IWindow::saveBits
  26.                   |dialogBackground
  27.                   |dialogBorder
  28.                   |systemMenu
  29.                   |titleBar),
  30.      clientCanvas(WND_MCCANVAS,
  31.                   this,
  32.                   this),
  33.      buttons(WND_STCANVAS, 
  34.                   &clientCanvas,
  35.                   &clientCanvas),
  36.      statText(DID_STATIC,
  37.                   &clientCanvas,
  38.                   &clientCanvas),          
  39.      textField( DID_ENTRY,
  40.                   &clientCanvas,
  41.                   &clientCanvas),
  42.      pushButton1( DID_OK,
  43.                   &buttons,
  44.                   &buttons),
  45.      pushButton2(DID_CANCEL,
  46.                   &buttons,
  47.                   &buttons),
  48.      dialogCommandHandler(this),
  49.      saveText(textString)
  50. // Contruct the dialog as a frame window owned by the window passed
  51. {   IFUNCTRACE_DEVELOP();
  52.  
  53.     textField.setText(saveText);                                              
  54.     textField.disableAutoScroll().enableMargin().enableTabStop();             
  55.  
  56.     statText.setText(DID_STATIC);                                             
  57.  
  58.     pushButton1.enableDefault().setText(IResourceId(DID_OK)).enableTabStop(); 
  59.     pushButton2.setText(IResourceId(DID_CANCEL));                             
  60.     buttons.setPackType(ISetCanvas::expanded).setMargin(ISize());             
  61.  
  62.     //  Position the dialog controls in the multicell canvas.                 
  63.     clientCanvas.addToCell(&statText , 2, 4);                                 
  64.     clientCanvas.addToCell(&textField, 2, 7);                                 
  65.     clientCanvas.addToCell(&buttons,   2,15);                                 
  66.  
  67.     //  Set the multicell canvas as the ATextDialog client window.              
  68.     //  Have the command handler start handling events for the frame window.    
  69.     //  Set the focus to the entry field.                                       
  70.     setClient( &clientCanvas );                                               
  71.     dialogCommandHandler.handleEventsFor(this);                               
  72.     textField.setFocus();                                                     
  73.  
  74. }
  75.  
  76. ATextDialog :: ~ATextDialog()
  77. // Destructor for the dialog frame
  78. {   IFUNCTRACE_DEVELOP();
  79.     dialogCommandHandler.stopHandlingEventsFor(this);                         
  80. }
  81.  
  82. ATextDialog& ATextDialog::setTextFromEntryField()                                      
  83.  //Update the reference
  84. {   IFUNCTRACE_DEVELOP();
  85.     saveText = textField.text();                                              
  86.     return (*this);             //Return a reference to the frame   
  87.  
  88. ADialogCommandHandler :: ADialogCommandHandler(ATextDialog *dialogFrame)
  89.   :frame(dialogFrame)
  90. //  Constructs the command handler for the dialog box.
  91. {   IFUNCTRACE_DEVELOP();}
  92.  
  93.     Boolean ADialogCommandHandler :: command(ICommandEvent & cmdEvent) 
  94.     // Handle menu commands for dialog window
  95. {   IFUNCTRACE_DEVELOP();
  96.   Boolean eventProcessed(true);         //Assume event will be processed    
  97.  
  98.     // Depending on the command event ID, optionally update the Hello World text;
  99.     // then dismiss the text dialog passing the event ID as the result.
  100.  
  101.     switch (cmdEvent.commandId())
  102.     { 
  103.         case DID_OK:                                                            
  104.             frame->setTextFromEntryField();                                       
  105.             frame->dismiss(DID_OK);                                               
  106.             break;                                                                
  107.         case DID_CANCEL:                                                        
  108.             frame->dismiss(DID_CANCEL);                                           
  109.             break;                                                                
  110.         default:
  111.             eventProcessed=false;           
  112.     }
  113.     return(eventProcessed);                                                   
  114.