Commit 4632fb81 authored by Alexander Larsson's avatar Alexander Larsson Committed by Owen Taylor

Integrate Erwann Chenede's multihead changes for the gtk/ directory.

Mon Apr 29 18:28:00 2002  Owen Taylor  <otaylor@redhat.com>

	Integrate Erwann Chenede's multihead changes for the gtk/ directory.

	* gtk/gtkclipboard.[ch]: Add gtk_clipboard_get_for_display(),
	make internals multihead aware.

	* gtk/gtkcolorsel.[ch]: Add
	gtk_color_selection_set_change_palette_with_screen_hook () [ugh!]
	make up for non-multihead safety of
	gtk_color_selection_set_change_palette_hook()

	* gtk/gtkinvisible.[ch] gtk/gtkmenu.[ch] gtkwindow.[ch]: Add
	gtk_{invisible,menu,window}_set_screen(); add "screen" properties
	for GtkWindow and GtkMenu.

	* gtk/gtkplug.[ch]: Add gtk_plug_construct_for_display(),
	gtk_plug_new_for_display(). Multihead fixes.

	* gtk/gtkselection.[ch]: Add gtk_selection_owner_set_for_display(),
	make internals multihead aware.

	* gtk/gtksettings.[ch]: Add gtk_settings_get_for_screen(), get
	rid of now-useless gtk_settings_constructor().

	* gtk/gtkstyle.[ch]: Add gtk_style_get_font_for_display(), fix
	check/radio button indicators bitmap handling to be multihead
	safe.

	* gtk/gtkwidget.[ch]: Add gtk_widget_get_screen(), gtk_widget_has_screen(),
	gtk_widget_get_display(), gtk_widget_get_clipboard(),
	gtk_widget_get_root_window().

	* gtk/gtkbindings.c gtk/gtkbutton.c gtk/gtkclist.c gtk/gtkcombo.c
	gtk/gtkctree.c gtk/gtkdnd.c gtk/gtkfilesel.c gtk/gtkgamma.c
	gtk/gtkhandlebox.c gtk/gtkhsv.c gtk/gtkimcontext.c gtk/gtklabel.c
	gtk/gtklist.c gtk/gtkmain.c gtk/gtkmenuitem.c gtk/gtkmenushell.c
	gtk/gtknotebook.c gtk/gtkoldeditable.c gtk/gtkoptionmenu.c
	gtk/gtkpaned.c gtk/gtkpreview.c gtk/gtksocket.c gtk/gtktext.c
	gtk/gtktextbuffer.c gtk/gtktextview.c gtk/gtktipsquery.c
	gtk/gtktooltips.c gtk/gtktreeview.c gtk/gtktreeviewcolumn.c:
	misc mechanical multihead-safety fixes.

	* gtk/gtkclipboard.c: Use a GtkImage rather than a pixmap for
	the dropper, look up the color palette only at realization time,
	other multihead fixes.

	* gtk/gtkcombo.c (gtk_combo_unrealize): Popdown the list when
	unrealizing.

	* gtk/gtkentry.c: Only claim ownership of the primary selection
	when realized, misc multihead fixes.

	* gtk/gtkfontsel.c: Only fill in fonts when attached to a screen,
	fix gtk_font_selection_get_font() for multihead.

	* gtk/gtkgc.c: make the depth => drawable hash per-screen.

	* gtk/gtkinvisible.c: Add a constructor that realizes the
	widget, so we get a realized widget with g_object_new() as
	well gtk_invisible_new() as before.

	* gtk/gtkmain.c: Get rid of unused gtk_visual/gtk_colormap
	variables.

	* gtk/gtktextdisplay.c: Add warnings if stipple bitmaps
	are used on the wrong screen.

	* gtk/gtktoolbar.c: Make handling of GtkSettings-based layout
	read properties and connect to settings when the screen is changed,
	rather than on init/finalize.

	* gtk/gtkwindow.c: Fix icon handing to be multihead safe ...
	default icon pixmaps/mask are only shared between windows on the
	same screen. Misc multihead fixes.

Sat Apr 27 13:49:53 2002  Owen Taylor  <otaylor@redhat.com>

	* gtk/gtkclipboard.c (gtk_clipboard_get_for_display):
	Update docs to reference GDK_SELECTION_CLIPBOARD rather GDK_NONE.

2002-04-29  Alex Larsson  <alexl@redhat.com>

	* gdk/linux-fb/gdkproperty-fb.c (gdk_property_get):
	Fix silly bug, noticed by Sven Neumann.

Sun Apr 28 22:43:55 2002  Jonathan Blandford  <jrb@gnome.org>

	* gtk/gtktreemodelsort.c (gtk_tree_model_sort_set_sort_func): Fix
	so that you can set a new sort func.
parent bc25b9b2
......@@ -27,9 +27,8 @@ The #GtkInvisible-struct struct contains no public fields.
<!-- ##### FUNCTION gtk_invisible_new ##### -->
<para>
Creates a new #GtkInvisible.
</para>
@Returns: a new #GtkInvisible.
@Returns:
......@@ -36,20 +36,14 @@ inside the first applications window.
<!-- ##### FUNCTION gtk_plug_construct ##### -->
<para>
Finishes the creation of a #GtkPlug widget. This function
will generally only be used by classes deriving
from #GtkPlug.
</para>
@plug: a #GtkPlug widget.
@socket_id: the window ID of the socket.
@plug:
@socket_id:
<!-- ##### FUNCTION gtk_plug_new ##### -->
<para>
Creates a new plug widget inside the #GtkSocket identified
by @socket_id. If @socket_id is 0, the plug is left "unplugged" and
can later be plugged into a #GtkSocket by gtk_socket_add_id().
</para>
@socket_id: the window ID of the socket, or 0.
......
......@@ -1076,6 +1076,7 @@ gtk_bindings_activate (GtkObject *object,
GdkModifierType modifiers)
{
GSList *entries = NULL;
GdkDisplay *display;
GtkKeyHash *key_hash;
gboolean handled = FALSE;
gboolean is_release;
......@@ -1088,7 +1089,9 @@ gtk_bindings_activate (GtkObject *object,
is_release = (modifiers & GDK_RELEASE_MASK) != 0;
modifiers = modifiers & BINDING_MOD_MASK () & ~GDK_RELEASE_MASK;
key_hash = binding_key_hash_for_keymap (gdk_keymap_get_default ());
display = gtk_widget_get_display (GTK_WIDGET (object));
key_hash = binding_key_hash_for_keymap (gdk_keymap_get_for_display (display));
entries = _gtk_key_hash_lookup_keyval (key_hash, keyval, modifiers);
handled = gtk_bindings_activate_list (object, entries, is_release);
......@@ -1113,6 +1116,7 @@ _gtk_bindings_activate_event (GtkObject *object,
GdkEventKey *event)
{
GSList *entries = NULL;
GdkDisplay *display;
GtkKeyHash *key_hash;
gboolean handled = FALSE;
......@@ -1121,7 +1125,9 @@ _gtk_bindings_activate_event (GtkObject *object,
if (!GTK_IS_WIDGET (object))
return FALSE;
key_hash = binding_key_hash_for_keymap (gdk_keymap_get_default ());
display = gtk_widget_get_display (GTK_WIDGET (object));
key_hash = binding_key_hash_for_keymap (gdk_keymap_get_for_display (display));
entries = _gtk_key_hash_lookup (key_hash,
event->hardware_keycode,
event->state & BINDING_MOD_MASK () & ~GDK_RELEASE_MASK,
......
......@@ -1084,7 +1084,8 @@ gtk_button_finish_activate (GtkButton *button,
g_source_remove (button->activate_timeout);
button->activate_timeout = 0;
gdk_keyboard_ungrab (gtk_get_current_event_time ());
gdk_display_keyboard_ungrab (gtk_widget_get_display (widget),
gtk_get_current_event_time ());
gtk_grab_remove (widget);
button->button_down = FALSE;
......
......@@ -49,6 +49,7 @@ struct _GtkClipboard
guint32 timestamp;
gboolean have_selection;
GdkDisplay *display;
};
struct _RequestContentsInfo
......@@ -68,9 +69,6 @@ static void selection_received (GtkWidget *widget,
GtkSelectionData *selection_data,
guint time);
static GSList *clipboards;
static GtkWidget *clipboard_widget;
enum {
TARGET_STRING,
TARGET_TEXT,
......@@ -84,15 +82,17 @@ static GQuark request_contents_key_id = 0;
static const gchar *clipboards_owned_key = "gtk-clipboards-owned";
static GQuark clipboards_owned_key_id = 0;
/**
* gtk_clipboard_get:
* gtk_clipboard_get_for_display:
* @display: the display for which the clipboard is to be retrieved or created
* @selection: a #GdkAtom which identifies the clipboard
* to use.
*
* Returns the clipboard object for the given selection.
* Cut/copy/paste menu items and keyboard shortcuts should use
* the default clipboard, returned by passing #GDK_NONE for @selection.
* the default clipboard, returned by passing %GDK_SELECTION_CLIPBOARD for @selection.
* (%GDK_NONE is supported as a synonym for GDK_SELECTION_CLIPBOARD
* for backwards compatibility reasons.)
* The currently-selected object or text should be provided on the clipboard
* identified by #GDK_SELECTION_PRIMARY. Cut/copy/paste menu items
* conceptually copy the contents of the #GDK_SELECTION_PRIMARY clipboard
......@@ -121,13 +121,18 @@ static GQuark clipboards_owned_key_id = 0;
* cannot be freed.
**/
GtkClipboard *
gtk_clipboard_get (GdkAtom selection)
gtk_clipboard_get_for_display (GdkDisplay *display, GdkAtom selection)
{
GtkClipboard *clipboard = NULL;
GSList *clipboards;
GSList *tmp_list;
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
if (selection == GDK_NONE)
selection = gdk_atom_intern ("CLIPBOARD", FALSE);
selection = GDK_SELECTION_CLIPBOARD;
clipboards = g_object_get_data (G_OBJECT (display), "gtk-clipboard-list");
tmp_list = clipboards;
while (tmp_list)
......@@ -143,19 +148,41 @@ gtk_clipboard_get (GdkAtom selection)
{
clipboard = g_new0 (GtkClipboard, 1);
clipboard->selection = selection;
clipboard->display = display;
clipboards = g_slist_prepend (clipboards, clipboard);
g_object_set_data (G_OBJECT (display), "gtk-clipboard-list", clipboards);
}
return clipboard;
}
/**
* gtk_clipboard_get():
* @selection: a #GdkAtom which identifies the clipboard
* to use.
*
* Returns the clipboard object for the given selection.
* See gtk_clipboard_get_for_display() for complete details.
*
* Return value: the appropriate clipboard object. If no
* clipboard already exists, a new one will
* be created. Once a clipboard object has
* been created, it is persistent for all time and
* cannot be freed.
**/
GtkClipboard *
gtk_clipboard_get (GdkAtom selection)
{
return gtk_clipboard_get_for_display (gdk_get_default_display (), selection);
}
static void
selection_get_cb (GtkWidget *widget,
GtkSelectionData *selection_data,
guint time,
guint info)
{
GtkClipboard *clipboard = gtk_clipboard_get (selection_data->selection);
GtkClipboard *clipboard = gtk_widget_get_clipboard (widget, selection_data->selection);
if (clipboard && clipboard->get_func)
clipboard->get_func (clipboard, selection_data, info, clipboard->user_data);
......@@ -165,7 +192,7 @@ static gboolean
selection_clear_event_cb (GtkWidget *widget,
GdkEventSelection *event)
{
GtkClipboard *clipboard = gtk_clipboard_get (event->selection);
GtkClipboard *clipboard = gtk_widget_get_clipboard (widget, event->selection);
if (clipboard)
{
......@@ -177,9 +204,10 @@ selection_clear_event_cb (GtkWidget *widget,
}
static GtkWidget *
make_clipboard_widget (gboolean provider)
make_clipboard_widget (GdkDisplay *display,
gboolean provider)
{
GtkWidget *widget = gtk_invisible_new ();
GtkWidget *widget = gtk_invisible_new_for_screen (gdk_display_get_default_screen (display));
gtk_signal_connect (GTK_OBJECT (widget), "selection_received",
GTK_SIGNAL_FUNC (selection_received), NULL);
......@@ -198,12 +226,17 @@ make_clipboard_widget (gboolean provider)
return widget;
}
static void
ensure_clipboard_widget ()
static GtkWidget *
get_clipboard_widget (GdkDisplay *display)
{
if (!clipboard_widget)
clipboard_widget = make_clipboard_widget (TRUE);
GtkWidget *clip_widget = g_object_get_data (G_OBJECT (display), "gtk-clipboard-widget");
if (!clip_widget)
{
clip_widget = make_clipboard_widget (display, TRUE);
g_object_set_data (G_OBJECT (display), "gtk-clipboard-widget", clip_widget);
}
return clip_widget;
}
/* This function makes a very good guess at what the correct
......@@ -224,10 +257,9 @@ ensure_clipboard_widget ()
static guint32
clipboard_get_timestamp (GtkClipboard *clipboard)
{
GtkWidget *clipboard_widget = get_clipboard_widget (clipboard->display);
guint32 timestamp = gtk_get_current_event_time ();
ensure_clipboard_widget ();
if (timestamp == GDK_CURRENT_TIME)
{
#ifdef GDK_WINDOWING_X11
......@@ -321,10 +353,12 @@ gtk_clipboard_set_contents (GtkClipboard *clipboard,
gpointer user_data,
gboolean have_owner)
{
ensure_clipboard_widget ();
GtkWidget *clipboard_widget = get_clipboard_widget (clipboard->display);
if (gtk_selection_owner_set (clipboard_widget, clipboard->selection,
clipboard_get_timestamp (clipboard)))
if (gtk_selection_owner_set_for_display (clipboard->display,
clipboard_widget,
clipboard->selection,
clipboard_get_timestamp (clipboard)))
{
clipboard->have_selection = TRUE;
......@@ -509,8 +543,10 @@ gtk_clipboard_clear (GtkClipboard *clipboard)
g_return_if_fail (clipboard != NULL);
if (clipboard->have_selection)
gtk_selection_owner_set (NULL, clipboard->selection,
clipboard_get_timestamp (clipboard));
gtk_selection_owner_set_for_display (clipboard->display,
NULL,
clipboard->selection,
clipboard_get_timestamp (clipboard));
}
static void
......@@ -595,13 +631,13 @@ selection_received (GtkWidget *widget,
RequestContentsInfo *request_info = get_request_contents_info (widget);
set_request_contents_info (widget, NULL);
request_info->callback (gtk_clipboard_get (selection_data->selection),
request_info->callback (gtk_widget_get_clipboard (widget, selection_data->selection),
selection_data,
request_info->user_data);
g_free (request_info);
if (widget != clipboard_widget)
if (widget != get_clipboard_widget (gtk_widget_get_display (widget)))
gtk_widget_destroy (widget);
}
......@@ -628,15 +664,16 @@ gtk_clipboard_request_contents (GtkClipboard *clipboard,
{
RequestContentsInfo *info;
GtkWidget *widget;
GtkWidget *clipboard_widget;
g_return_if_fail (clipboard != NULL);
g_return_if_fail (target != GDK_NONE);
g_return_if_fail (callback != NULL);
ensure_clipboard_widget ();
clipboard_widget = get_clipboard_widget (clipboard->display);
if (get_request_contents_info (clipboard_widget))
widget = make_clipboard_widget (FALSE);
widget = make_clipboard_widget (clipboard->display, FALSE);
else
widget = clipboard_widget;
......@@ -840,6 +877,21 @@ gtk_clipboard_wait_for_text (GtkClipboard *clipboard)
return results.data;
}
/**
* gtk_clipboard_get_display:
* @clipboard: a #GtkClipboard
*
* Gets the #GdkDisplay associated with @clipboard
*
* Return value: the #GdkDisplay associated with @clipboard
**/
GdkDisplay *
gtk_clipboard_get_display (GtkClipboard *clipboard)
{
g_return_val_if_fail (clipboard != NULL, NULL);
return clipboard->display;
}
/**
* gtk_clipboard_wait_is_text_available:
......
......@@ -28,7 +28,6 @@ extern "C" {
#include <gtk/gtkselection.h>
typedef struct _GtkClipboard GtkClipboard;
typedef void (* GtkClipboardReceivedFunc) (GtkClipboard *clipboard,
GtkSelectionData *selection_data,
......@@ -47,8 +46,15 @@ typedef void (* GtkClipboardGetFunc) (GtkClipboard *clipboard,
gpointer user_data_or_owner);
typedef void (* GtkClipboardClearFunc) (GtkClipboard *clipboard,
gpointer user_data_or_owner);
GtkClipboard *gtk_clipboard_get (GdkAtom selection);
GtkClipboard *gtk_clipboard_get_for_display (GdkDisplay *display,
GdkAtom selection);
#ifndef GDK_MULTIHEAD_SAFE
GtkClipboard *gtk_clipboard_get (GdkAtom selection);
#endif
GdkDisplay *gtk_clipboard_get_display (GtkClipboard *clipboard);
gboolean gtk_clipboard_set_with_data (GtkClipboard *clipboard,
const GtkTargetEntry *targets,
......
......@@ -1928,7 +1928,8 @@ abort_column_resize (GtkCList *clist)
GTK_CLIST_UNSET_FLAG (clist, CLIST_IN_DRAG);
gtk_grab_remove (GTK_WIDGET (clist));
gdk_pointer_ungrab (GDK_CURRENT_TIME);
gdk_display_pointer_ungrab (gtk_widget_get_display (GTK_WIDGET (clist)),
GDK_CURRENT_TIME);
clist->drag_pos = -1;
if (clist->x_drag >= 0 && clist->x_drag <= clist->clist_window_width - 1)
......@@ -3626,13 +3627,20 @@ fake_toggle_row (GtkCList *clist,
GTK_CLIST_ROW (work));
}
static gboolean
clist_has_grab (GtkCList *clist)
{
return (GTK_WIDGET_HAS_GRAB (clist) &&
gdk_display_pointer_is_grabbed (gtk_widget_get_display (GTK_WIDGET (clist))));
}
static void
toggle_focus_row (GtkCList *clist)
{
g_return_if_fail (clist != 0);
g_return_if_fail (GTK_IS_CLIST (clist));
if ((gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (clist)) ||
if (clist_has_grab (clist) ||
clist->focus_row < 0 || clist->focus_row >= clist->rows)
return;
......@@ -3669,7 +3677,7 @@ toggle_add_mode (GtkCList *clist)
g_return_if_fail (clist != 0);
g_return_if_fail (GTK_IS_CLIST (clist));
if ((gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (clist)) ||
if (clist_has_grab (clist) ||
clist->selection_mode != GTK_SELECTION_MULTIPLE)
return;
......@@ -3791,7 +3799,7 @@ real_select_all (GtkCList *clist)
{
g_return_if_fail (GTK_IS_CLIST (clist));
if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (clist))
if (clist_has_grab (clist))
return;
switch (clist->selection_mode)
......@@ -3831,7 +3839,7 @@ real_unselect_all (GtkCList *clist)
g_return_if_fail (GTK_IS_CLIST (clist));
if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (clist))
if (clist_has_grab (clist))
return;
switch (clist->selection_mode)
......@@ -3916,7 +3924,7 @@ real_undo_selection (GtkCList *clist)
g_return_if_fail (GTK_IS_CLIST (clist));
if ((gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (clist)) ||
if (clist_has_grab (clist) ||
clist->selection_mode != GTK_SELECTION_MULTIPLE)
return;
......@@ -4268,7 +4276,7 @@ start_selection (GtkCList *clist)
{
g_return_if_fail (GTK_IS_CLIST (clist));
if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (clist))
if (clist_has_grab (clist))
return;
set_anchor (clist, GTK_CLIST_ADD_MODE(clist), clist->focus_row,
......@@ -4280,7 +4288,8 @@ end_selection (GtkCList *clist)
{
g_return_if_fail (GTK_IS_CLIST (clist));
if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_FOCUS(clist))
if (gdk_display_pointer_is_grabbed (gtk_widget_get_display (GTK_WIDGET (clist))) &&
GTK_WIDGET_HAS_FOCUS (clist))
return;
GTK_CLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
......@@ -4294,7 +4303,7 @@ extend_selection (GtkCList *clist,
{
g_return_if_fail (GTK_IS_CLIST (clist));
if ((gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (clist)) ||
if (clist_has_grab (clist) ||
clist->selection_mode != GTK_SELECTION_MULTIPLE)
return;
......@@ -4536,7 +4545,8 @@ gtk_clist_realize (GtkWidget *widget)
GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK);
attributes_mask = GDK_WA_CURSOR;
attributes.cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW);
attributes.cursor = gdk_cursor_new_for_screen (gtk_widget_get_screen (widget),
GDK_SB_H_DOUBLE_ARROW);
clist->cursor_drag = attributes.cursor;
attributes.x = LIST_WIDTH (clist) + 1;
......@@ -4728,7 +4738,7 @@ gtk_clist_unmap (GtkWidget *widget)
{
GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (clist))
if (clist_has_grab (clist))
{
remove_grab (clist);
......@@ -5116,7 +5126,7 @@ gtk_clist_button_release (GtkWidget *widget,
GTK_CLIST_UNSET_FLAG (clist, CLIST_IN_DRAG);
gtk_widget_get_pointer (widget, &x, NULL);
gtk_grab_remove (widget);
gdk_pointer_ungrab (event->time);
gdk_display_pointer_ungrab (gtk_widget_get_display (widget), event->time);
if (clist->x_drag >= 0)
draw_xor_line (clist);
......@@ -5191,7 +5201,7 @@ gtk_clist_motion (GtkWidget *widget,
g_return_val_if_fail (GTK_IS_CLIST (widget), FALSE);
clist = GTK_CLIST (widget);
if (!(gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (clist)))
if (!clist_has_grab (clist))
return FALSE;
if (clist->drag_button > 0)
......@@ -6837,7 +6847,7 @@ scroll_horizontal (GtkCList *clist,
g_return_if_fail (clist != 0);
g_return_if_fail (GTK_IS_CLIST (clist));
if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (clist))
if (clist_has_grab (clist))
return;
for (last_column = clist->columns - 1;
......@@ -6911,7 +6921,7 @@ scroll_vertical (GtkCList *clist,
g_return_if_fail (GTK_IS_CLIST (clist));
if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (clist))
if (clist_has_grab (clist))
return;
switch (clist->selection_mode)
......@@ -7082,11 +7092,15 @@ vertical_timeout (GtkCList *clist)
static void
remove_grab (GtkCList *clist)
{
GtkWidget *widget = GTK_WIDGET (clist);
if (GTK_WIDGET_HAS_GRAB (clist))
{
gtk_grab_remove (GTK_WIDGET (clist));
if (gdk_pointer_is_grabbed ())
gdk_pointer_ungrab (GDK_CURRENT_TIME);
GdkDisplay *display = gtk_widget_get_display (widget);
gtk_grab_remove (widget);
if (gdk_display_pointer_is_grabbed (display))
gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
}
if (clist->htimer)
......@@ -7224,7 +7238,7 @@ real_sort_list (GtkCList *clist)
if (clist->rows <= 1)
return;
if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (clist))
if (clist_has_grab (clist))
return;
gtk_clist_freeze (clist);
......@@ -7803,7 +7817,8 @@ gtk_clist_set_button_actions (GtkCList *clist,
if (button < MAX_BUTTON)
{
if (gdk_pointer_is_grabbed () || GTK_WIDGET_HAS_GRAB (clist))
if (gdk_display_pointer_is_grabbed (gtk_widget_get_display (GTK_WIDGET (clist))) ||
GTK_WIDGET_HAS_GRAB (clist))
{
remove_grab (clist);
clist->drag_button = 0;
......
......@@ -56,6 +56,7 @@
#include "gtkmain.h"
#include "gtksettings.h"
#include "gtkintl.h"
#include "gtkimage.h"
#include <string.h>
......@@ -143,8 +144,6 @@ struct _ColorSelectionPrivate
static void gtk_color_selection_init (GtkColorSelection *colorsel);
static void gtk_color_selection_class_init (GtkColorSelectionClass *klass);
static void gtk_color_selection_destroy (GtkObject *object);
static void gtk_color_selection_finalize (GObject *object);
static void gtk_color_selection_realize (GtkWidget *widget);
static void update_color (GtkColorSelection *colorsel);
static void gtk_color_selection_set_property (GObject *object,
guint prop_id,
......@@ -155,6 +154,9 @@ static void gtk_color_selection_get_property (GObject *object
GValue *value,
GParamSpec *pspec);
static void gtk_color_selection_realize (GtkWidget *widget);
static void gtk_color_selection_unrealize (GtkWidget *widget);
static gint gtk_color_selection_get_palette_size (GtkColorSelection *colorsel);
static gboolean gtk_color_selection_get_palette_color (GtkColorSelection *colorsel,
gint index,
......@@ -166,7 +168,10 @@ static void gtk_color_selection_unset_palette_color (GtkColorSelection *colo
gint index);
static GdkGC *get_focus_gc (GtkWidget *drawing_area,
gint *focus_width);
static void default_change_palette_func (const GdkColor *colors,
static void default_noscreen_change_palette_func (const GdkColor *colors,
gint n_colors);
static void default_change_palette_func (GdkScreen *screen,
const GdkColor *colors,
gint n_colors);
static gpointer parent_class = NULL;
......@@ -174,9 +179,8 @@ static guint color_selection_signals[LAST_SIGNAL] = { 0 };
static gchar* default_colors = "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90";
static GtkColorSelectionChangePaletteFunc change_palette_hook = default_change_palette_func;
static GdkColor current_colors[GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT];
static GtkColorSelectionChangePaletteFunc noscreen_change_palette_hook = default_noscreen_change_palette_func;
static GtkColorSelectionChangePaletteWithScreenFunc change_palette_hook = default_change_palette_func;
/* The cursor for the dropper */
#define DROPPER_WIDTH 17
......@@ -199,8 +203,6 @@ static char dropper_mask[] = {
0x7c, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x0d, 0x00, 0x00,
0x02, 0x00, 0x00, };
static GdkCursor *picker_cursor = NULL;
/* XPM */
static char *picker[] = {
......@@ -269,6 +271,8 @@ color_sample_drag_begin (GtkWidget *widget,
priv = colorsel->private_data;
window = gtk_window_new (GTK_WINDOW_POPUP);
gtk_window_set_screen (GTK_WINDOW (window),
gtk_widget_get_screen (widget));
gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
gtk_widget_set_usize (window, 48, 32);
gtk_widget_realize (window);
......@@ -694,6 +698,8 @@ palette_drag_begin (GtkWidget *widget,
priv = colorsel->private_data;
window = gtk_window_new (GTK_WINDOW_POPUP);
gtk_window_set_screen (GTK_WINDOW (window),
gtk_widget_get_screen (widget));
gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
gtk_widget_set_usize (window, 48, 32);
gtk_widget_realize (window);
......@@ -744,6 +750,46 @@ palette_drag_end (GtkWidget *widget,
gtk_object_set_data (GTK_OBJECT (widget), "gtk-color-selection-drag-window", NULL);
}
static GdkColor *
get_current_colors (GtkColorSelection *colorsel)
{
GtkSettings *settings;
GdkColor *colors = NULL;
gint n_colors = 0;
gchar *palette;
settings = gtk_widget_get_settings (GTK_WIDGET (colorsel));
g_object_get (G_OBJECT (settings),
"gtk-color-palette", &palette,
NULL);
if (!gtk_color_selection_palette_from_string (palette, &colors, &n_colors))
{
gtk_color_selection_palette_from_string (default_colors, &colors, &n_colors);
}
else
{
/* If there are less colors provided than the number of slots in the
* color selection, we fill in the rest from the defaults.
*/
if (n_colors < (GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT))
{
GdkColor *tmp_colors = colors;
gint tmp_n_colors = n_colors;
gtk_color_selection_palette_from_string (default_colors, &colors, &n_colors);
memcpy (colors, tmp_colors, sizeof (GdkColor) * tmp_n_colors);
g_free (tmp_colors);
}
}
g_assert (n_colors >= GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
g_free (palette);
return colors;
}
/* Changes the model color */
static void
palette_change_color (GtkWidget *drawing_area,
......@@ -753,6 +799,8 @@ palette_change_color (GtkWidget *drawing_area,
gint x, y;
ColorSelectionPrivate *priv;
GdkColor gdk_color;
GdkColor *current_colors;
GdkScreen *screen;
g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
g_return_if_fail (GTK_IS_DRAWING_AREA (drawing_area));
......@@ -783,10 +831,25 @@ palette_change_color (GtkWidget *drawing_area,
g_assert (x < GTK_CUSTOM_PALETTE_WIDTH || y < GTK_CUSTOM_PALETTE_HEIGHT);
current_colors = get_current_colors (colorsel);
current_colors[y * GTK_CUSTOM_PALETTE_WIDTH + x] = gdk_color;
if (change_palette_hook)
(* change_palette_hook) (current_colors, GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
screen = gtk_widget_get_screen (GTK_WIDGET (colorsel));
if (change_palette_hook != default_change_palette_func)
(* change_palette_hook) (screen, current_colors,
GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
else if (noscreen_change_palette_hook != default_noscreen_change_palette_func)
{
if (screen != gdk_get_default_screen ())
g_warning ("gtk_color_selection_set_change_palette_hook used by widget is not on the default screen.");
(* noscreen_change_palette_hook) (current_colors,
GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
}
else
(* change_palette_hook) (screen, current_colors,
GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
g_free (current_colors);
}
/* Changes the view color */
......@@ -857,6 +920,7 @@ popup_position_func (GtkMenu *menu,
GtkWidget *widget;
GtkRequisition req;
gint root_x, root_y;
GdkScreen *screen;
widget = GTK_WIDGET (user_data);
......@@ -871,8 +935,9 @@ popup_position_func (GtkMenu *menu,
*y = root_y + widget->allocation.height / 2;
/* Ensure sanity */
*x = CLAMP (*x, 0, MAX (0, gdk_screen_width () - req.width));
*y = CLAMP (*y, 0, MAX (0, gdk_screen_height () - req.height));
screen = gtk_widget_get_screen (widget);
*x = CLAMP (*x, 0, MAX (0, gdk_screen_get_width (screen) - req.width));
*y = CLAMP (*y, 0, MAX (0, gdk_screen_get_height (screen) - req.height));
}
static void
......@@ -1088,28 +1153,30 @@ palette_new (GtkColorSelection *colorsel)
*
*/
static void
initialize_cursor (void)
static GdkCursor *
make_picker_cursor (GdkScreen *screen)
{
GdkCursor *cursor;
GdkColor fg, bg;
GdkPixmap *pixmap =
gdk_bitmap_create_from_data (NULL,
dropper_bits,
DROPPER_WIDTH, DROPPER_HEIGHT);
gdk_bitmap_create_from_data (gdk_screen_get_root_window (screen),
dropper_bits, DROPPER_WIDTH, DROPPER_HEIGHT);
GdkPixmap *mask =
gdk_bitmap_create_from_data (NULL,
dropper_mask,
DROPPER_WIDTH, DROPPER_HEIGHT);
gdk_bitmap_create_from_data (gdk_screen_get_root_window (screen),
dropper_mask, DROPPER_WIDTH, DROPPER_HEIGHT);