home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ibmodf.zip / CUSTOMER.ZIP / CUSTVIEW.CPP < prev    next >
Text File  |  1995-06-19  |  17KB  |  358 lines

  1. /*******************************************************************************
  2. * FILE NAME: custview.cpp                                                       *
  3. *                                                                              *
  4. * DESCRIPTION:                                                                 *
  5. *   This file contains the implementation of classes/functions declared        *
  6. *   in custview.hpp.                                                            *
  7. *                                                                              *
  8. * COPYRIGHT:                                                                   *
  9. *   Licensed Materials - Property of IBM                                       *
  10. *   (C) Copyright IBM Corporation 1994                                         *
  11. *   All Rights Reserved                                                        *
  12. *   US Government Users Restricted Rights - Use, duplication, or               *
  13. *   disclosure                                                                 *
  14. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  15. *                                                                              *
  16. *******************************************************************************/
  17. // Priority INT_MIN (-2147483647 - 1) + 1024 + 512
  18. #pragma priority( -2147482112 )
  19.  
  20. // ------- UICL and local includes ------------
  21. #include <custview.hpp>
  22. #include <ireslib.hpp>
  23.  
  24. #include <mydefs.h>
  25. #include <icolor.hpp>
  26.  
  27. // Segment definitions 
  28. #ifdef IC_PAGETUNE
  29.   #define _CUSTVIEW _CPP_
  30.   #include <ipagetun.h>
  31. #endif
  32.  
  33.  
  34. /*------------------------------------------------------------------------------
  35. | MyCustomerView ::MyCustomerView                                              |
  36. |                                                                              |
  37. | Constructor to create a form view                                            |
  38. ------------------------------------------------------------------------------*/
  39. MyCustomerView :: MyCustomerView (unsigned long ulId,
  40.                           CustomerModel* model,
  41.                           const ISize& sizeInit,
  42.                           const Style& style)
  43.    : ODFFormView (ulId,
  44.                   (ODFModel*)model,
  45.                   sizeInit,
  46.                   style)
  47. {
  48.   IApplication::current().setUserResourceLibrary ("custpart.dll");
  49.  
  50. /******************************************************************************/
  51. /* To RC compile this you must have the blues bitmap in the build directory   */
  52. /* or substitute with another .bmp file.                                      */
  53. /******************************************************************************/
  54.  
  55.   customerNameEF = new IEntryField(ID_CUST,  //Create entry field for customer name
  56.                                 this,
  57.                                 this,
  58.                                 IRectangle(10, 50, 190, 70) );
  59.   balanceEF = new IEntryField(ID_BALANCE,  //Create entry field for account balance
  60.                                this,
  61.                                this,
  62.                                IRectangle(10, 10, 150, 30) );
  63.  
  64.   // Don't set control values (or just set to a default); framework initializes
  65.   //   you by calling your modelChangedFunctions shortly after this ctor completes.
  66.  
  67.   customerNameEF->setFocus();                //Set focus to customer entry field
  68. }
  69.  
  70.  
  71.  
  72. /*------------------------------------------------------------------------------
  73. | MyCustomerView ::~MyCustomerView                                             |
  74. |                                                                              |
  75. ------------------------------------------------------------------------------*/
  76. MyCustomerView  :: ~MyCustomerView ()
  77. {
  78.    removeConnection (customerNameConn);
  79.    removeConnection (balanceConn);
  80.    // All IWindow-derived children of our view (e.g., background, customerNameEF)
  81.    //  are automatically deleted when our view is deleted.
  82. }
  83.  
  84. /*------------------------------------------------------------------------------
  85. | MyCustomerView ::makeConnections                                             |
  86. |                                                                              |
  87. ------------------------------------------------------------------------------*/
  88. MyCustomerView &MyCustomerView  :: makeConnections ()
  89. {
  90.   // Not all controls have to be modeled; some can be unrelated to any data in the
  91.   // model object, simply part of canned view-related information such as titles.
  92.   // Make note of the ones which are modeled.
  93.   customerNameConn = new IModelViewSynchConnection( 
  94.                            *(model()->customer()), 
  95.                            ICustomer::nameId,
  96.                            new IThreadMemberFn<MyCustomerView>
  97.                                   (*this, customerNameChanged),
  98.                            *this,
  99.                            *customerNameEF,
  100.                            new IThreadMemberFn<MyCustomerView>
  101.                                   (*this, customerNameEFChanged)  );
  102.   balanceConn = new IModelViewSynchConnection(
  103.                            *(model()->balance()), Balance::balanceId,
  104.                            new IThreadMemberFn<MyCustomerView>
  105.                                   (*this, balanceChanged),
  106.                            *this,
  107.                            *balanceEF,
  108.                            new IThreadMemberFn<MyCustomerView>
  109.                                   (*this, balanceEFChanged)  );
  110. }
  111.  
  112. /*------------------------------------------------------------------------------
  113. | MyCustomerView ::drawView                                                    |
  114. |                                                                              |
  115. | Gives derived classes an opportunity to draw in the view. At this time,      |
  116. | the view is already populated with controls. Default behavior is nothing.    |
  117. ------------------------------------------------------------------------------*/
  118. MyCustomerView &MyCustomerView :: drawView()
  119. {
  120.    //Don't do any drawing (but we could...)
  121.   return *this;
  122. }
  123.  
  124.  
  125. /*------------------------------------------------------------------------------
  126. | MyCustomerView ::model                                                       |
  127. |                                                                              |
  128. | Override of ODFFormView method, so we return OUR type of model instead of    |
  129. | a pointer typed to the base model class.                                     |
  130. ------------------------------------------------------------------------------*/
  131. CustomerModel *MyCustomerView :: model()
  132. {
  133.   return (CustomerModel*)Inherited::model();
  134. }
  135.  
  136.  
  137. /*------------------------------------------------------------------------------
  138. | MyCustomerView::customerNameEFChanged                                        |
  139. |                                                                              |
  140. ------------------------------------------------------------------------------*/
  141. void MyCustomerView :: customerNameEFChanged()
  142. {
  143.    if ( isViewEnabled() ) {
  144.       model()->customer()->setName( customerNameEF->text() );
  145.   } /* endif */
  146. }
  147.  
  148. /*------------------------------------------------------------------------------
  149. | MyCustomerView::customerNameChanged                                          |
  150. |                                                                              |
  151. ------------------------------------------------------------------------------*/
  152. void MyCustomerView :: customerNameChanged()
  153. {
  154.    if ( isViewEnabled() ) {
  155.      customerNameEF->setText( model()->customer()->name() );
  156.    } /* endif */
  157. }
  158.  
  159.  
  160. /*------------------------------------------------------------------------------
  161. | MyCustomerView::balanceEFChanged                                             |
  162. |                                                                              |
  163. ------------------------------------------------------------------------------*/
  164. void MyCustomerView :: balanceEFChanged()
  165. {
  166.    if ( isViewEnabled() ) {
  167.      // NOTE: is this an example of where primitive objects
  168.      // are actually useful after all? Is this what Avalon uses it's primitive
  169.      // objects for? see Steve, Dave L and also Steve Miller...
  170.      // Or is it better to force the user to create a class (as I did here) with
  171.      // only one attribute, with the assumption that the class will grow later?
  172.      model()->balance()->setValue( (unsigned long) (balanceEF->text().asUnsigned()) );
  173.    } /* endif */
  174. }
  175.  
  176. /*------------------------------------------------------------------------------
  177. | MyCustomerView::balanceChanged                                               |
  178. |                                                                              |
  179. ------------------------------------------------------------------------------*/
  180. void MyCustomerView :: balanceChanged()
  181. {
  182.    if ( isViewEnabled() ) {
  183.       balanceEF->setText( model()->balance()->asString() );
  184.    } /* endif */
  185. }
  186.  
  187.  
  188.  
  189.  
  190.  
  191. /*------------------------------------------------------------------------------
  192. | MySecondaryCustomerView ::MySecondaryCustomerView                            |
  193. |                                                                              |
  194. | Constructor to create a form view using a multicell canvas.                  |
  195. | NOTE                                                                         |
  196. |   Illustrates the use of a multi-cell canvas in a view.  Contrary to the     |
  197. |   recommended approach of setting the parent and owner of controls within    |
  198. |   the canvas to the canvas itself, this sample sets the owner of             |
  199. |   the controls to the view. This is to achieve proper event handling in      |
  200. |   particular cases. This practice may be changed in later driver.            |
  201. ------------------------------------------------------------------------------*/
  202. MySecondaryCustomerView :: MySecondaryCustomerView (unsigned long ulId,
  203.                                             CustomerModel* model,
  204.                                             const ISize& sizeInit,
  205.                                             const Style& style)
  206.   : ODFFormView (ulId,
  207.                  (ODFModel*)model,
  208.                  sizeInit,
  209.                  style),
  210.  
  211.    multiCell (new IMultiCellCanvas(ID_CANVAS, this, this)),
  212.    customerNameEF(ID_CUST, multiCell, this, IRectangle(5, 210, 190, 230)),
  213.    companyEF(ID_COMPANY, multiCell, this, IRectangle(5, 170, 190, 190)),
  214.    stateListBox(ID_STATE, multiCell, this, IRectangle(60, 15, 220, 90)),
  215.    custLabel (ID_CUST_LABEL, multiCell, this),
  216.    companyLabel (ID_COMPANY_LABEL, multiCell, this),
  217.    stateLabel (ID_STATE_LABEL, multiCell, this)
  218.  
  219. {
  220.   IApplication::current().setUserResourceLibrary ("custpart.dll");
  221.  
  222.   custLabel.setText (ID_CUST_LABEL);
  223.   custLabel.setLimit (custLabel.textLength());
  224.   companyLabel.setText (ID_COMPANY_LABEL);
  225.   companyLabel.setLimit (companyLabel.textLength());
  226.   stateLabel.setText (ID_STATE_LABEL);
  227.   stateLabel.setLimit (stateLabel.textLength());
  228.  
  229.   // Set the view's "client" to the multiCell so it will size when view is sized.
  230.   setViewClient (multiCell);
  231.  
  232.   // Add controls to the multi-cell canvas.
  233.   multiCell->addToCell (&custLabel, 2, 1, 2);
  234.   multiCell->addToCell (&customerNameEF, 2, 2, 2);
  235.   multiCell->addToCell (&companyLabel, 2, 4, 2);
  236.   multiCell->addToCell (&companyEF, 2, 5, 2);
  237.   multiCell->addToCell (&stateLabel, 2, 13, 2);
  238.   multiCell->addToCell (&stateListBox, 2, 14, 2);
  239.   multiCell->setColumnWidth (5, 10, true);
  240.  
  241.   //initialize the state listbox with it's three (view-specific) entries
  242.   stateListBox.add(1, "New York");
  243.   stateListBox.add(2, "North Carolina");
  244.   stateListBox.add(3, "California");
  245.  
  246.   // Don't set control values (or just set to a default); framework initializes
  247.   //   you by calling your modelChangedFunctions shortly after this ctor completes.
  248.  
  249.   customerNameEF.setFocus();                //Set focus to customer entry field
  250. }
  251.  
  252.  
  253. /*------------------------------------------------------------------------------
  254. | MySecondaryCustomerView ::~MySecondaryCustomerView                                   |
  255. |                                                                              |
  256. ------------------------------------------------------------------------------*/
  257. MySecondaryCustomerView  :: ~MySecondaryCustomerView ()
  258. {
  259.    removeConnection (customerNameConn);
  260.    removeConnection (companyConn);
  261.    removeConnection (stateConn);
  262. }
  263.  
  264.  
  265. /*------------------------------------------------------------------------------
  266. | MySecondaryCustomerView ::model                                              |
  267. |                                                                              |
  268. | Override of ODFFormView method, so we return OUR type of model instead of    |
  269. | a pointer typed to the base model class.                                     |
  270. ------------------------------------------------------------------------------*/
  271. CustomerModel *MySecondaryCustomerView :: model()
  272. {
  273.   return (CustomerModel*)Inherited::model();
  274. }
  275.  
  276.  
  277. /*------------------------------------------------------------------------------
  278. | MySecondaryCustomerView ::makeConnections                                        |
  279. |                                                                              |
  280. ------------------------------------------------------------------------------*/
  281. MySecondaryCustomerView &MySecondaryCustomerView  :: makeConnections ()
  282. {
  283.   // Not all controls have to be modeled; some can be unrelated to any data in the
  284.   // model object, simply part of canned view-related information such as titles.
  285.   // Make note of the ones which are modeled.
  286.   customerNameConn = new IModelViewSynchConnection( 
  287.                            *(model()->customer()), ICustomer::nameId,
  288.                            new IThreadMemberFn<MySecondaryCustomerView>
  289.                                   (*this, customerNameChanged),
  290.                            *this,
  291.                            customerNameEF,
  292.                            new IThreadMemberFn<MySecondaryCustomerView>
  293.                                   (*this, customerNameEFChanged) );
  294.   companyConn = new IModelViewSynchConnection(
  295.                            *(model()->company()), ICompany::nameId,
  296.                            new IThreadMemberFn<MySecondaryCustomerView>
  297.                                   (*this, companyChanged),
  298.                            *this,
  299.                            companyEF,
  300.                            new IThreadMemberFn<MySecondaryCustomerView>
  301.                                   (*this, companyEFChanged) );
  302.   stateConn = new IModelViewSynchConnection(
  303.                            *(model()->customer()->address()), IAddress::stateId,
  304.                            new IThreadMemberFn<MySecondaryCustomerView>
  305.                                   (*this, customerStateChanged),
  306.                            *this,
  307.                            stateListBox,
  308.                            new IThreadMemberFn<MySecondaryCustomerView>
  309.                                   (*this, customerStateLBChanged) );
  310. }
  311.  
  312.  
  313. void MySecondaryCustomerView :: customerNameEFChanged()
  314. {
  315.    if ( isViewEnabled() ) {                             
  316.      model()->customer()->setName( customerNameEF.text() );
  317.   } /* endif */
  318. }
  319.  
  320.  
  321. void MySecondaryCustomerView :: customerNameChanged()
  322. {
  323.    if ( isViewEnabled() ) {
  324.      customerNameEF.setText( model()->customer()->name() );
  325.    } /* endif */
  326. }
  327.  
  328.  
  329. void MySecondaryCustomerView :: customerStateLBChanged()
  330. {
  331.    if ( isViewEnabled() ) {
  332.      model()->customer()->address()->setState( stateListBox.itemText(stateListBox.selection()) );
  333.    } /* endif */
  334. }
  335. void MySecondaryCustomerView :: customerStateChanged()
  336. {
  337.    if ( isViewEnabled() ) {
  338.      unsigned long index = stateListBox.locateText( model()->customer()->address()->state() );
  339.      stateListBox.select(index);
  340.    } /* endif */
  341. }
  342.  
  343.  
  344. void MySecondaryCustomerView :: companyEFChanged()
  345. {
  346.    if ( isViewEnabled() ) {                             
  347.      model()->company()->setName( companyEF.text() );
  348.   } /* endif */
  349. }
  350.  
  351.  
  352. void MySecondaryCustomerView :: companyChanged()
  353. {
  354.    if ( isViewEnabled() ) {
  355.      companyEF.setText( model()->company()->name() );
  356.    } /* endif */
  357. }
  358.