home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sompar.zip / SETPAGES.CPP < prev    next >
C/C++ Source or Header  |  1993-12-19  |  14KB  |  485 lines

  1. //                
  2. // Project: Digitalk Parts like Toolbar and SOMObjects Demo
  3. // File:    Setpages.cpp
  4. // Author:  Stewart Hyde
  5. // Created: Dec   17, 1993
  6. // Updated: Dec   19, 1993
  7. //
  8. // Description:
  9. //
  10.  
  11. #include <ireslib.hpp>
  12. #include <iframe.hpp>
  13. #include <istring.hpp>
  14. #include <icolor.hpp>
  15. #include "setpages.hpp"
  16. #include "somparts.h"
  17.  
  18. // ------------------------------------------------------------------------
  19. //  Class:                DialogPage
  20. //  Function:            DialogPage (constructor)
  21. //                
  22. //  Description:        This is the contructor for the base dialog class
  23. //       
  24. //  Input:                IWindow *parentWin     - parent window
  25. //                            IWindow *ownerWin      - owner window
  26. //                            int        nIndex        - page index (for resources)
  27. //                            SomAction *somAction    - pointer to SomActions class
  28. //
  29. //  Output:                N/A
  30. //
  31. //  Notes:
  32. //
  33. // ------------------------------------------------------------------------
  34.  
  35. DialogPage::DialogPage(IWindow *parentWin,
  36.                              IWindow *ownerWin,
  37.                              int nIndex,
  38.                              SomAction *somAction)
  39.   : ICanvas(WND_FIRST_DIALOG+nIndex, 
  40.             parentWin,
  41.             ownerWin,
  42.             IRectangle(),
  43.             IWindow::noStyle),
  44.        gbtn101(101, this, this, ID_SET1_FUN1,
  45.                    mapDialogRect(IRectangle(0, 103, 40, 127)),
  46.                    IGraphicPushButton::defaultStyle() | IControl::tabStop),
  47.        gbtn102(102, this, this, ID_SET1_FUN2, 
  48.                    mapDialogRect(IRectangle(41, 103, 81, 127)),
  49.                    IGraphicPushButton::defaultStyle()  | IControl::tabStop),
  50.        gbtn103(103, this, this, ID_SET1_FUN3, 
  51.                    mapDialogRect(IRectangle(0, 78, 40, 102)),
  52.                    IGraphicPushButton::defaultStyle()  | IControl::tabStop),
  53.        gbtn104(104, this, this, ID_SET1_FUN4, 
  54.                    mapDialogRect(IRectangle(41, 78, 81, 102)),
  55.                    IGraphicPushButton::defaultStyle()  | IControl::tabStop),
  56.        gbtn105(105, this, this, ID_SET1_FUN5, 
  57.                    mapDialogRect(IRectangle(0, 52, 40, 76)),
  58.                    IGraphicPushButton::defaultStyle()  | IControl::tabStop),
  59.        gbtn106(106, this, this, ID_SET1_FUN6, 
  60.                    mapDialogRect(IRectangle(41, 52, 81, 76)),
  61.                    IGraphicPushButton::defaultStyle()  | IControl::tabStop),
  62.        gbtn107(107, this, this, ID_SET1_FUN7, 
  63.                    mapDialogRect(IRectangle(0, 26, 40, 50)),
  64.                    IGraphicPushButton::defaultStyle()  | IControl::tabStop),
  65.        gbtn108(108, this, this, ID_SET1_FUN8, 
  66.                    mapDialogRect(IRectangle(41, 26, 81, 50)),
  67.                    IGraphicPushButton::defaultStyle()  | IControl::tabStop),
  68.        edt109(109, this, this, 
  69.                    mapDialogRect(IRectangle(3, 130, 80, 142)),
  70.                    IEntryField::defaultStyle()  | IEntryField::readOnly),
  71.        txt110(110, this, this, 
  72.                    mapDialogRect(IRectangle(7, 9, 77, 17)),
  73.                    IStaticText::defaultStyle()  | IStaticText::top  |
  74.                          IStaticText::left),
  75.        grp112(112, this, this, 
  76.                    mapDialogRect(IRectangle(1, 3, 82, 27)),
  77.                    IGroupBox::defaultStyle())
  78. {
  79.     nPageIndex = nIndex;
  80.  
  81.     // ---------------------------------------------------------------------
  82.       // Save pointer to SomActions class
  83.     // ---------------------------------------------------------------------
  84.  
  85.     somAct= somAction;
  86.  
  87.     
  88.     // ---------------------------------------------------------------------
  89.     //  Handle command events so that pushbuttons can cause events
  90.     // ---------------------------------------------------------------------
  91.     
  92.       ICommandHandler::handleEventsFor(this);
  93.   
  94.     // ---------------------------------------------------------------------
  95.     // translate the dialog rectange to size approviate for system font
  96.     // ---------------------------------------------------------------------
  97.  
  98.       IRectangle sizeRect(82, 144);
  99.       sizeTo(mapDialogRect(sizeRect).size());
  100.   
  101.     // ---------------------------------------------------------------------
  102.       // setup all controls in dialog
  103.     // ---------------------------------------------------------------------
  104.  
  105.       setupControls();
  106. }                             
  107.  
  108. // ------------------------------------------------------------------------
  109. //  Class:                DialogPage
  110. //  Function:            mapDialogRect
  111. //                
  112. //  Description:        translates dialog units to pels
  113. //       
  114. //  Input:                IRectangle &oldRect
  115. //
  116. //  Output:                IRectangle
  117. //
  118. //  Notes:
  119. //
  120. // ------------------------------------------------------------------------
  121.  
  122. IRectangle DialogPage::mapDialogRect(const IRectangle &oldRect)
  123. {
  124.       IFont font("System Proportional");
  125.  
  126.     // ---------------------------------------------------------------------
  127.     // create a new rect that for each X dialog unit is equal to average 
  128.     // character width / 4 and for each Y dialog unit is equal to maximum
  129.     // character height / 8
  130.     // ---------------------------------------------------------------------
  131.  
  132.       IRectangle newRect(oldRect.left() * font.avgCharWidth() / 4,
  133.                         oldRect.bottom() * font.maxCharHeight() / 8,
  134.                          oldRect.right() * font.avgCharWidth() / 4,
  135.                          oldRect.top() * font.maxCharHeight() / 8);
  136.  
  137.     // ---------------------------------------------------------------------
  138.     // return the new translated rectange to caller
  139.     // ---------------------------------------------------------------------
  140.  
  141.       return(newRect);
  142. }
  143.  
  144. // ------------------------------------------------------------------------
  145. //  Class:                DialogPage
  146. //  Function:            setupControls
  147. //                
  148. //  Description:        initializes each control and sets approvate values
  149. //       
  150. //  Input:                N/A
  151. //
  152. //  Output:                N/A
  153. //
  154. //  Notes:
  155. //
  156. // ------------------------------------------------------------------------
  157.  
  158. void DialogPage::setupControls()
  159. {
  160.   txt110.setText(STR_FIRST_ACTIONS+nPageIndex);
  161.   refresh();    
  162. }
  163. // ------------------------------------------------------------------------
  164. //  Class:                DialogPage
  165. //  Function:            command
  166. //                
  167. //  Description:        base dialog page command event handler
  168. //       
  169. //  Input:                ICommandEvent &evt
  170. //
  171. //  Output:                Boolean
  172. //
  173. //  Notes:
  174. //
  175. // ------------------------------------------------------------------------
  176.  
  177. Boolean DialogPage::command(ICommandEvent &evt)
  178. {
  179.   return false;
  180. }
  181.  
  182. // ------------------------------------------------------------------------
  183. //  Class:                DialogPage
  184. //  Function:            setStatusEntry
  185. //                
  186. //  Description:        set up readonly status entry
  187. //       
  188. //  Input:                unsigned long resId - resource id
  189. //
  190. //  Output:                N/A
  191. //
  192. //  Notes:
  193. //
  194. // ------------------------------------------------------------------------
  195.  
  196.  
  197. void DialogPage::setStatusEntry(unsigned long resId)
  198. {
  199.     edt109.setText(resId);
  200. }
  201.  
  202.  
  203. // ------------------------------------------------------------------------
  204. //  Class:                DialogPage
  205. //  Function:            pageAction
  206. //                
  207. //  Description:        handle Page action for this page
  208. //       
  209. //  Input:                unsigned long ulAction - action
  210. //
  211. //  Output:                N/A
  212. //
  213. //  Notes:
  214. //
  215. // ------------------------------------------------------------------------
  216.  
  217. void DialogPage::pageAction(unsigned long ulAction)
  218. {
  219.     somAct->Process(nPageIndex,ulAction); 
  220. }
  221.  
  222. // ------------------------------------------------------------------------
  223. //  Class:                Set1Page
  224. //  Function:            Set1Page (constructor)
  225. //                
  226. //  Description:        This is the contructor for Set #1 dialog Page
  227. //       
  228. //  Input:                IWindow *parentWin - parent window
  229. //                            IWindow *ownerWin  - owner window
  230. //                            SomAction *somAction    - pointer to SomActions class
  231. //
  232. //  Output:                N/A
  233. //
  234. //  Notes:
  235. //
  236. // ------------------------------------------------------------------------
  237.  
  238. Set1Page::Set1Page(IWindow *parentWin,
  239.                          IWindow *ownerWin,
  240.                          SomAction *somAction)    
  241.     : DialogPage(parentWin,ownerWin,0,somAction)
  242. {
  243. }
  244.  
  245. // ------------------------------------------------------------------------
  246. //  Class:                Set1Page
  247. //  Function:            command
  248. //                
  249. //  Description:        Set #1 dialog page command event handler
  250. //       
  251. //  Input:                ICommandEvent &evt
  252. //
  253. //  Output:                Boolean
  254. //
  255. //  Notes:
  256. //
  257. // ------------------------------------------------------------------------
  258.  
  259. Boolean Set1Page::command(ICommandEvent &evt)
  260. {
  261.   unsigned long cmdId = evt.commandId();    
  262.  
  263.   switch(cmdId)
  264.   {
  265.     case 101:  // selected Push
  266.     case 102:  // selected Push
  267.     case 103:  // selected Push
  268.     case 104:  // selected Push
  269.     case 105:  // selected Push
  270.     case 106:  // selected Push
  271.     case 107:  // selected Push
  272.     case 108:  // selected Push
  273.     {
  274.           unsigned long resId = (cmdId - 101) + STR_SET1_FUN1;        
  275.  
  276.         setStatusEntry(resId);
  277.         pageAction(cmdId - 101);
  278.       break;
  279.     }
  280.      
  281.     default:
  282.         return false;
  283.   }
  284.   return true;
  285. }
  286.  
  287. // ------------------------------------------------------------------------
  288. //  Class:                Set2Page
  289. //  Function:            Set2Page (constructor)
  290. //                
  291. //  Description:        This is the contructor for Set #2 dialog Page
  292. //       
  293. //  Input:                IWindow *parentWin - parent window
  294. //                            IWindow *ownerWin  - owner window
  295. //                            SomAction *somAction    - pointer to SomActions class
  296. //
  297. //  Output:                N/A
  298. //
  299. //  Notes:
  300. //
  301. // ------------------------------------------------------------------------
  302.  
  303. Set2Page::Set2Page(IWindow *parentWin,
  304.                          IWindow *ownerWin,
  305.                          SomAction *somAction)    
  306.     : DialogPage(parentWin,ownerWin,1,somAction)
  307. {
  308. }
  309.  
  310. // ------------------------------------------------------------------------
  311. //  Class:                Set2Page
  312. //  Function:            command
  313. //                
  314. //  Description:        Set #2 dialog page command event handler
  315. //       
  316. //  Input:                ICommandEvent &evt
  317. //
  318. //  Output:                Boolean
  319. //
  320. //  Notes:
  321. //
  322. // ------------------------------------------------------------------------
  323.  
  324. Boolean Set2Page::command(ICommandEvent &evt)
  325. {
  326.   unsigned long cmdId = evt.commandId();    
  327.  
  328.   switch(cmdId)
  329.   {
  330.     case 101:  // selected Push
  331.     case 102:  // selected Push
  332.     case 103:  // selected Push
  333.     case 104:  // selected Push
  334.     case 105:  // selected Push
  335.     case 106:  // selected Push
  336.     case 107:  // selected Push
  337.     case 108:  // selected Push
  338.     {
  339.           unsigned long resId = (cmdId - 101) + STR_SET2_FUN1;        
  340.  
  341.         setStatusEntry(resId);
  342.         pageAction(cmdId - 101);
  343.       break;
  344.     }
  345.      
  346.     default:
  347.         return false;
  348.   }
  349.   return true;
  350. }
  351.  
  352.  
  353.  
  354. // ------------------------------------------------------------------------
  355. //  Class:                Set3Page
  356. //  Function:            Set3Page (constructor)
  357. //                
  358. //  Description:        This is the contructor for Set #3 dialog Page
  359. //       
  360. //  Input:                IWindow *parentWin - parent window
  361. //                            IWindow *ownerWin  - owner window
  362. //                            SomAction *somAction    - pointer to SomActions class
  363. //
  364. //  Output:                N/A
  365. //
  366. //  Notes:
  367. //
  368. // ------------------------------------------------------------------------
  369.  
  370. Set3Page::Set3Page(IWindow *parentWin,
  371.                          IWindow *ownerWin,
  372.                          SomAction *somAction)    
  373.     : DialogPage(parentWin,ownerWin,2,somAction)
  374. {
  375. }
  376.  
  377. // ------------------------------------------------------------------------
  378. //  Class:                Set3Page
  379. //  Function:            command
  380. //                
  381. //  Description:        Set #3 dialog page command event handler
  382. //       
  383. //  Input:                ICommandEvent &evt
  384. //
  385. //  Output:                Boolean
  386. //
  387. //  Notes:
  388. //
  389. // ------------------------------------------------------------------------
  390.  
  391. Boolean Set3Page::command(ICommandEvent &evt)
  392. {
  393.   unsigned long cmdId = evt.commandId();    
  394.  
  395.   switch(cmdId)
  396.   {
  397.     case 101:  // selected Push
  398.     case 102:  // selected Push
  399.     case 103:  // selected Push
  400.     case 104:  // selected Push
  401.     case 105:  // selected Push
  402.     case 106:  // selected Push
  403.     case 107:  // selected Push
  404.     case 108:  // selected Push
  405.     {
  406.           unsigned long resId = (cmdId - 101) + STR_SET3_FUN1;        
  407.  
  408.         setStatusEntry(resId);
  409.         pageAction(cmdId - 101);
  410.       break;
  411.     }
  412.     
  413.     default:
  414.         return false;
  415.   }
  416.   return true;
  417. }
  418.  
  419. // ------------------------------------------------------------------------
  420. //  Class:                Set4Page
  421. //  Function:            Set4Page (constructor)
  422. //                
  423. //  Description:        This is the contructor for Set #4 dialog Page
  424. //       
  425. //  Input:                IWindow *parentWin - parent window
  426. //                            IWindow *ownerWin  - owner window
  427. //                            SomAction *somAction    - pointer to SomActions class
  428. //
  429. //  Output:                N/A
  430. //
  431. //  Notes:
  432. //
  433. // ------------------------------------------------------------------------
  434.  
  435. Set4Page::Set4Page(IWindow *parentWin,
  436.                          IWindow *ownerWin,
  437.                          SomAction *somAction)    
  438.     : DialogPage(parentWin,ownerWin,3,somAction)
  439. {
  440. }
  441.  
  442.  
  443. // ------------------------------------------------------------------------
  444. //  Class:                Set4Page
  445. //  Function:            command
  446. //                
  447. //  Description:        Set #4 dialog page command event handler
  448. //       
  449. //  Input:                ICommandEvent &evt
  450. //
  451. //  Output:                Boolean
  452. //
  453. //  Notes:
  454. //
  455. // ------------------------------------------------------------------------
  456.  
  457. Boolean Set4Page::command(ICommandEvent &evt)
  458. {
  459.   unsigned long cmdId = evt.commandId();    
  460.  
  461.   switch(cmdId)
  462.   {
  463.     case 101:  // selected Push
  464.     case 102:  // selected Push
  465.     case 103:  // selected Push
  466.     case 104:  // selected Push
  467.     case 105:  // selected Push
  468.     case 106:  // selected Push
  469.     case 107:  // selected Push
  470.     case 108:  // selected Push
  471.     {
  472.           unsigned long resId = (cmdId - 101) + STR_SET4_FUN1;        
  473.  
  474.         setStatusEntry(resId);
  475.         pageAction(cmdId - 101);
  476.       break;
  477.     }
  478.      
  479.     default:
  480.         return false;
  481.   }
  482.   return true;
  483. }
  484.  
  485.