home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v5.zip / TOOLKT21 / CPLUS / SAMPLES / WPCAR / CARPP.CSC < prev    next >
Text File  |  1993-04-30  |  21KB  |  643 lines

  1. /******************************************************************************
  2. *
  3. *  Module Name: CARPP
  4. *
  5. *  OS/2 Work Place Shell Sample Program
  6. *
  7. *  Copyright (C) 1992 IBM Corporation
  8. *
  9. *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  10. *      sample code created by IBM Corporation. This sample code is not
  11. *      part of any standard or IBM product and is provided to you solely
  12. *      for  the purpose of assisting you in the development of your
  13. *      applications.  The code is provided "AS IS", without
  14. *      warranty of any kind.  IBM shall not be liable for any damages
  15. *      arising out of your use of the sample code, even if they have been
  16. *      advised of the possibility of such damages.                                                    *
  17. *
  18. ******************************************************************************/
  19.  
  20. ###   Note: The header preceding this comment will be emitted in all files.
  21. ###
  22. ###         Any comments to go public should be preceded with '--'
  23. ###         Any comments to remain private should be preceded with '#'
  24.  
  25. #******************************************************************************
  26. #   Include the class definition file for the parent class
  27. #******************************************************************************
  28.  
  29. include <wpdataf.sc>
  30.  
  31. #******************************************************************************
  32. #   Define the new class
  33. #******************************************************************************
  34.  
  35. class: Carpp,
  36.        external stem   = carpp,
  37.        local,
  38.        external prefix = carpp_,
  39.        classprefix     = carppM_,
  40.        major version   = 1,
  41.        minor version   = 2;
  42.  
  43. --
  44. -- CLASS: Carpp
  45. --
  46. -- CLASS HIERARCHY:
  47. --
  48. --     SOMObject
  49. --       └── WPObject
  50. --             └── WPFileSystem
  51. --                   └── WPDataFile
  52. --                         └──  Carpp
  53. --
  54. -- DESCRIPTION:
  55. --
  56. --    This is the sample car object class.
  57. --
  58. --    An instance of this class can be created as a Workplace object.
  59. --
  60.  
  61. #******************************************************************************
  62. #   Specify the parent class
  63. #******************************************************************************
  64.  
  65. parent: WPDataFile;
  66.  
  67. #******************************************************************************
  68. #   Specify the release order of new methods.  This ensures binary
  69. #   compatability if we change the order of our methods in .c and .csc files.
  70. #******************************************************************************
  71.  
  72. release order:
  73.               AddDashboardPage,
  74.               AddHornBeepPage,
  75.               clsQueryModuleHandle,
  76.               TrapTest;
  77.  
  78. #******************************************************************************
  79. #   Passthru IMPLEMENTATION definitions to the .xih file - BEFORE
  80. #******************************************************************************
  81.  
  82. passthru: C.xih, before;
  83.  
  84.    #define INCL_WIN
  85.    #define INCL_DOS
  86.    #define INCL_GPIBITMAPS
  87.    #define INCL_DOSERRORS
  88.    #include <os2.h>
  89.  
  90.    #define INCL_WPCLASS
  91.    #define INCL_WPFOLDER
  92.    #include <pmwp.h>
  93.  
  94.    #define ID_TITLE              100
  95.    #define ID_ICON               101 
  96.  
  97.    #define IDD_DASHBOARD         200                   /* settings page (dialog) */
  98.    #define IDD_HORNBEEP          202 
  99.  
  100.    /*
  101.     *   The following user-defined Popup menu items (ID_xxx) should be higher
  102.     *   than WPMENUID_USER.
  103.     *
  104.     *   The ID_OPENMENU will become a submenu of the system's popup open menu
  105.     *   id, WPMENUID_OPEN.
  106.     */
  107.    #define ID_BEEPMENU          (WPMENUID_USER+1)  /* menus added to popup menu */
  108.    #define ID_OPENMENU          (WPMENUID_USER+2) 
  109.    #define ID_TRAPMENU          (WPMENUID_USER+3) 
  110.  
  111.    #define IDM_OPENCAR          (WPMENUID_USER+4)  /* submenus of added menus */
  112.    #define IDM_BEEPHORN         (WPMENUID_USER+5) 
  113.    #define IDM_TRAPCAR          (WPMENUID_USER+6) 
  114.  
  115.    #define IDMSG_ACCESS_VIOLATION    100 
  116.    #define IDM_MSGBOX                999
  117.  
  118.    #define ID_FRAME                  3000                        /* client window id */
  119.    #define ID_CLIENT                 3001                        /* client window id */
  120.  
  121.    /*
  122.     *   Set unique view ids.
  123.     */
  124.    #define OPEN_CAR             ID_OPENMENU 
  125.  
  126.    #define CAR_TIMER            1001                               /* timer id */ 
  127.  
  128.    /*
  129.     *   IDs of dialog items in CARPP.RC
  130.     */
  131.    #define ID_UNDO                  801 
  132.    #define ID_DEFAULT               802 
  133.    #define ID_HELP                  803 
  134.    #define ID_HITONE                804 
  135.    #define ID_LOTONE                805
  136.    #define ID_SPEEDSLIDER           806
  137.    #define ID_STOP                  807
  138.    #define ID_SPEEDDATA             808
  139.    #define ID_GO                    809 
  140.  
  141.    /*
  142.     *  Keys for save-restore methods
  143.     */
  144.    #define IDKEY_HITONE            1 
  145.    #define IDKEY_LOTONE            2 
  146.    #define IDKEY_DURATION          3
  147.    #define IDKEY_RPM               4
  148.    #define IDKEY_BRAKEFLAG         5
  149.  
  150.    /*
  151.     *   Default values of instance data items
  152.     */
  153.    #define DEFAULT_DURATION          300
  154.    #define DEFAULT_HITONE            400 
  155.    #define DEFAULT_LOTONE            400 
  156.    #define DEFAULT_RPM               50
  157.    #define DEFAULT_BRAKEFLAG         FALSE
  158.  
  159.    /*
  160.     *   Help IDs
  161.     *
  162.     *   NOTE:  At this time, no source file is provided to build help for this
  163.     *   sample.  A pre-built help file, CAR.HLP, is provided containing the
  164.     *   following help ids.
  165.     */
  166.    #define ID_HELP_DEFAULT        256 
  167.    #define ID_HELP_DASHBOARD      257
  168.    #define ID_HELP_OPENCAR        258 
  169.    #define ID_HELP_HORNBEEP       259 
  170.    #define ID_HELP_BEEPHORN       260 
  171.  
  172.    /*
  173.     *   Indexes into CARDETAILS information. (arrays)
  174.     */
  175.    #define  INDEX_MAKE               0 
  176.    #define  INDEX_MODEL              1 
  177.    #define  INDEX_COLOR              2 
  178.    #define  INDEX_SALE_DATE          3
  179.    #define  INDEX_PRICE              4 
  180.  
  181.    /*
  182.     *   These defines are used as directional multipliers against x,y position.
  183.     */
  184.    #define CAR_LEFT       -1 
  185.    #define CAR_RIGHT       1 
  186.    #define CAR_DOWN       -1
  187.    #define CAR_UP          1 
  188.  
  189.    #define ICON_WIDTH     32      /* pels */
  190.    #define ICON_HEIGHT    32      /* pels */
  191.  
  192. endpassthru;   /* .xih after */
  193.  
  194. #******************************************************************************
  195. #   Passthru IMPLEMENTATION definitions to the .xih file - AFTER
  196. #******************************************************************************
  197.  
  198. passthru: C.xih, after;
  199.  
  200.    /*********************************************************************/
  201.    /* Include the header files for the components of the car                                    */
  202.    /*********************************************************************/
  203.  
  204.    #include "horn.h"
  205.    #include "brake.h"
  206.    #include "rpm.h"
  207.  
  208.    /*
  209.     *   CARDETAILS:  Structure used for details view
  210.     */
  211.    typedef struct _CARDETAILS
  212.    {
  213.       PSZ     pszMake;     /* Manufacturer      */
  214.       PSZ     pszModel;    /* Model             */
  215.       PSZ     pszColor;    /* Color of car      */
  216.       CDATE   cdateSale;   /* Date of sale      */
  217.       ULONG   ulPrice;     /* Price in dollars  */
  218.    } CARDETAILS;
  219.    typedef CARDETAILS *PCARDETAILS;
  220.  
  221.    /*
  222.     *   The following structures will be used to store window specific data
  223.     *   and a pointer to the object that created the window/dialog.
  224.     *
  225.     *   They're allocated when the Client window is created.  This
  226.     *   allows us to pass the *somSelf pointer and use it in our
  227.     *   window and dialog procedures (the system only passes this
  228.     *   pointer to methods).
  229.     */
  230.    typedef struct _WINDOWDATA
  231.    {
  232.       USHORT   cb;            /* size of this structure */
  233.       Carpp     *somSelf;       /* pointer to this instance */
  234.       USEITEM  UseItem;       /* global class usage information */
  235.       VIEWITEM ViewItem;      /* global class view information */
  236.       LONG     x;             /* x position of car in open view */
  237.       LONG     y;             /* y position of car in open view */
  238.       LONG     xDir;          /* x direction (CAR_LEFT or CAR_RIGHT) */
  239.       LONG     yDir;          /* y direction (CAR_UP or CAR_DOWN) */
  240.    } WINDOWDATA;
  241.    typedef WINDOWDATA *PWINDOWDATA;
  242.  
  243.    /*
  244.     *   Window data for the Dashboard dialog (settings page)
  245.     */
  246.    typedef struct _DASHDLGDATA
  247.    {
  248.       USHORT   cb;            /* size of this structure */
  249.       Carpp    *somSelf;        /* pointer to this instance         */
  250.       BOOL    PrevBrakes;     /* indicates if car is stopped      */
  251.       ULONG   PrevSpeed;      /* Speed car moves across screen    */
  252.    } DASHDLGDATA;
  253.    typedef DASHDLGDATA *PDASHDLGDATA;
  254.  
  255.    /*
  256.     *   Window data for the Horn dialog (settings page)
  257.     */
  258.    typedef struct _HORNDLGDATA
  259.    {
  260.       USHORT   cb;            /* size of this structure */
  261.       Carpp    *somSelf;        /* pointer to this instance         */
  262.       ULONG   PrevDuration;   /* Duration of the car's horn beep  */
  263.       ULONG   PrevHighTone;   /* The high note of the car beep    */
  264.       ULONG   PrevLowTone;    /* The low note of the car beep     */
  265.    } HORNDLGDATA;
  266.    typedef HORNDLGDATA *PHORNDLGDATA;
  267.  
  268.    /*
  269.     *   Private Debug helpers go here.  They can be enabled/disabled by
  270.     *   defining DEBUG as a compiler directive.
  271.     */
  272.    #if defined(DEBUG)
  273.  
  274.       #define DebugBox(title, text) \
  275.                                     \
  276.                  WinMessageBox(     \
  277.                     HWND_DESKTOP,   \
  278.                     HWND_DESKTOP,   \
  279.                     (PSZ) text,     \
  280.                     (PSZ) title,    \
  281.                     20,             \
  282.                     MB_OK | MB_INFORMATION | MB_MOVEABLE)
  283.    #else
  284.       #define DebugBox(title, text)   /* do nothing if not debugging */
  285.    #endif
  286.  
  287. endpassthru;   /* .xih after */
  288.  
  289. #******************************************************************************
  290. #   Define instance data
  291. #******************************************************************************
  292.  
  293. data:
  294.  
  295.    Brake     *carBrake;                      
  296.    Horn      *carHorn;                      
  297.    RPM       *carRPM;                      
  298.  
  299. #******************************************************************************
  300. #   Define methods
  301. #******************************************************************************
  302.  
  303. methods:
  304.  
  305. ULONG AddDashboardPage (HWND hwndNotebook);
  306. --
  307. -- METHOD: AddDashboardPage                               ( ) PRIVATE
  308. --                                                        (X) PUBLIC
  309. -- DESCRIPTION:
  310. --
  311. --   This method adds the dashboard page to the settings notebook.
  312. --
  313. -- RETURN:
  314. --
  315. --   0              Unsuccessful
  316. --   ulPageId       Identifier for the inserted page
  317. --
  318. -- HOW TO OVERRIDE:
  319. --
  320. --   Method should always be overridden in order to replace or remove
  321. --   the dashboard page from an object which is a descendent of Car.
  322. --   In most cases, an override of this method will not call the parent.
  323. --
  324.  
  325.  
  326. ULONG AddHornBeepPage (HWND hwndNotebook);
  327. --
  328. -- METHOD: AddHornBeepPage                                ( ) PRIVATE
  329. --                                                        (X) PUBLIC
  330. -- DESCRIPTION:
  331. --
  332. --   This method adds the horn beep page to the settings
  333. --   notebook.
  334. --
  335. -- RETURN:
  336. --
  337. --   0              Unsuccessful
  338. --   ulPageId       Identifier for the inserted page
  339. --
  340. -- HOW TO OVERRIDE:
  341. --
  342. --   Method should always be overridden in order to replace or remove
  343. --   the horn beep page from an object which is a descendent of Car.
  344. --   In most cases, an override of this method will not call the parent.
  345. --
  346.  
  347.  
  348. VOID TrapTest ();
  349. --
  350. -- METHOD: AddHornBeepPage                                ( ) PRIVATE
  351. --                                                        (X) PUBLIC
  352. -- DESCRIPTION:
  353. --
  354. --   This method tests the exception handling in this sample.
  355. --
  356. -- RETURN:
  357. --
  358. --   nothing
  359. --
  360. -- HOW TO OVERRIDE:
  361. --
  362. --   n/a
  363. --
  364.  
  365.  
  366. #******************************************************************************
  367. #   Specify methods being overridden
  368. #******************************************************************************
  369.  
  370. -----------------------------------------------------------------------------
  371. --   Methods from the WPObject class
  372. -----------------------------------------------------------------------------
  373.  
  374. override wpInitData;
  375. --
  376. -- OVERRIDE: wpInitData                                   ( ) PRIVATE
  377. --                                                        (X) PUBLIC
  378. -- DESCRIPTION:
  379. --
  380. --   Initialize our state variables. Allocate any extra memory that
  381. --   we might need.
  382. --
  383.  
  384. override wpUnInitData;
  385. --
  386. -- OVERRIDE: wpUnInitData                                 ( ) PRIVATE
  387. --                                                        (X) PUBLIC
  388. -- DESCRIPTION:
  389. --
  390. --   Clear up memory that was allocated on wpInitData.
  391. --
  392.  
  393. override wpSaveState;
  394. --
  395. -- METHOD: wpSaveState                                    ( ) PRIVATE
  396. --                                                        (X) PUBLIC
  397. -- DESCRIPTION:
  398. --
  399. --   Save our state variables (pitch and duration).
  400. --
  401.  
  402. override wpRestoreState;
  403. --
  404. -- METHOD: wpRestoreState                                 ( ) PRIVATE
  405. --                                                        (X) PUBLIC
  406. -- DESCRIPTION:
  407. --
  408. --   Retrieve our saved state variables (pitch and duration).
  409. --
  410.  
  411. override wpAddSettingsPages;
  412. --
  413. -- METHOD: wpAddSettingsPages                             ( ) PRIVATE
  414. --                                                        (X) PUBLIC
  415. -- DESCRIPTION:
  416. --
  417. --   Add our own settings page to let the user alter the pitch
  418. --   and duration of the car's beep.
  419. --
  420.  
  421. override wpFilterPopupMenu;
  422. --
  423. -- METHOD: wpFilterPopupMenu                              ( ) PRIVATE
  424. --                                                        (X) PUBLIC
  425. -- DESCRIPTION:
  426. --
  427. --   Filter out any options from the context that don't apply.
  428. --
  429. -- HOW TO OVERRIDE:
  430. --
  431. --   No restrictions.
  432. --
  433.  
  434. override wpModifyPopupMenu;
  435. --
  436. -- METHOD: wpModifyPopupMenu                              ( ) PRIVATE
  437. --                                                        (X) PUBLIC
  438. -- DESCRIPTION:
  439. --
  440. --   Add our extra option to the context menu to beep the horn
  441. --
  442.  
  443. override wpMenuItemSelected;
  444. --
  445. -- METHOD: wpMenuItemSelected                             ( ) PRIVATE
  446. --                                                        (X) PUBLIC
  447. -- DESCRIPTION:
  448. --
  449. --   Process input from the extra menu option that we added.
  450. --
  451.  
  452. override wpMenuItemHelpSelected;
  453. --
  454. -- METHOD: wpMenuItemHelpSelected                         ( ) PRIVATE
  455. --                                                        (X) PUBLIC
  456. -- DESCRIPTION:
  457. --
  458. --   Process input from the extra menu option that we added.
  459. --
  460.  
  461. override wpQueryDetailsData;
  462. --
  463. -- METHOD: wpQueryDetailsData                             ( ) PRIVATE
  464. --                                                        (X) PUBLIC
  465. -- DESCRIPTION:
  466. --
  467. --   Returns the car specific data for the details view of this object.
  468. --   Sets the pointer (*ppDetailsData) to the beginning of the buffer
  469. --   into which the data is written.
  470. --
  471.  
  472. override wpOpen;
  473. --
  474. --  METHOD: wpOpen                                         ( ) PRIVATE
  475. --                                                         (X) PUBLIC
  476. --  DESCRIPTION:
  477. --
  478. --    Opens the car window.
  479. --
  480.  
  481. override wpSetup;
  482. --
  483. -- METHOD: wpSetup                                        ( ) PRIVATE
  484. --                                                        (X) PUBLIC
  485. -- DESCRIPTION:
  486. --
  487. --   Specify Setup strings and do some initialization.  This method is
  488. --   invoked once an object is completely created.
  489. --
  490.  
  491. #******************************************************************************
  492. #   Define class methods
  493. #******************************************************************************
  494.  
  495. HMODULE  clsQueryModuleHandle (), class;
  496. --
  497. -- METHOD: clsQueryModuleHandle                           ( ) PRIVATE
  498. --                                                        (X) PUBLIC
  499. -- DESCRIPTION:
  500. --
  501. --   This method returns the module handle of this class.  If this is the
  502. --   first invocation, DosQueryModuleHandle is called to save the handle
  503. --   for future invocations.
  504. --
  505. -- RETURN:
  506. --
  507. --   0              Unsuccessful
  508. --   non-zero       module handle
  509. --
  510.  
  511. #******************************************************************************
  512. #   Specify class methods being overridden
  513. #******************************************************************************
  514.  
  515. override wpclsInitData, class;
  516. --
  517. -- METHOD: wpclsInitData
  518. --
  519. -- DESCRIPTION:
  520. --
  521. --   Initalize the class data
  522. --
  523.  
  524. override wpclsUnInitData, class;
  525. --
  526. -- METHOD: wpclsUnInitData
  527. --
  528. -- DESCRIPTION:
  529. --
  530. --   Free any class data
  531. --
  532.  
  533. override wpclsQueryTitle, class;
  534. --
  535. -- METHOD: wpclsQueryTitle                                ( ) PRIVATE
  536. --                                                        (X) PUBLIC
  537. -- DESCRIPTION:
  538. --
  539. --   Return the string "New car".
  540. --
  541.  
  542. override wpclsQueryIconData, class;
  543. --
  544. -- METHOD: wpclsQueryIconDdata                            ( ) PRIVATE
  545. --                                                        (X) PUBLIC
  546. -- DESCRIPTION:
  547. --
  548. --   Return the class icon
  549. --
  550.  
  551. override wpclsQueryDefaultHelp, class;
  552. --
  553. -- METHOD: wpclsQueryDefaultHelp                          ( ) PRIVATE
  554. --                                                        (X) PUBLIC
  555. -- DESCRIPTION:
  556. --
  557. --   Process input from the extra menu option that we added.
  558. --
  559.  
  560. override wpclsQueryDefaultView, class;
  561. --
  562. -- METHOD: wpclsQueryDefaultView                          ( ) PRIVATE
  563. --                                                        (X) PUBLIC
  564. -- DESCRIPTION:
  565. --
  566. --   Returns the default view for a new instance of this object.
  567. --
  568. -- REMARKS:
  569. --
  570. --   Tell the system what our default open view is...
  571. --
  572.  
  573. override wpclsQueryDetailsInfo, class;
  574. --
  575. -- METHOD: wpclsQueryDetailsInfo                          ( ) PRIVATE
  576. --                                                        (X) PUBLIC
  577. -- DESCRIPTION:
  578. --
  579. --   Appends the car specific chain of FIELDINFO structures describing the
  580. --   details data of this object to *ppDetailsData (if ppDetailsData
  581. --   is NON-NULL).  In this case it also sets *ppDetailsData to the
  582. --   head of the linked list.
  583. --
  584. --   Adds the number of bytes required by the details data for car to *pSize
  585. --   (if pSize is NON-NULL).
  586. --
  587. -- REMARKS:
  588. --
  589. --   Add details data for this object.
  590. --
  591.  
  592.     -- From WPFileSystem
  593.  
  594. override wpclsQueryDetails, class;
  595. --
  596. -- METHOD: wpclsQueryDetails                              ( ) PRIVATE
  597. --                                                        (X) PUBLIC
  598. -- DESCRIPTION:
  599. --
  600. --    Specify default details to display in details view
  601. --
  602. -- REMARKS:
  603. --
  604. --    A pointer details structure is modified and returned.
  605. --    Note: this is purely virtual at the moment (parent class doesn't
  606. --    do anything).
  607. --
  608.  
  609. override wpclsQueryInstanceFilter, class;
  610. --
  611. -- METHOD: wpclsQueryInstanceFilter                       ( ) PRIVATE
  612. --                                                        (X) PUBLIC
  613. -- DESCRIPTION:
  614. --
  615. --    The wpclsQueryInstanceFilter method is called to allow the class
  616. --    object to specify the file title filters for instances of its
  617. --    class.
  618. --
  619. -- REMARKS:
  620. --
  621. --    A pointer to a string containing file title filter(s).  This
  622. --    string can contain several file title filters separated by a
  623. --    comma.  Example: "*.TXT, *.DOC"
  624. --
  625.  
  626. override wpclsQueryStyle, class;
  627. --
  628. -- METHOD: wpclsQueryStyle                                ( ) PRIVATE
  629. --                                                        (X) PUBLIC
  630. -- DESCRIPTION:
  631. --
  632. --    The wpclsQueryStyle method is called to allow the class object
  633. --    to specify the default object class style for its instances.
  634. --
  635. -- REMARKS:
  636. --
  637. --    This method can be called at any time in order to determine the
  638. --    default style for instances of this class.
  639. --
  640. --    This method should be overridden in order to modify the default
  641. --    object style for instances of this class.
  642. --
  643.