File: editor_dialog.cpp

package info (click to toggle)
plucker 1.8-34
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 21,340 kB
  • sloc: ansic: 47,691; cpp: 42,310; python: 17,043; makefile: 1,521; perl: 1,492; pascal: 1,123; sh: 474; sed: 64; java: 13; csh: 6
file content (1030 lines) | stat: -rw-r--r-- 39,780 bytes parent folder | download | duplicates (4)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
//----------------------------------------------------------------------------------------
// Name:        editor_dialog.cpp
// Purpose:     Simple HTML editor dialog
// Author:      Robert O'Connor
// Modified by:
// Created:     2001/10/20
// Copyright:   (c) Robert O'Connor ( rob@medicalmnemonics.com )
// Licence:     GPL
// RCS-ID:      $Id: editor_dialog.cpp,v 1.26 2004/01/04 00:57:49 robertoconnor Exp $
//----------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------
// GCC implementation
//----------------------------------------------------------------------------------------

#if defined(__GNUG__) && ! defined(__APPLE__)
    #pragma implementation "editor_dialog.h"
#endif

//----------------------------------------------------------------------------------------
// Setup information
//----------------------------------------------------------------------------------------

#include "setup.h"

//----------------------------------------------------------------------------------------
// Begin feature removal condition
//----------------------------------------------------------------------------------------

#if ( setupUSE_INTEGRATED_HTML_EDITOR )

//----------------------------------------------------------------------------------------
// Standard wxWindows headers
//----------------------------------------------------------------------------------------

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

// For all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWindows headers)
#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif

//----------------------------------------------------------------------------------------
// Header of this .cpp file
//----------------------------------------------------------------------------------------

#include "editor_dialog.h"

//----------------------------------------------------------------------------------------
// Remaining headers: Needed wx headers, then wx/contrib headers, then application headers
//----------------------------------------------------------------------------------------

#include "wx/notebook.h"            // wxNotebook (need its event table)
#include "wx/html/htmlwin.h"        // wxHtmlWindow    

// ---------------------------------------------------------------------------------------

#include "wx/xrc/xmlres.h"          // XRC XML resources
#if ( setupUSE_STYLED_TEXT_CONTROL )
    #include "wx/wfstream.h"        // FileStream for loading StyledTextControl data
#endif

// ---------------------------------------------------------------------------------------

#include "configuration.h"
#include "body_dialog.h"
#include "bookmark_dialog.h"
#include "email_dialog.h"
#include "font_dialog.h"
#include "hr_dialog.h"
#include "hyperlink_dialog.h"
#include "image_dialog.h"
#include "ol_dialog.h"
#include "popup_dialog.h"
#include "span_dialog.h"
#include "table_dialog.h"
#include "td_th_dialog.h"
#include "ul_dialog.h"
#include "image_list.h"
#include "utils_controls.h"
#include "help_controller.h"

//----------------------------------------------------------------------------------------
// Internal constants
//----------------------------------------------------------------------------------------

// Index numbers of tabs (aka notebook pages) in the notebook, as will find each tab by
// index and assign an image to each tab. Also for the notebook page changing function.
enum {
    EDITOR_NOTEBOOK_PAGE_INDEX_EDIT             = 0, 
    EDITOR_NOTEBOOK_PAGE_INDEX_PREVIEW
};

//----------------------------------------------------------------------------------------
// Event table: connect the events to the handler functions to process them
//----------------------------------------------------------------------------------------

BEGIN_EVENT_TABLE( editor_dialog, wxDialog )
    // The id to pass for this event is the the id of notebook, not the id of the
    // notebook page
    EVT_NOTEBOOK_PAGE_CHANGING( XRCID( "editor_dialog_notebook" ), editor_dialog::on_notebook_changing)
    // The basic toolbar panel
    EVT_BUTTON( XRCID( "editor_dialog_basic_panel_hyperlink_button" ), editor_dialog::on_toolbar_hyperlink_button )
    // The advanced toolbar panel
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_hyperlink_button" ), editor_dialog::on_toolbar_hyperlink_button )

    EVT_BUTTON( XRCID( "editor_dialog_toolbar_mailto_button" ), editor_dialog::on_toolbar_mailto_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_bookmark_button" ), editor_dialog::on_toolbar_bookmark_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_popup_button" ), editor_dialog::on_toolbar_popup_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_paragraph_button" ), editor_dialog::on_toolbar_paragraph_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_paragraph_left_button" ), editor_dialog::on_toolbar_paragraph_left_button )    
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_paragraph_center_button" ), editor_dialog::on_toolbar_paragraph_center_button ) 
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_paragraph_right_button" ), editor_dialog::on_toolbar_paragraph_right_button ) 
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_paragraph_full_button" ), editor_dialog::on_toolbar_paragraph_full_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_break_button" ), editor_dialog::on_toolbar_break_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_image_button" ), editor_dialog::on_toolbar_image_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_hr_button" ), editor_dialog::on_toolbar_hr_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_nbsp_button" ), editor_dialog::on_toolbar_nbsp_button )

    EVT_BUTTON( XRCID( "editor_dialog_toolbar_span_button" ), editor_dialog::on_toolbar_span_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_div_left_button" ), editor_dialog::on_toolbar_div_left_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_div_center_button" ), editor_dialog::on_toolbar_div_center_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_div_right_button" ), editor_dialog::on_toolbar_div_right_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_center_button" ), editor_dialog::on_toolbar_center_button )
   EVT_BUTTON( XRCID( "editor_dialog_toolbar_blockquote_button" ), editor_dialog::on_toolbar_blockquote_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_q_button" ), editor_dialog::on_toolbar_q_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_cite_button" ), editor_dialog::on_toolbar_cite_button )

    EVT_BUTTON( XRCID( "editor_dialog_toolbar_font_button" ), editor_dialog::on_toolbar_font_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_bold_button" ), editor_dialog::on_toolbar_bold_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_strong_button" ), editor_dialog::on_toolbar_strong_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_italic_button" ), editor_dialog::on_toolbar_italic_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_em_button" ), editor_dialog::on_toolbar_em_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_underline_button" ), editor_dialog::on_toolbar_underline_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_strike_button" ), editor_dialog::on_toolbar_strike_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_tt_button" ), editor_dialog::on_toolbar_tt_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_sup_button" ), editor_dialog::on_toolbar_sup_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_sub_button" ), editor_dialog::on_toolbar_sub_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_preformatted_button" ), editor_dialog::on_toolbar_preformatted_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_code_button" ), editor_dialog::on_toolbar_code_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_h1_button" ), editor_dialog::on_toolbar_h1_button ) 
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_h2_button" ), editor_dialog::on_toolbar_h2_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_h3_button" ), editor_dialog::on_toolbar_h3_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_h4_button" ), editor_dialog::on_toolbar_h4_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_h5_button" ), editor_dialog::on_toolbar_h5_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_h6_button" ), editor_dialog::on_toolbar_h6_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_small_button" ), editor_dialog::on_toolbar_small_button )

    EVT_BUTTON( XRCID( "editor_dialog_toolbar_table_button" ), editor_dialog::on_toolbar_table_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_tr_button" ), editor_dialog::on_toolbar_tr_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_th_button" ), editor_dialog::on_toolbar_th_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_td_button" ), editor_dialog::on_toolbar_td_button )

    EVT_BUTTON( XRCID( "editor_dialog_toolbar_ordered_list_button" ), editor_dialog::on_toolbar_ordered_list_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_unordered_list_button" ), editor_dialog::on_toolbar_unordered_list_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_list_element_button" ), editor_dialog::on_toolbar_list_element_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_menu_button" ), editor_dialog::on_toolbar_menu_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_dt_button" ), editor_dialog::on_toolbar_dt_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_dd_button" ), editor_dialog::on_toolbar_dd_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_dl_button" ), editor_dialog::on_toolbar_dl_button )
    
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_html_button" ), editor_dialog::on_toolbar_html_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_meta_handheldfriendly_button" ), editor_dialog::on_toolbar_meta_handheldfriendly_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_body_button" ), editor_dialog::on_toolbar_body_button )
    EVT_BUTTON( XRCID( "editor_dialog_toolbar_comment_button" ), editor_dialog::on_toolbar_comment_button )

    EVT_BUTTON( wxID_OK, editor_dialog::OnOK )
    EVT_BUTTON( wxID_HELP_CONTEXT, editor_dialog::on_help_button )
END_EVENT_TABLE()

//----------------------------------------------------------------------------------------
// Public members
//----------------------------------------------------------------------------------------

// Constructor, including setting the dialog's m_editted_filename member to the
// incoming filename_to_load string.

editor_dialog::editor_dialog( wxWindow* parent, wxString filename_to_load )
                        : m_editted_filename( filename_to_load )
{
    wxXmlResource::Get()->LoadDialog( this, parent, "editor_dialog" );
            
    // Load either the simple or advanced toolbar into the <unknown> placeholder
    // in the XRC (similar to showcase_dialog.cpp--see there for comments).    
    bool use_advanced_toolbars = the_configuration->Read( "/PLUCKER_DESKTOP/editor_use_advanced_toolbars", 0L );
    
    if ( use_advanced_toolbars ) 
    {    
        wxXmlResource::Get()->AttachUnknownControl( wxT( "editor_dialog_toolbar_panel" ),
            wxXmlResource::Get()->LoadPanel( this, wxT( "editor_dialog_advanced_panel" ) ) );
    } 
    else 
    {
        wxXmlResource::Get()->AttachUnknownControl( wxT( "editor_dialog_toolbar_panel" ),
            wxXmlResource::Get()->LoadPanel( this, wxT( "editor_dialog_basic_panel" ) ) );
    }
    
    // Replaces the unknown placeholder in resource with a STC or TextCtrl
#if ( setupUSE_STYLED_TEXT_CONTROL )
    m_editor_stc = new wxStyledTextCtrl( this, -1 );
    wxXmlResource::Get()->AttachUnknownControl( wxT( "editor_dialog_stc_or_textctrl" ),
                                           m_editor_stc );                                           
#else       // setupUSE_STYLED_TEXT_CONTROL
    m_editor_textctrl = new wxTextCtrl( this, -1, wxEmptyString, wxDefaultPosition,
                                        wxSize( 0,0 ), wxTE_MULTILINE | wxHSCROLL );
    wxXmlResource::Get()->AttachUnknownControl( wxT( "editor_dialog_stc_or_textctrl" ),
                                            m_editor_textctrl );                                            
#endif      // setupUSE_STYLED_TEXT_CONTROL    

    // Initialize the settings for STC or TextCtrl
    stc_or_textctrl_init();
    
    // Give small icons to the 'Edit' and 'Preview' tabs, using images from the shareed 
    // wxImageList. First assign the imagelist to use to get images from, then tell what
    // index number to set the icons to. 
    XRCCTRL( *this, "editor_dialog_notebook", wxNotebook )
        ->SetImageList( image_list::get() );
    XRCCTRL( *this, "editor_dialog_notebook", wxNotebook )
        ->SetPageImage( EDITOR_NOTEBOOK_PAGE_INDEX_EDIT, SMALL_IMAGE_LIST_ID_EDITOR_DIALOG_EDIT_TAB );
    XRCCTRL( *this, "editor_dialog_notebook", wxNotebook )
        ->SetPageImage( EDITOR_NOTEBOOK_PAGE_INDEX_PREVIEW, SMALL_IMAGE_LIST_ID_EDITOR_DIALOG_PREVIEW_TAB );
    
    // Load the file into the STC or TextCtrl
    stc_or_textctrl_load_file( filename_to_load );
    
    // Set the size, position of the frame using our common function for this dialog
    // [utils_controls.cpp]
    utils_controls::read_dialog_position_and_size( this, "editor_dialog" );
}


// Destructor
editor_dialog::~editor_dialog()
{
    // Save the size and position of the dialog for next time
    // [utils_controls.cpp]
    utils_controls::write_dialog_position_and_size( this, "editor_dialog" );

    // Delete the added styled text control / textctrl so no memory leak.
    //! \todo SOURCE: Needed? Weren't they created as children so they should go anyways.
#if ( setupUSE_STYLED_TEXT_CONTROL )
    delete m_editor_stc; 
    m_editor_stc = NULL;
#else   // setupUSE_STYLED_TEXT_CONTROL
    delete m_editor_textctrl; 
    m_editor_textctrl = NULL;
#endif  // setupUSE_STYLED_TEXT_CONTROL
}

//----------------------------------------------------------------------------------------
// Private members: Non-event handlers
//----------------------------------------------------------------------------------------

// Initializes the STC or TextCtrl
void editor_dialog::stc_or_textctrl_init()
{
    // Make a default font for the STC or TextCtrl. Set the default point size up in 
    // plucker_defines.h, as it varies too much with the OS.
    wxFont default_font( plkrDEFAULT_TEXTCTRL_FONT_POINTSIZE,
                         wxFONTFAMILY_TELETYPE, 
                         wxFONTSTYLE_NORMAL,
                         wxFONTWEIGHT_NORMAL
//! \todo Remove the force to Courier after there is a font selector.
#ifdef __WXGTK__                         
                         ,
                         FALSE,
                         "Courier"
#endif                         
                         );  
                                
#if ( setupUSE_STYLED_TEXT_CONTROL )

    // Setup the default font, if it is OK
    if ( default_font.Ok() ) 
    {
        m_editor_stc->StyleSetFont( wxSTC_STYLE_DEFAULT, default_font );
    }
    // Clear any current styles.
    m_editor_stc->StyleClearAll();
    
    // The rest of these set up certain styles for HTML. See wx/stc/stc.h for the defines:   
    
    // wxSTC_H_DEFAULT: Normal text, not inside a <>: <tag>style</tag>style<nexttag>
    m_editor_stc->StyleSetForeground( wxSTC_H_DEFAULT, wxColour( 0x00, 0x00, 0x00 ) ); 
    
    // wxSTC_H_TAG: Tags: <style attribute="value"></style>
    m_editor_stc->StyleSetForeground( wxSTC_H_TAG,  wxColour( 0x99, 0x00, 0x99 ) );
    m_editor_stc->StyleSetBold( wxSTC_H_TAG, TRUE );
    
    // wxSTC_H_ATTRIBUTE: Attributes: <tag style="value">    
    m_editor_stc->StyleSetForeground( wxSTC_H_ATTRIBUTE, wxColour( 0xff, 0x00, 0x00 ) );
    m_editor_stc->StyleSetBold( wxSTC_H_ATTRIBUTE, TRUE );  

    // wxSTC_H_NUMBER: Unquoted attribute numerical values: <tag attribute=style>
    m_editor_stc->StyleSetForeground( wxSTC_H_NUMBER, wxColour( 0x00, 0x00, 0xff ) );
    
    // wxSTC_H_DOUBLESTRING: Doubled quoted attribute values: <tag attribute="style">
    m_editor_stc->StyleSetForeground( wxSTC_H_DOUBLESTRING, wxColour( 0x00, 0x00, 0xff ) );

    // wxSTC_H_SINGLESTRING: Single quoted attribute values: <tag attribute='style'>
    m_editor_stc->StyleSetForeground( wxSTC_H_SINGLESTRING,  wxColour( 0x00, 0x00, 0xff ) );

    // wxSTC_H_OTHER: Equal signs (=) between paramters and values: <tag attributestylevalue>
    m_editor_stc->StyleSetForeground( wxSTC_H_OTHER, wxColour( 0xff, 0x00, 0x00 ) );
    
    // wxSTC_H_COMMENT: HTML comments (also colors the <!--- and --->): <!--- style --->
    m_editor_stc->StyleSetForeground( wxSTC_H_COMMENT, wxColour( 0x99, 0x99, 0x99 ) );
    m_editor_stc->StyleSetItalic( wxSTC_H_COMMENT, TRUE );
    
    // wxSTC_H_ENTITY: Entities, such as &amp; or &nbsp;
    m_editor_stc->StyleSetForeground( wxSTC_H_ENTITY, wxColour( 0x00, 0x00, 0x00 ) );
    m_editor_stc->StyleSetItalic( wxSTC_H_ENTITY, TRUE );
    m_editor_stc->StyleSetBold( wxSTC_H_ENTITY, TRUE );  

    // Set the forecolor and backcolor for text currently wiped and selected 
    // with mouse. Fits in best with OS as a whole if use the OS system colors.
    m_editor_stc->SetSelForeground( TRUE, 
                  wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) );
    m_editor_stc->SetSelBackground( TRUE, 
                  wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHT ) );

    // Put line numbers in the margin ( ie the gutter )
    m_editor_stc->SetMarginType( 0, wxSTC_MARGIN_NUMBER );    
  
    // Format the font of the line numbers, and the margin width    
#ifdef __WXMSW__
    m_editor_stc->StyleSetSpec( wxSTC_STYLE_LINENUMBER, "size:7,face:Arial,fore:#666666" );
    m_editor_stc->SetMarginWidth( 0, 22 );
#else
    m_editor_stc->StyleSetSpec( wxSTC_STYLE_LINENUMBER, "size:9,face:Helvetica" );
    m_editor_stc->SetMarginWidth( 0, 22 );
#endif

#else       // setupUSE_STYLED_TEXT_CONTROL

    m_editor_textctrl->SetFont( default_font );
        
#endif    // setupUSE_STYLED_TEXT_CONTROL
}


// Loads the file to edit into the STC or TextCtrl
void editor_dialog::stc_or_textctrl_load_file( wxString filename )
{
#if ( setupUSE_STYLED_TEXT_CONTROL )

    // Load up the text
    wxFile   file( filename );
    wxString st;

    char* buff = st.GetWriteBuf( file.Length() );
    file.Read( buff, file.Length() );
    st.UngetWriteBuf();

    //! \todo SOURCE: Need to destruct the wxFile object here?
    file.~wxFile();

    m_editor_stc->InsertText( 0, st );
    m_editor_stc->EmptyUndoBuffer();
    
    // STC has differed lexers to colorize different language syntaxes. This sets the 
    // lexer to HTML syntax 
    m_editor_stc->SetLexer( wxSTC_LEX_HTML );
    
#else      // setupUSE_STYLED_TEXT_CONTROL

    // wxTextCtrl has its own function to load directly from a file.
    m_editor_textctrl->LoadFile( filename );
        
#endif    // setupUSE_STYLED_TEXT_CONTROL
}


// Inserts 2 string of text at the current insertion point. It is split into 2 strings
// so that can (a) Highlight a swatch of text and the start and ending text gets put
// on either side of the selected text, or (b) if no text selected, then backspace the
// caret to right before the ending text, so that when add a <h1></h1>, the caret gets
// placed in a logical place: <h1>|</h1> 
void editor_dialog::stc_or_textctrl_insert_text
    ( 
    wxString starting_text_to_insert,   // Text to insert at start of selection
    wxString ending_text_to_insert,     // Text to insert at end of a selection
    bool     tag_can_insert_newline     // Whether prudent to ever insert a '\n'
    )                                                 
{
    wxString selected_text;      // Currently selected text in the control
   
    // Add a trailing linefeed to the ending text, if so requested by the user in the
    // editor preferences, and it is prudent to do so (ie a newline after a <i> </i> doesn't
    // make sense.
    bool insert_a_linefeed = the_configuration->Read( "/PLUCKER_DESKTOP/editor_tools_insert_linefeeds", 1L); 
    if ( insert_a_linefeed && tag_can_insert_newline ) 
    {
        ending_text_to_insert += wxT( "\n" );  
    }        
    
#if ( setupUSE_STYLED_TEXT_CONTROL )
    selected_text = m_editor_stc->GetSelectedText();
    
    if ( selected_text == "" )
    {
        // No text selected, just add the two strings at the insertion point
        int original_caret_position = m_editor_stc->GetCurrentPos();
        m_editor_stc->InsertText( original_caret_position, ending_text_to_insert );
        m_editor_stc->InsertText( original_caret_position, starting_text_to_insert );
        // Now set the cursor to between the starting and ending text. The previous
        // insertion text ends up at the the original caret position, so just fast-forward
        // the length of the starting text        
        int length_of_starting_text_to_insert = (int) starting_text_to_insert.Length();
        int new_caret_position = original_caret_position + length_of_starting_text_to_insert;
        m_editor_stc->SetSelectionStart( new_caret_position );
        //m_editor_stc->SetCurrentPos( new_caret_position );
    } 
    else 
    {
        // Some text is selected, so put the ending_text at the end of the selected text,
        // and the starting text before the selected text.
        // First, store the positions of start and end of selection.
        int selection_starting_caret_position = m_editor_stc->GetSelectionStart();
        int selection_ending_caret_position = m_editor_stc->GetSelectionEnd();
        // Now insert the ending text at the ending caret position (by inserting the 
        // ending text first, the starting position doesn't change).
        m_editor_stc->InsertText( selection_ending_caret_position , ending_text_to_insert );
        m_editor_stc->InsertText( selection_starting_caret_position, starting_text_to_insert );
    }   
    
    // Set the focus from the toolbar, back to the STC. 
    m_editor_stc->SetFocus();
    
#else      // setupUSE_STYLED_TEXT_CONTROL

    long selection_starting_caret_position;
    long selection_ending_caret_position;
    
    m_editor_textctrl->GetSelection( &selection_starting_caret_position,
                                     &selection_ending_caret_position );
                        
    // If selection starting caret position equals the end, that means was no selection
    if ( selection_starting_caret_position == selection_ending_caret_position ) 
    {       
        long original_caret_position = m_editor_textctrl->GetInsertionPoint();
        // No text selected, just add the two strings at the insertion point 
        m_editor_textctrl->WriteText( starting_text_to_insert );
        m_editor_textctrl->WriteText( ending_text_to_insert );
        // Now set the cursor to between the starting and ending text. The previous
        // insertion text ends up at the the original caret position, so just fast-forward
        // the length of the starting text
        long length_of_starting_text_to_insert = (long) starting_text_to_insert.Length();
        long new_caret_position = original_caret_position + length_of_starting_text_to_insert;
        m_editor_textctrl->SetInsertionPoint( new_caret_position );
    } 
    else
    {
        // Some text is selected, so put the ending_text at the end of the selected text,
        // and the starting text before the selected text.
        // Set the insertion point to selection end, then insert ending text
        m_editor_textctrl->SetInsertionPoint( selection_ending_caret_position );
        m_editor_textctrl->WriteText( ending_text_to_insert );
        // Set the insertion point to selection end, then insert ending text
        m_editor_textctrl->SetInsertionPoint( selection_starting_caret_position );
        m_editor_textctrl->WriteText( starting_text_to_insert );
    }
        
    // Set the focus from the toolbar, back to the TextCtrl. 
    m_editor_textctrl->SetFocus();
#endif    // setupUSE_STYLED_TEXT_CONTROL
}

void editor_dialog::stc_or_textctrl_send_text_to_preview()        
{
    wxString preview_text;
    
#if ( setupUSE_STYLED_TEXT_CONTROL )
    
    // Get all the text in the styled text control.
    preview_text = m_editor_stc->GetText();
    
#else      // setupUSE_STYLED_TEXT_CONTROL

    // Get all the text in the wxTextCtrl        
    preview_text = m_editor_textctrl->GetValue();

#endif    // setupUSE_STYLED_TEXT_CONTROL

    // Set the preview html window to the preview_text string
    XRCCTRL( *this, "editor_dialog_preview_tab_htmlwindow", wxHtmlWindow )
        ->SetPage( preview_text );
    wxLogDebug ( "Set the value of htmlwindow" );
}


// Saves context of STC or TextCtrl to a file ( no filename argument, since
// using the class member 'm_editted_filename').
void editor_dialog::stc_or_textctrl_save_file()      
{

#if ( setupUSE_STYLED_TEXT_CONTROL )
    
    // TODO: override OnCancel/On Close to give a warning box if cancelling on a text control
    //       that was modified.
    
    wxString stc_text;
    // Create a file object, and importantly, the second parameter is wxFile::write
    // mode so, that can write to the file.
    wxFile   file( m_editted_filename, wxFile::write );
    
    // Get all the text in the styled text control.
    stc_text = m_editor_stc->GetText();
    
    // Dump the entire string to the file.
    file.Write( stc_text );
    
    //TODO: Need to destroy the wxFile object?
    file.~wxFile();
    
#else      // setupUSE_STYLED_TEXT_CONTROL
    
    // TODO: override OnCancel/On Close to give a warning box if cancelling on a text control
    //       that was modified.
    
    // Only bother saving if the text inside the textbox has been modified.
    if ( m_editor_textctrl->IsModified() ) 
    {     
        // Save the HTML code from the text control, back into the file.
        // Recall "this->m_editted_filename" was the home.html file that we
        // squirreled away when we first opened this dialog.
    
        bool successful = m_editor_textctrl->SaveFile( this->m_editted_filename );        
        // Show a warning message if unable to save.
        if( ! successful )
        {
            wxLogError( _( "Unable to save home.html" ) );
        }
    }  
    
#endif    // setupUSE_STYLED_TEXT_CONTROL
}

//----------------------------------------------------------------------------------------
// Private members: event handlers
//----------------------------------------------------------------------------------------

// Loads the html source of edit textctrl into preview htmlwindow, so can render a preview.
void editor_dialog::on_notebook_changing( wxNotebookEvent &event )
{ 
    // There is a on_notebook_changing event sent when loading dialog, and this causes a 
    // crash. Therefore we prevent it executing until our notebook is displayed.
    if ( this->wxWindow::IsShown() ) 
    {
        wxLogDebug( "Entering on_notebook_changing_function" );
        wxLogDebug( "Notebook event.GetOldSelection=%d", event.GetOldSelection() ); 
        if ( event.GetOldSelection() == EDITOR_NOTEBOOK_PAGE_INDEX_EDIT ) {   
            wxLogDebug( "Switching from edit tab, so sending text to preview tab" );     
            stc_or_textctrl_send_text_to_preview();
        }        
    }   
}


void editor_dialog::on_toolbar_hyperlink_button( wxCommandEvent &event )
{
   hyperlink_dialog a_hyperlink_dialog( this );   
    
   if ( a_hyperlink_dialog.ShowModal() == wxID_OK )
   {
       wxString starting_text;
       wxString ending_text;
       a_hyperlink_dialog.transfer_to( starting_text, ending_text );              
       stc_or_textctrl_insert_text( starting_text, ending_text, TRUE );
   }    

}


void editor_dialog::on_toolbar_mailto_button( wxCommandEvent &event )
{
   email_dialog a_email_dialog( this );   
    
   if ( a_email_dialog.ShowModal() == wxID_OK ) 
   {
       wxString starting_text;
       wxString ending_text;
       a_email_dialog.transfer_to( starting_text, ending_text );              
       stc_or_textctrl_insert_text( starting_text, ending_text, TRUE );
   }    
}


void editor_dialog::on_toolbar_bookmark_button( wxCommandEvent &event )
{
   bookmark_dialog a_bookmark_dialog( this );   
    
   if ( a_bookmark_dialog.ShowModal() == wxID_OK )
   {
       wxString starting_text;
       wxString ending_text;
       a_bookmark_dialog.transfer_to( starting_text, ending_text );              
       stc_or_textctrl_insert_text( starting_text, ending_text, TRUE );
   }    
}


void editor_dialog::on_toolbar_popup_button( wxCommandEvent &event )
{
   popup_dialog a_popup_dialog( this );   
    
   if ( a_popup_dialog.ShowModal() == wxID_OK )
   {
       wxString starting_text;
       wxString ending_text;
       a_popup_dialog.transfer_to( starting_text, ending_text );              
       stc_or_textctrl_insert_text( starting_text, ending_text, TRUE );
   }     
}

void editor_dialog::on_toolbar_paragraph_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<p>", "</p>", TRUE );
}


void editor_dialog::on_toolbar_paragraph_left_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<p align=\"left\">", "</p>", TRUE );
}


void editor_dialog::on_toolbar_paragraph_center_button( wxCommandEvent &event ) 
{
    stc_or_textctrl_insert_text( "<p align=\"center\">", "</p>", TRUE );
}


void editor_dialog::on_toolbar_paragraph_right_button( wxCommandEvent &event ) 
{
    stc_or_textctrl_insert_text( "<p align=\"right\">", "</p>", TRUE );
}


void editor_dialog::on_toolbar_paragraph_full_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<p align=\"full\">", "</p>", TRUE );
}


void editor_dialog::on_toolbar_break_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<br>", "", TRUE );
}


void editor_dialog::on_toolbar_image_button( wxCommandEvent &event )
{
   image_dialog a_image_dialog( this );   
    
   if ( a_image_dialog.ShowModal() == wxID_OK ) 
   {
       wxString starting_text;
       wxString ending_text;
       a_image_dialog.transfer_to( starting_text, ending_text );              
       stc_or_textctrl_insert_text( starting_text, ending_text, TRUE );
   }      
}


void editor_dialog::on_toolbar_hr_button( wxCommandEvent &event )
{
   hr_dialog a_hr_dialog( this );   
    
   if ( a_hr_dialog.ShowModal() == wxID_OK ) 
   {
       wxString starting_text;
       wxString ending_text;
       a_hr_dialog.transfer_to( starting_text, ending_text );              
       stc_or_textctrl_insert_text( starting_text, ending_text, TRUE );
   }    
}


void editor_dialog::on_toolbar_nbsp_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "&nbsp;", "", FALSE );
}


void editor_dialog::on_toolbar_span_button( wxCommandEvent &event )
{
   span_dialog a_span_dialog( this );   
    
   if ( a_span_dialog.ShowModal() == wxID_OK )
   {
       wxString starting_text;
       wxString ending_text;
       a_span_dialog.transfer_to( starting_text, ending_text );              
       stc_or_textctrl_insert_text( starting_text, ending_text, TRUE );
   }    
}


void editor_dialog::on_toolbar_div_left_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<div align=\"left\">", "</div>", TRUE );
}


void editor_dialog::on_toolbar_div_center_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<div align=\"center\">", "</div>", TRUE );
}


void editor_dialog::on_toolbar_div_right_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<div align=\"right\">", "</div>", TRUE );
}


void editor_dialog::on_toolbar_center_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<center>", "</center>", FALSE );
}


void editor_dialog::on_toolbar_blockquote_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<blockquote>", "</blockquote>", TRUE );
}


void editor_dialog::on_toolbar_q_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<q>", "</q>", TRUE );
}


void editor_dialog::on_toolbar_cite_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<cite>", "</cite>", TRUE );
}


void editor_dialog::on_toolbar_font_button( wxCommandEvent &event )
{
   font_dialog a_font_dialog( this );   
    
   if ( a_font_dialog.ShowModal() == wxID_OK )
   {
       wxString starting_text;
       wxString ending_text;
       a_font_dialog.transfer_to( starting_text, ending_text );              
       stc_or_textctrl_insert_text( starting_text, ending_text, TRUE );
   }    
}


void editor_dialog::on_toolbar_bold_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<b>", "</b>", FALSE );
}


void editor_dialog::on_toolbar_strong_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<strong>", "</strong>", FALSE );
}


void editor_dialog::on_toolbar_italic_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<i>", "</i>", FALSE );
}


void editor_dialog::on_toolbar_em_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<em>", "</em>", FALSE );
}


void editor_dialog::on_toolbar_underline_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<u>", "</u>", FALSE );
}


void editor_dialog::on_toolbar_strike_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<strike>", "</strike>", FALSE );
}


void editor_dialog::on_toolbar_tt_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<tt>", "</tt>", FALSE );
}


void editor_dialog::on_toolbar_sup_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<sup>", "</sup>", FALSE );
}


void editor_dialog::on_toolbar_sub_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<sub>", "</sub>", FALSE );
}


void editor_dialog::on_toolbar_preformatted_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<pre>", "</pre>", FALSE );
}


void editor_dialog::on_toolbar_code_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<code>", "</code>", TRUE);
}


void editor_dialog::on_toolbar_h1_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<h1>", "</h1>", TRUE );
}


void editor_dialog::on_toolbar_h2_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<h2>", "</h2>", TRUE );
}


void editor_dialog::on_toolbar_h3_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<h3>", "</h3>", TRUE );
}


void editor_dialog::on_toolbar_h4_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<h4>", "</h4>", TRUE );
}


void editor_dialog::on_toolbar_h5_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<h5>", "</h5>", TRUE );
}


void editor_dialog::on_toolbar_h6_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<h6>", "</h6>", TRUE );
}


void editor_dialog::on_toolbar_small_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<small>", "</small>", TRUE );
}


void editor_dialog::on_toolbar_table_button( wxCommandEvent &event )
{
    table_dialog a_table_dialog( this );

    if ( a_table_dialog.ShowModal() == wxID_OK ) 
    {
        wxString starting_text;
        wxString ending_text;
        a_table_dialog.transfer_to( starting_text, ending_text );
        stc_or_textctrl_insert_text( starting_text, ending_text, TRUE );
    }
}


void editor_dialog::on_toolbar_tr_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<tr>", "</tr>", TRUE );
}


void editor_dialog::on_toolbar_th_button( wxCommandEvent &event )
{
    td_th_dialog a_td_th_dialog( this, optionTD_TH_DIALOG_IS_TH );

    if ( a_td_th_dialog.ShowModal() == wxID_OK )
    {
        wxString starting_text;
        wxString ending_text;
        a_td_th_dialog.transfer_to( starting_text, ending_text );
        stc_or_textctrl_insert_text( starting_text, ending_text, TRUE );
    }
}


void editor_dialog::on_toolbar_td_button( wxCommandEvent &event )
{
    td_th_dialog a_td_th_dialog( this, optionTD_TH_DIALOG_IS_TD );

    if ( a_td_th_dialog.ShowModal() == wxID_OK ) 
    {
        wxString starting_text;
        wxString ending_text;
        a_td_th_dialog.transfer_to( starting_text, ending_text );
        stc_or_textctrl_insert_text( starting_text, ending_text, TRUE );
    }
}


void editor_dialog::on_toolbar_ordered_list_button( wxCommandEvent &event )
{
    ol_dialog a_ol_dialog( this );

    if ( a_ol_dialog.ShowModal() == wxID_OK )
    {
        wxString starting_text;
        wxString ending_text;
        a_ol_dialog.transfer_to( starting_text, ending_text );
        stc_or_textctrl_insert_text( starting_text, ending_text, TRUE );
    }
}

void editor_dialog::on_toolbar_unordered_list_button( wxCommandEvent &event )
{
    ul_dialog a_ul_dialog( this );

    if ( a_ul_dialog.ShowModal() == wxID_OK ) 
    {
        wxString starting_text;
        wxString ending_text;
        a_ul_dialog.transfer_to( starting_text, ending_text );
        stc_or_textctrl_insert_text( starting_text, ending_text, TRUE );
    }
}

void editor_dialog::on_toolbar_list_element_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<li>", "</li>", TRUE );
}

void editor_dialog::on_toolbar_menu_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<menu>", "</menu>", TRUE );
}


void editor_dialog::on_toolbar_dt_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<dt>", "</dt>", TRUE );
}


void editor_dialog::on_toolbar_dd_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<dd>", "</dd>", TRUE );
}


void editor_dialog::on_toolbar_dl_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<dl>", "</dl>", TRUE );
}

    
void editor_dialog::on_toolbar_html_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<html>", "</html>", TRUE );
}


void editor_dialog::on_toolbar_meta_handheldfriendly_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( 
                       "<meta name=\"HandheldFriendly\" content=\"true\">", "", TRUE );
}


void editor_dialog::on_toolbar_body_button( wxCommandEvent &event )
{
   body_dialog a_body_dialog( this );   
    
   if ( a_body_dialog.ShowModal() == wxID_OK )
   {
       wxString starting_text;
       wxString ending_text;
       a_body_dialog.transfer_to( starting_text, ending_text );              
       stc_or_textctrl_insert_text( starting_text, ending_text, TRUE );
   }    
}


void editor_dialog::on_toolbar_comment_button( wxCommandEvent &event )
{
    stc_or_textctrl_insert_text( "<!--- ", " --->", FALSE );
}


// Override wxDialog's default behavior for clicking an OK button.
void editor_dialog::OnOK( wxCommandEvent& event )
{
    // Save to a file.
    stc_or_textctrl_save_file();
    
    // Get rid of the modal dialog. Not transferring any info from this modal's control
    // to a parent dialog, so don't have to bother with wxWindow::Validate or 
    // wxWindow::TransferDataFromWindow.    
    EndModal( wxID_OK );
}


void editor_dialog::on_help_button( wxCommandEvent &event )
{
#if ( setupUSE_ONLINE_HELP )
    help_controller::get()->show_help_topic( plkrHELP_ID_EDITOR_DIALOG );    
#endif 
}

//----------------------------------------------------------------------------------------
// End feature removal condition
//----------------------------------------------------------------------------------------

#endif // setupUSE_INTEGRATED_HTML_EDITOR