[Mono-winforms-list] [Patch] Initial FontDialog class implementation
Jordi Mas
jmas@softcatala.org
Fri, 19 Sep 2003 12:27:51 +0200
This is a multi-part message in MIME format.
--------------060301070709000306030201
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Hello,
Here you have the initial FontDialog Box implementation. There are still a few
things to finnish but you can already do the basic stuff. I have not tried in
a wine enviroment, but it works fine in win32.
I also have written a simple sample to test it (FontDialogSample.cs). This
example is currently living in my machine at
mono/mcs/class/System.Windows.Forms/System.Windows.Forms.Test. I do not know
if it should be commited there or to the winforms cvs module. I'll suggest to
keep it at mono/mcs/class/System.Windows.Forms/System.Win because it looks
like the logical place to look for it.
Please, have a look and commit the diff and the example if you think is OK.
Best Regards,
--
Jordi Mas i Hernāndez (homepage http://www.softcatala.org/~jmas)
http://www.softcatala.org
--------------060301070709000306030201
Content-Type: text/plain;
name="fontdlg.txt"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline;
filename="fontdlg.txt"
Index: class/System.Drawing/System.Drawing/impl/wine/win32Enums.cs
===================================================================
RCS file: /mono/mcs/class/System.Drawing/System.Drawing/impl/wine/win32Enums.cs,v
retrieving revision 1.3
diff -c -r1.3 win32Enums.cs
*** class/System.Drawing/System.Drawing/impl/wine/win32Enums.cs 23 Aug 2003 09:39:37 -0000 1.3
--- class/System.Drawing/System.Drawing/impl/wine/win32Enums.cs 19 Sep 2003 10:20:10 -0000
***************
*** 4,9 ****
--- 4,10 ----
* Minor additons for project Mono by
* John Sohn (jsohn@columbus.rr.com)
* Dennis Hayes (dennish@raytek.com)
+ * Jordi Mas i Hernāndez (jmas@softcatala.org)
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
***************
*** 1053,1059 ****
LVM_FIRST = 0x1000,
LVM_GETSUBITEMRECT = (LVM_FIRST + 56),
LVM_GETITEMSTATE = (LVM_FIRST + 44),
! LVM_GETITEMTEXTW = (LVM_FIRST + 115)
}
#endregion
--- 1054,1064 ----
LVM_FIRST = 0x1000,
LVM_GETSUBITEMRECT = (LVM_FIRST + 56),
LVM_GETITEMSTATE = (LVM_FIRST + 44),
! LVM_GETITEMTEXTW = (LVM_FIRST + 115)
! LVM_INSERTITEMA = (LVM_FIRST + 7)
! LVM_INSERTITEMW = (LVM_FIRST + 77)
! LVM_INSERTCOLUMNA = (LVM_FIRST + 27)
! LVM_INSERTCOLUMNW = (LVM_FIRST + 97)
}
#endregion
Index: class/System.Windows.Forms/ChangeLog
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/ChangeLog,v
retrieving revision 1.11
diff -c -r1.11 ChangeLog
*** class/System.Windows.Forms/ChangeLog 31 Aug 2003 17:22:03 -0000 1.11
--- class/System.Windows.Forms/ChangeLog 19 Sep 2003 10:20:22 -0000
***************
*** 1,3 ****
--- 1,6 ----
+ 2003-09-19 Jordi Mas i Hernāndez <jmas@softcatala.org>
+ * Initial FileDialog Box implementation
+
2003-08-31 Jerome Laban <jlaban@wanadoo.fr>
* Label.cs: Fixed Text property not redrawing the label correctly.
Index: class/System.Windows.Forms/System.Windows.Forms/FontDialog.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/FontDialog.cs,v
retrieving revision 1.12
diff -c -r1.12 FontDialog.cs
*** class/System.Windows.Forms/System.Windows.Forms/FontDialog.cs 4 Dec 2002 01:35:40 -0000 1.12
--- class/System.Windows.Forms/System.Windows.Forms/FontDialog.cs 19 Sep 2003 10:20:23 -0000
***************
*** 4,197 ****
// Author:
// stubbed out by Daniel Carrera (dcarrera@math.toronto.edu)
// Dennis Hayes (dennish@raytek.com)
! // (C) 2002 Ximian, Inc
//
using System.Drawing;
! namespace System.Windows.Forms {
!
! // <summary>
! //
! // </summary>
!
! public class FontDialog : CommonDialog {
!
! //
! // --- Constructor
! //
! [MonoTODO]
! public FontDialog()
! {
! }
!
! //
! // --- Public Properties
! //
! [MonoTODO]
! public bool AllowScriptChange {
! get {
! throw new NotImplementedException ();
! }
! set {
! //FIXME:
! }
! }
! [MonoTODO]
! public bool AllowSimululations {
! get {
! throw new NotImplementedException ();
! }
! set {
! //FIXME:
! }
! }
! [MonoTODO]
! public bool AllowVectorForms {
! get {
! throw new NotImplementedException ();
! }
! set {
! //FIXME:
! }
! }
! [MonoTODO]
! public bool AllowVerticalForms {
! get {
! throw new NotImplementedException ();
! }
! set {
! //FIXME:
! }
! }
! [MonoTODO]
! public Color Color {
! get {
! throw new NotImplementedException ();
! }
! set {
! //FIXME:
! }
! }
! [MonoTODO]
! public bool FixedPitchOnly {
! get {
! throw new NotImplementedException ();
! }
! set {
! //FIXME:
! }
! }
! [MonoTODO]
! public Font Font {
! get {
! throw new NotImplementedException ();
! }
! set {
! //FIXME:
! }
! }
! [MonoTODO]
! public bool FontMustExist {
! get {
! throw new NotImplementedException ();
! }
! set {
! //FIXME:
! }
! }
! [MonoTODO]
! public int MaxSize {
! get {
! throw new NotImplementedException ();
! }
! set {
! //FIXME:
! }
! }
! [MonoTODO]
! public int MinSize {
! get {
! throw new NotImplementedException ();
! }
! set {
! //FIXME:
! }
! }
! [MonoTODO]
! public bool ScriptsOnly {
! get {
! throw new NotImplementedException ();
! }
! set {
! //FIXME:
! }
! }
! [MonoTODO]
! public bool ShowApply {
! get {
! throw new NotImplementedException ();
! }
! set {
! //FIXME:
! }
! }
! [MonoTODO]
! public bool ShowColor {
! get {
! throw new NotImplementedException ();
! }
! set {
! //FIXME:
! }
! }
! [MonoTODO]
! public bool ShowEffects {
! get {
! throw new NotImplementedException ();
! }
! set {
! //FIXME:
! }
! }
! [MonoTODO]
! public bool ShowHelp {
! get {
! throw new NotImplementedException ();
}
! set {
! //FIXME:
}
! }
!
!
! // --- Public Methods
!
! [MonoTODO]
! public override void Reset()
! {
! //FIXME:
! }
!
! //
! // --- Public Events
! //
! [MonoTODO]
! public event EventHandler Apply;
!
! //
! // --- Protected Properties
! //
!
! [MonoTODO]
! protected override IntPtr HookProc( IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam )
! {
! //FIXME:
! return base.HookProc(hWnd, msg, wparam,lparam);
! }
! [MonoTODO]
! protected override bool RunDialog(IntPtr hWndOwner)
! {
! throw new NotImplementedException ();
! }
! }
}
--- 4,220 ----
// Author:
// stubbed out by Daniel Carrera (dcarrera@math.toronto.edu)
// Dennis Hayes (dennish@raytek.com)
! // Implemented by Jordi Mas i Hernāndez (jmas@softcatala.org)
! //
! // (C) 2002-2003 Ximian, Inc
//
using System.Drawing;
! using System.Runtime.InteropServices;
! using System.Drawing;
! namespace System.Windows.Forms
! {
! public class FontDialog : CommonDialog
! {
! private bool bAllowScriptChange;
! private bool bAllowSimululations;
! private bool bAllowVectorForms;
! private bool bAllowVerticalForms;
! private Color color = Color.Black;
! private bool bFixedPitchOnly;
! private Font font;
! private bool bFontMustExist;
! private int nMaxSize;
! private int nMinSize;
! private bool bScriptsOnly;
! private bool bShowApply;
! private bool bShowColor;
! private bool bShowEffects;
! private bool bShowHelp;
!
! //
! // --- Constructor
! //
! public FontDialog()
! {
! defaultValues();
! }
! internal void defaultValues()
! {
! font = new Font("Microsoft Sans Serif", 8);
! bAllowScriptChange = true;
! bAllowSimululations = true;
! bAllowVectorForms = true;
! bAllowVerticalForms = true;
! color = Color.Black;
! bFixedPitchOnly = false;
! bFontMustExist = false;
! nMaxSize = 0 ;
! nMinSize = 0;
! bScriptsOnly = false;
! bShowApply = true;
! bShowColor = false;
! bShowEffects = true;
! bShowHelp = false;
! }
!
! //
! // --- Public Properties
! //
! public virtual bool AllowScriptChange
! {
! get { return bAllowScriptChange; }
! set { bAllowScriptChange = value; }
}
!
! public bool AllowSimululations
! {
! get { return AllowSimululations; }
! set { bAllowSimululations = value; }
}
!
! public bool AllowVectorForms
! {
! get { return AllowVectorForms; }
! set { AllowVectorForms = value; }
! }
!
! public bool AllowVerticalForms
! {
! get { return AllowVerticalForms; }
! set { AllowVerticalForms = value; }
! }
!
! public Color Color
! {
! get { return color; }
! set { color = value; }
! }
!
! public bool FixedPitchOnly
! {
! get { return bFixedPitchOnly; }
! set { bFixedPitchOnly = value; }
! }
!
! public Font Font
! {
! get { return font; }
! set { font = value; }
! }
!
! public bool FontMustExist
! {
! get { return bFontMustExist; }
! set { bFontMustExist = value; }
! }
!
! public int MaxSize
! {
! get { return nMaxSize; }
! set { nMaxSize = value; }
! }
!
! public int MinSize
! {
! get { return nMinSize; }
! set { nMinSize = value; }
! }
!
! public bool ScriptsOnly
! {
! get { return bScriptsOnly; }
! set { bScriptsOnly = value; }
! }
!
! public bool ShowApply
! {
! get { return bShowApply; }
! set { bShowApply = value; }
! }
!
! public bool ShowColor
! {
! get { return bShowColor; }
! set { bShowColor = value; }
! }
!
! public bool ShowEffects
! {
! get { return bShowEffects; }
! set { bShowEffects = value; }
! }
!
! public bool ShowHelp
! {
! get { return bShowHelp; }
! set { bShowHelp = value; }
! }
!
!
! // --- Public Methods
! public override void Reset()
! {
! defaultValues();
! }
!
! //
! // --- Public Events
! //
! [MonoTODO]
! public event EventHandler Apply;
!
!
! [MonoTODO]
! protected override IntPtr HookProc( IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam )
! {
! return base.HookProc(hWnd, msg, wparam,lparam);
! }
! protected override bool RunDialog(IntPtr hWndOwner)
! {
! CHOOSEFONT cf = new CHOOSEFONT();
! LOGFONT lf = new LOGFONT();
!
! cf.lStructSize = (uint)Marshal.SizeOf(cf);
! cf.nSizeMin = MinSize;
! cf.nSizeMax = MaxSize;
!
! lf.lfFaceName=Font.FontFamily.Name;
! lf.lfWeight = (uint)400/* FW_NORMAL*/ ;
! lf.lfHeight = (uint) -((Font.Size * 96)/72); // TODO: Use Win32.GetDeviceCaps(0, LOGPIXELSY) when implemented
!
! //cf.lpfnHook = new Win32.FnHookProc(HookProc);
! cf.Flags = (uint)(FontDlgFlags.CF_SCREENFONTS| /* FontDlgFlags.CF_ENABLEHOOK |*/ FontDlgFlags.CF_EFFECTS |FontDlgFlags.CF_INITTOLOGFONTSTRUCT);
!
! // Flags
! if (!AllowScriptChange) cf.Flags |= (int)FontDlgFlags.CF_NOSCRIPTSEL;
! if (ShowApply) cf.Flags |= (int)FontDlgFlags.CF_APPLY;
! if (bShowEffects) cf.Flags |= (int)FontDlgFlags.CF_EFFECTS;
! if (bShowHelp) cf.Flags |= (int)FontDlgFlags.CF_SHOWHELP;
! if (bFixedPitchOnly) cf.Flags |= (int)FontDlgFlags.CF_SHOWHELP;
! if (bFontMustExist) cf.Flags |= (int)FontDlgFlags.CF_FORCEFONTEXIST;
! if (!(MaxSize==0) || !(MinSize==0)) cf.Flags |= (int)FontDlgFlags.CF_LIMITSIZE;
!
! // Color
! cf.rgbColors = (uint) (color.R | color.G<<8 |color.B <<16);
! IntPtr lfBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(lf));
! Marshal.StructureToPtr(lf, lfBuffer, false);
! cf.lpLogFont = lfBuffer;
!
! // Show dialog box
! if (Win32_WineLess.ChooseFont(ref cf))
! {
! lf = (LOGFONT) Marshal.PtrToStructure(lfBuffer, typeof(LOGFONT));
! Marshal.FreeHGlobal(lfBuffer);
!
! // Get font
! font = new Font(lf.lfFaceName, cf.iPointSize/10);
! Color = Color.FromArgb (0, (int)cf.rgbColors & 0x0FF, (int)(cf.rgbColors >> 8) & 0x0FF, (int) (cf.rgbColors >> 16) & 0x0FF);
! return true;
! }
! else
! return false;
! }
! }
}
+
Index: class/System.Windows.Forms/System.Windows.Forms/win32Enums.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/win32Enums.cs,v
retrieving revision 1.35
diff -c -r1.35 win32Enums.cs
*** class/System.Windows.Forms/System.Windows.Forms/win32Enums.cs 11 Aug 2003 14:15:10 -0000 1.35
--- class/System.Windows.Forms/System.Windows.Forms/win32Enums.cs 19 Sep 2003 10:20:31 -0000
***************
*** 2896,2901 ****
--- 2896,2933 ----
OFN_ENABLEINCLUDENOTIFY = 0x00400000,
OFN_ENABLESIZING = 0x00800000
}
+
+ internal enum FontDlgFlags : int {
+ CF_SCREENFONTS = 0x00000001,
+ CF_PRINTERFONTS = 0x00000002,
+ CF_BOTH = (CF_SCREENFONTS | CF_PRINTERFONTS),
+ CF_SHOWHELP = 0x00000004,
+ CF_ENABLEHOOK = 0x00000008,
+ CF_ENABLETEMPLATE = 0x00000010,
+ CF_ENABLETEMPLATEHANDLE = 0x00000020,
+ CF_INITTOLOGFONTSTRUCT = 0x00000040,
+ CF_USESTYLE = 0x00000080,
+ CF_EFFECTS = 0x00000100,
+ CF_APPLY = 0x00000200,
+ CF_ANSIONLY = 0x00000400,
+ CF_SCRIPTSONLY = CF_ANSIONLY,
+ CF_NOVECTORFONTS = 0x00000800,
+ CF_NOOEMFONTS = CF_NOVECTORFONTS,
+ CF_NOSIMULATIONS = 0x00001000,
+ CF_LIMITSIZE = 0x00002000,
+ CF_FIXEDPITCHONLY = 0x00004000,
+ CF_WYSIWYG = 0x00008000, // must also have CF_SCREENFONTS & CF_PRINTERFONTS
+ CF_FORCEFONTEXIST = 0x00010000,
+ CF_SCALABLEONLY = 0x00020000,
+ CF_TTONLY = 0x00040000,
+ CF_NOFACESEL = 0x00080000,
+ CF_NOSTYLESEL = 0x00100000,
+ CF_NOSIZESEL = 0x00200000,
+ CF_SELECTSCRIPT = 0x00400000,
+ CF_NOSCRIPTSEL = 0x00800000,
+ CF_NOVERTFONTS = 0x01000000,
+
+ }
internal enum CommDlgErrors : uint {
FNERR_FILENAMECODES = 0x3000,
Index: class/System.Windows.Forms/System.Windows.Forms/win32Structs.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/win32Structs.cs,v
retrieving revision 1.23
diff -c -r1.23 win32Structs.cs
*** class/System.Windows.Forms/System.Windows.Forms/win32Structs.cs 8 Aug 2003 15:49:35 -0000 1.23
--- class/System.Windows.Forms/System.Windows.Forms/win32Structs.cs 19 Sep 2003 10:20:33 -0000
***************
*** 856,861 ****
--- 856,904 ----
internal Win32.FnHookProc lpfnHook;
internal string lpTemplateName;
}
+
+ [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
+ public struct LOGFONT
+ {
+ internal uint lfHeight;
+ internal uint lfWidth;
+ internal uint lfEscapement;
+ internal uint lfOrientation;
+ internal uint lfWeight;
+ internal byte lfItalic;
+ internal byte lfUnderline;
+ internal byte lfStrikeOut;
+ internal byte lfCharSet;
+ internal byte lfOutPrecision;
+ internal byte lfClipPrecision;
+ internal byte lfQuality;
+ internal byte lfPitchAndFamily;
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
+ internal string lfFaceName;
+
+ }
+
+ [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
+ public struct CHOOSEFONT {
+
+ internal uint lStructSize;
+ internal IntPtr hwndOwner;
+ internal IntPtr hDC;
+ internal IntPtr lpLogFont;
+ internal int iPointSize;
+ internal uint Flags;
+ internal uint rgbColors;
+ internal uint lCustData;
+ internal Win32.FnHookProc lpfnHook;
+ internal uint lpTemplateName;
+ internal IntPtr hInstance;
+ internal uint lpszStyle;
+ internal short nFontType;
+ internal short ___MISSING_ALIGNMENT__;
+ internal int nSizeMin;
+ internal int nSizeMax;
+
+ }
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
struct OFNOTIFY {
Index: class/System.Windows.Forms/System.Windows.Forms/win32functions.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/win32functions.cs,v
retrieving revision 1.53
diff -c -r1.53 win32functions.cs
*** class/System.Windows.Forms/System.Windows.Forms/win32functions.cs 31 Aug 2003 17:06:07 -0000 1.53
--- class/System.Windows.Forms/System.Windows.Forms/win32functions.cs 19 Sep 2003 10:20:38 -0000
***************
*** 71,76 ****
--- 71,82 ----
CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Ansi)]
internal static extern bool ChooseColor ( ref CHOOSECOLOR lpofn );
+
+
+ [DllImport ("comdlg32.dll",
+ CallingConvention = CallingConvention.StdCall,
+ CharSet = CharSet.Ansi)]
+ internal static extern bool ChooseFont ( ref CHOOSEFONT lpcf );
[DllImport ("comdlg32.dll",
CallingConvention = CallingConvention.StdCall,
--------------060301070709000306030201
Content-Type: text/plain;
name="FontDialogSample.cs"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline;
filename="FontDialogSample.cs"
//
// Test application for the FontDialog class implementation
//
// Author:
// Jordi Mas i Hernāndez, jmas@softcatala.org
//
using System;
using System.Collections;
using System.Windows.Forms;
using System.Drawing;
//
namespace FontDialogTest
{
public class myButton : System.Windows.Forms.Button
{
public FontDialog fontDialog = null;
public TestForm testForm = null;
public FontDialog fontdlg { get { return fontDialog; } }
public myButton(TestForm testFrm) : base()
{
fontDialog = new FontDialog();
testForm = testFrm;
}
/* User clicks the button*/
protected override void OnClick(EventArgs e)
{
// Show default values
Console.WriteLine("Default values---");
Console.WriteLine("AllowScriptChange " + fontDialog.AllowScriptChange);
Console.WriteLine("Color " + fontDialog.Color);
Console.WriteLine("FixedPitchOnly " + fontDialog.FixedPitchOnly);
Console.WriteLine("Font " + fontDialog.Font);
Console.WriteLine("FontMustExist " + fontDialog.FontMustExist);
Console.WriteLine("MaxSize " + fontDialog.MaxSize);
Console.WriteLine("MinSize " + fontDialog.MinSize);
Console.WriteLine("ScriptsOnly " + fontDialog.ScriptsOnly);
Console.WriteLine("ShowApply " + fontDialog.ShowApply);
Console.WriteLine("ShowColor " + fontDialog.ShowColor);
Console.WriteLine("ShowEffects " + fontDialog.ShowEffects);
Console.WriteLine("ShowHelp " + fontDialog.ShowHelp);
testForm.Update();
fontDialog.ShowColor = true;
fontDialog.Color = Color.Red;
fontDialog.MinSize = 10;
fontDialog.MaxSize = 12;
if(fontDialog.ShowDialog(this) != DialogResult.Cancel )
{
Console.WriteLine("Seleted Font " + fontDialog.Font.FontFamily.Name);
Console.WriteLine("Seleted Size " + fontDialog.Font.Size);
Console.WriteLine("Seleted Color " + fontDialog.Color);
testForm.Update();
}
else
{
fontDialog.Reset();
testForm.Update();
}
}
}
public class TestForm : System.Windows.Forms.Form
{
TextBox fontName = null;
TextBox fontSize = null;
TextBox fontColor = null;
myButton button = null;
public static void Main(string[] args)
{
Application.Run(new TestForm());
}
public TestForm()
{
InitializeComponent();
}
private void InitializeComponent()
{
Text = "Test application for the FontDialog class implementation";
FontDialog fontDialog = new FontDialog();
ClientSize = new System.Drawing.Size(300, 300);
button = new myButton(this);
button.Location = new System.Drawing.Point(5, 10);
button.Name = "button20";
button.Size = new System.Drawing.Size(100, 30);
button.Text = "Press me baby";
button.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
Controls.Add(button);
fontName = new TextBox();
fontName.Location = new System.Drawing.Point(5, 60);
fontName.Name = "FontName";
fontName.Size = new System.Drawing.Size(200, 30);
fontName.ReadOnly = true;
Controls.Add(fontName);
fontSize = new TextBox();
fontSize.Location = new System.Drawing.Point(5, 100);
fontSize.Name = "FontSize";
fontSize.Size = new System.Drawing.Size(200, 30);
fontSize.ReadOnly = true;
Controls.Add(fontSize);
fontColor = new TextBox();
fontColor.Location = new System.Drawing.Point(5, 140);
fontColor.Name = "FontSize";
fontColor.Size = new System.Drawing.Size(200, 30);
fontColor.ReadOnly = true;
Controls.Add(fontColor);
return;
}
public new void Update()
{
//fontName.Text = "Font: " + button.fontDialog.MaxSize + " "+ button.fontDialog.MinSize;
fontName.Text = "Font: " + button.fontDialog.Font.FontFamily.Name;
fontSize.Text = "Size: " + button.fontDialog.Font.Size;
fontColor.Text = "Color: " + button.fontDialog.Color;
}
}
}
--------------060301070709000306030201--