xref: /aoo4110/main/sfx2/source/dialog/styfitem.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sfx2.hxx"
26 
27 // INCLUDE ---------------------------------------------------------------
28 
29 #ifndef GCC
30 #endif
31 
32 #include <sfx2/styfitem.hxx>
33 #include <svtools/localresaccess.hxx>
34 #include <tools/debug.hxx>
35 
36 // -----------------------------------------------------------------------
37 
38 class SfxStyleFamilyItem_Impl
39 {
40 	Bitmap aBitmap;
41 	Image   aImage;
42 };
43 
44 // -----------------------------------------------------------------------
45 
46 // Implementierung des Resource-Konstruktors
47 
SfxStyleFamilyItem(const ResId & rResId)48 SfxStyleFamilyItem::SfxStyleFamilyItem( const ResId &rResId ) :
49 
50 	Resource( rResId.SetRT( RSC_SFX_STYLE_FAMILY_ITEM ) )
51 
52 {
53 	sal_uIntPtr nMask = ReadLongRes();
54 
55 	if(nMask & RSC_SFX_STYLE_ITEM_LIST)
56 	{
57 		sal_uIntPtr nCount = ReadLongRes();
58 		for( sal_uIntPtr i = 0; i < nCount; i++ )
59 		{
60 			SfxFilterTupel *pTupel = new SfxFilterTupel;
61 			pTupel->aName = ReadStringRes();
62 			long lFlags = ReadLongRes();
63 			pTupel->nFlags = (sal_uInt16)lFlags;
64 			aFilterList.Insert(pTupel, LIST_APPEND);
65 		}
66 	}
67 	if(nMask & RSC_SFX_STYLE_ITEM_BITMAP)
68 	{
69 		aBitmap = Bitmap(ResId((RSHEADER_TYPE *)GetClassRes(),*rResId.GetResMgr()));
70 		IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
71 	}
72 	if(nMask & RSC_SFX_STYLE_ITEM_TEXT)
73 	{
74 		aText = ReadStringRes();
75 	}
76 	if(nMask & RSC_SFX_STYLE_ITEM_HELPTEXT)
77 	{
78 		aHelpText = ReadStringRes();
79 	}
80 	if(nMask & RSC_SFX_STYLE_ITEM_STYLEFAMILY)
81 	{
82 		nFamily = (sal_uInt16)ReadLongRes();
83 	}
84 	else
85 		nFamily = SFX_STYLE_FAMILY_PARA;
86 	if(nMask & RSC_SFX_STYLE_ITEM_IMAGE)
87 	{
88 		aImage = Image(ResId((RSHEADER_TYPE *)GetClassRes(),*rResId.GetResMgr()));
89 		IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
90 	}
91 	else
92 		aImage = Image(aBitmap);
93 }
94 
95 // -----------------------------------------------------------------------
96 
97 // Destruktor; gibt interne Daten frei
98 
~SfxStyleFamilyItem()99 SfxStyleFamilyItem::~SfxStyleFamilyItem()
100 {
101 	SfxFilterTupel *pTupel = aFilterList.First();
102 	while(pTupel)
103 	{
104 		delete pTupel;
105 		pTupel = aFilterList.Next();
106 	}
107 }
108 
109 // -----------------------------------------------------------------------
110 
111 // Implementierung des Resource-Konstruktors
112 
SfxStyleFamilies(const ResId & rResId)113 SfxStyleFamilies::SfxStyleFamilies( const ResId& rResId ) :
114 
115 	Resource( rResId.SetRT( RSC_SFX_STYLE_FAMILIES ).SetAutoRelease( sal_False ) ),
116 	aEntryList( 4, 1 )
117 {
118 	sal_uIntPtr nCount = ReadLongRes();
119 	for( sal_uIntPtr i = 0; i < nCount; i++ )
120 	{
121 		const ResId aResId((RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr());
122 		SfxStyleFamilyItem *pItem = new SfxStyleFamilyItem(aResId);
123 		IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
124 		aEntryList.Insert(pItem, LIST_APPEND);
125 	}
126 
127 	FreeResource();
128 
129 	updateImages( rResId, BMP_COLOR_NORMAL );
130 }
131 
132 // -----------------------------------------------------------------------
133 
134 // Destruktor; gibt interne Daten frei
135 
~SfxStyleFamilies()136 SfxStyleFamilies::~SfxStyleFamilies()
137 {
138 	SfxStyleFamilyItem *pItem = aEntryList.First();
139 
140 	while(pItem)
141 	{
142 		delete pItem;
143 		pItem = aEntryList.Next();
144 	}
145 }
146 
147 
148 // -----------------------------------------------------------------------
149 
updateImages(const ResId & _rId,const BmpColorMode _eMode)150 sal_Bool SfxStyleFamilies::updateImages( const ResId& _rId, const BmpColorMode _eMode )
151 {
152 	sal_Bool bSuccess = sal_False;
153 
154 	{
155 		::svt::OLocalResourceAccess aLocalRes( _rId );
156 
157 		// check if the image list is present
158 		ResId aImageListId( (sal_uInt16)_eMode + 1, *_rId.GetResMgr() );
159 		aImageListId.SetRT( RSC_IMAGELIST );
160 
161 		if ( aLocalRes.IsAvailableRes( aImageListId ) )
162 		{	// there is such a list
163 			ImageList aImages( aImageListId );
164 
165 			// number of styles items/images
166 			sal_uInt16 nCount = aImages.GetImageCount( );
167 			DBG_ASSERT( Count() == nCount, "SfxStyleFamilies::updateImages: found the image list, but missing some bitmaps!" );
168 			if ( nCount > Count() )
169 				nCount = Count();
170 
171 			// set the images on the items
172 			for ( sal_uInt16 i = 0; i < nCount; ++i )
173 			{
174 				SfxStyleFamilyItem* pItem = static_cast< SfxStyleFamilyItem* >( aEntryList.GetObject( i ) );
175 				pItem->SetImage( aImages.GetImage( aImages.GetImageId( i ) ) );
176 			}
177 
178 			bSuccess = sal_True;
179 		}
180 	}
181 
182 	return bSuccess;
183 }
184