xref: /trunk/main/svx/inc/svx/gallery1.hxx (revision 3334a7e6)
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 #ifndef _SVX_GALLERY1_HXX_
25 #define _SVX_GALLERY1_HXX_
26 
27 #include <tools/string.hxx>
28 #include <tools/list.hxx>
29 #include <tools/urlobj.hxx>
30 #include <svl/brdcst.hxx>
31 #include "svx/svxdllapi.h"
32 //#include "gallery.hrc"
33 
34 #include <cstdio>
35 #include <list>
36 
37 // ---------------------
38 // - GalleryThemeEntry -
39 // ---------------------
40 
41 class SvStream;
42 
43 class GalleryThemeEntry
44 {
45 private:
46 
47 	String					aName;
48 	INetURLObject			aThmURL;
49 	INetURLObject			aSdgURL;
50 	INetURLObject			aSdvURL;
51 	sal_uInt32					nFileNumber;
52 	sal_uInt32					nId;
53 	sal_Bool					bReadOnly;
54 	sal_Bool					bImported;
55 	sal_Bool					bModified;
56 	sal_Bool					bThemeNameFromResource;
57 
58 							GalleryThemeEntry();
59 	INetURLObject			ImplGetURLIgnoreCase( const INetURLObject& rURL ) const;
60 
61 public:
62 
63 							GalleryThemeEntry( const INetURLObject& rBaseURL, const String& rName,
64 											   sal_uInt32 nFileNumber, sal_Bool bReadOnly, sal_Bool bImported,
65 											   sal_Bool bNewFile, sal_uInt32 nId, sal_Bool bThemeNameFromResource );
~GalleryThemeEntry()66 							~GalleryThemeEntry() {};
67 
GetThemeName() const68 	const String&			GetThemeName() const { return aName; }
GetFileNumber() const69 	sal_uInt32					GetFileNumber() const { return nFileNumber; }
70 
GetThmURL() const71 	const INetURLObject&	GetThmURL() const { return aThmURL; }
GetSdgURL() const72 	const INetURLObject&	GetSdgURL() const { return aSdgURL; }
GetSdvURL() const73 	const INetURLObject&	GetSdvURL() const { return aSdvURL; }
74 
IsImported() const75 	sal_Bool					IsImported() const { return bImported; }
IsReadOnly() const76 	sal_Bool					IsReadOnly() const { return bReadOnly; }
77 	sal_Bool					IsDefault() const;
78 
IsHidden() const79 	sal_Bool					IsHidden() const { return aName.SearchAscii( "private://gallery/hidden/" ) == 0; }
80 
IsModified() const81 	sal_Bool					IsModified() const { return bModified; }
SetModified(sal_Bool bSet)82 	void					SetModified( sal_Bool bSet ) { bModified = ( bSet && !IsImported() && !IsReadOnly() ); }
83 
84 	void					SetName( const String& rNewName );
IsNameFromResource() const85 	sal_Bool					IsNameFromResource() const { return bThemeNameFromResource; }
86 
GetId() const87 	sal_uInt32					GetId() const { return nId; }
88 	void					SetId( sal_uInt32 nNewId, sal_Bool bResetThemeName );
89 };
90 
91 DECLARE_LIST( GalleryThemeList, GalleryThemeEntry* )
92 
93 // ---------------------------
94 // - GalleryImportThemeEntry -
95 // ---------------------------
96 
97 struct GalleryImportThemeEntry
98 {
99 	String			aThemeName;
100 	String			aUIName;
101 	INetURLObject	aURL;
102 	String			aImportName;
103 };
104 DECLARE_LIST( GalleryImportThemeList, GalleryImportThemeEntry* )
105 
106 // -----------------------------------------------------------------------------
107 
108 SvStream& operator<<( SvStream& rOut, const GalleryImportThemeEntry& rEntry );
109 SvStream& operator>>( SvStream& rIn, GalleryImportThemeEntry& rEntry );
110 
111 // -----------
112 // - Gallery -
113 // -----------
114 
115 class SfxListener;
116 class GalleryTheme;
117 
118 class Gallery : public SfxBroadcaster
119 {
120 	// only for gengal utility!
121 	friend Gallery* createGallery( const rtl::OUString& );
122 	friend void disposeGallery( Gallery* );
123 
124 private:
125 
126 	GalleryThemeList			aThemeList;
127 	GalleryImportThemeList		aImportList;
128 	List						aThemeCache;
129 	INetURLObject				aRelURL;
130 	INetURLObject				aUserURL;
131 	rtl_TextEncoding			nReadTextEncoding;
132 	sal_uIntPtr						nLastFileNumber;
133 	sal_Bool						bMultiPath;
134 
135 	void						ImplLoad( const String& rMultiPath );
136 	void						ImplLoadSubDirs( const INetURLObject& rBaseURL, sal_Bool& rbIsReadOnly );
137 	void						ImplLoadImports();
138 	void 						ImplWriteImportList();
139 
140 	SVX_DLLPUBLIC GalleryThemeEntry*			ImplGetThemeEntry( const String& rThemeName );
141 	GalleryThemeEntry* 			ImplGetThemeEntry( sal_uIntPtr nThemeId );
142 	GalleryImportThemeEntry*	ImplGetImportThemeEntry( const String& rImportName );
143 
144 	GalleryTheme*				ImplGetCachedTheme( const GalleryThemeEntry* pThemeEntry );
145 	void						ImplDeleteCachedTheme( GalleryTheme* pTheme );
146 
147 								SVX_DLLPUBLIC Gallery( const String& rMultiPath );
148 								SVX_DLLPUBLIC ~Gallery();
149 
150 public:
151 
152 	SVX_DLLPUBLIC static Gallery* GetGalleryInstance();
153 
GetThemeCount() const154 	sal_uIntPtr					GetThemeCount() const { return aThemeList.Count(); }
GetThemeInfo(sal_uIntPtr nPos)155 	const GalleryThemeEntry*	GetThemeInfo( sal_uIntPtr nPos ) { return aThemeList.GetObject( nPos ); }
GetThemeInfo(const String & rThemeName)156 	const GalleryThemeEntry*	GetThemeInfo( const String& rThemeName ) { return ImplGetThemeEntry( rThemeName ); }
157 
158 	SVX_DLLPUBLIC sal_Bool			HasTheme( const String& rThemeName );
159 	String						GetThemeName( sal_uIntPtr nThemeId ) const;
160 
161 	SVX_DLLPUBLIC sal_Bool			CreateTheme( const String& rThemeName, sal_uInt32 nNumFrom = 0 );
162 	sal_Bool						CreateImportTheme( const INetURLObject& rURL, const String& rFileName );
163 	sal_Bool						RenameTheme( const String& rOldName, const String& rNewName );
164 	SVX_DLLPUBLIC sal_Bool						RemoveTheme( const String& rThemeName );
165 
166 	SVX_DLLPUBLIC GalleryTheme* AcquireTheme( const String& rThemeName, SfxListener& rListener );
167 	SVX_DLLPUBLIC void			ReleaseTheme( GalleryTheme*	pTheme, SfxListener& rListener );
168 
169 public:
170 
171 	INetURLObject				GetImportURL( const String& rThemeName );
172 
GetUserURL() const173 	const INetURLObject&		GetUserURL() const { return aUserURL; }
GetRelativeURL() const174 	const INetURLObject&		GetRelativeURL() const { return aRelURL; }
175 
IsMultiPath() const176 	sal_Bool						IsMultiPath() const { return bMultiPath; }
177 };
178 
179 #endif // _SVX_GALLERY1_HXX_
180