Compare commits

...

3 Commits

Author SHA1 Message Date
Owen Taylor
c85ee0c830 Don't queue a redraw if the size didn't change. queue a shallow redraw.
2005-02-11  Owen Taylor  <otaylor@redhat.com>

        * gtk/gtkwindow.c (gtk_window_size_allocate): Don't queue
        a redraw if the size didn't change. queue a shallow redraw.
2005-02-11 22:39:19 +00:00
Owen Taylor
d6386f036f Add a resizable-background style property that, if set, causes the entire
005-02-10  Owen Taylor  <otaylor@redhat.com>

        * gtk/gtkwindow.c: Add a resizable-background style property
        that, if set, causes the entire widget to be queued for
        redraw on ::size-allocate.
2005-02-10 20:54:00 +00:00
Owen Taylor
966550b52e Add a draw-border style property to allow themes to draw outside the
2005-02-10  Owen Taylor  <otaylor@redhat.com>

        * gtk/gtkwidget.c: Add a draw-border style property to allow
        themes to draw outside the widget's allocation.

        * gdk/x11/gdkevents-x11.c: Hack out Net/ThemeName to
        allow easier testing of theme stuff without having
        to change global GNOME configuration.
2005-02-10 19:44:31 +00:00
7 changed files with 135 additions and 406 deletions

View File

@@ -1,3 +1,23 @@
2005-02-11 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.c (gtk_window_size_allocate): Don't queue
a redraw if the size didn't change. queue a shallow redraw.
2005-02-10 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.c: Add a resizable-background style property
that, if set, causes the entire widget to be queued for
redraw on ::size-allocate.
2005-02-10 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c: Add a draw-border style property to allow
themes to draw outside the widget's allocation.
* gdk/x11/gdkevents-x11.c: Hack out Net/ThemeName to
allow easier testing of theme stuff without having
to change global GNOME configuration.
2005-02-09 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkmenushell.c (gtk_real_menu_shell_move_current): Fix RTL

View File

@@ -1,3 +1,23 @@
2005-02-11 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.c (gtk_window_size_allocate): Don't queue
a redraw if the size didn't change. queue a shallow redraw.
2005-02-10 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.c: Add a resizable-background style property
that, if set, causes the entire widget to be queued for
redraw on ::size-allocate.
2005-02-10 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c: Add a draw-border style property to allow
themes to draw outside the widget's allocation.
* gdk/x11/gdkevents-x11.c: Hack out Net/ThemeName to
allow easier testing of theme stuff without having
to change global GNOME configuration.
2005-02-09 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkmenushell.c (gtk_real_menu_shell_move_current): Fix RTL

View File

@@ -1,3 +1,23 @@
2005-02-11 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.c (gtk_window_size_allocate): Don't queue
a redraw if the size didn't change. queue a shallow redraw.
2005-02-10 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.c: Add a resizable-background style property
that, if set, causes the entire widget to be queued for
redraw on ::size-allocate.
2005-02-10 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c: Add a draw-border style property to allow
themes to draw outside the widget's allocation.
* gdk/x11/gdkevents-x11.c: Hack out Net/ThemeName to
allow easier testing of theme stuff without having
to change global GNOME configuration.
2005-02-09 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkmenushell.c (gtk_real_menu_shell_move_current): Fix RTL

View File

@@ -1,392 +0,0 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <gtk/gtk.h>
#include <demos.h>
static GtkTextBuffer *info_buffer;
static GtkTextBuffer *source_buffer;
static gchar *current_file = NULL;
enum {
TITLE_COLUMN,
FILENAME_COLUMN,
FUNC_COLUMN,
ITALIC_COLUMN,
NUM_COLUMNS
};
gboolean
read_line (FILE *stream, GString *str)
{
int n_read = 0;
flockfile (stream);
g_string_truncate (str, 0);
while (1)
{
int c;
c = getc_unlocked (stream);
if (c == EOF)
goto done;
else
n_read++;
switch (c)
{
case '\r':
case '\n':
{
int next_c = getc_unlocked (stream);
if (!(next_c == EOF ||
(c == '\r' && next_c == '\n') ||
(c == '\n' && next_c == '\r')))
ungetc (next_c, stream);
goto done;
}
default:
g_string_append_c (str, c);
}
}
done:
funlockfile (stream);
return n_read > 0;
}
void
load_file (const gchar *filename)
{
FILE *file;
GtkTextIter start, end;
GString *buffer = g_string_new (NULL);
int state = 0;
gboolean in_para = 0;
if (current_file && !strcmp (current_file, filename))
return;
g_free (current_file);
current_file = g_strdup (filename);
gtk_text_buffer_get_bounds (info_buffer, &start, &end);
gtk_text_buffer_delete (info_buffer, &start, &end);
gtk_text_buffer_get_bounds (source_buffer, &start, &end);
gtk_text_buffer_delete (source_buffer, &start, &end);
file = fopen (filename, "r");
if (!file)
{
g_warning ("Cannot open %s: %s\n", filename, g_strerror (errno));
return;
}
gtk_text_buffer_get_iter_at_offset (info_buffer, &start, 0);
while (read_line (file, buffer))
{
gchar *p = buffer->str;
gchar *q;
switch (state)
{
case 0:
/* Reading title */
while (*p == '/' || *p == '*' || isspace (*p))
p++;
q = p + strlen (p);
while (q > p && isspace (*(q - 1)))
q--;
if (q > p)
{
int len_chars = g_utf8_pointer_to_offset (p, q);
end = start;
g_assert (strlen (p) >= q - p);
gtk_text_buffer_insert (info_buffer, &end, p, q - p);
start = end;
gtk_text_iter_backward_chars (&start, len_chars);
gtk_text_buffer_apply_tag_by_name (info_buffer, "title", &start, &end);
start = end;
state++;
}
break;
case 1:
/* Reading body of info section */
while (isspace (*p))
p++;
if (*p == '*' && *(p + 1) == '/')
{
gtk_text_buffer_get_iter_at_offset (source_buffer, &start, 0);
state++;
}
else
{
int len;
while (*p == '*' || isspace (*p))
p++;
len = strlen (p);
while (isspace (*(p + len - 1)))
len--;
if (len > 0)
{
if (in_para)
gtk_text_buffer_insert (info_buffer, &start, " ", 1);
g_assert (strlen (p) >= len);
gtk_text_buffer_insert (info_buffer, &start, p, len);
in_para = 1;
}
else
{
gtk_text_buffer_insert (info_buffer, &start, "\n", 1);
in_para = 0;
}
}
break;
case 2:
/* Skipping blank lines */
while (isspace (*p))
p++;
if (*p)
{
p = buffer->str;
state++;
/* Fall through */
}
else
break;
case 3:
/* Reading program body */
gtk_text_buffer_insert (source_buffer, &start, p, -1);
gtk_text_buffer_insert (info_buffer, &start, "\n", 1);
break;
}
}
gtk_text_buffer_get_bounds (source_buffer, &start, &end);
gtk_text_buffer_apply_tag_by_name (info_buffer, "source", &start, &end);
}
gboolean
button_press_event_cb (GtkTreeView *tree_view,
GdkEventButton *event,
GtkTreeModel *model)
{
if (event->type == GDK_2BUTTON_PRESS)
{
GtkTreePath *path = NULL;
gtk_tree_view_get_path_at_pos (tree_view,
event->window,
event->x,
event->y,
&path,
NULL);
if (path)
{
GtkTreeIter iter;
gboolean italic;
GVoidFunc func;
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_store_get (GTK_TREE_STORE (model),
&iter,
FUNC_COLUMN, &func,
ITALIC_COLUMN, &italic,
-1);
(func) ();
gtk_tree_store_set (GTK_TREE_STORE (model),
&iter,
ITALIC_COLUMN, !italic,
-1);
gtk_tree_path_free (path);
}
gtk_signal_emit_stop_by_name (GTK_OBJECT (tree_view),
"button_press_event");
return TRUE;
}
return FALSE;
}
static void
selection_cb (GtkTreeSelection *selection,
GtkTreeModel *model)
{
GtkTreeIter iter;
GValue value = {0, };
if (! gtk_tree_selection_get_selected (selection, NULL, &iter))
return;
gtk_tree_model_get_value (model, &iter,
FILENAME_COLUMN,
&value);
load_file (g_value_get_string (&value));
g_value_unset (&value);
}
static GtkWidget *
create_text (GtkTextBuffer **buffer,
gboolean is_source)
{
GtkWidget *scrolled_window;
GtkWidget *text_view;
PangoFontDescription *font_desc;
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_SHADOW_IN);
text_view = gtk_text_view_new ();
gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
*buffer = gtk_text_buffer_new (NULL);
gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), *buffer);
gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE);
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (text_view), FALSE);
if (is_source)
{
font_desc = pango_font_description_from_string ("Courier 10");
gtk_widget_modify_font (text_view, font_desc);
pango_font_description_free (font_desc);
}
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), !is_source);
return scrolled_window;
}
/* Technically a list, but if we do go to 80 demos, we may want to move to a tree */
static GtkWidget *
create_tree (void)
{
GtkTreeSelection *selection;
GtkCellRenderer *cell;
GtkWidget *tree_view;
GtkTreeViewColumn *column;
GtkTreeStore *model;
GtkTreeIter iter;
gint i;
model = gtk_tree_store_new_with_types (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN);
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
gtk_tree_selection_set_type (GTK_TREE_SELECTION (selection),
GTK_TREE_SELECTION_SINGLE);
gtk_widget_set_usize (tree_view, 200, -1);
for (i=0; i < G_N_ELEMENTS (testgtk_demos); i++)
{
gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
gtk_tree_store_set (GTK_TREE_STORE (model),
&iter,
TITLE_COLUMN, testgtk_demos[i].title,
FILENAME_COLUMN, testgtk_demos[i].filename,
FUNC_COLUMN, testgtk_demos[i].func,
ITALIC_COLUMN, FALSE,
-1);
}
cell = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Widget",
cell,
"text", TITLE_COLUMN,
"italic", ITALIC_COLUMN,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view),
GTK_TREE_VIEW_COLUMN (column));
gtk_signal_connect (GTK_OBJECT (selection), "selection_changed", selection_cb, model);
gtk_signal_connect (GTK_OBJECT (tree_view), "button_press_event", GTK_SIGNAL_FUNC (button_press_event_cb), model);
return tree_view;
}
int
main (int argc, char **argv)
{
GtkWidget *window;
GtkWidget *notebook;
GtkWidget *hbox;
GtkWidget *tree;
GtkTextTag *tag;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
hbox = gtk_hbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), hbox);
tree = create_tree ();
gtk_box_pack_start (GTK_BOX (hbox), tree, FALSE, FALSE, 0);
notebook = gtk_notebook_new ();
gtk_box_pack_start (GTK_BOX (hbox), notebook, TRUE, TRUE, 0);
gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
create_text (&info_buffer, FALSE),
gtk_label_new ("Info"));
gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
create_text (&source_buffer, TRUE),
gtk_label_new ("Source"));
tag = gtk_text_buffer_create_tag (info_buffer, "title");
gtk_object_set (GTK_OBJECT (tag),
"font", "Sans 18",
NULL);
tag = gtk_text_buffer_create_tag (info_buffer, "source");
gtk_object_set (GTK_OBJECT (tag),
"font", "Courier 10",
"pixels_above_lines", 0,
"pixels_below_lines", 0,
NULL);
gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
gtk_widget_show_all (window);
load_file (testgtk_demos[0].filename);
gtk_main ();
return 0;
}

View File

@@ -2708,7 +2708,8 @@ static struct
{ "Net/DndDragThreshold", "gtk-dnd-drag-threshold" },
{ "Net/CursorBlink", "gtk-cursor-blink" },
{ "Net/CursorBlinkTime", "gtk-cursor-blink-time" },
{ "Net/ThemeName", "gtk-theme-name" },
/* Temporarily disabled for demo purposes */
/* { "Net/ThemeName", "gtk-theme-name" }, */
{ "Net/IconThemeName", "gtk-icon-theme-name" },
{ "Gtk/CanChangeAccels", "gtk-can-change-accels" },
{ "Gtk/ColorPalette", "gtk-color-palette" },

View File

@@ -1456,6 +1456,12 @@ gtk_widget_class_init (GtkWidgetClass *klass)
P_("Aspect ratio with which to draw insertion cursor"),
0.0, 1.0, 0.04,
G_PARAM_READABLE));
gtk_widget_class_install_style_property (klass,
g_param_spec_boxed ("draw-border",
P_("Draw Border"),
P_("Size of areas outside the widget's allocation to draw"),
GTK_TYPE_BORDER,
G_PARAM_READABLE));
}
static void
@@ -2425,6 +2431,36 @@ gtk_widget_queue_draw_area (GtkWidget *widget,
gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
}
static void
widget_get_draw_rectangle (GtkWidget *widget,
GdkRectangle *rect)
{
if (GTK_WIDGET_NO_WINDOW (widget))
{
GtkBorder *draw_border = NULL;
*rect = widget->allocation;
gtk_widget_style_get (widget,
"draw-border", &draw_border,
NULL);
if (draw_border)
{
rect->x -= draw_border->top;
rect->y -= draw_border->left;
rect->width += draw_border->left + draw_border->right;
rect->height += draw_border->top + draw_border->bottom;
}
}
else
{
rect->x = 0;
rect->y = 0;
rect->width = widget->allocation.width;
rect->height = widget->allocation.height;
}
}
/**
* gtk_widget_queue_draw:
* @widget: a #GtkWidget
@@ -2436,20 +2472,15 @@ gtk_widget_queue_draw_area (GtkWidget *widget,
void
gtk_widget_queue_draw (GtkWidget *widget)
{
GdkRectangle rect;
g_return_if_fail (GTK_IS_WIDGET (widget));
if (widget->allocation.width || widget->allocation.height)
{
if (GTK_WIDGET_NO_WINDOW (widget))
gtk_widget_queue_draw_area (widget, widget->allocation.x,
widget->allocation.y,
widget->allocation.width,
widget->allocation.height);
else
gtk_widget_queue_draw_area (widget, 0, 0,
widget->allocation.width,
widget->allocation.height);
}
widget_get_draw_rectangle (widget, &rect);
gtk_widget_queue_draw_area (widget,
rect.x, rect.y,
rect.width, rect.height);
}
/* Invalidates the given area (allocation-relative-coordinates)
@@ -3854,12 +3885,15 @@ GdkRegion *
gtk_widget_region_intersect (GtkWidget *widget,
GdkRegion *region)
{
GdkRectangle rect;
GdkRegion *dest;
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
g_return_val_if_fail (region != NULL, NULL);
widget_get_draw_rectangle (widget, &rect);
dest = gdk_region_rectangle (&widget->allocation);
dest = gdk_region_rectangle (&rect);
gdk_region_intersect (dest, region);

View File

@@ -725,6 +725,14 @@ gtk_window_class_init (GtkWindowClass *klass)
add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
add_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
gtk_widget_class_install_style_property (widget_class,
g_param_spec_boolean ("resizable-background",
P_("Resizable Background"),
P_("Whether to redraw the entire background on resize"),
FALSE,
G_PARAM_READABLE));
}
static void
@@ -4209,8 +4217,14 @@ gtk_window_size_allocate (GtkWidget *widget,
{
GtkWindow *window;
GtkAllocation child_allocation;
gboolean allocation_changed = FALSE;
window = GTK_WINDOW (widget);
if (allocation->width != widget->allocation.width ||
allocation->height != widget->allocation.height)
allocation_changed = TRUE;
widget->allocation = *allocation;
if (window->bin.child && GTK_WIDGET_VISIBLE (window->bin.child))
@@ -4231,6 +4245,18 @@ gtk_window_size_allocate (GtkWidget *widget,
allocation->width + window->frame_left + window->frame_right,
allocation->height + window->frame_top + window->frame_bottom);
}
if (allocation_changed && GTK_WIDGET_REALIZED (widget))
{
gboolean resizable_background;
gtk_widget_style_get (widget,
"resizable-background", &resizable_background,
NULL);
if (resizable_background)
gdk_window_invalidate_rect (widget->window, NULL, FALSE);
}
}
static gint