Ignore:
Timestamp:
Dec 5, 2002, 9:36:28 PM (23 years ago)
Author:
umoeller
Message:

New toolbar control.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/comctl.c

    r229 r232  
    9090#define INCL_WINSTDCNR
    9191#define INCL_WINENTRYFIELDS
     92#define INCL_WINSHELLDATA
    9293
    9394#define INCL_GPIPRIMITIVES
     
    112113#include "helpers\linklist.h"
    113114#include "helpers\winh.h"
     115#include "helpers\standards.h"
    114116
    115117#include "helpers\comctl.h"
    116118
    117119#pragma hdrstop
     120
     121/* ******************************************************************
     122 *
     123 *   Shared stuff
     124 *
     125 ********************************************************************/
     126
     127/*
     128 *@@ ctlSendWmControl:
     129 *      little helper that post a WM_CONTROL message to
     130 *      a control's owner.
     131 *
     132 *@@added V1.0.1 (2002-11-30) [umoeller]
     133 */
     134
     135MRESULT ctlSendWmControl(HWND hwndControl,     // in: control who's posting
     136                         USHORT usCode,        // in: code for SHORT2FROMMP(mp1)
     137                         MPARAM mp2)           // in: mp2 from WM_CONTROL
     138{
     139    HWND hwndOwner;
     140
     141    if (hwndOwner = WinQueryWindow(hwndControl, QW_OWNER))
     142        return WinSendMsg(hwndOwner,
     143                          WM_CONTROL,
     144                          MPFROM2SHORT(WinQueryWindowUShort(hwndControl, QWS_ID),
     145                                       usCode),
     146                          mp2);
     147
     148    return NULL;
     149}
     150
     151/*
     152 *@@ ctlPostWmControl:
     153 *      little helper that post a WM_CONTROL message to
     154 *      a control's owner.
     155 *
     156 *@@added V1.0.1 (2002-11-30) [umoeller]
     157 */
     158
     159BOOL ctlPostWmControl(HWND hwndControl,     // in: control who's posting
     160                      USHORT usCode,        // in: code for SHORT2FROMMP(mp1)
     161                      MPARAM mp2)           // in: mp2 from WM_CONTROL
     162{
     163    HWND hwndOwner;
     164
     165    if (hwndOwner = WinQueryWindow(hwndControl, QW_OWNER))
     166        return WinPostMsg(hwndOwner,
     167                          WM_CONTROL,
     168                          MPFROM2SHORT(WinQueryWindowUShort(hwndControl, QWS_ID),
     169                                       usCode),
     170                          mp2);
     171
     172    return FALSE;
     173}
     174
     175/*
     176 *@@ ctlInitDWD:
     177 *      ininitializes the DEFWINDATA struct for the
     178 *      given window. This must be called in WM_CREATE
     179 *      of a window proc if it intends to use
     180 *      ctlDefWindowProc as its default window procedure.
     181 *
     182 *@@added V1.0.1 (2002-11-30) [umoeller]
     183 */
     184
     185VOID ctlInitDWD(HWND hwnd,
     186                MPARAM mp2,
     187                PDEFWINDATA pdwd,
     188                PFNWP pDefWindowProc,
     189                const SYSCOLORSET *pSysColorSet)
     190{
     191    pdwd->hwnd = hwnd;
     192    pdwd->szlWin.cx = ((PCREATESTRUCT)mp2)->cx;
     193    pdwd->szlWin.cy = ((PCREATESTRUCT)mp2)->cy;
     194    pdwd->hab = WinQueryAnchorBlock(hwnd);
     195    pdwd->pDefWindowProc = pDefWindowProc;
     196    pdwd->pSysColorSet = pSysColorSet;
     197
     198    ctlRefreshColors(pdwd);
     199}
     200
     201/*
     202 *@@ ctlRefreshColors:
     203 *
     204 *@@added V1.0.1 (2002-11-30) [umoeller]
     205 */
     206
     207VOID ctlRefreshColors(PDEFWINDATA pdwd)
     208{
     209    pdwd->lcolBackground = winhQueryPresColor2(pdwd->hwnd,
     210                                               PP_BACKGROUNDCOLOR,
     211                                               PP_BACKGROUNDCOLORINDEX,
     212                                               pdwd->pSysColorSet->fInheritPP,
     213                                               pdwd->pSysColorSet->lBackIndex);
     214    pdwd->lcolForeground = winhQueryPresColor2(pdwd->hwnd,
     215                                               PP_FOREGROUNDCOLOR,
     216                                               PP_FOREGROUNDCOLORINDEX,
     217                                               pdwd->pSysColorSet->fInheritPP,
     218                                               pdwd->pSysColorSet->lForeIndex);
     219}
     220
     221/*
     222 *@@ ctlDefWindowProc:
     223 *      replacement default window procedure for controls that
     224 *      have a custom window class and do not inherit from
     225 *      standard OS/2 controls.
     226 *
     227 *      If a window proc wishes to use this, it must allocate
     228 *      its own private window data in WM_CREATE (preferrably in
     229 *      QWL_USER + 1) and have room for a DEFWINDATA struct in
     230 *      there. It must call ctlInitDWD in WM_CREATE also which
     231 *      initializes that structure. It can then safely pass
     232 *      messages to this function.
     233 *
     234 *@@added V1.0.1 (2002-11-30) [umoeller]
     235 */
     236
     237MRESULT ctlDefWindowProc(PDEFWINDATA pdwd, ULONG msg, MPARAM mp1, MPARAM mp2)
     238{
     239    MRESULT mrc = 0;
     240
     241    switch (msg)
     242    {
     243        case WM_SYSCOLORCHANGE:
     244        case WM_PRESPARAMCHANGED:
     245            ctlRefreshColors(pdwd);
     246        break;
     247
     248        default:
     249            mrc = pdwd->pDefWindowProc(pdwd->hwnd, msg, mp1, mp2);
     250    }
     251
     252    return mrc;
     253}
    118254
    119255/* ******************************************************************
     
    131267 *
    132268 *@@added V0.9.20 (2002-08-10) [umoeller]
     269 *@@changed V1.0.1 (2002-11-30) [umoeller]: added SEPS_VERTICAL
    133270 */
    134271
     
    150287                gpihSwitchToRGB(hps);
    151288
    152                 GpiSetColor(hps, WinQuerySysColor(HWND_DESKTOP, SYSCLR_BUTTONLIGHT, 0));
    153 
    154                 ptl.x = rcl.xLeft;
    155                 ptl.y = (rcl.yTop - rcl.yBottom) / 2 - 1;
    156                 GpiMove(hps, &ptl);
    157                 ptl.x = rcl.xRight;
    158                 GpiLine(hps, &ptl);
    159 
    160                 GpiSetColor(hps, WinQuerySysColor(HWND_DESKTOP, SYSCLR_BUTTONDARK, 0));
    161 
    162                 ptl.x = rcl.xLeft;
    163                 ++ptl.y;
    164                 GpiMove(hps, &ptl);
    165                 ptl.x = rcl.xRight;
    166                 GpiLine(hps, &ptl);
     289                WinFillRect(hps,
     290                            &rcl,
     291                            winhQueryPresColor2(hwnd,
     292                                                PP_BACKGROUNDCOLOR,
     293                                                PP_BACKGROUNDCOLORINDEX,
     294                                                TRUE,
     295                                                SYSCLR_WINDOW));
     296
     297                if (WinQueryWindowULong(hwnd, QWL_STYLE) & SEPS_VERTICAL)
     298                {
     299                    GpiSetColor(hps, G_lcol3DDark);
     300
     301                    ptl.x = (rcl.xRight - rcl.xLeft) / 2 - 1;
     302                    ptl.y = rcl.yBottom;
     303                    GpiMove(hps, &ptl);
     304                    ptl.y = rcl.yTop;
     305                    GpiLine(hps, &ptl);
     306
     307                    GpiSetColor(hps, G_lcol3DLight);
     308
     309                    ptl.y = rcl.yBottom;
     310                    ++ptl.x;
     311                    GpiMove(hps, &ptl);
     312                    ptl.y = rcl.yTop;
     313                    GpiLine(hps, &ptl);
     314                }
     315                else
     316                {
     317                    GpiSetColor(hps, G_lcol3DLight);
     318
     319                    ptl.x = rcl.xLeft;
     320                    ptl.y = (rcl.yTop - rcl.yBottom) / 2 - 1;
     321                    GpiMove(hps, &ptl);
     322                    ptl.x = rcl.xRight;
     323                    GpiLine(hps, &ptl);
     324
     325                    GpiSetColor(hps, G_lcol3DDark);
     326
     327                    ptl.x = rcl.xLeft;
     328                    ++ptl.y;
     329                    GpiMove(hps, &ptl);
     330                    ptl.x = rcl.xRight;
     331                    GpiLine(hps, &ptl);
     332                }
    167333
    168334                WinEndPaint(hps);
     
    179345
    180346/*
    181  *@@ ctlMakeSeparatorLine:
    182  *      turns the given static control into a 3D separator line.
     347 *@@ ctlRegisterSeparatorLine:
     348 *      registers the separator line control, which is a dull
     349 *      static displaying a 3D line for use as a separator
     350 *      in dialogs.
     351 *
     352 *      In addition to the standard WS_* styles, the control
     353 *      supports the SEPS_VERTICAL style bit. If set, the
     354 *      separator is vertical; if not, it is horizontal.
    183355 *
    184356 *@@added V1.0.0 (2002-08-12) [umoeller]
     
    195367
    196368        return WinRegisterClass(hab,
    197                                 WC_SEPARATORLINE,
     369                                WC_CCTL_SEPARATOR,
    198370                                fnwpSeparatorLine,
    199371                                (ciStatic.flClassStyle & ~CS_PUBLIC),
     
    203375
    204376    return FALSE;
    205 }
    206 
    207 /* ******************************************************************
    208  *
    209  *   "XButton" control
    210  *
    211  ********************************************************************/
    212 
    213 /*
    214  *@@ ctlPaintXButton:
    215  *      paints an X-button control. Can be called externally
    216  *      for just painting a button even if this is not really
    217  *      a window.
    218  *
    219  *      WARNING: this is work in progress and will change into
    220  *      the future. Eventually this will turn into a full
    221  *      button control replacement.
    222  *
    223  *@@added V0.9.13 (2001-06-21) [umoeller]
    224  *@@changed V0.9.16 (2001-10-24) [umoeller]: fixed wrong hatch color and paint offset
    225  *@@changed V0.9.16 (2001-10-28) [umoeller]: added bitmap support, fixed bad clip rectangle
    226  *@@changed V0.9.20 (2002-08-04) [umoeller]: fixed button offset, depressed color
    227  */
    228 
    229 VOID ctlPaintXButton(HPS hps,               // in: presentation space (RGB mode)
    230                      ULONG fl,              // in: XBF_* flags
    231                      PXBUTTONDATA pxbd)     // in: button data
    232 {
    233     ULONG   ulBorder = 0,
    234             cx,
    235             cy,
    236             ulOfs = 0;
    237     LONG    lLeft,
    238             lRight,
    239             lColorMiddle = pxbd->lMiddle;
    240     RECTL   rclWin;
    241 
    242     memcpy(&rclWin, &pxbd->rcl, sizeof(RECTL));
    243 
    244     if (0 == (fl & XBF_FLAT))
    245         ulBorder = 2;
    246 
    247     gpihSwitchToRGB(hps);
    248 
    249     if (fl & XBF_PRESSED)
    250     {
    251         // paint button "down":
    252         lLeft = pxbd->lcol3DDark;
    253         lRight = pxbd->lcol3DLight;
    254         // add offset for icon painting at the bottom
    255         ulOfs += 1;
    256         if (ulBorder == 0)
    257             ulBorder = 1;
    258 
    259         // make the depressed color darker
    260         // V0.9.20 (2002-07-31) [umoeller]
    261         gpihManipulateRGB(&lColorMiddle,
    262                           .95);
    263     }
    264     else
    265     {
    266         lLeft = pxbd->lcol3DLight;
    267         lRight = pxbd->lcol3DDark;
    268     }
    269 
    270     if (ulBorder)
    271     {
    272         // button border:
    273         // now paint button frame
    274 
    275         // make rcl inclusive
    276         rclWin.xRight--;
    277         rclWin.yTop--;
    278         gpihDraw3DFrame(hps,
    279                         &rclWin,        // inclusive
    280                         ulBorder,
    281                         lLeft,
    282                         lRight);
    283 
    284         // now paint button middle
    285         rclWin.xLeft += ulBorder;
    286         rclWin.yBottom += ulBorder;
    287         rclWin.xRight -= ulBorder - 1;  // make exclusive again
    288         rclWin.yTop -= ulBorder - 1;    // make exclusive again
    289     }
    290 
    291     if (fl & XBF_BACKGROUND)
    292         WinFillRect(hps,
    293                     &rclWin,        // exclusive
    294                     lColorMiddle);
    295 
    296     // get icon
    297     if (pxbd->hptr)
    298     {
    299         // calculate x and y to be centered in rectangle
    300         POINTL  ptl;
    301 
    302         cx = rclWin.xRight - rclWin.xLeft;
    303         cy = rclWin.yTop - rclWin.yBottom;
    304 
    305         ptl.x = rclWin.xLeft + ((cx - pxbd->cxIconOrBitmap) / 2);
    306         ptl.y = rclWin.yBottom + ((cy - pxbd->cyIconOrBitmap) / 2);
    307 
    308         if (fl & XBF_INUSE)
    309         {
    310             // caller wants in-use (hatched) emphasis:
    311             // draw a box then
    312             POINTL ptl2;
    313             ptl2.x = ptl.x - 2;
    314             ptl2.y = ptl.y - 2;
    315             GpiMove(hps,
    316                     &ptl2);     // &ptl
    317                                 // duh, typo V0.9.16 (2001-10-24) [umoeller]
    318             GpiSetPattern(hps, PATSYM_DIAG1);
    319             GpiSetColor(hps, RGBCOL_BLACK);     // V0.9.16 (2001-10-24) [umoeller]
    320             ptl2.x = ptl.x + pxbd->cxIconOrBitmap + 1; // inclusive!
    321             ptl2.y = ptl.y + pxbd->cyIconOrBitmap + 1; // inclusive!
    322             GpiBox(hps,
    323                    DRO_FILL,
    324                    &ptl2,
    325                    0,
    326                    0);
    327         }
    328 
    329         // now paint icon
    330 
    331         // make rcl inclusive           // V0.9.16 (2001-10-28) [umoeller]
    332         rclWin.xRight--;
    333         rclWin.yTop--;
    334         GpiIntersectClipRectangle(hps,
    335                                   &rclWin);    // inclusive!
    336 
    337         // center this in remaining rectl
    338         ptl.x += ulOfs;
    339         ptl.y -= ulOfs;
    340         if (fl & XBF_BITMAP)
    341             // V0.9.16 (2001-10-28) [umoeller]
    342             WinDrawBitmap(hps,
    343                           pxbd->hptr,           // a bitmap really
    344                           NULL,                 // entire bitmap
    345                           &ptl,
    346                           0,
    347                           0,
    348                           DBM_NORMAL);
    349         else
    350             WinDrawPointer(hps,
    351                            // center this in remaining rectl
    352                            ptl.x, //  + ulOfs,
    353                            ptl.y, //  - ulOfs,
    354                            pxbd->hptr,
    355                            DP_MINI);
    356     }
    357377}
    358378
     
    10971117            WinQueryWindowRect(hwndStatic, &pa->rclIcon);
    10981118            pa->OldStaticProc = WinSubclassWindow(hwndStatic, ctl_fnwpBitmapStatic);
    1099             pa->szlIcon.cx = WinQuerySysValue(HWND_DESKTOP, SV_CXICON);
    1100             pa->szlIcon.cy = WinQuerySysValue(HWND_DESKTOP, SV_CYICON);
     1119            pa->szlIcon.cx = G_cxIcon;
     1120            pa->szlIcon.cy = G_cyIcon;
    11011121        }
    11021122    }
     
    16281648                    // doesn't send any notifications, we
    16291649                    // use EN_CHANGED
    1630                     WinSendMsg(WinQueryWindow(hwndStatic, QW_OWNER),
    1631                                WM_CONTROL,
    1632                                MPFROM2SHORT(WinQueryWindowUShort(hwndStatic, QWS_ID),
    1633                                             EN_CHANGE),
    1634                                (MPARAM)hwndStatic);
     1650                    ctlSendWmControl(hwndStatic,
     1651                                     EN_CHANGE,
     1652                                     (MPARAM)hwndStatic);
    16351653                break;
    16361654            }
Note: See TracChangeset for help on using the changeset viewer.