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