update dev300-m58
[ooovba.git] / sfx2 / source / dialog / styfitem.cxx
blob941e6115496462d76f48fdf320b2002d0f447506
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: styfitem.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 // INCLUDE ---------------------------------------------------------------
36 #ifndef GCC
37 #endif
39 #include <sfx2/styfitem.hxx>
40 #include <svtools/localresaccess.hxx>
41 #include <tools/debug.hxx>
43 // -----------------------------------------------------------------------
45 class SfxStyleFamilyItem_Impl
47 Bitmap aBitmap;
48 Image aImage;
51 // -----------------------------------------------------------------------
53 // Implementierung des Resource-Konstruktors
55 SfxStyleFamilyItem::SfxStyleFamilyItem( const ResId &rResId ) :
57 Resource( rResId.SetRT( RSC_SFX_STYLE_FAMILY_ITEM ) )
60 ULONG nMask = ReadLongRes();
62 if(nMask & RSC_SFX_STYLE_ITEM_LIST)
64 ULONG nCount = ReadLongRes();
65 for( ULONG i = 0; i < nCount; i++ )
67 SfxFilterTupel *pTupel = new SfxFilterTupel;
68 pTupel->aName = ReadStringRes();
69 long lFlags = ReadLongRes();
70 pTupel->nFlags = (USHORT)lFlags;
71 aFilterList.Insert(pTupel, LIST_APPEND);
74 if(nMask & RSC_SFX_STYLE_ITEM_BITMAP)
76 aBitmap = Bitmap(ResId((RSHEADER_TYPE *)GetClassRes(),*rResId.GetResMgr()));
77 IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
79 if(nMask & RSC_SFX_STYLE_ITEM_TEXT)
81 aText = ReadStringRes();
83 if(nMask & RSC_SFX_STYLE_ITEM_HELPTEXT)
85 aHelpText = ReadStringRes();
87 if(nMask & RSC_SFX_STYLE_ITEM_STYLEFAMILY)
89 nFamily = (USHORT)ReadLongRes();
91 else
92 nFamily = SFX_STYLE_FAMILY_PARA;
93 if(nMask & RSC_SFX_STYLE_ITEM_IMAGE)
95 aImage = Image(ResId((RSHEADER_TYPE *)GetClassRes(),*rResId.GetResMgr()));
96 IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
98 else
99 aImage = Image(aBitmap);
102 // -----------------------------------------------------------------------
104 // Destruktor; gibt interne Daten frei
106 SfxStyleFamilyItem::~SfxStyleFamilyItem()
108 SfxFilterTupel *pTupel = aFilterList.First();
109 while(pTupel)
111 delete pTupel;
112 pTupel = aFilterList.Next();
116 // -----------------------------------------------------------------------
118 // Implementierung des Resource-Konstruktors
120 SfxStyleFamilies::SfxStyleFamilies( const ResId& rResId ) :
122 Resource( rResId.SetRT( RSC_SFX_STYLE_FAMILIES ).SetAutoRelease( FALSE ) ),
123 aEntryList( 4, 1 )
125 ULONG nCount = ReadLongRes();
126 for( ULONG i = 0; i < nCount; i++ )
128 const ResId aResId((RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr());
129 SfxStyleFamilyItem *pItem = new SfxStyleFamilyItem(aResId);
130 IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
131 aEntryList.Insert(pItem, LIST_APPEND);
134 FreeResource();
136 updateImages( rResId, BMP_COLOR_NORMAL );
139 // -----------------------------------------------------------------------
141 // Destruktor; gibt interne Daten frei
143 SfxStyleFamilies::~SfxStyleFamilies()
145 SfxStyleFamilyItem *pItem = aEntryList.First();
147 while(pItem)
149 delete pItem;
150 pItem = aEntryList.Next();
155 // -----------------------------------------------------------------------
157 sal_Bool SfxStyleFamilies::updateImages( const ResId& _rId, const BmpColorMode _eMode )
159 sal_Bool bSuccess = sal_False;
162 ::svt::OLocalResourceAccess aLocalRes( _rId );
164 // check if the image list is present
165 ResId aImageListId( (sal_uInt16)_eMode + 1, *_rId.GetResMgr() );
166 aImageListId.SetRT( RSC_IMAGELIST );
168 if ( aLocalRes.IsAvailableRes( aImageListId ) )
169 { // there is such a list
170 ImageList aImages( aImageListId );
172 // number of styles items/images
173 sal_uInt16 nCount = aImages.GetImageCount( );
174 DBG_ASSERT( Count() == nCount, "SfxStyleFamilies::updateImages: found the image list, but missing some bitmaps!" );
175 if ( nCount > Count() )
176 nCount = Count();
178 // set the images on the items
179 for ( sal_uInt16 i = 0; i < nCount; ++i )
181 SfxStyleFamilyItem* pItem = static_cast< SfxStyleFamilyItem* >( aEntryList.GetObject( i ) );
182 pItem->SetImage( aImages.GetImage( aImages.GetImageId( i ) ) );
185 bSuccess = sal_True;
189 return bSuccess;