xref: /trunk/main/svx/source/dialog/charmap.cxx (revision f6e50924346d0b8c0b07c91832a97665dd718b0c)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // include ---------------------------------------------------------------
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <stdio.h>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #define _SVX_CHARMAP_CXX_
32cdf0e10cSrcweir #include <vcl/svapp.hxx>
33cdf0e10cSrcweir #include <svtools/colorcfg.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <rtl/textenc.h>
36cdf0e10cSrcweir #include <svx/ucsubset.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <svx/dialogs.hrc>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <svx/charmap.hxx>
41cdf0e10cSrcweir #include <svx/dialmgr.hxx>
42cdf0e10cSrcweir #include <svx/svxdlg.hxx>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include "charmapacc.hxx"
45cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
46cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
47cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
48cdf0e10cSrcweir #include <comphelper/types.hxx>
49cdf0e10cSrcweir #include <svl/itemset.hxx>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
52cdf0e10cSrcweir 
53cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
54cdf0e10cSrcweir using namespace ::com::sun::star::uno;
55cdf0e10cSrcweir using namespace ::com::sun::star;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir // -----------------------------------------------------------------------
58cdf0e10cSrcweir sal_uInt32& SvxShowCharSet::getSelectedChar()
59cdf0e10cSrcweir {
60cdf0e10cSrcweir     static sal_uInt32 cSelectedChar = ' '; // keeps selected character over app livetime
61cdf0e10cSrcweir     return cSelectedChar;
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir // class SvxShowCharSet ==================================================
65cdf0e10cSrcweir 
66cdf0e10cSrcweir #define SBWIDTH 16
67cdf0e10cSrcweir 
68cdf0e10cSrcweir SvxShowCharSet::SvxShowCharSet( Window* pParent, const ResId& rResId ) :
69cdf0e10cSrcweir     Control( pParent, rResId )
70cdf0e10cSrcweir     ,m_pAccessible(NULL)
71cdf0e10cSrcweir     ,aVscrollSB( this, WB_VERT)
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     nSelectedIndex = -1;    // TODO: move into init list when it is no longer static
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     aOrigSize = GetOutputSizePixel();
76cdf0e10cSrcweir     aOrigPos = GetPosPixel();
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     SetStyle( GetStyle() | WB_CLIPCHILDREN );
79cdf0e10cSrcweir     aVscrollSB.SetScrollHdl( LINK( this, SvxShowCharSet, VscrollHdl ) );
80cdf0e10cSrcweir     aVscrollSB.EnableDrag( sal_True );
81cdf0e10cSrcweir     // other settings like aVscroll depend on selected font => see SetFont
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     bDrag = sal_False;
84cdf0e10cSrcweir     InitSettings( sal_True, sal_True );
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir // -----------------------------------------------------------------------
88cdf0e10cSrcweir 
89cdf0e10cSrcweir void SvxShowCharSet::GetFocus()
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     Control::GetFocus();
92cdf0e10cSrcweir     SelectIndex( nSelectedIndex, sal_True );
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir // -----------------------------------------------------------------------
96cdf0e10cSrcweir 
97cdf0e10cSrcweir void SvxShowCharSet::LoseFocus()
98cdf0e10cSrcweir {
99cdf0e10cSrcweir     Control::LoseFocus();
100cdf0e10cSrcweir     SelectIndex( nSelectedIndex, sal_False );
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir // -----------------------------------------------------------------------
104cdf0e10cSrcweir 
105cdf0e10cSrcweir void SvxShowCharSet::StateChanged( StateChangedType nType )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir     if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
108cdf0e10cSrcweir         InitSettings( sal_True, sal_False );
109cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
110cdf0e10cSrcweir         InitSettings( sal_False, sal_True );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     Control::StateChanged( nType );
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir // -----------------------------------------------------------------------
116cdf0e10cSrcweir 
117cdf0e10cSrcweir void SvxShowCharSet::DataChanged( const DataChangedEvent& rDCEvt )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir     if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS )
120cdf0e10cSrcweir       && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
121cdf0e10cSrcweir         InitSettings( sal_True, sal_True );
122cdf0e10cSrcweir     else
123cdf0e10cSrcweir         Control::DataChanged( rDCEvt );
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir // -----------------------------------------------------------------------
127cdf0e10cSrcweir 
128cdf0e10cSrcweir void SvxShowCharSet::MouseButtonDown( const MouseEvent& rMEvt )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir     if ( rMEvt.IsLeft() )
131cdf0e10cSrcweir     {
132cdf0e10cSrcweir         if ( rMEvt.GetClicks() == 1 )
133cdf0e10cSrcweir         {
134cdf0e10cSrcweir             GrabFocus();
135cdf0e10cSrcweir             bDrag = sal_True;
136cdf0e10cSrcweir             CaptureMouse();
137cdf0e10cSrcweir 
138cdf0e10cSrcweir             int nIndex = PixelToMapIndex( rMEvt.GetPosPixel() );
139cdf0e10cSrcweir             SelectIndex( nIndex );
140cdf0e10cSrcweir         }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir         if ( !(rMEvt.GetClicks() % 2) )
143cdf0e10cSrcweir             aDoubleClkHdl.Call( this );
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
147cdf0e10cSrcweir // -----------------------------------------------------------------------
148cdf0e10cSrcweir 
149cdf0e10cSrcweir void SvxShowCharSet::MouseButtonUp( const MouseEvent& rMEvt )
150cdf0e10cSrcweir {
151cdf0e10cSrcweir     if ( bDrag && rMEvt.IsLeft() )
152cdf0e10cSrcweir     {
153cdf0e10cSrcweir         // released mouse over character map
154cdf0e10cSrcweir         if ( Rectangle(Point(), GetOutputSize()).IsInside(rMEvt.GetPosPixel()))
155cdf0e10cSrcweir             aSelectHdl.Call( this );
156cdf0e10cSrcweir         ReleaseMouse();
157cdf0e10cSrcweir         bDrag = sal_False;
158cdf0e10cSrcweir     }
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir // -----------------------------------------------------------------------
162cdf0e10cSrcweir 
163cdf0e10cSrcweir void SvxShowCharSet::MouseMove( const MouseEvent& rMEvt )
164cdf0e10cSrcweir {
165cdf0e10cSrcweir     if ( rMEvt.IsLeft() && bDrag )
166cdf0e10cSrcweir     {
167cdf0e10cSrcweir         Point aPos  = rMEvt.GetPosPixel();
168cdf0e10cSrcweir         Size  aSize = GetSizePixel();
169cdf0e10cSrcweir 
170cdf0e10cSrcweir         if ( aPos.X() < 0 )
171cdf0e10cSrcweir             aPos.X() = 0;
172cdf0e10cSrcweir         else if ( aPos.X() > aSize.Width()-5 )
173cdf0e10cSrcweir             aPos.X() = aSize.Width()-5;
174cdf0e10cSrcweir         if ( aPos.Y() < 0 )
175cdf0e10cSrcweir             aPos.Y() = 0;
176cdf0e10cSrcweir         else if ( aPos.Y() > aSize.Height()-5 )
177cdf0e10cSrcweir             aPos.Y() = aSize.Height()-5;
178cdf0e10cSrcweir 
179cdf0e10cSrcweir         int nIndex = PixelToMapIndex( aPos );
180cdf0e10cSrcweir         SelectIndex( nIndex );
181cdf0e10cSrcweir     }
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir // -----------------------------------------------------------------------
185cdf0e10cSrcweir 
186cdf0e10cSrcweir void SvxShowCharSet::Command( const CommandEvent& rCEvt )
187cdf0e10cSrcweir {
188cdf0e10cSrcweir     if( !HandleScrollCommand( rCEvt, 0, &aVscrollSB ) )
189cdf0e10cSrcweir         Control::Command( rCEvt );
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir // -----------------------------------------------------------------------------
193cdf0e10cSrcweir 
194cdf0e10cSrcweir sal_uInt16 SvxShowCharSet::GetRowPos(sal_uInt16 _nPos) const
195cdf0e10cSrcweir {
196cdf0e10cSrcweir     return _nPos / COLUMN_COUNT ;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir // -----------------------------------------------------------------------------
200cdf0e10cSrcweir 
201cdf0e10cSrcweir sal_uInt16 SvxShowCharSet::GetColumnPos(sal_uInt16 _nPos) const
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     return _nPos % COLUMN_COUNT ;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir // -----------------------------------------------------------------------
207cdf0e10cSrcweir 
208cdf0e10cSrcweir int SvxShowCharSet::FirstInView( void ) const
209cdf0e10cSrcweir {
210cdf0e10cSrcweir     int nIndex = 0;
211cdf0e10cSrcweir     if( aVscrollSB.IsVisible() )
212cdf0e10cSrcweir         nIndex += aVscrollSB.GetThumbPos() * COLUMN_COUNT;
213cdf0e10cSrcweir     return nIndex;
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir // -----------------------------------------------------------------------
217cdf0e10cSrcweir 
218cdf0e10cSrcweir int SvxShowCharSet::LastInView( void ) const
219cdf0e10cSrcweir {
220cdf0e10cSrcweir     sal_uIntPtr nIndex = FirstInView();
221cdf0e10cSrcweir     nIndex += ROW_COUNT * COLUMN_COUNT - 1;
222cdf0e10cSrcweir     sal_uIntPtr nCompare = sal::static_int_cast<sal_uIntPtr>( maFontCharMap.GetCharCount() - 1 );
223cdf0e10cSrcweir     if( nIndex > nCompare )
224cdf0e10cSrcweir         nIndex = nCompare;
225cdf0e10cSrcweir     return nIndex;
226cdf0e10cSrcweir }
227cdf0e10cSrcweir 
228cdf0e10cSrcweir // -----------------------------------------------------------------------
229cdf0e10cSrcweir 
230cdf0e10cSrcweir inline Point SvxShowCharSet::MapIndexToPixel( int nIndex ) const
231cdf0e10cSrcweir {
232cdf0e10cSrcweir     const int nBase = FirstInView();
233cdf0e10cSrcweir     int x = ((nIndex - nBase) % COLUMN_COUNT) * nX;
234cdf0e10cSrcweir     int y = ((nIndex - nBase) / COLUMN_COUNT) * nY;
235cdf0e10cSrcweir     return Point( x, y );
236cdf0e10cSrcweir }
237cdf0e10cSrcweir // -----------------------------------------------------------------------------
238cdf0e10cSrcweir 
239cdf0e10cSrcweir int SvxShowCharSet::PixelToMapIndex( const Point& point) const
240cdf0e10cSrcweir {
241cdf0e10cSrcweir     int nBase = FirstInView();
242cdf0e10cSrcweir     return (nBase + (point.X()/nX) + (point.Y()/nY) * COLUMN_COUNT);
243cdf0e10cSrcweir }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir // -----------------------------------------------------------------------
246cdf0e10cSrcweir 
247cdf0e10cSrcweir void SvxShowCharSet::KeyInput( const KeyEvent& rKEvt )
248cdf0e10cSrcweir {
249cdf0e10cSrcweir     KeyCode aCode = rKEvt.GetKeyCode();
250cdf0e10cSrcweir 
251cdf0e10cSrcweir     if( aCode.GetModifier() )
252cdf0e10cSrcweir     {
253cdf0e10cSrcweir         Control::KeyInput( rKEvt );
254cdf0e10cSrcweir         return;
255cdf0e10cSrcweir     }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     int tmpSelected = nSelectedIndex;
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     switch ( aCode.GetCode() )
260cdf0e10cSrcweir     {
261cdf0e10cSrcweir         case KEY_SPACE:
262cdf0e10cSrcweir             aSelectHdl.Call( this );
263cdf0e10cSrcweir             break;
264cdf0e10cSrcweir         case KEY_LEFT:
265cdf0e10cSrcweir             --tmpSelected;
266cdf0e10cSrcweir             break;
267cdf0e10cSrcweir         case KEY_RIGHT:
268cdf0e10cSrcweir             ++tmpSelected;
269cdf0e10cSrcweir             break;
270cdf0e10cSrcweir         case KEY_UP:
271cdf0e10cSrcweir             tmpSelected -= COLUMN_COUNT;
272cdf0e10cSrcweir             break;
273cdf0e10cSrcweir         case KEY_DOWN:
274cdf0e10cSrcweir             tmpSelected += COLUMN_COUNT;
275cdf0e10cSrcweir             break;
276cdf0e10cSrcweir         case KEY_PAGEUP:
277cdf0e10cSrcweir             tmpSelected -= ROW_COUNT * COLUMN_COUNT;
278cdf0e10cSrcweir             break;
279cdf0e10cSrcweir         case KEY_PAGEDOWN:
280cdf0e10cSrcweir             tmpSelected += ROW_COUNT * COLUMN_COUNT;
281cdf0e10cSrcweir             break;
282cdf0e10cSrcweir         case KEY_HOME:
283cdf0e10cSrcweir             tmpSelected = 0;
284cdf0e10cSrcweir             break;
285cdf0e10cSrcweir         case KEY_END:
286cdf0e10cSrcweir             tmpSelected = maFontCharMap.GetCharCount() - 1;
287cdf0e10cSrcweir             break;
288cdf0e10cSrcweir         case KEY_TAB:   // some fonts have a character at these unicode control codes
289cdf0e10cSrcweir         case KEY_ESCAPE:
290cdf0e10cSrcweir         case KEY_RETURN:
291cdf0e10cSrcweir             Control::KeyInput( rKEvt );
292cdf0e10cSrcweir             tmpSelected = - 1;  // mark as invalid
293cdf0e10cSrcweir             break;
294cdf0e10cSrcweir         default:
295cdf0e10cSrcweir             {
296cdf0e10cSrcweir                 sal_UCS4 cChar = rKEvt.GetCharCode();
297cdf0e10cSrcweir                 sal_UCS4 cNext = maFontCharMap.GetNextChar( cChar - 1 );
298cdf0e10cSrcweir                 tmpSelected = maFontCharMap.GetIndexFromChar( cNext );
299cdf0e10cSrcweir                 if( tmpSelected < 0 || (cChar != cNext) )
300cdf0e10cSrcweir                 {
301cdf0e10cSrcweir                     Control::KeyInput( rKEvt );
302cdf0e10cSrcweir                     tmpSelected = - 1;  // mark as invalid
303cdf0e10cSrcweir                 }
304cdf0e10cSrcweir             }
305cdf0e10cSrcweir     }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir     if ( tmpSelected >= 0 )
308cdf0e10cSrcweir     {
309cdf0e10cSrcweir         SelectIndex( tmpSelected, sal_True );
310cdf0e10cSrcweir         aPreSelectHdl.Call( this );
311cdf0e10cSrcweir     }
312cdf0e10cSrcweir }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir // -----------------------------------------------------------------------
315cdf0e10cSrcweir 
316cdf0e10cSrcweir void SvxShowCharSet::Paint( const Rectangle& )
317cdf0e10cSrcweir {
318cdf0e10cSrcweir     DrawChars_Impl( FirstInView(), LastInView() );
319cdf0e10cSrcweir }
320cdf0e10cSrcweir // -----------------------------------------------------------------------------
321cdf0e10cSrcweir void SvxShowCharSet::DeSelect()
322cdf0e10cSrcweir {
323cdf0e10cSrcweir     DrawChars_Impl(nSelectedIndex,nSelectedIndex);
324cdf0e10cSrcweir }
325cdf0e10cSrcweir // -----------------------------------------------------------------------
326cdf0e10cSrcweir 
327cdf0e10cSrcweir void SvxShowCharSet::DrawChars_Impl( int n1, int n2 )
328cdf0e10cSrcweir {
329cdf0e10cSrcweir     if( n1 > LastInView() || n2 < FirstInView() )
330cdf0e10cSrcweir         return;
331cdf0e10cSrcweir 
332cdf0e10cSrcweir     Size aOutputSize = GetOutputSizePixel();
333cdf0e10cSrcweir     if( aVscrollSB.IsVisible() )
334cdf0e10cSrcweir         aOutputSize.setWidth( aOutputSize.Width() - SBWIDTH );
335cdf0e10cSrcweir 
336cdf0e10cSrcweir     int i;
337cdf0e10cSrcweir     for ( i = 1; i < COLUMN_COUNT; ++i )
338cdf0e10cSrcweir         DrawLine( Point( nX * i, 0 ), Point( nX * i, aOutputSize.Height() ) );
339cdf0e10cSrcweir     for ( i = 1; i < ROW_COUNT; ++i )
340cdf0e10cSrcweir         DrawLine( Point( 0, nY * i ), Point( aOutputSize.Width(), nY * i ) );
341cdf0e10cSrcweir 
342cdf0e10cSrcweir     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
343cdf0e10cSrcweir     const Color aWindowTextColor( rStyleSettings.GetFieldTextColor() );
344cdf0e10cSrcweir     Color aHighlightColor( rStyleSettings.GetHighlightColor() );
345cdf0e10cSrcweir     Color aHighlightTextColor( rStyleSettings.GetHighlightTextColor() );
346cdf0e10cSrcweir     Color aFaceColor( rStyleSettings.GetFaceColor() );
347cdf0e10cSrcweir     Color aLightColor( rStyleSettings.GetLightColor() );
348cdf0e10cSrcweir     Color aShadowColor( rStyleSettings.GetShadowColor() );
349cdf0e10cSrcweir 
350cdf0e10cSrcweir     int nTextHeight = GetTextHeight();
351cdf0e10cSrcweir     Rectangle aBoundRect;
352cdf0e10cSrcweir     for( i = n1; i <= n2; ++i )
353cdf0e10cSrcweir     {
354cdf0e10cSrcweir         Point pix = MapIndexToPixel( i );
355cdf0e10cSrcweir         int x = pix.X();
356cdf0e10cSrcweir         int y = pix.Y();
357cdf0e10cSrcweir 
358cdf0e10cSrcweir         rtl::OUStringBuffer buf;
359cdf0e10cSrcweir         buf.appendUtf32( maFontCharMap.GetCharFromIndex( i ) );
360cdf0e10cSrcweir         String aCharStr(buf.makeStringAndClear());
361cdf0e10cSrcweir         int nTextWidth = GetTextWidth(aCharStr);
362cdf0e10cSrcweir         int tx = x + (nX - nTextWidth + 1) / 2;
363cdf0e10cSrcweir         int ty = y + (nY - nTextHeight + 1) / 2;
364cdf0e10cSrcweir         Point aPointTxTy( tx, ty );
365cdf0e10cSrcweir 
366cdf0e10cSrcweir         // adjust position before it gets out of bounds
367cdf0e10cSrcweir         if( GetTextBoundRect( aBoundRect, aCharStr ) && !aBoundRect.IsEmpty() )
368cdf0e10cSrcweir         {
369cdf0e10cSrcweir             // zero advance width => use ink width to center glyph
370cdf0e10cSrcweir             if( !nTextWidth )
371cdf0e10cSrcweir             {
372cdf0e10cSrcweir                 aPointTxTy.X() = x - aBoundRect.Left()
373cdf0e10cSrcweir                                + (nX - aBoundRect.GetWidth() + 1) / 2;
374cdf0e10cSrcweir             }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir             aBoundRect += aPointTxTy;
377cdf0e10cSrcweir 
378cdf0e10cSrcweir             // shift back vertically if needed
379cdf0e10cSrcweir             int nYLDelta = aBoundRect.Top() - y;
380cdf0e10cSrcweir             int nYHDelta = (y + nY) - aBoundRect.Bottom();
381cdf0e10cSrcweir             if( nYLDelta <= 0 )
382cdf0e10cSrcweir                 aPointTxTy.Y() -= nYLDelta - 1;
383cdf0e10cSrcweir             else if( nYHDelta <= 0 )
384cdf0e10cSrcweir                 aPointTxTy.Y() += nYHDelta - 1;
385cdf0e10cSrcweir 
386cdf0e10cSrcweir             // shift back horizontally if needed
387cdf0e10cSrcweir             int nXLDelta = aBoundRect.Left() - x;
388cdf0e10cSrcweir             int nXHDelta = (x + nX) - aBoundRect.Right();
389cdf0e10cSrcweir             if( nXLDelta <= 0 )
390cdf0e10cSrcweir                 aPointTxTy.X() -= nXLDelta - 1;
391cdf0e10cSrcweir             else if( nXHDelta <= 0 )
392cdf0e10cSrcweir                 aPointTxTy.X() += nXHDelta - 1;
393cdf0e10cSrcweir         }
394cdf0e10cSrcweir 
395cdf0e10cSrcweir         Color aTextCol = GetTextColor();
396cdf0e10cSrcweir         if ( i != nSelectedIndex )
397cdf0e10cSrcweir         {
398cdf0e10cSrcweir             SetTextColor( aWindowTextColor );
399cdf0e10cSrcweir             DrawText( aPointTxTy, aCharStr );
400cdf0e10cSrcweir         }
401cdf0e10cSrcweir         else
402cdf0e10cSrcweir         {
403cdf0e10cSrcweir             Color aLineCol = GetLineColor();
404cdf0e10cSrcweir             Color aFillCol = GetFillColor();
405cdf0e10cSrcweir             SetLineColor();
406cdf0e10cSrcweir             Point aPointUL( x + 1, y + 1 );
407cdf0e10cSrcweir             if( HasFocus() )
408cdf0e10cSrcweir             {
409cdf0e10cSrcweir                 SetFillColor( aHighlightColor );
410cdf0e10cSrcweir                 DrawRect( Rectangle( aPointUL, Size(nX-1,nY-1) ) );
411cdf0e10cSrcweir 
412cdf0e10cSrcweir                 SetTextColor( aHighlightTextColor );
413cdf0e10cSrcweir                 DrawText( aPointTxTy, aCharStr );
414cdf0e10cSrcweir             }
415cdf0e10cSrcweir             else
416cdf0e10cSrcweir             {
417cdf0e10cSrcweir                 SetFillColor( aFaceColor );
418cdf0e10cSrcweir                 DrawRect( Rectangle( aPointUL, Size( nX-1, nY-1) ) );
419cdf0e10cSrcweir 
420cdf0e10cSrcweir                 SetLineColor( aLightColor );
421cdf0e10cSrcweir                 DrawLine( aPointUL, Point( x+nX-1, y+1) );
422cdf0e10cSrcweir                 DrawLine( aPointUL, Point( x+1, y+nY-1) );
423cdf0e10cSrcweir 
424cdf0e10cSrcweir                 SetLineColor( aShadowColor );
425cdf0e10cSrcweir                 DrawLine( Point( x+1, y+nY-1), Point( x+nX-1, y+nY-1) );
426cdf0e10cSrcweir                 DrawLine( Point( x+nX-1, y+nY-1), Point( x+nX-1, y+1) );
427cdf0e10cSrcweir 
428cdf0e10cSrcweir                 DrawText( aPointTxTy, aCharStr );
429cdf0e10cSrcweir             }
430cdf0e10cSrcweir             SetLineColor( aLineCol );
431cdf0e10cSrcweir             SetFillColor( aFillCol );
432cdf0e10cSrcweir         }
433cdf0e10cSrcweir         SetTextColor( aTextCol );
434cdf0e10cSrcweir     }
435cdf0e10cSrcweir }
436cdf0e10cSrcweir 
437cdf0e10cSrcweir // -----------------------------------------------------------------------
438cdf0e10cSrcweir 
439cdf0e10cSrcweir void SvxShowCharSet::InitSettings( sal_Bool bForeground, sal_Bool bBackground )
440cdf0e10cSrcweir {
441cdf0e10cSrcweir     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
442cdf0e10cSrcweir 
443cdf0e10cSrcweir     if ( bForeground )
444cdf0e10cSrcweir     {
445cdf0e10cSrcweir         Color aTextColor( rStyleSettings.GetDialogTextColor() );
446cdf0e10cSrcweir 
447cdf0e10cSrcweir         if ( IsControlForeground() )
448cdf0e10cSrcweir             aTextColor = GetControlForeground();
449cdf0e10cSrcweir         SetTextColor( aTextColor );
450cdf0e10cSrcweir     }
451cdf0e10cSrcweir 
452cdf0e10cSrcweir     if ( bBackground )
453cdf0e10cSrcweir     {
454cdf0e10cSrcweir         if ( IsControlBackground() )
455cdf0e10cSrcweir             SetBackground( GetControlBackground() );
456cdf0e10cSrcweir         else
457cdf0e10cSrcweir             SetBackground( rStyleSettings.GetWindowColor() );
458cdf0e10cSrcweir     }
459cdf0e10cSrcweir 
460cdf0e10cSrcweir     Invalidate();
461cdf0e10cSrcweir }
462cdf0e10cSrcweir 
463cdf0e10cSrcweir // -----------------------------------------------------------------------
464cdf0e10cSrcweir 
465cdf0e10cSrcweir sal_UCS4 SvxShowCharSet::GetSelectCharacter() const
466cdf0e10cSrcweir {
467cdf0e10cSrcweir     if( nSelectedIndex >= 0 )
468cdf0e10cSrcweir         getSelectedChar() = maFontCharMap.GetCharFromIndex( nSelectedIndex );
469cdf0e10cSrcweir     return getSelectedChar();
470cdf0e10cSrcweir }
471cdf0e10cSrcweir 
472cdf0e10cSrcweir // -----------------------------------------------------------------------
473cdf0e10cSrcweir 
474cdf0e10cSrcweir void SvxShowCharSet::SetFont( const Font& rFont )
475cdf0e10cSrcweir {
476cdf0e10cSrcweir     // save last selected unicode
477cdf0e10cSrcweir     if( nSelectedIndex >= 0 )
478cdf0e10cSrcweir         getSelectedChar() = maFontCharMap.GetCharFromIndex( nSelectedIndex );
479cdf0e10cSrcweir 
480cdf0e10cSrcweir     Font aFont = rFont;
481cdf0e10cSrcweir     aFont.SetWeight( WEIGHT_LIGHT );
482cdf0e10cSrcweir     aFont.SetAlign( ALIGN_TOP );
483cdf0e10cSrcweir     int nFontHeight = (aOrigSize.Height() - 5) * 2 / (3 * ROW_COUNT);
484cdf0e10cSrcweir     aFont.SetSize( PixelToLogic( Size( 0, nFontHeight ) ) );
485cdf0e10cSrcweir     aFont.SetTransparent( sal_True );
486cdf0e10cSrcweir     Control::SetFont( aFont );
487cdf0e10cSrcweir     GetFontCharMap( maFontCharMap );
488cdf0e10cSrcweir 
489cdf0e10cSrcweir     // hide scrollbar when there is nothing to scroll
490cdf0e10cSrcweir     sal_Bool bNeedVscroll = (maFontCharMap.GetCharCount() > ROW_COUNT*COLUMN_COUNT);
491cdf0e10cSrcweir 
492cdf0e10cSrcweir     nX = (aOrigSize.Width() - (bNeedVscroll ? SBWIDTH : 0)) / COLUMN_COUNT;
493cdf0e10cSrcweir     nY = aOrigSize.Height() / ROW_COUNT;
494cdf0e10cSrcweir 
495cdf0e10cSrcweir     if( bNeedVscroll)
496cdf0e10cSrcweir     {
497cdf0e10cSrcweir         aVscrollSB.SetPosSizePixel( nX * COLUMN_COUNT, 0, SBWIDTH, nY * ROW_COUNT );
498cdf0e10cSrcweir         aVscrollSB.SetRangeMin( 0 );
499cdf0e10cSrcweir         int nLastRow = (maFontCharMap.GetCharCount() - 1 + COLUMN_COUNT) / COLUMN_COUNT;
500cdf0e10cSrcweir         aVscrollSB.SetRangeMax( nLastRow );
501cdf0e10cSrcweir         aVscrollSB.SetPageSize( ROW_COUNT-1 );
502cdf0e10cSrcweir         aVscrollSB.SetVisibleSize( ROW_COUNT );
503cdf0e10cSrcweir     }
504cdf0e10cSrcweir 
505cdf0e10cSrcweir     // restore last selected unicode
506cdf0e10cSrcweir     int nMapIndex = maFontCharMap.GetIndexFromChar( getSelectedChar() );
507cdf0e10cSrcweir     SelectIndex( nMapIndex );
508cdf0e10cSrcweir 
509cdf0e10cSrcweir     // rearrange CharSet element in sync with nX- and nY-multiples
510cdf0e10cSrcweir     Size aNewSize( nX * COLUMN_COUNT + (bNeedVscroll ? SBWIDTH : 0), nY * ROW_COUNT );
511cdf0e10cSrcweir     Point aNewPos = aOrigPos + Point( (aOrigSize.Width() - aNewSize.Width()) / 2, 0 );
512cdf0e10cSrcweir     SetPosPixel( aNewPos );
513cdf0e10cSrcweir     SetOutputSizePixel( aNewSize );
514cdf0e10cSrcweir 
515cdf0e10cSrcweir     aVscrollSB.Show( bNeedVscroll );
516cdf0e10cSrcweir     Invalidate();
517cdf0e10cSrcweir }
518cdf0e10cSrcweir 
519cdf0e10cSrcweir // -----------------------------------------------------------------------
520cdf0e10cSrcweir 
521cdf0e10cSrcweir void SvxShowCharSet::SelectIndex( int nNewIndex, sal_Bool bFocus )
522cdf0e10cSrcweir {
523cdf0e10cSrcweir     if( nNewIndex < 0 )
524cdf0e10cSrcweir     {
525cdf0e10cSrcweir         // need to scroll see closest unicode
526cdf0e10cSrcweir         sal_uInt32 cPrev = maFontCharMap.GetPrevChar( getSelectedChar() );
527cdf0e10cSrcweir         int nMapIndex = maFontCharMap.GetIndexFromChar( cPrev );
528cdf0e10cSrcweir         int nNewPos = nMapIndex / COLUMN_COUNT;
529cdf0e10cSrcweir         aVscrollSB.SetThumbPos( nNewPos );
530cdf0e10cSrcweir         nSelectedIndex = bFocus ? nMapIndex+1 : -1;
531cdf0e10cSrcweir         Invalidate();
532cdf0e10cSrcweir         Update();
533cdf0e10cSrcweir     }
534cdf0e10cSrcweir     else if( nNewIndex < FirstInView() )
535cdf0e10cSrcweir     {
536cdf0e10cSrcweir         // need to scroll up to see selected item
537cdf0e10cSrcweir         int nOldPos = aVscrollSB.GetThumbPos();
538cdf0e10cSrcweir         int nDelta = (FirstInView() - nNewIndex + COLUMN_COUNT-1) / COLUMN_COUNT;
539cdf0e10cSrcweir         aVscrollSB.SetThumbPos( nOldPos - nDelta );
540cdf0e10cSrcweir         nSelectedIndex = nNewIndex;
541cdf0e10cSrcweir         Invalidate();
542cdf0e10cSrcweir         if( nDelta )
543cdf0e10cSrcweir             Update();
544cdf0e10cSrcweir     }
545cdf0e10cSrcweir     else if( nNewIndex > LastInView() )
546cdf0e10cSrcweir     {
547cdf0e10cSrcweir         // need to scroll down to see selected item
548cdf0e10cSrcweir         int nOldPos = aVscrollSB.GetThumbPos();
549cdf0e10cSrcweir         int nDelta = (nNewIndex - LastInView() + COLUMN_COUNT) / COLUMN_COUNT;
550cdf0e10cSrcweir         aVscrollSB.SetThumbPos( nOldPos + nDelta );
551cdf0e10cSrcweir         if( nNewIndex < maFontCharMap.GetCharCount() )
552cdf0e10cSrcweir         {
553cdf0e10cSrcweir             nSelectedIndex = nNewIndex;
554cdf0e10cSrcweir             Invalidate();
555cdf0e10cSrcweir         }
556cdf0e10cSrcweir         if( nOldPos != aVscrollSB.GetThumbPos() )
557cdf0e10cSrcweir         {
558cdf0e10cSrcweir             Invalidate();
559cdf0e10cSrcweir             Update();
560cdf0e10cSrcweir         }
561cdf0e10cSrcweir     }
562cdf0e10cSrcweir     else
563cdf0e10cSrcweir     {
564cdf0e10cSrcweir         // remove highlighted view
565cdf0e10cSrcweir         Color aLineCol = GetLineColor();
566cdf0e10cSrcweir         Color aFillCol = GetFillColor();
567cdf0e10cSrcweir         SetLineColor();
568cdf0e10cSrcweir         SetFillColor( GetBackground().GetColor() );
569cdf0e10cSrcweir 
570cdf0e10cSrcweir         Point aOldPixel = MapIndexToPixel( nSelectedIndex );
571cdf0e10cSrcweir         aOldPixel.Move( +1, +1);
572cdf0e10cSrcweir         DrawRect( Rectangle( aOldPixel, Size( nX-1, nY-1 ) ) );
573cdf0e10cSrcweir         SetLineColor( aLineCol );
574cdf0e10cSrcweir         SetFillColor( aFillCol );
575cdf0e10cSrcweir 
576cdf0e10cSrcweir         int nOldIndex = nSelectedIndex;
577cdf0e10cSrcweir         nSelectedIndex = nNewIndex;
578cdf0e10cSrcweir         DrawChars_Impl( nOldIndex, nOldIndex );
579cdf0e10cSrcweir         DrawChars_Impl( nNewIndex, nNewIndex );
580cdf0e10cSrcweir     }
581cdf0e10cSrcweir 
582cdf0e10cSrcweir     if( nSelectedIndex >= 0 )
583cdf0e10cSrcweir     {
584cdf0e10cSrcweir         getSelectedChar() = maFontCharMap.GetCharFromIndex( nSelectedIndex );
585cdf0e10cSrcweir         if( m_pAccessible )
586cdf0e10cSrcweir         {
587cdf0e10cSrcweir             ::svx::SvxShowCharSetItem* pItem = ImplGetItem(nSelectedIndex);
588cdf0e10cSrcweir             m_pAccessible->fireEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, Any(), makeAny(pItem->GetAccessible()) ); // this call asures that m_pItem is set
589cdf0e10cSrcweir 
590cdf0e10cSrcweir             OSL_ENSURE(pItem->m_pItem,"No accessible created!");
591cdf0e10cSrcweir             Any aOldAny, aNewAny;
592cdf0e10cSrcweir             aNewAny <<= AccessibleStateType::FOCUSED;
593cdf0e10cSrcweir             pItem->m_pItem->fireEvent( AccessibleEventId::STATE_CHANGED, aOldAny, aNewAny );
594cdf0e10cSrcweir 
595cdf0e10cSrcweir             aNewAny <<= AccessibleStateType::SELECTED;
596cdf0e10cSrcweir             pItem->m_pItem->fireEvent( AccessibleEventId::STATE_CHANGED, aOldAny, aNewAny );
597cdf0e10cSrcweir         }
598cdf0e10cSrcweir     }
599cdf0e10cSrcweir 
600cdf0e10cSrcweir 
601cdf0e10cSrcweir     aHighHdl.Call( this );
602cdf0e10cSrcweir }
603cdf0e10cSrcweir 
604cdf0e10cSrcweir // -----------------------------------------------------------------------
605cdf0e10cSrcweir 
606cdf0e10cSrcweir void SvxShowCharSet::SelectCharacter( sal_UCS4 cNew, sal_Bool bFocus )
607cdf0e10cSrcweir {
608cdf0e10cSrcweir     // get next available char of current font
609cdf0e10cSrcweir     sal_UCS4 cNext = maFontCharMap.GetNextChar( cNew - 1 );
610cdf0e10cSrcweir 
611cdf0e10cSrcweir     int nMapIndex = maFontCharMap.GetIndexFromChar( cNext );
612cdf0e10cSrcweir     SelectIndex( nMapIndex, bFocus );
613cdf0e10cSrcweir     if( !bFocus )
614cdf0e10cSrcweir     {
615cdf0e10cSrcweir         // move selected item to top row if not in focus
616cdf0e10cSrcweir         aVscrollSB.SetThumbPos( nMapIndex / COLUMN_COUNT );
617cdf0e10cSrcweir         Invalidate();
618cdf0e10cSrcweir     }
619cdf0e10cSrcweir }
620cdf0e10cSrcweir 
621cdf0e10cSrcweir // -----------------------------------------------------------------------
622cdf0e10cSrcweir 
623cdf0e10cSrcweir IMPL_LINK( SvxShowCharSet, VscrollHdl, ScrollBar *, EMPTYARG )
624cdf0e10cSrcweir {
625cdf0e10cSrcweir     if( nSelectedIndex < FirstInView() )
626cdf0e10cSrcweir     {
627cdf0e10cSrcweir         SelectIndex( FirstInView() + (nSelectedIndex % COLUMN_COUNT) );
628cdf0e10cSrcweir     }
629cdf0e10cSrcweir     else if( nSelectedIndex > LastInView() )
630cdf0e10cSrcweir     {
631cdf0e10cSrcweir         if( m_pAccessible )
632cdf0e10cSrcweir         {
633cdf0e10cSrcweir             ::com::sun::star::uno::Any aOldAny, aNewAny;
634cdf0e10cSrcweir             int nLast = LastInView();
635cdf0e10cSrcweir             for ( ; nLast != nSelectedIndex; ++nLast)
636cdf0e10cSrcweir             {
637cdf0e10cSrcweir                 aOldAny <<= ImplGetItem(nLast)->GetAccessible();
638cdf0e10cSrcweir                 m_pAccessible ->fireEvent( AccessibleEventId::CHILD, aOldAny, aNewAny );
639cdf0e10cSrcweir             }
640cdf0e10cSrcweir         }
641cdf0e10cSrcweir         SelectIndex( (LastInView() - COLUMN_COUNT + 1) + (nSelectedIndex % COLUMN_COUNT) );
642cdf0e10cSrcweir     }
643cdf0e10cSrcweir 
644cdf0e10cSrcweir     Invalidate();
645cdf0e10cSrcweir     return 0;
646cdf0e10cSrcweir }
647cdf0e10cSrcweir 
648cdf0e10cSrcweir // -----------------------------------------------------------------------
649cdf0e10cSrcweir 
650cdf0e10cSrcweir SvxShowCharSet::~SvxShowCharSet()
651cdf0e10cSrcweir {
652cdf0e10cSrcweir     if ( m_pAccessible )
653cdf0e10cSrcweir         ReleaseAccessible();
654cdf0e10cSrcweir }
655cdf0e10cSrcweir // -----------------------------------------------------------------------------
656cdf0e10cSrcweir void SvxShowCharSet::ReleaseAccessible()
657cdf0e10cSrcweir {
658cdf0e10cSrcweir     m_aItems.clear();
659cdf0e10cSrcweir     m_pAccessible = NULL;
660cdf0e10cSrcweir     m_xAccessible = NULL;
661cdf0e10cSrcweir }
662cdf0e10cSrcweir // -----------------------------------------------------------------------------
663cdf0e10cSrcweir ::com::sun::star::uno::Reference< XAccessible > SvxShowCharSet::CreateAccessible()
664cdf0e10cSrcweir {
665cdf0e10cSrcweir     OSL_ENSURE(!m_pAccessible,"Accessible already created!");
666cdf0e10cSrcweir     m_pAccessible = new ::svx::SvxShowCharSetVirtualAcc(this);
667cdf0e10cSrcweir     m_xAccessible = m_pAccessible;
668cdf0e10cSrcweir     return m_xAccessible;
669cdf0e10cSrcweir }
670cdf0e10cSrcweir // -----------------------------------------------------------------------------
671cdf0e10cSrcweir ::svx::SvxShowCharSetItem* SvxShowCharSet::ImplGetItem( int _nPos )
672cdf0e10cSrcweir {
673cdf0e10cSrcweir     ItemsMap::iterator aFind = m_aItems.find(_nPos);
674cdf0e10cSrcweir     if ( aFind == m_aItems.end() )
675cdf0e10cSrcweir     {
676cdf0e10cSrcweir         OSL_ENSURE(m_pAccessible,"Who wants to create a child of my table without a parent?");
677cdf0e10cSrcweir         aFind = m_aItems.insert(ItemsMap::value_type(_nPos,new ::svx::SvxShowCharSetItem(*this,m_pAccessible->getTable(),sal::static_int_cast< sal_uInt16 >(_nPos)))).first;
678cdf0e10cSrcweir         rtl::OUStringBuffer buf;
679cdf0e10cSrcweir         buf.appendUtf32( maFontCharMap.GetCharFromIndex( _nPos ) );
680cdf0e10cSrcweir         aFind->second->maText = buf.makeStringAndClear();
681cdf0e10cSrcweir         Point pix = MapIndexToPixel( _nPos );
682cdf0e10cSrcweir         aFind->second->maRect = Rectangle( Point( pix.X() + 1, pix.Y() + 1 ), Size(nX-1,nY-1) );
683cdf0e10cSrcweir     }
684cdf0e10cSrcweir 
685cdf0e10cSrcweir     return aFind->second;
686cdf0e10cSrcweir }
687cdf0e10cSrcweir // -----------------------------------------------------------------------------
688cdf0e10cSrcweir void SvxShowCharSet::ImplFireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue )
689cdf0e10cSrcweir {
690cdf0e10cSrcweir     if( m_pAccessible )
691cdf0e10cSrcweir         m_pAccessible->fireEvent( nEventId, rOldValue, rNewValue );
692cdf0e10cSrcweir }
693cdf0e10cSrcweir // -----------------------------------------------------------------------------
694cdf0e10cSrcweir ScrollBar* SvxShowCharSet::getScrollBar()
695cdf0e10cSrcweir {
696cdf0e10cSrcweir     return &aVscrollSB;
697cdf0e10cSrcweir }
698cdf0e10cSrcweir // -----------------------------------------------------------------------
699cdf0e10cSrcweir sal_Int32 SvxShowCharSet::getMaxCharCount() const
700cdf0e10cSrcweir {
701cdf0e10cSrcweir     return maFontCharMap.GetCharCount();
702cdf0e10cSrcweir }
703cdf0e10cSrcweir 
704cdf0e10cSrcweir 
705cdf0e10cSrcweir // class SubsetMap =======================================================
706cdf0e10cSrcweir // TODO: should be moved into Font Attributes stuff
707cdf0e10cSrcweir // we let it mature here though because it is currently the only use
708cdf0e10cSrcweir 
709cdf0e10cSrcweir SubsetMap::SubsetMap( const FontCharMap* pFontCharMap )
710cdf0e10cSrcweir :   Resource( SVX_RES(RID_SUBSETMAP) )
711cdf0e10cSrcweir {
712cdf0e10cSrcweir     InitList();
713cdf0e10cSrcweir     ApplyCharMap( pFontCharMap );
714cdf0e10cSrcweir     FreeResource();
715cdf0e10cSrcweir }
716cdf0e10cSrcweir 
717cdf0e10cSrcweir const Subset* SubsetMap::GetNextSubset( bool bFirst ) const
718cdf0e10cSrcweir {
719cdf0e10cSrcweir     if( bFirst )
720cdf0e10cSrcweir         maSubsetIterator = maSubsets.begin();
721cdf0e10cSrcweir     if( maSubsetIterator == maSubsets.end() )
722cdf0e10cSrcweir         return NULL;
723cdf0e10cSrcweir     const Subset* s = &*(maSubsetIterator++);
724cdf0e10cSrcweir     return s;
725cdf0e10cSrcweir }
726cdf0e10cSrcweir 
727cdf0e10cSrcweir const Subset* SubsetMap::GetSubsetByUnicode( sal_UCS4 cChar ) const
728cdf0e10cSrcweir {
729cdf0e10cSrcweir     // TODO: is it worth to avoid a linear search?
730cdf0e10cSrcweir     for( const Subset* s = GetNextSubset( true ); s; s = GetNextSubset( false ) )
731cdf0e10cSrcweir         if( (s->GetRangeMin() <= cChar) && (cChar <= s->GetRangeMax()) )
732cdf0e10cSrcweir             return s;
733cdf0e10cSrcweir     return NULL;
734cdf0e10cSrcweir }
735cdf0e10cSrcweir 
736cdf0e10cSrcweir inline Subset::Subset( sal_UCS4 nMin, sal_UCS4 nMax, int resId)
737cdf0e10cSrcweir :   mnRangeMin(nMin), mnRangeMax(nMax), maRangeName( SVX_RES(resId) )
738cdf0e10cSrcweir {}
739cdf0e10cSrcweir 
740cdf0e10cSrcweir void SubsetMap::InitList()
741cdf0e10cSrcweir {
742cdf0e10cSrcweir     static SubsetList aAllSubsets;
743cdf0e10cSrcweir     static bool bInit = true;
744cdf0e10cSrcweir     if( bInit )
745cdf0e10cSrcweir     {
746cdf0e10cSrcweir         bInit = false;
747cdf0e10cSrcweir 
748cdf0e10cSrcweir         // TODO: eventually merge or split unicode subranges
749cdf0e10cSrcweir         //       a "native writer" should decide for his subsets
750cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0020, 0x007F, RID_SUBSETSTR_BASIC_LATIN ) );
751cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0080, 0x00FF, RID_SUBSETSTR_LATIN_1 ) );
752cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0100, 0x017F, RID_SUBSETSTR_LATIN_EXTENDED_A ) );
753cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0180, 0x024F, RID_SUBSETSTR_LATIN_EXTENDED_B ) );
754cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0250, 0x02AF, RID_SUBSETSTR_IPA_EXTENSIONS ) );
755cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x02B0, 0x02FF, RID_SUBSETSTR_SPACING_MODIFIERS ) );
756cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0300, 0x036F, RID_SUBSETSTR_COMB_DIACRITICAL ) );
757cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0370, 0x03FF, RID_SUBSETSTR_BASIC_GREEK ) );
758cdf0e10cSrcweir     //  aAllSubsets.push_back( Subset( 0x03D0, 0x03F3, RID_SUBSETSTR_GREEK_SYMS_COPTIC ) );
759cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0400, 0x04FF, RID_SUBSETSTR_CYRILLIC ) );
760cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0530, 0x058F, RID_SUBSETSTR_ARMENIAN ) );
761cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0590, 0x05FF, RID_SUBSETSTR_BASIC_HEBREW ) );
762cdf0e10cSrcweir     //  aAllSubsets.push_back( Subset( 0x0591, 0x05C4, RID_SUBSETSTR_HEBREW_EXTENDED ) );
763cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0600, 0x065F, RID_SUBSETSTR_BASIC_ARABIC ) );
764cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0660, 0x06FF, RID_SUBSETSTR_ARABIC_EXTENDED ) );
765cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0700, 0x074F, RID_SUBSETSTR_SYRIAC ) );
766cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0780, 0x07BF, RID_SUBSETSTR_THAANA ) );
767cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0900, 0x097F, RID_SUBSETSTR_DEVANAGARI ) );
768cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0980, 0x09FF, RID_SUBSETSTR_BENGALI ) );
769cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0A00, 0x0A7F, RID_SUBSETSTR_GURMUKHI ) );
770cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0A80, 0x0AFF, RID_SUBSETSTR_GUJARATI ) );
771cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0B00, 0x0B7F, RID_SUBSETSTR_ORIYA ) );
772cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0B80, 0x0BFF, RID_SUBSETSTR_TAMIL ) );
773cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0C00, 0x0C7F, RID_SUBSETSTR_TELUGU ) );
774cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0C80, 0x0CFF, RID_SUBSETSTR_KANNADA ) );
775cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0D00, 0x0D7F, RID_SUBSETSTR_MALAYALAM ) );
776cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0D80, 0x0DFF, RID_SUBSETSTR_SINHALA ) );
777cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0E00, 0x0E7F, RID_SUBSETSTR_THAI ) );
778cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0E80, 0x0EFF, RID_SUBSETSTR_LAO ) );
779cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x0F00, 0x0FBF, RID_SUBSETSTR_TIBETAN ) );
780cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x1000, 0x109F, RID_SUBSETSTR_MYANMAR ) );
781cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x10A0, 0x10FF, RID_SUBSETSTR_BASIC_GEORGIAN ) );
782cdf0e10cSrcweir     //  aAllSubsets.push_back( Subset( 0x10A0, 0x10C5, RID_SUBSETSTR_GEORGIAN_EXTENDED ) );
783cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x1100, 0x11FF, RID_SUBSETSTR_HANGUL_JAMO ) );
784cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x1200, 0x137F, RID_SUBSETSTR_ETHIOPIC ) );
785cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x13A0, 0x13FF, RID_SUBSETSTR_CHEROKEE ) );
786cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x1400, 0x167F, RID_SUBSETSTR_CANADIAN_ABORIGINAL ) );
787cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x1680, 0x169F, RID_SUBSETSTR_OGHAM ) );
788cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x16A0, 0x16F0, RID_SUBSETSTR_RUNIC ) );
789cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x1700, 0x171F, RID_SUBSETSTR_TAGALOG ) );
790cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x1720, 0x173F, RID_SUBSETSTR_HANUNOO ) );
791cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x1740, 0x175F, RID_SUBSETSTR_BUHID ) );
792cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x1760, 0x177F, RID_SUBSETSTR_TAGBANWA ) );
793cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x1780, 0x17FF, RID_SUBSETSTR_KHMER ) );
794cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x1800, 0x18AF, RID_SUBSETSTR_MONGOLIAN ) );
795cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x1E00, 0x1EFF, RID_SUBSETSTR_LATIN_EXTENDED_ADDS ) );
796cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x1F00, 0x1FFF, RID_SUBSETSTR_GREEK_EXTENDED ) );
797cdf0e10cSrcweir 
798cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2000, 0x206F, RID_SUBSETSTR_GENERAL_PUNCTUATION ) );
799cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2070, 0x209F, RID_SUBSETSTR_SUB_SUPER_SCRIPTS ) );
800cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x20A0, 0x20CF, RID_SUBSETSTR_CURRENCY_SYMBOLS ) );
801cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x20D0, 0x20FF, RID_SUBSETSTR_COMB_DIACRITIC_SYMS ) );
802cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2100, 0x214F, RID_SUBSETSTR_LETTERLIKE_SYMBOLS ) );
803cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2150, 0x218F, RID_SUBSETSTR_NUMBER_FORMS ) );
804cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2190, 0x21FF, RID_SUBSETSTR_ARROWS ) );
805cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2200, 0x22FF, RID_SUBSETSTR_MATH_OPERATORS ) );
806cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2300, 0x23FF, RID_SUBSETSTR_MISC_TECHNICAL ) );
807cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2400, 0x243F, RID_SUBSETSTR_CONTROL_PICTURES ) );
808cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2440, 0x245F, RID_SUBSETSTR_OPTICAL_CHAR_REC ) );
809cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2460, 0x24FF, RID_SUBSETSTR_ENCLOSED_ALPHANUM ) );
810cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2500, 0x257F, RID_SUBSETSTR_BOX_DRAWING ) );
811cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2580, 0x259F, RID_SUBSETSTR_BLOCK_ELEMENTS ) );
812cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x25A0, 0x25FF, RID_SUBSETSTR_GEOMETRIC_SHAPES ) );
813cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2600, 0x26FF, RID_SUBSETSTR_MISC_DINGBATS ) );
814cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2700, 0x27BF, RID_SUBSETSTR_DINGBATS ) );
815cdf0e10cSrcweir 
816cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x27C0, 0x27FF, RID_SUBSETSTR_MISC_MATH_SYMS_A ) );
817cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x27F0, 0x27FF, RID_SUBSETSTR_SUPPL_ARROWS_A ) );
818cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2800, 0x28FF, RID_SUBSETSTR_BRAILLE_PATTERNS ) );
819cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2900, 0x297F, RID_SUBSETSTR_SUPPL_ARROWS_B ) );
820cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2980, 0x29FF, RID_SUBSETSTR_MISC_MATH_SYMS_B ) );
821cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2E80, 0x2EFF, RID_SUBSETSTR_CJK_RADICAL_SUPPL ) );
822cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2F00, 0x2FDF, RID_SUBSETSTR_KANXI_RADICALS ) );
823cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x2FF0, 0x2FFF, RID_SUBSETSTR_IDEO_DESC_CHARS ) );
824cdf0e10cSrcweir 
825cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x3000, 0x303F, RID_SUBSETSTR_CJK_SYMS_PUNCTUATION ) );
826cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x3040, 0x309F, RID_SUBSETSTR_HIRAGANA ) );
827cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x30A0, 0x30FF, RID_SUBSETSTR_KATAKANA ) );
828cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x3100, 0x312F, RID_SUBSETSTR_BOPOMOFO ) );
829cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x3130, 0x318F, RID_SUBSETSTR_HANGUL_COMPAT_JAMO ) );
830cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x3190, 0x319F, RID_SUBSETSTR_KANBUN ) );
831cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x31A0, 0x31BF, RID_SUBSETSTR_BOPOMOFO_EXTENDED ) );
832cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x31C0, 0x31FF, RID_SUBSETSTR_KATAKANA_PHONETIC ) );
833cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x3200, 0x32FF, RID_SUBSETSTR_ENCLOSED_CJK_LETTERS ) );
834cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x3300, 0x33FF, RID_SUBSETSTR_CJK_COMPATIBILITY ) );
835cdf0e10cSrcweir 
836cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x3400, 0x4DFF, RID_SUBSETSTR_CJK_EXT_A_UNIFIED_IDGRAPH ) );
837cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0x4E00, 0x9FA5, RID_SUBSETSTR_CJK_UNIFIED_IDGRAPH ) );
838cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xA000, 0xA4CF, RID_SUBSETSTR_YI ) );
839cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xAC00, 0xB097, RID_SUBSETSTR_HANGUL_GA ) );
840cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xB098, 0xB2E3, RID_SUBSETSTR_HANGUL_NA ) );
841cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xB2E4, 0xB77B, RID_SUBSETSTR_HANGUL_DA ) );
842cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xB77C, 0xB9C7, RID_SUBSETSTR_HANGUL_RA ) );
843cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xB9C8, 0xBC13, RID_SUBSETSTR_HANGUL_MA ) );
844cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xBC14, 0xC0AB, RID_SUBSETSTR_HANGUL_BA ) );
845cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xC0AC, 0xC543, RID_SUBSETSTR_HANGUL_SA ) );
846cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xC544, 0xC78F, RID_SUBSETSTR_HANGUL_AH ) );
847cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xC790, 0xCC27, RID_SUBSETSTR_HANGUL_JA ) );
848cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xCC28, 0xCE73, RID_SUBSETSTR_HANGUL_CHA ) );
849cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xCE74, 0xD0BF, RID_SUBSETSTR_HANGUL_KA ) );
850cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xD0C0, 0xD30B, RID_SUBSETSTR_HANGUL_TA ) );
851cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xD30C, 0xD557, RID_SUBSETSTR_HANGUL_PA ) );
852cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xD558, 0xD7A3, RID_SUBSETSTR_HANGUL_HA ) );
853cdf0e10cSrcweir     //  aAllSubsets.push_back( Subset( 0xAC00, 0xD7AF, RID_SUBSETSTR_HANGUL ) );
854cdf0e10cSrcweir 
855cdf0e10cSrcweir     //  aAllSubsets.push_back( Subset( 0xD800, 0xDFFF, RID_SUBSETSTR_SURROGATE ) );
856cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xE000, 0xF8FF, RID_SUBSETSTR_PRIVATE_USE_AREA ) );
857cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xF900, 0xFAFF, RID_SUBSETSTR_CJK_COMPAT_IDGRAPHS ) );
858cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xFB00, 0xFB4F, RID_SUBSETSTR_ALPHA_PRESENTATION ) );
859cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xFB50, 0xFDFF, RID_SUBSETSTR_ARABIC_PRESENT_A ) );
860cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xFE20, 0xFE2F, RID_SUBSETSTR_COMBINING_HALF_MARKS ) );
861cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xFE30, 0xFE4F, RID_SUBSETSTR_CJK_COMPAT_FORMS ) );
862cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xFE50, 0xFE6F, RID_SUBSETSTR_SMALL_FORM_VARIANTS ) );
863cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xFE70, 0xFEFF, RID_SUBSETSTR_ARABIC_PRESENT_B ) );
864cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xFF00, 0xFFEF, RID_SUBSETSTR_HALFW_FULLW_FORMS ) );
865cdf0e10cSrcweir         aAllSubsets.push_back( Subset( 0xFFF0, 0xFFFF, RID_SUBSETSTR_SPECIALS ) );
866cdf0e10cSrcweir     }
867cdf0e10cSrcweir 
868cdf0e10cSrcweir     maSubsets = aAllSubsets;
869cdf0e10cSrcweir }
870cdf0e10cSrcweir 
871cdf0e10cSrcweir void SubsetMap::ApplyCharMap( const FontCharMap* pFontCharMap )
872cdf0e10cSrcweir {
873cdf0e10cSrcweir     if( !pFontCharMap )
874cdf0e10cSrcweir         return;
875cdf0e10cSrcweir 
876cdf0e10cSrcweir     // remove subsets that are not matched in any range
877cdf0e10cSrcweir     SubsetList::iterator it_next = maSubsets.begin();
878cdf0e10cSrcweir     while( it_next != maSubsets.end() )
879cdf0e10cSrcweir     {
880cdf0e10cSrcweir         SubsetList::iterator it = it_next++;
881cdf0e10cSrcweir         const Subset& rSubset = *it;
882cdf0e10cSrcweir         sal_uInt32 cMin = rSubset.GetRangeMin();
883cdf0e10cSrcweir         sal_uInt32 cMax = rSubset.GetRangeMax();
884cdf0e10cSrcweir 
885cdf0e10cSrcweir         int nCount =  pFontCharMap->CountCharsInRange( cMin, cMax );
886cdf0e10cSrcweir         if( nCount <= 0 )
887cdf0e10cSrcweir             maSubsets.erase( it );
888cdf0e10cSrcweir     }
889cdf0e10cSrcweir }
890