Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : */
9 : #include <filter/msfilter/mstoolbar.hxx>
10 : #include <rtl/ustrbuf.hxx>
11 : #include <stdarg.h>
12 : #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
13 : #include <com/sun/star/ui/XImageManager.hpp>
14 : #include <com/sun/star/ui/ItemType.hpp>
15 : #include <com/sun/star/ui/ItemStyle.hpp>
16 : #include <com/sun/star/frame/XLayoutManager.hpp>
17 : #include <fstream>
18 : #include <vcl/dibtools.hxx>
19 : #include <vcl/graph.hxx>
20 : #include <vcl/bitmapex.hxx>
21 : #include <vcl/image.hxx>
22 : #include <map>
23 : #include <sfx2/objsh.hxx>
24 : #include <basic/basmgr.hxx>
25 : #include <filter/msfilter/msvbahelper.hxx>
26 : #include <svtools/miscopt.hxx>
27 : #include <vcl/svapp.hxx>
28 : #include <vcl/window.hxx>
29 :
30 : using namespace com::sun::star;
31 :
32 : int TBBase::nIndent = 0;
33 :
34 0 : void CustomToolBarImportHelper::ScaleImage( uno::Reference< graphic::XGraphic >& xGraphic, long nNewSize )
35 : {
36 0 : Graphic aGraphic( xGraphic );
37 0 : Size aSize = aGraphic.GetSizePixel();
38 0 : if ( aSize.Height() && ( aSize.Height() == aSize.Width() ) )
39 : {
40 0 : Image aImage( xGraphic );
41 0 : if ( aSize.Height() != nNewSize )
42 : {
43 0 : BitmapEx aBitmap = aImage.GetBitmapEx();
44 0 : BitmapEx aBitmapex = BitmapEx::AutoScaleBitmap(aBitmap, nNewSize );
45 0 : aImage = Image( aBitmapex);
46 0 : xGraphic = aImage.GetXGraphic();
47 0 : }
48 0 : }
49 0 : }
50 :
51 0 : void CustomToolBarImportHelper::applyIcons()
52 : {
53 0 : for ( std::vector< iconcontrolitem >::iterator it = iconcommands.begin(); it != iconcommands.end(); ++it )
54 : {
55 0 : uno::Sequence< OUString > commands(1);
56 0 : commands[ 0 ] = it->sCommand;
57 0 : uno::Sequence< uno::Reference< graphic::XGraphic > > images(1);
58 0 : images[ 0 ] = it->image;
59 :
60 : OSL_TRACE("About to applyIcons for command %s, have image ? %s", OUStringToOString( commands[ 0 ], RTL_TEXTENCODING_UTF8 ).getStr(), images[ 0 ].is() ? "yes" : "no" );
61 0 : uno::Reference< ui::XImageManager > xImageManager( getCfgManager()->getImageManager(), uno::UNO_QUERY_THROW );
62 0 : sal_uInt16 nColor = ui::ImageType::COLOR_NORMAL;
63 :
64 0 : Window* topwin = Application::GetActiveTopWindow();
65 0 : if ( topwin != NULL && topwin->GetDisplayBackground().GetColor().IsDark() )
66 0 : nColor = css::ui::ImageType::COLOR_HIGHCONTRAST;
67 :
68 0 : ScaleImage( images[ 0 ], 16 );
69 0 : xImageManager->replaceImages( ui::ImageType::SIZE_DEFAULT | nColor, commands, images );
70 0 : ScaleImage( images[ 0 ], 26 );
71 0 : xImageManager->replaceImages( ui::ImageType::SIZE_LARGE | nColor, commands, images );
72 0 : }
73 0 : }
74 :
75 0 : void CustomToolBarImportHelper::addIcon( const uno::Reference< graphic::XGraphic >& xImage, const OUString& sString )
76 : {
77 0 : iconcontrolitem item;
78 0 : item.sCommand = sString;
79 0 : item.image = xImage;
80 0 : iconcommands.push_back( item );
81 0 : }
82 :
83 0 : CustomToolBarImportHelper::CustomToolBarImportHelper( SfxObjectShell& rDocShell, const css::uno::Reference< css::ui::XUIConfigurationManager>& rxAppCfgMgr ) : mrDocSh( rDocShell )
84 : {
85 0 : m_xCfgSupp.set( mrDocSh.GetModel(), uno::UNO_QUERY_THROW );
86 0 : m_xAppCfgMgr.set( rxAppCfgMgr, uno::UNO_QUERY_THROW );
87 0 : }
88 :
89 : uno::Reference< ui::XUIConfigurationManager >
90 0 : CustomToolBarImportHelper::getCfgManager()
91 : {
92 0 : return m_xCfgSupp->getUIConfigurationManager();
93 : }
94 :
95 : uno::Reference< ui::XUIConfigurationManager >
96 0 : CustomToolBarImportHelper::getAppCfgManager()
97 : {
98 0 : return m_xAppCfgMgr;
99 : }
100 :
101 : uno::Any
102 0 : CustomToolBarImportHelper::createCommandFromMacro( const OUString& sCmd )
103 : {
104 : //"vnd.sun.star.script:Standard.Module1.Main?language=Basic&location=document"
105 0 : static OUString scheme( "vnd.sun.star.script:" );
106 0 : static OUString part2( "?language=Basic&location=document" );
107 : // create script url
108 0 : OUString scriptURL = scheme + sCmd + part2;
109 0 : return uno::makeAny( scriptURL );
110 : }
111 :
112 0 : OUString CustomToolBarImportHelper::MSOCommandToOOCommand( sal_Int16 msoCmd )
113 : {
114 0 : OUString result;
115 0 : if ( pMSOCmdConvertor.get() )
116 0 : result = pMSOCmdConvertor->MSOCommandToOOCommand( msoCmd );
117 0 : return result;
118 : }
119 :
120 0 : OUString CustomToolBarImportHelper::MSOTCIDToOOCommand( sal_Int16 msoTCID )
121 : {
122 0 : OUString result;
123 0 : if ( pMSOCmdConvertor.get() )
124 0 : result = pMSOCmdConvertor->MSOTCIDToOOCommand( msoTCID );
125 0 : return result;
126 : }
127 :
128 : bool
129 0 : CustomToolBarImportHelper::createMenu( const OUString& rName, const uno::Reference< container::XIndexAccess >& xMenuDesc, bool bPersist )
130 : {
131 0 : bool bRes = true;
132 : try
133 : {
134 0 : uno::Reference< ui::XUIConfigurationManager > xCfgManager( getCfgManager() );
135 0 : OUString sMenuBar("private:resource/menubar/");
136 0 : sMenuBar += rName;
137 0 : uno::Reference< container::XIndexContainer > xPopup( xCfgManager->createSettings(), uno::UNO_QUERY_THROW );
138 0 : uno::Reference< beans::XPropertySet > xProps( xPopup, uno::UNO_QUERY_THROW );
139 : // set name for menubar
140 0 : xProps->setPropertyValue("UIName", uno::makeAny( rName ) );
141 0 : if ( xPopup.is() )
142 : {
143 0 : uno::Sequence< beans::PropertyValue > aPopupMenu( 4 );
144 0 : aPopupMenu[0].Name = "CommandURL";
145 0 : aPopupMenu[0].Value = uno::makeAny( OUString("vnd.openoffice.org:") + rName );
146 0 : aPopupMenu[1].Name = "Label";
147 0 : aPopupMenu[1].Value <<= rName;
148 0 : aPopupMenu[2].Name = "ItemDescriptorContainer";
149 0 : aPopupMenu[2].Value = uno::makeAny( xMenuDesc );
150 0 : aPopupMenu[3].Name = "Type";
151 0 : aPopupMenu[3].Value <<= sal_Int32( 0 );
152 :
153 0 : xPopup->insertByIndex( xPopup->getCount(), uno::makeAny( aPopupMenu ) );
154 0 : if ( bPersist )
155 : {
156 0 : xCfgManager->insertSettings( sMenuBar, uno::Reference< container::XIndexAccess >( xPopup, uno::UNO_QUERY ) );
157 0 : uno::Reference< ui::XUIConfigurationPersistence > xPersistence( xCfgManager, uno::UNO_QUERY_THROW );
158 0 : xPersistence->store();
159 0 : }
160 0 : }
161 : }
162 0 : catch( const uno::Exception& )
163 : {
164 0 : bRes = false;
165 : }
166 0 : return bRes;
167 : }
168 :
169 : void
170 0 : TBBase::indent_printf( FILE* fp, const char* format, ... )
171 : {
172 : va_list ap;
173 0 : va_start ( ap, format );
174 :
175 : // indent nIndent spaces
176 0 : for ( int i=0; i<nIndent; ++i)
177 0 : fprintf(fp," ");
178 : // append the rest of the message
179 0 : vfprintf( fp, format, ap );
180 0 : va_end( ap );
181 0 : }
182 :
183 0 : TBCHeader::TBCHeader()
184 : : bSignature(0x3)
185 : , bVersion(0x01)
186 : , bFlagsTCR(0)
187 : , tct(0x1) // default to Button
188 : , tcid(0)
189 : , tbct(0)
190 0 : , bPriority(0)
191 : {
192 0 : }
193 :
194 0 : TBCHeader::~TBCHeader()
195 : {
196 0 : }
197 :
198 0 : bool TBCHeader::Read( SvStream &rS )
199 : {
200 : OSL_TRACE("TBCHeader::Read() stream pos 0x%x", rS.Tell() );
201 0 : nOffSet = rS.Tell();
202 0 : rS.ReadSChar( bSignature ).ReadSChar( bVersion ).ReadUChar( bFlagsTCR ).ReadUChar( tct ).ReadUInt16( tcid ).ReadUInt32( tbct ).ReadUChar( bPriority );
203 : // bit 4 ( from lsb )
204 0 : if ( bFlagsTCR & 0x10 )
205 : {
206 0 : width.reset( new sal_uInt16 );
207 0 : height.reset( new sal_uInt16 );
208 0 : rS.ReadUInt16( *width ).ReadUInt16( *height );
209 : }
210 0 : return true;
211 : }
212 :
213 0 : void TBCHeader::Print( FILE* fp )
214 : {
215 0 : Indent a;
216 0 : indent_printf(fp,"[ 0x%x ] TBCHeader -- dump\n", nOffSet );
217 0 : indent_printf(fp," bSignature 0x%x\n", bSignature );
218 0 : indent_printf(fp," bVersion 0x%x\n", bVersion );
219 0 : indent_printf(fp," bFlagsTCR 0x%x\n", bFlagsTCR );
220 0 : indent_printf(fp," tct 0x%x\n", tct );
221 0 : indent_printf(fp," tcid 0x%x\n", tcid );
222 0 : indent_printf(fp," tbct 0x%x\n", static_cast< unsigned int >( tbct ));
223 0 : indent_printf(fp," bPriority 0x%x\n", bPriority );
224 0 : if ( width.get() )
225 0 : indent_printf(fp," width 0x%d(0x%x)\n", *width, *width);
226 0 : if ( height.get() )
227 0 : indent_printf(fp," height 0x%d(0x%x)\n", *height, *height);
228 0 : }
229 :
230 0 : TBCData::TBCData( const TBCHeader& Header ) : rHeader( Header )
231 : {
232 0 : }
233 :
234 0 : bool TBCData::Read(SvStream &rS)
235 : {
236 : OSL_TRACE("TBCData::Read() stream pos 0x%x", rS.Tell() );
237 0 : nOffSet = rS.Tell();
238 0 : if ( !controlGeneralInfo.Read(rS) /*|| !controlSpecificInfo.Read(rS)*/ )
239 0 : return false;
240 0 : switch ( rHeader.getTct() )
241 : {
242 : case 0x01: // (Button control)
243 : case 0x10: // (ExpandingGrid control)
244 0 : controlSpecificInfo.reset( new TBCBSpecific() );
245 0 : break;
246 : case 0x0A: // (Popup control)
247 : case 0x0C: // (ButtonPopup control)
248 : case 0x0D: // (SplitButtonPopup control)
249 : case 0x0E: // (SplitButtonMRUPopup control)
250 0 : controlSpecificInfo.reset( new TBCMenuSpecific() );
251 0 : break;
252 : case 0x02: // (Edit control)
253 : case 0x04: // (ComboBox control)
254 : case 0x14: // (GraphicCombo control)
255 : case 0x03: // (DropDown control)
256 : case 0x06: // (SplitDropDown control)
257 : case 0x09: // (GraphicDropDown control)
258 0 : controlSpecificInfo.reset( new TBCComboDropdownSpecific( rHeader ) );
259 0 : break;
260 : default:
261 0 : break;
262 : }
263 0 : if ( controlSpecificInfo.get() )
264 0 : return controlSpecificInfo->Read( rS );
265 : //#FIXME I need to be able to handle different controlSpecificInfo types.
266 0 : return true;
267 : }
268 :
269 0 : TBCMenuSpecific* TBCData::getMenuSpecific()
270 : {
271 0 : TBCMenuSpecific* pMenu = dynamic_cast< TBCMenuSpecific* >( controlSpecificInfo.get() );
272 0 : return pMenu;
273 : }
274 0 : bool TBCData::ImportToolBarControl( CustomToolBarImportHelper& helper, std::vector< css::beans::PropertyValue >& props, bool& bBeginGroup, bool bIsMenuBar )
275 : {
276 0 : sal_uInt16 nStyle = 0;
277 0 : bBeginGroup = rHeader.isBeginGroup();
278 0 : controlGeneralInfo.ImportToolBarControlData( helper, props );
279 0 : beans::PropertyValue aProp;
280 0 : aProp.Name = "Visible";
281 0 : aProp.Value = uno::makeAny( rHeader.isVisible() ); // where is the visible attribute stored
282 0 : props.push_back( aProp );
283 0 : if ( rHeader.getTct() == 0x01
284 0 : || rHeader.getTct() == 0x10 )
285 : {
286 0 : TBCBSpecific* pSpecificInfo = dynamic_cast< TBCBSpecific* >( controlSpecificInfo.get() );
287 0 : if ( pSpecificInfo )
288 : {
289 : // if we have a icon then lets set it for the command
290 0 : OUString sCommand;
291 0 : for ( std::vector< css::beans::PropertyValue >::iterator it = props.begin(); it != props.end(); ++it )
292 : {
293 0 : if ( it->Name == "CommandURL" )
294 0 : it->Value >>= sCommand;
295 : }
296 0 : if ( TBCBitMap* pIcon = pSpecificInfo->getIcon() )
297 : {
298 : // Without a command openoffice won't display the icon
299 0 : if ( !sCommand.isEmpty() )
300 : {
301 0 : BitmapEx aBitEx( pIcon->getBitMap() );
302 0 : if ( pSpecificInfo->getIconMask() )
303 : // according to the spec:
304 : // "the iconMask is white in all the areas in which the icon is
305 : // displayed as transparent and is black in all other areas."
306 0 : aBitEx = BitmapEx( aBitEx.GetBitmap(), pSpecificInfo->getIconMask()->getBitMap().CreateMask( Color( COL_WHITE ) ) );
307 :
308 0 : Graphic aGraphic( aBitEx );
309 0 : helper.addIcon( aGraphic.GetXGraphic(), sCommand );
310 : }
311 : }
312 0 : else if ( pSpecificInfo->getBtnFace() )
313 : {
314 :
315 0 : OUString sBuiltInCmd = helper.MSOTCIDToOOCommand( *pSpecificInfo->getBtnFace() );
316 0 : if ( !sBuiltInCmd.isEmpty() )
317 : {
318 0 : uno::Sequence< OUString> sCmds(1);
319 0 : sCmds[ 0 ] = sBuiltInCmd;
320 0 : uno::Reference< ui::XImageManager > xImageManager( helper.getAppCfgManager()->getImageManager(), uno::UNO_QUERY_THROW );
321 : // 0 = default image size
322 0 : uno::Sequence< uno::Reference< graphic::XGraphic > > sImages = xImageManager->getImages( 0, sCmds );
323 0 : if ( sImages.getLength() && sImages[0].is() )
324 0 : helper.addIcon( sImages[0], sCommand );
325 0 : }
326 0 : }
327 : }
328 : }
329 0 : else if ( rHeader.getTct() == 0x0a )
330 : {
331 0 : aProp.Name = "CommandURL";
332 0 : OUString sMenuBar("private:resource/menubar/");
333 :
334 0 : TBCMenuSpecific* pMenu = getMenuSpecific();
335 0 : if ( pMenu )
336 0 : aProp.Value = uno::makeAny( sMenuBar += pMenu->Name() ); // name of popup
337 0 : nStyle |= ui::ItemStyle::DROP_DOWN;
338 0 : props.push_back( aProp );
339 : }
340 :
341 0 : short icontext = ( rHeader.getTbct() & 0x03 );
342 0 : aProp.Name = "Style";
343 0 : if ( bIsMenuBar )
344 : {
345 0 : nStyle |= ui::ItemStyle::TEXT;
346 0 : if ( !icontext || icontext == 0x3 )
347 : // Text And image
348 0 : nStyle |= ui::ItemStyle::ICON;
349 : }
350 : else
351 : {
352 0 : if ( ( icontext & 0x02 ) == 0x02 )
353 0 : nStyle |= ui::ItemStyle::TEXT;
354 0 : if ( !icontext || ( icontext & 0x03 ) == 0x03 )
355 0 : nStyle |= ui::ItemStyle::ICON;
356 : }
357 0 : aProp.Value <<= nStyle;
358 0 : props.push_back( aProp );
359 0 : return true; // just ignore
360 : }
361 :
362 0 : void TBCData::Print( FILE* fp )
363 : {
364 0 : Indent a;
365 0 : indent_printf(fp,"[ 0x%x ] TBCData -- dump\n", nOffSet );
366 0 : indent_printf(fp," dumping controlGeneralInfo( TBCGeneralInfo )\n");
367 0 : controlGeneralInfo.Print( fp );
368 : //if ( rHeader.getTct() == 1 )
369 0 : if ( controlSpecificInfo.get() )
370 : {
371 0 : indent_printf(fp," dumping controlSpecificInfo( TBCBSpecificInfo )\n");
372 0 : controlSpecificInfo->Print( fp );
373 0 : }
374 0 : }
375 :
376 : bool
377 0 : WString::Read( SvStream &rS )
378 : {
379 : OSL_TRACE("WString::Read() stream pos 0x%x", rS.Tell() );
380 0 : nOffSet = rS.Tell();
381 0 : sal_uInt8 nChars = 0;
382 0 : rS.ReadUChar( nChars );
383 0 : sString = read_uInt16s_ToOUString(rS, nChars);
384 0 : return true;
385 : }
386 :
387 0 : TBCExtraInfo::TBCExtraInfo()
388 : : idHelpContext(0)
389 : , tbcu(0)
390 0 : , tbmg(0)
391 : {
392 0 : }
393 :
394 : bool
395 0 : TBCExtraInfo::Read( SvStream &rS )
396 : {
397 : OSL_TRACE("TBCExtraInfo::Read() stream pos 0x%x", rS.Tell() );
398 0 : nOffSet = rS.Tell();
399 0 : if( !wstrHelpFile.Read( rS ) )
400 0 : return false;
401 :
402 0 : rS.ReadInt32( idHelpContext );
403 :
404 0 : if ( !wstrTag.Read( rS ) || !wstrOnAction.Read( rS ) || !wstrParam.Read( rS ) )
405 0 : return false;
406 :
407 0 : rS.ReadSChar( tbcu ).ReadSChar( tbmg );
408 0 : return true;
409 : }
410 :
411 : void
412 0 : TBCExtraInfo::Print( FILE* fp )
413 : {
414 0 : Indent a;
415 0 : indent_printf( fp, "[ 0x%x ] TBCExtraInfo -- dump\n", nOffSet );
416 : indent_printf( fp, " wstrHelpFile %s\n",
417 0 : OUStringToOString( wstrHelpFile.getString(), RTL_TEXTENCODING_UTF8 ).getStr() );
418 0 : indent_printf( fp, " idHelpContext 0x%x\n", static_cast< unsigned int >( idHelpContext ) );
419 : indent_printf( fp, " wstrTag %s\n",
420 0 : OUStringToOString( wstrTag.getString(), RTL_TEXTENCODING_UTF8 ).getStr() );
421 : indent_printf( fp, " wstrOnAction %s\n",
422 0 : OUStringToOString( wstrOnAction.getString(), RTL_TEXTENCODING_UTF8 ).getStr() );
423 : indent_printf( fp, " wstrParam %s\n",
424 0 : OUStringToOString( wstrParam.getString(), RTL_TEXTENCODING_UTF8 ).getStr() );
425 0 : indent_printf( fp, " tbcu 0x%x\n", tbcu );
426 0 : indent_printf( fp, " tbmg 0x%x\n", tbmg );
427 :
428 0 : }
429 :
430 : OUString
431 0 : TBCExtraInfo::getOnAction()
432 : {
433 0 : return wstrOnAction.getString();
434 : }
435 :
436 0 : TBCGeneralInfo::TBCGeneralInfo() : bFlags( 0 )
437 : {
438 0 : }
439 :
440 0 : bool TBCGeneralInfo::Read( SvStream &rS )
441 : {
442 : OSL_TRACE("TBCGeneralInfo::Read() stream pos 0x%x", rS.Tell() );
443 0 : nOffSet = rS.Tell();
444 0 : rS.ReadUChar( bFlags );
445 :
446 0 : if ( ( bFlags & 0x1 ) && !customText.Read( rS ) )
447 0 : return false;
448 0 : if ( ( bFlags & 0x2 ) && ( !descriptionText.Read( rS ) || !tooltip.Read( rS ) ) )
449 0 : return false;
450 0 : if ( ( bFlags & 0x4 ) && !extraInfo.Read( rS ) )
451 0 : return false;
452 0 : return true;
453 : }
454 :
455 : void
456 0 : TBCGeneralInfo::Print( FILE* fp )
457 : {
458 0 : Indent a;
459 0 : indent_printf( fp, "[ 0x%x ] TBCGeneralInfo -- dump\n", nOffSet );
460 0 : indent_printf( fp, " bFlags 0x%x\n", bFlags );
461 : indent_printf( fp, " customText %s\n",
462 0 : OUStringToOString( customText.getString(), RTL_TEXTENCODING_UTF8 ).getStr() );
463 : indent_printf( fp, " description %s\n",
464 0 : OUStringToOString( descriptionText.getString(), RTL_TEXTENCODING_UTF8 ).getStr() );
465 : indent_printf( fp, " tooltip %s\n",
466 0 : OUStringToOString( tooltip.getString(), RTL_TEXTENCODING_UTF8 ).getStr() );
467 0 : if ( bFlags & 0x4 )
468 0 : extraInfo.Print( fp );
469 0 : }
470 :
471 : bool
472 0 : TBCGeneralInfo::ImportToolBarControlData( CustomToolBarImportHelper& helper, std::vector< beans::PropertyValue >& sControlData )
473 : {
474 0 : if ( ( bFlags & 0x5 ) )
475 : {
476 0 : beans::PropertyValue aProp;
477 : // probably access to the header would be a better test than seeing if there is an action, e.g.
478 : // if ( rHeader.getTct() == 0x01 && rHeader.getTcID() == 0x01 ) // not defined, probably this is a command
479 0 : if ( !extraInfo.getOnAction().isEmpty() )
480 : {
481 0 : aProp.Name = "CommandURL";
482 0 : ooo::vba::MacroResolvedInfo aMacroInf = ooo::vba::resolveVBAMacro( &helper.GetDocShell(), extraInfo.getOnAction(), true );
483 0 : if ( aMacroInf.mbFound )
484 0 : aProp.Value = helper.createCommandFromMacro( aMacroInf.msResolvedMacro );
485 : else
486 0 : aProp.Value <<= OUString( "UnResolvedMacro[" ).concat( extraInfo.getOnAction() ).concat( OUString( "]" ) );
487 0 : sControlData.push_back( aProp );
488 : }
489 :
490 0 : aProp.Name = "Label";
491 0 : aProp.Value = uno::makeAny( customText.getString().replace('&','~') );
492 0 : sControlData.push_back( aProp );
493 :
494 0 : aProp.Name = "Type";
495 0 : aProp.Value = uno::makeAny( ui::ItemType::DEFAULT );
496 0 : sControlData.push_back( aProp );
497 :
498 0 : aProp.Name = "Tooltip";
499 0 : aProp.Value = uno::makeAny( tooltip.getString() );
500 0 : sControlData.push_back( aProp );
501 : /*
502 : aToolbarItem(0).Name = "CommandURL" wstrOnAction
503 : aToolbarItem(0).Value = Command
504 : aToolbarItem(1).Name = "Label" customText
505 : aToolbarItem(1).Value = Label
506 : aToolbarItem(2).Name = "Type"
507 : aToolbarItem(2).Value = 0
508 : aToolbarItem(3).Name = "Visible"
509 : aToolbarItem(3).Value = true
510 : */
511 : }
512 0 : return true;
513 : }
514 :
515 0 : TBCMenuSpecific::TBCMenuSpecific() : tbid( 0 )
516 : {
517 0 : }
518 :
519 : bool
520 0 : TBCMenuSpecific::Read( SvStream &rS)
521 : {
522 : OSL_TRACE("TBCMenuSpecific::Read() stream pos 0x%x", rS.Tell() );
523 0 : nOffSet = rS.Tell();
524 0 : rS.ReadInt32( tbid );
525 0 : if ( tbid == 1 )
526 : {
527 0 : name.reset( new WString() );
528 0 : return name->Read( rS );
529 : }
530 0 : return true;
531 : }
532 :
533 : void
534 0 : TBCMenuSpecific::Print( FILE* fp )
535 : {
536 0 : Indent a;
537 0 : indent_printf( fp, "[ 0x%x ] TBCMenuSpecific -- dump\n", nOffSet );
538 0 : indent_printf( fp, " tbid 0x%x\n", static_cast< unsigned int >( tbid ) );
539 0 : if ( tbid == 1 )
540 0 : indent_printf( fp, " name %s\n", OUStringToOString( name->getString(), RTL_TEXTENCODING_UTF8 ).getStr() );
541 :
542 0 : }
543 :
544 0 : OUString TBCMenuSpecific::Name()
545 : {
546 0 : OUString aName;
547 0 : if ( name.get() )
548 0 : aName = name->getString();
549 0 : return aName;
550 : }
551 0 : TBCBSpecific::TBCBSpecific() : bFlags( 0 )
552 : {
553 0 : }
554 :
555 0 : bool TBCBSpecific::Read( SvStream &rS)
556 : {
557 : OSL_TRACE("TBCBSpecific::Read() stream pos 0x%x", rS.Tell() );
558 0 : nOffSet = rS.Tell();
559 0 : rS.ReadUChar( bFlags );
560 :
561 : // bFlags determines what we read next
562 :
563 : // bFlags.fCustomBitmap = 1 ( 0x8 ) set
564 0 : if ( bFlags & 0x8 )
565 : {
566 0 : icon.reset( new TBCBitMap() );
567 0 : iconMask.reset( new TBCBitMap() );
568 0 : if ( !icon->Read( rS ) || !iconMask->Read( rS ) )
569 0 : return false;
570 : }
571 : // if bFlags.fCustomBtnFace = 1 ( 0x10 )
572 0 : if ( bFlags & 0x10 )
573 : {
574 0 : iBtnFace.reset( new sal_uInt16 );
575 0 : rS.ReadUInt16( *iBtnFace.get() );
576 : }
577 : // if bFlags.fAccelerator equals 1 ( 0x04 )
578 0 : if ( bFlags & 0x04 )
579 : {
580 0 : wstrAcc.reset( new WString() );
581 0 : return wstrAcc->Read( rS );
582 : }
583 0 : return true;
584 : }
585 :
586 :
587 0 : void TBCBSpecific::Print( FILE* fp )
588 : {
589 0 : Indent a;
590 0 : indent_printf( fp, "[ 0x%x ] TBCBSpecific -- dump\n", nOffSet );
591 0 : indent_printf( fp, " bFlags 0x%x\n", bFlags );
592 0 : bool bResult = ( icon.get() != NULL );
593 0 : indent_printf( fp, " icon present? %s\n", bResult ? "true" : "false" );
594 0 : if ( bResult )
595 : {
596 0 : Indent b;
597 0 : indent_printf( fp, " icon: \n");
598 0 : icon->Print( fp ); // will dump size
599 : }
600 0 : bResult = ( iconMask.get() != NULL );
601 0 : indent_printf( fp, " icon mask present? %s\n", bResult ? "true" : "false" );
602 0 : if ( bResult )
603 : {
604 0 : Indent c;
605 0 : indent_printf( fp, " icon mask: \n");
606 0 : iconMask->Print( fp ); // will dump size
607 : }
608 0 : if ( iBtnFace.get() )
609 : {
610 0 : indent_printf( fp, " iBtnFace 0x%x\n", *(iBtnFace.get()) );
611 : }
612 0 : bResult = ( wstrAcc.get() != NULL );
613 0 : indent_printf( fp, " option string present? %s ->%s<-\n", bResult ? "true" : "false", bResult ? OUStringToOString( wstrAcc->getString(), RTL_TEXTENCODING_UTF8 ).getStr() : "N/A" );
614 0 : }
615 :
616 : TBCBitMap*
617 0 : TBCBSpecific::getIcon()
618 : {
619 0 : return icon.get();
620 : }
621 :
622 : TBCBitMap*
623 0 : TBCBSpecific::getIconMask()
624 : {
625 0 : return iconMask.get();
626 : }
627 :
628 0 : TBCComboDropdownSpecific::TBCComboDropdownSpecific(const TBCHeader& header )
629 : {
630 0 : if ( header.getTcID() == 0x01 )
631 0 : data.reset( new TBCCDData() );
632 0 : }
633 :
634 0 : bool TBCComboDropdownSpecific::Read( SvStream &rS)
635 : {
636 0 : nOffSet = rS.Tell();
637 0 : if ( data.get() )
638 0 : return data->Read( rS );
639 0 : return true;
640 : }
641 :
642 0 : void TBCComboDropdownSpecific::Print( FILE* fp)
643 : {
644 0 : Indent a;
645 0 : indent_printf(fp,"[ 0x%x ] TBCComboDropdownSpecific -- dump\n", nOffSet );
646 0 : if ( data.get() )
647 0 : data->Print( fp );
648 : else
649 0 : indent_printf(fp," no data " );
650 0 : }
651 :
652 0 : TBCCDData::TBCCDData()
653 : : cwstrItems(0)
654 : , cwstrMRU(0)
655 : , iSel(0)
656 : , cLines(0)
657 0 : , dxWidth(0)
658 : {
659 0 : }
660 :
661 0 : TBCCDData::~TBCCDData()
662 : {
663 0 : }
664 :
665 0 : bool TBCCDData::Read( SvStream &rS)
666 : {
667 0 : nOffSet = rS.Tell();
668 0 : rS.ReadInt16( cwstrItems );
669 0 : if ( cwstrItems )
670 : {
671 0 : for( sal_Int32 index=0; index < cwstrItems; ++index )
672 : {
673 0 : WString aString;
674 0 : if ( !aString.Read( rS ) )
675 0 : return false;
676 0 : wstrList.push_back( aString );
677 0 : }
678 : }
679 0 : rS.ReadInt16( cwstrMRU ).ReadInt16( iSel ).ReadInt16( cLines ).ReadInt16( dxWidth );
680 :
681 0 : return wstrEdit.Read( rS );
682 : }
683 :
684 0 : void TBCCDData::Print( FILE* fp)
685 : {
686 0 : Indent a;
687 0 : indent_printf(fp,"[ 0x%x ] TBCCDData -- dump\n", nOffSet );
688 0 : indent_printf(fp," cwstrItems items in wstrList 0x%d\n", cwstrItems);
689 0 : for ( sal_Int32 index=0; index < cwstrItems; ++index )
690 : {
691 0 : Indent b;
692 0 : indent_printf(fp, " wstrList[%d] %s", static_cast< int >( index ), OUStringToOString( wstrList[index].getString(), RTL_TEXTENCODING_UTF8 ).getStr() );
693 0 : }
694 0 : indent_printf(fp," cwstrMRU num most recently used string 0x%d item\n", cwstrMRU);
695 0 : indent_printf(fp," iSel index of selected item 0x%d item\n", iSel);
696 0 : indent_printf(fp," cLines num of suggested lines to display 0x%d", cLines);
697 0 : indent_printf(fp," dxWidth width in pixels 0x%d", dxWidth);
698 0 : indent_printf(fp," wstrEdit %s", OUStringToOString( wstrEdit.getString(), RTL_TEXTENCODING_UTF8 ).getStr() );
699 0 : }
700 :
701 0 : TBCBitMap::TBCBitMap() : cbDIB( 0 )
702 : {
703 0 : }
704 :
705 0 : TBCBitMap::~TBCBitMap()
706 : {
707 0 : }
708 :
709 : // #FIXME Const-ness
710 : Bitmap&
711 0 : TBCBitMap::getBitMap()
712 : {
713 0 : return mBitMap;
714 : }
715 :
716 0 : bool TBCBitMap::Read( SvStream& rS)
717 : {
718 : OSL_TRACE("TBCBitMap::Read() stream pos 0x%x", rS.Tell() );
719 0 : nOffSet = rS.Tell();
720 0 : rS.ReadInt32( cbDIB );
721 : // cbDIB = sizeOf(biHeader) + sizeOf(colors) + sizeOf(bitmapData) + 10
722 0 : return ReadDIB(mBitMap, rS, false);
723 : }
724 :
725 0 : void TBCBitMap::Print( FILE* fp )
726 : {
727 0 : Indent a;
728 0 : indent_printf(fp, "[ 0x%x ] TBCBitMap -- dump\n", nOffSet );
729 0 : indent_printf(fp, " TBCBitMap size of bitmap data 0x%x\n", static_cast< unsigned int > ( cbDIB ) );
730 0 : }
731 :
732 0 : TB::TB() : bSignature(0x2),
733 : bVersion(0x1),
734 : cCL(0),
735 : ltbid( 0x1 ),
736 : ltbtr(0),
737 : cRowsDefault( 0 ),
738 0 : bFlags( 0 )
739 : {
740 0 : }
741 :
742 0 : bool TB::Read(SvStream &rS)
743 : {
744 : OSL_TRACE("TB::Read() stream pos 0x%x", rS.Tell() );
745 0 : nOffSet = rS.Tell();
746 0 : rS.ReadUChar( bSignature ).ReadUChar( bVersion ).ReadInt16( cCL ).ReadInt32( ltbid ).ReadUInt32( ltbtr ).ReadUInt16( cRowsDefault ).ReadUInt16( bFlags );
747 0 : name.Read( rS );
748 0 : return true;
749 :
750 : }
751 :
752 0 : bool TB::IsEnabled()
753 : {
754 0 : return ( bFlags & 0x01 ) != 0x01;
755 : }
756 :
757 0 : void TB::Print( FILE* fp )
758 : {
759 0 : Indent a;
760 0 : indent_printf(fp,"[ 0x%x ] TB -- dump\n", nOffSet );
761 0 : indent_printf(fp," bSignature 0x%x\n", bSignature );
762 0 : indent_printf(fp," bVersion 0x%x\n", bVersion );
763 0 : indent_printf(fp," cCL 0x%x\n", cCL );
764 0 : indent_printf(fp," ltbid 0x%x\n", ltbid );
765 0 : indent_printf(fp," ltbtr 0x%x\n", ltbtr );
766 0 : indent_printf(fp," cRowsDefault 0x%x\n", cRowsDefault );
767 0 : indent_printf(fp," bFlags 0x%x\n", bFlags );
768 0 : indent_printf(fp, " name %s\n", OUStringToOString( name.getString(), RTL_TEXTENCODING_UTF8 ).getStr() );
769 0 : }
770 :
771 0 : TBVisualData::TBVisualData() : tbds(0), tbv(0), tbdsDock(0), iRow(0)
772 : {
773 0 : }
774 :
775 0 : bool TBVisualData::Read( SvStream& rS )
776 : {
777 : OSL_TRACE("TBVisualData::Read() stream pos 0x%x", rS.Tell() );
778 0 : nOffSet = rS.Tell();
779 0 : rS.ReadSChar( tbds ).ReadSChar( tbv ).ReadSChar( tbdsDock ).ReadSChar( iRow );
780 0 : rcDock.Read( rS );
781 0 : rcFloat.Read( rS );
782 0 : return true;
783 : }
784 :
785 0 : void SRECT::Print( FILE* fp )
786 : {
787 0 : Indent a;
788 0 : indent_printf( fp, " left 0x%x\n", left);
789 0 : indent_printf( fp, " top 0x%x\n", top);
790 0 : indent_printf( fp, " right 0x%x\n", right);
791 0 : indent_printf( fp, " bottom 0x%x\n", bottom);
792 0 : }
793 :
794 0 : void TBVisualData::Print( FILE* fp )
795 : {
796 0 : Indent a;
797 0 : indent_printf( fp, "[ 0x%x ] TBVisualData -- dump\n", nOffSet );
798 0 : indent_printf( fp, " tbds 0x%x\n", tbds);
799 0 : indent_printf( fp, " tbv 0x%x\n", tbv);
800 0 : indent_printf( fp, " tbdsDoc 0x%x\n", tbdsDock);
801 0 : indent_printf( fp, " iRow 0x%x\n", iRow);
802 0 : rcDock.Print( fp );
803 0 : rcFloat.Print( fp );
804 0 : }
805 :
806 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|