[go: up one dir, main page]

File: dw_hruler.c

package info (click to toggle)
dillo 0.8.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,168 kB
  • ctags: 3,987
  • sloc: ansic: 32,778; sh: 3,401; makefile: 251; perl: 17
file content (141 lines) | stat: -rw-r--r-- 4,364 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * File: dw_hruler.c
 *
 * Copyright (C) 2000 Jorge Arellano Cid <jcid@dillo.org>
 *
 * 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 is really an empty widget, the HTML parser puts a border
 * around it, and drawing is done in Dw_widget_draw_widget_box. The
 * only remarkable point is that the DW_HAS_CONTENT flag is
 * cleared.
 */

#include "dw_hruler.h"
#include "dw_gtk_viewport.h"
#include "debug.h"

static void        Dw_hruler_init               (DwHruler *hruler);
static void        Dw_hruler_class_init         (DwHrulerClass *klass);

static void        Dw_hruler_size_request       (DwWidget *widget,
                                                 DwRequisition *requisition);
static void        Dw_hruler_draw               (DwWidget *widget,
                                                 DwRectangle *area,
                                                 GdkEventExpose *event);
static DwIterator* Dw_hruler_iterator           (DwWidget *widget,
                                                 gint32 mask,
                                                 gboolean at_end);
static void        Dw_hruler_iterator_highlight (DwIterator *it,
                                                 gint start,
                                                 gint end,
                                                 DwHighlightLayer layer);


GtkType a_Dw_hruler_get_type (void)
{
   static GtkType type = 0;

   if (!type) {
      GtkTypeInfo info = {
         "DwHruler",
         sizeof (DwHruler),
         sizeof (DwHrulerClass),
         (GtkClassInitFunc) Dw_hruler_class_init,
         (GtkObjectInitFunc) Dw_hruler_init,
         (GtkArgSetFunc) NULL,
         (GtkArgGetFunc) NULL,
         (GtkClassInitFunc) NULL
      };

      type = gtk_type_unique (DW_TYPE_WIDGET, &info);
   }

   return type;
}


DwWidget* a_Dw_hruler_new (void)
{
   GtkObject *object = gtk_object_new (DW_TYPE_HRULER, NULL);
   DBG_OBJ_CREATE (object, "DwHRuler");
   return DW_WIDGET (object);
}


static void Dw_hruler_init (DwHruler *hruler)
{
   int i;
   DW_WIDGET_UNSET_FLAGS (hruler, DW_HAS_CONTENT);
   for (i = 0; i < DW_HIGHLIGHT_NUM_LAYERS; i++)
      hruler->selected[i] = FALSE;
}


static void Dw_hruler_class_init (DwHrulerClass *klass)
{
   GtkObjectClass *object_class;
   DwWidgetClass *widget_class;

   object_class = GTK_OBJECT_CLASS (klass);

   widget_class = (DwWidgetClass*)klass;
   widget_class->size_request = Dw_hruler_size_request;
   widget_class->draw = Dw_hruler_draw;
   widget_class->iterator = Dw_hruler_iterator;
}


static void Dw_hruler_size_request (DwWidget *widget,
                                    DwRequisition *requisition)
{
   requisition->width = p_Dw_style_box_diff_width (widget->style);
   requisition->ascent = p_Dw_style_box_diff_height (widget->style);
   requisition->descent = 0;
}


static void Dw_hruler_draw (DwWidget *widget,
                            DwRectangle *area,
                            GdkEventExpose *event)
{
   int i;
   gboolean selected = FALSE;

   for (i = 0; i < DW_HIGHLIGHT_NUM_LAYERS && !selected; i++)
      selected = DW_HRULER(widget)->selected[i];
   p_Dw_widget_draw_widget_box (widget, area, selected);
   if (selected)
      p_Dw_widget_draw_selected (widget, area);
}


static DwIterator *Dw_hruler_iterator (DwWidget *widget,
                                       gint32 mask,
                                       gboolean at_end)
{
   DwIterator *it;

   it = p_Dw_widget_text_iterator (widget, mask, at_end,
                                   "-----------------------------------"
                                   "-----------------------------------");
   if (it)
     it->highlight = Dw_hruler_iterator_highlight;
   return it;
}

static void Dw_hruler_iterator_highlight (DwIterator *it,
                                          gint start,
                                          gint end,
                                          DwHighlightLayer layer)
{
   if (it->content.type == DW_CONTENT_TEXT) {
      DW_HRULER(it->widget)->selected[layer] = (start == 0 && end >= 1);
      p_Dw_widget_queue_draw (it->widget);
   }
}