1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
/////////////////////////////////////////////////////////////////////////
//
// CSizingControlBarG Version 2.43
//
// Created: Jan 24, 1998 Last Modified: August 03, 2000
//
// See the official site at www.datamekanix.com for documentation and
// the latest news.
//
/////////////////////////////////////////////////////////////////////////
// Copyright (C) 1998-2000 by Cristi Posea. All rights reserved.
//
// This code is free for personal and commercial use, providing this
// notice remains intact in the source files and all eventual changes are
// clearly marked with comments.
//
// You must obtain the author's consent before you can include this code
// in a software library.
//
// No warrantee of any kind, express or implied, is included with this
// software; use at your own risk, responsibility for damages (if any) to
// anyone resulting from the use of this software rests entirely with the
// user.
//
// Send bug reports, bug fixes, enhancements, requests, flames, etc. to
// cristi@datamekanix.com or post them at the message board at the site.
/////////////////////////////////////////////////////////////////////////
// sizecbar.cpp : implementation file
//
#include "stdafx.h"
#include "scbarg.h"
/////////////////////////////////////////////////////////////////////////
// CSizingControlBarG
IMPLEMENT_DYNAMIC(CSizingControlBarG, baseCSizingControlBarG);
CSizingControlBarG::CSizingControlBarG()
{
m_cyGripper = 12;
}
CSizingControlBarG::~CSizingControlBarG()
{
}
BEGIN_MESSAGE_MAP(CSizingControlBarG, baseCSizingControlBarG)
//{{AFX_MSG_MAP(CSizingControlBarG)
ON_WM_NCLBUTTONUP()
ON_WM_NCHITTEST()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_SETTEXT, OnSetText)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////
// CSizingControlBarG message handlers
/////////////////////////////////////////////////////////////////////////
// Mouse Handling
//
void CSizingControlBarG::OnNcLButtonUp(UINT nHitTest, CPoint point)
{
if(nHitTest == HTCLOSE)
m_pDockSite->ShowControlBar(this, FALSE, FALSE); // hide
baseCSizingControlBarG::OnNcLButtonUp(nHitTest, point);
}
void CSizingControlBarG::NcCalcClient(LPRECT pRc, UINT nDockBarID)
{
CRect rcBar(pRc); // save the bar rect
// subtract edges
baseCSizingControlBarG::NcCalcClient(pRc, nDockBarID);
if(!HasGripper())
return;
CRect rc(pRc); // the client rect as calculated by the base class
BOOL bHorz = (nDockBarID == AFX_IDW_DOCKBAR_TOP) ||
(nDockBarID == AFX_IDW_DOCKBAR_BOTTOM);
if(bHorz)
rc.DeflateRect(m_cyGripper, 0, 0, 0);
else
rc.DeflateRect(0, m_cyGripper, 0, 0);
// set position for the "x" (hide bar) button
CPoint ptOrgBtn;
if(bHorz)
ptOrgBtn = CPoint(rc.left - 13, rc.top);
else
ptOrgBtn = CPoint(rc.right - 12, rc.top - 13);
m_biHide.Move(ptOrgBtn - rcBar.TopLeft());
*pRc = rc;
}
void CSizingControlBarG::NcPaintGripper(CDC* pDC, CRect rcClient)
{
if(!HasGripper())
return;
// paints a simple "two raised lines" gripper
// override this if you want a more sophisticated gripper
CRect gripper = rcClient;
CRect rcbtn = m_biHide.GetRect();
BOOL bHorz = IsHorzDocked();
gripper.DeflateRect(1, 1);
if(bHorz)
{
// gripper at left
gripper.left -= m_cyGripper;
gripper.right = gripper.left + 3;
gripper.top = rcbtn.bottom + 3;
}
else
{
// gripper at top
gripper.top -= m_cyGripper;
gripper.bottom = gripper.top + 3;
gripper.right = rcbtn.left - 3;
}
pDC->Draw3dRect(gripper, ::GetSysColor(COLOR_BTNHIGHLIGHT),
::GetSysColor(COLOR_BTNSHADOW));
gripper.OffsetRect(bHorz ? 3 : 0, bHorz ? 0 : 3);
pDC->Draw3dRect(gripper, ::GetSysColor(COLOR_BTNHIGHLIGHT),
::GetSysColor(COLOR_BTNSHADOW));
m_biHide.Paint(pDC);
}
LRESULT CSizingControlBarG::OnNcHitTest(CPoint point)
{
CRect rcBar;
GetWindowRect(rcBar);
LRESULT nRet = baseCSizingControlBarG::OnNcHitTest(point);
if(nRet != HTCLIENT)
return nRet;
CRect rc = m_biHide.GetRect();
rc.OffsetRect(rcBar.TopLeft());
if(rc.PtInRect(point))
return HTCLOSE;
return HTCLIENT;
}
/////////////////////////////////////////////////////////////////////////
// CSizingControlBarG implementation helpers
void CSizingControlBarG::OnUpdateCmdUI(CFrameWnd* pTarget,
BOOL bDisableIfNoHndler)
{
UNUSED_ALWAYS(bDisableIfNoHndler);
UNUSED_ALWAYS(pTarget);
if(!HasGripper())
return;
BOOL bNeedPaint = FALSE;
CPoint pt;
::GetCursorPos(&pt);
BOOL bHit = (OnNcHitTest(pt) == HTCLOSE);
BOOL bLButtonDown = (::GetKeyState(VK_LBUTTON) < 0);
BOOL bWasPushed = m_biHide.bPushed;
m_biHide.bPushed = bHit && bLButtonDown;
BOOL bWasRaised = m_biHide.bRaised;
m_biHide.bRaised = bHit && !bLButtonDown;
bNeedPaint |= (m_biHide.bPushed ^ bWasPushed) ||
(m_biHide.bRaised ^ bWasRaised);
if(bNeedPaint)
SendMessage(WM_NCPAINT);
}
/////////////////////////////////////////////////////////////////////////
// CSCBButton
CSCBButton::CSCBButton()
{
bRaised = FALSE;
bPushed = FALSE;
}
void CSCBButton::Paint(CDC* pDC)
{
CRect rc = GetRect();
if(bPushed)
pDC->Draw3dRect(rc, ::GetSysColor(COLOR_BTNSHADOW),
::GetSysColor(COLOR_BTNHIGHLIGHT));
else if(bRaised)
pDC->Draw3dRect(rc, ::GetSysColor(COLOR_BTNHIGHLIGHT),
::GetSysColor(COLOR_BTNSHADOW));
COLORREF clrOldTextColor = pDC->GetTextColor();
pDC->SetTextColor(::GetSysColor(COLOR_BTNTEXT));
int nPrevBkMode = pDC->SetBkMode(TRANSPARENT);
CFont font;
int ppi = pDC->GetDeviceCaps(LOGPIXELSX);
int pointsize = MulDiv(60, 96, ppi); // 6 points at 96 ppi
font.CreatePointFont(pointsize, _T("Marlett"));
CFont* oldfont = pDC->SelectObject(&font);
pDC->TextOut(ptOrg.x + 2, ptOrg.y + 2, CString(_T("r"))); // x-like
pDC->SelectObject(oldfont);
pDC->SetBkMode(nPrevBkMode);
pDC->SetTextColor(clrOldTextColor);
}
BOOL CSizingControlBarG::HasGripper() const
{
#if defined(_SCB_MINIFRAME_CAPTION) || !defined(_SCB_REPLACE_MINIFRAME)
// if the miniframe has a caption, don't display the gripper
if(IsFloating())
return FALSE;
#endif //_SCB_MINIFRAME_CAPTION
return TRUE;
}
|