1*2ee96f1cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2ee96f1cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2ee96f1cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2ee96f1cSAndrew Rist * distributed with this work for additional information 6*2ee96f1cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2ee96f1cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2ee96f1cSAndrew Rist * "License"); you may not use this file except in compliance 9*2ee96f1cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*2ee96f1cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*2ee96f1cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2ee96f1cSAndrew Rist * software distributed under the License is distributed on an 15*2ee96f1cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2ee96f1cSAndrew Rist * KIND, either express or implied. See the License for the 17*2ee96f1cSAndrew Rist * specific language governing permissions and limitations 18*2ee96f1cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*2ee96f1cSAndrew Rist *************************************************************/ 21*2ee96f1cSAndrew Rist 22*2ee96f1cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_cui.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir // include --------------------------------------------------------------- 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <stdio.h> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #define _CUI_CHARMAP_CXX_ 32cdf0e10cSrcweir #include <tools/shl.hxx> 33cdf0e10cSrcweir #include <tools/debug.hxx> 34cdf0e10cSrcweir #include <vcl/sound.hxx> 35cdf0e10cSrcweir #include <vcl/svapp.hxx> 36cdf0e10cSrcweir #include <vcl/msgbox.hxx> 37cdf0e10cSrcweir #include <svtools/colorcfg.hxx> 38cdf0e10cSrcweir #include <svl/eitem.hxx> 39cdf0e10cSrcweir #include <svl/intitem.hxx> 40cdf0e10cSrcweir #include <svl/stritem.hxx> 41cdf0e10cSrcweir #include <svl/itempool.hxx> 42cdf0e10cSrcweir 43cdf0e10cSrcweir #include <rtl/textenc.h> 44cdf0e10cSrcweir #include <svx/ucsubset.hxx> 45cdf0e10cSrcweir 46cdf0e10cSrcweir #include <cuires.hrc> 47cdf0e10cSrcweir #include <dialmgr.hxx> 48cdf0e10cSrcweir #include "cuicharmap.hxx" 49cdf0e10cSrcweir #include <sfx2/request.hxx> 50cdf0e10cSrcweir #include <sfx2/sfxsids.hrc> 51cdf0e10cSrcweir #include <sfx2/app.hxx> 52cdf0e10cSrcweir #include <editeng/fontitem.hxx> 53cdf0e10cSrcweir #include "charmap.hrc" 54cdf0e10cSrcweir #include "macroass.hxx" 55cdf0e10cSrcweir 56cdf0e10cSrcweir // class SvxCharacterMap ================================================= 57cdf0e10cSrcweir 58cdf0e10cSrcweir SvxCharacterMap::SvxCharacterMap( Window* pParent, sal_Bool bOne, const SfxItemSet* pSet ) : 59cdf0e10cSrcweir SfxModalDialog( pParent, CUI_RES( RID_SVXDLG_CHARMAP ) ), 60cdf0e10cSrcweir mpCharMapData( 0 ) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pItem, SfxBoolItem, FN_PARAM_1, sal_False ); 63cdf0e10cSrcweir if ( pItem ) 64cdf0e10cSrcweir bOne = pItem->GetValue(); 65cdf0e10cSrcweir 66cdf0e10cSrcweir mpCharMapData = new SvxCharMapData( this, bOne, &CUI_MGR() ); 67cdf0e10cSrcweir 68cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pCharItem, SfxInt32Item, SID_ATTR_CHAR, sal_False ); 69cdf0e10cSrcweir if ( pCharItem ) 70cdf0e10cSrcweir SetChar( pCharItem->GetValue() ); 71cdf0e10cSrcweir 72cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pDisableItem, SfxBoolItem, FN_PARAM_2, sal_False ); 73cdf0e10cSrcweir if ( pDisableItem && pDisableItem->GetValue() ) 74cdf0e10cSrcweir DisableFontSelection(); 75cdf0e10cSrcweir 76cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, sal_False ); 77cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pFontNameItem, SfxStringItem, SID_FONT_NAME, sal_False ); 78cdf0e10cSrcweir if ( pFontItem ) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir Font aFont( pFontItem->GetFamilyName(), pFontItem->GetStyleName(), GetCharFont().GetSize() ); 81cdf0e10cSrcweir aFont.SetCharSet( pFontItem->GetCharSet() ); 82cdf0e10cSrcweir aFont.SetPitch( pFontItem->GetPitch() ); 83cdf0e10cSrcweir SetCharFont( aFont ); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir else if ( pFontNameItem ) 86cdf0e10cSrcweir { 87cdf0e10cSrcweir Font aFont( GetCharFont() ); 88cdf0e10cSrcweir aFont.SetName( pFontNameItem->GetValue() ); 89cdf0e10cSrcweir SetCharFont( aFont ); 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir FreeResource(); 93cdf0e10cSrcweir CreateOutputItemSet( pSet ? *pSet->GetPool() : SFX_APP()->GetPool() ); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir // ----------------------------------------------------------------------- 97cdf0e10cSrcweir 98cdf0e10cSrcweir SvxCharacterMap::~SvxCharacterMap() 99cdf0e10cSrcweir { 100cdf0e10cSrcweir delete mpCharMapData; 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir // ----------------------------------------------------------------------- 104cdf0e10cSrcweir 105cdf0e10cSrcweir const Font& SvxCharacterMap::GetCharFont() const 106cdf0e10cSrcweir { 107cdf0e10cSrcweir return mpCharMapData->aFont; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 110cdf0e10cSrcweir // ----------------------------------------------------------------------- 111cdf0e10cSrcweir 112cdf0e10cSrcweir void SvxCharacterMap::SetChar( sal_UCS4 c ) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir mpCharMapData->aShowSet.SelectCharacter( c ); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir // ----------------------------------------------------------------------- 118cdf0e10cSrcweir 119cdf0e10cSrcweir sal_UCS4 SvxCharacterMap::GetChar() const 120cdf0e10cSrcweir { 121cdf0e10cSrcweir return mpCharMapData->aShowSet.GetSelectCharacter(); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir // ----------------------------------------------------------------------- 125cdf0e10cSrcweir 126cdf0e10cSrcweir String SvxCharacterMap::GetCharacters() const 127cdf0e10cSrcweir { 128cdf0e10cSrcweir return mpCharMapData->aShowText.GetText(); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir 132cdf0e10cSrcweir // ----------------------------------------------------------------------- 133cdf0e10cSrcweir 134cdf0e10cSrcweir void SvxCharacterMap::DisableFontSelection() 135cdf0e10cSrcweir { 136cdf0e10cSrcweir mpCharMapData->aFontText.Disable(); 137cdf0e10cSrcweir mpCharMapData->aFontLB.Disable(); 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir void SvxCharacterMap::SetCharFont( const Font& rFont ) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir mpCharMapData->SetCharFont( rFont ); 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir short SvxCharacterMap::Execute() 146cdf0e10cSrcweir { 147cdf0e10cSrcweir short nResult = SfxModalDialog::Execute(); 148cdf0e10cSrcweir if ( nResult == RET_OK ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir SfxItemSet* pSet = GetItemSet(); 151cdf0e10cSrcweir if ( pSet ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir const SfxItemPool* pPool = pSet->GetPool(); 154cdf0e10cSrcweir const Font& rFont( GetCharFont() ); 155cdf0e10cSrcweir pSet->Put( SfxStringItem( pPool->GetWhich(SID_CHARMAP), GetCharacters() ) ); 156cdf0e10cSrcweir pSet->Put( SvxFontItem( rFont.GetFamily(), rFont.GetName(), 157cdf0e10cSrcweir rFont.GetStyleName(), rFont.GetPitch(), rFont.GetCharSet(), pPool->GetWhich(SID_ATTR_CHAR_FONT) ) ); 158cdf0e10cSrcweir pSet->Put( SfxStringItem( pPool->GetWhich(SID_FONT_NAME), rFont.GetName() ) ); 159cdf0e10cSrcweir pSet->Put( SfxInt32Item( pPool->GetWhich(SID_ATTR_CHAR), GetChar() ) ); 160cdf0e10cSrcweir } 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir return nResult; 164cdf0e10cSrcweir } 165cdf0e10cSrcweir 166cdf0e10cSrcweir 167cdf0e10cSrcweir // class SvxShowText ===================================================== 168cdf0e10cSrcweir 169cdf0e10cSrcweir SvxShowText::SvxShowText( Window* pParent, const ResId& rResId, sal_Bool bCenter ) 170cdf0e10cSrcweir : Control( pParent, rResId ), 171cdf0e10cSrcweir mbCenter( bCenter) 172cdf0e10cSrcweir {} 173cdf0e10cSrcweir 174cdf0e10cSrcweir // ----------------------------------------------------------------------- 175cdf0e10cSrcweir 176cdf0e10cSrcweir void SvxShowText::Paint( const Rectangle& ) 177cdf0e10cSrcweir { 178cdf0e10cSrcweir Color aTextCol = GetTextColor(); 179cdf0e10cSrcweir 180cdf0e10cSrcweir const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); 181cdf0e10cSrcweir const Color aWindowTextColor( rStyleSettings.GetDialogTextColor() ); 182cdf0e10cSrcweir SetTextColor( aWindowTextColor ); 183cdf0e10cSrcweir 184cdf0e10cSrcweir const String aText = GetText(); 185cdf0e10cSrcweir const Size aSize = GetOutputSizePixel(); 186cdf0e10cSrcweir Point aPoint( 2, mnY ); 187cdf0e10cSrcweir 188cdf0e10cSrcweir // adjust position using ink boundary if possible 189cdf0e10cSrcweir Rectangle aBoundRect; 190cdf0e10cSrcweir if( !GetTextBoundRect( aBoundRect, aText ) || aBoundRect.IsEmpty() ) 191cdf0e10cSrcweir aPoint.X() = (aSize.Width() - GetTextWidth( aText )) / 2; 192cdf0e10cSrcweir else 193cdf0e10cSrcweir { 194cdf0e10cSrcweir // adjust position before it gets out of bounds 195cdf0e10cSrcweir aBoundRect += aPoint; 196cdf0e10cSrcweir 197cdf0e10cSrcweir // shift back vertically if needed 198cdf0e10cSrcweir int nYLDelta = aBoundRect.Top(); 199cdf0e10cSrcweir int nYHDelta = aSize.Height() - aBoundRect.Bottom(); 200cdf0e10cSrcweir if( nYLDelta <= 0 ) 201cdf0e10cSrcweir aPoint.Y() -= nYLDelta - 1; 202cdf0e10cSrcweir else if( nYHDelta <= 0 ) 203cdf0e10cSrcweir aPoint.Y() += nYHDelta - 1; 204cdf0e10cSrcweir 205cdf0e10cSrcweir if( mbCenter ) 206cdf0e10cSrcweir { 207cdf0e10cSrcweir // move glyph to middle of cell 208cdf0e10cSrcweir aPoint.X() = -aBoundRect.Left() 209cdf0e10cSrcweir + (aSize.Width() - aBoundRect.GetWidth()) / 2; 210cdf0e10cSrcweir } 211cdf0e10cSrcweir else 212cdf0e10cSrcweir { 213cdf0e10cSrcweir // shift back horizontally if needed 214cdf0e10cSrcweir int nXLDelta = aBoundRect.Left(); 215cdf0e10cSrcweir int nXHDelta = aSize.Width() - aBoundRect.Right(); 216cdf0e10cSrcweir if( nXLDelta <= 0 ) 217cdf0e10cSrcweir aPoint.X() -= nXLDelta - 1; 218cdf0e10cSrcweir else if( nXHDelta <= 0 ) 219cdf0e10cSrcweir aPoint.X() += nXHDelta - 1; 220cdf0e10cSrcweir } 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir DrawText( aPoint, aText ); 224cdf0e10cSrcweir SetTextColor( aTextCol ); 225cdf0e10cSrcweir } 226cdf0e10cSrcweir 227cdf0e10cSrcweir // ----------------------------------------------------------------------- 228cdf0e10cSrcweir 229cdf0e10cSrcweir void SvxShowText::SetFont( const Font& rFont ) 230cdf0e10cSrcweir { 231cdf0e10cSrcweir long nWinHeight = GetOutputSizePixel().Height(); 232cdf0e10cSrcweir Font aFont = rFont; 233cdf0e10cSrcweir aFont.SetWeight( WEIGHT_NORMAL ); 234cdf0e10cSrcweir aFont.SetAlign( ALIGN_TOP ); 235cdf0e10cSrcweir aFont.SetSize( PixelToLogic( Size( 0, nWinHeight/2 ) ) ); 236cdf0e10cSrcweir aFont.SetTransparent( sal_True ); 237cdf0e10cSrcweir Control::SetFont( aFont ); 238cdf0e10cSrcweir mnY = ( nWinHeight - GetTextHeight() ) / 2; 239cdf0e10cSrcweir 240cdf0e10cSrcweir Invalidate(); 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir // ----------------------------------------------------------------------- 244cdf0e10cSrcweir 245cdf0e10cSrcweir void SvxShowText::SetText( const String& rText ) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir Control::SetText( rText ); 248cdf0e10cSrcweir Invalidate(); 249cdf0e10cSrcweir } 250cdf0e10cSrcweir 251cdf0e10cSrcweir // ----------------------------------------------------------------------- 252cdf0e10cSrcweir 253cdf0e10cSrcweir SvxShowText::~SvxShowText() 254cdf0e10cSrcweir {} 255cdf0e10cSrcweir 256cdf0e10cSrcweir // class SvxCharacterMap ================================================= 257cdf0e10cSrcweir 258cdf0e10cSrcweir SvxCharMapData::SvxCharMapData( SfxModalDialog* pDialog, sal_Bool bOne_, ResMgr* pResContext ) 259cdf0e10cSrcweir : mpDialog( pDialog ), 260cdf0e10cSrcweir aShowSet ( pDialog, ResId( CT_SHOWSET, *pResContext ) ), 261cdf0e10cSrcweir aShowText ( pDialog, ResId( CT_SHOWTEXT, *pResContext ) ), 262cdf0e10cSrcweir // aShowShortcut ( pDialog, ResId( CT_ASSIGN, *pResContext ) ), 263cdf0e10cSrcweir aOKBtn ( pDialog, ResId( BTN_CHAR_OK, *pResContext ) ), 264cdf0e10cSrcweir aCancelBtn ( pDialog, ResId( BTN_CHAR_CANCEL, *pResContext ) ), 265cdf0e10cSrcweir aHelpBtn ( pDialog, ResId( BTN_CHAR_HELP, *pResContext ) ), 266cdf0e10cSrcweir aDeleteBtn ( pDialog, ResId( BTN_DELETE, *pResContext ) ), 267cdf0e10cSrcweir // aAssignBtn ( pDialog, ResId( BT_ASSIGN, *pResContext ) ), 268cdf0e10cSrcweir aFontText ( pDialog, ResId( FT_FONT, *pResContext ) ), 269cdf0e10cSrcweir aFontLB ( pDialog, ResId( LB_FONT, *pResContext ) ), 270cdf0e10cSrcweir aSubsetText ( pDialog, ResId( FT_SUBSET, *pResContext ) ), 271cdf0e10cSrcweir aSubsetLB ( pDialog, ResId( LB_SUBSET, *pResContext ) ), 272cdf0e10cSrcweir aSymbolText ( pDialog, ResId( FT_SYMBOLE, *pResContext ) ), 273cdf0e10cSrcweir aShowChar ( pDialog, ResId( CT_SHOWCHAR, *pResContext ), sal_True ), 274cdf0e10cSrcweir aCharCodeText ( pDialog, ResId( FT_CHARCODE, *pResContext ) ), 275cdf0e10cSrcweir // aAssignText ( pDialog, ResId( FT_ASSIGN, *pResContext ) ), 276cdf0e10cSrcweir bOne( bOne_ ), 277cdf0e10cSrcweir pSubsetMap( NULL ) 278cdf0e10cSrcweir { 279cdf0e10cSrcweir aFont = pDialog->GetFont(); 280cdf0e10cSrcweir aFont.SetTransparent( sal_True ); 281cdf0e10cSrcweir aFont.SetFamily( FAMILY_DONTKNOW ); 282cdf0e10cSrcweir aFont.SetPitch( PITCH_DONTKNOW ); 283cdf0e10cSrcweir aFont.SetCharSet( RTL_TEXTENCODING_DONTKNOW ); 284cdf0e10cSrcweir 285cdf0e10cSrcweir if ( bOne ) 286cdf0e10cSrcweir { 287cdf0e10cSrcweir Size aDlgSize = pDialog->GetSizePixel(); 288cdf0e10cSrcweir pDialog->SetSizePixel( Size( aDlgSize.Width(), 289cdf0e10cSrcweir aDlgSize.Height()-aShowText.GetSizePixel().Height() ) ); 290cdf0e10cSrcweir aSymbolText.Hide(); 291cdf0e10cSrcweir aShowText.Hide(); 292cdf0e10cSrcweir aDeleteBtn.Hide(); 293cdf0e10cSrcweir } 294cdf0e10cSrcweir 295cdf0e10cSrcweir String aDefStr( aFont.GetName() ); 296cdf0e10cSrcweir String aLastName; 297cdf0e10cSrcweir int nCount = mpDialog->GetDevFontCount(); 298cdf0e10cSrcweir for ( int i = 0; i < nCount; i++ ) 299cdf0e10cSrcweir { 300cdf0e10cSrcweir String aFontName( mpDialog->GetDevFont( i ).GetName() ); 301cdf0e10cSrcweir if ( aFontName != aLastName ) 302cdf0e10cSrcweir { 303cdf0e10cSrcweir aLastName = aFontName; 304cdf0e10cSrcweir sal_uInt16 nPos = aFontLB.InsertEntry( aFontName ); 305cdf0e10cSrcweir aFontLB.SetEntryData( nPos, (void*)(sal_uLong)i ); 306cdf0e10cSrcweir } 307cdf0e10cSrcweir } 308cdf0e10cSrcweir // the font may not be in the list => 309cdf0e10cSrcweir // try to find a font name token in list and select found font, 310cdf0e10cSrcweir // else select topmost entry 311cdf0e10cSrcweir FASTBOOL bFound = (aFontLB.GetEntryPos( aDefStr ) == LISTBOX_ENTRY_NOTFOUND ); 312cdf0e10cSrcweir if( !bFound ) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir for ( xub_StrLen i = 0; i < aDefStr.GetTokenCount(); ++i ) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir String aToken = aDefStr.GetToken(i); 317cdf0e10cSrcweir if ( aFontLB.GetEntryPos( aToken ) != LISTBOX_ENTRY_NOTFOUND ) 318cdf0e10cSrcweir { 319cdf0e10cSrcweir aDefStr = aToken; 320cdf0e10cSrcweir bFound = sal_True; 321cdf0e10cSrcweir break; 322cdf0e10cSrcweir } 323cdf0e10cSrcweir } 324cdf0e10cSrcweir } 325cdf0e10cSrcweir 326cdf0e10cSrcweir if ( bFound ) 327cdf0e10cSrcweir aFontLB.SelectEntry( aDefStr ); 328cdf0e10cSrcweir else if ( aFontLB.GetEntryCount() ) 329cdf0e10cSrcweir aFontLB.SelectEntryPos(0); 330cdf0e10cSrcweir FontSelectHdl( &aFontLB ); 331cdf0e10cSrcweir 332cdf0e10cSrcweir aOKBtn.SetClickHdl( LINK( this, SvxCharMapData, OKHdl ) ); 333cdf0e10cSrcweir aFontLB.SetSelectHdl( LINK( this, SvxCharMapData, FontSelectHdl ) ); 334cdf0e10cSrcweir aSubsetLB.SetSelectHdl( LINK( this, SvxCharMapData, SubsetSelectHdl ) ); 335cdf0e10cSrcweir aShowSet.SetDoubleClickHdl( LINK( this, SvxCharMapData, CharDoubleClickHdl ) ); 336cdf0e10cSrcweir aShowSet.SetSelectHdl( LINK( this, SvxCharMapData, CharSelectHdl ) ); 337cdf0e10cSrcweir aShowSet.SetHighlightHdl( LINK( this, SvxCharMapData, CharHighlightHdl ) ); 338cdf0e10cSrcweir aShowSet.SetPreSelectHdl( LINK( this, SvxCharMapData, CharPreSelectHdl ) ); 339cdf0e10cSrcweir aDeleteBtn.SetClickHdl( LINK( this, SvxCharMapData, DeleteHdl ) ); 340cdf0e10cSrcweir // aAssignBtn.SetClickHdl( LINK( this, SvxCharMapData, AssignHdl ) ); 341cdf0e10cSrcweir 342cdf0e10cSrcweir if( SvxShowCharSet::getSelectedChar() == ' ') 343cdf0e10cSrcweir aOKBtn.Disable(); 344cdf0e10cSrcweir else 345cdf0e10cSrcweir aOKBtn.Enable(); 346cdf0e10cSrcweir 347cdf0e10cSrcweir // left align aShowText field 348cdf0e10cSrcweir int nLeftEdge = aSymbolText.GetPosPixel().X(); 349cdf0e10cSrcweir nLeftEdge += aSymbolText.GetTextWidth( aSymbolText.GetText() ); 350cdf0e10cSrcweir Size aNewSize = aShowText.GetOutputSizePixel(); 351cdf0e10cSrcweir aShowText.SetPosPixel( Point( nLeftEdge+4, aShowText.GetPosPixel().Y() ) ); 352cdf0e10cSrcweir } 353cdf0e10cSrcweir 354cdf0e10cSrcweir // ----------------------------------------------------------------------- 355cdf0e10cSrcweir 356cdf0e10cSrcweir void SvxCharMapData::SetCharFont( const Font& rFont ) 357cdf0e10cSrcweir { 358cdf0e10cSrcweir // first get the underlying info in order to get font names 359cdf0e10cSrcweir // like "Times New Roman;Times" resolved 360cdf0e10cSrcweir Font aTmp( mpDialog->GetFontMetric( rFont ) ); 361cdf0e10cSrcweir 362cdf0e10cSrcweir if ( aFontLB.GetEntryPos( aTmp.GetName() ) == LISTBOX_ENTRY_NOTFOUND ) 363cdf0e10cSrcweir return; 364cdf0e10cSrcweir 365cdf0e10cSrcweir aFontLB.SelectEntry( aTmp.GetName() ); 366cdf0e10cSrcweir aFont = aTmp; 367cdf0e10cSrcweir FontSelectHdl( &aFontLB ); 368cdf0e10cSrcweir 369cdf0e10cSrcweir // for compatibility reasons 370cdf0e10cSrcweir mpDialog->ModalDialog::SetFont( aFont ); 371cdf0e10cSrcweir } 372cdf0e10cSrcweir 373cdf0e10cSrcweir // ----------------------------------------------------------------------- 374cdf0e10cSrcweir 375cdf0e10cSrcweir IMPL_LINK( SvxCharMapData, OKHdl, OKButton *, EMPTYARG ) 376cdf0e10cSrcweir { 377cdf0e10cSrcweir String aStr = aShowText.GetText(); 378cdf0e10cSrcweir 379cdf0e10cSrcweir if ( !aStr.Len() ) 380cdf0e10cSrcweir { 381cdf0e10cSrcweir sal_UCS4 cChar = aShowSet.GetSelectCharacter(); 382cdf0e10cSrcweir // using the new UCS4 constructor 383cdf0e10cSrcweir rtl::OUString aOUStr( &cChar, 1 ); 384cdf0e10cSrcweir aShowText.SetText( aOUStr ); 385cdf0e10cSrcweir } 386cdf0e10cSrcweir mpDialog->EndDialog( sal_True ); 387cdf0e10cSrcweir return 0; 388cdf0e10cSrcweir } 389cdf0e10cSrcweir 390cdf0e10cSrcweir // ----------------------------------------------------------------------- 391cdf0e10cSrcweir 392cdf0e10cSrcweir IMPL_LINK( SvxCharMapData, FontSelectHdl, ListBox *, EMPTYARG ) 393cdf0e10cSrcweir { 394cdf0e10cSrcweir sal_uInt16 nPos = aFontLB.GetSelectEntryPos(), 395cdf0e10cSrcweir nFont = (sal_uInt16)(sal_uLong)aFontLB.GetEntryData( nPos ); 396cdf0e10cSrcweir aFont = mpDialog->GetDevFont( nFont ); 397cdf0e10cSrcweir aFont.SetWeight( WEIGHT_DONTKNOW ); 398cdf0e10cSrcweir aFont.SetItalic( ITALIC_NONE ); 399cdf0e10cSrcweir aFont.SetWidthType( WIDTH_DONTKNOW ); 400cdf0e10cSrcweir aFont.SetPitch( PITCH_DONTKNOW ); 401cdf0e10cSrcweir aFont.SetFamily( FAMILY_DONTKNOW ); 402cdf0e10cSrcweir 403cdf0e10cSrcweir // notify children using this font 404cdf0e10cSrcweir aShowSet.SetFont( aFont ); 405cdf0e10cSrcweir aShowChar.SetFont( aFont ); 406cdf0e10cSrcweir aShowText.SetFont( aFont ); 407cdf0e10cSrcweir 408cdf0e10cSrcweir // right align some fields to aShowSet 409cdf0e10cSrcweir int nRightEdge = aShowSet.GetPosPixel().X() + aShowSet.GetOutputSizePixel().Width(); 410cdf0e10cSrcweir Size aNewSize = aSubsetLB.GetOutputSizePixel(); 411cdf0e10cSrcweir aNewSize.setWidth( nRightEdge - aSubsetLB.GetPosPixel().X() ); 412cdf0e10cSrcweir aSubsetLB.SetOutputSizePixel( aNewSize ); 413cdf0e10cSrcweir 414cdf0e10cSrcweir // setup unicode subset listbar with font specific subsets, 415cdf0e10cSrcweir // hide unicode subset listbar for symbol fonts 416cdf0e10cSrcweir // TODO: get info from the Font once it provides it 417cdf0e10cSrcweir if( pSubsetMap) 418cdf0e10cSrcweir delete pSubsetMap; 419cdf0e10cSrcweir pSubsetMap = NULL; 420cdf0e10cSrcweir 421cdf0e10cSrcweir sal_Bool bNeedSubset = (aFont.GetCharSet() != RTL_TEXTENCODING_SYMBOL); 422cdf0e10cSrcweir if( bNeedSubset ) 423cdf0e10cSrcweir { 424cdf0e10cSrcweir FontCharMap aFontCharMap; 425cdf0e10cSrcweir aShowSet.GetFontCharMap( aFontCharMap ); 426cdf0e10cSrcweir pSubsetMap = new SubsetMap( &aFontCharMap ); 427cdf0e10cSrcweir 428cdf0e10cSrcweir // update subset listbox for new font's unicode subsets 429cdf0e10cSrcweir aSubsetLB.Clear(); 430cdf0e10cSrcweir // TODO: is it worth to improve the stupid linear search? 431cdf0e10cSrcweir bool bFirst = true; 432cdf0e10cSrcweir const Subset* s; 433cdf0e10cSrcweir while( NULL != (s = pSubsetMap->GetNextSubset( bFirst )) ) 434cdf0e10cSrcweir { 435cdf0e10cSrcweir sal_uInt16 nPos_ = aSubsetLB.InsertEntry( s->GetName() ); 436cdf0e10cSrcweir aSubsetLB.SetEntryData( nPos_, (void*)s ); 437cdf0e10cSrcweir // NOTE: subset must live at least as long as the selected font 438cdf0e10cSrcweir if( bFirst ) 439cdf0e10cSrcweir aSubsetLB.SelectEntryPos( nPos_ ); 440cdf0e10cSrcweir bFirst = false; 441cdf0e10cSrcweir } 442cdf0e10cSrcweir if( aSubsetLB.GetEntryCount() <= 1 ) 443cdf0e10cSrcweir bNeedSubset = sal_False; 444cdf0e10cSrcweir } 445cdf0e10cSrcweir 446cdf0e10cSrcweir aSubsetText.Show( bNeedSubset); 447cdf0e10cSrcweir aSubsetLB.Show( bNeedSubset); 448cdf0e10cSrcweir 449cdf0e10cSrcweir return 0; 450cdf0e10cSrcweir } 451cdf0e10cSrcweir 452cdf0e10cSrcweir // ----------------------------------------------------------------------- 453cdf0e10cSrcweir 454cdf0e10cSrcweir IMPL_LINK( SvxCharMapData, SubsetSelectHdl, ListBox *, EMPTYARG ) 455cdf0e10cSrcweir { 456cdf0e10cSrcweir sal_uInt16 nPos = aSubsetLB.GetSelectEntryPos(); 457cdf0e10cSrcweir const Subset* pSubset = reinterpret_cast<const Subset*> (aSubsetLB.GetEntryData(nPos)); 458cdf0e10cSrcweir if( pSubset ) 459cdf0e10cSrcweir { 460cdf0e10cSrcweir sal_UCS4 cFirst = pSubset->GetRangeMin(); 461cdf0e10cSrcweir aShowSet.SelectCharacter( cFirst ); 462cdf0e10cSrcweir } 463cdf0e10cSrcweir aSubsetLB.SelectEntryPos( nPos ); 464cdf0e10cSrcweir return 0; 465cdf0e10cSrcweir } 466cdf0e10cSrcweir 467cdf0e10cSrcweir // ----------------------------------------------------------------------- 468cdf0e10cSrcweir 469cdf0e10cSrcweir IMPL_LINK( SvxCharMapData, CharDoubleClickHdl, Control *, EMPTYARG ) 470cdf0e10cSrcweir { 471cdf0e10cSrcweir mpDialog->EndDialog( sal_True ); 472cdf0e10cSrcweir return 0; 473cdf0e10cSrcweir } 474cdf0e10cSrcweir 475cdf0e10cSrcweir // ----------------------------------------------------------------------- 476cdf0e10cSrcweir 477cdf0e10cSrcweir IMPL_LINK( SvxCharMapData, CharSelectHdl, Control *, EMPTYARG ) 478cdf0e10cSrcweir { 479cdf0e10cSrcweir if ( !bOne ) 480cdf0e10cSrcweir { 481cdf0e10cSrcweir String aText = aShowText.GetText(); 482cdf0e10cSrcweir 483cdf0e10cSrcweir if ( aText.Len() == CHARMAP_MAXLEN ) 484cdf0e10cSrcweir Sound::Beep( SOUND_WARNING ); 485cdf0e10cSrcweir else 486cdf0e10cSrcweir { 487cdf0e10cSrcweir sal_UCS4 cChar = aShowSet.GetSelectCharacter(); 488cdf0e10cSrcweir // using the new UCS4 constructor 489cdf0e10cSrcweir rtl::OUString aOUStr( &cChar, 1 ); 490cdf0e10cSrcweir aShowText.SetText( aText + aOUStr ); 491cdf0e10cSrcweir } 492cdf0e10cSrcweir 493cdf0e10cSrcweir } 494cdf0e10cSrcweir aOKBtn.Enable(); 495cdf0e10cSrcweir return 0; 496cdf0e10cSrcweir } 497cdf0e10cSrcweir 498cdf0e10cSrcweir // ----------------------------------------------------------------------- 499cdf0e10cSrcweir 500cdf0e10cSrcweir IMPL_LINK( SvxCharMapData, CharHighlightHdl, Control *, EMPTYARG ) 501cdf0e10cSrcweir { 502cdf0e10cSrcweir String aText; 503cdf0e10cSrcweir sal_UCS4 cChar = aShowSet.GetSelectCharacter(); 504cdf0e10cSrcweir sal_Bool bSelect = (cChar > 0); 505cdf0e10cSrcweir 506cdf0e10cSrcweir // show char sample 507cdf0e10cSrcweir if ( bSelect ) 508cdf0e10cSrcweir { 509cdf0e10cSrcweir // using the new UCS4 constructor 510cdf0e10cSrcweir aText = rtl::OUString( &cChar, 1 ); 511cdf0e10cSrcweir 512cdf0e10cSrcweir const Subset* pSubset = NULL; 513cdf0e10cSrcweir if( pSubsetMap ) 514cdf0e10cSrcweir pSubset = pSubsetMap->GetSubsetByUnicode( cChar ); 515cdf0e10cSrcweir if( pSubset ) 516cdf0e10cSrcweir aSubsetLB.SelectEntry( pSubset->GetName() ); 517cdf0e10cSrcweir else 518cdf0e10cSrcweir aSubsetLB.SetNoSelection(); 519cdf0e10cSrcweir } 520cdf0e10cSrcweir aShowChar.SetText( aText ); 521cdf0e10cSrcweir aShowChar.Update(); 522cdf0e10cSrcweir 523cdf0e10cSrcweir // show char code 524cdf0e10cSrcweir if ( bSelect ) 525cdf0e10cSrcweir { 526cdf0e10cSrcweir char aBuf[32]; 527cdf0e10cSrcweir snprintf( aBuf, sizeof(aBuf), "U+%04X", static_cast<unsigned>(cChar) ); 528cdf0e10cSrcweir if( cChar < 0x0100 ) 529cdf0e10cSrcweir snprintf( aBuf+6, sizeof(aBuf)-6, " (%u)", static_cast<unsigned>(cChar) ); 530cdf0e10cSrcweir aText = String::CreateFromAscii( aBuf ); 531cdf0e10cSrcweir } 532cdf0e10cSrcweir aCharCodeText.SetText( aText ); 533cdf0e10cSrcweir 534cdf0e10cSrcweir return 0; 535cdf0e10cSrcweir } 536cdf0e10cSrcweir 537cdf0e10cSrcweir // ----------------------------------------------------------------------- 538cdf0e10cSrcweir 539cdf0e10cSrcweir IMPL_LINK( SvxCharMapData, CharPreSelectHdl, Control *, EMPTYARG ) 540cdf0e10cSrcweir { 541cdf0e10cSrcweir // adjust subset selection 542cdf0e10cSrcweir if( pSubsetMap ) 543cdf0e10cSrcweir { 544cdf0e10cSrcweir sal_UCS4 cChar = aShowSet.GetSelectCharacter(); 545cdf0e10cSrcweir const Subset* pSubset = pSubsetMap->GetSubsetByUnicode( cChar ); 546cdf0e10cSrcweir if( pSubset ) 547cdf0e10cSrcweir aSubsetLB.SelectEntry( pSubset->GetName() ); 548cdf0e10cSrcweir } 549cdf0e10cSrcweir 550cdf0e10cSrcweir aOKBtn.Enable(); 551cdf0e10cSrcweir return 0; 552cdf0e10cSrcweir } 553cdf0e10cSrcweir 554cdf0e10cSrcweir // ----------------------------------------------------------------------- 555cdf0e10cSrcweir 556cdf0e10cSrcweir IMPL_LINK( SvxCharMapData, DeleteHdl, PushButton *, EMPTYARG ) 557cdf0e10cSrcweir { 558cdf0e10cSrcweir aShowText.SetText( String() ); 559cdf0e10cSrcweir aOKBtn.Disable(); 560cdf0e10cSrcweir return 0; 561cdf0e10cSrcweir } 562cdf0e10cSrcweir 563cdf0e10cSrcweir #include <sfx2/objsh.hxx> 564cdf0e10cSrcweir #include <vcl/msgbox.hxx> 565cdf0e10cSrcweir #include <svl/stritem.hxx> 566cdf0e10cSrcweir 567cdf0e10cSrcweir IMPL_LINK( SvxCharMapData, AssignHdl, PushButton *, EMPTYARG ) 568cdf0e10cSrcweir { 569cdf0e10cSrcweir SfxAllItemSet aSet( SfxObjectShell::Current()->GetPool() ); 570cdf0e10cSrcweir aSet.Put( SfxStringItem( SID_CHARMAP, String::CreateFromAscii("test") ) ); 571cdf0e10cSrcweir SfxModalDialog* pDlg = new SfxMacroAssignDlg( mpDialog, com::sun::star::uno::Reference < com::sun::star::frame::XFrame >(), aSet ); 572cdf0e10cSrcweir if ( pDlg && pDlg->Execute() == RET_OK ) 573cdf0e10cSrcweir { 574cdf0e10cSrcweir const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); 575cdf0e10cSrcweir const SfxPoolItem* pItem; 576cdf0e10cSrcweir if( SFX_ITEM_SET == pOutSet->GetItemState( SID_CHARMAP, sal_False, &pItem ) ) 577cdf0e10cSrcweir { 578cdf0e10cSrcweir // show assigned shortcut 579cdf0e10cSrcweir } 580cdf0e10cSrcweir } 581cdf0e10cSrcweir 582cdf0e10cSrcweir delete pDlg; 583cdf0e10cSrcweir 584cdf0e10cSrcweir return 0; 585cdf0e10cSrcweir } 586