1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: optgenrl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
38 // include ---------------------------------------------------------------
39 #include <tools/shl.hxx>
40 #include <vcl/svapp.hxx>
41 #include <vcl/msgbox.hxx>
42 #include <svtools/saveopt.hxx>
44 #define _SVX_OPTGENRL_CXX
46 #include <svx/dialogs.hrc>
47 #include "optgenrl.hrc"
48 #include <svtools/useroptions.hxx>
49 #include "cuioptgenrl.hxx"
50 #include <svx/dialmgr.hxx>
51 #include "dlgutil.hxx"
52 #include <svx/strarray.hxx>
54 #define TRIM(s) s.EraseLeadingChars().EraseTrailingChars()
56 // struct GeneralTabPage_Impl --------------------------------------------
58 struct GeneralTabPage_Impl
68 GeneralTabPage_Impl() :
69 mbStreetEnabled ( FALSE
),
70 mbPLZEnabled ( FALSE
),
71 mbCityEnabled ( FALSE
),
72 mbUsCityEnabled ( FALSE
),
73 mbUsZipEnabled ( FALSE
) {}
76 // -----------------------------------------------------------------------
78 // kommt aus adritem.cxx
79 //CHINA001 extern String ConvertToStore_Impl( const String& );
80 //copy from adritem.cxx, since it will leave in svx.
81 String
ConvertToStore_Impl( const String
& rText
)
86 while ( i
< rText
.Len() )
88 if ( rText
.GetChar(i
) == '\\' || rText
.GetChar(i
) == '#' )
90 sRet
+= rText
.GetChar(i
++);
96 // -----------------------------------------------------------------------
98 SvxGeneralTabPage::SvxGeneralTabPage( Window
* pParent
, const SfxItemSet
& rCoreSet
) :
100 SfxTabPage( pParent
, SVX_RES(RID_SFXPAGE_GENERAL
), rCoreSet
),
102 aCompanyLbl ( this, SVX_RES( FT_COMPANY
), true ),
103 aCompanyEdit ( this, SVX_RES( ED_COMPANY
), INDEX_NOTSET
, &aCompanyLbl
),
104 aNameLbl ( this, SVX_RES( FT_NAME
), true ),
105 aNameLblRuss ( this, SVX_RES( FT_NAME_RUSS
), true ),
106 aFirstName ( this, SVX_RES( ED_FIRSTNAME
), 0, &aNameLbl
),
107 aFatherName ( this, SVX_RES( ED_FATHERNAME
) ),
108 aName ( this, SVX_RES( ED_NAME
), 1, &aNameLbl
),
109 aShortName ( this, SVX_RES( ED_SHORTNAME
), 2, &aNameLbl
),
110 aStreetLbl ( this, SVX_RES( FT_STREET
), true ),
111 aStreetLblRuss ( this, SVX_RES( FT_STREET_RUSS
), true ),
112 aStreetEdit ( this, SVX_RES( ED_STREET
), 0, &aStreetLbl
),
113 aApartmentNrEdit( this, SVX_RES( ED_APARTMENTNR
), 1, &aStreetLblRuss
),
114 aCityLbl ( this, SVX_RES( FT_CITY
), true ),
115 aPLZEdit ( this, SVX_RES( ED_PLZ
), 0, &aCityLbl
),
116 aCityEdit ( this, SVX_RES( ED_CITY
), 1, &aCityLbl
),
117 aUsCityEdit ( this, SVX_RES( ED_US_CITY
), 0, &aCityLbl
),
118 aUsStateEdit ( this, SVX_RES( ED_US_STATE
), 1, &aCityLbl
),
119 aUsZipEdit ( this, SVX_RES( ED_US_ZIPCODE
), 2, &aCityLbl
),
120 aCountryLbl ( this, SVX_RES( FT_COUNTRY
), true ),
121 aCountryEdit ( this, SVX_RES( ED_COUNTRY
), INDEX_NOTSET
, &aCountryLbl
),
122 aTitlePosLbl ( this, SVX_RES( FT_TITLEPOS
), true ),
123 aTitleEdit ( this, SVX_RES( ED_TITLE
), 0, &aTitlePosLbl
),
124 aPositionEdit ( this, SVX_RES( ED_POSITION
), 1, &aTitlePosLbl
),
125 aPhoneLbl ( this, SVX_RES( FT_PHONE
), true ),
126 aTelPrivEdit ( this, SVX_RES( ED_TELPRIVAT
), 0, &aPhoneLbl
),
127 aTelCompanyEdit ( this, SVX_RES( ED_TELCOMPANY
), 1, &aPhoneLbl
),
128 aFaxMailLbl ( this, SVX_RES( FT_FAXMAIL
), true ),
129 aFaxEdit ( this, SVX_RES( ED_FAX
), 0, &aFaxMailLbl
),
130 aEmailEdit ( this, SVX_RES( ED_EMAIL
), 1, &aFaxMailLbl
),
131 aAddrFrm ( this, SVX_RES( GB_ADDRESS
) ),
132 aUseDataCB ( this, SVX_RES( CB_USEDATA
) ),
134 pImpl ( new GeneralTabPage_Impl
)
137 LanguageType eLang
= Application::GetSettings().GetUILanguage();
138 pImpl
->maQueryStr
= String( SVX_RES( STR_QUERY_REG
) );
140 if ( LANGUAGE_ENGLISH_US
== eLang
)
142 // amerikanische Postadresse aufbauen
145 aCityLbl
.SetText( SVX_RES( STR_US_STATE
) );
147 else if ( LANGUAGE_RUSSIAN
== eLang
)
155 aStreetLblRuss
.Show();
158 aName
.SetLabel( &aNameLblRuss
);
159 aFirstName
.SetIndex( 1 );
160 aFirstName
.SetLabel( &aNameLblRuss
);
161 aFatherName
.SetIndex( 2 );
162 aFatherName
.SetLabel( &aNameLblRuss
);
163 aShortName
.SetIndex( 3 );
164 aShortName
.SetLabel( &aNameLblRuss
);
166 Point aEditPoint
= LogicToPixel( Point( MID
, LINE(1) ), MAP_APPFONT
);
167 Point aRightPoint
= LogicToPixel( Point( RIGHT
, LINE(1) ), MAP_APPFONT
);
168 Size aEditSize
= LogicToPixel( Size( 42, 12 ), MAP_APPFONT
);
169 Size a2Size
= LogicToPixel( Size( 2, 2 ), MAP_APPFONT
);
170 long nDelta
= aEditSize
.Width() + a2Size
.Width();
171 aName
.SetPosSizePixel( aEditPoint
, aEditSize
);
172 aEditPoint
.X() = aEditPoint
.X() + nDelta
;
173 aFirstName
.SetPosSizePixel( aEditPoint
, aEditSize
);
174 aEditPoint
.X() = aEditPoint
.X() + nDelta
;
175 aFatherName
.SetPosSizePixel( aEditPoint
, aEditSize
);
176 aEditPoint
.X() = aEditPoint
.X() + nDelta
;
177 aEditSize
.Width() = aRightPoint
.X() - aEditPoint
.X();
178 aShortName
.SetPosSizePixel( aEditPoint
, aEditSize
);
180 Size aStreetSize
= aStreetEdit
.GetSizePixel();
181 aStreetSize
.Width() = aStreetSize
.Width() - aEditSize
.Width() - a2Size
.Width();
182 aStreetEdit
.SetSizePixel( aStreetSize
);
183 aApartmentNrEdit
.Show();
184 Point aApartmentPoint
= LogicToPixel( Point( MID
, LINE(2) ), MAP_APPFONT
);
185 aApartmentPoint
.X() = aEditPoint
.X();
186 aApartmentNrEdit
.SetPosSizePixel( aApartmentPoint
, aEditSize
);
188 aName
.SetZOrder( &aNameLblRuss
, WINDOW_ZORDER_BEHIND
);
189 aFirstName
.SetZOrder( &aName
, WINDOW_ZORDER_BEHIND
);
190 aFatherName
.SetZOrder( &aFirstName
, WINDOW_ZORDER_BEHIND
);
201 // diese Page braucht ExchangeSupport
202 SetExchangeSupport();
204 Link aLink
= LINK( this, SvxGeneralTabPage
, ModifyHdl_Impl
);
205 aFirstName
.SetModifyHdl( aLink
);
206 aName
.SetModifyHdl( aLink
);
208 // because some labels have text for more than one edit field we have to split these texts
209 // and set these texts as accessible name of the corresponding edit fields
210 SvxUserEdit
* pEdits
[] =
212 &aCompanyEdit
, &aFirstName
, &aFatherName
, &aName
, &aShortName
, &aStreetEdit
,
213 &aApartmentNrEdit
, &aPLZEdit
, &aCityEdit
, &aUsCityEdit
, &aUsStateEdit
, &aUsZipEdit
,
214 &aCountryEdit
, &aTitleEdit
, &aPositionEdit
, &aTelPrivEdit
, &aTelCompanyEdit
,
215 &aFaxEdit
, &aEmailEdit
, NULL
217 SvxUserEdit
** pCurrent
= pEdits
;
220 Window
* pLabel
= (*pCurrent
)->GetLabel();
223 String sName
, sText
= pLabel
->GetDisplayText();
224 sal_Int16 nIndex
= (*pCurrent
)->GetIndex();
225 if ( INDEX_NOTSET
== nIndex
)
228 sName
= sText
.GetToken( nIndex
, '/' );
229 sName
.EraseAllChars( '(' );
230 sName
.EraseAllChars( ')' );
231 if ( sName
.Len() > 0 )
232 (*pCurrent
)->SetAccessibleName( sName
);
238 //------------------------------------------------------------------------
240 SvxGeneralTabPage::~SvxGeneralTabPage()
245 //------------------------------------------------------------------------
247 SfxTabPage
* SvxGeneralTabPage::Create( Window
* pParent
, const SfxItemSet
& rAttrSet
)
249 return ( new SvxGeneralTabPage( pParent
, rAttrSet
) );
252 //------------------------------------------------------------------------
254 BOOL
SvxGeneralTabPage::FillItemSet( SfxItemSet
& )
256 // Eingaben trimmen (f"uhrende und nachfolgende Leerzeichen entfernen)
257 aCompanyEdit
.SetText( TRIM(aCompanyEdit
.GetText()) );
258 aFirstName
.SetText( TRIM(aFirstName
.GetText()) );
259 aName
.SetText( TRIM(aName
.GetText()) );
260 aShortName
.SetText( TRIM(aShortName
.GetText()) );
261 aStreetEdit
.SetText( TRIM(aStreetEdit
.GetText()) );
262 aCountryEdit
.SetText( TRIM(aCountryEdit
.GetText()) );
263 aPLZEdit
.SetText( TRIM(aPLZEdit
.GetText()) );
264 aCityEdit
.SetText( TRIM(aCityEdit
.GetText()) );
265 aUsCityEdit
.SetText( TRIM(aUsCityEdit
.GetText()) );
266 aUsStateEdit
.SetText( TRIM(aUsStateEdit
.GetText()) );
267 aUsZipEdit
.SetText( TRIM(aUsZipEdit
.GetText()) );
268 aTitleEdit
.SetText( TRIM(aTitleEdit
.GetText()) );
269 aPositionEdit
.SetText( TRIM(aPositionEdit
.GetText()) );
270 aTelPrivEdit
.SetText( TRIM(aTelPrivEdit
.GetText()) );
271 aTelCompanyEdit
.SetText( TRIM(aTelCompanyEdit
.GetText()) );
272 aFaxEdit
.SetText( TRIM(aFaxEdit
.GetText()) );
273 aEmailEdit
.SetText( TRIM(aEmailEdit
.GetText()) );
275 BOOL bModified
= FALSE
;
276 bModified
|= GetAddress_Impl();
277 SvtSaveOptions aSaveOpt
;
278 if ( aUseDataCB
.IsChecked() != aSaveOpt
.IsUseUserData() )
280 aSaveOpt
.SetUseUserData( aUseDataCB
.IsChecked() );
286 //------------------------------------------------------------------------
288 void SvxGeneralTabPage::Reset( const SfxItemSet
& rSet
)
292 USHORT nWhich
= GetWhich( SID_FIELD_GRABFOCUS
);
293 if ( rSet
.GetItemState( nWhich
) == SFX_ITEM_SET
)
295 USHORT nField
= ( (SfxUInt16Item
&)rSet
.Get( nWhich
) ).GetValue();
299 case COMPANY_EDIT
: aCompanyEdit
.GrabFocus(); break;
300 case FIRSTNAME_EDIT
: aFirstName
.GrabFocus(); break;
301 case LASTNAME_EDIT
: aName
.GrabFocus(); break;
302 case STREET_EDIT
: aStreetEdit
.GrabFocus(); break;
303 case COUNTRY_EDIT
: aCountryEdit
.GrabFocus(); break;
305 if ( aPLZEdit
.IsVisible() )
306 aPLZEdit
.GrabFocus();
308 aUsZipEdit
.GrabFocus();
311 if ( aCityEdit
.IsVisible() )
312 aCityEdit
.GrabFocus();
314 aUsCityEdit
.GrabFocus();
317 if ( aUsStateEdit
.IsVisible() )
318 aUsStateEdit
.GrabFocus();
320 aCityEdit
.GrabFocus();
322 case TITLE_EDIT
: aTitleEdit
.GrabFocus(); break;
323 case POSITION_EDIT
: aPositionEdit
.GrabFocus(); break;
324 case SHORTNAME_EDIT
: aShortName
.GrabFocus(); break;
325 case TELPRIV_EDIT
: aTelPrivEdit
.GrabFocus(); break;
326 case TELCOMPANY_EDIT
: aTelCompanyEdit
.GrabFocus(); break;
327 case FAX_EDIT
: aFaxEdit
.GrabFocus(); break;
328 case EMAIL_EDIT
: aEmailEdit
.GrabFocus(); break;
329 default: aCompanyEdit
.GrabFocus();
333 aUseDataCB
.Check( SvtSaveOptions().IsUseUserData() );
336 //------------------------------------------------------------------------
338 IMPL_LINK( SvxGeneralTabPage
, ModifyHdl_Impl
, Edit
*, pEdit
)
340 if ( aShortName
.IsEnabled() )
342 String
aShortStr( aShortName
.GetText() );
343 switch ( aShortStr
.Len() )
346 aShortStr
= String( RTL_CONSTASCII_STRINGPARAM(" ") );
354 USHORT nPos
= ( pEdit
== &aFirstName
) ? 0 : 1;
355 String aTxt
= pEdit
->GetText();
356 sal_Unicode cChar
= ( aTxt
.Len() > 0 ) ? aTxt
.GetChar(0) : ' ';
357 aShortStr
.SetChar( nPos
, cChar
);
358 aShortStr
.EraseTrailingChars();
359 aShortName
.SetText( aShortStr
);
364 //------------------------------------------------------------------------
366 sal_Bool
SvxGeneralTabPage::GetAddress_Impl()
369 ( aCompanyEdit
.GetSavedValue() != aCompanyEdit
.GetText() ||
370 aFirstName
.GetSavedValue() != aFirstName
.GetText() ||
371 aFatherName
.GetSavedValue() != aFatherName
.GetText() ||
372 aName
.GetSavedValue() != aName
.GetText() ||
373 aShortName
.GetSavedValue() != aShortName
.GetText() ||
374 aStreetEdit
.GetSavedValue() != aStreetEdit
.GetText() ||
375 aApartmentNrEdit
.GetSavedValue() != aApartmentNrEdit
.GetText() ||
376 aPLZEdit
.GetSavedValue() != aPLZEdit
.GetText() ||
377 aCityEdit
.GetSavedValue() != aCityEdit
.GetText() ||
378 aUsCityEdit
.GetSavedValue() != aUsCityEdit
.GetText() ||
379 aUsStateEdit
.GetSavedValue() != aUsStateEdit
.GetText() ||
380 aUsZipEdit
.GetSavedValue() != aUsZipEdit
.GetText() ||
381 aCountryEdit
.GetSavedValue() != aCountryEdit
.GetText() ||
382 aTitleEdit
.GetSavedValue() != aTitleEdit
.GetText() ||
383 aPositionEdit
.GetSavedValue() != aPositionEdit
.GetText() ||
384 aTelPrivEdit
.GetSavedValue() != aTelPrivEdit
.GetText() ||
385 aTelCompanyEdit
.GetSavedValue() != aTelCompanyEdit
.GetText() ||
386 aFaxEdit
.GetSavedValue() != aFaxEdit
.GetText() ||
387 aEmailEdit
.GetSavedValue() != aEmailEdit
.GetText() );
389 LanguageType eLang
= Application::GetSettings().GetUILanguage();
390 BOOL bUS
= ( LANGUAGE_ENGLISH_US
== eLang
);
392 SvtUserOptions aUserOpt
;
393 aUserOpt
.SetCompany(aCompanyEdit
.GetText());
394 aUserOpt
.SetFirstName(aFirstName
.GetText());
395 aUserOpt
.SetLastName(aName
.GetText());
396 aUserOpt
.SetID( aShortName
.GetText());
398 aUserOpt
.SetStreet(aStreetEdit
.GetText() );
400 aUserOpt
.SetCountry(aCountryEdit
.GetText() );
402 aUserOpt
.SetZip(bUS
? aUsZipEdit
.GetText() : aPLZEdit
.GetText() );
403 aUserOpt
.SetCity(bUS
? aUsCityEdit
.GetText() : aCityEdit
.GetText() );
405 aUserOpt
.SetTitle( aTitleEdit
.GetText() );
406 aUserOpt
.SetPosition(aPositionEdit
.GetText() );
407 aUserOpt
.SetTelephoneHome( aTelPrivEdit
.GetText() );
408 aUserOpt
.SetTelephoneWork( aTelCompanyEdit
.GetText() );
409 aUserOpt
.SetFax( aFaxEdit
.GetText() );
410 aUserOpt
.SetEmail( aEmailEdit
.GetText() );
411 aUserOpt
.SetState( bUS
? aUsStateEdit
.GetText() : String() );
413 if ( LANGUAGE_RUSSIAN
== eLang
)
415 aUserOpt
.SetFathersName( aFatherName
.GetText() );
416 aUserOpt
.SetApartment( aApartmentNrEdit
.GetText() );
421 //------------------------------------------------------------------------
423 void SvxGeneralTabPage::SetAddress_Impl()
425 LanguageType eLang
= Application::GetSettings().GetUILanguage();
426 BOOL bUS
= ( LANGUAGE_ENGLISH_US
== eLang
);
427 SvtUserOptions aUserOpt
;
428 aCompanyEdit
.SetText( aUserOpt
.GetCompany() );
429 if ( aUserOpt
.IsTokenReadonly( USER_OPT_COMPANY
) )
431 aCompanyLbl
.Disable();
432 aCompanyEdit
.Disable();
434 sal_Int16 nEditCount
= 0;
435 aFirstName
.SetText( aUserOpt
.GetFirstName() );
436 if ( aUserOpt
.IsTokenReadonly( USER_OPT_FIRSTNAME
) )
438 aFirstName
.Disable();
441 aName
.SetText( aUserOpt
.GetLastName() );
442 if ( aUserOpt
.IsTokenReadonly( USER_OPT_LASTNAME
) )
447 aShortName
.SetText( aUserOpt
.GetID() );
448 if ( aUserOpt
.IsTokenReadonly( USER_OPT_ID
) )
450 aShortName
.Disable();
453 aNameLbl
.Enable( ( nEditCount
!= 3 ) );
454 aStreetEdit
.SetText( aUserOpt
.GetStreet() );
455 if ( aUserOpt
.IsTokenReadonly( USER_OPT_STREET
) )
457 aStreetLbl
.Disable();
458 aStreetEdit
.Disable();
460 Edit
* pPLZEdit
= bUS
? &aUsZipEdit
: &aPLZEdit
;
461 Edit
* pCityEdit
= bUS
? &aUsCityEdit
: &aCityEdit
;
462 pPLZEdit
->SetText( aUserOpt
.GetZip() );
463 pCityEdit
->SetText( aUserOpt
.GetCity() );
465 if ( aUserOpt
.IsTokenReadonly( USER_OPT_ZIP
) )
470 if ( aUserOpt
.IsTokenReadonly( USER_OPT_CITY
) )
472 pCityEdit
->Disable();
477 aUsStateEdit
.SetText( aUserOpt
.GetState() );
478 if ( aUserOpt
.IsTokenReadonly( USER_OPT_STATE
) )
480 aUsStateEdit
.Disable();
484 aCityLbl
.Enable( ( nEditCount
!= ( bUS
? 3 : 2 ) ) );
485 aCountryEdit
.SetText( aUserOpt
.GetCountry() );
486 if ( aUserOpt
.IsTokenReadonly( USER_OPT_COUNTRY
) )
488 aCountryLbl
.Disable();
489 aCountryEdit
.Disable();
491 aTitleEdit
.SetText( aUserOpt
.GetTitle() );
492 aPositionEdit
.SetText( aUserOpt
.GetPosition() );
494 if ( aUserOpt
.IsTokenReadonly( USER_OPT_TITLE
) )
496 aTitleEdit
.Disable();
499 if ( aUserOpt
.IsTokenReadonly( USER_OPT_POSITION
) )
501 aPositionEdit
.Disable();
504 aTitlePosLbl
.Enable( ( nEditCount
!= 2 ) );
505 aTelPrivEdit
.SetText( aUserOpt
.GetTelephoneHome() );
506 aTelCompanyEdit
.SetText( aUserOpt
.GetTelephoneWork() );
508 if ( aUserOpt
.IsTokenReadonly( USER_OPT_TELEPHONEHOME
) )
510 aTelPrivEdit
.Disable();
513 if ( aUserOpt
.IsTokenReadonly( USER_OPT_TELEPHONEWORK
) )
515 aTelCompanyEdit
.Disable();
518 aPhoneLbl
.Enable( ( nEditCount
!= 2 ) );
519 aFaxEdit
.SetText( aUserOpt
.GetFax() );
520 aEmailEdit
.SetText( aUserOpt
.GetEmail() );
522 if ( aUserOpt
.IsTokenReadonly( USER_OPT_FAX
) )
527 if ( aUserOpt
.IsTokenReadonly( USER_OPT_EMAIL
) )
529 aEmailEdit
.Disable();
532 aFaxMailLbl
.Enable( ( nEditCount
!= 2 ) );
534 if ( LANGUAGE_RUSSIAN
== eLang
)
536 aFatherName
.SetText( aUserOpt
.GetFathersName() );
537 aApartmentNrEdit
.SetText( aUserOpt
.GetApartment() );
540 aCompanyEdit
.SaveValue();
541 aFirstName
.SaveValue();
542 aFatherName
.SaveValue();
544 aShortName
.SaveValue();
545 aStreetEdit
.SaveValue();
546 aApartmentNrEdit
.SaveValue();
547 aPLZEdit
.SaveValue();
548 aCityEdit
.SaveValue();
549 aUsCityEdit
.SaveValue();
550 aUsStateEdit
.SaveValue();
551 aUsZipEdit
.SaveValue();
552 aCountryEdit
.SaveValue();
553 aTitleEdit
.SaveValue();
554 aPositionEdit
.SaveValue();
555 aTelPrivEdit
.SaveValue();
556 aTelCompanyEdit
.SaveValue();
557 aFaxEdit
.SaveValue();
558 aEmailEdit
.SaveValue();
561 // -----------------------------------------------------------------------
563 int SvxGeneralTabPage::DeactivatePage( SfxItemSet
* _pSet
)
566 FillItemSet( *_pSet
);