home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / prnt3.zip / ToolBar.C < prev    next >
C/C++ Source or Header  |  1995-03-12  |  12KB  |  318 lines

  1. #pragma    title("Printer Driver  --  Version 3  --  (ToolBar.C)")
  2. #pragma    subtitle("   Application Window - Interface Definitions")
  3.  
  4. #pragma    info(noext)
  5.  
  6. #define    INCL_GPI           /* Include OS/2 PM GPI Interface    */
  7. #define    INCL_WIN           /* Include OS/2 PM Windows Interface    */
  8.  
  9. #include <os2.h>
  10.  
  11. #include "appdefs.h"
  12. #include "prnsetup.h"
  13.  
  14. /* This    module contains    tool bar window    procedure.            */
  15.  
  16. /* Filename:   ToolBar.C                        */
  17.  
  18. /*  Version:   2                            */
  19. /*  Created:   1995-03-07                        */
  20. /*  Revised:   1995-03-09                        */
  21.  
  22. /* Routines:   static VOID CalcSize(PRECTL prcl);            */
  23. /*           MRESULT EXPENTRY    ToolBarWndProc(HWND hWnd, ULONG    msg,    */
  24. /*                           MPARAM mp1, MPARAM mp2);    */
  25.  
  26. /************************************************************************/
  27. /************************************************************************/
  28. /************************************************************************/
  29. /* DISCLAIMER OF WARRANTIES:                        */
  30. /* -------------------------                        */
  31. /* The following [enclosed] code is sample code    created    by IBM        */
  32. /* Corporation and Prominare Inc.  This    sample code is not part    of any    */
  33. /* standard IBM    product    and is provided    to you solely for the purpose    */
  34. /* of assisting    you in the development of your applications.  The code    */
  35. /* is provided "AS IS",    without    warranty of any    kind.  Neither IBM nor    */
  36. /* Prominare shall be liable for any damages arising out of your    */
  37. /* use of the sample code, even    if they    have been advised of the    */
  38. /* possibility of such damages.                        */
  39. /************************************************************************/
  40. /************************************************************************/
  41. /************************************************************************/
  42. /*               D I S C L A I M E R                */
  43. /* This    code is    provided on an as is basis with    no implied support.    */
  44. /* It should be    considered freeware that cannot    be rebundled as        */
  45. /* part    of a larger "*ware" offering without our consent.        */
  46. /************************************************************************/
  47. /************************************************************************/
  48. /************************************************************************/
  49.  
  50. /* Copyright ╕ International Business Machines Corp., 1995.        */
  51. /* Copyright ╕ 1995  Prominare Inc.  All Rights    Reserved.        */
  52.  
  53. /* --------------------------------------------------------------------    */
  54.  
  55. static SWP aswp[4];           /* Size/Window Position Array    */
  56. static POINTL aptlShade[5];       /* Shadow Points            */
  57.  
  58. #define    ASWP_FONTLABEL       0
  59. #define    ASWP_FONTNAMES       1
  60. #define    ASWP_SIZELABEL       2
  61. #define    ASWP_FONTSIZES       3
  62.  
  63. static VOID CalcSize(PRECTL prcl);
  64.  
  65. #pragma    subtitle("   Shadowed Frame DLL - Control Window Procedure")
  66. #pragma    page ( )
  67.  
  68. /* --- CalcSize    ---------------------------------------    [ Private ] ---    */
  69. /*                                    */
  70. /*     This function is    used to    calculate the sizes and    positions    */
  71. /*     of the various elements that are    used to    make up    the font    */
  72. /*     selection combo boxes within the    tool bar.            */
  73. /*                                    */
  74. /*     Upon Entry:                            */
  75. /*                                    */
  76. /*     PRECTL     prcl; = Control Rectangle Pointer            */
  77. /*                                    */
  78. /*     Upon Exit:                            */
  79. /*                                    */
  80. /*     Nothing                                */
  81. /*                                    */
  82. /* --------------------------------------------------------------------    */
  83.  
  84. static VOID CalcSize(PRECTL prcl)
  85.  
  86. {
  87.  
  88. WinQueryWindowPos(aswp[ASWP_FONTSIZES].hwnd, &aswp[ASWP_FONTSIZES]);
  89.  
  90. aswp[ASWP_FONTSIZES].x = (prcl->xRight - prcl->xLeft) -    aswp[ASWP_FONTSIZES].cx    - 10L;
  91. aswp[ASWP_SIZELABEL].x = aswp[ASWP_FONTSIZES].x    - aswp[ASWP_SIZELABEL].cx - 5L;
  92.  
  93. WinQueryWindowPos(aswp[ASWP_FONTLABEL].hwnd, &aswp[ASWP_FONTLABEL]);
  94. aswp[ASWP_FONTNAMES].x = aswp[ASWP_FONTLABEL].x    + aswp[ASWP_FONTLABEL].cx + 5L;
  95. aswp[ASWP_FONTNAMES].cx    = (aswp[ASWP_SIZELABEL].x - 5L)    - aswp[ASWP_FONTNAMES].x;
  96.  
  97. WinSetMultWindowPos(hAB, aswp, 4UL);
  98.  
  99. }
  100. #pragma    subtitle("   Client Window - Client Window Procedure")
  101. #pragma    page( )
  102.  
  103. /* --- ToolBarWndProc ---------------------------------    [ Private ] ---    */
  104. /*                                    */
  105. /*     This function is    used to    process    the messages sent to the    */
  106. /*     applications client window.                    */
  107. /*                                    */
  108. /*     Upon Entry:                            */
  109. /*                                    */
  110. /*     HWND   hWnd; = Window Handle                    */
  111. /*     ULONG  msg;  = PM Message                    */
  112. /*     MPARAM mp1;  = Message Parameter    1                */
  113. /*     MPARAM mp2;  = Message Parameter    2                */
  114. /*                                    */
  115. /*     Upon Exit:                            */
  116. /*                                    */
  117. /*     ToolBarWndProc =    Message    Handling Result                */
  118. /*                                    */
  119. /* --------------------------------------------------------------------    */
  120.  
  121. MRESULT    EXPENTRY ToolBarWndProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  122.  
  123. {
  124. HDC           hdcPrinter;       /* Printer Device Context Handle    */
  125. HPS           hpsPrinter;       /* Presentation Space Handle        */
  126. RECTL           rcl;           /* Window Rectangle            */
  127. HPS           hPS;           /* Presentation Space Handle        */
  128. PCREATESTRUCT  pcrst;           /* Create Structure Pointer        */
  129. POINTL           ptl;           /* Display Point            */
  130. SIZEL           sizlPage;       /* Page Size    Holder            */
  131. FONTSEL           fselToolBar;       /* Tool Bar Font Selected        */
  132. register INT i;               /* Loop Counter            */
  133.  
  134. switch ( msg )
  135.    {
  136.             /* Window being    created, perform window        */
  137.             /* initialization                */
  138.    case    WM_CREATE :
  139.             /************************************************/
  140.             /* PDSGetTemplate is used to allow controls in    */
  141.             /* windows.  Do    not remove this    function if you    */
  142.             /* intend to include controls within the window.*/
  143.             /************************************************/
  144.  
  145.        PDSGetTemplate(hWnd, ID_TOOLBAR);
  146.  
  147.        for ( i = 0; i <    4; i++ )
  148.        WinQueryWindowPos(WinWindowFromID(hWnd, (ULONG)(IT_FONTLABEL    + i)), &aswp[i]);
  149.  
  150.        ptl.x = 0L;
  151.        ptl.y = 80L;
  152.        WinMapDlgPoints(HWND_DESKTOP, &ptl, 1UL,    TRUE);
  153.  
  154.                /* Adjust the size of the combo box and cause it    */
  155.                /* to be    resized    to its new size            */
  156.  
  157.        aswp[ASWP_FONTSIZES].y  = (aswp[ASWP_FONTNAMES].y  -= ptl.y);
  158.        aswp[ASWP_FONTSIZES].cy = (aswp[ASWP_FONTNAMES].cy += ptl.y);
  159.  
  160.        aswp[ASWP_FONTLABEL].fl = aswp[ASWP_FONTLABEL].fl = SWP_MOVE;
  161.        aswp[ASWP_FONTNAMES].fl = aswp[ASWP_FONTSIZES].fl = SWP_SIZE | SWP_MOVE;
  162.  
  163.        WinSetMultWindowPos(WinQueryAnchorBlock(hWnd), aswp, 4UL);
  164.  
  165.        pcrst = (PCREATESTRUCT)PVOIDFROMMP(mp2);
  166.        rcl.xLeft   =\
  167.        rcl.yBottom = 0L;
  168.        rcl.xRight  = pcrst->cx;
  169.        rcl.yTop       = pcrst->cy;
  170.        if ( (pcrst->cx > 0L) &&    (pcrst->cy > 0L) )
  171.        CalcSize(&rcl);
  172.  
  173.        switch (    lSetFonts(WinWindowFromID(hWnd,    CBX_FONT)) )
  174.        {
  175.                /* Error    return:    bad HDC    for printer        */
  176.        case    1L :
  177.            WinMessageBox(HWND_DESKTOP, hWnd, "Printer Device Context could not be opened.",
  178.                  "Print Font Example", 0UL,    MB_OK |    MB_ICONHAND | MB_MOVEABLE);
  179.            return(MRFROMLONG(TRUE));
  180.  
  181.                /* Error    return:    bad HPS    for printer        */
  182.        case    2L :
  183.            WinMessageBox(HWND_DESKTOP, hWnd, "Printer Presentation Space could not be created.",
  184.                  "Print Font Example", 0UL,    MB_OK |    MB_ICONHAND | MB_MOVEABLE);
  185.            return(MRFROMLONG(TRUE));
  186.  
  187.                /* Error    return:    no error, fonts    set in combo    */
  188.        default :
  189.            break;
  190.        }
  191.  
  192.        break;
  193.                /* Size of control changing, reset the display    */
  194.                /* points of the    line                */
  195.    case    WM_SIZE    :
  196.        if ( ((LONG)(SHORT)SHORT1FROMMP(mp2) > 0L) &&
  197.         ((LONG)(SHORT)SHORT2FROMMP(mp2) > 0L) )
  198.        {
  199.        WinQueryWindowRect(hWnd, &rcl);
  200.        CalcSize(&rcl);
  201.  
  202.                /* Set the new width and    height of the window    */
  203.  
  204.        aptlShade[1].y = aptlShade[2].y = SHORT2FROMMP(mp2) - 1L;
  205.        aptlShade[2].x = aptlShade[3].x = SHORT1FROMMP(mp2) - 1L;
  206.        }
  207.        break;
  208.             /* Process key press from keyboard        */
  209.    case    WM_CHAR    :
  210.             /************************************************/
  211.             /* PDSKeyProc is used to allow controls    in    */
  212.             /* windows.  Do    not remove this    function if you    */
  213.             /* intend to include controls within the window.*/
  214.             /************************************************/
  215.  
  216.     return(PDSKeyProc(hWnd,    msg, mp1, mp2));
  217.  
  218.             /* Process control selections            */
  219.    case    WM_CONTROL :
  220.        switch (    SHORT2FROMMP(mp1) )
  221.        {
  222.                /* Process message combo    box entry selections    */
  223.  
  224.        case    CBN_LBSELECT :
  225.            switch (    SHORT1FROMMP(mp1) )
  226.            {
  227.            case    CBX_FONT :
  228.                SetFontSize(WinWindowFromID(hWnd, CBX_FONT),
  229.                    WinWindowFromID(hWnd, CBX_FONTSIZE));
  230.                if ( fQuerySelectedFont(WinWindowFromID(hWnd, CBX_FONT),
  231.                            WinWindowFromID(hWnd, CBX_FONTSIZE), &fselToolBar) &&
  232.                 ((hdcPrinter = PrnOpenInfoDC(&prn, "PM_Q_STD")) != (HDC)NULL) &&
  233.                 hpsPrint )
  234.                {
  235.                sizlPage.cx = sizlPage.cy = 0L;
  236.                DeleteFontCache(hpsPrint, &fcache);
  237.                BuildFontCache(hpsPrint,
  238.                       hpsPrinter = GpiCreatePS(hAB,    hdcPrinter, &sizlPage,
  239.                                    PU_TWIPS | GPIF_DEFAULT | GPIT_MICRO    | GPIA_ASSOC),
  240.                       hdcPrinter,
  241.                       fselToolBar.szFacename, fselToolBar.lNominalPointSize,
  242.                       &fcache);
  243.                BuildFontCache(hpsPrint, hpsPrinter,    hdcPrinter,
  244.                       fselToolBar.szFacename, 100L,
  245.                       &fcacheScale);
  246.                GpiAssociate(hpsPrinter, (HDC)NULL);
  247.                GpiDestroyPS(hpsPrinter);
  248.                DevCloseDC(hdcPrinter);
  249.  
  250.                WinInvalidateRect(hwndPrnSetup, (PRECTL)NULL, FALSE);
  251.                }
  252.                break;
  253.  
  254.            case    CBX_FONTSIZE :
  255.                if ( fQuerySelectedFont(WinWindowFromID(hWnd, CBX_FONT),
  256.                            WinWindowFromID(hWnd, CBX_FONTSIZE), &fselToolBar) &&
  257.                 ((hdcPrinter = PrnOpenInfoDC(&prn, "PM_Q_STD")) != (HDC)NULL) &&
  258.                 hpsPrint )
  259.                {
  260.                sizlPage.cx = sizlPage.cy = 0L;
  261.                DeleteFontCache(hpsPrint, &fcache);
  262.                BuildFontCache(hpsPrint,
  263.                       hpsPrinter = GpiCreatePS(hAB,    hdcPrinter, &sizlPage,
  264.                                    PU_TWIPS | GPIF_DEFAULT | GPIT_MICRO    | GPIA_ASSOC),
  265.                       hdcPrinter,
  266.                       fselToolBar.szFacename, fselToolBar.lNominalPointSize,
  267.                       &fcache);
  268.                GpiAssociate(hpsPrinter, (HDC)NULL);
  269.                GpiDestroyPS(hpsPrinter);
  270.                DevCloseDC(hdcPrinter);
  271.  
  272.                WinInvalidateRect(hwndPrnSetup, (PRECTL)NULL, FALSE);
  273.                }
  274.                break;
  275.            }
  276.            break;
  277.        }
  278.        break;
  279.             /* Erase window    background            */
  280.  
  281.    case    WM_ERASEBACKGROUND :
  282.        WinQueryWindowRect(hWnd,    &rcl);
  283.        WinMapWindowPoints(hWnd,    hwndToolBarFrame, (PPOINTL)(PVOID)&rcl,    2L);
  284.        GpiCreateLogColorTable((HPS)mp1,    0L, LCOLF_RGB, 0L, 0L, (PLONG)NULL);
  285.        WinFillRect((HPS)mp1, &rcl, RGBCLR_DIALOGBACKGROUND);
  286.        break;
  287.             /* Paint client    window                */
  288.    case    WM_PAINT :
  289.                /* Get the presentation space and set the first    */
  290.                /* outline edge colour to white            */
  291.  
  292.        GpiCreateLogColorTable(hPS = WinBeginPaint(hWnd,    (HPS)NULL, (PRECTL)NULL),
  293.                   0L, LCOLF_RGB, 0L, 0L, (PLONG)NULL);
  294.        GpiSetColor(hPS,    RGB_WHITE);
  295.  
  296.                /* Set up the starting position and start    */
  297.                /* drawing the lighted edge of the window    */
  298.  
  299.        GpiMove(hPS, aptlShade);
  300.        GpiPolyLine(hPS,    2L, &aptlShade[1]);
  301.  
  302.                /* Set the shaded edge colour and start the    */
  303.                /* drawing of the shaded    edge of    the window    */
  304.  
  305.        GpiSetColor(hPS,    RGBCLR_SHADOW);
  306.        GpiPolyLine(hPS,    2L, &aptlShade[3]);
  307.  
  308.                /* Release the presentation space        */
  309.        WinEndPaint(hPS);
  310.        break;
  311.  
  312.             /* Default message processing            */
  313.    default :
  314.        return(WinDefWindowProc(hWnd, msg, mp1, mp2));
  315.    }
  316. return(0L);
  317. }
  318.