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