File: gwygraphcorner.c

package info (click to toggle)
gwyddion 2.62-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 51,952 kB
  • sloc: ansic: 398,486; python: 7,877; sh: 5,492; makefile: 4,723; xml: 3,883; cpp: 1,969; pascal: 418; perl: 154; ruby: 130
file content (155 lines) | stat: -rw-r--r-- 5,077 bytes parent folder | download | duplicates (4)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 *  $Id: gwygraphcorner.c 20678 2017-12-18 18:26:55Z yeti-dn $
 *  Copyright (C) 2003 David Necas (Yeti), Petr Klapetek.
 *  E-mail: yeti@gwyddion.net, klapetek@gwyddion.net.
 *
 *  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.
 */

#include "config.h"
#include <gtk/gtkwidget.h>
#include <libgwyddion/gwymacros.h>
#include <libgwydgets/gwygraphcorner.h>

static void     gwy_graph_corner_realize       (GtkWidget *widget);
static void     gwy_graph_corner_size_request  (GtkWidget *widget,
                                                GtkRequisition *requisition);
static void     gwy_graph_corner_size_allocate (GtkWidget *widget,
                                                GtkAllocation *allocation);
static gboolean gwy_graph_corner_expose        (GtkWidget *widget,
                                                GdkEventExpose *event);

G_DEFINE_TYPE(GwyGraphCorner, gwy_graph_corner, GTK_TYPE_WIDGET)

static void
gwy_graph_corner_class_init(GwyGraphCornerClass *klass)
{
    GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);

    widget_class->realize = gwy_graph_corner_realize;
    widget_class->expose_event = gwy_graph_corner_expose;
    widget_class->size_request = gwy_graph_corner_size_request;
    widget_class->size_allocate = gwy_graph_corner_size_allocate;
}

static void
gwy_graph_corner_init(G_GNUC_UNUSED GwyGraphCorner *graph_corner)
{
}

/**
 * gwy_graph_corner_new:
 *
 * Creates a new graph corner.
 *
 * Returns: A new graph corner as a #GtkWidget.
 **/
GtkWidget*
gwy_graph_corner_new()
{
    GwyGraphCorner *graph_corner;

    graph_corner = g_object_new(GWY_TYPE_GRAPH_CORNER, NULL);

    return GTK_WIDGET(graph_corner);
}

static void
gwy_graph_corner_realize(GtkWidget *widget)
{
    GdkWindowAttr attributes;
    gint i, attributes_mask;
    GtkStyle *style;

    GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);

    attributes.x = widget->allocation.x;
    attributes.y = widget->allocation.y;
    attributes.width = widget->allocation.width;
    attributes.height = widget->allocation.height;
    attributes.wclass = GDK_INPUT_OUTPUT;
    attributes.window_type = GDK_WINDOW_CHILD;
    attributes.visual = gtk_widget_get_visual(widget);
    attributes.colormap = gtk_widget_get_colormap(widget);
    attributes.event_mask = gtk_widget_get_events(widget);
    attributes.event_mask |= GDK_EXPOSURE_MASK;

    attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
    widget->window = gdk_window_new(widget->parent->window,
                                    &attributes, attributes_mask);
    gdk_window_set_user_data(widget->window, widget);

    widget->style = gtk_style_attach(widget->style, widget->window);

    /* set background to white forever */
    style = gtk_style_copy(widget->style);
    for (i = 0; i < 5; i++) {
        style->bg_gc[i] = widget->style->white_gc;
        style->bg[i] = widget->style->white;
    }
    gtk_style_set_background(style, widget->window, GTK_STATE_NORMAL);
    g_object_unref(style);
}

static void
gwy_graph_corner_size_request(G_GNUC_UNUSED GtkWidget *widget,
                              GtkRequisition *requisition)
{
    requisition->width = 0;
    requisition->height = 0;
}

static void
gwy_graph_corner_size_allocate(GtkWidget *widget,
                               GtkAllocation *allocation)
{
    widget->allocation = *allocation;

    if (GTK_WIDGET_REALIZED(widget)) {
        gdk_window_move_resize(widget->window,
                               allocation->x, allocation->y,
                               allocation->width, allocation->height);
    }
}

static gboolean
gwy_graph_corner_expose(GtkWidget *widget,
                       GdkEventExpose *event)
{
    if (event->count > 0)
        return FALSE;

    gdk_window_clear_area(widget->window,
                          0, 0,
                          widget->allocation.width,
                          widget->allocation.height);

    return FALSE;
}

/************************** Documentation ****************************/

/**
 * SECTION:gwygraphcorner
 * @title: GwyGraphCorner
 * @short_description: Graph corners
 *
 * #GwyGraphCorner is a part of #GwyGraph and it currently has no
 * functionality.  It is reserved for future.  It will be probably used for
 * some graph options quick accesibility.
 **/

/* vim: set cin et ts=4 sw=4 cino=>1s,e0,n0,f0,{0,}0,^0,\:1s,=0,g1s,h0,t0,+1s,c3,(0,u0 : */