Bump version to 5.0-14
[LibreOffice.git] / svtools / source / control / stdmenu.cxx
blob6a5e0dcf18f40773863c2766bfdf47e27e3315f5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <string.h>
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 )
52 // clear menu
53 Clear();
55 // add fonts
56 if (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();
68 while ( j )
70 OUString aText = GetItemText( GetItemId( j-1 ) );
71 if ( rI18nHelper.CompareString( rName, aText ) > 0 )
72 break;
73 j--;
75 InsertItem( i+1, rName, MenuItemBits::RADIOCHECK | MenuItemBits::AUTOCHECK, OString(), j );
79 SetCurName( maCurName );
82 void FontNameMenu::SetCurName(const OUString& rName)
84 maCurName = rName;
86 // check menu entry
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 ) )
94 nChecked = nItemId;
96 OUString aText = GetItemText( nItemId );
97 if ( aText == maCurName )
99 CheckItem( nItemId, true );
100 return;
104 if ( nChecked )
105 CheckItem( nChecked, false );
108 FontSizeMenu::FontSizeMenu()
109 : mpHeightAry( NULL )
110 , mnCurHeight( 100 )
112 SetMenuFlags( GetMenuFlags() | MenuFlags::NoAutoMnemonics );
115 FontSizeMenu::~FontSizeMenu()
117 if ( mpHeightAry )
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();
132 if ( !nCurItemId )
133 mnCurHeight = 0;
134 else
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 )
145 Clear();
147 // setup font size array
148 if ( mpHeightAry )
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] )
155 nSizeCount++;
157 sal_uInt16 nPos = 0;
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 );
177 else
179 // for fixed size fonts only selectable font size names
180 pTempAry = pAry;
181 while ( *pTempAry )
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 );
190 pTempAry++;
195 // then insert numerical font size values
196 const vcl::I18nHelper& rI18nHelper = Application::GetSettings().GetUILocaleI18nHelper();
197 pTempAry = pAry;
198 while ( *pTempAry )
200 mpHeightAry[nPos] = *pTempAry;
201 nPos++; // Id is nPos+1
202 InsertItem( nPos, rI18nHelper.GetNum( *pTempAry, 1, true, false ), MenuItemBits::RADIOCHECK | MenuItemBits::AUTOCHECK );
203 pTempAry++;
206 SetCurHeight( mnCurHeight );
209 void FontSizeMenu::SetCurHeight( long nHeight )
211 mnCurHeight = nHeight;
213 // check menu item
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 );
223 return;
226 if ( IsItemChecked( nItemId ) )
227 nChecked = nItemId;
230 if ( nChecked )
231 CheckItem( nChecked, false );
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */