gtk2/gdk/win32/gdkdrawable-win32.c

223 lines
5.8 KiB
C
Raw Normal View History

/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
* Copyright (C) 1998-2004 Tor Lillqvist
* Copyright (C) 2001-2005 Hans Breuer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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-2000. 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>
Massive changes. Too many to list here, but I'll try a summary: 2002-02-17 Tor Lillqvist <tml@iki.fi> * gdk/win32/*.c: Massive changes. Too many to list here, but I'll try a summary: 1) Unify GdkPixmap and GdkImage implementation: For each GdkPixmap, allocate a GdkImage, and vice versa. GdkPixmapImplWin32Data has a pointer to the GdkImage. GdkImage::windowing_data is a pointer to the GdkPixmap. This simplifies many pixmap and image related functions a lot, and reduces duplicated code snippets. For instance, there is only one place in gdk/win32 where CreateDIBSection() is called, in the function _gdk_win32_new_pixmap(). Converting a bitmap (GdkPixmap) to a Windows region is almost trivial, with the bitmap bits being readily accessible in the associated GdkImage. All blitting between GdkPixmaps, GdkWindows and GdkImages goes through handled the _gdk_win32_blit() function, which calls different functions to handle the cases of blitting from pixmaps, inside windows (scrolling), or from windows, which all require somewhat different handling. 2) Support 256-color mode. This has long been very broken, now it works more or less OK. Keep the logical palette for each colormap as small as possible while allocating and freeing colors. Select and realize the logical palette associated with a GdkColormap into a DC before drawing or blitting. When the display is in 256-color mode, make it possible for the user to override the size of the palette(s) used with either the GDK_WIN32_MAX_COLORS environment variable, or a -max-colors command line option. It is possible to reduce the palette size all the way down to using just the 16 static colors (which causes the system visual to be of type GDK_VISUAL_STATIC_COLOR. This could possibly be useful if one desperately wants to avoid color flashing. (Note that in order for this to work properly, an as of yet not commited fix to gdkrgb.c is needed.) Handle the palette messages. On WM_PALETTECHANGED, call UpdateColors() for the given window hierarchy. Do this only if a window in some other top-level window hierarchy caused the palette change (realized a palette). Do this max five times in a row (an arbitrarily chosen limit), though, otherwise redraw by generating expose events. On WM_QUERYNEWPALETTE, cause a redraw of the whole window hierarchy by generating GDK_EXPOSE events. 3) Code cleanup in general. For instance, remove the "emulated" X11 structs ColormapStruct, Visual and XStandardColormap. Use the new GDK_DEBUG_* flags for debugging output in the relevant source files. Remove the unused colormap hash table in gdkcolor-win32.c 4) Plug some resource leaks. 2002-02-14 Tor Lillqvist <tml@iki.fi> * gdk/win32/gdkdnd-win32.c (gdk_dropfiles_filter): Use g_filename_to_uri() to actually create legal URIs in the text/uri-list data.
2002-02-17 00:25:05 +00:00
#include <stdio.h>
1999-11-17 00:45:37 +00:00
#include <glib.h>
#include <pango/pangowin32.h>
#include <cairo-win32.h>
Large changes to the Win32 backend, partially made necessary by the 2000-05-02 Tor Lillqvist <tml@iki.fi> Large changes to the Win32 backend, partially made necessary by the changes to the backend-independent internal structures. Attempts to implement similar backing store stuff as on X11. The current (CVS) version of the Win32 backend is *not* as stable as it was before the no-flicker branch was merged. A zipfile with that version is available from http://www.gimp.org/win32/. That should be use by "production" code until this CVS version is usable. (But note, the Win32 backend has never been claimed to be "production quality".) * README.win32: Add the above comment about versions. * gdk/gdkwindow.c: Don't use backing store for now on Win32. * gdk/gdk.def: Update. * gdk/gdkfont.h: Declare temporary Win32-only functions. Will presumably be replaced by some more better mechanism as 1.4 gets closer to release shape. * gdk/makefile.{cygwin,msc}: Update. * gdk/win32/*.c: Correct inclusions of the backend-specific and internal headers. Change code according to changes in these. Use gdk_drawable_*, not gdk_window_* where necessary. * gdk/win32/gdkdnd-win32.c: Use MISC selector for GDK_NOTE, not our old DND. * gdk/win32/gdkdrawable-win32.c (gdk_win32_draw_text): Don't try to interpret single characters as UTF-8. Thanks to Hans Breuer. Use correct function name in warning messages. * gdk/win32/gdkevents-win32.c: Use correct parameter lists for the GSourceFuncs gdk_event_prepare and gdk_event_check. (gdk_event_get_graphics_expose): Do implement, use PeekMessage. Thanks to Hans Breuer. (event_mask_string): Debugging function to print an GdkEventMask. (gdk_pointer_grab): Use it. * gdk/win32/gdkfont-win32.c: The Unicode subrange that the (old) book I used claimed was Hangul actually is CJK Unified Ideographs Extension A. Also, Hangul Syllables were missing. Improve logging. * gdk/win32/gdkgc-win32.c: Largish changes. * gdk/win32/gdkim-win32.c (gdk_set_locale): Use g_win32_getlocale() from GLib, and not setlocale() to get current locale name. * gdk/win32/gdkprivate-win32.h * gdk/win32/gdkwin32.h: Move stuff from gdkprivate-win32.h to gdkwin32.h, similarily as in the X11 backend. * gdk/win32/gdkwindow-win32.c (gdk_propagate_shapes): Bugfix, assignment was used instead of equals in if test. Thanks to Hans Breuer. * gdk/win32/makefile.{cygwin,msc} * gtk/makefile.{cygwin,msc}: Updates. Better kludge to get the path to the Win32 headers that works also with the mingw compiler. * gtk/gtkstyle.c: Include <string.h>.
2000-05-01 22:06:49 +00:00
#include "gdkprivate-win32.h"
1999-11-17 00:45:37 +00:00
static cairo_surface_t *gdk_win32_ref_cairo_surface (GdkDrawable *drawable);
static cairo_surface_t *gdk_win32_create_cairo_surface (GdkDrawable *drawable,
int width,
int height);
static void gdk_drawable_impl_win32_finalize (GObject *object);
static const cairo_user_data_key_t gdk_win32_cairo_key;
G_DEFINE_TYPE (GdkDrawableImplWin32, _gdk_drawable_impl_win32, GDK_TYPE_DRAWABLE)
1999-11-17 00:45:37 +00:00
static void
_gdk_drawable_impl_win32_class_init (GdkDrawableImplWin32Class *klass)
{
GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gdk_drawable_impl_win32_finalize;
drawable_class->ref_cairo_surface = gdk_win32_ref_cairo_surface;
drawable_class->create_cairo_surface = gdk_win32_create_cairo_surface;
}
1999-11-17 00:45:37 +00:00
static void
_gdk_drawable_impl_win32_init (GdkDrawableImplWin32 *impl)
{
}
static void
gdk_drawable_impl_win32_finalize (GObject *object)
{
G_OBJECT_CLASS (_gdk_drawable_impl_win32_parent_class)->finalize (object);
}
1999-11-17 00:45:37 +00:00
/*****************************************************
* Win32 specific implementations of generic functions *
*****************************************************/
1999-11-17 00:45:37 +00:00
/* Drawing
*/
/**
* _gdk_win32_drawable_acquire_dc
* @drawable: a Win32 #GdkDrawable implementation
*
* Gets a DC with the given drawable selected into
* it.
*
* Return value: The DC, on success. Otherwise
* %NULL. If this function succeeded
* _gdk_win32_drawable_release_dc() must be called
* release the DC when you are done using it.
**/
HDC
_gdk_win32_drawable_acquire_dc (GdkDrawable *drawable)
{
GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
if (GDK_IS_WINDOW_IMPL_WIN32 (drawable) &&
GDK_WINDOW_DESTROYED (impl->wrapper))
return NULL;
if (!impl->hdc)
{
2010-10-06 22:14:46 +00:00
impl->hdc = GetDC (impl->handle);
if (!impl->hdc)
WIN32_GDI_FAILED ("GetDC");
}
if (impl->hdc)
{
impl->hdc_count++;
return impl->hdc;
}
else
2009-03-01 13:55:50 +00:00
{
return NULL;
}
}
/**
* _gdk_win32_drawable_release_dc
* @drawable: a Win32 #GdkDrawable implementation
*
* Releases the reference count for the DC
* from _gdk_win32_drawable_acquire_dc()
**/
void
_gdk_win32_drawable_release_dc (GdkDrawable *drawable)
{
GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
g_return_if_fail (impl->hdc_count > 0);
impl->hdc_count--;
if (impl->hdc_count == 0)
{
if (impl->saved_dc_bitmap)
{
GDI_CALL (SelectObject, (impl->hdc, impl->saved_dc_bitmap));
impl->saved_dc_bitmap = NULL;
}
if (impl->hdc)
{
2010-10-06 22:14:46 +00:00
GDI_CALL (ReleaseDC, (impl->handle, impl->hdc));
impl->hdc = NULL;
}
}
}
static cairo_surface_t *
gdk_win32_create_cairo_surface (GdkDrawable *drawable,
gint width,
gint height)
{
/* width and height are determined from the DC */
return gdk_win32_ref_cairo_surface (drawable);
}
static void
gdk_win32_cairo_surface_destroy (void *data)
{
GdkDrawableImplWin32 *impl = data;
_gdk_win32_drawable_release_dc (GDK_DRAWABLE (impl));
impl->cairo_surface = NULL;
}
static cairo_surface_t *
gdk_win32_ref_cairo_surface (GdkDrawable *drawable)
{
GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
if (GDK_IS_WINDOW_IMPL_WIN32 (drawable) &&
GDK_WINDOW_DESTROYED (impl->wrapper))
return NULL;
if (!impl->cairo_surface)
{
HDC hdc = _gdk_win32_drawable_acquire_dc (drawable);
if (!hdc)
return NULL;
impl->cairo_surface = cairo_win32_surface_create (hdc);
cairo_surface_set_user_data (impl->cairo_surface, &gdk_win32_cairo_key,
2009-02-16 18:26:35 +00:00
drawable, gdk_win32_cairo_surface_destroy);
}
else
cairo_surface_reference (impl->cairo_surface);
return impl->cairo_surface;
}
Massive changes. Too many to list here, but I'll try a summary: 2002-02-17 Tor Lillqvist <tml@iki.fi> * gdk/win32/*.c: Massive changes. Too many to list here, but I'll try a summary: 1) Unify GdkPixmap and GdkImage implementation: For each GdkPixmap, allocate a GdkImage, and vice versa. GdkPixmapImplWin32Data has a pointer to the GdkImage. GdkImage::windowing_data is a pointer to the GdkPixmap. This simplifies many pixmap and image related functions a lot, and reduces duplicated code snippets. For instance, there is only one place in gdk/win32 where CreateDIBSection() is called, in the function _gdk_win32_new_pixmap(). Converting a bitmap (GdkPixmap) to a Windows region is almost trivial, with the bitmap bits being readily accessible in the associated GdkImage. All blitting between GdkPixmaps, GdkWindows and GdkImages goes through handled the _gdk_win32_blit() function, which calls different functions to handle the cases of blitting from pixmaps, inside windows (scrolling), or from windows, which all require somewhat different handling. 2) Support 256-color mode. This has long been very broken, now it works more or less OK. Keep the logical palette for each colormap as small as possible while allocating and freeing colors. Select and realize the logical palette associated with a GdkColormap into a DC before drawing or blitting. When the display is in 256-color mode, make it possible for the user to override the size of the palette(s) used with either the GDK_WIN32_MAX_COLORS environment variable, or a -max-colors command line option. It is possible to reduce the palette size all the way down to using just the 16 static colors (which causes the system visual to be of type GDK_VISUAL_STATIC_COLOR. This could possibly be useful if one desperately wants to avoid color flashing. (Note that in order for this to work properly, an as of yet not commited fix to gdkrgb.c is needed.) Handle the palette messages. On WM_PALETTECHANGED, call UpdateColors() for the given window hierarchy. Do this only if a window in some other top-level window hierarchy caused the palette change (realized a palette). Do this max five times in a row (an arbitrarily chosen limit), though, otherwise redraw by generating expose events. On WM_QUERYNEWPALETTE, cause a redraw of the whole window hierarchy by generating GDK_EXPOSE events. 3) Code cleanup in general. For instance, remove the "emulated" X11 structs ColormapStruct, Visual and XStandardColormap. Use the new GDK_DEBUG_* flags for debugging output in the relevant source files. Remove the unused colormap hash table in gdkcolor-win32.c 4) Plug some resource leaks. 2002-02-14 Tor Lillqvist <tml@iki.fi> * gdk/win32/gdkdnd-win32.c (gdk_dropfiles_filter): Use g_filename_to_uri() to actually create legal URIs in the text/uri-list data.
2002-02-17 00:25:05 +00:00
HGDIOBJ
gdk_win32_drawable_get_handle (GdkDrawable *drawable)
{
Massive changes. Too many to list here, but I'll try a summary: 2002-02-17 Tor Lillqvist <tml@iki.fi> * gdk/win32/*.c: Massive changes. Too many to list here, but I'll try a summary: 1) Unify GdkPixmap and GdkImage implementation: For each GdkPixmap, allocate a GdkImage, and vice versa. GdkPixmapImplWin32Data has a pointer to the GdkImage. GdkImage::windowing_data is a pointer to the GdkPixmap. This simplifies many pixmap and image related functions a lot, and reduces duplicated code snippets. For instance, there is only one place in gdk/win32 where CreateDIBSection() is called, in the function _gdk_win32_new_pixmap(). Converting a bitmap (GdkPixmap) to a Windows region is almost trivial, with the bitmap bits being readily accessible in the associated GdkImage. All blitting between GdkPixmaps, GdkWindows and GdkImages goes through handled the _gdk_win32_blit() function, which calls different functions to handle the cases of blitting from pixmaps, inside windows (scrolling), or from windows, which all require somewhat different handling. 2) Support 256-color mode. This has long been very broken, now it works more or less OK. Keep the logical palette for each colormap as small as possible while allocating and freeing colors. Select and realize the logical palette associated with a GdkColormap into a DC before drawing or blitting. When the display is in 256-color mode, make it possible for the user to override the size of the palette(s) used with either the GDK_WIN32_MAX_COLORS environment variable, or a -max-colors command line option. It is possible to reduce the palette size all the way down to using just the 16 static colors (which causes the system visual to be of type GDK_VISUAL_STATIC_COLOR. This could possibly be useful if one desperately wants to avoid color flashing. (Note that in order for this to work properly, an as of yet not commited fix to gdkrgb.c is needed.) Handle the palette messages. On WM_PALETTECHANGED, call UpdateColors() for the given window hierarchy. Do this only if a window in some other top-level window hierarchy caused the palette change (realized a palette). Do this max five times in a row (an arbitrarily chosen limit), though, otherwise redraw by generating expose events. On WM_QUERYNEWPALETTE, cause a redraw of the whole window hierarchy by generating GDK_EXPOSE events. 3) Code cleanup in general. For instance, remove the "emulated" X11 structs ColormapStruct, Visual and XStandardColormap. Use the new GDK_DEBUG_* flags for debugging output in the relevant source files. Remove the unused colormap hash table in gdkcolor-win32.c 4) Plug some resource leaks. 2002-02-14 Tor Lillqvist <tml@iki.fi> * gdk/win32/gdkdnd-win32.c (gdk_dropfiles_filter): Use g_filename_to_uri() to actually create legal URIs in the text/uri-list data.
2002-02-17 00:25:05 +00:00
return GDK_DRAWABLE_HANDLE (drawable);
}
/**
* _gdk_win32_drawable_finish
* @drawable: a Win32 #GdkDrawable implementation
*
* Releases any resources allocated internally for the drawable.
* This is called when the drawable becomes unusable, i.e.
* gdk_window_destroy() is called.
**/
void
_gdk_win32_drawable_finish (GdkDrawable *drawable)
{
GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
if (impl->cairo_surface)
{
cairo_surface_finish (impl->cairo_surface);
2009-03-01 13:55:50 +00:00
cairo_surface_set_user_data (impl->cairo_surface, &gdk_win32_cairo_key, NULL, NULL);
}
2009-03-01 13:55:50 +00:00
g_assert (impl->hdc_count == 0);
}