changeset 76:c390bd107089

FontDialog
author Frank Benoit <benoit@tionex.de>
date Tue, 05 Feb 2008 04:03:25 +0100
parents f824f1836871
children 205350493476
files doc/Common.txt dwt/widgets/FontDialog.d
diffstat 2 files changed, 29 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/doc/Common.txt	Tue Feb 05 03:50:39 2008 +0100
+++ b/doc/Common.txt	Tue Feb 05 04:03:25 2008 +0100
@@ -27,7 +27,6 @@
     DateTime
     DirectoryDialog
     FileDialog
-    FontDialog
 
 
 
--- a/dwt/widgets/FontDialog.d	Tue Feb 05 03:50:39 2008 +0100
+++ b/dwt/widgets/FontDialog.d	Tue Feb 05 04:03:25 2008 +0100
@@ -12,32 +12,19 @@
  *******************************************************************************/
 module dwt.widgets.FontDialog;
 
-import dwt.widgets.Dialog;
-import dwt.widgets.Shell;
-
-class FontDialog : Dialog {
-    public this (Shell parent) {
-        this (parent, 0);
-    }
-    public this (Shell parent, int style) {
-        super (parent, style);
-    }
-}
-/++
 import dwt.DWT;
 import dwt.DWTException;
 import dwt.graphics.Font;
 import dwt.graphics.FontData;
 import dwt.graphics.PaletteData;
 import dwt.graphics.RGB;
-import dwt.internal.win32.CHOOSEFONT;
-import dwt.internal.win32.LOGFONT;
-import dwt.internal.win32.LOGFONTA;
-import dwt.internal.win32.LOGFONTW;
 import dwt.internal.win32.OS;
-import dwt.internal.win32.TEXTMETRIC;
-import dwt.internal.win32.TEXTMETRICA;
-import dwt.internal.win32.TEXTMETRICW;
+
+import dwt.widgets.Dialog;
+import dwt.widgets.Shell;
+import dwt.widgets.Display;
+
+import dwt.dwthelper.utils;
 
 /**
  * Instances of this class allow the user to select a font
@@ -53,7 +40,7 @@
  * within the DWT implementation.
  * </p>
  */
-public class FontDialog extends Dialog {
+public class FontDialog : Dialog {
     FontData fontData;
     RGB rgb;
 
@@ -70,7 +57,7 @@
  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
  * </ul>
  */
-public FontDialog (Shell parent) {
+public this (Shell parent) {
     this (parent, DWT.PRIMARY_MODAL);
 }
 
@@ -98,7 +85,7 @@
  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
  * </ul>
  */
-public FontDialog (Shell parent, int style) {
+public this (Shell parent, int style) {
     super (parent, style);
     checkSubclass ();
 }
@@ -158,25 +145,25 @@
     if (OS.IsWinCE) DWT.error (DWT.ERROR_NOT_IMPLEMENTED);
 
     /* Get the owner HWND for the dialog */
-    int hwndOwner = 0;
+    HWND hwndOwner;
     if (parent !is null) hwndOwner = parent.handle;
 
     /* Open the dialog */
-    int hHeap = OS.GetProcessHeap ();
-    CHOOSEFONT lpcf = new CHOOSEFONT ();
+    auto hHeap = OS.GetProcessHeap ();
+    CHOOSEFONT lpcf;
     lpcf.lStructSize = CHOOSEFONT.sizeof;
     lpcf.hwndOwner = hwndOwner;
     lpcf.Flags = OS.CF_SCREENFONTS | OS.CF_EFFECTS;
-    int lpLogFont = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, LOGFONT.sizeof);
-    if (fontData !is null && fontData.data !is null) {
+    auto lpLogFont = cast(LOGFONT*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, LOGFONT.sizeof);
+    if (fontData !is null /+&& fontData.data !is null+/) {
         LOGFONT logFont = fontData.data;
         int lfHeight = logFont.lfHeight;
-        int hDC = OS.GetDC (0);
-        int pixels = -(int)(0.5f + (fontData.height * OS.GetDeviceCaps(hDC, OS.LOGPIXELSY) / 72));
-        OS.ReleaseDC (0, hDC);
+        auto hDC = OS.GetDC (null);
+        int pixels = -cast(int)(0.5f + (fontData.height * OS.GetDeviceCaps(hDC, OS.LOGPIXELSY) / 72));
+        OS.ReleaseDC (null, hDC);
         logFont.lfHeight = pixels;
         lpcf.Flags |= OS.CF_INITTOLOGFONTSTRUCT;
-        OS.MoveMemory (lpLogFont, logFont, LOGFONT.sizeof);
+        OS.MoveMemory (lpLogFont, &logFont, LOGFONT.sizeof);
         logFont.lfHeight = lfHeight;
     }
     lpcf.lpLogFont = lpLogFont;
@@ -197,7 +184,7 @@
     }
 
     /* Open the dialog */
-    bool success = OS.ChooseFont (lpcf);
+    bool success = cast(bool) OS.ChooseFont (&lpcf);
 
     /* Clear the temporary dialog modal parent */
     if ((style & (DWT.APPLICATION_MODAL | DWT.SYSTEM_MODAL)) !is 0) {
@@ -206,14 +193,14 @@
 
     /* Compute the result */
     if (success) {
-        LOGFONT logFont = OS.IsUnicode ? (LOGFONT) new LOGFONTW () : new LOGFONTA ();
-        OS.MoveMemory (logFont, lpLogFont, LOGFONT.sizeof);
+        LOGFONT* logFont = lpLogFont;
+        //OS.MoveMemory (logFont, lpLogFont, LOGFONT.sizeof);
 
         /*
          * This will not work on multiple screens or
          * for printing. Should use DC for the proper device.
          */
-        int hDC = OS.GetDC(0);
+        auto hDC = OS.GetDC(null);
         int logPixelsY = OS.GetDeviceCaps(hDC, OS.LOGPIXELSY);
         int pixels = 0;
         if (logFont.lfHeight > 0) {
@@ -225,17 +212,17 @@
              * we must subtract the internal leading, which requires a TEXTMETRIC,
              * which in turn requires font creation.
              */
-            int hFont = OS.CreateFontIndirect(logFont);
-            int oldFont = OS.SelectObject(hDC, hFont);
-            TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ();
-            OS.GetTextMetrics(hDC, lptm);
+            auto hFont = OS.CreateFontIndirect(logFont);
+            auto oldFont = OS.SelectObject(hDC, hFont);
+            TEXTMETRIC lptm ;
+            OS.GetTextMetrics(hDC, &lptm);
             OS.SelectObject(hDC, oldFont);
             OS.DeleteObject(hFont);
             pixels = logFont.lfHeight - lptm.tmInternalLeading;
         } else {
             pixels = -logFont.lfHeight;
         }
-        OS.ReleaseDC(0, hDC);
+        OS.ReleaseDC(null, hDC);
 
         float points = pixels * 72f /logPixelsY;
         fontData = FontData.win32_new (logFont, points);
@@ -246,7 +233,7 @@
     }
 
     /* Free the OS memory */
-    if (lpLogFont !is 0) OS.HeapFree (hHeap, 0, lpLogFont);
+    if (lpLogFont !is null) OS.HeapFree (hHeap, 0, lpLogFont);
 
     /*
     * This code is intentionally commented.  On some
@@ -308,4 +295,4 @@
 }
 
 }
-++/
+