2 /* $Id: style.ccg,v 1.5 2006/11/23 14:47:48 murrayc Exp $ */
4 /* Copyright 1998-2002 The gtkmm Development Team
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <gtkmm/widget.h>
23 #include <gtk/gtkstyle.h>
32 Okay these are my notes on how a GtkStyle works.
33 They are not meant to be taken as documentation as I didn't
36 styles keeps a copy of itself for each color depth. Thus
37 changing a style after it has been attached wont work!
39 At allocation time a Gtk Style has
40 - all GC set to 0 as they will be allocated later
41 - has all color values set to default values.
42 - a ref count of 1 and an attach count of 0 (floating?)
43 - a properly referenced font.
44 - colormap and depth are invalid.
45 - The style list and rcstyle are 0. (??? styles wasn't set explicitly!)
47 It returns to this state if the style is detatched from
50 Attach acts to sink the object removing it from the floating state.
52 attaching a style for the first time initializes it.
54 - sets the colormap and depth.
55 - sets the mid colors. (thus allowing user to set these would be pointless)
56 - gets black and white from the colormap.
57 - allocates all the colors.
58 - uses gtk_gc_get to share a gc if there is a matching one.
60 Conclusions, we need to rework the concept of Gdk to allow
65 void Style::set_font(const Pango::FontDescription& font_desc)
67 g_return_if_fail(font_desc.gobj() != 0);
69 // It will be freed when it goes out of scope.
70 const Pango::FontDescription fontBefore (gobj()->font_desc, false);
72 gobj()->font_desc = font_desc.gobj_copy();
75 Pango::FontDescription Style::get_font() const
77 // Direct struct access seems the only way.
78 return Pango::FontDescription(gobj()->font_desc, true); // true = make a copy.
81 Glib::RefPtr<Gdk::GC> Style::get_fg_gc(StateType state_type)
83 return Glib::wrap(gobj()->fg_gc[state_type], true);
86 Glib::RefPtr<const Gdk::GC> Style::get_fg_gc(StateType state_type) const
88 return Glib::wrap(gobj()->fg_gc[state_type], true);
91 Glib::RefPtr<Gdk::GC> Style::get_bg_gc(StateType state_type)
93 return Glib::wrap(gobj()->bg_gc[state_type], true);
96 Glib::RefPtr<const Gdk::GC> Style::get_bg_gc(StateType state_type) const
98 return Glib::wrap(gobj()->bg_gc[state_type], true);
101 Glib::RefPtr<Gdk::GC> Style::get_light_gc(StateType state_type)
103 return Glib::wrap(gobj()->light_gc[state_type], true);
106 Glib::RefPtr<const Gdk::GC> Style::get_light_gc(StateType state_type) const
108 return Glib::wrap(gobj()->light_gc[state_type], true);
111 Glib::RefPtr<Gdk::GC> Style::get_dark_gc(StateType state_type)
113 return Glib::wrap(gobj()->dark_gc[state_type], true);
116 Glib::RefPtr<const Gdk::GC> Style::get_dark_gc(StateType state_type) const
118 return Glib::wrap(gobj()->dark_gc[state_type], true);
121 Glib::RefPtr<Gdk::GC> Style::get_mid_gc(StateType state_type)
123 return Glib::wrap(gobj()->mid_gc[state_type], true);
126 Glib::RefPtr<const Gdk::GC> Style::get_mid_gc(StateType state_type) const
128 return Glib::wrap(gobj()->mid_gc[state_type], true);
131 Glib::RefPtr<Gdk::GC> Style::get_text_gc(StateType state_type)
133 return Glib::wrap(gobj()->text_gc[state_type], true);
136 Glib::RefPtr<const Gdk::GC> Style::get_text_gc(StateType state_type) const
138 return Glib::wrap(gobj()->text_gc[state_type], true);
141 Glib::RefPtr<Gdk::GC> Style::get_base_gc(StateType state_type)
143 return Glib::wrap(gobj()->base_gc[state_type], true);
146 Glib::RefPtr<const Gdk::GC> Style::get_base_gc(StateType state_type) const
148 return Glib::wrap(gobj()->base_gc[state_type], true);
151 _DEPRECATE_IFDEF_START
152 Gdk::Color Style::get_background(StateType state_type) const
154 GdkColor* pGdkColor = const_cast<GdkColor*>(&(gobj()->bg[state_type]));
155 return Glib::wrap(pGdkColor, true); //true = take_copy.
158 Glib::RefPtr<Gdk::Pixmap> Style::get_background_pixmap(StateType state_type)
160 return Glib::wrap((GdkPixmapObject*) (gobj()->bg_pixmap[state_type]), true); //true = take_copy.
163 void Style::set_bg_pixmap(StateType state_type, const Glib::RefPtr<Gdk::Pixmap>& pixmap)
165 GdkPixmap *const old_pixmap = gobj()->bg_pixmap[state_type];
166 gobj()->bg_pixmap[state_type] = Glib::unwrap_copy(pixmap);
169 g_object_unref(old_pixmap);
173 void Style::set_bg_pixmap(StateType state_type, const Glib::RefPtr<const Gdk::Pixmap>& pixmap)
175 GdkPixmap *const old_pixmap = gobj()->bg_pixmap[state_type];
176 Glib::RefPtr<Gdk::Pixmap> pixmap_unconst = Glib::RefPtr<Gdk::Pixmap>::cast_const(pixmap);
177 gobj()->bg_pixmap[state_type] = Glib::unwrap_copy(pixmap_unconst); //unwrap_copy() needs a non-const.
180 g_object_unref(old_pixmap);
183 Glib::RefPtr<Gdk::Pixmap> Style::get_bg_pixmap(StateType state_type)
185 return Glib::wrap((GdkPixmapObject*) (gobj()->bg_pixmap[state_type]), true); // true = take_copy
188 Glib::RefPtr<const Gdk::Pixmap> Style::get_bg_pixmap(StateType state_type) const
190 return Glib::wrap((GdkPixmapObject*) (gobj()->bg_pixmap[state_type]), true); // true = take_copy
193 void Style::set_xthickness(int xthickness)
195 gobj()->xthickness = xthickness;
198 void Style::set_ythickness(int ythickness)
200 gobj()->ythickness = ythickness;
203 void Style::paint_polygon(const Glib::RefPtr<Gdk::Window>& window,
204 StateType state_type,
205 ShadowType shadow_type,
206 const Gdk::Rectangle& area,
208 const Glib::ustring& detail,
209 const Glib::ArrayHandle<Gdk::Point>& points,
213 const_cast<GtkStyle*>(gobj()),
214 Glib::unwrap(window),
215 (GtkStateType) state_type,
216 (GtkShadowType) shadow_type,
217 const_cast<GdkRectangle*>(area.gobj()),
220 reinterpret_cast<GdkPoint*>(const_cast<Gdk::Point*>(points.data())),
225 IconSet Style::lookup_icon_set(const Gtk::StockID& stock_id)
227 GtkIconSet* pIconSet = gtk_style_lookup_icon_set(gobj(), stock_id.get_c_str());
228 return IconSet(pIconSet, true); //true = take_copy.