1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 29*cdf0e10cSrcweir // my own includes 30*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include "fltdlg.hxx" 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #ifndef UUI_IDS_HRC 35*cdf0e10cSrcweir #include "ids.hrc" 36*cdf0e10cSrcweir #endif 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #ifndef UUI_FLTDLG_HRC 39*cdf0e10cSrcweir #include "fltdlg.hrc" 40*cdf0e10cSrcweir #endif 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 43*cdf0e10cSrcweir // includes of other projects 44*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 45*cdf0e10cSrcweir #include <com/sun/star/util/XStringWidth.hpp> 46*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 47*cdf0e10cSrcweir #include <unotools/localfilehelper.hxx> 48*cdf0e10cSrcweir #include <tools/list.hxx> 49*cdf0e10cSrcweir #include <tools/urlobj.hxx> 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir #ifndef _BUTTON_HXX //autogen 52*cdf0e10cSrcweir #include <vcl/button.hxx> 53*cdf0e10cSrcweir #endif 54*cdf0e10cSrcweir #include <vos/mutex.hxx> 55*cdf0e10cSrcweir #include <vcl/svapp.hxx> 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir namespace uui 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir /*-************************************************************************************************************//** 61*cdf0e10cSrcweir @short initialize filter dialog with start values 62*cdf0e10cSrcweir @descr We set some neccessary informations on these instance for later working and create internal structures. 63*cdf0e10cSrcweir After construction user should call "SetFilters()" and "SetURL()" to fill listbox with selectable filter 64*cdf0e10cSrcweir names and set file name of file, which should be used for selected filter. 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir @seealso method SetFilters() 67*cdf0e10cSrcweir @seealso method SetURL() 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir @param "pParentWindow" , parent window for dialog 70*cdf0e10cSrcweir @param "pResMgr" , ressource manager 71*cdf0e10cSrcweir @return - 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir @onerror - 74*cdf0e10cSrcweir @threadsafe no 75*cdf0e10cSrcweir *//*-*************************************************************************************************************/ 76*cdf0e10cSrcweir FilterDialog::FilterDialog( Window* pParentWindow , 77*cdf0e10cSrcweir ResMgr* pResMgr ) 78*cdf0e10cSrcweir : ModalDialog ( pParentWindow, ResId( DLG_FILTER_SELECT, *pResMgr ) ) 79*cdf0e10cSrcweir , m_ftURL ( this, ResId( FT_URL, *pResMgr ) ) 80*cdf0e10cSrcweir , m_lbFilters ( this, ResId( LB_FILTERS, *pResMgr ) ) 81*cdf0e10cSrcweir , m_btnOK ( this, ResId( BTN_OK, *pResMgr ) ) 82*cdf0e10cSrcweir , m_btnCancel ( this, ResId( BTN_CANCEL, *pResMgr ) ) 83*cdf0e10cSrcweir , m_btnHelp ( this, ResId( BTN_HELP, *pResMgr ) ) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir FreeResource(); 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir /*-************************************************************************************************************//** 89*cdf0e10cSrcweir @short set file name on dialog control 90*cdf0e10cSrcweir @descr We convert given URL (it must be an URL!) into valid file name and show it on our dialog. 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir @seealso - 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir @param "sURL", URL for showing 95*cdf0e10cSrcweir @return - 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir @onerror - 98*cdf0e10cSrcweir @threadsafe no 99*cdf0e10cSrcweir *//*-*************************************************************************************************************/ 100*cdf0e10cSrcweir void FilterDialog::SetURL( const String& sURL ) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir // convert it and use given pure string as fallback if convertion failed 103*cdf0e10cSrcweir m_ftURL.SetText( impl_buildUIFileName(sURL) ); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir /*-************************************************************************************************************//** 107*cdf0e10cSrcweir @short change list of filter names 108*cdf0e10cSrcweir @descr We save given pointer internal and use it to fill our listbox with given names. 109*cdf0e10cSrcweir Saved list pointer is used on method "AskForFilter()" too, to find user selected item 110*cdf0e10cSrcweir and return pointer into these list as result of operation. 111*cdf0e10cSrcweir So it's possible to call dialog again and again for different or same filter list 112*cdf0e10cSrcweir and ask user for his decision by best performance! 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir @attention Don't free memory of given list after this call till object will die ... or 115*cdf0e10cSrcweir you call "ChangeFilters( NULL )"! Then we forget it too. 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir @seealso method AskForFilter() 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir @param "pFilterNames", pointer to list of filter names, which should be used for later operations. 120*cdf0e10cSrcweir @return - 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir @onerror We clear list box and forget our currently set filter informations completly! 123*cdf0e10cSrcweir @threadsafe no 124*cdf0e10cSrcweir *//*-*************************************************************************************************************/ 125*cdf0e10cSrcweir void FilterDialog::ChangeFilters( const FilterNameList* pFilterNames ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir m_pFilterNames = pFilterNames; 128*cdf0e10cSrcweir m_lbFilters.Clear(); 129*cdf0e10cSrcweir if( m_pFilterNames != NULL ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir for( FilterNameListPtr pItem = m_pFilterNames->begin(); 132*cdf0e10cSrcweir pItem != m_pFilterNames->end() ; 133*cdf0e10cSrcweir ++pItem ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir m_lbFilters.InsertEntry( pItem->sUI ); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir /*-************************************************************************************************************//** 141*cdf0e10cSrcweir @short ask user for his decision 142*cdf0e10cSrcweir @descr We show the dialog and if user finish it with "OK" - we try to find selected item in internal saved 143*cdf0e10cSrcweir name list (which you must set in "ChangeFilters()"!). If we return sal_True as result, you can use out 144*cdf0e10cSrcweir parameter "pSelectedItem" as pointer into your FilterNameList to get selected item realy ... 145*cdf0e10cSrcweir but if we return sal_False ... user hsa cancel the dialog ... you shouldnt do that. pSelectedItem isnt 146*cdf0e10cSrcweir set to any valid value then. We don't change them ... 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir @seealso method ChangeFilters() 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir @param "pSelectedItem", returns result of selection as pointer into set list of filter names 151*cdf0e10cSrcweir (valid for function return sal_True only!) 152*cdf0e10cSrcweir @return true => pSelectedItem parameter points into name list and represent use decision 153*cdf0e10cSrcweir false => use has cancelled dialog (pSelectedItem isnt valid then!) 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir @onerror We return false ... but don't change pSelectedItem! 156*cdf0e10cSrcweir @threadsafe no 157*cdf0e10cSrcweir *//*-*************************************************************************************************************/ 158*cdf0e10cSrcweir bool FilterDialog::AskForFilter( FilterNameListPtr& pSelectedItem ) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir bool bSelected = sal_False; 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir if( m_pFilterNames != NULL ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir if( ModalDialog::Execute() == RET_OK ) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir String sEntry = m_lbFilters.GetSelectEntry(); 167*cdf0e10cSrcweir if( sEntry.Len() > 0 ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir int nPos = m_lbFilters.GetSelectEntryPos(); 170*cdf0e10cSrcweir if( nPos < (int)(m_pFilterNames->size()) ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir pSelectedItem = m_pFilterNames->begin(); 173*cdf0e10cSrcweir pSelectedItem += nPos; 174*cdf0e10cSrcweir bSelected = ( pSelectedItem != m_pFilterNames->end() ); 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir return bSelected; 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir /*-************************************************************************************************************//** 184*cdf0e10cSrcweir @short helper class to calculate length of given string 185*cdf0e10cSrcweir @descr Instances of it can be used as callback for INetURLObject::getAbbreviated() method to build 186*cdf0e10cSrcweir short URLs to show it on GUI. We use in ctor set OutputDevice to call special VCL method ... 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir @seealso method OutputDevice::GetTextWidth() 189*cdf0e10cSrcweir @seealso method InetURLObject::getAbbreviated() 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir @param - 192*cdf0e10cSrcweir @return - 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir @onerror - 195*cdf0e10cSrcweir @threadsafe no 196*cdf0e10cSrcweir *//*-*************************************************************************************************************/ 197*cdf0e10cSrcweir class StringCalculator : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XStringWidth > 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir public: 200*cdf0e10cSrcweir StringCalculator( const OutputDevice* pDevice ) 201*cdf0e10cSrcweir : m_pDevice( pDevice ) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir sal_Int32 SAL_CALL queryStringWidth( const ::rtl::OUString& sString ) throw( ::com::sun::star::uno::RuntimeException ) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir return (sal_Int32)(m_pDevice->GetTextWidth(String(sString))); 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir private: 211*cdf0e10cSrcweir const OutputDevice* m_pDevice; 212*cdf0e10cSrcweir }; 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir /*-************************************************************************************************************//** 215*cdf0e10cSrcweir @short try to build short name of given URL to show it n GUI 216*cdf0e10cSrcweir @descr We detect type of given URL automaticly and build this short name depend on this type ... 217*cdf0e10cSrcweir If we couldnt make it right we return full given string without any changes ... 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir @seealso class LocalFileHelper 220*cdf0e10cSrcweir @seealso method InetURLObject::getAbbreviated() 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir @param "sName", file name 223*cdf0e10cSrcweir @return A short file name ... 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir @onerror We return given name without any changes. 226*cdf0e10cSrcweir @threadsafe no 227*cdf0e10cSrcweir *//*-*************************************************************************************************************/ 228*cdf0e10cSrcweir String FilterDialog::impl_buildUIFileName( const String& sName ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir String sShortName( sName ); 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir if( ::utl::LocalFileHelper::ConvertURLToSystemPath( sName, sShortName ) == sal_True ) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir // its a system file ... build short name by using osl functionality 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir else 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir // otherwise its realy a url ... build short name by using INetURLObject 239*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::util::XStringWidth > xStringCalculator( new StringCalculator(&m_ftURL) ); 240*cdf0e10cSrcweir if( xStringCalculator.is() == sal_True ) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir INetURLObject aBuilder ( sName ); 243*cdf0e10cSrcweir Size aSize = m_ftURL.GetOutputSize(); 244*cdf0e10cSrcweir sShortName = aBuilder.getAbbreviated( xStringCalculator, aSize.Width(), INetURLObject::DECODE_UNAMBIGUOUS ); 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir return sShortName; 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir } // namespace uui 252