Author: pbartok
Date: 2005-04-28 12:39:03 -0400 (Thu, 28 Apr 2005)
New Revision: 43732
Added:
trunk/winforms/wordpad/
trunk/winforms/wordpad/Makefile
trunk/winforms/wordpad/support.cs
trunk/winforms/wordpad/wordpad.cs
trunk/winforms/wordpad/wordpad.csproj
trunk/winforms/wordpad/wordpad.csproj.user
Log:
- WordPad application for testing RichTextBox
Added: trunk/winforms/wordpad/Makefile
===================================================================
--- trunk/winforms/wordpad/Makefile 2005-04-28 16:20:33 UTC (rev 43731)
+++ trunk/winforms/wordpad/Makefile 2005-04-28 16:39:03 UTC (rev 43732)
@@ -0,0 +1,10 @@
+all: mono
+
+mono: wordpad.cs support.cs
+ mcs wordpad.cs support.cs /r:System.Windows.Forms.dll
/r:System.Drawing.dll
+
+dotnet: wordpad.cs support.cs
+ csc wordpad.cs support.cs /r:System.Windows.Forms.dll
/r:System.Drawing.dll
+
+clean:
+ rm wordpad.exe -r -f
Added: trunk/winforms/wordpad/support.cs
===================================================================
--- trunk/winforms/wordpad/support.cs 2005-04-28 16:20:33 UTC (rev 43731)
+++ trunk/winforms/wordpad/support.cs 2005-04-28 16:39:03 UTC (rev 43732)
@@ -0,0 +1,548 @@
+using System;
+using System.Collections;
+using System.Drawing;
+using System.IO;
+using System.IO.IsolatedStorage;
+using System.Globalization;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.Windows.Forms;
+
+namespace WordPad {
+ [Serializable]
+ public class Configuration {
+ #region Local Variables
+ private Point location;
+ private Size size;
+ private bool shortcutbar;
+ private bool formatbar;
+ private ArrayList mru;
+ #endregion // Local Variables
+
+ #region Constructors
+ public Configuration() {
+ size = new Size(300, 300);
+ location = new Point(-1, -1);
+ shortcutbar = true;
+ formatbar = true;
+ mru = new ArrayList(4);
+ }
+ #endregion // Constructors
+
+ #region Properties
+ public Point Location {
+ get { return location; }
+ set { location = value; }
+ }
+
+ public Size Size {
+ get { return size; }
+ set { size = value; }
+ }
+
+ public bool ShortcutBar {
+ get { return shortcutbar; }
+ set { shortcutbar = value; }
+ }
+
+ public bool FormatBar {
+ get { return formatbar; }
+ set { formatbar = value; }
+ }
+
+ public ArrayList MRU {
+ get { return mru; }
+ set { mru = value; }
+ }
+ #endregion // Properties
+
+ #region Static Methods
+ static public void Save(Configuration config) {
+ IsolatedStorageFile isoFile;
+
+ isoFile = IsolatedStorageFile.GetUserStoreForAssembly();
+
+ try {
+ using (IsolatedStorageFileStream isoStream =
new IsolatedStorageFileStream("WordPad", FileMode.OpenOrCreate,
FileAccess.Write, isoFile)) {
+ BinaryFormatter formatter;
+
+ formatter = new BinaryFormatter();
+ formatter.Serialize(isoStream, config);
+ }
+ }
+
+ catch {
+ MessageBox.Show("Could not save configuration",
"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ }
+ }
+
+ static public Configuration Load() {
+ Configuration config;
+ IsolatedStorageFile isoFile;
+
+ isoFile = IsolatedStorageFile.GetUserStoreForAssembly();
+
+ try {
+ using (IsolatedStorageFileStream isoStream =
new IsolatedStorageFileStream("WordPad", FileMode.Open, FileAccess.Read,
isoFile)) {
+ BinaryFormatter formatter;
+
+ formatter = new BinaryFormatter();
+ config =
(Configuration)formatter.Deserialize(isoStream);
+
+ return config;
+ }
+ }
+
+ catch {
+ MessageBox.Show("Could not load configuration",
"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ }
+
+ // We failed, return default
+ return new Configuration();
+ }
+
+ static public void Apply(WordPad wordpad) {
+ Configuration config;
+
+ config = Configuration.Load();
+
+ if (config.Location.X != -1) {
+ wordpad.StartPosition =
FormStartPosition.Manual;
+ }
+ wordpad.Location = config.Location;
+ wordpad.Size = config.Size;
+
+ if (config.FormatBar) {
+ wordpad.formatting.Visible = true;
+ } else {
+ wordpad.formatting.Visible = false;
+ }
+
+ if (config.ShortcutBar) {
+ wordpad.buttons.Visible = true;
+ } else {
+ wordpad.buttons.Visible = false;
+ }
+
+ wordpad.MRU = config.MRU;
+ }
+
+ static public void Store(WordPad wordpad) {
+ Configuration config;
+
+ config = new Configuration();
+
+ config.Location = wordpad.Location;
+ config.Size = wordpad.Size;
+ config.MRU = wordpad.MRU;
+
+ if (wordpad.formatting.Visible) {
+ config.FormatBar = true;
+ } else {
+ config.FormatBar = true;
+ }
+
+ if (wordpad.buttons.Visible) {
+ config.ShortcutBar = true;
+ } else {
+ config.ShortcutBar = true;
+ }
+
+ Configuration.Save(config);
+ }
+ #endregion
+ }
+
+ #region WordPad Format Toolbar
+ public class WordPadFormat : Control {
+ #region Local Variables
+ WordPad wordpad;
+ ComboBox fonts;
+ ComboBox sizes;
+ #endregion // Local Variables
+
+ #region Constructors
+ public WordPadFormat(WordPad wordpad) {
+ FontFamily[] fontFamilies;
+
+ this.wordpad = wordpad;
+ Height = 21;
+ fonts = new ComboBox();
+ sizes = new ComboBox();
+
+ fonts.DropDownStyle = ComboBoxStyle.DropDownList;
+
+ fontFamilies = FontFamily.Families;
+ fonts.BeginUpdate( );
+ foreach ( FontFamily ff in fontFamilies ) {
+ fonts.Items.Add( ff.Name );
+ }
+ fonts.EndUpdate();
+ fonts.Location = new Point(0, 0);
+ fonts.Width = 150;
+
+ fonts.SelectedIndex = fonts.FindString("Arial");
+ fonts.SelectedIndexChanged += new
EventHandler(fonts_SelectedIndexChanged);
+
+ sizes.DropDownStyle = ComboBoxStyle.DropDownList;
+ sizes.Location = new Point(160, 0);
+ sizes.Width = 50;
+
+ sizes.Items.AddRange(new string[] {"8", "9", "10",
"11", "12", "14", "16", "18", "20", "22", "24", "26", "28", "36", "48", "72"});
+ sizes.SelectedIndex = 4;
+ sizes.SelectedIndexChanged += new
EventHandler(sizes_SelectedIndexChanged);
+
+
+
+ this.Controls.Add(fonts);
+ this.Controls.Add(sizes);
+ }
+ #endregion // Constructors
+
+ #region Properties
+ #endregion // Properties
+
+ #region Methods
+ #endregion // Methods
+
+ #region Event Handlers
+ #endregion // Event Handlers
+
+ private void fonts_SelectedIndexChanged(object sender,
EventArgs e) {
+ if ((wordpad.edit != null) &&
(wordpad.edit.SelectionLength > 0)) {
+ wordpad.edit.SelectionFont = new
Font((string)fonts.Items[fonts.SelectedIndex],
Int32.Parse((string)(sizes.Items[sizes.SelectedIndex])));
+ wordpad.edit.Focus();
+ }
+ }
+
+ private void sizes_SelectedIndexChanged(object sender,
EventArgs e) {
+ if ((wordpad.edit != null) &&
(wordpad.edit.SelectionLength > 0)) {
+ wordpad.edit.SelectionFont = new
Font((string)fonts.Items[fonts.SelectedIndex],
Int32.Parse((string)(sizes.Items[sizes.SelectedIndex])));
+ wordpad.edit.Focus();
+ }
+ }
+ }
+ #endregion // WordPad Format Toolbar
+
+
+ #region WordPad Menu Class
+ public class WordPadMenu {
+ #region Local Variables
+ MainMenu menu;
+ MenuItem file, edit, view, insert, format, help;
+ MenuItem mnew, open, save, saveas, print, printpreview,
pagesetup, mru1, mru2, mru3, mru4, exit;
+ MenuItem undo, cut, copy, paste, clear, selectall, find,
findnext, replace;
+ MenuItem toolbar, formatbar, statusbar, options;
+ MenuItem datetime;
+ MenuItem fontstyle, bullet, paragraph, tabs;
+ MenuItem about;
+ StatusBar status;
+ WordPad wordpad;
+ #endregion // Local Variables
+
+ #region Constructor
+ public WordPadMenu(WordPad wordpad, StatusBar status) {
+ this.status = status;
+ this.wordpad = wordpad;
+
+ mnew = new MenuItem(MenuMerge.Add, 0, Shortcut.CtrlN,
"&New...", new EventHandler(NewDocument), null, new
EventHandler(MenuClickHandler), null);
+ open = new MenuItem(MenuMerge.Add, 0, Shortcut.CtrlO,
"&Open...", new EventHandler(OpenDocument), null, new
EventHandler(MenuClickHandler), null);
+ save = new MenuItem(MenuMerge.Add, 0, Shortcut.CtrlS,
"&Save...", new EventHandler(SaveDocument), null, new
EventHandler(MenuClickHandler), null);
+ saveas = new MenuItem(MenuMerge.Add, 0, Shortcut.None,
"Save &As...", new EventHandler(SaveAs), null, new
EventHandler(MenuClickHandler), null);
+ print = new MenuItem(MenuMerge.Add, 0, Shortcut.CtrlP,
"&Print...", new EventHandler(PrintDocument), null, new
EventHandler(MenuClickHandler), null);
+ printpreview = new MenuItem(MenuMerge.Add, 0,
Shortcut.None, "Print Pre&view", new EventHandler(PrintPreview), null, new
EventHandler(MenuClickHandler), null);
+ pagesetup = new MenuItem(MenuMerge.Add, 0,
Shortcut.None, "Page Set&up...", new EventHandler(PrintPageSetup), null, new
EventHandler(MenuClickHandler), null);
+ mru1 = new MenuItem(MenuMerge.Add, 0, Shortcut.None,
"&1 - ", new EventHandler(OpenMRU1), null, new EventHandler(MenuClickHandler),
null);
+ mru2 = new MenuItem(MenuMerge.Add, 0, Shortcut.None,
"&2 - ", new EventHandler(OpenMRU2), null, new EventHandler(MenuClickHandler),
null);
+ mru3 = new MenuItem(MenuMerge.Add, 0, Shortcut.None,
"&3 - ", new EventHandler(OpenMRU3), null, new EventHandler(MenuClickHandler),
null);
+ mru4 = new MenuItem(MenuMerge.Add, 0, Shortcut.None,
"&4 - ", new EventHandler(OpenMRU4), null, new EventHandler(MenuClickHandler),
null);
+ exit = new MenuItem(MenuMerge.Add, 0, Shortcut.None,
"E&xit", new EventHandler(Exit), null, new EventHandler(MenuClickHandler),
null);
+
+
+ // FILE menu
+ file = new MenuItem("&File");
+ UpdateMRU();
+
+
+ // EDIT menu
+ edit = new MenuItem("&Edit");
+ undo = new MenuItem(MenuMerge.Add, 0, Shortcut.CtrlZ,
"&Undo", new EventHandler(DoUndo), null, new EventHandler(MenuClickHandler),
null);
+ cut = new MenuItem(MenuMerge.Add, 0, Shortcut.CtrlX,
"Cu&t", new EventHandler(DoCut), null, new EventHandler(MenuClickHandler),
null);
+ copy = new MenuItem(MenuMerge.Add, 0, Shortcut.CtrlC,
"&Copy", new EventHandler(DoCopy), null, new EventHandler(MenuClickHandler),
null);
+ paste = new MenuItem(MenuMerge.Add, 0, Shortcut.CtrlV,
"&Paste", new EventHandler(DoPaste), null, new EventHandler(MenuClickHandler),
null);
+ clear = new MenuItem(MenuMerge.Add, 0, Shortcut.Del,
"Cle&ar", new EventHandler(DoClear), null, new EventHandler(MenuClickHandler),
null);
+ selectall = new MenuItem(MenuMerge.Add, 0,
Shortcut.CtrlA, "Select A&ll", new EventHandler(DoSelectAll), null, new
EventHandler(MenuClickHandler), null);
+ find = new MenuItem(MenuMerge.Add, 0, Shortcut.CtrlF,
"&Find...", new EventHandler(DoFind), null, new EventHandler(MenuClickHandler),
null);
+ findnext = new MenuItem(MenuMerge.Add, 0, Shortcut.F3,
"Find &Next", new EventHandler(DoFindNext), null, new
EventHandler(MenuClickHandler), null);
+ replace = new MenuItem(MenuMerge.Add, 0,
Shortcut.CtrlH, "R&eplace...", new EventHandler(DoReplace), null, new
EventHandler(MenuClickHandler), null);
+ edit.MenuItems.AddRange(new MenuItem[] {undo, new
MenuItem("-"), cut, copy, paste, clear, selectall, new MenuItem("-"), find,
findnext, replace});
+
+
+ // VIEW menu
+ view = new MenuItem("&View");
+ toolbar = new MenuItem(MenuMerge.Add, 0, Shortcut.None,
"&Toolbar", new EventHandler(DoToolBar), null, new
EventHandler(MenuClickHandler), null);
+ formatbar = new MenuItem(MenuMerge.Add, 0,
Shortcut.None, "&Format Bar", new EventHandler(DoFormatBar), null, new
EventHandler(MenuClickHandler), null);
+ statusbar = new MenuItem(MenuMerge.Add, 0,
Shortcut.None, "&Status Bar", new EventHandler(DoStatusBar), null, new
EventHandler(MenuClickHandler), null);
+ options = new MenuItem(MenuMerge.Add, 0, Shortcut.None,
"&Options...", new EventHandler(Options), null, new
EventHandler(MenuClickHandler), null);
+ view.MenuItems.AddRange(new MenuItem[] {toolbar,
formatbar, statusbar, new MenuItem("-"), options});
+
+
+ // INSERT menu
+ insert = new MenuItem("&Insert");
+ datetime = new MenuItem(MenuMerge.Add, 0,
Shortcut.None, "&Date and Time...", new EventHandler(InsertDateTime), null, new
EventHandler(MenuClickHandler), null);
+ insert.MenuItems.AddRange(new MenuItem[] {datetime});
+
+
+ // FORMAT menu
+ format = new MenuItem("F&ormat");
+ fontstyle = new MenuItem(MenuMerge.Add, 0,
Shortcut.None, "&Font...", new EventHandler(ChangeFont), null, new
EventHandler(MenuClickHandler), null);
+ bullet = new MenuItem(MenuMerge.Add, 0, Shortcut.None,
"&Bullet Style", new EventHandler(ChangeBulletStyle), null, new
EventHandler(MenuClickHandler), null);
+ paragraph = new MenuItem(MenuMerge.Add, 0,
Shortcut.None, "&Paragraph...", new EventHandler(ChangeParagraph), null, new
EventHandler(MenuClickHandler), null);
+ tabs = new MenuItem(MenuMerge.Add, 0, Shortcut.None,
"&Tabs...", new EventHandler(ChangeTabs), null, new
EventHandler(MenuClickHandler), null);
+ format.MenuItems.AddRange(new MenuItem[] {fontstyle,
bullet, paragraph, tabs});
+
+
+ // HELP menu
+ help = new MenuItem("Help");
+ about = new MenuItem(MenuMerge.Add, 0, Shortcut.None,
"&About...", new EventHandler(About), null, new EventHandler(MenuClickHandler),
null);
+ help.MenuItems.AddRange(new MenuItem[] {about});
+
+ menu = new MainMenu(new MenuItem[] {file, edit, view,
insert, format, help});
+ }
+ #endregion // Constructor
+
+ #region Properties
+ public StatusBar StatusBarObject {
+ get { return status; }
+ set { status = value; }
+ }
+
+ public MainMenu MainMenu {
+ get { return menu; }
+ }
+
+ public bool Undo {
+ get { return undo.Enabled; }
+ set { undo.Enabled = value; }
+ }
+
+ public bool Cut {
+ get { return cut.Enabled; }
+ set { cut.Enabled = value; }
+ }
+
+ public bool Copy {
+ get { return copy.Enabled; }
+ set { copy.Enabled = value; }
+ }
+
+ public bool Paste {
+ get { return paste.Enabled; }
+ set { paste.Enabled = value; }
+ }
+
+ public bool Clear {
+ get { return clear.Enabled; }
+ set { clear.Enabled = value; }
+ }
+
+ public bool FindNext {
+ get { return findnext.Enabled; }
+ set { findnext.Enabled = value; }
+ }
+
+ public bool ToolBar {
+ get { return toolbar.Checked; }
+ set { toolbar.Checked = value; }
+ }
+
+ public bool FormatBar {
+ get { return formatbar.Checked; }
+ set { formatbar.Checked = value; }
+ }
+
+ public bool StatusBar {
+ get { return statusbar.Checked; }
+ set { statusbar.Checked = value; }
+ }
+ #endregion // Properties
+
+ #region Methods
+ public void UpdateMRU() {
+ if (wordpad != null && wordpad.MRU != null) {
+ if (wordpad.MRU.Count > 0) mru1.Text = "&1 - "
+ (string)wordpad.MRU[0];
+ if (wordpad.MRU.Count > 1) mru2.Text = "&2 - "
+ (string)wordpad.MRU[1];
+ if (wordpad.MRU.Count > 2) mru3.Text = "&3 - "
+ (string)wordpad.MRU[2];
+ if (wordpad.MRU.Count > 3) mru4.Text = "&4 - "
+ (string)wordpad.MRU[3];
+ }
+
+ // FILE menu
+ file.MenuItems.Clear();
+ file.MenuItems.AddRange(new MenuItem[] {mnew, open,
save, saveas, new MenuItem("-"), print, printpreview, pagesetup, new
MenuItem("-")});
+ if (wordpad != null && wordpad.MRU != null) {
+ if (wordpad.MRU.Count > 0)
file.MenuItems.Add(mru1);
+ if (wordpad.MRU.Count > 1)
file.MenuItems.Add(mru2);
+ if (wordpad.MRU.Count > 2)
file.MenuItems.Add(mru3);
+ if (wordpad.MRU.Count > 3)
file.MenuItems.Add(mru4);
+ file.MenuItems.Add(new MenuItem("-"));
+ }
+ file.MenuItems.Add(exit);
+ }
+ #endregion // Methods
+
+ #region Event Handlers
+ private void MenuClickHandler(object sender, EventArgs e) {
+ if (status != null) {
+ if (sender == mnew) status.Text = "Create new
document";
+ if (sender == open) status.Text = "Open
existing document";
+ if (sender == save) status.Text = "Save current
document";
+ if (sender == saveas) status.Text = "Save
current document under new name";
+ if (sender == print) status.Text = "Print
document";
+ if (sender == printpreview) status.Text =
"Preview printed document";
+ if (sender == pagesetup) status.Text = "Set up
page layout for printing";
+ if (sender == mru1 || sender == mru2 || sender
== mru3 || sender == mru4) status.Text = "Open this document";
+ if (sender == exit) status.Text = "Exit
application";
+
+ if (sender == undo) status.Text = "Undo last
change";
+ if (sender == cut) status.Text = "Cut the
selection and put it into the clipboard";
+ if (sender == copy) status.Text = "Copy the
selection into the clipboard";
+ if (sender == paste) status.Text = "Paste
clipboard contents";
+ if (sender == clear) status.Text = "Remove
selected text";
+ if (sender == selectall) status.Text = "Select
the whole document";
+ if (sender == find) status.Text = "Find text";
+ if (sender == findnext) status.Text = "Repeat
last find operation";
+ if (sender == replace) status.Text = "Find and
replace text";
+
+ if (sender == toolbar) status.Text = "Show or
hide the toolbar";
+ if (sender == formatbar) status.Text = "Show or
hide the formatting bar";
+ if (sender == statusbar) status.Text = "Show or
hide the status bar";
+ if (sender == options) status.Text = "Set
Options";
+
+ if (sender == datetime) status.Text = "Insert
current date and time";
+
+ if (sender == fontstyle) status.Text = "Change
Font";
+ if (sender == bullet) status.Text = "Change
Bullet Style";
+ if (sender == paragraph) status.Text = "Change
Paragraph settings";
+ if (sender == tabs) status.Text = "Change tab
settings";
+
+ if (sender == about) status.Text = "Display
information about this application";
+ }
+ }
+
+ // FILE
+ private void NewDocument(object sender, EventArgs e) {
+ wordpad.Clear();
+ }
+
+ private void OpenDocument(object sender, EventArgs e) {
+ wordpad.Open();
+ }
+
+ private void SaveDocument(object sender, EventArgs e) {
+ wordpad.Save(false);
+ }
+
+ private void SaveAs(object sender, EventArgs e) {
+ wordpad.Save(true);
+ }
+
+ private void PrintDocument(object sender, EventArgs e) {
+ }
+
+ private void PrintPreview(object sender, EventArgs e) {
+ }
+
+ private void PrintPageSetup(object sender, EventArgs e) {
+ }
+
+ private void OpenMRU1(object sender, EventArgs e) {
+ wordpad.OpenFile((string)wordpad.MRU[0],
((string)(wordpad.MRU[0])).EndsWith(".rtf") ? RichTextBoxStreamType.RichText :
RichTextBoxStreamType.PlainText);
+ }
+
+ private void OpenMRU2(object sender, EventArgs e) {
+ wordpad.OpenFile((string)wordpad.MRU[1],
((string)(wordpad.MRU[1])).EndsWith(".rtf") ? RichTextBoxStreamType.RichText :
RichTextBoxStreamType.PlainText);
+ }
+
+ private void OpenMRU3(object sender, EventArgs e) {
+ wordpad.OpenFile((string)wordpad.MRU[2],
((string)(wordpad.MRU[2])).EndsWith(".rtf") ? RichTextBoxStreamType.RichText :
RichTextBoxStreamType.PlainText);
+ }
+
+ private void OpenMRU4(object sender, EventArgs e) {
+ wordpad.OpenFile((string)wordpad.MRU[3],
((string)(wordpad.MRU[3])).EndsWith(".rtf") ? RichTextBoxStreamType.RichText :
RichTextBoxStreamType.PlainText);
+ }
+
+ private void Exit(object sender, EventArgs e) {
+ wordpad.Exit();
+ }
+
+ // EDIT
+ private void DoUndo(object sender, EventArgs e) {
+ wordpad.edit.Undo();
+ }
+
+ private void DoCut(object sender, EventArgs e) {
+ wordpad.edit.Cut();
+ }
+
+ private void DoCopy(object sender, EventArgs e) {
+ wordpad.edit.Copy();
+ }
+
+ private void DoPaste(object sender, EventArgs e) {
+ wordpad.edit.Paste();
+ }
+
+ private void DoClear(object sender, EventArgs e) {
+ }
+
+ private void DoSelectAll(object sender, EventArgs e) {
+ wordpad.edit.SelectAll();
+ }
+
+ private void DoFind(object sender, EventArgs e) {
+ }
+
+ private void DoFindNext(object sender, EventArgs e) {
+ }
+
+ private void DoReplace(object sender, EventArgs e) {
+ }
+
+ // VIEW
+ private void DoToolBar(object sender, EventArgs e) {
+ }
+
+ private void DoFormatBar(object sender, EventArgs e) {
+ }
+
+ private void DoStatusBar(object sender, EventArgs e) {
+ }
+
+ private void Options(object sender, EventArgs e) {
+ }
+
+ // INSERT
+ private void InsertDateTime(object sender, EventArgs e) {
+ }
+
+ // FORMAT
+ private void ChangeFont(object sender, EventArgs e) {
+ }
+
+ private void ChangeBulletStyle(object sender, EventArgs e) {
+ }
+
+ private void ChangeParagraph(object sender, EventArgs e) {
+ }
+
+ private void ChangeTabs(object sender, EventArgs e) {
+ }
+
+ // HELP
+ private void About(object sender, EventArgs e) {
+ }
+
+ #endregion
+ }
+ #endregion // WordPad Menu Class
+}
Added: trunk/winforms/wordpad/wordpad.cs
===================================================================
--- trunk/winforms/wordpad/wordpad.cs 2005-04-28 16:20:33 UTC (rev 43731)
+++ trunk/winforms/wordpad/wordpad.cs 2005-04-28 16:39:03 UTC (rev 43732)
@@ -0,0 +1,307 @@
+using System;
+using System.Collections;
+using System.ComponentModel;
+using System.Drawing;
+using System.Windows.Forms;
+
+namespace WordPad {
+ public class WordPad : System.Windows.Forms.Form {
+ #region Local Variables
+ static public WordPad wordpad;
+ static public int debug;
+
+ // UI Components
+ public RichTextBox edit;
+ public WordPadMenu menu;
+ public ToolBar buttons;
+ public WordPadFormat formatting;
+ public StatusBar status;
+ public Panel toolbarpanel;
+
+ // Document
+ public string filename;
+ public RichTextBoxStreamType filetype;
+
+ // State
+ public bool changed;
+ public ArrayList mru;
+ #endregion // Local Variables
+
+ #region Constructors
+ public WordPad(string file) {
+ // Object setup
+ changed = false;
+ if (file != null) {
+ filename = file;
+ } else {
+ filename = "Document";
+ }
+ filetype = RichTextBoxStreamType.RichText;
+
+ // UI Setup
+ toolbarpanel = new Panel();
+ buttons = new ToolBar();
+ formatting = new WordPadFormat(this);
+ status = new StatusBar();
+ edit = new RichTextBox();
+ Configuration.Apply(this); // Call before creating
the menu to have MRU loaded
+ menu = new WordPadMenu(this, status);
+
+ this.Menu = menu.MainMenu;
+
+ buttons.Appearance = ToolBarAppearance.Flat;
+ buttons.TextAlign = ToolBarTextAlign.Right;
+ buttons.ButtonSize = new Size(12, 12);
+ buttons.Buttons.Add("New");
+ buttons.Buttons.Add("Open");
+ buttons.Buttons.Add("Save");
+ buttons.Divider = false;
+
+ buttons.Location = new Point(0, 0);
+ formatting.Location = new Point(0, buttons.Height);
+ toolbarpanel.Height = buttons.Height +
formatting.Height + 8;
+ formatting.Dock = DockStyle.Bottom;
+
+ // Register all required events
+ this.Closing += new CancelEventHandler(WordPadClosing);
+ edit.TextChanged += new EventHandler(DocumentChanged);
+
+ // Layout
+ toolbarpanel.Controls.Add(buttons);
+ toolbarpanel.Controls.Add(formatting);
+
+ // Edit must be first to be 'filled' properly
+ this.Controls.Add(edit);
+ this.Controls.Add(toolbarpanel);
+ this.Controls.Add(status);
+
+ toolbarpanel.Dock = DockStyle.Top;
+ status.Dock = DockStyle.Bottom;
+ edit.Dock = DockStyle.Fill;
+
+ // Load our file, if any
+ if (file != null) {
+ OpenFile(file, file.EndsWith("txt") ?
RichTextBoxStreamType.PlainText : RichTextBoxStreamType.RichText);
+ }
+ UpdateTitle();
+ }
+ #endregion // Constructors
+
+ #region Properties
+ public bool Changed {
+ get {
+ return changed;
+ }
+
+ set {
+ if (changed != value) {
+ changed = value;
+ UpdateTitle();
+ }
+ }
+ }
+
+ public string Filename {
+ get {
+ return filename;
+ }
+
+ set {
+ if (filename != value) {
+ filename = value;
+ UpdateTitle();
+ }
+ }
+ }
+
+ public ArrayList MRU {
+ get {
+ return mru;
+ }
+
+ set {
+ mru = value;
+ }
+ }
+ #endregion // Properties
+
+ #region Methods
+ public void AddMRU(string item) {
+ while (mru.Contains(item)) {
+ mru.Remove(item);
+ }
+ mru.Insert(0, item);
+ while (mru.Count > 4) {
+ mru.RemoveAt(4);
+ }
+ menu.UpdateMRU();
+ }
+
+ public void Clear() {
+ DialogResult result;
+
+ if (Changed) {
+ result = MessageBox.Show("Save changed to " +
filename + "?", "WordPad", MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
+
+ if (result == DialogResult.Cancel) {
+ return;
+ }
+
+ if (result == DialogResult.Yes) {
+ Save(false);
+ }
+ }
+
+ // FIXME - we need a dialog and ask for the document
type
+ filename = "Document";
+ filetype = RichTextBoxStreamType.RichText;
+ edit.Clear();
+ Changed = false;
+ }
+
+
+ public void Exit() {
+ DialogResult result;
+
+ if (Changed) {
+ result = MessageBox.Show("Save changed to " +
filename + "?", "WordPad", MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
+
+ if (result == DialogResult.Cancel) {
+ return;
+ }
+
+ if (result == DialogResult.Yes) {
+ Save(false);
+ }
+ }
+ Application.Exit();
+ }
+
+ public bool Open() {
+ OpenFileDialog openfile;
+
+ openfile = new OpenFileDialog();
+ openfile.AddExtension = true;
+ openfile.CheckFileExists = true;
+ openfile.DereferenceLinks = true;
+ openfile.DefaultExt = "rtf";
+ openfile.Filter = "Rich Text Format (*.rtf)|*.rtf|Text
files (*.txt)|*.txt|All files (*.*)|*.*";
+
+ if (openfile.ShowDialog() == DialogResult.Cancel) {
+ return false;
+ }
+
+ if (openfile.FilterIndex == 1) {
+ return OpenFile(openfile.FileName,
RichTextBoxStreamType.RichText);
+ } else {
+ return OpenFile(openfile.FileName,
RichTextBoxStreamType.PlainText);
+ }
+ }
+
+ public bool OpenFile(string name, RichTextBoxStreamType type) {
+ if (Changed) {
+ DialogResult result;
+
+ result = MessageBox.Show("Save changed to " +
filename + "?", "WordPad", MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
+
+ if (result == DialogResult.Cancel) {
+ return false;
+ }
+
+ if (result == DialogResult.Yes) {
+ Save(false);
+ }
+ }
+
+ filename = name;
+ filetype = type;
+ edit.LoadFile(filename, filetype);
+ AddMRU(filename);
+ Changed = false;
+ return true;
+ }
+
+ public bool Save(bool ask) {
+ if ((filename == "Document") || ask) {
+ SaveFileDialog savefile;
+ DialogResult result;
+
+ savefile = new SaveFileDialog();
+ savefile.AddExtension = true;
+ savefile.CheckFileExists = false;
+ savefile.DereferenceLinks = true;
+ savefile.DefaultExt = "rtf";
+ savefile.Filter = "Rich Text Format
(*.rtf)|*.rtf|Text files (*.txt)|*.txt|All files (*.*)|*.*";
+
+ result = savefile.ShowDialog();
+
+ if (result != DialogResult.OK) {
+ return false;
+ }
+
+ if (savefile.FilterIndex == 1) {
+ filetype =
RichTextBoxStreamType.RichText;
+ } else {
+ filetype =
RichTextBoxStreamType.PlainText;
+ }
+ filename = savefile.FileName;
+ }
+
+ if (filename == String.Empty) {
+ return false;
+ }
+
+ edit.SaveFile(filename, filetype);
+ Changed = false;
+ return true;
+ }
+
+ public void UpdateTitle() {
+ string title;
+
+ title = filename + (Changed ? "*" : "") + " - WordPad";
+ this.Text = title;
+ }
+ #endregion // Methods
+
+ #region Static Methods
+ public static int Main(string[] args) {
+ string file;
+
+ file = null;
+
+ if (args.Length > 0) {
+ for (int i=0; i< args.Length; i++) {
+ if ((args[i] == "-d") || (args[i] ==
"--debug")) {
+ debug++;
+ continue;
+ }
+
+ if ((args[i] == "-?") || (args[i] ==
"-h") || (args[i] == "--help")) {
+ Console.WriteLine("Usage: <cmd>
[-d | --debug]");
+ return 0;
+ }
+
+ file = args[i];
+ }
+ }
+
+ wordpad = new WordPad(null);
+ Application.Run(wordpad);
+
+ return 0;
+ }
+ #endregion // Static Methods
+
+ #region Event Handlers
+ private void WordPadClosing(object sender, CancelEventArgs e) {
+ Configuration.Store(wordpad);
+ }
+
+ private void DocumentChanged(object sender, EventArgs e) {
+ wordpad.Changed = true;
+ }
+ #endregion // Event Handlers
+
+ }
+}
Added: trunk/winforms/wordpad/wordpad.csproj
===================================================================
--- trunk/winforms/wordpad/wordpad.csproj 2005-04-28 16:20:33 UTC (rev
43731)
+++ trunk/winforms/wordpad/wordpad.csproj 2005-04-28 16:39:03 UTC (rev
43732)
@@ -0,0 +1,100 @@
+<VisualStudioProject>
+ <CSHARP
+ ProjectType = "Local"
+ ProductVersion = "7.10.3077"
+ SchemaVersion = "2.0"
+ ProjectGuid = "{6BFBF47B-EB76-4BDF-99DB-D8E7CAD550F2}"
+ >
+ <Build>
+ <Settings
+ ApplicationIcon = ""
+ AssemblyKeyContainerName = ""
+ AssemblyName = "wordpad"
+ AssemblyOriginatorKeyFile = ""
+ DefaultClientScript = "JScript"
+ DefaultHTMLPageLayout = "Grid"
+ DefaultTargetSchema = "IE50"
+ DelaySign = "false"
+ OutputType = "Exe"
+ PreBuildEvent = ""
+ PostBuildEvent = ""
+ RootNamespace = "wordpad"
+ RunPostBuildEvent = "OnBuildSuccess"
+ StartupObject = ""
+ >
+ <Config
+ Name = "Debug"
+ AllowUnsafeBlocks = "false"
+ BaseAddress = "285212672"
+ CheckForOverflowUnderflow = "false"
+ ConfigurationOverrideFile = ""
+ DefineConstants = ""
+ DocumentationFile = ""
+ DebugSymbols = "true"
+ FileAlignment = "4096"
+ IncrementalBuild = "false"
+ NoStdLib = "false"
+ NoWarn = ""
+ Optimize = "false"
+ OutputPath = "bin\Debug\"
+ RegisterForComInterop = "false"
+ RemoveIntegerChecks = "false"
+ TreatWarningsAsErrors = "false"
+ WarningLevel = "1"
+ />
+ <Config
+ Name = "Release"
+ AllowUnsafeBlocks = "false"
+ BaseAddress = "285212672"
+ CheckForOverflowUnderflow = "false"
+ ConfigurationOverrideFile = ""
+ DefineConstants = ""
+ DocumentationFile = ""
+ DebugSymbols = "false"
+ FileAlignment = "4096"
+ IncrementalBuild = "false"
+ NoStdLib = "false"
+ NoWarn = ""
+ Optimize = "false"
+ OutputPath = "bin\Release\"
+ RegisterForComInterop = "false"
+ RemoveIntegerChecks = "false"
+ TreatWarningsAsErrors = "false"
+ WarningLevel = "1"
+ />
+ </Settings>
+ <References>
+ <Reference
+ Name = "System"
+ AssemblyName = "System"
+ HintPath =
"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll"
+ />
+ <Reference
+ Name = "System.Drawing"
+ AssemblyName = "System.Drawing"
+ HintPath =
"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Drawing.dll"
+ />
+ <Reference
+ Name = "System.Windows.Forms"
+ AssemblyName = "System.Windows.Forms"
+ HintPath =
"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Windows.Forms.dll"
+ />
+ </References>
+ </Build>
+ <Files>
+ <Include>
+ <File
+ RelPath = "support.cs"
+ SubType = "Component"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "wordpad.cs"
+ SubType = "Form"
+ BuildAction = "Compile"
+ />
+ </Include>
+ </Files>
+ </CSHARP>
+</VisualStudioProject>
+
Added: trunk/winforms/wordpad/wordpad.csproj.user
===================================================================
--- trunk/winforms/wordpad/wordpad.csproj.user 2005-04-28 16:20:33 UTC (rev
43731)
+++ trunk/winforms/wordpad/wordpad.csproj.user 2005-04-28 16:39:03 UTC (rev
43732)
@@ -0,0 +1,48 @@
+<VisualStudioProject>
+ <CSHARP LastOpenVersion = "7.10.3077" >
+ <Build>
+ <Settings ReferencePath = "" >
+ <Config
+ Name = "Debug"
+ EnableASPDebugging = "false"
+ EnableASPXDebugging = "false"
+ EnableUnmanagedDebugging = "false"
+ EnableSQLServerDebugging = "false"
+ RemoteDebugEnabled = "false"
+ RemoteDebugMachine = ""
+ StartAction = "Project"
+ StartArguments = ""
+ StartPage = ""
+ StartProgram = ""
+ StartURL = ""
+ StartWorkingDirectory = ""
+ StartWithIE = "true"
+ />
+ <Config
+ Name = "Release"
+ EnableASPDebugging = "false"
+ EnableASPXDebugging = "false"
+ EnableUnmanagedDebugging = "false"
+ EnableSQLServerDebugging = "false"
+ RemoteDebugEnabled = "false"
+ RemoteDebugMachine = ""
+ StartAction = "Project"
+ StartArguments = ""
+ StartPage = ""
+ StartProgram = ""
+ StartURL = ""
+ StartWorkingDirectory = ""
+ StartWithIE = "true"
+ />
+ </Settings>
+ </Build>
+ <OtherProjectSettings
+ CopyProjectDestinationFolder = ""
+ CopyProjectUncPath = ""
+ CopyProjectOption = "0"
+ ProjectView = "ProjectFiles"
+ ProjectTrust = "0"
+ />
+ </CSHARP>
+</VisualStudioProject>
+
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches