1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <vcl/svapp.hxx>
22 #include <vcl/settings.hxx>
23 #include <vcl/i18nhelp.hxx>
24 #include <svtools/ctrltool.hxx>
25 #include <svtools/stdmenu.hxx>
27 FontNameMenu::FontNameMenu()
29 SetMenuFlags( GetMenuFlags() | MenuFlags::NoAutoMnemonics
);
32 FontNameMenu::~FontNameMenu()
36 void FontNameMenu::Select()
38 maCurName
= GetItemText( GetCurItemId() );
39 maSelectHdl
.Call( this );
42 void FontNameMenu::Highlight()
44 OUString aTempName
= maCurName
;
45 maCurName
= GetItemText( GetCurItemId() );
46 maHighlightHdl
.Call( this );
47 maCurName
= aTempName
;
50 void FontNameMenu::Fill( const FontList
* pList
)
58 const vcl::I18nHelper
& rI18nHelper
= Application::GetSettings().GetUILocaleI18nHelper();
59 // more than 100 fonts reduces the speed of opening the menu.
60 // So only the first 100 fonts will be displayed.
61 sal_uInt16 nFontCount
= ::std::min( pList
->GetFontNameCount(), static_cast< sal_uInt16
>(100) );
62 for (sal_uInt16 i
= 0; i
< nFontCount
; ++i
)
64 const OUString
& rName
= pList
->GetFontName( i
).GetName();
66 // sort with the I18nHelper
67 sal_uInt16 j
= GetItemCount();
70 OUString aText
= GetItemText( GetItemId( j
-1 ) );
71 if ( rI18nHelper
.CompareString( rName
, aText
) > 0 )
75 InsertItem( i
+1, rName
, MenuItemBits::RADIOCHECK
| MenuItemBits::AUTOCHECK
, OString(), j
);
79 SetCurName( maCurName
);
82 void FontNameMenu::SetCurName(const OUString
& rName
)
87 sal_uInt16 nChecked
= 0;
88 sal_uInt16 nItemCount
= GetItemCount();
89 for( sal_uInt16 i
= 0; i
< nItemCount
; i
++ )
91 sal_uInt16 nItemId
= GetItemId( i
);
93 if ( IsItemChecked( nItemId
) )
96 OUString aText
= GetItemText( nItemId
);
97 if ( aText
== maCurName
)
99 CheckItem( nItemId
, true );
105 CheckItem( nChecked
, false );
108 FontSizeMenu::FontSizeMenu()
109 : mpHeightAry( NULL
)
112 SetMenuFlags( GetMenuFlags() | MenuFlags::NoAutoMnemonics
);
115 FontSizeMenu::~FontSizeMenu()
118 delete[] mpHeightAry
;
121 void FontSizeMenu::Select()
123 const sal_uInt16 nCurItemId
= GetCurItemId();
124 mnCurHeight
= mpHeightAry
[ nCurItemId
- 1 ];
125 maSelectHdl
.Call( this );
128 void FontSizeMenu::Highlight()
130 const long nTempHeight
= mnCurHeight
;
131 const sal_uInt16 nCurItemId
= GetCurItemId();
136 //sal_Int32 nValue = GetItemText( nCurItemId ).ToInt32();
137 mnCurHeight
= mpHeightAry
[ nCurItemId
- 1 ];
139 maHighlightHdl
.Call( this );
140 mnCurHeight
= nTempHeight
;
143 void FontSizeMenu::Fill( const vcl::FontInfo
& rInfo
, const FontList
* pList
)
147 // setup font size array
149 delete[] mpHeightAry
;
151 const sal_IntPtr
* pTempAry
;
152 const sal_IntPtr
* pAry
= pList
->GetSizeAry( rInfo
);
153 sal_uInt16 nSizeCount
= 0;
154 while ( pAry
[nSizeCount
] )
159 // first insert font size names (for simplified/traditional chinese)
160 FontSizeNames
aFontSizeNames( Application::GetSettings().GetUILanguageTag().getLanguageType() );
161 mpHeightAry
= new long[nSizeCount
+aFontSizeNames
.Count()];
162 if ( !aFontSizeNames
.IsEmpty() )
164 if ( pAry
== FontList::GetStdSizeAry() )
166 // for scalable fonts all font size names
167 sal_uLong nCount
= aFontSizeNames
.Count();
168 for( sal_uLong i
= 0; i
< nCount
; i
++ )
170 OUString aSizeName
= aFontSizeNames
.GetIndexName( i
);
171 long nSize
= aFontSizeNames
.GetIndexSize( i
);
172 mpHeightAry
[nPos
] = nSize
;
173 nPos
++; // Id is nPos+1
174 InsertItem( nPos
, aSizeName
, MenuItemBits::RADIOCHECK
| MenuItemBits::AUTOCHECK
);
179 // for fixed size fonts only selectable font size names
183 OUString aSizeName
= aFontSizeNames
.Size2Name( *pTempAry
);
184 if ( !aSizeName
.isEmpty() )
186 mpHeightAry
[nPos
] = *pTempAry
;
187 nPos
++; // Id is nPos+1
188 InsertItem( nPos
, aSizeName
, MenuItemBits::RADIOCHECK
| MenuItemBits::AUTOCHECK
);
195 // then insert numerical font size values
196 const vcl::I18nHelper
& rI18nHelper
= Application::GetSettings().GetUILocaleI18nHelper();
200 mpHeightAry
[nPos
] = *pTempAry
;
201 nPos
++; // Id is nPos+1
202 InsertItem( nPos
, rI18nHelper
.GetNum( *pTempAry
, 1, true, false ), MenuItemBits::RADIOCHECK
| MenuItemBits::AUTOCHECK
);
206 SetCurHeight( mnCurHeight
);
209 void FontSizeMenu::SetCurHeight( long nHeight
)
211 mnCurHeight
= nHeight
;
214 sal_uInt16 nChecked
= 0;
215 sal_uInt16 nItemCount
= GetItemCount();
216 for( sal_uInt16 i
= 0; i
< nItemCount
; i
++ )
218 sal_uInt16 nItemId
= GetItemId( i
);
220 if ( mpHeightAry
[i
] == nHeight
)
222 CheckItem( nItemId
, true );
226 if ( IsItemChecked( nItemId
) )
231 CheckItem( nChecked
, false );
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */