-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmlEditorChild.h
More file actions
1080 lines (963 loc) · 26.5 KB
/
xmlEditorChild.h
File metadata and controls
1080 lines (963 loc) · 26.5 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
/*
Project: Windows Class Library
Module: xmlEditorChild.h
Description: A control used to edit XML data
Author: Martin Gäckler
Address: Hofmannsthalweg 14, A-4030 Linz
Web: https://www.gaeckler.at/
Copyright: (c) 1988-2025 Martin Gäckler
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
THIS SOFTWARE IS PROVIDED BY Martin Gäckler, Linz, Austria ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#ifndef XML_EDITOR_CHILD_H
#define XML_EDITOR_CHILD_H
// --------------------------------------------------------------------- //
// ----- switches ------------------------------------------------------ //
// --------------------------------------------------------------------- //
#ifndef STRICT
#define STRICT 1
#endif
// --------------------------------------------------------------------- //
// ----- includes ------------------------------------------------------ //
// --------------------------------------------------------------------- //
#include <winlib/childWin.h>
#include <gak/xml.h>
#include <gak/shared.h>
#include <stdio.h>
// --------------------------------------------------------------------- //
// ----- module switches ----------------------------------------------- //
// --------------------------------------------------------------------- //
#ifdef __BORLANDC__
# pragma option -RT-
# pragma option -b
# pragma option -a4
# pragma option -pc
#endif
namespace winlib
{
// --------------------------------------------------------------------- //
// ----- constants ----------------------------------------------------- //
// --------------------------------------------------------------------- //
// --------------------------------------------------------------------- //
// ----- macros -------------------------------------------------------- //
// --------------------------------------------------------------------- //
// --------------------------------------------------------------------- //
// ----- type definitions ---------------------------------------------- //
// --------------------------------------------------------------------- //
// --------------------------------------------------------------------- //
// ----- class definitions --------------------------------------------- //
// --------------------------------------------------------------------- //
class Device;
class XMLeditorChild;
namespace internal
{
class ResizeException
{
int m_incWidth;
public:
ResizeException( int incWidth )
{
m_incWidth = incWidth;
}
int getIncWidth() const
{
return m_incWidth;
}
};
class XML_VIEWER_BOX;
typedef gak::SharedObjectPointer<XML_VIEWER_BOX> XML_VIEWER_BOX_PTR;
/*
A XML_LINE_CHUNG represents one part of a line, with the same format
I can contain either a part of an inline element or an inline block element.
*/
class XML_LINE_CHUNK
{
Point m_position;
gak::xml::XmlText *m_theElement;
STRING *m_text;
XML_VIEWER_BOX_PTR m_theInlineBlockBox;
public:
int width;
size_t startPos, len;
XML_LINE_CHUNK()
{
m_theInlineBlockBox = nullptr;
m_theElement = nullptr;
m_text = nullptr;
}
void moveBy( int x, int y );
void moveRight( int x )
{
moveBy( x, 0 );
}
const Point &getPosition() const
{
return m_position;
}
void setPosition( int x, int y )
{
m_position.x = x;
m_position.y = y;
}
void setText( gak::xml::XmlText *theElement, STRING *text )
{
m_theInlineBlockBox = nullptr;
m_theElement = theElement;
m_text = text;
}
gak::xml::XmlText *getTextElement() const
{
return m_theElement;
}
const STRING &getText() const
{
return *m_text;
}
STRING *getTextPtr() const
{
return m_text;
}
bool isTextElement() const
{
return m_theElement && m_text;
}
const XML_VIEWER_BOX *getInlineBox() const
{
return m_theInlineBlockBox;
}
XML_VIEWER_BOX *getInlineBox()
{
return m_theInlineBlockBox;
}
bool isBlockElement() const
{
return bool(m_theInlineBlockBox);
}
void setBlockElement( XML_VIEWER_BOX *theInlineBlockBox )
{
m_theInlineBlockBox = theInlineBlockBox;
m_theElement = nullptr;
m_text = nullptr;
}
#ifdef _DEBUG
void dump( FILE *fp, unsigned level )
{
for( unsigned i=0; i<level; i++ )
fputs( " ", fp );
fprintf(
fp,
"Pos: %d,%d width: %d\n",
m_position.x, m_position.y,
width
);
for( unsigned i=0; i<level; i++ )
fputs( " ", fp );
if( m_theElement )
fprintf( fp, "CHUNK Element %s", (const char *)m_theElement->getParent()->getTag() );
else
fputs( "No Element", fp );
fprintf( fp, "%p\n", getInlineBox() );
if( !m_theElement && !getInlineBox() )
fputs( ">>> WARN: EMPTY CHUNK\n", fp );
else if( m_theElement && getInlineBox() )
fputs( ">>> WARN: OVERLOADED CHUNK\n", fp );
}
#endif
};
/*
A XML Line represent one line of a block element
*/
struct XML_LINE
{
Point m_position;
int m_lineWidth, m_lineHeight, m_maxWidth;
gak::Array<XML_LINE_CHUNK> m_theLine;
XML_LINE()
{
m_position.x = 0;
m_position.y = 0;
m_maxWidth = m_lineWidth = m_lineHeight = 0;
}
void moveBy( int x, int y );
void moveRight( int x )
{
moveBy( x, 0 );
}
void moveDown( int y )
{
moveBy( 0, y );
}
const XML_LINE_CHUNK &getChunk( size_t chunk ) const
{
return m_theLine[chunk];
}
#ifdef _DEBUG
void dump( FILE *fp, unsigned level )
{
int newLevel = level+1;
for( unsigned i=0; i<level; i++ )
fputs( " ", fp );
fprintf(
fp,
"Pos: %d,%d width: %d height: %d\n",
m_position.x, m_position.y,
m_lineWidth, m_lineHeight
);
for( unsigned i=0; i<level; i++ )
fputs( " ", fp );
fprintf( fp, "Num Chunks: %d\n", int(m_theLine.size()) );
for( size_t i=0; i<m_theLine.size(); i++ )
m_theLine[i].dump( fp, newLevel );
}
#endif
};
class XML_CURSOR_POS
{
XML_VIEWER_BOX_PTR m_viewerBox;
size_t m_line, m_chunk, m_insertPos;
int m_horizOffset;
public:
gak::xml::Element *getElement() const;
void setPosition(
const XML_VIEWER_BOX_PTR &viewerBox,
size_t line,
size_t chunk,
size_t insertPos,
int horizOffset
)
{
m_viewerBox = viewerBox;
m_line = line;
m_chunk = chunk;
m_insertPos = insertPos;
m_horizOffset = horizOffset;
}
void setPosition(
size_t line,
size_t chunk,
size_t insertPos,
int horizOffset
)
{
m_line = line;
m_chunk = chunk;
m_insertPos = insertPos;
m_horizOffset = horizOffset;
}
void setPosition(
size_t chunk,
size_t insertPos,
int horizOffset
)
{
m_chunk = chunk;
m_insertPos = insertPos;
m_horizOffset = horizOffset;
}
void setPosition(
size_t insertPos,
int horizOffset
)
{
m_insertPos = insertPos;
m_horizOffset = horizOffset;
}
void movePosition(
int insertPos,
int horizOffset
)
{
m_insertPos += insertPos;
m_horizOffset += horizOffset;
}
void clear()
{
m_viewerBox = nullptr;
m_line = size_t(-1);
m_chunk = size_t(-1);
m_insertPos = 0;
m_horizOffset = 0;
}
const XML_VIEWER_BOX *getViewerBox() const
{
return m_viewerBox;
}
XML_VIEWER_BOX *getViewerBox()
{
return m_viewerBox;
}
size_t getLine() const
{
return m_line;
}
size_t getChunk() const
{
return m_chunk;
}
size_t getInsertPos() const
{
return m_insertPos;
}
int getHorizOffset() const
{
return m_horizOffset;
}
};
/*
A XML_VIEWWER_ITEM represents one content item of an XML block element.
the item can be either an inline element or an inline block element
*/
class XML_VIEWER_ITEM
{
// the inline bloc element
XML_VIEWER_BOX_PTR m_viewerBox;
// OR the XML Element
gak::xml::Element *m_theElement;
bool m_autoWrap, m_preserveBlanks, m_preserveBreaks;
STRING m_text;
public:
XML_VIEWER_ITEM()
{
m_theElement = nullptr;
}
~XML_VIEWER_ITEM()
{
}
void clear()
{
m_viewerBox = nullptr;
m_theElement = nullptr;
}
/*
for line boxes
*/
void setXmlElement(
gak::xml::Element *xmlElement, const STRING &text,
bool autoWrap, bool preserveBlanks, bool preserveBreaks
)
{
m_viewerBox = nullptr;
m_theElement = xmlElement;
m_text = text;
m_autoWrap = autoWrap;
m_preserveBlanks = preserveBlanks;
m_preserveBreaks = preserveBreaks;
}
gak::xml::Element *getXmlElement( void ) const
{
return m_theElement;
}
const STRING &getXmlText() const
{
return m_text;
}
STRING *getXmlTextPtr()
{
return &m_text;
}
bool getAutoWrap() const
{
return m_autoWrap;
}
bool getPreserveBreaks() const
{
return m_preserveBreaks;
}
bool getPreserveBlanks() const
{
return m_preserveBlanks;
}
/*
for inline boxes
*/
void setViewerBox( XML_VIEWER_BOX *xmlViewerBox )
{
m_viewerBox = xmlViewerBox;
m_theElement = nullptr;
}
const XML_VIEWER_BOX *getViewerBox( void ) const
{
return m_viewerBox;
}
XML_VIEWER_BOX *getViewerBox( void )
{
return m_viewerBox;
}
};
/*
A XML_VIEWER_BOX is created for each xml block element
*/
class XML_VIEWER_BOX : public gak::SharedObject
{
friend class XML_TABLE_ROW_VIEWER_BOX;
protected:
enum CURSOR_DIRECTION { CURSOR_UP, CURSOR_DOWN };
RectBorder m_docPosition;
gak::css::Position m_position;
gak::css::Display m_display;
gak::css::ListStyle m_listStyle;
int m_itemNumber;
int m_margin_left,
m_margin_right,
m_margin_top,
m_margin_bottom;
int m_padding_left,
m_padding_right,
m_padding_top,
m_padding_bottom;
int m_border_width_left,
m_border_width_right,
m_border_width_top,
m_border_width_bottom;
gak::css::Border m_border_style_left,
m_border_style_right,
m_border_style_top,
m_border_style_bottom;
int m_maxWidth,
m_innerWidth,
m_innerWidthPercent;
int m_maxHeight, m_innerHeight, m_innerHeightPercent;
gak::xml::Element *m_theElement;
XML_VIEWER_BOX_PTR m_parentBox;
gak::Array<XML_VIEWER_ITEM> m_childElements;
gak::Array<XML_VIEWER_BOX_PTR> m_subBoxes;
gak::Array<RectBorder> m_leftBoxes, m_rightBoxes;
gak::Array<XML_LINE> m_theContent;
static STRING prepareText(
const STRING &text, bool preserveBlanks, bool preserveBreaks
);
static int cssSizeToPixel(
const Device &context, const STRING &cssString,
gak::xml::Element *fontSource
);
void createBox(
const Device &context, gak::xml::Element *theRoot,
gak::css::Display display, gak::css::Position position,
int itemNumber
);
virtual XML_VIEWER_BOX_PTR createBox(
gak::css::Display childDisplay,
int itemNumber
);
void findBoxes( const Device &context, gak::xml::Element *theRoot );
static void createFont(
Device &context, gak::xml::Element *theText , bool withBackground
);
static int getLineHeight( Device &context, gak::xml::Element *theText );
int findTop( int y, int boxWidth, int innerLeft, int innerRight );
size_t findLeftBox( int y );
int findLeft( int y, int minLeft );
size_t findRightBox( int y );
int findRight( int y, int minRight );
static int findCharPos(
Device &context, int cursorPos,
const STRING &text, size_t startPos, size_t *len
);
static int findWrapPos(
Device &context, int maxWidth, bool breakWord,
const STRING &text, size_t startPos, size_t *len
);
bool findCharPosInLine(
Device &context, size_t line, int screenPosition,
XML_CURSOR_POS *cursorPos,
CURSOR_DIRECTION direction
) const;
void getScreenPosition(
int vertOffset, int horizOffset,
RectBorder *screenPosition
)
{
*screenPosition = m_docPosition;
if( m_position < gak::css::POS_FIXED )
{
screenPosition->left -= horizOffset;
screenPosition->top -= vertOffset;;
screenPosition->right -= horizOffset;
screenPosition->bottom -= vertOffset;
}
}
public:
XML_VIEWER_BOX( int itemNumber=0 )
{
m_theElement = nullptr;
m_parentBox = nullptr;
memset( &m_docPosition, 0, sizeof( m_docPosition ) );
m_itemNumber = itemNumber;
}
~XML_VIEWER_BOX()
{
}
virtual void buildBoxTree(
const Device &context, gak::xml::Element *theRoot, XML_VIEWER_BOX *container
);
virtual int calcSize(
Device &context,
int x, int y,
int maxWidth, int windowWidth, int windowHeight,
RectBorder *screen
);
void drawLine(
Device &context, XMLeditorChild *theWindow,
XML_LINE &theLine, bool includeBlocks
);
void draw( Device &context, XMLeditorChild *theWindow );
gak::css::Styles *getCssStyle();
void moveBy( int x, int y );
void moveRight( int x )
{
moveBy( x, 0 );
}
void moveDown( int y )
{
moveBy( 0, y );
}
bool findLineNChunk(
Device &context, gak::xml::XmlText *xmlText, size_t insertPos,
XML_CURSOR_POS *cursorPos
);
bool findElementScreenPosition(
gak::xml::Element *theElement,
int *x, int *y,
XML_CURSOR_POS *cursorPos
) const;
gak::xml::Element *findElementOnScreen(
Device &context,
int x, int y, int horizOffset, int vertOffset,
XML_CURSOR_POS *cursorPos
) const;
size_t getNumLines() const
{
return m_theContent.size();
}
const XML_LINE &getLine( size_t line ) const
{
return m_theContent[line];
}
gak::xml::Element *getElement() const
{
return m_theElement;
}
gak::xml::Element *getElement( size_t line, size_t chunk ) const
{
const XML_LINE &theLine = getLine( line );
const XML_LINE_CHUNK &theChunk = theLine.getChunk( chunk );
return theChunk.getTextElement();
}
gak::xml::Element *locateFirstElement(
XML_CURSOR_POS *cursorPos
) const;
bool locateNextLine(
Device &context,
XML_VIEWER_BOX *current, XML_CURSOR_POS *cursorPos,
int oldPosition
);
bool locateNextChunk( XML_VIEWER_BOX *current, XML_CURSOR_POS *cursorPos );
bool moveCursorDown( Device &context, XML_CURSOR_POS *cursorPos );
bool moveCursorRight( Device &context, XML_CURSOR_POS *cursorPos );
bool moveCursorRightWord( Device &context, XML_CURSOR_POS *cursorPos );
void moveCursorEnd( XML_CURSOR_POS *cursorPos );
gak::xml::Element *locateLastElement(
XML_CURSOR_POS *cursorPos
) const;
bool locatePrevLine(
Device &context,
XML_VIEWER_BOX *current, XML_CURSOR_POS *cursorPos,
int oldPosition
);
bool locatePrevChunk( XML_VIEWER_BOX *current, XML_CURSOR_POS *cursorPos );
bool moveCursorLeft( Device &context, XML_CURSOR_POS *cursorPos );
bool moveCursorLeftWord( Device &context, XML_CURSOR_POS *cursorPos );
void moveCursorStart( XML_CURSOR_POS *cursorPos );
bool moveCursorUp( Device &context, XML_CURSOR_POS *cursorPos );
gak::xml::XmlText *insertCharacter(
Device &context, XMLeditorChild *theWindow, XML_CURSOR_POS *cursorPos,
int c,
bool *doWrap
);
gak::xml::XmlText *deleteCharacter(
Device &context, XMLeditorChild *theWindow,
const XML_CURSOR_POS *cursorPos,
bool *doWrap
);
const XML_VIEWER_BOX *getParent() const
{
return m_parentBox;
}
int getItemNumber() const
{
return m_itemNumber;
}
#ifdef _DEBUG
void dump( FILE *fp, unsigned level )
{
unsigned newLevel = level+1;
for( unsigned i=0; i<level; i++ )
fputs( " ", fp );
if( m_theElement )
fprintf( fp, "%s\n", (const char *)m_theElement->getTag() );
else
fputs( "<NO ELEMENT>\n", fp );
for( unsigned i=0; i<level; i++ )
fputs( " ", fp );
fprintf( fp, "Num Lines: %d\n", (int)m_theContent.size() );
for( size_t i=0; i<m_theContent.size(); i++ )
m_theContent[i].dump( fp, newLevel );
for( unsigned i=0; i<level; i++ )
fputs( " ", fp );
fputs( "Subboxes:\n", fp );
for( size_t i=0; i<m_subBoxes.size(); i++ )
m_subBoxes[i]->dump( fp, newLevel );
for( unsigned i=0; i<level; i++ )
fputs( " ", fp );
fputs( "Childboxes:\n", fp );
for( size_t i=0; i<m_childElements.size(); i++ )
{
XML_VIEWER_ITEM &theItem = m_childElements[i];
XML_VIEWER_BOX *childBox = theItem.getViewerBox();
if( childBox )
childBox->dump( fp, newLevel );
}
}
#endif
};
class XML_TABLE_VIEWER_BOX : public XML_VIEWER_BOX
{
gak::ArrayOfInts m_styleWidths, m_columnWidths;
public:
XML_TABLE_VIEWER_BOX(int itemNumber) : XML_VIEWER_BOX(itemNumber) {}
virtual void buildBoxTree(
const Device &context, gak::xml::Element *theRoot, XML_VIEWER_BOX *container
);
virtual XML_VIEWER_BOX_PTR createBox(
gak::css::Display childDisplay,
int itemNumber
);
using XML_VIEWER_BOX::createBox;
void calcColumnWidth(
Device &context, int windowWidth, int windowHeight
);
virtual int calcSize(
Device &context,
int x, int y,
int maxWidth, int windowWidth, int windowHeight,
RectBorder *screen
);
void initColumn( int itemNumber )
{
m_columnWidths[itemNumber] = 0;
m_styleWidths[itemNumber] = 0;
}
int getColumnWidth( int itemNumber )
{
return m_columnWidths[itemNumber];
}
void setColumnWidth( int itemNumber, int width )
{
int &oldWidth = m_columnWidths[itemNumber];
if( oldWidth < width )
oldWidth = width;
}
void setStyleWidth( int itemNumber, int width )
{
int &oldWidth = m_styleWidths[itemNumber];
if( oldWidth < width )
oldWidth = width;
}
};
class XML_TABLE_GROUP_VIEWER_BOX : public XML_VIEWER_BOX
{
public:
XML_TABLE_GROUP_VIEWER_BOX(int itemNumber) : XML_VIEWER_BOX(itemNumber) {}
virtual void buildBoxTree(
const Device &context, gak::xml::Element *theRoot, XML_VIEWER_BOX *container
);
virtual XML_VIEWER_BOX_PTR createBox(
gak::css::Display childDisplay,
int itemNumber
);
using XML_VIEWER_BOX::createBox;
virtual int calcSize(
Device &context,
int x, int y,
int maxWidth, int windowWidth, int windowHeight,
RectBorder *screen
);
void calcColumnWidth(
Device &context, int windowWidth, int windowHeight
);
void initColumn( int itemNumber )
{
XML_TABLE_VIEWER_BOX *table = (XML_TABLE_VIEWER_BOX *)((XML_VIEWER_BOX*)m_parentBox);
table->initColumn( itemNumber );
}
int getColumnWidth( int itemNumber )
{
XML_TABLE_VIEWER_BOX *table = (XML_TABLE_VIEWER_BOX *)((XML_VIEWER_BOX*)m_parentBox);
return table->getColumnWidth( itemNumber );
}
void setColumnWidth( int itemNumber, int width )
{
XML_TABLE_VIEWER_BOX *table = (XML_TABLE_VIEWER_BOX *)((XML_VIEWER_BOX*)m_parentBox);
table->setColumnWidth( itemNumber, width );
}
void setStyleWidth( int itemNumber, int width )
{
XML_TABLE_VIEWER_BOX *table = (XML_TABLE_VIEWER_BOX *)((XML_VIEWER_BOX*)m_parentBox);
table->setStyleWidth( itemNumber, width );
}
};
class XML_TABLE_ROW_VIEWER_BOX : public XML_VIEWER_BOX
{
public:
XML_TABLE_ROW_VIEWER_BOX(int itemNumber) : XML_VIEWER_BOX(itemNumber) {}
virtual void buildBoxTree(
const Device &context, gak::xml::Element *theRoot, XML_VIEWER_BOX *container
);
void calcColumnWidth(
Device &context, int windowWidth, int windowHeight
);
virtual int calcSize(
Device &context,
int x, int y,
int maxWidth, int windowWidth, int windowHeight,
RectBorder *screen
);
virtual XML_VIEWER_BOX_PTR createBox(
gak::css::Display childDisplay,
int itemNumber
);
using XML_VIEWER_BOX::createBox;
void initColumn( int itemNumber )
{
XML_TABLE_GROUP_VIEWER_BOX *group = (XML_TABLE_GROUP_VIEWER_BOX *)((XML_VIEWER_BOX*)m_parentBox);
group->initColumn( itemNumber );
}
int getColumnWidth( int itemNumber )
{
XML_TABLE_GROUP_VIEWER_BOX *group = (XML_TABLE_GROUP_VIEWER_BOX *)((XML_VIEWER_BOX*)m_parentBox);
return group->getColumnWidth( itemNumber );
}
void setColumnWidth( int itemNumber, int width )
{
XML_TABLE_GROUP_VIEWER_BOX *group = (XML_TABLE_GROUP_VIEWER_BOX *)((XML_VIEWER_BOX*)m_parentBox);
group->setColumnWidth( itemNumber, width );
}
void setStyleWidth( int itemNumber, int width )
{
XML_TABLE_GROUP_VIEWER_BOX *group = (XML_TABLE_GROUP_VIEWER_BOX *)((XML_VIEWER_BOX*)m_parentBox);
group->setStyleWidth( itemNumber, width );
}
};
class XML_TABLE_CELL_VIEWER_BOX : public XML_VIEWER_BOX
{
public:
XML_TABLE_CELL_VIEWER_BOX(int itemNumber) : XML_VIEWER_BOX(itemNumber) {}
virtual void buildBoxTree(
const Device &context, gak::xml::Element *theRoot, XML_VIEWER_BOX *container
);
void initColumn()
{
XML_TABLE_ROW_VIEWER_BOX *row = (XML_TABLE_ROW_VIEWER_BOX *)((XML_VIEWER_BOX*)m_parentBox);
row->initColumn( m_itemNumber );
}
int getColumnWidth()
{
XML_TABLE_ROW_VIEWER_BOX *row = (XML_TABLE_ROW_VIEWER_BOX *)((XML_VIEWER_BOX*)m_parentBox);
return row->getColumnWidth( m_itemNumber );
}
void setColumnWidth( int width )
{
XML_TABLE_ROW_VIEWER_BOX *row = (XML_TABLE_ROW_VIEWER_BOX *)((XML_VIEWER_BOX*)m_parentBox);
row->setColumnWidth( m_itemNumber, width );
}
void setStyleWidth( int width )
{
XML_TABLE_ROW_VIEWER_BOX *row = (XML_TABLE_ROW_VIEWER_BOX *)((XML_VIEWER_BOX*)m_parentBox);
row->setStyleWidth( m_itemNumber, width );
}
virtual int calcSize(
Device &context,
int x, int y,
int maxWidth, int windowWidth, int windowHeight,
RectBorder *screen
);
};
} // namespace internal
class XMLeditorChild : public ChildWindow
{
private:
bool m_xmlFrames;
internal::XML_VIEWER_BOX_PTR m_theViewerBox;
int m_vertOffset, m_horizOffset;
Size m_size;
RectBorder m_boxSize;
internal::XML_CURSOR_POS m_cursorPos;
bool m_cursorVisible;
#ifdef _DEBUG
void dump()
{
STRING tmp = getenv( "TEMP" );
tmp += "\\temp.txt";
FILE *fp = fopen( tmp, "w" );
m_theViewerBox->dump( fp, 0 );
fclose( fp );
}
#endif
void enableCursor()
{
if( !hasTimer() )
{
m_cursorVisible = false;
setTimer( 500 );
}
focus();
}
void disableCursor( Device &context )
{
if( hasTimer() )
{
hideCursor(context);
m_cursorPos.clear();
removeTimer();
}
}
void hideCursor( Device &context )
{
if( m_cursorVisible )
drawCursor( context );
}
static void registerClass();
virtual STRING getWindowClassName() const;
public:
static const char className[];
private:
void drawCursor( Device &context );
virtual void handleTimer();
virtual ProcessStatus handleVertScroll( VertScrollCode scrollCode, int nPos, HWND scrollBar );
virtual ProcessStatus handleHorizScroll( HorizScrollCode scrollCode, int nPos, HWND );
virtual ProcessStatus handleRepaint( Device &hDC );
virtual ProcessStatus handleResize( const Size &newSize );
virtual ProcessStatus handleLeftButton( LeftButton leftButton, WPARAM modifier, const Point &position );
virtual void handleFocus();
virtual ProcessStatus handleKeyDown( int key );
virtual ProcessStatus handleCharacterInput( int c );
virtual void handleKillFocus();
public:
XMLeditorChild( BasicWindow *owner )
: ChildWindow( owner )
{
registerClass();
m_theViewerBox = nullptr;
m_xmlFrames = false;
m_cursorVisible = false;
m_vertOffset = m_horizOffset = 0;
}
void refresh();
void setDocument( gak::xml::Document *newDocument );
void showElement( gak::xml::Element *theElement );
void enableXmlFrames()
{
if( !m_xmlFrames )
{
m_xmlFrames = true;
invalidateWindow();
}
}
void disableXmlFrames()
{
if( m_xmlFrames )
{
m_xmlFrames = false;
invalidateWindow();
}
}
bool isXmlFrameEnabled() const
{
return m_xmlFrames;
}
int getVertOffset() const
{
return m_vertOffset;
}
int getHorizOffset() const
{
return m_horizOffset;
}