Use g_filename_to_utf8 to convert the font names Windows gives us from

2000-02-04  Tor Lillqvist  <tml@iki.fi>

* gdk/win32/gdkfont-win32.c (logfont_to_xlfd): Use
g_filename_to_utf8 to convert the font names Windows gives us from
whatever is the default codepage to UTF-8.
(gdk_font_load_internal) Use g_filename_from_utf8 for conversion
in the other direction.

* gdk/win32/gdkgc-win32.c (gdk_win32_gc_set_values): Fix cut&paste
error in debugging output.

2000-02-02  Tor Lillqvist  <tml@iki.fi>

* gdk/win32/gdkwindow-win32.c (gdk_window_clear): Pass zero width
and height parameters to gdk_window_clear_area(). Not minus one.

2000-02-01  Tor Lillqvist  <tml@iki.fi>

* gtk/gtkfilesel.c: Use the g_filename_to_utf8 and
g_filename_from_utf8 functions (which were added a moment ago to
GLib). Some cleanups: Use gbooleans. Use GStrings instead of fixed
size buffers.

* gtk/gtkfilesel.h: Add comment about
gtk_file_selection_get_filename returning the filename in the C
runtime's encoding.

* README.win32
* gdk/gdk.def
* gdk/makefile.{cygwin,msc}
* gtk/gtk.def: Updates.

* gdk/gdkcursor-win32.c: Initialise refcount.
This commit is contained in:
Tor Lillqvist 2000-02-03 01:19:03 +00:00 committed by Tor Lillqvist
parent e489f9c26c
commit e57b1afa2b
19 changed files with 351 additions and 119 deletions

View File

@ -1,9 +1,43 @@
2000-02-04 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkfont-win32.c (logfont_to_xlfd): Use
g_filename_to_utf8 to convert the font names Windows gives us from
whatever is the default codepage to UTF-8.
(gdk_font_load_internal) Use g_filename_from_utf8 for conversion
in the other direction.
* gdk/win32/gdkgc-win32.c (gdk_win32_gc_set_values): Fix cut&paste
error in debugging output.
2000-02-02 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkwindow-win32.c (gdk_window_clear): Pass zero width
and height parameters to gdk_window_clear_area(). Not minus one.
Wed Feb 2 11:58:05 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkdnd.c (gtk_drag_selection_received): Add some sanity
checks if the widget passed to gtk_drag_get_data() was not the
dest widget.
2000-02-01 Tor Lillqvist <tml@iki.fi>
* gtk/gtkfilesel.c: Use the g_filename_to_utf8 and
g_filename_from_utf8 functions (which were added a moment ago to
GLib). Some cleanups: Use gbooleans. Use GStrings instead of fixed
size buffers.
* gtk/gtkfilesel.h: Add comment about
gtk_file_selection_get_filename returning the filename in the C
runtime's encoding.
* README.win32
* gdk/gdk.def
* gdk/makefile.{cygwin,msc}
* gtk/gtk.def: Updates.
* gdk/gdkcursor-win32.c: Initialise refcount.
2000-01-31 Yuan-Chung Cheng <platin@linux.org.tw>
* configure.in: Added "zh_CN.GB2312" to ALL_LINGUAS.

View File

@ -1,9 +1,43 @@
2000-02-04 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkfont-win32.c (logfont_to_xlfd): Use
g_filename_to_utf8 to convert the font names Windows gives us from
whatever is the default codepage to UTF-8.
(gdk_font_load_internal) Use g_filename_from_utf8 for conversion
in the other direction.
* gdk/win32/gdkgc-win32.c (gdk_win32_gc_set_values): Fix cut&paste
error in debugging output.
2000-02-02 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkwindow-win32.c (gdk_window_clear): Pass zero width
and height parameters to gdk_window_clear_area(). Not minus one.
Wed Feb 2 11:58:05 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkdnd.c (gtk_drag_selection_received): Add some sanity
checks if the widget passed to gtk_drag_get_data() was not the
dest widget.
2000-02-01 Tor Lillqvist <tml@iki.fi>
* gtk/gtkfilesel.c: Use the g_filename_to_utf8 and
g_filename_from_utf8 functions (which were added a moment ago to
GLib). Some cleanups: Use gbooleans. Use GStrings instead of fixed
size buffers.
* gtk/gtkfilesel.h: Add comment about
gtk_file_selection_get_filename returning the filename in the C
runtime's encoding.
* README.win32
* gdk/gdk.def
* gdk/makefile.{cygwin,msc}
* gtk/gtk.def: Updates.
* gdk/gdkcursor-win32.c: Initialise refcount.
2000-01-31 Yuan-Chung Cheng <platin@linux.org.tw>
* configure.in: Added "zh_CN.GB2312" to ALL_LINGUAS.

View File

@ -1,9 +1,43 @@
2000-02-04 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkfont-win32.c (logfont_to_xlfd): Use
g_filename_to_utf8 to convert the font names Windows gives us from
whatever is the default codepage to UTF-8.
(gdk_font_load_internal) Use g_filename_from_utf8 for conversion
in the other direction.
* gdk/win32/gdkgc-win32.c (gdk_win32_gc_set_values): Fix cut&paste
error in debugging output.
2000-02-02 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkwindow-win32.c (gdk_window_clear): Pass zero width
and height parameters to gdk_window_clear_area(). Not minus one.
Wed Feb 2 11:58:05 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkdnd.c (gtk_drag_selection_received): Add some sanity
checks if the widget passed to gtk_drag_get_data() was not the
dest widget.
2000-02-01 Tor Lillqvist <tml@iki.fi>
* gtk/gtkfilesel.c: Use the g_filename_to_utf8 and
g_filename_from_utf8 functions (which were added a moment ago to
GLib). Some cleanups: Use gbooleans. Use GStrings instead of fixed
size buffers.
* gtk/gtkfilesel.h: Add comment about
gtk_file_selection_get_filename returning the filename in the C
runtime's encoding.
* README.win32
* gdk/gdk.def
* gdk/makefile.{cygwin,msc}
* gtk/gtk.def: Updates.
* gdk/gdkcursor-win32.c: Initialise refcount.
2000-01-31 Yuan-Chung Cheng <platin@linux.org.tw>
* configure.in: Added "zh_CN.GB2312" to ALL_LINGUAS.

View File

@ -1,9 +1,43 @@
2000-02-04 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkfont-win32.c (logfont_to_xlfd): Use
g_filename_to_utf8 to convert the font names Windows gives us from
whatever is the default codepage to UTF-8.
(gdk_font_load_internal) Use g_filename_from_utf8 for conversion
in the other direction.
* gdk/win32/gdkgc-win32.c (gdk_win32_gc_set_values): Fix cut&paste
error in debugging output.
2000-02-02 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkwindow-win32.c (gdk_window_clear): Pass zero width
and height parameters to gdk_window_clear_area(). Not minus one.
Wed Feb 2 11:58:05 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkdnd.c (gtk_drag_selection_received): Add some sanity
checks if the widget passed to gtk_drag_get_data() was not the
dest widget.
2000-02-01 Tor Lillqvist <tml@iki.fi>
* gtk/gtkfilesel.c: Use the g_filename_to_utf8 and
g_filename_from_utf8 functions (which were added a moment ago to
GLib). Some cleanups: Use gbooleans. Use GStrings instead of fixed
size buffers.
* gtk/gtkfilesel.h: Add comment about
gtk_file_selection_get_filename returning the filename in the C
runtime's encoding.
* README.win32
* gdk/gdk.def
* gdk/makefile.{cygwin,msc}
* gtk/gtk.def: Updates.
* gdk/gdkcursor-win32.c: Initialise refcount.
2000-01-31 Yuan-Chung Cheng <platin@linux.org.tw>
* configure.in: Added "zh_CN.GB2312" to ALL_LINGUAS.

View File

@ -1,9 +1,43 @@
2000-02-04 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkfont-win32.c (logfont_to_xlfd): Use
g_filename_to_utf8 to convert the font names Windows gives us from
whatever is the default codepage to UTF-8.
(gdk_font_load_internal) Use g_filename_from_utf8 for conversion
in the other direction.
* gdk/win32/gdkgc-win32.c (gdk_win32_gc_set_values): Fix cut&paste
error in debugging output.
2000-02-02 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkwindow-win32.c (gdk_window_clear): Pass zero width
and height parameters to gdk_window_clear_area(). Not minus one.
Wed Feb 2 11:58:05 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkdnd.c (gtk_drag_selection_received): Add some sanity
checks if the widget passed to gtk_drag_get_data() was not the
dest widget.
2000-02-01 Tor Lillqvist <tml@iki.fi>
* gtk/gtkfilesel.c: Use the g_filename_to_utf8 and
g_filename_from_utf8 functions (which were added a moment ago to
GLib). Some cleanups: Use gbooleans. Use GStrings instead of fixed
size buffers.
* gtk/gtkfilesel.h: Add comment about
gtk_file_selection_get_filename returning the filename in the C
runtime's encoding.
* README.win32
* gdk/gdk.def
* gdk/makefile.{cygwin,msc}
* gtk/gtk.def: Updates.
* gdk/gdkcursor-win32.c: Initialise refcount.
2000-01-31 Yuan-Chung Cheng <platin@linux.org.tw>
* configure.in: Added "zh_CN.GB2312" to ALL_LINGUAS.

View File

@ -1,9 +1,43 @@
2000-02-04 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkfont-win32.c (logfont_to_xlfd): Use
g_filename_to_utf8 to convert the font names Windows gives us from
whatever is the default codepage to UTF-8.
(gdk_font_load_internal) Use g_filename_from_utf8 for conversion
in the other direction.
* gdk/win32/gdkgc-win32.c (gdk_win32_gc_set_values): Fix cut&paste
error in debugging output.
2000-02-02 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkwindow-win32.c (gdk_window_clear): Pass zero width
and height parameters to gdk_window_clear_area(). Not minus one.
Wed Feb 2 11:58:05 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkdnd.c (gtk_drag_selection_received): Add some sanity
checks if the widget passed to gtk_drag_get_data() was not the
dest widget.
2000-02-01 Tor Lillqvist <tml@iki.fi>
* gtk/gtkfilesel.c: Use the g_filename_to_utf8 and
g_filename_from_utf8 functions (which were added a moment ago to
GLib). Some cleanups: Use gbooleans. Use GStrings instead of fixed
size buffers.
* gtk/gtkfilesel.h: Add comment about
gtk_file_selection_get_filename returning the filename in the C
runtime's encoding.
* README.win32
* gdk/gdk.def
* gdk/makefile.{cygwin,msc}
* gtk/gtk.def: Updates.
* gdk/gdkcursor-win32.c: Initialise refcount.
2000-01-31 Yuan-Chung Cheng <platin@linux.org.tw>
* configure.in: Added "zh_CN.GB2312" to ALL_LINGUAS.

View File

@ -1,9 +1,43 @@
2000-02-04 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkfont-win32.c (logfont_to_xlfd): Use
g_filename_to_utf8 to convert the font names Windows gives us from
whatever is the default codepage to UTF-8.
(gdk_font_load_internal) Use g_filename_from_utf8 for conversion
in the other direction.
* gdk/win32/gdkgc-win32.c (gdk_win32_gc_set_values): Fix cut&paste
error in debugging output.
2000-02-02 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkwindow-win32.c (gdk_window_clear): Pass zero width
and height parameters to gdk_window_clear_area(). Not minus one.
Wed Feb 2 11:58:05 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkdnd.c (gtk_drag_selection_received): Add some sanity
checks if the widget passed to gtk_drag_get_data() was not the
dest widget.
2000-02-01 Tor Lillqvist <tml@iki.fi>
* gtk/gtkfilesel.c: Use the g_filename_to_utf8 and
g_filename_from_utf8 functions (which were added a moment ago to
GLib). Some cleanups: Use gbooleans. Use GStrings instead of fixed
size buffers.
* gtk/gtkfilesel.h: Add comment about
gtk_file_selection_get_filename returning the filename in the C
runtime's encoding.
* README.win32
* gdk/gdk.def
* gdk/makefile.{cygwin,msc}
* gtk/gtk.def: Updates.
* gdk/gdkcursor-win32.c: Initialise refcount.
2000-01-31 Yuan-Chung Cheng <platin@linux.org.tw>
* configure.in: Added "zh_CN.GB2312" to ALL_LINGUAS.

View File

@ -13,8 +13,11 @@ gtk\makefile.msc (or makefile.cygwin).
See the README.win32 file in the GLib distribution for instructions
how to build with gcc.
The same instructions are also useful if you want to build
applications that use GTk+ on Win32.
To use GTk+ on Win32, you also need either of the above mentioned
compilers. Other compilers might work, but don't count on it. The
same instructions on how to set up a correct version of gcc should
also be followed if you want to build applications that use GTk+ with
gcc.
The tablet support uses the Wintab API. The Wintab development kit can
be downloaded from http://www.pointing.com. If you don't care for

View File

@ -10,12 +10,6 @@ EXPORTS
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_color_context_add_palette
gdk_color_context_free
gdk_color_context_free_dither
@ -29,6 +23,12 @@ EXPORTS
gdk_color_context_new_mono
gdk_color_context_query_color
gdk_color_context_query_colors
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
@ -42,9 +42,10 @@ EXPORTS
gdk_colors_alloc
gdk_colors_free
gdk_colors_store
gdk_cursor_destroy
gdk_cursor_new
gdk_cursor_new_from_pixmap
gdk_cursor_ref
gdk_cursor_unref
gdk_dnd_init
gdk_drag_abort
gdk_drag_begin
@ -112,14 +113,14 @@ EXPORTS
gdk_exit
gdk_flush
gdk_font_equal
gdk_font_full_name_free
gdk_font_full_name_get
gdk_font_id
gdk_font_list_free
gdk_font_list_new
gdk_font_load
gdk_font_ref
gdk_font_unref
gdk_font_full_name_get
gdk_font_full_name_free
gdk_fontset_load
gdk_free_compound_text
gdk_free_text_list

View File

@ -31,6 +31,7 @@ all: \
gdk_OBJECTS = \
gdk.o \
gdkcolor.o \
gdkcursor.o \
gdkdraw.o \
gdkevents.o \
gdkfont.o \

View File

@ -40,6 +40,7 @@ all: \
gdk_OBJECTS = \
gdk.obj \
gdkcolor.obj \
gdkcursor.obj \
gdkdraw.obj \
gdkevents.obj \
gdkfont.obj \

View File

@ -132,6 +132,7 @@ gdk_cursor_new (GdkCursorType cursor_type)
private->xcursor = xcursor;
cursor = (GdkCursor*) private;
cursor->type = cursor_type;
cursor->refcount = 1;
return cursor;
}
@ -262,12 +263,12 @@ _gdk_cursor_destroy (GdkCursor *cursor)
g_return_if_fail (cursor != NULL);
private = (GdkCursorPrivate *) cursor;
GDK_NOTE (MISC, g_print ("gdk_cursor_destroy: %#x\n",
GDK_NOTE (MISC, g_print ("_gdk_cursor_destroy: %#x\n",
(cursor->type == GDK_CURSOR_IS_PIXMAP) ? private->xcursor : 0));
if (cursor->type == GDK_CURSOR_IS_PIXMAP)
if (!DestroyIcon (private->xcursor))
g_warning ("gdk_cursor_destroy: DestroyIcon failed");
g_warning ("_gdk_cursor_destroy: DestroyIcon failed");
g_free (private);
}

View File

@ -134,7 +134,8 @@ logfont_to_xlfd (const LOGFONT *lfp,
const gchar *registry, *encoding;
int point_size;
static int logpixelsy = 0;
gchar facename[LF_FACESIZE*3];
gchar facename[LF_FACESIZE*5];
gchar *utf8_facename;
gchar *p;
const gchar *q;
@ -218,9 +219,14 @@ logfont_to_xlfd (const LOGFONT *lfp,
if (res == -1)
res = logpixelsy;
/* Replace illegal characters with hex escapes. */
/* Convert the facename Windows fives us from the locale-dependent
* codepage to UTF-8.
*/
utf8_facename = g_filename_to_utf8 (lfp->lfFaceName);
/* Replace characters illegal in an XLFD with hex escapes. */
p = facename;
q = lfp->lfFaceName;
q = utf8_facename;
while (*q)
{
if (*q == '-' || *q == '*' || *q == '?' || *q == '%')
@ -230,8 +236,9 @@ logfont_to_xlfd (const LOGFONT *lfp,
q++;
}
*p = '\0';
g_free (utf8_facename);
return g_strdup_printf
return g_strdup_printf
("-%s-%s-%s-%s-%s-%s-%d-%d-%d-%d-%s-%d-%s-%s",
"unknown",
facename,
@ -259,6 +266,7 @@ gdk_font_full_name_get (GdkFont *font)
GSList *list;
GString *string;
gchar *result;
gchar *xlfd;
LOGFONT logfont;
g_return_val_if_fail (font != NULL, NULL);
@ -278,9 +286,9 @@ gdk_font_full_name_get (GdkFont *font)
return NULL;
}
string =
g_string_append (string,
logfont_to_xlfd (&logfont, logfont.lfHeight, -1, 0));
xlfd = logfont_to_xlfd (&logfont, logfont.lfHeight, -1, 0);
string = g_string_append (string, xlfd);
g_free (xlfd);
list = list->next;
if (list)
string = g_string_append_c (string, ',');
@ -1124,7 +1132,7 @@ gdk_font_load_internal (const gchar *font_name)
DWORD fdwItalic, fdwUnderline, fdwStrikeOut, fdwCharSet,
fdwOutputPrecision, fdwClipPrecision, fdwQuality, fdwPitchAndFamily;
HGDIOBJ oldfont;
const char *lpszFace;
char *lpszFace;
gchar face[100];
int numfields, n1, n2, tries;
@ -1164,7 +1172,7 @@ gdk_font_load_internal (const gchar *font_name)
fdwClipPrecision = CLIP_DEFAULT_PRECIS;
fdwQuality = PROOF_QUALITY;
fdwPitchAndFamily = DEFAULT_PITCH;
lpszFace = font_name;
lpszFace = g_filename_from_utf8 (font_name);
}
else if (numfields != 5)
{
@ -1176,7 +1184,7 @@ gdk_font_load_internal (const gchar *font_name)
/* It must be a XLFD name */
/* Check for hex escapes in the font family,
* put in there by gtkfontsel.
* put in there by logfont_to_xlfd. Convert them in-place.
*/
p = family;
while (*p)
@ -1351,7 +1359,7 @@ gdk_font_load_internal (const gchar *font_name)
fdwPitchAndFamily = VARIABLE_PITCH;
else
fdwPitchAndFamily = DEFAULT_PITCH;
lpszFace = family;
lpszFace = g_filename_from_utf8 (family);
}
for (tries = 0; ; tries++)
@ -1364,15 +1372,20 @@ gdk_font_load_internal (const gchar *font_name)
fnWeight, fdwItalic, fdwUnderline, fdwStrikeOut,
fdwCharSet, fdwOutputPrecision, fdwClipPrecision,
fdwQuality, fdwPitchAndFamily, lpszFace));
if ((hfont =
CreateFont (nHeight, nWidth, nEscapement, nOrientation,
fnWeight, fdwItalic, fdwUnderline, fdwStrikeOut,
fdwCharSet, fdwOutputPrecision, fdwClipPrecision,
fdwQuality, fdwPitchAndFamily, lpszFace)) != NULL)
hfont = CreateFont (nHeight, nWidth, nEscapement, nOrientation,
fnWeight, fdwItalic, fdwUnderline, fdwStrikeOut,
fdwCharSet, fdwOutputPrecision, fdwClipPrecision,
fdwQuality, fdwPitchAndFamily, lpszFace);
/* After the first try lpszFace contains a return value
* from g_filename_from_utf8(), so free it.
*/
if (tries == 0)
g_free (lpszFace);
if (hfont != NULL)
break;
/* If we fail, try some similar fonts often found on Windows. */
if (tries == 0)
{
if (g_strcasecmp (family, "helvetica") == 0)

View File

@ -431,7 +431,7 @@ gdk_win32_gc_set_values (GdkGC *gc,
if (values_mask & GDK_GC_BACKGROUND)
{
GDK_NOTE (MISC, g_print ("bg = %s ",
gdk_color_to_string (&values->foreground)));
gdk_color_to_string (&values->background)));
data->background = values->background;
data->values_mask |= GDK_GC_BACKGROUND;
}

View File

@ -240,7 +240,7 @@ gdk_wcstombs (const GdkWChar *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
* On Win32, the 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!
*/
@ -391,4 +391,3 @@ gdk_nmbstowchar_ts (wchar_t *dest,
return n;
}

View File

@ -1003,7 +1003,7 @@ gdk_window_clear (GdkWindow *window)
g_return_if_fail (GDK_IS_WINDOW (window));
if (!GDK_DRAWABLE_DESTROYED (window))
gdk_window_clear_area (window, 0, 0, -1, -1);
gdk_window_clear_area (window, 0, 0, 0, 0);
}

View File

@ -343,6 +343,7 @@ EXPORTS
gtk_container_forall
gtk_container_foreach
gtk_container_foreach_full
gtk_container_get_toplevels
gtk_container_get_type
gtk_container_query_child_args
gtk_container_queue_resize
@ -353,6 +354,7 @@ EXPORTS
gtk_container_set_focus_child
gtk_container_set_focus_hadjustment
gtk_container_set_focus_vadjustment
gtk_container_set_reallocate_redraws
gtk_container_set_resize_mode
gtk_container_unregister_toplevel
gtk_ctree_collapse
@ -365,6 +367,7 @@ EXPORTS
gtk_ctree_export_to_gnode
gtk_ctree_find
gtk_ctree_find_all_by_row_data
gtk_ctree_find_all_by_row_data_custom
gtk_ctree_find_by_row_data
gtk_ctree_find_by_row_data_custom
gtk_ctree_find_node_ptr
@ -663,6 +666,7 @@ EXPORTS
gtk_list_unselect_child
gtk_list_unselect_item
gtk_main
gtk_main_do_event
gtk_main_iteration
gtk_main_iteration_do
gtk_main_level
@ -811,6 +815,7 @@ EXPORTS
gtk_object_ref
gtk_object_remove_data
gtk_object_remove_data_by_id
gtk_object_remove_no_notify
gtk_object_remove_no_notify_by_id
gtk_object_set
gtk_object_set_data
@ -1279,10 +1284,12 @@ EXPORTS
gtk_widget_newv
gtk_widget_path
gtk_widget_pop_colormap
gtk_widget_pop_composite_child
gtk_widget_pop_style
gtk_widget_pop_visual
gtk_widget_popup
gtk_widget_push_colormap
gtk_widget_push_composite_child
gtk_widget_push_style
gtk_widget_push_visual
gtk_widget_queue_clear

View File

@ -26,10 +26,6 @@
#include "config.h"
#include <glib.h> /* To get stat->_stat redefinition
* for mingw32
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -137,8 +133,6 @@ struct _CompletionDirSent
dev_t device;
gint entry_count;
gchar *name_buffer; /* memory segment containing names of all entries */
struct _CompletionDirEntry *entries;
};
@ -164,7 +158,7 @@ struct _CompletionDir
*/
struct _CompletionDirEntry
{
gint is_dir;
gboolean is_dir;
gchar *entry_name;
};
@ -181,7 +175,7 @@ struct _PossibleCompletion
*/
gchar *text;
gint is_a_completion;
gint is_directory;
gboolean is_directory;
/* Private fields
*/
@ -194,7 +188,7 @@ struct _CompletionState
gchar *updated_text;
gint updated_text_len;
gint updated_text_alloc;
gint re_complete;
gboolean re_complete;
gchar *user_dir_name_buffer;
gint user_directories_len;
@ -242,7 +236,7 @@ static gint cmpl_is_a_completion (PossibleCompletion*);
/* True if the completion is a directory
*/
static gint cmpl_is_directory (PossibleCompletion*);
static gboolean cmpl_is_directory (PossibleCompletion*);
/* Obtains the next completion, or NULL
*/
@ -260,7 +254,7 @@ static gchar* cmpl_updated_text (CompletionState* cmpl_state)
/* After updating, to see if the completion was a directory, call
* this. If it was, you should consider re-calling completion_matches.
*/
static gint cmpl_updated_dir (CompletionState* cmpl_state);
static gboolean cmpl_updated_dir (CompletionState* cmpl_state);
/* Current location: if using file completion, return the current
* directory, from which file completion begins. More specifically,
@ -703,7 +697,7 @@ void
gtk_file_selection_set_filename (GtkFileSelection *filesel,
const gchar *filename)
{
char buf[MAXPATHLEN];
gchar *buf;
const char *name, *last_slash;
g_return_if_fail (filesel != NULL);
@ -714,16 +708,13 @@ gtk_file_selection_set_filename (GtkFileSelection *filesel,
if (!last_slash)
{
buf[0] = 0;
buf = g_strdup ("");
name = filename;
}
else
{
gint len = MIN (MAXPATHLEN - 1, last_slash - filename + 1);
strncpy (buf, filename, len);
buf[len] = 0;
buf = g_strdup (filename);
buf[last_slash - filename + 1] = 0;
name = last_slash + 1;
}
@ -731,6 +722,7 @@ gtk_file_selection_set_filename (GtkFileSelection *filesel,
if (filesel->selection_entry)
gtk_entry_set_text (GTK_ENTRY (filesel->selection_entry), name);
g_free (buf);
}
gchar*
@ -750,7 +742,7 @@ gtk_file_selection_get_filename (GtkFileSelection *filesel)
if (text)
{
filename = cmpl_completion_fullname (text, filesel->cmpl_state);
return filename;
return g_filename_from_utf8 (filename);
}
return nothing;
@ -1661,7 +1653,7 @@ cmpl_updated_text (CompletionState* cmpl_state)
return cmpl_state->updated_text;
}
static gint
static gboolean
cmpl_updated_dir (CompletionState* cmpl_state)
{
return cmpl_state->re_complete;
@ -1737,7 +1729,7 @@ cmpl_this_completion (PossibleCompletion* pc)
return pc->text;
}
static gint
static gboolean
cmpl_is_directory (PossibleCompletion* pc)
{
return pc->is_directory;
@ -1845,7 +1837,9 @@ free_dir(CompletionDir* dir)
static void
free_dir_sent(CompletionDirSent* sent)
{
g_free(sent->name_buffer);
gint i;
for (i = 0; i < sent->entry_count; i++)
g_free(sent->entries[i].entry_name);
g_free(sent->entries);
g_free(sent);
}
@ -2102,32 +2096,22 @@ open_relative_dir(gchar* dir_name,
CompletionDir* dir,
CompletionState *cmpl_state)
{
gchar path_buf[2*MAXPATHLEN];
CompletionDir *result;
GString *path;
if(dir->fullname_len + strlen(dir_name) + 2 >= MAXPATHLEN)
{
cmpl_errno = CMPL_ERRNO_TOO_LONG;
return NULL;
}
path = g_string_sized_new (dir->fullname_len + strlen (dir_name) + 10);
g_string_assign (path, dir->fullname);
strcpy(path_buf, dir->fullname);
if(dir->fullname_len > 1
&& path->str[dir->fullname_len - 1] != G_DIR_SEPARATOR)
g_string_append_c (path, G_DIR_SEPARATOR);
g_string_append (path, dir_name);
if(dir->fullname_len > 1)
{
if (path_buf[dir->fullname_len - 1] != G_DIR_SEPARATOR)
{
path_buf[dir->fullname_len] = G_DIR_SEPARATOR;
strcpy (path_buf + dir->fullname_len + 1, dir_name);
}
else
strcpy (path_buf + dir->fullname_len, dir_name);
}
else
{
strcpy(path_buf + dir->fullname_len, dir_name);
}
result = open_dir(path->str, cmpl_state);
return open_dir(path_buf, cmpl_state);
g_string_free (path, TRUE);
return result;
}
/* after the cache lookup fails, really open a new directory */
@ -2138,29 +2122,23 @@ open_new_dir(gchar* dir_name, struct stat* sbuf, gboolean stat_subdirs)
DIR* directory;
gchar *buffer_ptr;
struct dirent *dirent_ptr;
gint buffer_size = 0;
gint entry_count = 0;
gint i;
struct stat ent_sbuf;
char path_buf[MAXPATHLEN*2];
gint path_buf_len;
GString *path;
gchar *xdir, *xname;
int entry_len;
sent = g_new(CompletionDirSent, 1);
sent->mtime = sbuf->st_mtime;
sent->inode = sbuf->st_ino;
sent->device = sbuf->st_dev;
path_buf_len = strlen(dir_name);
path = g_string_sized_new (2*MAXPATHLEN + 10);
if (path_buf_len > MAXPATHLEN)
{
cmpl_errno = CMPL_ERRNO_TOO_LONG;
return NULL;
}
strcpy(path_buf, dir_name);
directory = opendir(dir_name);
xdir = g_filename_from_utf8 (dir_name);
directory = opendir(xdir);
g_free (xdir);
if(!directory)
{
@ -2170,24 +2148,12 @@ open_new_dir(gchar* dir_name, struct stat* sbuf, gboolean stat_subdirs)
while((dirent_ptr = readdir(directory)) != NULL)
{
int entry_len = strlen(dirent_ptr->d_name);
buffer_size += entry_len + 1;
entry_count += 1;
if(path_buf_len + entry_len + 2 >= MAXPATHLEN)
{
cmpl_errno = CMPL_ERRNO_TOO_LONG;
closedir(directory);
return NULL;
}
entry_count++;
}
sent->name_buffer = g_new(gchar, buffer_size);
sent->entries = g_new(CompletionDirEntry, entry_count);
sent->entry_count = entry_count;
buffer_ptr = sent->name_buffer;
rewinddir(directory);
for(i = 0; i < entry_count; i += 1)
@ -2201,33 +2167,29 @@ open_new_dir(gchar* dir_name, struct stat* sbuf, gboolean stat_subdirs)
return NULL;
}
strcpy(buffer_ptr, dirent_ptr->d_name);
sent->entries[i].entry_name = buffer_ptr;
buffer_ptr += strlen(dirent_ptr->d_name);
*buffer_ptr = 0;
buffer_ptr += 1;
sent->entries[i].entry_name = g_filename_to_utf8 (dirent_ptr->d_name);
if (path_buf[path_buf_len-1] != G_DIR_SEPARATOR)
g_string_assign (path, dir_name);
if (path->str[path->len-1] != G_DIR_SEPARATOR)
{
path_buf[path_buf_len] = G_DIR_SEPARATOR;
strcpy(path_buf + path_buf_len + 1, dirent_ptr->d_name);
g_string_append_c (path, G_DIR_SEPARATOR);
}
else
strcpy(path_buf + path_buf_len, dirent_ptr->d_name);
g_string_append (path, dirent_ptr->d_name);
if (stat_subdirs)
{
if(stat(path_buf, &ent_sbuf) >= 0 && S_ISDIR(ent_sbuf.st_mode))
sent->entries[i].is_dir = 1;
if(stat(path->str, &ent_sbuf) >= 0 && S_ISDIR(ent_sbuf.st_mode))
sent->entries[i].is_dir = TRUE;
else
/* stat may fail, and we don't mind, since it could be a
* dangling symlink. */
sent->entries[i].is_dir = 0;
sent->entries[i].is_dir = FALSE;
}
else
sent->entries[i].is_dir = 1;
}
g_string_free (path, TRUE);
qsort(sent->entries, sent->entry_count, sizeof(CompletionDirEntry), compare_cmpl_dir);
closedir(directory);
@ -2562,7 +2524,7 @@ attempt_homedir_completion(gchar* text_to_complete,
}
cmpl_state->the_completion.is_a_completion = 1;
cmpl_state->the_completion.is_directory = 1;
cmpl_state->the_completion.is_directory = TRUE;
append_completion_text("~", cmpl_state);
@ -2583,7 +2545,7 @@ attempt_homedir_completion(gchar* text_to_complete,
{
cmpl_state->user_completion_index += 1;
cmpl_state->the_completion.is_a_completion = 1;
cmpl_state->the_completion.is_directory = 1;
cmpl_state->the_completion.is_directory = TRUE;
return append_completion_text("~" G_DIR_SEPARATOR_S, cmpl_state);
}

View File

@ -86,7 +86,13 @@ GtkType gtk_file_selection_get_type (void);
GtkWidget* gtk_file_selection_new (const gchar *title);
void gtk_file_selection_set_filename (GtkFileSelection *filesel,
const gchar *filename);
/* This function returns the selected filename in the C runtime's
* multibyte string encoding, which may or may not be the same as that
* used by GDK (UTF-8). To convert to UTF-8, call g_filename_to_utf8().
* The returned string should be deallocated with g_free().
*/
gchar* gtk_file_selection_get_filename (GtkFileSelection *filesel);
void gtk_file_selection_complete (GtkFileSelection *filesel,
const gchar *pattern);
void gtk_file_selection_show_fileop_buttons (GtkFileSelection *filesel);