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
268
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Implements a special dockable dialog bar that activates itself when
// the mouse cursor moves over it. This enables stacking of the
// bars with only a small portion of each visible.
//
// $Workfile: $
// $Date: $
//
//-----------------------------------------------------------------------------
// $Log: $
//
// $NoKeywords: $
//=============================================================================//
#include "stdafx.h"
#include "hammer.h"
#include "HammerBar.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
BEGIN_MESSAGE_MAP(CHammerBar, CDialogBar)
ON_WM_SETCURSOR()
END_MESSAGE_MAP()
//-----------------------------------------------------------------------------
// Purpose: Automagically bring this bar to the top when the mouse cursor passes
// over it.
// Input : pWnd -
// nHitTest -
// message -
// Output : Always returns FALSE.
//-----------------------------------------------------------------------------
BOOL CHammerBar::OnSetCursor(CWnd *pWnd, UINT nHitTest, UINT message)
{
if (APP()->IsActiveApp())
{
// The control bar window is actually our grandparent.
CWnd *pwnd = GetParent();
if (pwnd != NULL)
{
pwnd = pwnd->GetParent();
if (pwnd != NULL)
{
pwnd->BringWindowToTop();
}
}
}
//this wasn't being called and fixes some minor cursor problems.
return CWnd::OnSetCursor( pWnd, nHitTest, message );
}
//-----------------------------------------------------------------------------
// Purpose: called automatically on a resize.
// calls the function to move the bar's controls around on a resize.
// also calls the CWnd OnSize so it can do what it needs to.
// Input : passed in by windows
// UINT nType
// int cx - change in width
// int cy - change in height
// Output : void
//-----------------------------------------------------------------------------
void CHammerBar::OnSize( UINT nType, int cx, int cy )
{
CWnd::OnSize( nType, cx, cy );
AdjustControls();
}
//-----------------------------------------------------------------------------
// Purpose: called by windows when the edges of the dialog are clicked
// returns the size of the dialog
// Input : passed automatically by windows
// int nLength - amount the dialog edge has moved
// DWORD dwMode - type of dialog/movement we are dealing with
// Output : CSize - size of the dialog
//-----------------------------------------------------------------------------
CSize CHammerBar::CalcDynamicLayout(int nLength, DWORD dwMode)
{
CSize newSize;
// If the bar is docked, use the default size
if ( (dwMode & LM_VERTDOCK) || (dwMode & LM_HORZDOCK) )
{
m_sizeDocked.cy = m_sizeFloating.cy;
return m_sizeDocked;
}
//if the bar is floating, use the current floating size
if ( dwMode & LM_MRUWIDTH )
{
return m_sizeFloating;
}
// In all other cases, we are changing the length with a drag
if ( dwMode & LM_LENGTHY )
{
//the bar is being resized in the y direction
newSize = CSize( m_sizeFloating.cx, m_sizeFloating.cy = nLength );
}
else
{
//the bar is being resized in the x direction
newSize = CSize( m_sizeFloating.cx = nLength, m_sizeFloating.cy);
}
CString textTitle;
GetWindowText( textTitle );
//it should not be possible that a bar with no name could be dynamic; this check is just to be safe
if ( !textTitle.IsEmpty() )
{
//writing the new size of the bar to the registry
textTitle = "FloatingBarSize\\" + textTitle;
APP()->WriteProfileInt( textTitle, "floatX", newSize.cx );
APP()->WriteProfileInt( textTitle, "floatY", newSize.cy );
}
return newSize;
}
//-----------------------------------------------------------------------------
// Purpose: creates the CHammerBar.
// makes sure a bar created with this old function isn't dyanmic
// initializes size variables.
// Input : CWnd *pParentWnd
// UINT nIDTemplate - the ID of the dialog to be created
// UINT nStyle - the type of dialog we are making
// UINT nID -
// Output : BOOL - TRUE on success
//-----------------------------------------------------------------------------
BOOL CHammerBar::Create( CWnd* pParentWnd, UINT nIDTemplate, UINT nStyle, UINT nID )
{
//cannot have a dynamic bar with this Create function; must use the one that takes the window name
UINT nStyleFixed = nStyle & ~CBRS_SIZE_DYNAMIC;
if ( !CDialogBar::Create(pParentWnd,nIDTemplate,nStyleFixed,nID) )
return FALSE;
m_sizeFloating = m_sizeDocked = m_sizeDefault;
return TRUE;
}
//-----------------------------------------------------------------------------
// Purpose: creates the CHammerBar.
// initializes size variables.
// reads saved dimension information from registry
// Input : CWnd *pParentWnd
// UINT nIDTemplate - the ID of the dialog to be created
// UINT nStyle - the type of dialog we are making
// UINT nID -
// Output : BOOL - TRUE on success
//-----------------------------------------------------------------------------
BOOL CHammerBar::Create( CWnd* pParentWnd, UINT nIDTemplate, UINT nStyle, UINT nID, char *pszName )
{
UINT nStyleFixed = nStyle;
if ( *pszName == 0 )
{
//did not give a title and cannot have a dynamic bar. Routing back through old create
return Create( pParentWnd, nIDTemplate, nStyle, nID );
}
else
{
if ( !CDialogBar::Create(pParentWnd,nIDTemplate,nStyleFixed,nID) )
return FALSE;
SetWindowText( pszName );
CString textTitle;
textTitle = "FloatingBarSize\\" + CString(pszName);
//read size from registry
m_sizeFloating.cx = APP()->GetProfileInt( textTitle, "floatX", m_sizeDefault.cx );
m_sizeFloating.cy = APP()->GetProfileInt( textTitle, "floatY", m_sizeDefault.cy );
m_sizeDocked = m_sizeDefault;
}
return TRUE;
}
//-----------------------------------------------------------------------------
// Purpose: moves controls based on their placement information
//
// Input : void
//
// Output : void
//-----------------------------------------------------------------------------
void CHammerBar::AdjustControls( void )
{
CRect HammerBarPos;
GetWindowRect( &HammerBarPos );
int nHammerBarHeight = HammerBarPos.Height();
int nHammerBarWidth = HammerBarPos.Width();
for( int iControl = 0; iControl < m_ControlList.Size(); iControl++ )
{
ControlInfo_t currentControl = m_ControlList[ iControl ];
int nDialogID = currentControl.m_nIDDialogItem;
int nControlWidthDifference = currentControl.m_nWidthBuffer;
int nControlHeightDifference = currentControl.m_nHeightBuffer;
DWORD dwPlacement = currentControl.m_dwPlacementFlag;
CWnd* pControl = GetDlgItem( nDialogID );
if ( pControl != NULL )
{
if ( dwPlacement & GROUP_BOX )
{
pControl->SetWindowPos( NULL, 0, 0, nHammerBarWidth - nControlWidthDifference ,
nHammerBarHeight - nControlHeightDifference, SWP_NOMOVE|SWP_NOZORDER );
}
if ( dwPlacement & BOTTOM_JUSTIFY )
{
CRect controlPos;
pControl->GetWindowRect( &controlPos );
pControl->SetWindowPos( NULL, controlPos.left - HammerBarPos.left,
HammerBarPos.Height() - currentControl.m_nPosY, 0, 0, SWP_NOSIZE|SWP_NOZORDER );
}
if ( dwPlacement & RIGHT_JUSTIFY )
{
CRect controlPos;
pControl->GetWindowRect( &controlPos );
pControl->SetWindowPos( NULL, HammerBarPos.Width() - currentControl.m_nPosX,
controlPos.top - HammerBarPos.top, 0, 0, SWP_NOSIZE|SWP_NOZORDER );
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose: adds controls to the CHammerBar
// determines position and stretch settings based on default design /
// Input : int nIDTemplate - ID from .rc file of control to be added
// DWORD dwPlacementFlag - placement information
// GROUP_BOX - will be stretched to fit new size
// BOTTOM_JUSTIFY - will move with the bottom of the dialog
// RIGHT_JUSTIFY - will move with the right side of the dialog//
// Output : void
//-----------------------------------------------------------------------------
void CHammerBar::AddControl( int nIDTemplate, DWORD dwPlacementFlag )
{
ControlInfo_t newControl;
newControl.m_nIDDialogItem = nIDTemplate;
newControl.m_dwPlacementFlag = dwPlacementFlag;
CWnd *pControl = GetDlgItem( nIDTemplate );
if ( pControl != NULL )
{
CRect controlPos, hammerBarPos;
pControl->GetWindowRect( &controlPos );
GetWindowRect( &hammerBarPos );
newControl.m_nHeightBuffer = m_sizeDefault.cy - controlPos.Height();
newControl.m_nWidthBuffer = m_sizeDefault.cx - controlPos.Width();
newControl.m_nPosX = m_sizeDefault.cx + hammerBarPos.left - controlPos.left;
newControl.m_nPosY = m_sizeDefault.cy + hammerBarPos.top - controlPos.top;
m_ControlList.AddToTail( newControl );
}
}
CHammerBar::~CHammerBar()
{
m_ControlList.RemoveAll();
}
|