⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dw_widget.c

📁 浏览器的源代码,可移植到嵌入式设备.
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * File: dw_widget.c * * Copyright (C) 2001-2003  Sebastian Geerken <S.Geerken@ping.de> * * 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. */#include <gtk/gtk.h>#include <stdio.h>#include <string.h>#include "msg.h"#include "dw_widget.h"#include "dw_marshal.h"#include "dw_container.h"#include "dw_gtk_viewport.h"#define DEBUG_EVENT 10#define DEBUG_SIZE   0#define DEBUG_ALLOC  0/*#define DEBUG_LEVEL 10*/#include "debug.h"static void Dw_widget_init                (DwWidget *widget);static void Dw_widget_class_init          (DwWidgetClass *klass);static void Dw_widget_shutdown            (GtkObject *object);static void Dw_widget_destroy             (GtkObject *object);static void Dw_widget_real_size_request   (DwWidget *widget,                                           DwRequisition *requisition);static void Dw_widget_real_get_extremes   (DwWidget *widget,                                           DwExtremes *extremes);static void Dw_widget_update_cursor       (DwWidget *widget);enum{   SIZE_REQUEST,   FAST_SIZE_REQUEST,   SIZE_ALLOCATE,   SET_WIDTH,   SET_ASCENT,   SET_DESCENT,   DRAW,   REALIZE,   UNREALIZE,   BUTTON_PRESS_EVENT,   BUTTON_RELEASE_EVENT,   MOTION_NOTIFY_EVENT,   ENTER_NOTIFY_EVENT,   LEAVE_NOTIFY_EVENT,   LAST_SIGNAL};static GtkObjectClass *parent_class;static guint widget_signals[LAST_SIGNAL] = { 0 };/* * Standard Gtk+ function */GtkType a_Dw_widget_get_type (void){   static GtkType type = 0;   if (!type) {      GtkTypeInfo info = {         "DwWidget",         sizeof (DwWidget),         sizeof (DwWidgetClass),         (GtkClassInitFunc) Dw_widget_class_init,         (GtkObjectInitFunc) Dw_widget_init,         (GtkArgSetFunc) NULL,         (GtkArgGetFunc) NULL,         (GtkClassInitFunc) NULL      };      type = gtk_type_unique (GTK_TYPE_OBJECT, &info);   }   return type;}/* * Standard Gtk+ function */static void Dw_widget_init (DwWidget *widget){   widget->flags = DW_NEEDS_RESIZE | DW_EXTREMES_CHANGED | DW_HAS_CONTENT;   widget->parent = NULL;   widget->viewport = NULL;   widget->allocation.x = -1;   widget->allocation.y = -1;   widget->allocation.width = 1;   widget->allocation.ascent = 1;   widget->allocation.descent = 0;   widget->cursor = NULL;   widget->style = NULL;   widget->bg_color = NULL;   widget->button_sensitive = TRUE;   widget->button_sensitive_set = FALSE;}/* * Standard Gtk+ function */static void Dw_widget_class_init (DwWidgetClass *klass){   GtkObjectClass *object_class;   parent_class = gtk_type_class (gtk_object_get_type ());   object_class = GTK_OBJECT_CLASS (klass);   widget_signals[SIZE_REQUEST] =      gtk_signal_new ("size_request",                      GTK_RUN_FIRST,                      object_class->type,                      GTK_SIGNAL_OFFSET (DwWidgetClass, size_request),                      gtk_marshal_NONE__POINTER,                      GTK_TYPE_NONE,                      1, GTK_TYPE_POINTER);   widget_signals[SIZE_ALLOCATE] =      gtk_signal_new ("size_allocate",                      GTK_RUN_FIRST,                      object_class->type,                      GTK_SIGNAL_OFFSET (DwWidgetClass, size_allocate),                      gtk_marshal_NONE__POINTER,                      GTK_TYPE_NONE,                      1, GTK_TYPE_POINTER);   widget_signals[SET_WIDTH] =      gtk_signal_new ("set_width",                      GTK_RUN_FIRST,                      object_class->type,                      GTK_SIGNAL_OFFSET (DwWidgetClass, set_width),                      gtk_marshal_NONE__INT,                      GTK_TYPE_NONE,                      1, GTK_TYPE_UINT);   widget_signals[SET_ASCENT] =      gtk_signal_new ("set_ascent",                      GTK_RUN_FIRST,                      object_class->type,                      GTK_SIGNAL_OFFSET (DwWidgetClass, set_ascent),                      gtk_marshal_NONE__INT,                      GTK_TYPE_NONE,                      1, GTK_TYPE_UINT);   widget_signals[SET_DESCENT] =      gtk_signal_new ("set_descent",                      GTK_RUN_FIRST,                      object_class->type,                      GTK_SIGNAL_OFFSET (DwWidgetClass, set_descent),                      gtk_marshal_NONE__INT,                      GTK_TYPE_NONE,                      1, GTK_TYPE_UINT);   widget_signals[DRAW] =      gtk_signal_new ("draw",                      GTK_RUN_FIRST,                      object_class->type,                      GTK_SIGNAL_OFFSET (DwWidgetClass, draw),                      gtk_marshal_NONE__POINTER_POINTER,                      GTK_TYPE_NONE,                      2, GTK_TYPE_POINTER, GTK_TYPE_GDK_EVENT);   widget_signals[REALIZE] =      gtk_signal_new ("realize",                      GTK_RUN_FIRST,                      object_class->type,                      GTK_SIGNAL_OFFSET (DwWidgetClass, realize),                      gtk_marshal_NONE__NONE,                      GTK_TYPE_NONE, 0);   widget_signals[UNREALIZE] =      gtk_signal_new ("unrealize",                      GTK_RUN_FIRST,                      object_class->type,                      GTK_SIGNAL_OFFSET (DwWidgetClass, unrealize),                      gtk_marshal_NONE__NONE,                      GTK_TYPE_NONE, 0);  widget_signals[BUTTON_PRESS_EVENT] =     gtk_signal_new ("button_press_event",                     GTK_RUN_LAST,                     object_class->type,                     GTK_SIGNAL_OFFSET (DwWidgetClass, button_press_event),                     p_Dw_marshal_BOOL__INT_INT_POINTER,                     GTK_TYPE_BOOL,                     3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_GDK_EVENT);  widget_signals[BUTTON_RELEASE_EVENT] =     gtk_signal_new ("button_release_event",                     GTK_RUN_LAST,                     object_class->type,                     GTK_SIGNAL_OFFSET (DwWidgetClass, button_release_event),                     p_Dw_marshal_BOOL__INT_INT_POINTER,                     GTK_TYPE_BOOL,                     3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_GDK_EVENT);  widget_signals[MOTION_NOTIFY_EVENT] =     gtk_signal_new ("motion_notify_event",                     GTK_RUN_LAST,                     object_class->type,                     GTK_SIGNAL_OFFSET (DwWidgetClass, motion_notify_event),                     p_Dw_marshal_BOOL__INT_INT_POINTER,                     GTK_TYPE_BOOL,                     3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_GDK_EVENT);  widget_signals[ENTER_NOTIFY_EVENT] =     gtk_signal_new ("enter_notify_event",                     GTK_RUN_LAST,                     object_class->type,                     GTK_SIGNAL_OFFSET (DwWidgetClass, enter_notify_event),                     p_Dw_marshal_BOOL__POINTER_POINTER,                     GTK_TYPE_BOOL,                     2, GTK_TYPE_POINTER, GTK_TYPE_GDK_EVENT);  widget_signals[LEAVE_NOTIFY_EVENT] =     gtk_signal_new ("leave_notify_event",                     GTK_RUN_LAST,                     object_class->type,                     GTK_SIGNAL_OFFSET (DwWidgetClass, leave_notify_event),                     p_Dw_marshal_BOOL__POINTER_POINTER,                     GTK_TYPE_BOOL,                     2, GTK_TYPE_POINTER, GTK_TYPE_GDK_EVENT);   gtk_object_class_add_signals (object_class, widget_signals, LAST_SIGNAL);   object_class->shutdown = Dw_widget_shutdown;   object_class->destroy = Dw_widget_destroy;   klass->size_request = Dw_widget_real_size_request;   klass->get_extremes = Dw_widget_real_get_extremes;   klass->size_allocate = NULL;   klass->mark_size_change = NULL;   klass->mark_extremes_change = NULL;   klass->set_width = NULL;   klass->set_ascent = NULL;   klass->set_descent = NULL;   klass->draw = NULL;   klass->realize = NULL;   klass->unrealize = NULL;   klass->button_press_event = NULL;   klass->button_release_event = NULL;   klass->motion_notify_event = NULL;   klass->enter_notify_event = NULL;   klass->leave_notify_event = NULL;   klass->iterator = NULL;}/* * Standard Gtk+ function */static void Dw_widget_shutdown (GtkObject *object){   DwWidget *widget;   widget = DW_WIDGET (object);   a_Dw_widget_unrealize (widget);   if (widget->parent)      Dw_container_remove (DW_CONTAINER (widget->parent), widget);   else      Dw_gtk_viewport_remove_dw (GTK_DW_VIEWPORT (widget->viewport));   parent_class->shutdown (object);}/* * Standard Gtk+ function */static void Dw_widget_destroy (GtkObject *object){   DwWidget *widget;   widget = DW_WIDGET (object);   /* The widget the pointer is in? */   if (widget->viewport != NULL &&       widget == GTK_DW_VIEWPORT(widget->viewport)->last_entered)      /* todo: perhaps call the leave_notify function? */      GTK_DW_VIEWPORT(widget->viewport)->last_entered = NULL;   if (widget->style)      a_Dw_style_unref (widget->style);   parent_class->destroy (object);}/* * Standard Dw function */static void Dw_widget_real_size_request (DwWidget *widget,                                         DwRequisition *requisition){   g_warning ("DwWidget::size_request not implemented for `%s'",              gtk_type_name (GTK_OBJECT_TYPE (widget)));   /* return random size to prevent crashes*/   requisition->width = 50;   requisition->ascent = 50;   requisition->descent = 50;}/* * Standard Dw function */static void Dw_widget_real_get_extremes (DwWidget *widget,                                         DwExtremes *extremes){   /* Simply return the requisition width */   DwRequisition requisition;   a_Dw_widget_size_request (widget, &requisition);   extremes->min_width = extremes->max_width = requisition.width;}/* * This function is a wrapper for DwWidget::size_request; it calls * this method only when needed. */void a_Dw_widget_size_request (DwWidget *widget,                               DwRequisition *requisition){   if (DW_WIDGET_NEEDS_RESIZE (widget)) {      /* todo: check requisition == &(widget->requisition) and do what? */      gtk_signal_emit (GTK_OBJECT (widget), widget_signals[SIZE_REQUEST],                       requisition);      widget->requisition = *requisition;      DW_WIDGET_UNSET_FLAGS (widget, DW_NEEDS_RESIZE);      DBG_OBJ_SET_NUM (widget, "requisition.width", widget->requisition.width);      DBG_OBJ_SET_NUM (widget, "requisition.ascent",                       widget->requisition.ascent);      DBG_OBJ_SET_NUM (widget, "requisition.descent",                       widget->requisition.descent);   } else      *requisition = widget->requisition;}/* * Wrapper for DwWidget::get_extremes. */void a_Dw_widget_get_extremes (DwWidget *widget,                               DwExtremes *extremes){   DwWidgetClass *klass;   if (DW_WIDGET_EXTREMES_CHANGED (widget)) {      klass =  DW_WIDGET_CLASS (GTK_OBJECT(widget)->klass);      (* (klass->get_extremes)) (widget, extremes);      widget->extremes = *extremes;      DW_WIDGET_UNSET_FLAGS (widget, DW_EXTREMES_CHANGED);      DBG_OBJ_SET_NUM (widget, "extremes.min_width",                       widget->extremes.min_width);      DBG_OBJ_SET_NUM (widget, "extremes.max_width",                       widget->extremes.max_width);   } else      *extremes = widget->extremes;}/* * Wrapper for DwWidget::size_allocate, only called when needed. */void a_Dw_widget_size_allocate  (DwWidget *widget,                                 DwAllocation *allocation){   if (DW_WIDGET_NEEDS_ALLOCATE (widget) ||       allocation->x != widget->allocation.x ||       allocation->y != widget->allocation.y ||       allocation->width != widget->allocation.width ||       allocation->ascent != widget->allocation.ascent ||       allocation->descent != widget->allocation.descent) {      DEBUG_MSG (DEBUG_ALLOC,                 "a %stop-level %s with parent_ref = %d is newly allocated "                 "from %d, %d, %d x %d x %d ...\n",                 widget->parent ? "non-" : "",                 gtk_type_name (GTK_OBJECT_TYPE (widget)), widget->parent_ref,                 widget->allocation.x, widget->allocation.y,                 widget->allocation.width, widget->allocation.ascent,                 widget->allocation.descent);      gtk_signal_emit (GTK_OBJECT (widget), widget_signals[SIZE_ALLOCATE],                       allocation);      DEBUG_MSG (DEBUG_ALLOC, "... to %d, %d, %d x %d x %d\n",                 widget->allocation.x, widget->allocation.y,                 widget->allocation.width, widget->allocation.ascent,                 widget->allocation.descent);      widget->allocation = *allocation;      DW_WIDGET_UNSET_FLAGS (widget, DW_NEEDS_ALLOCATE);      DBG_OBJ_SET_NUM (widget, "allocation.x", widget->allocation.x);      DBG_OBJ_SET_NUM (widget, "allocation.y", widget->allocation.y);      DBG_OBJ_SET_NUM (widget, "allocation.width", widget->allocation.width);      DBG_OBJ_SET_NUM (widget, "allocation.ascent", widget->allocation.ascent);      DBG_OBJ_SET_NUM (widget, "allocation.descent",                       widget->allocation.descent);   }   /*DW_WIDGET_UNSET_FLAGS (widget, DW_NEEDS_RESIZE);*/}void a_Dw_widget_set_width (DwWidget *widget,                            gint32 width){   gtk_signal_emit (GTK_OBJECT (widget), widget_signals[SET_WIDTH], width);}void a_Dw_widget_set_ascent (DwWidget *widget,                             gint32 ascent){   gtk_signal_emit (GTK_OBJECT (widget), widget_signals[SET_ASCENT], ascent);}void a_Dw_widget_set_descent (DwWidget *widget,                              gint32 descent){   gtk_signal_emit (GTK_OBJECT (widget), widget_signals[SET_DESCENT], descent);}void a_Dw_widget_draw (DwWidget *widget,                       DwRectangle *area,                       GdkEventExpose *event){   /* NOTE: This function depends on that widgets are always drawn top-down.    * The initial draw call is done for the top-level widget by the viewport,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -