00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022 #ifndef __WXMASKEDIT_cpp__
00023 #define __WXMASKEDIT_cpp__
00024
00025
00026 #include "wx/wxEdit/wxMaskEdit.h"
00027 #include <wx/msgdlg.h>
00028
00029
00031
00032
00033
00035
00037
00038 TextPart::TextPart(size_t ord )
00039 : m_ord(ord)
00040 {
00041 }
00042
00043 TextPart::~TextPart()
00044 {
00045 }
00046 wxString TextPart::getValue() const
00047 {
00048 return m_val;
00049 }
00050
00051 void TextPart::setValue(const wxString& val)
00052 {
00053 m_val = val;
00054 }
00055
00056 size_t TextPart::getOrder() const
00057 {
00058 return m_ord;
00059 }
00060
00061 size_t TextPart::getSize() const
00062 {
00063 return m_val.Len();
00064 }
00065
00066 void TextPart::append(char c)
00067 {
00068 m_val += c;
00069 }
00070
00071 bool TextPart::isStatic() const
00072 {
00073 return true;
00074 }
00075
00076 int TextPart::OnKeyDown(wxKeyEvent& evt, size_t pos)
00077 {
00078
00079
00080 if(evt.GetKeyCode() == WXK_DELETE && pos == 9999999 ) pos = 0 ;
00081
00082 return 0;
00083 }
00084
00085 void TextPart::normalize()
00086 {
00087
00088 }
00089
00090 wxString TextPart::getTransform() const
00091 {
00092 return m_val;
00093 }
00094
00095 void TextPart::setStyle(size_t style )
00096 {
00097 m_style = style ;
00098 }
00099 size_t TextPart::getStyle() const
00100 {
00101 return m_style;
00102 }
00104
00106
00108
00109
00110
00112
00114 NumberGroup::NumberGroup(size_t ord, NumberGroup::NGBehaviour beh)
00115 : TextPart(ord), m_beh(beh)
00116 {
00117 }
00118
00119 NumberGroup::~NumberGroup()
00120 {
00121 }
00122
00123 wxString NumberGroup::getValue() const
00124 {
00125 wxString ret;
00126 size_t valLen = TextPart::getValue().Len();
00127
00128 for (size_t i = 0; i < valLen; i++) {
00129 if ( wxMaskEdit::IsControl(TextPart::getValue()[i]) ) {
00130 ret += "_";
00131 }
00132 else {
00133 ret += TextPart::getValue()[i];
00134 }
00135 }
00136
00137 return ret;
00138 }
00139
00140 bool NumberGroup::isStatic() const
00141 {
00142 return false;
00143 }
00144
00145
00146
00147 int NumberGroup::OnKeyDown(wxKeyEvent& evt, size_t pos)
00148 {
00149 int style = this->getStyle();
00150 wxString val( TextPart::getValue() );
00151 if(style != ME_NUM && style != ME_SIGNED &&
00152 style != ME_NDEC && style != ME_NDECS && style != ME_DATE ) return 0 ;
00153
00154 if (evt.GetKeyCode() == WXK_BACK) {
00155 val[pos] = '#';
00156 this->setValue(val);
00157 return 0;
00158 }
00159 else if (evt.GetKeyCode() == WXK_DELETE) {
00160
00161 val[pos] = '#';
00162 this->setValue(val);
00163 return 0;
00164 }
00165
00166 val[pos] = evt.GetKeyCode();
00167 this->setValue(val);
00168 return 1;
00169
00170 }
00171
00172
00173
00174 void NumberGroup::normalize()
00175 {
00176
00177 if (m_beh == NBLANKS) {
00178 this->goNormBlank();
00179 }
00180 else if (m_beh == NZEROS) {
00181 this->goNormZero();
00182 }
00183
00184 }
00185
00186 void NumberGroup::goNormBlank()
00187 {
00188 wxString val( TextPart::getValue() );
00189
00190 val.Replace("#", "_");
00191
00192
00193 for (size_t i = this->getSize(), n =this->getSize()-1 ; i >0 ; i-- , n--) if(val[n] == '_') val.Remove(n,1);
00194
00195 size_t ldiff = this->getSize() - val.Len();
00196
00197 if ( this->getStyle() == ME_NDEC || this->getStyle() == ME_NDECS) {
00198 if (TextPart::getOrder() < 2 )
00199 if ( ldiff > 0 ) val.Pad(ldiff, '_', false);
00200 if (TextPart::getOrder() == 2 )
00201 if ( ldiff > 0 ) val.Pad(ldiff, '0', true);
00202 }
00203
00204 if ( this->getStyle() == ME_NUM || this->getStyle() == ME_SIGNED) {
00205 if ( ldiff > 0 ) val.Pad(ldiff, '_', false);
00206 }
00207
00208 if ( this->getStyle() == ME_DATE) {
00209 if ( ldiff > 0 ) val.Pad(ldiff, '0', false);
00210 }
00211
00212 this->setValue(val);
00213 }
00214
00215 void NumberGroup::goNormZero()
00216 {
00217 wxString val( TextPart::getValue() );
00218
00219 val.Replace("#", "_");
00220
00221
00222 for (size_t i = this->getSize(), n =this->getSize()-1 ; i >0 ; i-- , n--) if(val[n] == '_') val.Remove(n,1);
00223
00224
00225
00226 size_t ldiff = this->getSize() - val.Len();
00227 if ( this->getStyle() == ME_NDEC || this->getStyle() == ME_NDECS) {
00228 if (TextPart::getOrder() < 2 )
00229 if ( ldiff > 0 ) val.Pad(ldiff, '0', false);
00230 if (TextPart::getOrder() == 2 )
00231 if ( ldiff > 0 ) val.Pad(ldiff, '0', true);
00232 }
00233 if ( this->getStyle() == ME_NUM || this->getStyle() == ME_SIGNED
00234 || this->getStyle() == ME_DATE) {
00235 if ( ldiff > 0 ) val.Pad(ldiff, '0', false);
00236 }
00237
00238 this->setValue(val);
00239 }
00240
00241 wxString NumberGroup::getTransform() const
00242 {
00243
00244
00245
00246
00247
00248
00249 wxString val( TextPart::getValue() );
00250 size_t ncar = this->getSize();
00251 val.Replace("_", " ");
00252
00253 size_t ldiff = ncar - val.Len();
00254 if (m_beh == NZEROS) val.Pad(ldiff, '0', false);
00255
00256
00257 if (m_beh == NBLANKS) val.Pad(ldiff, ' ', false);
00258
00259
00260
00261 return val;
00262 }
00263
00264
00265
00267
00269
00271
00272
00274
00276 LetterGroup::LetterGroup(size_t ord)
00277 : TextPart(ord)
00278 {
00279 }
00280
00281 LetterGroup::~LetterGroup()
00282 {
00283 }
00284
00285 wxString LetterGroup::getValue() const
00286 {
00287 wxString ret;
00288 size_t valLen = TextPart::getValue().Len();
00289
00290 for (size_t i = 0; i < valLen; i++) {
00291 if ( wxMaskEdit::IsControl(TextPart::getValue()[i]) ) {
00292 ret += "_";
00293 }
00294 else {
00295 ret += TextPart::getValue()[i];
00296 }
00297 }
00298
00299 return ret;
00300 }
00301
00302 bool LetterGroup::isStatic() const
00303 {
00304 return false;
00305 }
00306
00307
00308
00309
00310 int LetterGroup::OnKeyDown(wxKeyEvent& evt, size_t pos )
00311 {
00312 int style = this->getStyle();
00313 wxString val( TextPart::getValue() );
00314
00315 if (evt.GetKeyCode() == WXK_BACK ) {
00316
00317 val[pos] = '§';
00318 this->setValue(val);
00319 return 0;
00320 }
00321 if (evt.GetKeyCode() == WXK_DELETE ) {
00322
00323 val[pos] = '§';
00324 this->setValue(val);
00325 return 0;
00326 }
00327
00328
00329 val[pos] = evt.GetKeyCode();
00330
00331
00332 if (style== ME_CAPITAL || style== ME_CAPBLK || style== ME_CAPLBR ) {
00333 if (evt.GetKeyCode() >= 224 ) val[pos] = evt.GetKeyCode() -32;
00334 else val[pos]= toupper(evt.GetKeyCode());
00335 }
00336 this->setValue(val);
00337
00338 return 1;
00339
00340 }
00341
00342 void LetterGroup::normalize()
00343 {
00344 wxString val( TextPart::getValue() );
00345
00346 val.Replace("§", "_");
00347
00348 size_t ldiff = this->getSize() - val.Len();
00349
00350 if (ldiff > 0) {
00351 val.Pad(ldiff, '_', false);
00352 }
00353 this->setValue(val);
00354 }
00355
00356 wxString LetterGroup::getTransform() const
00357 {
00358 wxString val( TextPart::getValue() );
00359 val.Replace("_", " ",true);
00360 return val;
00361
00362 }
00363
00364
00366
00368
00369
00370
00371
00373
00374
00375
00376
00378
00380 IMPLEMENT_DYNAMIC_CLASS(wxMaskEdit, wxTextCtrl)
00381
00382 BEGIN_EVENT_TABLE(wxMaskEdit, wxTextCtrl)
00383 EVT_CHAR(wxMaskEdit::OnKeyPress)
00384 EVT_SET_FOCUS(wxMaskEdit::OnSetFocus)
00385 EVT_KILL_FOCUS(wxMaskEdit::OnLostFocus)
00386 END_EVENT_TABLE()
00387
00388 const wxString wxMaskEdit::m_control = wxString("#§");
00389
00390 wxMaskEdit::wxMaskEdit()
00391 : m_firstfocus(true)
00392 {
00393 }
00394
00395 wxMaskEdit::wxMaskEdit(wxWindow *parent, wxWindowID id,
00396 const wxString &txt,
00397 const wxPoint &pos,
00398 const wxSize &size,
00399 long style,
00400 const wxValidator &validator ,
00401 const wxString &name,
00402 const wxString &mask,
00403 unsigned int MskStyle ,
00404 bool GroupStyle
00405
00406 )
00407
00408 {
00409 if ( GroupStyle == GBLANKS) m_behav = NumberGroup::NGBehaviour (GBLANKS);
00410 else m_behav = NumberGroup::NGBehaviour(GZEROS);
00411 this->m_firstfocus= true;
00412
00413 m_Text = txt;
00414 if ( MskStyle > 11 ) wxMessageBox("Non Conforme Style MaskEdit");
00415
00416 this->wxTextCtrl::Create(parent, id, txt, pos, size,style,validator,name);
00417
00418 this->SetFont(wxFont(10,wxFONTFAMILY_SWISS, wxNORMAL,wxFONTWEIGHT_NORMAL ,true,wxT("Courier")));
00419
00420
00421 if (mask.Len() > 0 ) {
00422 this->ParseMask(mask, MskStyle);
00423 this->SetMaxLength(this->SzToL(mask.Length()));
00424
00425 this->SetDisplay(m_Text);
00426 }
00427
00428
00429
00430 }
00431
00432
00433 wxMaskEdit::~wxMaskEdit()
00434 {
00435
00436 WX_CLEAR_ARRAY(m_parts);
00437 }
00438
00439
00440
00441 long wxMaskEdit::SzToL(size_t size_value) {
00442 long long_value;
00443 wxString s = wxString::Format(wxT("%d"), size_value) ;
00444 s.ToLong(&long_value);
00445
00446
00447
00448
00449
00450 return long_value;
00451 }
00452
00453
00454
00455
00456 void wxMaskEdit::wxMaskSet(
00457 const wxString &mask,
00458 unsigned int MskStyle ,
00459 bool GroupStyle
00460
00461 )
00462 {
00463 if ( GroupStyle == GBLANKS) m_behav = NumberGroup::NGBehaviour (GBLANKS);
00464 else m_behav = NumberGroup::NGBehaviour(GZEROS);
00465 this->m_firstfocus= true;
00466
00467
00468 WX_CLEAR_ARRAY(m_parts);
00469
00470 if ( MskStyle > 11 ) wxMessageBox("Non Conforme Style MaskEdit");
00471
00472 this->ParseMask(mask, MskStyle);
00473 this->SetMaxLength(this->SzToL(mask.Length()));
00474
00475
00476 this->SetDisplay(this->m_Text);
00477 }
00478
00479
00480
00481 void wxMaskEdit::ParseMask(const wxString& mask, int style)
00482 {
00483 m_mask = mask ;
00484
00485 char cEdit = 0x00;
00486 TextPart* part = 0;
00487 this->NbrIdx = 0;
00488 this->Msk_Style = style;
00489 for (size_t i = 0; i < mask.Len(); i++) {
00490
00491 if ( mask[i] != cEdit && IsControl(mask[i]) ) {
00492 if (part) m_parts.Add(part);
00493
00494 if (mask[i] == '#') {
00495 cEdit = '#';
00496 part = new NumberGroup(this->NbrIdx, m_behav);
00497 this->NbrIdx ++;
00498
00499 }
00500 else if (mask[i] == '§' ) {
00501 cEdit = '§';
00502 part = new LetterGroup(this->NbrIdx);
00503 this->NbrIdx ++;
00504
00505 }
00506 }
00507 else if (!IsControl(mask[i])) {
00508 if (part) m_parts.Add(part);
00509 cEdit = '0';
00510 part = new TextPart(this->NbrIdx);
00511 this->NbrIdx ++;
00512 }
00513
00514 part->append( mask[i] );
00515 part->setStyle(style);
00516 }
00517
00518 if (part) m_parts.Add( part );
00519
00520
00521 -- NbrIdx;
00522 }
00523
00524
00525
00526
00527 void wxMaskEdit::DrawMask()
00528 {
00529 this->SetValue(GenMaskText());
00530 }
00531
00532 wxString wxMaskEdit::GenMaskText()
00533 {
00534 wxString full;
00535
00536 for (size_t i = 0; i < m_parts.GetCount(); i++) {
00537 full += m_parts.Item(i)->getValue();
00538 }
00539 return full;
00540 }
00541
00542
00543
00544 TextPart* wxMaskEdit::FindPart()
00545 {
00546 size_t pos = this->GetInsertionPoint();
00547 size_t currtot = 0;
00548
00549 for (size_t i = 0; i < m_parts.GetCount(); i++) {
00550 currtot += m_parts.Item(i)->getSize();
00551
00552 if (currtot > pos) {
00553 return m_parts.Item(i);
00554 }
00555 }
00556
00557 return 0;
00558 }
00559
00560
00561
00562 size_t wxMaskEdit::FindItem()
00563 {
00564 size_t pos = this->GetInsertionPoint();
00565 size_t currtot = 0;
00566 size_t i ;
00567 for (i = 0; i < m_parts.GetCount(); i++) {
00568 currtot += m_parts.Item(i)->getSize();
00569
00570 if (currtot > pos) {
00571 return i;
00572 }
00573 }
00574
00575 return --i;
00576 }
00577
00578
00579
00580
00581 size_t wxMaskEdit::ItemPos(size_t item)
00582 {
00583 size_t pos = 0;
00584
00585 for (size_t i = 0; i <= item; i++)
00586 pos += m_parts.Item(i)->getSize();
00587
00588
00589 return pos;
00590 }
00591
00592
00593
00594 size_t wxMaskEdit::FindIdx()
00595 {
00596 size_t pos = this->GetInsertionPoint();
00597 size_t currtot = 0;
00598
00599 for (size_t i = 0; i < m_parts.GetCount(); i++) {
00600 currtot += m_parts.Item(i)->getSize();
00601
00602 if (currtot > pos) {
00603 return m_parts.Item(i)->getSize() - (currtot - pos);
00604 }
00605 }
00606
00607 return 0;
00608 }
00609
00610
00611
00612 bool wxMaskEdit::IsControl(char c)
00613 {
00614 return m_control.Find(c) != -1;
00615 }
00616
00617
00618
00619
00620 void wxMaskEdit::OnSetFocus(wxFocusEvent& evt)
00621 {
00622 if (m_firstfocus) {
00623 this->SetInsertionPoint(0);
00624 this->FixInsPt(0, 1);
00625
00626 m_firstfocus = false;
00627 }
00628
00629 evt.Skip();
00630 }
00631
00632
00633
00634 void wxMaskEdit::OnLostFocus(wxFocusEvent& evt)
00635 {
00636
00637 long inspt = this->GetInsertionPoint();
00638
00639
00640 for (size_t i = 0; i < m_parts.GetCount(); i++) {
00641 m_parts.Item(i)->normalize();
00642 }
00643
00644
00645 this->DrawMask();
00646
00647
00648 this->SetInsertionPoint(inspt);
00649 m_firstfocus = true;
00650 evt.Skip();
00651 }
00652
00653
00654
00655
00656
00657
00658 void wxMaskEdit::OnKeyPress(wxKeyEvent& evt)
00659 {
00660 TextPart* p = this->FindPart();
00661 size_t pos = 0 ;
00662 size_t savpos = 0;
00663 wxString val_;
00664
00665
00666
00667
00668 if (false == this->CtrlKey(evt) ){ evt.Skip(); return; }
00669
00670 if ( evt.HasModifiers() ||
00671 evt.GetKeyCode() == WXK_RETURN ||
00672 evt.GetKeyCode() == WXK_TAB ) { evt.Skip(); return; }
00673
00674
00675
00676 if (evt.GetKeyCode() == WXK_END ) {
00677 if (this->FindPart())
00678 { p->normalize();
00679 pos = this->ItemPos(this->FindItem());
00680 this->DrawMask();
00681 this->FixInsPt(pos,1);
00682 }
00683 return;
00684 }
00685
00686
00687 if ((evt.GetKeyCode() >= 32 && evt.GetKeyCode() <= 127 )
00688 ||(evt.GetKeyCode() >= 128 && evt.GetKeyCode() <= 255)
00689 ||(evt.GetKeyCode() >= 326 && evt.GetKeyCode() <= 335)
00690 || (evt.GetKeyCode() == WXK_BACK)
00691 || (evt.GetKeyCode() == WXK_DELETE) ) {
00692
00693 p = this->FindPart();
00694 pos = this->GetInsertionPoint();
00695
00696
00697
00698 if (this->FindPart() && this->FindPart()->isStatic() && evt.GetKeyCode() != WXK_BACK) {
00699 pos++;
00700 this->FixInsPt(pos, 1);
00701 }
00702
00703
00704 if (evt.GetKeyCode() == WXK_BACK ) {
00705
00706 if (pos > 0 ) pos-- ;
00707 this->SetInsertionPoint(this->SzToL(pos));
00708 p = this->FindPart();
00709 if (m_mask[pos] != '#' && m_mask[pos] !='§' ) return;
00710 else {
00711 savpos =this->FindIdx();
00712 p->OnKeyDown(evt,savpos);
00713 this->DrawMask();
00714 this->SetInsertionPoint(this->SzToL(pos));
00715 return;
00716 }
00717
00718 }
00719
00720 else if (evt.GetKeyCode() == WXK_DELETE ) {
00721
00722 size_t item = this->FindItem();
00723
00724 pos=0;
00725 wxKeyEvent k(wxEVT_CHAR);
00726 k.m_keyCode = WXK_DELETE;
00727
00728 this->FixInsPt(0, 1);
00729
00730 for (size_t i = 0; i <= item; i++ ) {
00731
00732 this->SetInsertionPoint(this->SzToL(pos));
00733 p = this->FindPart(); savpos =pos;
00734
00735 for (size_t n = 0; n <= p->getSize() ; n++) {
00736
00737 if (m_mask[pos] == '#' || m_mask[pos] =='§' )
00738 if (i == item) p->OnKeyDown(k,n);
00739 pos++; }
00740 pos--;
00741 }
00742 this->DrawMask();
00743 this->FixInsPt(savpos, 1);
00744 pos = this->GetInsertionPoint();
00745 return;
00746 }
00747
00748 if (this->FindPart()) {
00749 int dir = p->OnKeyDown(evt,this->FindIdx());
00750 this->DrawMask();
00751 pos += dir;
00752 this->FixInsPt(pos, 1);
00753 }
00754
00755 }
00756 else if (evt.GetKeyCode() == WXK_LEFT || evt.GetKeyCode() == WXK_UP ||
00757 evt.GetKeyCode() == WXK_NUMPAD_LEFT) {
00758
00759 val_ = this->getAbsValue().Trim(false);
00760 if (val_.Len() == 0) { this->FixInsPt(pos, 1); return; }
00761
00762 pos = this->GetInsertionPoint();
00763 if (pos > 0) {
00764
00765 this->FixInsPt(--pos, 0);
00766 }
00767
00768 }
00769 else if (evt.GetKeyCode() == WXK_RIGHT || evt.GetKeyCode() == WXK_DOWN||
00770 evt.GetKeyCode() == WXK_NUMPAD_RIGHT) {
00771
00772 val_ = this->getAbsValue().Trim(false);
00773 if (val_.Len() == 0) { this->FixInsPt(pos, 1); return; }
00774
00775 pos = this->GetInsertionPoint();
00776 if (pos < val_.Len()) {
00777
00778 this->FixInsPt(++pos, 1);
00779 }
00780
00781 }
00782 else {
00783 evt.Skip();
00784 }
00785 }
00786
00787
00788
00789
00790
00791 wxString wxMaskEdit::getGroupText(size_t idx) const
00792 {
00793 if ( this->NbrIdx < idx) return wxT("¤");
00794 else return m_parts[idx]->getTransform();
00795 }
00796
00797
00798
00799
00800
00801 wxString wxMaskEdit::getAbsValue() const
00802 {
00803 wxString ret;
00804 wxString trt ;
00805
00806 for (size_t i = 0; i < m_parts.GetCount(); i++) {
00807
00808 m_parts[i]->normalize();
00809
00810 trt += m_parts[i]->getTransform();
00811
00812 }
00813
00814 for (size_t i = 0; i < m_mask.Length(); i++) {
00815 switch(this->Msk_Style)
00816 {
00817 case ME_NDEC : if ( trt[i] != ' ' ) ret += trt[i]; break;
00818
00819 case ME_NDECS : if ( trt[i] != ' ' ) ret += trt[i]; break;
00820
00821 case ME_NUM : if (m_mask[i] == '#' && trt[i] != ' ' ) ret += trt[i]; break;
00822
00823 case ME_SIGNED : if (m_mask[i] == '#' && trt[i] != ' ' ) ret += trt[i]; break;
00824
00825 case ME_DATE : if (m_mask[i] == '#') ret += trt[i]; break;
00826
00827 default:
00828 if ( m_mask[i] =='§') if ( trt[i] != ' ' ) ret += trt[i];break;
00829 }
00830 }
00831 ret.Trim();
00832 return ret.Trim(true);
00833 }
00834
00835
00836 char * wxMaskEdit::ToChar() const
00837 {
00838 wxString ret;
00839 wxString trt ;
00840 char * vchar ;
00841 for (size_t i = 0; i < m_parts.GetCount(); i++) {
00842
00843 m_parts[i]->normalize();
00844
00845 trt += m_parts[i]->getTransform();
00846
00847 }
00848
00849 for (size_t i = 0; i < m_mask.Length(); i++) {
00850 if ( trt[i] != '_' & trt[i] != ' ' ) ret += trt[i];
00851 }
00852 ret.Trim(); ret.Trim(true);
00853 vchar = (char*) malloc( ret.Length() );
00854 strcpy(vchar,ret.c_str());
00855
00856 return &(vchar[0]);
00857 }
00858
00859
00860
00861
00862 wxString wxMaskEdit::getTextValue() const
00863 {
00864 wxString ret;
00865
00866 for (size_t i = 0; i < m_parts.GetCount(); i++) {
00867 m_parts[i]->normalize();
00868 ret += m_parts[i]->getTransform();
00869 }
00870 ret.Replace("_", " ");
00871 return ret;
00872 }
00873
00874
00875
00876
00877 void wxMaskEdit::FixInsPt(size_t pos, int dir)
00878 {
00879 size_t masksz = this->GenMaskText().Len();
00880 if(pos >= masksz) {
00881 this->SetInsertionPoint(this->SzToL(masksz));
00882 return;
00883 }
00884
00885 if (pos <= 0 && dir <= 0) {
00886 this->SetInsertionPoint(0);
00887
00888 if (this->FindPart() && this->FindPart()->isStatic()) {
00889 FixInsPt(pos, 1);
00890 }
00891
00892 return;
00893 }
00894
00895 this->SetInsertionPoint(this->SzToL(pos));
00896
00897 if (dir == 0) return;
00898
00899
00900 while (this->FindPart() &&
00901 this->FindPart()->isStatic()) {
00902
00903 if (pos == 0 && dir < 0) {
00904 if (this->FindPart() && this->FindPart()->isStatic()) {
00905 FixInsPt(pos, 1);
00906 }
00907
00908 break;
00909 }
00910 else if(pos >= masksz) {
00911 break;
00912 }
00913
00914 pos += dir;
00915 this->SetInsertionPoint(this->SzToL(pos));
00916 }
00917 }
00918
00919
00920
00921
00922 void wxMaskEdit::SetDisplay(const wxString& value)
00923 {
00924 wxString xval = value ;
00925 int ncar = 0;
00926
00927 this->SetInsertionPoint(0);
00928 wxKeyEvent k(wxEVT_CHAR);
00929
00930
00931
00932 TextPart* p = this->FindPart();
00933 for (size_t i = 0 , pos = 0; i < m_parts.GetCount(); i++ ) {
00934 this->SetInsertionPoint(this->SzToL(pos));
00935 p = this->FindPart();
00936
00937 k.m_keyCode = WXK_DELETE;
00938
00939 for (size_t n = 0; n < p->getSize(); n++) {
00940 if (m_mask[pos] == '#' || m_mask[pos] =='§') p->OnKeyDown(k,n); pos++; }
00941 }
00942
00943
00944
00945 this->SetInsertionPoint(0); FixInsPt(0, 0);
00946 if (this->Msk_Style == ME_SIGNED || this->Msk_Style == ME_NDECS )
00947 {p = this->FindPart(); k.m_keyCode = '+'; p->OnKeyDown(k,0);}
00948
00949 if (value != "") for (size_t i = 0; i < xval.Len(); i++) {
00950 ncar = xval[i]; if ( ncar <0 ) k.m_keyCode = 256 + ncar ; else k.m_keyCode = ncar;
00951 this->OnKeyPress(k);
00952 }
00953 this->DrawMask();
00954 wxFocusEvent e;
00955 this->OnLostFocus(e);
00956 }
00957
00958
00959
00960
00961
00962
00963 void wxMaskEdit::SetClear()
00964 {
00965 this->SetDisplay(wxT(""));
00966 }
00967
00968
00969
00970
00971 bool wxMaskEdit::CtrlKey(wxKeyEvent& evt)
00972 {
00973
00974
00975
00976
00977
00978 if (this->IsEditable() == false ) return false;
00979 if (evt.GetKeyCode() == '_' || evt.GetKeyCode() == '#' || evt.GetKeyCode() == '§' ) return false;
00980
00981 if (evt.GetKeyCode() == WXK_RETURN) return true;
00982
00983 if (evt.GetKeyCode() == WXK_TAB) return true;
00984
00985 if (evt.GetKeyCode() == WXK_NUMPAD_TAB) return true;
00986
00987 if (evt.GetKeyCode() == WXK_END) return true;
00988
00989 if (evt.GetKeyCode() == WXK_BACK ||
00990 evt.GetKeyCode() == WXK_DELETE) return true;
00991
00992 if (evt.GetKeyCode() == WXK_LEFT || evt.GetKeyCode() == WXK_UP ||
00993 evt.GetKeyCode() == WXK_NUMPAD_LEFT) return true;
00994
00995 if (evt.GetKeyCode() == WXK_RIGHT || evt.GetKeyCode() == WXK_DOWN||
00996 evt.GetKeyCode() == WXK_NUMPAD_RIGHT) return true;
00997
00998
00999
01000
01001
01002 if (evt.GetKeyCode() >= 255 ) return false;
01003
01004
01005 size_t pos = this->GetInsertionPoint();
01006 if (evt.GetKeyCode() == 32 && pos == 0 ) return false ;
01007
01008
01009
01010 if(this->Msk_Style == ME_LIBRE || this->Msk_Style == ME_CAPLBR )
01011 { if (evt.GetKeyCode() >= 32 && evt.GetKeyCode() <= 127) return true;
01012 if (evt.GetKeyCode() >= 128 && evt.GetKeyCode() <= 255) return true;
01013
01014 }
01015 if(this->Msk_Style == ME_CAPBLK )
01016 { if ( m_mask[pos] !='§' ) return false;
01017 if (evt.GetKeyCode() >= 'A' && evt.GetKeyCode() <= 'Z') return true;
01018 if (evt.GetKeyCode() >= 'a' && evt.GetKeyCode() <= 'z') return true;
01019 if (evt.GetKeyCode() >= 128 && evt.GetKeyCode() <= 255) return true;
01020 if (evt.GetKeyCode() == ' ')return true;
01021 }
01022 if(this->Msk_Style == ME_CAPITAL )
01023 { if ( m_mask[pos] !='§' ) return false;
01024 if (evt.GetKeyCode() >= 'A' && evt.GetKeyCode() <= 'Z') return true;
01025 if (evt.GetKeyCode() >= 'a' && evt.GetKeyCode() <= 'z') return true;
01026 if (evt.GetKeyCode() == 128 && evt.GetKeyCode() == 163) return true;
01027 if (evt.GetKeyCode() >= 192 && evt.GetKeyCode() <= 255) return true;
01028 }
01029 if(this->Msk_Style == ME_LTRNUM )
01030 { if (evt.GetKeyCode() >= 'A' && evt.GetKeyCode() <= 'Z') return true;
01031 if (evt.GetKeyCode() >= 'a' && evt.GetKeyCode() <= 'z') return true;
01032 if (evt.GetKeyCode() == 128 && evt.GetKeyCode() == 163) return true;
01033 if (evt.GetKeyCode() >= 192 && evt.GetKeyCode() <= 255) return true;
01034 if (evt.GetKeyCode() >= '0' && evt.GetKeyCode() <= '9') return true;
01035 if (evt.GetKeyCode() == ' ' ) return true;
01036 }
01037 if(this->Msk_Style == ME_LTRBLK)
01038 { if ( m_mask[pos] !='§' ) return false;
01039 if (evt.GetKeyCode() >= 'A' && evt.GetKeyCode() <= 'Z') return true;
01040 if (evt.GetKeyCode() >= 'a' && evt.GetKeyCode() <= 'z') return true;
01041 if (evt.GetKeyCode() == ' ' ) return true;
01042 }
01043 if(this->Msk_Style == ME_ALPHA )
01044 { if ( m_mask[pos] !='§' ) return false;
01045 if (evt.GetKeyCode() >= 'A' && evt.GetKeyCode() <= 'Z') return true;
01046 if (evt.GetKeyCode() >= 'a' && evt.GetKeyCode() <= 'z') return true;
01047 if (evt.GetKeyCode() == 128 && evt.GetKeyCode() == 163) return true;
01048 if (evt.GetKeyCode() >= 192 && evt.GetKeyCode() <= 255) return true;
01049 if (evt.GetKeyCode() == ' ' ) return true;
01050 }
01051 if(this->Msk_Style == ME_NUM || this->Msk_Style == ME_NDEC )
01052 { if ( m_mask[pos] !='#' ) return false;
01053 if (evt.GetKeyCode() >= '0' && evt.GetKeyCode() <= '9' ) return true;
01054 }
01055
01056 if(this->Msk_Style == ME_SIGNED || this->Msk_Style == ME_NDECS )
01057 {
01058 if (evt.GetKeyCode() == '-' && m_mask[pos] =='§') return true;
01059 if (evt.GetKeyCode() == '+' && m_mask[pos] =='§') return true;
01060 if ( m_mask[pos] !='#' ) return false;
01061 if (evt.GetKeyCode() >= '0' && evt.GetKeyCode() <= '9') return true;
01062
01063 }
01064 if(this->Msk_Style == ME_DATE )
01065 { if ( m_mask[pos] !='#' ) return false;
01066 if (evt.GetKeyCode() >= '0' && evt.GetKeyCode() <= '9' ) return true;
01067 }
01068
01069 return false;
01070 }
01071 #endif