]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/fontdlg.cpp
Compile fixes.
[wxWidgets.git] / src / mac / carbon / fontdlg.cpp
index 913ee8015bee00f47d776dcfa33d57ea523845cc..5fafc36dbf2d00ce28a48ba8b0be1da4d719d301 100644 (file)
@@ -36,26 +36,26 @@ pascal OSStatus wxFontDialogEventHandler(   EventHandlerCallRef inHandlerCallRef,
    
     OSStatus status = noErr;
     
-    ATSUFontID fontid;
-    Fixed fontsize;
-    RGBColor fontcolor;
+    FMFontFamily fontfamily;
     FMFontStyle fontstyle;
+    FMFontSize fontsize;
+    RGBColor fontcolor;
         
+    status = GetEventParameter (event, kEventParamFMFontFamily,
+                                    typeFMFontFamily, NULL,
+                                    sizeof (FMFontFamily), 
+                                    NULL, &(fontfamily)); 
+    check_noerr (status); 
+
     status = GetEventParameter (event, kEventParamFMFontStyle,
                                     typeFMFontStyle, NULL,
                                     sizeof (FMFontStyle), 
                                     NULL, &(fontstyle)); 
     check_noerr (status); 
 
-    status = GetEventParameter (event, kEventParamATSUFontID,
-                                    typeATSUFontID, NULL,
-                                    sizeof (ATSUFontID), 
-                                    NULL, &(fontid)); 
-    check_noerr (status); 
-
-    status = GetEventParameter (event, kEventParamATSUFontSize,
-                                    typeATSUSize, NULL,
-                                    sizeof (Fixed), 
+    status = GetEventParameter (event, kEventParamFMFontSize,
+                                    typeFMFontSize, NULL,
+                                    sizeof (FMFontSize), 
                                     NULL, &(fontsize)); 
 
     check_noerr (status);
@@ -65,73 +65,31 @@ pascal OSStatus wxFontDialogEventHandler(   EventHandlerCallRef inHandlerCallRef,
                                     sizeof( RGBColor ), NULL, &fontcolor); 
     check_noerr (status);
     
-    //TODO:
-    //TODO:    Make a utility function for converting ATSU to WX font (what we're doing :))
-    //TODO:
-        
     //now do the conversion to the wx font data
     wxFontData theFontData;
     wxFont        theFont;
  
-    //first, the easy part - set the color
+    //set color
     wxColour theColor;
     theColor.Set(&(WXCOLORREF&)fontcolor);
     theFontData.SetColour(theColor);
+        
+    //set size
+    theFont.SetPointSize(fontsize);
     
-    //
-    //now the hard part - convert the atsu font to a wx font
-    //
-    
-    //point size - fixed, but straight conversion, I think
-    theFont.SetPointSize(fontsize >> 16);
-    
-    //font name - first get length, then allocate/copy/deallocate name buffer
-    FontNameCode               theNameCode;
-    FontPlatformCode   thePlatformCode;        
-    FontScriptCode             theScriptCode;
-    FontLanguageCode   theLanguageCode;    
-    //the above have types in SFNTTypes.h
-
-    ByteCount                  theActualLength;
-    ATSUGetIndFontName(fontid, 
-                       0, //first font in index array
-                       0, //need to get length first
-                       NULL, //nothin'
-                       &theActualLength,
-                       &theNameCode,
-                       &thePlatformCode,
-                       &theScriptCode,
-                       &theLanguageCode);
-    
-    Ptr szBuffer = NewPtr(theActualLength);
-    ATSUGetIndFontName(fontid, 
-                       0, //first font in index array
-                       theActualLength, 
-                       szBuffer, 
-                       &theActualLength,
-                       &theNameCode,
-                       &thePlatformCode,
-                       &theScriptCode,
-                       &theLanguageCode);
-    
-    //its unicode - convert it to wx's char value and put it in there
-    theFont.SetFaceName(wxConvLocal.cMB2WX((char*)szBuffer));
-    DisposePtr(szBuffer);
-    
+    //set name
+    Str255 theFontName;
+    GetFontName(fontfamily, theFontName);
+    theFont.SetFaceName(wxMacMakeStringFromPascal(theFontName));
+      
     //TODOTODO: Get font family - mayby by the script code?
     theFont.SetFamily(wxDEFAULT);  
 
-    //TODOTODO: Get other styles?  Font weight?
-    theFont.SetStyle(0 +
-                     ((fontstyle & bold) ? wxFONTFLAG_BOLD : 0) +
-                     ((fontstyle & italic) ? wxFONTFLAG_ITALIC : 0) +
-                     ((fontstyle & underline) ? wxFONTFLAG_UNDERLINED : 0)
-                     );
+    //TODOTODO: Get other styles?
+    theFont.SetStyle(((fontstyle & italic) ? wxFONTSTYLE_ITALIC : 0));
     theFont.SetWeight((fontstyle & bold) ? wxBOLD : wxNORMAL);   
-    
-    //for debugging
-    //wxPrintf(wxT("FaceName:%s\nSize:%i\n"), theFont.GetFaceName().c_str(), theFont.GetPointSize());
-    
+    theFont.SetUnderlined(((fontstyle & underline) ? true : false));
+        
     //phew!!  We're done - set the chosen font
     theFontData.SetChosenFont(theFont);
     ((wxFontDialog*)pData)->SetData(theFontData);
@@ -239,6 +197,11 @@ int wxFontDialog::ShowModal()
     status = ATSUDisposeStyle(theStyle);
     check_noerr(status);
     
+    //in case the user doesn't choose anything -
+    //if he doesn't we'll get a bad font with red text
+    m_fontData.SetChosenFont(m_fontData.GetInitialFont());
+    m_fontData.SetColour(wxColour(0,0,0));
+    
     //finally, show the font dialog
     if( (status = FPShowHideFontPanel()) == noErr)
     {