bump product version to 5.0.4.1
[LibreOffice.git] / sfx2 / source / dialog / styfitem.cxx
blobbc3aeb6553e2608e094b462214c960c69f48eeb6
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 .
20 #include <sfx2/styfitem.hxx>
21 #include <svtools/localresaccess.hxx>
22 #include <tools/debug.hxx>
26 class SfxStyleFamilyItem_Impl
28 Bitmap aBitmap;
29 Image aImage;
34 // Implementierung des Resource-Konstruktors
36 SfxStyleFamilyItem::SfxStyleFamilyItem( const ResId &rResId ) :
38 Resource( rResId.SetRT( RSC_SFX_STYLE_FAMILY_ITEM ) )
41 sal_uIntPtr nMask = ReadLongRes();
43 if(nMask & RSC_SFX_STYLE_ITEM_LIST)
45 sal_uIntPtr nCount = ReadLongRes();
46 for( sal_uIntPtr i = 0; i < nCount; i++ )
48 SfxFilterTupel *pTupel = new SfxFilterTupel;
49 pTupel->aName = ReadStringRes();
50 long lFlags = ReadLongRes();
51 pTupel->nFlags = (sal_uInt16)lFlags;
52 aFilterList.push_back( pTupel );
55 if(nMask & RSC_SFX_STYLE_ITEM_BITMAP)
57 aBitmap = Bitmap(ResId(static_cast<RSHEADER_TYPE *>(GetClassRes()),*rResId.GetResMgr()));
58 IncrementRes( GetObjSizeRes( static_cast<RSHEADER_TYPE *>(GetClassRes()) ) );
60 if(nMask & RSC_SFX_STYLE_ITEM_TEXT)
62 aText = ReadStringRes();
64 if(nMask & RSC_SFX_STYLE_ITEM_HELPTEXT)
66 aHelpText = ReadStringRes();
68 if(nMask & RSC_SFX_STYLE_ITEM_STYLEFAMILY)
70 nFamily = (sal_uInt16)ReadLongRes();
72 else
73 nFamily = SFX_STYLE_FAMILY_PARA;
74 if(nMask & RSC_SFX_STYLE_ITEM_IMAGE)
76 aImage = Image(ResId(static_cast<RSHEADER_TYPE *>(GetClassRes()),*rResId.GetResMgr()));
77 IncrementRes( GetObjSizeRes( static_cast<RSHEADER_TYPE *>(GetClassRes()) ) );
79 else
80 aImage = Image(aBitmap);
85 // Destructor; releases the internal data
87 SfxStyleFamilyItem::~SfxStyleFamilyItem()
89 for ( size_t i = 0, n = aFilterList.size(); i < n; ++i )
90 delete aFilterList[ i ];
91 aFilterList.clear();
96 // Implementation of the resource constructor
98 SfxStyleFamilies::SfxStyleFamilies( const ResId& rResId ) :
99 Resource( rResId.SetRT( RSC_SFX_STYLE_FAMILIES ).SetAutoRelease( false ) )
101 sal_uIntPtr nCount = ReadLongRes();
102 for( sal_uIntPtr i = 0; i < nCount; i++ )
104 const ResId aResId(static_cast<RSHEADER_TYPE *>(GetClassRes()), *rResId.GetResMgr());
105 SfxStyleFamilyItem *pItem = new SfxStyleFamilyItem(aResId);
106 IncrementRes( GetObjSizeRes( static_cast<RSHEADER_TYPE *>(GetClassRes()) ) );
107 aEntryList.push_back( pItem );
110 FreeResource();
112 updateImages( rResId );
117 // Destructor; releases the internal data
119 SfxStyleFamilies::~SfxStyleFamilies()
121 for ( size_t i = 0, n = aEntryList.size(); i < n; ++i )
122 delete aEntryList[ i ];
123 aEntryList.clear();
129 bool SfxStyleFamilies::updateImages( const ResId& _rId )
131 bool bSuccess = false;
134 ::svt::OLocalResourceAccess aLocalRes( _rId );
136 // check if the image list is present
137 ResId aImageListId( (sal_uInt16) 1, *_rId.GetResMgr() );
138 aImageListId.SetRT( RSC_IMAGELIST );
140 if ( aLocalRes.IsAvailableRes( aImageListId ) )
141 { // there is such a list
142 ImageList aImages( aImageListId );
144 // number of styles items/images
145 sal_uInt16 nCount = aImages.GetImageCount( );
146 DBG_ASSERT( aEntryList.size() == nCount, "SfxStyleFamilies::updateImages: found the image list, but missing some bitmaps!" );
147 if ( nCount > aEntryList.size() )
148 nCount = aEntryList.size();
150 // set the images on the items
151 for ( size_t i = 0; i < nCount; ++i )
153 SfxStyleFamilyItem* pItem = aEntryList[ i ];
154 pItem->SetImage( aImages.GetImage( aImages.GetImageId( i ) ) );
157 bSuccess = true;
161 return bSuccess;
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */