Author: fabien
Date: 2008-11-05 04:54:39 -0800 (Wed, 05 Nov 2008)
New Revision: 6498
Log:
Got inspired from manolo STR#2067 proposal to fix OSX window title not utf8 
aware, but generalized it so that all Fl_mac.cxx calls the same new 
q_set_window_title() function(). Now OSX Window shows UTF8 title correctly. old 
code is still present but factorized in the new q_set_window_title() 
function(BTW the Str255 truncation was omitted in one part of the old code), 
please review so that we can remove that old non-UTF8 aware code.

Modified:
   branches/branch-1.3/src/Fl_mac.cxx

Modified: branches/branch-1.3/src/Fl_mac.cxx
===================================================================
--- branches/branch-1.3/src/Fl_mac.cxx  2008-11-05 01:55:17 UTC (rev 6497)
+++ branches/branch-1.3/src/Fl_mac.cxx  2008-11-05 12:54:39 UTC (rev 6498)
@@ -1956,8 +1956,25 @@
   breakMacEventLoop();
   return noErr;
 }
+// fc:  
+static void  q_set_window_title(Window xid, const char * name ) {
+#if 1
+    CFStringRef utf8_title = CFStringCreateWithCString(NULL, (name ? name : 
""), kCFStringEncodingUTF8);
+    SetWindowTitleWithCFString(xid, utf8_title);
+    CFRelease(utf8_title);
+#else // old non-utf8 code to remove after new utf8 code approval :
+    Str255 pTitle;
+    if (name) {
+      if (strlen(name) > 255) pTitle[0] = 255;
+      else pTitle[0] = strlen(name);
+      memcpy(pTitle+1, name, pTitle[0]);
+    } 
+    else 
+      pTitle[0] = 0;
+    SetWTitle(xid, pTitle);
+#endif
+}
 
-
 /**
  * go ahead, create that (sub)window
  * \todo we should make menu windows slightly transparent for the new Mac look
@@ -2068,14 +2085,7 @@
     wRect.right  = w->x() + w->w(); if (wRect.right<=wRect.left) wRect.right = 
wRect.left+1;
 
     const char *name = w->label();
-    Str255 pTitle; 
-    if (name) {
-      if (strlen(name) > 255) pTitle[0] = 255;
-      else pTitle[0] = strlen(name);
 
-      memcpy(pTitle+1, name, pTitle[0]);
-    } else pTitle[0] = 0;
-
     Fl_X* x = new Fl_X;
     x->other_xid = 0; // room for doublebuffering image map. On OS X this is 
only used by overlay windows
     x->region = 0;
@@ -2087,7 +2097,7 @@
 
     winattr &= GetAvailableWindowAttributes( winclass );       // make sure 
that the window will open
     CreateNewWindow( winclass, winattr, &wRect, &(x->xid) );
-    SetWTitle(x->xid, pTitle);
+    q_set_window_title(x->xid, name);
     MoveWindow(x->xid, wRect.left, wRect.top, 1);      // avoid Carbon Bug on 
old OS
     if (w->non_modal() && !w->modal()) {
       // Major kludge: this is to have the regular look, but stay above the 
document windows
@@ -2224,12 +2234,10 @@
  */
 void Fl_Window::label(const char *name,const char */*iname*/) {
   Fl_Widget::label(name);
-  Str255 pTitle;
 
-  if (name) { pTitle[0] = strlen(name); memcpy(pTitle+1, name, pTitle[0]); }
-  else pTitle[0] = 0;
-
-  if (shown() || i) SetWTitle(fl_xid(this), pTitle);
+  if (shown() || i) {
+    q_set_window_title(fl_xid(this), name);
+  }
 }
 
 

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to