diff -Nur skipstone-bak/src/bookmarks.c skipstone/src/bookmarks.c --- skipstone-bak/src/bookmarks.c Fri Jun 22 12:51:36 2001 +++ skipstone/src/bookmarks.c Wed Jul 11 23:28:29 2001 @@ -59,7 +59,7 @@ } url = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(skipstone->combo)->entry)); - title = gtk_moz_embed_get_title(skipstone->embed); + title = mozilla_get_document_title (skipstone->embed, NULL); if (g_strcasecmp(url,"") == 0) { return; diff -Nur skipstone-bak/src/go.c skipstone/src/go.c --- skipstone-bak/src/go.c Sun Apr 15 14:05:27 2001 +++ skipstone/src/go.c Wed Jul 11 23:28:29 2001 @@ -31,7 +31,7 @@ gint list_length; g_return_if_fail(go_menu != NULL); - title = gtk_moz_embed_get_title(skipstone->embed); + title = mozilla_get_document_title (skipstone->embed, NULL); if (!strcmp(location,"about:blank")) return; /* dont add that! */ if (!title || !strcmp(title,"")) title = location; /* no title? use the url */ add_it = check_for_dupe(go_menu,title); diff -Nur skipstone-bak/src/interface-notebook.c skipstone/src/interface-notebook.c --- skipstone-bak/src/interface-notebook.c Fri Jul 6 03:34:23 2001 +++ skipstone/src/interface-notebook.c Wed Jul 11 23:29:48 2001 @@ -264,7 +264,7 @@ gtk_widget_hide(skipstone->vbox); - title = gtk_moz_embed_get_title(skipstone->embed); + title = mozilla_get_document_title (skipstone->embed, NULL); skipstone->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_policy(GTK_WINDOW(skipstone->window), TRUE, TRUE, FALSE); if (title) diff -Nur skipstone-bak/src/moz_callbacks.c skipstone/src/moz_callbacks.c --- skipstone-bak/src/moz_callbacks.c Fri Jul 6 03:34:23 2001 +++ skipstone/src/moz_callbacks.c Wed Jul 11 23:31:10 2001 @@ -127,7 +127,7 @@ if (skipstone->is_notebook) { - title = gtk_moz_embed_get_title(skipstone->embed); + title = mozilla_get_document_title (skipstone->embed, NULL); if (!title || !strcmp(title,"")) title = _("Untitled Document"); if (!config.show_tabs && g_slist_length(window_count) == 1) { @@ -151,7 +151,8 @@ return; } - title = g_strdup_printf("SkipStone - %s", gtk_moz_embed_get_title(skipstone->embed)); + title = g_strdup_printf(_("SkipStone - %s"), mozilla_get_document_title (skipstone->embed, NULL)); + gtk_window_set_title(GTK_WINDOW(skipstone->window), title); g_free(title); diff -Nur skipstone-bak/src/mozilla.cpp skipstone/src/mozilla.cpp --- skipstone-bak/src/mozilla.cpp Sun Jul 8 01:54:44 2001 +++ skipstone/src/mozilla.cpp Wed Jul 11 23:33:15 2001 @@ -50,6 +50,20 @@ #include "nsNetUtil.h" #include "nsIWebBrowserFind.h" +#include "nsIPrefService.h" +#include "nsICharsetConverterManager.h" +#include "nsICharsetConverterManager2.h" +#include "nsIUnicodeEncoder.h" +#include "nsIPrintOptions.h" +#include "nsGfxCIID.h" +#include "nsICacheService.h" +#include "nsIPassword.h" +#include "nsIPasswordManager.h" +#include "nsIDOMWindow.h" +#include "nsIEmbeddingSiteWindow.h" +#include "nsIWindowWatcher.h" +#include "nsIWebBrowserChrome.h" + #include "PromptService.h" #include "nsGfxCIID.h" #include "nsIContentViewer.h" @@ -72,6 +86,8 @@ #define CONTEXT_OTHER 128 #define CONTEXT_XUL 256 +#define UTF8_ENCODER_ID "@mozilla.org/intl/unicode/encoder;1?charset=UTF-8" +#define UTF8_DECODER_ID "@mozilla.org/intl/unicode/decoder;1?charset=UTF-8" static NS_DEFINE_CID(kCTextServicesDocumentCID, NS_TEXTSERVICESDOCUMENT_CID); static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); @@ -83,6 +99,14 @@ static nsIDOMDocument *mozilla_get_dom_document(nsIPresShell *presShell); static gchar *mozilla_get_attribute (nsIDOMNode *node, gchar *attribute); +extern "C" +{ +gchar *mozilla_unicode_to_utf8 (const PRUnichar *uniStr); +gchar *mozilla_unicode_to_locale (const PRUnichar *uniStr); +PRUnichar *mozilla_utf8_to_unicode (const gchar *utfStr); +PRUnichar *mozilla_locale_to_unicode (const gchar *locStr); +} + #define PREF_ID NS_PREF_CONTRACTID class SkipNsHistory @@ -364,17 +388,20 @@ extern "C" gboolean mozilla_find(GtkMozEmbed *b, const char *exp, PRBool IgnoreCase, PRBool SearchBackWards, PRBool DidFind) { + PRUnichar *search_string; + g_return_val_if_fail(b != NULL, FALSE); nsresult result = 0; nsIWebBrowser *wb = nsnull; gtk_moz_embed_get_nsIWebBrowser(b,&wb); nsCOMPtr finder(do_GetInterface(wb)); - nsString searchString; - searchString.AssignWithConversion(exp); - finder->SetSearchString(searchString.get()); + search_string = mozilla_locale_to_unicode (exp); + finder->SetSearchString(search_string); finder->SetFindBackwards(SearchBackWards); finder->SetMatchCase(IgnoreCase); result = finder->FindNext(&DidFind); + g_free (search_string); + return DidFind; } @@ -617,6 +644,197 @@ if (NS_FAILED(result)) return NS_ERROR_FAILURE; result = io->SetOffline(offline); return NS_SUCCEEDED (result) ? TRUE : FALSE; +} + +/** + * mozilla_get_document_title: get the document title in a locale specific + * NULL terminated C string, using the private UniCode interface. + */ +extern "C" gchar * +mozilla_get_document_title (GtkMozEmbed *embed, gchar **title_utf8) +{ + PRUnichar *unicode_title; + gchar *title; + + /* get the title in unicode */ + unicode_title = gtk_moz_embed_get_title_unichar (embed); + + /* do get utf8 version too */ + if (title_utf8 != NULL) + { + *title_utf8 = mozilla_unicode_to_utf8 (unicode_title); + } + + /* attempt conversion */ + title = mozilla_unicode_to_locale (unicode_title); + + /* free unicode version */ + g_free (unicode_title); + + /* return it */ + return title; +} + +/** + * mozilla_unicode_to_utf8: Encodes unicode string to UTF-8 + * @uniStr: The unicode string to encode + */ +extern "C" gchar * +mozilla_unicode_to_utf8 (const PRUnichar *uniStr) +{ + PRInt32 sSize,dSize; + nsresult result; + + const nsString str (uniStr); + + sSize = str.Length (); + + nsCOMPtr + unicodeEncoder = do_CreateInstance (UTF8_ENCODER_ID); + + /* GetMaxLength returns a worst case prediction for the size + of the returned char*. Using it ensures that Convert will + not run out of space */ + result = unicodeEncoder->GetMaxLength (uniStr, sSize, &dSize); + gchar *utfStr = g_new0 (gchar, dSize + 1); + + /* Convert must be passed the size of unicode string and + the size of the char* buffer so that bad things(tm) + won't happen. No null termination here. */ + result = unicodeEncoder->Convert (uniStr, &sSize, utfStr, &dSize); + + /* Finish ensures that the encoder is left in a clean state + for it's next use. */ + result = unicodeEncoder->Finish (utfStr, &dSize); + + /* Normally a null would need to appended at this point but + cStr was initialised to zero, so there's no need */ + return utfStr; +} + +/** + * mozilla_unicode_to_locale: Encodes unicode string to something + * valid for the current locale (which can then be used in GTK+ labels). + * @uniStr: The unicode string to encode + */ +extern "C" gchar * +mozilla_unicode_to_locale (const PRUnichar *uniStr) +{ + PRInt32 sSize; + wchar_t *wide; + gchar *output; + gint i, count; + + /* sanity */ + if (uniStr == NULL) + { + return NULL; + } + + const nsString str (uniStr); + sSize = str.Length (); + + /* allocate a wide string big enough to hold the unicode string, + * this is necessary since wchar_t is 32-bits with glibc */ + wide = g_new0 (wchar_t, sSize + 1); + for (i = 0; i < sSize + 1; i++) + { + wide[i] = uniStr[i]; + } + + /* use glibc function to determine the size of this string once + * encoded to a locale specfic multibyte string */ + count = wcstombs (NULL, wide, 0); + + /* check for success */ + if (count == -1) + { + /* let Mozilla do a (lossy) conversion then */ + nsCString str; + str.AssignWithConversion(uniStr); + g_free (wide); + return g_strdup (str.get()); /* FIXME strdup needed? */ + } + + /* allocate a string big enough and do the actual conversion */ + output = g_new0 (gchar, count + 1); + count = wcstombs (output, wide, count + 1); + g_assert (count != -1); + + /* free wide version and return */ + g_free (wide); + return output; +} + +/** + * mozilla_utf8_to_unicode: Decodes UTF-8 string to unicode + * @utfStr: The unicode string to encode + */ +extern "C" PRUnichar * +mozilla_utf8_to_unicode (const gchar *utfStr) +{ + PRInt32 sSize,dSize; + nsresult result; + + for (sSize = 0; utfStr[sSize] != 0; sSize++); + + nsCOMPtr unicodeDecoder = + do_CreateInstance (UTF8_DECODER_ID); + + /* Unicode decoding is much the same as encoding as + described in mozilla_session_history comments, + but there is no Finish function needed to complete + the process */ + result = unicodeDecoder->GetMaxLength (utfStr, sSize, &dSize); + PRUnichar *uniStr = g_new0 (PRUnichar, dSize + 1); + + result = unicodeDecoder->Convert (utfStr, &sSize, uniStr, &dSize); + + return uniStr; +} + +/** + * mozilla_locale_to_unicode: Decodes a string encoded for the current + * locale into unicode. Used for getting text entered in a GTK+ entry + * into a form which mozilla can use. + * @locStr: The unicode string to encode + */ +extern "C" PRUnichar * +mozilla_locale_to_unicode (const gchar *locStr) +{ + PRUnichar *uniStr; + wchar_t *wide; + gint i, count; + + /* sanity */ + if (locStr == NULL) + { + return NULL; + } + + /* count the number of wide characters which will be produced */ + count = mbstowcs (NULL, locStr, 0); + if (count == -1) + { + /* hmm, shouldnt happen but fallback to utf8 */ + g_warning ("unusual locale string: [%s]\n", locStr); + return mozilla_utf8_to_unicode (locStr); + } + + /* allocate and decode */ + wide = g_new0 (wchar_t, count + 1); + mbstowcs (wide, locStr, count + 1); + + /* make a unicode string and copy into it */ + uniStr = g_new0 (PRUnichar, count + 1); + for (i = 0; i < count + 1; i++) + { + uniStr[i] = wide[i]; + } + + /* free wide string and return the unicode one */ + g_free (wide); + return uniStr; } extern "C" diff -Nur skipstone-bak/src/skipstone.h skipstone/src/skipstone.h --- skipstone-bak/src/skipstone.h Sun Jul 1 01:16:07 2001 +++ skipstone/src/skipstone.h Wed Jul 11 23:34:11 2001 @@ -170,6 +170,7 @@ extern gpointer mozilla_history_init(GtkMozEmbed *b); extern void mozilla_save_image(GtkMozEmbed *b,gchar *location,gchar *FullPath); extern void mozilla_destroy_history(gpointer SkipNsHistory); +extern gchar * mozilla_get_document_title (GtkMozEmbed *embed, gchar **title_utf8); /* go */