home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / lancelot / ltimepie.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  8.1 KB  |  190 lines

  1. /******************************************************************************
  2. * .FILE:         ltimepie.hpp                                                 *
  3. *                                                                             *
  4. * .DESCRIPTION:  Lancelot Sample Program:              Class Definition       *
  5. *                                                                             *
  6. * .CLASSES:      LTimeCardPieChart                                            *
  7. *                LPieChartResizeHandler                                       *
  8. *                TaskElement                                                  *
  9. *                                                                             *
  10. * .COPYRIGHT:                                                                 *
  11. *    Licensed Material - Program-Property of IBM                              *
  12. *    (C) Copyright IBM Corp. 1992, 1996 - All Rights Reserved                 *
  13. *                                                                             *
  14. * .DISCLAIMER:                                                                *
  15. *   The following [enclosed] code is sample code created by IBM               *
  16. *   Corporation.  This sample code is not part of any standard IBM product    *
  17. *   and is provided to you solely for the purpose of assisting you in the     *
  18. *   development of your applications.  The code is provided 'AS IS',          *
  19. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  20. *   arising out of your use of the sample code, even if they have been        *
  21. *   advised of the possibility of such damages.                               *
  22. *                                                                             *
  23. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  24. *                                                                             *
  25. ******************************************************************************/
  26. #include "ltimec.hpp"
  27. #ifndef _LTIMEPIE_
  28. #define _LTIMEPIE_
  29.  
  30. #include <igpie.hpp>
  31. #include <igrect.hpp>
  32. #include <igstring.hpp>
  33. #include <imcelcv.hpp>
  34. #include <iglist.hpp>
  35. #include <idrawcv.hpp>
  36. #include <isizehdr.hpp>
  37. #include <ikeyset.h>
  38. #include <istring.hpp>
  39. #include <ifont.hpp>
  40. #include "lancelot.h"
  41.  
  42. class LTimeCardPieChart;
  43.  
  44. /******************************************************************************
  45. * Class TaskElement - Collection element with task name and hours.            *
  46. ******************************************************************************/
  47. class TaskElement : public IBase
  48. {
  49.    public:
  50. /*------------------------ Constructors/Destructor ----------------------------
  51. | Construct the object in only one way:                                       |
  52. | 1) Task name and hours worked for the task.                                 |
  53. -----------------------------------------------------------------------------*/
  54.       TaskElement( IString theTask, unsigned short theHours )
  55.            :aTask( theTask ), aHours( theHours ) {};
  56.  
  57. /*------------------------------- Accessors -----------------------------------
  58. | These functions provide a means of getting and setting the accessible       |
  59. | attributes of instances of this class:                                      |
  60. |   task                - Returns the task name                               |
  61. |   hours               - Returns the task hours                              |
  62. -----------------------------------------------------------------------------*/
  63.       IString const
  64.          &task() const { return aTask; };
  65.  
  66.       unsigned short const
  67.          &hours() const { return aHours; };
  68.  
  69. /*------------------------------- Operators -----------------------------------
  70. | Arithmetic and comparative operations for instances of this class:          |
  71. |   ==                  - Compares two TaskElements for equality              |
  72. -----------------------------------------------------------------------------*/
  73.       Boolean
  74.          operator == (TaskElement const& k) const { return aTask == k.aTask; };
  75.  
  76.    private:
  77.       IString
  78.          aTask;
  79.  
  80.       unsigned short
  81.          aHours;
  82. };
  83. /*------------------------------- Accessors -----------------------------------
  84. | These functions provide a means of getting and setting the accessible       |
  85. | attributes of instances of this class:                                      |
  86. |   key                 - Defines and returns the key for a TaskElement       |
  87. -----------------------------------------------------------------------------*/
  88. inline IString const
  89.    &key( TaskElement const& k ) { return k.task(); };
  90.  
  91. typedef
  92.    IKeySet< TaskElement, IString > TaskSet;
  93.  
  94.  
  95. /******************************************************************************
  96. * Class LPieChartResizeHandler - Handle resize events for the pie chart.      *
  97. ******************************************************************************/
  98. class LPieChartResizeHandler : public IResizeHandler
  99. {
  100.    public:
  101. /*------------------------ Constructors/Destructor ----------------------------
  102. | Construct the object in only one way:                                       |
  103. | 1) LTimeCardPieChart                                                        |
  104. -----------------------------------------------------------------------------*/
  105.       LPieChartResizeHandler( LTimeCardPieChart* pie );
  106.  
  107.       virtual ~LPieChartResizeHandler();
  108.  
  109. /*----------------------------- Event Processing ------------------------------
  110. | Handle and process events:                                                  |
  111. |   windowResize        - Process resize events.                              |
  112. -----------------------------------------------------------------------------*/
  113.    protected:
  114.       virtual Boolean
  115.          windowResize( IResizeEvent& event );
  116.  
  117.    private:
  118.       LTimeCardPieChart
  119.         *ppieChart;
  120. };
  121.  
  122.  
  123. /******************************************************************************
  124. * Class LTimeCardPieChart - Timecard pie chart class.                         *
  125. ******************************************************************************/
  126. class LTimeCardPieChart : public IDrawingCanvas
  127. {
  128.    public:
  129. /*------------------------ Constructors/Destructor ----------------------------
  130. | Construct the object in only one way:                                       |
  131. | 1) ResourceId, parent, owner, location, and LTimeCardData.                  |
  132. -----------------------------------------------------------------------------*/
  133.       LTimeCardPieChart( unsigned long windoId,
  134.                          IWindow* parent, IWindow* owner,
  135.                          const IRectangle& location = IRectangle(),
  136.                          LTimeCardData* pTimeData = NULL );
  137.  
  138.      ~LTimeCardPieChart();
  139.  
  140. /*------------------------------- Actions -------------------------------------
  141. | Actions for instances of this class:                                        |
  142. |   resizePieChart      - Resize the pie chart and legend.                    |
  143. |   refreshData         - Refresh the timecard data.                          |
  144. |   drawPie             - Draw the pie chart and legend.                      |
  145. |   calculatePieData    - Pie chart and legend calculations.                  |
  146. -----------------------------------------------------------------------------*/
  147.       LTimeCardPieChart
  148.         &resizePieChart( const ISize& size );
  149.  
  150.       LTimeCardPieChart
  151.         &refreshData( LTimeCardData * tcp ) { pTimeCardData = tcp; return *this; };
  152.  
  153.       LTimeCardPieChart
  154.         &drawPie(),
  155.         &calculatePieData();
  156.  
  157.    private:
  158.       LTimeCardData
  159.         *pTimeCardData;
  160.  
  161.       IGList
  162.          graphList;
  163.  
  164.       LPieChartResizeHandler
  165.          pieChartResizeHandler;
  166.  
  167.       IFont
  168.          legendFont;
  169.  
  170.       IGPie
  171.         *ppieSlice[ ID_TIMECARD_ENTRIES ];
  172.  
  173.       IGRectangle
  174.         *ppieLegendKey[ ID_TIMECARD_ENTRIES ];
  175.  
  176.       IGString
  177.         *ppieLegendKeyText[ ID_TIMECARD_ENTRIES ];
  178.  
  179.       unsigned short
  180.          numberSlices,
  181.          totalHours;
  182.  
  183.       TaskSet
  184.          tasks;
  185.  
  186.       TaskSet::Cursor
  187.          tasksCursor;
  188. };
  189. #endif
  190.