The Gnome Chemistry Utils  0.14.0
theme.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 /*
4  * GChemPaint library
5  * theme.h
6  *
7  * Copyright (C) 2002-2009 Jean Bréfort <jean.brefort@normalesup.org>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 3 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22  * USA
23  */
24 
25 #ifndef GCHEMPAINT_THEME_H
26 #define GCHEMPAINT_THEME_H
27 
28 #include <gcu/macros.h>
29 #include <gcu/object.h>
30 #include <libxml/tree.h>
31 #include <list>
32 #include <map>
33 #include <string>
34 #include <set>
35 
38 namespace gcp {
39 
43 typedef enum {
60 } ThemeType;
61 
67 class Theme
68 {
69 friend class ThemeManager;
70 friend class PrefsDlg;
71 
72 public:
78  Theme (char const *name);
82  ~Theme ();
83 
87  std::string &GetName () {return m_Name;}
88 
92  std::string &GetFileName () {return (m_FileName.length ())? m_FileName: m_Name;}
93 
100  bool Save (xmlDocPtr xml);
106  bool Load (xmlNodePtr node);
112  bool operator== (const Theme &theme);
118  void AddClient (gcu::Object *client) {m_Clients.insert (client);}
124  void RemoveClient (gcu::Object *client);
128  void NotifyChanged ();
129 
130 private:
131  std::string m_Name, m_FileName;
132  std::set <gcu::Object*> m_Clients;
133  bool modified;
134  bool locked;
135 
139 GCU_RO_PROP (double, BondLength)
143 GCU_RO_PROP (double, BondAngle)
147 GCU_RO_PROP (double, BondDist)
151 GCU_RO_PROP (double, BondWidth)
155 GCU_RO_PROP (double, ArrowLength)
159 GCU_RO_PROP (double, HashWidth)
163 GCU_RO_PROP (double, HashDist)
167 GCU_RO_PROP (double, StereoBondWidth)
171 GCU_RO_PROP (double, ZoomFactor)
175 GCU_RO_PROP (double, Padding)
179 GCU_RO_PROP (double, ArrowHeadA)
183 GCU_RO_PROP (double, ArrowHeadB)
187 GCU_RO_PROP (double, ArrowHeadC)
191 GCU_RO_PROP (double, ArrowDist)
195 GCU_RO_PROP (double, ArrowWidth)
199 GCU_RO_PROP (double, ArrowPadding)
203 GCU_RO_PROP (double, ArrowObjectPadding)
207 GCU_RO_PROP (double, StoichiometryPadding)
211 GCU_RO_PROP (double, ObjectPadding)
215 GCU_RO_PROP (double, SignPadding)
219 GCU_RO_PROP (double, ChargeSignSize)
223 GCU_RO_PROP (gchar*, FontFamily)
227 GCU_RO_PROP (PangoStyle, FontStyle)
231 GCU_RO_PROP (PangoWeight, FontWeight)
235 GCU_RO_PROP (PangoVariant, FontVariant)
239 GCU_RO_PROP (PangoStretch, FontStretch)
243 GCU_RO_PROP (gint, FontSize)
247 GCU_RO_PROP (gchar*, TextFontFamily)
251 GCU_RO_PROP (PangoStyle, TextFontStyle)
255 GCU_RO_PROP (PangoWeight, TextFontWeight)
259 GCU_RO_PROP (PangoVariant, TextFontVariant)
263 GCU_RO_PROP (PangoStretch, TextFontStretch)
267 GCU_RO_PROP (gint, TextFontSize)
271 GCU_RO_PROP (ThemeType, ThemeType);
272 };
273 
281 {
282 public:
286  ThemeManager ();
290  ~ThemeManager ();
291 
297  Theme *GetTheme (char const *name);
303  Theme *GetTheme (std::string &name);
307  std::list <std::string> const &GetThemesNames ();
315  void OnConfigChanged (GOConfNode *node, gchar const *name);
321  Theme *CreateNewTheme (Theme *theme = NULL);
331  void AddFileTheme (Theme *theme, char const *label);
338  void RemoveFileTheme (Theme *theme);
345  void ChangeThemeName (Theme *theme, char const *name);
349  Theme *GetDefaultTheme () {return m_DefaultTheme;}
356  void SetDefaultTheme (char const *name);
361  void Shutdown ();
362 
363 private:
364  void ParseDir (std::string &path, ThemeType type);
365 
366 private:
367  std::map <std::string, Theme*> m_Themes;
368  std::list <std::string> m_Names;
369  GOConfNode *m_ConfNode;
370  guint m_NotificationId;
371  Theme *m_DefaultTheme;
372 };
373 
377 extern ThemeManager TheThemeManager;
378 
379 } // namespace gcp
380 
381 #endif // GCHEMPAINT_THEME_H