home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / taman002.zip / TASKMANA.ZIP / src / kDlgBase.cpp < prev    next >
C/C++ Source or Header  |  2000-04-29  |  33KB  |  1,066 lines

  1. /* $Id: kDlgBase.cpp,v 1.1 2000/04/29 19:06:34 stknut Exp $
  2.  *
  3.  * kDlgBase (kClassLib) - Base class for all types of dialogs.
  4.  *
  5.  * Copyright (c) 1999-2000 knut st. osmundsen
  6.  *
  7.  */
  8.  
  9.  
  10. /*******************************************************************************
  11. *   Defined Constants And Macros                                               *
  12. *******************************************************************************/
  13. #define INCL_WINDIALOGS
  14. #define INCL_WINERRORS
  15. #define INCL_WINWINDOWMGR
  16. #define INCL_WININPUT
  17. #define INCL_WINSTDCNR
  18. #define INCL_WINTIMER
  19. #define INCL_WINFRAMEMGR
  20. #define INCL_DOSERRORS
  21. #define INCL_DOSRESOURCES
  22.  
  23.  
  24. /*******************************************************************************
  25. *   Header Files                                                               *
  26. *******************************************************************************/
  27. #include <os2.h>
  28. #ifdef USE_KLIB
  29.     #include <kAssert.h>
  30.     #include <kLog.h>
  31.     #include <kHeap.h>
  32. #endif
  33. #include <stdlib.h>
  34. #include <stddef.h>
  35. #include <string.h>
  36. #include <stdarg.h>
  37. #include <stdio.h>
  38.  
  39. #include "kError.h"
  40. #include "kDlgBase.h"
  41.  
  42.  
  43. /*******************************************************************************
  44. *   Internal Functions                                                         *
  45. *******************************************************************************/
  46. static MRESULT _System forwarder(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  47.  
  48.  
  49.  
  50. /*********/
  51. /* stubs */
  52. /*********/
  53. #pragma info(none)
  54. VOID  kDlgBase::cnrBeginEdit(USHORT usId, ULONG cb, HWND hwndCnr, PRECORDCORE pRecord, PFIELDINFO pFieldInfo, PSZ *ppszText, ULONG cbText, ULONG id)
  55. {
  56. }
  57.  
  58. VOID  kDlgBase::cnrCollapseTree(USHORT usId, PRECORDCORE pRecord)
  59. {
  60. }
  61.  
  62. VOID  kDlgBase::cnrContextMenu(USHORT usId, PRECORDCORE pRecord)
  63. {
  64. }
  65.  
  66. ULONG kDlgBase::cnrDragAfter(USHORT usId, PRECORDCORE pRecord, PDRAGINFO pDragInfo)
  67. {
  68.     return 0;
  69. }
  70.  
  71. VOID  kDlgBase::cnrDragLeave(USHORT usId, PRECORDCORE pRecord, PDRAGINFO pDragInfo)
  72. {
  73. }
  74.  
  75. ULONG kDlgBase::cnrDragOver(USHORT usId, PRECORDCORE pRecord, PDRAGINFO pDragInfo)
  76. {
  77.     return 0;
  78. }
  79.  
  80. VOID  kDlgBase::cnrDrop(USHORT usId, PRECORDCORE pRecord, PDRAGINFO pDragInfo)
  81. {
  82. }
  83.  
  84. VOID  kDlgBase::cnrDropNotify(USHORT usId, PRECORDCORE pRecord, PDRAGINFO pDragInfo, HWND hwndTarget)
  85. {
  86. }
  87.  
  88. VOID  kDlgBase::cnrDropHelp(USHORT usId, PRECORDCORE pRecord, PDRAGINFO pDragInfo)
  89. {
  90. }
  91.  
  92. VOID  kDlgBase::cnrEmphasis(USHORT usId, HWND hwndCnr, PRECORDCORE pRecord, ULONG fEmphasisMask)
  93. {
  94. }
  95.  
  96. VOID  kDlgBase::cnrEndEdit(USHORT usId, ULONG cb, HWND hwndCnr, PRECORDCORE pRecord, PFIELDINFO pFieldInfo, PSZ *ppszText, ULONG cbText, ULONG id)
  97. {
  98. }
  99.  
  100. VOID  kDlgBase::cnrEnter(USHORT usId, HWND hwndCnr, PRECORDCORE pRecord, ULONG fKey)
  101. {
  102. }
  103.  
  104. VOID  kDlgBase::cnrExpandTree(USHORT usId, PRECORDCORE pRecord)
  105. {
  106. }
  107.  
  108. VOID  kDlgBase::cnrGridResized(USHORT usId, SHORT sGridRows, SHORT sGridCols)
  109. {
  110. }
  111.  
  112. VOID  kDlgBase::cnrHelp(USHORT usId, PRECORDCORE pRecord)
  113. {
  114. }
  115.  
  116. VOID  kDlgBase::cnrInitDrag(USHORT usId, HWND hwndCnr, PRECORDCORE pRecord, LONG x, LONG y, LONG cx, LONG cy)
  117. {
  118. }
  119.  
  120. VOID  kDlgBase::cnrKillFocus(USHORT usId, HWND hwndCnr)
  121. {
  122. }
  123.  
  124. VOID  kDlgBase::cnrPickup(USHORT usId, HWND hwndCnr, PRECORDCORE pRecord, LONG x, LONG y, LONG cx, LONG cy)
  125. {
  126. }
  127.  
  128. VOID  kDlgBase::cnrQueryDelta(USHORT usId, HWND hwndCnr, ULONG fDelta)
  129. {
  130. }
  131.  
  132. VOID  kDlgBase::cnrReallocPSZ(USHORT usId, ULONG cb, HWND hwndCnr, PRECORDCORE pRecord, PFIELDINFO pFieldInfo, PSZ *ppszText, ULONG cbText, ULONG id)
  133. {
  134. }
  135.  
  136. VOID  kDlgBase::cnrScroll(USHORT usId, HWND hwndCnr, LONG lScrollInc, ULONG fScroll)
  137. {
  138. }
  139.  
  140. VOID  kDlgBase::cnrSetFocus(USHORT usId, HWND hwndCnr)
  141. {
  142. }
  143.  
  144. #pragma info(restore)
  145.  
  146.  
  147.  
  148.  
  149. /**
  150.  * Control message.
  151.  * @param     id             Control id.
  152.  * @param     usNotifyCode   Notification code.
  153.  * @param     ulControlSpec  Controlspecific paramenter.
  154.  */
  155. ULONG kDlgBase::controlIntern(USHORT usId, USHORT usNotifyCode, ULONG ulControlSpec)
  156. {
  157.     char   szClassName[20];
  158.     LONG   cch;
  159.     HWND   hwndCtrl;
  160.     ULONG  ulClassNumber;
  161.     ULONG  ulRet = 0;
  162.  
  163.     hwndCtrl = WinWindowFromID(hwnd, usId);
  164.     if (hwndCtrl != NULLHANDLE
  165.         && (cch = WinQueryClassName(hwndCtrl, sizeof(szClassName), &szClassName[0]))
  166.         && cch > 0 && cch <= 4
  167.         && szClassName[0] == '#'
  168.         && (ulClassNumber = atoi(&szClassName[1])) != 0)
  169.     {
  170.         ulClassNumber |= 0xffff0000L;
  171.         switch (ulClassNumber)
  172.         {
  173.             /* container notification messages */
  174.          #define PSZ ULONG //#define WC_CONTAINER         ((PSZ)0xffff0025L)
  175.             case WC_CONTAINER:
  176.          #undef PSZ
  177.                 switch (usNotifyCode)
  178.                 {
  179.                     case CN_BEGINEDIT:
  180.                         cnrBeginEdit(usId,
  181.                                      ((PCNREDITDATA)ulControlSpec)->cb,
  182.                                      ((PCNREDITDATA)ulControlSpec)->hwndCnr,
  183.                                      ((PCNREDITDATA)ulControlSpec)->pRecord,
  184.                                      ((PCNREDITDATA)ulControlSpec)->pFieldInfo,
  185.                                      ((PCNREDITDATA)ulControlSpec)->ppszText,
  186.                                      ((PCNREDITDATA)ulControlSpec)->cbText,
  187.                                      ((PCNREDITDATA)ulControlSpec)->id);
  188.                         break;
  189.  
  190.                     case CN_COLLAPSETREE:
  191.                         cnrCollapseTree(usId, (PRECORDCORE)ulControlSpec);
  192.                         break;
  193.  
  194.                     case CN_CONTEXTMENU:
  195.                         cnrContextMenu(usId, (PRECORDCORE)ulControlSpec);
  196.                         break;
  197.  
  198.                     case CN_DRAGAFTER:
  199.                         ulRet = cnrDragAfter(usId,
  200.                                              ((PCNRDRAGINFO)ulControlSpec)->pRecord,
  201.                                              ((PCNRDRAGINFO)ulControlSpec)->pDragInfo);
  202.                         break;
  203.  
  204.                     case CN_DRAGLEAVE:
  205.                         cnrDragLeave(usId,
  206.                                      ((PCNRDRAGINFO)ulControlSpec)->pRecord,
  207.                                      ((PCNRDRAGINFO)ulControlSpec)->pDragInfo);
  208.                         break;
  209.  
  210.                     case CN_DRAGOVER:
  211.                         ulRet = cnrDragOver(usId,
  212.                                             ((PCNRDRAGINFO)ulControlSpec)->pRecord,
  213.                                             ((PCNRDRAGINFO)ulControlSpec)->pDragInfo);
  214.                         break;
  215.  
  216.                     case CN_DROP:
  217.                         cnrDrop(usId,
  218.                                 ((PCNRDRAGINFO)ulControlSpec)->pRecord,
  219.                                 ((PCNRDRAGINFO)ulControlSpec)->pDragInfo);
  220.                         break;
  221.  
  222.                     case CN_DROPNOTIFY:
  223.                         cnrDropNotify(usId,
  224.                                       ((PCNRLAZYDRAGINFO)ulControlSpec)->pRecord,
  225.                                       ((PCNRLAZYDRAGINFO)ulControlSpec)->pDragInfo,
  226.                                       ((PCNRLAZYDRAGINFO)ulControlSpec)->hwndTarget);
  227.                         break;
  228.  
  229.                     case CN_DROPHELP:
  230.                         cnrDropHelp(usId,
  231.                                     ((PCNRDRAGINFO)ulControlSpec)->pRecord,
  232.                                     ((PCNRDRAGINFO)ulControlSpec)->pDragInfo);
  233.                         break;
  234.  
  235.                     case CN_EMPHASIS:
  236.                         cnrEmphasis(usId,
  237.                                     ((PNOTIFYRECORDEMPHASIS)ulControlSpec)->hwndCnr,
  238.                                     ((PNOTIFYRECORDEMPHASIS)ulControlSpec)->pRecord,
  239.                                     ((PNOTIFYRECORDEMPHASIS)ulControlSpec)->fEmphasisMask);
  240.                         break;
  241.  
  242.                     case CN_ENDEDIT:
  243.                         cnrEndEdit(usId,
  244.                                    ((PCNREDITDATA)ulControlSpec)->cb,
  245.                                    ((PCNREDITDATA)ulControlSpec)->hwndCnr,
  246.                                    ((PCNREDITDATA)ulControlSpec)->pRecord,
  247.                                    ((PCNREDITDATA)ulControlSpec)->pFieldInfo,
  248.                                    ((PCNREDITDATA)ulControlSpec)->ppszText,
  249.                                    ((PCNREDITDATA)ulControlSpec)->cbText,
  250.                                    ((PCNREDITDATA)ulControlSpec)->id);
  251.                         break;
  252.  
  253.                     case CN_ENTER:
  254.                         cnrEnter(usId,
  255.                                  ((PNOTIFYRECORDENTER)ulControlSpec)->hwndCnr,
  256.                                  ((PNOTIFYRECORDENTER)ulControlSpec)->pRecord,
  257.                                  ((PNOTIFYRECORDENTER)ulControlSpec)->fKey);
  258.                         break;
  259.  
  260.                     case CN_EXPANDTREE:
  261.                         cnrExpandTree(usId, (PRECORDCORE)ulControlSpec);
  262.                         break;
  263.  
  264.                     case CN_GRIDRESIZED:
  265.                         cnrGridResized(usId, SHORT1FROMMP(ulControlSpec), SHORT2FROMMP(ulControlSpec));
  266.                         break;
  267.  
  268.                     case CN_HELP:
  269.                         cnrHelp(usId, (PRECORDCORE)ulControlSpec);
  270.                         break;
  271.  
  272.                     case CN_INITDRAG:
  273.                         cnrInitDrag(usId,
  274.                                     ((PCNRDRAGINIT)ulControlSpec)->hwndCnr,
  275.                                     ((PCNRDRAGINIT)ulControlSpec)->pRecord,
  276.                                     ((PCNRDRAGINIT)ulControlSpec)->x,
  277.                                     ((PCNRDRAGINIT)ulControlSpec)->y,
  278.                                     ((PCNRDRAGINIT)ulControlSpec)->cx,
  279.                                     ((PCNRDRAGINIT)ulControlSpec)->cy);
  280.                         break;
  281.  
  282.                     case CN_KILLFOCUS:
  283.                         cnrKillFocus(usId, (HWND)ulControlSpec);
  284.                         break;
  285.  
  286.                     case CN_PICKUP:
  287.                         cnrPickup(usId,
  288.                                   ((PCNRDRAGINIT)ulControlSpec)->hwndCnr,
  289.                                   ((PCNRDRAGINIT)ulControlSpec)->pRecord,
  290.                                   ((PCNRDRAGINIT)ulControlSpec)->x,
  291.                                   ((PCNRDRAGINIT)ulControlSpec)->y,
  292.                                   ((PCNRDRAGINIT)ulControlSpec)->cx,
  293.                                   ((PCNRDRAGINIT)ulControlSpec)->cy);
  294.                         break;
  295.  
  296.                     case CN_QUERYDELTA:
  297.                         cnrQueryDelta(usId,
  298.                                       ((PNOTIFYDELTA)ulControlSpec)->hwndCnr,
  299.                                       ((PNOTIFYDELTA)ulControlSpec)->fDelta);
  300.                         break;
  301.  
  302.                     case CN_REALLOCPSZ:
  303.                         cnrReallocPSZ(usId,
  304.                                       ((PCNREDITDATA)ulControlSpec)->cb,
  305.                                       ((PCNREDITDATA)ulControlSpec)->hwndCnr,
  306.                                       ((PCNREDITDATA)ulControlSpec)->pRecord,
  307.                                       ((PCNREDITDATA)ulControlSpec)->pFieldInfo,
  308.                                       ((PCNREDITDATA)ulControlSpec)->ppszText,
  309.                                       ((PCNREDITDATA)ulControlSpec)->cbText,
  310.                                       ((PCNREDITDATA)ulControlSpec)->id);
  311.                         break;
  312.  
  313.                     case CN_SCROLL:
  314.                         cnrScroll(usId,
  315.                                   ((PNOTIFYSCROLL)ulControlSpec)->hwndCnr,
  316.                                   ((PNOTIFYSCROLL)ulControlSpec)->lScrollInc,
  317.                                   ((PNOTIFYSCROLL)ulControlSpec)->fScroll);
  318.                         break;
  319.  
  320.                     case CN_SETFOCUS:
  321.                         cnrSetFocus(usId, (HWND)ulControlSpec);
  322.                         break;
  323.  
  324.                     default:
  325.                         ulRet = control(usId, usNotifyCode, ulControlSpec);
  326.                         break;
  327.                 }
  328.                 break; /*case WC_CONTAINER*/
  329.  
  330.             default:
  331.                 ulRet = control(usId, usNotifyCode, ulControlSpec);
  332.                 break;
  333.         }/* switch (ulClassNumber) */
  334.       #undef PSZ
  335.  
  336.     }
  337.     else
  338.         ulRet = control(usId, usNotifyCode, ulControlSpec);
  339.  
  340.     return ulRet;
  341. }
  342.  
  343.  
  344. /**
  345.  * Start timer (interface to WinStartTimer).
  346.  * @returns   Timer id. 0 on error.
  347.  * @param     idTimer       Requested timer id.
  348.  * @param     idTimeout     Time out (ms).
  349.  */
  350. ULONG kDlgBase::timerStart(ULONG idTimer, ULONG dtTimeout)
  351. {
  352.     return WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, idTimer, dtTimeout);
  353. }
  354.  
  355.  
  356.  
  357. /**
  358.  * Stop timer (interface to WinStopTimer).
  359.  * @returns   success indicator.
  360.  * @param     idTimer  Id of timer to stop.
  361.  * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
  362.  */
  363. BOOL kDlgBase::timerStop(ULONG idTimer)
  364. {
  365.     return WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, idTimer);
  366. }
  367.  
  368.  
  369.  
  370.  
  371.  
  372. /**
  373.  * button click or dbl click event.
  374.  * @returns   TRUE if event was handled, FALSE if not.
  375.  * @param     ptsPointerPos  Pointer posision relative to this window.
  376.  * @param     fsHitTestres   Hit test result.
  377.  * @param     fsflags
  378.  * @remark    stub.
  379.  */
  380. BOOL kDlgBase::button1Click(POINTS ptsPointerPos, USHORT fsHitTestres, USHORT fsFlags)
  381. {
  382.     return(BOOL)WinDefDlgProc(hwnd, WM_BUTTON1CLICK,
  383.                               *(MPARAM *)&ptsPointerPos,
  384.                               MPFROM2SHORT(fsHitTestres, fsFlags));
  385. }
  386.  
  387.  
  388.  
  389. /**
  390.  * button click or dbl click event.
  391.  * @returns   TRUE if event was handled, FALSE if not.
  392.  * @param     ptsPointerPos  Pointer posision relative to this window.
  393.  * @param     fsHitTestres   Hit test result.
  394.  * @param     fsflags
  395.  * @remark    stub.
  396.  */
  397. BOOL kDlgBase::button1DblClick(POINTS ptsPointerPos, USHORT fsHitTestres, USHORT fsFlags)
  398. {
  399.     return(BOOL)WinDefDlgProc(hwnd, WM_BUTTON1DBLCLK,
  400.                               *(MPARAM *)&ptsPointerPos,
  401.                               MPFROM2SHORT(fsHitTestres, fsFlags));
  402. }
  403.  
  404.  
  405.  
  406. /**
  407.  * button click or dbl click event. WM_BUTTON1DOWN
  408.  * @returns   TRUE if event was handled, FALSE if not.
  409.  * @param     ptsPointerPos  Pointer posision relative to this window.
  410.  * @param     fsHitTestres   Hit test result.
  411.  * @param     fsflags
  412.  * @remark    stub.
  413.  */
  414. BOOL kDlgBase::button1Down(POINTS ptsPointerPos, USHORT fsHitTestres, USHORT fsFlags)
  415. {
  416.     return(BOOL)WinDefDlgProc(hwnd, WM_BUTTON1DOWN,
  417.                               *(MPARAM *)&ptsPointerPos,
  418.                               MPFROM2SHORT(fsHitTestres, fsFlags));
  419. }
  420.  
  421.  
  422.  
  423. /**
  424.  * button click or dbl click event.
  425.  * @returns   TRUE if event was handled, FALSE if not.
  426.  * @param     ptsPointerPos  Pointer posision relative to this window.
  427.  * @param     fsHitTestres   Hit test result.
  428.  * @param     fsflags
  429.  * @remark    stub.
  430.  */
  431. BOOL kDlgBase::button2Click(POINTS ptsPointerPos, USHORT fsHitTestres, USHORT fsFlags)
  432. {
  433.     return(BOOL)WinDefDlgProc(hwnd, WM_BUTTON2CLICK,
  434.                               MPFROM2SHORT(ptsPointerPos.x, ptsPointerPos.y),
  435.                               MPFROM2SHORT(fsHitTestres, fsFlags));
  436. }
  437.  
  438.  
  439.  
  440. /**
  441.  * button click or dbl click event.
  442.  * @returns   TRUE if event was handled, FALSE if not.
  443.  * @param     ptsPointerPos  Pointer posision relative to this window.
  444.  * @param     fsHitTestres   Hit test result.
  445.  * @param     fsflags
  446.  * @remark    stub.
  447.  */
  448. BOOL kDlgBase::button2DblClick(POINTS ptsPointerPos, USHORT fsHitTestres, USHORT fsFlags)
  449. {
  450.     return(BOOL)WinDefDlgProc(hwnd, WM_BUTTON2DBLCLK,
  451.                               MPFROM2SHORT(ptsPointerPos.x, ptsPointerPos.y),
  452.                               MPFROM2SHORT(fsHitTestres, fsFlags));
  453. }
  454.  
  455.  
  456.  
  457. /**
  458.  * button click or dbl click event.
  459.  * @returns   TRUE if event was handled, FALSE if not.
  460.  * @param     ptsPointerPos  Pointer posision relative to this window.
  461.  * @param     fsHitTestres   Hit test result.
  462.  * @param     fsflags
  463.  * @remark    stub.
  464.  */
  465. BOOL kDlgBase::button2Down(POINTS ptsPointerPos, USHORT fsHitTestres, USHORT fsFlags)
  466. {
  467.     return(BOOL)WinDefDlgProc(hwnd, WM_BUTTON2DOWN,
  468.                               MPFROM2SHORT(ptsPointerPos.x, ptsPointerPos.y),
  469.                               MPFROM2SHORT(fsHitTestres, fsFlags));
  470. }
  471.  
  472.  
  473.  
  474. /**
  475.  * button click or dbl click event.
  476.  * @returns   TRUE if event was handled, FALSE if not.
  477.  * @param     ptsPointerPos  Pointer posision relative to this window.
  478.  * @param     fsHitTestres   Hit test result.
  479.  * @param     fsflags
  480.  * @remark    stub.
  481.  */
  482. BOOL kDlgBase::button3Click(POINTS ptsPointerPos, USHORT fsHitTestres, USHORT fsFlags)
  483. {
  484.     return(BOOL)WinDefDlgProc(hwnd, WM_BUTTON3CLICK,
  485.                               MPFROM2SHORT(ptsPointerPos.x, ptsPointerPos.y),
  486.                               MPFROM2SHORT(fsHitTestres, fsFlags));
  487. }
  488.  
  489.  
  490.  
  491. /**
  492.  * button click or dbl click event.
  493.  * @returns   TRUE if event was handled, FALSE if not.
  494.  * @param     ptsPointerPos  Pointer posision relative to this window.
  495.  * @param     fsHitTestres   Hit test result.
  496.  * @param     fsflags
  497.  * @remark    stub.
  498.  */
  499. BOOL kDlgBase::button3DblClick(POINTS ptsPointerPos, USHORT fsHitTestres, USHORT fsFlags)
  500. {
  501.     return(BOOL)WinDefDlgProc(hwnd, WM_BUTTON3DBLCLK,
  502.                               MPFROM2SHORT(ptsPointerPos.x, ptsPointerPos.y),
  503.                               MPFROM2SHORT(fsHitTestres, fsFlags));
  504. }
  505.  
  506.  
  507.  
  508. /**
  509.  * button click or dbl click event.
  510.  * @returns   TRUE if event was handled, FALSE if not.
  511.  * @param     ptsPointerPos  Pointer posision relative to this window.
  512.  * @param     fsHitTestres   Hit test result.
  513.  * @param     fsflags
  514.  * @remark    stub.
  515.  */
  516. BOOL kDlgBase::button3Down(POINTS ptsPointerPos, USHORT fsHitTestres, USHORT fsFlags)
  517. {
  518.     return(BOOL)WinDefDlgProc(hwnd, WM_BUTTON3DOWN,
  519.                               MPFROM2SHORT(ptsPointerPos.x, ptsPointerPos.y),
  520.                               MPFROM2SHORT(fsHitTestres, fsFlags));
  521. }
  522.  
  523.  
  524.  
  525. /**
  526.  * Default command.
  527.  * @param     usCmd     Control id which send/posted the message.
  528.  * @param     usSource  Source id.
  529.  * @param     fPointer  Mouse pointer flag.
  530.  * @remark    dismisses the dialog if DID_OK or DID_CANCEL.
  531.  */
  532. VOID kDlgBase::command(USHORT usCmd, USHORT usSource, BOOL fPointer)
  533. {
  534.     if (usCmd == DID_CANCEL || usCmd == DID_OK)
  535.         close();
  536.  
  537.     /* unreferenced */
  538.     usSource = usSource;
  539.     fPointer = fPointer;
  540. }
  541.  
  542.  
  543.  
  544. /**
  545.  * Control message.
  546.  * @param     usId           Control id.
  547.  * @param     usNotifyCode   Notification code.
  548.  * @param     ulControlSpec  Controlspecific paramenter.
  549.  */
  550. ULONG kDlgBase::control(USHORT usId, USHORT usNotifyCode, ULONG ulControlSpec)
  551. {
  552.     /* no action */
  553.     /* unreferenced */
  554.     usId = usId;
  555.     usNotifyCode = usNotifyCode;
  556.     ulControlSpec = ulControlSpec;
  557.     return (ULONG)(PULONG)WinDefDlgProc(hwnd, WM_CONTROL, MPFROM2SHORT(usId, usNotifyCode), MPFROMLONG(ulControlSpec));
  558. }
  559.  
  560.  
  561.  
  562. /**
  563.  * Destroy message.
  564.  */
  565. VOID kDlgBase::destroy()
  566. {
  567.     /* no action */
  568. }
  569.  
  570.  
  571.  
  572. /**
  573.  * Initdialog message.
  574.  * @returns   TRUE  - on success.
  575.  *            FALSE - on failiure.
  576.  * @param     hwndFocus  Handle to the focus window.
  577.  */
  578. BOOL kDlgBase::initDlg(HWND hwndFocus)
  579. {
  580.     /* no action */
  581.  
  582.     /* unreferenced */
  583.     hwndFocus = hwndFocus;
  584.  
  585.     return TRUE;
  586. }
  587.  
  588.  
  589.  
  590. /**
  591.  * Initmenu message. Enables and disables menuitems.
  592.  * @param     usMenuId  Control id of menu.
  593.  * @param     hwndMnu   WindowHandle of menu.
  594.  */
  595. VOID kDlgBase::initMenu(USHORT usMenuId, HWND hwndMnu)
  596. {
  597.     /* no action */
  598.  
  599.     /* unreferenced */
  600.     usMenuId = usMenuId;
  601.     hwndMnu = hwndMnu;
  602. }
  603.  
  604.  
  605.  
  606. /**
  607.  * Menuend message.
  608.  * @param     usMenuId  Control id of menu.
  609.  * @param     hwndMnu   WindowHandle of menu.
  610.  */
  611. VOID kDlgBase::menuEnd(USHORT usMenuId, HWND hwndMnu)
  612. {
  613.     /* no action */
  614.  
  615.     /* unreferenced */
  616.     usMenuId = usMenuId;
  617.     hwndMnu = hwndMnu;
  618. }
  619.  
  620.  
  621.  
  622. /**
  623.  * Syscomand message.
  624.  * @param     usCmd     Control id which send/posted the message.
  625.  * @param     usSource  Source id.
  626.  * @param     fPointer  Mouse pointer flag.
  627.  */
  628. VOID kDlgBase::sysCommand(USHORT usCmd, USHORT usSource, BOOL fPointer)
  629. {
  630.     /* send to default window procedure */
  631.     WinDefDlgProc(hwnd, WM_SYSCOMMAND, (MPARAM)usCmd, MPFROM2SHORT(usSource, fPointer));
  632. }
  633.  
  634.  
  635. /**
  636.  * WM_CLOSE stub.
  637.  */
  638. VOID kDlgBase::close()
  639. {
  640.     /* send to default window procedure */
  641.     if (fModal)
  642.         WinDefDlgProc(hwnd, WM_CLOSE, NULL, NULL);
  643.     else
  644.         WinDestroyWindow(hwnd);
  645. }
  646.  
  647.  
  648.  
  649. /**
  650.  * WM_TIMER message stub.
  651.  * @param     idTimer  Timer id.
  652.  */
  653. VOID kDlgBase::timer(ULONG idTimer)
  654. {
  655.     idTimer = idTimer;
  656. }
  657.  
  658.  
  659. /**
  660.  * WM_SIZE message stub.
  661.  * @param     cxOld  Old width.
  662.  * @param     cyOld  Old height.
  663.  * @param     cxNew  New width.
  664.  * @param     cyNew  New height
  665.  * @remark    Useless for dialogs!?!
  666.  */
  667. VOID kDlgBase::size(SHORT cxOld, SHORT cyOld, SHORT cxNew, SHORT cyNew)
  668. {
  669.     cxOld = cxOld;
  670.     cyOld = cyOld;
  671.     cxNew = cxNew;
  672.     cyNew = cyNew;
  673. }
  674.  
  675.  
  676. /**
  677.  * WM_ADJUSTWINDOWPOS stub.
  678.  * @param     pswp          New windowframe state.
  679.  */
  680. BOOL  kDlgBase::adjustWindowPos(PSWP pswp)
  681. {
  682.     return (BOOL)WinDefDlgProc(hwnd, WM_ADJUSTWINDOWPOS, pswp, NULL);
  683. }
  684.  
  685.  
  686. /**
  687.  * WM_ADJUSTFRAMEPOS stub.
  688.  * @param     pswp          New windowframe state.
  689.  * @param     hsavewphsvwp  Identifier of the frame window repositioning process.
  690.  */
  691. VOID  kDlgBase::adjustFramePos(PSWP pswp, HSAVEWP hsavewphsvwp)
  692. {
  693.     pswp = pswp;
  694.     hsavewphsvwp = hsavewphsvwp;
  695. }
  696.  
  697.  
  698. /**
  699.  * Creates an dialog from a resource dialogtemplate.
  700.  * @param     ulResId      Resource id of the template.
  701.  * @param     hmodRes      Module handle of the module containing the template.
  702.  * @param     hwndOwner    Windowhandle of the owner window.
  703.  * @param     hwndParent   Windowhandle of the parent window. Defaults to HWND_DESKTOP.
  704.  * @remark    Throws kError on error.
  705.  *            Use the show()/showModal() methods to show the dialog
  706.  */
  707. kDlgBase::kDlgBase(ULONG ulResId, HMODULE hmodRes, HWND hwndOwner, HWND hwndParent /*= HWND_DESKTOP*/) throw (kError)
  708. : fModal(FALSE)
  709. {
  710.     APIRET rc;
  711.  
  712.     /* get resource pointer */
  713.     rc = DosGetResource(hmodRes, RT_DIALOG, ulResId, (PPVOID)&pDlgTemplate);
  714.     if (rc != NO_ERROR)
  715.         throw (kError(rc, kError::dos));
  716.  
  717.     /* create dialog from template */
  718.     hwnd = WinCreateDlg(hwndParent, hwndOwner, forwarder, pDlgTemplate, this);
  719.     if (hwnd == NULLHANDLE)
  720.         throw (kError(kError::unused, kError::win));
  721. }
  722.  
  723.  
  724. /**
  725.  * Creates an dialog from a resource dialogtemplate.
  726.  * @param     pszTitle          Dialog title.
  727.  * @param     id                Dialog id.
  728.  * @param     flDialogStyle     Dialog style flags.
  729.  * @param     flDialogCreate    Dialog (frame) create flags.
  730.  * @param     x                 x-coordinate.
  731.  * @param     y                 y-coordinate.
  732.  * @param     cx                width
  733.  * @param     cy                hight
  734.  * @param     hwndOwner         Owner window
  735.  * @param     hwndParent        Parent window.
  736.  * @remark    Throws kError on error.
  737.  *            Use the show()/showModal() methods to show the dialog
  738.  */
  739. kDlgBase::kDlgBase(PCSZ pszTitle, ULONG id, ULONG flDialogStyle, ULONG flDialogCreate,
  740.                    LONG x, LONG y, LONG cx, LONG cy,
  741.                    HWND hwndOwner, HWND hwndParent/* = HWND_DESKTOP */) throw (kError)
  742. : fModal(FALSE)
  743. {
  744.     int    cb;                          /* Size of the dialog template. */
  745.  
  746.     /* flDialogStyle should have WS_CLIPSIBLINGS and WS_SAVEBITS set! */
  747.     flDialogStyle |= WS_CLIPSIBLINGS | WS_SAVEBITS;
  748.  
  749.     /* make a fake template for this dialog. */
  750.     cb = sizeof(DLGTEMPLATE) + strlen(pszTitle) + 1 + sizeof(ULONG);
  751.     pDlgTemplate = (PDLGTEMPLATE)calloc(cb, 1);
  752.     if (pDlgTemplate == NULL)
  753.         throw (kError(kError::alloc_failed));
  754.  
  755.     pDlgTemplate->cbTemplate        = (USHORT)cb;
  756.     pDlgTemplate->offadlgti         = offsetof(DLGTEMPLATE, adlgti);
  757.     pDlgTemplate->fsTemplateStatus  = 1;
  758.     pDlgTemplate->iItemFocus        = (USHORT)~0;
  759.  
  760.     pDlgTemplate->adlgti[0].cchClassName = 0;
  761.     pDlgTemplate->adlgti[0].offClassName = (USHORT)(ULONG)WC_FRAME;
  762.     pDlgTemplate->adlgti[0].cchText      = (USHORT)strlen(pszTitle);
  763.     pDlgTemplate->adlgti[0].offText      = (USHORT)sizeof(DLGTEMPLATE);
  764.     strcpy((char*)(pDlgTemplate+1), pszTitle);
  765.     pDlgTemplate->adlgti[0].flStyle      = flDialogStyle;
  766.     pDlgTemplate->adlgti[0].id           = (USHORT)id;
  767.     pDlgTemplate->adlgti[0].offCtlData   = (USHORT)(pDlgTemplate->adlgti[0].offText + strlen(pszTitle) + 1);
  768.     *(PULONG)((unsigned)(pDlgTemplate+1) + pDlgTemplate->adlgti[0].offCtlData) = flDialogCreate;
  769.     pDlgTemplate->adlgti[0].x       = (SHORT)x;
  770.     pDlgTemplate->adlgti[0].y       = (SHORT)y;
  771.     pDlgTemplate->adlgti[0].cx      = (SHORT)cx;
  772.     pDlgTemplate->adlgti[0].cy      = (SHORT)cy;
  773.  
  774.     /*
  775.      * Debug stuff
  776.      */
  777.     #if 0
  778.     PDLGTEMPLATE pDlg2;
  779.     DosGetResource(NULLHANDLE, RT_DIALOG, 100, (PPVOID)&pDlg2);
  780.     #endif
  781.     /* create dialog from template */
  782.     hwnd = WinCreateDlg(hwndParent, hwndOwner, forwarder, pDlgTemplate, this);
  783.     if (hwnd == NULLHANDLE)
  784.         throw (kError(kError::unused, kError::win));
  785. }
  786.  
  787.  
  788. /**
  789.  * Destroy the dialog and release the resource.
  790.  */
  791. kDlgBase::~kDlgBase()
  792. {
  793.     if (fModal && !(WinQueryWindowUShort(hwnd, QWS_FLAGS) & FF_DLGDISMISSED))
  794.         WinDismissDlg(hwnd, DID_CANCEL);
  795.     WinDestroyWindow(hwnd);
  796.     hwnd = NULLHANDLE;
  797.     DosFreeResource(pDlgTemplate);
  798.     pDlgTemplate = NULL;
  799. }
  800.  
  801.  
  802.  
  803. /**
  804.  * Hides the dialog.
  805.  * @returns   TRUE - the dialog was hidden.
  806.  *            FALSE - something failed.
  807.  */
  808. BOOL kDlgBase::hide()
  809. {
  810.     return WinSetWindowPos(hwnd, NULLHANDLE, 0,0,0,0, SWP_HIDE);
  811. }
  812.  
  813.  
  814.  
  815. /**
  816.  * Shows the dialog - modelessly.
  817.  * @returns   TRUE - the dialog was shown.
  818.  *            FALSE - failed showing the dialog.
  819.  */
  820. BOOL kDlgBase::show()
  821. {
  822.     fModal = FALSE;
  823.     return WinSetWindowPos(hwnd, NULLHANDLE, 0,0,0,0, SWP_SHOW);
  824. }
  825.  
  826.  
  827. /**
  828.  * Shows the dialog modally.
  829.  * @returns   WinProcessDlg return code.
  830.  */
  831. ULONG kDlgBase::showModal()
  832. {
  833.     fModal = TRUE;
  834.     return WinProcessDlg(hwnd);
  835. }
  836.  
  837.  
  838. /**
  839.  * Sets the dialog title.
  840.  * @returns   Success indicator.
  841.  * @param     pszTitle  Pointer to string containing the new title.
  842.  */
  843. BOOL  kDlgBase::setTitle(PCSZ pszTitle)
  844. {
  845.     return WinSetWindowText(hwnd, pszTitle);
  846. }
  847.  
  848.  
  849. /**
  850.  * Resize the dialog.
  851.  * @returns   Success indicator. TRUE / FALSE.
  852.  * @param     cx  Size in x direction (pixels).
  853.  * @param     cy  Size in y direction (pixels).
  854.  */
  855. BOOL kDlgBase::resize(LONG cx, LONG cy)
  856. {
  857.     return WinSetWindowPos(hwnd, NULLHANDLE, 0, 0, cx, cy, SWP_SIZE);
  858. }
  859.  
  860.  
  861. /**
  862.  * Resize and mode the dialog.
  863.  * @returns   Success indicator. TRUE / FALSE.
  864.  * @param     x   x-coordinate for left lower corner.
  865.  * @param     y   y-coordinate for left lower corner.
  866.  * @param     cx  Size in x direction (pixels).
  867.  * @param     cy  Size in y direction (pixels).
  868.  */
  869. BOOL kDlgBase::resizeAndMove(LONG x, LONG y, LONG cx, LONG cy)
  870. {
  871.     return WinSetWindowPos(hwnd, NULLHANDLE, x, y, cx, cy, SWP_SIZE | SWP_MOVE);
  872. }
  873.  
  874.  
  875. /**
  876.  * Gets the size rectangle of the window.
  877.  * @returns   Success indicator. TRUE / FALSE.
  878.  * @param     prectl  Pointer to rectangle.
  879.  */
  880. BOOL kDlgBase::queryRectangle(PRECTL prectl)
  881. {
  882.     SWP swp;
  883.     if (WinQueryWindowPos(hwnd, &swp))
  884.     {
  885.         prectl->xLeft   = swp.x;
  886.         prectl->yBottom = swp.y;
  887.         prectl->xRight  = swp.x + swp.cx;
  888.         prectl->yTop    = swp.y + swp.cy;
  889.         return TRUE;
  890.     }
  891.     return FALSE;
  892. }
  893.  
  894. /**
  895.  * Gets the window handler for this dialog.
  896.  * @returns   Handle to dialog. NULLHANDE on error.
  897.  */
  898. HWND kDlgBase::getHwnd()
  899. {
  900.     return hwnd;
  901. }
  902.  
  903.  
  904.  
  905. /**
  906.  * Forwards messages to kDlgBaseMsgLoop if a QWS_USER is registered.
  907.  * When WM_INITDLG, it stores the this pointer (mp2) in QWS_USER.
  908.  * @returns   depended on msg. See PMREF for more.
  909.  * @param     hwnd  Handle of the(this) window receiving the message.
  910.  * @param     msg   Message id. See PMREF for more.
  911.  * @param     mp1   Message paramenter one. See PMREF for more.
  912.  * @param     mp2   Message paramenter two. See PMREF for more.
  913.  * @remark    Forwarder.
  914.  */
  915. static MRESULT forwarder(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  916. {
  917.     kDlgBase *pthis;
  918.     PVOID pv;
  919.  
  920.     pv = (PVOID)WinQueryWindowULong(hwnd, QWL_USER);
  921.     if (msg == WM_INITDLG)
  922.     {
  923.         pv = mp2;
  924.         WinSetWindowULong(hwnd, QWL_USER, (ULONG)pv);
  925.     }
  926.     if (pv != NULL)
  927.     {
  928.         pthis = (kDlgBase*)pv;
  929.         return pthis->msgLoop(hwnd, msg, mp1, mp2);
  930.     }
  931.     else
  932.         return WinDefDlgProc(hwnd, msg, mp1, mp2);
  933. }
  934.  
  935.  
  936.  
  937. /**
  938.  * Message loop.
  939.  * @returns   depended on msg. See PMREF for more.
  940.  * @param     hwnd  Handle of the(this) window receiving the message.
  941.  * @param     msg   Message id. See PMREF for more.
  942.  * @param     mp1   Message paramenter one. See PMREF for more.
  943.  * @param     mp2   Message paramenter two. See PMREF for more.
  944.  */
  945. MRESULT kDlgBase::msgLoop(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  946. {
  947.     MRESULT mr = NULL;
  948.     switch (msg)
  949.     {
  950.         case WM_COMMAND:
  951.             command(SHORT1FROMMP(mp1), SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
  952.             break;
  953.  
  954.         case WM_CONTROL:
  955.             mr = (MRESULT)controlIntern(SHORT1FROMMP(mp1), SHORT2FROMMP(mp1), (ULONG)mp2);
  956.             break;
  957.  
  958.         case WM_DESTROY:
  959.             destroy();
  960.             break;
  961.  
  962.         case WM_INITDLG:
  963.             mr = (MRESULT)!initDlg((HWND)mp1);
  964.             break;
  965.  
  966.         case WM_INITMENU:
  967.             initMenu(SHORT1FROMMP(mp1), (HWND)mp2);
  968.             break;
  969.  
  970.         case WM_MENUEND:
  971.             menuEnd(SHORT1FROMMP(mp1), (HWND)mp2);
  972.             break;
  973.  
  974.         case WM_BUTTON1CLICK:
  975.             mr = (MRESULT)button1Click(*(PPOINTS)&mp1, SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
  976.             break;
  977.  
  978.         case WM_BUTTON1DBLCLK:
  979.             mr = (MRESULT)button1DblClick(*(PPOINTS)&mp1, SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
  980.             break;
  981.  
  982.         case WM_BUTTON1DOWN:
  983.             mr = (MRESULT)button1Down(*(PPOINTS)&mp1, SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
  984.             break;
  985.  
  986.         case WM_BUTTON2CLICK:
  987.             mr = (MRESULT)button2Click(*(PPOINTS)&mp1, SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
  988.             break;
  989.  
  990.         case WM_BUTTON2DBLCLK:
  991.             mr = (MRESULT)button2DblClick(*(PPOINTS)&mp1, SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
  992.             break;
  993.  
  994.         case WM_BUTTON2DOWN:
  995.             mr = (MRESULT)button2Down(*(PPOINTS)&mp1, SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
  996.             break;
  997.  
  998.         case WM_BUTTON3CLICK:
  999.             mr = (MRESULT)button3Click(*(PPOINTS)&mp1, SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
  1000.             break;
  1001.  
  1002.         case WM_BUTTON3DBLCLK:
  1003.             mr = (MRESULT)button3DblClick(*(PPOINTS)&mp1, SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
  1004.             break;
  1005.  
  1006.         case WM_BUTTON3DOWN:
  1007.             mr = (MRESULT)button3Down(*(PPOINTS)&mp1, SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
  1008.             break;
  1009.  
  1010.         case WM_SYSCOMMAND:
  1011.             sysCommand(SHORT1FROMMP(mp1), SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
  1012.             break;
  1013.  
  1014.         case WM_CLOSE:
  1015.             this->close();
  1016.             break;
  1017.  
  1018.         case WM_TIMER:
  1019.             timer((ULONG)mp1);
  1020.             mr = WinDefDlgProc(hwnd, msg, mp1, mp2);
  1021.             break;
  1022.  
  1023.         case WM_SIZE:
  1024.             size(SHORT1FROMMP(mp1), SHORT2FROMMP(mp1),
  1025.                  SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
  1026.             break;
  1027.  
  1028.         case WM_ADJUSTWINDOWPOS:
  1029.             mr = (MRESULT)adjustWindowPos((PSWP)mp1);
  1030.             break;
  1031.  
  1032.         case WM_ADJUSTFRAMEPOS:
  1033.             adjustFramePos((PSWP)mp1, (HSAVEWP)mp2);
  1034.             mr = WinDefDlgProc(hwnd, msg, mp1, mp2);
  1035.             break;
  1036.  
  1037.         default:
  1038.             mr = WinDefDlgProc(hwnd, msg, mp1, mp2);
  1039.     }
  1040.     return mr;
  1041. }
  1042.  
  1043.  
  1044.  
  1045. /**
  1046.  * Sets the window text for a dialog item - printf styled.
  1047.  * @returns   sucessindicator.
  1048.  * @param     ulId          Id of the dialog item.
  1049.  * @param     pszFormat     Format string. (printf styled);
  1050.  * @param     ...           More arguments.
  1051.  * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
  1052.  * @remark
  1053.  */
  1054. BOOL    kDlgBase::setDlgItemText(ULONG ulId, PCSZ pszFormat, ...)
  1055. {
  1056.     va_list arg;
  1057.     CHAR    szBuffer[1024];
  1058.  
  1059.     va_start(arg, pszFormat);
  1060.     vsprintf(szBuffer, pszFormat, arg);
  1061.     va_end(arg);
  1062.  
  1063.     return WinSetDlgItemText(hwnd, ulId, szBuffer);
  1064. }
  1065.  
  1066.