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