Ignore:
Timestamp:
Mar 6, 2002, 6:34:48 PM (23 years ago)
Author:
umoeller
Message:

misc fixes

File:
1 edited

Legend:

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

    r142 r146  
    187187
    188188/*
    189  *@@ CHECKBOXCNROWNER:
    190  *
    191  *
    192  *@@added V0.9.0 (99-11-28) [umoeller]
    193  */
    194 
    195 typedef struct _CHECKBOXCNROWNER
    196 {
    197     HWND        hwndCnr;            // container window handle
    198     USHORT      usCnrID;            // container item ID
    199     HWND        hwndOwner;          // owner of that container
    200     PFNWP       pfnwpCnrOrig;       // original window proc of hwndCnr
    201     PFNWP       pfnwpOwnerOrig;     // original window proc of hwndOwner
    202 
    203     HAB         habCnr;
    204 
    205     PCHECKBOXRECORDCORE preccClicked;   // != NULL if mb1 is currently down on recc
    206     PCHECKBOXRECORDCORE preccSpace;     // != NULL if space key is down with recc
    207     RECTL       rclReccClicked;     // rectangle of that record
    208 } CHECKBOXCNROWNER, *PCHECKBOXCNROWNER;
    209 
    210 /*
    211189 *@@ CnrCheckboxClicked:
    212190 *
     
    249227
    250228/*
    251  *@@ ctl_fnwpSubclCheckboxCnr:
     229 *@@ ctlDrawCheckBoxRecord:
     230 *
     231 *@@added V0.9.18 (2002-03-03) [umoeller]
     232 */
     233
     234MRESULT ctlDrawCheckBoxRecord(MPARAM mp2)
     235{
     236    MRESULT mrc = 0;
     237
     238    // get generic DRAWITEM structure
     239    POWNERITEM poi = (POWNERITEM)mp2;
     240
     241    // _Pmpf(("WM_DRAWITEM poi->idItem %d", poi->idItem));
     242
     243    // check if we're to draw the icon
     244    // (and not the text)
     245    if (poi->idItem == CMA_ICON)
     246    {
     247        PCNRDRAWITEMINFO pcdi = (PCNRDRAWITEMINFO)poi->hItem;
     248        PCHECKBOXRECORDCORE precc = (PCHECKBOXRECORDCORE)pcdi->pRecord;
     249
     250        if (precc->ulStyle & WS_VISIBLE)
     251        {
     252            USHORT usRow,
     253                   usColumn;
     254
     255            switch (precc->usCheckState)
     256            {
     257                case 0: // unchecked
     258                    usRow = 2;
     259                    usColumn = 0;
     260                break;
     261
     262                case 1: // checked
     263                    usRow = 2;
     264                    usColumn = 1;
     265                break;
     266
     267                case 2: // indeterminate
     268                    usRow = 0;
     269                    usColumn = 1;
     270                break;
     271            }
     272
     273            if (precc->ulStyle & BS_BITMAP)
     274                // button currently depressed:
     275                // add two to column
     276                usColumn += 2;
     277
     278            ctlDrawCheckbox(poi->hps,
     279                            poi->rclItem.xLeft,
     280                            poi->rclItem.yBottom,
     281                            usRow,
     282                            usColumn,
     283                            // halftoned?
     284                            ((precc->recc.flRecordAttr & CRA_DISABLED) != 0));
     285            mrc = (MPARAM)FALSE;
     286                        // we still need the cnr to draw the
     287                        // emphasis
     288        }
     289        else
     290            mrc = (MPARAM)TRUE; // tell cnr that we've drawn the item;
     291                    // don't even draw emphasis
     292    }
     293    else if (poi->idItem == CMA_TEXT)
     294    {
     295        // for text, buttons etc.:
     296        PCNRDRAWITEMINFO pcdi = (PCNRDRAWITEMINFO)poi->hItem;
     297        PCHECKBOXRECORDCORE precc = (PCHECKBOXRECORDCORE)pcdi->pRecord;
     298        if (precc->recc.flRecordAttr & CRA_DISABLED)
     299        {
     300            RECTL rcl2;
     301            LONG lBackground, lForeground;
     302            ULONG flCmd = DT_LEFT | DT_TOP | DT_ERASERECT;
     303            if ((pcdi->pRecord->flRecordAttr) & CRA_SELECTED)
     304            {
     305                // disabled and selected:
     306                lBackground = WinQuerySysColor(HWND_DESKTOP,
     307                                               SYSCLR_SHADOWTEXT, 0);
     308                lForeground = winhQueryPresColor(poi->hwnd,
     309                                                 PP_BACKGROUNDCOLOR,
     310                                                 FALSE, // no inherit
     311                                                 SYSCLR_WINDOW);
     312            }
     313            else
     314            {
     315                // disabled and not selected:
     316                lBackground = winhQueryPresColor(poi->hwnd,
     317                                                 PP_BACKGROUNDCOLOR,
     318                                                 FALSE,
     319                                                 SYSCLR_WINDOW);
     320                lForeground = winhQueryPresColor(poi->hwnd,
     321                                                 PP_FOREGROUNDCOLOR,
     322                                                 FALSE, // no inherit
     323                                                 SYSCLR_WINDOWTEXT);
     324                flCmd |= DT_HALFTONE;
     325            }
     326
     327            // _Pmpf(("back: 0x%lX, fore: 0x%lX", lBackground, lForeground));
     328
     329            GpiCreateLogColorTable(poi->hps, 0, LCOLF_RGB, 0, 0, NULL);
     330            GpiSetBackColor(poi->hps, lBackground);
     331            GpiSetColor(poi->hps, lForeground);
     332
     333            memcpy(&rcl2, &(poi->rclItem), sizeof(rcl2));
     334
     335            winhDrawFormattedText(poi->hps,
     336                                  &rcl2,
     337                                  precc->recc.pszTree,
     338                                  flCmd);
     339            mrc = (MPARAM)TRUE;
     340        }
     341        else
     342            // tell cnr to draw the item
     343            mrc = (MPARAM)FALSE;
     344    }
     345    else
     346        // tell cnr to draw the item
     347        mrc = (MPARAM)FALSE;
     348
     349    return mrc;
     350}
     351
     352/*
     353 *@@ fnwpSubclCheckboxCnr:
    252354 *      window proc for subclassed containers.
    253355 *      See ctlMakeCheckboxContainer for details.
    254356 *
    255357 *@@added V0.9.0 (99-11-29) [umoeller]
    256  */
    257 
    258 MRESULT EXPENTRY ctl_fnwpSubclCheckboxCnr(HWND hwndCnr, ULONG msg, MPARAM mp1, MPARAM mp2)
     358 *@@changed V0.9.18 (2002-03-03) [umoeller]: fixed bad orig win msg, other optimizations
     359 */
     360
     361static MRESULT EXPENTRY fnwpSubclCheckboxCnr(HWND hwndCnr, ULONG msg, MPARAM mp1, MPARAM mp2)
    259362{
    260363    MRESULT             mrc = 0;
     
    270373            if (pcbco->hwndCnr == hwndCnr)
    271374            {
    272                 pfnwpOrig = pcbco->pfnwpOwnerOrig;
     375                pfnwpOrig = pcbco->pfnwpCnrOrig; // fixed V0.9.18 (2002-03-03) [umoeller]
    273376                break;
    274377            }
     
    314417                mrc = pfnwpOrig(hwndCnr, msg, mp1, mp2);
    315418                        // apperently, the cnr captures the mouse
    316             break; }
     419            }
     420            break;
    317421
    318422            case WM_MOUSEMOVE:
     
    438542
    439543                mrc = pfnwpOrig(hwndCnr, msg, mp1, mp2);
    440             break; }
     544            }
     545            break;
    441546
    442547            /*
     
    452557                if (WinRequestMutexSem(G_hmtxCnrOwnersList, 5000) == NO_ERROR)
    453558                {
     559                    if (WinIsWindow(pcbco->habCnr,
     560                                    pcbco->hwndOwner))
     561                        // un-subclass the owner
     562                        WinSubclassWindow(pcbco->hwndOwner,
     563                                          pcbco->pfnwpOwnerOrig);
     564
    454565                    lstRemoveItem(G_pllCnrOwners, pcbco);
     566
    455567                    if (lstCountItems(G_pllCnrOwners) == 0)
    456568                    {
     
    475587
    476588/*
    477  *@@ ctl_fnwpSubclCheckboxCnrOwner:
     589 *@@ fnwpSubclCheckboxCnrOwner:
    478590 *      window proc for subclassed container owners.
    479591 *      See ctlMakeCheckboxContainer for details.
     
    482594 */
    483595
    484 MRESULT EXPENTRY ctl_fnwpSubclCheckboxCnrOwner(HWND hwndOwner, ULONG msg, MPARAM mp1, MPARAM mp2)
     596static MRESULT EXPENTRY fnwpSubclCheckboxCnrOwner(HWND hwndOwner, ULONG msg, MPARAM mp1, MPARAM mp2)
    485597{
    486598    MRESULT             mrc = 0;
     
    531643                                                   precc,
    532644                                                   TRUE);
    533                         break; }
     645                        }
     646                        break;
    534647                    }
    535648                }
    536649
    537650                mrc = pfnwpOrig(hwndOwner, msg, mp1, mp2);
    538             break; }
     651            }
     652            break;
    539653
    540654            /*
     
    546660            case WM_DRAWITEM:
    547661            {
    548                 USHORT usID = SHORT1FROMMP(mp1);
    549                 if (usID == pcbco->usCnrID)
    550                 {
    551                     // get generic DRAWITEM structure
    552                     POWNERITEM poi = (POWNERITEM)mp2;
    553 
    554                     // _Pmpf(("WM_DRAWITEM poi->idItem %d", poi->idItem));
    555 
    556                     // check if we're to draw the icon
    557                     // (and not the text)
    558                     if (poi->idItem == CMA_ICON)
    559                     {
    560                         PCNRDRAWITEMINFO pcdi = (PCNRDRAWITEMINFO)poi->hItem;
    561                         PCHECKBOXRECORDCORE precc = (PCHECKBOXRECORDCORE)pcdi->pRecord;
    562 
    563                         if (precc->ulStyle & WS_VISIBLE)
    564                         {
    565                             USHORT usRow,
    566                                    usColumn;
    567 
    568                             switch (precc->usCheckState)
    569                             {
    570                                 case 0: // unchecked
    571                                     usRow = 2;
    572                                     usColumn = 0;
    573                                 break;
    574 
    575                                 case 1: // checked
    576                                     usRow = 2;
    577                                     usColumn = 1;
    578                                 break;
    579 
    580                                 case 2: // indeterminate
    581                                     usRow = 0;
    582                                     usColumn = 1;
    583                                 break;
    584                             }
    585 
    586                             if (precc->ulStyle & BS_BITMAP)
    587                                 // button currently depressed:
    588                                 // add two to column
    589                                 usColumn += 2;
    590 
    591                             ctlDrawCheckbox(poi->hps,
    592                                             poi->rclItem.xLeft,
    593                                             poi->rclItem.yBottom,
    594                                             usRow,
    595                                             usColumn,
    596                                             // halftoned?
    597                                             ((precc->recc.flRecordAttr & CRA_DISABLED) != 0));
    598                             mrc = (MPARAM)FALSE;
    599                                         // we still need the cnr to draw the
    600                                         // emphasis
    601                         }
    602                         else
    603                             mrc = (MPARAM)TRUE; // tell cnr that we've drawn the item;
    604                                     // don't even draw emphasis
    605                     }
    606                     else if (poi->idItem == CMA_TEXT)
    607                     {
    608                         // for text, buttons etc.:
    609                         PCNRDRAWITEMINFO pcdi = (PCNRDRAWITEMINFO)poi->hItem;
    610                         PCHECKBOXRECORDCORE precc = (PCHECKBOXRECORDCORE)pcdi->pRecord;
    611                         if (precc->recc.flRecordAttr & CRA_DISABLED)
    612                         {
    613                             RECTL rcl2;
    614                             LONG lBackground, lForeground;
    615                             ULONG flCmd = DT_LEFT | DT_TOP | DT_ERASERECT;
    616                             if ((pcdi->pRecord->flRecordAttr) & CRA_SELECTED)
    617                             {
    618                                 // disabled and selected:
    619                                 lBackground = WinQuerySysColor(HWND_DESKTOP,
    620                                                                SYSCLR_SHADOWTEXT, 0);
    621                                 lForeground = winhQueryPresColor(poi->hwnd,
    622                                                                  PP_BACKGROUNDCOLOR,
    623                                                                  FALSE, // no inherit
    624                                                                  SYSCLR_WINDOW);
    625                             }
    626                             else
    627                             {
    628                                 // disabled and not selected:
    629                                 lBackground = winhQueryPresColor(poi->hwnd,
    630                                                                  PP_BACKGROUNDCOLOR,
    631                                                                  FALSE,
    632                                                                  SYSCLR_WINDOW);
    633                                 lForeground = winhQueryPresColor(poi->hwnd,
    634                                                                  PP_FOREGROUNDCOLOR,
    635                                                                  FALSE, // no inherit
    636                                                                  SYSCLR_WINDOWTEXT);
    637                                 flCmd |= DT_HALFTONE;
    638                             }
    639 
    640                             // _Pmpf(("back: 0x%lX, fore: 0x%lX", lBackground, lForeground));
    641 
    642                             GpiCreateLogColorTable(poi->hps, 0, LCOLF_RGB, 0, 0, NULL);
    643                             GpiSetBackColor(poi->hps, lBackground);
    644                             GpiSetColor(poi->hps, lForeground);
    645 
    646                             memcpy(&rcl2, &(poi->rclItem), sizeof(rcl2));
    647 
    648                             winhDrawFormattedText(poi->hps,
    649                                                   &rcl2,
    650                                                   precc->recc.pszTree,
    651                                                   flCmd);
    652                             mrc = (MPARAM)TRUE;
    653                         }
    654                         else
    655                             // tell cnr to draw the item
    656                             mrc = (MPARAM)FALSE;
    657                     }
    658                     else
    659                         // tell cnr to draw the item
    660                         mrc = (MPARAM)FALSE;
    661                 }
     662                if (SHORT1FROMMP(mp1) == pcbco->usCnrID)
     663                    mrc = ctlDrawCheckBoxRecord(mp2);
    662664                else
    663665                    mrc = pfnwpOrig(hwndOwner, msg, mp1, mp2);
    664             break; }
     666            }
     667            break;
    665668
    666669            default:
     
    672675
    673676    return (mrc);
     677}
     678
     679/*
     680 *@@ ctlInitCheckboxContainer:
     681 *
     682 *@@added V0.9.18 (2002-03-03) [umoeller]
     683 */
     684
     685VOID ctlInitCheckboxContainer(HWND hwndCnr)
     686{
     687    if (G_hbmCheckboxes == NULLHANDLE)
     688    {
     689        // first call:
     690        BITMAPINFOHEADER bmih;
     691        // load checkboxes bitmap
     692        G_hbmCheckboxes = WinGetSysBitmap(HWND_DESKTOP,
     693                                          SBMP_CHECKBOXES);
     694
     695        // _Pmpf(("hbmCheckboxes: 0x%lX", G_hbmCheckboxes));
     696
     697        // and compute size of one checkbox
     698        // (4 columns, 3 rows)
     699        GpiQueryBitmapParameters(G_hbmCheckboxes,
     700                                 &bmih);
     701        G_cxCheckbox = bmih.cx / 4;
     702    }
     703
     704    BEGIN_CNRINFO()
     705    {
     706        cnrhSetView(CV_TREE | CV_ICON | CA_TREELINE | CA_OWNERDRAW | CV_MINI);
     707        cnrhSetTreeIndent(20);
     708        cnrhSetBmpOrIconSize(G_cxCheckbox, G_cxCheckbox);
     709    } END_CNRINFO(hwndCnr);
     710}
     711
     712/*
     713 *@@ ctlSubclassCheckboxContainer:
     714 *
     715 *@@added V0.9.18 (2002-03-03) [umoeller]
     716 */
     717
     718PCHECKBOXCNROWNER ctlSubclassCheckboxContainer(HWND hwndCnr)
     719{
     720    PFNWP pfnwpCnrOrig;
     721    if (pfnwpCnrOrig = WinSubclassWindow(hwndCnr, fnwpSubclCheckboxCnr))
     722    {
     723        // cnr successfully subclassed:
     724        // create storage for both subclassed cnr and owner
     725        PCHECKBOXCNROWNER pcbco;
     726        if (pcbco = (PCHECKBOXCNROWNER)malloc(sizeof(CHECKBOXCNROWNER)))
     727        {
     728            memset(pcbco, 0, sizeof(CHECKBOXCNROWNER));
     729            pcbco->hwndCnr = hwndCnr;
     730            pcbco->usCnrID = WinQueryWindowUShort(hwndCnr, QWS_ID);
     731            pcbco->hwndOwner = WinQueryWindow(hwndCnr, QW_OWNER);
     732            pcbco->pfnwpCnrOrig = pfnwpCnrOrig;
     733
     734            pcbco->habCnr = WinQueryAnchorBlock(hwndCnr);
     735
     736            return (pcbco);
     737        }
     738    }
     739
     740    return NULL;
    674741}
    675742
     
    749816    if (hwndCnr)
    750817    {
    751         if (G_hbmCheckboxes == NULLHANDLE)
    752         {
    753             // first call:
    754             BITMAPINFOHEADER bmih;
    755             // load checkboxes bitmap
    756             G_hbmCheckboxes = WinGetSysBitmap(HWND_DESKTOP,
    757                                               SBMP_CHECKBOXES);
    758 
    759             // _Pmpf(("hbmCheckboxes: 0x%lX", G_hbmCheckboxes));
    760 
    761             // and compute size of one checkbox
    762             // (4 columns, 3 rows)
    763             GpiQueryBitmapParameters(G_hbmCheckboxes,
    764                                      &bmih);
    765             G_cxCheckbox = bmih.cx / 4;
    766         }
    767 
    768         BEGIN_CNRINFO()
    769         {
    770             cnrhSetView(CV_TREE | CV_ICON | CA_TREELINE | CA_OWNERDRAW | CV_MINI);
    771             cnrhSetTreeIndent(20);
    772             cnrhSetBmpOrIconSize(G_cxCheckbox, G_cxCheckbox);
    773             // cnrhSetSortFunc(fnCompareName);
    774         } END_CNRINFO(hwndCnr);
     818        ctlInitCheckboxContainer(hwndCnr);
    775819
    776820        if (    (hwndCnrOwner)
     
    779823        {
    780824            // subclass container owner
    781             PFNWP pfnwpOwnerOrig = WinSubclassWindow(hwndCnrOwner, ctl_fnwpSubclCheckboxCnrOwner);
     825            PFNWP pfnwpOwnerOrig = WinSubclassWindow(hwndCnrOwner, fnwpSubclCheckboxCnrOwner);
    782826            /* _Pmpf(("Subclassed hwnd 0x%lX: orig 0x%lX",
    783827                    hwndCnrOwner, pfnwpOwnerOrig)); */
     
    786830                // owner successfully subclassed:
    787831                // subclass container too
    788                 PFNWP pfnwpCnrOrig = WinSubclassWindow(hwndCnr, ctl_fnwpSubclCheckboxCnr);
    789                 if (pfnwpCnrOrig)
     832                PCHECKBOXCNROWNER pcbco;
     833                if (pcbco = ctlSubclassCheckboxContainer(hwndCnr))
    790834                {
    791                     // cnr successfully subclassed:
    792                     // create storage for both subclassed cnr and owner
    793                     PCHECKBOXCNROWNER pcbco = (PCHECKBOXCNROWNER)malloc(sizeof(CHECKBOXCNROWNER));
    794                     if (pcbco)
     835                    if (WinRequestMutexSem(G_hmtxCnrOwnersList, 5000) == NO_ERROR)
    795836                    {
    796                         memset(pcbco, 0, sizeof(CHECKBOXCNROWNER));
    797                         pcbco->hwndCnr = hwndCnr;
    798                         pcbco->usCnrID = usCnrID;
    799                         pcbco->hwndOwner = hwndCnrOwner;
    800                         pcbco->pfnwpCnrOrig = pfnwpCnrOrig;
     837                        lstAppendItem(G_pllCnrOwners, pcbco);
     838                        DosReleaseMutexSem(G_hmtxCnrOwnersList);
     839                        brc = TRUE;
     840
    801841                        pcbco->pfnwpOwnerOrig = pfnwpOwnerOrig;
    802 
    803                         pcbco->habCnr = WinQueryAnchorBlock(hwndCnr);
    804 
    805                         if (WinRequestMutexSem(G_hmtxCnrOwnersList, 5000) == NO_ERROR)
    806                         {
    807                             lstAppendItem(G_pllCnrOwners, pcbco);
    808                             DosReleaseMutexSem(G_hmtxCnrOwnersList);
    809                             brc = TRUE;
    810                         }
    811842                    }
    812 
    813                     if (!brc)
    814                         // failed: unsubclass cnr
    815                         WinSubclassWindow(hwndCnr, pfnwpCnrOrig);
    816843                }
    817 
    818                 if (!brc)
    819                     // failed: unsubclass owner
    820                     WinSubclassWindow(hwndCnrOwner, pfnwpOwnerOrig);
    821844            }
    822845        }
     
    956979 *      ID and updates that record enablement. If
    957980 *      the record is disabled, it's painted halftoned
    958  *      by ctl_fnwpSubclCheckboxCnr.
     981 *      by fnwpSubclCheckboxCnr.
    959982 *
    960983 *@@added V0.9.1 (99-12-03) [umoeller]
Note: See TracChangeset for help on using the changeset viewer.