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

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //                                              SAMPLE CODE
  3. //
  4. // FileName: ACDFVw1.cpp
  5. //
  6. // ClassName: ACompDocFwkView
  7. //
  8. // Description: Compound Document Framework (SimpleServer) View
  9. //              This is a simple sample to demonstrate how to create a basic
  10. //              server application. The view class inherits from the IView
  11. //              class.
  12. //              The server has an entry field on the screen. This data
  13. //              is set to "Hello World" when the view is redrawn (drawContents)
  14. //              The view does not 'set' the model data only 'get'.
  15. //              
  16. ///////////////////////////////////////////////////////////////////////////////
  17. #include "ACDFMdl1.hpp"
  18. #include "ACDFVw1.hpp"
  19. #include "ACDFRes1.h"
  20.  
  21. #include <iMetaTyp.hpp>
  22. #include <iframe.hpp>
  23. #include <igstring.hpp>
  24. #include <igrect.hpp>
  25. #include <igrafctx.hpp>
  26. #include <assert.h>
  27. #include <iguibndl.hpp> // must be include after windows.h
  28.  
  29. ACompDocFwkView::ACompDocFwkView(IGUIBundle& bundle ) :
  30.     IView(bundle),
  31.     fDataEntryField (ID_ENTRY, this, this)  // Constructor for the entry field
  32. // Constructor
  33. {       IFUNCTRACE_DEVELOP();
  34.     bundle.frameWindow().setIcon(IC_ACDF1);   // Set the window icon
  35. }
  36.  
  37. ACompDocFwkView::~ACompDocFwkView()
  38. // Destructor
  39. {       IFUNCTRACE_DEVELOP(); }
  40.  
  41. ACompDocFwkModel* ACompDocFwkView::getModelPointer() const
  42. // Get the pointer to the model 
  43. {       IFUNCTRACE_DEVELOP();
  44.     ACompDocFwkModel* fOurModel = NULL;
  45.     ::dynamicCastTo( fOurModel,model() ); // Downcasts the Model pointer
  46.     return fOurModel;                     
  47. }
  48.  
  49. void ACompDocFwkView::initialize()
  50. // Intialize code e.g build menus
  51. {       IFUNCTRACE_DEVELOP();
  52.     IView::initialize();
  53.     bundle().objectView().setBackgroundColor(IColor(64,128,128)); // Set the color to green
  54.  
  55.     fDataEntryField.moveSizeTo(IRectangle(IPoint(10,10), IPoint(100,40)));
  56.     ACompDocFwkModel* fOurModel = getModelPointer();
  57.     assert(fOurModel != NULL);
  58.  
  59.     fDataEntryField.setText(fOurModel->getString());
  60.  
  61. }
  62.  
  63. void ACompDocFwkView::drawContents( IPresSpaceHandle& hdl,
  64.                 const IRectangle& invalidArea,
  65.                 Boolean metaFile )
  66. //  We can override "drawContents" if we want to optimize our drawing
  67. //  or do things differently when rendering to a meta-file (where controls
  68. //  won't be displayed).
  69. {       IFUNCTRACE_DEVELOP();
  70.     ACompDocFwkModel* fOurModel = getModelPointer();
  71.     assert(fOurModel != NULL);
  72.      
  73.     if (metaFile)
  74.     {
  75.       //Place the embedded inactive image here!!!
  76.        IGString myText(fOurModel->getString(),IPoint(20,10));
  77.        IGRectangle myRect(IRectangle(IPoint(10,10), IPoint(150,40)));
  78.        IGraphicContext ctxt ( hdl );
  79.        ctxt.setFillColor(IColor::white);
  80.        myRect.drawOn(ctxt);
  81.        myText.drawOn(ctxt);
  82.     }
  83. }
  84.