GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svtools / source / control / stdmenu.cxx
blobf579dc2bd83db9d8339df434ab750a48af92e3d8
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 .
21 #include <string.h>
22 #include <vcl/svapp.hxx>
23 #include <vcl/i18nhelp.hxx>
24 #include <svtools/ctrltool.hxx>
25 #include <svtools/stdmenu.hxx>
27 // ========================================================================
29 FontNameMenu::FontNameMenu()
31 SetMenuFlags( GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS );
34 // -----------------------------------------------------------------------
36 FontNameMenu::~FontNameMenu()
40 // -----------------------------------------------------------------------
42 void FontNameMenu::Select()
44 maCurName = GetItemText( GetCurItemId() );
45 maSelectHdl.Call( this );
48 // -----------------------------------------------------------------------
50 void FontNameMenu::Highlight()
52 OUString aTempName = maCurName;
53 maCurName = GetItemText( GetCurItemId() );
54 maHighlightHdl.Call( this );
55 maCurName = aTempName;
58 // -----------------------------------------------------------------------
60 void FontNameMenu::Fill( const FontList* pList )
62 // clear menu
63 Clear();
65 // add fonts
66 const vcl::I18nHelper& rI18nHelper = Application::GetSettings().GetUILocaleI18nHelper();
67 // more than 100 fonts reduces the speed of opening the menu.
68 // So only the first 100 fonts will be displayed.
69 sal_uInt16 nFontCount = ::std::min( pList->GetFontNameCount(), static_cast< sal_uInt16 >(100) );
70 for (sal_uInt16 i = 0; i < nFontCount; ++i)
72 const OUString& rName = pList->GetFontName( i ).GetName();
74 // sort with the I18nHelper
75 sal_uInt16 j = GetItemCount();
76 while ( j )
78 OUString aText = GetItemText( GetItemId( j-1 ) );
79 if ( rI18nHelper.CompareString( rName, aText ) > 0 )
80 break;
81 j--;
83 InsertItem( i+1, rName, MIB_RADIOCHECK | MIB_AUTOCHECK, OString(), j );
86 SetCurName( maCurName );
89 // -----------------------------------------------------------------------
91 void FontNameMenu::SetCurName(const OUString& rName)
93 maCurName = rName;
95 // Menueintrag checken
96 sal_uInt16 nChecked = 0;
97 sal_uInt16 nItemCount = GetItemCount();
98 for( sal_uInt16 i = 0; i < nItemCount; i++ )
100 sal_uInt16 nItemId = GetItemId( i );
102 if ( IsItemChecked( nItemId ) )
103 nChecked = nItemId;
105 OUString aText = GetItemText( nItemId );
106 if ( aText == maCurName )
108 CheckItem( nItemId, sal_True );
109 return;
113 if ( nChecked )
114 CheckItem( nChecked, sal_False );
117 // ========================================================================
119 FontSizeMenu::FontSizeMenu()
120 : mpHeightAry( NULL )
121 , mnCurHeight( 100 )
123 SetMenuFlags( GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS );
126 // -----------------------------------------------------------------------
128 FontSizeMenu::~FontSizeMenu()
130 if ( mpHeightAry )
131 delete[] mpHeightAry;
134 // -----------------------------------------------------------------------
136 void FontSizeMenu::Select()
138 const sal_uInt16 nCurItemId = GetCurItemId();
139 mnCurHeight = mpHeightAry[ nCurItemId - 1 ];
140 maSelectHdl.Call( this );
143 // -----------------------------------------------------------------------
145 void FontSizeMenu::Highlight()
147 const long nTempHeight = mnCurHeight;
148 const sal_uInt16 nCurItemId = GetCurItemId();
149 if ( !nCurItemId )
150 mnCurHeight = 0;
151 else
153 //sal_Int32 nValue = GetItemText( nCurItemId ).ToInt32();
154 mnCurHeight = mpHeightAry[ nCurItemId - 1 ];
156 maHighlightHdl.Call( this );
157 mnCurHeight = nTempHeight;
160 // -----------------------------------------------------------------------
162 void FontSizeMenu::Fill( const FontInfo& rInfo, const FontList* pList )
164 Clear();
166 // setup font size array
167 if ( mpHeightAry )
168 delete[] mpHeightAry;
170 const sal_IntPtr* pTempAry;
171 const sal_IntPtr* pAry = pList->GetSizeAry( rInfo );
172 sal_uInt16 nSizeCount = 0;
173 while ( pAry[nSizeCount] )
174 nSizeCount++;
176 sal_uInt16 nPos = 0;
178 // first insert font size names (for simplified/traditional chinese)
179 FontSizeNames aFontSizeNames( Application::GetSettings().GetUILanguageTag().getLanguageType() );
180 mpHeightAry = new long[nSizeCount+aFontSizeNames.Count()];
181 if ( !aFontSizeNames.IsEmpty() )
183 if ( pAry == pList->GetStdSizeAry() )
185 // for scalable fonts all font size names
186 sal_uLong nCount = aFontSizeNames.Count();
187 for( sal_uLong i = 0; i < nCount; i++ )
189 OUString aSizeName = aFontSizeNames.GetIndexName( i );
190 long nSize = aFontSizeNames.GetIndexSize( i );
191 mpHeightAry[nPos] = nSize;
192 nPos++; // Id is nPos+1
193 InsertItem( nPos, aSizeName, MIB_RADIOCHECK | MIB_AUTOCHECK );
196 else
198 // for fixed size fonts only selectable font size names
199 pTempAry = pAry;
200 while ( *pTempAry )
202 OUString aSizeName = aFontSizeNames.Size2Name( *pTempAry );
203 if ( !aSizeName.isEmpty() )
205 mpHeightAry[nPos] = *pTempAry;
206 nPos++; // Id is nPos+1
207 InsertItem( nPos, aSizeName, MIB_RADIOCHECK | MIB_AUTOCHECK );
209 pTempAry++;
214 // then insert numerical font size values
215 const vcl::I18nHelper& rI18nHelper = Application::GetSettings().GetUILocaleI18nHelper();
216 pTempAry = pAry;
217 while ( *pTempAry )
219 mpHeightAry[nPos] = *pTempAry;
220 nPos++; // Id is nPos+1
221 InsertItem( nPos, rI18nHelper.GetNum( *pTempAry, 1, sal_True, sal_False ), MIB_RADIOCHECK | MIB_AUTOCHECK );
222 pTempAry++;
225 SetCurHeight( mnCurHeight );
228 // -----------------------------------------------------------------------
230 void FontSizeMenu::SetCurHeight( long nHeight )
232 mnCurHeight = nHeight;
234 // check menu item
235 sal_uInt16 nChecked = 0;
236 sal_uInt16 nItemCount = GetItemCount();
237 for( sal_uInt16 i = 0; i < nItemCount; i++ )
239 sal_uInt16 nItemId = GetItemId( i );
241 if ( mpHeightAry[i] == nHeight )
243 CheckItem( nItemId, sal_True );
244 return;
247 if ( IsItemChecked( nItemId ) )
248 nChecked = nItemId;
251 if ( nChecked )
252 CheckItem( nChecked, sal_False );
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */