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