-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathscbarg.cpp
More file actions
267 lines (214 loc) · 8.5 KB
/
Copy pathscbarg.cpp
File metadata and controls
267 lines (214 loc) · 8.5 KB
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/////////////////////////////////////////////////////////////////////////
//
// CSizingControlBarG Version 2.45
//
// Created: Jan 24, 1998 Last Modified: April 16, 2010
//
// See the official site at www.datamekanix.com for documentation and
// the latest news.
//
/////////////////////////////////////////////////////////////////////////
// Copyright (C) 1998-2010 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.
//
// 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 .
/////////////////////////////////////////////////////////////////////////
// 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
//MPC-BE custom code start
// Work in screen coordinates before converting back to
// client coordinates to account for possible RTL layout
GetParent()->ClientToScreen(rcBar);
GetParent()->ClientToScreen(rc);
//MPC-BE custom code end
BOOL bHorz = (nDockBarID == AFX_IDW_DOCKBAR_TOP) ||
(nDockBarID == AFX_IDW_DOCKBAR_BOTTOM);
if (bHorz)
rc.DeflateRect(ScaleX(m_cyGripper), 0, 0, 0);
else
rc.DeflateRect(0, ScaleY(m_cyGripper), 0, 0);
// set position for the "x" (hide bar) button
CPoint ptOrgBtn;
if (bHorz)
ptOrgBtn = CPoint(rc.left - ScaleX(m_cyGripper), rc.top);
else
ptOrgBtn = CPoint(rc.right - ScaleX(m_cyGripper) - 2, rc.top - ScaleY(m_cyGripper));
m_biHide.Move(ptOrgBtn - rcBar.TopLeft());
//MPC-BE custom code start
// Work in screen coordinates before converting back to
// client coordinates to account for possible RTL layout
GetParent()->ScreenToClient(&rc);
//MPC-BE custom code end
*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(CSize(ScaleX(m_cyGripper), ScaleY(m_cyGripper)));
BOOL bHorz = IsHorzDocked();
gripper.DeflateRect(1, 1);
const auto sizeX = ScaleX(m_cyGripper) / 4;
const auto sizeY = ScaleY(m_cyGripper) / 4;
if (bHorz)
{ // gripper at left
gripper.left -= (ScaleX(m_cyGripper) / 2 + sizeX * 2);
gripper.right = gripper.left + sizeX;
gripper.top = rcbtn.bottom + 3;
}
else
{ // gripper at top
gripper.top -= (ScaleY(m_cyGripper) / 2 + sizeY * 2);
gripper.bottom = gripper.top + sizeY;
gripper.right = rcbtn.left - 3;
}
// In the dark theme the system 3D colours are near-black on the dark frame (the gripper lines
// vanished); use themed light/dark greys so the two raised lines stay visible.
const COLORREF clrHi = m_bUseDarkTheme ? ColorThemeRGB(95, 100, 105) : ::GetSysColor(COLOR_BTNHIGHLIGHT);
const COLORREF clrLo = m_bUseDarkTheme ? ColorThemeRGB(20, 25, 30) : ::GetSysColor(COLOR_BTNSHADOW);
pDC->Draw3dRect(gripper, clrHi, clrLo);
gripper.OffsetRect(bHorz ? sizeX : 0, bHorz ? 0 : sizeY);
pDC->Draw3dRect(gripper, clrHi, clrLo);
m_biHide.Paint(pDC, this, CSize(ScaleX(m_cyGripper), ScaleY(m_cyGripper)));
}
LRESULT CSizingControlBarG::OnNcHitTest(CPoint point)
{
CRect rcBar;
GetWindowRect(rcBar);
LRESULT nRet = baseCSizingControlBarG::OnNcHitTest(point);
if (nRet != HTCLIENT)
return nRet;
//MPC-BE custom code start
// Convert to client coordinates to account for possible RTL layout
ScreenToClient(&rcBar);
ScreenToClient(&point);
//MPC-BE custom code end
CRect rc = m_biHide.GetRect(CSize(ScaleX(m_cyGripper), ScaleY(m_cyGripper)));
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, const CSizingControlBar* parent, const CSize& size/* = (DEFSIZE, DEFSIZE)*/)
{
CRect rc = GetRect(size);
// btn highlight
if (bPushed)
if (parent->m_bUseDarkTheme) {
pDC->Draw3dRect(rc, parent->ColorThemeRGB(5, 10, 15), parent->ColorThemeRGB(55, 60, 65));
} else {
pDC->Draw3dRect(rc, ::GetSysColor(COLOR_BTNSHADOW),
::GetSysColor(COLOR_BTNHIGHLIGHT));
}
else if (bRaised)
if (parent->m_bUseDarkTheme) {
pDC->Draw3dRect(rc, parent->ColorThemeRGB(55, 60, 65), parent->ColorThemeRGB(5, 10, 15));
} else {
pDC->Draw3dRect(rc, ::GetSysColor(COLOR_BTNHIGHLIGHT),
::GetSysColor(COLOR_BTNSHADOW));
}
COLORREF clrOldTextColor = pDC->GetTextColor();
pDC->SetTextColor(parent->m_bUseDarkTheme ? parent->ColorThemeRGB(125, 130, 135) : ::GetSysColor(COLOR_BTNTEXT));
int nPrevBkMode = pDC->SetBkMode(TRANSPARENT);
CFont font;
font.CreateFontW(parent->ScaleY(9), 0, 0, 0, FW_SEMIBOLD, 0, 0, 0, DEFAULT_CHARSET,
OUT_RASTER_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_MODERN, L"Marlett");
CFont* oldfont = pDC->SelectObject(&font);
//MPC-BE custom code start
// TextOut is affected by the layout so we need to account for that
DWORD dwLayout = pDC->GetLayout();
pDC->TextOutW(ptOrg.x + (dwLayout == LAYOUT_LTR ? 2 : -1), ptOrg.y + 2, L"r"); // x-like
//MPC-BE custom code end
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;
}