diff -ur skipstone-0.7.5-bak/src/bookmarks.c skipstone-0.7.5/src/bookmarks.c --- skipstone-0.7.5-bak/src/bookmarks.c Sat Aug 18 02:49:51 2001 +++ skipstone-0.7.5/src/bookmarks.c Tue Sep 11 20:10:49 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); if (g_strcasecmp(url,"") == 0) { return; diff -ur skipstone-0.7.5-bak/src/go.c skipstone-0.7.5/src/go.c --- skipstone-0.7.5-bak/src/go.c Sat Aug 18 02:49:51 2001 +++ skipstone-0.7.5/src/go.c Tue Sep 11 20:11:01 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); 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 -ur skipstone-0.7.5-bak/src/interface-notebook.c skipstone-0.7.5/src/interface-notebook.c --- skipstone-0.7.5-bak/src/interface-notebook.c Sat Aug 18 02:49:51 2001 +++ skipstone-0.7.5/src/interface-notebook.c Tue Sep 11 20:11:23 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); skipstone->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_policy(GTK_WINDOW(skipstone->window), TRUE, TRUE, FALSE); if (title) diff -ur skipstone-0.7.5-bak/src/moz_callbacks.c skipstone-0.7.5/src/moz_callbacks.c --- skipstone-0.7.5-bak/src/moz_callbacks.c Sat Aug 18 02:49:51 2001 +++ skipstone-0.7.5/src/moz_callbacks.c Tue Sep 11 20:11:44 2001 @@ -127,7 +127,7 @@ gint free_title=0; if (skipstone->is_notebook) { - title = gtk_moz_embed_get_title(skipstone->embed); + title = mozilla_get_document_title (skipstone->embed); if (!title || !strcmp(title,"")) { title = g_strdup(_("Untitled Document")); @@ -156,7 +156,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)); + gtk_window_set_title(GTK_WINDOW(skipstone->window), title); g_free(title); diff -ur skipstone-0.7.5-bak/src/mozilla.cpp skipstone-0.7.5/src/mozilla.cpp --- skipstone-0.7.5-bak/src/mozilla.cpp Sat Aug 18 02:49:51 2001 +++ skipstone-0.7.5/src/mozilla.cpp Tue Sep 11 20:33:20 2001 @@ -50,6 +50,11 @@ #include "nsNetUtil.h" #include "nsIWebBrowserFind.h" +#include "nsIUnicodeEncoder.h" +#include "nsIUnicodeDecoder.h" +#include "nsIPlatformCharset.h" +#include "nsICharsetConverterManager.h" + #include "PromptService.h" #include "nsGfxCIID.h" #include "nsIContentViewer.h" @@ -72,17 +77,23 @@ #define CONTEXT_OTHER 128 #define CONTEXT_XUL 256 - static NS_DEFINE_CID(kCTextServicesDocumentCID, NS_TEXTSERVICESDOCUMENT_CID); static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID); static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); +static NS_DEFINE_CID(kPlatformCharsetCID, NS_PLATFORMCHARSET_CID); static nsIDocShell *mozilla_get_docshell (GtkMozEmbed *b); static nsIPresShell *mozilla_get_presShell(nsIDocShell *docShell); static nsIDOMDocument *mozilla_get_dom_document(nsIPresShell *presShell); static gchar *mozilla_get_attribute (nsIDOMNode *node, gchar *attribute); +extern "C" +{ +gchar *mozilla_unicode_to_locale (const PRUnichar *uniStr); +PRUnichar *mozilla_locale_to_unicode (const gchar *locStr); +} + #define PREF_ID NS_PREF_CONTRACTID class SkipNsHistory @@ -371,17 +382,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; } @@ -624,6 +638,148 @@ 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) +{ + PRUnichar *unicode_title; + gchar *title; + + /* get the title in unicode */ + unicode_title = gtk_moz_embed_get_title_unichar (embed); + + /* attempt conversion */ + title = mozilla_unicode_to_locale (unicode_title); + + /* free unicode version */ + g_free (unicode_title); + + /* return it */ + return title; +} + +/** + * 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,dSize; + gchar *output; + nsAutoString platformCharset; + nsresult rv; + + /* sanity */ + if (uniStr == NULL) + { + return NULL; + } + + nsCOMPtr svc; + nsCOMPtr ccm; + nsCOMPtr encoder; + const nsString str (uniStr); + + svc = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) + { + rv = svc->GetCharset(kPlatformCharsetSel_Menu, + platformCharset); + } + if (NS_SUCCEEDED(rv)) + { + ccm = do_GetService (NS_CHARSETCONVERTERMANAGER_CONTRACTID, + &rv); + } + if (NS_SUCCEEDED(rv)) + { + rv = ccm->GetUnicodeEncoder(&platformCharset, + getter_AddRefs(encoder)); + } + if (NS_SUCCEEDED(rv)) { + sSize = str.Length (); + encoder->GetMaxLength (str.get(), sSize, &dSize); + if (dSize) + { + output = g_new0 (gchar, dSize + 1); + encoder->Convert (str.get(), &sSize, output, &dSize); + encoder->Finish (output, &dSize); + encoder->Reset (); + return output; + } + } + /* return empty string, if something fail */ + output = g_new0 (gchar, 1); + *output = '\0'; + return output; +} + +/** + * 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) +{ + PRInt32 sSize,dSize; + PRUnichar *uniStr; + nsAutoString platformCharset; + nsresult rv; + + /* sanity */ + if (locStr == NULL) + { + return NULL; + } + + nsCOMPtr svc; + nsCOMPtr ccm; + nsCOMPtr decoder; + + svc = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) + { + rv = svc->GetCharset(kPlatformCharsetSel_Menu, + platformCharset); + } + if (NS_SUCCEEDED(rv)) + { + ccm = do_GetService (NS_CHARSETCONVERTERMANAGER_CONTRACTID, + &rv); + } + if (NS_SUCCEEDED(rv)) + { + rv = ccm->GetUnicodeDecoder(&platformCharset, + getter_AddRefs(decoder)); + } + if (NS_SUCCEEDED(rv)) + { + /* FIXME: if locStr in UTF-16/UCS-2/UCS-4 etc, + this will not work */ + sSize = strlen(locStr); + decoder->GetMaxLength (locStr, sSize, &dSize); + if (dSize) + { + uniStr = g_new0 (PRUnichar, dSize + 1); + decoder->Convert (locStr, &sSize, uniStr, &dSize); + uniStr[dSize] = '\0'; + decoder->Reset (); + return uniStr; + } + } + /* return empty string, if something fail */ + uniStr = g_new0 (PRUnichar, 1); + uniStr[0] = '\0'; + return uniStr; } extern "C" diff -ur skipstone-0.7.5-bak/src/skipstone.h skipstone-0.7.5/src/skipstone.h --- skipstone-0.7.5-bak/src/skipstone.h Sat Aug 18 02:49:51 2001 +++ skipstone-0.7.5/src/skipstone.h Tue Sep 11 20:09:48 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); /* go */