scbarg.cpp

00001 
00002 //
00003 // CSizingControlBarG           Version 2.43
00004 // 
00005 // Created: Jan 24, 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 // [email protected] or post them at the message board at the site.
00028 
00029 // sizecbar.cpp : implementation file
00030 //
00031 
00032 #include "stdafx.h"
00033 
00034 #include "scbarg.h"
00035 
00036 #ifdef _DEBUG
00037 #define new DEBUG_NEW
00038 #undef THIS_FILE
00039 static char THIS_FILE[] = __FILE__;
00040 #endif
00041 
00043 // CSizingControlBarG
00044 
00045 IMPLEMENT_DYNAMIC(CSizingControlBarG, baseCSizingControlBarG);
00046 
00047 CSizingControlBarG::CSizingControlBarG()
00048 {
00049     m_cyGripper = 12;
00050 }
00051 
00052 CSizingControlBarG::~CSizingControlBarG()
00053 {
00054 }
00055 
00056 BEGIN_MESSAGE_MAP(CSizingControlBarG, baseCSizingControlBarG)
00057     //{{AFX_MSG_MAP(CSizingControlBarG)
00058     ON_WM_NCLBUTTONUP()
00059     ON_WM_NCHITTEST()
00060     //}}AFX_MSG_MAP
00061     ON_MESSAGE(WM_SETTEXT, OnSetText)
00062 END_MESSAGE_MAP()
00063 
00065 // CSizingControlBarG message handlers
00066 
00068 // Mouse Handling
00069 //
00070 
00071 void CSizingControlBarG::OnNcLButtonUp(UINT nHitTest, CPoint point)
00072 {
00073     if (nHitTest == HTCLOSE)
00074         m_pDockSite->ShowControlBar(this, FALSE, FALSE); // hide
00075 
00076     baseCSizingControlBarG::OnNcLButtonUp(nHitTest, point);
00077 }
00078 
00079 void CSizingControlBarG::NcCalcClient(LPRECT pRc, UINT nDockBarID)
00080 {
00081     CRect rcBar(pRc); // save the bar rect
00082 
00083     // subtract edges
00084     baseCSizingControlBarG::NcCalcClient(pRc, nDockBarID);
00085 
00086     if (!HasGripper())
00087         return;
00088 
00089     CRect rc(pRc); // the client rect as calculated by the base class
00090 
00091     BOOL bHorz = (nDockBarID == AFX_IDW_DOCKBAR_TOP) ||
00092                  (nDockBarID == AFX_IDW_DOCKBAR_BOTTOM);
00093 
00094     if (bHorz)
00095         rc.DeflateRect(m_cyGripper, 0, 0, 0);
00096     else
00097         rc.DeflateRect(0, m_cyGripper, 0, 0);
00098 
00099     // set position for the "x" (hide bar) button
00100     CPoint ptOrgBtn;
00101     if (bHorz)
00102         ptOrgBtn = CPoint(rc.left - 13, rc.top);
00103     else
00104         ptOrgBtn = CPoint(rc.right - 12, rc.top - 13);
00105 
00106     m_biHide.Move(ptOrgBtn - rcBar.TopLeft());
00107 
00108     *pRc = rc;
00109 }
00110 
00111 void CSizingControlBarG::NcPaintGripper(CDC* pDC, CRect rcClient)
00112 {
00113     if (!HasGripper())
00114         return;
00115 
00116     // paints a simple "two raised lines" gripper
00117     // override this if you want a more sophisticated gripper
00118     CRect gripper = rcClient;
00119     CRect rcbtn = m_biHide.GetRect();
00120     BOOL bHorz = IsHorzDocked();
00121 
00122     gripper.DeflateRect(1, 1);
00123     if (bHorz)
00124     {   // gripper at left
00125         gripper.left -= m_cyGripper;
00126         gripper.right = gripper.left + 3;
00127         gripper.top = rcbtn.bottom + 3;
00128     }
00129     else
00130     {   // gripper at top
00131         gripper.top -= m_cyGripper;
00132         gripper.bottom = gripper.top + 3;
00133         gripper.right = rcbtn.left - 3;
00134     }
00135 
00136     pDC->Draw3dRect(gripper, ::GetSysColor(COLOR_BTNHIGHLIGHT),
00137         ::GetSysColor(COLOR_BTNSHADOW));
00138 
00139     gripper.OffsetRect(bHorz ? 3 : 0, bHorz ? 0 : 3);
00140 
00141     pDC->Draw3dRect(gripper, ::GetSysColor(COLOR_BTNHIGHLIGHT),
00142         ::GetSysColor(COLOR_BTNSHADOW));
00143 
00144     m_biHide.Paint(pDC);
00145 }
00146 
00147 LRESULT CSizingControlBarG::OnNcHitTest(CPoint point)
00148 {
00149     CRect rcBar;
00150     GetWindowRect(rcBar);
00151 
00152     LRESULT nRet = baseCSizingControlBarG::OnNcHitTest(point);
00153     if (nRet != HTCLIENT)
00154         return nRet;
00155 
00156     CRect rc = m_biHide.GetRect();
00157     rc.OffsetRect(rcBar.TopLeft());
00158     if (rc.PtInRect(point))
00159         return HTCLOSE;
00160 
00161     return HTCLIENT;
00162 }
00163 
00165 // CSizingControlBarG implementation helpers
00166 
00167 void CSizingControlBarG::OnUpdateCmdUI(CFrameWnd* pTarget,
00168                                       BOOL bDisableIfNoHndler)
00169 {
00170     UNUSED_ALWAYS(bDisableIfNoHndler);
00171     UNUSED_ALWAYS(pTarget);
00172 
00173     if (!HasGripper())
00174         return;
00175 
00176     BOOL bNeedPaint = FALSE;
00177 
00178     CPoint pt;
00179     ::GetCursorPos(&pt);
00180     BOOL bHit = (OnNcHitTest(pt) == HTCLOSE);
00181     BOOL bLButtonDown = (::GetKeyState(VK_LBUTTON) < 0);
00182 
00183     BOOL bWasPushed = m_biHide.bPushed;
00184     m_biHide.bPushed = bHit && bLButtonDown;
00185 
00186     BOOL bWasRaised = m_biHide.bRaised;
00187     m_biHide.bRaised = bHit && !bLButtonDown;
00188 
00189     bNeedPaint |= (m_biHide.bPushed ^ bWasPushed) ||
00190                   (m_biHide.bRaised ^ bWasRaised);
00191 
00192     if (bNeedPaint)
00193         SendMessage(WM_NCPAINT);
00194 }
00195 
00197 // CSCBButton
00198 
00199 CSCBButton::CSCBButton()
00200 {
00201     bRaised = FALSE;
00202     bPushed = FALSE;
00203 }
00204 
00205 void CSCBButton::Paint(CDC* pDC)
00206 {
00207     CRect rc = GetRect();
00208 
00209     if (bPushed)
00210         pDC->Draw3dRect(rc, ::GetSysColor(COLOR_BTNSHADOW),
00211             ::GetSysColor(COLOR_BTNHIGHLIGHT));
00212     else
00213         if (bRaised)
00214             pDC->Draw3dRect(rc, ::GetSysColor(COLOR_BTNHIGHLIGHT),
00215                 ::GetSysColor(COLOR_BTNSHADOW));
00216 
00217     COLORREF clrOldTextColor = pDC->GetTextColor();
00218     pDC->SetTextColor(::GetSysColor(COLOR_BTNTEXT));
00219     int nPrevBkMode = pDC->SetBkMode(TRANSPARENT);
00220     CFont font;
00221     int ppi = pDC->GetDeviceCaps(LOGPIXELSX);
00222     int pointsize = MulDiv(60, 96, ppi); // 6 points at 96 ppi
00223     font.CreatePointFont(pointsize, _T("Marlett"));
00224     CFont* oldfont = pDC->SelectObject(&font);
00225 
00226     pDC->TextOut(ptOrg.x + 2, ptOrg.y + 2, CString(_T("r"))); // x-like
00227 
00228     pDC->SelectObject(oldfont);
00229     pDC->SetBkMode(nPrevBkMode);
00230     pDC->SetTextColor(clrOldTextColor);
00231 }
00232 
00233 BOOL CSizingControlBarG::HasGripper() const
00234 {
00235 #if defined(_SCB_MINIFRAME_CAPTION) || !defined(_SCB_REPLACE_MINIFRAME)
00236     // if the miniframe has a caption, don't display the gripper
00237     if (IsFloating())
00238         return FALSE;
00239 #endif //_SCB_MINIFRAME_CAPTION
00240 
00241     return TRUE;
00242 }

Generated on Tue Dec 13 14:47:57 2005 for guliverkli by  doxygen 1.4.5