-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewHisto.cpp
executable file
·1224 lines (1030 loc) · 31.2 KB
/
ViewHisto.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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//////////////////////////////////////////////////////////////////////
// Calques 3D - a 3D Dynamic Geometry Learning Environment
// Copyright (c) 1997-2007 Nicolas Van Labeke
//////////////////////////////////////////////////////////////////////
// This file is part of Calques 3D.
//
// Calques 3D 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.
//
// Calques 3D 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 Calques 3D; if not, write to The Free Software Foundation, Inc.,
// 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//////////////////////////////////////////////////////////////////////
// ViewHisto.cpp: implementation of the CViewHisto class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Calques3D.h"
#include "Calques3DDoc.h"
#include "ViewHisto.h"
#include "objects\Text3D.h"
#include "objects\CompositeObj3D.h"
#include "prefs\Prefs.h"
#include "Prefs\Prefs.h"
#include <io.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CViewHisto
IMPLEMENT_DYNCREATE(CViewHisto, CTreeView)//CListView)
CViewHisto::CViewHisto()
{
m_ImageList.Create(IDB_VAR_ICONS,14,0,RGB(255,255,255));
m_bRefit = FALSE;
}
CViewHisto::~CViewHisto()
{
int nb = GetDocument()->m_cObjectSet.GetSize();
for (int i=0;i<nb;i++)
{
CObject3D* pObj = GetDocument()->m_cObjectSet.GetAt(i);
if (!pObj) continue;
//if (DYNAMIC_DOWNCAST(CEquation3D,pObj)) continue;
pObj->ClearHistory();
}
}
BEGIN_MESSAGE_MAP(CViewHisto, CTreeView)//CListView)
//{{AFX_MSG_MAP(CViewHisto)
ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelChanged)
ON_NOTIFY_REFLECT(TVN_SELCHANGING, OnSelChanging)
ON_WM_KILLFOCUS()
ON_WM_SETFOCUS()
ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
ON_NOTIFY_REFLECT(TVN_ITEMEXPANDING, OnItemExpanding)
ON_NOTIFY_REFLECT(NM_CLICK, OnClick)
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_HISTORY_EXPANDALL, OnExpandAll)
ON_COMMAND(ID_HISTORY_COLLAPSEALL, OnCollapseAll)
ON_COMMAND(ID_HISTORY_EXPORTSYMBOLIC, OnHistoryExport)
ON_NOTIFY_REFLECT(TVN_ITEMEXPANDED, OnItemExpanded)
ON_WM_CONTEXTMENU()
ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
//}}AFX_MSG_MAP
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)
ON_COMMAND(ID_FILE_PRINT, CTreeView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CTreeView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CViewHisto drawing
void CViewHisto::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
/////////////////////////////////////////////////////////////////////////////
// CViewHisto diagnostics
#ifdef _DEBUG
void CViewHisto::AssertValid() const
{
CTreeView::AssertValid();
}
void CViewHisto::Dump(CDumpContext& dc) const
{
CTreeView::Dump(dc);
}
CCalques3DDoc* CViewHisto::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCalques3DDoc)));
return (CCalques3DDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CViewHisto message handlers
void CViewHisto::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();
m_pSelHiddenObject = NULL;
// TODO: Add your specialized code here and/or call the base class
//CListCtrl& mListCtrl = GetListCtrl();
CTreeCtrl& mListCtrl = GetTreeCtrl();
if (mListCtrl)
{
DWORD dwStyle = mListCtrl.GetStyle();
//dwStyle |= /*WS_CHILD | WS_VISIBLE| */LVS_LIST | /*LVS_AUTOARRANGE | /*LVS_ALIGNTOP | /*LVS_ALIGNLEFT | */
// LVS_SINGLESEL | LVS_SHOWSELALWAYS ;
dwStyle |= TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | TVS_SHOWSELALWAYS ;
::SetWindowLong(mListCtrl.m_hWnd,GWL_STYLE,dwStyle);
//DWORD dwExtStyle = mListCtrl.GetExStyle();
//dwExtStyle |= LVS_EX_INFOTIP | TVS_FULLROWSELECT ;
//mListCtrl.SetExtendedStyle(dwExtStyle);
mListCtrl.SetImageList(&m_ImageList,LVSIL_NORMAL);
int nb = GetDocument()->m_cObjectSet.GetSize();
for (int i=0;i<nb;i++)
{
CObject3D* pObj = GetDocument()->m_cObjectSet.GetAt(i);
if (!pObj) continue;
//if (DYNAMIC_DOWNCAST(CEquation3D,pObj)) continue;
pObj->DrawHistory(mListCtrl);
/* CString mstr = pObj->GetObjectDef();
TV_INSERTSTRUCT curTreeItem;
curTreeItem.hParent = TVI_ROOT;
curTreeItem.hInsertAfter = TVI_LAST;
curTreeItem.item.mask = TVIF_TEXT | TVIF_PARAM;
if (!pObj->bVisible || !pObj->bValidate)
{
curTreeItem.item.mask |= TVIF_IMAGE | TVIF_SELECTEDIMAGE ;
curTreeItem.item.iImage = (!pObj->bVisible) ? 2 : 1;
curTreeItem.item.iSelectedImage = (!pObj->bVisible) ? 2 : 1;
//curTreeItem.item.iSelectedImage = curTreeItem.item.iImage + 1;
}
curTreeItem.item.pszText = mstr.GetBuffer(mstr.GetLength());
curTreeItem.item.lParam = (LPARAM)pObj;
//pObj->CalculVisuel(GetVisualParam());
//pObj->Draw(pDC,GetVisualParam());
HTREEITEM ppTree =mListCtrl.InsertItem(&curTreeItem);
if (ppTree)
pObj->pHistItem = ppTree;*/
}
}
}
void CViewHisto::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
// TODO: Add your specialized code here and/or call the base class
// BOOL bRedraw = TRUE;
switch (lHint)
{
case WM_UPDATEOBJ_ADD: // Object Added
{
CTreeCtrl& mListCtrl = GetTreeCtrl();
if (!mListCtrl) break;
m_bRefit = TRUE;
SetRedraw(FALSE);
CObject3D *pObj=NULL;
pObj = DYNAMIC_DOWNCAST(CObject3D,pHint);
if (pObj) pObj->DrawHistory(mListCtrl);
m_bRefit = FALSE;
SetRedraw(TRUE);
}
break;
case WM_UPDATEOBJ_MOD: // Object Modified
{
CTreeCtrl& mListCtrl = GetTreeCtrl();
if (!mListCtrl) break;
CObject3D *pObj = DYNAMIC_DOWNCAST(CObject3D,pHint);
if (!pObj) break;
pObj->DrawHistory(mListCtrl);
CxObject3DSet mySet;
pObj->GetDependList(&mySet);
int nb = mySet.GetSize();
for (int i=0;i<nb;i++)
{
CObject3D* pObj2 = mySet.GetAt(i);
if (!pObj2) continue;
pObj2->DrawHistory(mListCtrl);
}
}
break;
case WM_UPDATEOBJ_MOV: // Object Moved
{
CTreeCtrl& mListCtrl = GetTreeCtrl();
if (!mListCtrl) break;
CObject3D *pObj2 = DYNAMIC_DOWNCAST(CObject3D,pHint);
if (!pObj2) break;
CxObject3DSet plist;
pObj2->GetDependList(&plist);
for (int i=0;i<plist.GetSize();i++)
{
CObject3D* pObj = plist[i];
if (!pObj) continue;
if (pObj->pComposite) continue;
pObj->DrawHistory(mListCtrl);
}
}
break;
case WM_UPDATEOBJ_SEL: // Object Selected
{
CTreeCtrl& mListCtrl = GetTreeCtrl();
if (!mListCtrl) break;
CObject3D *pObj2 = DYNAMIC_DOWNCAST(CObject3D,pHint);
//CEquation3D *pEqu = DYNAMIC_DOWNCAST(CEquation3D,pObj2);
//if (pEqu)
{
//pObj2 = pEqu->pSource;
}
if (m_pSelHiddenObject!=NULL)
{
m_pSelHiddenObject->SetVisible(false);
OnUpdate(this,WM_UPDATEOBJ_MOD,m_pSelHiddenObject);
m_pSelHiddenObject=NULL;
}
HTREEITEM pItem = NULL;
if (pObj2 && pObj2->pHistItem)
pItem = pObj2->pHistItem;
m_bRefit = TRUE;
mListCtrl.Select(pItem,TVGN_CARET);
m_bRefit = FALSE;
}
break;
case WM_UPDATEOBJ_DEL: // Object Deleted
{
CTreeCtrl& mListCtrl = GetTreeCtrl();
if (!mListCtrl) break;
SetRedraw(FALSE);
CObject3D *pObj2 = DYNAMIC_DOWNCAST(CObject3D,pHint);
if (pObj2 && pObj2->pHistItem)
{
mListCtrl.DeleteItem(pObj2->pHistItem);
pObj2->ClearHistory();
}
int nb = GetDocument()->m_cObjectSet.GetSize();
for (int i=0;i<nb;i++)
{
CObject3D* pObj = GetDocument()->m_cObjectSet.GetAt(i);
//if (DYNAMIC_DOWNCAST(CEquation3D,pObj)) continue;
if (!pObj) continue;
pObj->DrawHistory(mListCtrl);
}
SetRedraw(TRUE);
}
case WM_UPDATEOBJ_ALL: // Objects redrawn
default:
// bRedraw = FALSE;
break;
}
// if (bRedraw)
// {
// Invalidate();
// UpdateWindow();
// }
}
void CViewHisto::OnSelChanged(NMHDR* pNMHDR, LRESULT* pResult)
{
if (m_bRefit) return;
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
// TVITEM pOld = pNMTreeView->itemOld;
TVITEM pNew = pNMTreeView->itemNew;
BOOL bRedraw = FALSE;
CObject3D* pObj = NULL;
if (m_pSelHiddenObject!=NULL)
{
m_pSelHiddenObject->SetVisible(false);
OnUpdate(this,WM_UPDATEOBJ_MOD,m_pSelHiddenObject);
m_pSelHiddenObject=NULL;
}
if (pNew.hItem)
{
pObj = (CObject3D*)pNew.lParam;
if (pObj)
{
// pObj->bIsSelected = TRUE;
if (!pObj->IsVisible() && TPref::THistory.bShowSelectHidden)
{
m_pSelHiddenObject = pObj;
m_pSelHiddenObject->SetVisible(true);
OnUpdate(this,WM_UPDATEOBJ_MOD,pObj);
}
bRedraw = TRUE;
}
}
if (bRedraw)
GetDocument()->UpdateAllViews(this,WM_UPDATEOBJ_SEL,pObj);
*pResult = 0;
}
void CViewHisto::OnSelChanging(NMHDR* pNMHDR, LRESULT* pResult)
{
if (m_bRefit) return;
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
/*
BOOL bRedraw = FALSE;
CObject3D* pObj =NULL;
TVITEM pNew = pNMTreeView->itemOld;
if (pNew.hItem)
{
pObj = (CObject3D*)pNew.lParam;
if (pObj)
{
//pObj->bIsSelected = FALSE;
bRedraw = TRUE;
}
}
if (bRedraw)
GetDocument()->UpdateAllViews(this,WM_UPDATEOBJ_MOD,pObj);
*/
*pResult = 0;
}
void CViewHisto::OnKillFocus(CWnd* pNewWnd)
{
CTreeView::OnKillFocus(pNewWnd);
if (m_bRefit) return;
if (m_pSelHiddenObject!=NULL)
{
m_pSelHiddenObject->SetVisible(false);
OnUpdate(this,WM_UPDATEOBJ_MOD,m_pSelHiddenObject);
m_pSelHiddenObject=NULL;
}
// TODO: Add your message handler code here
/* CTreeCtrl& mListCtrl = GetTreeCtrl();
if (!mListCtrl) return;
HTREEITEM pItem = mListCtrl.GetSelectedItem();
if (!pItem) return;
CObject3D* pObj = (CObject3D*)(mListCtrl.GetItemData(pItem));
if (!pObj) return;
pObj->bIsSelected = FALSE;
GetDocument()->UpdateAllViews(this,WM_UPDATEOBJ_MOD,pObj);*/
}
void CViewHisto::OnSetFocus(CWnd* pOldWnd)
{
CTreeView::OnSetFocus(pOldWnd);
if (m_bRefit) return;
/* // TODO: Add your message handler code here
CTreeCtrl& mListCtrl = GetTreeCtrl();
if (!mListCtrl) return;
HTREEITEM pItem = mListCtrl.GetSelectedItem();
if (!pItem) return;
CObject3D* pObj = (CObject3D*)(mListCtrl.GetItemData(pItem));
if (!pObj) return;
pObj->bIsSelected = TRUE;
GetDocument()->UpdateAllViews(this,WM_UPDATEOBJ_MOD,pObj);*/
}
void CViewHisto::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
{
if (m_bRefit) return;
// TODO: Add your control notification handler code here
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
CTreeCtrl& mListCtrl = GetTreeCtrl();
if (!mListCtrl) return;
HTREEITEM pItem = mListCtrl.GetSelectedItem();
if (!pItem) return;
CObject3D* pObj = (CObject3D*)(mListCtrl.GetItemData(pItem));
if (!pObj) return;
if (pObj->bValidate)
{
if (m_pSelHiddenObject == pObj)
{
pObj->SetVisible(false);
}
GetDocument()->ModifyPropObject(pObj);
if (m_pSelHiddenObject == pObj)
{
if (pObj->IsVisible())
{
m_pSelHiddenObject = NULL;
}
}
}
else
{
UINT rr = pObj->CalculConceptuel();
pObj->HandleObjectError(rr,TRUE);
}
//pObj->SetProperties();
*pResult = 1;
}
void CViewHisto::OnItemExpanding(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
SetRedraw(FALSE);
*pResult = 0;
}
void CViewHisto::OnItemExpanded(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
SetRedraw(TRUE);
*pResult = 0;
}
void CViewHisto::OnClick(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
*pResult = 0;
}
void CViewHisto::OnFilePrintPreview()
{
BCGPPrintPreview (this);
}
void CViewHisto::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
NMTVCUSTOMDRAW *pcd = (NMTVCUSTOMDRAW *)pNMHDR;
HTREEITEM hitem;
CTreeCtrl& mListCtrl = GetTreeCtrl();
if (!mListCtrl) return;
switch ( pcd->nmcd.dwDrawStage )
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW;
return;
case CDDS_ITEMPREPAINT :
hitem = (HTREEITEM)pcd->nmcd.dwItemSpec;
NMCUSTOMDRAW mcd = pcd->nmcd;
CObject3D* pObj = (CObject3D*)mListCtrl.GetItemData(hitem);
//#define CDIS_SELECTED 0x0001
//#define CDIS_GRAYED 0x0002
//#define CDIS_DISABLED 0x0004
//#define CDIS_CHECKED 0x0008
//#define CDIS_FOCUS 0x0010
//#define CDIS_DEFAULT 0x0020
//#define CDIS_HOT 0x0040
//#define CDIS_MARKED 0x0080
//#define CDIS_INDETERMINATE 0x0100
if (mcd.hdc)
{
CDC ppDC;
CDC *pDC = ppDC.FromHandle(mcd.hdc);
if (pDC)
{
CFont *mFont = pDC->GetCurrentFont();
}
}
//SelectObject(pcd->nmcd.hdc, hfnt);
if (pObj && !pObj->bValidate)
{
//if (!(mcd.uItemState & CDIS_SELECTED))
pcd->clrText = RGB(255,0,0);
if (mcd.uItemState & CDIS_FOCUS)
pcd->clrText = RGB(255,128,128);
//pcd->clrTextBk =RGB(255,0,0);
}
if (pObj && !pObj->bVisible)
{
pcd->clrText = RGB(128,128,128);
}
*pResult = CDRF_DODEFAULT;// do not set *pResult = CDRF_SKIPDEFAULT
return;
}
}
#define LEFT_MARGIN 4
#define RIGHT_MARGIN 4
#define TOP_MARGIN 4
#define BOTTOM_MARGIN 4
void CViewHisto::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
// CTreeView::OnPrint(pDC, pInfo);
// Save dc state
int nSavedDC = pDC->SaveDC();
// Set font
CFont Font;
LOGFONT lf;
CFont *pOldFont = GetFont();
pOldFont->GetLogFont(&lf);
lf.lfHeight=m_nRowHeight-1;
lf.lfWidth=0;
Font.CreateFontIndirect(&lf);
pDC->SelectObject(&Font);
// PrintHeadFoot(pDC,pInfo);
pDC->SetWindowOrg(-1*(LEFT_MARGIN*m_nCharWidth),-m_nRowHeight*TOP_MARGIN);
int height;
if (pInfo->m_nCurPage==pInfo->GetMaxPage())
height=rcBounds.Height()-((pInfo->m_nCurPage-1)*m_nRowsPerPage*m_nRowHeight);
else
height=m_nRowsPerPage*m_nRowHeight;
int top=(pInfo->m_nCurPage-1)*m_nRowsPerPage*m_nRowHeight;
pDC->SetBkColor(RGB(255,255,255));
pDC->SetTextColor(RGB(0,0,0));
LPBITMAPINFOHEADER lpbi;
lpbi = (LPBITMAPINFOHEADER)hDIB;
int nColors = lpbi->biClrUsed ? lpbi->biClrUsed : 1 << lpbi->biBitCount;
BITMAPINFO &bmInfo = *(LPBITMAPINFO)hDIB;
LPVOID lpDIBBits;
if( bmInfo.bmiHeader.biBitCount > 8 )
lpDIBBits = (LPVOID)((LPDWORD)(bmInfo.bmiColors +
bmInfo.bmiHeader.biClrUsed) +
((bmInfo.bmiHeader.biCompression == BI_BITFIELDS) ? 3 : 0));
else
lpDIBBits = (LPVOID)(bmInfo.bmiColors + nColors);
HDC hDC=pDC->GetSafeHdc();
StretchDIBits(hDC, // hDC
0, // DestX
0, // DestY
rcBounds.Width(), // nDestWidth
height, // nDestHeight
rcBounds.left, // SrcX
rcBounds.Height()-top-height, // SrcY
rcBounds.Width(), // wSrcWidth
height, // wSrcHeight
lpDIBBits, // lpBits
&bmInfo, // lpBitsInfo
DIB_RGB_COLORS, // wUsage
SRCCOPY); // dwROP
pDC->SelectObject(pOldFont);
pDC->RestoreDC( nSavedDC );
}
BOOL CViewHisto::OnPreparePrinting(CPrintInfo* pInfo)
{
// TODO: call DoPreparePrinting to invoke the Print dialog box
return DoPreparePrinting(pInfo);
//return CTreeView::OnPreparePrinting(pInfo);
}
void CViewHisto::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
CTreeCtrl& mListCtrl = GetTreeCtrl();
if (!mListCtrl) return;
CTreeCtrl* Tree = &mListCtrl ;
HTREEITEM hItem=Tree->GetRootItem();
Tree->GetItemRect(hItem,rcBounds,TRUE);
m_nRowHeight = rcBounds.Height();
// Find the total number of visible items & the right most coordinate
int ItemCount=0;
do
{
ItemCount++;
CRect rc;
Tree->GetItemRect(hItem,rc,TRUE);
if (rc.right>rcBounds.right)
rcBounds.right=rc.right;
hItem=Tree->GetNextItem(hItem,TVGN_NEXTVISIBLE);
}
while (hItem);
// Find the entire print boundary
int ScrollMin,ScrollMax;
GetScrollRange(SB_HORZ,&ScrollMin,&ScrollMax);
rcBounds.left=0;
if (ScrollMax>rcBounds.right)
rcBounds.right=ScrollMax+1;
rcBounds.top=0;
rcBounds.bottom=m_nRowHeight*ItemCount;
// Get text width
CDC *pCtlDC = Tree->GetDC();
if (NULL == pCtlDC) return;
TEXTMETRIC tm;
pCtlDC->GetTextMetrics(&tm);
m_nCharWidth = tm.tmAveCharWidth;
double d = (double)pDC->GetDeviceCaps(LOGPIXELSY)/(double)pCtlDC->GetDeviceCaps(LOGPIXELSY);
ReleaseDC(pCtlDC);
// Find rows per page
int nPageHeight = pDC->GetDeviceCaps(VERTRES);
m_nRowsPerPage = (int)((double)nPageHeight/d)/m_nRowHeight-TOP_MARGIN-BOTTOM_MARGIN;
// Set maximum pages
int pages=(ItemCount-1)/m_nRowsPerPage+1;
pInfo->SetMaxPage(pages);
// Create a memory DC compatible with the paint DC
CPaintDC dc(this);
CDC MemDC;
MemDC.CreateCompatibleDC(&dc);
// Select a compatible bitmap into the memory DC
CBitmap bitmap;
bitmap.CreateCompatibleBitmap(&dc, rcBounds.Width(), rcBounds.Height() );
MemDC.SelectObject(&bitmap);
// Enlarge window size to include the whole print area boundary
GetWindowPlacement(&WndPlace);
MoveWindow(0,0,::GetSystemMetrics(SM_CXEDGE)*2+rcBounds.Width(),
::GetSystemMetrics(SM_CYEDGE)*2+rcBounds.Height(),FALSE);
ShowScrollBar(SB_BOTH,FALSE);
// Call the default printing
Tree->EnsureVisible(Tree->GetRootItem());
CWnd::DefWindowProc( WM_PAINT, (WPARAM)MemDC.m_hDC, 0 );
// Now create a mask
CDC MaskDC;
MaskDC.CreateCompatibleDC(&dc);
CBitmap maskBitmap;
// Create monochrome bitmap for the mask
maskBitmap.CreateBitmap( rcBounds.Width(), rcBounds.Height(), 1, 1, NULL );
MaskDC.SelectObject( &maskBitmap );
MemDC.SetBkColor( ::GetSysColor( COLOR_WINDOW ) );
// Create the mask from the memory DC
MaskDC.BitBlt( 0, 0, rcBounds.Width(), rcBounds.Height(), &MemDC,
rcBounds.left, rcBounds.top, SRCCOPY );
// Copy image to clipboard
CBitmap clipbitmap;
clipbitmap.CreateCompatibleBitmap(&dc, rcBounds.Width(), rcBounds.Height() );
CDC clipDC;
clipDC.CreateCompatibleDC(&dc);
CBitmap* pOldBitmap = clipDC.SelectObject(&clipbitmap);
clipDC.BitBlt( 0, 0, rcBounds.Width(), rcBounds.Height(), &MemDC,
rcBounds.left, rcBounds.top, SRCCOPY);
OpenClipboard();
EmptyClipboard();
SetClipboardData(CF_BITMAP, clipbitmap.GetSafeHandle());
CloseClipboard();
clipDC.SelectObject(pOldBitmap);
clipbitmap.Detach();
// Copy the image in MemDC transparently
MemDC.SetBkColor(RGB(0,0,0));
MemDC.SetTextColor(RGB(255,255,255));
MemDC.BitBlt(rcBounds.left, rcBounds.top, rcBounds.Width(), rcBounds.Height(),
&MaskDC, rcBounds.left, rcBounds.top, MERGEPAINT);
CPalette pal;
hDIB=DDBToDIB(bitmap, BI_RGB, &pal );
//CTreeView::OnBeginPrinting(pDC, pInfo);
}
HANDLE CViewHisto::DDBToDIB( CBitmap& bitmap, DWORD dwCompression, CPalette* pPal )
{
BITMAP bm;
BITMAPINFOHEADER bi;
LPBITMAPINFOHEADER lpbi;
DWORD dwLen;
HANDLE hDIB;
HANDLE handle;
HDC hDC;
HPALETTE hPal;
ASSERT( bitmap.GetSafeHandle() );
// The function has no arg for bitfields
if ( dwCompression == BI_BITFIELDS )
return NULL;
// If a palette has not been supplied use defaul palette
hPal = (HPALETTE) pPal->GetSafeHandle();
if (hPal==NULL)
hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE);
// Get bitmap information
bitmap.GetObject(sizeof(bm),(LPSTR)&bm);
// Initialize the bitmapinfoheader
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = bm.bmWidth;
bi.biHeight = bm.bmHeight;
bi.biPlanes = 1;
bi.biBitCount = bm.bmPlanes * bm.bmBitsPixel;
bi.biCompression = dwCompression;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
// Compute the size of the infoheader and the color table
int nColors = (1 << bi.biBitCount);
if ( nColors > 256 )
nColors = 0;
dwLen = bi.biSize + nColors * sizeof(RGBQUAD);
// We need a device context to get the DIB from
hDC = ::GetDC(NULL);
hPal = SelectPalette(hDC,hPal,FALSE);
RealizePalette(hDC);
// Allocate enough memory to hold bitmapinfoheader and color table
hDIB = GlobalAlloc(GMEM_FIXED,dwLen);
if (!hDIB)
{
SelectPalette(hDC,hPal,FALSE);
::ReleaseDC(NULL,hDC);
return NULL;
}
lpbi = (LPBITMAPINFOHEADER)hDIB;
*lpbi = bi;
// Call GetDIBits with a NULL lpBits param, so the device driver
// will calculate the biSizeImage field
GetDIBits(hDC, (HBITMAP)bitmap.GetSafeHandle(), 0L, (DWORD)bi.biHeight,
(LPBYTE)NULL, (LPBITMAPINFO)lpbi, (DWORD)DIB_RGB_COLORS);
bi = *lpbi;
// If the driver did not fill in the biSizeImage field, then compute it
// Each scan line of the image is aligned on a DWORD (32bit) boundary
if (bi.biSizeImage == 0)
{
bi.biSizeImage = ((((bi.biWidth * bi.biBitCount) + 31) & ~31) / 8)
* bi.biHeight;
// If a compression scheme is used the result may infact be larger
// Increase the size to account for this.
if (dwCompression != BI_RGB)
bi.biSizeImage = (bi.biSizeImage * 3) / 2;
}
// Realloc the buffer so that it can hold all the bits
dwLen += bi.biSizeImage;
if (handle = GlobalReAlloc(hDIB, dwLen, GMEM_MOVEABLE))
hDIB = handle;
else
{
GlobalFree(hDIB);
// Reselect the original palette
SelectPalette(hDC,hPal,FALSE);
::ReleaseDC(NULL,hDC);
return NULL;
}
// Get the bitmap bits
lpbi = (LPBITMAPINFOHEADER)hDIB;
// FINALLY get the DIB
BOOL bGotBits = GetDIBits( hDC, (HBITMAP)bitmap.GetSafeHandle(),
0L, // Start scan line
(DWORD)bi.biHeight, // # of scan lines
(LPBYTE)lpbi // address for bitmap bits
+ (bi.biSize + nColors * sizeof(RGBQUAD)),
(LPBITMAPINFO)lpbi, // address of bitmapinfo
(DWORD)DIB_RGB_COLORS); // Use RGB for color table
if( !bGotBits )
{
GlobalFree(hDIB);
SelectPalette(hDC,hPal,FALSE);
::ReleaseDC(NULL,hDC);
return NULL;
}
SelectPalette(hDC,hPal,FALSE);
::ReleaseDC(NULL,hDC);
return hDIB;
}
void CViewHisto::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
GlobalFree(hDIB);
SetWindowPlacement(&WndPlace);
RedrawWindow();
//CTreeView::OnEndPrinting(pDC, pInfo);
}
void CViewHisto::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
CTreeView::OnPrepareDC(pDC, pInfo);
// Map logical unit of screen to printer unit
pDC->SetMapMode(MM_ANISOTROPIC);
CClientDC dcScreen(NULL);
pDC->SetWindowExt(dcScreen.GetDeviceCaps(LOGPIXELSX),dcScreen.GetDeviceCaps(LOGPIXELSX));
pDC->SetViewportExt(pDC->GetDeviceCaps(LOGPIXELSX),pDC->GetDeviceCaps(LOGPIXELSX));
}
void CViewHisto::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
/*CWnd *pwnd = AfxGetMainWnd();
CString strHelp;
strHelp.LoadString(AFX_IDS_IDLEMESSAGE);
pwnd->SendMessage(WM_SHOWCTXTHELP,(WPARAM)(&strHelp));*/
CTreeView::OnMouseMove(nFlags, point);
}
void CViewHisto::OnExpandAll()
{
// TODO: Add your command handler code here
SetRedraw(FALSE);
CTreeCtrl& mListCtrl = GetTreeCtrl();
if (!mListCtrl) return;
//mListCtrl.Expand(TVI_ROOT,TVE_TOGGLE);
HTREEITEM hti = mListCtrl.GetRootItem();
do
{
ExpandBranch( hti );
}
while( (hti = mListCtrl.GetNextSiblingItem( hti )) != NULL );
//ExpandBranch(hti);
SetRedraw(TRUE);
}
void CViewHisto::OnCollapseAll()
{
SetRedraw(FALSE);
CTreeCtrl& mListCtrl = GetTreeCtrl();
if (!mListCtrl) return;
//mListCtrl.Expand(TVI_ROOT,TVE_TOGGLE);
HTREEITEM hti = mListCtrl.GetRootItem();
do
{
CollapseBranch( hti );
}
while( (hti = mListCtrl.GetNextSiblingItem( hti )) != NULL );
//ExpandBranch(hti);
SetRedraw(TRUE);
}
void CViewHisto::ExpandBranch( HTREEITEM hti )
{
CTreeCtrl& mListCtrl = GetTreeCtrl();
if (!mListCtrl) return;
if( mListCtrl.ItemHasChildren( hti ) && hti != NULL)
{
mListCtrl.Expand( hti, TVE_EXPAND );
hti = mListCtrl.GetChildItem( hti );
do
{
ExpandBranch( hti );
}
while( (hti = mListCtrl.GetNextSiblingItem( hti )) != NULL );
}
mListCtrl.EnsureVisible( mListCtrl.GetSelectedItem() );
}
void CViewHisto::CollapseBranch( HTREEITEM hti )
{
CTreeCtrl& mListCtrl = GetTreeCtrl();
if (!mListCtrl) return;
if( mListCtrl.ItemHasChildren( hti ) && hti != NULL)
{
mListCtrl.Expand( hti, TVE_COLLAPSE );
hti = mListCtrl.GetChildItem( hti );
do
{
CollapseBranch( hti );
}
while( (hti = mListCtrl.GetNextSiblingItem( hti )) != NULL );
}
mListCtrl.EnsureVisible( mListCtrl.GetSelectedItem() );
}
void CViewHisto::OnHistoryExport()
{
static int nDefFormat = 1;
CString szFilter = _T("Mathematica Symbolic Description (*.txt)|*.txt|");
szFilter += _T("Maple Symbolic Description (*.txt)|*.txt|");
szFilter += _T("X3D Scene (*.x3d)|*.x3d|");
szFilter += _T("DOT Graph Layout (*.dot)|*.dot||");
CFileDialog mdlg(FALSE,_T("txt"),_T("*.txt"),
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
szFilter,
this);
DWORD mFlag = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
mdlg.m_ofn.Flags |= mFlag;
mdlg.m_ofn.nFilterIndex = nDefFormat;
int ret = mdlg.DoModal();
if (ret!=IDOK) return;
CString m_strPath = mdlg.m_ofn.lpstrFile;
int nformat = mdlg.m_ofn.nFilterIndex;
nDefFormat = nformat;
CString strSymb;
if (nformat==1)
strSymb = OnExportSymbolic(CObject3D::EXPORT_MATHEMATICA);
else if (nformat==2)
strSymb = OnExportSymbolic(CObject3D::EXPORT_MAPLE);
else if (nformat==3)
strSymb = OnExportX3D();
else if (nformat==4)
strSymb = OnExportDot();
else
return;
FILE *fp = NULL;
fopen_s(&fp,mdlg.m_ofn.lpstrFile,_T("w+"));
TRY
{