-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDlgTreeFrame.cpp
More file actions
505 lines (384 loc) · 11.4 KB
/
DlgTreeFrame.cpp
File metadata and controls
505 lines (384 loc) · 11.4 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
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
505
/*******************************************************************
// 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
//
*******************************************************************/
// DlgTreeFrame.cpp : implementation file
//
#include "stdafx.h"
#include "vp.h"
#include "DlgTreeFrame.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgTreeFrame dialog
CDlgTreeFrame::CDlgTreeFrame(CWnd* pParent /*=NULL*/)
: CDialog(CDlgTreeFrame::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgTreeFrame)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// No list so far
m_pg.dwSize = 0;
m_pg.pHead = NULL;
m_pg.pTail = NULL;
m_pg.pParent = NULL;
m_dwSize = 0;
m_dwIndex = 0;
m_dwStartPage = 0;
m_dwIcon = 0;
m_hpg = NULL;
m_bApply = FALSE;
m_dwLastPage = 0;
}
CDlgTreeFrame::~CDlgTreeFrame()
{
Destroy();
}
void CDlgTreeFrame::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgTreeFrame)
DDX_Control(pDX, IDC_TREE, m_tree);
DDX_Control(pDX, IDC_BLANK, m_blank);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgTreeFrame, CDialog)
//{{AFX_MSG_MAP(CDlgTreeFrame)
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE, OnSelchangedTree)
ON_BN_CLICKED(IDC_APPLY, OnApply)
ON_BN_CLICKED(IDC_PLEASEHELP, OnPleasehelp)
ON_NOTIFY(TVN_ITEMEXPANDED, IDC_TREE, OnItemexpandedTree)
//}}AFX_MSG_MAP
ON_MESSAGE( WM_PG_ENAPPLY, OnEnableApply )
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgTreeFrame message handlers
BOOL CDlgTreeFrame::OnInitDialog()
{
CDialog::OnInitDialog();
// Set tree icons if any
if ( m_dwIcon > 0 )
m_tree.SetImageList( &m_images, TVSIL_NORMAL );
// Fill in the tree
FillTree();
// Set to first page
SetPageByIndex( m_dwStartPage );
CWnd *pApply = GetDlgItem( IDC_APPLY );
if ( pApply != NULL ) pApply->EnableWindow( FALSE );
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgTreeFrame::Destroy()
{
m_pg.dwSize = 0;
m_pg.pTail = NULL;
DeleteTreePageList( m_pg.pHead );
m_pg.pHead = NULL;
m_dwSize = 0;
m_dwIndex = 0;
m_dwStartPage = 0;
// Reset image list
m_dwIcon = 0;
m_images.DeleteImageList();
}
void CDlgTreeFrame::DeleteTreePageList(LPTREEPAGEINFO node)
{
while ( node != NULL )
{ LPTREEPAGEINFO next = node->pNext;
// Delete sub pages if any
if ( node->pHead != NULL )
{ DeleteTreePageList( node->pHead );
node->pHead = NULL;
} // end if
// Delete the page
if ( node->pg != NULL )
{ delete node->pg;
node->pg = NULL;
} // end if
delete node;
node = next;
// Strike one page
if ( m_dwSize ) m_dwSize--;
} // end while
}
HTPAGE CDlgTreeFrame::AddPage(HTPAGE hParent, HICON hIcon, CDialog * pg, DWORD idd, LPCTSTR name, LPCTSTR help, LPCTSTR hlink)
{
// Sanity checks
if ( name == NULL ) return FALSE;
// Use top of list if none specified
if ( hParent == NULL ) hParent = &m_pg;
// Allocate memory
LPTREEPAGEINFO node = new TREEPAGEINFO;
if ( node == NULL ) return FALSE;
ZeroMemory( node, sizeof( TREEPAGEINFO ) );
// Save page information
node->index = m_dwIndex++;
node->icon = hIcon;
node->pg = pg;
node->idd = idd;
if ( name != NULL ) strcpy_sz( node->name, name );
if ( help != NULL ) strcpy_sz( node->help, help );
if ( hlink != NULL ) strcpy_sz( node->hlink, hlink );
// Add this node to the list
node->pParent = hParent;
node->pNext = NULL;
node->pPrev = hParent->pTail;
if ( hParent->pTail == NULL ) hParent->pHead = node;
else hParent->pTail->pNext = node;
hParent->pTail = node;
hParent->dwSize++;
m_dwSize++;
if ( hIcon != NULL )
{
// Add icon to image list
if ( m_images.GetSafeHandle() == NULL )
m_images.Create( 16, 16, ILC_MASK | ILC_COLOR24, 32, 32 );
// Add this icon
m_images.Add( hIcon );
// Count one icon
node->iindex = m_dwIcon++;
} // end if
// No icon
else node->iindex = MAXDWORD;
return node;
}
BOOL CDlgTreeFrame::RemovePage(HTPAGE hParent, HTPAGE node)
{
// Sanity check
if ( node == NULL ) return FALSE;
// Use top of list if none specified
if ( hParent == NULL ) hParent = &m_pg;
// Remove this node from the list
if ( node->pPrev != NULL ) node->pPrev->pNext = node->pNext;
if ( node->pNext != NULL ) node->pNext->pPrev = node->pPrev;
if ( hParent->pHead == node ) hParent->pHead = node->pNext;
if ( hParent->pTail == node ) hParent->pTail = node->pPrev;
// Delete this node
if ( node->pHead != NULL )
{ DeleteTreePageList( node->pHead );
node->pHead = NULL;
} // end if
delete node;
// Decrement the count
if ( m_dwSize ) m_dwSize--;
return TRUE;
}
BOOL CDlgTreeFrame::SetPage(HTPAGE hpg)
{
// Sanity checks
if ( hpg == NULL ) return FALSE;
// Lose current page
if ( m_hpg != NULL && m_hpg->pg != NULL &&
IsWindow( m_hpg->pg->GetSafeHwnd() ) )
{
// Hide the page
m_hpg->pg->ShowWindow( SW_HIDE );
} // end if
// Get a pointer to the help button
CWnd *pHelp = GetDlgItem( IDC_PLEASEHELP );
// Enable / Disable help button
if ( pHelp != NULL )
{
// Show help button if help file
if ( hpg != NULL && hpg->help[ 0 ] != NULL )
{
pHelp->ShowWindow( SW_SHOWNORMAL );
// Disable button if file not available
char link[ CWF_STRSIZE ];
CWinFile::BuildPath( link, m_helproot, hpg->help );
pHelp->EnableWindow( CWinFile::DoesExist( link ) );
} // end if
// Is there a link
else if ( hpg != NULL && hpg->hlink[ 0 ] != NULL )
pHelp->EnableWindow( TRUE );
// Hide help button if no help
else pHelp->ShowWindow( SW_HIDE );
} // end if
if ( hpg != NULL && hpg->pg != NULL )
{
// Create dialog if needed
if ( !::IsWindow( hpg->pg->GetSafeHwnd() ) )
hpg->pg->Create( hpg->idd, &m_blank );
} // end if
// Save current page
m_hpg = hpg;
m_dwLastPage = m_hpg->index;
// Size everything
Size();
return TRUE;
}
BOOL CDlgTreeFrame::Size()
{
CWnd *pBlank = GetDlgItem( IDC_BLANK );
RECT rect;
SetRect( &rect, 0, 0, 0, 0 );
// Set page parent window position
if ( pBlank != NULL )
m_blank.GetClientRect( &rect );
// InflateRect( &rect, -4, -4 );
// Set page window position
if ( m_hpg != NULL && m_hpg->pg != NULL &&
::IsWindow( m_hpg->pg->GetSafeHwnd() ) )
{
// Show the blank
if ( pBlank != NULL ) pBlank->ShowWindow( SW_SHOWNORMAL );
// Set the page position
m_hpg->pg->ShowWindow( SW_SHOWNORMAL );
m_hpg->pg->SetWindowPos( NULL, rect.left, rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
SWP_NOZORDER | SWP_NOACTIVATE );
m_hpg->pg->RedrawWindow();
} // end if
else if ( pBlank != NULL ) pBlank->ShowWindow( SW_HIDE );
return TRUE;
}
BOOL CDlgTreeFrame::SetPageByIndex( DWORD i, HTPAGE hParent )
{
LPTREEPAGEINFO ptpi = NULL;
// Search each page
while ( ( ptpi = GetNext( hParent, ptpi ) ) != NULL )
if ( ptpi->index == i ) return SetPage( ptpi );
else if ( ptpi->pHead != NULL ) if ( SetPageByIndex( i, ptpi ) )
return TRUE;
return FALSE;
}
BOOL CDlgTreeFrame::FillTree(HTPAGE hParent, HTREEITEM hItemParent)
{
DWORD added = 0;
// Reset tree contents
if ( hParent == NULL && hItemParent == NULL )
m_tree.DeleteAllItems();
LPTREEPAGEINFO ptpi = NULL;
// Search each page
while ( ( ptpi = GetNext( hParent, ptpi ) ) != NULL )
{ added++;
HTREEITEM hItem = MakeTreeEntry( ptpi->name, hItemParent, ptpi->iindex );
m_tree.SetItemData( hItem, (DWORD)ptpi );
if ( ptpi->index == m_dwStartPage ) m_tree.Select( hItem, TVGN_CARET );
if ( ptpi->pHead != NULL ) added += FillTree( ptpi, hItem );
} // end while
return added;
}
HTREEITEM CDlgTreeFrame::MakeTreeEntry(LPCTSTR pText, HTREEITEM hParent, DWORD dwImage)
{
HTREEITEM hItem;
TV_INSERTSTRUCT tv;
char pszTemp[256];
strcpy_sz( pszTemp, pText );
tv.item.pszText = pszTemp;
tv.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
tv.item.state = 0;
tv.item.iImage = dwImage;
tv.item.iSelectedImage = dwImage;
tv.hInsertAfter = TVI_LAST;
if ( hParent != NULL ) tv.hParent = hParent;
else tv.hParent = TVI_ROOT;
hItem = m_tree.InsertItem( &tv );
// Start expanded
if ( hParent != NULL )
m_tree.Expand( hParent, TVE_EXPAND );
return hItem;
}
void CDlgTreeFrame::OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
*pResult = 0;
HTREEITEM hItem = m_tree.GetSelectedItem();
if ( hItem == NULL ) return;
LPTREEPAGEINFO ptpi = (LPTREEPAGEINFO)m_tree.GetItemData( hItem );
if ( ptpi == NULL ) return;
// Make this the current page
SetPage( ptpi );
}
void CDlgTreeFrame::OnOK()
{
// Tell pages to save data
SendPageMessage( WM_PG_SAVE );
CDialog::OnOK();
}
void CDlgTreeFrame::OnCancel()
{
// Tell pages to restore data
SendPageMessage( WM_PG_RESTORE );
CDialog::OnCancel();
}
void CDlgTreeFrame::SendPageMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, LPTREEPAGEINFO pParent)
{
LPTREEPAGEINFO ptpi = NULL;
// Search each page
while ( ( ptpi = GetNext( pParent, ptpi ) ) != NULL )
{
// Send message to this page if valid
if ( ptpi->pg != NULL && ::IsWindow( ptpi->pg->GetSafeHwnd() ) )
ptpi->pg->SendMessage( uMsg, wParam, lParam );
// Send message to sub pages if any
if ( ptpi->pHead != NULL ) SendPageMessage( uMsg, wParam, lParam, ptpi );
} // end while
}
void CDlgTreeFrame::EnableApply(HWND hWnd)
{
if ( !::IsWindow( hWnd ) ) return;
hWnd = ::GetParent( hWnd );
if ( !::IsWindow( hWnd ) ) return;
hWnd = ::GetParent( hWnd );
if ( !::IsWindow( hWnd ) ) return;
::SendMessage( hWnd, WM_PG_ENAPPLY, 0, 0L );
}
LRESULT CDlgTreeFrame::OnEnableApply(WPARAM wParam, LPARAM lParam)
{
m_bApply = TRUE;
CWnd *pApply = GetDlgItem( IDC_APPLY );
if ( pApply != NULL ) pApply->EnableWindow( TRUE );
return 0;
}
void CDlgTreeFrame::OnApply()
{
// Tell pages to save data
SendPageMessage( WM_PG_SAVE );
m_bApply = FALSE;
CWnd *pApply = GetDlgItem( IDC_APPLY );
if ( pApply != NULL ) pApply->EnableWindow( FALSE );
}
void CDlgTreeFrame::OnPleasehelp()
{
if ( m_hpg == NULL ) return;
// Open help if any
if ( m_hpg->help[ 0 ] == NULL ) return;
// Open the help file
char link[ CWF_STRSIZE ];
CWinFile::BuildPath( link, m_helproot, m_hpg->help );
ShellExecute( NULL, "open", link, NULL, NULL, SW_SHOWNORMAL );
}
void CDlgTreeFrame::OnItemexpandedTree(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
}
DWORD CDlgTreeFrame::GetCurPageIndex()
{
LPTREEPAGEINFO ptpi = NULL;
// Search each page
while ( ( ptpi = GetNext( NULL, ptpi ) ) != NULL )
if ( ptpi == m_hpg ) return ptpi->index;
return 0;
}