Hi all!

I haven't been able to work w/ FLTK for a while, but recently my company decided to use FLTK for our new product.

So, I ported FLTK1 to windows CE. Porting was pretty easy, only one day work, I 
expected more :)
It works quite well already, even though there's still some things missing. For example some drawing code like Arc, Pie & friends doesn't work yet.

I saw some time ago lot's of interest for windows CE port, maybe some one find 
this useful.
I attached patch that contains code for port.

This patch allows also compile FLTK for UNICODE enabled visual studio, then it makes use of MS WCHAR enabled functions only. This makes it very easy to port UTF-8 later, atleast on windows port point of view ;)

If there's interest we could merge this to the FLTK1? 1.1.9? 1.2.0?
IMO, we could merge it straight after 1.1.8 to somewhere, I just don't know which version is going to be developed after that :)

BR,
Mikko Lähteenmäki
Index: FL/win32.H
===================================================================
--- FL/win32.H  (revision 5870)
+++ FL/win32.H  (working copy)
@@ -34,15 +34,36 @@
 #endif // !Fl_X_H
 
 #include <windows.h>
+#include <tchar.h>
+
 // In some of the distributions, the gcc header files are missing some stuff:
 #ifndef LPMINMAXINFO
-#define LPMINMAXINFO MINMAXINFO*
+#  ifdef _WIN32_WCE
+#    define LPMINMAXINFO void *
+#  else
+#    define LPMINMAXINFO MINMAXINFO*
+#  endif
 #endif
 #ifndef VK_LWIN
-#define VK_LWIN 0x5B
-#define VK_RWIN 0x5C
-#define VK_APPS 0x5D
+#  define VK_LWIN 0x5B
+#  define VK_RWIN 0x5C
+#  define VK_APPS 0x5D
 #endif
+#ifndef IDI_APPLICATION
+#  define IDI_APPLICATION MAKEINTRESOURCE(32512)
+#endif
+#ifndef WS_EX_LEFT
+#  define WS_EX_LEFT 0
+#endif
+#ifndef WS_EX_CONTROLPARENT
+#  define WS_EX_CONTROLPARENT 0
+#endif
+#ifndef SW_SHOWMINNOACTIVE
+#  define SW_SHOWMINNOACTIVE SW_HIDE
+#endif
+#ifndef WS_EX_NOACTIVATE
+#  define WS_EX_NOACTIVATE 0
+#endif
 
 // some random X equivalents
 typedef HWND Window;
@@ -147,6 +168,31 @@
 
 extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& 
b);
 
+// Convert char <--> WCHAR
+#ifdef _UNICODE
+// Unicode enabled, see conversion functions in Fl_win32.cxx
+extern "C" const TCHAR *c2tc(const char *str);
+extern "C" const char *tc2c(const TCHAR *str);
+#else
+// Ok. No unicode enabled, just dummy functions
+inline const TCHAR *c2tc(const char *str) { return str; }
+inline const char *tc2c(const TCHAR *str) { return str; }
+#endif
+
+// Windows CE emulation layer.. sigh..
+#ifdef _WIN32_WCE
+extern "C" int errno;
+extern "C" char *getenv(const char *name);
+extern "C" int _putenv(char *string);
+extern "C" int _mkdir(const char *path);
+extern "C" int _access(const char *path, int mode);
+extern "C" char *strerror(int errnum);
+extern "C" void rewind(FILE *stream);
+extern "C" char *_getcwd(char *buf, size_t size);
+extern "C" int chdir(const char *path);
+extern "C" void *bsearch(const void *key, const void *base, size_t num, size_t 
width, int (*compare)(const void *, const void *));
+#endif
+
 //
 // End of "$Id$".
 //
Index: src/filename_absolute.cxx
===================================================================
--- src/filename_absolute.cxx   (revision 5870)
+++ src/filename_absolute.cxx   (working copy)
@@ -36,7 +36,11 @@
 #include "flstring.h"
 #include <ctype.h>
 #if defined(WIN32) && !defined(__CYGWIN__)
-# include <direct.h>
+#ifndef _WIN32_WCE
+#  include <direct.h>
+#else
+#  include <FL/x.h>
+#endif
 // Visual C++ 2005 incorrectly displays a warning about the use of POSIX APIs
 // on Windows, which is supposed to be POSIX compliant...
 #  define getcwd _getcwd
Index: src/filename_expand.cxx
===================================================================
--- src/filename_expand.cxx     (revision 5870)
+++ src/filename_expand.cxx     (working copy)
@@ -39,6 +39,10 @@
 # include <pwd.h>
 #endif
 
+#ifdef _WIN32_WCE
+#  include <FL/x.H>
+#endif
+
 #if defined(WIN32) || defined(__EMX__) && !defined(__CYGWIN__)
 static inline int isdirsep(char c) {return c=='/' || c=='\\';}
 #else
Index: src/filename_isdir.cxx
===================================================================
--- src/filename_isdir.cxx      (revision 5870)
+++ src/filename_isdir.cxx      (working copy)
@@ -28,8 +28,12 @@
 // Used by fl_file_chooser
 
 #include "flstring.h"
-#include <sys/types.h>
-#include <sys/stat.h>
+#ifndef _WIN32_WCE
+#  include <sys/types.h>
+#  include <sys/stat.h>
+#else
+#  include <FL/x.h>
+#endif
 #include <ctype.h>
 #include <FL/filename.H>
 
@@ -47,6 +51,9 @@
 }
 
 int fl_filename_isdir(const char* n) {
+#ifdef _WIN32_WCE
+  return (GetFileAttributes(c2tc(n)) & FILE_ATTRIBUTE_DIRECTORY) != 0;
+#else
   struct stat  s;
   char         fn[1024];
   int          length;
@@ -84,6 +91,7 @@
 #endif
 
   return !stat(n, &s) && (s.st_mode&0170000)==0040000;
+#endif
 }
 
 //
Index: src/Fl.cxx
===================================================================
--- src/Fl.cxx  (revision 5870)
+++ src/Fl.cxx  (working copy)
@@ -388,7 +388,9 @@
   ~Fl_Win32_At_Exit() {
     fl_free_fonts();        // do some WIN32 cleanup
     fl_cleanup_pens();
+#ifndef _WIN32_WCE
     OleUninitialize();
+#endif
     fl_brush_action(1);
     fl_cleanup_dc_list();
   }
@@ -481,7 +483,9 @@
   }
 
 #ifdef WIN32
+#  ifndef _WIN32_WCE
   GdiFlush();
+#  endif
 #elif defined(__APPLE_QD__)
   GrafPtr port;
   GetPort( &port );
Index: src/Fl_abort.cxx
===================================================================
--- src/Fl_abort.cxx    (revision 5870)
+++ src/Fl_abort.cxx    (working copy)
@@ -37,7 +37,12 @@
 
 #ifdef WIN32
 #  include <windows.h>
+#  include <FL/x.h>
 
+#ifndef MB_SYSTEMMODAL
+#  define MB_SYSTEMMODAL 0
+#endif
+
 static void warning(const char *, ...) {
   // Show nothing for warnings under WIN32...
 }
@@ -48,7 +53,7 @@
   va_start(args, format);
   vsnprintf(buf, 1024, format, args);
   va_end(args);
-  MessageBox(0,buf,"Error",MB_ICONEXCLAMATION|MB_SYSTEMMODAL);
+  MessageBox(0,c2tc(buf),_T("Error"),MB_ICONEXCLAMATION|MB_SYSTEMMODAL);
 }
 
 static void fatal(const char *format, ...) {
@@ -57,7 +62,7 @@
   va_start(args, format);
   vsnprintf(buf, 1024, format, args);
   va_end(args);
-  MessageBox(0,buf,"Error",MB_ICONSTOP|MB_SYSTEMMODAL);
+  MessageBox(0,c2tc(buf),_T("Error"),MB_ICONSTOP|MB_SYSTEMMODAL);
   ::exit(1);
 }
 
Index: src/fl_arci.cxx
===================================================================
--- src/fl_arci.cxx     (revision 5870)
+++ src/fl_arci.cxx     (working copy)
@@ -47,6 +47,10 @@
 void fl_arc(int x,int y,int w,int h,double a1,double a2) {
   if (w <= 0 || h <= 0) return;
 #ifdef WIN32
+#  ifdef _WIN32_WCE
+  // ML: FIX ME!!!
+  Ellipse(fl_gc, x, y, x+w, y+h);
+#  else
   int xa = x+w/2+int(w*cos(a1/180.0*M_PI));
   int ya = y+h/2-int(h*sin(a1/180.0*M_PI));
   int xb = x+w/2+int(w*cos(a2/180.0*M_PI));
@@ -55,6 +59,7 @@
     if (xa == xb && ya == yb) SetPixel(fl_gc, xa, ya, fl_RGB());
     else Arc(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb);
   } else Arc(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb);
+#  endif
 #elif defined(__APPLE_QD__)
   Rect r; r.left=x; r.right=x+w; r.top=y; r.bottom=y+h;
   a1 = a2-a1; a2 = 450-a2;
@@ -87,6 +92,10 @@
   int xb = x+w/2+int(w*cos(a2/180.0*M_PI));
   int yb = y+h/2-int(h*sin(a2/180.0*M_PI));
   SelectObject(fl_gc, fl_brush());
+#  ifdef _WIN32_WCE
+  // ML: FIX ME!!!
+  Ellipse(fl_gc, x, y, x+w, y+h);
+#  else
   if (fabs(a1 - a2) < 90) {
     if (xa == xb && ya == yb) {
       MoveToEx(fl_gc, x+w/2, y+h/2, 0L); 
@@ -94,6 +103,7 @@
       SetPixel(fl_gc, xa, ya, fl_RGB());
     } else Pie(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb);
   } else Pie(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb); 
+#endif
 #elif defined(__APPLE_QD__)
   Rect r; r.left=x; r.right=x+w; r.top=y; r.bottom=y+h;
   a1 = a2-a1; a2 = 450-a2;
Index: src/fl_call_main.c
===================================================================
--- src/fl_call_main.c  (revision 5870)
+++ src/fl_call_main.c  (working copy)
@@ -63,11 +63,20 @@
 #    define __argv _argv
 #  endif /* BORLAND5 */
 
-int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
-                             LPSTR lpCmdLine, int nCmdShow) {
+#ifdef _WIN32_WCE
+// Exported from Fl_win32.cxx
+const char *tc2c(const TCHAR *str);
+#endif
+
+#ifndef _WIN32_WCE
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR 
lpCmdLine, int nCmdShow)
+#else
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR 
lpCmdLine, int nCmdShow)
+#endif
+{
   int rc;
 
-#  ifdef _DEBUG
+#  if defined(_DEBUG) && !defined(_WIN32_WCE)
  /*
   * If we are using compiling in debug mode, open a console window so
   * we can see any printf's, etc...
@@ -85,9 +94,22 @@
 #  endif /* _DEBUG */
 
   /* Run the standard main entry point function... */
+#ifdef _WIN32_WCE
+  {
+    // No cmd line parameters in WCE...
+    TCHAR fname[256];
+    char appname[256];
+    char *argv[2] = { appname, NULL };
+    DWORD len = GetModuleFileName(NULL, fname, 255);
+    strncpy(appname, tc2c(fname), len);
+    appname[len] = '\0';
+    rc = main(1, argv);
+  }
+#else
   rc = main(__argc, __argv);
+#endif
 
-#  ifdef _DEBUG
+#  if defined(_DEBUG) && !defined(_WIN32_WCE)
   fclose(stdin);
   fclose(stdout);
   fclose(stderr);
Index: src/fl_cursor.cxx
===================================================================
--- src/fl_cursor.cxx   (revision 5870)
+++ src/fl_cursor.cxx   (working copy)
@@ -74,7 +74,7 @@
   } else if (c == FL_CURSOR_DEFAULT) {
     i->cursor = fl_default_cursor;
   } else {
-    LPSTR n;
+    LPCTSTR n;
     switch (c) {
     case FL_CURSOR_ARROW:      n = IDC_ARROW; break;
     case FL_CURSOR_CROSS:      n = IDC_CROSS; break;
Index: src/fl_dnd_win32.cxx
===================================================================
--- src/fl_dnd_win32.cxx        (revision 5870)
+++ src/fl_dnd_win32.cxx        (working copy)
@@ -32,7 +32,9 @@
 #include "flstring.h"
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/types.h>
+#ifndef _WIN32_WCE
+#  include <sys/types.h>
+#endif
 #include <time.h>
 #if defined(__CYGWIN__)
 #include <sys/time.h>
@@ -49,7 +51,8 @@
 Fl_Window *fl_dnd_target_window = 0;
 
 // All of the following code requires GCC 3.x or a non-GNU compiler...
-#if !defined(__GNUC__) || __GNUC__ >= 3
+// Drop target code is disabled for Windows CE, There's no DragQueryFile() and 
friends..
+#if (!defined(__GNUC__) || __GNUC__ >= 3) && !defined(_WIN32_WCE)
 
 #include <ole2.h>
 #include <shellapi.h>
@@ -234,6 +237,19 @@
       int i, n, nn = 0, nf = DragQueryFile( hdrop, (UINT)-1, 0, 0 );
       for ( i=0; i<nf; i++ ) nn += DragQueryFile( hdrop, i, 0, 0 );
       nn += nf;
+#ifdef _UNICODE   
+      TCHAR *buffer = (TCHAR*)malloc((nn+1) * sizeof(TCHAR));
+      TCHAR *dst = buffer;
+      for ( i=0; i<nf; i++ ) {
+       n = DragQueryFile( hdrop, i, dst, nn );
+       dst += n;
+       if ( i<nf-1 ) *dst++ = '\n';
+      }
+      *dst = 0;
+      Fl::e_text = strdup(tc2c(buffer));
+      Fl::e_length = strlen(Fl::e_text);
+      free(buffer);
+#else
       Fl::e_length = nn-1;
       char *dst = Fl::e_text = (char*)malloc(nn+1);
       for ( i=0; i<nf; i++ ) {
@@ -242,6 +258,7 @@
        if ( i<nf-1 ) *dst++ = '\n';
       }
       *dst = 0;
+#endif
       ReleaseStgMedium( &medium );
       currDragResult = 1;
       return currDragResult;
Index: src/Fl_Double_Window.cxx
===================================================================
--- src/Fl_Double_Window.cxx    (revision 5870)
+++ src/Fl_Double_Window.cxx    (working copy)
@@ -66,6 +66,8 @@
 
 #ifdef WIN32
 
+#include <FL/x.H>
+
 // Code used to switch output to an off-screen window.  See macros in
 // win32.H which save the old state in local variables.
 
@@ -87,11 +89,15 @@
   if (been_here) return can_do;
   been_here = 1;
   // load the library that implements alpha blending
-  HMODULE hMod = LoadLibrary("MSIMG32.DLL");
+  HMODULE hMod = LoadLibrary(_T("MSIMG32.DLL"));
   // give up if that doesn't exist (Win95?)
   if (!hMod) return 0;
   // now find the blending function inside that dll
+#ifdef _WIN32_WCE
+  fl_alpha_blend = (fl_alpha_blend_func)GetProcAddress(hMod, _T("AlphaBlend"));
+#else
   fl_alpha_blend = (fl_alpha_blend_func)GetProcAddress(hMod, "AlphaBlend");
+#endif
   // give up if we can't find it (Win95)
   if (!fl_alpha_blend) return 0;
   // we have the  call, but does our display support alpha blending?
Index: src/fl_draw_image_win32.cxx
===================================================================
--- src/fl_draw_image_win32.cxx (revision 5870)
+++ src/fl_draw_image_win32.cxx (working copy)
@@ -117,6 +117,8 @@
 {
 #if USE_COLORMAP
   char indexed = (fl_palette != 0);
+#else
+  char indexed = 0;
 #endif
 
   if (depth==0) depth = 3;
Index: src/Fl_File_Browser.cxx
===================================================================
--- src/Fl_File_Browser.cxx     (revision 5870)
+++ src/Fl_File_Browser.cxx     (working copy)
@@ -50,7 +50,9 @@
 #  include <mntent.h>
 #elif defined(WIN32)
 #  include <windows.h>
+#ifndef _WIN32_WCE
 #  include <direct.h>
+#endif
 // Apparently Borland C++ defines DIRECTORY in <direct.h>, which
 // interfers with the Fl_File_Icon enumeration of the same name.
 #  ifdef DIRECTORY
@@ -459,6 +461,7 @@
 
     endmntent(m);
 #  else
+#  ifndef _WIN32_WCE
     //
     // Normal WIN32 code uses drive bits...
     //
@@ -477,6 +480,9 @@
 
        num_files ++;
       }
+#  else
+    add("/", icon);
+#  endif // _WIN32_WCE
 #  endif // __CYGWIN__
 #elif defined(__EMX__)
     //
Index: src/Fl_File_Chooser2.cxx
===================================================================
--- src/Fl_File_Chooser2.cxx    (revision 5870)
+++ src/Fl_File_Chooser2.cxx    (working copy)
@@ -56,12 +56,15 @@
 #include <stdlib.h>
 #include "flstring.h"
 #include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
+#ifndef _WIN32_WCE
+#  include <sys/stat.h>
+#  include <sys/types.h>
+#endif
 #if defined(WIN32) && ! defined (__CYGWIN__)
-#  include <direct.h>
-#  include <io.h>
+#  ifndef _WIN32_WCE
+#    include <direct.h>
+#    include <io.h>
+#  endif
 // Visual C++ 2005 incorrectly displays a warning about the use of POSIX APIs
 // on Windows, which is supposed to be POSIX compliant...
 #  define access _access
Index: src/Fl_File_Icon.cxx
===================================================================
--- src/Fl_File_Icon.cxx        (revision 5870)
+++ src/Fl_File_Icon.cxx        (working copy)
@@ -45,10 +45,14 @@
 #include <stdlib.h>
 #include "flstring.h"
 #include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+#ifndef _WIN32_WCE
+#  include <sys/stat.h>
+#  include <sys/types.h>
+#endif
 #if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
-#  include <io.h>
+#  ifndef _WIN32_WCE
+#    include <io.h>
+#  endif
 #  define F_OK 0
 #else
 #  include <unistd.h>
Index: src/fl_font_win32.cxx
===================================================================
--- src/fl_font_win32.cxx       (revision 5870)
+++ src/fl_font_win32.cxx       (working copy)
@@ -25,6 +25,8 @@
 //     http://www.fltk.org/str.php
 //
 
+#include <FL/x.H>
+
 Fl_FontSize::Fl_FontSize(const char* name, int size) {
   int weight = FW_NORMAL;
   int italic = 0;
@@ -35,28 +37,37 @@
   case ' ': break;
   default: name--;
   }
-  fid = CreateFont(
-    -size, // negative makes it use "char size"
-    0,             // logical average character width 
-    0,             // angle of escapement 
-    0,             // base-line orientation angle 
-    weight,
-    italic,
-    FALSE,             // underline attribute flag 
-    FALSE,             // strikeout attribute flag 
-    DEFAULT_CHARSET,    // character set identifier 
-    OUT_DEFAULT_PRECIS,        // output precision 
-    CLIP_DEFAULT_PRECIS,// clipping precision 
-    DEFAULT_QUALITY,   // output quality 
-    DEFAULT_PITCH,     // pitch and family 
-    name               // pointer to typeface name string 
-    );
+
+  LOGFONT lf;
+  memset(&lf, 0, sizeof(lf));
+  lf.lfHeight         = -size; // negative makes it use "char size"
+  lf.lfWidth          = 0L;
+  lf.lfEscapement     = 0L;
+  lf.lfOrientation    = 0L;
+  lf.lfWeight         = weight;
+  lf.lfItalic         = italic;
+  lf.lfUnderline      = FALSE;
+  lf.lfStrikeOut      = FALSE;
+  lf.lfCharSet        = DEFAULT_CHARSET;
+  lf.lfClipPrecision  = CLIP_DEFAULT_PRECIS;
+  lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
+  lf.lfOutPrecision   = OUT_DEFAULT_PRECIS;
+  lf.lfQuality        = DEFAULT_QUALITY;
+  _tcsncpy(lf.lfFaceName, c2tc(name), LF_FACESIZE-1);
+
+  fid = CreateFontIndirect(&lf);
+
   if (!fl_gc) fl_GetDC(0);
   SelectObject(fl_gc, fid);
   GetTextMetrics(fl_gc, &metr);
 //  BOOL ret = GetCharWidthFloat(fl_gc, metr.tmFirstChar, metr.tmLastChar, 
font->width+metr.tmFirstChar);
 // ...would be the right call, but is not implemented into Window95! (WinNT?)
+#ifdef _UNICODE
+  GetCharWidth32(fl_gc, 0, 255, width);
+#else
   GetCharWidth(fl_gc, 0, 255, width);
+#endif  
+
 #if HAVE_GL
   listbase = 0;
 #endif
@@ -148,19 +159,27 @@
 double fl_width(const char* c, int n) {
   if (!fl_fontsize) return -1.0;
   double w = 0.0;
-  while (n--) w += fl_fontsize->width[uchar(*c++)];
+  while (n--) {
+    w += fl_fontsize->width[uchar(*c++)];
+  }
   return w;
 }
 
 double fl_width(uchar c) {
-  if (fl_fontsize) return fl_fontsize->width[c];
+  if (fl_fontsize) {
+    return fl_fontsize->width[c];
+  }
   else return -1.0;
 }
 
 void fl_draw(const char* str, int n, int x, int y) {
   COLORREF oldColor = SetTextColor(fl_gc, fl_RGB());
   if (fl_fontsize) SelectObject(fl_gc, fl_fontsize->fid);
+#if defined(_UNICODE)
+  ExtTextOut(fl_gc, x, y, 0, NULL, c2tc(str), n, NULL);
+#else
   TextOut(fl_gc, x, y, str, n);
+#endif
   SetTextColor(fl_gc, oldColor);
 }
 
Index: src/Fl_get_key_win32.cxx
===================================================================
--- src/Fl_get_key_win32.cxx    (revision 5870)
+++ src/Fl_get_key_win32.cxx    (working copy)
@@ -128,9 +128,10 @@
 }
 
 int Fl::get_key(int k) {
-  uchar foo[256];
+  return (GetAsyncKeyState(fltk2ms(k))&~1) != 0;
+  /*uchar foo[256];
   GetKeyboardState(foo);
-  return foo[fltk2ms(k)]&~1;
+  return foo[fltk2ms(k)]&~1;*/
 }
 
 //
Index: src/Fl_Help_View.cxx
===================================================================
--- src/Fl_Help_View.cxx        (revision 5870)
+++ src/Fl_Help_View.cxx        (working copy)
@@ -66,8 +66,12 @@
 #include <math.h>
 
 #if defined(WIN32) && ! defined(__CYGWIN__)
-#  include <io.h>
-#  include <direct.h>
+#  ifndef _WIN32_WCE
+#    include <io.h>
+#    include <direct.h>
+#  else
+#    include <FL/x.H>
+#  endif
 // Visual C++ 2005 incorrectly displays a warning about the use of POSIX APIs
 // on Windows, which is supposed to be POSIX compliant...
 #  define getcwd _getcwd
Index: src/fl_line_style.cxx
===================================================================
--- src/fl_line_style.cxx       (revision 5870)
+++ src/fl_line_style.cxx       (working copy)
@@ -47,6 +47,9 @@
 
 void fl_line_style(int style, int width, char* dashes) {
 #ifdef WIN32
+#ifdef _WIN32_WCE
+  HPEN newpen = CreatePen((style & 0xff), width, fl_RGB());
+#else
   // According to Bill, the "default" cap and join should be the
   // "fastest" mode supported for the platform.  I don't know why
   // they should be different (same graphics cards, etc., right?) MRS
@@ -62,7 +65,8 @@
   }
   if ((style || n) && !width) width = 1; // fix cards that do nothing for 0?
   LOGBRUSH penbrush = {BS_SOLID,fl_RGB(),0}; // can this be fl_brush()?
-  HPEN newpen = ExtCreatePen(s1, width, &penbrush, n, n ? a : 0);
+  HPEN newpen = ExtCreatePen(s1, width, &penbrush, n, n ? a : 0);  
+#endif
   if (!newpen) {
     Fl::error("fl_line_style(): Could not create GDI pen object.");
     return;
Index: src/Fl_lock.cxx
===================================================================
--- src/Fl_lock.cxx     (revision 5870)
+++ src/Fl_lock.cxx     (working copy)
@@ -132,7 +132,9 @@
 // Windows threading...
 #ifdef WIN32
 #  include <windows.h>
-#  include <process.h>
+#  ifndef _WIN32_WCE
+#    include <process.h>
+#  endif
 #  include <FL/x.H>
 
 // These pointers are in Fl_win32.cxx:
Index: src/fl_open_uri.cxx
===================================================================
--- src/fl_open_uri.cxx (revision 5870)
+++ src/fl_open_uri.cxx (working copy)
@@ -30,11 +30,15 @@
 //
 
 #include <FL/filename.H>
+#include <FL/x.H>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
-#include <sys/types.h>
 #include "flstring.h"
+#ifndef _WIN32_WCE
+#  include <sys/types.h>
+#endif
 #ifdef WIN32
 #  include <windows.h>
 #  include <shellapi.h>
@@ -113,9 +117,14 @@
 
 #ifdef WIN32
   if (msg) snprintf(msg, msglen, "open %s", uri);
+  SHELLEXECUTEINFO execinfo;
+  memset(&execinfo, 0, sizeof(execinfo));
+  execinfo.cbSize = sizeof(execinfo);
+  execinfo.lpVerb = _T("open");
+  execinfo.lpFile = c2tc(uri);
+  execinfo.nShow = SW_SHOW;
+  return (int)ShellExecuteEx(&execinfo) != 0;
 
-  return (int)ShellExecute(HWND_DESKTOP, "open", uri, NULL, NULL, SW_SHOW) > 
32;
-
 #elif defined(__APPLE__)
   char *argv[3];                       // Command-line arguments
 
Index: src/Fl_Preferences.cxx
===================================================================
--- src/Fl_Preferences.cxx      (revision 5870)
+++ src/Fl_Preferences.cxx      (working copy)
@@ -29,16 +29,22 @@
 #include <FL/Fl.H>
 #include <FL/Fl_Preferences.H>
 #include <FL/filename.H>
+#include <FL/x.H>
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
 #include "flstring.h"
-#include <sys/stat.h>
 
+#ifndef _WIN32_WCE
+#  include <sys/stat.h>
+#endif
+
 #if defined(WIN32) && !defined(__CYGWIN__)
+#ifndef _WIN32_WCE
 #  include <direct.h>
 #  include <io.h>
+#endif
 // Visual C++ 2005 incorrectly displays a warning about the use of POSIX APIs
 // on Windows, which is supposed to be POSIX compliant...
 #  define access _access
@@ -636,23 +642,23 @@
 
   switch (root) {
     case SYSTEM:
-      err = RegOpenKey( HKEY_LOCAL_MACHINE, FLPREFS_RESOURCE, &key );
+      err = RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T(FLPREFS_RESOURCE), 0, 
KEY_READ, &key );
       if (err == ERROR_SUCCESS) {
        nn = FL_PATH_MAX - appDataLen;
-       err = RegQueryValueEx( key, "Common AppData", 0L, &type, 
(BYTE*)filename, &nn );
+       err = RegQueryValueEx( key, _T("Common AppData"), 0L, &type, 
(BYTE*)filename, &nn );
        if ( ( err != ERROR_SUCCESS ) && ( type == REG_SZ ) )
          filename[0] = 0;
         RegCloseKey(key);
       }
       break;
     case USER:
-      err = RegOpenKey( HKEY_CURRENT_USER, FLPREFS_RESOURCE, &key );
+      err = RegOpenKeyEx( HKEY_CURRENT_USER, _T(FLPREFS_RESOURCE), 0, 
KEY_READ, &key );
       if (err == ERROR_SUCCESS) {
        nn = FL_PATH_MAX - appDataLen;
-       err = RegQueryValueEx( key, "AppData", 0L, &type, (BYTE*)filename, &nn 
);
+       err = RegQueryValueEx( key, _T("AppData"), 0L, &type, (BYTE*)filename, 
&nn );
        if ( ( err != ERROR_SUCCESS ) && ( type == REG_SZ ) )
        {
-         err = RegQueryValueEx( key, "Personal", 0L, &type, (BYTE*)filename, 
&nn );
+         err = RegQueryValueEx( key, _T("Personal"), 0L, &type, 
(BYTE*)filename, &nn );
          if ( ( err != ERROR_SUCCESS ) && ( type == REG_SZ ) )
            filename[0] = 0;
        }
Index: src/fl_scroll_area.cxx
===================================================================
--- src/fl_scroll_area.cxx      (revision 5870)
+++ src/fl_scroll_area.cxx      (working copy)
@@ -72,7 +72,9 @@
     clip_y = Y+src_h;
     clip_h = H-src_h;
   }
-#ifdef WIN32
+#ifdef WIN32 
+
+#  ifndef _WIN32_WCE
   typedef int (WINAPI* fl_GetRandomRgn_func)(HDC, HRGN, INT);
   static fl_GetRandomRgn_func fl_GetRandomRgn = 0L;
   static char first_time = 1;
@@ -80,7 +82,7 @@
   // We will have to do some Region magic now, so let's see if the 
   // required function is available (and it should be staring w/Win95)
   if (first_time) {
-    HMODULE hMod = GetModuleHandle("GDI32.DLL");
+    HMODULE hMod = GetModuleHandle(_T("GDI32.DLL"));
     if (hMod) {
       fl_GetRandomRgn = (fl_GetRandomRgn_func)GetProcAddress(hMod, 
"GetRandomRgn");
     }
@@ -122,6 +124,7 @@
       return;
     }
   }
+#  endif // _WIN32_WCE
 
   // Great, we can do an accelerated scroll insteasd of re-rendering
   BitBlt(fl_gc, dest_x, dest_y, src_w, src_h, fl_gc, src_x, src_y,SRCCOPY);
Index: src/fl_set_fonts_win32.cxx
===================================================================
--- src/fl_set_fonts_win32.cxx  (revision 5870)
+++ src/fl_set_fonts_win32.cxx  (working copy)
@@ -66,7 +66,7 @@
        DWORD            /*FontType*/,
        LPARAM           p) {
   if (!p && lpelf->lfCharSet != ANSI_CHARSET) return 1;
-  const char *n = lpelf->lfFaceName;
+  const char *n = tc2c(lpelf->lfFaceName);
   for (int i=0; i<FL_FREE_FONT; i++) // skip if one of our built-in fonts
     if (!strcmp(Fl::get_font_name((Fl_Font)i),n)) return 1;
   char buffer[LF_FACESIZE + 1];
@@ -137,7 +137,7 @@
   if (!fl_gc) fl_GetDC(0);
   cyPerInch = GetDeviceCaps(fl_gc, LOGPIXELSY);
   if (cyPerInch < 1) cyPerInch = 1;
-  EnumFontFamilies(fl_gc, s->name+1, (FONTENUMPROC)EnumSizeCb, 0);
+  EnumFontFamilies(fl_gc, c2tc(s->name+1), (FONTENUMPROC)EnumSizeCb, 0);
 
   sizep = sizes;
   return nbSize;
Index: src/Fl_Shared_Image.cxx
===================================================================
--- src/Fl_Shared_Image.cxx     (revision 5870)
+++ src/Fl_Shared_Image.cxx     (working copy)
@@ -33,6 +33,7 @@
 #include <FL/Fl_Shared_Image.H>
 #include <FL/Fl_XBM_Image.H>
 #include <FL/Fl_XPM_Image.H>
+#include <FL/x.H>
 
 
 //
Index: src/fl_vertex.cxx
===================================================================
--- src/fl_vertex.cxx   (revision 5870)
+++ src/fl_vertex.cxx   (working copy)
@@ -266,7 +266,15 @@
 #ifdef WIN32
   if (n>2) {
     SelectObject(fl_gc, fl_brush());
+#ifdef _WIN32_WCE
+    int idx = 0;
+    for (int i=0; i<numcount; i++) {
+      Polygon(fl_gc, &p[idx], counts[i]);
+      idx += counts[i];
+    }
+#else
     PolyPolygon(fl_gc, p, counts, numcount);
+#endif
   }
 #elif defined(__APPLE_QD__)
   if (n<=1) return;
@@ -304,9 +312,19 @@
 #ifdef WIN32
   if (what==POLYGON) {
     SelectObject(fl_gc, fl_brush());
+#  ifdef _WIN32_WCE
+    // ML: FIX ME!!!
+    Ellipse(fl_gc, llx, lly, llx+w, lly+h);
+#  else
     Pie(fl_gc, llx, lly, llx+w, lly+h, 0,0, 0,0); 
+#  endif
   } else
+#  ifdef _WIN32_WCE
+    // ML: FIX ME!!!
+    Ellipse(fl_gc, llx, lly, llx+w, lly+h);
+#  else
     Arc(fl_gc, llx, lly, llx+w, lly+h, 0,0, 0,0); 
+#  endif
 #elif defined(__APPLE_QD__)
   Rect rt; rt.left=llx; rt.right=llx+w; rt.top=lly; rt.bottom=lly+h;
   (what == POLYGON ? PaintOval : FrameOval)(&rt);
Index: src/Fl_wce.cxx
===================================================================
--- src/Fl_wce.cxx      (revision 0)
+++ src/Fl_wce.cxx      (revision 0)
@@ -0,0 +1,137 @@
+//
+// "$Id:$"
+//
+// WIN CE-specific code for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 1998-2007 by Bill Spitzak and others.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library 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
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library 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.
+//
+// Please report all bugs and problems on the following page:
+//
+//     http://www.fltk.org/str.php
+//
+
+//
+// This file contains POSIX emulation layer for windows ce
+//
+
+// Damn winsock defines these also.. 
+#undef ENAMETOOLONG
+#undef ENOTEMPTY
+
+#include <errno.h>
+
+extern "C" int errno = 0;
+
+extern "C" int _access(const char *path, int mode)
+{
+  if (GetFileAttributes(c2tc(path)) == 0xFFFFFFFF) {
+    errno = EACCES;
+    return -1;
+  }
+  errno = 0;
+  return 0;
+}
+
+extern "C" int _mkdir(const char *path)
+{
+  if (CreateDirectory(c2tc(path), NULL) == 0) {
+    if (GetLastError() == ERROR_FILE_EXISTS) {
+      errno = EEXIST;
+    }
+    return -1;
+  }
+  errno = 0;
+  return 0;
+}
+
+extern "C" char *getenv(const char *name)
+{
+  // No env variables in CE
+  return NULL;   
+}
+
+extern "C" int _putenv(char *string)
+{
+  // No env variables in CE
+  return -1;
+}
+
+// Current directory emulation.. Win ce has no consept of current directory.
+static char fl_current_dir[MAX_PATH] = "/";
+
+extern "C" char *_getcwd(char *buf, size_t size)
+{
+  strncpy(buf, fl_current_dir, size);
+  return buf;
+}
+
+extern "C" int chdir(const char *path)
+{
+  if (_access(path, 0) == 0) {
+    strncpy(fl_current_dir, path, MAX_PATH-1);
+    return 0;
+  }
+  return -1;
+}
+
+extern "C" void rewind(FILE *stream)
+{
+  fseek(stream, 0, SEEK_SET);
+}
+
+extern "C" char *strerror(int errnum)
+{
+  static char buf[32];
+  sprintf(buf, "Error %d", errnum);
+  return buf;
+}
+
+extern "C" void *bsearch(const void *key, const void *base, size_t num, size_t 
width, int (*compare)(const void *, const void *))
+{
+  char *lo = (char *) base;
+  char *hi = (char *) base + (num - 1) * width;
+  char *mid;
+  unsigned int half;
+  int result;
+
+  while (lo <= hi)
+  {
+    if (half = num / 2)
+    {
+      mid = lo + (num & 1 ? half : (half - 1)) * width;
+      if (!(result = (*compare)(key,mid)))
+        return mid;
+      else if (result < 0)
+      {
+        hi = mid - width;
+        num = num & 1 ? half : half-1;
+      }
+      else    
+      {
+        lo = mid + width;
+        num = half;
+      }
+    }
+    else if (num)
+      return ((*compare)(key,lo) ? NULL : lo);
+    else
+      break;
+  }
+
+  return NULL;
+}
\ No newline at end of file
Index: src/Fl_Widget.cxx
===================================================================
--- src/Fl_Widget.cxx   (revision 5870)
+++ src/Fl_Widget.cxx   (working copy)
@@ -76,7 +76,12 @@
   return 0;
 }
 
+#ifdef _WIN32_WCE
+// Let's put little bit smaller font for windows ce devices by default.. They 
usually has small displays
+int FL_NORMAL_SIZE = 12;
+#else
 int FL_NORMAL_SIZE = 14;
+#endif
 
 Fl_Widget::Fl_Widget(int X, int Y, int W, int H, const char* L) {
 
Index: src/Fl_win32.cxx
===================================================================
--- src/Fl_win32.cxx    (revision 5870)
+++ src/Fl_win32.cxx    (working copy)
@@ -38,7 +38,9 @@
 #include "Fl_Font.H"
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/types.h>
+#ifndef _WIN32_WCE
+#  include <sys/types.h>
+#endif
 #include <time.h>
 #ifdef __CYGWIN__
 #  include <sys/time.h>
@@ -55,6 +57,9 @@
 #  include <shellapi.h>
 #endif // !__GNUC__ || __GNUC__ >= 3
 
+#ifdef _WIN32_WCE
+#  include "Fl_wce.cxx"
+#endif
 
 //
 // USE_ASYNC_SELECT - define it if you have WSAAsyncSelect()...
@@ -76,7 +81,7 @@
 
 //#define USE_TRACK_MOUSE
 
-#if !defined(__GNUC__)
+#if !defined(__GNUC__) && !defined(_WIN32_WCE)
 #  define USE_TRACK_MOUSE
 #endif // !__GNUC__
 
@@ -130,7 +135,7 @@
 #define POLLOUT 4
 #define POLLERR 8
 
-#if !defined(__GNUC__) || __GNUC__ >= 3
+#if (!defined(__GNUC__) || __GNUC__ >= 3) && !defined(_WIN32_WCE)
 extern IDropTarget *flIDropTarget;
 #endif // !__GNUC__ || __GNUC__ >= 3
 
@@ -695,8 +700,10 @@
     PostQuitMessage(0);
     return 0;
 
+#ifndef _WIN32_WCE
+  case WM_NCPAINT :
+#endif
   case WM_SYNCPAINT :
-  case WM_NCPAINT :
   case WM_ERASEBKGND :
     // Andreas Weitl - WM_SYNCPAINT needs to be passed to DefWindowProc
     // so that Windows can generate the proper paint messages...
@@ -786,6 +793,7 @@
     }
     break;
 
+#ifndef _WIN32_WCE
   case WM_ACTIVATEAPP:
     // From [EMAIL PROTECTED], we should process WM_ACTIVATEAPP
     // messages to restore the correct state of the shift/ctrl/alt/lock
@@ -806,6 +814,7 @@
       return 0;
     }
     break;
+#endif
 
   case WM_KEYDOWN:
   case WM_SYSKEYDOWN:
@@ -917,9 +926,11 @@
     return 0;
   }
 
+#ifndef _WIN32_WCE
   case WM_GETMINMAXINFO:
     Fl_X::i(window)->set_minmax((LPMINMAXINFO)lParam);
     break;
+#endif
 
   case WM_SIZE:
     if (!window->parent()) {
@@ -1058,11 +1069,14 @@
   // This is the original (pre 1.1.7) routine to calculate window border sizes.
   if (fallback) {
     if (w->border() && !w->parent()) {
+#ifndef _WIN32_WCE
       if (w->size_range_set && (w->maxw != w->minw || w->maxh != w->minh)) {
         ret = 2;
         bx = GetSystemMetrics(SM_CXSIZEFRAME);
         by = GetSystemMetrics(SM_CYSIZEFRAME);
-      } else {
+      } else 
+#endif
+      {
         ret = 1;
         bx = GetSystemMetrics(SM_CXFIXEDFRAME);
         by = GetSystemMetrics(SM_CYFIXEDFRAME);
@@ -1104,6 +1118,10 @@
 
 ////////////////////////////////////////////////////////////////
 
+#ifndef SWP_NOSENDCHANGING
+#  define SWP_NOSENDCHANGING 0
+#endif
+
 void Fl_Window::resize(int X,int Y,int W,int H) {
   UINT flags = SWP_NOSENDCHANGING | SWP_NOZORDER 
              | SWP_NOACTIVATE | SWP_NOOWNERZORDER;
@@ -1190,14 +1208,41 @@
 
   static NameList class_name_list;
   static const char *first_class_name = 0L;
+#ifdef _UNICODE
+  TCHAR tchar_class_name[256];
+#else
+  const char *tchar_class_name;
+#endif
   const char *class_name = w->xclass();
   if (!class_name) class_name = first_class_name; // reuse first class name 
used
   if (!class_name) class_name = "FLTK"; // default to create a "FLTK" WNDCLASS
   if (!first_class_name) {
     first_class_name = class_name;
   }
+#ifdef _UNICODE
+  const WCHAR *unicode_class_name = c2tc(class_name);
+  _tcsncpy(tchar_class_name, unicode_class_name, 255);
+#else
+  tchar_class_name = class_name;
+#endif
 
   if (!class_name_list.has_name(class_name)) {
+#ifdef _WIN32_WCE
+    WNDCLASS wc;
+    memset(&wc, 0, sizeof(wc));
+    //wc.style = CS_HREDRAW | CS_VREDRAW | CS_CLASSDC | CS_DBLCLKS;
+    wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
+    wc.lpfnWndProc = (WNDPROC)WndProc;
+    wc.hInstance = fl_display;
+    if (!w->icon())
+      w->icon((void *)LoadIcon(NULL, IDI_APPLICATION));
+    wc.hIcon = (HICON)w->icon();
+    wc.hCursor = fl_default_cursor = LoadCursor(NULL, IDC_ARROW);
+    //uchar r,g,b; Fl::get_color(FL_GRAY,r,g,b);
+    //wc.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(r,g,b));
+    wc.lpszClassName = tchar_class_name;
+    RegisterClass(&wc);
+#else
     WNDCLASSEX wc;
     memset(&wc, 0, sizeof(wc));
     wc.cbSize = sizeof(WNDCLASSEX);
@@ -1214,16 +1259,17 @@
     wc.hCursor = fl_default_cursor = LoadCursor(NULL, IDC_ARROW);
     //uchar r,g,b; Fl::get_color(FL_GRAY,r,g,b);
     //wc.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(r,g,b));
-    wc.lpszClassName = class_name;
+    wc.lpszClassName = tchar_class_name;
     RegisterClassEx(&wc);
+#endif
     class_name_list.add_name(class_name);
   }
 
-  const char* message_name = "FLTK::ThreadWakeup";
+  const TCHAR* message_name = _T("FLTK::ThreadWakeup");
   if (!fl_wake_msg) fl_wake_msg = RegisterWindowMessage(message_name);
 
   HWND parent;
-  DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
+  DWORD style = 0;//WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
   DWORD styleEx = WS_EX_LEFT;
 
   int xp = w->x();
@@ -1252,8 +1298,9 @@
     int xwm = xp , ywm = yp , bt, bx, by;
     switch (fake_X_wm(w, xwm, ywm, bt, bx, by)) {
       // No border (used for menus)
-      case 0: style |= WS_POPUP;
-              styleEx |= WS_EX_TOOLWINDOW;
+      case 0: style = WS_POPUP;
+              styleEx |= WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE;
+              styleEx &= ~WS_EX_WINDOWEDGE;
              break;
 
       // Thin border and title bar
@@ -1288,15 +1335,20 @@
     } else if (Fl::grab()) parent = fl_xid(Fl::grab());
   }
 
+  if (!w->parent() && parent) {
+    style |= WS_POPUP;
+  }
+
   Fl_X* x = new Fl_X;
   x->other_xid = 0;
   x->setwindow(w);
   x->region = 0;
   x->private_dc = 0;
   x->cursor = fl_default_cursor;
+  const TCHAR *tchar_label = c2tc(w->label());
   x->xid = CreateWindowEx(
     styleEx,
-    class_name, w->label(), style,
+    tchar_class_name, tchar_label, style,
     xp, yp, wp, hp,
     parent,
     NULL, // menu
@@ -1321,7 +1373,7 @@
             (Fl::grab() || (style & WS_POPUP)) ? SW_SHOWNOACTIVATE : 
SW_SHOWNORMAL);
 
   // Drag-n-drop requires GCC 3.x or a non-GNU compiler...
-#if !defined(__GNUC__) || __GNUC__ >= 3
+#if (!defined(__GNUC__) || __GNUC__ >= 3) && !defined(_WIN32_WCE)
   // Register all windows for potential drag'n'drop operations
   static char oleInitialized = 0;
   if (!oleInitialized) { OleInitialize(0L); oleInitialized=1; }
@@ -1334,8 +1386,6 @@
 }
 
 
-
-
 /////////////////////////////////////////////////////////////////////////////
 /// Win32 timers
 ///
@@ -1389,25 +1439,35 @@
     unsigned int elapsed = (unsigned int)(time * 1000);
 
     if ( !s_TimerWnd ) {
-        const char* timer_class = "FLTimer";
+        const TCHAR* timer_class = _T("FLTimer");
+#ifndef _WIN32_WCE
         WNDCLASSEX wc;
+#else
+        WNDCLASS wc;
+#endif
         memset(&wc, 0, sizeof(wc));
+#ifndef _WIN32_WCE
         wc.cbSize = sizeof (wc);
         wc.style = CS_CLASSDC;
+#endif
         wc.lpfnWndProc = (WNDPROC)s_TimerProc;
         wc.hInstance = fl_display;
         wc.lpszClassName = timer_class;
+#ifndef _WIN32_WCE
         /*ATOM atom =*/ RegisterClassEx(&wc);
+#else
+        RegisterClass(&wc);
+#endif
         // create a zero size window to handle timer events
         s_TimerWnd = CreateWindowEx(WS_EX_LEFT | WS_EX_TOOLWINDOW,
-                                    timer_class, "",
+                                    timer_class, _T(""),
                                     WS_POPUP,
                                     0, 0, 0, 0,
                                     NULL, NULL, fl_display, NULL);
         // just in case this OS won't let us create a 0x0 size window:
         if (!s_TimerWnd) 
           s_TimerWnd = CreateWindowEx(WS_EX_LEFT | WS_EX_TOOLWINDOW,
-                                    timer_class, "",
+                                    timer_class, _T(""),
                                     WS_POPUP,
                                     0, 0, 1, 1,
                                     NULL, NULL, fl_display, NULL);
@@ -1459,6 +1519,7 @@
 
 void Fl_X::set_minmax(LPMINMAXINFO minmax)
 {
+#ifndef _WIN32_WCE
   int td, wd, hd, dummy_x, dummy_y;
 
   fake_X_wm(w, dummy_x, dummy_y, td, wd, hd);
@@ -1476,6 +1537,7 @@
     minmax->ptMaxTrackSize.y = w->maxh + hd;
     minmax->ptMaxSize.y = w->maxh + hd;
   }
+#endif
 }
 
 ////////////////////////////////////////////////////////////////
@@ -1497,7 +1559,7 @@
   iconlabel_ = iname;
   if (shown() && !parent()) {
     if (!name) name = "";
-    SetWindowText(i->xid, name);
+    SetWindowText(i->xid, c2tc(name));
     // if (!iname) iname = fl_filename_name(name);
     // should do something with iname here...
   }
@@ -1531,7 +1593,9 @@
     Fl_X::make(this);
   } else {
     // Once again, we would lose the capture if we activated the window.
+#ifndef _WIN32_WCE
     if (IsIconic(i->xid)) OpenIcon(i->xid);
+#endif
     if (!fl_capture) BringWindowToTop(i->xid);
     //ShowWindow(i->xid,fl_capture?SW_SHOWNOACTIVATE:SW_RESTORE);
   }
@@ -1671,7 +1735,60 @@
   } while(t);
 }
 
+#ifdef _UNICODE
+// Convert char -> wchar (UTF-16)
+extern "C" const TCHAR *c2tc(const char *str)
+{
+  static TCHAR *buf = NULL;
+  static int buf_size = 0;
+  int len = 0;
+  
+  if (!str) return NULL;
 
+  // Get size of the MB string
+  len = strlen(str);
+
+  // Allocate buffer
+  if (buf_size < len+1) {
+    buf_size = len+1; // +1 for NULL
+    if (buf) free(buf);
+    buf = (TCHAR*)malloc(buf_size * sizeof(TCHAR));
+  }
+
+  // Convert to wide chars
+  len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, len, buf, buf_size);
+  buf[len] = '\0';
+  return buf;
+}
+
+// Convert wchar (UTF-16) -> char
+extern "C" const char *tc2c(const TCHAR *str)
+{
+  static char *buf = NULL;
+  static int buf_size = 0;
+  int len = 0;
+  const char *defchar = "?";
+  BOOL defused = FALSE;
+  
+  if (!str) return NULL;
+
+  // Get size of the needed buffer
+  len = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, defchar, &defused);
+
+  // Allocate buffer
+  if (buf_size < len+1) {
+    buf_size = len+1; // +1 for NULL
+    if (buf) free(buf);
+    buf = (char*)malloc(buf_size);
+  }
+
+  // Convert
+  len = WideCharToMultiByte(CP_ACP, 0, str, -1, buf, buf_size, defchar, 
&defused);
+  buf[len] = '\0';
+  return buf;
+}
+#endif
+
 //
 // End of "$Id$".
 //
Index: src/Fl_Window_hotspot.cxx
===================================================================
--- src/Fl_Window_hotspot.cxx   (revision 5870)
+++ src/Fl_Window_hotspot.cxx   (working copy)
@@ -50,10 +50,13 @@
 
     if (border()) {
 #ifdef WIN32
+#  ifndef _WIN32_WCE
       if (size_range_set && (maxw != minw || maxh != minh)) {
         left = right = GetSystemMetrics(SM_CXSIZEFRAME);
         top = bottom = GetSystemMetrics(SM_CYSIZEFRAME);
-      } else {
+      } else 
+#  endif
+      {
         left = right = GetSystemMetrics(SM_CXFIXEDFRAME); 
         top = bottom = GetSystemMetrics(SM_CYFIXEDFRAME);
       }
Index: src/numericsort.c
===================================================================
--- src/numericsort.c   (revision 5870)
+++ src/numericsort.c   (working copy)
@@ -31,8 +31,11 @@
 #include <config.h>
 #include <ctype.h>
 #include <stdlib.h>
-#include <sys/types.h>
 
+#ifndef _WIN32_WCE
+#  include <sys/types.h>
+#endif
+
 #include <FL/filename.H>
 
 #if !defined(WIN32) || defined(__CYGWIN__)
Index: src/scandir_win32.c
===================================================================
--- src/scandir_win32.c (revision 5870)
+++ src/scandir_win32.c (working copy)
@@ -33,9 +33,19 @@
 #include <windows.h>
 #include <stdlib.h>
 
+#ifdef _UNICODE
+// Exported from Fl_win32.cxx
+const TCHAR *c2tc(const char *str);
+const char *tc2c(const TCHAR *str);
+#else
+inline const TCHAR *c2tc(const char *str) { return str; }
+inline const char *tc2c(const TCHAR *str) { return str; }
+#endif
+
 int fl_scandir(const char *dirname, struct dirent ***namelist,
               int (*select)(struct dirent *),
-              int (*compar)(struct dirent **, struct dirent **)) {
+              int (*compar)(struct dirent **, struct dirent **)) 
+{
   int len;
   char *findIn, *d, is_dir = 0;
   WIN32_FIND_DATA find;
@@ -57,11 +67,11 @@
   if ((len>0) && (d[-1]=='\\')) { *d++ = '*'; *d = 0; is_dir = 1; }
   if ((len>1) && (d[-1]=='.') && (d[-2]=='\\')) { d[-1] = '*'; is_dir = 1; }
   if (!is_dir) { /* this file may still be a directory that we need to list */
-    DWORD attr = GetFileAttributes(findIn);
+    DWORD attr = GetFileAttributes(c2tc(findIn));
     if (attr&FILE_ATTRIBUTE_DIRECTORY) 
       strcpy(d, "\\*");
   }
-  if ((h=FindFirstFile(findIn, &find))==INVALID_HANDLE_VALUE) {
+  if ((h=FindFirstFile(c2tc(findIn), &find))==INVALID_HANDLE_VALUE) {
     free(findIn);
     ret = GetLastError();
     if (ret != ERROR_NO_MORE_FILES) {
@@ -71,8 +81,8 @@
     return nDir;
   }
   do {
-    selectDir=(struct dirent*)malloc(sizeof(struct 
dirent)+strlen(find.cFileName)+2);
-    strcpy(selectDir->d_name, find.cFileName);
+    selectDir=(struct dirent*)malloc(sizeof(struct 
dirent)+strlen(tc2c(find.cFileName))+2);
+    strcpy(selectDir->d_name, tc2c(find.cFileName));
     if (find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
       /* Append a trailing slash to directory names... */
       strcat(selectDir->d_name, "/");
Index: src/screen_xywh.cxx
===================================================================
--- src/screen_xywh.cxx (revision 5870)
+++ src/screen_xywh.cxx (working copy)
@@ -35,7 +35,7 @@
 static int num_screens = 0;
 
 #ifdef WIN32
-#  if !defined(HMONITOR_DECLARED) && (_WIN32_WINNT < 0x0500)
+#  if !defined(HMONITOR_DECLARED) && (_WIN32_WINNT < 0x0500) && 
!defined(_WIN32_WCE)
 #    define COMPILE_MULTIMON_STUBS
 #    include <multimon.h>
 #  endif // !HMONITOR_DECLARED && _WIN32_WINNT < 0x0500
@@ -75,11 +75,15 @@
 static void screen_init() {
   // Since not all versions of Windows include multiple monitor support,
   // we do a run-time check for the required functions...
-  HMODULE hMod = GetModuleHandle("USER32.DLL");
+  HMODULE hMod = GetModuleHandle(_T("USER32.DLL"));
 
   if (hMod) {
     // check that EnumDisplayMonitors is available
+#ifdef _WIN32_WCE
+    fl_edm_func fl_edm = (fl_edm_func)GetProcAddress(hMod, 
_T("EnumDisplayMonitors"));
+#else
     fl_edm_func fl_edm = (fl_edm_func)GetProcAddress(hMod, 
"EnumDisplayMonitors");
+#endif
 
     if (fl_edm) {
       // We do have EnumDisplayMonitors, so lets find out how many monitors...
@@ -87,7 +91,11 @@
 
       if (num_screens > 1) {
         // If there is more than 1 monitor, enumerate them...
+#ifdef _WIN32_WCE
+        fl_gmi = (fl_gmi_func)GetProcAddress(hMod, _T("GetMonitorInfoA"));
+#else
         fl_gmi = (fl_gmi_func)GetProcAddress(hMod, "GetMonitorInfoA");
+#endif
 
         if (fl_gmi) {
           // We have GetMonitorInfoA, enumerate all the screens...
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to