re-adding for manual rename of repository files.

This commit is contained in:
Tor Lillqvist 1999-11-11 22:12:27 +00:00
parent 7ca8753ac5
commit 638ebcee70
34 changed files with 39496 additions and 0 deletions

323
gdk/win32/gdk-win32.def Normal file
View File

@ -0,0 +1,323 @@
EXPORTS
gdk_atom_intern
gdk_atom_name
gdk_beep
gdk_bitmap_create_from_data
gdk_bitmap_ref
gdk_bitmap_unref
gdk_char_height
gdk_char_measure
gdk_char_width
gdk_char_width_wc
gdk_color_alloc
gdk_color_black
gdk_color_change
gdk_color_copy
gdk_color_equal
gdk_color_free
gdk_color_hash
gdk_color_parse
gdk_color_white
gdk_colormap_alloc_color
gdk_colormap_alloc_colors
gdk_colormap_change
gdk_colormap_free_colors
gdk_colormap_get_system
gdk_colormap_get_system_size
gdk_colormap_get_visual
gdk_colormap_new
gdk_colormap_ref
gdk_colormap_unref
gdk_colors_alloc
gdk_colors_free
gdk_colors_store
gdk_cursor_destroy
gdk_cursor_new
gdk_cursor_new_from_pixmap
gdk_debug_flags
gdk_dnd_init
gdk_drag_abort
gdk_drag_begin
gdk_drag_context_new
gdk_drag_context_ref
gdk_drag_context_unref
gdk_drag_drop
gdk_drag_find_window
gdk_drag_get_protocol
gdk_drag_get_selection
gdk_drag_motion
gdk_drag_status
gdk_drop_finish
gdk_drop_reply
gdk_draw_arc
gdk_draw_gray_image
gdk_draw_image
gdk_draw_indexed_image
gdk_draw_line
gdk_draw_lines
gdk_draw_pixmap
gdk_draw_point
gdk_draw_points
gdk_draw_polygon
gdk_draw_rectangle
gdk_draw_rgb_32_image
gdk_draw_rgb_image
gdk_draw_rgb_image_dithalign
gdk_draw_segments
gdk_draw_string
gdk_draw_text
gdk_draw_text_wc
gdk_drawable_get_colormap
gdk_drawable_get_size
gdk_drawable_get_type
gdk_drawable_get_visual
gdk_drawable_set_colormap
gdk_drawable_set_data
gdk_error_code
gdk_error_trap_pop
gdk_error_trap_push
gdk_error_warnings
gdk_event_copy
gdk_event_free
gdk_event_get
gdk_event_get_graphics_expose
gdk_event_get_time
gdk_event_handler_set
gdk_event_peek
gdk_event_put
gdk_event_send_client_message
gdk_event_send_clientmessage_toall
gdk_events_pending
gdk_exit
gdk_flush
gdk_font_equal
gdk_font_id
gdk_font_list_free
gdk_font_list_new
gdk_font_load
gdk_font_ref
gdk_font_unref
gdk_font_xlfd_create
gdk_font_xlfd_free
gdk_fontset_load
gdk_free_compound_text
gdk_free_text_list
gdk_gc_copy
gdk_gc_destroy
gdk_gc_get_values
gdk_gc_new
gdk_gc_new_with_values
gdk_gc_ref
gdk_gc_set_background
gdk_gc_set_clip_mask
gdk_gc_set_clip_origin
gdk_gc_set_clip_rectangle
gdk_gc_set_clip_region
gdk_gc_set_dashes
gdk_gc_set_exposures
gdk_gc_set_fill
gdk_gc_set_font
gdk_gc_set_foreground
gdk_gc_set_function
gdk_gc_set_line_attributes
gdk_gc_set_stipple
gdk_gc_set_subwindow
gdk_gc_set_tile
gdk_gc_set_ts_origin
gdk_gc_unref
gdk_get_display
gdk_get_show_events
gdk_get_use_xshm
gdk_ic_destroy
gdk_ic_get_attr
gdk_ic_get_events
gdk_ic_get_style
gdk_ic_get_values
gdk_ic_new
gdk_ic_set_attr
gdk_ic_set_values
gdk_im_begin
gdk_im_decide_style
gdk_im_end
gdk_im_ready
gdk_im_set_best_style
gdk_image_bitmap_new
gdk_image_destroy
gdk_image_get
gdk_image_get_pixel
gdk_image_new
gdk_image_new_bitmap
gdk_image_put_pixel
gdk_init
gdk_init_check
gdk_input_add
gdk_input_add_full
gdk_input_exit
gdk_input_init
gdk_input_list_devices
gdk_input_motion_events
gdk_input_remove
gdk_input_set_axes
gdk_input_set_extension_events
gdk_input_set_key
gdk_input_set_mode
gdk_input_set_source
gdk_input_window_get_pointer
gdk_key_repeat_disable
gdk_key_repeat_restore
gdk_keyboard_grab
gdk_keyboard_ungrab
gdk_keyval_from_name
gdk_keyval_is_lower
gdk_keyval_is_upper
gdk_keyval_name
gdk_keyval_to_lower
gdk_keyval_to_upper
gdk_list_visuals
gdk_mbstowcs
gdk_null_window_warnings
gdk_pixmap_colormap_create_from_xpm
gdk_pixmap_colormap_create_from_xpm_d
gdk_pixmap_create_from_data
gdk_pixmap_create_from_xpm
gdk_pixmap_create_from_xpm_d
gdk_pixmap_create_on_shared_image
gdk_pixmap_foreign_new
gdk_pixmap_new
gdk_pixmap_ref
gdk_pixmap_unref
gdk_pointer_grab
gdk_pointer_is_grabbed
gdk_pointer_ungrab
gdk_progclass
gdk_property_change
gdk_property_delete
gdk_property_get
gdk_query_depths
gdk_query_visual_types
gdk_rectangle_intersect
gdk_rectangle_union
gdk_region_destroy
gdk_region_empty
gdk_region_equal
gdk_region_get_clipbox
gdk_region_new
gdk_region_offset
gdk_region_point_in
gdk_region_polygon
gdk_region_rect_in
gdk_region_shrink
gdk_region_union_with_rect
gdk_regions_intersect
gdk_regions_subtract
gdk_regions_union
gdk_regions_xor
gdk_rgb_cmap_free
gdk_rgb_cmap_new
gdk_rgb_ditherable
gdk_rgb_gc_set_background
gdk_rgb_gc_set_foreground
gdk_rgb_get_cmap
gdk_rgb_get_visual
gdk_rgb_init
gdk_rgb_set_install
gdk_rgb_set_min_colors
gdk_rgb_set_verbose
gdk_rgb_xpixel_from_rgb
gdk_root_parent
gdk_screen_height
gdk_screen_height_mm
gdk_screen_width
gdk_screen_width_mm
gdk_selection_convert
gdk_selection_owner_get
gdk_selection_owner_set
gdk_selection_property
gdk_selection_property_get
gdk_selection_send_notify
gdk_set_locale
gdk_set_show_events
gdk_set_use_xshm
gdk_string_extents
gdk_string_height
gdk_string_measure
gdk_string_to_compound_text
gdk_string_width
gdk_text_extents
gdk_text_extents_wc
gdk_text_height
gdk_text_measure
gdk_text_property_to_text_list
gdk_text_width
gdk_text_width_wc
gdk_threads_enter
gdk_threads_leave
gdk_threads_mutex
gdk_visual_get_best
gdk_visual_get_best_depth
gdk_visual_get_best_type
gdk_visual_get_best_with_both
gdk_visual_get_best_with_depth
gdk_visual_get_best_with_type
gdk_visual_get_system
gdk_visual_ref
gdk_visual_unref
gdk_wcstombs
gdk_window_add_filter
gdk_window_at_pointer
gdk_window_clear
gdk_window_clear_area
gdk_window_clear_area_e
gdk_window_destroy
gdk_window_foreign_new
gdk_window_get_deskrelative_origin
gdk_window_get_children
gdk_window_get_events
gdk_window_get_geometry
gdk_window_get_origin
gdk_window_get_parent
gdk_window_get_pointer
gdk_window_get_position
gdk_window_get_root_origin
gdk_window_get_toplevel
gdk_window_get_toplevels
gdk_window_get_user_data
gdk_window_hide
gdk_window_is_visible
gdk_window_is_viewable
gdk_window_lower
gdk_window_merge_child_shapes
gdk_window_move
gdk_window_move_resize
gdk_window_new
gdk_window_raise
gdk_window_ref
gdk_window_register_dnd
gdk_window_remove_filter
gdk_window_reparent
gdk_window_resize
gdk_window_set_back_pixmap
gdk_window_set_background
gdk_window_set_child_shapes
gdk_window_set_cursor
gdk_window_set_decorations
gdk_window_set_events
gdk_window_set_functions
gdk_window_set_geometry_hints
gdk_window_set_group
gdk_window_set_hints
gdk_window_set_icon
gdk_window_set_icon_name
gdk_window_set_override_redirect
gdk_window_set_role
gdk_window_set_static_gravities
gdk_window_set_title
gdk_window_set_transient_for
gdk_window_set_user_data
gdk_window_shape_combine_mask
gdk_window_show
gdk_window_unref
gdk_window_withdraw
gdk_xid_table_insert
gdk_xid_table_lookup
gdk_xid_table_remove

2115
gdk/win32/gdk.c Normal file

File diff suppressed because it is too large Load Diff

323
gdk/win32/gdk.def Normal file
View File

@ -0,0 +1,323 @@
EXPORTS
gdk_atom_intern
gdk_atom_name
gdk_beep
gdk_bitmap_create_from_data
gdk_bitmap_ref
gdk_bitmap_unref
gdk_char_height
gdk_char_measure
gdk_char_width
gdk_char_width_wc
gdk_color_alloc
gdk_color_black
gdk_color_change
gdk_color_copy
gdk_color_equal
gdk_color_free
gdk_color_hash
gdk_color_parse
gdk_color_white
gdk_colormap_alloc_color
gdk_colormap_alloc_colors
gdk_colormap_change
gdk_colormap_free_colors
gdk_colormap_get_system
gdk_colormap_get_system_size
gdk_colormap_get_visual
gdk_colormap_new
gdk_colormap_ref
gdk_colormap_unref
gdk_colors_alloc
gdk_colors_free
gdk_colors_store
gdk_cursor_destroy
gdk_cursor_new
gdk_cursor_new_from_pixmap
gdk_debug_flags
gdk_dnd_init
gdk_drag_abort
gdk_drag_begin
gdk_drag_context_new
gdk_drag_context_ref
gdk_drag_context_unref
gdk_drag_drop
gdk_drag_find_window
gdk_drag_get_protocol
gdk_drag_get_selection
gdk_drag_motion
gdk_drag_status
gdk_drop_finish
gdk_drop_reply
gdk_draw_arc
gdk_draw_gray_image
gdk_draw_image
gdk_draw_indexed_image
gdk_draw_line
gdk_draw_lines
gdk_draw_pixmap
gdk_draw_point
gdk_draw_points
gdk_draw_polygon
gdk_draw_rectangle
gdk_draw_rgb_32_image
gdk_draw_rgb_image
gdk_draw_rgb_image_dithalign
gdk_draw_segments
gdk_draw_string
gdk_draw_text
gdk_draw_text_wc
gdk_drawable_get_colormap
gdk_drawable_get_size
gdk_drawable_get_type
gdk_drawable_get_visual
gdk_drawable_set_colormap
gdk_drawable_set_data
gdk_error_code
gdk_error_trap_pop
gdk_error_trap_push
gdk_error_warnings
gdk_event_copy
gdk_event_free
gdk_event_get
gdk_event_get_graphics_expose
gdk_event_get_time
gdk_event_handler_set
gdk_event_peek
gdk_event_put
gdk_event_send_client_message
gdk_event_send_clientmessage_toall
gdk_events_pending
gdk_exit
gdk_flush
gdk_font_equal
gdk_font_id
gdk_font_list_free
gdk_font_list_new
gdk_font_load
gdk_font_ref
gdk_font_unref
gdk_font_xlfd_create
gdk_font_xlfd_free
gdk_fontset_load
gdk_free_compound_text
gdk_free_text_list
gdk_gc_copy
gdk_gc_destroy
gdk_gc_get_values
gdk_gc_new
gdk_gc_new_with_values
gdk_gc_ref
gdk_gc_set_background
gdk_gc_set_clip_mask
gdk_gc_set_clip_origin
gdk_gc_set_clip_rectangle
gdk_gc_set_clip_region
gdk_gc_set_dashes
gdk_gc_set_exposures
gdk_gc_set_fill
gdk_gc_set_font
gdk_gc_set_foreground
gdk_gc_set_function
gdk_gc_set_line_attributes
gdk_gc_set_stipple
gdk_gc_set_subwindow
gdk_gc_set_tile
gdk_gc_set_ts_origin
gdk_gc_unref
gdk_get_display
gdk_get_show_events
gdk_get_use_xshm
gdk_ic_destroy
gdk_ic_get_attr
gdk_ic_get_events
gdk_ic_get_style
gdk_ic_get_values
gdk_ic_new
gdk_ic_set_attr
gdk_ic_set_values
gdk_im_begin
gdk_im_decide_style
gdk_im_end
gdk_im_ready
gdk_im_set_best_style
gdk_image_bitmap_new
gdk_image_destroy
gdk_image_get
gdk_image_get_pixel
gdk_image_new
gdk_image_new_bitmap
gdk_image_put_pixel
gdk_init
gdk_init_check
gdk_input_add
gdk_input_add_full
gdk_input_exit
gdk_input_init
gdk_input_list_devices
gdk_input_motion_events
gdk_input_remove
gdk_input_set_axes
gdk_input_set_extension_events
gdk_input_set_key
gdk_input_set_mode
gdk_input_set_source
gdk_input_window_get_pointer
gdk_key_repeat_disable
gdk_key_repeat_restore
gdk_keyboard_grab
gdk_keyboard_ungrab
gdk_keyval_from_name
gdk_keyval_is_lower
gdk_keyval_is_upper
gdk_keyval_name
gdk_keyval_to_lower
gdk_keyval_to_upper
gdk_list_visuals
gdk_mbstowcs
gdk_null_window_warnings
gdk_pixmap_colormap_create_from_xpm
gdk_pixmap_colormap_create_from_xpm_d
gdk_pixmap_create_from_data
gdk_pixmap_create_from_xpm
gdk_pixmap_create_from_xpm_d
gdk_pixmap_create_on_shared_image
gdk_pixmap_foreign_new
gdk_pixmap_new
gdk_pixmap_ref
gdk_pixmap_unref
gdk_pointer_grab
gdk_pointer_is_grabbed
gdk_pointer_ungrab
gdk_progclass
gdk_property_change
gdk_property_delete
gdk_property_get
gdk_query_depths
gdk_query_visual_types
gdk_rectangle_intersect
gdk_rectangle_union
gdk_region_destroy
gdk_region_empty
gdk_region_equal
gdk_region_get_clipbox
gdk_region_new
gdk_region_offset
gdk_region_point_in
gdk_region_polygon
gdk_region_rect_in
gdk_region_shrink
gdk_region_union_with_rect
gdk_regions_intersect
gdk_regions_subtract
gdk_regions_union
gdk_regions_xor
gdk_rgb_cmap_free
gdk_rgb_cmap_new
gdk_rgb_ditherable
gdk_rgb_gc_set_background
gdk_rgb_gc_set_foreground
gdk_rgb_get_cmap
gdk_rgb_get_visual
gdk_rgb_init
gdk_rgb_set_install
gdk_rgb_set_min_colors
gdk_rgb_set_verbose
gdk_rgb_xpixel_from_rgb
gdk_root_parent
gdk_screen_height
gdk_screen_height_mm
gdk_screen_width
gdk_screen_width_mm
gdk_selection_convert
gdk_selection_owner_get
gdk_selection_owner_set
gdk_selection_property
gdk_selection_property_get
gdk_selection_send_notify
gdk_set_locale
gdk_set_show_events
gdk_set_use_xshm
gdk_string_extents
gdk_string_height
gdk_string_measure
gdk_string_to_compound_text
gdk_string_width
gdk_text_extents
gdk_text_extents_wc
gdk_text_height
gdk_text_measure
gdk_text_property_to_text_list
gdk_text_width
gdk_text_width_wc
gdk_threads_enter
gdk_threads_leave
gdk_threads_mutex
gdk_visual_get_best
gdk_visual_get_best_depth
gdk_visual_get_best_type
gdk_visual_get_best_with_both
gdk_visual_get_best_with_depth
gdk_visual_get_best_with_type
gdk_visual_get_system
gdk_visual_ref
gdk_visual_unref
gdk_wcstombs
gdk_window_add_filter
gdk_window_at_pointer
gdk_window_clear
gdk_window_clear_area
gdk_window_clear_area_e
gdk_window_destroy
gdk_window_foreign_new
gdk_window_get_deskrelative_origin
gdk_window_get_children
gdk_window_get_events
gdk_window_get_geometry
gdk_window_get_origin
gdk_window_get_parent
gdk_window_get_pointer
gdk_window_get_position
gdk_window_get_root_origin
gdk_window_get_toplevel
gdk_window_get_toplevels
gdk_window_get_user_data
gdk_window_hide
gdk_window_is_visible
gdk_window_is_viewable
gdk_window_lower
gdk_window_merge_child_shapes
gdk_window_move
gdk_window_move_resize
gdk_window_new
gdk_window_raise
gdk_window_ref
gdk_window_register_dnd
gdk_window_remove_filter
gdk_window_reparent
gdk_window_resize
gdk_window_set_back_pixmap
gdk_window_set_background
gdk_window_set_child_shapes
gdk_window_set_cursor
gdk_window_set_decorations
gdk_window_set_events
gdk_window_set_functions
gdk_window_set_geometry_hints
gdk_window_set_group
gdk_window_set_hints
gdk_window_set_icon
gdk_window_set_icon_name
gdk_window_set_override_redirect
gdk_window_set_role
gdk_window_set_static_gravities
gdk_window_set_title
gdk_window_set_transient_for
gdk_window_set_user_data
gdk_window_shape_combine_mask
gdk_window_show
gdk_window_unref
gdk_window_withdraw
gdk_xid_table_insert
gdk_xid_table_lookup
gdk_xid_table_remove

973
gdk/win32/gdkdnd-win32.c Normal file
View File

@ -0,0 +1,973 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1999 Peter Mattis, Spencer Kimball and Josh MacDonald
* Copyright (C) 1998-1999 Tor Lillqvist
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include <string.h>
/* #define OLE2_DND */
#define INITGUID
#include "gdkdnd.h"
#include "gdkproperty.h"
#include "gdkprivate.h"
#include "gdkx.h"
#ifdef OLE2_DND
#include <ole2.h>
#else
#include <objbase.h>
#endif
#ifdef _MSC_VER /* These aren't in mingw32 */
#include <shlobj.h>
#include <shlguid.h>
#endif
#ifndef _MSC_VER
static IID IID_IUnknown = {
0x00000000, 0x0000, 0x0000, { 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 } };
static IID IID_IDropSource = {
0x00000121, 0x0000, 0x0000, { 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 } };
static IID IID_IDropTarget = {
0x00000122, 0x0000, 0x0000, { 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 } };
#endif
#include <gdk/gdk.h>
typedef struct _GdkDragContextPrivate GdkDragContextPrivate;
typedef enum {
GDK_DRAG_STATUS_DRAG,
GDK_DRAG_STATUS_MOTION_WAIT,
GDK_DRAG_STATUS_ACTION_WAIT,
GDK_DRAG_STATUS_DROP
} GtkDragStatus;
typedef enum {
GDK_DRAG_SOURCE,
GDK_DRAG_TARGET
} GdkDragKind;
#ifdef OLE2_DND
#define PRINT_GUID(guid) \
g_print ("guid = %.08x-%.04x-%.04x-%.02x%.02x-%.02x%.02x%.02x%.02x%.02x%.02x", \
((gulong *) guid)[0], \
((gushort *) guid)[2], \
((gushort *) guid)[3], \
((guchar *) guid)[8], \
((guchar *) guid)[9], \
((guchar *) guid)[10], \
((guchar *) guid)[11], \
((guchar *) guid)[12], \
((guchar *) guid)[13], \
((guchar *) guid)[14], \
((guchar *) guid)[15]);
#endif /* OLE2_DND */
/* Structure that holds information about a drag in progress.
* this is used on both source and destination sides.
*/
struct _GdkDragContextPrivate {
GdkDragContext context;
guint ref_count;
guint16 last_x; /* Coordinates from last event */
guint16 last_y;
HWND dest_xid;
guint drag_status; /* Current status of drag */
};
GdkDragContext *current_dest_drag = NULL;
/* Drag Contexts */
static GList *contexts;
GdkDragContext *
gdk_drag_context_new (void)
{
GdkDragContextPrivate *result;
result = g_new0 (GdkDragContextPrivate, 1);
result->ref_count = 1;
contexts = g_list_prepend (contexts, result);
return (GdkDragContext *)result;
}
void
gdk_drag_context_ref (GdkDragContext *context)
{
g_return_if_fail (context != NULL);
((GdkDragContextPrivate *)context)->ref_count++;
}
void
gdk_drag_context_unref (GdkDragContext *context)
{
GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
g_return_if_fail (context != NULL);
private->ref_count--;
GDK_NOTE (DND, g_print ("gdk_drag_context_unref: %d%s\n",
private->ref_count,
(private->ref_count == 0 ? " freeing" : "")));
if (private->ref_count == 0)
{
g_dataset_destroy (private);
g_list_free (context->targets);
if (context->source_window)
gdk_window_unref (context->source_window);
if (context->dest_window)
gdk_window_unref (context->dest_window);
contexts = g_list_remove (contexts, private);
g_free (private);
}
}
#if 0
static GdkDragContext *
gdk_drag_context_find (gboolean is_source,
HWND source_xid,
HWND dest_xid)
{
GList *tmp_list = contexts;
GdkDragContext *context;
while (tmp_list)
{
context = (GdkDragContext *)tmp_list->data;
if ((!context->is_source == !is_source) &&
((source_xid == None) || (context->source_window &&
(GDK_WINDOW_XWINDOW (context->source_window) == source_xid))) &&
((dest_xid == None) || (context->dest_window &&
(GDK_WINDOW_XWINDOW (context->dest_window) == dest_xid))))
return context;
tmp_list = tmp_list->next;
}
return NULL;
}
#endif
typedef struct {
#ifdef OLE2_DND
IDropTarget idt;
#endif
GdkDragContext *context;
} target_drag_context;
typedef struct {
#ifdef OLE2_DND
IDropSource ids;
#endif
GdkDragContext *context;
} source_drag_context;
#ifdef OLE2_DND
static ULONG STDMETHODCALLTYPE
m_add_ref_target (IDropTarget __RPC_FAR *This)
{
target_drag_context *ctx = (target_drag_context *) This;
GdkDragContextPrivate *private = (GdkDragContextPrivate *) ctx->context;
GDK_NOTE (DND, g_print ("m_add_ref_target\n"));
gdk_drag_context_ref (ctx->context);
return private->ref_count;
}
static HRESULT STDMETHODCALLTYPE
m_query_interface_target (IDropTarget __RPC_FAR *This,
REFIID riid,
void __RPC_FAR *__RPC_FAR *ppvObject)
{
GDK_NOTE (DND, g_print ("m_query_interface_target\n"));
*ppvObject = NULL;
PRINT_GUID (riid);
if (IsEqualGUID (riid, &IID_IUnknown))
{
g_print ("...IUnknown\n");
m_add_ref_target (This);
*ppvObject = This;
return S_OK;
}
else if (IsEqualGUID (riid, &IID_IDropTarget))
{
g_print ("...IDropTarget\n");
m_add_ref_target (This);
*ppvObject = This;
return S_OK;
}
else
{
g_print ("...Huh?\n");
return E_NOINTERFACE;
}
}
static ULONG STDMETHODCALLTYPE
m_release_target (IDropTarget __RPC_FAR *This)
{
target_drag_context *ctx = (target_drag_context *) This;
GdkDragContextPrivate *private = (GdkDragContextPrivate *) ctx->context;
GDK_NOTE (DND, g_print ("m_release_target\n"));
gdk_drag_context_unref (ctx->context);
if (private->ref_count == 1)
{
gdk_drag_context_unref (ctx->context);
return 0;
}
else
return private->ref_count - 1;
}
static HRESULT STDMETHODCALLTYPE
m_drag_enter (IDropTarget __RPC_FAR *This,
IDataObject __RPC_FAR *pDataObj,
DWORD grfKeyState,
POINTL pt,
DWORD __RPC_FAR *pdwEffect)
{
GDK_NOTE (DND, g_print ("m_drag_enter\n"));
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_drag_over (IDropTarget __RPC_FAR *This,
DWORD grfKeyState,
POINTL pt,
DWORD __RPC_FAR *pdwEffect)
{
GDK_NOTE (DND, g_print ("m_drag_over\n"));
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_drag_leave (IDropTarget __RPC_FAR *This)
{
GDK_NOTE (DND, g_print ("m_drag_leave\n"));
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_drop (IDropTarget __RPC_FAR *This,
IDataObject __RPC_FAR *pDataObj,
DWORD grfKeyState,
POINTL pt,
DWORD __RPC_FAR *pdwEffect)
{
GDK_NOTE (DND, g_print ("m_drop\n"));
return E_UNEXPECTED;
}
static ULONG STDMETHODCALLTYPE
m_add_ref_source (IDropSource __RPC_FAR *This)
{
source_drag_context *ctx = (source_drag_context *) This;
GdkDragContextPrivate *private = (GdkDragContextPrivate *) ctx->context;
GDK_NOTE (DND, g_print ("m_add_ref_source\n"));
gdk_drag_context_ref (ctx->context);
return private->ref_count;
}
static HRESULT STDMETHODCALLTYPE
m_query_interface_source (IDropSource __RPC_FAR *This,
REFIID riid,
void __RPC_FAR *__RPC_FAR *ppvObject)
{
GDK_NOTE (DND, g_print ("m_query_interface_source\n"));
*ppvObject = NULL;
PRINT_GUID (riid);
if (IsEqualGUID (riid, &IID_IUnknown))
{
g_print ("...IUnknown\n");
m_add_ref_source (This);
*ppvObject = This;
return S_OK;
}
else if (IsEqualGUID (riid, &IID_IDropSource))
{
g_print ("...IDropSource\n");
m_add_ref_source (This);
*ppvObject = This;
return S_OK;
}
else
{
g_print ("...Huh?\n");
return E_NOINTERFACE;
}
}
static ULONG STDMETHODCALLTYPE
m_release_source (IDropSource __RPC_FAR *This)
{
source_drag_context *ctx = (source_drag_context *) This;
GdkDragContextPrivate *private = (GdkDragContextPrivate *) ctx->context;
GDK_NOTE (DND, g_print ("m_release_source\n"));
gdk_drag_context_unref (ctx->context);
if (private->ref_count == 1)
{
gdk_drag_context_unref (ctx->context);
return 0;
}
else
return private->ref_count - 1;
}
static HRESULT STDMETHODCALLTYPE
m_query_continue_drag (IDropSource __RPC_FAR *This,
BOOL fEscapePressed,
DWORD grfKeyState)
{
GDK_NOTE (DND, g_print ("m_query_continue_drag\n"));
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_give_feedback (IDropSource __RPC_FAR *This,
DWORD dwEffect)
{
GDK_NOTE (DND, g_print ("m_give_feedback\n"));
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_query_interface_object (IDataObject __RPC_FAR *This,
REFIID riid,
void __RPC_FAR *__RPC_FAR *ppvObject)
{
return E_UNEXPECTED;
}
static ULONG STDMETHODCALLTYPE
m_add_ref_object (IDataObject __RPC_FAR *This)
{
return E_UNEXPECTED;
}
static ULONG STDMETHODCALLTYPE
m_release_object (IDataObject __RPC_FAR *This)
{
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_get_data (IDataObject __RPC_FAR *This,
FORMATETC *pFormatEtc,
STGMEDIUM *pMedium)
{
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_get_data_here (IDataObject __RPC_FAR *This,
FORMATETC *pFormatEtc,
STGMEDIUM *pMedium)
{
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_query_get_data (IDataObject __RPC_FAR *This,
FORMATETC *pFormatEtc)
{
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_get_canonical_format_etc (IDataObject __RPC_FAR *This,
FORMATETC *pFormatEtcIn,
FORMATETC *pFormatEtcOut)
{
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_set_data (IDataObject __RPC_FAR *This,
FORMATETC *pFormatEtc,
STGMEDIUM *pMedium,
BOOL fRelease)
{
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_enum_format_etc (IDataObject __RPC_FAR *This,
DWORD dwDirection,
IEnumFORMATETC **ppEnumFormatEtc)
{
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_d_advise (IDataObject __RPC_FAR *This,
FORMATETC *pFormatetc,
DWORD advf,
IAdviseSink *pAdvSink,
DWORD *pdwConnection)
{
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_d_unadvise (IDataObject __RPC_FAR *This,
DWORD dwConnection)
{
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_enum_d_advise (IDataObject __RPC_FAR *This,
IEnumSTATDATA **ppenumAdvise)
{
return E_UNEXPECTED;
}
static IDropTargetVtbl idt_vtbl = {
m_query_interface_target,
m_add_ref_target,
m_release_target,
m_drag_enter,
m_drag_over,
m_drag_leave,
m_drop
};
static IDropSourceVtbl ids_vtbl = {
m_query_interface_source,
m_add_ref_source,
m_release_source,
m_query_continue_drag,
m_give_feedback
};
static IDataObjectVtbl ido_vtbl = {
m_query_interface_object,
m_add_ref_object,
m_release_object,
m_get_data,
m_get_data_here,
m_query_get_data,
m_get_canonical_format_etc,
m_set_data,
m_enum_format_etc,
m_d_advise,
m_d_unadvise,
m_enum_d_advise
};
#endif /* OLE2_DND */
static target_drag_context *
target_context_new (void)
{
target_drag_context *result;
result = g_new0 (target_drag_context, 1);
#ifdef OLE2_DND
result->idt.lpVtbl = &idt_vtbl;
#endif
result->context = gdk_drag_context_new ();
return result;
}
static source_drag_context *
source_context_new (void)
{
source_drag_context *result;
result = g_new0 (source_drag_context, 1);
#ifdef OLE2_DND
result->ids.lpVtbl = &ids_vtbl;
#endif
result->context = gdk_drag_context_new ();
return result;
}
#ifdef _MSC_VER
/* From MS Knowledge Base article Q130698 */
/* resolve_link() fills the filename and path buffer
* with relevant information
* hWnd - calling app's window handle.
*
* lpszLinkName - name of the link file passed into the function.
*
* lpszPath - the buffer that will receive the file pathname.
*/
static HRESULT
resolve_link(HWND hWnd,
LPCTSTR lpszLinkName,
LPSTR lpszPath,
LPSTR lpszDescription)
{
HRESULT hres;
IShellLink *psl;
WIN32_FIND_DATA wfd;
/* Assume Failure to start with: */
*lpszPath = 0;
if (lpszDescription)
*lpszDescription = 0;
/* Call CoCreateInstance to obtain the IShellLink interface
* pointer. This call fails if CoInitialize is not called, so it is
* assumed that CoInitialize has been called.
*/
hres = CoCreateInstance (&CLSID_ShellLink,
NULL,
CLSCTX_INPROC_SERVER,
&IID_IShellLink,
(LPVOID *)&psl);
if (SUCCEEDED (hres))
{
IPersistFile *ppf;
/* The IShellLink interface supports the IPersistFile
* interface. Get an interface pointer to it.
*/
hres = psl->lpVtbl->QueryInterface (psl,
&IID_IPersistFile,
(LPVOID *) &ppf);
if (SUCCEEDED (hres))
{
WORD wsz[MAX_PATH];
/* Convert the given link name string to wide character string. */
MultiByteToWideChar (CP_ACP, 0,
lpszLinkName,
-1, wsz, MAX_PATH);
/* Load the file. */
hres = ppf->lpVtbl->Load (ppf, wsz, STGM_READ);
if (SUCCEEDED (hres))
{
/* Resolve the link by calling the Resolve()
* interface function.
*/
hres = psl->lpVtbl->Resolve(psl, hWnd,
SLR_ANY_MATCH |
SLR_NO_UI);
if (SUCCEEDED (hres))
{
hres = psl->lpVtbl->GetPath (psl, lpszPath,
MAX_PATH,
(WIN32_FIND_DATA*)&wfd,
0);
if (SUCCEEDED (hres) && lpszDescription != NULL)
{
hres = psl->lpVtbl->GetDescription (psl,
lpszDescription,
MAX_PATH );
if (!SUCCEEDED (hres))
return FALSE;
}
}
}
ppf->lpVtbl->Release (ppf);
}
psl->lpVtbl->Release (psl);
}
return SUCCEEDED (hres);
}
#else
#define resolve_link(hWnd, lpszLinkName, lpszPath, lpszDescription) FALSE
#endif
static GdkFilterReturn
gdk_dropfiles_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data)
{
GdkDragContext *context;
GdkDragContextPrivate *private;
static GdkAtom text_uri_list_atom = GDK_NONE;
GString *result;
MSG *msg = (MSG *) xev;
HANDLE hdrop;
POINT pt;
gint nfiles, i, k;
guchar fileName[MAX_PATH], linkedFile[MAX_PATH];
if (text_uri_list_atom == GDK_NONE)
text_uri_list_atom = gdk_atom_intern ("text/uri-list", FALSE);
if (msg->message == WM_DROPFILES)
{
GDK_NOTE (DND, g_print ("WM_DROPFILES: %#x\n", msg->hwnd));
context = gdk_drag_context_new ();
private = (GdkDragContextPrivate *) context;
context->protocol = GDK_DRAG_PROTO_WIN32_DROPFILES;
context->is_source = FALSE;
context->source_window = (GdkWindow *) gdk_root_parent;
context->dest_window = event->any.window;
gdk_window_ref (context->dest_window);
/* WM_DROPFILES drops are always file names */
context->targets =
g_list_append (NULL, GUINT_TO_POINTER (text_uri_list_atom));
current_dest_drag = context;
event->dnd.type = GDK_DROP_START;
event->dnd.context = current_dest_drag;
gdk_drag_context_ref (current_dest_drag);
hdrop = (HANDLE) msg->wParam;
DragQueryPoint (hdrop, &pt);
ClientToScreen (msg->hwnd, &pt);
event->dnd.x_root = pt.x;
event->dnd.y_root = pt.y;
event->dnd.time = msg->time;
nfiles = DragQueryFile (hdrop, 0xFFFFFFFF, NULL, 0);
result = g_string_new (NULL);
for (i = 0; i < nfiles; i++)
{
g_string_append (result, "file:");
DragQueryFile (hdrop, i, fileName, MAX_PATH);
/* Resolve shortcuts */
if (resolve_link (msg->hwnd, fileName, linkedFile, NULL))
{
g_string_append (result, linkedFile);
GDK_NOTE (DND, g_print ("...%s link to %s\n",
fileName, linkedFile));
}
else
{
g_string_append (result, fileName);
GDK_NOTE (DND, g_print ("...%s\n", fileName));
}
g_string_append (result, "\015\012");
}
gdk_sel_prop_store ((GdkWindow *) gdk_root_parent,
text_uri_list_atom, 8, result->str, result->len + 1);
DragFinish (hdrop);
return GDK_FILTER_TRANSLATE;
}
else
return GDK_FILTER_CONTINUE;
}
/*************************************************************
************************** Public API ***********************
*************************************************************/
void
gdk_dnd_init (void)
{
HRESULT hres;
#ifdef OLE2_DND
hres = OleInitialize (NULL);
if (! SUCCEEDED (hres))
g_error ("OleInitialize failed");
#endif
}
void
gdk_dnd_exit (void)
{
#ifdef OLE2_DND
OleUninitialize ();
#endif
}
/* Source side */
static void
gdk_drag_do_leave (GdkDragContext *context, guint32 time)
{
if (context->dest_window)
{
GDK_NOTE (DND, g_print ("gdk_drag_do_leave\n"));
gdk_window_unref (context->dest_window);
context->dest_window = NULL;
}
}
GdkDragContext *
gdk_drag_begin (GdkWindow *window,
GList *targets)
{
GList *tmp_list;
source_drag_context *ctx;
g_return_val_if_fail (window != NULL, NULL);
GDK_NOTE (DND, g_print ("gdk_drag_begin\n"));
ctx = source_context_new ();
ctx->context->is_source = TRUE;
ctx->context->source_window = window;
gdk_window_ref (window);
tmp_list = g_list_last (targets);
ctx->context->targets = NULL;
while (tmp_list)
{
ctx->context->targets = g_list_prepend (ctx->context->targets,
tmp_list->data);
tmp_list = tmp_list->prev;
}
ctx->context->actions = 0;
#if 0
DoDragDrop (...);
#endif
return ctx->context;
}
guint32
gdk_drag_get_protocol (guint32 xid,
GdkDragProtocol *protocol)
{
/* This isn't used */
return 0;
}
void
gdk_drag_find_window (GdkDragContext *context,
GdkWindow *drag_window,
gint x_root,
gint y_root,
GdkWindow **dest_window,
GdkDragProtocol *protocol)
{
GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
GdkDrawablePrivate *drag_window_private = (GdkDrawablePrivate*) drag_window;
HWND recipient;
POINT pt;
GDK_NOTE (DND, g_print ("gdk_drag_find_window: %#x +%d+%d\n",
(drag_window ? drag_window_private->xwindow : 0),
x_root, y_root));
pt.x = x_root;
pt.y = y_root;
recipient = WindowFromPoint (pt);
if (recipient == NULL)
*dest_window = NULL;
else
{
*dest_window = gdk_window_lookup (recipient);
if (*dest_window)
gdk_window_ref (*dest_window);
*protocol = GDK_DRAG_PROTO_WIN32_DROPFILES;
}
}
gboolean
gdk_drag_motion (GdkDragContext *context,
GdkWindow *dest_window,
GdkDragProtocol protocol,
gint x_root,
gint y_root,
GdkDragAction suggested_action,
GdkDragAction possible_actions,
guint32 time)
{
return FALSE;
}
void
gdk_drag_drop (GdkDragContext *context,
guint32 time)
{
g_return_if_fail (context != NULL);
g_warning ("gdk_drag_drop: not implemented\n");
}
void
gdk_drag_abort (GdkDragContext *context,
guint32 time)
{
g_return_if_fail (context != NULL);
gdk_drag_do_leave (context, time);
}
/* Destination side */
void
gdk_drag_status (GdkDragContext *context,
GdkDragAction action,
guint32 time)
{
GDK_NOTE (DND, g_print ("gdk_drag_status\n"));
}
void
gdk_drop_reply (GdkDragContext *context,
gboolean ok,
guint32 time)
{
}
void
gdk_drop_finish (GdkDragContext *context,
gboolean success,
guint32 time)
{
}
static GdkFilterReturn
gdk_destroy_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data)
{
#ifdef OLE2_DND
MSG *msg = (MSG *) xev;
if (msg->message == WM_DESTROY)
{
IDropTarget *idtp = (IDropTarget *) data;
GDK_NOTE (DND, g_print ("gdk_destroy_filter: WM_DESTROY: %#x\n", msg->hwnd));
RevokeDragDrop (msg->hwnd);
CoLockObjectExternal (idtp, FALSE, TRUE);
}
#endif
return GDK_FILTER_CONTINUE;
}
void
gdk_window_register_dnd (GdkWindow *window)
{
GdkDrawablePrivate *private = (GdkDrawablePrivate *) window;
#ifdef OLE2_DND
target_drag_context *context;
HRESULT hres;
#endif
g_return_if_fail (window != NULL);
GDK_NOTE (DND, g_print ("gdk_window_register_dnd: %#x\n", private->xwindow));
/* We always claim to accept dropped files, but in fact we might not,
* of course. This function is called in such a way that it cannot know
* whether the window (widget) in question actually accepts files
* (in gtk, data of type text/uri-list) or not.
*/
gdk_window_add_filter (window, gdk_dropfiles_filter, NULL);
DragAcceptFiles (private->xwindow, TRUE);
#ifdef OLE2_DND
/* Register for OLE2 d&d */
context = target_context_new ();
hres = CoLockObjectExternal ((IUnknown *) &context->idt, TRUE, FALSE);
if (!SUCCEEDED (hres))
g_warning ("gdk_window_register_dnd: CoLockObjectExternal failed");
else
{
hres = RegisterDragDrop (private->xwindow, &context->idt);
if (hres == DRAGDROP_E_ALREADYREGISTERED)
{
g_print ("DRAGDROP_E_ALREADYREGISTERED\n");
CoLockObjectExternal ((IUnknown *) &context->idt, FALSE, FALSE);
}
else if (!SUCCEEDED (hres))
g_warning ("gdk_window_register_dnd: RegisterDragDrop failed");
else
{
gdk_window_add_filter (window, gdk_destroy_filter, &context->idt);
}
}
#endif
}
/*************************************************************
* gdk_drag_get_selection:
* Returns the selection atom for the current source window
* arguments:
*
* results:
*************************************************************/
GdkAtom
gdk_drag_get_selection (GdkDragContext *context)
{
if (context->protocol == GDK_DRAG_PROTO_WIN32_DROPFILES)
return gdk_win32_dropfiles_atom;
else if (context->protocol == GDK_DRAG_PROTO_OLE2)
return gdk_ole2_dnd_atom;
else
return GDK_NONE;
}

973
gdk/win32/gdkdnd.c Normal file
View File

@ -0,0 +1,973 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1999 Peter Mattis, Spencer Kimball and Josh MacDonald
* Copyright (C) 1998-1999 Tor Lillqvist
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include <string.h>
/* #define OLE2_DND */
#define INITGUID
#include "gdkdnd.h"
#include "gdkproperty.h"
#include "gdkprivate.h"
#include "gdkx.h"
#ifdef OLE2_DND
#include <ole2.h>
#else
#include <objbase.h>
#endif
#ifdef _MSC_VER /* These aren't in mingw32 */
#include <shlobj.h>
#include <shlguid.h>
#endif
#ifndef _MSC_VER
static IID IID_IUnknown = {
0x00000000, 0x0000, 0x0000, { 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 } };
static IID IID_IDropSource = {
0x00000121, 0x0000, 0x0000, { 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 } };
static IID IID_IDropTarget = {
0x00000122, 0x0000, 0x0000, { 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 } };
#endif
#include <gdk/gdk.h>
typedef struct _GdkDragContextPrivate GdkDragContextPrivate;
typedef enum {
GDK_DRAG_STATUS_DRAG,
GDK_DRAG_STATUS_MOTION_WAIT,
GDK_DRAG_STATUS_ACTION_WAIT,
GDK_DRAG_STATUS_DROP
} GtkDragStatus;
typedef enum {
GDK_DRAG_SOURCE,
GDK_DRAG_TARGET
} GdkDragKind;
#ifdef OLE2_DND
#define PRINT_GUID(guid) \
g_print ("guid = %.08x-%.04x-%.04x-%.02x%.02x-%.02x%.02x%.02x%.02x%.02x%.02x", \
((gulong *) guid)[0], \
((gushort *) guid)[2], \
((gushort *) guid)[3], \
((guchar *) guid)[8], \
((guchar *) guid)[9], \
((guchar *) guid)[10], \
((guchar *) guid)[11], \
((guchar *) guid)[12], \
((guchar *) guid)[13], \
((guchar *) guid)[14], \
((guchar *) guid)[15]);
#endif /* OLE2_DND */
/* Structure that holds information about a drag in progress.
* this is used on both source and destination sides.
*/
struct _GdkDragContextPrivate {
GdkDragContext context;
guint ref_count;
guint16 last_x; /* Coordinates from last event */
guint16 last_y;
HWND dest_xid;
guint drag_status; /* Current status of drag */
};
GdkDragContext *current_dest_drag = NULL;
/* Drag Contexts */
static GList *contexts;
GdkDragContext *
gdk_drag_context_new (void)
{
GdkDragContextPrivate *result;
result = g_new0 (GdkDragContextPrivate, 1);
result->ref_count = 1;
contexts = g_list_prepend (contexts, result);
return (GdkDragContext *)result;
}
void
gdk_drag_context_ref (GdkDragContext *context)
{
g_return_if_fail (context != NULL);
((GdkDragContextPrivate *)context)->ref_count++;
}
void
gdk_drag_context_unref (GdkDragContext *context)
{
GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
g_return_if_fail (context != NULL);
private->ref_count--;
GDK_NOTE (DND, g_print ("gdk_drag_context_unref: %d%s\n",
private->ref_count,
(private->ref_count == 0 ? " freeing" : "")));
if (private->ref_count == 0)
{
g_dataset_destroy (private);
g_list_free (context->targets);
if (context->source_window)
gdk_window_unref (context->source_window);
if (context->dest_window)
gdk_window_unref (context->dest_window);
contexts = g_list_remove (contexts, private);
g_free (private);
}
}
#if 0
static GdkDragContext *
gdk_drag_context_find (gboolean is_source,
HWND source_xid,
HWND dest_xid)
{
GList *tmp_list = contexts;
GdkDragContext *context;
while (tmp_list)
{
context = (GdkDragContext *)tmp_list->data;
if ((!context->is_source == !is_source) &&
((source_xid == None) || (context->source_window &&
(GDK_WINDOW_XWINDOW (context->source_window) == source_xid))) &&
((dest_xid == None) || (context->dest_window &&
(GDK_WINDOW_XWINDOW (context->dest_window) == dest_xid))))
return context;
tmp_list = tmp_list->next;
}
return NULL;
}
#endif
typedef struct {
#ifdef OLE2_DND
IDropTarget idt;
#endif
GdkDragContext *context;
} target_drag_context;
typedef struct {
#ifdef OLE2_DND
IDropSource ids;
#endif
GdkDragContext *context;
} source_drag_context;
#ifdef OLE2_DND
static ULONG STDMETHODCALLTYPE
m_add_ref_target (IDropTarget __RPC_FAR *This)
{
target_drag_context *ctx = (target_drag_context *) This;
GdkDragContextPrivate *private = (GdkDragContextPrivate *) ctx->context;
GDK_NOTE (DND, g_print ("m_add_ref_target\n"));
gdk_drag_context_ref (ctx->context);
return private->ref_count;
}
static HRESULT STDMETHODCALLTYPE
m_query_interface_target (IDropTarget __RPC_FAR *This,
REFIID riid,
void __RPC_FAR *__RPC_FAR *ppvObject)
{
GDK_NOTE (DND, g_print ("m_query_interface_target\n"));
*ppvObject = NULL;
PRINT_GUID (riid);
if (IsEqualGUID (riid, &IID_IUnknown))
{
g_print ("...IUnknown\n");
m_add_ref_target (This);
*ppvObject = This;
return S_OK;
}
else if (IsEqualGUID (riid, &IID_IDropTarget))
{
g_print ("...IDropTarget\n");
m_add_ref_target (This);
*ppvObject = This;
return S_OK;
}
else
{
g_print ("...Huh?\n");
return E_NOINTERFACE;
}
}
static ULONG STDMETHODCALLTYPE
m_release_target (IDropTarget __RPC_FAR *This)
{
target_drag_context *ctx = (target_drag_context *) This;
GdkDragContextPrivate *private = (GdkDragContextPrivate *) ctx->context;
GDK_NOTE (DND, g_print ("m_release_target\n"));
gdk_drag_context_unref (ctx->context);
if (private->ref_count == 1)
{
gdk_drag_context_unref (ctx->context);
return 0;
}
else
return private->ref_count - 1;
}
static HRESULT STDMETHODCALLTYPE
m_drag_enter (IDropTarget __RPC_FAR *This,
IDataObject __RPC_FAR *pDataObj,
DWORD grfKeyState,
POINTL pt,
DWORD __RPC_FAR *pdwEffect)
{
GDK_NOTE (DND, g_print ("m_drag_enter\n"));
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_drag_over (IDropTarget __RPC_FAR *This,
DWORD grfKeyState,
POINTL pt,
DWORD __RPC_FAR *pdwEffect)
{
GDK_NOTE (DND, g_print ("m_drag_over\n"));
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_drag_leave (IDropTarget __RPC_FAR *This)
{
GDK_NOTE (DND, g_print ("m_drag_leave\n"));
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_drop (IDropTarget __RPC_FAR *This,
IDataObject __RPC_FAR *pDataObj,
DWORD grfKeyState,
POINTL pt,
DWORD __RPC_FAR *pdwEffect)
{
GDK_NOTE (DND, g_print ("m_drop\n"));
return E_UNEXPECTED;
}
static ULONG STDMETHODCALLTYPE
m_add_ref_source (IDropSource __RPC_FAR *This)
{
source_drag_context *ctx = (source_drag_context *) This;
GdkDragContextPrivate *private = (GdkDragContextPrivate *) ctx->context;
GDK_NOTE (DND, g_print ("m_add_ref_source\n"));
gdk_drag_context_ref (ctx->context);
return private->ref_count;
}
static HRESULT STDMETHODCALLTYPE
m_query_interface_source (IDropSource __RPC_FAR *This,
REFIID riid,
void __RPC_FAR *__RPC_FAR *ppvObject)
{
GDK_NOTE (DND, g_print ("m_query_interface_source\n"));
*ppvObject = NULL;
PRINT_GUID (riid);
if (IsEqualGUID (riid, &IID_IUnknown))
{
g_print ("...IUnknown\n");
m_add_ref_source (This);
*ppvObject = This;
return S_OK;
}
else if (IsEqualGUID (riid, &IID_IDropSource))
{
g_print ("...IDropSource\n");
m_add_ref_source (This);
*ppvObject = This;
return S_OK;
}
else
{
g_print ("...Huh?\n");
return E_NOINTERFACE;
}
}
static ULONG STDMETHODCALLTYPE
m_release_source (IDropSource __RPC_FAR *This)
{
source_drag_context *ctx = (source_drag_context *) This;
GdkDragContextPrivate *private = (GdkDragContextPrivate *) ctx->context;
GDK_NOTE (DND, g_print ("m_release_source\n"));
gdk_drag_context_unref (ctx->context);
if (private->ref_count == 1)
{
gdk_drag_context_unref (ctx->context);
return 0;
}
else
return private->ref_count - 1;
}
static HRESULT STDMETHODCALLTYPE
m_query_continue_drag (IDropSource __RPC_FAR *This,
BOOL fEscapePressed,
DWORD grfKeyState)
{
GDK_NOTE (DND, g_print ("m_query_continue_drag\n"));
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_give_feedback (IDropSource __RPC_FAR *This,
DWORD dwEffect)
{
GDK_NOTE (DND, g_print ("m_give_feedback\n"));
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_query_interface_object (IDataObject __RPC_FAR *This,
REFIID riid,
void __RPC_FAR *__RPC_FAR *ppvObject)
{
return E_UNEXPECTED;
}
static ULONG STDMETHODCALLTYPE
m_add_ref_object (IDataObject __RPC_FAR *This)
{
return E_UNEXPECTED;
}
static ULONG STDMETHODCALLTYPE
m_release_object (IDataObject __RPC_FAR *This)
{
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_get_data (IDataObject __RPC_FAR *This,
FORMATETC *pFormatEtc,
STGMEDIUM *pMedium)
{
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_get_data_here (IDataObject __RPC_FAR *This,
FORMATETC *pFormatEtc,
STGMEDIUM *pMedium)
{
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_query_get_data (IDataObject __RPC_FAR *This,
FORMATETC *pFormatEtc)
{
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_get_canonical_format_etc (IDataObject __RPC_FAR *This,
FORMATETC *pFormatEtcIn,
FORMATETC *pFormatEtcOut)
{
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_set_data (IDataObject __RPC_FAR *This,
FORMATETC *pFormatEtc,
STGMEDIUM *pMedium,
BOOL fRelease)
{
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_enum_format_etc (IDataObject __RPC_FAR *This,
DWORD dwDirection,
IEnumFORMATETC **ppEnumFormatEtc)
{
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_d_advise (IDataObject __RPC_FAR *This,
FORMATETC *pFormatetc,
DWORD advf,
IAdviseSink *pAdvSink,
DWORD *pdwConnection)
{
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_d_unadvise (IDataObject __RPC_FAR *This,
DWORD dwConnection)
{
return E_UNEXPECTED;
}
static HRESULT STDMETHODCALLTYPE
m_enum_d_advise (IDataObject __RPC_FAR *This,
IEnumSTATDATA **ppenumAdvise)
{
return E_UNEXPECTED;
}
static IDropTargetVtbl idt_vtbl = {
m_query_interface_target,
m_add_ref_target,
m_release_target,
m_drag_enter,
m_drag_over,
m_drag_leave,
m_drop
};
static IDropSourceVtbl ids_vtbl = {
m_query_interface_source,
m_add_ref_source,
m_release_source,
m_query_continue_drag,
m_give_feedback
};
static IDataObjectVtbl ido_vtbl = {
m_query_interface_object,
m_add_ref_object,
m_release_object,
m_get_data,
m_get_data_here,
m_query_get_data,
m_get_canonical_format_etc,
m_set_data,
m_enum_format_etc,
m_d_advise,
m_d_unadvise,
m_enum_d_advise
};
#endif /* OLE2_DND */
static target_drag_context *
target_context_new (void)
{
target_drag_context *result;
result = g_new0 (target_drag_context, 1);
#ifdef OLE2_DND
result->idt.lpVtbl = &idt_vtbl;
#endif
result->context = gdk_drag_context_new ();
return result;
}
static source_drag_context *
source_context_new (void)
{
source_drag_context *result;
result = g_new0 (source_drag_context, 1);
#ifdef OLE2_DND
result->ids.lpVtbl = &ids_vtbl;
#endif
result->context = gdk_drag_context_new ();
return result;
}
#ifdef _MSC_VER
/* From MS Knowledge Base article Q130698 */
/* resolve_link() fills the filename and path buffer
* with relevant information
* hWnd - calling app's window handle.
*
* lpszLinkName - name of the link file passed into the function.
*
* lpszPath - the buffer that will receive the file pathname.
*/
static HRESULT
resolve_link(HWND hWnd,
LPCTSTR lpszLinkName,
LPSTR lpszPath,
LPSTR lpszDescription)
{
HRESULT hres;
IShellLink *psl;
WIN32_FIND_DATA wfd;
/* Assume Failure to start with: */
*lpszPath = 0;
if (lpszDescription)
*lpszDescription = 0;
/* Call CoCreateInstance to obtain the IShellLink interface
* pointer. This call fails if CoInitialize is not called, so it is
* assumed that CoInitialize has been called.
*/
hres = CoCreateInstance (&CLSID_ShellLink,
NULL,
CLSCTX_INPROC_SERVER,
&IID_IShellLink,
(LPVOID *)&psl);
if (SUCCEEDED (hres))
{
IPersistFile *ppf;
/* The IShellLink interface supports the IPersistFile
* interface. Get an interface pointer to it.
*/
hres = psl->lpVtbl->QueryInterface (psl,
&IID_IPersistFile,
(LPVOID *) &ppf);
if (SUCCEEDED (hres))
{
WORD wsz[MAX_PATH];
/* Convert the given link name string to wide character string. */
MultiByteToWideChar (CP_ACP, 0,
lpszLinkName,
-1, wsz, MAX_PATH);
/* Load the file. */
hres = ppf->lpVtbl->Load (ppf, wsz, STGM_READ);
if (SUCCEEDED (hres))
{
/* Resolve the link by calling the Resolve()
* interface function.
*/
hres = psl->lpVtbl->Resolve(psl, hWnd,
SLR_ANY_MATCH |
SLR_NO_UI);
if (SUCCEEDED (hres))
{
hres = psl->lpVtbl->GetPath (psl, lpszPath,
MAX_PATH,
(WIN32_FIND_DATA*)&wfd,
0);
if (SUCCEEDED (hres) && lpszDescription != NULL)
{
hres = psl->lpVtbl->GetDescription (psl,
lpszDescription,
MAX_PATH );
if (!SUCCEEDED (hres))
return FALSE;
}
}
}
ppf->lpVtbl->Release (ppf);
}
psl->lpVtbl->Release (psl);
}
return SUCCEEDED (hres);
}
#else
#define resolve_link(hWnd, lpszLinkName, lpszPath, lpszDescription) FALSE
#endif
static GdkFilterReturn
gdk_dropfiles_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data)
{
GdkDragContext *context;
GdkDragContextPrivate *private;
static GdkAtom text_uri_list_atom = GDK_NONE;
GString *result;
MSG *msg = (MSG *) xev;
HANDLE hdrop;
POINT pt;
gint nfiles, i, k;
guchar fileName[MAX_PATH], linkedFile[MAX_PATH];
if (text_uri_list_atom == GDK_NONE)
text_uri_list_atom = gdk_atom_intern ("text/uri-list", FALSE);
if (msg->message == WM_DROPFILES)
{
GDK_NOTE (DND, g_print ("WM_DROPFILES: %#x\n", msg->hwnd));
context = gdk_drag_context_new ();
private = (GdkDragContextPrivate *) context;
context->protocol = GDK_DRAG_PROTO_WIN32_DROPFILES;
context->is_source = FALSE;
context->source_window = (GdkWindow *) gdk_root_parent;
context->dest_window = event->any.window;
gdk_window_ref (context->dest_window);
/* WM_DROPFILES drops are always file names */
context->targets =
g_list_append (NULL, GUINT_TO_POINTER (text_uri_list_atom));
current_dest_drag = context;
event->dnd.type = GDK_DROP_START;
event->dnd.context = current_dest_drag;
gdk_drag_context_ref (current_dest_drag);
hdrop = (HANDLE) msg->wParam;
DragQueryPoint (hdrop, &pt);
ClientToScreen (msg->hwnd, &pt);
event->dnd.x_root = pt.x;
event->dnd.y_root = pt.y;
event->dnd.time = msg->time;
nfiles = DragQueryFile (hdrop, 0xFFFFFFFF, NULL, 0);
result = g_string_new (NULL);
for (i = 0; i < nfiles; i++)
{
g_string_append (result, "file:");
DragQueryFile (hdrop, i, fileName, MAX_PATH);
/* Resolve shortcuts */
if (resolve_link (msg->hwnd, fileName, linkedFile, NULL))
{
g_string_append (result, linkedFile);
GDK_NOTE (DND, g_print ("...%s link to %s\n",
fileName, linkedFile));
}
else
{
g_string_append (result, fileName);
GDK_NOTE (DND, g_print ("...%s\n", fileName));
}
g_string_append (result, "\015\012");
}
gdk_sel_prop_store ((GdkWindow *) gdk_root_parent,
text_uri_list_atom, 8, result->str, result->len + 1);
DragFinish (hdrop);
return GDK_FILTER_TRANSLATE;
}
else
return GDK_FILTER_CONTINUE;
}
/*************************************************************
************************** Public API ***********************
*************************************************************/
void
gdk_dnd_init (void)
{
HRESULT hres;
#ifdef OLE2_DND
hres = OleInitialize (NULL);
if (! SUCCEEDED (hres))
g_error ("OleInitialize failed");
#endif
}
void
gdk_dnd_exit (void)
{
#ifdef OLE2_DND
OleUninitialize ();
#endif
}
/* Source side */
static void
gdk_drag_do_leave (GdkDragContext *context, guint32 time)
{
if (context->dest_window)
{
GDK_NOTE (DND, g_print ("gdk_drag_do_leave\n"));
gdk_window_unref (context->dest_window);
context->dest_window = NULL;
}
}
GdkDragContext *
gdk_drag_begin (GdkWindow *window,
GList *targets)
{
GList *tmp_list;
source_drag_context *ctx;
g_return_val_if_fail (window != NULL, NULL);
GDK_NOTE (DND, g_print ("gdk_drag_begin\n"));
ctx = source_context_new ();
ctx->context->is_source = TRUE;
ctx->context->source_window = window;
gdk_window_ref (window);
tmp_list = g_list_last (targets);
ctx->context->targets = NULL;
while (tmp_list)
{
ctx->context->targets = g_list_prepend (ctx->context->targets,
tmp_list->data);
tmp_list = tmp_list->prev;
}
ctx->context->actions = 0;
#if 0
DoDragDrop (...);
#endif
return ctx->context;
}
guint32
gdk_drag_get_protocol (guint32 xid,
GdkDragProtocol *protocol)
{
/* This isn't used */
return 0;
}
void
gdk_drag_find_window (GdkDragContext *context,
GdkWindow *drag_window,
gint x_root,
gint y_root,
GdkWindow **dest_window,
GdkDragProtocol *protocol)
{
GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
GdkDrawablePrivate *drag_window_private = (GdkDrawablePrivate*) drag_window;
HWND recipient;
POINT pt;
GDK_NOTE (DND, g_print ("gdk_drag_find_window: %#x +%d+%d\n",
(drag_window ? drag_window_private->xwindow : 0),
x_root, y_root));
pt.x = x_root;
pt.y = y_root;
recipient = WindowFromPoint (pt);
if (recipient == NULL)
*dest_window = NULL;
else
{
*dest_window = gdk_window_lookup (recipient);
if (*dest_window)
gdk_window_ref (*dest_window);
*protocol = GDK_DRAG_PROTO_WIN32_DROPFILES;
}
}
gboolean
gdk_drag_motion (GdkDragContext *context,
GdkWindow *dest_window,
GdkDragProtocol protocol,
gint x_root,
gint y_root,
GdkDragAction suggested_action,
GdkDragAction possible_actions,
guint32 time)
{
return FALSE;
}
void
gdk_drag_drop (GdkDragContext *context,
guint32 time)
{
g_return_if_fail (context != NULL);
g_warning ("gdk_drag_drop: not implemented\n");
}
void
gdk_drag_abort (GdkDragContext *context,
guint32 time)
{
g_return_if_fail (context != NULL);
gdk_drag_do_leave (context, time);
}
/* Destination side */
void
gdk_drag_status (GdkDragContext *context,
GdkDragAction action,
guint32 time)
{
GDK_NOTE (DND, g_print ("gdk_drag_status\n"));
}
void
gdk_drop_reply (GdkDragContext *context,
gboolean ok,
guint32 time)
{
}
void
gdk_drop_finish (GdkDragContext *context,
gboolean success,
guint32 time)
{
}
static GdkFilterReturn
gdk_destroy_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data)
{
#ifdef OLE2_DND
MSG *msg = (MSG *) xev;
if (msg->message == WM_DESTROY)
{
IDropTarget *idtp = (IDropTarget *) data;
GDK_NOTE (DND, g_print ("gdk_destroy_filter: WM_DESTROY: %#x\n", msg->hwnd));
RevokeDragDrop (msg->hwnd);
CoLockObjectExternal (idtp, FALSE, TRUE);
}
#endif
return GDK_FILTER_CONTINUE;
}
void
gdk_window_register_dnd (GdkWindow *window)
{
GdkDrawablePrivate *private = (GdkDrawablePrivate *) window;
#ifdef OLE2_DND
target_drag_context *context;
HRESULT hres;
#endif
g_return_if_fail (window != NULL);
GDK_NOTE (DND, g_print ("gdk_window_register_dnd: %#x\n", private->xwindow));
/* We always claim to accept dropped files, but in fact we might not,
* of course. This function is called in such a way that it cannot know
* whether the window (widget) in question actually accepts files
* (in gtk, data of type text/uri-list) or not.
*/
gdk_window_add_filter (window, gdk_dropfiles_filter, NULL);
DragAcceptFiles (private->xwindow, TRUE);
#ifdef OLE2_DND
/* Register for OLE2 d&d */
context = target_context_new ();
hres = CoLockObjectExternal ((IUnknown *) &context->idt, TRUE, FALSE);
if (!SUCCEEDED (hres))
g_warning ("gdk_window_register_dnd: CoLockObjectExternal failed");
else
{
hres = RegisterDragDrop (private->xwindow, &context->idt);
if (hres == DRAGDROP_E_ALREADYREGISTERED)
{
g_print ("DRAGDROP_E_ALREADYREGISTERED\n");
CoLockObjectExternal ((IUnknown *) &context->idt, FALSE, FALSE);
}
else if (!SUCCEEDED (hres))
g_warning ("gdk_window_register_dnd: RegisterDragDrop failed");
else
{
gdk_window_add_filter (window, gdk_destroy_filter, &context->idt);
}
}
#endif
}
/*************************************************************
* gdk_drag_get_selection:
* Returns the selection atom for the current source window
* arguments:
*
* results:
*************************************************************/
GdkAtom
gdk_drag_get_selection (GdkDragContext *context)
{
if (context->protocol == GDK_DRAG_PROTO_WIN32_DROPFILES)
return gdk_win32_dropfiles_atom;
else if (context->protocol == GDK_DRAG_PROTO_OLE2)
return gdk_ole2_dnd_atom;
else
return GDK_NONE;
}

909
gdk/win32/gdkdraw.c Normal file
View File

@ -0,0 +1,909 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include <math.h>
#include "gdkdrawable.h"
#include "gdkprivate.h"
#include "gdkwindow.h"
#include "gdkx.h"
#ifndef G_PI
#define G_PI 3.14159265358979323846
#endif
/* Manipulation of drawables
*/
void
gdk_drawable_set_data (GdkDrawable *drawable,
const gchar *key,
gpointer data,
GDestroyNotify destroy_func)
{
g_dataset_set_data_full (drawable, key, data, destroy_func);
}
void
gdk_drawable_get_data (GdkDrawable *drawable,
const gchar *key)
{
g_dataset_get_data (drawable, key);
}
GdkDrawableType
gdk_drawable_get_type (GdkDrawable *drawable)
{
g_return_val_if_fail (drawable != NULL, (GdkDrawableType) -1);
return GDK_DRAWABLE_TYPE (drawable);
}
void
gdk_drawable_get_size (GdkDrawable *drawable,
gint *width,
gint *height)
{
GdkDrawablePrivate *drawable_private;
g_return_if_fail (drawable != NULL);
drawable_private = (GdkDrawablePrivate*) drawable;
if (width)
*width = drawable_private->width;
if (height)
*height = drawable_private->height;
}
void
gdk_drawable_set_colormap (GdkDrawable *drawable,
GdkColormap *colormap)
{
GdkDrawablePrivate *drawable_private;
GdkColormapPrivate *colormap_private;
g_return_if_fail (drawable != NULL);
g_return_if_fail (colormap != NULL);
drawable_private = (GdkDrawablePrivate*) drawable;
colormap_private = (GdkColormapPrivate*) colormap;
if (!GDK_DRAWABLE_DESTROYED (drawable))
{
if (GDK_IS_WINDOW (drawable))
{
g_return_if_fail (colormap_private->visual !=
((GdkColormapPrivate*)(drawable_private->colormap))->visual);
/* XXX ??? */
GDK_NOTE (MISC, g_print ("gdk_drawable_set_colormap: %#x %#x\n",
GDK_DRAWABLE_XID (drawable),
colormap_private->xcolormap));
}
if (drawable_private->colormap)
gdk_colormap_unref (drawable_private->colormap);
drawable_private->colormap = colormap;
gdk_colormap_ref (drawable_private->colormap);
if (GDK_IS_WINDOW (drawable) &&
drawable_private->window_type != GDK_WINDOW_TOPLEVEL)
gdk_window_add_colormap_windows (drawable);
}
}
GdkColormap*
gdk_drawable_get_colormap (GdkDrawable *drawable)
{
GdkDrawablePrivate *drawable_private;
g_return_val_if_fail (drawable != NULL, NULL);
drawable_private = (GdkDrawablePrivate*) drawable;
if (!GDK_DRAWABLE_DESTROYED (drawable))
{
if (drawable_private->colormap == NULL)
return gdk_colormap_get_system (); /* XXX ??? */
else
return drawable_private->colormap;
}
return NULL;
}
GdkVisual*
gdk_drawable_get_visual (GdkDrawable *drawable)
{
GdkColormap *colormap;
g_return_val_if_fail (drawable != NULL, NULL);
colormap = gdk_drawable_get_colormap (drawable);
return colormap ? gdk_colormap_get_visual (colormap) : NULL;
}
void
gdk_draw_point (GdkDrawable *drawable,
GdkGC *gc,
gint x,
gint y)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
HDC hdc;
g_return_if_fail (drawable != NULL);
g_return_if_fail (gc != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
hdc = gdk_gc_predraw (drawable_private, gc_private);
/* We use LineTo because SetPixel wants the COLORREF directly,
* and doesn't use the current pen, which is what we want.
*/
if (!MoveToEx (hdc, x, y, NULL))
g_warning ("gdk_draw_point: MoveToEx failed");
if (!LineTo (hdc, x + 1, y))
g_warning ("gdk_draw_point: LineTo failed");
gdk_gc_postdraw (drawable_private, gc_private);
}
void
gdk_draw_line (GdkDrawable *drawable,
GdkGC *gc,
gint x1,
gint y1,
gint x2,
gint y2)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
HDC hdc;
g_return_if_fail (drawable != NULL);
g_return_if_fail (gc != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
hdc = gdk_gc_predraw (drawable_private, gc_private);
GDK_NOTE (MISC, g_print ("gdk_draw_line: %#x (%d) +%d+%d..+%d+%d\n",
drawable_private->xwindow, gc_private,
x1, y1, x2, y2));
MoveToEx (hdc, x1, y1, NULL);
if (!LineTo (hdc, x2, y2))
g_warning ("gdk_draw_line: LineTo #1 failed");
/* LineTo doesn't draw the last point, so if we have a pen width of 1,
* we draw the end pixel separately... With wider pens we don't care.
* //HB: But the NT developers don't read their API documentation ...
*/
if (gc_private->pen_width == 1 && windows_version > 0x80000000)
if (!LineTo (hdc, x2 + 1, y2))
g_warning ("gdk_draw_line: LineTo #2 failed");
gdk_gc_postdraw (drawable_private, gc_private);
}
void
gdk_draw_rectangle (GdkDrawable *drawable,
GdkGC *gc,
gint filled,
gint x,
gint y,
gint width,
gint height)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
HDC hdc;
HGDIOBJ oldpen, oldbrush;
g_return_if_fail (drawable != NULL);
g_return_if_fail (gc != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
if (width == -1)
width = drawable_private->width;
if (height == -1)
height = drawable_private->height;
hdc = gdk_gc_predraw (drawable_private, gc_private);
GDK_NOTE (MISC, g_print ("gdk_draw_rectangle: %#x (%d) %s%dx%d@+%d+%d\n",
drawable_private->xwindow,
gc_private,
(filled ? "fill " : ""),
width, height, x, y));
#if 0
{
HBRUSH hbr = GetCurrentObject (hdc, OBJ_BRUSH);
HPEN hpen = GetCurrentObject (hdc, OBJ_PEN);
LOGBRUSH lbr;
LOGPEN lpen;
GetObject (hbr, sizeof (lbr), &lbr);
GetObject (hpen, sizeof (lpen), &lpen);
g_print ("current brush: style = %s, color = 0x%.08x\n",
(lbr.lbStyle == BS_SOLID ? "SOLID" : "???"),
lbr.lbColor);
g_print ("current pen: style = %s, width = %d, color = 0x%.08x\n",
(lpen.lopnStyle == PS_SOLID ? "SOLID" : "???"),
lpen.lopnWidth,
lpen.lopnColor);
}
#endif
if (filled)
oldpen = SelectObject (hdc, GetStockObject (NULL_PEN));
else
oldbrush = SelectObject (hdc, GetStockObject (HOLLOW_BRUSH));
if (!Rectangle (hdc, x, y, x+width+1, y+height+1))
g_warning ("gdk_draw_rectangle: Rectangle failed");
if (filled)
SelectObject (hdc, oldpen);
else
SelectObject (hdc, oldbrush);
gdk_gc_postdraw (drawable_private, gc_private);
}
void
gdk_draw_arc (GdkDrawable *drawable,
GdkGC *gc,
gint filled,
gint x,
gint y,
gint width,
gint height,
gint angle1,
gint angle2)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
HDC hdc;
int nXStartArc, nYStartArc, nXEndArc, nYEndArc;
g_return_if_fail (drawable != NULL);
g_return_if_fail (gc != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
if (width == -1)
width = drawable_private->width;
if (height == -1)
height = drawable_private->height;
GDK_NOTE (MISC, g_print ("gdk_draw_arc: %#x %d,%d,%d,%d %d %d\n",
drawable_private->xwindow,
x, y, width, height, angle1, angle2));
if (width != 0 && height != 0 && angle2 != 0)
{
hdc = gdk_gc_predraw (drawable_private, gc_private);
if (angle2 >= 360*64)
{
nXStartArc = nYStartArc = nXEndArc = nYEndArc = 0;
}
else if (angle2 > 0)
{
/* The 100. is just an arbitrary value */
nXStartArc = x + width/2 + 100. * cos(angle1/64.*2.*G_PI/360.);
nYStartArc = y + height/2 + -100. * sin(angle1/64.*2.*G_PI/360.);
nXEndArc = x + width/2 + 100. * cos((angle1+angle2)/64.*2.*G_PI/360.);
nYEndArc = y + height/2 + -100. * sin((angle1+angle2)/64.*2.*G_PI/360.);
}
else
{
nXEndArc = x + width/2 + 100. * cos(angle1/64.*2.*G_PI/360.);
nYEndArc = y + height/2 + -100. * sin(angle1/64.*2.*G_PI/360.);
nXStartArc = x + width/2 + 100. * cos((angle1+angle2)/64.*2.*G_PI/360.);
nYStartArc = y + height/2 + -100. * sin((angle1+angle2)/64.*2.*G_PI/360.);
}
if (filled)
{
GDK_NOTE (MISC, g_print ("...Pie(hdc,%d,%d,%d,%d,%d,%d,%d,%d)\n",
x, y, x+width, y+height,
nXStartArc, nYStartArc,
nXEndArc, nYEndArc));
Pie (hdc, x, y, x+width, y+height,
nXStartArc, nYStartArc, nXEndArc, nYEndArc);
}
else
{
GDK_NOTE (MISC, g_print ("...Arc(hdc,%d,%d,%d,%d,%d,%d,%d,%d)\n",
x, y, x+width, y+height,
nXStartArc, nYStartArc,
nXEndArc, nYEndArc));
Arc (hdc, x, y, x+width, y+height,
nXStartArc, nYStartArc, nXEndArc, nYEndArc);
}
gdk_gc_postdraw (drawable_private, gc_private);
}
}
void
gdk_draw_polygon (GdkDrawable *drawable,
GdkGC *gc,
gint filled,
GdkPoint *points,
gint npoints)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
HDC hdc;
POINT *pts;
int i;
g_return_if_fail (drawable != NULL);
g_return_if_fail (gc != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
GDK_NOTE (MISC, g_print ("gdk_draw_polygon: %#x (%d) %d\n",
drawable_private->xwindow, gc_private,
npoints));
if (npoints < 2)
return;
hdc = gdk_gc_predraw (drawable_private, gc_private);
pts = g_malloc ((npoints+1) * sizeof (POINT));
for (i = 0; i < npoints; i++)
{
pts[i].x = points[i].x;
pts[i].y = points[i].y;
}
if ((points[0].x != points[npoints-1].x) ||
(points[0].y != points[npoints-1].y))
{
pts[npoints].x = points[0].x;
pts[npoints].y = points[0].y;
npoints++;
}
if (filled)
{
if (!Polygon (hdc, pts, npoints))
g_warning ("gdk_draw_polygon: Polygon failed");
}
else
{
if (!Polyline (hdc, pts, npoints))
g_warning ("gdk_draw_polygon: Polyline failed");
}
g_free (pts);
gdk_gc_postdraw (drawable_private, gc_private);
}
typedef struct
{
gint x, y;
HDC hdc;
} gdk_draw_text_arg;
/* gdk_draw_string
*/
void
gdk_draw_string (GdkDrawable *drawable,
GdkFont *font,
GdkGC *gc,
gint x,
gint y,
const gchar *string)
{
gdk_draw_text (drawable, font, gc, x, y, string, strlen (string));
}
static void
gdk_draw_text_handler (GdkWin32SingleFont *singlefont,
const wchar_t *wcstr,
int wclen,
void *arg)
{
HGDIOBJ oldfont;
SIZE size;
gdk_draw_text_arg *argp = (gdk_draw_text_arg *) arg;
if (!singlefont)
return;
if ((oldfont = SelectObject (argp->hdc, singlefont->xfont)) == NULL)
{
g_warning ("gdk_draw_text_handler: SelectObject failed");
return;
}
if (!TextOutW (argp->hdc, argp->x, argp->y, wcstr, wclen))
g_warning ("gdk_draw_text_handler: TextOutW failed");
GetTextExtentPoint32W (argp->hdc, wcstr, wclen, &size);
argp->x += size.cx;
SelectObject (argp->hdc, oldfont);
}
/* gdk_draw_text
*
*/
void
gdk_draw_text (GdkDrawable *drawable,
GdkFont *font,
GdkGC *gc,
gint x,
gint y,
const gchar *text,
gint text_length)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
wchar_t *wcstr;
gint wlen;
gdk_draw_text_arg arg;
g_return_if_fail (drawable != NULL);
g_return_if_fail (font != NULL);
g_return_if_fail (gc != NULL);
g_return_if_fail (text != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
if (text_length == 0)
return;
g_assert (font->type == GDK_FONT_FONT || font->type == GDK_FONT_FONTSET);
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
arg.x = x;
arg.y = y;
arg.hdc = gdk_gc_predraw (drawable_private, gc_private);
GDK_NOTE (MISC, g_print ("gdk_draw_text: %#x (%d,%d) \"%.*s\" (len %d)\n",
drawable_private->xwindow,
x, y,
(text_length > 10 ? 10 : text_length),
text, text_length));
wcstr = g_new (wchar_t, text_length);
if ((wlen = gdk_nmbstowchar_ts (wcstr, text, text_length, text_length)) == -1)
g_warning ("gdk_draw_text: gdk_nmbstowchar_ts failed");
else
gdk_wchar_text_handle (font, wcstr, wlen,
gdk_draw_text_handler, &arg);
g_free (wcstr);
gdk_gc_postdraw (drawable_private, gc_private);
}
void
gdk_draw_text_wc (GdkDrawable *drawable,
GdkFont *font,
GdkGC *gc,
gint x,
gint y,
const GdkWChar *text,
gint text_length)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
gint i, wlen;
wchar_t *wcstr;
gdk_draw_text_arg arg;
g_return_if_fail (drawable != NULL);
g_return_if_fail (font != NULL);
g_return_if_fail (gc != NULL);
g_return_if_fail (text != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
if (text_length == 0)
return;
g_assert (font->type == GDK_FONT_FONT || font->type == GDK_FONT_FONTSET);
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
arg.x = x;
arg.y = y;
arg.hdc = gdk_gc_predraw (drawable_private, gc_private);
GDK_NOTE (MISC, g_print ("gdk_draw_text_wc: %#x (%d,%d) len: %d\n",
drawable_private->xwindow,
x, y, text_length));
if (sizeof (wchar_t) != sizeof (GdkWChar))
{
wcstr = g_new (wchar_t, text_length);
for (i = 0; i < text_length; i++)
wcstr[i] = text[i];
}
else
wcstr = (wchar_t *) text;
gdk_wchar_text_handle (font, wcstr, text_length,
gdk_draw_text_handler, &arg);
if (sizeof (wchar_t) != sizeof (GdkWChar))
g_free (wcstr);
gdk_gc_postdraw (drawable_private, gc_private);
}
void
gdk_draw_pixmap (GdkDrawable *drawable,
GdkGC *gc,
GdkPixmap *src,
gint xsrc,
gint ysrc,
gint xdest,
gint ydest,
gint width,
gint height)
{
GdkDrawablePrivate *drawable_private;
GdkDrawablePrivate *src_private;
GdkGCPrivate *gc_private;
HDC hdc;
HDC srcdc;
HGDIOBJ hgdiobj;
HRGN src_rgn, draw_rgn, outside_rgn;
RECT r;
g_return_if_fail (drawable != NULL);
g_return_if_fail (src != NULL);
g_return_if_fail (gc != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable) || GDK_DRAWABLE_DESTROYED (src))
return;
drawable_private = (GdkDrawablePrivate*) drawable;
src_private = (GdkDrawablePrivate*) src;
gc_private = (GdkGCPrivate*) gc;
if (width == -1)
width = src_private->width; /* Or should we subtract xsrc? */
if (height == -1)
height = src_private->height; /* Ditto? */
GDK_NOTE (MISC, g_print ("gdk_draw_pixmap: dest: %#x "
"src: %#x %dx%d@+%d+%d"
" dest: %#x @+%d+%d\n",
drawable_private->xwindow,
src_private->xwindow,
width, height, xsrc, ysrc,
drawable_private->xwindow, xdest, ydest));
hdc = gdk_gc_predraw (drawable_private, gc_private);
src_rgn = CreateRectRgn (0, 0, src_private->width + 1, src_private->height + 1);
draw_rgn = CreateRectRgn (xsrc, ysrc, xsrc + width + 1, ysrc + height + 1);
SetRectEmpty (&r);
outside_rgn = CreateRectRgnIndirect (&r);
if (drawable_private->window_type != GDK_DRAWABLE_PIXMAP)
{
/* If we are drawing on a window, calculate the region that is
* outside the source pixmap, and invalidate that, causing it to
* be cleared. XXX
*/
if (CombineRgn (outside_rgn, draw_rgn, src_rgn, RGN_DIFF) != NULLREGION)
{
OffsetRgn (outside_rgn, xdest, ydest);
GDK_NOTE (MISC, (GetRgnBox (outside_rgn, &r),
g_print ("...calling InvalidateRgn, "
"bbox: %dx%d@+%d+%d\n",
r.right - r.left - 1, r.bottom - r.top - 1,
r.left, r.top)));
InvalidateRgn (drawable_private->xwindow, outside_rgn, TRUE);
}
}
#if 1 /* Don't know if this is necessary */
if (CombineRgn (draw_rgn, draw_rgn, src_rgn, RGN_AND) == COMPLEXREGION)
g_warning ("gdk_draw_pixmap: CombineRgn returned a COMPLEXREGION");
GetRgnBox (draw_rgn, &r);
if (r.left != xsrc
|| r.top != ysrc
|| r.right != xsrc + width + 1
|| r.bottom != ysrc + height + 1)
{
xdest += r.left - xsrc;
xsrc = r.left;
ydest += r.top - ysrc;
ysrc = r.top;
width = r.right - xsrc - 1;
height = r.bottom - ysrc - 1;
GDK_NOTE (MISC, g_print ("... restricted to src: %dx%d@+%d+%d, "
"dest: @+%d+%d\n",
width, height, xsrc, ysrc,
xdest, ydest));
}
#endif
DeleteObject (src_rgn);
DeleteObject (draw_rgn);
DeleteObject (outside_rgn);
/* Strangely enough, this function is called also to bitblt
* from a window.
*/
if (src_private->window_type == GDK_DRAWABLE_PIXMAP)
{
if ((srcdc = CreateCompatibleDC (hdc)) == NULL)
g_warning ("gdk_draw_pixmap: CreateCompatibleDC failed");
if ((hgdiobj = SelectObject (srcdc, src_private->xwindow)) == NULL)
g_warning ("gdk_draw_pixmap: SelectObject #1 failed");
if (!BitBlt (hdc, xdest, ydest, width, height,
srcdc, xsrc, ysrc, SRCCOPY))
g_warning ("gdk_draw_pixmap: BitBlt failed");
if ((SelectObject (srcdc, hgdiobj) == NULL))
g_warning ("gdk_draw_pixmap: SelectObject #2 failed");
if (!DeleteDC (srcdc))
g_warning ("gdk_draw_pixmap: DeleteDC failed");
}
else
{
if (drawable_private->xwindow == src_private->xwindow)
{
/* Blitting inside a window, use ScrollDC */
RECT scrollRect, clipRect, emptyRect;
HRGN updateRgn;
scrollRect.left = MIN (xsrc, xdest);
scrollRect.top = MIN (ysrc, ydest);
scrollRect.right = MAX (xsrc + width + 1, xdest + width + 1);
scrollRect.bottom = MAX (ysrc + height + 1, ydest + height + 1);
clipRect.left = xdest;
clipRect.top = ydest;
clipRect.right = xdest + width + 1;
clipRect.bottom = ydest + height + 1;
SetRectEmpty (&emptyRect);
updateRgn = CreateRectRgnIndirect (&emptyRect);
if (!ScrollDC (hdc, xdest - xsrc, ydest - ysrc,
&scrollRect, &clipRect,
updateRgn, NULL))
g_warning ("gdk_draw_pixmap: ScrollDC failed");
if (!InvalidateRgn (drawable_private->xwindow, updateRgn, FALSE))
g_warning ("gdk_draw_pixmap: InvalidateRgn failed");
if (!UpdateWindow (drawable_private->xwindow))
g_warning ("gdk_draw_pixmap: UpdateWindow failed");
}
else
{
if ((srcdc = GetDC (src_private->xwindow)) == NULL)
g_warning ("gdk_draw_pixmap: GetDC failed");
if (!BitBlt (hdc, xdest, ydest, width, height,
srcdc, xsrc, ysrc, SRCCOPY))
g_warning ("gdk_draw_pixmap: BitBlt failed");
ReleaseDC (src_private->xwindow, srcdc);
}
}
gdk_gc_postdraw (drawable_private, gc_private);
}
void
gdk_draw_image (GdkDrawable *drawable,
GdkGC *gc,
GdkImage *image,
gint xsrc,
gint ysrc,
gint xdest,
gint ydest,
gint width,
gint height)
{
GdkImagePrivate *image_private;
g_return_if_fail (drawable != NULL);
g_return_if_fail (image != NULL);
g_return_if_fail (gc != NULL);
image_private = (GdkImagePrivate*) image;
g_return_if_fail (image_private->image_put != NULL);
if (width == -1)
width = image->width;
if (height == -1)
height = image->height;
(* image_private->image_put) (drawable, gc, image, xsrc, ysrc,
xdest, ydest, width, height);
}
void
gdk_draw_points (GdkDrawable *drawable,
GdkGC *gc,
GdkPoint *points,
gint npoints)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
HDC hdc;
int i;
g_return_if_fail (drawable != NULL);
g_return_if_fail ((points != NULL) && (npoints > 0));
g_return_if_fail (gc != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
hdc = gdk_gc_predraw (drawable_private, gc_private);
GDK_NOTE (MISC, g_print ("gdk_draw_points: %#x destdc: (%d) %#x "
"npoints: %d\n",
drawable_private->xwindow, gc_private, hdc,
npoints));
for (i = 0; i < npoints; i++)
{
if (!MoveToEx (hdc, points[i].x, points[i].y, NULL))
g_warning ("gdk_draw_points: MoveToEx failed");
if (!LineTo (hdc, points[i].x + 1, points[i].y))
g_warning ("gdk_draw_points: LineTo failed");
}
gdk_gc_postdraw (drawable_private, gc_private);
}
void
gdk_draw_segments (GdkDrawable *drawable,
GdkGC *gc,
GdkSegment *segs,
gint nsegs)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
HDC hdc;
int i;
if (nsegs <= 0)
return;
g_return_if_fail (drawable != NULL);
g_return_if_fail (segs != NULL);
g_return_if_fail (gc != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
hdc = gdk_gc_predraw (drawable_private, gc_private);
for (i = 0; i < nsegs; i++)
{
if (!MoveToEx (hdc, segs[i].x1, segs[i].y1, NULL))
g_warning ("gdk_draw_segments: MoveToEx failed");
if (!LineTo (hdc, segs[i].x2, segs[i].y2))
g_warning ("gdk_draw_segments: LineTo #1 failed");
/* Draw end pixel */
if (gc_private->pen_width == 1)
if (!LineTo (hdc, segs[i].x2 + 1, segs[i].y2))
g_warning ("gdk_draw_segments: LineTo #2 failed");
}
gdk_gc_postdraw (drawable_private, gc_private);
}
void
gdk_draw_lines (GdkDrawable *drawable,
GdkGC *gc,
GdkPoint *points,
gint npoints)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
HDC hdc;
POINT *pts;
int i;
if (npoints < 2)
return;
g_return_if_fail (drawable != NULL);
g_return_if_fail (points != NULL);
g_return_if_fail (gc != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
hdc = gdk_gc_predraw (drawable_private, gc_private);
#if 1
pts = g_malloc (npoints * sizeof (POINT));
for (i = 0; i < npoints; i++)
{
pts[i].x = points[i].x;
pts[i].y = points[i].y;
}
if (!Polyline (hdc, pts, npoints))
g_warning ("gdk_draw_lines: Polyline(,,%d) failed", npoints);
g_free (pts);
/* Draw end pixel */
if (gc_private->pen_width == 1)
{
MoveToEx (hdc, points[npoints-1].x, points[npoints-1].y, NULL);
if (!LineTo (hdc, points[npoints-1].x + 1, points[npoints-1].y))
g_warning ("gdk_draw_lines: LineTo failed");
}
#else
MoveToEx (hdc, points[0].x, points[0].y, NULL);
for (i = 1; i < npoints; i++)
if (!LineTo (hdc, points[i].x, points[i].y))
g_warning ("gdk_draw_lines: LineTo #1 failed");
/* Draw end pixel */
if (gc_private->pen_width == 1)
if (!LineTo (hdc, points[npoints-1].x + 1, points[npoints-1].y))
g_warning ("gdk_draw_lines: LineTo #2 failed");
#endif
gdk_gc_postdraw (drawable_private, gc_private);
}

View File

@ -0,0 +1,909 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include <math.h>
#include "gdkdrawable.h"
#include "gdkprivate.h"
#include "gdkwindow.h"
#include "gdkx.h"
#ifndef G_PI
#define G_PI 3.14159265358979323846
#endif
/* Manipulation of drawables
*/
void
gdk_drawable_set_data (GdkDrawable *drawable,
const gchar *key,
gpointer data,
GDestroyNotify destroy_func)
{
g_dataset_set_data_full (drawable, key, data, destroy_func);
}
void
gdk_drawable_get_data (GdkDrawable *drawable,
const gchar *key)
{
g_dataset_get_data (drawable, key);
}
GdkDrawableType
gdk_drawable_get_type (GdkDrawable *drawable)
{
g_return_val_if_fail (drawable != NULL, (GdkDrawableType) -1);
return GDK_DRAWABLE_TYPE (drawable);
}
void
gdk_drawable_get_size (GdkDrawable *drawable,
gint *width,
gint *height)
{
GdkDrawablePrivate *drawable_private;
g_return_if_fail (drawable != NULL);
drawable_private = (GdkDrawablePrivate*) drawable;
if (width)
*width = drawable_private->width;
if (height)
*height = drawable_private->height;
}
void
gdk_drawable_set_colormap (GdkDrawable *drawable,
GdkColormap *colormap)
{
GdkDrawablePrivate *drawable_private;
GdkColormapPrivate *colormap_private;
g_return_if_fail (drawable != NULL);
g_return_if_fail (colormap != NULL);
drawable_private = (GdkDrawablePrivate*) drawable;
colormap_private = (GdkColormapPrivate*) colormap;
if (!GDK_DRAWABLE_DESTROYED (drawable))
{
if (GDK_IS_WINDOW (drawable))
{
g_return_if_fail (colormap_private->visual !=
((GdkColormapPrivate*)(drawable_private->colormap))->visual);
/* XXX ??? */
GDK_NOTE (MISC, g_print ("gdk_drawable_set_colormap: %#x %#x\n",
GDK_DRAWABLE_XID (drawable),
colormap_private->xcolormap));
}
if (drawable_private->colormap)
gdk_colormap_unref (drawable_private->colormap);
drawable_private->colormap = colormap;
gdk_colormap_ref (drawable_private->colormap);
if (GDK_IS_WINDOW (drawable) &&
drawable_private->window_type != GDK_WINDOW_TOPLEVEL)
gdk_window_add_colormap_windows (drawable);
}
}
GdkColormap*
gdk_drawable_get_colormap (GdkDrawable *drawable)
{
GdkDrawablePrivate *drawable_private;
g_return_val_if_fail (drawable != NULL, NULL);
drawable_private = (GdkDrawablePrivate*) drawable;
if (!GDK_DRAWABLE_DESTROYED (drawable))
{
if (drawable_private->colormap == NULL)
return gdk_colormap_get_system (); /* XXX ??? */
else
return drawable_private->colormap;
}
return NULL;
}
GdkVisual*
gdk_drawable_get_visual (GdkDrawable *drawable)
{
GdkColormap *colormap;
g_return_val_if_fail (drawable != NULL, NULL);
colormap = gdk_drawable_get_colormap (drawable);
return colormap ? gdk_colormap_get_visual (colormap) : NULL;
}
void
gdk_draw_point (GdkDrawable *drawable,
GdkGC *gc,
gint x,
gint y)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
HDC hdc;
g_return_if_fail (drawable != NULL);
g_return_if_fail (gc != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
hdc = gdk_gc_predraw (drawable_private, gc_private);
/* We use LineTo because SetPixel wants the COLORREF directly,
* and doesn't use the current pen, which is what we want.
*/
if (!MoveToEx (hdc, x, y, NULL))
g_warning ("gdk_draw_point: MoveToEx failed");
if (!LineTo (hdc, x + 1, y))
g_warning ("gdk_draw_point: LineTo failed");
gdk_gc_postdraw (drawable_private, gc_private);
}
void
gdk_draw_line (GdkDrawable *drawable,
GdkGC *gc,
gint x1,
gint y1,
gint x2,
gint y2)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
HDC hdc;
g_return_if_fail (drawable != NULL);
g_return_if_fail (gc != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
hdc = gdk_gc_predraw (drawable_private, gc_private);
GDK_NOTE (MISC, g_print ("gdk_draw_line: %#x (%d) +%d+%d..+%d+%d\n",
drawable_private->xwindow, gc_private,
x1, y1, x2, y2));
MoveToEx (hdc, x1, y1, NULL);
if (!LineTo (hdc, x2, y2))
g_warning ("gdk_draw_line: LineTo #1 failed");
/* LineTo doesn't draw the last point, so if we have a pen width of 1,
* we draw the end pixel separately... With wider pens we don't care.
* //HB: But the NT developers don't read their API documentation ...
*/
if (gc_private->pen_width == 1 && windows_version > 0x80000000)
if (!LineTo (hdc, x2 + 1, y2))
g_warning ("gdk_draw_line: LineTo #2 failed");
gdk_gc_postdraw (drawable_private, gc_private);
}
void
gdk_draw_rectangle (GdkDrawable *drawable,
GdkGC *gc,
gint filled,
gint x,
gint y,
gint width,
gint height)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
HDC hdc;
HGDIOBJ oldpen, oldbrush;
g_return_if_fail (drawable != NULL);
g_return_if_fail (gc != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
if (width == -1)
width = drawable_private->width;
if (height == -1)
height = drawable_private->height;
hdc = gdk_gc_predraw (drawable_private, gc_private);
GDK_NOTE (MISC, g_print ("gdk_draw_rectangle: %#x (%d) %s%dx%d@+%d+%d\n",
drawable_private->xwindow,
gc_private,
(filled ? "fill " : ""),
width, height, x, y));
#if 0
{
HBRUSH hbr = GetCurrentObject (hdc, OBJ_BRUSH);
HPEN hpen = GetCurrentObject (hdc, OBJ_PEN);
LOGBRUSH lbr;
LOGPEN lpen;
GetObject (hbr, sizeof (lbr), &lbr);
GetObject (hpen, sizeof (lpen), &lpen);
g_print ("current brush: style = %s, color = 0x%.08x\n",
(lbr.lbStyle == BS_SOLID ? "SOLID" : "???"),
lbr.lbColor);
g_print ("current pen: style = %s, width = %d, color = 0x%.08x\n",
(lpen.lopnStyle == PS_SOLID ? "SOLID" : "???"),
lpen.lopnWidth,
lpen.lopnColor);
}
#endif
if (filled)
oldpen = SelectObject (hdc, GetStockObject (NULL_PEN));
else
oldbrush = SelectObject (hdc, GetStockObject (HOLLOW_BRUSH));
if (!Rectangle (hdc, x, y, x+width+1, y+height+1))
g_warning ("gdk_draw_rectangle: Rectangle failed");
if (filled)
SelectObject (hdc, oldpen);
else
SelectObject (hdc, oldbrush);
gdk_gc_postdraw (drawable_private, gc_private);
}
void
gdk_draw_arc (GdkDrawable *drawable,
GdkGC *gc,
gint filled,
gint x,
gint y,
gint width,
gint height,
gint angle1,
gint angle2)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
HDC hdc;
int nXStartArc, nYStartArc, nXEndArc, nYEndArc;
g_return_if_fail (drawable != NULL);
g_return_if_fail (gc != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
if (width == -1)
width = drawable_private->width;
if (height == -1)
height = drawable_private->height;
GDK_NOTE (MISC, g_print ("gdk_draw_arc: %#x %d,%d,%d,%d %d %d\n",
drawable_private->xwindow,
x, y, width, height, angle1, angle2));
if (width != 0 && height != 0 && angle2 != 0)
{
hdc = gdk_gc_predraw (drawable_private, gc_private);
if (angle2 >= 360*64)
{
nXStartArc = nYStartArc = nXEndArc = nYEndArc = 0;
}
else if (angle2 > 0)
{
/* The 100. is just an arbitrary value */
nXStartArc = x + width/2 + 100. * cos(angle1/64.*2.*G_PI/360.);
nYStartArc = y + height/2 + -100. * sin(angle1/64.*2.*G_PI/360.);
nXEndArc = x + width/2 + 100. * cos((angle1+angle2)/64.*2.*G_PI/360.);
nYEndArc = y + height/2 + -100. * sin((angle1+angle2)/64.*2.*G_PI/360.);
}
else
{
nXEndArc = x + width/2 + 100. * cos(angle1/64.*2.*G_PI/360.);
nYEndArc = y + height/2 + -100. * sin(angle1/64.*2.*G_PI/360.);
nXStartArc = x + width/2 + 100. * cos((angle1+angle2)/64.*2.*G_PI/360.);
nYStartArc = y + height/2 + -100. * sin((angle1+angle2)/64.*2.*G_PI/360.);
}
if (filled)
{
GDK_NOTE (MISC, g_print ("...Pie(hdc,%d,%d,%d,%d,%d,%d,%d,%d)\n",
x, y, x+width, y+height,
nXStartArc, nYStartArc,
nXEndArc, nYEndArc));
Pie (hdc, x, y, x+width, y+height,
nXStartArc, nYStartArc, nXEndArc, nYEndArc);
}
else
{
GDK_NOTE (MISC, g_print ("...Arc(hdc,%d,%d,%d,%d,%d,%d,%d,%d)\n",
x, y, x+width, y+height,
nXStartArc, nYStartArc,
nXEndArc, nYEndArc));
Arc (hdc, x, y, x+width, y+height,
nXStartArc, nYStartArc, nXEndArc, nYEndArc);
}
gdk_gc_postdraw (drawable_private, gc_private);
}
}
void
gdk_draw_polygon (GdkDrawable *drawable,
GdkGC *gc,
gint filled,
GdkPoint *points,
gint npoints)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
HDC hdc;
POINT *pts;
int i;
g_return_if_fail (drawable != NULL);
g_return_if_fail (gc != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
GDK_NOTE (MISC, g_print ("gdk_draw_polygon: %#x (%d) %d\n",
drawable_private->xwindow, gc_private,
npoints));
if (npoints < 2)
return;
hdc = gdk_gc_predraw (drawable_private, gc_private);
pts = g_malloc ((npoints+1) * sizeof (POINT));
for (i = 0; i < npoints; i++)
{
pts[i].x = points[i].x;
pts[i].y = points[i].y;
}
if ((points[0].x != points[npoints-1].x) ||
(points[0].y != points[npoints-1].y))
{
pts[npoints].x = points[0].x;
pts[npoints].y = points[0].y;
npoints++;
}
if (filled)
{
if (!Polygon (hdc, pts, npoints))
g_warning ("gdk_draw_polygon: Polygon failed");
}
else
{
if (!Polyline (hdc, pts, npoints))
g_warning ("gdk_draw_polygon: Polyline failed");
}
g_free (pts);
gdk_gc_postdraw (drawable_private, gc_private);
}
typedef struct
{
gint x, y;
HDC hdc;
} gdk_draw_text_arg;
/* gdk_draw_string
*/
void
gdk_draw_string (GdkDrawable *drawable,
GdkFont *font,
GdkGC *gc,
gint x,
gint y,
const gchar *string)
{
gdk_draw_text (drawable, font, gc, x, y, string, strlen (string));
}
static void
gdk_draw_text_handler (GdkWin32SingleFont *singlefont,
const wchar_t *wcstr,
int wclen,
void *arg)
{
HGDIOBJ oldfont;
SIZE size;
gdk_draw_text_arg *argp = (gdk_draw_text_arg *) arg;
if (!singlefont)
return;
if ((oldfont = SelectObject (argp->hdc, singlefont->xfont)) == NULL)
{
g_warning ("gdk_draw_text_handler: SelectObject failed");
return;
}
if (!TextOutW (argp->hdc, argp->x, argp->y, wcstr, wclen))
g_warning ("gdk_draw_text_handler: TextOutW failed");
GetTextExtentPoint32W (argp->hdc, wcstr, wclen, &size);
argp->x += size.cx;
SelectObject (argp->hdc, oldfont);
}
/* gdk_draw_text
*
*/
void
gdk_draw_text (GdkDrawable *drawable,
GdkFont *font,
GdkGC *gc,
gint x,
gint y,
const gchar *text,
gint text_length)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
wchar_t *wcstr;
gint wlen;
gdk_draw_text_arg arg;
g_return_if_fail (drawable != NULL);
g_return_if_fail (font != NULL);
g_return_if_fail (gc != NULL);
g_return_if_fail (text != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
if (text_length == 0)
return;
g_assert (font->type == GDK_FONT_FONT || font->type == GDK_FONT_FONTSET);
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
arg.x = x;
arg.y = y;
arg.hdc = gdk_gc_predraw (drawable_private, gc_private);
GDK_NOTE (MISC, g_print ("gdk_draw_text: %#x (%d,%d) \"%.*s\" (len %d)\n",
drawable_private->xwindow,
x, y,
(text_length > 10 ? 10 : text_length),
text, text_length));
wcstr = g_new (wchar_t, text_length);
if ((wlen = gdk_nmbstowchar_ts (wcstr, text, text_length, text_length)) == -1)
g_warning ("gdk_draw_text: gdk_nmbstowchar_ts failed");
else
gdk_wchar_text_handle (font, wcstr, wlen,
gdk_draw_text_handler, &arg);
g_free (wcstr);
gdk_gc_postdraw (drawable_private, gc_private);
}
void
gdk_draw_text_wc (GdkDrawable *drawable,
GdkFont *font,
GdkGC *gc,
gint x,
gint y,
const GdkWChar *text,
gint text_length)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
gint i, wlen;
wchar_t *wcstr;
gdk_draw_text_arg arg;
g_return_if_fail (drawable != NULL);
g_return_if_fail (font != NULL);
g_return_if_fail (gc != NULL);
g_return_if_fail (text != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
if (text_length == 0)
return;
g_assert (font->type == GDK_FONT_FONT || font->type == GDK_FONT_FONTSET);
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
arg.x = x;
arg.y = y;
arg.hdc = gdk_gc_predraw (drawable_private, gc_private);
GDK_NOTE (MISC, g_print ("gdk_draw_text_wc: %#x (%d,%d) len: %d\n",
drawable_private->xwindow,
x, y, text_length));
if (sizeof (wchar_t) != sizeof (GdkWChar))
{
wcstr = g_new (wchar_t, text_length);
for (i = 0; i < text_length; i++)
wcstr[i] = text[i];
}
else
wcstr = (wchar_t *) text;
gdk_wchar_text_handle (font, wcstr, text_length,
gdk_draw_text_handler, &arg);
if (sizeof (wchar_t) != sizeof (GdkWChar))
g_free (wcstr);
gdk_gc_postdraw (drawable_private, gc_private);
}
void
gdk_draw_pixmap (GdkDrawable *drawable,
GdkGC *gc,
GdkPixmap *src,
gint xsrc,
gint ysrc,
gint xdest,
gint ydest,
gint width,
gint height)
{
GdkDrawablePrivate *drawable_private;
GdkDrawablePrivate *src_private;
GdkGCPrivate *gc_private;
HDC hdc;
HDC srcdc;
HGDIOBJ hgdiobj;
HRGN src_rgn, draw_rgn, outside_rgn;
RECT r;
g_return_if_fail (drawable != NULL);
g_return_if_fail (src != NULL);
g_return_if_fail (gc != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable) || GDK_DRAWABLE_DESTROYED (src))
return;
drawable_private = (GdkDrawablePrivate*) drawable;
src_private = (GdkDrawablePrivate*) src;
gc_private = (GdkGCPrivate*) gc;
if (width == -1)
width = src_private->width; /* Or should we subtract xsrc? */
if (height == -1)
height = src_private->height; /* Ditto? */
GDK_NOTE (MISC, g_print ("gdk_draw_pixmap: dest: %#x "
"src: %#x %dx%d@+%d+%d"
" dest: %#x @+%d+%d\n",
drawable_private->xwindow,
src_private->xwindow,
width, height, xsrc, ysrc,
drawable_private->xwindow, xdest, ydest));
hdc = gdk_gc_predraw (drawable_private, gc_private);
src_rgn = CreateRectRgn (0, 0, src_private->width + 1, src_private->height + 1);
draw_rgn = CreateRectRgn (xsrc, ysrc, xsrc + width + 1, ysrc + height + 1);
SetRectEmpty (&r);
outside_rgn = CreateRectRgnIndirect (&r);
if (drawable_private->window_type != GDK_DRAWABLE_PIXMAP)
{
/* If we are drawing on a window, calculate the region that is
* outside the source pixmap, and invalidate that, causing it to
* be cleared. XXX
*/
if (CombineRgn (outside_rgn, draw_rgn, src_rgn, RGN_DIFF) != NULLREGION)
{
OffsetRgn (outside_rgn, xdest, ydest);
GDK_NOTE (MISC, (GetRgnBox (outside_rgn, &r),
g_print ("...calling InvalidateRgn, "
"bbox: %dx%d@+%d+%d\n",
r.right - r.left - 1, r.bottom - r.top - 1,
r.left, r.top)));
InvalidateRgn (drawable_private->xwindow, outside_rgn, TRUE);
}
}
#if 1 /* Don't know if this is necessary */
if (CombineRgn (draw_rgn, draw_rgn, src_rgn, RGN_AND) == COMPLEXREGION)
g_warning ("gdk_draw_pixmap: CombineRgn returned a COMPLEXREGION");
GetRgnBox (draw_rgn, &r);
if (r.left != xsrc
|| r.top != ysrc
|| r.right != xsrc + width + 1
|| r.bottom != ysrc + height + 1)
{
xdest += r.left - xsrc;
xsrc = r.left;
ydest += r.top - ysrc;
ysrc = r.top;
width = r.right - xsrc - 1;
height = r.bottom - ysrc - 1;
GDK_NOTE (MISC, g_print ("... restricted to src: %dx%d@+%d+%d, "
"dest: @+%d+%d\n",
width, height, xsrc, ysrc,
xdest, ydest));
}
#endif
DeleteObject (src_rgn);
DeleteObject (draw_rgn);
DeleteObject (outside_rgn);
/* Strangely enough, this function is called also to bitblt
* from a window.
*/
if (src_private->window_type == GDK_DRAWABLE_PIXMAP)
{
if ((srcdc = CreateCompatibleDC (hdc)) == NULL)
g_warning ("gdk_draw_pixmap: CreateCompatibleDC failed");
if ((hgdiobj = SelectObject (srcdc, src_private->xwindow)) == NULL)
g_warning ("gdk_draw_pixmap: SelectObject #1 failed");
if (!BitBlt (hdc, xdest, ydest, width, height,
srcdc, xsrc, ysrc, SRCCOPY))
g_warning ("gdk_draw_pixmap: BitBlt failed");
if ((SelectObject (srcdc, hgdiobj) == NULL))
g_warning ("gdk_draw_pixmap: SelectObject #2 failed");
if (!DeleteDC (srcdc))
g_warning ("gdk_draw_pixmap: DeleteDC failed");
}
else
{
if (drawable_private->xwindow == src_private->xwindow)
{
/* Blitting inside a window, use ScrollDC */
RECT scrollRect, clipRect, emptyRect;
HRGN updateRgn;
scrollRect.left = MIN (xsrc, xdest);
scrollRect.top = MIN (ysrc, ydest);
scrollRect.right = MAX (xsrc + width + 1, xdest + width + 1);
scrollRect.bottom = MAX (ysrc + height + 1, ydest + height + 1);
clipRect.left = xdest;
clipRect.top = ydest;
clipRect.right = xdest + width + 1;
clipRect.bottom = ydest + height + 1;
SetRectEmpty (&emptyRect);
updateRgn = CreateRectRgnIndirect (&emptyRect);
if (!ScrollDC (hdc, xdest - xsrc, ydest - ysrc,
&scrollRect, &clipRect,
updateRgn, NULL))
g_warning ("gdk_draw_pixmap: ScrollDC failed");
if (!InvalidateRgn (drawable_private->xwindow, updateRgn, FALSE))
g_warning ("gdk_draw_pixmap: InvalidateRgn failed");
if (!UpdateWindow (drawable_private->xwindow))
g_warning ("gdk_draw_pixmap: UpdateWindow failed");
}
else
{
if ((srcdc = GetDC (src_private->xwindow)) == NULL)
g_warning ("gdk_draw_pixmap: GetDC failed");
if (!BitBlt (hdc, xdest, ydest, width, height,
srcdc, xsrc, ysrc, SRCCOPY))
g_warning ("gdk_draw_pixmap: BitBlt failed");
ReleaseDC (src_private->xwindow, srcdc);
}
}
gdk_gc_postdraw (drawable_private, gc_private);
}
void
gdk_draw_image (GdkDrawable *drawable,
GdkGC *gc,
GdkImage *image,
gint xsrc,
gint ysrc,
gint xdest,
gint ydest,
gint width,
gint height)
{
GdkImagePrivate *image_private;
g_return_if_fail (drawable != NULL);
g_return_if_fail (image != NULL);
g_return_if_fail (gc != NULL);
image_private = (GdkImagePrivate*) image;
g_return_if_fail (image_private->image_put != NULL);
if (width == -1)
width = image->width;
if (height == -1)
height = image->height;
(* image_private->image_put) (drawable, gc, image, xsrc, ysrc,
xdest, ydest, width, height);
}
void
gdk_draw_points (GdkDrawable *drawable,
GdkGC *gc,
GdkPoint *points,
gint npoints)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
HDC hdc;
int i;
g_return_if_fail (drawable != NULL);
g_return_if_fail ((points != NULL) && (npoints > 0));
g_return_if_fail (gc != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
hdc = gdk_gc_predraw (drawable_private, gc_private);
GDK_NOTE (MISC, g_print ("gdk_draw_points: %#x destdc: (%d) %#x "
"npoints: %d\n",
drawable_private->xwindow, gc_private, hdc,
npoints));
for (i = 0; i < npoints; i++)
{
if (!MoveToEx (hdc, points[i].x, points[i].y, NULL))
g_warning ("gdk_draw_points: MoveToEx failed");
if (!LineTo (hdc, points[i].x + 1, points[i].y))
g_warning ("gdk_draw_points: LineTo failed");
}
gdk_gc_postdraw (drawable_private, gc_private);
}
void
gdk_draw_segments (GdkDrawable *drawable,
GdkGC *gc,
GdkSegment *segs,
gint nsegs)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
HDC hdc;
int i;
if (nsegs <= 0)
return;
g_return_if_fail (drawable != NULL);
g_return_if_fail (segs != NULL);
g_return_if_fail (gc != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
hdc = gdk_gc_predraw (drawable_private, gc_private);
for (i = 0; i < nsegs; i++)
{
if (!MoveToEx (hdc, segs[i].x1, segs[i].y1, NULL))
g_warning ("gdk_draw_segments: MoveToEx failed");
if (!LineTo (hdc, segs[i].x2, segs[i].y2))
g_warning ("gdk_draw_segments: LineTo #1 failed");
/* Draw end pixel */
if (gc_private->pen_width == 1)
if (!LineTo (hdc, segs[i].x2 + 1, segs[i].y2))
g_warning ("gdk_draw_segments: LineTo #2 failed");
}
gdk_gc_postdraw (drawable_private, gc_private);
}
void
gdk_draw_lines (GdkDrawable *drawable,
GdkGC *gc,
GdkPoint *points,
gint npoints)
{
GdkDrawablePrivate *drawable_private;
GdkGCPrivate *gc_private;
HDC hdc;
POINT *pts;
int i;
if (npoints < 2)
return;
g_return_if_fail (drawable != NULL);
g_return_if_fail (points != NULL);
g_return_if_fail (gc != NULL);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;
drawable_private = (GdkDrawablePrivate*) drawable;
gc_private = (GdkGCPrivate*) gc;
hdc = gdk_gc_predraw (drawable_private, gc_private);
#if 1
pts = g_malloc (npoints * sizeof (POINT));
for (i = 0; i < npoints; i++)
{
pts[i].x = points[i].x;
pts[i].y = points[i].y;
}
if (!Polyline (hdc, pts, npoints))
g_warning ("gdk_draw_lines: Polyline(,,%d) failed", npoints);
g_free (pts);
/* Draw end pixel */
if (gc_private->pen_width == 1)
{
MoveToEx (hdc, points[npoints-1].x, points[npoints-1].y, NULL);
if (!LineTo (hdc, points[npoints-1].x + 1, points[npoints-1].y))
g_warning ("gdk_draw_lines: LineTo failed");
}
#else
MoveToEx (hdc, points[0].x, points[0].y, NULL);
for (i = 1; i < npoints; i++)
if (!LineTo (hdc, points[i].x, points[i].y))
g_warning ("gdk_draw_lines: LineTo #1 failed");
/* Draw end pixel */
if (gc_private->pen_width == 1)
if (!LineTo (hdc, points[npoints-1].x + 1, points[npoints-1].y))
g_warning ("gdk_draw_lines: LineTo #2 failed");
#endif
gdk_gc_postdraw (drawable_private, gc_private);
}

5193
gdk/win32/gdkevents-win32.c Normal file

File diff suppressed because it is too large Load Diff

5193
gdk/win32/gdkevents.c Normal file

File diff suppressed because it is too large Load Diff

1501
gdk/win32/gdkfont-win32.c Normal file

File diff suppressed because it is too large Load Diff

1501
gdk/win32/gdkfont.c Normal file

File diff suppressed because it is too large Load Diff

1392
gdk/win32/gdkgc-win32.c Normal file

File diff suppressed because it is too large Load Diff

1392
gdk/win32/gdkgc.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,51 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "gdktypes.h"
#include "gdkprivate.h"
guint gdk_debug_flags = 0;
HWND gdk_root_window = NULL;
HWND gdk_leader_window;
GDKVAR GdkWindowPrivate *gdk_root_parent = NULL;
HDC gdk_DC;
HINSTANCE gdk_DLLInstance;
HINSTANCE gdk_ProgInstance;
UINT gdk_selection_notify_msg;
UINT gdk_selection_request_msg;
UINT gdk_selection_clear_msg;
GdkAtom gdk_clipboard_atom;
GdkAtom gdk_win32_dropfiles_atom;
GdkAtom gdk_ole2_dnd_atom;
Atom gdk_selection_property;
gchar *gdk_progclass = NULL;
gint gdk_error_code;
gint gdk_error_warnings = TRUE;
gint gdk_null_window_warnings = TRUE;
GMutex *gdk_threads_mutex = NULL;
DWORD windows_version = 0;

51
gdk/win32/gdkglobals.c Normal file
View File

@ -0,0 +1,51 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "gdktypes.h"
#include "gdkprivate.h"
guint gdk_debug_flags = 0;
HWND gdk_root_window = NULL;
HWND gdk_leader_window;
GDKVAR GdkWindowPrivate *gdk_root_parent = NULL;
HDC gdk_DC;
HINSTANCE gdk_DLLInstance;
HINSTANCE gdk_ProgInstance;
UINT gdk_selection_notify_msg;
UINT gdk_selection_request_msg;
UINT gdk_selection_clear_msg;
GdkAtom gdk_clipboard_atom;
GdkAtom gdk_win32_dropfiles_atom;
GdkAtom gdk_ole2_dnd_atom;
Atom gdk_selection_property;
gchar *gdk_progclass = NULL;
gint gdk_error_code;
gint gdk_error_warnings = TRUE;
gint gdk_null_window_warnings = TRUE;
GMutex *gdk_threads_mutex = NULL;
DWORD windows_version = 0;

394
gdk/win32/gdkim-win32.c Normal file
View File

@ -0,0 +1,394 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "gdkim.h"
#include "gdkpixmap.h"
#include "gdkprivate.h"
#include "gdki18n.h"
#include "gdkx.h"
/*
*--------------------------------------------------------------
* gdk_set_locale
*
* Arguments:
*
* Results:
*
* Side effects:
*
*--------------------------------------------------------------
*/
gchar*
gdk_set_locale (void)
{
gchar *current_locale;
if (!setlocale (LC_ALL,""))
g_warning ("locale not supported by C library");
current_locale = setlocale (LC_ALL, NULL);
return current_locale;
}
void
gdk_im_begin (GdkIC *ic, GdkWindow* window)
{
}
void
gdk_im_end (void)
{
}
GdkIMStyle
gdk_im_decide_style (GdkIMStyle supported_style)
{
return GDK_IM_PREEDIT_NONE | GDK_IM_STATUS_NONE;
}
GdkIMStyle
gdk_im_set_best_style (GdkIMStyle style)
{
return GDK_IM_PREEDIT_NONE | GDK_IM_STATUS_NONE;
}
gint
gdk_im_ready (void)
{
return FALSE;
}
GdkIC *
gdk_ic_new (GdkICAttr *attr, GdkICAttributesType mask)
{
return NULL;
}
void
gdk_ic_destroy (GdkIC *ic)
{
}
GdkIMStyle
gdk_ic_get_style (GdkIC *ic)
{
return GDK_IM_PREEDIT_NONE | GDK_IM_STATUS_NONE;
}
void
gdk_ic_set_values (GdkIC *ic, ...)
{
}
void
gdk_ic_get_values (GdkIC *ic, ...)
{
}
GdkICAttributesType
gdk_ic_set_attr (GdkIC *ic, GdkICAttr *attr, GdkICAttributesType mask)
{
return 0;
}
GdkICAttributesType
gdk_ic_get_attr (GdkIC *ic, GdkICAttr *attr, GdkICAttributesType mask)
{
return 0;
}
GdkEventMask
gdk_ic_get_events (GdkIC *ic)
{
return 0;
}
/*
* gdk_wcstombs
*
* Returns a multi-byte string converted from the specified array
* of wide characters. The string is newly allocated. The array of
* wide characters must be null-terminated. If the conversion is
* failed, it returns NULL.
*
* On Win32, we always use UTF-8.
*/
gchar *
gdk_wcstombs (const GdkWChar *src)
{
gint len;
const GdkWChar *wcp;
guchar *mbstr, *bp;
wcp = src;
len = 0;
while (*wcp)
{
const GdkWChar c = *wcp++;
if (c < 0x80)
len += 1;
else if (c < 0x800)
len += 2;
else if (c < 0x10000)
len += 3;
else if (c < 0x200000)
len += 4;
else if (c < 0x4000000)
len += 5;
else
len += 6;
}
mbstr = g_malloc (len + 1);
wcp = src;
bp = mbstr;
while (*wcp)
{
int first;
int i;
GdkWChar c = *wcp++;
if (c < 0x80)
{
first = 0;
len = 1;
}
else if (c < 0x800)
{
first = 0xc0;
len = 2;
}
else if (c < 0x10000)
{
first = 0xe0;
len = 3;
}
else if (c < 0x200000)
{
first = 0xf0;
len = 4;
}
else if (c < 0x4000000)
{
first = 0xf8;
len = 5;
}
else
{
first = 0xfc;
len = 6;
}
/* Woo-hoo! */
switch (len)
{
case 6: bp[5] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
case 5: bp[4] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
case 4: bp[3] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
case 3: bp[2] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
case 2: bp[1] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
case 1: bp[0] = c | first;
}
bp += len;
}
*bp = 0;
return mbstr;
}
/*
* gdk_mbstowcs
*
* Converts the specified string into GDK wide characters, and,
* returns the number of wide characters written. The string 'src'
* must be null-terminated. If the conversion is failed, it returns
* -1.
*
* On Win32, thr string is assumed to be in UTF-8. Also note that
* GdkWChar is 32 bits, while wchar_t, and the wide characters the
* Windows API uses, are 16 bits!
*/
/* First a helper function for not zero-terminated strings */
gint
gdk_nmbstowcs (GdkWChar *dest,
const gchar *src,
gint src_len,
gint dest_max)
{
guchar *cp, *end;
gint n;
cp = (guchar *) src;
end = cp + src_len;
n = 0;
while (cp != end && dest != dest + dest_max)
{
gint i, mask = 0, len;
guchar c = *cp;
if (c < 0x80)
{
len = 1;
mask = 0x7f;
}
else if ((c & 0xe0) == 0xc0)
{
len = 2;
mask = 0x1f;
}
else if ((c & 0xf0) == 0xe0)
{
len = 3;
mask = 0x0f;
}
else if ((c & 0xf8) == 0xf0)
{
len = 4;
mask = 0x07;
}
else if ((c & 0xfc) == 0xf8)
{
len = 5;
mask = 0x03;
}
else if ((c & 0xfc) == 0xfc)
{
len = 6;
mask = 0x01;
}
else
return -1;
if (cp + len > end)
return -1;
*dest = (cp[0] & mask);
for (i = 1; i < len; i++)
{
if ((cp[i] & 0xc0) != 0x80)
return -1;
*dest <<= 6;
*dest |= (cp[i] & 0x3f);
}
if (*dest == -1)
return -1;
cp += len;
dest++;
n++;
}
if (cp != end)
return -1;
return n;
}
gint
gdk_mbstowcs (GdkWChar *dest,
const gchar *src,
gint dest_max)
{
return gdk_nmbstowcs (dest, src, strlen (src), dest_max);
}
/* A version that converts to wchar_t wide chars */
gint
gdk_nmbstowchar_ts (wchar_t *dest,
const gchar *src,
gint src_len,
gint dest_max)
{
wchar_t *wcp;
guchar *cp, *end;
gint n;
wcp = dest;
cp = (guchar *) src;
end = cp + src_len;
n = 0;
while (cp != end && wcp != dest + dest_max)
{
gint i, mask = 0, len;
guchar c = *cp;
if (c < 0x80)
{
len = 1;
mask = 0x7f;
}
else if ((c & 0xe0) == 0xc0)
{
len = 2;
mask = 0x1f;
}
else if ((c & 0xf0) == 0xe0)
{
len = 3;
mask = 0x0f;
}
else /* Other lengths are not possible with 16-bit wchar_t! */
return -1;
if (cp + len > end)
return -1;
*wcp = (cp[0] & mask);
for (i = 1; i < len; i++)
{
if ((cp[i] & 0xc0) != 0x80)
return -1;
*wcp <<= 6;
*wcp |= (cp[i] & 0x3f);
}
if (*wcp == 0xFFFF)
return -1;
cp += len;
wcp++;
n++;
}
if (cp != end)
return -1;
return n;
}

394
gdk/win32/gdkim.c Normal file
View File

@ -0,0 +1,394 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "gdkim.h"
#include "gdkpixmap.h"
#include "gdkprivate.h"
#include "gdki18n.h"
#include "gdkx.h"
/*
*--------------------------------------------------------------
* gdk_set_locale
*
* Arguments:
*
* Results:
*
* Side effects:
*
*--------------------------------------------------------------
*/
gchar*
gdk_set_locale (void)
{
gchar *current_locale;
if (!setlocale (LC_ALL,""))
g_warning ("locale not supported by C library");
current_locale = setlocale (LC_ALL, NULL);
return current_locale;
}
void
gdk_im_begin (GdkIC *ic, GdkWindow* window)
{
}
void
gdk_im_end (void)
{
}
GdkIMStyle
gdk_im_decide_style (GdkIMStyle supported_style)
{
return GDK_IM_PREEDIT_NONE | GDK_IM_STATUS_NONE;
}
GdkIMStyle
gdk_im_set_best_style (GdkIMStyle style)
{
return GDK_IM_PREEDIT_NONE | GDK_IM_STATUS_NONE;
}
gint
gdk_im_ready (void)
{
return FALSE;
}
GdkIC *
gdk_ic_new (GdkICAttr *attr, GdkICAttributesType mask)
{
return NULL;
}
void
gdk_ic_destroy (GdkIC *ic)
{
}
GdkIMStyle
gdk_ic_get_style (GdkIC *ic)
{
return GDK_IM_PREEDIT_NONE | GDK_IM_STATUS_NONE;
}
void
gdk_ic_set_values (GdkIC *ic, ...)
{
}
void
gdk_ic_get_values (GdkIC *ic, ...)
{
}
GdkICAttributesType
gdk_ic_set_attr (GdkIC *ic, GdkICAttr *attr, GdkICAttributesType mask)
{
return 0;
}
GdkICAttributesType
gdk_ic_get_attr (GdkIC *ic, GdkICAttr *attr, GdkICAttributesType mask)
{
return 0;
}
GdkEventMask
gdk_ic_get_events (GdkIC *ic)
{
return 0;
}
/*
* gdk_wcstombs
*
* Returns a multi-byte string converted from the specified array
* of wide characters. The string is newly allocated. The array of
* wide characters must be null-terminated. If the conversion is
* failed, it returns NULL.
*
* On Win32, we always use UTF-8.
*/
gchar *
gdk_wcstombs (const GdkWChar *src)
{
gint len;
const GdkWChar *wcp;
guchar *mbstr, *bp;
wcp = src;
len = 0;
while (*wcp)
{
const GdkWChar c = *wcp++;
if (c < 0x80)
len += 1;
else if (c < 0x800)
len += 2;
else if (c < 0x10000)
len += 3;
else if (c < 0x200000)
len += 4;
else if (c < 0x4000000)
len += 5;
else
len += 6;
}
mbstr = g_malloc (len + 1);
wcp = src;
bp = mbstr;
while (*wcp)
{
int first;
int i;
GdkWChar c = *wcp++;
if (c < 0x80)
{
first = 0;
len = 1;
}
else if (c < 0x800)
{
first = 0xc0;
len = 2;
}
else if (c < 0x10000)
{
first = 0xe0;
len = 3;
}
else if (c < 0x200000)
{
first = 0xf0;
len = 4;
}
else if (c < 0x4000000)
{
first = 0xf8;
len = 5;
}
else
{
first = 0xfc;
len = 6;
}
/* Woo-hoo! */
switch (len)
{
case 6: bp[5] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
case 5: bp[4] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
case 4: bp[3] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
case 3: bp[2] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
case 2: bp[1] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
case 1: bp[0] = c | first;
}
bp += len;
}
*bp = 0;
return mbstr;
}
/*
* gdk_mbstowcs
*
* Converts the specified string into GDK wide characters, and,
* returns the number of wide characters written. The string 'src'
* must be null-terminated. If the conversion is failed, it returns
* -1.
*
* On Win32, thr string is assumed to be in UTF-8. Also note that
* GdkWChar is 32 bits, while wchar_t, and the wide characters the
* Windows API uses, are 16 bits!
*/
/* First a helper function for not zero-terminated strings */
gint
gdk_nmbstowcs (GdkWChar *dest,
const gchar *src,
gint src_len,
gint dest_max)
{
guchar *cp, *end;
gint n;
cp = (guchar *) src;
end = cp + src_len;
n = 0;
while (cp != end && dest != dest + dest_max)
{
gint i, mask = 0, len;
guchar c = *cp;
if (c < 0x80)
{
len = 1;
mask = 0x7f;
}
else if ((c & 0xe0) == 0xc0)
{
len = 2;
mask = 0x1f;
}
else if ((c & 0xf0) == 0xe0)
{
len = 3;
mask = 0x0f;
}
else if ((c & 0xf8) == 0xf0)
{
len = 4;
mask = 0x07;
}
else if ((c & 0xfc) == 0xf8)
{
len = 5;
mask = 0x03;
}
else if ((c & 0xfc) == 0xfc)
{
len = 6;
mask = 0x01;
}
else
return -1;
if (cp + len > end)
return -1;
*dest = (cp[0] & mask);
for (i = 1; i < len; i++)
{
if ((cp[i] & 0xc0) != 0x80)
return -1;
*dest <<= 6;
*dest |= (cp[i] & 0x3f);
}
if (*dest == -1)
return -1;
cp += len;
dest++;
n++;
}
if (cp != end)
return -1;
return n;
}
gint
gdk_mbstowcs (GdkWChar *dest,
const gchar *src,
gint dest_max)
{
return gdk_nmbstowcs (dest, src, strlen (src), dest_max);
}
/* A version that converts to wchar_t wide chars */
gint
gdk_nmbstowchar_ts (wchar_t *dest,
const gchar *src,
gint src_len,
gint dest_max)
{
wchar_t *wcp;
guchar *cp, *end;
gint n;
wcp = dest;
cp = (guchar *) src;
end = cp + src_len;
n = 0;
while (cp != end && wcp != dest + dest_max)
{
gint i, mask = 0, len;
guchar c = *cp;
if (c < 0x80)
{
len = 1;
mask = 0x7f;
}
else if ((c & 0xe0) == 0xc0)
{
len = 2;
mask = 0x1f;
}
else if ((c & 0xf0) == 0xe0)
{
len = 3;
mask = 0x0f;
}
else /* Other lengths are not possible with 16-bit wchar_t! */
return -1;
if (cp + len > end)
return -1;
*wcp = (cp[0] & mask);
for (i = 1; i < len; i++)
{
if ((cp[i] & 0xc0) != 0x80)
return -1;
*wcp <<= 6;
*wcp |= (cp[i] & 0x3f);
}
if (*wcp == 0xFFFF)
return -1;
cp += len;
wcp++;
n++;
}
if (cp != end)
return -1;
return n;
}

1685
gdk/win32/gdkinput-win32.c Normal file

File diff suppressed because it is too large Load Diff

1685
gdk/win32/gdkinput.c Normal file

File diff suppressed because it is too large Load Diff

2115
gdk/win32/gdkmain-win32.c Normal file

File diff suppressed because it is too large Load Diff

1002
gdk/win32/gdkpixmap-win32.c Normal file

File diff suppressed because it is too large Load Diff

1002
gdk/win32/gdkpixmap.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,459 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#ifndef __GDK_PRIVATE_H__
#define __GDK_PRIVATE_H__
#define STRICT /* We want strict type checks */
#include <windows.h>
#include <commctrl.h>
/* Make up for some minor mingw32 lossage */
/* PS_JOIN_MASK is missing from the mingw32 headers */
#ifndef PS_JOIN_MASK
#define PS_JOIN_MASK (PS_JOIN_BEVEL|PS_JOIN_MITER|PS_JOIN_ROUND)
#endif
/* CLR_INVALID is missing */
#ifndef CLR_INVALID
#define CLR_INVALID CLR_NONE
#endif
/* Some charsets are missing */
#ifndef JOHAB_CHARSET
#define JOHAB_CHARSET 130
#endif
#ifndef VIETNAMESE_CHARSET
#define VIETNAMESE_CHARSET 163
#endif
#ifndef VM_OEM_PLUS
#define VK_OEM_PLUS 0xBB
#endif
#include <time.h>
#include <gdk/gdktypes.h>
#include <gdk/gdkcursor.h>
#include <gdk/gdkevents.h>
#include <gdk/gdkfont.h>
#include <gdk/gdkgc.h>
#include <gdk/gdkim.h>
#include <gdk/gdkimage.h>
#include <gdk/gdkregion.h>
#include <gdk/gdkvisual.h>
#include <gdk/gdkwindow.h>
#define GDK_DRAWABLE_TYPE(d) (((GdkDrawablePrivate *)d)->window_type)
#define GDK_IS_WINDOW(d) (GDK_DRAWABLE_TYPE(d) <= GDK_WINDOW_TEMP || \
GDK_DRAWABLE_TYPE(d) == GDK_WINDOW_FOREIGN)
#define GDK_IS_PIXMAP(d) (GDK_DRAWABLE_TYPE(d) == GDK_DRAWABLE_PIXMAP)
#define GDK_DRAWABLE_DESTROYED(d) (((GdkDrawablePrivate *)d)->destroyed)
#define gdk_window_lookup(xid) ((GdkWindow*) gdk_xid_table_lookup (xid))
#define gdk_pixmap_lookup(xid) ((GdkPixmap*) gdk_xid_table_lookup (xid))
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Define corresponding Windows types for some X11 types, just for laziness.
*/
typedef HANDLE XID;
typedef PALETTEENTRY XColor;
typedef HDC GC;
typedef ATOM Atom;
typedef HCURSOR Cursor;
typedef guint VisualID;
typedef DWORD KeySym;
typedef int Status;
/* Define some of the X11 constants also here, again just for laziness */
/* Generic null resource */
#define None 0
/* Error codes */
#define Success 0
/* Grabbing status */
#define GrabSuccess 0
#define AlreadyGrabbed 2
/* For CreateColormap */
#define AllocNone 0
#define AllocAll 1
/* Some structs are somewhat useful to emulate internally, just to
keep the code less #ifdefed. */
typedef struct {
HPALETTE palette; /* Palette handle used when drawing. */
guint size; /* Number of entries in the palette. */
gboolean stale; /* 1 if palette needs to be realized,
* otherwise 0. */
gboolean *in_use;
gboolean rc_palette; /* If RC_PALETTE is on in the RASTERCAPS */
gulong sizepalette; /* SIZEPALETTE if rc_palette */
} ColormapStruct, *Colormap;
typedef struct {
gint map_entries;
guint visualid;
guint bitspixel;
} Visual;
typedef struct {
Colormap colormap;
unsigned long red_max;
unsigned long red_mult;
unsigned long green_max;
unsigned long green_mult;
unsigned long blue_max;
unsigned long blue_mult;
unsigned long base_pixel;
} XStandardColormap;
typedef struct _GdkDrawablePrivate GdkDrawablePrivate;
/* typedef struct _GdkDrawablePrivate GdkPixmapPrivate; */
typedef struct _GdkWindowPrivate GdkWindowPrivate;
typedef struct _GdkImagePrivate GdkImagePrivate;
typedef struct _GdkGCPrivate GdkGCPrivate;
typedef struct _GdkColormapPrivate GdkColormapPrivate;
typedef struct _GdkColorInfo GdkColorInfo;
typedef struct _GdkVisualPrivate GdkVisualPrivate;
typedef struct _GdkFontPrivate GdkFontPrivate;
typedef struct _GdkCursorPrivate GdkCursorPrivate;
typedef struct _GdkEventFilter GdkEventFilter;
typedef struct _GdkClientFilter GdkClientFilter;
typedef struct _GdkRegionPrivate GdkRegionPrivate;
struct _GdkDrawablePrivate
{
GdkDrawable drawable;
guint8 window_type;
guint ref_count;
guint16 width;
guint16 height;
HANDLE xwindow;
GdkColormap *colormap;
guint destroyed : 2;
};
struct _GdkWindowPrivate
{
GdkDrawablePrivate drawable;
GdkWindow *parent;
gint16 x;
gint16 y;
guint8 resize_count;
guint mapped : 1;
guint guffaw_gravity : 1;
/* We must keep the event mask here to filter them ourselves */
gint event_mask;
/* Values for bg_type */
#define GDK_WIN32_BG_NORMAL 0
#define GDK_WIN32_BG_PIXEL 1
#define GDK_WIN32_BG_PIXMAP 2
#define GDK_WIN32_BG_PARENT_RELATIVE 3
#define GDK_WIN32_BG_TRANSPARENT 4
/* We draw the background ourselves at WM_ERASEBKGND */
guchar bg_type;
GdkColor bg_pixel;
GdkPixmap *bg_pixmap;
HCURSOR xcursor;
/* Window size hints */
gint hint_flags;
gint hint_x, hint_y;
gint hint_min_width, hint_min_height;
gint hint_max_width, hint_max_height;
gint extension_events;
gboolean extension_events_selected;
GList *filters;
GList *children;
HKL input_locale;
CHARSETINFO charset_info;
};
struct _GdkImagePrivate
{
GdkImage image;
HBITMAP ximage;
gpointer x_shm_info;
void (*image_put) (GdkDrawable *window,
GdkGC *gc,
GdkImage *image,
gint xsrc,
gint ysrc,
gint xdest,
gint ydest,
gint width,
gint height);
};
struct _GdkGCPrivate
{
GdkGC gc;
GC xgc;
/* A Windows Device Context (DC) is not equivalent to an X11
* GC. We can use a DC only in the window for which it was
* allocated, or (in the case of a memory DC) with the bitmap that
* has been selected into it. Thus, we have to release and
* reallocate a DC each time the GdkGC is used to paint into a new
* window or pixmap. We thus keep all the necessary values in the
* GdkGCPrivate struct.
*/
GdkGCValuesMask values_mask;
GdkColor foreground;
GdkColor background;
GdkFont *font;
gint rop2;
GdkFill fill_style;
GdkPixmap *tile;
GdkPixmap *stipple;
HRGN clip_region;
GdkSubwindowMode subwindow_mode;
gint ts_x_origin;
gint ts_y_origin;
gint clip_x_origin;
gint clip_y_origin;
gint graphics_exposures;
gint pen_width;
DWORD pen_style;
HANDLE hwnd; /* If a DC is allocated, for which window
or what bitmap is selected into it */
int saved_dc;
guint ref_count;
};
typedef enum {
GDK_COLOR_WRITEABLE = 1 << 0
} GdkColorInfoFlags;
struct _GdkColorInfo
{
GdkColorInfoFlags flags;
guint ref_count;
};
struct _GdkColormapPrivate
{
GdkColormap colormap;
Colormap xcolormap;
GdkVisual *visual;
gint private_val;
GHashTable *hash;
GdkColorInfo *info;
time_t last_sync_time;
guint ref_count;
};
struct _GdkVisualPrivate
{
GdkVisual visual;
Visual *xvisual;
};
typedef struct
{
HFONT xfont;
DWORD charset;
UINT codepage;
CPINFO cpinfo;
FONTSIGNATURE fs;
} GdkWin32SingleFont;
struct _GdkFontPrivate
{
GdkFont font;
guint ref_count;
GSList *fonts;
GSList *names;
};
struct _GdkCursorPrivate
{
GdkCursor cursor;
Cursor xcursor;
};
struct _GdkEventFilter {
GdkFilterFunc function;
gpointer data;
};
struct _GdkClientFilter {
GdkAtom type;
GdkFilterFunc function;
gpointer data;
};
struct _GdkRegionPrivate
{
GdkRegion region;
HRGN xregion;
};
typedef enum {
GDK_DEBUG_MISC = 1 << 0,
GDK_DEBUG_EVENTS = 1 << 1,
GDK_DEBUG_DND = 1 << 2,
GDK_DEBUG_COLOR_CONTEXT = 1 << 3,
GDK_DEBUG_XIM = 1 << 4,
GDK_DEBUG_SELECTION = 1 << 5
} GdkDebugFlag;
void gdk_events_init (void);
void gdk_window_init (void);
void gdk_visual_init (void);
void gdk_selection_init (void);
void gdk_dnd_init (void);
void gdk_dnd_exit (void);
void gdk_image_init (void);
void gdk_image_exit (void);
GdkColormap* gdk_colormap_lookup (Colormap xcolormap);
GdkVisual* gdk_visual_lookup (Visual *xvisual);
void gdk_window_add_colormap_windows (GdkWindow *window);
void gdk_window_destroy_notify (GdkWindow *window);
void gdk_xid_table_insert (XID *xid,
gpointer data);
void gdk_xid_table_remove (XID xid);
gpointer gdk_xid_table_lookup (XID xid);
/* Internal functions */
HDC gdk_gc_predraw (GdkDrawablePrivate *drawable_private,
GdkGCPrivate *gc_private);
void gdk_gc_postdraw (GdkDrawablePrivate *drawable_private,
GdkGCPrivate *gc_private);
HRGN BitmapToRegion (HBITMAP hBmp);
void gdk_sel_prop_store (GdkWindow *owner,
GdkAtom type,
gint format,
guchar *data,
gint length);
void gdk_event_queue_append (GdkEvent *event);
gint gdk_nmbstowcs (GdkWChar *dest,
const gchar *src,
gint src_len,
gint dest_max);
gint gdk_nmbstowchar_ts (wchar_t *dest,
const gchar *src,
gint src_len,
gint dest_max);
void gdk_wchar_text_handle (GdkFont *font,
const wchar_t *wcstr,
int wclen,
void (*handler)(GdkWin32SingleFont *,
const wchar_t *,
int,
void *),
void *arg);
/* Please see gdkwindow.c for comments on how to use */
HWND gdk_window_xid_at(HWND base, gint bx, gint by, gint x, gint y, GList *excludes, gboolean excl_child);
HWND gdk_window_xid_at_coords(gint x, gint y, GList *excludes, gboolean excl_child);
extern gint gdk_debug_level;
extern gint gdk_show_events;
extern gint gdk_stack_trace;
extern HWND gdk_root_window;
extern HWND gdk_leader_window;
GDKVAR GdkWindowPrivate *gdk_root_parent;
GDKVAR Atom gdk_selection_property;
GDKVAR gchar *gdk_progclass;
GDKVAR gint gdk_error_code;
GDKVAR gint gdk_error_warnings;
GDKVAR gint gdk_null_window_warnings;
extern gint gdk_event_func_from_window_proc;
extern HDC gdk_DC;
extern HINSTANCE gdk_DLLInstance;
extern HINSTANCE gdk_ProgInstance;
extern UINT gdk_selection_notify_msg;
extern UINT gdk_selection_request_msg;
extern UINT gdk_selection_clear_msg;
extern GdkAtom gdk_clipboard_atom;
extern GdkAtom gdk_win32_dropfiles_atom;
extern GdkAtom gdk_ole2_dnd_atom;
extern LRESULT CALLBACK gdk_WindowProc (HWND, UINT, WPARAM, LPARAM);
extern DWORD windows_version;
/* Debugging support */
#ifdef G_ENABLE_DEBUG
#define GDK_NOTE(type,action) G_STMT_START { \
if (gdk_debug_flags & GDK_DEBUG_##type) \
{ action; }; } G_STMT_END
#else /* !G_ENABLE_DEBUG */
#define GDK_NOTE(type,action)
#endif /* G_ENABLE_DEBUG */
GDKVAR guint gdk_debug_flags;
/* Internal functions for debug output etc. */
char *gdk_color_to_string (GdkColor *);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __GDK_PRIVATE_H__ */

459
gdk/win32/gdkprivate.h Normal file
View File

@ -0,0 +1,459 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#ifndef __GDK_PRIVATE_H__
#define __GDK_PRIVATE_H__
#define STRICT /* We want strict type checks */
#include <windows.h>
#include <commctrl.h>
/* Make up for some minor mingw32 lossage */
/* PS_JOIN_MASK is missing from the mingw32 headers */
#ifndef PS_JOIN_MASK
#define PS_JOIN_MASK (PS_JOIN_BEVEL|PS_JOIN_MITER|PS_JOIN_ROUND)
#endif
/* CLR_INVALID is missing */
#ifndef CLR_INVALID
#define CLR_INVALID CLR_NONE
#endif
/* Some charsets are missing */
#ifndef JOHAB_CHARSET
#define JOHAB_CHARSET 130
#endif
#ifndef VIETNAMESE_CHARSET
#define VIETNAMESE_CHARSET 163
#endif
#ifndef VM_OEM_PLUS
#define VK_OEM_PLUS 0xBB
#endif
#include <time.h>
#include <gdk/gdktypes.h>
#include <gdk/gdkcursor.h>
#include <gdk/gdkevents.h>
#include <gdk/gdkfont.h>
#include <gdk/gdkgc.h>
#include <gdk/gdkim.h>
#include <gdk/gdkimage.h>
#include <gdk/gdkregion.h>
#include <gdk/gdkvisual.h>
#include <gdk/gdkwindow.h>
#define GDK_DRAWABLE_TYPE(d) (((GdkDrawablePrivate *)d)->window_type)
#define GDK_IS_WINDOW(d) (GDK_DRAWABLE_TYPE(d) <= GDK_WINDOW_TEMP || \
GDK_DRAWABLE_TYPE(d) == GDK_WINDOW_FOREIGN)
#define GDK_IS_PIXMAP(d) (GDK_DRAWABLE_TYPE(d) == GDK_DRAWABLE_PIXMAP)
#define GDK_DRAWABLE_DESTROYED(d) (((GdkDrawablePrivate *)d)->destroyed)
#define gdk_window_lookup(xid) ((GdkWindow*) gdk_xid_table_lookup (xid))
#define gdk_pixmap_lookup(xid) ((GdkPixmap*) gdk_xid_table_lookup (xid))
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Define corresponding Windows types for some X11 types, just for laziness.
*/
typedef HANDLE XID;
typedef PALETTEENTRY XColor;
typedef HDC GC;
typedef ATOM Atom;
typedef HCURSOR Cursor;
typedef guint VisualID;
typedef DWORD KeySym;
typedef int Status;
/* Define some of the X11 constants also here, again just for laziness */
/* Generic null resource */
#define None 0
/* Error codes */
#define Success 0
/* Grabbing status */
#define GrabSuccess 0
#define AlreadyGrabbed 2
/* For CreateColormap */
#define AllocNone 0
#define AllocAll 1
/* Some structs are somewhat useful to emulate internally, just to
keep the code less #ifdefed. */
typedef struct {
HPALETTE palette; /* Palette handle used when drawing. */
guint size; /* Number of entries in the palette. */
gboolean stale; /* 1 if palette needs to be realized,
* otherwise 0. */
gboolean *in_use;
gboolean rc_palette; /* If RC_PALETTE is on in the RASTERCAPS */
gulong sizepalette; /* SIZEPALETTE if rc_palette */
} ColormapStruct, *Colormap;
typedef struct {
gint map_entries;
guint visualid;
guint bitspixel;
} Visual;
typedef struct {
Colormap colormap;
unsigned long red_max;
unsigned long red_mult;
unsigned long green_max;
unsigned long green_mult;
unsigned long blue_max;
unsigned long blue_mult;
unsigned long base_pixel;
} XStandardColormap;
typedef struct _GdkDrawablePrivate GdkDrawablePrivate;
/* typedef struct _GdkDrawablePrivate GdkPixmapPrivate; */
typedef struct _GdkWindowPrivate GdkWindowPrivate;
typedef struct _GdkImagePrivate GdkImagePrivate;
typedef struct _GdkGCPrivate GdkGCPrivate;
typedef struct _GdkColormapPrivate GdkColormapPrivate;
typedef struct _GdkColorInfo GdkColorInfo;
typedef struct _GdkVisualPrivate GdkVisualPrivate;
typedef struct _GdkFontPrivate GdkFontPrivate;
typedef struct _GdkCursorPrivate GdkCursorPrivate;
typedef struct _GdkEventFilter GdkEventFilter;
typedef struct _GdkClientFilter GdkClientFilter;
typedef struct _GdkRegionPrivate GdkRegionPrivate;
struct _GdkDrawablePrivate
{
GdkDrawable drawable;
guint8 window_type;
guint ref_count;
guint16 width;
guint16 height;
HANDLE xwindow;
GdkColormap *colormap;
guint destroyed : 2;
};
struct _GdkWindowPrivate
{
GdkDrawablePrivate drawable;
GdkWindow *parent;
gint16 x;
gint16 y;
guint8 resize_count;
guint mapped : 1;
guint guffaw_gravity : 1;
/* We must keep the event mask here to filter them ourselves */
gint event_mask;
/* Values for bg_type */
#define GDK_WIN32_BG_NORMAL 0
#define GDK_WIN32_BG_PIXEL 1
#define GDK_WIN32_BG_PIXMAP 2
#define GDK_WIN32_BG_PARENT_RELATIVE 3
#define GDK_WIN32_BG_TRANSPARENT 4
/* We draw the background ourselves at WM_ERASEBKGND */
guchar bg_type;
GdkColor bg_pixel;
GdkPixmap *bg_pixmap;
HCURSOR xcursor;
/* Window size hints */
gint hint_flags;
gint hint_x, hint_y;
gint hint_min_width, hint_min_height;
gint hint_max_width, hint_max_height;
gint extension_events;
gboolean extension_events_selected;
GList *filters;
GList *children;
HKL input_locale;
CHARSETINFO charset_info;
};
struct _GdkImagePrivate
{
GdkImage image;
HBITMAP ximage;
gpointer x_shm_info;
void (*image_put) (GdkDrawable *window,
GdkGC *gc,
GdkImage *image,
gint xsrc,
gint ysrc,
gint xdest,
gint ydest,
gint width,
gint height);
};
struct _GdkGCPrivate
{
GdkGC gc;
GC xgc;
/* A Windows Device Context (DC) is not equivalent to an X11
* GC. We can use a DC only in the window for which it was
* allocated, or (in the case of a memory DC) with the bitmap that
* has been selected into it. Thus, we have to release and
* reallocate a DC each time the GdkGC is used to paint into a new
* window or pixmap. We thus keep all the necessary values in the
* GdkGCPrivate struct.
*/
GdkGCValuesMask values_mask;
GdkColor foreground;
GdkColor background;
GdkFont *font;
gint rop2;
GdkFill fill_style;
GdkPixmap *tile;
GdkPixmap *stipple;
HRGN clip_region;
GdkSubwindowMode subwindow_mode;
gint ts_x_origin;
gint ts_y_origin;
gint clip_x_origin;
gint clip_y_origin;
gint graphics_exposures;
gint pen_width;
DWORD pen_style;
HANDLE hwnd; /* If a DC is allocated, for which window
or what bitmap is selected into it */
int saved_dc;
guint ref_count;
};
typedef enum {
GDK_COLOR_WRITEABLE = 1 << 0
} GdkColorInfoFlags;
struct _GdkColorInfo
{
GdkColorInfoFlags flags;
guint ref_count;
};
struct _GdkColormapPrivate
{
GdkColormap colormap;
Colormap xcolormap;
GdkVisual *visual;
gint private_val;
GHashTable *hash;
GdkColorInfo *info;
time_t last_sync_time;
guint ref_count;
};
struct _GdkVisualPrivate
{
GdkVisual visual;
Visual *xvisual;
};
typedef struct
{
HFONT xfont;
DWORD charset;
UINT codepage;
CPINFO cpinfo;
FONTSIGNATURE fs;
} GdkWin32SingleFont;
struct _GdkFontPrivate
{
GdkFont font;
guint ref_count;
GSList *fonts;
GSList *names;
};
struct _GdkCursorPrivate
{
GdkCursor cursor;
Cursor xcursor;
};
struct _GdkEventFilter {
GdkFilterFunc function;
gpointer data;
};
struct _GdkClientFilter {
GdkAtom type;
GdkFilterFunc function;
gpointer data;
};
struct _GdkRegionPrivate
{
GdkRegion region;
HRGN xregion;
};
typedef enum {
GDK_DEBUG_MISC = 1 << 0,
GDK_DEBUG_EVENTS = 1 << 1,
GDK_DEBUG_DND = 1 << 2,
GDK_DEBUG_COLOR_CONTEXT = 1 << 3,
GDK_DEBUG_XIM = 1 << 4,
GDK_DEBUG_SELECTION = 1 << 5
} GdkDebugFlag;
void gdk_events_init (void);
void gdk_window_init (void);
void gdk_visual_init (void);
void gdk_selection_init (void);
void gdk_dnd_init (void);
void gdk_dnd_exit (void);
void gdk_image_init (void);
void gdk_image_exit (void);
GdkColormap* gdk_colormap_lookup (Colormap xcolormap);
GdkVisual* gdk_visual_lookup (Visual *xvisual);
void gdk_window_add_colormap_windows (GdkWindow *window);
void gdk_window_destroy_notify (GdkWindow *window);
void gdk_xid_table_insert (XID *xid,
gpointer data);
void gdk_xid_table_remove (XID xid);
gpointer gdk_xid_table_lookup (XID xid);
/* Internal functions */
HDC gdk_gc_predraw (GdkDrawablePrivate *drawable_private,
GdkGCPrivate *gc_private);
void gdk_gc_postdraw (GdkDrawablePrivate *drawable_private,
GdkGCPrivate *gc_private);
HRGN BitmapToRegion (HBITMAP hBmp);
void gdk_sel_prop_store (GdkWindow *owner,
GdkAtom type,
gint format,
guchar *data,
gint length);
void gdk_event_queue_append (GdkEvent *event);
gint gdk_nmbstowcs (GdkWChar *dest,
const gchar *src,
gint src_len,
gint dest_max);
gint gdk_nmbstowchar_ts (wchar_t *dest,
const gchar *src,
gint src_len,
gint dest_max);
void gdk_wchar_text_handle (GdkFont *font,
const wchar_t *wcstr,
int wclen,
void (*handler)(GdkWin32SingleFont *,
const wchar_t *,
int,
void *),
void *arg);
/* Please see gdkwindow.c for comments on how to use */
HWND gdk_window_xid_at(HWND base, gint bx, gint by, gint x, gint y, GList *excludes, gboolean excl_child);
HWND gdk_window_xid_at_coords(gint x, gint y, GList *excludes, gboolean excl_child);
extern gint gdk_debug_level;
extern gint gdk_show_events;
extern gint gdk_stack_trace;
extern HWND gdk_root_window;
extern HWND gdk_leader_window;
GDKVAR GdkWindowPrivate *gdk_root_parent;
GDKVAR Atom gdk_selection_property;
GDKVAR gchar *gdk_progclass;
GDKVAR gint gdk_error_code;
GDKVAR gint gdk_error_warnings;
GDKVAR gint gdk_null_window_warnings;
extern gint gdk_event_func_from_window_proc;
extern HDC gdk_DC;
extern HINSTANCE gdk_DLLInstance;
extern HINSTANCE gdk_ProgInstance;
extern UINT gdk_selection_notify_msg;
extern UINT gdk_selection_request_msg;
extern UINT gdk_selection_clear_msg;
extern GdkAtom gdk_clipboard_atom;
extern GdkAtom gdk_win32_dropfiles_atom;
extern GdkAtom gdk_ole2_dnd_atom;
extern LRESULT CALLBACK gdk_WindowProc (HWND, UINT, WPARAM, LPARAM);
extern DWORD windows_version;
/* Debugging support */
#ifdef G_ENABLE_DEBUG
#define GDK_NOTE(type,action) G_STMT_START { \
if (gdk_debug_flags & GDK_DEBUG_##type) \
{ action; }; } G_STMT_END
#else /* !G_ENABLE_DEBUG */
#define GDK_NOTE(type,action)
#endif /* G_ENABLE_DEBUG */
GDKVAR guint gdk_debug_flags;
/* Internal functions for debug output etc. */
char *gdk_color_to_string (GdkColor *);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __GDK_PRIVATE_H__ */

View File

@ -0,0 +1,228 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include <string.h>
#include "gdkproperty.h"
#include "gdkselection.h"
#include "gdkprivate.h"
#include "gdkx.h"
GdkAtom
gdk_atom_intern (const gchar *atom_name,
gint only_if_exists)
{
GdkAtom retval;
static GHashTable *atom_hash = NULL;
if (!atom_hash)
atom_hash = g_hash_table_new (g_str_hash, g_str_equal);
retval = GPOINTER_TO_UINT (g_hash_table_lookup (atom_hash, atom_name));
if (!retval)
{
if (strcmp (atom_name, "PRIMARY") == 0)
retval = GDK_SELECTION_PRIMARY;
else if (strcmp (atom_name, "SECONDARY") == 0)
retval = GDK_SELECTION_SECONDARY;
else if (strcmp (atom_name, "ATOM") == 0)
retval = GDK_SELECTION_TYPE_ATOM;
else if (strcmp (atom_name, "BITMAP") == 0)
retval = GDK_SELECTION_TYPE_BITMAP;
else if (strcmp (atom_name, "COLORMAP") == 0)
retval = GDK_SELECTION_TYPE_COLORMAP;
else if (strcmp (atom_name, "DRAWABLE") == 0)
retval = GDK_SELECTION_TYPE_DRAWABLE;
else if (strcmp (atom_name, "INTEGER") == 0)
retval = GDK_SELECTION_TYPE_INTEGER;
else if (strcmp (atom_name, "PIXMAP") == 0)
retval = GDK_SELECTION_TYPE_PIXMAP;
else if (strcmp (atom_name, "WINDOW") == 0)
retval = GDK_SELECTION_TYPE_WINDOW;
else if (strcmp (atom_name, "STRING") == 0)
retval = GDK_SELECTION_TYPE_STRING;
else
{
retval = GlobalFindAtom (atom_name);
if (only_if_exists && retval == 0)
retval = 0;
else
retval = GlobalAddAtom (atom_name);
}
g_hash_table_insert (atom_hash,
g_strdup (atom_name),
GUINT_TO_POINTER (retval));
}
return retval;
}
gchar *
gdk_atom_name (GdkAtom atom)
{
gchar name[256];
switch (atom)
{
case GDK_SELECTION_PRIMARY: return g_strdup ("PRIMARY");
case GDK_SELECTION_SECONDARY: return g_strdup ("SECONDARY");
case GDK_SELECTION_TYPE_ATOM: return g_strdup ("ATOM");
case GDK_SELECTION_TYPE_BITMAP: return g_strdup ("BITMAP");
case GDK_SELECTION_TYPE_COLORMAP: return g_strdup ("COLORMAP");
case GDK_SELECTION_TYPE_DRAWABLE: return g_strdup ("DRAWABLE");
case GDK_SELECTION_TYPE_INTEGER: return g_strdup ("INTEGER");
case GDK_SELECTION_TYPE_PIXMAP: return g_strdup ("PIXMAP");
case GDK_SELECTION_TYPE_WINDOW: return g_strdup ("WINDOW");
case GDK_SELECTION_TYPE_STRING: return g_strdup ("STRING");
}
if (atom < 0xC000)
return g_strdup_printf ("#%x", atom);
else if (GlobalGetAtomName (atom, name, sizeof (name)) == 0)
return NULL;
return g_strdup (name);
}
gint
gdk_property_get (GdkWindow *window,
GdkAtom property,
GdkAtom type,
gulong offset,
gulong length,
gint pdelete,
GdkAtom *actual_property_type,
gint *actual_format_type,
gint *actual_length,
guchar **data)
{
g_warning ("gdk_property_get: Not implemented");
return FALSE;
}
void
gdk_property_change (GdkWindow *window,
GdkAtom property,
GdkAtom type,
gint format,
GdkPropMode mode,
guchar *data,
gint nelements)
{
HGLOBAL hdata;
gint i, length;
gchar *prop_name, *type_name;
guchar *ptr;
if (GDK_DRAWABLE_DESTROYED (window))
return;
GDK_NOTE (SELECTION,
(prop_name = gdk_atom_name (property),
type_name = gdk_atom_name (type),
g_print ("gdk_property_change: %#x %#x (%s) %#x (%s) %s %d*%d bytes %.10s\n",
GDK_DRAWABLE_XID (window), property, prop_name,
type, type_name,
(mode == GDK_PROP_MODE_REPLACE ? "REPLACE" :
(mode == GDK_PROP_MODE_PREPEND ? "PREPEND" :
(mode == GDK_PROP_MODE_APPEND ? "APPEND" :
"???"))),
format, nelements, data),
g_free (prop_name),
g_free (type_name)));
if (property == gdk_selection_property
&& type == GDK_TARGET_STRING
&& format == 8
&& mode == GDK_PROP_MODE_REPLACE)
{
length = nelements;
ptr = data;
for (i = 0; i < nelements; i++)
if (*ptr++ == '\n')
length++;
#if 1
GDK_NOTE (SELECTION, g_print ("...OpenClipboard(%#x)\n",
GDK_DRAWABLE_XID (window)));
if (!OpenClipboard (GDK_DRAWABLE_XID (window)))
{
g_warning ("gdk_property_change: OpenClipboard failed");
return;
}
#endif
hdata = GlobalAlloc (GMEM_MOVEABLE|GMEM_DDESHARE, length + 1);
ptr = GlobalLock (hdata);
GDK_NOTE (SELECTION, g_print ("...hdata=%#x, ptr=%#x\n", hdata, ptr));
for (i = 0; i < nelements; i++)
{
if (*data == '\n')
*ptr++ = '\r';
*ptr++ = *data++;
}
*ptr++ = '\0';
GlobalUnlock (hdata);
GDK_NOTE (SELECTION, g_print ("...SetClipboardData(CF_TEXT, %#x)\n",
hdata));
if (!SetClipboardData(CF_TEXT, hdata))
g_warning ("gdk_property_change: SetClipboardData failed: %d",
GetLastError ());
#if 1
GDK_NOTE (SELECTION, g_print ("...CloseClipboard()\n"));
if (!CloseClipboard ())
{
g_warning ("gdk_property_change: CloseClipboard failed");
return;
}
#endif
}
else
g_warning ("gdk_property_change: General case not implemented");
}
void
gdk_property_delete (GdkWindow *window,
GdkAtom property)
{
gchar *prop_name, *type_name;
extern void gdk_selection_property_delete (GdkWindow *);
if (GDK_DRAWABLE_DESTROYED (window))
return;
GDK_NOTE (SELECTION,
(prop_name = gdk_atom_name (property),
g_print ("gdk_property_delete: %#x %#x (%s)\n",
(window ? GDK_DRAWABLE_XID (window) : 0),
property, prop_name),
g_free (prop_name)));
if (property == gdk_selection_property)
gdk_selection_property_delete (window);
else
g_warning ("gdk_property_delete: General case not implemented");
}

228
gdk/win32/gdkproperty.c Normal file
View File

@ -0,0 +1,228 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include <string.h>
#include "gdkproperty.h"
#include "gdkselection.h"
#include "gdkprivate.h"
#include "gdkx.h"
GdkAtom
gdk_atom_intern (const gchar *atom_name,
gint only_if_exists)
{
GdkAtom retval;
static GHashTable *atom_hash = NULL;
if (!atom_hash)
atom_hash = g_hash_table_new (g_str_hash, g_str_equal);
retval = GPOINTER_TO_UINT (g_hash_table_lookup (atom_hash, atom_name));
if (!retval)
{
if (strcmp (atom_name, "PRIMARY") == 0)
retval = GDK_SELECTION_PRIMARY;
else if (strcmp (atom_name, "SECONDARY") == 0)
retval = GDK_SELECTION_SECONDARY;
else if (strcmp (atom_name, "ATOM") == 0)
retval = GDK_SELECTION_TYPE_ATOM;
else if (strcmp (atom_name, "BITMAP") == 0)
retval = GDK_SELECTION_TYPE_BITMAP;
else if (strcmp (atom_name, "COLORMAP") == 0)
retval = GDK_SELECTION_TYPE_COLORMAP;
else if (strcmp (atom_name, "DRAWABLE") == 0)
retval = GDK_SELECTION_TYPE_DRAWABLE;
else if (strcmp (atom_name, "INTEGER") == 0)
retval = GDK_SELECTION_TYPE_INTEGER;
else if (strcmp (atom_name, "PIXMAP") == 0)
retval = GDK_SELECTION_TYPE_PIXMAP;
else if (strcmp (atom_name, "WINDOW") == 0)
retval = GDK_SELECTION_TYPE_WINDOW;
else if (strcmp (atom_name, "STRING") == 0)
retval = GDK_SELECTION_TYPE_STRING;
else
{
retval = GlobalFindAtom (atom_name);
if (only_if_exists && retval == 0)
retval = 0;
else
retval = GlobalAddAtom (atom_name);
}
g_hash_table_insert (atom_hash,
g_strdup (atom_name),
GUINT_TO_POINTER (retval));
}
return retval;
}
gchar *
gdk_atom_name (GdkAtom atom)
{
gchar name[256];
switch (atom)
{
case GDK_SELECTION_PRIMARY: return g_strdup ("PRIMARY");
case GDK_SELECTION_SECONDARY: return g_strdup ("SECONDARY");
case GDK_SELECTION_TYPE_ATOM: return g_strdup ("ATOM");
case GDK_SELECTION_TYPE_BITMAP: return g_strdup ("BITMAP");
case GDK_SELECTION_TYPE_COLORMAP: return g_strdup ("COLORMAP");
case GDK_SELECTION_TYPE_DRAWABLE: return g_strdup ("DRAWABLE");
case GDK_SELECTION_TYPE_INTEGER: return g_strdup ("INTEGER");
case GDK_SELECTION_TYPE_PIXMAP: return g_strdup ("PIXMAP");
case GDK_SELECTION_TYPE_WINDOW: return g_strdup ("WINDOW");
case GDK_SELECTION_TYPE_STRING: return g_strdup ("STRING");
}
if (atom < 0xC000)
return g_strdup_printf ("#%x", atom);
else if (GlobalGetAtomName (atom, name, sizeof (name)) == 0)
return NULL;
return g_strdup (name);
}
gint
gdk_property_get (GdkWindow *window,
GdkAtom property,
GdkAtom type,
gulong offset,
gulong length,
gint pdelete,
GdkAtom *actual_property_type,
gint *actual_format_type,
gint *actual_length,
guchar **data)
{
g_warning ("gdk_property_get: Not implemented");
return FALSE;
}
void
gdk_property_change (GdkWindow *window,
GdkAtom property,
GdkAtom type,
gint format,
GdkPropMode mode,
guchar *data,
gint nelements)
{
HGLOBAL hdata;
gint i, length;
gchar *prop_name, *type_name;
guchar *ptr;
if (GDK_DRAWABLE_DESTROYED (window))
return;
GDK_NOTE (SELECTION,
(prop_name = gdk_atom_name (property),
type_name = gdk_atom_name (type),
g_print ("gdk_property_change: %#x %#x (%s) %#x (%s) %s %d*%d bytes %.10s\n",
GDK_DRAWABLE_XID (window), property, prop_name,
type, type_name,
(mode == GDK_PROP_MODE_REPLACE ? "REPLACE" :
(mode == GDK_PROP_MODE_PREPEND ? "PREPEND" :
(mode == GDK_PROP_MODE_APPEND ? "APPEND" :
"???"))),
format, nelements, data),
g_free (prop_name),
g_free (type_name)));
if (property == gdk_selection_property
&& type == GDK_TARGET_STRING
&& format == 8
&& mode == GDK_PROP_MODE_REPLACE)
{
length = nelements;
ptr = data;
for (i = 0; i < nelements; i++)
if (*ptr++ == '\n')
length++;
#if 1
GDK_NOTE (SELECTION, g_print ("...OpenClipboard(%#x)\n",
GDK_DRAWABLE_XID (window)));
if (!OpenClipboard (GDK_DRAWABLE_XID (window)))
{
g_warning ("gdk_property_change: OpenClipboard failed");
return;
}
#endif
hdata = GlobalAlloc (GMEM_MOVEABLE|GMEM_DDESHARE, length + 1);
ptr = GlobalLock (hdata);
GDK_NOTE (SELECTION, g_print ("...hdata=%#x, ptr=%#x\n", hdata, ptr));
for (i = 0; i < nelements; i++)
{
if (*data == '\n')
*ptr++ = '\r';
*ptr++ = *data++;
}
*ptr++ = '\0';
GlobalUnlock (hdata);
GDK_NOTE (SELECTION, g_print ("...SetClipboardData(CF_TEXT, %#x)\n",
hdata));
if (!SetClipboardData(CF_TEXT, hdata))
g_warning ("gdk_property_change: SetClipboardData failed: %d",
GetLastError ());
#if 1
GDK_NOTE (SELECTION, g_print ("...CloseClipboard()\n"));
if (!CloseClipboard ())
{
g_warning ("gdk_property_change: CloseClipboard failed");
return;
}
#endif
}
else
g_warning ("gdk_property_change: General case not implemented");
}
void
gdk_property_delete (GdkWindow *window,
GdkAtom property)
{
gchar *prop_name, *type_name;
extern void gdk_selection_property_delete (GdkWindow *);
if (GDK_DRAWABLE_DESTROYED (window))
return;
GDK_NOTE (SELECTION,
(prop_name = gdk_atom_name (property),
g_print ("gdk_property_delete: %#x %#x (%s)\n",
(window ? GDK_DRAWABLE_XID (window) : 0),
property, prop_name),
g_free (prop_name)));
if (property == gdk_selection_property)
gdk_selection_property_delete (window);
else
g_warning ("gdk_property_delete: General case not implemented");
}

367
gdk/win32/gdkregion-win32.c Normal file
View File

@ -0,0 +1,367 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include "gdk.h"
#include "gdkprivate.h"
GdkRegion*
gdk_region_new (void)
{
GdkRegionPrivate *private;
GdkRegion *region;
HRGN xregion;
RECT emptyRect;
/* Create an empty region */
SetRectEmpty (&emptyRect);
xregion = CreateRectRgnIndirect (&emptyRect);
private = g_new (GdkRegionPrivate, 1);
private->xregion = xregion;
region = (GdkRegion*) private;
region->user_data = NULL;
return region;
}
void
gdk_region_destroy (GdkRegion *region)
{
GdkRegionPrivate *private;
g_return_if_fail (region != NULL);
private = (GdkRegionPrivate *) region;
DeleteObject (private->xregion);
g_free (private);
}
gboolean
gdk_region_empty (GdkRegion *region)
{
GdkRegionPrivate *private;
RECT rect;
g_return_val_if_fail (region != NULL, 0);
private = (GdkRegionPrivate *) region;
return (GetRgnBox (private->xregion, &rect) == NULLREGION);
}
gboolean
gdk_region_equal (GdkRegion *region1,
GdkRegion *region2)
{
GdkRegionPrivate *private1;
GdkRegionPrivate *private2;
g_return_val_if_fail (region1 != NULL, 0);
g_return_val_if_fail (region2 != NULL, 0);
private1 = (GdkRegionPrivate *) region1;
private2 = (GdkRegionPrivate *) region2;
return EqualRgn (private1->xregion, private2->xregion);
}
void
gdk_region_get_clipbox(GdkRegion *region,
GdkRectangle *rectangle)
{
GdkRegionPrivate *rp;
RECT r;
g_return_if_fail(region != NULL);
g_return_if_fail(rectangle != NULL);
rp = (GdkRegionPrivate *)region;
GetRgnBox (rp->xregion, &r);
rectangle->x = r.left;
rectangle->y = r.top;
rectangle->width = r.right - r.left;
rectangle->height = r.bottom - r.top;
}
gboolean
gdk_region_point_in (GdkRegion *region,
gint x,
gint y)
{
GdkRegionPrivate *private;
g_return_val_if_fail (region != NULL, 0);
private = (GdkRegionPrivate *) region;
return PtInRegion (private->xregion, x, y);
}
GdkOverlapType
gdk_region_rect_in (GdkRegion *region,
GdkRectangle *rect)
{
GdkRegionPrivate *private;
RECT r;
int res;
g_return_val_if_fail (region != NULL, 0);
private = (GdkRegionPrivate *) region;
r.left = rect->x;
r.top = rect->y;
r.right = rect->x + rect->width;
r.bottom = rect->y + rect->height;
if (RectInRegion (private->xregion, &r))
return GDK_OVERLAP_RECTANGLE_PART;
return GDK_OVERLAP_RECTANGLE_OUT; /*what else ? */
}
GdkRegion *
gdk_region_polygon (GdkPoint *points,
gint npoints,
GdkFillRule fill_rule)
{
GdkRegionPrivate *private;
GdkRegion *region;
HRGN xregion;
POINT *pts;
gint xfill_rule = ALTERNATE;
gint i;
g_return_val_if_fail (points != NULL, NULL);
g_return_val_if_fail (npoints != 0, NULL); /* maybe we should check for at least three points */
switch (fill_rule)
{
case GDK_EVEN_ODD_RULE:
xfill_rule = ALTERNATE;
break;
case GDK_WINDING_RULE:
xfill_rule = WINDING;
break;
}
pts = g_malloc (npoints * sizeof (*pts));
for (i = 0; i < npoints; i++)
{
pts[i].x = points[i].x;
pts[i].y = points[i].y;
}
xregion = CreatePolygonRgn (pts, npoints, xfill_rule);
g_free (pts);
private = g_new (GdkRegionPrivate, 1);
private->xregion = xregion;
region = (GdkRegion *) private;
region->user_data = NULL;
return region;
}
void
gdk_region_offset (GdkRegion *region,
gint dx,
gint dy)
{
GdkRegionPrivate *private;
g_return_if_fail (region != NULL);
private = (GdkRegionPrivate *) region;
OffsetRgn (private->xregion, dx, dy);
}
void
gdk_region_shrink (GdkRegion *region,
gint dx,
gint dy)
{
GdkRegionPrivate *private;
HRGN shrunken_bbox;
RECT r;
g_return_if_fail (region != NULL);
private = (GdkRegionPrivate *) region;
if (dx > 0 || dy > 0)
{
/* We want to shrink it in one or both dimensions.
* Is it correct just to intersect it with a smaller bounding box?
* XXX
*/
GetRgnBox (private->xregion, &r);
if (dx > 0)
{
r.left += dx - dx/2;
r.right -= dx/2;
}
if (dy > 0)
{
r.top += dy - dy/2;
r.bottom -= dy/2;
}
shrunken_bbox = CreateRectRgnIndirect (&r);
CombineRgn (private->xregion, private->xregion,
shrunken_bbox, RGN_AND);
DeleteObject (shrunken_bbox);
}
else
{
/* Do nothing if the regions is expanded? XXX */
}
}
GdkRegion*
gdk_region_union_with_rect (GdkRegion *region,
GdkRectangle *rect)
{
GdkRegionPrivate *private;
GdkRegion *res;
GdkRegionPrivate *res_private;
RECT xrect;
HRGN rectangle;
g_return_val_if_fail (region != NULL, NULL);
private = (GdkRegionPrivate *) region;
xrect.left = rect->x;
xrect.top = rect->y;
xrect.right = rect->x + rect->width;
xrect.bottom = rect->y + rect->height;
res = gdk_region_new ();
res_private = (GdkRegionPrivate *) res;
rectangle = CreateRectRgnIndirect (&xrect);
CombineRgn (res_private->xregion, private->xregion,
rectangle, RGN_OR);
DeleteObject (rectangle);
return res;
}
GdkRegion*
gdk_regions_intersect (GdkRegion *source1,
GdkRegion *source2)
{
GdkRegionPrivate *private1;
GdkRegionPrivate *private2;
GdkRegion *res;
GdkRegionPrivate *res_private;
g_return_val_if_fail (source1 != NULL, NULL);
g_return_val_if_fail (source2 != NULL, NULL);
private1 = (GdkRegionPrivate *) source1;
private2 = (GdkRegionPrivate *) source2;
res = gdk_region_new ();
res_private = (GdkRegionPrivate *) res;
CombineRgn (res_private->xregion, private1->xregion, private2->xregion,
RGN_AND);
return res;
}
GdkRegion*
gdk_regions_union (GdkRegion *source1,
GdkRegion *source2)
{
GdkRegionPrivate *private1;
GdkRegionPrivate *private2;
GdkRegion *res;
GdkRegionPrivate *res_private;
g_return_val_if_fail (source1 != NULL, NULL);
g_return_val_if_fail (source2 != NULL, NULL);
private1 = (GdkRegionPrivate *) source1;
private2 = (GdkRegionPrivate *) source2;
res = gdk_region_new ();
res_private = (GdkRegionPrivate *) res;
CombineRgn (res_private->xregion, private1->xregion, private2->xregion,
RGN_OR);
return res;
}
GdkRegion*
gdk_regions_subtract (GdkRegion *source1,
GdkRegion *source2)
{
GdkRegionPrivate *private1;
GdkRegionPrivate *private2;
GdkRegion *res;
GdkRegionPrivate *res_private;
g_return_val_if_fail (source1 != NULL, NULL);
g_return_val_if_fail (source2 != NULL, NULL);
private1 = (GdkRegionPrivate *) source1;
private2 = (GdkRegionPrivate *) source2;
res = gdk_region_new ();
res_private = (GdkRegionPrivate *) res;
CombineRgn (res_private->xregion, private1->xregion, private2->xregion,
RGN_DIFF);
return res;
}
GdkRegion*
gdk_regions_xor (GdkRegion *source1,
GdkRegion *source2)
{
GdkRegionPrivate *private1;
GdkRegionPrivate *private2;
GdkRegion *res;
GdkRegionPrivate *res_private;
g_return_val_if_fail (source1 != NULL, NULL);
g_return_val_if_fail (source2 != NULL, NULL);
private1 = (GdkRegionPrivate *) source1;
private2 = (GdkRegionPrivate *) source2;
res = gdk_region_new ();
res_private = (GdkRegionPrivate *) res;
CombineRgn (res_private->xregion, private1->xregion, private2->xregion,
RGN_XOR);
return res;
}

367
gdk/win32/gdkregion.c Normal file
View File

@ -0,0 +1,367 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include "gdk.h"
#include "gdkprivate.h"
GdkRegion*
gdk_region_new (void)
{
GdkRegionPrivate *private;
GdkRegion *region;
HRGN xregion;
RECT emptyRect;
/* Create an empty region */
SetRectEmpty (&emptyRect);
xregion = CreateRectRgnIndirect (&emptyRect);
private = g_new (GdkRegionPrivate, 1);
private->xregion = xregion;
region = (GdkRegion*) private;
region->user_data = NULL;
return region;
}
void
gdk_region_destroy (GdkRegion *region)
{
GdkRegionPrivate *private;
g_return_if_fail (region != NULL);
private = (GdkRegionPrivate *) region;
DeleteObject (private->xregion);
g_free (private);
}
gboolean
gdk_region_empty (GdkRegion *region)
{
GdkRegionPrivate *private;
RECT rect;
g_return_val_if_fail (region != NULL, 0);
private = (GdkRegionPrivate *) region;
return (GetRgnBox (private->xregion, &rect) == NULLREGION);
}
gboolean
gdk_region_equal (GdkRegion *region1,
GdkRegion *region2)
{
GdkRegionPrivate *private1;
GdkRegionPrivate *private2;
g_return_val_if_fail (region1 != NULL, 0);
g_return_val_if_fail (region2 != NULL, 0);
private1 = (GdkRegionPrivate *) region1;
private2 = (GdkRegionPrivate *) region2;
return EqualRgn (private1->xregion, private2->xregion);
}
void
gdk_region_get_clipbox(GdkRegion *region,
GdkRectangle *rectangle)
{
GdkRegionPrivate *rp;
RECT r;
g_return_if_fail(region != NULL);
g_return_if_fail(rectangle != NULL);
rp = (GdkRegionPrivate *)region;
GetRgnBox (rp->xregion, &r);
rectangle->x = r.left;
rectangle->y = r.top;
rectangle->width = r.right - r.left;
rectangle->height = r.bottom - r.top;
}
gboolean
gdk_region_point_in (GdkRegion *region,
gint x,
gint y)
{
GdkRegionPrivate *private;
g_return_val_if_fail (region != NULL, 0);
private = (GdkRegionPrivate *) region;
return PtInRegion (private->xregion, x, y);
}
GdkOverlapType
gdk_region_rect_in (GdkRegion *region,
GdkRectangle *rect)
{
GdkRegionPrivate *private;
RECT r;
int res;
g_return_val_if_fail (region != NULL, 0);
private = (GdkRegionPrivate *) region;
r.left = rect->x;
r.top = rect->y;
r.right = rect->x + rect->width;
r.bottom = rect->y + rect->height;
if (RectInRegion (private->xregion, &r))
return GDK_OVERLAP_RECTANGLE_PART;
return GDK_OVERLAP_RECTANGLE_OUT; /*what else ? */
}
GdkRegion *
gdk_region_polygon (GdkPoint *points,
gint npoints,
GdkFillRule fill_rule)
{
GdkRegionPrivate *private;
GdkRegion *region;
HRGN xregion;
POINT *pts;
gint xfill_rule = ALTERNATE;
gint i;
g_return_val_if_fail (points != NULL, NULL);
g_return_val_if_fail (npoints != 0, NULL); /* maybe we should check for at least three points */
switch (fill_rule)
{
case GDK_EVEN_ODD_RULE:
xfill_rule = ALTERNATE;
break;
case GDK_WINDING_RULE:
xfill_rule = WINDING;
break;
}
pts = g_malloc (npoints * sizeof (*pts));
for (i = 0; i < npoints; i++)
{
pts[i].x = points[i].x;
pts[i].y = points[i].y;
}
xregion = CreatePolygonRgn (pts, npoints, xfill_rule);
g_free (pts);
private = g_new (GdkRegionPrivate, 1);
private->xregion = xregion;
region = (GdkRegion *) private;
region->user_data = NULL;
return region;
}
void
gdk_region_offset (GdkRegion *region,
gint dx,
gint dy)
{
GdkRegionPrivate *private;
g_return_if_fail (region != NULL);
private = (GdkRegionPrivate *) region;
OffsetRgn (private->xregion, dx, dy);
}
void
gdk_region_shrink (GdkRegion *region,
gint dx,
gint dy)
{
GdkRegionPrivate *private;
HRGN shrunken_bbox;
RECT r;
g_return_if_fail (region != NULL);
private = (GdkRegionPrivate *) region;
if (dx > 0 || dy > 0)
{
/* We want to shrink it in one or both dimensions.
* Is it correct just to intersect it with a smaller bounding box?
* XXX
*/
GetRgnBox (private->xregion, &r);
if (dx > 0)
{
r.left += dx - dx/2;
r.right -= dx/2;
}
if (dy > 0)
{
r.top += dy - dy/2;
r.bottom -= dy/2;
}
shrunken_bbox = CreateRectRgnIndirect (&r);
CombineRgn (private->xregion, private->xregion,
shrunken_bbox, RGN_AND);
DeleteObject (shrunken_bbox);
}
else
{
/* Do nothing if the regions is expanded? XXX */
}
}
GdkRegion*
gdk_region_union_with_rect (GdkRegion *region,
GdkRectangle *rect)
{
GdkRegionPrivate *private;
GdkRegion *res;
GdkRegionPrivate *res_private;
RECT xrect;
HRGN rectangle;
g_return_val_if_fail (region != NULL, NULL);
private = (GdkRegionPrivate *) region;
xrect.left = rect->x;
xrect.top = rect->y;
xrect.right = rect->x + rect->width;
xrect.bottom = rect->y + rect->height;
res = gdk_region_new ();
res_private = (GdkRegionPrivate *) res;
rectangle = CreateRectRgnIndirect (&xrect);
CombineRgn (res_private->xregion, private->xregion,
rectangle, RGN_OR);
DeleteObject (rectangle);
return res;
}
GdkRegion*
gdk_regions_intersect (GdkRegion *source1,
GdkRegion *source2)
{
GdkRegionPrivate *private1;
GdkRegionPrivate *private2;
GdkRegion *res;
GdkRegionPrivate *res_private;
g_return_val_if_fail (source1 != NULL, NULL);
g_return_val_if_fail (source2 != NULL, NULL);
private1 = (GdkRegionPrivate *) source1;
private2 = (GdkRegionPrivate *) source2;
res = gdk_region_new ();
res_private = (GdkRegionPrivate *) res;
CombineRgn (res_private->xregion, private1->xregion, private2->xregion,
RGN_AND);
return res;
}
GdkRegion*
gdk_regions_union (GdkRegion *source1,
GdkRegion *source2)
{
GdkRegionPrivate *private1;
GdkRegionPrivate *private2;
GdkRegion *res;
GdkRegionPrivate *res_private;
g_return_val_if_fail (source1 != NULL, NULL);
g_return_val_if_fail (source2 != NULL, NULL);
private1 = (GdkRegionPrivate *) source1;
private2 = (GdkRegionPrivate *) source2;
res = gdk_region_new ();
res_private = (GdkRegionPrivate *) res;
CombineRgn (res_private->xregion, private1->xregion, private2->xregion,
RGN_OR);
return res;
}
GdkRegion*
gdk_regions_subtract (GdkRegion *source1,
GdkRegion *source2)
{
GdkRegionPrivate *private1;
GdkRegionPrivate *private2;
GdkRegion *res;
GdkRegionPrivate *res_private;
g_return_val_if_fail (source1 != NULL, NULL);
g_return_val_if_fail (source2 != NULL, NULL);
private1 = (GdkRegionPrivate *) source1;
private2 = (GdkRegionPrivate *) source2;
res = gdk_region_new ();
res_private = (GdkRegionPrivate *) res;
CombineRgn (res_private->xregion, private1->xregion, private2->xregion,
RGN_DIFF);
return res;
}
GdkRegion*
gdk_regions_xor (GdkRegion *source1,
GdkRegion *source2)
{
GdkRegionPrivate *private1;
GdkRegionPrivate *private2;
GdkRegion *res;
GdkRegionPrivate *res_private;
g_return_val_if_fail (source1 != NULL, NULL);
g_return_val_if_fail (source2 != NULL, NULL);
private1 = (GdkRegionPrivate *) source1;
private2 = (GdkRegionPrivate *) source2;
res = gdk_region_new ();
res_private = (GdkRegionPrivate *) res;
CombineRgn (res_private->xregion, private1->xregion, private2->xregion,
RGN_XOR);
return res;
}

View File

@ -0,0 +1,403 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include <string.h>
#include <gdk/gdk.h>
#include "gdkx.h"
/* We emulate the GDK_SELECTION window properties by storing
* it's data in a per-window hashtable.
*/
typedef struct {
guchar *data;
gint length;
gint format;
GdkAtom type;
} GdkSelProp;
static GHashTable *sel_prop_table = NULL;
void
gdk_selection_init (void)
{
if (sel_prop_table == NULL)
sel_prop_table = g_hash_table_new (g_int_hash, g_int_equal);
}
void
gdk_sel_prop_store (GdkWindow *owner,
GdkAtom type,
gint format,
guchar *data,
gint length)
{
GdkSelProp *prop;
prop = g_hash_table_lookup (sel_prop_table, &GDK_DRAWABLE_XID (owner));
if (prop != NULL)
{
g_free (prop->data);
g_hash_table_remove (sel_prop_table, &GDK_DRAWABLE_XID (owner));
}
prop = g_new (GdkSelProp, 1);
prop->data = data;
prop->length = length;
prop->format = format;
prop->type = type;
g_hash_table_insert (sel_prop_table, &GDK_DRAWABLE_XID (owner), prop);
}
gint
gdk_selection_owner_set (GdkWindow *owner,
GdkAtom selection,
guint32 time,
gint send_event)
{
gchar *sel_name;
HWND xwindow;
GDK_NOTE (SELECTION,
(sel_name = gdk_atom_name (selection),
g_print ("gdk_selection_owner_set: %#x %#x (%s)\n",
(owner ? GDK_DRAWABLE_XID (owner) : 0),
selection, sel_name),
g_free (sel_name)));
if (selection != gdk_clipboard_atom)
return FALSE;
if (owner != NULL)
xwindow = GDK_DRAWABLE_XID (owner);
else
xwindow = NULL;
GDK_NOTE (SELECTION, g_print ("...OpenClipboard(%#x)\n", xwindow));
if (!OpenClipboard (xwindow))
{
g_warning ("gdk_selection_owner_set: OpenClipboard failed");
return FALSE;
}
GDK_NOTE (SELECTION, g_print ("...EmptyClipboard()\n"));
if (!EmptyClipboard ())
{
g_warning ("gdk_selection_owner_set: EmptyClipboard failed");
CloseClipboard ();
return FALSE;
}
#if 0
/* No delayed rendering */
if (xwindow != NULL)
SetClipboardData (CF_TEXT, NULL);
#endif
GDK_NOTE (SELECTION, g_print ("...CloseClipboard()\n"));
if (!CloseClipboard ())
{
g_warning ("gdk_selection_owner_set: CloseClipboard failed");
return FALSE;
}
if (owner != NULL)
{
/* Send ourselves an ersatz selection request message so that
* gdk_property_change will be called to store the clipboard data.
*/
SendMessage (xwindow, gdk_selection_request_msg,
selection, 0);
}
return TRUE;
}
GdkWindow*
gdk_selection_owner_get (GdkAtom selection)
{
GdkWindow *window;
gchar *sel_name;
#if 1
/* XXX Hmm, gtk selections seem to work best with this. This causes
* gtk to always get the clipboard contents from Windows, and not
* from the editable's own stashed-away copy.
*/
return NULL;
#else
if (selection != gdk_clipboard_atom)
window = NULL;
else
window = gdk_window_lookup (GetClipboardOwner ());
#endif
GDK_NOTE (SELECTION,
(sel_name = gdk_atom_name (selection),
g_print ("gdk_selection_owner_get: %#x (%s) = %#x\n",
selection, sel_name,
(window ? GDK_DRAWABLE_XID (window) : 0)),
g_free (sel_name)));
return window;
}
void
gdk_selection_convert (GdkWindow *requestor,
GdkAtom selection,
GdkAtom target,
guint32 time)
{
HGLOBAL hdata;
GdkSelProp *prop;
guchar *ptr, *data, *datap, *p;
guint i, length, slength;
gchar *sel_name, *tgt_name;
g_return_if_fail (requestor != NULL);
if (GDK_DRAWABLE_DESTROYED (requestor))
return;
GDK_NOTE (SELECTION,
(sel_name = gdk_atom_name (selection),
tgt_name = gdk_atom_name (target),
g_print ("gdk_selection_convert: %#x %#x (%s) %#x (%s)\n",
GDK_DRAWABLE_XID (requestor), selection, sel_name, target, tgt_name),
g_free (sel_name),
g_free (tgt_name)));
if (selection == gdk_clipboard_atom)
{
/* Converting the CLIPBOARD selection means he wants the
* contents of the clipboard. Get the clipboard data,
* and store it for later.
*/
GDK_NOTE (SELECTION, g_print ("...OpenClipboard(%#x)\n",
GDK_DRAWABLE_XID (requestor)));
if (!OpenClipboard (GDK_DRAWABLE_XID (requestor)))
{
g_warning ("gdk_selection_convert: OpenClipboard failed");
return;
}
GDK_NOTE (SELECTION, g_print ("...GetClipboardData(CF_TEXT)\n"));
if ((hdata = GetClipboardData (CF_TEXT)) != NULL)
{
if ((ptr = GlobalLock (hdata)) != NULL)
{
length = GlobalSize (hdata);
GDK_NOTE (SELECTION, g_print ("...got data: %d bytes: %.10s\n",
length, ptr));
slength = 0;
p = ptr;
for (i = 0; i < length; i++)
{
if (*p == '\0')
break;
else if (*p != '\r')
slength++;
p++;
}
data = datap = g_malloc (slength + 1);
p = ptr;
for (i = 0; i < length; i++)
{
if (*p == '\0')
break;
else if (*p != '\r')
*datap++ = *p;
p++;
}
*datap++ = '\0';
gdk_sel_prop_store (requestor, GDK_TARGET_STRING, 8,
data, strlen (data) + 1);
GlobalUnlock (hdata);
}
}
GDK_NOTE (SELECTION, g_print ("...CloseClipboard()\n"));
CloseClipboard ();
/* Send ourselves an ersatz selection notify message so that we actually
* fetch the data.
*/
SendMessage (GDK_DRAWABLE_XID (requestor), gdk_selection_notify_msg, selection, target);
}
else if (selection == gdk_win32_dropfiles_atom)
{
/* This means he wants the names of the dropped files.
* gdk_dropfiles_filter already has stored the text/uri-list
* data, tempoarily on gdk_root_parent's selection "property".
*/
GdkSelProp *prop;
prop = g_hash_table_lookup (sel_prop_table, &gdk_root_parent->drawable.xwindow);
if (prop != NULL)
{
g_hash_table_remove (sel_prop_table, &gdk_root_parent->drawable.xwindow);
gdk_sel_prop_store (requestor, prop->type, prop->format,
prop->data, prop->length);
g_free (prop);
SendMessage (GDK_DRAWABLE_XID (requestor), gdk_selection_notify_msg, selection, target);
}
}
else
{
g_warning ("gdk_selection_convert: General case not implemented");
}
}
gint
gdk_selection_property_get (GdkWindow *requestor,
guchar **data,
GdkAtom *ret_type,
gint *ret_format)
{
GdkSelProp *prop;
g_return_val_if_fail (requestor != NULL, 0);
g_return_val_if_fail (GDK_IS_WINDOW (requestor), 0);
if (GDK_DRAWABLE_DESTROYED (requestor))
return 0;
GDK_NOTE (SELECTION, g_print ("gdk_selection_property_get: %#x\n",
GDK_DRAWABLE_XID (requestor)));
prop = g_hash_table_lookup (sel_prop_table, &GDK_DRAWABLE_XID (requestor));
if (prop == NULL)
{
*data = NULL;
return 0;
}
*data = g_malloc (prop->length);
if (prop->length > 0)
memmove (*data, prop->data, prop->length);
if (ret_type)
*ret_type = prop->type;
if (ret_format)
*ret_format = prop->format;
return prop->length;
}
void
gdk_selection_property_delete (GdkWindow *window)
{
GdkSelProp *prop;
prop = g_hash_table_lookup (sel_prop_table, &GDK_DRAWABLE_XID (window));
if (prop != NULL)
{
g_free (prop->data);
g_hash_table_remove (sel_prop_table, &GDK_DRAWABLE_XID (window));
}
else
g_warning ("huh?");
}
void
gdk_selection_send_notify (guint32 requestor,
GdkAtom selection,
GdkAtom target,
GdkAtom property,
guint32 time)
{
gchar *sel_name, *tgt_name, *prop_name;
GDK_NOTE (SELECTION,
(sel_name = gdk_atom_name (selection),
tgt_name = gdk_atom_name (target),
prop_name = gdk_atom_name (property),
g_print ("gdk_selection_send_notify: %#x %#x (%s) %#x (%s) %#x (%s)\n",
requestor,
selection, sel_name,
target, tgt_name,
property, prop_name),
g_free (sel_name),
g_free (tgt_name),
g_free (prop_name)));
/* Send ourselves a selection clear message so that gtk thinks we don't
* have the selection, and will claim it anew when needed, and
* we thus get a chance to store data in the Windows clipboard.
* Otherwise, if a gtkeditable does a copy to clipboard several times
* only the first one actually gets copied to the Windows clipboard,
* as only he first one causes a call to gdk_property_change.
*
* Hmm, there is something fishy with this. Cut and paste inside the
* same app didn't work, the gtkeditable immediately forgot the
* clipboard contents in gtk_editable_selection_clear as a result of
* this message. OTOH, when I changed gdk_selection_owner_get to
* always return NULL, it works. Sigh.
*/
SendMessage ((HWND) requestor, gdk_selection_clear_msg, selection, 0);
}
gint
gdk_text_property_to_text_list (GdkAtom encoding,
gint format,
guchar *text,
gint length,
gchar ***list)
{
GDK_NOTE (SELECTION,
g_print ("gdk_text_property_to_text_list not implemented\n"));
return 0;
}
void
gdk_free_text_list (gchar **list)
{
g_return_if_fail (list != NULL);
/* ??? */
}
gint
gdk_string_to_compound_text (gchar *str,
GdkAtom *encoding,
gint *format,
guchar **ctext,
gint *length)
{
g_warning ("gdk_string_to_compound_text: Not implemented");
return 0;
}
void
gdk_free_compound_text (guchar *ctext)
{
g_warning ("gdk_free_compound_text: Not implemented");
}

403
gdk/win32/gdkselection.c Normal file
View File

@ -0,0 +1,403 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include <string.h>
#include <gdk/gdk.h>
#include "gdkx.h"
/* We emulate the GDK_SELECTION window properties by storing
* it's data in a per-window hashtable.
*/
typedef struct {
guchar *data;
gint length;
gint format;
GdkAtom type;
} GdkSelProp;
static GHashTable *sel_prop_table = NULL;
void
gdk_selection_init (void)
{
if (sel_prop_table == NULL)
sel_prop_table = g_hash_table_new (g_int_hash, g_int_equal);
}
void
gdk_sel_prop_store (GdkWindow *owner,
GdkAtom type,
gint format,
guchar *data,
gint length)
{
GdkSelProp *prop;
prop = g_hash_table_lookup (sel_prop_table, &GDK_DRAWABLE_XID (owner));
if (prop != NULL)
{
g_free (prop->data);
g_hash_table_remove (sel_prop_table, &GDK_DRAWABLE_XID (owner));
}
prop = g_new (GdkSelProp, 1);
prop->data = data;
prop->length = length;
prop->format = format;
prop->type = type;
g_hash_table_insert (sel_prop_table, &GDK_DRAWABLE_XID (owner), prop);
}
gint
gdk_selection_owner_set (GdkWindow *owner,
GdkAtom selection,
guint32 time,
gint send_event)
{
gchar *sel_name;
HWND xwindow;
GDK_NOTE (SELECTION,
(sel_name = gdk_atom_name (selection),
g_print ("gdk_selection_owner_set: %#x %#x (%s)\n",
(owner ? GDK_DRAWABLE_XID (owner) : 0),
selection, sel_name),
g_free (sel_name)));
if (selection != gdk_clipboard_atom)
return FALSE;
if (owner != NULL)
xwindow = GDK_DRAWABLE_XID (owner);
else
xwindow = NULL;
GDK_NOTE (SELECTION, g_print ("...OpenClipboard(%#x)\n", xwindow));
if (!OpenClipboard (xwindow))
{
g_warning ("gdk_selection_owner_set: OpenClipboard failed");
return FALSE;
}
GDK_NOTE (SELECTION, g_print ("...EmptyClipboard()\n"));
if (!EmptyClipboard ())
{
g_warning ("gdk_selection_owner_set: EmptyClipboard failed");
CloseClipboard ();
return FALSE;
}
#if 0
/* No delayed rendering */
if (xwindow != NULL)
SetClipboardData (CF_TEXT, NULL);
#endif
GDK_NOTE (SELECTION, g_print ("...CloseClipboard()\n"));
if (!CloseClipboard ())
{
g_warning ("gdk_selection_owner_set: CloseClipboard failed");
return FALSE;
}
if (owner != NULL)
{
/* Send ourselves an ersatz selection request message so that
* gdk_property_change will be called to store the clipboard data.
*/
SendMessage (xwindow, gdk_selection_request_msg,
selection, 0);
}
return TRUE;
}
GdkWindow*
gdk_selection_owner_get (GdkAtom selection)
{
GdkWindow *window;
gchar *sel_name;
#if 1
/* XXX Hmm, gtk selections seem to work best with this. This causes
* gtk to always get the clipboard contents from Windows, and not
* from the editable's own stashed-away copy.
*/
return NULL;
#else
if (selection != gdk_clipboard_atom)
window = NULL;
else
window = gdk_window_lookup (GetClipboardOwner ());
#endif
GDK_NOTE (SELECTION,
(sel_name = gdk_atom_name (selection),
g_print ("gdk_selection_owner_get: %#x (%s) = %#x\n",
selection, sel_name,
(window ? GDK_DRAWABLE_XID (window) : 0)),
g_free (sel_name)));
return window;
}
void
gdk_selection_convert (GdkWindow *requestor,
GdkAtom selection,
GdkAtom target,
guint32 time)
{
HGLOBAL hdata;
GdkSelProp *prop;
guchar *ptr, *data, *datap, *p;
guint i, length, slength;
gchar *sel_name, *tgt_name;
g_return_if_fail (requestor != NULL);
if (GDK_DRAWABLE_DESTROYED (requestor))
return;
GDK_NOTE (SELECTION,
(sel_name = gdk_atom_name (selection),
tgt_name = gdk_atom_name (target),
g_print ("gdk_selection_convert: %#x %#x (%s) %#x (%s)\n",
GDK_DRAWABLE_XID (requestor), selection, sel_name, target, tgt_name),
g_free (sel_name),
g_free (tgt_name)));
if (selection == gdk_clipboard_atom)
{
/* Converting the CLIPBOARD selection means he wants the
* contents of the clipboard. Get the clipboard data,
* and store it for later.
*/
GDK_NOTE (SELECTION, g_print ("...OpenClipboard(%#x)\n",
GDK_DRAWABLE_XID (requestor)));
if (!OpenClipboard (GDK_DRAWABLE_XID (requestor)))
{
g_warning ("gdk_selection_convert: OpenClipboard failed");
return;
}
GDK_NOTE (SELECTION, g_print ("...GetClipboardData(CF_TEXT)\n"));
if ((hdata = GetClipboardData (CF_TEXT)) != NULL)
{
if ((ptr = GlobalLock (hdata)) != NULL)
{
length = GlobalSize (hdata);
GDK_NOTE (SELECTION, g_print ("...got data: %d bytes: %.10s\n",
length, ptr));
slength = 0;
p = ptr;
for (i = 0; i < length; i++)
{
if (*p == '\0')
break;
else if (*p != '\r')
slength++;
p++;
}
data = datap = g_malloc (slength + 1);
p = ptr;
for (i = 0; i < length; i++)
{
if (*p == '\0')
break;
else if (*p != '\r')
*datap++ = *p;
p++;
}
*datap++ = '\0';
gdk_sel_prop_store (requestor, GDK_TARGET_STRING, 8,
data, strlen (data) + 1);
GlobalUnlock (hdata);
}
}
GDK_NOTE (SELECTION, g_print ("...CloseClipboard()\n"));
CloseClipboard ();
/* Send ourselves an ersatz selection notify message so that we actually
* fetch the data.
*/
SendMessage (GDK_DRAWABLE_XID (requestor), gdk_selection_notify_msg, selection, target);
}
else if (selection == gdk_win32_dropfiles_atom)
{
/* This means he wants the names of the dropped files.
* gdk_dropfiles_filter already has stored the text/uri-list
* data, tempoarily on gdk_root_parent's selection "property".
*/
GdkSelProp *prop;
prop = g_hash_table_lookup (sel_prop_table, &gdk_root_parent->drawable.xwindow);
if (prop != NULL)
{
g_hash_table_remove (sel_prop_table, &gdk_root_parent->drawable.xwindow);
gdk_sel_prop_store (requestor, prop->type, prop->format,
prop->data, prop->length);
g_free (prop);
SendMessage (GDK_DRAWABLE_XID (requestor), gdk_selection_notify_msg, selection, target);
}
}
else
{
g_warning ("gdk_selection_convert: General case not implemented");
}
}
gint
gdk_selection_property_get (GdkWindow *requestor,
guchar **data,
GdkAtom *ret_type,
gint *ret_format)
{
GdkSelProp *prop;
g_return_val_if_fail (requestor != NULL, 0);
g_return_val_if_fail (GDK_IS_WINDOW (requestor), 0);
if (GDK_DRAWABLE_DESTROYED (requestor))
return 0;
GDK_NOTE (SELECTION, g_print ("gdk_selection_property_get: %#x\n",
GDK_DRAWABLE_XID (requestor)));
prop = g_hash_table_lookup (sel_prop_table, &GDK_DRAWABLE_XID (requestor));
if (prop == NULL)
{
*data = NULL;
return 0;
}
*data = g_malloc (prop->length);
if (prop->length > 0)
memmove (*data, prop->data, prop->length);
if (ret_type)
*ret_type = prop->type;
if (ret_format)
*ret_format = prop->format;
return prop->length;
}
void
gdk_selection_property_delete (GdkWindow *window)
{
GdkSelProp *prop;
prop = g_hash_table_lookup (sel_prop_table, &GDK_DRAWABLE_XID (window));
if (prop != NULL)
{
g_free (prop->data);
g_hash_table_remove (sel_prop_table, &GDK_DRAWABLE_XID (window));
}
else
g_warning ("huh?");
}
void
gdk_selection_send_notify (guint32 requestor,
GdkAtom selection,
GdkAtom target,
GdkAtom property,
guint32 time)
{
gchar *sel_name, *tgt_name, *prop_name;
GDK_NOTE (SELECTION,
(sel_name = gdk_atom_name (selection),
tgt_name = gdk_atom_name (target),
prop_name = gdk_atom_name (property),
g_print ("gdk_selection_send_notify: %#x %#x (%s) %#x (%s) %#x (%s)\n",
requestor,
selection, sel_name,
target, tgt_name,
property, prop_name),
g_free (sel_name),
g_free (tgt_name),
g_free (prop_name)));
/* Send ourselves a selection clear message so that gtk thinks we don't
* have the selection, and will claim it anew when needed, and
* we thus get a chance to store data in the Windows clipboard.
* Otherwise, if a gtkeditable does a copy to clipboard several times
* only the first one actually gets copied to the Windows clipboard,
* as only he first one causes a call to gdk_property_change.
*
* Hmm, there is something fishy with this. Cut and paste inside the
* same app didn't work, the gtkeditable immediately forgot the
* clipboard contents in gtk_editable_selection_clear as a result of
* this message. OTOH, when I changed gdk_selection_owner_get to
* always return NULL, it works. Sigh.
*/
SendMessage ((HWND) requestor, gdk_selection_clear_msg, selection, 0);
}
gint
gdk_text_property_to_text_list (GdkAtom encoding,
gint format,
guchar *text,
gint length,
gchar ***list)
{
GDK_NOTE (SELECTION,
g_print ("gdk_text_property_to_text_list not implemented\n"));
return 0;
}
void
gdk_free_text_list (gchar **list)
{
g_return_if_fail (list != NULL);
/* ??? */
}
gint
gdk_string_to_compound_text (gchar *str,
GdkAtom *encoding,
gint *format,
guchar **ctext,
gint *length)
{
g_warning ("gdk_string_to_compound_text: Not implemented");
return 0;
}
void
gdk_free_compound_text (guchar *ctext)
{
g_warning ("gdk_free_compound_text: Not implemented");
}

346
gdk/win32/gdkvisual-win32.c Normal file
View File

@ -0,0 +1,346 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include "gdkvisual.h"
#include "gdkprivate.h"
static void gdk_visual_decompose_mask (gulong mask,
gint *shift,
gint *prec);
static GdkVisualPrivate *system_visual;
static gint available_depths[1];
static GdkVisualType available_types[1];
#ifdef G_ENABLE_DEBUG
static const gchar* visual_names[] =
{
"static gray",
"grayscale",
"static color",
"pseudo color",
"true color",
"direct color",
};
#endif /* G_ENABLE_DEBUG */
void
gdk_visual_init (void)
{
struct
{
BITMAPINFOHEADER bi;
union
{
RGBQUAD colors[256];
DWORD fields[256];
} u;
} bmi;
HBITMAP hbm;
int rastercaps, numcolors, sizepalette, bitspixel;
system_visual = g_new (GdkVisualPrivate, 1);
bitspixel = GetDeviceCaps (gdk_DC, BITSPIXEL);
rastercaps = GetDeviceCaps (gdk_DC, RASTERCAPS);
system_visual->xvisual = g_new (Visual, 1);
system_visual->xvisual->visualid = 0;
system_visual->xvisual->bitspixel = bitspixel;
if (rastercaps & RC_PALETTE)
{
system_visual->visual.type = GDK_VISUAL_PSEUDO_COLOR;
numcolors = GetDeviceCaps (gdk_DC, NUMCOLORS);
sizepalette = GetDeviceCaps (gdk_DC, SIZEPALETTE);
system_visual->xvisual->map_entries = sizepalette;
}
else if (bitspixel == 1)
{
system_visual->visual.type = GDK_VISUAL_STATIC_GRAY;
system_visual->xvisual->map_entries = 2;
}
else if (bitspixel == 4)
{
system_visual->visual.type = GDK_VISUAL_STATIC_COLOR;
system_visual->xvisual->map_entries = 16;
}
else if (bitspixel == 8)
{
system_visual->visual.type = GDK_VISUAL_STATIC_COLOR;
system_visual->xvisual->map_entries = 256;
}
else if (bitspixel == 16)
{
system_visual->visual.type = GDK_VISUAL_TRUE_COLOR;
#if 1
/* This code by Mike Enright,
* see http://www.users.cts.com/sd/m/menright/display.html
*/
memset (&bmi, 0, sizeof (bmi));
bmi.bi.biSize = sizeof (bmi.bi);
hbm = CreateCompatibleBitmap (gdk_DC, 1, 1);
GetDIBits (gdk_DC, hbm, 0, 1, NULL,
(BITMAPINFO *) &bmi, DIB_RGB_COLORS);
GetDIBits (gdk_DC, hbm, 0, 1, NULL,
(BITMAPINFO *) &bmi, DIB_RGB_COLORS);
DeleteObject (hbm);
if (bmi.bi.biCompression != BI_BITFIELDS)
{
/* Either BI_RGB or BI_RLE_something
* .... or perhaps (!!) something else.
* Theoretically biCompression might be
* mmioFourCC('c','v','i','d') but I doubt it.
*/
if (bmi.bi.biCompression == BI_RGB)
{
/* It's 555 */
bitspixel = 15;
system_visual->visual.red_mask = 0x00007C00;
system_visual->visual.green_mask = 0x000003E0;
system_visual->visual.blue_mask = 0x0000001F;
}
else
{
g_assert_not_reached ();
}
}
else
{
DWORD allmasks =
bmi.u.fields[0] | bmi.u.fields[1] | bmi.u.fields[2];
int k = 0;
while (allmasks)
{
if (allmasks&1)
k++;
allmasks/=2;
}
bitspixel = k;
system_visual->visual.red_mask = bmi.u.fields[0];
system_visual->visual.green_mask = bmi.u.fields[1];
system_visual->visual.blue_mask = bmi.u.fields[2];
}
#else
/* Old, incorrect (but still working) code. */
#if 0
system_visual->visual.red_mask = 0x0000F800;
system_visual->visual.green_mask = 0x000007E0;
system_visual->visual.blue_mask = 0x0000001F;
#else
system_visual->visual.red_mask = 0x00007C00;
system_visual->visual.green_mask = 0x000003E0;
system_visual->visual.blue_mask = 0x0000001F;
#endif
#endif
}
else if (bitspixel == 24 || bitspixel == 32)
{
bitspixel = 24;
system_visual->visual.type = GDK_VISUAL_TRUE_COLOR;
system_visual->visual.red_mask = 0x00FF0000;
system_visual->visual.green_mask = 0x0000FF00;
system_visual->visual.blue_mask = 0x000000FF;
}
else
g_error ("gdk_visual_init: unsupported BITSPIXEL: %d\n", bitspixel);
system_visual->visual.depth = bitspixel;
system_visual->visual.byte_order = GDK_LSB_FIRST;
system_visual->visual.bits_per_rgb = 42; /* Not used? */
if ((system_visual->visual.type == GDK_VISUAL_TRUE_COLOR) ||
(system_visual->visual.type == GDK_VISUAL_DIRECT_COLOR))
{
gdk_visual_decompose_mask (system_visual->visual.red_mask,
&system_visual->visual.red_shift,
&system_visual->visual.red_prec);
gdk_visual_decompose_mask (system_visual->visual.green_mask,
&system_visual->visual.green_shift,
&system_visual->visual.green_prec);
gdk_visual_decompose_mask (system_visual->visual.blue_mask,
&system_visual->visual.blue_shift,
&system_visual->visual.blue_prec);
system_visual->xvisual->map_entries =
1 << (MAX (system_visual->visual.red_prec,
MAX (system_visual->visual.green_prec,
system_visual->visual.blue_prec)));
}
else
{
system_visual->visual.red_mask = 0;
system_visual->visual.red_shift = 0;
system_visual->visual.red_prec = 0;
system_visual->visual.green_mask = 0;
system_visual->visual.green_shift = 0;
system_visual->visual.green_prec = 0;
system_visual->visual.blue_mask = 0;
system_visual->visual.blue_shift = 0;
system_visual->visual.blue_prec = 0;
}
system_visual->visual.colormap_size = system_visual->xvisual->map_entries;
available_depths[0] = system_visual->visual.depth;
available_types[0] = system_visual->visual.type;
}
GdkVisual*
gdk_visual_ref (GdkVisual *visual)
{
return visual;
}
void
gdk_visual_unref (GdkVisual *visual)
{
return;
}
gint
gdk_visual_get_best_depth (void)
{
return available_depths[0];
}
GdkVisualType
gdk_visual_get_best_type (void)
{
return available_types[0];
}
GdkVisual*
gdk_visual_get_system (void)
{
return ((GdkVisual*) system_visual);
}
GdkVisual*
gdk_visual_get_best (void)
{
return ((GdkVisual*) system_visual);
}
GdkVisual*
gdk_visual_get_best_with_depth (gint depth)
{
if (depth == system_visual->visual.depth)
return (GdkVisual*) system_visual;
else
return NULL;
}
GdkVisual*
gdk_visual_get_best_with_type (GdkVisualType visual_type)
{
if (visual_type == system_visual->visual.type)
return (GdkVisual*) system_visual;
else
return NULL;
}
GdkVisual*
gdk_visual_get_best_with_both (gint depth,
GdkVisualType visual_type)
{
if ((depth == system_visual->visual.depth) &&
(visual_type == system_visual->visual.type))
return (GdkVisual*) system_visual;
else
return NULL;
}
void
gdk_query_depths (gint **depths,
gint *count)
{
*count = 1;
*depths = available_depths;
}
void
gdk_query_visual_types (GdkVisualType **visual_types,
gint *count)
{
*count = 1;
*visual_types = available_types;
}
GList*
gdk_list_visuals (void)
{
return g_list_append (NULL, (gpointer) system_visual);
}
GdkVisual*
gdk_visual_lookup (Visual *xvisual)
{
if (system_visual->xvisual == xvisual)
return (GdkVisual *) system_visual;
else
return NULL;
}
GdkVisual*
gdkx_visual_get (VisualID xvisualid)
{
if (xvisualid == system_visual->xvisual->visualid)
return (GdkVisual*) system_visual;
else
return NULL;
}
static void
gdk_visual_decompose_mask (gulong mask,
gint *shift,
gint *prec)
{
*shift = 0;
*prec = 0;
while (!(mask & 0x1))
{
(*shift)++;
mask >>= 1;
}
while (mask & 0x1)
{
(*prec)++;
mask >>= 1;
}
}

346
gdk/win32/gdkvisual.c Normal file
View File

@ -0,0 +1,346 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include "gdkvisual.h"
#include "gdkprivate.h"
static void gdk_visual_decompose_mask (gulong mask,
gint *shift,
gint *prec);
static GdkVisualPrivate *system_visual;
static gint available_depths[1];
static GdkVisualType available_types[1];
#ifdef G_ENABLE_DEBUG
static const gchar* visual_names[] =
{
"static gray",
"grayscale",
"static color",
"pseudo color",
"true color",
"direct color",
};
#endif /* G_ENABLE_DEBUG */
void
gdk_visual_init (void)
{
struct
{
BITMAPINFOHEADER bi;
union
{
RGBQUAD colors[256];
DWORD fields[256];
} u;
} bmi;
HBITMAP hbm;
int rastercaps, numcolors, sizepalette, bitspixel;
system_visual = g_new (GdkVisualPrivate, 1);
bitspixel = GetDeviceCaps (gdk_DC, BITSPIXEL);
rastercaps = GetDeviceCaps (gdk_DC, RASTERCAPS);
system_visual->xvisual = g_new (Visual, 1);
system_visual->xvisual->visualid = 0;
system_visual->xvisual->bitspixel = bitspixel;
if (rastercaps & RC_PALETTE)
{
system_visual->visual.type = GDK_VISUAL_PSEUDO_COLOR;
numcolors = GetDeviceCaps (gdk_DC, NUMCOLORS);
sizepalette = GetDeviceCaps (gdk_DC, SIZEPALETTE);
system_visual->xvisual->map_entries = sizepalette;
}
else if (bitspixel == 1)
{
system_visual->visual.type = GDK_VISUAL_STATIC_GRAY;
system_visual->xvisual->map_entries = 2;
}
else if (bitspixel == 4)
{
system_visual->visual.type = GDK_VISUAL_STATIC_COLOR;
system_visual->xvisual->map_entries = 16;
}
else if (bitspixel == 8)
{
system_visual->visual.type = GDK_VISUAL_STATIC_COLOR;
system_visual->xvisual->map_entries = 256;
}
else if (bitspixel == 16)
{
system_visual->visual.type = GDK_VISUAL_TRUE_COLOR;
#if 1
/* This code by Mike Enright,
* see http://www.users.cts.com/sd/m/menright/display.html
*/
memset (&bmi, 0, sizeof (bmi));
bmi.bi.biSize = sizeof (bmi.bi);
hbm = CreateCompatibleBitmap (gdk_DC, 1, 1);
GetDIBits (gdk_DC, hbm, 0, 1, NULL,
(BITMAPINFO *) &bmi, DIB_RGB_COLORS);
GetDIBits (gdk_DC, hbm, 0, 1, NULL,
(BITMAPINFO *) &bmi, DIB_RGB_COLORS);
DeleteObject (hbm);
if (bmi.bi.biCompression != BI_BITFIELDS)
{
/* Either BI_RGB or BI_RLE_something
* .... or perhaps (!!) something else.
* Theoretically biCompression might be
* mmioFourCC('c','v','i','d') but I doubt it.
*/
if (bmi.bi.biCompression == BI_RGB)
{
/* It's 555 */
bitspixel = 15;
system_visual->visual.red_mask = 0x00007C00;
system_visual->visual.green_mask = 0x000003E0;
system_visual->visual.blue_mask = 0x0000001F;
}
else
{
g_assert_not_reached ();
}
}
else
{
DWORD allmasks =
bmi.u.fields[0] | bmi.u.fields[1] | bmi.u.fields[2];
int k = 0;
while (allmasks)
{
if (allmasks&1)
k++;
allmasks/=2;
}
bitspixel = k;
system_visual->visual.red_mask = bmi.u.fields[0];
system_visual->visual.green_mask = bmi.u.fields[1];
system_visual->visual.blue_mask = bmi.u.fields[2];
}
#else
/* Old, incorrect (but still working) code. */
#if 0
system_visual->visual.red_mask = 0x0000F800;
system_visual->visual.green_mask = 0x000007E0;
system_visual->visual.blue_mask = 0x0000001F;
#else
system_visual->visual.red_mask = 0x00007C00;
system_visual->visual.green_mask = 0x000003E0;
system_visual->visual.blue_mask = 0x0000001F;
#endif
#endif
}
else if (bitspixel == 24 || bitspixel == 32)
{
bitspixel = 24;
system_visual->visual.type = GDK_VISUAL_TRUE_COLOR;
system_visual->visual.red_mask = 0x00FF0000;
system_visual->visual.green_mask = 0x0000FF00;
system_visual->visual.blue_mask = 0x000000FF;
}
else
g_error ("gdk_visual_init: unsupported BITSPIXEL: %d\n", bitspixel);
system_visual->visual.depth = bitspixel;
system_visual->visual.byte_order = GDK_LSB_FIRST;
system_visual->visual.bits_per_rgb = 42; /* Not used? */
if ((system_visual->visual.type == GDK_VISUAL_TRUE_COLOR) ||
(system_visual->visual.type == GDK_VISUAL_DIRECT_COLOR))
{
gdk_visual_decompose_mask (system_visual->visual.red_mask,
&system_visual->visual.red_shift,
&system_visual->visual.red_prec);
gdk_visual_decompose_mask (system_visual->visual.green_mask,
&system_visual->visual.green_shift,
&system_visual->visual.green_prec);
gdk_visual_decompose_mask (system_visual->visual.blue_mask,
&system_visual->visual.blue_shift,
&system_visual->visual.blue_prec);
system_visual->xvisual->map_entries =
1 << (MAX (system_visual->visual.red_prec,
MAX (system_visual->visual.green_prec,
system_visual->visual.blue_prec)));
}
else
{
system_visual->visual.red_mask = 0;
system_visual->visual.red_shift = 0;
system_visual->visual.red_prec = 0;
system_visual->visual.green_mask = 0;
system_visual->visual.green_shift = 0;
system_visual->visual.green_prec = 0;
system_visual->visual.blue_mask = 0;
system_visual->visual.blue_shift = 0;
system_visual->visual.blue_prec = 0;
}
system_visual->visual.colormap_size = system_visual->xvisual->map_entries;
available_depths[0] = system_visual->visual.depth;
available_types[0] = system_visual->visual.type;
}
GdkVisual*
gdk_visual_ref (GdkVisual *visual)
{
return visual;
}
void
gdk_visual_unref (GdkVisual *visual)
{
return;
}
gint
gdk_visual_get_best_depth (void)
{
return available_depths[0];
}
GdkVisualType
gdk_visual_get_best_type (void)
{
return available_types[0];
}
GdkVisual*
gdk_visual_get_system (void)
{
return ((GdkVisual*) system_visual);
}
GdkVisual*
gdk_visual_get_best (void)
{
return ((GdkVisual*) system_visual);
}
GdkVisual*
gdk_visual_get_best_with_depth (gint depth)
{
if (depth == system_visual->visual.depth)
return (GdkVisual*) system_visual;
else
return NULL;
}
GdkVisual*
gdk_visual_get_best_with_type (GdkVisualType visual_type)
{
if (visual_type == system_visual->visual.type)
return (GdkVisual*) system_visual;
else
return NULL;
}
GdkVisual*
gdk_visual_get_best_with_both (gint depth,
GdkVisualType visual_type)
{
if ((depth == system_visual->visual.depth) &&
(visual_type == system_visual->visual.type))
return (GdkVisual*) system_visual;
else
return NULL;
}
void
gdk_query_depths (gint **depths,
gint *count)
{
*count = 1;
*depths = available_depths;
}
void
gdk_query_visual_types (GdkVisualType **visual_types,
gint *count)
{
*count = 1;
*visual_types = available_types;
}
GList*
gdk_list_visuals (void)
{
return g_list_append (NULL, (gpointer) system_visual);
}
GdkVisual*
gdk_visual_lookup (Visual *xvisual)
{
if (system_visual->xvisual == xvisual)
return (GdkVisual *) system_visual;
else
return NULL;
}
GdkVisual*
gdkx_visual_get (VisualID xvisualid)
{
if (xvisualid == system_visual->xvisual->visualid)
return (GdkVisual*) system_visual;
else
return NULL;
}
static void
gdk_visual_decompose_mask (gulong mask,
gint *shift,
gint *prec)
{
*shift = 0;
*prec = 0;
while (!(mask & 0x1))
{
(*shift)++;
mask >>= 1;
}
while (mask & 0x1)
{
(*prec)++;
mask >>= 1;
}
}

2407
gdk/win32/gdkwindow-win32.c Normal file

File diff suppressed because it is too large Load Diff

2407
gdk/win32/gdkwindow.c Normal file

File diff suppressed because it is too large Load Diff