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 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <sfx2/styfitem.hxx>
21 : #include <svtools/localresaccess.hxx>
22 : #include <tools/debug.hxx>
23 :
24 :
25 :
26 : class SfxStyleFamilyItem_Impl
27 : {
28 : Bitmap aBitmap;
29 : Image aImage;
30 : };
31 :
32 :
33 :
34 : // Implementierung des Resource-Konstruktors
35 :
36 0 : SfxStyleFamilyItem::SfxStyleFamilyItem( const ResId &rResId ) :
37 :
38 0 : Resource( rResId.SetRT( RSC_SFX_STYLE_FAMILY_ITEM ) )
39 :
40 : {
41 0 : sal_uIntPtr nMask = ReadLongRes();
42 :
43 0 : if(nMask & RSC_SFX_STYLE_ITEM_LIST)
44 : {
45 0 : sal_uIntPtr nCount = ReadLongRes();
46 0 : for( sal_uIntPtr i = 0; i < nCount; i++ )
47 : {
48 0 : SfxFilterTupel *pTupel = new SfxFilterTupel;
49 0 : pTupel->aName = ReadStringRes();
50 0 : long lFlags = ReadLongRes();
51 0 : pTupel->nFlags = (sal_uInt16)lFlags;
52 0 : aFilterList.push_back( pTupel );
53 : }
54 : }
55 0 : if(nMask & RSC_SFX_STYLE_ITEM_BITMAP)
56 : {
57 0 : aBitmap = Bitmap(ResId((RSHEADER_TYPE *)GetClassRes(),*rResId.GetResMgr()));
58 0 : IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
59 : }
60 0 : if(nMask & RSC_SFX_STYLE_ITEM_TEXT)
61 : {
62 0 : aText = ReadStringRes();
63 : }
64 0 : if(nMask & RSC_SFX_STYLE_ITEM_HELPTEXT)
65 : {
66 0 : aHelpText = ReadStringRes();
67 : }
68 0 : if(nMask & RSC_SFX_STYLE_ITEM_STYLEFAMILY)
69 : {
70 0 : nFamily = (sal_uInt16)ReadLongRes();
71 : }
72 : else
73 0 : nFamily = SFX_STYLE_FAMILY_PARA;
74 0 : if(nMask & RSC_SFX_STYLE_ITEM_IMAGE)
75 : {
76 0 : aImage = Image(ResId((RSHEADER_TYPE *)GetClassRes(),*rResId.GetResMgr()));
77 0 : IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
78 : }
79 : else
80 0 : aImage = Image(aBitmap);
81 0 : }
82 :
83 :
84 :
85 : // Destructor; releases the internal data
86 :
87 0 : SfxStyleFamilyItem::~SfxStyleFamilyItem()
88 : {
89 0 : for ( size_t i = 0, n = aFilterList.size(); i < n; ++i )
90 0 : delete aFilterList[ i ];
91 0 : aFilterList.clear();
92 0 : }
93 :
94 :
95 :
96 : // Implementation of the resource constructor
97 :
98 0 : SfxStyleFamilies::SfxStyleFamilies( const ResId& rResId ) :
99 0 : Resource( rResId.SetRT( RSC_SFX_STYLE_FAMILIES ).SetAutoRelease( false ) )
100 : {
101 0 : sal_uIntPtr nCount = ReadLongRes();
102 0 : for( sal_uIntPtr i = 0; i < nCount; i++ )
103 : {
104 0 : const ResId aResId((RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr());
105 0 : SfxStyleFamilyItem *pItem = new SfxStyleFamilyItem(aResId);
106 0 : IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
107 0 : aEntryList.push_back( pItem );
108 : }
109 :
110 0 : FreeResource();
111 :
112 0 : updateImages( rResId );
113 0 : }
114 :
115 :
116 :
117 : // Destructor; releases the internal data
118 :
119 0 : SfxStyleFamilies::~SfxStyleFamilies()
120 : {
121 0 : for ( size_t i = 0, n = aEntryList.size(); i < n; ++i )
122 0 : delete aEntryList[ i ];
123 0 : aEntryList.clear();
124 0 : }
125 :
126 :
127 :
128 :
129 0 : bool SfxStyleFamilies::updateImages( const ResId& _rId )
130 : {
131 0 : bool bSuccess = false;
132 :
133 : {
134 0 : ::svt::OLocalResourceAccess aLocalRes( _rId );
135 :
136 : // check if the image list is present
137 0 : ResId aImageListId( (sal_uInt16) 1, *_rId.GetResMgr() );
138 0 : aImageListId.SetRT( RSC_IMAGELIST );
139 :
140 0 : if ( aLocalRes.IsAvailableRes( aImageListId ) )
141 : { // there is such a list
142 0 : ImageList aImages( aImageListId );
143 :
144 : // number of styles items/images
145 0 : sal_uInt16 nCount = aImages.GetImageCount( );
146 : DBG_ASSERT( aEntryList.size() == nCount, "SfxStyleFamilies::updateImages: found the image list, but missing some bitmaps!" );
147 0 : if ( nCount > aEntryList.size() )
148 0 : nCount = aEntryList.size();
149 :
150 : // set the images on the items
151 0 : for ( size_t i = 0; i < nCount; ++i )
152 : {
153 0 : SfxStyleFamilyItem* pItem = aEntryList[ i ];
154 0 : pItem->SetImage( aImages.GetImage( aImages.GetImageId( i ) ) );
155 : }
156 :
157 0 : bSuccess = true;
158 0 : }
159 : }
160 :
161 0 : return bSuccess;
162 : }
163 :
164 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|