-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtmltabledesigner.cpp
More file actions
918 lines (754 loc) · 19.8 KB
/
htmltabledesigner.cpp
File metadata and controls
918 lines (754 loc) · 19.8 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
//============================================================================
// Author: C. Drozdowski. MIT license.
//============================================================================
#include <Origin.h>
#include <../OriginLab/DialogEx.h>
#include <../OriginLab/HTMLDlg.h>
#include <GetNBox.h>
// Constants for dialog.
#define HTML_TABLE_DESIGNER_DLG_INIT_WIDTH 650
#define HTML_TABLE_DESIGNER_DLG_INIT_HEIGHT 500
#define HTML_TABLE_DESIGNER_DLG_MIN_WIDTH 650
#define HTML_TABLE_DESIGNER_DLG_MIN_HEIGHT 500
#define STR_HTML_TABLE_DESIGNER_USER_STYLES_FOLDER "User Styles"
#define STR_HTML_TABLE_DESIGNER_ORIGIN_TABLE_CSS_CLASS ".origin-table"
#define STR_HTML_TABLE_DESIGNER_STYLE_ID "html-table-designer-styles"
#define STR_HTML_TABLE_DESIGNER_STYLE_COMMENT_BEGIN "<!-- Begin HTML Table Designer Styles -->"
#define STR_HTML_TABLE_DESIGNER_STYLE_COMMENT_END "<!-- End HTML Table Designer Styles -->"
#define STR_HTML_TABLE_DESIGNER_CSS_COMMENT_RESET "/* Reset Origin-generated table styles */"
#define STR_HTML_TABLE_DESIGNER_CSS_COMMENT_APP "/* App-generated table styles */"
class clsStyleList
{
public:
vector<string> styles;
clsStyleList()
{
}
};
class HTMLTableDesignerDlg;
static HTMLTableDesignerDlg *s_pHTMLTableDesignerDlg = NULL;
class HTMLTableDesignerDlg : public HTMLDlg
{
public:
HTMLTableDesignerDlg()
{
waitCursor junk;
m_pvar = new LTVarTempChange("@HTDD", 1);
m_strSettings = LoadJsonConfigFile("settings.json");
m_strResetStyles = LoadResetStyles();
m_strPreview = LoadPreview();
m_strIntro = LoadIntro();
}
~HTMLTableDesignerDlg()
{
if( m_pvar )
NICE_SAFE_REMOVAL(m_pvar);
}
int Create(HWND hParent = NULL, DWORD dwOptions = 0)
{
InitMsgMap();
int nRet = HTMLDlg::Create(hParent, dwOptions);
ModifyStyle(0, WS_MAXIMIZEBOX | WS_MINIMIZEBOX);
return nRet;
}
string LoadStyleList()
{
return GetStyleList();
}
string LoadStyle(string strName)
{
return DoLoadStyle(strName);
}
string SaveStyle(string strName, string strCss)
{
if( !_SaveStyleDialog(strName) )
return "";
if( !DoSaveStyle(strName, strCss) )
return "";
return strName;
}
string LoadLastUsed()
{
return DoLoadLastUsed();
}
bool SaveLastUsed(string strCss)
{
return DoSaveLastUsed(strCss);
}
bool ExportStyle(string strName, string strCss)
{
string strFile = GetSaveAsBox("*.css Cascading Style Sheet File", NULL, strName);
if( strFile.IsEmpty() )
return false;
return SaveCssFile(strFile, strCss);
}
string ImportStyle()
{
string strFile = GetOpenBox("*.css Cascading Style Sheet File", NULL);
return DoImportStyle(strFile);
}
bool PreviewStyle(string strCss)
{
string str = m_strPreview;
str.Replace("APP_STYLES", FormatCombinedStyle(strCss));
if( str.IsEmpty() )
return false;
if( !m_notePreview.IsValid() )
m_notePreview.Create();
if( !m_notePreview.IsValid() )
return false;
m_notePreview.Text = str;
m_notePreview.CheckShowActivate();
// Set Notes window to HTML mode.
LT_execute("note.syntax=1;");
LT_execute("note.view=1;");
return true;
}
bool ApplyStyle(string strCss)
{
// Create the full styles to put into report.
string strStyles = FormatCombinedStyle(strCss);
// Copy full styles to clipboard as a safety move.
copy_to_clipboard(strStyles, true, false);
// Test if active window is a Note and is not the preview.
Note note = Project.Notes();
if (!note.IsValid())
{
ErrorMsg("An HTML report is not the active window.");
return false;
}
if (m_notePreview.IsValid() && note == m_notePreview)
{
ErrorMsg("Styles cannot be applied to the Preview window.");
return false;
}
// Get Note syntax and if not HTML or Markdown, error and return.
double syntax = 0;
LT_get_var("note.syntax", &syntax);
if (0 == syntax)
{
ErrorMsg("The Active Note window isn't set up as an HTML report. Its syntax is neither HTML nor Markdown.");
return false;
}
// If Markdown, need to remove class selector.
if (2 == syntax)
strStyles.Replace(STR_HTML_TABLE_DESIGNER_ORIGIN_TABLE_CSS_CLASS, "");
// Get text of Note window.
string strText = note.Text;
// Look for and replace any pre-existing App-based styles in Note text and return.
int nPosBegin = strText.Find(STR_HTML_TABLE_DESIGNER_STYLE_COMMENT_BEGIN);
if (nPosBegin > -1)
{
int nPosEnd = strText.Find(STR_HTML_TABLE_DESIGNER_STYLE_COMMENT_END, nPosBegin);
if (-1 == nPosEnd)
{
ErrorMsg("Unable to replace styles- missing delimter comment.");
return false;
}
nPosEnd += strlen(STR_HTML_TABLE_DESIGNER_STYLE_COMMENT_END) - 1;
string strNew = StripStyles(strText, nPosBegin, nPosEnd);
strNew.TrimLeft();
strStyles.TrimRight(); // It ends with \r\n and if left in, will keep adding them to content every time updated. So remove trailing \r\n's.
strNew.Insert(nPosBegin, strStyles);
note.Text = strNew;
return true;
}
// Otherwise, for Markdown syntax, Insert at beginning and return.
if (2 == syntax)
{
string strNew;
strNew.Format("%s%s", strStyles, strText);
note.Text = strNew;
return true;
}
// Otherwise, for HTML syntax...
// Look for <head> element by searching for </head> because, if it exists,
// we will insert before </head> and return.
int nPosHead = strText.Find("</head>");
if (nPosHead > -1)
{
strText.Insert(nPosHead, strStyles);
note.Text = strText;
return true;
}
// Look for <body> element by searching for <body> because, if it exists,
// we will insert after </body> and return.
int nPosBodyStart = strText.Find("<body");
if (nPosBodyStart > -1)
{
int nPosBodyEnd = strText.Find(">", nPosBodyStart);
if (-1 == nPosBodyEnd)
{
ErrorMsg("Malformed <body> element.");
return false;
}
strText.Insert(nPosBodyEnd + 1, strStyles);
note.Text = strText;
return true;
}
// If no <head> or <body>, then insert at beginning.
string strNew;
strNew.Format("%s%s", strStyles, strText);
note.Text = strNew;
return true;
}
string GetIntro()
{
return m_strIntro;
}
bool CloseClick()
{
if( m_notePreview.IsValid() )
m_notePreview.Destroy();
Close();
return true;
}
string LoadSettings()
{
string strJson = (!m_strSettings.IsEmpty()) ? m_strSettings : "{}";
return strJson;
}
void SaveSettings(string strJson)
{
SaveJsonConfigFile("settings.json", strJson);
}
// Javascript-callable MessageBox() wrapper providing more options that Javascript
// versions not the least of which that it allows dialog title to be set.
// See mswin.h for constants for type and return value.
int OCMessageBox(string strText, string strCaption, int nType = MB_OK)
{
if( strCaption.IsEmpty() )
strCaption = GetDialogTitle();
// int OWINAPI MessageBox( HWND hWnd, LPCSTR lpText, LPCSTR lpCaption = NULL, UINT uType = MB_OK ); // Open a Windows message box.
// See mswin.h for constants related to type and return values.
return MessageBox(GetSafeHwnd(), strText, strCaption, nType);
}
protected:
DECLARE_DISPATCH_MAP
EVENTS_BEGIN_DERIV(HTMLDlg)
ON_CANCEL(OnCancel)
ON_DESTROY(OnDestroy)
ON_SIZE(OnDlgResize)
ON_GETMINMAXINFO(OnMinMaxInfo)
ON_SYSCOMMAND(OnSystemCommand)
EVENTS_END_DERIV
BOOL OnCancel()
{
// When Origin exits with this dialog open, this gets called.
// If it is exiting, don't call CloseClick because it prompts
// for saving which may lead to crash.
double dCW;
LT_get_var("@CW", &dCW);
if (2 == dCW)
return TRUE;
CloseClick();
return TRUE;
}
string GetInitURL()
{
string strFile = __FILE__;
return GetFilePath(strFile) + "app.html";
}
string GetDialogTitle() {return "HTML Table Designer";}
BOOL OnDestroy()
{
HTMLDlg::OnDestroy();
s_pHTMLTableDesignerDlg = NULL;
delete this;
return TRUE;
}
BOOL GetDlgInitSize(int& width, int& height)
{
width = HTML_TABLE_DESIGNER_DLG_INIT_WIDTH;
height = HTML_TABLE_DESIGNER_DLG_INIT_HEIGHT;
return TRUE;
}
BOOL OnDlgResize(int nType, int cx, int cy)
{
if( !IsInitReady() )
return false;
// MoveControlsHelper _temp(this); // you can uncomment this line, if the dialog flickers when you resize it
HTMLDlg::OnDlgResize(nType, cx, cy);
if( !IsHTMLDocumentCompleted() )
return FALSE;
return TRUE;
}
int GetMinClientTrackWidth()
{
return CheckConvertDlgSizeWithDPI(HTML_TABLE_DESIGNER_DLG_MIN_WIDTH, true);
}
int GetMinClientTrackHeight()
{
return CheckConvertDlgSizeWithDPI(HTML_TABLE_DESIGNER_DLG_MIN_HEIGHT, false);
}
bool OnSystemCommand(int nCmd)
{
if (SC_MAXIMIZE == nCmd)
{
return FALSE;
}
if (SC_MINIMIZE == nCmd)
{
if(!IsRolledup())
{
Rollup(true);
if (m_notePreview)
m_notePreview.GetWindow().ShowWindow(SW_HIDE);
}
else
{
Rollup(FALSE);
if (m_notePreview)
{
m_notePreview.GetWindow().ShowWindow(SW_SHOW);
m_notePreview.CheckShowActivate();
}
}
return FALSE;
}
return TRUE;
//return HTMLDlg::OnSystemCommand(nCmd);
}
private:
string FormatCombinedStyle(const string& strCss)
{
string str;
str.Format("%s\n<style id=\"%s\">\n%s</style>\n%s\n",
STR_HTML_TABLE_DESIGNER_STYLE_COMMENT_BEGIN,
STR_HTML_TABLE_DESIGNER_STYLE_ID,
FormatCss(strCss),
STR_HTML_TABLE_DESIGNER_STYLE_COMMENT_END
);
return str;
}
string FormatCss(const string& strCss)
{
string str;
str.Format("%s\n%s\n\n%s\n%s",
STR_HTML_TABLE_DESIGNER_CSS_COMMENT_RESET,
m_strResetStyles,
STR_HTML_TABLE_DESIGNER_CSS_COMMENT_APP,
strCss
);
return str;
}
string StripStyles(LPCSTR in, int nBegin, int nEnd)
{
if (nEnd <= nBegin)
return in;
string str;
int len = strlen(in) + nEnd - nBegin + 1;
LPSTR out = str.GetBuffer(len+1);
memset(out, 0, len+1);
int nPos = 0;
while (*in)
{
if (nPos == nBegin)
{
while (*in && nPos <= nEnd)
{
in++;
nPos++;
}
continue;
}
*out = *in;
out++;
in++;
nPos++;
}
str.ReleaseBuffer();
return str;
}
void ErrorMsg(LPCSTR msg)
{
MessageBox(GetSafeHwnd(), msg, GetDialogTitle(), MB_OK|MB_ICONEXCLAMATION);
}
string DoLoadStyle(string strName)
{
string strCss;
strName += ".css";
strName = GetFileName(strName, false);
string strTemp = __FILE__;
string strPath = GetFilePath(strTemp) + STR_HTML_TABLE_DESIGNER_USER_STYLES_FOLDER;
string strFile;
strFile.Format("%s/%s", strPath, strName);
if( strFile.IsFile() )
{
stdioFile ff;
if( ff.Open(strFile, file::modeRead | file::typeText) )
{
strCss = "";
string strLine;
while( ff.ReadString(strLine) )
{
strCss += strLine;
}
ff.Close();
}
}
return strCss;
}
string DoImportStyle(const string& strFile)
{
string strCss;
if( strFile.IsFile() )
{
stdioFile ff;
if( ff.Open(strFile, file::modeRead | file::typeText) )
{
strCss = "";
string strLine;
while( ff.ReadString(strLine) )
{
strCss += strLine;
}
ff.Close();
}
}
return strCss;
}
bool DoSaveStyle(string& strName, const string& strCss)
{
if( strName.IsEmpty() )
return false;
if( 0 != strName.Right(4).CompareNoCase(".css") )
strName += ".css";
// Make sure it is only a file name with no path component.
strName = GetFileName(strName, true);
string strTemp = __FILE__;
string strPath = GetFilePath(strTemp) + STR_HTML_TABLE_DESIGNER_USER_STYLES_FOLDER;
string strFile;
strFile.Format("%s/%s.%s", strPath, strName, "css");
bool bRet = false;
stdioFile ff;
if( ff.Open(strFile, file::modeCreate | file::modeWrite | file::typeText) )
{
ff.WriteString(strCss);
ff.Close();
bRet = true;
}
return bRet;
}
string DoLoadLastUsed()
{
string strCss;
string strName = "lastused.css";
string strTemp = __FILE__;
string strPath = GetFilePath(strTemp);
string strFile;
strFile.Format("%s/%s", strPath, strName);
if( strFile.IsFile() )
{
stdioFile ff;
if( ff.Open(strFile, file::modeRead | file::typeText) )
{
strCss = "";
string strLine;
while( ff.ReadString(strLine) )
{
strCss += strLine;
}
ff.Close();
}
}
return strCss;
}
bool DoSaveLastUsed(const string& strCss)
{
string strName = "lastused.css";
string strTemp = __FILE__;
string strPath = GetFilePath(strTemp);
string strFile;
strFile.Format("%s/%s", strPath, strName);
bool bRet = false;
stdioFile ff;
if( ff.Open(strFile, file::modeCreate | file::modeWrite | file::typeText) )
{
ff.WriteString(strCss);
ff.Close();
bRet = true;
}
return bRet;
}
string GetStyleList()
{
string strJson;
clsStyleList cls;
vector<string> vs;
string strTemp = __FILE__;
string strPath = GetFilePath(strTemp) + STR_HTML_TABLE_DESIGNER_USER_STYLES_FOLDER;
FindFiles(vs, strPath, "*.css", true, 0);
int nSize = vs.GetSize();
for( int nn = 0; nn < nSize; nn++ )
{
vs[nn] = GetFileName(vs[nn], true);
}
cls.styles = vs;
JSON.ToString(cls, strJson);
return strJson;
}
string LoadOriginStyles()
{
string strRet = "";
string strFile = GetOriginPath(ORIGIN_PATH_SYSTEM) + "Ohtml/NotePage/styles/global.css";
if( strFile.IsFile() )
{
stdioFile ff;
if( ff.Open(strFile, file::modeRead | file::typeText) )
{
strRet = "";
string strLine;
while( ff.ReadString(strLine) )
{
strRet += strLine + "\n";
}
ff.Close();
}
}
strRet.TrimLeft();
strRet.TrimRight();
return strRet;
}
string LoadResetStyles()
{
string strRet = "";
string strTemp = __FILE__;
string strPath = GetFilePath(strTemp);
string strFile = strPath + "resetstyles.css";
if( strFile.IsFile() )
{
stdioFile ff;
if( ff.Open(strFile, file::modeRead | file::typeText) )
{
strRet = "";
string strLine;
while( ff.ReadString(strLine) )
{
strRet += strLine + "\n";
}
ff.Close();
}
}
strRet.TrimLeft();
strRet.TrimRight();
return strRet;
}
string LoadPreview()
{
string strRet = "";
string strTemp = __FILE__;
string strPath = GetFilePath(strTemp);
string strFile = strPath + "preview.html";
if( strFile.IsFile() )
{
stdioFile ff;
if( ff.Open(strFile, file::modeRead | file::typeText) )
{
strRet = "";
string strLine;
while( ff.ReadString(strLine) )
{
strRet += strLine + "\n";
}
ff.Close();
}
}
strRet.Replace("ORIGIN_STYLES", LoadOriginStyles());
return strRet;
}
string LoadIntro()
{
string strRet = "";
string strTemp = __FILE__;
string strPath = GetFilePath(strTemp);
string strFile = strPath + "intro.html";
if( strFile.IsFile() )
{
stdioFile ff;
if( ff.Open(strFile, file::modeRead | file::typeText) )
{
strRet = "";
string strLine;
while( ff.ReadString(strLine) )
{
strRet += strLine + "\n";
}
ff.Close();
}
}
return strRet;
}
bool SaveCssFile(string strFile, string strCss)
{
if( strFile.IsEmpty() )
return false;
bool bRet = false;
stdioFile ff;
if( ff.Open(strFile, file::modeCreate | file::modeWrite | file::typeText) )
{
ff.WriteString(strCss);
ff.Close();
bRet = true;
}
return bRet;
}
string LoadJsonConfigFile(string strFile)
{
string strJson = "{}";
string strTemp = __FILE__;
strFile = GetFilePath(strTemp) + strFile;
if( strFile.IsFile() )
{
stdioFile ff;
if( ff.Open(strFile, file::modeRead | file::typeText) )
{
strJson = "";
string strLine;
while( ff.ReadString(strLine) )
{
if( 0 != strLine.Left(2).Compare("//") )
strJson += strLine;
}
ff.Close();
}
if( strJson.IsEmpty() )
strJson = "{}";
}
return strJson;
}
bool SaveJsonConfigFile(string strFile, string strJson)
{
if( strJson.IsEmpty() )
strJson = "{}";
string strTemp = __FILE__;
strFile = GetFilePath(strTemp) + strFile;
bool bRet = false;
stdioFile ff;
if( ff.Open(strFile, file::modeCreate | file::modeWrite | file::typeText) )
{
ff.WriteString(strJson);
ff.Close();
bRet = true;
}
return bRet;
}
private:
Note m_notePreview;
string m_strResetStyles;
string m_strPreview;
string m_strIntro;
string m_strSettings;
LTVarTempChange* m_pvar;
}; //End class HTMLTableDesignerDlg.
BEGIN_DISPATCH_MAP(HTMLTableDesignerDlg, HTMLDlg)
DISP_FUNCTION(HTMLTableDesignerDlg, LoadStyleList, VTS_STR, VTS_VOID)
DISP_FUNCTION(HTMLTableDesignerDlg, LoadStyle, VTS_STR, VTS_STR)
DISP_FUNCTION(HTMLTableDesignerDlg, SaveStyle, VTS_STR, VTS_STR VTS_STR)
DISP_FUNCTION(HTMLTableDesignerDlg, LoadLastUsed, VTS_STR, VTS_VOID)
DISP_FUNCTION(HTMLTableDesignerDlg, SaveLastUsed, VTS_BOOL, VTS_STR)
DISP_FUNCTION(HTMLTableDesignerDlg, ExportStyle, VTS_BOOL, VTS_STR VTS_STR)
DISP_FUNCTION(HTMLTableDesignerDlg, ImportStyle, VTS_STR, VTS_VOID)
DISP_FUNCTION(HTMLTableDesignerDlg, PreviewStyle, VTS_BOOL, VTS_STR)
DISP_FUNCTION(HTMLTableDesignerDlg, ApplyStyle, VTS_BOOL, VTS_STR)
DISP_FUNCTION(HTMLTableDesignerDlg, LoadSettings, VTS_STR, VTS_VOID)
DISP_FUNCTION(HTMLTableDesignerDlg, GetIntro, VTS_STR, VTS_VOID)
DISP_FUNCTION(HTMLTableDesignerDlg, SaveSettings, VTS_VOID, VTS_STR)
DISP_FUNCTION(HTMLTableDesignerDlg, CloseClick, VTS_BOOL, VTS_VOID)
DISP_FUNCTION(HTMLTableDesignerDlg, OCMessageBox, VTS_I4, VTS_STR VTS_STR VTS_I4)
END_DISPATCH_MAP
// Dialog to get style name from user.
static bool _SaveStyleDialog(string& strName) // Note pass by reference.
{
strName.TrimLeft();
strName.TrimRight();
if( s_pHTMLTableDesignerDlg == NULL )
return false;
string strJson = s_pHTMLTableDesignerDlg->LoadStyleList();
clsStyleList cls;
JSON.FromString(cls, strJson);
vector<string> vsList;
vsList = cls.styles;
string strList;
strList.SetTokens(vsList, '|');
int nID = 100;
GETN_TREE(tr)
GETN_STRLIST(name, "Style Name", strName, "|" + strList) GETN_ID(nID++)
// Hidden lookup list.
tr.list.strVals = vsList;
tr.list.SetAttribute(STR_SHOW_ATTRIB, false);
tr.save.nVal = 0;
tr.save.SetAttribute(STR_SHOW_ATTRIB, false);
if( !GetNBox(tr, _DlgEventFunc, "Save Style", "Enter or select an existing name with which to save the current style.") )
return false;
strName = tr.name.strVal;
bool bRet = (1 == tr.save.nVal);
return bRet;
}
// Dialog event function for _SaveStyleDialog above.
static int _DlgEventFunc(TreeNode& tr, int nRow, int nEvent, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& getNContainer, string& strAux, string& strErrMsg)
{
if( nEvent < 0 && GETNE_ON_INIT == nEvent )
{
O_SET_BIT(dwEnables, GETNGEVT_OK_ENABLE,!tr.name.strVal.IsEmpty());
return true;
}
if( nEvent < 0 && GETNE_ON_VALUE_CHANGE == nEvent )
{
tr.name.strVal.TrimLeft();
tr.name.strVal.TrimRight();
if( tr.name.strVal.IsEmpty() )
{
O_SET_BIT(dwEnables, GETNGEVT_OK_ENABLE, false);
return true;
}
if ( !is_str_valid_for_filename(tr.name.strVal) )
{
MessageBox(getNContainer.GetSafeHwnd(), "Style name contains invalid characters.\r\n\r\nIt is restricted to the same characters allowed in file names.", "Save Style", MB_OK | MB_ICONSTOP);
O_SET_BIT(dwEnables, GETNGEVT_OK_ENABLE, false);
return true;
}
}
if (nEvent < 0 && GETNE_ON_OK == nEvent )
{
tr.name.strVal.TrimLeft();
tr.name.strVal.TrimRight();
if( tr.name.strVal.IsEmpty() )
tr.save.nVal = 0;
else if( tr.list.strVals.Find(tr.name.strVal) > -1 )
{
if( IDYES == MessageBox(getNContainer.GetSafeHwnd(), "Do you want to replace selected style?", "Save Style" , MB_YESNOCANCEL) )
tr.save.nVal = 1;
else
tr.save.nVal = 0;
}
else
tr.save.nVal = 1;
return true;
}
return false;
}
#pragma labtalk(1) // Enable for LabTalk calling.
void HTMLTableDesignerApp_Run()
{
if( s_pHTMLTableDesignerDlg == NULL )
{
s_pHTMLTableDesignerDlg = new HTMLTableDesignerDlg;
if( s_pHTMLTableDesignerDlg )
s_pHTMLTableDesignerDlg->Create(GetWindow());
}
else
{
s_pHTMLTableDesignerDlg->PostMessage(WM_SYSCOMMAND, SC_RESTORE);
if( s_pHTMLTableDesignerDlg->IsRolledup() )
s_pHTMLTableDesignerDlg->Rollup(false);
SetActiveWindow(s_pHTMLTableDesignerDlg->GetSafeHwnd());
FLASHWINFO st;
st.cbSize = sizeof(st);
st.hwnd = s_pHTMLTableDesignerDlg->GetSafeHwnd();
st.dwFlags = FLASHW_CAPTION;
st.uCount = 3;
st.dwTimeout = 0;
FlashWindowEx(&st);
}
}