Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / dialog / styfitem.cxx
blob54ff9d8482997ebc8a64951ff689434b6d6b382e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 // INCLUDE ---------------------------------------------------------------
32 #include <sfx2/styfitem.hxx>
33 #include <svtools/localresaccess.hxx>
34 #include <tools/debug.hxx>
36 // -----------------------------------------------------------------------
38 class SfxStyleFamilyItem_Impl
40 Bitmap aBitmap;
41 Image aImage;
44 // -----------------------------------------------------------------------
46 // Implementierung des Resource-Konstruktors
48 SfxStyleFamilyItem::SfxStyleFamilyItem( const ResId &rResId ) :
50 Resource( rResId.SetRT( RSC_SFX_STYLE_FAMILY_ITEM ) )
53 sal_uIntPtr nMask = ReadLongRes();
55 if(nMask & RSC_SFX_STYLE_ITEM_LIST)
57 sal_uIntPtr nCount = ReadLongRes();
58 for( sal_uIntPtr i = 0; i < nCount; i++ )
60 SfxFilterTupel *pTupel = new SfxFilterTupel;
61 pTupel->aName = ReadStringRes();
62 long lFlags = ReadLongRes();
63 pTupel->nFlags = (sal_uInt16)lFlags;
64 aFilterList.push_back( pTupel );
67 if(nMask & RSC_SFX_STYLE_ITEM_BITMAP)
69 aBitmap = Bitmap(ResId((RSHEADER_TYPE *)GetClassRes(),*rResId.GetResMgr()));
70 IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
72 if(nMask & RSC_SFX_STYLE_ITEM_TEXT)
74 aText = ReadStringRes();
76 if(nMask & RSC_SFX_STYLE_ITEM_HELPTEXT)
78 aHelpText = ReadStringRes();
80 if(nMask & RSC_SFX_STYLE_ITEM_STYLEFAMILY)
82 nFamily = (sal_uInt16)ReadLongRes();
84 else
85 nFamily = SFX_STYLE_FAMILY_PARA;
86 if(nMask & RSC_SFX_STYLE_ITEM_IMAGE)
88 aImage = Image(ResId((RSHEADER_TYPE *)GetClassRes(),*rResId.GetResMgr()));
89 IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
91 else
92 aImage = Image(aBitmap);
95 // -----------------------------------------------------------------------
97 // Destructor; releases the internal data
99 SfxStyleFamilyItem::~SfxStyleFamilyItem()
101 for ( size_t i = 0, n = aFilterList.size(); i < n; ++i )
102 delete aFilterList[ i ];
103 aFilterList.clear();
106 // -----------------------------------------------------------------------
108 // Implementation of the resource constructor
110 SfxStyleFamilies::SfxStyleFamilies( const ResId& rResId ) :
111 Resource( rResId.SetRT( RSC_SFX_STYLE_FAMILIES ).SetAutoRelease( false ) )
113 sal_uIntPtr nCount = ReadLongRes();
114 for( sal_uIntPtr i = 0; i < nCount; i++ )
116 const ResId aResId((RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr());
117 SfxStyleFamilyItem *pItem = new SfxStyleFamilyItem(aResId);
118 IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
119 aEntryList.push_back( pItem );
122 FreeResource();
124 updateImages( rResId );
127 // -----------------------------------------------------------------------
129 // Destructor; releases the internal data
131 SfxStyleFamilies::~SfxStyleFamilies()
133 for ( size_t i = 0, n = aEntryList.size(); i < n; ++i )
134 delete aEntryList[ i ];
135 aEntryList.clear();
139 // -----------------------------------------------------------------------
141 sal_Bool SfxStyleFamilies::updateImages( const ResId& _rId )
143 sal_Bool bSuccess = sal_False;
146 ::svt::OLocalResourceAccess aLocalRes( _rId );
148 // check if the image list is present
149 ResId aImageListId( (sal_uInt16) 1, *_rId.GetResMgr() );
150 aImageListId.SetRT( RSC_IMAGELIST );
152 if ( aLocalRes.IsAvailableRes( aImageListId ) )
153 { // there is such a list
154 ImageList aImages( aImageListId );
156 // number of styles items/images
157 sal_uInt16 nCount = aImages.GetImageCount( );
158 DBG_ASSERT( aEntryList.size() == nCount, "SfxStyleFamilies::updateImages: found the image list, but missing some bitmaps!" );
159 if ( nCount > aEntryList.size() )
160 nCount = aEntryList.size();
162 // set the images on the items
163 for ( size_t i = 0; i < nCount; ++i )
165 SfxStyleFamilyItem* pItem = aEntryList[ i ];
166 pItem->SetImage( aImages.GetImage( aImages.GetImageId( i ) ) );
169 bSuccess = sal_True;
173 return bSuccess;
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */