Add a TextView reftests checking border-windows

TextView border windows are internal windows used to draw on the gutter
of the textview (e.g. line numbers). The test uses the gmodule hook to
programmatically draw on the border-windows at each side of the textview
and compares the result with 3x3 grid of labels.
This commit is contained in:
Paolo Borelli 2014-06-15 18:11:15 +02:00
parent 2c5be3b231
commit 2eeff1eed6
5 changed files with 194 additions and 0 deletions

View File

@ -328,6 +328,9 @@ testdata = \
symbolic-icon-translucent-color.css \
symbolic-icon-translucent-color.ref.ui \
symbolic-icon-translucent-color.ui \
textview-border-windows.css \
textview-border-windows.ref.ui \
textview-border-windows.ui \
textview-margins.css \
textview-margins.ref.ui \
textview-margins.ui \
@ -372,6 +375,7 @@ libreftest_la_LIBADD = $(gtk_reftest_LDADD)
libreftest_la_SOURCES = \
set-default-direction.c \
expand-expander.c \
textview-border-windows.c \
$(NULL)
substitutions = \

View File

@ -0,0 +1,75 @@
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gtk/gtk.h>
static void
paint_border (GtkTextView *text_view,
cairo_t *cr,
GtkTextWindowType type,
GtkStyleContext *context,
const char *class)
{
GdkWindow *window;
window = gtk_text_view_get_window (text_view, type);
if (window != NULL &&
gtk_cairo_should_draw_window (cr, window))
{
gint w, h;
gtk_style_context_save (context);
gtk_style_context_add_class (context, class);
w = gdk_window_get_width (window);
h = gdk_window_get_height (window);
gtk_cairo_transform_to_window (cr, GTK_WIDGET (text_view), window);
cairo_save (cr);
gtk_render_background (context, cr, 0, 0, w, h);
cairo_restore (cr);
gtk_style_context_restore (context);
}
}
G_MODULE_EXPORT gboolean
paint_border_windows (GtkTextView *text_view,
cairo_t *cr)
{
GtkStyleContext *context;
context = gtk_widget_get_style_context (GTK_WIDGET (text_view));
paint_border (text_view, cr, GTK_TEXT_WINDOW_LEFT, context, "left");
paint_border (text_view, cr, GTK_TEXT_WINDOW_RIGHT, context, "right");
paint_border (text_view, cr, GTK_TEXT_WINDOW_TOP, context, "top");
paint_border (text_view, cr, GTK_TEXT_WINDOW_BOTTOM, context, "bottom");
return FALSE;
}
G_MODULE_EXPORT void
add_border_windows (GtkTextView *text_view)
{
gtk_text_view_set_border_window_size (text_view, GTK_TEXT_WINDOW_LEFT, 30);
gtk_text_view_set_border_window_size (text_view, GTK_TEXT_WINDOW_RIGHT, 30);
gtk_text_view_set_border_window_size (text_view, GTK_TEXT_WINDOW_TOP, 30);
gtk_text_view_set_border_window_size (text_view, GTK_TEXT_WINDOW_BOTTOM, 30);
}

View File

@ -0,0 +1,21 @@
@import "reset-to-defaults.css";
.top,
#label_n {
background-color: blue;
}
.left,
#label_w {
background-color: green;
}
.right,
#label_e {
background-color: yellow;
}
.bottom,
#label_s {
background-color: red;
}

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<object class="GtkWindow" id="window">
<property name="can_focus">False</property>
<property name="type">popup</property>
<child>
<object class="GtkGrid" id="grid1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label1">
<property name="width_request">100</property>
<property name="height_request">100</property>
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_n">
<property name="name">label_n</property>
<property name="height_request">30</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_w">
<property name="name">label_w</property>
<property name="width_request">30</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_e">
<property name="name">label_e</property>
<property name="width_request">30</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_s">
<property name="name">label_s</property>
<property name="height_request">30</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<object class="GtkWindow" id="window">
<property name="can_focus">False</property>
<property name="type">popup</property>
<child>
<object class="GtkTextView" id="textview1">
<property name="width_request">160</property>
<property name="height_request">160</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="wrap_mode">word</property>
<signal name="map" handler="reftest:add_border_windows" swapped="no"/>
<signal name="draw" handler="reftest:paint_border_windows" swapped="no"/>
</object>
</child>
</object>
</interface>