]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/fontdlgg.cpp
Fixed separator handling for menus.
[wxWidgets.git] / src / generic / fontdlgg.cpp
index c9f46c7f5ea3d918910cffd8fa4241243db77e30..9ac0c7dcfa4034a28728e1653ef1f27e5b0bd04c 100644 (file)
@@ -1,15 +1,15 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Name:        fontdlgg.cpp
+// Name:        src/generic/fontdlgg.cpp
 // Purpose:     Generic font dialog
 // Author:      Julian Smart
 // Modified by:
 // Created:     04/01/98
 // RCS-ID:      $Id$
 // Purpose:     Generic font dialog
 // Author:      Julian Smart
 // Modified by:
 // Created:     04/01/98
 // RCS-ID:      $Id$
-// Copyright:   (c) Julian Smart and Markus Holzem
-// Licence:     wxWindows license
+// Copyright:   (c) Julian Smart
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
 #pragma implementation "fontdlgg.h"
 #endif
 
 #pragma implementation "fontdlgg.h"
 #endif
 
@@ -41,7 +41,7 @@
 
 #include "wx/cmndata.h"
 #include "wx/sizer.h"
 
 #include "wx/cmndata.h"
 #include "wx/sizer.h"
-#include "wx/generic/fontdlgg.h"
+#include "wx/fontdlg.h"
 
 //-----------------------------------------------------------------------------
 // helper class - wxFontPreviewer
 
 //-----------------------------------------------------------------------------
 // helper class - wxFontPreviewer
@@ -74,14 +74,14 @@ void wxFontPreviewer::OnPaint(wxPaintEvent& WXUNUSED(event))
 
     if ( font.Ok() )
     {
 
     if ( font.Ok() )
     {
-        dc.SetFont(GetFont());
+        dc.SetFont(font);
         // Calculate vertical centre
         long w, h;
         // Calculate vertical centre
         long w, h;
-        dc.GetTextExtent("X", &w, &h);
+        dc.GetTextExtent( wxT("X"), &w, &h);
         dc.SetTextForeground(GetForegroundColour());
         dc.SetClippingRegion(2, 2, size.x-4, size.y-4);
         dc.DrawText(_("ABCDEFGabcdefg12345"), 
         dc.SetTextForeground(GetForegroundColour());
         dc.SetClippingRegion(2, 2, size.x-4, size.y-4);
         dc.DrawText(_("ABCDEFGabcdefg12345"), 
-                    10, h/2 + size.y/2);
+                     10, size.y/2 - h/2);
         dc.DestroyClippingRegion();
     }
 }
         dc.DestroyClippingRegion();
     }
 }
@@ -163,23 +163,14 @@ static wxString wxColourDialogNames[NUM_COLS]={wxT("ORANGE"),
  * Generic wxFontDialog
  */
 
  * Generic wxFontDialog
  */
 
-wxGenericFontDialog::wxGenericFontDialog(void)
+void wxGenericFontDialog::Init()
 {
   m_useEvents = FALSE;
   m_previewer = NULL;
 {
   m_useEvents = FALSE;
   m_previewer = NULL;
-  dialogParent = NULL;
+  Create( m_parent ) ;
 }
 
 }
 
-wxGenericFontDialog::wxGenericFontDialog(wxWindow *parent, const wxFontData& data):
-  wxDialog(parent, -1, _("Font"), wxDefaultPosition, wxDefaultSize,
-           wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxRESIZE_BORDER)
-{
-  m_useEvents = FALSE;
-  m_previewer = NULL;
-  Create(parent, data);
-}
-
-wxGenericFontDialog::~wxGenericFontDialog(void)
+wxGenericFontDialog::~wxGenericFontDialog()
 {
 }
 
 {
 }
 
@@ -188,31 +179,38 @@ void wxGenericFontDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
   EndModal(wxID_CANCEL);
 }
 
   EndModal(wxID_CANCEL);
 }
 
-bool wxGenericFontDialog::Create(wxWindow *parent, const wxFontData& data)
+bool wxGenericFontDialog::DoCreate(wxWindow *parent)
 {
 {
-  dialogParent = parent;
-
-  fontData = data;
+    if ( !wxDialog::Create( parent , -1 , _T("Choose Font") , wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
+        _T("fontdialog") ) )
+    {
+        wxFAIL_MSG( wxT("wxFontDialog creation failed") );
+        return FALSE;
+    }
 
   InitializeFont();
   CreateWidgets();
  
 
   InitializeFont();
   CreateWidgets();
  
+  // sets initial font in preview area
+  wxCommandEvent dummy;
+  OnChangeFont(dummy);
+  
   return TRUE;
 }
 
   return TRUE;
 }
 
-int wxGenericFontDialog::ShowModal(void)
+int wxGenericFontDialog::ShowModal()
 {
 {
-  int ret = wxDialog::ShowModal();
+    int ret = wxDialog::ShowModal();
 
     if (ret != wxID_CANCEL)
     {
 
     if (ret != wxID_CANCEL)
     {
-      fontData.chosenFont = dialogFont;
+      m_fontData.m_chosenFont = dialogFont;
     }
 
     return ret;
 }
 
     }
 
     return ret;
 }
 
-void wxGenericFontDialog::CreateWidgets(void)
+void wxGenericFontDialog::CreateWidgets()
 {
   wxBusyCursor bcur;
 
 {
   wxBusyCursor bcur;
 
@@ -243,8 +241,8 @@ void wxGenericFontDialog::CreateWidgets(void)
   int i;
   for ( i = 0; i < 40; i++)
   {
   int i;
   for ( i = 0; i < 40; i++)
   {
-    char buf[5];
-    sprintf(buf, "%d", i + 1);
+    wxChar buf[5];
+    wxSprintf(buf, wxT("%d"), i + 1);
     pointSizes[i] = buf;
   }
 
     pointSizes[i] = buf;
   }
 
@@ -254,12 +252,12 @@ void wxGenericFontDialog::CreateWidgets(void)
   m_previewer = new wxFontPreviewer(this);
 
   wxButton *okButton = new wxButton(this, wxID_OK, _("OK"));
   m_previewer = new wxFontPreviewer(this);
 
   wxButton *okButton = new wxButton(this, wxID_OK, _("OK"));
-  wxButton *cancelButton = new wxButton(this, wxID_OK, _("Cancel"));
+  wxButton *cancelButton = new wxButton(this, wxID_CANCEL, _("Cancel"));
 
   familyChoice->SetStringSelection( wxFontFamilyIntToString(dialogFont.GetFamily()) );
   styleChoice->SetStringSelection(wxFontStyleIntToString(dialogFont.GetStyle()));
   weightChoice->SetStringSelection(wxFontWeightIntToString(dialogFont.GetWeight()));
 
   familyChoice->SetStringSelection( wxFontFamilyIntToString(dialogFont.GetFamily()) );
   styleChoice->SetStringSelection(wxFontStyleIntToString(dialogFont.GetStyle()));
   weightChoice->SetStringSelection(wxFontWeightIntToString(dialogFont.GetWeight()));
-  wxString name(wxTheColourDatabase->FindName(fontData.fontColour));
+  wxString name(wxTheColourDatabase->FindName(m_fontData.GetColour()));
   colourChoice->SetStringSelection(name);
 
   underLineCheckBox->SetValue(dialogFont.GetUnderlined());
   colourChoice->SetStringSelection(name);
 
   underLineCheckBox->SetValue(dialogFont.GetUnderlined());
@@ -304,7 +302,7 @@ void wxGenericFontDialog::CreateWidgets(void)
   m_useEvents = TRUE;
 }
 
   m_useEvents = TRUE;
 }
 
-void wxGenericFontDialog::InitializeFont(void)
+void wxGenericFontDialog::InitializeFont()
 {
   int fontFamily = wxSWISS;
   int fontWeight = wxNORMAL;
 {
   int fontFamily = wxSWISS;
   int fontWeight = wxNORMAL;
@@ -312,13 +310,13 @@ void wxGenericFontDialog::InitializeFont(void)
   int fontSize = 12;
   int fontUnderline = FALSE;
 
   int fontSize = 12;
   int fontUnderline = FALSE;
 
-  if (fontData.initialFont.Ok())
+  if (m_fontData.m_initialFont.Ok())
   {
   {
-      fontFamily = fontData.initialFont.GetFamily();
-      fontWeight = fontData.initialFont.GetWeight();
-      fontStyle = fontData.initialFont.GetStyle();
-      fontSize = fontData.initialFont.GetPointSize();
-      fontUnderline = fontData.initialFont.GetUnderlined();
+      fontFamily = m_fontData.m_initialFont.GetFamily();
+      fontWeight = m_fontData.m_initialFont.GetWeight();
+      fontStyle = m_fontData.m_initialFont.GetStyle();
+      fontSize = m_fontData.m_initialFont.GetPointSize();
+      fontUnderline = m_fontData.m_initialFont.GetUnderlined();
   }
 
   dialogFont = wxFont(fontSize, fontFamily, fontStyle, fontWeight, (fontUnderline != 0));
   }
 
   dialogFont = wxFont(fontSize, fontFamily, fontStyle, fontWeight, (fontUnderline != 0));
@@ -331,12 +329,9 @@ void wxGenericFontDialog::OnChangeFont(wxCommandEvent& WXUNUSED(event))
 {
   if (!m_useEvents) return;
 
 {
   if (!m_useEvents) return;
 
-  int fontFamily = 0;  /* shut up buggy egcs warnings */
-  fontFamily = wxFontFamilyStringToInt(WXSTRINGCAST familyChoice->GetStringSelection());
-  int fontWeight = 0;
-  fontWeight = wxFontWeightStringToInt(WXSTRINGCAST weightChoice->GetStringSelection());
-  int fontStyle = 0;
-  fontStyle = wxFontStyleStringToInt(WXSTRINGCAST styleChoice->GetStringSelection());
+  int fontFamily = wxFontFamilyStringToInt(WXSTRINGCAST familyChoice->GetStringSelection());
+  int fontWeight = wxFontWeightStringToInt(WXSTRINGCAST weightChoice->GetStringSelection());
+  int fontStyle = wxFontStyleStringToInt(WXSTRINGCAST styleChoice->GetStringSelection());
   int fontSize = wxAtoi(pointSizeChoice->GetStringSelection());
   int fontUnderline = underLineCheckBox->GetValue();
 
   int fontSize = wxAtoi(pointSizeChoice->GetStringSelection());
   int fontUnderline = underLineCheckBox->GetValue();
 
@@ -344,12 +339,11 @@ void wxGenericFontDialog::OnChangeFont(wxCommandEvent& WXUNUSED(event))
   m_previewer->SetFont(dialogFont);
   if (colourChoice->GetStringSelection() != wxT(""))
   {
   m_previewer->SetFont(dialogFont);
   if (colourChoice->GetStringSelection() != wxT(""))
   {
-    wxColour *col = (wxColour*) NULL;
-    col = wxTheColourDatabase->FindColour(colourChoice->GetStringSelection());
-    if (col)
+    wxColour col = wxTheColourDatabase->Find(colourChoice->GetStringSelection());
+    if (col.Ok())
     {
     {
-      fontData.fontColour = *col;
-      m_previewer->SetForegroundColour(*col);
+      m_fontData.m_fontColour = col;
+      m_previewer->SetForegroundColour(col);
     }
   }
   m_previewer->Refresh();
     }
   }
   m_previewer->Refresh();