00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "themewidget.h"
00025 #include <math.h>
00026
00027 static void meta_area_class_init (MetaAreaClass *klass);
00028 static void meta_area_init (MetaArea *area);
00029 static void meta_area_size_request (GtkWidget *widget,
00030 GtkRequisition *req);
00031 static gint meta_area_expose (GtkWidget *widget,
00032 GdkEventExpose *event);
00033 static void meta_area_finalize (GObject *object);
00034
00035
00036 static GtkMiscClass *parent_class;
00037
00038 GtkType
00039 meta_area_get_type (void)
00040 {
00041 static GtkType area_type = 0;
00042
00043 if (!area_type)
00044 {
00045 static const GtkTypeInfo area_info =
00046 {
00047 "MetaArea",
00048 sizeof (MetaArea),
00049 sizeof (MetaAreaClass),
00050 (GtkClassInitFunc) meta_area_class_init,
00051 (GtkObjectInitFunc) meta_area_init,
00052 NULL,
00053 NULL,
00054 (GtkClassInitFunc) NULL,
00055 };
00056
00057 area_type = gtk_type_unique (GTK_TYPE_MISC, &area_info);
00058 }
00059
00060 return area_type;
00061 }
00062
00063 static void
00064 meta_area_class_init (MetaAreaClass *class)
00065 {
00066 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
00067 GtkObjectClass *object_class;
00068 GtkWidgetClass *widget_class;
00069
00070 object_class = (GtkObjectClass*) class;
00071 widget_class = (GtkWidgetClass*) class;
00072 parent_class = gtk_type_class (gtk_misc_get_type ());
00073
00074 gobject_class->finalize = meta_area_finalize;
00075
00076 widget_class->expose_event = meta_area_expose;
00077 widget_class->size_request = meta_area_size_request;
00078 }
00079
00080 static void
00081 meta_area_init (MetaArea *area)
00082 {
00083 GTK_WIDGET_SET_FLAGS (area, GTK_NO_WINDOW);
00084 }
00085
00086 GtkWidget*
00087 meta_area_new (void)
00088 {
00089 MetaArea *area;
00090
00091 area = gtk_type_new (META_TYPE_AREA);
00092
00093 return GTK_WIDGET (area);
00094 }
00095
00096 static void
00097 meta_area_finalize (GObject *object)
00098 {
00099 MetaArea *area;
00100
00101 area = META_AREA (object);
00102
00103 if (area->dnotify)
00104 (* area->dnotify) (area->user_data);
00105
00106 G_OBJECT_CLASS (parent_class)->finalize (object);
00107 }
00108
00109 static gint
00110 meta_area_expose (GtkWidget *widget,
00111 GdkEventExpose *event)
00112 {
00113 MetaArea *area;
00114 GtkMisc *misc;
00115 gint x, y;
00116 gfloat xalign;
00117
00118 g_return_val_if_fail (META_IS_AREA (widget), FALSE);
00119 g_return_val_if_fail (event != NULL, FALSE);
00120
00121 if (GTK_WIDGET_DRAWABLE (widget))
00122 {
00123 area = META_AREA (widget);
00124 misc = GTK_MISC (widget);
00125
00126 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
00127 xalign = misc->xalign;
00128 else
00129 xalign = 1.0 - misc->xalign;
00130
00131 x = floor (widget->allocation.x + misc->xpad
00132 + ((widget->allocation.width - widget->requisition.width) * xalign)
00133 + 0.5);
00134 y = floor (widget->allocation.y + misc->ypad
00135 + ((widget->allocation.height - widget->requisition.height) * misc->yalign)
00136 + 0.5);
00137
00138 if (area->expose_func)
00139 {
00140 (* area->expose_func) (area, event, x, y,
00141 area->user_data);
00142 }
00143 }
00144
00145 return FALSE;
00146 }
00147
00148 static void
00149 meta_area_size_request (GtkWidget *widget,
00150 GtkRequisition *req)
00151 {
00152 MetaArea *area;
00153
00154 area = META_AREA (widget);
00155
00156 req->width = 0;
00157 req->height = 0;
00158
00159 if (area->size_func)
00160 {
00161 (* area->size_func) (area, &req->width, &req->height,
00162 area->user_data);
00163 }
00164 }
00165
00166 void
00167 meta_area_setup (MetaArea *area,
00168 MetaAreaSizeFunc size_func,
00169 MetaAreaExposeFunc expose_func,
00170 void *user_data,
00171 GDestroyNotify dnotify)
00172 {
00173 if (area->dnotify)
00174 (* area->dnotify) (area->user_data);
00175
00176 area->size_func = size_func;
00177 area->expose_func = expose_func;
00178 area->user_data = user_data;
00179 area->dnotify = dnotify;
00180
00181 gtk_widget_queue_resize (GTK_WIDGET (area));
00182 }
00183