5 #define YUILogComponent "gtk"
6 #include <yui/Libyui_config.h>
15 #include "ygtkfixed.h"
18 static void doMoveChild (GtkWidget *fixed, YWidget *ychild,
int x,
int y)
20 GtkWidget *child = YGWidget::get (ychild)->getLayout();
21 ygtk_fixed_set_child_pos (YGTK_FIXED (fixed), child, x, y);
24 #define YGLAYOUT_INIT \
25 ygtk_fixed_setup (YGTK_FIXED (getWidget()), preferred_width_cb, preferred_height_cb, set_size_cb, this);
26 #define YGLAYOUT_PREFERRED_SIZE_IMPL(ParentClass) \
27 static gint preferred_width_cb (YGtkFixed *fixed, gpointer pThis) { \
28 return ((ParentClass *) pThis)->ParentClass::preferredWidth(); \
30 static gint preferred_height_cb (YGtkFixed *fixed, gpointer pThis) { \
31 return ((ParentClass *) pThis)->ParentClass::preferredHeight(); \
33 #define YGLAYOUT_SET_SIZE_IMPL(ParentClass) \
34 static void set_size_cb (YGtkFixed *fixed, gint width, gint height, \
36 ((ParentClass *) pThis)->ParentClass::setSize (width, height); \
38 virtual void moveChild (YWidget *ychild, int x, int y) \
39 { doMoveChild (getWidget(), ychild, x, y); } \
41 #include <YPushButton.h>
50 void addWidget (YWidget *ywidget)
52 if (
dynamic_cast <YPushButton *
> (ywidget)) {
53 bool create_group = !group;
55 group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
56 gtk_size_group_add_widget (group, YGWidget::get (ywidget)->getLayout());
58 g_object_unref (G_OBJECT (group));
63 #include <YLayoutBox.h>
72 : YLayoutBox (NULL, dim),
73 YGWidget (
this, parent, YGTK_TYPE_FIXED, NULL)
79 virtual void doAddChild (YWidget *ychild, GtkWidget *container)
81 YGWidget::doAddChild (ychild, container);
82 if (primary() == YD_HORIZ)
83 group.addWidget (ychild);
86 YGWIDGET_IMPL_CONTAINER (YLayoutBox)
87 YGLAYOUT_PREFERRED_SIZE_IMPL (YLayoutBox)
88 YGLAYOUT_SET_SIZE_IMPL (YLayoutBox)
91 YLayoutBox *YGWidgetFactory::createLayoutBox (YWidget *parent, YUIDimension dimension)
94 #include <YButtonBox.h>
103 YGWidget (
this, parent, YGTK_TYPE_FIXED, NULL)
107 setLayoutPolicy (gnomeLayoutPolicy());
111 virtual void doAddChild (YWidget *ychild, GtkWidget *container)
113 YGWidget::doAddChild (ychild, container);
114 group.addWidget (ychild);
117 YGWIDGET_IMPL_CONTAINER (YButtonBox)
118 YGLAYOUT_PREFERRED_SIZE_IMPL (YButtonBox)
119 YGLAYOUT_SET_SIZE_IMPL (YButtonBox)
122 YButtonBox *YGWidgetFactory::createButtonBox (YWidget *parent)
125 #include <YAlignment.h>
129 GdkPixbuf *m_background_pixbuf;
132 YGAlignment (YWidget *parent, YAlignmentType halign, YAlignmentType valign)
133 : YAlignment (NULL, halign, valign),
134 YGWidget (
this, parent, YGTK_TYPE_FIXED, NULL)
137 m_background_pixbuf = 0;
143 if (m_background_pixbuf)
144 g_object_unref (G_OBJECT (m_background_pixbuf));
147 YGWIDGET_IMPL_CONTAINER (YAlignment)
148 YGLAYOUT_PREFERRED_SIZE_IMPL (YAlignment)
149 YGLAYOUT_SET_SIZE_IMPL (YAlignment)
151 virtual void setBackgroundPixmap (
const std::string &_filename)
153 YAlignment::setBackgroundPixmap (_filename);
155 std::string filename (YAlignment::backgroundPixmap());
156 if (m_background_pixbuf)
157 g_object_unref (G_OBJECT (m_background_pixbuf));
159 if (filename.empty()) {
160 m_background_pixbuf = 0;
161 g_signal_handlers_disconnect_by_func (G_OBJECT (getWidget()),
162 (
void*) draw_event_cb,
this);
166 m_background_pixbuf = gdk_pixbuf_new_from_file (filename.c_str(), &error);
167 if (!m_background_pixbuf)
168 g_warning (
"Setting YAlignment background - couldn't load image '%s' - %s",
169 filename.c_str(), error->message);
171 g_signal_connect (G_OBJECT (getWidget()),
"draw",
172 G_CALLBACK (YGAlignment::draw_event_cb),
this);
176 static gboolean draw_event_cb (GtkWidget *widget, cairo_t *cr,
YGAlignment *pThis,
int width,
int height)
178 gdk_cairo_set_source_pixbuf (cr, pThis->m_background_pixbuf, 0, 0);
179 cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
181 cairo_rectangle (cr, 0, 0, width, height);
184 gtk_container_propagate_draw (GTK_CONTAINER (widget),
185 gtk_bin_get_child(GTK_BIN (widget)), cr);
191 YAlignment *YGWidgetFactory::createAlignment (YWidget *parent, YAlignmentType halign,
192 YAlignmentType valign)
193 {
return new YGAlignment (parent, halign, valign); }
203 YGWidget (
this, parent, GTK_TYPE_EVENT_BOX, NULL)
208 YGWIDGET_IMPL_COMMON (YEmpty)
211 YEmpty *YGWidgetFactory::createEmpty (YWidget *parent)
212 {
return new YGEmpty (parent); }
214 #include <YSpacing.h>
220 YGSpacing (YWidget *parent, YUIDimension dim,
bool stretchable, YLayoutSize_t size)
221 : YSpacing (NULL, dim, stretchable, size),
222 YGWidget (
this, parent, YGTK_TYPE_FIXED, NULL)
228 YGWIDGET_IMPL_COMMON (YSpacing)
229 YGLAYOUT_PREFERRED_SIZE_IMPL (YSpacing)
230 static void set_size_cb (
YGtkFixed *fixed, gint width, gint height,
234 YSpacing *YGWidgetFactory::createSpacing (YWidget *parent, YUIDimension dim,
235 bool stretchable, YLayoutSize_t size)
237 return new YGSpacing (parent, dim, stretchable, size);
240 #include <YReplacePoint.h>
247 : YReplacePoint (NULL),
248 YGWidget (
this, parent, GTK_TYPE_EVENT_BOX, NULL)
253 YGWIDGET_IMPL_CONTAINER (YReplacePoint)
256 YReplacePoint *YGWidgetFactory::createReplacePoint (YWidget *parent)
266 YGSquash (YWidget *parent,
bool hsquash,
bool vsquash)
267 : YSquash (NULL, hsquash, vsquash),
268 YGWidget (
this, parent, GTK_TYPE_EVENT_BOX, NULL)
273 YGWIDGET_IMPL_CONTAINER (YSquash)
276 YSquash *YGWidgetFactory::createSquash (YWidget *parent,
bool hsquash,
bool vsquash)
277 {
return new YGSquash (parent, hsquash, vsquash); }