diff options
author | Michael Meeks <michael.meeks@suse.com> | 2011-11-07 14:01:16 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2011-11-07 14:19:35 +0000 |
commit | 6de32a1afc947e71754f4266d5c167eccbc8f78b (patch) | |
tree | 5aabd10edf675cd4a2a1e43f51b40cfab194dc04 /vcl/unx | |
parent | 6aa51640706ca332e6439e6097cc81a2b1dbb275 (diff) |
gtk: cleanup resource provider and associated lifecycle issue
Diffstat (limited to 'vcl/unx')
-rw-r--r-- | vcl/unx/gtk/fpicker/SalGtkFilePicker.cxx | 29 | ||||
-rw-r--r-- | vcl/unx/gtk/fpicker/SalGtkFolderPicker.cxx | 5 | ||||
-rw-r--r-- | vcl/unx/gtk/fpicker/SalGtkPicker.cxx | 34 | ||||
-rw-r--r-- | vcl/unx/gtk/fpicker/SalGtkPicker.hxx | 14 | ||||
-rw-r--r-- | vcl/unx/gtk/fpicker/resourceprovider.cxx | 56 | ||||
-rw-r--r-- | vcl/unx/gtk/fpicker/resourceprovider.hxx | 69 |
6 files changed, 40 insertions, 167 deletions
diff --git a/vcl/unx/gtk/fpicker/SalGtkFilePicker.cxx b/vcl/unx/gtk/fpicker/SalGtkFilePicker.cxx index fb88175d8e00..853931634c4a 100644 --- a/vcl/unx/gtk/fpicker/SalGtkFilePicker.cxx +++ b/vcl/unx/gtk/fpicker/SalGtkFilePicker.cxx @@ -56,7 +56,6 @@ #include <set> #include <string.h> -#include "gtk/fpicker/resourceprovider.hxx" #include "gtk/fpicker/SalGtkFilePicker.hxx" //------------------------------------------------------------------------ @@ -147,8 +146,7 @@ SalGtkFilePicker::SalGtkFilePicker( const uno::Reference< uno::XComponentContext mbListVisibility[i] = false; } - CResourceProvider aResProvider; - OUString aFilePickerTitle = aResProvider.getResString( FILE_PICKER_TITLE_OPEN ); + OUString aFilePickerTitle = getResString( FILE_PICKER_TITLE_OPEN ); m_pDialog = gtk_file_chooser_dialog_new( OUStringToOString( aFilePickerTitle, RTL_TEXTENCODING_UTF8 ).getStr(), @@ -182,7 +180,7 @@ SalGtkFilePicker::SalGtkFilePicker( const uno::Reference< uno::XComponentContext #define LABEL_TOGGLE( elem ) \ case elem : \ - aLabel = aResProvider.getResString( CHECKBOX_##elem ); \ + aLabel = getResString( CHECKBOX_##elem ); \ setLabel( CHECKBOX_##elem, aLabel ); \ break @@ -222,7 +220,7 @@ SalGtkFilePicker::SalGtkFilePicker( const uno::Reference< uno::XComponentContext #define LABEL_LIST( elem ) \ case elem : \ - aLabel = aResProvider.getResString( LISTBOX_##elem##_LABEL ); \ + aLabel = getResString( LISTBOX_##elem##_LABEL ); \ setLabel( LISTBOX_##elem##_LABEL, aLabel ); \ break @@ -244,7 +242,7 @@ SalGtkFilePicker::SalGtkFilePicker( const uno::Reference< uno::XComponentContext gtk_box_pack_end( GTK_BOX( m_pVBox ), m_pHBoxs[i], sal_False, sal_False, 0 ); } - aLabel = aResProvider.getResString( FILE_PICKER_FILE_TYPE ); + aLabel = getResString( FILE_PICKER_FILE_TYPE ); m_pFilterExpander = gtk_expander_new_with_mnemonic( OUStringToOString( aLabel, RTL_TEXTENCODING_UTF8 ).getStr()); @@ -1006,10 +1004,7 @@ sal_Int16 SAL_CALL SalGtkFilePicker::execute() throw( uno::RuntimeException ) OString sFileName = unicodetouri( aPathSeq[0] ); if( g_file_test( g_filename_from_uri( sFileName.getStr(), NULL, NULL ), G_FILE_TEST_IS_REGULAR ) ) { - CResourceProvider aResProvider; GtkWidget *dlg; - - INetURLObject aFileObj( sFileName ); OString baseName( @@ -1024,7 +1019,7 @@ sal_Int16 SAL_CALL SalGtkFilePicker::execute() throw( uno::RuntimeException ) ); OString aMsg( OUStringToOString( - aResProvider.getResString( FILE_PICKER_OVERWRITE ), + getResString( FILE_PICKER_OVERWRITE ), RTL_TEXTENCODING_UTF8 ) ); @@ -1045,7 +1040,7 @@ sal_Int16 SAL_CALL SalGtkFilePicker::execute() throw( uno::RuntimeException ) ); gtk_window_set_title( GTK_WINDOW( dlg ), - OUStringToOString(aResProvider.getResString(FILE_PICKER_TITLE_SAVE ), + OUStringToOString(getResString(FILE_PICKER_TITLE_SAVE ), RTL_TEXTENCODING_UTF8 ).getStr() ); RunDialog* pAnotherDialog = new RunDialog(dlg, xToolkit, xDesktop); @@ -1486,8 +1481,7 @@ void SAL_CALL SalGtkFilePicker::setImage( sal_Int16 /*aImageFormat*/, const uno: void SalGtkFilePicker::implChangeType( GtkTreeSelection *selection ) { - CResourceProvider aResProvider; - OUString aLabel = aResProvider.getResString( FILE_PICKER_FILE_TYPE ); + OUString aLabel = getResString( FILE_PICKER_FILE_TYPE ); GtkTreeIter iter; GtkTreeModel *model; @@ -1734,8 +1728,7 @@ void SAL_CALL SalGtkFilePicker::initialize( const uno::Sequence<uno::Any>& aArgu if( GTK_FILE_CHOOSER_ACTION_SAVE == eAction ) { - CResourceProvider aResProvider; - OUString aFilePickerTitle(aResProvider.getResString( FILE_PICKER_TITLE_SAVE )); + OUString aFilePickerTitle(getResString( FILE_PICKER_TITLE_SAVE )); gtk_window_set_title ( GTK_WINDOW( m_pDialog ), OUStringToOString( aFilePickerTitle, RTL_TEXTENCODING_UTF8 ).getStr() ); } @@ -1750,8 +1743,7 @@ void SAL_CALL SalGtkFilePicker::initialize( const uno::Sequence<uno::Any>& aArgu #ifdef GTK_STOCK_MEDIA_PLAY m_pButtons[ nTVIndex ] = gtk_dialog_add_button( GTK_DIALOG( m_pDialog ), GTK_STOCK_MEDIA_PLAY, 1 ); #else - CResourceProvider aResProvider; - OString aPlay = OUStringToOString( aResProvider.getResString( PUSHBUTTON_PLAY ), RTL_TEXTENCODING_UTF8 ); + OString aPlay = OUStringToOString( getResString( PUSHBUTTON_PLAY ), RTL_TEXTENCODING_UTF8 ); m_pButtons[ nTVIndex ] = gtk_dialog_add_button( GTK_DIALOG( m_pDialog ), aPlay.getStr(), 1 ); #endif } @@ -1969,8 +1961,7 @@ void SalGtkFilePicker::SetFilters() sAllFilter += OUString(sal_Unicode(';')); sAllFilter += *aIter; } - CResourceProvider aResProvider; - sPseudoFilter = aResProvider.getResString(FILE_PICKER_ALLFORMATS); + sPseudoFilter = getResString(FILE_PICKER_ALLFORMATS); m_pPseudoFilter = implAddFilter( sPseudoFilter, sAllFilter ); } } diff --git a/vcl/unx/gtk/fpicker/SalGtkFolderPicker.cxx b/vcl/unx/gtk/fpicker/SalGtkFolderPicker.cxx index f4e2476cedd6..e40101f9af84 100644 --- a/vcl/unx/gtk/fpicker/SalGtkFolderPicker.cxx +++ b/vcl/unx/gtk/fpicker/SalGtkFolderPicker.cxx @@ -45,7 +45,6 @@ #include <osl/mutex.hxx> #include <vcl/svapp.hxx> #include "unx/gtk/gtkinst.hxx" -#include "gtk/fpicker/resourceprovider.hxx" #include "gtk/fpicker/SalGtkFolderPicker.hxx" #include <string.h> @@ -62,10 +61,8 @@ using namespace ::com::sun::star::uno; SalGtkFolderPicker::SalGtkFolderPicker( const uno::Reference< uno::XComponentContext >& xContext ) : SalGtkPicker( xContext ) { - CResourceProvider aResProvider; - m_pDialog = gtk_file_chooser_dialog_new( - OUStringToOString( aResProvider.getResString( FOLDERPICKER_TITLE ), RTL_TEXTENCODING_UTF8 ).getStr(), + OUStringToOString( getResString( FOLDERPICKER_TITLE ), RTL_TEXTENCODING_UTF8 ).getStr(), NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, (char *)NULL ); diff --git a/vcl/unx/gtk/fpicker/SalGtkPicker.cxx b/vcl/unx/gtk/fpicker/SalGtkPicker.cxx index 7146b99f6b20..dc951a54addc 100644 --- a/vcl/unx/gtk/fpicker/SalGtkPicker.cxx +++ b/vcl/unx/gtk/fpicker/SalGtkPicker.cxx @@ -57,10 +57,6 @@ #include "unx/gtk/gtkframe.hxx" #include "gtk/fpicker/SalGtkPicker.hxx" -//------------------------------------------------------------------------ -// namespace directives -//------------------------------------------------------------------------ - using namespace ::rtl; using namespace ::com::sun::star; using namespace ::com::sun::star::lang; @@ -203,29 +199,17 @@ void SalGtkPicker::setGtkLanguage() if (bSet) return; - OUString sUILocale; - try - { - uno::Reference<lang::XMultiComponentFactory> xConfigMgr( - createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.ConfigurationProvider"))), - UNO_QUERY_THROW ); - - Sequence< Any > theArgs(1); - theArgs[ 0 ] <<= OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Linguistic/General")); - - uno::Reference< container::XNameAccess > xNameAccess = - uno::Reference< container::XNameAccess >(xConfigMgr->createInstanceWithArgumentsAndContext( - OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.ConfigurationAccess")), theArgs, m_xContext ), UNO_QUERY_THROW ); - - if (xNameAccess.is()) - xNameAccess->getByName(OUString(RTL_CONSTASCII_USTRINGPARAM("UILocale"))) >>= sUILocale; - } catch (...) {} + ::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILocale(); + rtl::OUStringBuffer aBuffer; + aBuffer.append( aLocale.Language ); + aBuffer.appendAscii( "_" ); + aBuffer.append( aLocale.Country ); + aBuffer.appendAscii( ".UTF-8" ); - if (sUILocale.getLength()) + if (aBuffer.getLength() > 8) { - sUILocale = sUILocale.replace('-', '_'); - rtl::OUString envVar(RTL_CONSTASCII_USTRINGPARAM("LANGUAGE")); - osl_setEnvironment(envVar.pData, sUILocale.pData); + rtl::OUString envVar( RTL_CONSTASCII_USTRINGPARAM( "LANGUAGE" ) ); + osl_setEnvironment( envVar.pData, aBuffer.makeStringAndClear().pData ); } bSet = true; } diff --git a/vcl/unx/gtk/fpicker/SalGtkPicker.hxx b/vcl/unx/gtk/fpicker/SalGtkPicker.hxx index 760021d36b52..a4fe68f98309 100644 --- a/vcl/unx/gtk/fpicker/SalGtkPicker.hxx +++ b/vcl/unx/gtk/fpicker/SalGtkPicker.hxx @@ -49,9 +49,13 @@ #include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> -//---------------------------------------------------------- -// class declaration -//---------------------------------------------------------- +#define FOLDERPICKER_TITLE 500 +#define FOLDER_PICKER_DEF_DESCRIPTION 501 +#define FILE_PICKER_TITLE_OPEN 502 +#define FILE_PICKER_TITLE_SAVE 503 +#define FILE_PICKER_FILE_TYPE 504 +#define FILE_PICKER_OVERWRITE 505 +#define FILE_PICKER_ALLFORMATS 506 class SalGtkPicker { @@ -73,9 +77,11 @@ class SalGtkPicker rtl::OUString uritounicode(const gchar *pIn); rtl::OString unicodetouri(const rtl::OUString &rURL); - // to instanciate own services + // to instantiate own services ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; ::com::sun::star::uno::Reference< com::sun::star::uno::XInterface > createInstance( const rtl::OUString &rName ); + + rtl::OUString getResString( sal_Int32 aId ); private: void setGtkLanguage(); }; diff --git a/vcl/unx/gtk/fpicker/resourceprovider.cxx b/vcl/unx/gtk/fpicker/resourceprovider.cxx index 5d19d789afc9..b12d4e1f99da 100644 --- a/vcl/unx/gtk/fpicker/resourceprovider.cxx +++ b/vcl/unx/gtk/fpicker/resourceprovider.cxx @@ -27,7 +27,6 @@ ************************************************************************/ #include <osl/diagnose.h> -#include "resourceprovider.hxx" #include <vcl/svapp.hxx> #include <tools/resmgr.hxx> #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> @@ -35,6 +34,7 @@ #include "svids.hrc" #include "svdata.hxx" +#include "gtk/fpicker/SalGtkPicker.hxx" using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds; using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds; @@ -77,55 +77,19 @@ static sal_Int16 CtrlIdToResId( sal_Int32 aControlId ) return -1; } -class CResourceProvider_Impl +rtl::OUString SalGtkPicker::getResString( sal_Int32 aId ) { -public: - CResourceProvider_Impl( ) + rtl::OUString aResString; + try { - m_ResMgr = ImplGetResMgr(); + // translate the control id to a resource id + sal_Int16 aResId = CtrlIdToResId( aId ); + if ( aResId > -1 ) + aResString = String( ResId( aResId, *ImplGetResMgr() ) ); } + catch(...) { } - ~CResourceProvider_Impl( ) - { - delete m_ResMgr; - } - - rtl::OUString getResString( sal_Int16 aId ) - { - OSL_ASSERT( m_ResMgr ); - - String aResString; - try - { - // translate the control id to a resource id - sal_Int16 aResId = CtrlIdToResId( aId ); - if ( aResId > -1 ) - aResString = String( ResId( aResId, *m_ResMgr ) ); - } - catch(...) - { - } - - return rtl::OUString( aResString ); - } - -public: - ResMgr* m_ResMgr; -}; - -CResourceProvider::CResourceProvider( ) : - m_pImpl( new CResourceProvider_Impl() ) -{ -} - -CResourceProvider::~CResourceProvider( ) -{ - delete m_pImpl; -} - -rtl::OUString CResourceProvider::getResString( sal_Int32 aId ) -{ - return m_pImpl->getResString( aId ).replace('~', '_'); + return aResString.replace('~', '_'); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/gtk/fpicker/resourceprovider.hxx b/vcl/unx/gtk/fpicker/resourceprovider.hxx deleted file mode 100644 index 5bbbbfd68e7e..000000000000 --- a/vcl/unx/gtk/fpicker/resourceprovider.hxx +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - - -#ifndef _RESOURCEPROVIDER_HXX_ -#define _RESOURCEPROVIDER_HXX_ - -//------------------------------------------------------------------------ -// includes -//------------------------------------------------------------------------ - -#include <sal/types.h> - -#include <rtl/ustring.hxx> - -#define FOLDERPICKER_TITLE 500 -#define FOLDER_PICKER_DEF_DESCRIPTION 501 -#define FILE_PICKER_TITLE_OPEN 502 -#define FILE_PICKER_TITLE_SAVE 503 -#define FILE_PICKER_FILE_TYPE 504 -#define FILE_PICKER_OVERWRITE 505 -#define FILE_PICKER_ALLFORMATS 506 - -//------------------------------------------------------------------------ -// deklarations -//------------------------------------------------------------------------ - -class CResourceProvider_Impl; - -class CResourceProvider -{ -public: - CResourceProvider( ); - ~CResourceProvider( ); - - rtl::OUString getResString( sal_Int32 aId ); - -private: - CResourceProvider_Impl* m_pImpl; -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |