- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# scbarcf.cpp

    00001
    00002 //
    00003 // CSizingControlBarCF          Version 2.43
    00004 //
    00005 // Created: Dec 21, 1998        Last Modified: August 03, 2000
    00006 //
    00007 // See the official site at www.datamekanix.com for documentation and
    00008 // the latest news.
    00009 //
    00011 // Copyright (C) 1998-2000 by Cristi Posea. All rights reserved.
    00012 //
    00013 // This code is free for personal and commercial use, providing this
    00014 // notice remains intact in the source files and all eventual changes are
    00015 // clearly marked with comments.
    00016 //
    00017 // You must obtain the author's consent before you can include this code
    00018 // in a software library.
    00019 //
    00020 // No warrantee of any kind, express or implied, is included with this
    00021 // software; use at your own risk, responsibility for damages (if any) to
    00022 // anyone resulting from the use of this software rests entirely with the
    00023 // user.
    00024 //
    00025 // Send bug reports, bug fixes, enhancements, requests, flames, etc. to
    00026 // cristi@datamekanix.com or post them at the message board at the site.
    00028
    00029 #include "stdafx.h"
    00030 #include "scbarcf.h"
    00031
    00033 // CSizingControlBarCF
    00034
    00035 IMPLEMENT_DYNAMIC(CSizingControlBarCF, baseCSizingControlBarCF);
    00036
    00037 int CALLBACK EnumFontFamProc(ENUMLOGFONT FAR *lpelf,
    00038                              NEWTEXTMETRIC FAR *lpntm,
    00039                              int FontType,
    00040                              LPARAM lParam)
    00041 {
    00042     UNUSED_ALWAYS(lpelf);
    00043     UNUSED_ALWAYS(lpntm);
    00044     UNUSED_ALWAYS(FontType);
    00045     UNUSED_ALWAYS(lParam);
    00046
    00047     return 0;
    00048 }
    00049
    00050 CSizingControlBarCF::CSizingControlBarCF()
    00051 {
    00052     m_bActive = FALSE;
    00053
    00054     CDC dc;
    00055     dc.CreateCompatibleDC(NULL);
    00056
    00057     m_sFontFace = (::EnumFontFamilies(dc.m_hDC,
    00058         _T("Tahoma"), (FONTENUMPROC) EnumFontFamProc, 0) == 0) ?
    00059         _T("Tahoma") : _T("Arial");
    00060
    00061     dc.DeleteDC();
    00062
    00063 }
    00064
    00065 BEGIN_MESSAGE_MAP(CSizingControlBarCF, baseCSizingControlBarCF)
    00066     //{{AFX_MSG_MAP(CSizingControlBarCF)
    00067     //}}AFX_MSG_MAP
    00068     ON_MESSAGE(WM_SETTEXT, OnSetText)
    00069 END_MESSAGE_MAP()
    00070
    00071 void CSizingControlBarCF::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
    00072 {
    00073     baseCSizingControlBarCF::OnUpdateCmdUI(pTarget, bDisableIfNoHndler);
    00074
    00075     if (!HasGripper())
    00076         return;
    00077
    00078     BOOL bNeedPaint = FALSE;
    00079
    00080     CWnd* pFocus = GetFocus();
    00081     BOOL bActiveOld = m_bActive;
    00082
    00083     m_bActive = (pFocus->GetSafeHwnd() && IsChild(pFocus));
    00084
    00085     if (m_bActive != bActiveOld)
    00086         bNeedPaint = TRUE;
    00087
    00088     if (bNeedPaint)
    00089         SendMessage(WM_NCPAINT);
    00090 }
    00091
    00092 // gradient defines (if not already defined)
    00093 #ifndef COLOR_GRADIENTACTIVECAPTION
    00094 #define COLOR_GRADIENTACTIVECAPTION     27
    00095 #define COLOR_GRADIENTINACTIVECAPTION   28
    00096 #define SPI_GETGRADIENTCAPTIONS         0x1008
    00097 #endif
    00098
    00099 void CSizingControlBarCF::NcPaintGripper(CDC* pDC, CRect rcClient)
    00100 {
    00101     if (!HasGripper())
    00102         return;
    00103
    00104     // compute the caption rectangle
    00105     BOOL bHorz = IsHorzDocked();
    00106     CRect rcGrip = rcClient;
    00107     CRect rcBtn = m_biHide.GetRect();
    00108     if (bHorz)
    00109     {   // right side gripper
    00110         rcGrip.left -= m_cyGripper + 1;
    00111         rcGrip.right = rcGrip.left + 11;
    00112         rcGrip.top = rcBtn.bottom + 3;
    00113     }
    00114     else
    00115     {   // gripper at top
    00116         rcGrip.top -= m_cyGripper + 1;
    00117         rcGrip.bottom = rcGrip.top + 11;
    00118         rcGrip.right = rcBtn.left - 3;
    00119     }
    00120     rcGrip.InflateRect(bHorz ? 1 : 0, bHorz ? 0 : 1);
    00121
    00122     // draw the caption background
    00123     //CBrush br;
    00124     COLORREF clrCptn = m_bActive ?
    00125         ::GetSysColor(COLOR_ACTIVECAPTION) :
    00126         ::GetSysColor(COLOR_INACTIVECAPTION);
    00127
    00128     // query gradient info (usually TRUE for Win98/Win2k)
    00129     BOOL bGradient = FALSE;
    00130     ::SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &bGradient, 0);
    00131
    00132     if (!bGradient)
    00133         pDC->FillSolidRect(&rcGrip, clrCptn); // solid color
    00134     else
    00135     {
    00136         // gradient from left to right or from bottom to top
    00137         // get second gradient color (the right end)
    00138         COLORREF clrCptnRight = m_bActive ?
    00139             ::GetSysColor(COLOR_GRADIENTACTIVECAPTION) :
    00140             ::GetSysColor(COLOR_GRADIENTINACTIVECAPTION);
    00141
    00142         // this will make 2^6 = 64 fountain steps
    00143         int nShift = 6;
    00144         int nSteps = 1 << nShift;
    00145
    00146         for (int i = 0; i < nSteps; i++)
    00147         {
    00148             // do a little alpha blending
    00149             int nR = (GetRValue(clrCptn) * (nSteps - i) +
    00150                       GetRValue(clrCptnRight) * i) >> nShift;
    00151             int nG = (GetGValue(clrCptn) * (nSteps - i) +
    00152                       GetGValue(clrCptnRight) * i) >> nShift;
    00153             int nB = (GetBValue(clrCptn) * (nSteps - i) +
    00154                       GetBValue(clrCptnRight) * i) >> nShift;
    00155
    00156             COLORREF cr = RGB(nR, nG, nB);
    00157
    00158             // then paint with the resulting color
    00159             CRect r2 = rcGrip;
    00160             if (bHorz)
    00161             {
    00162                 r2.bottom = rcGrip.bottom -
    00163                     ((i * rcGrip.Height()) >> nShift);
    00164                 r2.top = rcGrip.bottom -
    00165                     (((i + 1) * rcGrip.Height()) >> nShift);
    00166                 if (r2.Height() > 0)
    00167                     pDC->FillSolidRect(r2, cr);
    00168             }
    00169             else
    00170             {
    00171                 r2.left = rcGrip.left +
    00172                     ((i * rcGrip.Width()) >> nShift);
    00173                 r2.right = rcGrip.left +
    00174                     (((i + 1) * rcGrip.Width()) >> nShift);
    00175                 if (r2.Width() > 0)
    00176                     pDC->FillSolidRect(r2, cr);
    00177             }
    00178         }
    00179     }
    00180
    00181     // draw the caption text - first select a font
    00182     CFont font;
    00183     int ppi = pDC->GetDeviceCaps(LOGPIXELSX);
    00184     int pointsize = MulDiv(85, 96, ppi); // 8.5 points at 96 ppi
    00185
    00186     LOGFONT lf;
    00187     BOOL bFont = font.CreatePointFont(pointsize, m_sFontFace);
    00188     if (bFont)
    00189     {
    00190         // get the text color
    00191         COLORREF clrCptnText = m_bActive ?
    00192             ::GetSysColor(COLOR_CAPTIONTEXT) :
    00193             ::GetSysColor(COLOR_INACTIVECAPTIONTEXT);
    00194
    00195         int nOldBkMode = pDC->SetBkMode(TRANSPARENT);
    00196         COLORREF clrOldText = pDC->SetTextColor(clrCptnText);
    00197
    00198         if (bHorz)
    00199         {
    00200             // rotate text 90 degrees CCW if horizontally docked
    00201             font.GetLogFont(&lf);
    00202             font.DeleteObject();
    00203             lf.lfEscapement = 900;
    00204             font.CreateFontIndirect(&lf);
    00205         }
    00206
    00207         CFont* pOldFont = pDC->SelectObject(&font);
    00208         CString sTitle;
    00209         GetWindowText(sTitle);
    00210
    00211         CPoint ptOrg = bHorz ?
    00212             CPoint(rcGrip.left - 1, rcGrip.bottom - 3) :
    00213             CPoint(rcGrip.left + 3, rcGrip.top - 1);
    00214
    00215         pDC->ExtTextOut(ptOrg.x, ptOrg.y,
    00216             ETO_CLIPPED, rcGrip, sTitle, NULL);
    00217
    00218         pDC->SelectObject(pOldFont);
    00219         pDC->SetBkMode(nOldBkMode);
    00220         pDC->SetTextColor(clrOldText);
    00221     }
    00222
    00223     // draw the button
    00224     m_biHide.Paint(pDC);
    00225 }
    00226
    00227 LRESULT CSizingControlBarCF::OnSetText(WPARAM wParam, LPARAM lParam)
    00228 {
    00229     LRESULT lResult = baseCSizingControlBarCF::OnSetText(wParam, lParam);
    00230
    00231     SendMessage(WM_NCPAINT);
    00232
    00233     return lResult;
    00234 }