From 9be8cc68cda77b22259bb418b5577918ba891362 Mon Sep 17 00:00:00 2001 From: Matteo Casalin Date: Sat, 24 Aug 2013 14:22:58 +0200 Subject: String to OUString and hide implementation details Change-Id: I91ca70273b2262f8aee7e7bb8000d1271e727b18 Reviewed-on: https://gerrit.libreoffice.org/5617 Reviewed-by: Michael Stahl Tested-by: Michael Stahl --- sw/source/ui/frmdlg/cption.cxx | 22 ++++----- sw/source/ui/inc/initui.hxx | 25 +++++----- sw/source/ui/misc/glossary.cxx | 48 ++++++++----------- sw/source/ui/uiview/viewdlg2.cxx | 25 +++------- sw/source/ui/utlui/initui.cxx | 101 ++++++++++++++++++++++++++++++--------- 5 files changed, 126 insertions(+), 95 deletions(-) diff --git a/sw/source/ui/frmdlg/cption.cxx b/sw/source/ui/frmdlg/cption.cxx index 201b1c7f4f51..f124f1be90e5 100644 --- a/sw/source/ui/frmdlg/cption.cxx +++ b/sw/source/ui/frmdlg/cption.cxx @@ -42,17 +42,13 @@ #include #include #include +#include "initui.hxx" #include #include #include using namespace ::com::sun::star; -extern String* GetOldGrfCat(); -extern String* GetOldTabCat(); -extern String* GetOldFrmCat(); -extern String* GetOldDrwCat(); - class SwSequenceOptionDialog : public SvxStandardDialog { ListBox* m_pLbLevel; @@ -144,12 +140,12 @@ SwCaptionDialog::SwCaptionDialog( Window *pParent, SwView &rV ) : m_pCategoryBox->InsertEntry(pType->GetName()); } - String* pString = 0; + OUString sString; sal_uInt16 nPoolId = 0; if (eType & nsSelectionType::SEL_GRF) { nPoolId = RES_POOLCOLL_LABEL_ABB; - pString = ::GetOldGrfCat(); + sString = ::GetOldGrfCat(); bCopyAttributes = sal_True; sObjectName = rSh.GetFlyName(); //if not OLE @@ -163,7 +159,7 @@ SwCaptionDialog::SwCaptionDialog( Window *pParent, SwView &rV ) : else if( eType & nsSelectionType::SEL_TBL ) { nPoolId = RES_POOLCOLL_LABEL_TABLE; - pString = ::GetOldTabCat(); + sString = ::GetOldTabCat(); uno::Reference< text::XTextTablesSupplier > xTables(xModel, uno::UNO_QUERY); xNameAccess = xTables->getTextTables(); sObjectName = rSh.GetTableFmt()->GetName(); @@ -171,7 +167,7 @@ SwCaptionDialog::SwCaptionDialog( Window *pParent, SwView &rV ) : else if( eType & nsSelectionType::SEL_FRM ) { nPoolId = RES_POOLCOLL_LABEL_FRAME; - pString = ::GetOldFrmCat(); + sString = ::GetOldFrmCat(); uno::Reference< text::XTextFramesSupplier > xFrms(xModel, uno::UNO_QUERY); xNameAccess = xFrms->getTextFrames(); sObjectName = rSh.GetFlyName(); @@ -179,17 +175,17 @@ SwCaptionDialog::SwCaptionDialog( Window *pParent, SwView &rV ) : else if( eType == nsSelectionType::SEL_TXT ) { nPoolId = RES_POOLCOLL_LABEL_FRAME; - pString = ::GetOldFrmCat(); + sString = ::GetOldFrmCat(); } else if( eType & nsSelectionType::SEL_DRW ) { nPoolId = RES_POOLCOLL_LABEL_DRAWING; - pString = ::GetOldDrwCat(); + sString = ::GetOldDrwCat(); } if( nPoolId ) { - if( pString && pString->Len()) - m_pCategoryBox->SetText( *pString ); + if (!sString.isEmpty()) + m_pCategoryBox->SetText( sString ); else m_pCategoryBox->SetText( SwStyleNameMapper::GetUIName( nPoolId, aEmptyStr )); diff --git a/sw/source/ui/inc/initui.hxx b/sw/source/ui/inc/initui.hxx index 297bb0bf4b78..c6f0b10f2d37 100644 --- a/sw/source/ui/inc/initui.hxx +++ b/sw/source/ui/inc/initui.hxx @@ -21,6 +21,7 @@ #include "tools/solar.h" #include "swdllapi.h" +#include "rtl/ustring.hxx" #include @@ -35,19 +36,17 @@ class SwThesaurus; */ extern SwThesaurus* pThes; -extern String* pOldGrfCat; -extern String* pOldTabCat; -extern String* pOldFrmCat; - -extern String* pCurrGlosGroup; - -SW_DLLPUBLIC String* GetOldGrfCat(); -SW_DLLPUBLIC String* GetOldTabCat(); -SW_DLLPUBLIC String* GetOldFrmCat(); -SW_DLLPUBLIC String* GetOldDrwCat(); - -SW_DLLPUBLIC String* GetCurrGlosGroup(); -SW_DLLPUBLIC void SetCurrGlosGroup(String* pStr); +SW_DLLPUBLIC OUString GetOldGrfCat(); +SW_DLLPUBLIC void SetOldGrfCat(OUString sStr); +SW_DLLPUBLIC OUString GetOldTabCat(); +SW_DLLPUBLIC void SetOldTabCat(OUString sStr); +SW_DLLPUBLIC OUString GetOldFrmCat(); +SW_DLLPUBLIC void SetOldFrmCat(OUString sStr); +SW_DLLPUBLIC OUString GetOldDrwCat(); +SW_DLLPUBLIC void SetOldDrwCat(OUString sStr); + +SW_DLLPUBLIC OUString GetCurrGlosGroup(); +SW_DLLPUBLIC void SetCurrGlosGroup(OUString sStr); extern std::vector* pDBNameList; diff --git a/sw/source/ui/misc/glossary.cxx b/sw/source/ui/misc/glossary.cxx index 414430d4eb62..4319fcd9dbc5 100644 --- a/sw/source/ui/misc/glossary.cxx +++ b/sw/source/ui/misc/glossary.cxx @@ -159,16 +159,14 @@ SwNewGlosNameDlg::SwNewGlosNameDlg(Window* pParent, ------------------------------------------------------------------------*/ String SwGlossaryDlg::GetCurrGroup() { - if( ::GetCurrGlosGroup() && ::GetCurrGlosGroup()->Len() ) - return *(::GetCurrGlosGroup()); + if( !::GetCurrGlosGroup().isEmpty() ) + return ::GetCurrGlosGroup(); return SwGlossaries::GetDefName(); } void SwGlossaryDlg::SetActGroup(const String &rGrp) { - if( !::GetCurrGlosGroup() ) - ::SetCurrGlosGroup( new String ); - *(::GetCurrGlosGroup()) = rGrp; + ::SetCurrGlosGroup(rGrp); } SwGlossaryDlg::SwGlossaryDlg(SfxViewFrame* pViewFrame, @@ -200,10 +198,6 @@ SwGlossaryDlg::SwGlossaryDlg(SfxViewFrame* pViewFrame, SvtLinguConfig aLocalLinguConfig; - // initialise static-pointer - if( !::GetCurrGlosGroup() ) - ::SetCurrGlosGroup(new String); - PopupMenu *pMenu = m_pEditBtn->GetPopupMenu(); assert(pMenu); pMenu->SetActivateHdl(LINK(this,SwGlossaryDlg,EnableHdl)); @@ -251,11 +245,10 @@ IMPL_LINK( SwGlossaryDlg, GrpSelect, SvTreeListBox *, pBox ) return 0; SvTreeListEntry* pParent = pBox->GetParent(pEntry) ? pBox->GetParent(pEntry) : pEntry; GroupUserData* pGroupData = (GroupUserData*)pParent->GetUserData(); - String *pGlosGroup = ::GetCurrGlosGroup(); - (*pGlosGroup) = pGroupData->sGroupName; - (*pGlosGroup) += GLOS_DELIM; - (*pGlosGroup) += OUString::number(pGroupData->nPathIdx); - pGlossaryHdl->SetCurGroup(*pGlosGroup); + ::SetCurrGlosGroup(pGroupData->sGroupName + + OUString(GLOS_DELIM) + + OUString::number(pGroupData->nPathIdx)); + pGlossaryHdl->SetCurGroup(::GetCurrGlosGroup()); // set current text block bReadOnly = pGlossaryHdl->IsReadOnly(); EnableShortName( !bReadOnly ); @@ -268,7 +261,7 @@ IMPL_LINK( SwGlossaryDlg, GrpSelect, SvTreeListBox *, pBox ) m_pShortNameEdit->SetText(*(String*)pEntry->GetUserData()); pEntry = pBox->GetParent(pEntry); m_pInsertBtn->Enable( !bIsDocReadOnly); - ShowAutoText(*::GetCurrGlosGroup(), m_pShortNameEdit->GetText()); + ShowAutoText(::GetCurrGlosGroup(), m_pShortNameEdit->GetText()); } else ShowAutoText(aEmptyStr, aEmptyStr); @@ -277,10 +270,10 @@ IMPL_LINK( SwGlossaryDlg, GrpSelect, SvTreeListBox *, pBox ) if( SfxRequest::HasMacroRecorder( pSh->GetView().GetViewFrame() ) ) { SfxRequest aReq( pSh->GetView().GetViewFrame(), FN_SET_ACT_GLOSSARY ); - String sTemp(*::GetCurrGlosGroup()); + OUString sTemp(::GetCurrGlosGroup()); // the zeroth path is not being recorded! - if('0' == sTemp.GetToken(1, GLOS_DELIM).GetChar(0)) - sTemp = sTemp.GetToken(0, GLOS_DELIM); + if (sTemp.getToken(1, GLOS_DELIM).startsWith("0")) + sTemp = sTemp.getToken(0, GLOS_DELIM); aReq.AppendItem(SfxStringItem(FN_SET_ACT_GLOSSARY, sTemp)); aReq.Done(); } @@ -294,10 +287,10 @@ void SwGlossaryDlg::Apply() if( SfxRequest::HasMacroRecorder( pSh->GetView().GetViewFrame() ) ) { SfxRequest aReq( pSh->GetView().GetViewFrame(), FN_INSERT_GLOSSARY ); - String sTemp(*::GetCurrGlosGroup()); + OUString sTemp(::GetCurrGlosGroup()); // the zeroth path is not being recorded! - if('0' == sTemp.GetToken(1, GLOS_DELIM).GetChar(0)) - sTemp = sTemp.GetToken(0, GLOS_DELIM); + if (sTemp.getToken(1, GLOS_DELIM).startsWith("0")) + sTemp = sTemp.getToken(0, GLOS_DELIM); aReq.AppendItem(SfxStringItem(FN_INSERT_GLOSSARY, sTemp)); aReq.AppendItem(SfxStringItem(FN_PARAM_1, aGlosName)); aReq.Done(); @@ -454,10 +447,10 @@ IMPL_LINK( SwGlossaryDlg, MenuHdl, Menu *, pMn ) if( SfxRequest::HasMacroRecorder( pSh->GetView().GetViewFrame() ) ) { SfxRequest aReq(pSh->GetView().GetViewFrame(), FN_NEW_GLOSSARY); - String sTemp(*::GetCurrGlosGroup()); + OUString sTemp(::GetCurrGlosGroup()); // the zeroth path is not being recorded! - if('0' == sTemp.GetToken(1, GLOS_DELIM).GetChar(0)) - sTemp = sTemp.GetToken(0, GLOS_DELIM); + if (sTemp.getToken(1, GLOS_DELIM).startsWith("0")) + sTemp = sTemp.getToken(0, GLOS_DELIM); aReq.AppendItem(SfxStringItem(FN_NEW_GLOSSARY, sTemp)); aReq.AppendItem(SfxStringItem(FN_PARAM_1, aShortName)); aReq.AppendItem(SfxStringItem(FN_PARAM_2, aStr)); @@ -674,8 +667,8 @@ void SwGlossaryDlg::Init() // display text block regions const sal_uInt16 nCnt = pGlossaryHdl->GetGroupCnt(); SvTreeListEntry* pSelEntry = 0; - const String sSelStr(::GetCurrGlosGroup()->GetToken(0, GLOS_DELIM)); - const sal_uInt16 nSelPath = static_cast< sal_uInt16 >(::GetCurrGlosGroup()->GetToken(1, GLOS_DELIM).ToInt32()); + const OUString sSelStr(::GetCurrGlosGroup().getToken(0, GLOS_DELIM)); + const sal_uInt16 nSelPath = static_cast< sal_uInt16 >(::GetCurrGlosGroup().getToken(1, GLOS_DELIM).toInt32()); // #i66304# - "My AutoText" comes from mytexts.bau, but should be translated const OUString sMyAutoTextEnglish("My AutoText"); const OUString sMyAutoTextTranslated(SW_RES(STR_MY_AUTOTEXT)); @@ -1073,8 +1066,7 @@ void SwGlossaryDlg::ShowPreview() EX_SHOW_ONLINE_LAYOUT, &aLink ); } - if (::GetCurrGlosGroup()) - ShowAutoText(*::GetCurrGlosGroup(), m_pShortNameEdit->GetText()); + ShowAutoText(::GetCurrGlosGroup(), m_pShortNameEdit->GetText()); }; IMPL_LINK_NOARG(SwGlossaryDlg, PreviewLoadedHdl) diff --git a/sw/source/ui/uiview/viewdlg2.cxx b/sw/source/ui/uiview/viewdlg2.cxx index 2594c8fd7599..e91509dcf828 100644 --- a/sw/source/ui/uiview/viewdlg2.cxx +++ b/sw/source/ui/uiview/viewdlg2.cxx @@ -37,17 +37,13 @@ #include "edtwin.hxx" #include +#include "initui.hxx" #include "swabstdlg.hxx" #include "frmui.hrc" #include "misc.hrc" #include "view.hrc" -extern String* pOldGrfCat; -extern String* pOldTabCat; -extern String* pOldFrmCat; -extern String* pOldDrwCat; - void SwView::ExecDlgExt(SfxRequest &rReq) { Window *pMDI = &GetViewFrame()->GetWindow(); @@ -192,25 +188,16 @@ void SwView::InsertCaption(const InsCaptionOpt *pOpt) } // rember category - String** ppStr = 0; if (eType & nsSelectionType::SEL_GRF) - ppStr = &pOldGrfCat; + SetOldGrfCat(rName); else if( eType & nsSelectionType::SEL_TBL) - ppStr = &pOldTabCat; + SetOldTabCat(rName); else if( eType & nsSelectionType::SEL_FRM) - ppStr = &pOldFrmCat; + SetOldFrmCat(rName); else if( eType == nsSelectionType::SEL_TXT) - ppStr = &pOldFrmCat; + SetOldFrmCat(rName); else if( eType & nsSelectionType::SEL_DRW) - ppStr = &pOldDrwCat; - - if( ppStr ) - { - if( !*ppStr ) - *ppStr = new String( rName ); - else - **ppStr = rName; - } + SetOldDrwCat(rName); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/ui/utlui/initui.cxx b/sw/source/ui/utlui/initui.cxx index 043b650eed63..52fef745d172 100644 --- a/sw/source/ui/utlui/initui.cxx +++ b/sw/source/ui/utlui/initui.cxx @@ -42,35 +42,96 @@ SwGlossaries* pGlossaries = 0; // Provides all needed paths. Is initialized by UI. SwGlossaryList* pGlossaryList = 0; -String* pOldGrfCat = 0; -String* pOldTabCat = 0; -String* pOldFrmCat = 0; -String* pOldDrwCat = 0; -String* pCurrGlosGroup = 0; +namespace +{ + +enum CachedStringID +{ + OldGrfCat, + OldTabCat, + OldFrmCat, + OldDrwCat, + CurrGlosGroup, + CachedStrings +}; + +OUString *StringCache[CachedStrings] = {0}; + +inline OUString GetCachedString(CachedStringID id) +{ + return StringCache[id] ? *StringCache[id] : OUString(); +} + +inline void SetCachedString(CachedStringID id, OUString sStr) +{ + if (StringCache[id]) + { + *StringCache[id] = sStr; + } + else + { + StringCache[id] = new OUString(sStr); + } +} + +void ClearStringCache() +{ + for (int i=0; i* pDBNameList = 0; @@ -97,11 +158,7 @@ void _FinitUI() delete SwFieldType::pFldNames; - delete pOldGrfCat; - delete pOldTabCat; - delete pOldFrmCat; - delete pOldDrwCat; - delete pCurrGlosGroup; + ClearStringCache(); delete pDBNameList; delete pGlossaryList; delete pAuthFieldNameList; -- cgit