]> git.saurik.com Git - wxWidgets.git/commitdiff
allow entering font description string interactively
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 22 Aug 2006 10:07:35 +0000 (10:07 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 22 Aug 2006 10:07:35 +0000 (10:07 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40738 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/font/font.cpp

index 7fe8717618c9950c58bbe08d9b7585c3a93ade9a..7c6c89794da84c3860d038c3274e558bad922319 100644 (file)
@@ -266,9 +266,9 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
 
     menuFont->AppendSeparator();
     menuFont->Append(Font_CheckNativeToFromString,
-                     wxT("Check Native Font Info To/From String"));
+                     wxT("Set native font &description\tShift-Ctrl-D"));
     menuFont->Append(Font_CheckNativeToFromUserString,
-                     wxT("Check Native Font Info User String"));
+                     wxT("Set &user font description\tShift-Ctrl-U"));
     menuFont->Append(Font_CheckFaceName,
                      wxT("Check font face name"));                     
 
@@ -481,22 +481,26 @@ void MyFrame::OnEnumerateFamiliesForEncoding(wxCommandEvent& WXUNUSED(event))
 
 void MyFrame::OnCheckNativeToFromString(wxCommandEvent& WXUNUSED(event))
 {
-    wxString fontInfo = m_canvas->GetTextFont().GetNativeFontInfoDesc();
-
+    wxString fontInfo = wxGetTextFromUser
+                        (
+                            wxT("Enter native font string"),
+                            wxT("Input font description"),
+                            m_canvas->GetTextFont().GetNativeFontInfoDesc(),
+                            this
+                        );
     if ( fontInfo.empty() )
+        return;     // user clicked "Cancel" - do nothing
+
+    wxFont font;
+    font.SetNativeFontInfo(fontInfo);
+    if ( !font.Ok() )
     {
-        wxLogError(wxT("Native font info string is empty!"));
+        wxLogError(wxT("Font info string \"%s\" is invalid."),
+                   fontInfo.c_str());
+        return;
     }
-    else
-    {
-        wxFont *font = wxFont::New(fontInfo);
-        if ( fontInfo != font->GetNativeFontInfoDesc() )
-            wxLogError(wxT("wxNativeFontInfo ToString()/FromString() broken!"));
-        else
-            wxLogMessage(wxT("wxNativeFontInfo works: %s"), fontInfo.c_str());
 
-        delete font;
-     }
+    DoChangeFont(font);
 }
 
 void MyFrame::OnCheckFaceName(wxCommandEvent& WXUNUSED(event))