-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgridView.cpp
More file actions
1142 lines (989 loc) · 28 KB
/
gridView.cpp
File metadata and controls
1142 lines (989 loc) · 28 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: gridView.cpp
Description: A control displaying data in a grid
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.
*/
// --------------------------------------------------------------------- //
// ----- switches ------------------------------------------------------ //
// --------------------------------------------------------------------- //
// --------------------------------------------------------------------- //
// ----- includes ------------------------------------------------------ //
// --------------------------------------------------------------------- //
#include <WINLIB/gridView.h>
#include <WINLIB\DEVICE.H>
#include <WINLIB/RAW_DATA.H>
#include <WINLIB/messages.h>
// --------------------------------------------------------------------- //
// ----- imported datas ------------------------------------------------ //
// --------------------------------------------------------------------- //
// --------------------------------------------------------------------- //
// ----- module switches ----------------------------------------------- //
// --------------------------------------------------------------------- //
#ifdef __BORLANDC__
# pragma option -RT-
# pragma option -b
# pragma option -a4
# pragma option -pc
#endif
namespace winlib
{
using namespace gak;
// --------------------------------------------------------------------- //
// ----- constants ----------------------------------------------------- //
// --------------------------------------------------------------------- //
// --------------------------------------------------------------------- //
// ----- macros -------------------------------------------------------- //
// --------------------------------------------------------------------- //
// --------------------------------------------------------------------- //
// ----- type definitions ---------------------------------------------- //
// --------------------------------------------------------------------- //
// --------------------------------------------------------------------- //
// ----- class definitions --------------------------------------------- //
// --------------------------------------------------------------------- //
// --------------------------------------------------------------------- //
// ----- exported datas ------------------------------------------------ //
// --------------------------------------------------------------------- //
// --------------------------------------------------------------------- //
// ----- module static data -------------------------------------------- //
// --------------------------------------------------------------------- //
// --------------------------------------------------------------------- //
// ----- class static data --------------------------------------------- //
// --------------------------------------------------------------------- //
const char GridViewer::className[] = "GridViewer";
// --------------------------------------------------------------------- //
// ----- prototypes ---------------------------------------------------- //
// --------------------------------------------------------------------- //
// --------------------------------------------------------------------- //
// ----- module functions ---------------------------------------------- //
// --------------------------------------------------------------------- //
// --------------------------------------------------------------------- //
// ----- class inlines ------------------------------------------------- //
// --------------------------------------------------------------------- //
// --------------------------------------------------------------------- //
// ----- class constructors/destructors -------------------------------- //
// --------------------------------------------------------------------- //
// --------------------------------------------------------------------- //
// ----- class static functions ---------------------------------------- //
// --------------------------------------------------------------------- //
void GridViewer::registerClass()
{
static bool registered = false;
if( !registered )
{
WNDCLASS wc;
fillDefaultClass( &wc );
// wc.style |= CS_DBLCLKS;
wc.lpszClassName = className;
wc.hCursor = NULL;
registered = ChildWindow::registerClass( &wc );
}
}
// --------------------------------------------------------------------- //
// ----- class privates ------------------------------------------------ //
// --------------------------------------------------------------------- //
void GridViewer::calcDimensions( const Size &size )
{
assert( m_rowAttributes.size() == m_data.getNumRows() );
assert( m_colAttributes.size() == m_data.getNumCols() );
if( m_data.getNumRows() && m_data.getNumCols() )
{
double colWidth = m_colWidth ? m_colWidth : double(size.width)/double(m_data.getNumCols());
double rowHeight = getRowHeight();
double left = 0;
for(
gak::PODarray<ColAttribute>::iterator it = m_colAttributes.begin(), endIT = m_colAttributes.end();
it != endIT;
++it
)
{
it->left = unsigned(left+0.5);
if( it->width )
left += it->width;
else
left += colWidth;
it->right = unsigned(left+0.5);
}
m_totalWidth = int(left+0.5);
if( m_totalWidth > size.width )
{
showHorizScrollBar( 0, int(left-size.width) );
if( m_horizOffset > m_totalWidth - size.width )
m_horizOffset = m_totalWidth - size.width;
setHorizScrollPos( m_horizOffset );
}
else
{
m_horizOffset = 0;
hideHorizScrollBar();
}
double top = 0;
for(
gak::PODarray<RowAttribute>::iterator it = m_rowAttributes.begin(), endIT = m_rowAttributes.end();
it != endIT;
++it
)
{
it->top = unsigned(top+0.5);
if( it->height )
top += it->height;
else
top += rowHeight;
it->bottom = unsigned(top+0.5);
}
m_totalHeight = int(top+0.5);
if( m_totalHeight > size.height )
{
showVertScrollBar( 0, m_totalHeight-size.height );
if( m_vertOffset > m_totalHeight - size.height )
m_vertOffset = m_totalHeight - size.height;
setVertScrollPos( m_vertOffset );
}
else
{
m_vertOffset = 0;
hideVertScrollBar();
}
}
updateCaretPos();
}
RectBorder GridViewer::getCellVirtualPosition( size_t col, size_t row )
{
RectBorder rect;
const ColAttribute &colAttribute = m_colAttributes[col];
rect.left = colAttribute.left;
rect.right = colAttribute.right;
const RowAttribute &rowAttribute = m_rowAttributes[row];
rect.top = rowAttribute.top;
rect.bottom = rowAttribute.bottom;
return rect;
}
RectBorder GridViewer::getCellScreenPosition( size_t col, size_t row )
{
RectBorder rect = getCellVirtualPosition( col, row );
if( col >= m_fixedCols )
{
rect.left -= m_horizOffset;
rect.right -= m_horizOffset;
}
if( row >= m_fixedRows )
{
rect.top -= m_vertOffset;
rect.bottom -= m_vertOffset;
}
return rect;
}
void GridViewer::drawCell( Device &hDC, const RectBorder &rect, const TheCell &cellData, size_t offset )
{
doEnterFunction("GridViewer::drawCell");
RectBorder textRect = rect;
textRect.left += cellPadding;
textRect.top += cellPadding-1;
textRect.right -= cellPadding;
textRect.bottom -= cellPadding;
if( offset )
hDC.drawText( cellData.text+offset, cellData.text.strlen()-offset, textRect, DT_NOPREFIX|DT_LEFT|DT_TOP );
else
hDC.drawText( cellData.text, textRect, DT_NOPREFIX|DT_LEFT|DT_TOP );
if( &cellData == m_editCell && m_editPos != m_selPos )
{
Size size;
hDC.getTextExtent( cellData.text+offset, m_selPos-offset, &size );
if( m_editPos < m_selPos )
{
textRect.right = textRect.left+size.width;
textRect.left += m_caretOffsetPixel;
}
else
{
textRect.right = textRect.left + m_caretOffsetPixel;
textRect.left += size.width;
}
hDC.setROP2( R2_NOT );
hDC.getBrush().createSyscolor( scSELECTION );
hDC.getPen().setStyle( Pen::psNull );
hDC.rectangle( textRect );
hDC.setROP2( R2_COPYPEN );
}
}
void GridViewer::drawEditCell( Device &hDC, const RectBorder &rect )
{
assert( m_editCell );
hDC.getBrush().createSyscolor( scWINDOW_FACE );
hDC.getPen().setStyle( Pen::psSolid ).setWidth( 1 );
hDC.rectangle( rect.left, rect.top, rect.right, rect.bottom );
hideCaret();
drawCell( hDC, rect, *m_editCell, m_editOffset );
showCaret();
}
void GridViewer::updateCaretPos()
{
if( m_editCell )
{
int left = m_colAttributes[m_editCol].left+1;
if( m_editCol >= m_fixedCols )
left -= m_horizOffset;
int top = m_rowAttributes[m_editRow].top;
if( m_editRow >= m_fixedRows )
{
top -= m_vertOffset;
}
moveCaret( left+m_caretOffsetPixel, top );
}
}
void GridViewer::moveCursor( size_t newEditCol, size_t newEditRow )
{
assert( newEditCol < m_data.getNumCols() );
assert( newEditRow < m_data.getNumRows() );
if( !m_editCell || newEditRow != m_editRow || newEditCol != m_editCol )
{
if( m_editCell )
{
getParent()->postMessage(WM_GRID_ITEM_EXIT, getId(), MAKELPARAM(m_editCol, m_editRow) );
}
m_selPos = m_editPos = 0;
m_editOffset = 0;
m_caretOffsetPixel = 0;
m_editCell = &m_data( newEditCol, newEditRow );
m_editRow = newEditRow;
m_editCol = newEditCol;
if( m_editCell )
{
getParent()->postMessage(WM_GRID_ITEM_ENTER, getId(), MAKELPARAM(m_editCol, m_editRow) );
}
if( newEditCol >= m_fixedCols && newEditRow >= m_fixedRows )
{
Size size= getClientSize();
RectBorder rect = getCellScreenPosition( m_editCol, m_editRow );
int minLeft = m_colAttributes[m_fixedCols].left;
if( rect.left < minLeft )
{
m_horizOffset -= minLeft-rect.left;
setHorizScrollPos( m_horizOffset );
}
else if( rect.right > size.width )
{
int visibleWidth = math::min( rect.getWidth(), size.width-minLeft );
m_horizOffset = rect.left+m_horizOffset-size.width+visibleWidth;
setHorizScrollPos( m_horizOffset );
}
int minTop = m_rowAttributes[m_fixedRows].top;
if( rect.top < minTop )
{
m_vertOffset -= minTop-rect.top;
setVertScrollPos( m_vertOffset );
}
else if( rect.bottom > size.height )
{
int visibleHeight = math::min( rect.getHeight(), size.height-minTop );
m_vertOffset = rect.top+m_vertOffset-size.height+visibleHeight;
setVertScrollPos( m_vertOffset );
}
}
updateCaretPos();
invalidateWindow();
}
}
void GridViewer::moveCursorNextCell()
{
size_t newEditRow = m_editRow;
size_t newEditCol = m_editCol+1;
if( newEditCol >= m_data.getNumCols() )
{
if( getStyle() & gvCOL_CREATE )
setNumCols( newEditCol+1 );
else
{
newEditRow++;
newEditCol = m_fixedCols;
if( newEditRow >= m_data.getNumRows() )
{
if( getStyle() & gvROW_CREATE )
setNumRows( newEditRow+1 );
else
{
newEditRow = m_editRow;
newEditCol = m_editCol;
}
}
}
}
moveCursor( newEditCol, newEditRow );
}
void GridViewer::moveCursorPrevCell()
{
if( m_editCol > m_fixedCols )
{
moveCursor( m_editCol-1, m_editRow );
}
else if( m_editRow > m_fixedRows )
{
moveCursor( m_data.getNumCols()-1, m_editRow-1 );
}
}
bool GridViewer::moveCursorLeftWord( Device &hDC, bool includeSelection )
{
assert( m_editCell );
size_t newEditPos = m_editPos;
while( newEditPos )
{
if( !isspace( m_editCell->text[--newEditPos] ) )
/*v*/ break;
}
while( newEditPos )
{
if( isspace( m_editCell->text[--newEditPos] ) )
/*v*/ break;
}
if( isspace( m_editCell->text[newEditPos] ) )
newEditPos++;
return moveCursor( hDC, newEditPos, includeSelection );
}
bool GridViewer::moveCursorRightWord( Device &hDC, bool includeSelection )
{
assert( m_editCell );
size_t len = m_editCell->text.strlen();
size_t newEditPos = m_editPos;
while( newEditPos < len )
{
if( isspace( m_editCell->text[newEditPos] ) )
/*v*/ break;
newEditPos++;
}
while( newEditPos < len )
{
if( !isspace( m_editCell->text[newEditPos] ) )
/*v*/ break;
newEditPos++;
}
return moveCursor( hDC, newEditPos, includeSelection );
}
bool GridViewer::moveCursor( Device &hDC, size_t newPosition, bool includeSelection )
{
assert( m_editCell );
bool scrolled = m_editPos != m_selPos;
if( newPosition <= m_editOffset )
{
scrolled = scrolled || newPosition < m_editOffset;
m_editOffset = newPosition;
m_caretOffsetPixel = 0;
}
else
{
if( newPosition > m_editCell->text.strlen() )
newPosition = m_editCell->text.strlen();
Size size;
hDC.getTextExtent( m_editCell->text, m_editOffset, newPosition-m_editOffset, &size );
m_caretOffsetPixel = size.width;
int width = getVisibleTextWidth( m_editCol );
while( width < m_caretOffsetPixel )
{
hDC.getTextExtent( m_editCell->text[m_editOffset++], &size );
m_caretOffsetPixel -= size.width;
scrolled = true;
}
}
m_editPos = newPosition;
if( includeSelection )
m_selPos = newPosition;
else
scrolled = true;
updateCaretPos();
return scrolled;
}
// --------------------------------------------------------------------- //
// ----- class protected ----------------------------------------------- //
// --------------------------------------------------------------------- //
// --------------------------------------------------------------------- //
// ----- class virtuals ------------------------------------------------ //
// --------------------------------------------------------------------- //
STRING GridViewer::getWindowClassName() const
{
return className;
}
ProcessStatus GridViewer::handleVertScroll( VertScrollCode scrollCode, int nPos, HWND /*scrollBar*/ )
{
int rowHeight = getRowHeight();
Size size = getClientSize();
switch( scrollCode )
{
case vscTOP:
nPos = 0;
break;
case vscLINE_UP:
nPos = m_vertOffset - rowHeight;
break;
case vscPAGE_UP:
nPos = m_vertOffset - size.height;
break;
case vscLINE_DOWN:
nPos = m_vertOffset + rowHeight;
break;
case vscPAGE_DOWN:
nPos = m_vertOffset + size.height;
break;
case vscBOTTOM:
nPos = m_totalHeight - size.height;
break;
case vscTHUMB_POSITION:
case vscTHUMB_TRACK:
break;
default:
/***/ return psDO_DEFAULT;
}
int maxNpos;
if( nPos < 0 )
nPos = 0;
else if( nPos > (maxNpos = m_totalHeight - size.height) )
nPos = maxNpos;
setVertScrollPos( nPos );
m_vertOffset = nPos;
updateCaretPos();
invalidateWindow();
return psPROCESSED;
}
ProcessStatus GridViewer::handleHorizScroll( HorizScrollCode scrollCode, int nPos, HWND )
{
int rowHeight = getRowHeight();
Size size = getClientSize();
switch( scrollCode )
{
case hscLEFT:
nPos = 0;
break;
case hscLINE_LEFT:
nPos = m_horizOffset - rowHeight;
break;
case hscPAGE_LEFT:
nPos = m_horizOffset - size.width;
break;
case hscLINE_RIGHT:
nPos = m_horizOffset + rowHeight;
break;
case hscPAGE_RIGHT:
nPos = m_horizOffset + size.width;
break;
case hscRIGHT:
nPos = m_totalWidth - size.width;
break;
case hscTHUMB_POSITION:
case hscTHUMB_TRACK:
break;
default:
/***/ return psDO_DEFAULT;
}
int maxNpos;
if( nPos < 0 )
nPos = 0;
else if( nPos > (maxNpos = m_totalWidth - size.width) )
nPos = maxNpos;
setHorizScrollPos( nPos );
m_horizOffset = nPos;
updateCaretPos();
invalidateWindow();
return psPROCESSED;
}
ProcessStatus GridViewer::handleResize( const Size &newSize )
{
calcDimensions( newSize );
return psDO_DEFAULT;
}
ProcessStatus GridViewer::handleRepaint( Device &hDC )
{
doEnterFunction("GridViewer::handleRepaint");
assert( m_rowAttributes.size() == m_data.getNumRows() );
assert( m_colAttributes.size() == m_data.getNumCols() );
Size size = getSize();
int fixedHeight = m_fixedRows ? m_rowAttributes[m_fixedRows-1].bottom : 0;
int fixedWidth = m_fixedCols ? m_colAttributes[m_fixedCols-1].right : 0;
if( getStyle() & gvGRID )
{
doEnterFunction("GridViewer::drawGrid");
hDC.getPen().setStyle( Pen::psDot ).setWidth( 1 );
unsigned col=0;
for(
gak::PODarray<ColAttribute>::iterator it = m_colAttributes.begin(), endIT = m_colAttributes.end();
it != endIT;
++it, ++col
)
{
int pos = it->left;
if( col >= m_fixedCols )
pos -= m_horizOffset;
if( pos >= size.width )
break;
if( pos > 0 )
{
hDC.verticalLine( pos, 0, size.height );
}
}
unsigned row=0;
for(
gak::PODarray<RowAttribute>::iterator it = m_rowAttributes.begin(), endIT = m_rowAttributes.end();
it != endIT;
++it, ++row
)
{
int pos = it->top;
if( row >= m_fixedRows )
pos -= m_vertOffset;
if( pos >= size.height )
break;
if( pos > 0 )
hDC.horizontalLine( 0, size.width, pos );
}
}
if( m_data.getNumRows() && m_data.getNumCols() )
{
doEnterFunction("showText");
size_t col=0;
hDC.selectFont( getFont() );
hDC.clrBackgroundColor();
for(
gak::PODarray<ColAttribute>::iterator it = m_colAttributes.begin(), endIT = m_colAttributes.end();
it != endIT;
++it, ++col
)
{
RectBorder rect;
rect.left = it->left;
rect.right = it->right;
if( col >= m_fixedCols )
{
rect.left -= m_horizOffset;
rect.right -= m_horizOffset;
}
if( rect.left > size.width )
/*v*/ break;
if( rect.right > 0 )
{
size_t row=0;
for(
gak::PODarray<RowAttribute>::iterator it = m_rowAttributes.begin(), endIT = m_rowAttributes.end();
it != endIT;
++it, ++row
)
{
rect.top = it->top;
rect.bottom = it->bottom;
if( m_vertOffset && row >= m_fixedRows )
{
rect.top -= m_vertOffset;
rect.bottom -= m_vertOffset;
}
if( rect.top > size.height )
/*v*/ break;
if( rect.bottom > 0 )
{
const TheCell &cellData = getCellData( col, row );
if( row < m_fixedRows || col < m_fixedCols )
{
doEnterFunction("prepare Fixed Cells");
if( row < m_fixedRows && col < m_fixedCols )
hDC.removeClipping();
else if( row < m_fixedRows )
hDC.setClipping( fixedWidth, 0, size.width, size.height );
else if( col < m_fixedCols )
hDC.setClipping( 0, fixedHeight, size.width, size.height );
hDC.getBrush().createSyscolor( scDIALOG_FACE );
hDC.getPen().setStyle( Pen::psNull );
hDC.rectangle( rect.left, rect.top, rect.right, rect.bottom );
}
else if( cellData.attribute.backgroundColor > 0 )
{
hDC.getBrush().create( cellData.attribute.backgroundColor );
hDC.getPen().setStyle( Pen::psNull );
hDC.rectangle( rect.left, rect.top, rect.right, rect.bottom );
}
else
{
hDC.setClipping( fixedWidth, fixedHeight, size.width, size.height );
}
if( m_editCell == &cellData )
{
drawEditCell( hDC, rect );
}
else if( !cellData.text.isEmpty() )
{
drawCell( hDC, rect, cellData, 0 );
}
}
}
}
}
}
return psPROCESSED;
}
ProcessStatus GridViewer::handleMouseMove( WPARAM /*modifier*/, const Point &position )
{
MouseState newState = m_mouseState;
unsigned long style = getStyle();
if( (m_mouseState == msNORMAL || m_mouseState == msSTART_COL_SIZER) && (style & gvCOL_SIZABLE) )
{
newState = msNORMAL;
size_t col = 0;
for(
gak::PODarray<ColAttribute>::iterator it = m_colAttributes.begin(), endIT = m_colAttributes.end();
it != endIT;
++it, ++col
)
{
int right = it->right;
if( col >= m_fixedCols )
right -= m_horizOffset;
if( abs(int(right - position.x)) <= mouseSizeWidth )
{
newState = msSTART_COL_SIZER;
m_sizerCol = col;
break;
}
}
}
else if( m_mouseState == msDO_COL_SIZER )
{
int left = m_colAttributes[m_sizerCol].left;
if( m_sizerCol >= m_fixedCols )
left -= m_horizOffset;
int newWidth = position.x - left;
if( newWidth > mouseSizeWidth*2 )
{
setColWidth( m_sizerCol, newWidth );
invalidateWindow();
}
}
else if( !(style & gvCOL_SIZABLE) )
{
SetCursor( LoadCursor( NULL, IDC_ARROW ) );
}
if( newState != m_mouseState )
{
m_mouseState = newState;
if( m_mouseState == msSTART_COL_SIZER || m_mouseState == msDO_COL_SIZER )
SetCursor( LoadCursor( NULL, IDC_SIZEWE ) );
else
SetCursor( LoadCursor( NULL, IDC_ARROW ) );
}
return psPROCESSED;
}
ProcessStatus GridViewer::handleLeftButton( LeftButton leftButton, WPARAM /*modifier*/, const Point &position )
{
unsigned long style = getStyle();
if( leftButton == lbDOWN && m_mouseState == msSTART_COL_SIZER )
{
m_mouseState = msDO_COL_SIZER;
captureMouse();
return psPROCESSED;
}
else if( leftButton == lbDOWN && m_mouseState == msNORMAL && (style & (gvEDITABLE|gvCAPTION_EDITABLE)) )
{
TheCell *lastEditCell = m_editCell;
size_t lastCol = m_editCol;
size_t lastRow = m_editRow;
m_editCell = NULL;
int caretLeft;
size_t col = 0;
for(
gak::PODarray<ColAttribute>::iterator it = m_colAttributes.begin(), endIT = m_colAttributes.end();
it != endIT;
++it, ++col
)
{
int left = it->left;
int right = it->right;
if( m_horizOffset && col >= m_fixedCols )
{
left -= m_horizOffset;
right -= m_horizOffset;
}
if( left < position.x && position.x < right )
{
caretLeft = left;
/*v*/ break;
}
}
if( col < m_data.getNumCols() )
{
size_t row=0;
for(
gak::PODarray<RowAttribute>::iterator it = m_rowAttributes.begin(), endIT = m_rowAttributes.end();
it != endIT;
++it, ++row
)
{
bool isCaption = (col < m_fixedCols || row < m_fixedRows);
int top = it->top;
int bottom = it->bottom;
if( m_vertOffset && row >= m_fixedRows )
{
top -= m_vertOffset;
bottom -= m_vertOffset;
}
if( top < position.y && position.y < bottom )
{
if( isCaption && !(style&gvCAPTION_EDITABLE) )
break;
if( !isCaption && !(style&gvEDITABLE) )
break;
focus();
createCaret( caretLeft+1, top, bottom-top );
m_editCol = col;
m_editRow = row;
m_editCell = &getCellData( col, row );
m_selPos = m_editPos = 0;
m_editOffset = 0;
m_caretOffsetPixel = 0;
/*v*/ break;
}
}
}
if( lastEditCell != m_editCell )
{
if( lastEditCell )
{
getParent()->postMessage(WM_GRID_ITEM_EXIT, getId(), MAKELPARAM(lastCol, lastRow) );
}
if( m_editCell )
{
getParent()->postMessage(WM_GRID_ITEM_ENTER, getId(), MAKELPARAM(m_editCol, m_editRow) );
}
else
{
destroyCaret();
}
invalidateWindow();
}
}
else if( leftButton == lbUP && m_mouseState == msDO_COL_SIZER )
{
m_mouseState = msSTART_COL_SIZER;
releaseMouse();
return psPROCESSED;
}
return psDO_DEFAULT;
}
ProcessStatus GridViewer::handleKeyDown( int key )
{
if( m_editCell )
{
DrawDevice hDC( this );
switch( key )
{
case VK_HOME:
if( moveCursor( hDC, 0, !isShiftKey() ) )
drawEditCell( hDC );
break;
case VK_END:
if( moveCursor( hDC, m_editCell->text.strlen(), !isShiftKey() ) )
drawEditCell( hDC );
break;
case VK_RIGHT:
if( (isControlKey() ? moveCursorRightWord( hDC, !isShiftKey() ) : moveCursorRight( hDC, !isShiftKey() )) )
drawEditCell( hDC );
break;
case VK_LEFT:
if( (isControlKey() ? moveCursorLeftWord( hDC, !isShiftKey() ) : moveCursorLeft( hDC, !isShiftKey() )) )
drawEditCell( hDC );
break;
case VK_INSERT:
if( isControlKey() )
copy();
else if( isShiftKey() )
paste();
break;
case VK_DELETE:
if( m_editPos < m_editCell->text.strlen() || m_selPos < m_editCell->text.strlen() )
{
if( m_editPos != m_selPos )
{
if( isShiftKey() )
copy();
deleteSelection();
}
else
m_editCell->text.delChar( m_editPos );
drawEditCell( hDC );
notifyParent();
}
break;
case VK_BACK:
if( m_editPos || m_selPos )
{
if( m_editPos != m_selPos )
deleteSelection();
else
{
moveCursorLeft( hDC, true );
m_editCell->text.delChar( m_editPos );
}
drawEditCell( hDC );
notifyParent();
}
break;
case VK_TAB:
if( isShiftKey() )
moveCursorPrevCell();
else
moveCursorNextCell();
break;
case VK_RETURN:
{
size_t newEditRow = m_editRow+1;
if( newEditRow >= m_data.getNumRows() )
{
if( getStyle() & gvROW_CREATE )
setNumRows( newEditRow+1 );
else
{
newEditRow = m_editRow;
}
}
moveCursor( m_editCol, newEditRow );
break;
}
default:
/***/ return psDO_DEFAULT;
}
/***/ return psPROCESSED;
}
return psDO_DEFAULT;
}