LCOV - code coverage report
Current view: top level - basctl/source/basicide - basicbox.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 254 0.0 %
Date: 2014-04-11 Functions: 0 48 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <basidesh.hrc>
      21             : #include <basidesh.hxx>
      22             : #include <basobj.hxx>
      23             : 
      24             : #include <basicbox.hxx>
      25             : #include <iderid.hxx>
      26             : #include <iderdll.hxx>
      27             : #include <bastypes.hxx>
      28             : #include "bastype2.hxx"
      29             : #include "basdoc.hxx"
      30             : 
      31             : #include "localizationmgr.hxx"
      32             : #include "managelang.hxx"
      33             : #include "dlgresid.hrc"
      34             : #include <editeng/unolingu.hxx>
      35             : 
      36             : #include <sfx2/dinfdlg.hxx>
      37             : #include <sfx2/dispatch.hxx>
      38             : #include <svtools/langtab.hxx>
      39             : 
      40             : namespace basctl
      41             : {
      42             : 
      43             : using namespace ::com::sun::star;
      44             : using namespace ::com::sun::star::lang;
      45             : using namespace ::com::sun::star::uno;
      46             : 
      47           0 : SFX_IMPL_TOOLBOX_CONTROL( LibBoxControl, SfxStringItem );
      48             : 
      49           0 : LibBoxControl::LibBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
      50           0 :     : SfxToolBoxControl( nSlotId, nId, rTbx )
      51             : {
      52           0 : }
      53             : 
      54             : 
      55             : 
      56           0 : LibBoxControl::~LibBoxControl()
      57             : {
      58           0 : }
      59             : 
      60             : 
      61             : 
      62           0 : void LibBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
      63             : {
      64           0 :     LibBox* pBox = (LibBox*)GetToolBox().GetItemWindow(GetId());
      65             : 
      66             :     DBG_ASSERT( pBox, "Box not found" );
      67           0 :     if ( !pBox )
      68           0 :         return;
      69             : 
      70           0 :     if ( eState != SFX_ITEM_AVAILABLE )
      71           0 :         pBox->Disable();
      72             :     else
      73             :     {
      74           0 :         pBox->Enable();
      75           0 :         pBox->Update(dynamic_cast<SfxStringItem const*>(pState));
      76             :     }
      77             : }
      78             : 
      79             : 
      80             : 
      81           0 : Window* LibBoxControl::CreateItemWindow( Window *pParent )
      82             : {
      83           0 :     return new LibBox( pParent, m_xFrame );
      84             : }
      85             : 
      86             : 
      87             : //= DocListenerBox
      88             : 
      89             : 
      90           0 : DocListenerBox::DocListenerBox( Window* pParent )
      91             :     :ListBox( pParent, WinBits( WB_BORDER | WB_DROPDOWN ) )
      92           0 :     ,m_aNotifier( *this )
      93             : {
      94           0 : }
      95             : 
      96           0 : DocListenerBox::~DocListenerBox()
      97             : {
      98           0 :     m_aNotifier.dispose();
      99           0 : }
     100             : 
     101           0 : void DocListenerBox::onDocumentCreated( const ScriptDocument& /*_rDocument*/ )
     102             : {
     103           0 :     FillBox();
     104           0 : }
     105             : 
     106           0 : void DocListenerBox::onDocumentOpened( const ScriptDocument& /*_rDocument*/ )
     107             : {
     108           0 :     FillBox();
     109           0 : }
     110             : 
     111           0 : void DocListenerBox::onDocumentSave( const ScriptDocument& /*_rDocument*/ )
     112             : {
     113             :     // not interested in
     114           0 : }
     115             : 
     116           0 : void DocListenerBox::onDocumentSaveDone( const ScriptDocument& /*_rDocument*/ )
     117             : {
     118             :     // not interested in
     119           0 : }
     120             : 
     121           0 : void DocListenerBox::onDocumentSaveAs( const ScriptDocument& /*_rDocument*/ )
     122             : {
     123             :     // not interested in
     124           0 : }
     125             : 
     126           0 : void DocListenerBox::onDocumentSaveAsDone( const ScriptDocument& /*_rDocument*/ )
     127             : {
     128           0 :     FillBox();
     129           0 : }
     130             : 
     131           0 : void DocListenerBox::onDocumentClosed( const ScriptDocument& /*_rDocument*/ )
     132             : {
     133           0 :     FillBox();
     134           0 : }
     135             : 
     136           0 : void DocListenerBox::onDocumentTitleChanged( const ScriptDocument& /*_rDocument*/ )
     137             : {
     138             :     // not interested in
     139           0 : }
     140             : 
     141           0 : void DocListenerBox::onDocumentModeChanged( const ScriptDocument& /*_rDocument*/ )
     142             : {
     143             :     // not interested in
     144           0 : }
     145             : 
     146             : 
     147             : //= basctl::LibBox
     148             : 
     149           0 : LibBox::LibBox( Window* pParent, const uno::Reference< frame::XFrame >& rFrame ) :
     150             :     DocListenerBox( pParent ),
     151           0 :     m_xFrame( rFrame )
     152             : {
     153           0 :     FillBox();
     154           0 :     bIgnoreSelect = true;   // do not yet transfer select of 0
     155           0 :     bFillBox = true;
     156           0 :     SelectEntryPos( 0 );
     157           0 :     aCurText = GetEntry( 0 );
     158           0 :     SetSizePixel( Size( 250, 200 ) );
     159           0 :     bIgnoreSelect = false;
     160           0 : }
     161             : 
     162             : 
     163             : 
     164           0 : LibBox::~LibBox()
     165             : {
     166           0 :     ClearBox();
     167           0 : }
     168             : 
     169           0 : void LibBox::Update( const SfxStringItem* pItem )
     170             : {
     171             : 
     172             : //  if ( !pItem  || !pItem->GetValue().Len() )
     173           0 :         FillBox();
     174             : 
     175           0 :     if ( pItem )
     176             :     {
     177           0 :         aCurText = pItem->GetValue();
     178           0 :         if ( aCurText.isEmpty() )
     179           0 :             aCurText = OUString( IDEResId( RID_STR_ALL ) );
     180             :     }
     181             : 
     182           0 :     if ( GetSelectEntry() != aCurText )
     183           0 :         SelectEntry( aCurText );
     184           0 : }
     185             : 
     186           0 : void LibBox::ReleaseFocus()
     187             : {
     188           0 :     SfxViewShell* pCurSh = SfxViewShell::Current();
     189             :     DBG_ASSERT( pCurSh, "Current ViewShell not found!" );
     190             : 
     191           0 :     if ( pCurSh )
     192             :     {
     193           0 :         Window* pShellWin = pCurSh->GetWindow();
     194           0 :         if ( !pShellWin )
     195           0 :             pShellWin = Application::GetDefDialogParent();
     196             : 
     197           0 :         pShellWin->GrabFocus();
     198             :     }
     199           0 : }
     200             : 
     201           0 : void LibBox::FillBox()
     202             : {
     203           0 :     SetUpdateMode(false);
     204           0 :     bIgnoreSelect = true;
     205             : 
     206           0 :     aCurText = GetSelectEntry();
     207             : 
     208           0 :     SelectEntryPos( 0 );
     209           0 :     ClearBox();
     210             : 
     211             :     // create list box entries
     212           0 :     sal_Int32 nPos = InsertEntry( OUString( IDEResId( RID_STR_ALL ) ), LISTBOX_APPEND );
     213           0 :     SetEntryData( nPos, new LibEntry( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_UNKNOWN, OUString() ) );
     214           0 :     InsertEntries( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_USER );
     215           0 :     InsertEntries( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_SHARE );
     216             : 
     217           0 :     ScriptDocuments aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::DocumentsSorted ) );
     218           0 :     for (   ScriptDocuments::const_iterator doc = aDocuments.begin();
     219           0 :             doc != aDocuments.end();
     220             :             ++doc
     221             :         )
     222             :     {
     223           0 :         InsertEntries( *doc, LIBRARY_LOCATION_DOCUMENT );
     224             :     }
     225             : 
     226           0 :     SetUpdateMode(true);
     227             : 
     228           0 :     SelectEntry( aCurText );
     229           0 :     if ( !GetSelectEntryCount() )
     230             :     {
     231           0 :         SelectEntryPos( GetEntryCount() );
     232           0 :         aCurText = GetSelectEntry();
     233             :     }
     234           0 :     bIgnoreSelect = false;
     235           0 : }
     236             : 
     237           0 : void LibBox::InsertEntries( const ScriptDocument& rDocument, LibraryLocation eLocation )
     238             : {
     239             :     // get a sorted list of library names
     240           0 :     Sequence< OUString > aLibNames = rDocument.getLibraryNames();
     241           0 :     sal_Int32 nLibCount = aLibNames.getLength();
     242           0 :     const OUString* pLibNames = aLibNames.getConstArray();
     243             : 
     244           0 :     for ( sal_Int32 i = 0 ; i < nLibCount ; ++i )
     245             :     {
     246           0 :         OUString aLibName = pLibNames[ i ];
     247           0 :         if ( eLocation == rDocument.getLibraryLocation( aLibName ) )
     248             :         {
     249           0 :             OUString aName( rDocument.getTitle( eLocation ) );
     250           0 :             OUString aEntryText( CreateMgrAndLibStr( aName, aLibName ) );
     251           0 :             sal_Int32 nPos = InsertEntry( aEntryText, LISTBOX_APPEND );
     252           0 :             SetEntryData( nPos, new LibEntry( rDocument, eLocation, aLibName ) );
     253             :         }
     254           0 :     }
     255           0 : }
     256             : 
     257           0 : bool LibBox::PreNotify( NotifyEvent& rNEvt )
     258             : {
     259           0 :     bool nDone = false;
     260           0 :     if( rNEvt.GetType() == EVENT_KEYINPUT )
     261             :     {
     262           0 :         KeyEvent aKeyEvt = *rNEvt.GetKeyEvent();
     263           0 :         sal_uInt16 nKeyCode = aKeyEvt.GetKeyCode().GetCode();
     264           0 :         switch( nKeyCode )
     265             :         {
     266             :             case KEY_RETURN:
     267             :             {
     268           0 :                 NotifyIDE();
     269           0 :                 nDone = true;
     270             :             }
     271           0 :             break;
     272             : 
     273             :             case KEY_ESCAPE:
     274             :             {
     275           0 :                 SelectEntry( aCurText );
     276           0 :                 ReleaseFocus();
     277           0 :                 nDone = true;
     278             :             }
     279           0 :             break;
     280             :         }
     281             :     }
     282           0 :     else if( rNEvt.GetType() == EVENT_GETFOCUS )
     283             :     {
     284           0 :         if ( bFillBox )
     285             :         {
     286           0 :             FillBox();
     287           0 :             bFillBox = false;
     288             :         }
     289             :     }
     290           0 :     else if( rNEvt.GetType() == EVENT_LOSEFOCUS )
     291             :     {
     292           0 :         if ( !HasChildPathFocus(true) )
     293             :         {
     294           0 :             bIgnoreSelect = true;
     295           0 :             bFillBox = true;
     296             :         }
     297             :     }
     298             : 
     299           0 :     return nDone || ListBox::PreNotify( rNEvt );
     300             : }
     301             : 
     302           0 : void LibBox::Select()
     303             : {
     304           0 :     if ( !IsTravelSelect() )
     305             :     {
     306           0 :         if ( !bIgnoreSelect )
     307           0 :             NotifyIDE();
     308             :         else
     309           0 :             SelectEntry( aCurText );    // since 306... (Select after Escape)
     310             :     }
     311           0 : }
     312             : 
     313           0 : void LibBox::NotifyIDE()
     314             : {
     315           0 :     sal_Int32 nSelPos = GetSelectEntryPos();
     316           0 :     if (LibEntry* pEntry = static_cast<LibEntry*>(GetEntryData(nSelPos)))
     317             :     {
     318           0 :         ScriptDocument aDocument( pEntry->GetDocument() );
     319           0 :         SfxUsrAnyItem aDocumentItem( SID_BASICIDE_ARG_DOCUMENT_MODEL, uno::makeAny( aDocument.getDocumentOrNull() ) );
     320           0 :         OUString aLibName = pEntry->GetLibName();
     321           0 :         SfxStringItem aLibNameItem( SID_BASICIDE_ARG_LIBNAME, aLibName );
     322           0 :         if (SfxDispatcher* pDispatcher = GetDispatcher())
     323             :             pDispatcher->Execute(
     324             :                 SID_BASICIDE_LIBSELECTED,
     325             :                 SFX_CALLMODE_SYNCHRON, &aDocumentItem, &aLibNameItem, 0L
     326           0 :             );
     327             :     }
     328           0 :     ReleaseFocus();
     329           0 : }
     330             : 
     331           0 : void LibBox::ClearBox()
     332             : {
     333           0 :     sal_Int32 nCount = GetEntryCount();
     334           0 :     for ( sal_Int32 i = 0; i < nCount; ++i )
     335             :     {
     336           0 :         LibEntry* pEntry = static_cast<LibEntry*>(GetEntryData( i ));
     337           0 :         delete pEntry;
     338             :     }
     339           0 :     ListBox::Clear();
     340           0 : }
     341             : 
     342             : // class LanguageBoxControl ----------------------------------------------
     343             : 
     344           0 : SFX_IMPL_TOOLBOX_CONTROL( LanguageBoxControl, SfxStringItem );
     345             : 
     346           0 : LanguageBoxControl::LanguageBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
     347           0 :     : SfxToolBoxControl( nSlotId, nId, rTbx )
     348             : {
     349           0 : }
     350             : 
     351           0 : LanguageBoxControl::~LanguageBoxControl()
     352             : {
     353           0 : }
     354             : 
     355           0 : void LanguageBoxControl::StateChanged( sal_uInt16 nID, SfxItemState eState, const SfxPoolItem* pItem )
     356             : {
     357             :     (void)nID;
     358           0 :     if (LanguageBox* pBox = static_cast<LanguageBox*>(GetToolBox().GetItemWindow(GetId())))
     359             :     {
     360           0 :         if (eState != SFX_ITEM_AVAILABLE)
     361           0 :             pBox->Disable();
     362             :         else
     363             :         {
     364           0 :             pBox->Enable();
     365           0 :             pBox->Update(dynamic_cast<SfxStringItem const*>(pItem));
     366             :         }
     367             :     }
     368           0 : }
     369             : 
     370           0 : Window* LanguageBoxControl::CreateItemWindow( Window *pParent )
     371             : {
     372           0 :     return new LanguageBox( pParent );
     373             : }
     374             : 
     375             : // class basctl::LanguageBox -----------------------------------------------
     376             : 
     377           0 : LanguageBox::LanguageBox( Window* pParent ) :
     378             : 
     379             :     DocListenerBox( pParent ),
     380             : 
     381             :     m_sNotLocalizedStr( IDEResId( RID_STR_TRANSLATION_NOTLOCALIZED ) ),
     382             :     m_sDefaultLanguageStr( IDEResId( RID_STR_TRANSLATION_DEFAULT ) ),
     383             : 
     384           0 :     m_bIgnoreSelect( false )
     385             : 
     386             : {
     387           0 :     SetSizePixel( Size( 210, 200 ) );
     388             : 
     389           0 :     FillBox();
     390           0 : }
     391             : 
     392           0 : LanguageBox::~LanguageBox()
     393             : {
     394           0 :     ClearBox();
     395           0 : }
     396             : 
     397           0 : void LanguageBox::FillBox()
     398             : {
     399           0 :     SetUpdateMode(false);
     400           0 :     m_bIgnoreSelect = true;
     401           0 :     m_sCurrentText = GetSelectEntry();
     402           0 :     ClearBox();
     403             : 
     404           0 :     boost::shared_ptr<LocalizationMgr> pCurMgr(GetShell()->GetCurLocalizationMgr());
     405           0 :     if ( pCurMgr->isLibraryLocalized() )
     406             :     {
     407           0 :         Enable();
     408           0 :         SvtLanguageTable aLangTable;
     409           0 :         Locale aDefaultLocale = pCurMgr->getStringResourceManager()->getDefaultLocale();
     410           0 :         Locale aCurrentLocale = pCurMgr->getStringResourceManager()->getCurrentLocale();
     411           0 :         Sequence< Locale > aLocaleSeq = pCurMgr->getStringResourceManager()->getLocales();
     412           0 :         const Locale* pLocale = aLocaleSeq.getConstArray();
     413           0 :         sal_Int32 i, nCount = aLocaleSeq.getLength();
     414           0 :         sal_Int32 nSelPos = LISTBOX_ENTRY_NOTFOUND;
     415           0 :         for ( i = 0;  i < nCount;  ++i )
     416             :         {
     417           0 :             bool bIsDefault = localesAreEqual( aDefaultLocale, pLocale[i] );
     418           0 :             bool bIsCurrent = localesAreEqual( aCurrentLocale, pLocale[i] );
     419           0 :             LanguageType eLangType = LanguageTag::convertToLanguageType( pLocale[i] );
     420           0 :             OUString sLanguage = aLangTable.GetString( eLangType );
     421           0 :             if ( bIsDefault )
     422             :             {
     423           0 :                 sLanguage += " ";
     424           0 :                 sLanguage += m_sDefaultLanguageStr;
     425             :             }
     426           0 :             sal_Int32 nPos = InsertEntry( sLanguage );
     427           0 :             SetEntryData( nPos, new LanguageEntry( sLanguage, pLocale[i], bIsDefault ) );
     428             : 
     429           0 :             if ( bIsCurrent )
     430           0 :                 nSelPos = nPos;
     431           0 :         }
     432             : 
     433           0 :         if ( nSelPos != LISTBOX_ENTRY_NOTFOUND )
     434             :         {
     435           0 :             SelectEntryPos( nSelPos );
     436           0 :             m_sCurrentText = GetSelectEntry();
     437           0 :         }
     438             :     }
     439             :     else
     440             :     {
     441           0 :         InsertEntry( m_sNotLocalizedStr );
     442           0 :         SelectEntryPos(0);
     443           0 :         Disable();
     444             :     }
     445             : 
     446           0 :     SetUpdateMode(true);
     447           0 :     m_bIgnoreSelect = false;
     448           0 : }
     449             : 
     450           0 : void LanguageBox::ClearBox()
     451             : {
     452           0 :     sal_Int32 nCount = GetEntryCount();
     453           0 :     for ( sal_Int32 i = 0; i < nCount; ++i )
     454             :     {
     455           0 :         LanguageEntry* pEntry = (LanguageEntry*)GetEntryData(i);
     456           0 :         delete pEntry;
     457             :     }
     458           0 :     ListBox::Clear();
     459           0 : }
     460             : 
     461           0 : void LanguageBox::SetLanguage()
     462             : {
     463           0 :     LanguageEntry* pEntry = (LanguageEntry*)GetEntryData( GetSelectEntryPos() );
     464           0 :     if ( pEntry )
     465           0 :         GetShell()->GetCurLocalizationMgr()->handleSetCurrentLocale( pEntry->m_aLocale );
     466           0 : }
     467             : 
     468           0 : void LanguageBox::Select()
     469             : {
     470           0 :     if ( !m_bIgnoreSelect )
     471           0 :         SetLanguage();
     472             :     else
     473           0 :         SelectEntry( m_sCurrentText );  // Select after Escape
     474           0 : }
     475             : 
     476           0 : bool LanguageBox::PreNotify( NotifyEvent& rNEvt )
     477             : {
     478           0 :     bool nDone = false;
     479           0 :     if( rNEvt.GetType() == EVENT_KEYINPUT )
     480             :     {
     481           0 :         sal_uInt16 nKeyCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
     482           0 :         switch( nKeyCode )
     483             :         {
     484             :             case KEY_RETURN:
     485             :             {
     486           0 :                 SetLanguage();
     487           0 :                 nDone = true;
     488             :             }
     489           0 :             break;
     490             : 
     491             :             case KEY_ESCAPE:
     492             :             {
     493           0 :                 SelectEntry( m_sCurrentText );
     494           0 :                 nDone = true;
     495             :             }
     496           0 :             break;
     497             :         }
     498             :     }
     499           0 :     else if( rNEvt.GetType() == EVENT_GETFOCUS )
     500             :     {
     501             :     }
     502           0 :     else if( rNEvt.GetType() == EVENT_LOSEFOCUS )
     503             :     {
     504             :     }
     505             : 
     506           0 :     return nDone || ListBox::PreNotify( rNEvt );
     507             : }
     508             : 
     509           0 : void LanguageBox::Update( const SfxStringItem* pItem )
     510             : {
     511           0 :     FillBox();
     512             : 
     513           0 :     if ( pItem && !pItem->GetValue().isEmpty() )
     514             :     {
     515           0 :         m_sCurrentText = pItem->GetValue();
     516           0 :         if ( GetSelectEntry() != m_sCurrentText )
     517           0 :             SelectEntry( m_sCurrentText );
     518             :     }
     519           0 : }
     520             : 
     521             : 
     522           0 : } // namespace basctl
     523             : 
     524             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10