Author: rpmcruz
Date: Mon Jun 2 16:25:02 2008
New Revision: 47992
URL: http://svn.opensuse.org/viewcvs/yast?rev=47992&view=rev
Log:
* src/YGWidget.h/cc & src/YGLayout.h/cc: now using libyui for
the layout to avoid bugs and stuff. It's inter-laced with GTK,
so we can keep our simplified containers like the dumbtab.
* src/ygtkfixed.h/.c: added this container that makes life easier
for YGLayoutBox and others.
* src/ygtkratiobox.h/.c: simplified it.
Added:
trunk/gtk/src/ygtkfixed.c
trunk/gtk/src/ygtkfixed.h
Modified:
trunk/gtk/ChangeLog
trunk/gtk/src/Makefile.am
trunk/gtk/src/YGBarGraph.cc
trunk/gtk/src/YGDialog.cc
trunk/gtk/src/YGDialog.h
trunk/gtk/src/YGLabel.cc
trunk/gtk/src/YGLayout.cc
trunk/gtk/src/YGProgressBar.cc
trunk/gtk/src/YGUI.cc
trunk/gtk/src/YGUI.h
trunk/gtk/src/YGWidget.cc
trunk/gtk/src/YGWidget.h
trunk/gtk/src/ygtkbargraph.c
trunk/gtk/src/ygtkratiobox.c
trunk/gtk/src/ygtkratiobox.h
Modified: trunk/gtk/ChangeLog
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/ChangeLog?rev=47992&r1=47991&r2=47992&view=diff
==============================================================================
--- trunk/gtk/ChangeLog (original)
+++ trunk/gtk/ChangeLog Mon Jun 2 16:25:02 2008
@@ -1,3 +1,14 @@
+2008-06-02 Ricardo Cruz
+
+ * src/YGWidget.h/cc & src/YGLayout.h/cc: now using libyui for
+ the layout to avoid bugs and stuff. It's inter-laced with GTK,
+ so we can keep our simplified containers like the dumbtab.
+
+ * src/ygtkfixed.h/.c: added this container that makes life easier
+ for YGLayoutBox and others.
+
+ * src/ygtkratiobox.h/.c: simplified it.
+
2008-05-28 Ricardo Cruz
* src/YGDialog.cc: bug fix: seems like we shouldn't unref the
Modified: trunk/gtk/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/Makefile.am?rev=47992&r1=47991&r2=47992&view=diff
==============================================================================
--- trunk/gtk/src/Makefile.am (original)
+++ trunk/gtk/src/Makefile.am Mon Jun 2 16:25:02 2008
@@ -40,6 +40,7 @@
YGWizard.cc \
YGPackageSelector.cc \
ygtkratiobox.c \
+ ygtkfixed.c \
ygtkbargraph.c \
ygtksteps.c \
ygtkfieldentry.c \
Modified: trunk/gtk/src/YGBarGraph.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGBarGraph.cc?rev=47992&r1=47991&r2=47992&view=diff
==============================================================================
--- trunk/gtk/src/YGBarGraph.cc (original)
+++ trunk/gtk/src/YGBarGraph.cc Mon Jun 2 16:25:02 2008
@@ -15,7 +15,9 @@
YGBarGraph (YWidget *parent)
: YBarGraph (NULL)
, YGWidget (this, parent, true, YGTK_TYPE_BAR_GRAPH, NULL)
- {}
+ {
+ setMinSize (500, 0);
+ }
// YBarGraph
virtual void doUpdate()
Modified: trunk/gtk/src/YGDialog.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGDialog.cc?rev=47992&r1=47991&r2=47992&view=diff
==============================================================================
--- trunk/gtk/src/YGDialog.cc (original)
+++ trunk/gtk/src/YGDialog.cc Mon Jun 2 16:25:02 2008
@@ -7,90 +7,6 @@
#include
#include // easter
-/*
- * GtkWindow sub-class to ensure we can't get a size-allocation
- * that is larger than the screen.
- */
-typedef struct {
- GtkWindow parent;
- gboolean fullscreen;
-} YGtkWindow;
-
-typedef struct {
- GtkWindowClass parent_class;
-} YGtkWindowClass;
-
-G_DEFINE_TYPE (YGtkWindow, ygtk_window, GTK_TYPE_WINDOW)
-
-static void ygtk_window_set_fullscreen (YGtkWindow *window,
- gboolean fullscreen)
-{
- window->fullscreen = fullscreen;
-}
-
-static void ygtk_window_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
-{
- YGtkWindow *ywindow = (YGtkWindow *) widget;
-
- GTK_WIDGET_CLASS (ygtk_window_parent_class)->size_request (widget, requisition);
-
-// fprintf (stderr, "ygtk_window_size_request: %d %d\n",
-// requisition->width, requisition->height);
-
- GdkScreen *screen = gtk_widget_get_screen (widget);
- int max_screen_width = gdk_screen_get_width (screen);
- int max_screen_height = gdk_screen_get_height (screen);
-
- /*
- * FIXME: do we want to call gdk_window_get_frame_extents
- * on the root window ? - will that tell us about panels etc. ?
- *
- * FIXME: do we want to defer 'map' until we can get our
- * frame size from the realized window to do better here ?
- */
-
- // in the meantime shrink ourselves a little, to account for
- // window decoration / panels etc.
- if (!ywindow->fullscreen)
- {
- max_screen_height = 0.90 * max_screen_height;
- max_screen_width = 0.90 * max_screen_width;
- }
-
- if (requisition->width > max_screen_width)
- {
-// fprintf (stderr, "cropping width from %d to %d\n",
-// requisition->width, max_screen_width);
- requisition->width = max_screen_width;
- }
- if (requisition->height > max_screen_height)
- {
-// fprintf (stderr, "cropping height from %d to %d\n",
-// requisition->height, max_screen_height);
- requisition->height = max_screen_height;
- }
-}
-
-static void ygtk_window_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
-{
-/* fprintf (stderr, "YGDialog size alloc %d %d\n",
- allocation->width, allocation->height); */
- GTK_WIDGET_CLASS (ygtk_window_parent_class)->size_allocate (widget, allocation);
-}
-
-static void ygtk_window_init (YGtkWindow *) {}
-static void ygtk_window_class_init (YGtkWindowClass *klass)
-{
- GtkWidgetClass *wklass = (GtkWidgetClass *) klass;
-
- ygtk_window_parent_class = g_type_class_peek_parent (klass);
-
- wklass->size_request = ygtk_window_size_request;
- wklass->size_allocate = ygtk_window_size_allocate;
-}
-
/* In the main dialog case, it doesn't necessarly have a window of its own. If
there is already a main window, it should replace its content -- and when closed,
the previous dialog restored.
@@ -100,6 +16,8 @@
be a YGDialog and is swap-able.
*/
+#define DEFAULT_WIDTH 650
+#define DEFAULT_HEIGHT 550
class YGWindow;
static YGWindow *main_window = 0;
@@ -118,9 +36,9 @@
YGWindow (bool _main_window, YGDialog *ydialog)
{
- m_widget = GTK_WIDGET (g_object_new (ygtk_window_get_type(), NULL));
- g_object_ref (G_OBJECT (m_widget));
- gtk_object_sink (GTK_OBJECT (m_widget));
+ m_widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ g_object_ref_sink (G_OBJECT (m_widget));
+ g_object_set (G_OBJECT (m_widget), "allow-shrink", TRUE, NULL);
m_refcount = 0;
m_child = NULL;
@@ -161,14 +79,9 @@
}
if (_main_window) {
- int w = YGUI::ui()->_getDefaultWidth(),
- h = YGUI::ui()->_getDefaultHeight();
- gtk_window_set_default_size (window, w, h);
-
- if (YGUI::ui()->setFullscreen()) {
- gtk_window_fullscreen (window);
- ygtk_window_set_fullscreen ((YGtkWindow *)window, TRUE);
- }
+ gtk_window_set_default_size (window, DEFAULT_WIDTH, DEFAULT_HEIGHT);
+ if (YGUI::ui()->setFullscreen())
+ gtk_window_fullscreen (window);
}
gtk_window_set_role (window, "yast2-gtk");
@@ -202,8 +115,9 @@
void normalCursor()
{
- if (GTK_WIDGET_REALIZED (m_widget))
+ if (GTK_WIDGET_REALIZED (m_widget)) {
gdk_window_set_cursor (m_widget->window, NULL);
+ }
}
void busyCursor()
@@ -270,8 +184,7 @@
IMPL
// if not main dialog, close it on escape
if (event->keyval == GDK_Escape &&
- /* not main window */ main_window != pThis)
- {
+ /* not main window */ main_window != pThis) {
pThis->close();
return TRUE;
@@ -403,9 +316,6 @@
gtk_box_pack_start (GTK_BOX (getWidget()), icon, FALSE, FALSE, 12);
gtk_box_pack_start (GTK_BOX (getWidget()), m_containee, TRUE, TRUE, 0);
-
- GtkRequisition req;
- gtk_widget_size_request (icon, &req);
}
else
gtk_box_pack_start (GTK_BOX (getWidget()), m_containee, TRUE, TRUE, 0);
@@ -482,21 +392,12 @@
{
// libyui calls YDialog::setSize() to force a geometry recalculation as a
// result of changed layout properties
- struct inner {
- static void syncStretchable (YWidget *ywidget, YGWidget *widget)
- {
- for (YWidgetListConstIterator it = ywidget->childrenBegin();
- it != ywidget->childrenEnd(); it++) {
- YWidget *ychild = const_cast (*it);
- YGWidget *child = YGWidget::get (ychild);
- if (child) {
- widget->syncStretchable (ychild, child);
- syncStretchable (ychild, child);
- }
- }
- }
- };
- inner::syncStretchable (this, this);
+ GtkWidget *window = m_window->getWidget();
+ if (GTK_WIDGET_REALIZED (window)) {
+ gtk_widget_queue_resize (window);
+ if (!isMainDialog())
+ gtk_window_resize (GTK_WINDOW (window), width, height);
+ }
}
YDialog *YGWidgetFactory::createDialog (YDialogType dialogType, YDialogColorMode colorMode)
Modified: trunk/gtk/src/YGDialog.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGDialog.h?rev=47992&r1=47991&r2=47992&view=diff
==============================================================================
--- trunk/gtk/src/YGDialog.h (original)
+++ trunk/gtk/src/YGDialog.h Mon Jun 2 16:25:02 2008
@@ -29,8 +29,8 @@
virtual void setSize (int width, int height);
virtual void setEnabled (bool enabled);
- virtual int preferredWidth() { return 0; }
- virtual int preferredHeight() { return 0; }
+// virtual int preferredWidth() { return 0; }
+// virtual int preferredHeight() { return 0; }
virtual void openInternal();
virtual void activate();
Modified: trunk/gtk/src/YGLabel.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGLabel.cc?rev=47992&r1=47991&r2=47992&view=diff
==============================================================================
--- trunk/gtk/src/YGLabel.cc (original)
+++ trunk/gtk/src/YGLabel.cc Mon Jun 2 16:25:02 2008
@@ -27,11 +27,16 @@
virtual void setText (const string &label)
{
- gtk_label_set_label (GTK_LABEL (getWidget()), label.c_str());
+ if (isOutputField()) {
+ std::string l (label);
+ std::string::size_type i = l.find ('\n', 0);
+ if (i != std::string::npos)
+ l.erase (i);
+ gtk_label_set_label (GTK_LABEL (getWidget()), l.c_str());
+ }
+ else
+ gtk_label_set_label (GTK_LABEL (getWidget()), label.c_str());
YLabel::setText (label);
-
- // Some YCP progs have no labeled labels cluttering the layout
- label.empty() ? gtk_widget_hide (getWidget()) : gtk_widget_show (getWidget());
}
YGWIDGET_IMPL_COMMON
Modified: trunk/gtk/src/YGLayout.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGLayout.cc?rev=47992&r1=47991&r2=47992&view=diff
==============================================================================
--- trunk/gtk/src/YGLayout.cc (original)
+++ trunk/gtk/src/YGLayout.cc Mon Jun 2 16:25:02 2008
@@ -7,104 +7,53 @@
#include "YGWidget.h"
#include "YGUtils.h"
+/* Our layout stuff is a hybrid between GTK and libyui. We use libyui
+ for YLayoutBox and a couple of other widgets, but we do things GTK
+ friendly, so for single-child containers like GtkNotebook we don't
+ have to do any work. */
+
+#include "ygtkfixed.h"
+
+static void doMoveChild (GtkWidget *fixed, YWidget *ychild, int x, int y)
+{
+ GtkWidget *child = YGWidget::get (ychild)->getLayout();
+ ygtk_fixed_set_child_pos (YGTK_FIXED (fixed), child, x, y);
+}
+
+#define YGLAYOUT_INIT \
+ ygtk_fixed_setup (YGTK_FIXED (getWidget()), preferred_size_cb, set_size_cb, this);
+#define YGLAYOUT_PREFERRED_SIZE_IMPL(ParentClass) \
+ static void preferred_size_cb (YGtkFixed *fixed, gint *width, gint *height, \
+ gpointer pThis) { \
+ *width = ((ParentClass *) pThis)->ParentClass::preferredWidth(); \
+ *height = ((ParentClass *) pThis)->ParentClass::preferredHeight(); \
+ }
+#define YGLAYOUT_SET_SIZE_IMPL(ParentClass) \
+ static void set_size_cb (YGtkFixed *fixed, gint width, gint height, \
+ gpointer pThis) { \
+ ((ParentClass *) pThis)->ParentClass::setSize (width, height); \
+ } \
+ virtual void setSize (int width, int height) { doSetSize (width, height); } \
+ virtual void moveChild (YWidget *ychild, int x, int y) \
+ { doMoveChild (getWidget(), ychild, x, y); }
+
#include "YLayoutBox.h"
-#include "ygtkratiobox.h"
-#include "YSpacing.h"
-#include "YPushButton.h"
-#include "YMenuButton.h"
-// GtkBox-like container (actually, more like our YGtkRatioBox)
class YGLayoutBox : public YLayoutBox, public YGWidget
{
- // This group is meant to set all YGLabeledWidget with horizontal label
- // to share the same width (if they belong to the same YSplit), so they
- // look right
- GtkSizeGroup *m_labels_group, *m_buttons_group;
-
public:
YGLayoutBox (YWidget *parent, YUIDimension dim)
: YLayoutBox (NULL, dim),
- YGWidget (this, parent, true,
- dim == YD_HORIZ ? YGTK_TYPE_RATIO_HBOX : YGTK_TYPE_RATIO_VBOX, NULL)
+ YGWidget (this, parent, true, YGTK_TYPE_FIXED, NULL)
{
setBorder (0);
- m_labels_group = m_buttons_group = NULL;
- }
-
- ~YGLayoutBox()
- {
- if (m_labels_group)
- g_object_unref (G_OBJECT (m_labels_group));
- if (m_buttons_group)
- g_object_unref (G_OBJECT (m_buttons_group));
+ YGLAYOUT_INIT
}
YGWIDGET_IMPL_CHILD_ADDED (getWidget())
YGWIDGET_IMPL_CHILD_REMOVED (getWidget())
- virtual void moveChild (YWidget *child, int x, int y) {}
-
- void addSizeGroup (YGLabeledWidget *labeledWidget)
- {
- GtkWidget *label = labeledWidget->getLabelWidget();
- if (m_labels_group) {
- GSList *labels = gtk_size_group_get_widgets (m_labels_group);
- if (g_slist_find (labels, label)) // contains label already?
- return;
- // labels is not to be freed!
- }
- else
- m_labels_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
- gtk_size_group_add_widget (m_labels_group, label);
- }
-
- virtual void syncStretchable (YWidget *ychild, YGWidget *child)
- {
- IMPL
- YGtkRatioBox *box = YGTK_RATIO_BOX (getWidget());
-
- YUIDimension dim = primary();
- bool horiz_fill = ychild->stretchable (YD_HORIZ) || ychild->hasWeight (YD_HORIZ);
- bool vert_fill = ychild->stretchable (YD_VERT) || ychild->hasWeight (YD_VERT);
-
- ygtk_ratio_box_set_child_packing (box, child->getLayout(), ychild->stretchable (dim),
- isLayoutStretch (ychild, dim), ychild->weight (dim), horiz_fill, vert_fill, 0);
-
- // set all buttons to same height -- cause of stock icons...
- if (dim == YD_HORIZ) {
- bool isButton = false;
- if (dynamic_cast (ychild))
- isButton = true;
- else if (dynamic_cast (ychild))
- isButton = true;
- if (isButton) {
- if (!m_buttons_group)
- m_buttons_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
- gtk_size_group_add_widget (m_buttons_group, child->getWidget());
- }
- }
-
- // align horizontal widget labels to the same width
- // we do some work here, since they may be placed inside a HBox or something...
- if (dim == YD_HORIZ && !horiz_fill)
- return;
- YWidget *yLabeledWidget = ychild;
- while (yLabeledWidget->hasChildren()) { // container
- YWidget *container = yLabeledWidget;
- for (YWidgetListConstIterator it = container->childrenBegin();
- it != container->childrenEnd(); it++) {
- yLabeledWidget = *it;
- if (!dynamic_cast (yLabeledWidget) /*ignore spacings*/)
- break;
- }
- }
- YGLabeledWidget *labeledWidget =
- dynamic_cast (YGWidget::get (yLabeledWidget));
- if (labeledWidget && labeledWidget->orientation() == YD_HORIZ) {
-/* horiz_fill = yLabeledWidget->stretchable (YD_HORIZ) || yLabeledWidget->hasWeight (YD_HORIZ);
- if (horiz_fill)*/
- addSizeGroup (labeledWidget);
- }
- }
+ YGLAYOUT_PREFERRED_SIZE_IMPL (YLayoutBox)
+ YGLAYOUT_SET_SIZE_IMPL (YLayoutBox)
};
YLayoutBox *YGWidgetFactory::createLayoutBox (YWidget *parent, YUIDimension dimension)
@@ -122,10 +71,11 @@
public:
YGAlignment (YWidget *parent, YAlignmentType halign, YAlignmentType valign)
: YAlignment (NULL, halign, valign),
- YGWidget (this, parent, true, GTK_TYPE_ALIGNMENT, NULL)
+ YGWidget (this, parent, true, YGTK_TYPE_FIXED, NULL)
{
setBorder (0);
m_background_pixbuf = 0;
+ YGLAYOUT_INIT
}
virtual ~YGAlignment()
@@ -134,61 +84,10 @@
g_object_unref (G_OBJECT (m_background_pixbuf));
}
- virtual void doAddChild (YWidget *ychild, GtkWidget *container)
- {
- YGWidget::doAddChild (ychild, container);
-
- /* The padding is used for stuff like making YCP progs nicer for
- yast-qt wizard, so it hurts us -- it's disabled. */
- //child->setPadding (topMargin(), bottomMargin(),
- // leftMargin(), rightMargin());
- setMinSize (minWidth(), minHeight());
- }
YGWIDGET_IMPL_CHILD_ADDED (m_widget)
YGWIDGET_IMPL_CHILD_REMOVED (m_widget)
- virtual void moveChild (YWidget *child, int x, int y) {}
-
- virtual void syncStretchable (YWidget *ychild, YGWidget *child)
- {
- IMPL
- setAlignment (alignment (YD_HORIZ), alignment (YD_VERT));
- }
-
- void setAlignment (YAlignmentType halign, YAlignmentType valign)
- {
- struct inner {
- // helper -- converts YWidget YAlignmentType to Gtk's align float
- static float yToGtkAlign (YAlignmentType align)
- {
- switch (align) {
- case YAlignBegin: return 0.0;
- default:
- case YAlignCenter: return 0.5;
- case YAlignEnd: return 1.0;
- }
- }
- };
-
- float xalign, yalign, xscale, yscale;
- xalign = inner::yToGtkAlign (halign);
- yalign = inner::yToGtkAlign (valign);
- xscale = (halign == YAlignUnchanged) ? 1 : 0;
- yscale = (valign == YAlignUnchanged) ? 1 : 0;
- if (hasChildren()) {
- // special case: child has stretch opt
- if (!xscale && firstChild()->stretchable (YD_HORIZ))
- xscale = 1;
- if (!yscale && firstChild()->stretchable (YD_VERT))
- yscale = 1;
- }
- gtk_alignment_set (GTK_ALIGNMENT (getWidget()), xalign, yalign, xscale, yscale);
- }
-
- void setPadding (int top, int bottom, int left, int right)
- {
- gtk_alignment_set_padding (GTK_ALIGNMENT (getWidget()),
- top, bottom, left, right);
- }
+ YGLAYOUT_PREFERRED_SIZE_IMPL (YAlignment)
+ YGLAYOUT_SET_SIZE_IMPL (YAlignment)
virtual void setBackgroundPixmap (string filename)
{
@@ -234,32 +133,6 @@
GTK_BIN (widget)->child, event);
return TRUE;
}
-
- virtual string getDebugLabel() const
- {
- struct inner {
- static const char *alignLabel (YAlignmentType align)
- {
- switch (align) {
- case YAlignUnchanged:
- return "unchanged";
- case YAlignBegin:
- return "begin";
- case YAlignEnd:
- return "end";
- case YAlignCenter:
- return "center";
- }
- return ""; /*not run*/
- }
- };
-
- string str;
- str += inner::alignLabel (alignment (YD_HORIZ));
- str += " x ";
- str += inner::alignLabel (alignment (YD_VERT));
- return str;
- }
};
YAlignment *YGWidgetFactory::createAlignment (YWidget *parent, YAlignmentType halign,
@@ -299,14 +172,16 @@
public:
YGSpacing (YWidget *parent, YUIDimension dim, bool stretchable, YLayoutSize_t size)
: YSpacing (NULL, dim, stretchable, size),
- YGWidget (this, parent, true, GTK_TYPE_EVENT_BOX, NULL)
+ YGWidget (this, parent, true, YGTK_TYPE_FIXED, NULL)
{
setBorder (0);
- int width = YSpacing::size (YD_HORIZ), height = YSpacing::size (YD_VERT);
- gtk_widget_set_size_request (getWidget(), width, height);
+ YGLAYOUT_INIT
}
YGWIDGET_IMPL_COMMON
+ YGLAYOUT_PREFERRED_SIZE_IMPL (YLayoutBox)
+ static void set_size_cb (YGtkFixed *fixed, gint width, gint height,
+ gpointer pThis) {}
};
YSpacing *YGWidgetFactory::createSpacing (YWidget *parent, YUIDimension dim,
@@ -317,9 +192,6 @@
#include "YReplacePoint.h"
-//TEMP:
-#include "YPushButton.h"
-
// an empty space that will get replaced
class YGReplacePoint : public YReplacePoint, public YGWidget
{
@@ -331,6 +203,7 @@
setBorder (0);
}
+ YGWIDGET_IMPL_COMMON
YGWIDGET_IMPL_CHILD_ADDED (getWidget())
YGWIDGET_IMPL_CHILD_REMOVED (getWidget())
};
@@ -355,6 +228,7 @@
setBorder (0);
}
+ YGWIDGET_IMPL_COMMON
YGWIDGET_IMPL_CHILD_ADDED (getWidget())
YGWIDGET_IMPL_CHILD_REMOVED (getWidget())
};
Modified: trunk/gtk/src/YGProgressBar.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGProgressBar.cc?rev=47992&r1=47991&r2=47992&view=diff
==============================================================================
--- trunk/gtk/src/YGProgressBar.cc (original)
+++ trunk/gtk/src/YGProgressBar.cc Mon Jun 2 16:25:02 2008
@@ -99,7 +99,6 @@
, YGWidget (this, parent, true,
horizontal() ? YGTK_TYPE_RATIO_HBOX : YGTK_TYPE_RATIO_VBOX, NULL)
{
-// ygtk_ratio_box_set_homogeneous (YGTK_RATIO_BOX (getWidget()), TRUE);
ygtk_ratio_box_set_spacing (YGTK_RATIO_BOX (getWidget()), 2);
for (int s = 0; s < segments(); s++) {
GtkWidget* bar = gtk_progress_bar_new();
@@ -111,8 +110,7 @@
gtk_widget_set_size_request (bar, min_size, -1);
else
gtk_widget_set_size_request (bar, -1, min_size);
- ygtk_ratio_box_pack (YGTK_RATIO_BOX (getWidget()), bar,
- getSegmentWeight (s), TRUE, TRUE, 0);
+ ygtk_ratio_box_pack (YGTK_RATIO_BOX (getWidget()), bar, getSegmentWeight (s));
}
ygtk_adj_size_set_max (YGTK_ADJ_SIZE (m_adj_size), horizontal() ? 200 : 0,
Modified: trunk/gtk/src/YGUI.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGUI.cc?rev=47992&r1=47991&r2=47992&view=diff
==============================================================================
--- trunk/gtk/src/YGUI.cc (original)
+++ trunk/gtk/src/YGUI.cc Mon Jun 2 16:25:02 2008
@@ -37,7 +37,6 @@
IMPL
m_have_wm = true;
m_no_border = m_fullscreen = false;
- m_default_size.width = m_default_size.height = 0;
YGUI::setTextdomain( TEXTDOMAIN );
@@ -88,15 +87,6 @@
m_fullscreen = true;
else if (!strcmp (argp, "noborder"))
m_no_border = true;
- else if (!strcmp (argp, "geometry")) {
- argp = argv [++i];
- if (i == argc)
- printf ("Warning: no value passed to --geometry\n");
- else if (sscanf (argp, "%dx%d", &m_default_size.width,
- &m_default_size.height) == EOF) {
- printf ("Warning: invalid --geometry value: %s\n", argp);
- }
- }
else if (!strcmp (argp, "help")) {
printf (
"Command line options for the YaST2 Gtk UI:\n"
@@ -127,20 +117,6 @@
static int getDisplayHeight()
{ return gdk_screen_get_height (getScreen()); }
-int YGUI::_getDefaultWidth()
-{
- if (!m_default_size.width)
- m_default_size.width = MIN (600, getDisplayWidth());
- return m_default_size.width;
-}
-
-int YGUI::_getDefaultHeight()
-{
- if (!m_default_size.height)
- m_default_size.height = MIN (450, getDisplayHeight());
- return m_default_size.height;
-}
-
static gboolean ycp_wakeup_fn (GIOChannel *source, GIOCondition condition,
gpointer data)
{
Modified: trunk/gtk/src/YGUI.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGUI.h?rev=47992&r1=47991&r2=47992&view=diff
==============================================================================
--- trunk/gtk/src/YGUI.h (original)
+++ trunk/gtk/src/YGUI.h Mon Jun 2 16:25:02 2008
@@ -89,11 +89,9 @@
// window-related arguments
bool m_have_wm, m_no_border, m_fullscreen;
- GtkRequisition m_default_size;
public:
// Helpers for internal use [ visibility hidden ]
- int _getDefaultWidth(); int _getDefaultHeight();
bool setFullscreen() const { return m_fullscreen; }
bool hasWM() const { return m_have_wm; }
bool unsetBorder() const { return m_no_border; }
Modified: trunk/gtk/src/YGWidget.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGWidget.cc?rev=47992&r1=47991&r2=47992&view=diff
==============================================================================
--- trunk/gtk/src/YGWidget.cc (original)
+++ trunk/gtk/src/YGWidget.cc Mon Jun 2 16:25:02 2008
@@ -48,14 +48,20 @@
ywidget->setParent (yparent);
yparent->addChild (ywidget);
}
+ m_sizeReq.width = 0;
}
YGWidget::~YGWidget()
{
IMPL
+ // remove children if container?
+#if 0
+ if (GTK_IS_CONTAINER (m_widget))
+ gtk_container_foreach (GTK_CONTAINER (m_widget),
+ (GtkCallback) gtk_container_remove, NULL);
+#endif
gtk_widget_destroy (m_adj_size);
g_object_unref (G_OBJECT (m_adj_size));
- // remove all children if container?
}
void YGWidget::show()
@@ -106,6 +112,26 @@
}
}
+int YGWidget::getPreferredSize (YUIDimension dimension)
+{
+ if (!m_sizeReq.width)
+ gtk_widget_size_request (m_adj_size, &m_sizeReq);
+ return dimension == YD_HORIZ ? m_sizeReq.width : m_sizeReq.height;
+}
+
+#include "ygtkfixed.h"
+
+void YGWidget::doSetSize (int width, int height)
+{
+ GtkWidget *parent = 0;
+ if (m_ywidget->parent())
+ parent = YGWidget::get (m_ywidget->parent())->getWidget();
+
+ if (parent && YGTK_IS_FIXED (parent))
+ ygtk_fixed_set_child_size (YGTK_FIXED (parent), m_adj_size, width, height);
+ m_sizeReq.width = 0;
+}
+
void YGWidget::emitEvent(YEvent::EventReason reason, bool if_notify,
bool if_not_pending, bool immediate)
{
@@ -161,7 +187,8 @@
bool show, GType type,
const char *property_name, ...)
: YGWidget (ywidget, parent, show,
- label_ori == YD_VERT ? GTK_TYPE_VBOX : GTK_TYPE_HBOX,
+// label_ori == YD_VERT ? GTK_TYPE_VBOX : GTK_TYPE_HBOX,
+ GTK_TYPE_VBOX,
"spacing", LABEL_WIDGET_SPACING, NULL)
{
// Create the field widget
Modified: trunk/gtk/src/YGWidget.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGWidget.h?rev=47992&r1=47991&r2=47992&view=diff
==============================================================================
--- trunk/gtk/src/YGWidget.h (original)
+++ trunk/gtk/src/YGWidget.h Mon Jun 2 16:25:02 2008
@@ -47,11 +47,12 @@
void setMinSize (unsigned int min_width, unsigned int min_height);
void setMinSizeInChars (unsigned int min_width, unsigned int min_height);
- // whenever the stretchable property may change (eg. when adding a child
- // for a container), call this function to make sure it is honored.
- virtual void syncStretchable (YWidget *ychild, YGWidget *child) {}
-
protected:
+ // layout
+ virtual int getPreferredSize (YUIDimension dimension);
+ void doSetSize (int width, int height);
+ GtkRequisition m_sizeReq; // cache
+
void show();
GtkWidget *m_widget; // associated GtkWidget -- use getWidget()
@@ -75,9 +76,9 @@
doSetEnabled (enabled); \
YWidget::setEnabled (enabled); \
} \
- virtual int preferredWidth() { return 0; } \
- virtual int preferredHeight() { return 0; } \
- virtual void setSize (int width, int height) {}
+ virtual int preferredWidth() { return getPreferredSize (YD_HORIZ); } \
+ virtual int preferredHeight() { return getPreferredSize (YD_VERT); } \
+ virtual void setSize (int width, int height) { doSetSize (width, height); }
#define YGWIDGET_IMPL_USE_BOLD(ParentClass) \
virtual void setUseBoldFont (bool useBold) { \
Modified: trunk/gtk/src/ygtkbargraph.c
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/ygtkbargraph.c?rev=47992&r1=47991&r2=47992&view=diff
==============================================================================
--- trunk/gtk/src/ygtkbargraph.c (original)
+++ trunk/gtk/src/ygtkbargraph.c Mon Jun 2 16:25:02 2008
@@ -25,9 +25,6 @@
static void ygtk_bar_graph_size_request (GtkWidget *widget, GtkRequisition *requisition)
{
GTK_WIDGET_CLASS (ygtk_bar_graph_parent_class)->size_request (widget, requisition);
- const int max_width = 250;
- if (requisition->width > max_width)
- requisition->width = max_width;
requisition->height += 6;
}
@@ -95,8 +92,7 @@
// Set proportion
gtk_widget_set_size_request (box, 10, -1); // for homogeneous...
- ygtk_ratio_box_set_child_packing (YGTK_RATIO_BOX (bar), box, TRUE, FALSE,
- MAX (value, 1), TRUE, TRUE, 0);
+ ygtk_ratio_box_set_child_packing (YGTK_RATIO_BOX (bar), box, MAX (value, 1));
// Set background color
// The Tango palette
Added: trunk/gtk/src/ygtkfixed.c
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/ygtkfixed.c?rev=47992&view=auto
==============================================================================
--- trunk/gtk/src/ygtkfixed.c (added)
+++ trunk/gtk/src/ygtkfixed.c Mon Jun 2 16:25:02 2008
@@ -0,0 +1,139 @@
+/********************************************************************
+ * YaST2-GTK - http://en.opensuse.org/YaST2-GTK *
+ ********************************************************************/
+
+/* YGtkFixed container */
+// check the header file for information about this container
+
+#include
+#include
+#include
+#include "ygtkfixed.h"
+
+G_DEFINE_TYPE (YGtkFixed, ygtk_fixed, GTK_TYPE_CONTAINER)
+
+static void ygtk_fixed_init (YGtkFixed *fixed)
+{
+ GTK_WIDGET_SET_FLAGS (fixed, GTK_NO_WINDOW);
+ gtk_widget_set_redraw_on_allocate (GTK_WIDGET (fixed), FALSE);
+}
+
+void ygtk_fixed_setup (YGtkFixed *fixed, YGtkPreferredSize cb1, YGtkSetSize cb2, gpointer data)
+{
+ fixed->preferred_size_cb = cb1;
+ fixed->set_size_cb = cb2;
+ fixed->data = data;
+}
+
+static YGtkFixedChild *ygtk_fixed_get_child (YGtkFixed *fixed, GtkWidget *widget)
+{
+ GSList *i;
+ for (i = fixed->children; i; i = i->next) {
+ YGtkFixedChild *child = i->data;
+ if (child->widget == widget)
+ return child;
+ }
+ return NULL;
+}
+
+void ygtk_fixed_set_child_pos (YGtkFixed *fixed, GtkWidget *widget, gint x, gint y)
+{
+ YGtkFixedChild *child = ygtk_fixed_get_child (fixed, widget);
+ child->x = x;
+ child->y = y;
+}
+
+void ygtk_fixed_set_child_size (YGtkFixed *fixed, GtkWidget *widget, gint width, gint height)
+{
+ YGtkFixedChild *child = ygtk_fixed_get_child (fixed, widget);
+ child->width = width;
+ child->height = height;
+}
+
+static void ygtk_fixed_add (GtkContainer *container, GtkWidget *widget)
+{
+ YGtkFixed *fixed = YGTK_FIXED (container);
+ YGtkFixedChild *child = g_new0 (YGtkFixedChild, 1);
+ child->widget = widget;
+ child->width = child->height = 50;
+ fixed->children = g_slist_append (fixed->children, child);
+ gtk_widget_set_parent (widget, GTK_WIDGET (fixed));
+}
+
+static void ygtk_fixed_remove (GtkContainer *container, GtkWidget *widget)
+{
+ YGtkFixed *fixed = YGTK_FIXED (container);
+ GSList *i;
+ for (i = fixed->children; i; i = i->next) {
+ YGtkFixedChild *child = i->data;
+ if (child->widget == widget) {
+ gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
+ gtk_widget_unparent (widget);
+ fixed->children = g_slist_delete_link (fixed->children, i);
+ g_free (child);
+ if (was_visible)
+ gtk_widget_queue_resize (GTK_WIDGET (container));
+ break;
+ }
+ }
+}
+
+static void ygtk_fixed_forall (GtkContainer *container, gboolean include_internals,
+ GtkCallback callback, gpointer callback_data)
+{
+ g_return_if_fail (callback != NULL);
+ YGtkFixed *fixed = YGTK_FIXED (container);
+ GSList *i = fixed->children;
+ while (i) {
+ YGtkFixedChild *child = i->data;
+ i = i->next; // current node might get removed...
+ (* callback) (child->widget, callback_data);
+ }
+}
+
+static void ygtk_fixed_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ YGtkFixed *fixed = YGTK_FIXED (widget);
+ fixed->preferred_size_cb (fixed, &requisition->width, &requisition->height,
+ fixed->data);
+
+ GTK_WIDGET_CLASS (ygtk_fixed_parent_class)->size_request (widget, requisition);
+}
+
+static void ygtk_fixed_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ YGtkFixed *fixed = YGTK_FIXED (widget);
+ fixed->set_size_cb (fixed, allocation->width, allocation->height, fixed->data);
+
+ GSList *i;
+ for (i = fixed->children; i; i = i->next) {
+ YGtkFixedChild *child = i->data;
+ int x = child->x + allocation->x;
+ int y = child->y + allocation->y;
+ GtkAllocation child_alloc =
+ { x, y, child->width, child->height };
+ gtk_widget_size_allocate (child->widget, &child_alloc);
+ }
+ GTK_WIDGET_CLASS (ygtk_fixed_parent_class)->size_allocate (widget, allocation);
+}
+
+static GType ygtk_fixed_child_type (GtkContainer *container)
+{ return GTK_TYPE_WIDGET; }
+
+static void ygtk_fixed_class_init (YGtkFixedClass *klass)
+{
+ ygtk_fixed_parent_class = g_type_class_peek_parent (klass);
+
+ GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
+ container_class->add = ygtk_fixed_add;
+ container_class->remove = ygtk_fixed_remove;
+ container_class->forall = ygtk_fixed_forall;
+ container_class->child_type = ygtk_fixed_child_type;
+
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ widget_class->size_request = ygtk_fixed_size_request;
+ widget_class->size_allocate = ygtk_fixed_size_allocate;
+}
+
Added: trunk/gtk/src/ygtkfixed.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/ygtkfixed.h?rev=47992&view=auto
==============================================================================
--- trunk/gtk/src/ygtkfixed.h (added)
+++ trunk/gtk/src/ygtkfixed.h Mon Jun 2 16:25:02 2008
@@ -0,0 +1,64 @@
+/********************************************************************
+ * YaST2-GTK - http://en.opensuse.org/YaST2-GTK *
+ ********************************************************************/
+
+/* GtkFixed just doesn't cut it... gtk_fixed_move_child() does a queue_resize
+ and the all thing is just not quite appropriate... */
+
+#ifndef YGTK_FIXED_H
+#define YGTK_FIXED_H
+
+#include
+G_BEGIN_DECLS
+
+#define YGTK_TYPE_FIXED (ygtk_fixed_get_type ())
+#define YGTK_FIXED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ YGTK_TYPE_FIXED, YGtkFixed))
+#define YGTK_FIXED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ YGTK_TYPE_FIXED, YGtkFixedClass))
+#define YGTK_IS_FIXED(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ YGTK_TYPE_FIXED))
+#define YGTK_IS_FIXED_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ YGTK_TYPE_FIXED))
+#define YGTK_FIXED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ YGTK_TYPE_FIXED, YGtkFixedClass))
+
+typedef struct _YGtkFixed YGtkFixed;
+typedef struct _YGtkFixedClass YGtkFixedClass;
+
+typedef void (*YGtkPreferredSize) (YGtkFixed *, gint *, gint *, gpointer);
+typedef void (*YGtkSetSize) (YGtkFixed *, gint, gint, gpointer);
+
+struct _YGtkFixed
+{
+ GtkContainer parent;
+ // private (read-only):
+ GSList *children;
+ YGtkPreferredSize preferred_size_cb;
+ YGtkSetSize set_size_cb;
+ gpointer data;
+};
+
+struct _YGtkFixedClass
+{
+ GtkContainerClass parent_class;
+};
+
+typedef struct _YGtkFixedChild
+{
+ GtkWidget *widget;
+ // members
+ // post-pone all position and size setting, to avoid unnecessary work
+ gint x, y, width, height;
+} YGtkFixedChild;
+
+GType ygtk_fixed_get_type (void) G_GNUC_CONST;
+
+void ygtk_fixed_setup (YGtkFixed *fixed, YGtkPreferredSize cb1, YGtkSetSize cb2, gpointer data);
+
+void ygtk_fixed_set_child_pos (YGtkFixed *fixed, GtkWidget *widget, gint x, gint y);
+void ygtk_fixed_set_child_size (YGtkFixed *fixed, GtkWidget *widget, gint width, gint height);
+
+G_END_DECLS
+#endif /*YGTK_FIXED_H*/
+
Modified: trunk/gtk/src/ygtkratiobox.c
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/ygtkratiobox.c?rev=47992&r1=47991&r2=47992&view=diff
==============================================================================
--- trunk/gtk/src/ygtkratiobox.c (original)
+++ trunk/gtk/src/ygtkratiobox.c Mon Jun 2 16:25:02 2008
@@ -2,8 +2,8 @@
* YaST2-GTK - http://en.opensuse.org/YaST2-GTK *
********************************************************************/
-/* YGtkRatioBox widget */
-// check the header file for information about this widget
+/* YGtkRatioBox container */
+// check the header file for information about this container
#include
#include
@@ -20,18 +20,12 @@
static GType ygtk_ratio_box_child_type (GtkContainer* container)
{ return GTK_TYPE_WIDGET; }
-void ygtk_ratio_box_pack (YGtkRatioBox *box, GtkWidget *child,
- gfloat ratio, gboolean xfill, gboolean yfill,
- guint padding)
+void ygtk_ratio_box_pack (YGtkRatioBox *box, GtkWidget *child, gfloat ratio)
{
YGtkRatioBoxChild* child_info;
child_info = g_new (YGtkRatioBoxChild, 1);
child_info->widget = child;
child_info->ratio = ratio;
- child_info->padding = padding;
- child_info->xfill = xfill;
- child_info->yfill = yfill;
- child_info->expand = 0;
box->children = g_list_append (box->children, child_info);
@@ -56,7 +50,7 @@
static void ygtk_ratio_box_add (GtkContainer *container, GtkWidget *child)
{
- ygtk_ratio_box_pack (YGTK_RATIO_BOX (container), child, 1.0, TRUE, TRUE, 0);
+ ygtk_ratio_box_pack (YGTK_RATIO_BOX (container), child, 1.0);
}
static void ygtk_ratio_box_remove (GtkContainer *container, GtkWidget *widget)
@@ -104,67 +98,29 @@
GtkRequisition *requisition,
GtkOrientation orientation)
{
- YGtkRatioBox* box = YGTK_RATIO_BOX (widget);
- gfloat ratios_sum = 0;
- box->has_must_expand = FALSE;
- GList* child;
- for (child = box->children; child; child = child->next) {
- YGtkRatioBoxChild* box_child = (YGtkRatioBoxChild*) child->data;
- if (!GTK_WIDGET_VISIBLE (box_child->widget))
- continue;
- if (box_child->ratio)
- ratios_sum += box_child->ratio;
- if (box_child->must_expand)
- box->has_must_expand = TRUE;
- }
-
- // If we want to calculate horizontal size, primary_req would be horizontal
- // length, while secondary the height. Idem for the inverse.
- guint primary_req = 0, secondary_req = 0;
- box->weight_length = 0; // biggest ratio of widget-size / widget-ratio
+ requisition->width = requisition->height = 0;
- for (child = box->children; child; child = child->next) {
- YGtkRatioBoxChild* box_child = (YGtkRatioBoxChild*) child->data;
- if (!GTK_WIDGET_VISIBLE (box_child->widget))
+ YGtkRatioBox* box = YGTK_RATIO_BOX (widget);
+ gint children_nb = 0;
+ GList *i;
+ for (i = box->children; i; i = i->next) {
+ YGtkRatioBoxChild* child = i->data;
+ if (!GTK_WIDGET_VISIBLE (child->widget))
continue;
GtkRequisition child_req;
- gtk_widget_size_request (box_child->widget, &child_req);
-
- guint prim_length, sec_length;
- if (orientation == GTK_ORIENTATION_HORIZONTAL) {
- prim_length = child_req.width;
- sec_length = child_req.height;
- }
- else {
- prim_length = child_req.height;
- sec_length = child_req.width;
- }
-
- if (box_child->ratio)
- {
- int length = (prim_length * ratios_sum) / box_child->ratio;
- box->weight_length = MAX (box->weight_length, length);
- }
+ gtk_widget_size_request (child->widget, &child_req);
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ requisition->height = MAX (requisition->height, child_req.height);
else
- primary_req += prim_length;
- primary_req += box_child->padding + box->spacing;
- secondary_req = MAX (secondary_req, sec_length);
- }
-
- primary_req += box->weight_length;
-
- guint border = GTK_CONTAINER (widget)->border_width * 2;
- primary_req += border*2; secondary_req += border*2;
-
- if (orientation == GTK_ORIENTATION_HORIZONTAL) {
- requisition->width = primary_req;
- requisition->height = secondary_req;
- }
- else {
- requisition->width = secondary_req;
- requisition->height = primary_req;
+ requisition->width = MAX (requisition->width, child_req.width);
+ children_nb++;
}
+ gint spacing = children_nb ? box->spacing*(children_nb-1) : 0;
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ requisition->width += spacing;
+ else
+ requisition->height += spacing;
}
static void ygtk_ratio_box_size_allocate (GtkWidget *widget,
@@ -172,163 +128,65 @@
GtkOrientation orientation)
{
YGtkRatioBox* box = YGTK_RATIO_BOX (widget);
- guint border = GTK_CONTAINER (widget)->border_width;
- // a first loop to get some data for expansibles (ie. childs with weight)
gfloat ratios_sum = 0;
- gint expand_num = 0, max_ratio = 0;
- gint expansable_length, num_children = 0;
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- expansable_length = allocation->width - border*2;
- else
- expansable_length = allocation->height - border*2;
+ gint children_nb = 0;
- GList* child;
- for (child = box->children; child; child = child->next) {
- YGtkRatioBoxChild* box_child = (YGtkRatioBoxChild*) child->data;
- if (!GTK_WIDGET_VISIBLE (box_child->widget))
+ GList* i;
+ for (i = box->children; i; i = i->next) {
+ YGtkRatioBoxChild* child = i->data;
+ if (!GTK_WIDGET_VISIBLE (child->widget))
continue;
- if (box_child->expand)
- expand_num++;
- if (box_child->ratio)
- {
- ratios_sum += box_child->ratio;
- max_ratio = MAX (max_ratio, box_child->ratio);
- }
-
- if (!box_child->ratio)
- {
- GtkRequisition child_req;
- gtk_widget_get_child_requisition (box_child->widget, &child_req);
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- expansable_length -= child_req.width;
- else
- expansable_length -= child_req.height;
- }
- expansable_length -= box->spacing - box_child->padding;
- num_children++;
+ ratios_sum += child->ratio;
+ children_nb++;
}
- expansable_length -= box->weight_length;
-/* fprintf (stderr, "%p: expansible length %d allocation %d num children %d\n",
- box, expansable_length,
- (orientation == GTK_ORIENTATION_HORIZONTAL ?
- allocation->width : allocation->height),
- num_children); */
- gint child_pos = 0;
+ gint spacing = children_nb ? box->spacing*(children_nb-1) : 0;
+
+ gint length;
if (orientation == GTK_ORIENTATION_HORIZONTAL)
- child_pos = allocation->x + border;
+ length = allocation->width - spacing;
else
- child_pos = allocation->y + border;
+ length = allocation->height - spacing;
+ gint child_pos = 0;
- gboolean right_to_left = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
- for (child = box->children; child; child = child->next) {
- YGtkRatioBoxChild* box_child = (YGtkRatioBoxChild*) child->data;
- if (!GTK_WIDGET_VISIBLE (box_child->widget))
+ for (i = box->children; i; i = i->next) {
+ YGtkRatioBoxChild* child = i->data;
+ if (!GTK_WIDGET_VISIBLE (child->widget))
continue;
-/* fprintf (stderr, "%p: ratio box child: ratio %g expand %d must_expand %d "
- "xfill %d yfill %d\n", box,
- box_child->ratio, box_child->expand, box_child->must_expand,
- box_child->xfill, box_child->yfill); */
-
- GtkAllocation child_alloc;
- gint length;
-
GtkRequisition child_req;
- gtk_widget_get_child_requisition (box_child->widget, &child_req);
-
- if (!box_child->ratio)
- {
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- length = child_req.width;
- else
- length = child_req.height;
- }
-
- // give extra size (honor stretch order)
- if (box_child->ratio)
- {
- int available_length = box->weight_length;
- if (!box->has_must_expand)
- available_length += expansable_length;
- length = (box_child->ratio * available_length) / ratios_sum;
- }
- else if (box_child->expand && (ratios_sum == 0 || box_child->must_expand))
- {
- if (expansable_length > 0)
- length += expansable_length / expand_num;
- }
-
- gint spacing_to_next = length + box->spacing + box_child->padding;
- if (!box_child->ratio && expansable_length < 0)
- {
- // oh dear - we can't shrink anything, but we didn't get the size
- // we requested this can happen with some large text entry fields.
- // try to shrink everything just a bit & hope. Should we shrink
- // things marked 'expandable' instead ? - what if there are none ?
- double scale;
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- scale = (double)(allocation->width + expansable_length) / allocation->width;
- else
- scale = (double)(allocation->height + expansable_length) / allocation->height;
-// fprintf (stderr, "%p: trunc length %d -> %d by scale %g\n",
-// box, length, (int) floor (scale * length), scale);
- length = floor (scale * length);
- spacing_to_next = floor (scale * spacing_to_next);
- }
+ gtk_widget_get_child_requisition (child->widget, &child_req);
+ gint child_length = (child->ratio * length) / ratios_sum;
+ GtkAllocation child_alloc;
if (orientation == GTK_ORIENTATION_HORIZONTAL) {
child_alloc.x = child_pos;
- child_alloc.y = allocation->y + border;
- child_alloc.width = length;
- child_alloc.height = allocation->height - border*2;
+ child_alloc.y = allocation->y;
+ child_alloc.width = child_length;
+ child_alloc.height = allocation->height;
}
else { // GTK_ORIENTATION_VERTICAL
- child_alloc.x = allocation->x + border;
+ child_alloc.x = allocation->x;
child_alloc.y = child_pos;
- child_alloc.width = allocation->width - border*2;
- child_alloc.height = length;
+ child_alloc.width = allocation->width;
+ child_alloc.height = child_length;
}
- if (!box_child->xfill) {
- // we also need to center the widget
- gint width = MIN (child_alloc.width, child_req.width);
- child_alloc.x += MAX ((child_alloc.width - width) / 2, 0);
- child_alloc.width = width;
- }
- if (!box_child->yfill) {
- gint height = MIN (child_alloc.height, child_req.height);
- child_alloc.y += MAX ((child_alloc.height - height) / 2, 0);
- child_alloc.height = height;
- }
-
- if (right_to_left)
- child_alloc.x = allocation->width - child_alloc.x - child_alloc.width;
-
- gtk_widget_size_allocate (box_child->widget, &child_alloc);
- child_pos += spacing_to_next;
+ gtk_widget_size_allocate (child->widget, &child_alloc);
+ child_pos += child_length + box->spacing;
}
}
-void ygtk_ratio_box_set_child_packing (YGtkRatioBox *box, GtkWidget *child,
- gboolean expand, gboolean must_expand, gfloat ratio, gboolean xfill, gboolean yfill,
- guint padding)
+void ygtk_ratio_box_set_child_packing (YGtkRatioBox *box, GtkWidget *child, gfloat ratio)
{
YGtkRatioBoxChild *child_info;
child_info = ygtk_ratio_get_child_info (box, child);
if (child_info) {
gtk_widget_freeze_child_notify (child);
-
child_info->ratio = ratio;
- child_info->xfill = xfill;
- child_info->yfill = yfill;
- child_info->padding = padding;
- child_info->expand = expand;
- child_info->must_expand = expand && must_expand;
-
if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (box))
gtk_widget_queue_resize (child);
@@ -336,7 +194,7 @@
}
}
-void ygtk_ratio_box_set_spacing (YGtkRatioBox *box, gint spacing)
+void ygtk_ratio_box_set_spacing (YGtkRatioBox *box, guint spacing)
{
box->spacing = spacing;
}
Modified: trunk/gtk/src/ygtkratiobox.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/ygtkratiobox.h?rev=47992&r1=47991&r2=47992&view=diff
==============================================================================
--- trunk/gtk/src/ygtkratiobox.h (original)
+++ trunk/gtk/src/ygtkratiobox.h Mon Jun 2 16:25:02 2008
@@ -2,33 +2,12 @@
* YaST2-GTK - http://en.opensuse.org/YaST2-GTK *
********************************************************************/
-/* YGtkRatioBox is an improvement over the GtkBox container that
- allows the programmer to set stretch weights to containees.
-
- It is similar to GtkBox in usage but instead of feeding an
- expand boolean, a weight is given instead. In fact, it should
- behave just the same as a GtkBox if you give 0 for not expand
- and 1 to.
-*/
-/*
- Quirks (cause of yast-core):
- if one of the children has certain special properties, then only widgets with
- the same properties will be expanded. These are, by order:
- both stretch and rubber-band
- both stretch and weight
- weight
- stretch
-
- We use different naming:
- stretch = expand
- rubber-band or layout-stretch = must expand
- weight = ratio
+/* YGtkRatioBox uses weights instead of the single state expand boolean.
*/
#ifndef YGTK_RATIO_BOX_H
#define YGTK_RATIO_BOX_H
-#include
#include
G_BEGIN_DECLS
@@ -50,9 +29,7 @@
// private (read-only):
GList *children;
- gint16 spacing;
- guint weight_length; // min-length for weight widgets
- guint has_must_expand : 1; // cache
+ guint spacing;
} YGtkRatioBox;
typedef struct _YGtkRatioBoxClass
@@ -64,28 +41,15 @@
{
GtkWidget *widget;
// members
- guint16 padding;
gfloat ratio;
- guint xfill : 1;
- guint yfill : 1;
- guint expand : 1; // twilight zone flag; use ratio
- guint must_expand : 1; // higher order expand
} YGtkRatioBoxChild;
GType ygtk_ratio_box_get_type (void) G_GNUC_CONST;
-void ygtk_ratio_box_set_spacing (YGtkRatioBox *box, gint spacing);
-
-void ygtk_ratio_box_pack (YGtkRatioBox *box, GtkWidget *child, gfloat ratio,
- gboolean xfill, gboolean yfill, guint padding);
+void ygtk_ratio_box_set_spacing (YGtkRatioBox *box, guint spacing);
-// You can either use ratios or the expand boolean. If some child has a ratio set (to
-// a value other than 0), then expand flags will be ignored -- use must_expand in such
-// cases, when you want a child to expand like the child of the most ratio.
-// (rules based on those of libyui -- check top)
-void ygtk_ratio_box_set_child_packing (YGtkRatioBox *box, GtkWidget *child,
- gboolean expand, gboolean must_expand, gfloat ratio, gboolean xfill, gboolean yfill,
- guint padding);
+void ygtk_ratio_box_pack (YGtkRatioBox *box, GtkWidget *child, gfloat ratio);
+void ygtk_ratio_box_set_child_packing (YGtkRatioBox *box, GtkWidget *child, gfloat ratio);
/* RatioHBox */
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org