Index: work/gtk/trunctext/Makefile =================================================================== --- work/gtk/trunctext/Makefile (nonexistent) +++ work/gtk/trunctext/Makefile (revision 17352) @@ -0,0 +1,14 @@ +TRUNK=../../../trunk +CFLAGS=-g -Wall -I $(TRUNK)/src_plugins `pkg-config --cflags gtk+-2.0` +LDFLAGS=-g `pkg-config --libs gtk+-2.0` +#CFLAGS=-g -Wall -I $(TRUNK)/src_plugins -DPCB_GTK3 `pkg-config --cflags gtk+-3.0` +#LDFLAGS=-g `pkg-config --libs gtk+-3.0` + +all: trunctext_demo + +trunctext_demo: trunctext_demo.o wt_trunc_text.o + +wt_trunc_text.o: wt_trunc_text.h + +clean: + rm *.o trunctext_demo Index: work/gtk/trunctext/trunctext_demo.c =================================================================== --- work/gtk/trunctext/trunctext_demo.c (nonexistent) +++ work/gtk/trunctext/trunctext_demo.c (revision 17352) @@ -0,0 +1,54 @@ +#include + +#include "wt_trunc_text.h" + +GtkWidget *build_text_test() +{ + GtkWidget *box = gtkc_vbox_new(FALSE, 0); + GtkWidget *hbox = gtkc_hbox_new(FALSE, 0); + + GtkWidget *h_label = gtk_label_new("Horizontal"); + GtkWidget *v_label = gtk_label_new("Vertical"); + /*GtkWidget *vt_label = gtk_label_new("Vert_truncated");*/ + GtkWidget *vt_label = gtkc_trunctext_new("Vert_truncated"); + + gtk_label_set_angle(v_label, 90.0); + + gtk_label_set_angle(vt_label, 90.0); + gtk_misc_set_alignment(GTK_MISC(vt_label), 0, 1); + gtk_widget_set_size_request(vt_label, 16, 1); + gtk_box_pack_start(hbox, vt_label, TRUE, FALSE, 0); + gtk_box_pack_start(hbox, gtk_label_new("layer name"), TRUE, TRUE, 0); + + gtk_box_pack_start(box, h_label, TRUE, FALSE, 0); + gtk_box_pack_start(box, v_label, TRUE, FALSE, 0); + gtk_box_pack_start(box, gtk_label_new("-----"), TRUE, FALSE, 0); + gtk_box_pack_start(box, hbox, TRUE, FALSE, 0); + + return box; +} + +int main(int argc, char **argv) +{ + GtkWidget *mainwin; + GtkWidget *test; + + /* Initialize the widget set */ + gtk_init(&argc, &argv); + /* Create the main window */ + mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_default_size(GTK_WINDOW(mainwin), 10, 20); + g_signal_connect(G_OBJECT(mainwin), "destroy", G_CALLBACK(gtk_main_quit), NULL); + + /* Set up GUI elements */ + test = build_text_test(); + gtk_container_add(GTK_CONTAINER(mainwin), test); + + /* Show the application window */ + gtk_widget_show_all(mainwin); + + /* Enter the main event loop, and wait for user interaction */ + gtk_main(); + + return 0; +} Index: work/gtk/trunctext/wt_trunc_text.c =================================================================== --- work/gtk/trunctext/wt_trunc_text.c (nonexistent) +++ work/gtk/trunctext/wt_trunc_text.c (revision 17352) @@ -0,0 +1,103 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * Copyright (C) 2018 Alain Vigne + * + * This module is subject to the GNU GPL as described below. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Contact: + * Project page: http://repo.hu/projects/pcb-rnd + * lead developer: email to pcb-rnd (at) igor2.repo.hu + * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") + */ + +#include "wt_trunc_text.h" + +static gpointer gtk_trunctext_parent_class = NULL; + +GtkTrunctext *gtk_trunctext_construct(GType object_type, const gchar * str) +{ + GtkTrunctext *self = NULL; + self = (GtkTrunctext *) g_object_new(object_type, NULL); + + if (str && *str) + gtk_label_set_text(GTK_LABEL(self), str); + + return self; +} + +GtkTrunctext *gtk_trunctext_new(const gchar * str) +{ + return gtk_trunctext_construct(TYPE_GTK_TRUNCTEXT, str); +} + +static void gtk_trunctext_get_preferred_width(GtkWidget * widget, gint * minimum_size, gint * natural_size) +{ + *minimum_size = 1; + *natural_size = 1; +} + +static void gtk_trunctext_get_preferred_width_for_height(GtkWidget * widget, gint height, gint * minimum_width, gint * natural_width) +{ + *minimum_width = 1; + *natural_width = 1; +} + +static void gtk_trunctext_get_preferred_height_and_baseline_for_width(GtkWidget * widget, gint width, gint * minimum_height, gint * natural_height, gint * minimum_baseline, gint * natural_baseline) +{ + *minimum_height = 1; + *natural_height = 1; + *minimum_baseline = 0; + *natural_baseline = 0; +} + +static void gtk_trunctext_class_init(GtkTrunctextClass * klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); + +#ifdef PCB_GTK3 + widget_class->get_preferred_width = gtk_trunctext_get_preferred_width; + widget_class->get_preferred_height = gtk_trunctext_get_preferred_width; + widget_class->get_preferred_width_for_height = gtk_trunctext_get_preferred_width_for_height; + widget_class->get_preferred_height_for_width = gtk_trunctext_get_preferred_width_for_height; + widget_class->get_preferred_height_and_baseline_for_width = gtk_trunctext_get_preferred_height_and_baseline_for_width; +#endif + + gtk_trunctext_parent_class = g_type_class_peek_parent(klass); +} + +static void gtk_trunctext_instance_init(GtkTrunctext * self) +{ +} + +GType gtk_trunctext_get_type(void) +{ + static volatile gsize gtk_trunctext_type_id__volatile = 0; + + if (g_once_init_enter(>k_trunctext_type_id__volatile)) { + static const GTypeInfo g_define_type_info = + { sizeof(GtkTrunctextClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gtk_trunctext_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof(GtkTrunctext), 0, (GInstanceInitFunc) gtk_trunctext_instance_init, NULL }; + GType gtk_trunctext_type_id; + + gtk_trunctext_type_id = g_type_register_static(gtk_label_get_type(), "GtkTrunctext", &g_define_type_info, 0); + g_once_init_leave(>k_trunctext_type_id__volatile, gtk_trunctext_type_id); + } + + return gtk_trunctext_type_id__volatile; +} Index: work/gtk/trunctext/wt_trunc_text.h =================================================================== --- work/gtk/trunctext/wt_trunc_text.h (nonexistent) +++ work/gtk/trunctext/wt_trunc_text.h (revision 17352) @@ -0,0 +1,78 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * Copyright (C) 2018 Alain Vigne + * + * This module is subject to the GNU GPL as described below. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Contact: + * Project page: http://repo.hu/projects/pcb-rnd + * lead developer: email to pcb-rnd (at) igor2.repo.hu + * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") + */ + +#ifndef PCB_GTK_TRUNC_TEXT_H +#define PCB_GTK_TRUNC_TEXT_H + +#include +typedef struct _GtkTrunctext GtkTrunctext; +typedef struct _GtkTrunctextClass GtkTrunctextClass; +GtkTrunctext *gtk_trunctext_new(const gchar *str); + +#include "lib_gtk_common/compat.h" +/* To be included in compat.h */ +#ifdef PCB_GTK3 +static inline GtkWidget *gtkc_trunctext_new(const gchar *str) +{ + return gtk_trunctext_new(str); +} +#else +/* GTK2 */ +static inline GtkWidget *gtkc_trunctext_new(const gchar *str) +{ + return gtk_label_new(str); +} +#endif + +/* GtkTrunctext is a subclass of GtkLabel */ +#define TYPE_GTK_TRUNCTEXT (gtk_trunctext_get_type ()) +#define GTK_TRUNCTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GTK_TRUNCTEXT, GtkTrunctext)) +#define GTK_TRUNCTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GTK_TRUNCTEXT, GtkTrunctextClass)) +#define IS_GTK_TRUNCTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GTK_TRUNCTEXT)) +#define IS_GTK_TRUNCTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GTK_TRUNCTEXT)) +#define GTK_TRUNCTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GTK_TRUNCTEXT, GtkTrunctextClass)) + +GType gtk_trunctext_get_type(void) G_GNUC_CONST; + +GtkTrunctext *gtk_trunctext_construct(GType object_type, const gchar *str); + +enum { + GTK_TRUNCTEXT_0_PROPERTY, + GTK_TRUNCTEXT_NUM_PROPERTIES +}; +static GParamSpec *gtk_trunctext_properties[GTK_TRUNCTEXT_NUM_PROPERTIES]; + +struct _GtkTrunctext { + GtkLabel parent_instance; +}; + +struct _GtkTrunctextClass { + GtkLabelClass parent_class; +}; + +#endif