1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: stdmenu.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
37 #include <vcl/svapp.hxx>
40 #include <vcl/i18nhelp.hxx>
42 #include <ctrltool.hxx>
43 #include <stdmenu.hxx>
45 // ========================================================================
47 FontNameMenu::FontNameMenu()
49 SetMenuFlags( GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS
);
52 // -----------------------------------------------------------------------
54 FontNameMenu::~FontNameMenu()
58 // -----------------------------------------------------------------------
60 void FontNameMenu::Select()
62 maCurName
= GetItemText( GetCurItemId() );
63 maSelectHdl
.Call( this );
66 // -----------------------------------------------------------------------
68 void FontNameMenu::Highlight()
70 XubString aTempName
= maCurName
;
71 maCurName
= GetItemText( GetCurItemId() );
72 maHighlightHdl
.Call( this );
73 maCurName
= aTempName
;
76 // -----------------------------------------------------------------------
78 void FontNameMenu::Fill( const FontList
* pList
)
84 const vcl::I18nHelper
& rI18nHelper
= Application::GetSettings().GetUILocaleI18nHelper();
85 // more than 100 fonts reduces the speed of opening the menu.
86 // So only the first 100 fonts will be displayed.
87 USHORT nFontCount
= ::std::min( pList
->GetFontNameCount(), static_cast< USHORT
>(100) );
88 for ( USHORT i
= 0; i
< nFontCount
; i
++ )
90 const XubString
& rName
= pList
->GetFontName( i
).GetName();
92 // sort with the I18nHelper
93 USHORT j
= GetItemCount();
96 XubString aText
= GetItemText( GetItemId( j
-1 ) );
97 if ( rI18nHelper
.CompareString( rName
, aText
) > 0 )
101 InsertItem( i
+1, rName
, MIB_RADIOCHECK
| MIB_AUTOCHECK
, j
);
104 SetCurName( maCurName
);
107 // -----------------------------------------------------------------------
109 void FontNameMenu::SetCurName( const XubString
& rName
)
113 // Menueintrag checken
115 USHORT nItemCount
= GetItemCount();
116 for( USHORT i
= 0; i
< nItemCount
; i
++ )
118 USHORT nItemId
= GetItemId( i
);
120 if ( IsItemChecked( nItemId
) )
123 XubString aText
= GetItemText( nItemId
);
124 if ( aText
== maCurName
)
126 CheckItem( nItemId
, TRUE
);
132 CheckItem( nChecked
, FALSE
);
135 // ========================================================================
137 FontStyleMenu::FontStyleMenu()
139 SetMenuFlags( GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS
);
142 // -----------------------------------------------------------------------
144 FontStyleMenu::~FontStyleMenu()
148 // -----------------------------------------------------------------------
150 void FontStyleMenu::Select()
152 USHORT nCurId
= GetCurItemId();
154 if ( (nCurId
>= FONTSTYLEMENU_FIRSTID
) && (nCurId
<= FONTSTYLEMENU_LASTID
) )
156 maCurStyle
= GetItemText( nCurId
);
157 maSelectHdl
.Call( this );
163 // -----------------------------------------------------------------------
165 void FontStyleMenu::Highlight()
167 USHORT nCurId
= GetCurItemId();
169 if ( (nCurId
>= FONTSTYLEMENU_FIRSTID
) && (nCurId
<= FONTSTYLEMENU_LASTID
) )
171 XubString aTempName
= maCurStyle
;
172 maCurStyle
= GetItemText( nCurId
);
173 maHighlightHdl
.Call( this );
174 maCurStyle
= aTempName
;
177 PopupMenu::Highlight();
180 // -----------------------------------------------------------------------
182 BOOL
FontStyleMenu::ImplIsAlreadyInserted( const XubString
& rStyleName
, USHORT nCount
)
184 for ( USHORT i
= 0; i
< nCount
; i
++ )
186 if ( GetItemText( i
+FONTSTYLEMENU_FIRSTID
) == rStyleName
)
193 // -----------------------------------------------------------------------
195 void FontStyleMenu::Fill( const XubString
& rName
, const FontList
* pList
)
197 USHORT nItemId
= GetItemId( 0 );
198 while ( (nItemId
>= FONTSTYLEMENU_FIRSTID
) &&
199 (nItemId
<= FONTSTYLEMENU_LASTID
) )
202 nItemId
= GetItemId( 0 );
205 // Existiert ein Font mit diesem Namen
206 sal_Handle hFontInfo
= pList
->GetFirstFontInfo( rName
);
209 XubString aStyleText
;
211 USHORT nId
= FONTSTYLEMENU_FIRSTID
;
212 FontWeight eLastWeight
= WEIGHT_DONTKNOW
;
213 FontItalic eLastItalic
= ITALIC_NONE
;
214 FontWidth eLastWidth
= WIDTH_DONTKNOW
;
215 BOOL bNormal
= FALSE
;
216 BOOL bItalic
= FALSE
;
218 BOOL bBoldItalic
= FALSE
;
219 BOOL bInsert
= FALSE
;
223 aInfo
= pList
->GetFontInfo( hFontInfo
);
225 FontWeight eWeight
= aInfo
.GetWeight();
226 FontItalic eItalic
= aInfo
.GetItalic();
227 FontWidth eWidth
= aInfo
.GetWidthType();
228 // Only if the attributes are different, we insert the
229 // Font to avoid double Entries in different languages
230 if ( (eWeight
!= eLastWeight
) || (eItalic
!= eLastItalic
) ||
231 (eWidth
!= eLastWidth
) )
235 InsertItem( nId
, aStyleText
,
236 MIB_RADIOCHECK
| MIB_AUTOCHECK
, nPos
);
241 if ( eWeight
<= WEIGHT_NORMAL
)
243 if ( eItalic
!= ITALIC_NONE
)
250 if ( eItalic
!= ITALIC_NONE
)
256 // For wrong StyleNames we replace this with the correct once
257 aStyleText
= pList
->GetStyleName( aInfo
);
258 bInsert
= !ImplIsAlreadyInserted( aStyleText
, nPos
);
261 aStyleText
= pList
->GetStyleName( eWeight
, eItalic
);
262 bInsert
= !ImplIsAlreadyInserted( aStyleText
, nPos
);
265 eLastWeight
= eWeight
;
266 eLastItalic
= eItalic
;
273 // If we have two names for the same attributes
274 // we prefer the translated standard names
275 const XubString
& rAttrStyleText
= pList
->GetStyleName( eWeight
, eItalic
);
276 if ( rAttrStyleText
!= aStyleText
)
278 XubString aTempStyleText
= pList
->GetStyleName( aInfo
);
279 if ( rAttrStyleText
== aTempStyleText
)
280 aStyleText
= rAttrStyleText
;
281 bInsert
= !ImplIsAlreadyInserted( aStyleText
, nPos
);
286 if ( !bItalic
&& (aStyleText
== pList
->GetItalicStr()) )
288 else if ( !bBold
&& (aStyleText
== pList
->GetBoldStr()) )
290 else if ( !bBoldItalic
&& (aStyleText
== pList
->GetBoldItalicStr()) )
293 hFontInfo
= pList
->GetNextFontInfo( hFontInfo
);
298 InsertItem( nId
, aStyleText
,
299 MIB_RADIOCHECK
| MIB_AUTOCHECK
, nPos
);
304 // Bestimmte Styles als Nachbildung
309 InsertItem( nId
, pList
->GetItalicStr(),
310 MIB_RADIOCHECK
| MIB_AUTOCHECK
, nPos
);
316 InsertItem( nId
, pList
->GetBoldStr(),
317 MIB_RADIOCHECK
| MIB_AUTOCHECK
, nPos
);
324 if ( bNormal
|| bItalic
|| bBold
)
326 InsertItem( nId
, pList
->GetBoldItalicStr(),
327 MIB_RADIOCHECK
| MIB_AUTOCHECK
, nPos
);
335 // Wenn Font nicht, dann Standard-Styles einfuegen
336 InsertItem( FONTSTYLEMENU_FIRSTID
, pList
->GetNormalStr(),
337 MIB_RADIOCHECK
| MIB_AUTOCHECK
, 0 );
338 InsertItem( FONTSTYLEMENU_FIRSTID
+1, pList
->GetItalicStr(),
339 MIB_RADIOCHECK
| MIB_AUTOCHECK
, 0 );
340 InsertItem( FONTSTYLEMENU_FIRSTID
+2, pList
->GetBoldStr(),
341 MIB_RADIOCHECK
| MIB_AUTOCHECK
, 0 );
342 InsertItem( FONTSTYLEMENU_FIRSTID
+3, pList
->GetBoldItalicStr(),
343 MIB_RADIOCHECK
| MIB_AUTOCHECK
, 0 );
346 SetCurStyle( maCurStyle
);
349 // -----------------------------------------------------------------------
351 void FontStyleMenu::SetCurStyle( const XubString
& rStyle
)
355 // Menueintrag checken
357 USHORT nItemCount
= GetItemCount();
358 for( USHORT i
= 0; i
< nItemCount
; i
++ )
360 USHORT nItemId
= GetItemId( i
);
362 if ( (nItemId
< FONTSTYLEMENU_FIRSTID
) ||
363 (nItemId
> FONTSTYLEMENU_LASTID
) )
366 if ( IsItemChecked( nItemId
) )
369 XubString aText
= GetItemText( nItemId
);
370 if ( aText
== maCurStyle
)
372 CheckItem( nItemId
, TRUE
);
378 CheckItem( nChecked
, FALSE
);
381 // ========================================================================
383 FontSizeMenu::FontSizeMenu()
384 : mpHeightAry( NULL
)
387 SetMenuFlags( GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS
);
390 // -----------------------------------------------------------------------
392 FontSizeMenu::~FontSizeMenu()
395 delete[] mpHeightAry
;
398 // -----------------------------------------------------------------------
400 void FontSizeMenu::Select()
402 const USHORT nCurItemId
= GetCurItemId();
403 mnCurHeight
= mpHeightAry
[ nCurItemId
- 1 ];
404 maSelectHdl
.Call( this );
407 // -----------------------------------------------------------------------
409 void FontSizeMenu::Highlight()
411 const long nTempHeight
= mnCurHeight
;
412 const USHORT nCurItemId
= GetCurItemId();
417 //sal_Int32 nValue = GetItemText( nCurItemId ).ToInt32();
418 mnCurHeight
= mpHeightAry
[ nCurItemId
- 1 ];
420 maHighlightHdl
.Call( this );
421 mnCurHeight
= nTempHeight
;
424 // -----------------------------------------------------------------------
426 void FontSizeMenu::Fill( const FontInfo
& rInfo
, const FontList
* pList
)
430 // setup font size array
432 delete[] mpHeightAry
;
434 const long* pTempAry
;
435 const long* pAry
= pList
->GetSizeAry( rInfo
);
436 USHORT nSizeCount
= 0;
437 while ( pAry
[nSizeCount
] )
442 // first insert font size names (for simplified/traditional chinese)
443 FontSizeNames
aFontSizeNames( Application::GetSettings().GetUILanguage() );
444 mpHeightAry
= new long[nSizeCount
+aFontSizeNames
.Count()];
445 if ( !aFontSizeNames
.IsEmpty() )
447 if ( pAry
== pList
->GetStdSizeAry() )
449 // for scalable fonts all font size names
450 ULONG nCount
= aFontSizeNames
.Count();
451 for( ULONG i
= 0; i
< nCount
; i
++ )
453 String aSizeName
= aFontSizeNames
.GetIndexName( i
);
454 long nSize
= aFontSizeNames
.GetIndexSize( i
);
455 mpHeightAry
[nPos
] = nSize
;
456 nPos
++; // Id is nPos+1
457 InsertItem( nPos
, aSizeName
, MIB_RADIOCHECK
| MIB_AUTOCHECK
);
462 // for fixed size fonts only selectable font size names
466 String aSizeName
= aFontSizeNames
.Size2Name( *pTempAry
);
467 if ( aSizeName
.Len() )
469 mpHeightAry
[nPos
] = *pTempAry
;
470 nPos
++; // Id is nPos+1
471 InsertItem( nPos
, aSizeName
, MIB_RADIOCHECK
| MIB_AUTOCHECK
);
478 // then insert numerical font size values
479 const vcl::I18nHelper
& rI18nHelper
= Application::GetSettings().GetUILocaleI18nHelper();
483 mpHeightAry
[nPos
] = *pTempAry
;
484 nPos
++; // Id is nPos+1
485 InsertItem( nPos
, rI18nHelper
.GetNum( *pTempAry
, 1, TRUE
, FALSE
), MIB_RADIOCHECK
| MIB_AUTOCHECK
);
489 SetCurHeight( mnCurHeight
);
492 // -----------------------------------------------------------------------
494 void FontSizeMenu::SetCurHeight( long nHeight
)
496 mnCurHeight
= nHeight
;
499 XubString aHeight
= Application::GetSettings().GetUILocaleI18nHelper().GetNum( nHeight
, 1, TRUE
, FALSE
);
501 USHORT nItemCount
= GetItemCount();
502 for( USHORT i
= 0; i
< nItemCount
; i
++ )
504 USHORT nItemId
= GetItemId( i
);
506 if ( mpHeightAry
[i
] == nHeight
)
508 CheckItem( nItemId
, TRUE
);
512 if ( IsItemChecked( nItemId
) )
517 CheckItem( nChecked
, FALSE
);