namespace CSharpToHTML
{
/// <summary>MainForm</summary>
public class MainForm : System.Windows.Forms.Form
{
#region デザイナ変数
private System.Windows.Forms.Button changeButton;
private System.Windows.Forms.Label bodyLabel;
private System.Windows.Forms.TextBox bodyTextBox;
private System.Windows.Forms.MainMenu mainMenu;
private System.Windows.Forms.MenuItem menuItemExit;
private System.Windows.Forms.ProgressBar changeProgressBar;
private System.Windows.Forms.Button bodyClearButton;
private System.Windows.Forms.MenuItem menuItemOpen;
private System.Windows.Forms.MenuItem menuItemFile;
private System.Windows.Forms.MenuItem menuItemOption;
private System.Windows.Forms.MenuItem menuItemFont;
private System.Windows.Forms.MenuItem menuItemHelp;
private System.Windows.Forms.MenuItem menuItemAbout;
private System.Windows.Forms.MenuItem menuItemHelpIndex;
private System.Windows.Forms.MenuItem menuItemEdit;
private System.Windows.Forms.MenuItem menuItemPaste;
private System.Windows.Forms.MenuItem menuItemClear;
private System.Windows.Forms.RadioButton csharpModeRadioButton;
private System.Windows.Forms.RadioButton cplusplusModeRadioButton;
private System.Windows.Forms.CheckBox autoChangeCheckBox;
private System.Windows.Forms.GroupBox changeModeGroupBox;
private System.Windows.Forms.MenuItem menuItemHtmlOption;
private System.Windows.Forms.MenuItem menuItemAutoChange;
private System.Windows.Forms.MenuItem menuItemCsharpMode;
private System.Windows.Forms.MenuItem menuItemCplusplusMode;
private System.Windows.Forms.MenuItem menuItemChange;
/// <summary>必要なデザイナ変数</summary>
private System.ComponentModel.Container components = null;
#endregion // デザイナ変数
#region Constructor
public MainForm(string fileName)
{
InitializeFirst();
// Windows フォーム デザイナ サポートに必要
InitializeComponent();
readFromRegistry();
InitializeOther();
if (fileName != null)
autoChangeFile(fileName);
}
#endregion // Constructor
#region Overrides
/// <summary>使用されているリソースに後処理を実行</summary>
protected override void Dispose(bool disposing)
{
writeToRegistry();
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#endregion // Overrides
#region Windows Form Designer generated code
/// <summary>
/// デザイナ サポートに必要なメソッド
/// </summary>
private void InitializeComponent()
{
this.changeButton = new System.Windows.Forms.Button();
this.bodyLabel = new System.Windows.Forms.Label();
this.bodyTextBox = new System.Windows.Forms.TextBox();
this.mainMenu = new System.Windows.Forms.MainMenu();
this.menuItemFile = new System.Windows.Forms.MenuItem();
this.menuItemOpen = new System.Windows.Forms.MenuItem();
this.menuItemChange = new System.Windows.Forms.MenuItem();
this.menuItemExit = new System.Windows.Forms.MenuItem();
this.menuItemEdit = new System.Windows.Forms.MenuItem();
this.menuItemPaste = new System.Windows.Forms.MenuItem();
this.menuItemClear = new System.Windows.Forms.MenuItem();
this.menuItemOption = new System.Windows.Forms.MenuItem();
this.menuItemHtmlOption = new System.Windows.Forms.MenuItem();
this.menuItemFont = new System.Windows.Forms.MenuItem();
this.menuItemAutoChange = new System.Windows.Forms.MenuItem();
this.menuItemCsharpMode = new System.Windows.Forms.MenuItem();
this.menuItemCplusplusMode = new System.Windows.Forms.MenuItem();
this.menuItemHelp = new System.Windows.Forms.MenuItem();
this.menuItemHelpIndex = new System.Windows.Forms.MenuItem();
this.menuItemAbout = new System.Windows.Forms.MenuItem();
this.cplusplusModeRadioButton = new System.Windows.Forms.RadioButton();
this.csharpModeRadioButton = new System.Windows.Forms.RadioButton();
this.changeProgressBar = new System.Windows.Forms.ProgressBar();
this.bodyClearButton = new System.Windows.Forms.Button();
this.autoChangeCheckBox = new System.Windows.Forms.CheckBox();
this.changeModeGroupBox = new System.Windows.Forms.GroupBox();
this.changeModeGroupBox.SuspendLayout();
this.SuspendLayout();
//
// changeButton
//
this.changeButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
this.changeButton.Location = new System.Drawing.Point(16, 400);
this.changeButton.Name = "changeButton";
this.changeButton.TabIndex = 4;
this.changeButton.Text = "変換";
this.changeButton.Click += new System.EventHandler(this.menuItemChange_Click);
//
// bodyLabel
//
this.bodyLabel.Location = new System.Drawing.Point(16, 16);
this.bodyLabel.Name = "bodyLabel";
this.bodyLabel.TabIndex = 1;
this.bodyLabel.Text = "C#/C++ ソース";
//
// bodyTextBox
//
this.bodyTextBox.AcceptsTab = true;
this.bodyTextBox.AllowDrop = true;
this.bodyTextBox.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.bodyTextBox.Font = new System.Drawing.Font("MS ゴシック", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128)));
this.bodyTextBox.Location = new System.Drawing.Point(16, 40);
this.bodyTextBox.MaxLength = 655350;
this.bodyTextBox.Multiline = true;
this.bodyTextBox.Name = "bodyTextBox";
this.bodyTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.bodyTextBox.Size = new System.Drawing.Size(400, 312);
this.bodyTextBox.TabIndex = 2;
this.bodyTextBox.Text = "";
this.bodyTextBox.DragDrop += new System.Windows.Forms.DragEventHandler(this.bodyTextBox_DragDrop);
this.bodyTextBox.DragEnter += new System.Windows.Forms.DragEventHandler(this.bodyTextBox_DragEnter);
//
// mainMenu
//
this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemFile,
this.menuItemEdit,
this.menuItemOption,
this.menuItemHelp});
//
// menuItemFile
//
this.menuItemFile.Index = 0;
this.menuItemFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemOpen,
this.menuItemChange,
this.menuItemExit});
this.menuItemFile.Text = "ファイル(&F)";
//
// menuItemOpen
//
this.menuItemOpen.Index = 0;
this.menuItemOpen.Shortcut = System.Windows.Forms.Shortcut.CtrlO;
this.menuItemOpen.Text = "ソース ファイル読み込み...(&F)";
this.menuItemOpen.Click += new System.EventHandler(this.menuItemOpen_Click);
//
// menuItemChange
//
this.menuItemChange.Index = 1;
this.menuItemChange.Text = "変換(&C)";
this.menuItemChange.Click += new System.EventHandler(this.menuItemChange_Click);
//
// menuItemExit
//
this.menuItemExit.Index = 2;
this.menuItemExit.Text = "終了(&X)";
this.menuItemExit.Click += new System.EventHandler(this.menuItemExit_Click);
//
// menuItemEdit
//
this.menuItemEdit.Index = 1;
this.menuItemEdit.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemPaste,
this.menuItemClear});
this.menuItemEdit.Shortcut = System.Windows.Forms.Shortcut.CtrlX;
this.menuItemEdit.Text = "編集(&E)";
//
// menuItemPaste
//
this.menuItemPaste.Index = 0;
this.menuItemPaste.Shortcut = System.Windows.Forms.Shortcut.CtrlV;
this.menuItemPaste.Text = "ソースの貼り付け(&P)";
this.menuItemPaste.Click += new System.EventHandler(this.menuItemPaste_Click);
//
// menuItemClear
//
this.menuItemClear.Index = 1;
this.menuItemClear.Shortcut = System.Windows.Forms.Shortcut.CtrlQ;
this.menuItemClear.Text = "ソースのクリア(&C)";
this.menuItemClear.Click += new System.EventHandler(this.menuItemClear_Click);
//
// menuItemOption
//
this.menuItemOption.Index = 2;
this.menuItemOption.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemHtmlOption,
this.menuItemFont,
this.menuItemAutoChange,
this.menuItemCsharpMode,
this.menuItemCplusplusMode});
this.menuItemOption.Text = "オプション(&O)";
//
// menuItemHtmlOption
//
this.menuItemHtmlOption.Index = 0;
this.menuItemHtmlOption.Text = "詳細設定...(&S)";
this.menuItemHtmlOption.Click += new System.EventHandler(this.menuItemHtmlOption_Click);
//
// menuItemFont
//
this.menuItemFont.Index = 1;
this.menuItemFont.Text = "フォント...(&F)";
this.menuItemFont.Click += new System.EventHandler(this.menuItemFont_Click);
//
// menuItemAutoChange
//
this.menuItemAutoChange.Index = 2;
this.menuItemAutoChange.Text = "自動変換(&A)";
this.menuItemAutoChange.Click += new System.EventHandler(this.menuItemAutoChange_Click);
//
// menuItemCsharpMode
//
this.menuItemCsharpMode.Index = 3;
this.menuItemCsharpMode.Text = "変換モード - C#(&C)";
this.menuItemCsharpMode.Click += new System.EventHandler(this.menuItemCsharpMode_Click);
//
// menuItemCplusplusMode
//
this.menuItemCplusplusMode.Index = 4;
this.menuItemCplusplusMode.Text = "変換モード - C++(&P)";
this.menuItemCplusplusMode.Click += new System.EventHandler(this.menuItemCplusplusMode_Click);
//
// menuItemHelp
//
this.menuItemHelp.Index = 3;
this.menuItemHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemHelpIndex,
this.menuItemAbout});
this.menuItemHelp.Text = "ヘルプ(&H)";
//
// menuItemHelpIndex
//
this.menuItemHelpIndex.Index = 0;
this.menuItemHelpIndex.Text = "ヘルプ...(&H)";
this.menuItemHelpIndex.Click += new System.EventHandler(this.menuItemHelpIndex_Click);
//
// menuItemAbout
//
this.menuItemAbout.Index = 1;
this.menuItemAbout.Text = "バージョン情報...(&A)";
this.menuItemAbout.Click += new System.EventHandler(this.menuItemAbout_Click);
//
// cplusplusModeRadioButton
//
this.cplusplusModeRadioButton.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
this.cplusplusModeRadioButton.Location = new System.Drawing.Point(248, 16);
this.cplusplusModeRadioButton.Name = "cplusplusModeRadioButton";
this.cplusplusModeRadioButton.TabIndex = 9;
this.cplusplusModeRadioButton.Text = "C++ モード";
this.cplusplusModeRadioButton.CheckedChanged += new System.EventHandler(this.cplusplusModeRadioButton_Click);
//
// csharpModeRadioButton
//
this.csharpModeRadioButton.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
this.csharpModeRadioButton.Location = new System.Drawing.Point(40, 16);
this.csharpModeRadioButton.Name = "csharpModeRadioButton";
this.csharpModeRadioButton.TabIndex = 8;
this.csharpModeRadioButton.TabStop = true;
this.csharpModeRadioButton.Text = "C# モード";
this.csharpModeRadioButton.CheckedChanged += new System.EventHandler(this.csharpModeRadioButton_Click);
//
// changeProgressBar
//
this.changeProgressBar.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.changeProgressBar.Enabled = false;
this.changeProgressBar.Location = new System.Drawing.Point(200, 400);
this.changeProgressBar.Name = "changeProgressBar";
this.changeProgressBar.Size = new System.Drawing.Size(216, 23);
this.changeProgressBar.Step = 1;
this.changeProgressBar.TabIndex = 6;
this.changeProgressBar.Visible = false;
//
// bodyClearButton
//
this.bodyClearButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
this.bodyClearButton.Location = new System.Drawing.Point(344, 352);
this.bodyClearButton.Name = "bodyClearButton";
this.bodyClearButton.TabIndex = 3;
this.bodyClearButton.Text = "クリア";
this.bodyClearButton.Click += new System.EventHandler(this.menuItemClear_Click);
//
// autoChangeCheckBox
//
this.autoChangeCheckBox.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
this.autoChangeCheckBox.Location = new System.Drawing.Point(104, 400);
this.autoChangeCheckBox.Name = "autoChangeCheckBox";
this.autoChangeCheckBox.Size = new System.Drawing.Size(80, 24);
this.autoChangeCheckBox.TabIndex = 5;
this.autoChangeCheckBox.Text = "自動変換";
this.autoChangeCheckBox.CheckedChanged += new System.EventHandler(this.autoChangeCheckBox_Click);
//
// changeModeGroupBox
//
this.changeModeGroupBox.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
this.changeModeGroupBox.Controls.AddRange(new System.Windows.Forms.Control[] {
this.csharpModeRadioButton,
this.cplusplusModeRadioButton});
this.changeModeGroupBox.Location = new System.Drawing.Point(16, 432);
this.changeModeGroupBox.Name = "changeModeGroupBox";
this.changeModeGroupBox.Size = new System.Drawing.Size(400, 56);
this.changeModeGroupBox.TabIndex = 7;
this.changeModeGroupBox.TabStop = false;
this.changeModeGroupBox.Text = "変換モード";
//
// MainForm
//
this.AllowDrop = true;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(424, 497);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.changeModeGroupBox,
this.autoChangeCheckBox,
this.bodyClearButton,
this.changeProgressBar,
this.changeButton,
this.bodyLabel,
this.bodyTextBox});
this.Menu = this.mainMenu;
this.MinimumSize = new System.Drawing.Size(432, 288);
this.Name = "MainForm";
this.Text = "CSharpToHTML";
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.bodyTextBox_DragDrop);
this.DragEnter += new System.Windows.Forms.DragEventHandler(this.bodyTextBox_DragEnter);
this.changeModeGroupBox.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion // Windows Form Designer generated code
#region Main
/// <summary>アプリケーションのメイン エントリ ポイント</summary>
[System.STAThread]
static void Main(string[] args)
{
MainForm mainForm = null;
try
{
mainForm = new MainForm((args.Length > 0) ? args[0] : null);
}
catch (System.Exception error)
{
System.Windows.Forms.MessageBox.Show(error.ToString(), "エラー",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Error);
}
if (mainForm != null)
System.Windows.Forms.Application.Run(mainForm);
}
#endregion // Main
#region Privates
private const string helpFileName = @".\CSharpToHTMLHelp.html";
private const string outputFileName = @".\@__temp__@.html";
private bool AutoChangeMode
{
get { return autoChangeCheckBox.Checked; }
set
{
autoChangeCheckBox.Checked = value;
menuItemAutoChange.Checked = value;
}
}
private System.Drawing.Font font
{
get
{
return bodyTextBox.Font;
}
set
{
bodyTextBox.Font = value;
}
}
private void InitializeFirst()
{
CtoHTML.CtoHTML.Keyword.initialize();
readFromRegistry();
}
private void InitializeOther()
{
modeFromProperty();
CtoHTML.CtoHTML.OnProgressMin += new CtoHTML.CtoHTML.ProgressMin (ProgressMin );
CtoHTML.CtoHTML.OnProgressMax += new CtoHTML.CtoHTML.ProgressMax (ProgressMax );
CtoHTML.CtoHTML.OnProgressStep += new CtoHTML.CtoHTML.ProgressStep(ProgressStep);
}
private const string autoChangeModeKeyName = "Auto Change Mode";
private void textRead(System.IO.Stream stream)
{
if (stream != null)
{
System.Text.Encoding encoding = CtoHTML.CtoHTML.indexToEncoding(0);
System.IO.TextReader reader = new System.IO.StreamReader(stream, encoding);
bodyTextBox.Text = reader.ReadToEnd();
reader.Close();
}
}
private void textRead(string fileName)
{
try
{
System.IO.FileStream inputFileStream = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
if (inputFileStream != null)
textRead(inputFileStream);
}
catch (System.Exception error)
{
System.Diagnostics.Trace.WriteLine(error.ToString());
throw error;
}
}
private void modeFromProperty()
{
switch (CtoHTML.CtoHTML.Mode)
{
case CtoHTML.CtoHTML.ModeKind.CSharp :
menuItemCsharpMode.Checked = true ;
menuItemCplusplusMode.Checked = false;
csharpModeRadioButton.Checked = true ;
cplusplusModeRadioButton.Checked = false;
break;
case CtoHTML.CtoHTML.ModeKind.CPlusPlus:
menuItemCsharpMode.Checked = false;
menuItemCplusplusMode.Checked = true ;
csharpModeRadioButton.Checked = false;
cplusplusModeRadioButton.Checked = true ;
break;
default :
menuItemCsharpMode.Checked = true ;
menuItemCplusplusMode.Checked = false;
csharpModeRadioButton.Checked = true ;
cplusplusModeRadioButton.Checked = false;
break;
}
}
private void readFromRegistry()
{
try
{
Microsoft.Win32.RegistryKey applicationKey = Registry.getApplicationKey();
font = Registry.readFont (applicationKey);
AutoChangeMode = Registry.readBoolean(applicationKey, autoChangeModeKeyName);
CtoHTML.CtoHTML.read(applicationKey);
}
catch (System.Exception error)
{
System.Diagnostics.Trace.WriteLine("レジストリの情報が無効でした.デフォルト値を使用します.");
System.Diagnostics.Trace.WriteLine(error.ToString());
}
}
private void writeToRegistry()
{
try
{
Microsoft.Win32.RegistryKey applicationKey = Registry.getApplicationKey();
Registry.writeFont (applicationKey, font);
Registry.writeBoolean(applicationKey, autoChangeModeKeyName, AutoChangeMode);
CtoHTML.CtoHTML.write(applicationKey);
}
catch (System.Exception error)
{
System.Diagnostics.Trace.WriteLine("レジストリへの書き込みに失敗しました.");
System.Diagnostics.Trace.WriteLine(error.ToString());
}
}
private void ProgressMin(int n)
{
changeProgressBar.Minimum = n;
changeProgressBar.Step = 1;
changeProgressBar.Value = 1;
}
private void ProgressMax(int n)
{
changeProgressBar.Maximum = n;
}
private void ProgressStep()
{
changeProgressBar.PerformStep();
}
private static bool isCSharpFile(string fileName)
{
fileName = fileName.TrimEnd(new char[] {' '});
string[] texts = fileName.Split (new char[] {'.'});
if (texts.Length > 0)
{
return (texts[texts.Length - 1].ToLower().CompareTo("cs") == 0);
}
return false;
}
private static bool isCPlusPlusFile(string fileName)
{
fileName = fileName.TrimEnd(new char[] {' '});
string[] texts = fileName.Split (new char[] {'.'});
if (texts.Length > 0)
{
string ext = texts[texts.Length - 1].ToLower();
return (ext.CompareTo("cpp") == 0 || ext.CompareTo("h") == 0 || ext.CompareTo("hpp") == 0);
}
return false;
}
private void changeMode(string fileName)
{
if (isCSharpFile (fileName))
{
CtoHTML.CtoHTML.Mode = CtoHTML.CtoHTML.ModeKind.CSharp ;
modeFromProperty();
}
else if (isCPlusPlusFile(fileName))
{
CtoHTML.CtoHTML.Mode = CtoHTML.CtoHTML.ModeKind.CPlusPlus;
modeFromProperty();
}
}
private void change()
{
modeFromProperty();
changeProgressBar.Show();
try
{
CtoHTML.CtoHTML.filter(bodyTextBox.Text, outputFileName);
}
catch (System.Exception error)
{
System.Windows.Forms.MessageBox.Show(error.ToString(), "エラー",