home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lstbx2.zip / driver.c < prev    next >
C/C++ Source or Header  |  1994-04-21  |  14KB  |  433 lines

  1. #pragma    title("Prominare Designer  --  Version 2.10 -- (Colours.C)")
  2. #pragma    subtitle("   Prominare Designer - Interface Definitions")
  3.  
  4. #define    INCL_DOS           /* Include OS/2 DOS Kernal        */
  5. #define    INCL_GPI           /* Include OS/2 PM GPI Interface    */
  6. #define    INCL_WIN           /* Include OS/2 PM Windows Interface    */
  7. #define    INCL_WINSTDSPIN           /* Include OS/2 PM Spin Buttons    */
  8. #define    INCL_NLS           /* Include OS/2 PM NLS        */
  9. #define    INCL_SW               /* Include OS/2 MultiMedia Support    */
  10.  
  11. #pragma    info(nopar)
  12.  
  13. static char *MODID = "@(#)driver.c:1.07";
  14.  
  15. #include <os2.h>
  16. #include <string.h>
  17. #include <stdio.h>
  18.  
  19. #include "listbox.h"
  20.  
  21. /* The application is created using the    following options in Prominare    */
  22. /* Builder:                                */
  23. /*                                    */
  24. /* Option           Value                        */
  25. /* ------           -----                        */
  26. /* Memory Model           Small                        */
  27. /* Op Sys           OS/2 2.x    PM Normal                */
  28. /* Optimization           Maximize                        */
  29. /* Compile Type           Compile Only                    */
  30. /*               Error Trap                    */
  31. /*               ExePack                        */
  32. /*               Link                        */
  33. /* CPU               80386                        */
  34. /* Warning Level       3                        */    
  35. /*                                    */
  36. /* Equivalent command line invocation of each module using the        */
  37. /* IBM C Set/2 Compiler    Version    1.0 is:                    */
  38. /*                                    */
  39. /*     Icc -G3s- -O+ -Sm -C -W3    -Fofilename filename.C            */
  40.  
  41. /* Filename:   Driver.C                            */
  42.  
  43. /*  Version:   2.10                            */
  44. /*  Created:   1990-12-29                        */
  45. /*  Revised:   1994-01-05                        */
  46.  
  47.  
  48. /* --------------------------------------------------------------------    */
  49.  
  50. /* --- Module Definitions ---------------------------------------------    */
  51.  
  52. #define    USER_RESERVED       8       /* Control Reserved Memory Size    */
  53.  
  54. PSZ pszDriverClassName = "ListBox.Desktop";
  55.  
  56. HPOINTER hptrWait;
  57. HPOINTER hptrArrow;
  58. HWND     hwndDriver;           /* Program Window Handle        */
  59. HWND     hwndDriverFrame;       /* Program Frame Handle        */
  60. HAB     hAB;               /* Program Anchor Block Handle    */
  61. HMQ     hmqDriver;           /* Program Message Queue Handle    */
  62.  
  63. HWND     hwndListx;
  64. HWND     hwndList1;
  65. HWND     hwndList2;
  66.  
  67. HWND     hwndListA;
  68. HWND     hwndListB;
  69.  
  70. #define    RGBCLR_DIALOGBACKGROUND    0x00ccccccL
  71.  
  72. INT main(INT, CHAR *[ ]);
  73. MRESULT    EXPENTRY ListBoxWndProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  74. MRESULT    EXPENTRY DriverWndProc(HWND hWnd, ULONG    msg, MPARAM mp1, MPARAM    mp2);
  75.  
  76.  
  77. #pragma    subtitle("   Client Window - Client Window Procedure")
  78. #pragma    page( )
  79.  
  80. /* --- DriverWndProc --------------------------------------------------    */
  81. /*                                    */
  82. /*     This function is    used to    process    the messages for the main    */
  83. /*     Client Window.                            */
  84. /*                                    */
  85. /*     Upon Entry:                            */
  86. /*                                    */
  87. /*     HWND   hWnd; = Window Handle                    */
  88. /*     ULONG  msg;  = PM Message                    */
  89. /*     MPARAM mp1;  = Message Parameter    1                */
  90. /*     MPARAM mp2;  = Message Parameter    2                */
  91. /*                                    */
  92. /*     Upon Exit:                            */
  93. /*                                    */
  94. /*     DriverWndProc = Message Handling    Result                */
  95. /*                                    */
  96. /* --------------------------------------------------------------------    */
  97.  
  98. MRESULT    EXPENTRY DriverWndProc(HWND hWnd, ULONG    msg, MPARAM mp1, MPARAM    mp2)
  99.  
  100. {
  101. CHAR         szFile[CCHMAXPATH];   /* File HOlder            */
  102. FILEFINDBUF3 findbuf;           /* File Find    Buffer            */
  103. FONTMETRICS  fm;           /* Font Metrics Structure        */
  104. HDIR         hDir = (HDIR)HDIR_CREATE; /* Directory Handle        */
  105. HPS         hPS;           /* Presentation Space Handle        */
  106. HWND         hwndListBox;       /* List Box Window Handle        */
  107. LISTBOXCDATA lbwcd;           /* List Box Window Control Data    */
  108. POWNERITEM   poi;           /* Owner Item            */
  109. RECTL         rcl;           /* Client Window Rectangle        */
  110. ULONG         ulFileCnt = 1UL;       /* File Counter Holder        */
  111. register INT i,    k, n;           /* Loop Counter            */
  112.  
  113. switch ( msg )
  114.    {
  115.                /* Perform window initialization            */
  116.    case    WM_CREATE :
  117.        hptrArrow = WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW,    FALSE);
  118.        WinSetPointer(HWND_DESKTOP, hptrWait = WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT, FALSE));
  119.        memset(&lbwcd, 0, sizeof(LISTBOXCDATA));
  120.        lbwcd.cb    = sizeof(LISTBOXCDATA);
  121.        lbwcd.ulVersion = LBV_110;
  122.        lbwcd.vdata.lbcd1_1.flExtStyles = LSXS_CHECKBOX;
  123.  
  124.        hwndList1 = WinCreateWindow(hWnd, "ListBoxWindow", "", LS_HORZSCROLL | LS_EXTENDEDSEL | WS_VISIBLE,
  125.                    10L,    10L, 100L, 175L, hWnd,
  126.                    HWND_TOP, 1024UL, (PVOID)&lbwcd, (PVOID)NULL);
  127.  
  128.        hwndListx = WinCreateWindow(hWnd, "ListBoxWindow", "", LS_HORZSCROLL | LS_EXTENDEDSEL | WS_VISIBLE,
  129.                    125L, 10L, 100L, 175L, hWnd,
  130.                    HWND_TOP, 1024UL, (PVOID)&lbwcd, (PVOID)NULL);
  131.  
  132.        hwndList2 = WinCreateWindow(hWnd, "ListBoxWindow", "", WS_VISIBLE, 10L, 190L, 250L, 200L, hWnd,
  133.                    HWND_TOP, 1025UL, (PVOID)&lbwcd, (PVOID)NULL);
  134.  
  135.        WinSendMsg(hwndList1, LMXM_SETSOUNDEVENT, MPFROMLONG(LSND_SINGLECLICK),
  136.           MPFROMP("ahooga.wav"));
  137.        WinSendMsg(hwndListx, LMXM_SETSOUNDEVENT, MPFROMLONG(LSND_DOUBLECLICK),
  138.           MPFROMP("flush.wav"));
  139.  
  140.        hwndListA = WinCreateWindow(hWnd, WC_LISTBOX, "", LS_OWNERDRAW |    LS_HORZSCROLL |    LS_MULTIPLESEL | WS_VISIBLE,
  141.                    275L, 10L, 100L, 175L, hWnd,
  142.                    HWND_TOP, 1026UL, (PVOID)NULL, (PVOID)NULL);
  143.  
  144.                /* Sub-class the    default    window procedure with    */
  145.                /* new one which    will handle specific messages    */
  146.                /* allowing better control over the sizing frame    */
  147.  
  148.        hwndListB = WinCreateWindow(hWnd, WC_LISTBOX, "", WS_VISIBLE | LS_EXTENDEDSEL, 275L, 190L, 250L,    200L, hWnd,
  149.                    HWND_TOP, 1027UL, (PVOID)NULL, (PVOID)NULL);
  150.  
  151.        for ( i = 0; i <    10; i++    )
  152.        {
  153.        sprintf(szFile, "Item %04d Item %04d Item %04d", i, i, i);
  154.            WinSendMsg(hwndListx, LM_INSERTITEM,
  155.               MPFROMLONG(LIT_END),
  156.               MPFROMP(szFile));
  157.        }
  158.  
  159.        n = (INT)WinSendMsg(hwndList2, LMX_CALCLINECOUNT, MPFROMLONG(175L), 0L);
  160.  
  161.        k = 0;
  162.  
  163.        WinSendMsg(hwndList2, LM_SETITEMHEIGHT, MPFROMLONG(36L),    0L);
  164.  
  165.        if ( !DosFindFirst("*.*", &hDir,    FILE_NORMAL,
  166.               (PVOID)&findbuf, sizeof(FILEFINDBUF3),
  167.               &ulFileCnt, FIL_STANDARD) )
  168.        {
  169.        do
  170.            {
  171.            WinSendMsg(hwndList2, LM_INSERTITEM,
  172.               MPFROMLONG(LIT_SORTDESCENDING),
  173.               MPFROMP(findbuf.achName));
  174.            WinSendMsg(hwndList1, LM_INSERTITEM,
  175.               MPFROMLONG(LIT_SORTASCENDING),
  176.               MPFROMP(findbuf.achName));
  177.            if ( ++k    > n )
  178.            WinSendMsg(hwndList2, LM_SETTOPINDEX, MPFROMLONG(k -    n), 0L);
  179.            WinSendMsg(hwndListB, LM_INSERTITEM,
  180.               MPFROMLONG(LIT_SORTDESCENDING),
  181.               MPFROMP(findbuf.achName));
  182.            WinSendMsg(hwndListA, LM_INSERTITEM,
  183.               MPFROMLONG(LIT_SORTASCENDING),
  184.               MPFROMP(findbuf.achName));
  185.            }
  186.            while ( !DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3), &ulFileCnt) );
  187.        DosFindClose(hDir);
  188.        }
  189.        break;
  190.  
  191.    case    WM_BUTTON1DOWN :
  192.        WinEnableWindowUpdate(hwndListA,    FALSE);
  193.        WinEnableWindowUpdate(hwndList1,    FALSE);
  194.  
  195.        WinSendMsg(hwndListA, LM_DELETEALL, 0L, 0L);
  196.        WinSendMsg(hwndList1, LM_DELETEALL, 0L, 0L);
  197.        i = 0;
  198.        if ( !DosFindFirst("*.*", &hDir,    FILE_NORMAL,
  199.               (PVOID)&findbuf, sizeof(FILEFINDBUF3),
  200.               &ulFileCnt, FIL_STANDARD) )
  201.        {
  202.        do
  203.            {
  204.            WinSendMsg(hwndListA, LM_INSERTITEM,
  205.               MPFROMLONG(LIT_SORTASCENDING),
  206.               MPFROMP(findbuf.achName));
  207.            WinSendMsg(hwndList1, LM_INSERTITEM,
  208.               MPFROMLONG(LIT_SORTASCENDING),
  209.               MPFROMP(findbuf.achName));
  210.            ++i;
  211.            }
  212.            while ( !DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3), &ulFileCnt) );
  213.        DosFindClose(hDir);
  214.        }
  215.        WinShowWindow(hwndListA,    TRUE);
  216.        WinShowWindow(hwndList1,    TRUE);
  217.  
  218.        while ( i )
  219.        {
  220.        if (    i % 2 )
  221.            {
  222.            WinSendMsg(hwndListA, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(TRUE));
  223.            WinSendMsg(hwndList1, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(TRUE));
  224.            }
  225.        --i;
  226.        }
  227.        break;
  228.  
  229.    case    WM_CONTROL :
  230.        switch (    SHORT2FROMMP(mp1) )
  231.        {
  232.                /* Process double click on a List Box        */
  233.  
  234.        case    LN_SELECT :
  235.            switch (    SHORT1FROMMP(mp1) )
  236.            {
  237.            case    1024UL :
  238.            /*  WinAlarm(HWND_DESKTOP, WA_NOTE);      */
  239.                break;
  240.  
  241.            case    1027UL :
  242.            /*  WinAlarm(HWND_DESKTOP, WA_ERROR);  */
  243.                break;
  244.            }
  245.            break;
  246.        }
  247.        break;
  248.  
  249.  
  250.    case    WM_MEASUREITEM :
  251.        GpiQueryFontMetrics(hPS = WinGetPS(hWnd), sizeof(FONTMETRICS), &fm);
  252.        WinReleasePS(hPS);
  253.        return(MRFROMLONG(fm.lMaxBaselineExt));
  254.  
  255.                /* Draw a list box item                */
  256.    case    WM_DRAWITEM :
  257.  
  258.        if ( SHORT1FROMMP(mp1) == 1024 )
  259.        hwndListBox = hwndList1;
  260.        else
  261.        if (    SHORT1FROMMP(mp1) == 1026 )
  262.            hwndListBox = hwndListA;
  263.  
  264.                /* Point    to Owner Item information        */
  265.  
  266.        poi = (POWNERITEM)mp2;
  267.        GpiCreateLogColorTable(poi->hps,    0L, LCOLF_RGB, 0L, 0L, (PLONG)NULL);
  268.  
  269.        i = (INT)LONGFROMMR(WinSendMsg(hwndListBox, LM_QUERYITEMTEXTLENGTH,
  270.                       MPFROMLONG(poi->idItem), 0L));
  271.  
  272.        i = (INT)LONGFROMMR(WinSendMsg(hwndListBox, LM_QUERYITEMTEXT,
  273.                       MPFROM2SHORT(poi->idItem,    CCHMAXPATH),
  274.                       MPFROMP(szFile)));
  275.  
  276.                /* Check    to see if item to be drawn or        */
  277.                /* highlighted                    */
  278.  
  279.        if ( poi->fsState != poi->fsStateOld )
  280.        {
  281.        WinFillRect(poi->hps, &poi->rclItem,    RGBCLR_DIALOGBACKGROUND);
  282.  
  283.        if (    poi->fsState )
  284.            WinDrawText(poi->hps, -1L, szFile, &poi->rclItem,
  285.                RGB_BLACK, RGBCLR_DIALOGBACKGROUND, DT_LEFT | DT_VCENTER |
  286.                DT_ERASERECT);
  287.  
  288.                /* Set item highlighting    by inverting the items    */
  289.                /* rectangle colour                */
  290.  
  291.        WinInvertRect(poi->hps, &poi->rclItem);
  292.  
  293.        if (    !poi->fsState )
  294.            WinDrawText(poi->hps, -1L, szFile, &poi->rclItem,
  295.                RGB_BLACK, RGBCLR_DIALOGBACKGROUND, DT_LEFT | DT_VCENTER |
  296.                DT_ERASERECT);
  297.        poi->fsState    = poi->fsStateOld = 0;
  298.        }
  299.        else
  300.        {
  301.                /* Item needs to    be drawn, get item rectangle    */
  302.                /* item position                    */
  303.  
  304.        WinFillRect(poi->hps, &poi->rclItem,    RGBCLR_DIALOGBACKGROUND);
  305.  
  306.        WinDrawText(poi->hps, -1L, szFile, &poi->rclItem,
  307.                RGB_BLACK, RGBCLR_DIALOGBACKGROUND, DT_LEFT | DT_VCENTER    |
  308.                DT_ERASERECT);
  309.        }
  310.        return(MRFROMLONG(TRUE));
  311.  
  312.    case    WM_BUTTON1DBLCLK :
  313.        i = 0;
  314.        if ( !DosFindFirst("*.*", &hDir,    FILE_NORMAL,
  315.               (PVOID)&findbuf, sizeof(FILEFINDBUF3),
  316.               &ulFileCnt, FIL_STANDARD) )
  317.        {
  318.        do
  319.            {
  320.            ++i;
  321.            }
  322.            while ( !DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3), &ulFileCnt) );
  323.        DosFindClose(hDir);
  324.        }
  325.  
  326.        while ( i )
  327.        {
  328.        if (    i % 2 )
  329.            {
  330.            WinSendMsg(hwndListA, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(FALSE));
  331.            WinSendMsg(hwndList1, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(FALSE));
  332.            }
  333.        --i;
  334.        }
  335.        break;
  336.  
  337.    case    WM_BUTTON2DOWN :
  338.  
  339.        for ( i = 0; i <    5; i++ )
  340.        WinSendMsg(hwndListx, LM_DELETEITEM,    MPFROMSHORT(2),    0L);
  341.  
  342. #if 0
  343.        WinSendMsg(hwndListA, LM_SELECTITEM, MPFROMLONG(LIT_NONE), MPFROMLONG(TRUE));
  344.  
  345.        i = LIT_FIRST;
  346.        while ( (i = (INT)LONGFROMMR(WinSendMsg(hwndList1, LM_QUERYSELECTION, MPFROMLONG(i), 0L))) != LIT_NONE )
  347.        WinSendMsg(hwndList1, LM_SELECTITEM,    MPFROMLONG(i), MPFROMLONG(FALSE));
  348. #endif
  349.        break;
  350.                /* Erase    background                */
  351.  
  352.    case    WM_ERASEBACKGROUND :
  353.        WinQueryWindowRect(hWnd,    &rcl);
  354.        WinFillRect((HPS)mp1, &rcl, SYSCLR_DIALOGBACKGROUND);
  355.        break;
  356.                /* Paint    the main client    window            */
  357.    case    WM_PAINT :
  358.        WinSetPointer(HWND_DESKTOP, hptrWait);
  359.  
  360.        WinFillRect(hPS = WinBeginPaint(hWnd, (HPS)NULL,    &rcl), &rcl, SYSCLR_DIALOGBACKGROUND);
  361.  
  362.        WinEndPaint(hPS);
  363.        WinSetPointer(HWND_DESKTOP, hptrArrow);
  364.        break;
  365.                /* Close    Down                    */
  366.    case    WM_CLOSE :
  367.  
  368.        WinPostMsg(hWnd,    WM_QUIT, 0L, 0L);
  369.        break;
  370.  
  371.    case    WM_DESTROY :
  372.        WinDestroyPointer(hptrArrow);
  373.        WinDestroyPointer(hptrWait);
  374.        break;
  375.                /* Default message processing            */
  376.    default:
  377.        return(WinDefWindowProc(hWnd, msg, mp1, mp2));
  378.    }
  379. return(0L);
  380. }
  381. #pragma    subtitle("   Program Controller")
  382. #pragma    page( )
  383.  
  384. /* --- Main Program Controller ----------------------------------------    */
  385.  
  386. INT main(INT argc, CHAR    *argv[ ])
  387.  
  388. {
  389. QMSG       qmsg;           /* PM Message Queue Holder        */
  390. ULONG       flCreateFlags;       /* Window Creation Flags        */
  391.  
  392.                /* Initialize the program for PM    and create the    */
  393.                /* message queue                    */
  394.  
  395. WinSetCp(hmqDriver = WinCreateMsgQueue(hAB = WinInitialize(0), 0), 850);
  396.  
  397.                /* Register the main program window class    */
  398.  
  399. if ( !WinRegisterClass(hAB, pszDriverClassName,    (PFNWP)DriverWndProc,
  400.                CS_CLIPCHILDREN | CS_SYNCPAINT |    CS_SIZEREDRAW, 0) )
  401.    return(1);
  402.                /* Register the main program window class    */
  403.  
  404. if ( !fRegisterListBox(hAB) )
  405.    return(1);
  406.                /* Create the main program window but do    not    */
  407.                /* show it yet                    */
  408.  
  409. flCreateFlags =    FCF_TITLEBAR | FCF_NOBYTEALIGN | FCF_SYSMENU | FCF_SIZEBORDER |    FCF_SHELLPOSITION;
  410. if ( !(hwndDriverFrame = WinCreateStdWindow(HWND_DESKTOP, WS_VISIBLE,
  411.                           &flCreateFlags,
  412.                           pszDriverClassName, NULL,    0L,
  413.                          (HMODULE)0L, 0L,
  414.                           &hwndDriver)) )
  415.    {
  416.    return(1);
  417.    }
  418.                /* Retrieve and then dispatch messages        */
  419.  
  420. while (    WinGetMsg(hAB, &qmsg, (HWND)NULL, 0, 0)    )
  421.    WinDispatchMsg(hAB, &qmsg);
  422.  
  423. WinDestroyWindow(hwndDriverFrame);
  424.  
  425. WinDestroyMsgQueue(hmqDriver);
  426.  
  427.                /* Notify PM that main program thread not needed    */
  428.                /* any longer                    */
  429. WinTerminate(hAB);
  430.  
  431. return(0);
  432. }
  433.