forked from wheresjames/wpub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3DList.cpp
504 lines (386 loc) · 10.9 KB
/
3DList.cpp
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
/*******************************************************************
// Copyright (c) 2002, 2003, 2004, 2005,
// Robert Umbehant
// mailto:rumbehant@wheresjames.com
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330,
// Boston, MA 02111-1307 USA
//
*******************************************************************/
// 3DList.cpp : implementation file
//
#include "stdafx.h"
#include "3DList.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define WM_DBLCLICKED WM_USER + 502
/////////////////////////////////////////////////////////////////////////////
// C3DList
C3DList::C3DList()
{
m_bInitialize = TRUE;
m_hContextMenu = NULL;
}
C3DList::~C3DList()
{
m_bInitialize = TRUE;
}
BEGIN_MESSAGE_MAP(C3DList, CStatic)
//{{AFX_MSG_MAP(C3DList)
ON_WM_ERASEBKGND()
ON_WM_PAINT()
ON_WM_VSCROLL()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDBLCLK()
ON_WM_DESTROY()
ON_WM_HSCROLL()
ON_WM_SIZE()
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// C3DList message handlers
BOOL C3DList::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
// return CStatic::OnEraseBkgnd(pDC);
}
void C3DList::OnPaint()
{
CPaintDC dc(this); // device context for painting
UpdateVScrollBar();
UpdateHScrollBar();
RECT rect;
GetClientRect( &rect );
rect.right -= GetSystemMetrics( SM_CXVSCROLL );
// No bottom scroll bar if autosizing header
if ( !GetListCtrl().GetHeader().IsAutosizing() )
rect.bottom -= GetSystemMetrics( SM_CYHSCROLL );
// Get a dc in which to draw
HDC hDC = dc.GetSafeHdc();
if ( m_offscreen.Create( hDC, &rect ) )
hDC = m_offscreen.GetSafeHdc();
// Draw the list
if ( !m_list.Draw( hDC, &rect, GetSafeHwnd() ) )
CGrDC::FillSolidRect( hDC, &rect, RGB( 128, 128, 128 ) );
// Draw to the screen
m_offscreen.Draw( dc.GetSafeHdc(), &rect );
}
void C3DList::Initialize()
{
m_bInitialize = FALSE;
// Set clip children style
DWORD style = GetWindowLong( GetSafeHwnd(), GWL_STYLE );
style |= WS_CLIPCHILDREN;
SetWindowLong( GetSafeHwnd(), GWL_STYLE, style );
// Create the scroll bar
RECT rect;
GetClientRect( &rect );
rect.left = rect.right - GetSystemMetrics( SM_CXVSCROLL );
m_scrollbar.Create( SBS_RIGHTALIGN | SBS_VERT,
// SBS_SIZEBOXBOTTOMRIGHTALIGN | SBS_SIZEBOX,
rect, this, 0 );
m_scrollbar.ShowWindow( SW_SHOWNORMAL );
// Create the horizontal scroll bar
GetClientRect( &rect );
rect.top = rect.bottom - GetSystemMetrics( SM_CYHSCROLL );
rect.right -= GetSystemMetrics( SM_CXVSCROLL );
m_hscroll.Create( SBS_RIGHTALIGN | SBS_HORZ,
// SBS_SIZEBOXBOTTOMRIGHTALIGN | SBS_SIZEBOX,
rect, this, 0 );
// Hide or show scroll bar
if ( !GetListCtrl().GetHeader().IsAutosizing() )
m_hscroll.ShowWindow( SW_SHOWNORMAL );
else m_hscroll.ShowWindow( SW_HIDE );
Size();
}
void C3DList::UpdateVScrollBar()
{
if ( m_bInitialize ) Initialize();
if ( !IsWindow( m_scrollbar.GetSafeHwnd() ) ) return;
RECT rect;
GetClientRect( &rect );
// Get scroll range info
DWORD mr = m_list.GetScrollLineMax( &rect );
DWORD pg = m_list.GetLinesPerPage( &rect );
DWORD cl = m_list.GetCurLine();
DWORD sz = m_list.GetUncollapsedLines();
if ( sz ) sz--;
if ( mr > 0 )
{
// Reset current line if needed
if ( cl > mr ) m_list.SetCurLine( cl = mr );
SCROLLINFO info; ZeroMemory( &info, sizeof( info ) );
info.cbSize = sizeof( SCROLLINFO );
info.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
info.nMin = 0;
info.nMax = sz;
info.nPage = pg; //( sz > mr ) ? sz - mr : 0;
info.nPos = cl;
// Set the scroll bar info
m_scrollbar.SetScrollInfo( &info );
} // end if
// Enable / disable window
m_scrollbar.EnableWindow( ( mr != 0 ) );
}
void C3DList::OnLButtonDown(UINT nFlags, CPoint point)
{
SetCapture();
RECT rect, hs, vs;
GetClientRect( &rect );
m_scrollbar.GetClientRect( &vs );
rect.right -= RW( vs );
// If horizontal scroll bar
if ( !GetListCtrl().GetHeader().IsAutosizing() )
{
m_hscroll.GetClientRect( &hs );
rect.bottom -= RH( hs );
} // end if
// Let list handle button press
if ( m_list.OnLButtonDown( nFlags, &point, &rect ) )
{
RECT rect;
GetClientRect( &rect );
rect.right -= GetSystemMetrics( SM_CXVSCROLL );
rect.bottom -= GetSystemMetrics( SM_CYHSCROLL );
RedrawWindow( &rect );
UpdateVScrollBar();
} // end if
CStatic::OnLButtonDown(nFlags, point);
}
void C3DList::OnLButtonUp(UINT nFlags, CPoint point)
{
ReleaseCapture();
m_list.OnLButtonUp();
UpdateHScrollBar();
CStatic::OnLButtonUp(nFlags, point);
}
void C3DList::OnMouseMove(UINT nFlags, CPoint point)
{
RECT rect;
GetClientRect( &rect );
// Let list handle mouse move
if ( m_list.OnMouseMove( nFlags, &point, &rect ) )
{
RECT rect;
GetClientRect( &rect );
rect.right -= GetSystemMetrics( SM_CXVSCROLL );
rect.bottom -= GetSystemMetrics( SM_CYHSCROLL );
RedrawWindow( &rect );
} // end if
// Set the correct cursor
SetCursor( m_list.GetCursor( &rect, &point ) );
// CStatic::OnMouseMove(nFlags, point);
}
void C3DList::OnLButtonDblClk(UINT nFlags, CPoint point)
{
HWND hParent = ::GetParent( GetSafeHwnd() );
if ( hParent != NULL ) ::SendMessage( hParent, WM_DBLCLICKED, 0, 0L );
CStatic::OnLButtonDblClk(nFlags, point);
}
void C3DList::Size()
{
// Must have window
if ( !IsWindow( GetSafeHwnd() ) ) return;
RECT rect;
GetClientRect( &rect );
UpdateVScrollBar();
UpdateHScrollBar();
// Set scroll bar position
rect.left = rect.right - GetSystemMetrics( SM_CXVSCROLL );
if ( IsWindow( m_scrollbar.GetSafeHwnd() ) )
{
m_scrollbar.SetWindowPos( NULL, rect.left, rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
SWP_NOZORDER | SWP_NOACTIVATE );
m_scrollbar.RedrawWindow();
// Validate vscroll
ValidateRect( &rect );
} // end if
// Set scroll bar position
GetClientRect( &rect );
rect.top = rect.bottom - GetSystemMetrics( SM_CYHSCROLL );
rect.right -= GetSystemMetrics( SM_CXVSCROLL );
if ( IsWindow( m_hscroll.GetSafeHwnd() ) )
{
m_hscroll.SetWindowPos( NULL, rect.left, rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
SWP_NOZORDER | SWP_NOACTIVATE );
m_hscroll.RedrawWindow();
// Hide or show scroll bar
if ( !GetListCtrl().GetHeader().IsAutosizing() )
{
// Ensure visible
m_hscroll.ShowWindow( SW_SHOWNORMAL );
// Validate hscroll
ValidateRect( &rect );
} // end if
else m_hscroll.ShowWindow( SW_HIDE );
} // end if
RedrawWindow();
}
void C3DList::OnDestroy()
{
CStatic::OnDestroy();
m_bInitialize = TRUE;
}
void C3DList::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if ( pScrollBar != NULL )
{
RECT rect;
GetClientRect( &rect );
DWORD lpp = m_list.GetLinesPerPage( &rect );
int pos = pScrollBar->GetScrollPos();
int min, max;
pScrollBar->GetScrollRange( &min, &max );
switch( nSBCode )
{
case SB_BOTTOM :
pScrollBar->SetScrollPos( max );
break;
case SB_LINEDOWN :
pScrollBar->SetScrollPos( pos + 1 );
break;
case SB_LINEUP :
pScrollBar->SetScrollPos( pos - 1 );
break;
case SB_PAGEDOWN :
pScrollBar->SetScrollPos( pos + lpp );
break;
case SB_PAGEUP :
pScrollBar->SetScrollPos( pos - lpp );
break;
case SB_THUMBPOSITION :
pScrollBar->SetScrollPos( nPos );
break;
case SB_THUMBTRACK :
pScrollBar->SetScrollPos( nPos );
break;
case SB_TOP :
pScrollBar->SetScrollPos( min );
break;
} // end switch
if ( pScrollBar == &m_scrollbar )
{
m_list.SetCurLine( pScrollBar->GetScrollPos() );
RECT rect;
GetClientRect( &rect );
rect.right -= GetSystemMetrics( SM_CXVSCROLL );
RedrawWindow( &rect );
} // end if
} // end if
CStatic::OnVScroll(nSBCode, nPos, pScrollBar);
}
void C3DList::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if ( pScrollBar != NULL )
{
RECT rect;
GetClientRect( &rect );
int pos = pScrollBar->GetScrollPos();
int min, max;
pScrollBar->GetScrollRange( &min, &max );
switch( nSBCode )
{
case SB_BOTTOM :
pScrollBar->SetScrollPos( max );
break;
case SB_LINEDOWN :
pScrollBar->SetScrollPos( pos + 1 );
break;
case SB_LINEUP :
pScrollBar->SetScrollPos( pos - 1 );
break;
case SB_PAGEDOWN :
pScrollBar->SetScrollPos( pos + ( rect.right - rect.left ) );
break;
case SB_PAGEUP :
pScrollBar->SetScrollPos( pos - ( rect.right - rect.left ) );
break;
case SB_THUMBPOSITION :
pScrollBar->SetScrollPos( nPos );
break;
case SB_THUMBTRACK :
pScrollBar->SetScrollPos( nPos );
break;
case SB_TOP :
pScrollBar->SetScrollPos( min );
break;
} // end switch
if ( pScrollBar == &m_hscroll )
{
m_list.SetHScroll( pScrollBar->GetScrollPos() );
RECT rect;
GetClientRect( &rect );
rect.right -= GetSystemMetrics( SM_CXVSCROLL );
rect.bottom -= GetSystemMetrics( SM_CYHSCROLL );
RedrawWindow( &rect );
} // end if
} // end if
CStatic::OnHScroll(nSBCode, nPos, pScrollBar);
}
void C3DList::UpdateHScrollBar()
{
if ( !IsWindow( m_hscroll.GetSafeHwnd() ) ) return;
RECT rect;
GetClientRect( &rect );
long width = rect.right - rect.left - GetSystemMetrics( SM_CXVSCROLL );
long ms = m_list.GetTotalWidth();
long cs = m_list.GetHScroll();
// Calc max scroll
if ( width > ms ) ms = 0; else ms -= width;
// Reset current line if needed
if ( cs > ms )
{
m_list.SetHScroll( cs = ms );
RedrawWindow();
} // end if
// Set scroll range
// m_hscroll.SetScrollRange( 0, ms, FALSE );
// m_hscroll.SetScrollPos( cs, TRUE );
if ( ms > 0 )
{
SCROLLINFO info; ZeroMemory( &info, sizeof( info ) );
info.cbSize = sizeof( SCROLLINFO );
info.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
info.nMin = 0;
info.nMax = ms;
info.nPage = width; //( sz > mr ) ? sz - mr : 0;
info.nPos = cs;
// Set the scroll bar info
m_hscroll.SetScrollInfo( &info );
} // end if
// Enable/disable scroll bar
m_hscroll.EnableWindow( ( ms != 0 ) );
}
void C3DList::OnSize(UINT nType, int cx, int cy)
{
CStatic::OnSize(nType, cx, cy);
Size();
}
void C3DList::OnRButtonDown(UINT nFlags, CPoint point)
{
// Send right click message if needed
if ( m_hContextMenu != NULL )
::PostMessage( m_hContextMenu, WM_RBUTTONDOWN, (WPARAM)nFlags,
(LPARAM)MAKELONG( point.x, point.y ) );
CStatic::OnRButtonDown(nFlags, point);
}