More GTK+ uiArea work and bug fixes.

This commit is contained in:
Pietro Gagliardi 2015-09-04 21:12:41 -04:00
parent bd3764e176
commit 30b6a0a696
3 changed files with 59 additions and 4 deletions

View File

@ -15,7 +15,7 @@ struct areaPrivate {
static void areaWidget_scrollable_init(GtkScrollable *);
G_DEFINE_ABSTRACT_TYPE_WITH_CODE(areaWidget, areaWidget, GTK_TYPE_DRAWING_AREA,
G_DEFINE_TYPE_WITH_CODE(areaWidget, areaWidget, GTK_TYPE_DRAWING_AREA,
G_IMPLEMENT_INTERFACE(GTK_TYPE_SCROLLABLE, areaWidget_scrollable_init))
static void updateScroll(areaWidget *a)
@ -48,8 +48,8 @@ static void updateScroll(areaWidget *a)
ap->clientHeight / pixelsPer);
// TODO notify adjustment changes?
g_object_notify(G_OBJECT(a), "hadjustment");
g_object_notify(G_OBJECT(a), "vadjustment");
// g_object_notify(G_OBJECT(a), "hadjustment");
// g_object_notify(G_OBJECT(a), "vadjustment");
}
static void areaWidget_init(areaWidget *a)
@ -114,13 +114,18 @@ static void areaWidget_size_allocate(GtkWidget *w, GtkAllocation *allocation)
// TODO events
enum {
pHAdjustment = 1,
// normal properties must come before override properties
// thanks gregier in irc.gimp.net/#gtk+
pAreaHandler = 1,
pHAdjustment,
pVAdjustment,
pHScrollPolicy,
pVScrollPolicy,
nProps,
};
static GParamSpec *pspecAreaHandler;
static void onValueChanged(GtkAdjustment *a, gpointer data)
{
gtk_widget_queue_draw(GTK_WIDGET(data));
@ -159,6 +164,9 @@ static void areaWidget_set_property(GObject *obj, guint prop, const GValue *valu
case pVScrollPolicy:
ap->vpolicy = g_value_get_enum(value);
return;
case pAreaHandler:
ap->ah = (uiAreaHandler *) g_value_get_pointer(value);
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop, pspec);
}
@ -201,6 +209,14 @@ static void areaWidget_class_init(areaWidgetClass *class)
// GTK_WIDGET_CLASS(class)->motion_notify_event = areaWidget_motion_notify_event;
// GTK_WIDGET_CLASS(class)->key_press_event = areaWidget_key_press_event;
g_type_class_add_private(G_OBJECT_CLASS(class), sizeof (struct areaPrivate));
pspecAreaHandler = g_param_spec_pointer("area-handler",
"area-handler",
"Area handler.",
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
g_object_class_install_property(G_OBJECT_CLASS(class), pAreaHandler, pspecAreaHandler);
// this is the actual interface implementation
g_object_class_override_property(G_OBJECT_CLASS(class), pHAdjustment, "hadjustment");
g_object_class_override_property(G_OBJECT_CLASS(class), pVAdjustment, "vadjustment");
@ -212,3 +228,10 @@ static void areaWidget_scrollable_init(GtkScrollable *iface)
{
// no need to do anything; the interface only has properties
}
GtkWidget *newArea(uiAreaHandler *ah)
{
return GTK_WIDGET(g_object_new(areaWidgetType,
"area-handler", ah,
NULL));
}

View File

@ -28,3 +28,5 @@ struct areaWidgetClass {
extern GType areaWidget_get_type(void);
#include "ui.h"
extern GtkWidget *newArea(uiAreaHandler *ah);

View File

@ -25,6 +25,21 @@ static void handlerVScrollConfig(uiAreaHandler *a, uiArea *area, uintmax_t *n, u
*pixelsPer = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ppvspinb));
}
static void recalcScroll(GtkSpinButton *sb, gpointer data)
{
// TODO
}
static GtkWidget *makeSpinbox(int min)
{
GtkWidget *sb;
sb = gtk_spin_button_new_with_range(min, 100000, 1);
gtk_spin_button_set_digits(GTK_SPIN_BUTTON(sb), 0);
g_signal_connect(sb, "value-changed", G_CALLBACK(recalcScroll), NULL);
return sb;
}
int main(void)
{
GtkWidget *mainwin;
@ -61,18 +76,33 @@ int main(void)
gtk_grid_attach(GTK_GRID(grid),
gtk_label_new("H Count"),
0, 0, 1, 1);
nhspinb = makeSpinbox(0);
gtk_grid_attach(GTK_GRID(grid), nhspinb,
1, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid),
gtk_label_new("H Pixels Per"),
0, 1, 1, 1);
pphspinb = makeSpinbox(1);
gtk_grid_attach(GTK_GRID(grid), pphspinb,
1, 1, 1, 1);
gtk_grid_attach(GTK_GRID(grid),
gtk_label_new("V Count"),
0, 2, 1, 1);
nvspinb = makeSpinbox(0);
gtk_grid_attach(GTK_GRID(grid), nvspinb,
1, 2, 1, 1);
gtk_grid_attach(GTK_GRID(grid),
gtk_label_new("V Pixels Per"),
0, 3, 1, 1);
ppvspinb = makeSpinbox(1);
gtk_grid_attach(GTK_GRID(grid), ppvspinb,
1, 3, 1, 1);
area = newArea((uiAreaHandler *) (&h));
gtk_container_add(GTK_CONTAINER(scroller), area);
gtk_widget_show_all(mainwin);
gtk_main();