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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifdef SC_DLLIMPLEMENTATION
#undef SC_DLLIMPLEMENTATION
#endif
#include <comphelper/string.hxx>
#include <vcl/svapp.hxx>
#include <svl/aeitem.hxx>
#include <svl/stritem.hxx>
#include <svl/eitem.hxx>
#include <svl/intitem.hxx>
#include <basic/sbmeth.hxx>
#include <basic/sbstar.hxx>
#include <basic/sbmod.hxx>
#include <sfx2/app.hxx>
#include "scresid.hxx"
#include "sc.hrc"
#include "stringutil.hxx"
#include "validat.hxx"
#include "validate.hrc"
#include "validate.hxx"
#include "compiler.hxx"
#include "formula/opcode.hxx"
// cell range picker
#include "tabvwsh.hxx"
#include <sfx2/viewfrm.hxx>
#include <sfx2/childwin.hxx>
#include "reffact.hxx"
// ============================================================================
static sal_uInt16 pValueRanges[] =
{
FID_VALID_MODE, FID_VALID_ERRTEXT,
FID_VALID_LISTTYPE, FID_VALID_LISTTYPE,
0
};
// ============================================================================
ScValidationDlg::ScValidationDlg(Window* pParent, const SfxItemSet* pArgSet,
ScTabViewShell *pTabViewSh, SfxBindings *pB /*= NULL*/)
: ScValidationDlgBase(pParent ? pParent : SFX_APP()->GetTopWindow(),
"ValidationDialog", "modules/scalc/ui/validationdialog.ui", pArgSet, pB)
, m_pTabVwSh(pTabViewSh)
, m_nValuePageId(0)
, m_bOwnRefHdlr(false)
, m_bRefInputting(false)
{
m_nValuePageId = AddTabPage("criteria", ScTPValidationValue::Create, 0);
AddTabPage("inputhelp", ScTPValidationHelp::Create, 0);
AddTabPage("erroralert", ScTPValidationError::Create, 0);
get(m_pHBox, "refinputbox");
}
void ScTPValidationValue::SetReferenceHdl( const ScRange&rRange , ScDocument* pDoc )
{
if ( rRange.aStart != rRange.aEnd )
if ( ScValidationDlg *pValidationDlg = GetValidationDlg() )
if( m_pRefEdit )
pValidationDlg->RefInputStart( m_pRefEdit );
if ( m_pRefEdit )
{
OUString aStr(rRange.Format(SCR_ABS_3D, pDoc));
m_pRefEdit->SetRefString( aStr );
}
}
void ScTPValidationValue:: SetActiveHdl()
{
if ( m_pRefEdit ) m_pRefEdit->GrabFocus();
if ( ScValidationDlg *pValidationDlg = GetValidationDlg() )
if( m_pRefEdit )
{
pValidationDlg->RefInputDone();
}
}
void ScTPValidationValue::RefInputStartPreHdl( formula::RefEdit* pEdit, formula::RefButton* pButton )
{
if ( ScValidationDlg *pValidationDlg = GetValidationDlg() )
{
Window *pNewParent = pValidationDlg->get_refinput_shrink_parent();
if( pEdit == m_pRefEdit && m_pRefEdit->GetParent() != pNewParent )
{
maRefEditPos = m_pRefEdit->GetPosPixel();
maRefEditSize = m_pRefEdit->GetSizePixel();
m_pRefEdit->SetParent(pNewParent);
}
if( pButton == &m_btnRef && m_btnRef.GetParent() != pNewParent )
{
maBtnRefPos = m_btnRef.GetPosPixel();
maBtnRefSize = m_btnRef.GetSizePixel();
m_btnRef.SetParent(pNewParent);
}
pNewParent->Show();
}
}
void ScTPValidationValue::RefInputDonePostHdl()
{
if( m_pRefEdit && m_pRefEdit->GetParent()!= this )
{
m_pRefEdit->SetParent( this );
m_pRefEdit->SetPosSizePixel( maRefEditPos, maRefEditSize );
m_btnRef.SetParent( m_pRefEdit ); //if Edit SetParent but button not, the tab order will be incorrect, need button to setparent to anthor window and restore parent later in order to restore the tab order
}
if( m_btnRef.GetParent()!=this )
{
m_btnRef.SetParent( this );
m_btnRef.SetPosSizePixel( maBtnRefPos, maBtnRefSize );
}
if ( ScValidationDlg *pValidationDlg = GetValidationDlg() )
pValidationDlg->get_refinput_shrink_parent()->Hide();
if( m_pRefEdit && !m_pRefEdit->HasFocus() )
m_pRefEdit->GrabFocus();
}
bool ScValidationDlg::Close()
{
if( m_bOwnRefHdlr )
{
if (SfxTabPage* pPage = GetTabPage(m_nValuePageId))
static_cast<ScTPValidationValue*>(pPage)->RemoveRefDlg();
}
return ScValidationDlgBase::Close();
}
ScValidationDlg::~ScValidationDlg()
{
if( m_bOwnRefHdlr )
RemoveRefDlg( false );
}
// ============================================================================
namespace {
/** Converts the passed ScValidationMode to the position in the list box. */
sal_uInt16 lclGetPosFromValMode( ScValidationMode eValMode )
{
sal_uInt16 nLbPos = SC_VALIDDLG_ALLOW_ANY;
switch( eValMode )
{
case SC_VALID_ANY: nLbPos = SC_VALIDDLG_ALLOW_ANY; break;
case SC_VALID_WHOLE: nLbPos = SC_VALIDDLG_ALLOW_WHOLE; break;
case SC_VALID_DECIMAL: nLbPos = SC_VALIDDLG_ALLOW_DECIMAL; break;
case SC_VALID_DATE: nLbPos = SC_VALIDDLG_ALLOW_DATE; break;
case SC_VALID_TIME: nLbPos = SC_VALIDDLG_ALLOW_TIME; break;
case SC_VALID_TEXTLEN: nLbPos = SC_VALIDDLG_ALLOW_TEXTLEN; break;
case SC_VALID_LIST: nLbPos = SC_VALIDDLG_ALLOW_RANGE; break;
case SC_VALID_CUSTOM: nLbPos = SC_VALIDDLG_ALLOW_ANY; break; // not supported
default: OSL_FAIL( "lclGetPosFromValMode - unknown validity mode" );
}
return nLbPos;
}
/** Converts the passed list box position to an ScValidationMode. */
ScValidationMode lclGetValModeFromPos( sal_uInt16 nLbPos )
{
ScValidationMode eValMode = SC_VALID_ANY;
switch( nLbPos )
{
case SC_VALIDDLG_ALLOW_ANY: eValMode = SC_VALID_ANY; break;
case SC_VALIDDLG_ALLOW_WHOLE: eValMode = SC_VALID_WHOLE; break;
case SC_VALIDDLG_ALLOW_DECIMAL: eValMode = SC_VALID_DECIMAL; break;
case SC_VALIDDLG_ALLOW_DATE: eValMode = SC_VALID_DATE; break;
case SC_VALIDDLG_ALLOW_TIME: eValMode = SC_VALID_TIME; break;
case SC_VALIDDLG_ALLOW_RANGE: eValMode = SC_VALID_LIST; break;
case SC_VALIDDLG_ALLOW_LIST: eValMode = SC_VALID_LIST; break;
case SC_VALIDDLG_ALLOW_TEXTLEN: eValMode = SC_VALID_TEXTLEN; break;
default: OSL_FAIL( "lclGetValModeFromPos - invalid list box position" );
}
return eValMode;
}
/** Converts the passed ScConditionMode to the position in the list box. */
sal_uInt16 lclGetPosFromCondMode( ScConditionMode eCondMode )
{
sal_uInt16 nLbPos = SC_VALIDDLG_DATA_EQUAL;
switch( eCondMode )
{
case SC_COND_NONE: // may occur in old XML files after Excel import
case SC_COND_EQUAL: nLbPos = SC_VALIDDLG_DATA_EQUAL; break;
case SC_COND_LESS: nLbPos = SC_VALIDDLG_DATA_LESS; break;
case SC_COND_GREATER: nLbPos = SC_VALIDDLG_DATA_GREATER; break;
case SC_COND_EQLESS: nLbPos = SC_VALIDDLG_DATA_EQLESS; break;
case SC_COND_EQGREATER: nLbPos = SC_VALIDDLG_DATA_EQGREATER; break;
case SC_COND_NOTEQUAL: nLbPos = SC_VALIDDLG_DATA_NOTEQUAL; break;
case SC_COND_BETWEEN: nLbPos = SC_VALIDDLG_DATA_VALIDRANGE; break;
case SC_COND_NOTBETWEEN: nLbPos = SC_VALIDDLG_DATA_INVALIDRANGE; break;
default: OSL_FAIL( "lclGetPosFromCondMode - unknown condition mode" );
}
return nLbPos;
}
/** Converts the passed list box position to an ScConditionMode. */
ScConditionMode lclGetCondModeFromPos( sal_uInt16 nLbPos )
{
ScConditionMode eCondMode = SC_COND_EQUAL;
switch( nLbPos )
{
case SC_VALIDDLG_DATA_EQUAL: eCondMode = SC_COND_EQUAL; break;
case SC_VALIDDLG_DATA_LESS: eCondMode = SC_COND_LESS; break;
case SC_VALIDDLG_DATA_GREATER: eCondMode = SC_COND_GREATER; break;
case SC_VALIDDLG_DATA_EQLESS: eCondMode = SC_COND_EQLESS; break;
case SC_VALIDDLG_DATA_EQGREATER: eCondMode = SC_COND_EQGREATER; break;
case SC_VALIDDLG_DATA_NOTEQUAL: eCondMode = SC_COND_NOTEQUAL; break;
case SC_VALIDDLG_DATA_VALIDRANGE: eCondMode = SC_COND_BETWEEN; break;
case SC_VALIDDLG_DATA_INVALIDRANGE: eCondMode = SC_COND_NOTBETWEEN; break;
default: OSL_FAIL( "lclGetCondModeFromPos - invalid list box position" );
}
return eCondMode;
}
/** Converts line feed separated string to a formula with strings separated by semicolons.
@descr Keeps all empty strings.
Example: abc\ndef\n\nghi -> "abc";"def";"";"ghi".
@param rFmlaStr (out-param) The converted formula string. */
void lclGetFormulaFromStringList( OUString& rFmlaStr, const OUString& rStringList, sal_Unicode cFmlaSep )
{
rFmlaStr = "";
sal_Int32 nTokenCnt = comphelper::string::getTokenCount(rStringList, '\n');
for( sal_Int32 nToken = 0, nStringIx = 0; nToken < (sal_Int32) nTokenCnt; ++nToken )
{
OUString aToken( rStringList.getToken( 0, '\n', nStringIx ) );
ScGlobal::AddQuotes( aToken, '"' );
rFmlaStr = ScGlobal::addToken(rFmlaStr, aToken, cFmlaSep);
}
if( rFmlaStr.isEmpty() )
rFmlaStr = "\"\"";
}
/** Converts formula with strings separated by semicolons to line feed separated string.
@descr Keeps all empty strings. Ignores all empty tokens (multiple semicolons).
Example: "abc";;;"def";"";"ghi" -> abc\ndef\n\nghi.
@param rStringList (out-param) The converted line feed separated string list.
@return true = Conversion successful. */
bool lclGetStringListFromFormula( OUString& rStringList, const OUString& rFmlaStr, sal_Unicode cFmlaSep )
{
OUString aQuotes( "\"\"" );
sal_Int32 nTokenCnt = ScStringUtil::GetQuotedTokenCount(rFmlaStr, aQuotes, cFmlaSep );
rStringList="";
bool bIsStringList = (nTokenCnt > 0);
bool bTokenAdded = false;
for( sal_Int32 nToken = 0, nStringIx = 0; bIsStringList && (nToken < nTokenCnt); ++nToken )
{
OUString aToken( ScStringUtil::GetQuotedToken(rFmlaStr, 0, aQuotes, cFmlaSep, nStringIx ) );
aToken = comphelper::string::strip(aToken, ' ');
if( !aToken.isEmpty() ) // ignore empty tokens, i.e. "a";;"b"
{
bIsStringList = ScGlobal::IsQuoted( aToken, '"' );
if( bIsStringList )
{
ScGlobal::EraseQuotes( aToken, '"' );
rStringList = ScGlobal::addToken(rStringList, aToken, '\n', 1, bTokenAdded);
bTokenAdded = true;
}
}
}
return bIsStringList;
}
} // namespace
ScTPValidationValue::ScTPValidationValue( Window* pParent, const SfxItemSet& rArgSet ) :
SfxTabPage( pParent, ScResId( TP_VALIDATION_VALUES ), rArgSet ),
maFtAllow ( this, ScResId( FT_ALLOW ) ),
maLbAllow ( this, ScResId( LB_ALLOW ) ),
maCbAllow ( this, ScResId( TSB_ALLOW_BLANKS ) ),
maCbShow ( this, ScResId( CB_SHOWLIST ) ),
maCbSort ( this, ScResId( CB_SORTLIST ) ),
maFtValue ( this, ScResId( FT_VALUE ) ),
maLbValue ( this, ScResId( LB_VALUE ) ),
maFtMin ( this, ScResId( FT_MIN ) ),
maEdMin ( this, NULL, &maFtMin, ScResId( EDT_MIN ) ),
maEdList ( this, ScResId( EDT_LIST ) ),
maFtMax ( this, ScResId( FT_MAX ) ),
maEdMax ( this, NULL, &maFtMax, ScResId( EDT_MAX ) ),
maFtHint ( this, ScResId( FT_SOURCEHINT ) ),
maStrMin ( ScResId( SCSTR_VALID_MINIMUM ) ),
maStrMax ( ScResId( SCSTR_VALID_MAXIMUM ) ),
maStrValue( ScResId( SCSTR_VALID_VALUE ) ),
maStrRange( ScResId( SCSTR_VALID_RANGE ) ),
maStrList ( ScResId( SCSTR_VALID_LIST ) ),
m_btnRef( this, ScResId( RB_VALIDITY_REF ) )
{
Init();
FreeResource();
// list separator in formulas
OUString aListSep = ::ScCompiler::GetNativeSymbol( ocSep );
OSL_ENSURE( aListSep.getLength() == 1, "ScTPValidationValue::ScTPValidationValue - list separator error" );
mcFmlaSep = aListSep.getLength() ? aListSep[0] : ';';
m_btnRef.Hide(); // cell range picker
}
ScTPValidationValue::~ScTPValidationValue()
{
}
void ScTPValidationValue::Init()
{
maLbAllow.SetSelectHdl( LINK( this, ScTPValidationValue, SelectHdl ) );
maLbValue.SetSelectHdl( LINK( this, ScTPValidationValue, SelectHdl ) );
maCbShow.SetClickHdl( LINK( this, ScTPValidationValue, CheckHdl ) );
// cell range picker
maEdMin.SetGetFocusHdl( LINK( this, ScTPValidationValue, EditSetFocusHdl ) );
maEdMin.SetLoseFocusHdl( LINK( this, ScTPValidationValue, KillFocusHdl ) );
maEdMax.SetGetFocusHdl( LINK( this, ScTPValidationValue, EditSetFocusHdl ) );
m_btnRef.SetLoseFocusHdl( LINK( this, ScTPValidationValue, KillFocusHdl ) );
maEdMax.SetLoseFocusHdl( LINK( this, ScTPValidationValue, KillFocusHdl ) );
maLbAllow.SelectEntryPos( SC_VALIDDLG_ALLOW_ANY );
maLbValue.SelectEntryPos( SC_VALIDDLG_DATA_EQUAL );
SelectHdl( NULL );
CheckHdl( NULL );
}
SfxTabPage* ScTPValidationValue::Create( Window* pParent, const SfxItemSet& rArgSet )
{
return( new ScTPValidationValue( pParent, rArgSet ) );
}
sal_uInt16* ScTPValidationValue::GetRanges()
{
return pValueRanges;
}
void ScTPValidationValue::Reset( const SfxItemSet& rArgSet )
{
const SfxPoolItem* pItem;
sal_uInt16 nLbPos = SC_VALIDDLG_ALLOW_ANY;
if( rArgSet.GetItemState( FID_VALID_MODE, true, &pItem ) == SFX_ITEM_SET )
nLbPos = lclGetPosFromValMode( static_cast< ScValidationMode >(
static_cast< const SfxAllEnumItem* >( pItem )->GetValue() ) );
maLbAllow.SelectEntryPos( nLbPos );
nLbPos = SC_VALIDDLG_DATA_EQUAL;
if( rArgSet.GetItemState( FID_VALID_CONDMODE, true, &pItem ) == SFX_ITEM_SET )
nLbPos = lclGetPosFromCondMode( static_cast< ScConditionMode >(
static_cast< const SfxAllEnumItem* >( pItem )->GetValue() ) );
maLbValue.SelectEntryPos( nLbPos );
// *** check boxes ***
sal_Bool bCheck = sal_True;
if( rArgSet.GetItemState( FID_VALID_BLANK, true, &pItem ) == SFX_ITEM_SET )
bCheck = static_cast< const SfxBoolItem* >( pItem )->GetValue();
maCbAllow.Check( bCheck );
sal_Int32 nListType = ValidListType::UNSORTED;
if( rArgSet.GetItemState( FID_VALID_LISTTYPE, true, &pItem ) == SFX_ITEM_SET )
nListType = static_cast< const SfxInt16Item* >( pItem )->GetValue();
maCbShow.Check( nListType != ValidListType::INVISIBLE );
maCbSort.Check( nListType == ValidListType::SORTEDASCENDING );
// *** formulas ***
OUString aFmlaStr;
if ( rArgSet.GetItemState( FID_VALID_VALUE1, true, &pItem ) == SFX_ITEM_SET )
aFmlaStr = static_cast< const SfxStringItem* >( pItem )->GetValue();
SetFirstFormula( aFmlaStr );
aFmlaStr= "";
if ( rArgSet.GetItemState( FID_VALID_VALUE2, true, &pItem ) == SFX_ITEM_SET )
aFmlaStr = static_cast< const SfxStringItem* >( pItem )->GetValue();
SetSecondFormula( aFmlaStr );
SelectHdl( NULL );
CheckHdl( NULL );
}
sal_Bool ScTPValidationValue::FillItemSet( SfxItemSet& rArgSet )
{
sal_Int16 nListType = maCbShow.IsChecked() ?
(maCbSort.IsChecked() ? ValidListType::SORTEDASCENDING : ValidListType::UNSORTED) :
ValidListType::INVISIBLE;
rArgSet.Put( SfxAllEnumItem( FID_VALID_MODE, sal::static_int_cast<sal_uInt16>(
lclGetValModeFromPos( maLbAllow.GetSelectEntryPos() ) ) ) );
rArgSet.Put( SfxAllEnumItem( FID_VALID_CONDMODE, sal::static_int_cast<sal_uInt16>(
lclGetCondModeFromPos( maLbValue.GetSelectEntryPos() ) ) ) );
rArgSet.Put( SfxStringItem( FID_VALID_VALUE1, GetFirstFormula() ) );
rArgSet.Put( SfxStringItem( FID_VALID_VALUE2, GetSecondFormula() ) );
rArgSet.Put( SfxBoolItem( FID_VALID_BLANK, maCbAllow.IsChecked() ) );
rArgSet.Put( SfxInt16Item( FID_VALID_LISTTYPE, nListType ) );
return sal_True;
}
OUString ScTPValidationValue::GetFirstFormula() const
{
OUString aFmlaStr;
if( maLbAllow.GetSelectEntryPos() == SC_VALIDDLG_ALLOW_LIST )
lclGetFormulaFromStringList( aFmlaStr, maEdList.GetText(), mcFmlaSep );
else
aFmlaStr = maEdMin.GetText();
return aFmlaStr;
}
OUString ScTPValidationValue::GetSecondFormula() const
{
return maEdMax.GetText();
}
void ScTPValidationValue::SetFirstFormula( const OUString& rFmlaStr )
{
// try if formula is a string list, validation mode must already be set
OUString aStringList;
if( (maLbAllow.GetSelectEntryPos() == SC_VALIDDLG_ALLOW_RANGE) &&
lclGetStringListFromFormula( aStringList, rFmlaStr, mcFmlaSep ) )
{
maEdList.SetText( aStringList );
maEdMin.SetText( EMPTY_OUSTRING );
// change validation mode to string list
maLbAllow.SelectEntryPos( SC_VALIDDLG_ALLOW_LIST );
}
else
{
maEdMin.SetText( rFmlaStr );
maEdList.SetText( EMPTY_OUSTRING );
}
}
void ScTPValidationValue::SetSecondFormula( const OUString& rFmlaStr )
{
maEdMax.SetText( rFmlaStr );
}
ScValidationDlg * ScTPValidationValue::GetValidationDlg()
{
if( Window *pParent = GetParent() )
do{
if ( dynamic_cast<ScValidationDlg*>( pParent ) )
return static_cast< ScValidationDlg * >( pParent );
}while ( NULL != ( pParent = pParent->GetParent() ) );
return NULL;
}
void ScTPValidationValue::SetupRefDlg()
{
if( ScValidationDlg *pValidationDlg = GetValidationDlg() )
{
if( pValidationDlg->SetupRefDlg() )
{
pValidationDlg->SetHandler( this );
pValidationDlg->SetSetRefHdl( (ScRefHandlerHelper::PFUNCSETREFHDLTYPE)( &ScTPValidationValue::SetReferenceHdl ) );
pValidationDlg->SetSetActHdl( (ScRefHandlerHelper::PCOMMONHDLTYPE)( &ScTPValidationValue::SetActiveHdl ) );
pValidationDlg->SetRefInputStartPreHdl( (ScRefHandlerHelper::PINPUTSTARTDLTYPE)( &ScTPValidationValue::RefInputStartPreHdl ) );
pValidationDlg->SetRefInputDonePostHdl( (ScRefHandlerHelper::PCOMMONHDLTYPE)( &ScTPValidationValue::RefInputDonePostHdl ) );
Window *pLabel = NULL;
if ( maEdMax.IsVisible() )
{
m_pRefEdit = &maEdMax;
pLabel = &maFtMax;
}
else if ( maEdMin.IsVisible() )
{
m_pRefEdit = &maEdMin;
pLabel = &maFtMin;
}
if( m_pRefEdit && !m_pRefEdit->HasFocus() )
m_pRefEdit->GrabFocus();
if( m_pRefEdit )
m_pRefEdit->SetReferences( pValidationDlg, pLabel );
m_btnRef.SetReferences( pValidationDlg, m_pRefEdit );
}
}
}
void ScTPValidationValue::RemoveRefDlg()
{
if( ScValidationDlg *pValidationDlg = GetValidationDlg() )
{
if( pValidationDlg->RemoveRefDlg() )
{
pValidationDlg->SetHandler( NULL );
pValidationDlg->SetSetRefHdl( NULL );
pValidationDlg->SetSetActHdl( NULL );
pValidationDlg->SetRefInputStartPreHdl( NULL );
pValidationDlg->SetRefInputDonePostHdl( NULL );
if( m_pRefEdit )
m_pRefEdit->SetReferences( NULL, NULL );
m_pRefEdit = NULL;
m_btnRef.SetReferences( NULL, NULL );
#if ! defined( WNT ) && !defined( _MSC_VER )
TidyListBoxes();
#endif
}
}
}
void ScTPValidationValue::TidyListBoxes()
{
if ( Window *pWnd = GetChild( 0 ) )
{
bool bFindLst = false;
std::list<Window*> alstOrder;
do{
if( pWnd->GetParent() == this )
{
if ( !bFindLst )
{
try{
if( dynamic_cast<ListBox*>(pWnd)||dynamic_cast<ListBox*>(pWnd->GetWindow(WINDOW_CLIENT) ) )
bFindLst = true;
}
catch( ... )
{
if ( *(void**)pWnd == *(void**)&maLbValue )
bFindLst = true;
else if ( Window *pClient = pWnd->GetWindow( WINDOW_CLIENT ) )
if ( *(void**)pClient == *(void**)&maLbValue )
bFindLst = true;
}
}
if ( bFindLst )
alstOrder.push_back( pWnd->GetWindow( WINDOW_CLIENT ) );
}
}while( NULL != ( pWnd = pWnd->GetWindow( WINDOW_NEXT ) ) );
pWnd = GetChild(0);
while( std::find( alstOrder.begin(), alstOrder.end(), pWnd ) != alstOrder.end() && NULL != ( pWnd = pWnd->GetWindow( WINDOW_NEXT) ) ) ;
if ( pWnd )
{
for ( std::list<Window*>::iterator i = alstOrder.begin(); i!=alstOrder.end(); ++i )
{
Window *pParent = (*i)->GetParent();
(*i)->SetParent( pWnd );
(*i)->SetParent( pParent );
}
}
}
}
IMPL_LINK_NOARG(ScTPValidationValue, EditSetFocusHdl)
{
sal_uInt16 nPos=maLbAllow.GetSelectEntryPos();
if ( nPos == SC_VALIDDLG_ALLOW_RANGE )
{
SetupRefDlg();
}
return 0;
}
IMPL_LINK( ScTPValidationValue, KillFocusHdl, Window *, pWnd )
{
if( pWnd == m_pRefEdit || pWnd == &m_btnRef )
if( ScValidationDlg *pValidationDlg = GetValidationDlg() )
if ( (pValidationDlg->IsActive() || pValidationDlg->IsChildFocus() ) && !pValidationDlg->IsRefInputting() )
if( ( !m_pRefEdit || !m_pRefEdit->HasFocus()) && !m_btnRef.HasFocus() )
{
RemoveRefDlg();
}
return 0;
}
IMPL_LINK_NOARG(ScTPValidationValue, SelectHdl)
{
sal_uInt16 nLbPos = maLbAllow.GetSelectEntryPos();
bool bEnable = (nLbPos != SC_VALIDDLG_ALLOW_ANY);
bool bRange = (nLbPos == SC_VALIDDLG_ALLOW_RANGE);
bool bList = (nLbPos == SC_VALIDDLG_ALLOW_LIST);
maCbAllow.Enable( bEnable ); // Empty cell
maFtValue.Enable( bEnable );
maLbValue.Enable( bEnable );
maFtMin.Enable( bEnable );
maEdMin.Enable( bEnable );
maEdList.Enable( bEnable );
maFtMax.Enable( bEnable );
maEdMax.Enable( bEnable );
bool bShowMax = false;
if( bRange )
maFtMin.SetText( maStrRange );
else if( bList )
maFtMin.SetText( maStrList );
else
{
switch( maLbValue.GetSelectEntryPos() )
{
case SC_VALIDDLG_DATA_EQUAL:
case SC_VALIDDLG_DATA_NOTEQUAL: maFtMin.SetText( maStrValue ); break;
case SC_VALIDDLG_DATA_LESS:
case SC_VALIDDLG_DATA_EQLESS: maFtMin.SetText( maStrMax ); break;
case SC_VALIDDLG_DATA_VALIDRANGE:
case SC_VALIDDLG_DATA_INVALIDRANGE: bShowMax = true; // fall through
case SC_VALIDDLG_DATA_GREATER:
case SC_VALIDDLG_DATA_EQGREATER: maFtMin.SetText( maStrMin ); break;
default:
OSL_FAIL( "ScTPValidationValue::SelectHdl - unknown condition mode" );
}
}
maCbShow.Show( bRange || bList );
maCbSort.Show( bRange || bList );
maFtValue.Show( !bRange && !bList );
maLbValue.Show( !bRange && !bList );
maEdMin.Show( !bList );
maEdList.Show( bList );
maFtMax.Show( bShowMax );
maEdMax.Show( bShowMax );
maFtHint.Show( bRange );
m_btnRef.Show( bRange ); // cell range picker
return 0;
}
IMPL_LINK_NOARG(ScTPValidationValue, CheckHdl)
{
maCbSort.Enable( maCbShow.IsChecked() );
return 0;
}
//========================================================================
//========================================================================
// Input Help Page
ScTPValidationHelp::ScTPValidationHelp( Window* pParent,
const SfxItemSet& rArgSet )
: SfxTabPage ( pParent,
"ValidationHelpTabPage" , "modules/scalc/ui/validationhelptabpage.ui" ,
rArgSet )
{
get(pTsbHelp,"tsbhelp");
get(pEdtTitle,"title");
get(pEdInputHelp,"inputhelp");
pEdInputHelp->set_height_request(pEdInputHelp->GetTextHeight() * 12);
pEdInputHelp->set_width_request(pEdInputHelp->approximate_char_width() * 50);
Init();
}
ScTPValidationHelp::~ScTPValidationHelp()
{
}
void ScTPValidationHelp::Init()
{
pTsbHelp->EnableTriState( false );
}
sal_uInt16* ScTPValidationHelp::GetRanges()
{
return pValueRanges;
}
SfxTabPage* ScTPValidationHelp::Create( Window* pParent,
const SfxItemSet& rArgSet )
{
return ( new ScTPValidationHelp( pParent, rArgSet ) );
}
void ScTPValidationHelp::Reset( const SfxItemSet& rArgSet )
{
const SfxPoolItem* pItem;
if ( rArgSet.GetItemState( FID_VALID_SHOWHELP, true, &pItem ) == SFX_ITEM_SET )
pTsbHelp->SetState( ((const SfxBoolItem*)pItem)->GetValue() ? TRISTATE_TRUE : TRISTATE_FALSE );
else
pTsbHelp->SetState( TRISTATE_FALSE );
if ( rArgSet.GetItemState( FID_VALID_HELPTITLE, true, &pItem ) == SFX_ITEM_SET )
pEdtTitle->SetText( ((const SfxStringItem*)pItem)->GetValue() );
else
pEdtTitle->SetText( EMPTY_OUSTRING );
if ( rArgSet.GetItemState( FID_VALID_HELPTEXT, true, &pItem ) == SFX_ITEM_SET )
pEdInputHelp->SetText( ((const SfxStringItem*)pItem)->GetValue() );
else
pEdInputHelp->SetText( EMPTY_OUSTRING );
}
sal_Bool ScTPValidationHelp::FillItemSet( SfxItemSet& rArgSet )
{
rArgSet.Put( SfxBoolItem( FID_VALID_SHOWHELP, pTsbHelp->GetState() == TRISTATE_TRUE ) );
rArgSet.Put( SfxStringItem( FID_VALID_HELPTITLE, pEdtTitle->GetText() ) );
rArgSet.Put( SfxStringItem( FID_VALID_HELPTEXT, pEdInputHelp->GetText() ) );
return sal_True;
}
//========================================================================
//========================================================================
// Error Alert Page
ScTPValidationError::ScTPValidationError( Window* pParent,
const SfxItemSet& rArgSet )
: SfxTabPage ( pParent,
"ErrorAlertTabPage" , "modules/scalc/ui/erroralerttabpage.ui" ,
rArgSet )
{
get(m_pTsbShow,"tsbshow");
get(m_pLbAction,"actionCB");
get(m_pBtnSearch,"browseBtn");
get(m_pEdtTitle,"title");
get(m_pFtError,"errormsg_label");
get(m_pEdError,"errorMsg");
m_pEdError->set_height_request(m_pEdError->GetTextHeight() * 12);
m_pEdError->set_width_request(m_pEdError->approximate_char_width() * 50);
Init();
}
ScTPValidationError::~ScTPValidationError()
{
}
void ScTPValidationError::Init()
{
m_pLbAction->SetSelectHdl( LINK( this, ScTPValidationError, SelectActionHdl ) );
m_pBtnSearch->SetClickHdl( LINK( this, ScTPValidationError, ClickSearchHdl ) );
m_pLbAction->SelectEntryPos( 0 );
m_pTsbShow->EnableTriState( false );
SelectActionHdl( NULL );
}
sal_uInt16* ScTPValidationError::GetRanges()
{
return pValueRanges;
}
SfxTabPage* ScTPValidationError::Create( Window* pParent,
const SfxItemSet& rArgSet )
{
return ( new ScTPValidationError( pParent, rArgSet ) );
}
void ScTPValidationError::Reset( const SfxItemSet& rArgSet )
{
const SfxPoolItem* pItem;
if ( rArgSet.GetItemState( FID_VALID_SHOWERR, true, &pItem ) == SFX_ITEM_SET )
m_pTsbShow->SetState( ((const SfxBoolItem*)pItem)->GetValue() ? TRISTATE_TRUE : TRISTATE_FALSE );
else
m_pTsbShow->SetState( TRISTATE_TRUE ); // check by default
if ( rArgSet.GetItemState( FID_VALID_ERRSTYLE, true, &pItem ) == SFX_ITEM_SET )
m_pLbAction->SelectEntryPos( ((const SfxAllEnumItem*)pItem)->GetValue() );
else
m_pLbAction->SelectEntryPos( 0 );
if ( rArgSet.GetItemState( FID_VALID_ERRTITLE, true, &pItem ) == SFX_ITEM_SET )
m_pEdtTitle->SetText( ((const SfxStringItem*)pItem)->GetValue() );
else
m_pEdtTitle->SetText( EMPTY_OUSTRING );
if ( rArgSet.GetItemState( FID_VALID_ERRTEXT, true, &pItem ) == SFX_ITEM_SET )
m_pEdError->SetText( ((const SfxStringItem*)pItem)->GetValue() );
else
m_pEdError->SetText( EMPTY_OUSTRING );
SelectActionHdl( NULL );
}
sal_Bool ScTPValidationError::FillItemSet( SfxItemSet& rArgSet )
{
rArgSet.Put( SfxBoolItem( FID_VALID_SHOWERR, m_pTsbShow->GetState() == TRISTATE_TRUE ) );
rArgSet.Put( SfxAllEnumItem( FID_VALID_ERRSTYLE, m_pLbAction->GetSelectEntryPos() ) );
rArgSet.Put( SfxStringItem( FID_VALID_ERRTITLE, m_pEdtTitle->GetText() ) );
rArgSet.Put( SfxStringItem( FID_VALID_ERRTEXT, m_pEdError->GetText() ) );
return sal_True;
}
IMPL_LINK_NOARG(ScTPValidationError, SelectActionHdl)
{
ScValidErrorStyle eStyle = (ScValidErrorStyle) m_pLbAction->GetSelectEntryPos();
sal_Bool bMacro = ( eStyle == SC_VALERR_MACRO );
m_pBtnSearch->Enable( bMacro );
m_pFtError->Enable( !bMacro );
m_pEdError->Enable( !bMacro );
return( 0L );
}
IMPL_LINK_NOARG(ScTPValidationError, ClickSearchHdl)
{
Window* pOld = Application::GetDefDialogParent();
Application::SetDefDialogParent( this );
// Use static SfxApplication method to bring up selector dialog for
// choosing a script
OUString aScriptURL = SfxApplication::ChooseScript();
Application::SetDefDialogParent( pOld );
if ( aScriptURL != NULL && !aScriptURL.isEmpty() )
{
m_pEdtTitle->SetText( aScriptURL );
}
return( 0L );
}
bool ScValidationDlg::EnterRefStatus()
{
ScTabViewShell *pTabViewShell = GetTabViewShell();
if( !pTabViewShell ) return false;
sal_uInt16 nId = SLOTID;
SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
if ( pWnd && pWnd->GetWindow()!= this ) pWnd = NULL;
SC_MOD()->SetRefDialog( nId, pWnd ? false : sal_True );
return true;
}
bool ScValidationDlg::LeaveRefStatus()
{
ScTabViewShell *pTabViewShell = GetTabViewShell();
if( !pTabViewShell ) return false;
sal_uInt16 nId = SLOTID;
SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
if ( pViewFrm->GetChildWindow( nId ) )
{
DoClose( nId );
}
return true;
}
bool ScValidationDlg::SetupRefDlg()
{
if ( m_bOwnRefHdlr ) return false;
if( EnterRefMode() )
{
SetModal( false );
return m_bOwnRefHdlr = true && EnterRefStatus();
}
return false;
}
bool ScValidationDlg::RemoveRefDlg( bool bRestoreModal /* = true */ )
{
bool bVisLock = false;
bool bFreeWindowLock = false;
ScTabViewShell *pTabVwSh = GetTabViewShell();
if( !pTabVwSh ) return false;
if ( SfxChildWindow* pWnd = pTabVwSh->GetViewFrame()->GetChildWindow( SID_VALIDITY_REFERENCE ) )
{
bVisLock = static_cast<ScValidityRefChildWin*>(pWnd)->LockVisible( true );
bFreeWindowLock = static_cast<ScValidityRefChildWin*>(pWnd)->LockFreeWindow( true );
}
if ( !m_bOwnRefHdlr ) return false;
if( LeaveRefStatus() && LeaveRefMode() )
{
m_bOwnRefHdlr = false;
if( bRestoreModal )
SetModal( true );
}
if ( SfxChildWindow* pWnd = pTabVwSh->GetViewFrame()->GetChildWindow( SID_VALIDITY_REFERENCE ) )
{
static_cast<ScValidityRefChildWin*>(pWnd)->LockVisible( bVisLock );
static_cast<ScValidityRefChildWin*>(pWnd)->LockFreeWindow( bFreeWindowLock );
}
return true;
}
void ScTPValidationValue::ScRefButtonEx::Click()
{
if( ScTPValidationValue *pParent = dynamic_cast< ScTPValidationValue*>( GetParent() ) )
pParent->OnClick( this );
formula::RefButton::Click();
}
void ScTPValidationValue::OnClick( Button *pBtn )
{
if( pBtn == &m_btnRef )
SetupRefDlg();
}
bool ScValidationDlg::IsChildFocus()
{
if ( const Window *pWin = Application::GetFocusWindow() )
while( NULL != ( pWin = pWin->GetParent() ) )
if( pWin == this )
return true;
return false;
}
bool ScValidationDlg::IsAlive()
{
return SC_MOD()->IsAliveRefDlg( SLOTID, this );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|