xref: /aoo41x/main/sfx2/source/dialog/styfitem.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sfx2.hxx"
30 
31 // INCLUDE ---------------------------------------------------------------
32 
33 #ifndef GCC
34 #endif
35 
36 #include <sfx2/styfitem.hxx>
37 #include <svtools/localresaccess.hxx>
38 #include <tools/debug.hxx>
39 
40 // -----------------------------------------------------------------------
41 
42 class SfxStyleFamilyItem_Impl
43 {
44 	Bitmap aBitmap;
45 	Image   aImage;
46 };
47 
48 // -----------------------------------------------------------------------
49 
50 // Implementierung des Resource-Konstruktors
51 
52 SfxStyleFamilyItem::SfxStyleFamilyItem( const ResId &rResId ) :
53 
54 	Resource( rResId.SetRT( RSC_SFX_STYLE_FAMILY_ITEM ) )
55 
56 {
57 	sal_uIntPtr nMask = ReadLongRes();
58 
59 	if(nMask & RSC_SFX_STYLE_ITEM_LIST)
60 	{
61 		sal_uIntPtr nCount = ReadLongRes();
62 		for( sal_uIntPtr i = 0; i < nCount; i++ )
63 		{
64 			SfxFilterTupel *pTupel = new SfxFilterTupel;
65 			pTupel->aName = ReadStringRes();
66 			long lFlags = ReadLongRes();
67 			pTupel->nFlags = (sal_uInt16)lFlags;
68 			aFilterList.Insert(pTupel, LIST_APPEND);
69 		}
70 	}
71 	if(nMask & RSC_SFX_STYLE_ITEM_BITMAP)
72 	{
73 		aBitmap = Bitmap(ResId((RSHEADER_TYPE *)GetClassRes(),*rResId.GetResMgr()));
74 		IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
75 	}
76 	if(nMask & RSC_SFX_STYLE_ITEM_TEXT)
77 	{
78 		aText = ReadStringRes();
79 	}
80 	if(nMask & RSC_SFX_STYLE_ITEM_HELPTEXT)
81 	{
82 		aHelpText = ReadStringRes();
83 	}
84 	if(nMask & RSC_SFX_STYLE_ITEM_STYLEFAMILY)
85 	{
86 		nFamily = (sal_uInt16)ReadLongRes();
87 	}
88 	else
89 		nFamily = SFX_STYLE_FAMILY_PARA;
90 	if(nMask & RSC_SFX_STYLE_ITEM_IMAGE)
91 	{
92 		aImage = Image(ResId((RSHEADER_TYPE *)GetClassRes(),*rResId.GetResMgr()));
93 		IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
94 	}
95 	else
96 		aImage = Image(aBitmap);
97 }
98 
99 // -----------------------------------------------------------------------
100 
101 // Destruktor; gibt interne Daten frei
102 
103 SfxStyleFamilyItem::~SfxStyleFamilyItem()
104 {
105 	SfxFilterTupel *pTupel = aFilterList.First();
106 	while(pTupel)
107 	{
108 		delete pTupel;
109 		pTupel = aFilterList.Next();
110 	}
111 }
112 
113 // -----------------------------------------------------------------------
114 
115 // Implementierung des Resource-Konstruktors
116 
117 SfxStyleFamilies::SfxStyleFamilies( const ResId& rResId ) :
118 
119 	Resource( rResId.SetRT( RSC_SFX_STYLE_FAMILIES ).SetAutoRelease( sal_False ) ),
120 	aEntryList( 4, 1 )
121 {
122 	sal_uIntPtr nCount = ReadLongRes();
123 	for( sal_uIntPtr i = 0; i < nCount; i++ )
124 	{
125 		const ResId aResId((RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr());
126 		SfxStyleFamilyItem *pItem = new SfxStyleFamilyItem(aResId);
127 		IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
128 		aEntryList.Insert(pItem, LIST_APPEND);
129 	}
130 
131 	FreeResource();
132 
133 	updateImages( rResId, BMP_COLOR_NORMAL );
134 }
135 
136 // -----------------------------------------------------------------------
137 
138 // Destruktor; gibt interne Daten frei
139 
140 SfxStyleFamilies::~SfxStyleFamilies()
141 {
142 	SfxStyleFamilyItem *pItem = aEntryList.First();
143 
144 	while(pItem)
145 	{
146 		delete pItem;
147 		pItem = aEntryList.Next();
148 	}
149 }
150 
151 
152 // -----------------------------------------------------------------------
153 
154 sal_Bool SfxStyleFamilies::updateImages( const ResId& _rId, const BmpColorMode _eMode )
155 {
156 	sal_Bool bSuccess = sal_False;
157 
158 	{
159 		::svt::OLocalResourceAccess aLocalRes( _rId );
160 
161 		// check if the image list is present
162 		ResId aImageListId( (sal_uInt16)_eMode + 1, *_rId.GetResMgr() );
163 		aImageListId.SetRT( RSC_IMAGELIST );
164 
165 		if ( aLocalRes.IsAvailableRes( aImageListId ) )
166 		{	// there is such a list
167 			ImageList aImages( aImageListId );
168 
169 			// number of styles items/images
170 			sal_uInt16 nCount = aImages.GetImageCount( );
171 			DBG_ASSERT( Count() == nCount, "SfxStyleFamilies::updateImages: found the image list, but missing some bitmaps!" );
172 			if ( nCount > Count() )
173 				nCount = Count();
174 
175 			// set the images on the items
176 			for ( sal_uInt16 i = 0; i < nCount; ++i )
177 			{
178 				SfxStyleFamilyItem* pItem = static_cast< SfxStyleFamilyItem* >( aEntryList.GetObject( i ) );
179 				pItem->SetImage( aImages.GetImage( aImages.GetImageId( i ) ) );
180 			}
181 
182 			bSuccess = sal_True;
183 		}
184 	}
185 
186 	return bSuccess;
187 }
188