Commit 693fa02b authored by Tim Janik's avatar Tim Janik Committed by Tim Janik

we make an active server grab now, this way we can change the cursor

Fri Feb 27 15:31:55 1998  Tim Janik  <timj@gimp.org>

        * gtk/gtktipsquery.c: we make an active server grab now, this way we
        can change the cursor globally and don't need to tweak event masks
        of other windows.

        * gtk/gtkframe.c (gtk_frame_style_set): recompute label size.

        * gtk/gtkwidget.h:
        * gtk/gtkwidget.c:
        New signal GtkWidget::style_set to be emitted when a widget's style
        changed. New flag GTK_RC_STYLE to indicate whether an rc lookup has
        been perfomed for the widget.
        (gtk_widget_ensure_style): New function.
        (gtk_widget_set_rc_style): New function.

        * docs/styles.txt: new file.
parent a36ffb12
Fri Feb 27 15:31:55 1998 Tim Janik <timj@gimp.org>
* gtk/gtktipsquery.c: we make an active server grab now, this way we
can change the cursor globally and don't need to tweak event masks
of other windows.
* gtk/gtkframe.c (gtk_frame_style_set): recompute label size.
* gtk/gtkwidget.h:
* gtk/gtkwidget.c:
New signal GtkWidget::style_set to be emitted when a widget's style
changed. New flag GTK_RC_STYLE to indicate whether an rc lookup has
been perfomed for the widget.
(gtk_widget_ensure_style): New function.
(gtk_widget_set_rc_style): New function.
* docs/styles.txt: new file.
Fri Feb 27 01:11:55 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtktext.c
......
Fri Feb 27 15:31:55 1998 Tim Janik <timj@gimp.org>
* gtk/gtktipsquery.c: we make an active server grab now, this way we
can change the cursor globally and don't need to tweak event masks
of other windows.
* gtk/gtkframe.c (gtk_frame_style_set): recompute label size.
* gtk/gtkwidget.h:
* gtk/gtkwidget.c:
New signal GtkWidget::style_set to be emitted when a widget's style
changed. New flag GTK_RC_STYLE to indicate whether an rc lookup has
been perfomed for the widget.
(gtk_widget_ensure_style): New function.
(gtk_widget_set_rc_style): New function.
* docs/styles.txt: new file.
Fri Feb 27 01:11:55 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtktext.c
......
Fri Feb 27 15:31:55 1998 Tim Janik <timj@gimp.org>
* gtk/gtktipsquery.c: we make an active server grab now, this way we
can change the cursor globally and don't need to tweak event masks
of other windows.
* gtk/gtkframe.c (gtk_frame_style_set): recompute label size.
* gtk/gtkwidget.h:
* gtk/gtkwidget.c:
New signal GtkWidget::style_set to be emitted when a widget's style
changed. New flag GTK_RC_STYLE to indicate whether an rc lookup has
been perfomed for the widget.
(gtk_widget_ensure_style): New function.
(gtk_widget_set_rc_style): New function.
* docs/styles.txt: new file.
Fri Feb 27 01:11:55 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtktext.c
......
Fri Feb 27 15:31:55 1998 Tim Janik <timj@gimp.org>
* gtk/gtktipsquery.c: we make an active server grab now, this way we
can change the cursor globally and don't need to tweak event masks
of other windows.
* gtk/gtkframe.c (gtk_frame_style_set): recompute label size.
* gtk/gtkwidget.h:
* gtk/gtkwidget.c:
New signal GtkWidget::style_set to be emitted when a widget's style
changed. New flag GTK_RC_STYLE to indicate whether an rc lookup has
been perfomed for the widget.
(gtk_widget_ensure_style): New function.
(gtk_widget_set_rc_style): New function.
* docs/styles.txt: new file.
Fri Feb 27 01:11:55 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtktext.c
......
Fri Feb 27 15:31:55 1998 Tim Janik <timj@gimp.org>
* gtk/gtktipsquery.c: we make an active server grab now, this way we
can change the cursor globally and don't need to tweak event masks
of other windows.
* gtk/gtkframe.c (gtk_frame_style_set): recompute label size.
* gtk/gtkwidget.h:
* gtk/gtkwidget.c:
New signal GtkWidget::style_set to be emitted when a widget's style
changed. New flag GTK_RC_STYLE to indicate whether an rc lookup has
been perfomed for the widget.
(gtk_widget_ensure_style): New function.
(gtk_widget_set_rc_style): New function.
* docs/styles.txt: new file.
Fri Feb 27 01:11:55 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtktext.c
......
Fri Feb 27 15:31:55 1998 Tim Janik <timj@gimp.org>
* gtk/gtktipsquery.c: we make an active server grab now, this way we
can change the cursor globally and don't need to tweak event masks
of other windows.
* gtk/gtkframe.c (gtk_frame_style_set): recompute label size.
* gtk/gtkwidget.h:
* gtk/gtkwidget.c:
New signal GtkWidget::style_set to be emitted when a widget's style
changed. New flag GTK_RC_STYLE to indicate whether an rc lookup has
been perfomed for the widget.
(gtk_widget_ensure_style): New function.
(gtk_widget_set_rc_style): New function.
* docs/styles.txt: new file.
Fri Feb 27 01:11:55 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtktext.c
......
Fri Feb 27 15:31:55 1998 Tim Janik <timj@gimp.org>
* gtk/gtktipsquery.c: we make an active server grab now, this way we
can change the cursor globally and don't need to tweak event masks
of other windows.
* gtk/gtkframe.c (gtk_frame_style_set): recompute label size.
* gtk/gtkwidget.h:
* gtk/gtkwidget.c:
New signal GtkWidget::style_set to be emitted when a widget's style
changed. New flag GTK_RC_STYLE to indicate whether an rc lookup has
been perfomed for the widget.
(gtk_widget_ensure_style): New function.
(gtk_widget_set_rc_style): New function.
* docs/styles.txt: new file.
Fri Feb 27 01:11:55 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtktext.c
......
......@@ -4,6 +4,8 @@ TODO BEFORE GTK 1.0
Bugs:
* gtk_list_clear_items: free start_list
* GtkComboBox: need to destroy gdk cursor
* Vertical scrollbar: the expose event looks hosed and is causing
quite a bit of flickering
......@@ -60,6 +62,12 @@ Bugs:
-timj
Additions:
* it might be good to ues stdio and getch() instead of 1-character reads.
so one can take advantage of buffering. Currently each read() takes a separate
syscall.
* implement gtk_default_draw_oval
* Lists should scroll to center the recently selected item if it isn't
visible.
......@@ -74,7 +82,9 @@ Additions:
* Make widget attributes configurable after the widget is created (timj).
* Implementation of owens widget style proposal.
* Change gtk_widget_propagate_default_style() mechanism to
void gtk_rc_string_export (const gchar *rc_additions,
gboolean override_rc_styles);
TODO AFTER GTK 1.0
......
......@@ -11,6 +11,7 @@ EXTRA_DIST = \
debugging.txt \
developers.txt \
refcounting.txt \
styles.txt \
text_widget.txt \
widget_system.txt
......
HANDLING WIDGET STYLES
======================
A widget gets created with a default style.
The global default style can be affected by gtk_widget_set_default_style()
and can be queried by gtk_widget_get_default_style().
The initial style that is assigned to a widget as default style upon
creation can be affected by wrapping the widget's creation as follows:
gtk_widget_push_style (my_style);
widget = gtk_type_new (gtk_button_get_type ());
gtk_widget_pop_style ();
There are certain functions to affect widget styles after a widget's
creation:
gtk_widget_set_style ()
Save the default style and set a user style.
This will override a previously set user style or
previously set rc styles.
gtk_widget_set_rc_style ()
Set GTK_RC_STYLE to indicate that an rc lookup has been performed.
If there is an rc style for a widget, set it and save the default style,
restore the default style otherwise.
This will override a previously set user style or rc style.
gtk_widget_ensure_style ()
Ensure taht the widget either has a user style set, or an rc lookup
has been performed.
gtk_rc_get_style ()
Return an rc style for a widget if there is one.
gtk_widget_set_name ()
Change widget name, and perform a new rc lookup if no user style
is set.
gtk_widget_realize ()
Besides realizing the widget this function will:
- perform an rc lookup if neccessary,
- attach a widget's style.
gtk_widget_get_style ()
Return a widgets style, this function will perform an rc lookup
if neccessary.
gtk_widget_set_parent ()
This function will perform rc lookups recursively for all widgets
that do not have a user style set.
gtk_style_copy ()
This function can be used to copy a widgets style.
The style can subsequntly be changed (e.g., by modifications to the
red/green/blue values of a certain color) and then be applied to the
widget via gtk_widget_set_style().
GtkWidget::style_set
This signal will be emitted for a widget once its style changes with
the previous style supplied.
the GtkWidgetClass implements a default handler for this signal that
will set the widget's window's background of widgets that provide their
own windows according to the new style.
Derived widgets need to overide this default handler, if:
- their size requisition depends on the current style.
(e.g., on the style's fonts)
- they set the background of widget->window to something other than.
style->bg. (e.g., GtkListItem)
- the widget provides windows other than widget->window.
- the widget has any other stored dependencies on the style.
Flag indications:
!GTK_RC_STYLE && !GTK_USER_STYLE:
The widget has it's default style set, and no rc lookup has been
performed.
GTK_USER_STYLE:
GTK_RC_STYLE is not set.
The widget has a user style assigned, and it's default style has been
saved.
GTK_RC_STYLE:
GTK_USER_STYLE is not set.
If the widget has a saved default style, it has been assigned an
rc style.
If the widget does not have a saved default style, it still has its
default style but an rc lookup has already been performed.
- Tim Janik <timj@gimp.org>
1998/02/27
......@@ -46,6 +46,8 @@ static void gtk_frame_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void gtk_frame_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void gtk_frame_style_set (GtkWidget *widget,
GtkStyle *previous_style);
static GtkBinClass *parent_class = NULL;
......@@ -97,6 +99,7 @@ gtk_frame_class_init (GtkFrameClass *class)
widget_class->expose_event = gtk_frame_expose;
widget_class->size_request = gtk_frame_size_request;
widget_class->size_allocate = gtk_frame_size_allocate;
widget_class->style_set = gtk_frame_style_set;
}
static void
......@@ -174,6 +177,25 @@ gtk_frame_new (const gchar *label)
return GTK_WIDGET (frame);
}
static void
gtk_frame_style_set (GtkWidget *widget,
GtkStyle *previous_style)
{
GtkFrame *frame;
frame = GTK_FRAME (widget);
if (frame->label)
{
frame->label_width = gdk_string_measure (GTK_WIDGET (frame)->style->font, frame->label) + 7;
frame->label_height = (GTK_WIDGET (frame)->style->font->ascent +
GTK_WIDGET (frame)->style->font->descent + 1);
}
if (GTK_WIDGET_CLASS (parent_class)->style_set)
GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style);
}
void
gtk_frame_set_label (GtkFrame *frame,
const gchar *label)
......
......@@ -153,7 +153,7 @@ static GScannerConfig gtk_rc_scanner_config =
TRUE /* scan_float */,
TRUE /* scan_hex */,
TRUE /* scan_hex_dollar */,
FALSE /* scan_string_sq */,
TRUE /* scan_string_sq */,
TRUE /* scan_string_dq */,
TRUE /* numbers_2_int */,
FALSE /* int_2_float */,
......@@ -266,7 +266,7 @@ gtk_rc_get_style (GtkWidget *widget)
}
}
return widget->style;
return NULL;
}
void
......
......@@ -158,6 +158,31 @@ static GSList *unattached_styles = NULL;
static GMemChunk *key_mem_chunk = NULL;
GtkStyle*
gtk_style_copy (GtkStyle *style)
{
GtkStyle *new_style;
guint i;
g_return_val_if_fail (style != NULL, NULL);
new_style = gtk_style_new ();
for (i = 0; i < 5; i++)
{
new_style->fg[i] = style->fg[i];
new_style->bg[i] = style->bg[i];
new_style->text[i] = style->text[i];
new_style->base[i] = style->base[i];
new_style->bg_pixmap[i] = style->bg_pixmap[i];
}
new_style->font = style->font;
gdk_font_ref (new_style->font);
return new_style;
}
GtkStyle*
gtk_style_new ()
......
......@@ -8,7 +8,7 @@
*
* 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
* 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
......@@ -35,6 +35,8 @@ typedef struct _GtkStyleClass GtkStyleClass;
/* fg, bg, light, dark, mid, text, base */
#define GTK_STYLE_NUM_STYLECOLORS() 7*5
#define GTK_STYLE_ATTACHED(style) (((GtkStyle*)(style))->attach_count > 0)
struct _GtkStyle
{
GdkColor fg[5];
......@@ -78,134 +80,135 @@ struct _GtkStyleClass
void (*draw_hline) (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
gint x1,
gint x2,
gint y);
gint x1,
gint x2,
gint y);
void (*draw_vline) (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
gint y1,
gint y2,
gint x);
gint y1,
gint y2,
gint x);
void (*draw_shadow) (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GtkShadowType shadow_type,
gint x,
gint y,
gint width,
gint height);
gint x,
gint y,
gint width,
gint height);
void (*draw_polygon) (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GtkShadowType shadow_type,
GdkPoint *point,
gint npoints,
gint fill);
gint npoints,
gint fill);
void (*draw_arrow) (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GtkShadowType shadow_type,
GtkArrowType arrow_type,
gint fill,
gint x,
gint y,
gint width,
gint height);
gint fill,
gint x,
gint y,
gint width,
gint height);
void (*draw_diamond) (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GtkShadowType shadow_type,
gint x,
gint y,
gint width,
gint height);
gint x,
gint y,
gint width,
gint height);
void (*draw_oval) (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GtkShadowType shadow_type,
gint x,
gint y,
gint width,
gint height);
gint x,
gint y,
gint width,
gint height);
void (*draw_string) (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
gint x,
gint y,
gint x,
gint y,
const gchar *string);
};
GtkStyle* gtk_style_new (void);
GtkStyle* gtk_style_attach (GtkStyle *style,
GdkWindow *window);
void gtk_style_detach (GtkStyle *style);
GtkStyle *gtk_style_ref (GtkStyle *style);
void gtk_style_unref (GtkStyle *style);
void gtk_style_set_background (GtkStyle *style,
GdkWindow *window,
GtkStyle* gtk_style_new (void);
GtkStyle* gtk_style_copy (GtkStyle *style);
GtkStyle* gtk_style_attach (GtkStyle *style,
GdkWindow *window);
void gtk_style_detach (GtkStyle *style);
GtkStyle* gtk_style_ref (GtkStyle *style);
void gtk_style_unref (GtkStyle *style);
void gtk_style_set_background (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type);
void gtk_draw_hline (GtkStyle *style,
void gtk_draw_hline (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
gint x1,
gint x2,
gint y);
void gtk_draw_vline (GtkStyle *style,
gint x1,
gint x2,
gint y);
void gtk_draw_vline (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
gint y1,
gint y2,
gint x);
void gtk_draw_shadow (GtkStyle *style,
gint y1,
gint y2,
gint x);
void gtk_draw_shadow (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GtkShadowType shadow_type,
gint x,
gint y,
gint width,
gint height);
void gtk_draw_polygon (GtkStyle *style,
gint x,
gint y,
gint width,
gint height);
void gtk_draw_polygon (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GtkShadowType shadow_type,
GdkPoint *points,
gint npoints,
gint fill);
void gtk_draw_arrow (GtkStyle *style,
GdkPoint *points,
gint npoints,
gint fill);
void gtk_draw_arrow (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GtkShadowType shadow_type,
GtkArrowType arrow_type,
gint fill,
gint x,
gint y,
gint width,
gint height);
void gtk_draw_diamond (GtkStyle *style,
gint fill,
gint x,
gint y,
gint width,
gint height);
void gtk_draw_diamond (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GtkShadowType shadow_type,
gint x,
gint y,
gint width,
gint height);
void gtk_draw_oval (GtkStyle *style,
gint x,
gint y,
gint width,
gint height);
void gtk_draw_oval (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GtkShadowType shadow_type,
gint x,
gint y,
gint width,
gint height);
void gtk_draw_string (GtkStyle *style,
gint x,
gint y,
gint width,
gint height);
void gtk_draw_string (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
gint x,
gint y,
gint x,
gint y,
const gchar *string);
......
......@@ -67,6 +67,8 @@
#define LAST_INDEX(t, m) ((m).index == TEXT_LENGTH(t))
#define CACHE_DATA(c) (*(LineParams*)(c)->data)
#define GTK_TEXT_INDEX(t, index) ((index) < (t)->gap_position ? (t)->text[index] : \
(t)->text[(index) + (t)->gap_size])
typedef struct _TextFont TextFont;
typedef struct _TextProperty TextProperty;
......
......@@ -82,7 +82,6 @@ static void gtk_tips_query_widget_entered (GtkTipsQuery *tips_query,
/* --- variables --- */
static GtkLabelClass *parent_class = NULL;
static gint tips_query_signals[SIGNAL_LAST] = { 0 };
static const gchar *key_event_mask = "gtk-tips-query-saved-event-mask";
/* --- functions --- */
......@@ -215,7 +214,7 @@ gtk_tips_query_init (GtkTipsQuery *tips_query)
tips_query->label_no_tip = g_strdup ("--- No Tip ---");
tips_query->caller = NULL;
tips_query->last_crossed = NULL;
tips_query->event_restore_list = NULL;
tips_query->query_cursor = NULL;
gtk_label_set (GTK_LABEL (tips_query), tips_query->label_inactive);
}
......@@ -344,6 +343,7 @@ gtk_tips_query_start_query (GtkTipsQuery *tips_query)
g_return_if_fail (tips_query != NULL);
g_return_if_fail (GTK_IS_TIPS_QUERY (tips_query));
g_return_if_fail (tips_query->in_query == FALSE);
g_return_if_fail (GTK_WIDGET_REALIZED (tips_query));
tips_query->in_query = TRUE;
gtk_signal_emit (GTK_OBJECT (tips_query), tips_query_signals[SIGNAL_START_QUERY]);
......@@ -360,51 +360,49 @@ gtk_tips_query_stop_query (GtkTipsQuery *tips_query)
tips_query->in_query = FALSE;
}
void
static void
gtk_tips_query_real_start_query (GtkTipsQuery *tips_query)
{
gint failure;
g_return_if_fail (tips_query != NULL);
g_return_if_fail (GTK_IS_TIPS_QUERY (tips_query));
tips_query->query_cursor = gdk_cursor_new (GDK_QUESTION_ARROW);
failure = gdk_pointer_grab (GTK_WIDGET (tips_query)->window,
TRUE,
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK,
NULL,
tips_query->query_cursor,
GDK_CURRENT_TIME);
if (failure)
{
gdk_cursor_destroy (tips_query->query_cursor);
tips_query->query_cursor = NULL;
}
gtk_grab_add (GTK_WIDGET (tips_query));
}
void
static void
gtk_tips_query_real_stop_query (GtkTipsQuery *tips_query)
{
GSList *list;
g_return_if_fail (tips_query != NULL);
g_return_if_fail (GTK_IS_TIPS_QUERY (tips_query));
gtk_grab_remove (GTK_WIDGET (tips_query));
if (tips_query->query_cursor)
{
gdk_pointer_ungrab (GDK_CURRENT_TIME);
gdk_cursor_destroy (tips_query->query_cursor);
tips_query->query_cursor = NULL;
}
if (tips_query->last_crossed)
{
gtk_widget_unref (tips_query->last_crossed);
tips_query->last_crossed = NULL;
}
list = tips_query->event_restore_list;
while (list)
{
GtkWidget *win_widget;
GdkEventMask *event_mask;
win_widget = list->data;
event_mask = gtk_object_get_data (GTK_OBJECT (win_widget), key_event_mask);
if (event_mask)
{
gtk_object_remove_data (GTK_OBJECT (win_widget), key_event_mask);
if (GTK_WIDGET_REALIZED (win_widget))
gdk_window_set_events (win_widget->window, *event_mask);
g_free (event_mask);
}
gtk_widget_unref (win_widget);
list = list->next;
}
g_slist_free (tips_query->event_restore_list);
tips_query->event_restore_list = NULL;
gtk_label_set (GTK_LABEL (tips_query), tips_query->label_inactive);
}
......@@ -488,7 +486,6 @@ gtk_tips_query_event (GtkWidget *widget,
event_handled = FALSE;
switch (event->type)
{
GdkEventMask *event_mask;
GdkWindow *pointer_window;
case GDK_LEAVE_NOTIFY:
......@@ -499,27 +496,11 @@ gtk_tips_query_event (GtkWidget *widget,
event_widget = NULL;
if (pointer_window)
gdk_window_get_user_data (pointer_window, (gpointer*) &event_widget);
/* fall through */
gtk_tips_query_emit_widget_entered (tips_query, event_widget);
event_handled = TRUE;
break;
case GDK_ENTER_NOTIFY:
if (event_widget)
{
event_mask = gtk_object_get_data (GTK_OBJECT (event_widget), key_event_mask);
if (!event_mask)
{
event_mask = g_new (GdkEventMask, 1);
*event_mask = gdk_window_get_events (event_widget->window);
gtk_object_set_data (GTK_OBJECT (event_widget), key_event_mask, event_mask);
gdk_window_set_events (event_widget->window,
*event_mask |
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK);
tips_query->event_restore_list =
g_slist_prepend (tips_query->event_restore_list, event_widget);
gtk_widget_ref (event_widget);
}
}
gtk_tips_query_emit_widget_entered (tips_query, event_widget);
event_handled = TRUE;
break;
......
......@@ -54,7 +54,8 @@ struct _GtkTipsQuery