-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormFrame.cpp
More file actions
1024 lines (925 loc) · 27.6 KB
/
FormFrame.cpp
File metadata and controls
1024 lines (925 loc) · 27.6 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
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
// FormFrame.cpp: implementation of the CFormFrame class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "usermsgs.h"
#include "FormFrame.h"
#include "MainFrm.h"
extern CMainFrame wndMain;
CFormFrame::CFormFrame(LPCTSTR file):\
m_FES_Busy(FALSE),
m_FES_Modified(FALSE),
m_FES_CanPaste(FALSE),
m_FES_CanUndo(FALSE),
m_FES_CanRedo(FALSE),
m_FES_ItemCount(0),
m_FES_SelectedItemCount(0),
m_bModified(FALSE),
m_file(file)
{
//g_app.IncScript();
}
CFormFrame::~CFormFrame()
{
//g_app.DecScript();
}
HRESULT CFormFrame::OnStateChanged(VARIANT_BOOL Busy, VARIANT_BOOL Modified, VARIANT_BOOL CanPaste, VARIANT_BOOL CanUndo, VARIANT_BOOL CanRedo, LONG ItemCount, LONG SelectedItemCount)
{
// save the form editor state
m_FES_Busy=Busy;
m_FES_Modified=Modified;
m_FES_CanPaste=CanPaste;
m_FES_CanUndo=CanUndo;
m_FES_CanRedo=CanRedo;
m_FES_ItemCount=ItemCount;
m_FES_SelectedItemCount=SelectedItemCount;
// set the modified flag
if(Modified)
{
SetModified(TRUE);
}
BOOL bSel = SelectedItemCount > 0 ? TRUE : FALSE;
UIEnable(ID_EDIT_PASTE, CanPaste == VARIANT_TRUE ? TRUE : FALSE );
UIEnable(ID_UNDO, CanUndo == VARIANT_TRUE ? TRUE : FALSE );
UIEnable(ID_REDO, CanRedo == VARIANT_TRUE ? TRUE : FALSE );
UIEnable(ID_EDIT_CUT,bSel);
UIEnable(ID_EDIT_COPY,bSel);
UIEnable(ID_DELETE,bSel);
UIEnable(ID_SELECT_ALL,ItemCount > 0 ? TRUE : FALSE);
UIEnable(ID_UNSELECT_ALL,bSel);
// etc ...
return S_OK;
}
HRESULT CFormFrame::OnEditScriptError(BSTR Source, long Number, BSTR description)
{
USES_CONVERSION;
LPCTSTR src = OLE2CT(Source);
LPCTSTR desc = OLE2CT(description);
CString s;
s.Format(_T("Error source: %s\r\nError number: %X\r\nDescription: %s"),
src,Number,desc);
MessageBox(s,_T("Error"),MB_ICONINFORMATION);
return S_OK;
}
// CFormFrame
BOOL CFormFrame::PreTranslateMessage(MSG* pMsg)
{
if(baseClass::PreTranslateMessage(pMsg))
return TRUE;
if(pMsg->message < WM_KEYFIRST || pMsg->message > WM_KEYLAST)
return FALSE;
CWindow wnd = pMsg->hwnd;
// determine which component the target window belongs to
CComPtr<IUnknown> spUnknown;
if(m_axFormEdit.IsWindow() && m_spFormEditor) // form editor
{
if(wnd==m_axFormEdit || m_axFormEdit.IsChild(wnd))
{
spUnknown= m_spFormEditor;
}
}
if(m_axScriptEdit.IsWindow() && m_spScriptEditor) // script editor
{
if(wnd==m_axScriptEdit || m_axScriptEdit.IsChild(wnd))
{
spUnknown=m_spScriptEditor;
}
}
if(m_axFormView.IsWindow() && m_spFormViewer) // form viewer
{
if(wnd==m_axFormView || m_axFormView.IsChild(wnd))
{
spUnknown=m_spFormViewer;
}
}
// if we need to handle the message
if(spUnknown!=NULL)
{
// give the component chance to translate accelerators
CComQIPtr<IOleInPlaceActiveObject> spOleInPlaceActiveObject(spUnknown);
if(spOleInPlaceActiveObject!=NULL &&
spOleInPlaceActiveObject->TranslateAccelerator(pMsg)!=S_FALSE)
{
return TRUE; // message handled
}
// if required give the host chance to translate accelerators, for example
}
return FALSE;
}
LRESULT CFormFrame::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
LRESULT res = baseClass::OnCreate(uMsg,wParam,lParam,bHandled);
bHandled = TRUE;
HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_FORMS),
IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
SetIcon(hIcon, TRUE);
HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_FORMS),
IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
SetIcon(hIconSmall, FALSE);
// create command bar window
HWND hWndCmdBar = m_CmdBar.Create(m_hWnd, rcDefault, NULL, ATL_SIMPLE_CMDBAR_PANE_STYLE);
// attach menu
m_CmdBar.AttachMenu(GetMenu());
// load command bar images
m_CmdBar.LoadImages(IDR_FORMFRAME);
// remove old menu
SetMenu(NULL);
HWND hWndToolBar = CreateSimpleToolBarCtrl(m_hWnd, IDR_FORMFRAME, FALSE, ATL_SIMPLE_TOOLBAR_PANE_STYLE);
UIAddToolBar(hWndToolBar);
CreateSimpleReBar(ATL_SIMPLE_REBAR_NOBORDER_STYLE);
AddSimpleReBarBand(hWndCmdBar);
AddSimpleReBarBand(hWndToolBar, NULL, TRUE);
hWndToolBar = CreateSimpleToolBarCtrl(m_hWnd, IDR_TOOLBAR2, FALSE, ATL_SIMPLE_TOOLBAR_PANE_STYLE);
UIAddToolBar(hWndToolBar);
AddSimpleReBarBand(hWndToolBar, NULL, TRUE);
hWndToolBar = CreateSimpleToolBarCtrl(m_hWnd, IDR_TOOLBAR3, FALSE, ATL_SIMPLE_TOOLBAR_PANE_STYLE);
UIAddToolBar(hWndToolBar);
AddSimpleReBarBand(hWndToolBar, NULL, TRUE);
CreateSimpleStatusBar();
UIAddToolBar(hWndToolBar);
UISetCheck(ID_VIEW_TOOLBAR, 1);
UISetCheck(ID_VIEW_STATUS_BAR, 1);
UIEnable(ID_EDIT_CUT,FALSE);
UIEnable(ID_EDIT_COPY,FALSE);
UIEnable(ID_EDIT_PASTE,FALSE);
UIEnable(ID_DELETE,FALSE);
UIEnable(ID_SELECT_ALL,FALSE);
UIEnable(ID_UNSELECT_ALL,FALSE);
// etc ...
// register object for message filtering and idle updates
CMessageLoop* pLoop = _Module.GetMessageLoop();
ATLASSERT(pLoop != NULL);
pLoop->AddMessageFilter(this);
HRESULT hr = S_OK;
//USES_CONVERSION;
LPOLESTR p = NULL;
ITypeLib *ptl = NULL;
/*hr = ::LoadTypeLib(OLESTR("irc12.tlb"), &ptl);
ATLASSERT(SUCCEEDED(hr));
hr = UpdateRegistry(FALSE);
ATLASSERT(SUCCEEDED(hr));
ptl->Release();*/
//hr = StringFromCLSID(DDFORMSLib::CLSID_FormEditor, &p);
hr = ::StringFromCLSID((DDFORMSLib::CLSID_FormEditor), &p);
if (SUCCEEDED(hr) && p) {
USES_CONVERSION;
CString id = _T("{E78FC0E6-1C8E-11D6-B6A6-B864D14CD046}");
//id += p;
//id = id.Right(id.GetLength() - 5);
ATLASSERT(IsWindow());
try {
HWND hWnd = m_axFormEdit.Create(m_hWnd, NULL, OLE2T(p), WS_CHILD | WS_VISIBLE, 0, (HMENU)IDC_FORMEDITOR1);
}
catch (...) {
MessageBox(GetErrorDesc(GetLastError()));
}
::CoTaskMemFree(p);
p = NULL;
}
hr = StringFromCLSID(DDFORMSLib::CLSID_SimpleScriptEditor, &p);
if (SUCCEEDED(hr) && p) {
CString id = _T("CLSID:");
id += p;
m_axScriptEdit.Create(m_hWnd, NULL,OLE2T(p), WS_CHILD | WS_VISIBLE, 0, (HMENU)IDC_SIMPLESCRIPTEDITOR1);
CoTaskMemFree(p);
p = NULL;
}
hr = StringFromCLSID(DDFORMSLib::CLSID_FormViewer, &p);
if (SUCCEEDED(hr) && p) {
CString id = _T("CLSID:");
id += p;
m_axFormView.Create(m_hWnd, NULL, OLE2T(p), WS_CHILD | WS_VISIBLE, 0, (HMENU)IDC_FORMVIEWER1);
CoTaskMemFree(p);
p = NULL;
}
if(SUCCEEDED(hr)){
hr = AtlAdviseSinkMap(this,true);
}
AddTab(m_axFormEdit,_T("form editor"));
AddTab(m_axScriptEdit,_T("script editor"));
AddTab(m_axFormView,_T("form view"));
ATLASSERT(SUCCEEDED(hr));
if(SUCCEEDED(hr)){
hr = m_axFormEdit.QueryControl(&m_spFormEditor);
if(SUCCEEDED(hr)){
hr = m_axFormView.QueryControl(&m_spFormViewer);
if (SUCCEEDED(hr)) {
hr = m_axScriptEdit.QueryControl(&m_spScriptEditor);
if (SUCCEEDED(hr)) {
CComPtr<DDFORMSLib::IScript2> spScript;
hr = m_spFormEditor->get_Script(&spScript);
if (SUCCEEDED(hr)) {
CComPtr<IUnknown> sp;
m_spScriptEditor.QueryInterface(&sp);
hr = spScript->put_Editor(sp);
if (SUCCEEDED(hr)) {
hr = m_spFormEditor->DDUnlock(0x355EFB54, 0x55385022, 0x019954C1, 0x4ED0972B);
if (SUCCEEDED(hr)) {
CComQIPtr<IDispatch> sp; wndMain.m_pIrc->QueryInterface(&sp);
ATLASSERT(!!sp);
hr = m_spFormEditor->Expose(OLESTR("no5"), sp);
if (SUCCEEDED(hr)) {
CComQIPtr<IDispatch> sp2 = sp;
hr = m_spFormViewer->Expose(OLESTR("no5"), sp2);
if (SUCCEEDED(hr)) {
if (m_file.IsEmpty())
FileNew();
else
FileOpen(m_file);
}
}
}
}
}
}
}
}
}
// put font of script editor
if(SUCCEEDED(hr) && m_spScriptEditor != NULL){
CComPtr<IFontDisp> spFont;
FONTDESC fd = { sizeof(fd),OLESTR("Courier"),FONTSIZE( 10 ),FW_NORMAL,ANSI_CHARSET,FALSE,FALSE,
FALSE };
HRESULT hr;
hr = ::OleCreateFontIndirect(&fd,IID_IFontDisp,(void **)&spFont);
if(SUCCEEDED(hr)){
hr = m_spScriptEditor->put_Font(spFont);
}
ATLASSERT(SUCCEEDED(hr));
}
ATLASSERT(SUCCEEDED(hr));
//bHandled = FALSE;
return 0;
}
LRESULT CFormFrame::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
baseClass::OnDestroy(uMsg,wParam,lParam,bHandled); // DestroyTabWindow();
AtlAdviseSinkMap(this,false);
bHandled = TRUE;
return 0;
}
LRESULT CFormFrame::OnNCDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return 0;
}
LRESULT CFormFrame::OnFileNew(WORD,WORD,HWND,BOOL &)
{
FileNew();
return 0;
}
LRESULT CFormFrame::OnFileOpen(WORD,WORD,HWND,BOOL &)
{
CFileDialog dlg(\
TRUE, // file open
_T("ddl"), // default extension
NULL, // file name
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_NOCHANGEDIR, // flags
_T("ddf files\0*.ddf\0All files\0*.*\0"), // filter
m_hWnd); // parent
CString path = wndMain.m_FormsPath;
dlg.m_ofn.lpstrInitialDir = (LPCTSTR)path;
if(IDOK == dlg.DoModal()){
FileOpen(dlg.m_szFileName);
}
return 0;
}
LRESULT CFormFrame::OnFileSave(WORD,WORD,HWND,BOOL &)
{
if(m_file.IsEmpty()){
BOOL dummy;
OnFileSaveAs(0,0,NULL,dummy);
}
else
FileSave(m_file);
return 0;
}
LRESULT CFormFrame::OnFileSaveAs(WORD,WORD,HWND,BOOL &)
{
CFileDialog dlg(\
FALSE, // file open
_T("ddf"), // default extension
NULL, // file name
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_NOCHANGEDIR, // flags
_T("ddf files\0*.ddf\0All files\0*.*\0)"), // filter
m_hWnd); // parent
CString path = wndMain.m_FormsPath;
dlg.m_ofn.lpstrInitialDir = (LPCTSTR)path;
if(IDOK == dlg.DoModal()){
FileSave(dlg.m_szFileName);
}
return 0;
}
LRESULT CFormFrame::OnAddFrame(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CComDispatchDriver spDispatch;
HRESULT hr = m_spFormEditor->Insert(OLESTR("DDControlPack.DDLabel"),&spDispatch);
if(SUCCEEDED(hr)){
// manipulate the new item
OLE_COLOR clrBack;
OLE_COLOR clrFore;
CComVariant v;
hr = m_spFormEditor->get_FormBackColor(&clrBack);
hr = m_spFormEditor->get_FormForeColor(&clrFore);
v = (long)3;
spDispatch.PutProperty(DISPID_BORDERSTYLE,&v/*ddcpBorderStyleEtched*/);
v = (long)clrFore;
spDispatch.PutProperty(DISPID_FORECOLOR,&v);
v = (long)clrBack;
spDispatch.PutProperty(DISPID_BACKCOLOR,&v);
}
return 0;
}
LRESULT CFormFrame::OnAddRect(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CComDispatchDriver spDispatch;
HRESULT hr = m_spFormEditor->Insert(OLESTR("DDControlPack.DDLabel"),&spDispatch);
if(SUCCEEDED(hr)){
// manipulate the new item
OLE_COLOR clrBack;
OLE_COLOR clrFore;
CComVariant v;
/*hr = m_spFormEditor->get_FormBackColor(&clrBack);
hr = m_spFormEditor->get_FormForeColor(&clrFore);*/
v = (long)3;
spDispatch.PutProperty(DISPID_BORDERSTYLE,&v/*ddcpBorderStyleEtched*/);
v = (long)clrFore;
spDispatch.PutProperty(DISPID_FORECOLOR,&v);
v = (long)clrBack;
spDispatch.PutProperty(DISPID_BACKCOLOR,&v);
}
return 0;
}
LRESULT CFormFrame::OnAddPicture(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CComDispatchDriver spDispatch;
HRESULT hr = m_spFormEditor->Insert(OLESTR("DDControlPack.DDPicture"),&spDispatch);
if(SUCCEEDED(hr)){
// manipulate the new item
}
return 0;
}
LRESULT CFormFrame::OnAddLabel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CComDispatchDriver spDispatch;
HRESULT hr = m_spFormEditor->Insert(OLESTR("DDControlPack.DDLabel"),&spDispatch);
if(SUCCEEDED(hr)){
// manipulate the new item
}
return 0;
}
LRESULT CFormFrame::OnAddButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CComDispatchDriver spDispatch;
HRESULT hr = m_spFormEditor->Insert(OLESTR("DDControlPack.DDButton"),&spDispatch);
if(SUCCEEDED(hr)){
// manipulate the new item
}
return 0;
}
LRESULT CFormFrame::OnAddCheck(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CComDispatchDriver spDispatch;
HRESULT hr = m_spFormEditor->Insert(OLESTR("DDControlPack.DDCheckBox"),&spDispatch);
if(SUCCEEDED(hr)){
// manipulate the new item
}
return 0;
}
LRESULT CFormFrame::OnAddRadio(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CComDispatchDriver spDispatch;
HRESULT hr = m_spFormEditor->Insert(OLESTR("DDControlPack.DDRadioButton"),&spDispatch);
if(SUCCEEDED(hr)){
// manipulate the new item
}
return 0;
}
LRESULT CFormFrame::OnAddText(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CComDispatchDriver spDispatch;
HRESULT hr = m_spFormEditor->Insert(OLESTR("DDControlPack.DDTextBox"),&spDispatch);
if(SUCCEEDED(hr)){
// manipulate the new item
}
return 0;
}
LRESULT CFormFrame::OnAddCombo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CComDispatchDriver spDispatch;
HRESULT hr = m_spFormEditor->Insert(OLESTR("DDControlPack.DDComboBox"),&spDispatch);
if(SUCCEEDED(hr)){
// manipulate the new item
}
return 0;
}
LRESULT CFormFrame::OnAddList(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CComDispatchDriver spDispatch;
HRESULT hr = m_spFormEditor->Insert(OLESTR("DDControlPack.DDListBox"),&spDispatch);
if(SUCCEEDED(hr)){
// manipulate the new item
}
return 0;
}
LRESULT CFormFrame::OnAddHScroll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CComDispatchDriver spDispatch;
HRESULT hr = m_spFormEditor->Insert(OLESTR("DDControlPack.DDHorzScrollBar"),&spDispatch);
if(SUCCEEDED(hr)){
// manipulate the new item
}
return 0;
}
LRESULT CFormFrame::OnAddVScroll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CComDispatchDriver spDispatch;
HRESULT hr = m_spFormEditor->Insert(OLESTR("DDControlPack.DDVertScrollBar"),&spDispatch);
if(SUCCEEDED(hr)){
// manipulate the new item
}
return 0;
}
LRESULT CFormFrame::OnAddSpin(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CComDispatchDriver spDispatch;
HRESULT hr = m_spFormEditor->Insert(OLESTR("MSComCtl2.UpDown"),&spDispatch);
if(SUCCEEDED(hr)){
// manipulate the new item
}
return 0;
}
LRESULT CFormFrame::OnAddSlider(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CComDispatchDriver spDispatch;
HRESULT hr = m_spFormEditor->Insert(OLESTR("MSComCtl2.Slider"),&spDispatch);
if(SUCCEEDED(hr)){
// manipulate the new item
}
return 0;
}
LRESULT CFormFrame::OnAddProgress(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CComDispatchDriver spDispatch;
HRESULT hr = m_spFormEditor->Insert(OLESTR("MSComCtlLib.ProgCtrl"),&spDispatch);
if(SUCCEEDED(hr)){
// manipulate the new item
}
return 0;
}
LRESULT CFormFrame::OnAddActivex(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
HRESULT hr;
CComBSTR progid;
hr = m_spFormEditor->ShowInsertDialog(&progid);
if(SUCCEEDED(hr) && progid.Length()){
CComDispatchDriver spDispatch;
hr = m_spFormEditor->Insert(progid,&spDispatch);
if(SUCCEEDED(hr)){
// manipulate the new item
}
}
return 0;
}
LRESULT CFormFrame::OnDelete(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
m_spFormEditor->Delete();
return 0;
}
LRESULT CFormFrame::OnGrid(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
VARIANT_BOOL b;
HRESULT hr = m_spFormEditor->get_GridVisible(&b);
if(SUCCEEDED(hr)){
//m_spFormEditor->put_GridVisible(b == VARIANT_TRUE ? VARIANT_FALSE : VARIANT_TRUE);
}
return 0;
}
LRESULT CFormFrame::OnGridSettings(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
return 0;
}
LRESULT CFormFrame::OnTab(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
m_spFormEditor->SetTabOrder();
return 0;
}
LRESULT CFormFrame::OnSelectAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
m_spFormEditor->SelectAll();
return 0;
}
LRESULT CFormFrame::OnUnselectAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
m_spFormEditor->SelectNone();
return 0;
}
LRESULT CFormFrame::OnProperties(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
m_spFormEditor->Properties();
return 0;
}
LRESULT CFormFrame::OnMoveCtl(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
switch(wID){
case ID_LEFT:
m_spFormEditor->MoveLeft();
break;
case ID_RIGHT:
m_spFormEditor->MoveRight();
break;
case ID_UP:
m_spFormEditor->MoveUp();
break;
case ID_DOWN:
m_spFormEditor->MoveDown();
break;
default:
break;
}
return 0;
}
LRESULT CFormFrame::OnSendBack(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
//m_spFormEditor->SendToBack();
return 0;
}
LRESULT CFormFrame::OnSendFront(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
//m_spFormEditor->BringToFront();
return 0;
}
LRESULT CFormFrame::OnAlignCtl(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
switch(wID){
case ID_ALIGN_LEFT:
m_spFormEditor->AlignLeft();
break;
case ID_ALIGN_RIGHT:
m_spFormEditor->AlignRight();
break;
case ID_ALIGN_TOP:
m_spFormEditor->AlignTop();
break;
case ID_ALIGN_BOTTOM:
m_spFormEditor->AlignBottom();
break;
default:
break;
}
return 0;
}
LRESULT CFormFrame::OnSpaceCtl(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
switch(wID){
case ID_SPACE_HORZ:
m_spFormEditor->SpaceHorizontally();
break;
case ID_SPACE_VERT:
m_spFormEditor->SpaceVertically();
break;
default:
break;
}
return 0;
}
LRESULT CFormFrame::OnSizeCtl(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
switch(wID){
case ID_SIZE_LARGEST_WIDTH:
m_spFormEditor->SizeWidthToLargest();
break;
case ID_SIZE_LARGEST_HEIGHT:
m_spFormEditor->SizeHeightToLargest();
break;
case ID_SIZE_LARGEST:
m_spFormEditor->SizeToLargest();
break;
case ID_SIZE_SMALLEST_WIDTH:
m_spFormEditor->SizeWidthToSmallest();
break;
case ID_SIZE_SMALLEST_HEIGHT:
m_spFormEditor->SizeHeightToSmallest();
break;
case ID_SIZE_SMALLEST:
m_spFormEditor->SizeToSmallest();
break;
default:
break;
}
return 0;
}
LRESULT CFormFrame::OnCenterCtl(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
switch(wID){
case ID_CENTER_HORZ:
m_spFormEditor->FormAlignHCenter();
break;
case ID_CENTER_VERT:
m_spFormEditor->FormAlignVCenter();
break;
case ID_CENTER:
m_spFormEditor->FormAlignBoth();
break;
default:
break;
}
return 0;
}
LRESULT CFormFrame::OnValidateScript(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
HRESULT hr;
VARIANT_BOOL res;
hr = m_spFormEditor->ValidateScript(&res);
if(SUCCEEDED(hr)){
if(res == VARIANT_TRUE)
MessageBox(_T("no errors"));
}
return 0;
}
LRESULT CFormFrame::OnPreviewAuto(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
VARIANT_BOOL bValid;
HRESULT hr;
hr = m_spFormEditor->ValidateScript(&bValid);
if(SUCCEEDED(hr) && bValid == VARIANT_TRUE){
// create the preview dialog
CPreviewDlg *pDlg = new CPreviewDlg(m_hWnd,TRUE);
USES_CONVERSION;
pDlg->m_AutoSizing=TRUE;
pDlg->m_FileName=MakeTempName();
// expose objects - see OnInitialUpdate() for more details
// class1
CExposedObjectInfo ExposedObjectInfo;
CComQIPtr<IDispatch> sp; wndMain.m_pIrc->QueryInterface(&sp);
ExposedObjectInfo.m_Name=_T("no5");
ExposedObjectInfo.m_spDispatch= sp;
pDlg->m_ExposedObjectInfoArray.Add(ExposedObjectInfo);
// save the form
CComBSTR filename = pDlg->m_FileName;
hr = m_spFormEditor->SaveToFile(filename);
if(SUCCEEDED(hr)){
// show the preview
pDlg->Create(m_hWnd);
pDlg->ShowWindow(SW_NORMAL);
}
}
return 0;
}
LRESULT CFormFrame::OnPreview(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
VARIANT_BOOL bValid;
HRESULT hr;
hr = m_spFormEditor->ValidateScript(&bValid);
if(SUCCEEDED(hr) && bValid == VARIANT_TRUE){
// create the preview dialog
CPreviewDlg *pDlg = new CPreviewDlg(m_hWnd,TRUE);
USES_CONVERSION;
pDlg->m_AutoSizing=FALSE;
pDlg->m_FileName=MakeTempName();
// expose objects - see OnInitialUpdate() for more details
CExposedObjectInfo ExposedObjectInfo;
CComQIPtr<IDispatch> sp; wndMain.m_pIrc->QueryInterface(&sp);
ExposedObjectInfo.m_Name=_T("no5");
ExposedObjectInfo.m_spDispatch= sp;
pDlg->m_ExposedObjectInfoArray.Add(ExposedObjectInfo);
// save the form
CComBSTR filename = pDlg->m_FileName;
hr = m_spFormEditor->SaveToFile(filename);
if(SUCCEEDED(hr)){
// show the preview
pDlg->Create(m_hWnd);
pDlg->ShowWindow(SW_NORMAL);
}
}
return 0;
}
LRESULT CFormFrame::OnEditCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
HRESULT hr = S_OK;
switch(wID){
case ID_EDIT_CUT:
hr = m_spFormEditor->Cut();
break;
case ID_EDIT_COPY:
hr = m_spFormEditor->Copy();
break;
case ID_EDIT_PASTE:
hr = m_spFormEditor->Paste();
break;
case ID_UNDO:
hr = m_spFormEditor->Undo();
break;
case ID_REDO:
hr = m_spFormEditor->Redo();
break;
default:
break;
}
ATLASSERT(SUCCEEDED(hr));
return 0;
}
LRESULT CFormFrame::OnTabSelChange(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
LRESULT lRes = baseClass::OnSelChange(idCtrl,pnmh,bHandled);
bHandled = TRUE;
int idx = m_TabCtrl.GetCurSel();
if(idx == 2){
USES_CONVERSION;
HRESULT hr = m_spFormEditor->SaveToFile(CT2OLE((LPCTSTR)MakeTempName()));
if(SUCCEEDED(hr)){
hr = m_spFormViewer->LoadFromFile(CT2OLE((LPCTSTR)MakeTempName()));
}
ATLASSERT(SUCCEEDED(hr));
}
return lRes;
}
LRESULT CFormFrame::OnTabSelChanging(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
LRESULT lRes = baseClass::OnSelChanging(idCtrl,pnmh,bHandled);
bHandled = TRUE;
int idx = m_TabCtrl.GetCurSel();
if(idx == 2){
// force unload of form viewer
m_spFormViewer->Unload();
}
return lRes;
}
void CFormFrame::FileNew(void)
{
HRESULT hr = m_spFormEditor->New();
hr = m_spScriptEditor->put_Modified(VARIANT_FALSE);
if(SUCCEEDED(hr)){
SetModified(FALSE);
m_file.Empty();
CComPtr<DDFORMSLib::IScript2> sp;
hr = m_spFormEditor->get_Script(&sp);
if(SUCCEEDED(hr)){
sp->put_Text(OLESTR(""));
}
}
}
void CFormFrame::FileOpen(LPCTSTR file)
{
USES_CONVERSION;
HRESULT hr = m_spFormEditor->LoadFromFile(CT2OLE(file));
if(SUCCEEDED(hr)){
hr = m_spScriptEditor->put_Modified(VARIANT_FALSE);
if(SUCCEEDED(hr)){
SetModified(FALSE);
m_file = file;
}
}
}
void CFormFrame::FileSave(LPCTSTR file)
{
USES_CONVERSION;
HRESULT hr = m_spFormEditor->SaveToFile(CT2OLE(file));
if(SUCCEEDED(hr)){
hr = m_spScriptEditor->put_Modified(VARIANT_FALSE);
if(SUCCEEDED(hr)){
SetModified(FALSE);
m_file = file;
}
}
}
CString CFormFrame::MakeTempName(void)
{
CString s("temp.ddf");
return s;
}
// CPreviewDlg
CPreviewDlg::CPreviewDlg(HWND hWndOwner,BOOL bModeless):\
m_bModeless(bModeless),
m_wndOwner(hWndOwner)
{
m_AutoSizing = FALSE;
//g_app.IncScript();
CExposedObjectInfo exp;
exp.m_Name = _T("no5");
CComQIPtr<IDispatch> sp; wndMain.m_pIrc->QueryInterface(&sp);
exp.m_spDispatch = sp;
m_ExposedObjectInfoArray.Add(exp);
}
CPreviewDlg::~CPreviewDlg()
{
//g_app.DecScript();
}
LRESULT CPreviewDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
HRESULT hr = S_OK;
CMessageLoop *p = _Module.GetMessageLoop();
p->AddMessageFilter(this);
// create host window and control
{
USES_CONVERSION;
LPOLESTR p = NULL;
hr = StringFromCLSID(DDFORMSLib::CLSID_FormViewer,&p);
if(SUCCEEDED(hr) && p){
m_ax.Create(m_hWnd,NULL,OLE2T(p),WS_CHILD|WS_VISIBLE,0,(HMENU)IDC_FORMVIEWER1);
CoTaskMemFree(p);
p = NULL;
hr = m_ax.QueryControl(&m_spFormViewer);
ATLASSERT(SUCCEEDED(hr));
if(FAILED(hr))
return 0;
}
}
// set the caption
CString Caption;
int len = GetWindowTextLength();
GetWindowText(Caption.GetBuffer(len + 1),len + 1);
Caption.ReleaseBuffer();
Caption+=m_AutoSizing ? _T(" (Auto Sizing)") : _T(" (None Auto Sizing)");
SetWindowText(Caption);
USES_CONVERSION;
// expose objects
for(long l=0; l<m_ExposedObjectInfoArray.GetSize(); l++)
{
m_spFormViewer->Expose(CT2OLE(m_ExposedObjectInfoArray[l].m_Name),
m_ExposedObjectInfoArray[l].m_spDispatch);
}
// load the form
m_spFormViewer->LoadFromFile(CT2OLE(m_FileName));
// set the form viewer background color (optional but looks better)
//m_FormViewer.SetBackColor(m_FormViewer.GetForm().GetBackColor());
// size the dialog
if(m_AutoSizing)
{
// calculate the none client area
CRect WindowRect;
GetWindowRect(WindowRect);
CRect ClientRect;
GetClientRect(ClientRect);
CComPtr<DDFORMSLib::IViewableForm> sp;
LONG FormWidth = 200,FormHeight = 200;
hr = m_spFormViewer->get_Form(&sp);
ATLASSERT(SUCCEEDED(hr));
if (SUCCEEDED(hr)) {
sp->get_Width(&FormWidth);
sp->get_Height(&FormHeight);
}
long NCWidth=WindowRect.Width()-ClientRect.Width();
long NCHeight=WindowRect.Height()-ClientRect.Height();
// calculate the required dialog dimensions
long Width=NCWidth+FormWidth;
long Height=NCHeight+FormHeight;
//Width += GetSystemMetrics(SM_CXVSCROLL);
//Height += GetSystemMetrics(SM_CYHSCROLL);
// prevent screen overrun
Width=min(Width,GetSystemMetrics(SM_CXSCREEN));
Height=min(Height,GetSystemMetrics(SM_CYSCREEN));
// size and position the dialog
(void)SetWindowPos(NULL,0,0,Width,Height,SWP_NOZORDER);
CenterWindow();
}
// size the form viewer
CRect ClientRect(0,0,0,0);
GetClientRect(ClientRect);
ATLASSERT(m_ax.IsWindow());
(void)m_ax.SetWindowPos(NULL,0,0,
ClientRect.Width(),ClientRect.Height(),SWP_NOZORDER);
// give focus to the form viewer
(void)m_ax.SetFocus();
//DlgResize_Init((m_AutoSizing ? false: true),false);
return FALSE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
LRESULT CPreviewDlg::OnNCDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if(m_bModeless){
m_wndOwner.PostMessage(WM_FORMVIEW,0,(LPARAM)this);
}
bHandled = FALSE;
return 0;
}
BOOL CPreviewDlg::PreTranslateMessage(MSG* pMsg)
{
if(IsDialogMessage(pMsg))
return TRUE;
if(pMsg->message < WM_KEYFIRST || pMsg->message > WM_KEYLAST)
return FALSE;
CWindow wnd = pMsg->hwnd;