using System;
using System .Collections .Generic;
using System .ComponentModel;
using System .Drawing;
using System .IO;
using System .Windows .Forms;
using Microsoft .Win32;
using MoveGraphLibrary;
namespace UserDrivenApplications
{
public enum NumberType { INT, DOUBLE };
public enum SetType { Numbers, Strings, ABArrays };
public partial class Form_DataWorld : Form
{
const string strAddRegKey = "Form_DataWorld";
Mover mover;
int iWasCaughtObject, iWasCaughtNode;
NodeShape shapeWasCaught;
Point ptMouse_Down, ptMouse_Up;
ElasticGroup groupPages, groupSets, groupNumbers, groupStrings;
ElasticGroup groupPressed;
Scale scalePressed;
List<Data_Page> pages = new List<Data_Page> ();
string strDataFile;
const string strFilterBIN = "Binary files(*.bin)|*.bin|All files(*.*)|*.*";
bool bDefaultViewNextOpening = false;
bool bRestore = false;
Control [] ctrlsGroupPages, ctrlsGroupSets, ctrlsGroupNumbers, ctrlsGroupStrings;
Control [] ctrlsListArrays, ctrlsEditABArray;
ElasticGroup groupListArrays;
GroupEditABArray groupEditXYArray;
GroupABArrays groupXYArrays;
// -------------------------------------------------
public Form_DataWorld ()
{
InitializeComponent ();
mover = new Mover (this);
}
// ------------------------------------------------- OnLoad
private void OnLoad (object sender, EventArgs e)
{
domainSetType .SelectedIndex = 0;
domainUD_NumType .SelectedIndex = 0;
DataFileName ();
ctrlsGroupPages = new Control [] { listPages, textNewPageName, btnDeletePage, btnShowHidePage };
ctrlsGroupSets = new Control [] { listSets, btnDeleteSet, btnShowHideSet, textNewSetName, domainSetType };
ctrlsGroupNumbers = new Control [] {textNum_Value, textNum_MinValue, textNum_MaxValue, domainUD_NumType,
textNum_Name, textNum_Comment, btnAddNumber, btnChangeNumber,
listNumbers, btnDeleteNumber, btnShowHideNumber, btnNumberUp, btnNumberDown };
ctrlsGroupStrings = new Control [] {textString_Name, textString_Value, textString_Comment, btnAddString, btnChangeString,
listStrings, btnDeleteString, btnShowHideString, btnStringUp, btnStringDown };
ctrlsListArrays = new Control [] { listABArrays, btnDeleteABArray, btnShowHideABArray, btnABArrayUp, btnABArrayDown,
textNewABArrayName, };
ctrlsEditABArray = new Control [] { textABArray_Xrange, textABArray_Yrange, textABArray_Comment, btnArrayFromFile, datagridXY };
RestoreFromRegistry ();
if (!bRestore)
{
groupPages = new ElasticGroup (this, new ElasticGroupElement [] {
new ElasticGroupElement (listPages),
new ElasticGroupElement (new CommentedControl (this, textNewPageName, Resizing .WE,
Side .E, "New page")),
new ElasticGroupElement (btnDeletePage),
new ElasticGroupElement (btnShowHidePage) },
"Pages");
groupSets = new ElasticGroup (this, new ElasticGroupElement [] {new ElasticGroupElement (listSets),
new ElasticGroupElement (btnDeleteSet),
new ElasticGroupElement (btnShowHideSet),
new ElasticGroupElement (new CommentedControl (this, textNewSetName, Resizing .WE,
Side .W, "New set")),
new ElasticGroupElement (domainSetType) },
"Single page");
// groupNumbers: groupNewNumber - groupViewNumbers
// groupNewNumber: textNum_Value - textNum_MinValue - textNum_MaxValue - domainUD_NumType - textNum_Name -
// textNum_Comment - btnAddNumber - btnChangeNumber
// groupViewNumbers: listNumbers - btnDeleteNumber - btnShowHideNumber - btnNumberUp - btnNumberDown
ElasticGroup groupNewNumber = new ElasticGroup (this, new ElasticGroupElement [] {
new ElasticGroupElement (new CommentedControl (this, textNum_Value, Resizing .WE, Side .N, SideAlignment .Left, "Value")),
new ElasticGroupElement (new CommentedControl (this, textNum_MinValue, Resizing .WE, Side .N, SideAlignment .Left, "Min")),
new ElasticGroupElement (new CommentedControl (this, textNum_MaxValue, Resizing .WE, Side .N, SideAlignment .Left, "Max")),
new ElasticGroupElement (new FramedControl (domainUD_NumType, Resizing.WE)),
new ElasticGroupElement (new CommentedControl (this, textNum_Name, Resizing .WE, Side .E, "Name")),
new ElasticGroupElement (new CommentedControl (this, textNum_Comment, Resizing .WE, Side .E, "Comment")),
new ElasticGroupElement (btnAddNumber),
new ElasticGroupElement (btnChangeNumber) });
ElasticGroup groupViewNumbers = new ElasticGroup (this, new Control [] {listNumbers, btnDeleteNumber,
btnShowHideNumber, btnNumberUp, btnNumberDown });
groupNumbers = new ElasticGroup (this, new ElasticGroupElement [] { new ElasticGroupElement (groupNewNumber),
new ElasticGroupElement (groupViewNumbers) },
"Numbers");
// groupStrings: groupNewString - groupViewStrings
// groupNewString: textString_Name - textString_Value - textString_Comment - btnAddString - btnChangeString
// groupViewStrings: listStrings - btnDeleteString - btnShowHideString - btnStringUp - btnStringDown
ElasticGroup groupNewString = new ElasticGroup (this, new ElasticGroupElement [] {
new ElasticGroupElement (new CommentedControl (this, textString_Name, Resizing .WE, Side .W, "Name")),
new ElasticGroupElement (new CommentedControl (this, textString_Value, Resizing .WE, Side .W, "Value")),
new ElasticGroupElement (new CommentedControl (this, textString_Comment, Resizing .WE, Side .W, "Comment")),
new ElasticGroupElement (btnAddString),
new ElasticGroupElement (btnChangeString)
});
ElasticGroup groupViewStrings = new ElasticGroup (this, new Control [] {listStrings, btnDeleteString, btnShowHideString,
btnStringUp, btnStringDown});
groupStrings = new ElasticGroup (this, new ElasticGroupElement [] { new ElasticGroupElement (groupNewString),
new ElasticGroupElement (groupViewStrings) },
"Strings");
// groupArrays: groupListArrays - groupNewArray
// groupListArrays: listArrays - btnDeleteArray - btnShowHideArray - btnArrayUp - btnArrayDown - textNewABArrayName
// groupNewArray: textArray_Xrange - textArray_Yrange - textArray_Comment -
// btnAddArray - btnChangeArray - datagridXY - btnArrayFromFile
groupListArrays = new ElasticGroup (this, new ElasticGroupElement [] { new ElasticGroupElement (listABArrays),
new ElasticGroupElement (btnDeleteABArray),
new ElasticGroupElement (btnShowHideABArray),
new ElasticGroupElement (btnABArrayUp),
new ElasticGroupElement (btnABArrayDown),
new ElasticGroupElement (new CommentedControl (this, textNewABArrayName, Resizing .WE, Side .W, "New array")) });
groupEditXYArray = new GroupEditABArray (this, ctrlsEditABArray);
groupXYArrays = new GroupABArrays (this, groupListArrays, groupEditXYArray, "Arrays");
}
RenewMover ();
ReadData ();
FillPagesList ();
if (pages .Count > 0)
{
listPages .Items [0] .Selected = true;
if (listSets .Items .Count > 0)
{
listSets .Items [0] .Selected = true;
}
else
{
GroupsClearDisable ();
}
}
else
{
EnableGroup_Sets (false);
GroupsClearDisable ();
}
}
// ------------------------------------------------- GroupsClearDisable
private void GroupsClearDisable ()
{
EnableGroup_Numbers (false);
EnableGroup_Strings (false);
EnableGroup_Arrays (false);
}
// ------------------------------------------------- OnFormClosing
private void OnFormClosing (object sender, FormClosingEventArgs e)
{
SaveData ();
if (bDefaultViewNextOpening &&
DialogResult .Yes == MessageBox .Show ("Do you really want to delete the view's settings and see the default view next time?",
"Closing",
MessageBoxButtons .YesNo, MessageBoxIcon .Question, MessageBoxDefaultButton .Button1))
{
DeleteRegistryEntry ();
}
else
{
SaveInfoToRegistry ();
}
}
// ------------------------------------------------- DataFileName
private void DataFileName ()
{
string pathExecutable = Application .ExecutablePath;
if (Path .HasExtension (pathExecutable))
{
string strExtension = Path .GetExtension (pathExecutable);
int iExtension = pathExecutable .LastIndexOf (strExtension);
strDataFile = pathExecutable .Substring (0, iExtension) + ".bin";
}
else
{
strDataFile = pathExecutable + ".bin";
}
}
// ------------------------------------------------- RenewMover
// order of groups: groupPages - groupSets - groupNumbers - groupStrings - groupArrays
void RenewMover ()
{
mover .Clear ();
groupXYArrays .IntoMover (mover, 0);
groupStrings .IntoMover (mover, 0);
groupNumbers .IntoMover (mover, 0);
groupSets .IntoMover (mover, 0);
groupPages .IntoMover (mover, 0);
}
// ------------------------------------------------- OnPaint
private void OnPaint (object sender, PaintEventArgs e)
{
Graphics grfx = e .Graphics;
groupXYArrays .Draw (grfx);
groupStrings .Draw (grfx);
groupNumbers .Draw (grfx);
groupSets .Draw (grfx);
groupPages .Draw (grfx);
}
// ------------------------------------------------- OnMouseDown
private void OnMouseDown (object sender, MouseEventArgs e)
{
ptMouse_Down = e .Location;
if (mover .Catch (e .Location, e .Button))
{
if (e .Button == MouseButtons .Left)
{
if (mover .CaughtSource is DotsOnPlot)
{
if (mover .CaughtNodeShape == NodeShape .Strip)
{
int iStrip = mover .CaughtNode - (4 + groupXYArrays .Dots .DotNumber);
PointF ptBase;
double fDist = Auxi_Geometry .DistanceToLine (e .Location, groupXYArrays .Dots .Points [iStrip],
groupXYArrays .Dots .Points [iStrip + 1], out ptBase);
mover .Release ();
int iDot = iStrip + 1;
groupXYArrays .Dots .InsertNewDot (iDot, Point .Round (ptBase));
ABArray_InsertTableLine (iDot);
NewPairIntoABArray (iDot, new Data_ABPair (groupXYArrays .Dots .Args [iDot],
groupXYArrays .Dots .Vals [iDot]));
Invalidate ();
mover .Catch (e .Location, e .Button);
}
if (mover .CaughtNodeShape == NodeShape .Circle)
{
int iDot = mover .CaughtNode - 4;
ABArray_RenewTableLine (iDot);
}
}
}
}
ContextMenuStrip = null;
}
// ------------------------------------------------- OnMouseUp
private void OnMouseUp (object sender, MouseEventArgs e)
{
ptMouse_Up = e .Location;
double nDist = Auxi_Geometry .Distance (ptMouse_Down, ptMouse_Up);
if (e .Button == MouseButtons .Left)
{
if (mover .Release (out iWasCaughtObject, out iWasCaughtNode, out shapeWasCaught))
{
GraphicalObject grobj = mover [iWasCaughtObject] .Source;
if (grobj is DotNest)
{
groupXYArrays .DotNest .DotReturnHome ();
if (groupXYArrays .MSPlot .MainArea .Area .Contains (e .Location) && shapeWasCaught == NodeShape .Circle &&
!groupXYArrays .DotNest .RectAround .Contains (e .Location))
{
int iDot = groupXYArrays .Dots .InsertNewDotInXOrder (e .Location); // new dot in DotsOnPlot
ABArray_InsertTableLine (iDot); // new row in datagridXY
NewPairIntoABArray (iDot, new Data_ABPair (groupXYArrays .Dots .Args [iDot], // new pair into data array
groupXYArrays .Dots .Vals [iDot]));
}
Invalidate ();
}
else if (grobj is DotsOnPlot)
{
if (shapeWasCaught == NodeShape .Circle)
{
int iDot = iWasCaughtNode - 4;
UpdatePairInABArray (iDot, new Data_ABPair (groupXYArrays .Dots .Args [iDot], // update pair in data array
groupXYArrays .Dots .Vals [iDot]));
}
}
else if ((grobj is RectCorners || grobj is MSPlot || grobj is Scale) &&
PageAndSetSelected && SelectedSet .SetType == SetType .ABArrays)
{
SavePlotView ();
}
}
}
else if (e .Button == MouseButtons .Right)
{
if (mover .Release (out iWasCaughtObject, out iWasCaughtNode, out shapeWasCaught))
{
if (nDist <= 3)
{
MenuSelection (iWasCaughtObject, shapeWasCaught);
}
}
else
{
if (nDist <= 3)
{
ContextMenuStrip = menuOnEmpty;
}
}
}
}
// ------------------------------------------------- NewPairIntoABArray
private void NewPairIntoABArray (int iDot, Data_ABPair pairNew)
{
if (listABArrays .Items .Count > 0 && listABArrays .SelectedIndices .Count > 0)
{
Data_Set set = SelectedSet;
Data_ABArray array = set .ABArrays [listABArrays .SelectedIndices [0]];
if (0 <= iDot && iDot <= array .Pairs .Count)
{
array .Pairs .Insert (iDot, pairNew);
}
}
}
// ------------------------------------------------- UpdatePairInABArray
private void UpdatePairInABArray (int iDot, Data_ABPair pairChange)
{
if (listABArrays .Items .Count > 0 && listABArrays .SelectedIndices .Count > 0)
{
Data_Set set = SelectedSet;
Data_ABArray array = set .ABArrays [listABArrays .SelectedIndices [0]];
if (0 <= iDot && iDot < array .Pairs .Count)
{
array .Pairs .RemoveAt (iDot);
array .Pairs .Insert (iDot, pairChange);
}
}
}
// ------------------------------------------------- RemovePairFromABArray
private void RemovePairFromABArray (int iDot)
{
if (listABArrays .Items .Count > 0 && listABArrays .SelectedIndices .Count > 0)
{
Data_Set set = SelectedSet;
Data_ABArray array = set .ABArrays [listABArrays .SelectedIndices [0]];
if (0 <= iDot && iDot < array .Pairs .Count)
{
array .Pairs .RemoveAt (iDot);
}
}
}
// ------------------------------------------------- MenuSelection
private void MenuSelection (int iInMover, NodeShape nodeshape)
{
GraphicalObject grobj = mover [iInMover] .Source;
if (grobj is ElasticGroup)
{
groupPressed = grobj as ElasticGroup;
ContextMenuStrip = menuOnGroup;
}
else if (grobj is GroupABArrays)
{
ContextMenuStrip = menuOnGroupArrays;
}
else if (grobj is DotsOnPlot && nodeshape == NodeShape .Circle)
{
ContextMenuStrip = menuOnDot;
}
else if (grobj is Scale)
{
scalePressed = grobj as Scale;
ContextMenuStrip = menuOnScale;
}
}
// ------------------------------------------------- OnMouseMove
private void OnMouseMove (object sender, MouseEventArgs e)
{
if (mover .Move (e .Location))
{
UpdateGroups ();
GraphicalObject grobj = mover .CaughtSource;
if (grobj is MSPlot || grobj is RectCorners)
{
groupXYArrays .Dots .PlotChanged ();
}
else if (grobj is DotsOnPlot && mover .CaughtNodeShape == NodeShape .Circle)
{
int iDot = mover .CaughtNode - 4;
ABArray_RenewTableLine (iDot);
}
if (grobj is ElasticGroup ||
grobj is FramedControl ||
grobj is CommentedControl ||
grobj is GroupEditABArray ||
grobj is GroupABArrays)
{
Update ();
}
Invalidate ();
}
}
// ------------------------------------------------- UpdateGroups
private void UpdateGroups ()
{
groupPages .Update ();
groupSets .Update ();
groupNumbers .Update ();
groupStrings .Update ();
groupListArrays .Update ();
groupXYArrays .Update ();
groupXYArrays .Update ();
}
// ------------------------------------------------- OnContextMenuChanged
private void OnContextMenuChanged (object sender, EventArgs e)
{
if (ContextMenuStrip != null)
{
ContextMenuStrip .Show (PointToScreen (ptMouse_Up));
}
}
// ------------------------------------------------- OnMouseDoubleClick
private void OnMouseDoubleClick (object sender, MouseEventArgs mea)
{
if (mover .Catch (mea .Location, MouseButtons .Left))
{
GraphicalObject grobj = mover [mover .CaughtObject] .Source;
if (grobj is Scale)
{
(grobj as Scale) .ParametersDialog (this, RenewMover, ScaleParametersChanged);
}
}
}
// ------------------------------------------------- ScaleParametersChanged
private void ScaleParametersChanged (object sender, EventArgs ea)
{
Invalidate ();
SavePlotView ();
}
// ------------------------------------------------- SavePlotView
private void SavePlotView ()
{
Data_ABArray data = SelectedABArray;
data .MSPlot .CopyView (groupEditXYArray .MSPlot);
}
// ***** menuOnGroup *****
// ------------------------------------------------- Opening_menuOnGroup
private void Opening_menuOnGroup (object sender, CancelEventArgs e)
{
ToolStripItemCollection items = menuOnGroup .Items;
if (groupPressed .ID == groupNumbers .ID || groupPressed .ID == groupStrings .ID)
{
items ["miHideGroup"] .Enabled = true;
}
else
{
items ["miHideGroup"] .Enabled = false;
}
items ["miFixUnfixElements"] .Text = groupPressed .ElementsMovable ? "Fix group's elements" : "Unfix group's elements";
}
// ------------------------------------------------- Click_miHideGroup
private void Click_miHideGroup (object sender, EventArgs e)
{
groupPressed .Visible = false;
RenewMover ();
Invalidate ();
}
// ------------------------------------------------- Click_miModifyGroup
private void Click_miModifyGroup (object sender, EventArgs e)
{
groupPressed .ParametersDialog (this, PointToScreen (ptMouse_Up), GroupParametersChanged);
}
// ------------------------------------------------- GroupParametersChanged
private void GroupParametersChanged (object sender, EventArgs ea)
{
UpdateGroups ();
Invalidate ();
}
// ------------------------------------------------- Click_miFixUnfixElements
private void Click_miFixUnfixElements (object sender, EventArgs e)
{
groupPressed .ElementsMovable = !groupPressed .ElementsMovable;
RenewMover ();
}
// ------------------------------------------------- Click_miGroupDefaultView
private void Click_miGroupDefaultView (object sender, EventArgs e)
{
groupPressed .DefaultView ();
UpdateGroups ();
RenewMover ();
Invalidate ();
}
// ***** menuOnGroupArrays *****
// ------------------------------------------------- Opening_menuOnGroupArrays
private void Opening_menuOnGroupArrays (object sender, CancelEventArgs e)
{
ToolStripItemCollection items = menuOnGroupArrays .Items;
((ToolStripMenuItem) items ["miShowGroupArraysFrame"]) .Checked = groupXYArrays .ShowFrame;
items ["miGroupArraysFrameColor"] .Enabled = groupXYArrays .ShowFrame;
}
// ------------------------------------------------- Click_miHideGroupArrays
private void Click_miHideGroupArrays (object sender, EventArgs e)
{
groupXYArrays .Visible = false;
RenewMover ();
Invalidate ();
}
// ------------------------------------------------- Click_miGroupArraysFont
private void Click_miGroupArraysFont (object sender, EventArgs e)
{
FontDialog dlg = new FontDialog ();
dlg .Font = groupXYArrays .TitleFont;
if (dlg .ShowDialog () == DialogResult .OK)
{
groupXYArrays .Font = dlg .Font;
groupXYArrays .Update ();
Invalidate ();
}
}
// ------------------------------------------------- Click_miGroupArraysBackColor
private void Click_miGroupArraysBackColor (object sender, EventArgs e)
{
ColorDialog dlg = new ColorDialog ();
dlg .Color = groupXYArrays .BackColor;
if (dlg .ShowDialog () == DialogResult .OK)
{
groupXYArrays .BackColor = dlg .Color;
Invalidate ();
}
}
// ------------------------------------------------- Click_miGroupArraysBackColorSpreadInside
private void Click_miGroupArraysBackColorSpreadInside (object sender, EventArgs e)
{
ColorDialog dlg = new ColorDialog ();
dlg .Color = groupXYArrays .BackColor;
if (dlg .ShowDialog () == DialogResult .OK)
{
groupXYArrays .BackColorSpreadInside = true;
groupXYArrays .BackColor = dlg .Color;
Invalidate ();
}
}
// ------------------------------------------------- DropDownOpening_miGroupArraysTransparency
private void DropDownOpening_miGroupArraysTransparency (object sender, EventArgs e)
{
int A = groupXYArrays .BackColor .A;
ToolStripMenuItem itemParent = (ToolStripMenuItem) sender;
ToolStripItemCollection items = itemParent .DropDownItems;
for (int i = 0; i < items .Count; i++)
{
((ToolStripMenuItem) items [i]) .Checked = A == Convert .ToInt32 (255 * (1 - Convert .ToSingle (items [i] .Text)));
}
}
// ------------------------------------------------- Click_miGroupArraysTransparency
private void Click_miGroupArraysTransparency (object sender, EventArgs e)
{
Color clrBack = groupXYArrays .BackColor;
Color clrNew = Color .FromArgb (Convert .ToInt32 (255 * (1 - Convert .ToSingle ((sender as ToolStripMenuItem) .Text))),
clrBack .R, clrBack .G, clrBack .B);
groupXYArrays .BackColor = clrNew;
Invalidate ();
}
// ------------------------------------------------- Click_miShowGroupArraysFrame
private void Click_miShowGroupArraysFrame (object sender, EventArgs e)
{
groupXYArrays .ShowFrame = !groupXYArrays .ShowFrame;
Invalidate ();
}
// ------------------------------------------------- Click_miGroupArraysFrameColor
private void Click_miGroupArraysFrameColor (object sender, EventArgs e)
{
ColorDialog dlg = new ColorDialog ();
dlg .Color = groupXYArrays .FrameColor;
if (dlg .ShowDialog () == DialogResult .OK)
{
groupXYArrays .FrameColor = dlg .Color;
Invalidate ();
}
}
// ------------------------------------------------- Click_miGroupArraysTitleFont
private void Click_miGroupArraysTitleFont (object sender, EventArgs e)
{
FontDialog dlg = new FontDialog ();
dlg .Font = groupXYArrays .TitleFont;
if (dlg .ShowDialog () == DialogResult .OK)
{
groupXYArrays .TitleFont = dlg .Font;
groupXYArrays .Update ();
Invalidate ();
}
}
// ***** menuOnDot *****
// ------------------------------------------------- Click_miDeleteDot
private void Click_miDeleteDot (object sender, EventArgs e)
{
int iDot = iWasCaughtNode - 4;
groupXYArrays .Dots .RemoveDot (iDot);
RemovePairFromABArray (iDot);
Data_Set set = SelectedSet;
Data_ABArray data = set .ABArrays [listABArrays .SelectedIndices [0]];
ABArray_IntoTable (data);
RenewMover ();
Invalidate ();
}
// ------------------------------------------------- Click_miDotsParams
private void Click_miDotsParams (object sender, EventArgs e)
{
Form_MarkedLineParameters form = new Form_MarkedLineParameters (groupEditXYArray .Line, PointToScreen (ptMouse_Up));
if (DialogResult .OK == form .ShowDialog ())
{
groupEditXYArray .Line = form .Line;
Invalidate ();
}
}
// ***** menuOnScale *****
// ------------------------------------------------- Click_miModifyScale
private void Click_miModifyScale (object sender, EventArgs e)
{
scalePressed .ParametersDialog (this, RenewMover, ScaleParametersChanged);
}
// ***** menuOnEmpty *****
// ------------------------------------------------- Opening_menuOnEmpty
private void Opening_menuOnEmpty (object sender, CancelEventArgs e)
{
ToolStripItemCollection items = menuOnEmpty .Items;
((ToolStripMenuItem) items ["miShowGroupNumbers"]) .Checked = groupNumbers .Visible;
((ToolStripMenuItem) items ["miShowGroupStrings"]) .Checked = groupStrings .Visible;
((ToolStripMenuItem) items ["miShowGroupArrays"]) .Checked = groupXYArrays .Visible;
((ToolStripMenuItem) items ["miDefaultViewNextTime"]) .Checked = bDefaultViewNextOpening;
}
// ------------------------------------------------- Click_miShowGroupNumbers
private void Click_miShowGroupNumbers (object sender, EventArgs e)
{
groupNumbers .Visible = !groupNumbers .Visible;
RenewMover ();
Invalidate ();
}
// ------------------------------------------------- Click_miShowGroupStrings
private void Click_miShowGroupStrings (object sender, EventArgs e)
{
groupStrings .Visible = !groupStrings .Visible;
RenewMover ();
Invalidate ();
}
// ------------------------------------------------- Click_miShowGroupArrays
private void Click_miShowGroupArrays (object sender, EventArgs e)
{
groupXYArrays .Visible = !groupXYArrays .Visible;
if (groupXYArrays .Visible)
{
if (listABArrays .Items .Count <= 0 || listABArrays .SelectedIndices .Count <= 0)
{
groupEditXYArray .DotNest .Visible = false;
}
}
RenewMover ();
Invalidate ();
}
// ------------------------------------------------- Click_miGeneralFont
private void Click_miGeneralFont (object sender, EventArgs e)
{
FontDialog dlg = new FontDialog ();
dlg .Font = Font;
if (dlg .ShowDialog () == DialogResult .OK)
{
groupPages .Font = dlg .Font;
groupSets .Font = dlg .Font;
groupNumbers .Font = dlg .Font;
groupStrings .Font = dlg .Font;
UpdateGroups ();
Invalidate ();
}
}
// ------------------------------------------------- Click_miDefaultViewNextOpening
private void Click_miDefaultViewNextOpening (object sender, EventArgs e)
{
bDefaultViewNextOpening = !bDefaultViewNextOpening;
}
// ------------------------------------------------- PageAndSetSelected
private bool PageAndSetSelected
{
get { return (listPages .SelectedIndices .Count > 0 && listSets .SelectedIndices .Count > 0); }
}
// ------------------------------------------------- SelectedPage
// only if PageSelected !!!
private Data_Page SelectedPage
{
get { return (pages [listPages .SelectedIndices [0]]); }
}
// ------------------------------------------------- SelectedSet
// only if PageAndSetSelected !!!
private Data_Set SelectedSet
{
get { return (SelectedPage .Sets [listSets .SelectedIndices [0]]); }
}
// ------------------------------------------------- PageAndSetAndArraySelected
private bool PageAndSetAndArraySelected
{
get
{
return (listPages .SelectedIndices .Count > 0 &&
listSets .SelectedIndices .Count > 0 &&
listABArrays .SelectedIndices .Count > 0);
}
}
// ------------------------------------------------- SelectedABArray
// only if PageAndSetSelected !!!
private Data_ABArray SelectedABArray
{
get
{
Data_Set set = SelectedSet;
Data_ABArray array = set .ABArrays [listABArrays .SelectedIndices [0]];
return (array);
}
}
// ------------------------------------------------- AfterLabelEdit_listPages
private void AfterLabelEdit_listPages (object sender, LabelEditEventArgs e)
{
if (string .IsNullOrEmpty (e .Label) || string .IsNullOrEmpty (e .Label .Trim ()))
{
e .CancelEdit = true;
return;
}
string str = e .Label .Trim ();
ListView list = sender as ListView;
int iSelLine = list .SelectedIndices [0];
for (int i = 0; i < list .Items .Count; i++)
{
if (i != iSelLine)
{
if (str == pages [i] .Name)
{
e .CancelEdit = true;
MessageBox .Show ("Page with such name already exists; select another name", "Rename page",
MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
return;
}
}
}
pages [iSelLine] .Name = str;
list .Items [iSelLine] .Selected = true;
}
// ------------------------------------------------- KeyPress_textNewPage
private void KeyPress_textNewPage (object sender, KeyPressEventArgs e)
{
TextBox txtbox = (TextBox) sender;
if ((int) e .KeyChar == (int) Keys .Enter)
{
string strNew = txtbox .Text .Trim ();
if (string .IsNullOrEmpty (strNew))
{
MessageBox .Show ("No name for the new Page", "Add page", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
}
else
{
for (int i = 0; i < pages .Count; i++)
{
if (strNew == pages [i] .Name)
{
MessageBox .Show ("Page with such name already exists; select another name", "Add page",
MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
return;
}
}
Data_Page pageNew = new Data_Page (true, strNew);
int j = pages .Count;
while (j > 0 && string .Compare (pages [j - 1] .Name, strNew) > 0)
{
j--;
}
pages .Insert (j, pageNew);
FillPagesList ();
listPages .Items [j] .Selected = true;
}
}
}
// ------------------------------------------------- FillPagesList
private void FillPagesList ()
{
listPages .Items .Clear ();
for (int i = 0; i < pages .Count; i++)
{
string [] strs = new string [2] { pages [i] .Name, pages [i] .ShowToUser ? "Yes" : "No" };
ListViewItem lvi = new ListViewItem (strs);
listPages .Items .Add (lvi);
}
}
// ------------------------------------------------- Click_btnDeletePage
private void Click_btnDeletePage (object sender, EventArgs e)
{
if (listPages .SelectedIndices .Count > 0)
{
if (DialogResult .Yes == MessageBox .Show ("Do you want to delete the selected page?", "Delete page",
MessageBoxButtons .YesNo, MessageBoxIcon .Question, MessageBoxDefaultButton .Button1))
{
pages .RemoveAt (listPages .SelectedIndices [0]);
FillPagesList ();
if (pages .Count > 0)
{
listPages .Items [0] .Selected = true;
}
}
}
}
// ------------------------------------------------- Click_btnShowHidePage
private void Click_btnShowHidePage (object sender, EventArgs e)
{
if (listPages .SelectedIndices .Count > 0)
{
int iSel = listPages .SelectedIndices [0];
pages [iSel] .ShowToUser = !pages [iSel] .ShowToUser;
FillPagesList ();
Auxi_Common .ListView_LineSelectAndShow (listPages, iSel);
}
}
// ------------------------------------------------- SelectedIndexChanged_listPages
private void SelectedIndexChanged_listPages (object sender, EventArgs e)
{
bool bEnable_SetsGroup;
if (listPages .SelectedIndices .Count > 0)
{
bEnable_SetsGroup = true;
}
else
{
bEnable_SetsGroup = false;
}
EnableGroup_Sets (bEnable_SetsGroup);
Invalidate ();
}
// ------------------------------------------------- EnableGroup_Sets
private void EnableGroup_Sets (bool bEnable)
{
List<Control> ctrls = groupSets .Controls;
foreach (Control control in ctrls)
{
control .Enabled = bEnable;
}
if (bEnable)
{
FillSetsList ();
groupSets .Title = "Sets on page " + SelectedPage .Name;
}
else
{
GroupsClearDisable ();
listSets .Items .Clear ();
groupSets .Title = "Sets";
}
}
// ------------------------------------------------- AfterLabelEdit_listSets
private void AfterLabelEdit_listSets (object sender, LabelEditEventArgs e)
{
if (string .IsNullOrEmpty (e .Label) || string .IsNullOrEmpty (e .Label .Trim ()))
{
e .CancelEdit = true;
return;
}
string str = e .Label .Trim ();
ListView list = sender as ListView;
int iSelLine = list .SelectedIndices [0];
Data_Page page = SelectedPage;
for (int i = 0; i < list .Items .Count; i++)
{
if (i != iSelLine)
{
if (str == page .Sets [i] .Name)
{
e .CancelEdit = true;
MessageBox .Show ("Set with such name already exists; select another name", "Rename set",
MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
return;
}
}
}
page .Sets [iSelLine] .Name = str;
list .Items [iSelLine] .Selected = true;
}
// ------------------------------------------------- FillSetsList
private void FillSetsList ()
{
listSets .Items .Clear ();
if (listPages .SelectedIndices .Count > 0)
{
Data_Page page = SelectedPage;
for (int i = 0; i < page .Sets .Count; i++)
{
Data_Set set = page .Sets [i];
int nElems, nOpenElems;
set .Statistics (out nElems, out nOpenElems);
string [] strs = new string [] {set .Name,
set .SetType .ToString () + " (" + nElems .ToString() + "," + nOpenElems .ToString() + ")",
set .ShowToUser ? "Yes" : "No" };
ListViewItem lvi = new ListViewItem (strs);
listSets .Items .Add (lvi);
}
}
}
// ------------------------------------------------- SetsList_RefreshSelectShow
private void SetsList_RefreshSelectShow (int iSelectShow)
{
FillSetsList ();
Auxi_Common .ListView_LineSelectAndShow (listSets, iSelectShow);
}
// ------------------------------------------------- Click_btnDeleteSet
private void Click_btnDeleteSet (object sender, EventArgs e)
{
if (PageAndSetSelected)
{
if (DialogResult .Yes == MessageBox .Show ("Do you want to delete the selected set?", "Delete set",
MessageBoxButtons .YesNo, MessageBoxIcon .Question, MessageBoxDefaultButton .Button1))
{
Data_Page page = SelectedPage;
page .Sets .RemoveAt (listSets .SelectedIndices [0]);
FillSetsList ();
}
}
}
// ------------------------------------------------- Click_btnShowHideSet
private void Click_btnShowHideSet (object sender, EventArgs e)
{
if (PageAndSetSelected)
{
Data_Page page = SelectedPage;
int iSetSelected = listSets .SelectedIndices [0];
Data_Set set = page .Sets [iSetSelected];
set .ShowToUser = !set .ShowToUser;
SetsList_RefreshSelectShow (iSetSelected);
}
}
// ------------------------------------------------- KeyPress_textNewSet
private void KeyPress_textNewSet (object sender, KeyPressEventArgs e)
{
TextBox txtbox = (TextBox) sender;
if ((int) e .KeyChar == (int) Keys .Enter)
{
if (listPages .SelectedIndices .Count <= 0)
{
MessageBox .Show ("Page for the new set is not selected", "Add set", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
}
else
{
Data_Page page = SelectedPage;
string strNew = txtbox .Text .Trim ();
if (string .IsNullOrEmpty (strNew))
{
MessageBox .Show ("No name for the new Set", "Add set", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
}
else
{
for (int i = 0; i < page .Sets .Count; i++)
{
if (strNew == page .Sets [i] .Name)
{
MessageBox .Show ("Set with such name already exists in this Page; select another name", "Add set",
MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
return;
}
}
Data_Set setNew = new Data_Set (strNew, page .ShowToUser, (SetType) domainSetType .SelectedIndex);
int j = page .Sets .Count;
while (j > 0 && string .Compare (page .Sets [j - 1] .Name, strNew) > 0)
{
j--;
}
page .Sets .Insert (j, setNew);
FillSetsList ();
Auxi_Common .ListView_LineSelectAndShow (listSets, j);
}
}
}
}
// ------------------------------------------------- SelectedIndexChanged_listSets
private void SelectedIndexChanged_listSets (object sender, EventArgs e)
{
if (listSets .SelectedIndices .Count <= 0)
{
GroupsClearDisable ();
}
else
{
Data_Set set = SelectedSet;
switch (set .SetType)
{
case SetType .Numbers:
EnableGroup_Strings (false);
EnableGroup_Arrays (false);
EnableGroup_Numbers (true);
ClearGroup_Numbers ();
groupNumbers .Title = "Numbers in set " + set .Name;
FillNumbersList ();
if (!Auxi_Common .ListView_LineSelectAndShow (listNumbers, 0))
{
DisableFourButtons_Numbers ();
}
break;
case SetType .Strings:
EnableGroup_Numbers (false);
EnableGroup_Arrays (false);
EnableGroup_Strings (true);
ClearGroup_Strings ();
groupStrings .Title = "Strings in set " + set .Name;
FillStringsList ();
if (!Auxi_Common .ListView_LineSelectAndShow (listStrings, 0))
{
DisableFourButtons_Strings ();
}
break;
case SetType .ABArrays:
EnableGroup_Numbers (false);
EnableGroup_Strings (false);
EnableGroup_Arrays (true);
ClearGroup_Arrays ();
groupXYArrays .Title = "Arrays in set " + set .Name;
FillABArraysList ();
if (!Auxi_Common .ListView_LineSelectAndShow (listABArrays, 0))
{
DisableFourButtons_ABArrays ();
EnableGroup_EditXYArrays (false);
}
break;
}
}
Invalidate ();
}
// ------------------------------------------------- SaveData
private void SaveData ()
{
int nPagesWithData = 0;
for (int i = 0; i < pages .Count; i++)
{
pages [i] .RemoveEmptySets ();
}
for (int i = 0; i < pages .Count; i++)
{
if (pages [i] .HasData)
{
nPagesWithData++;
}
}
if (nPagesWithData > 0)
{
FileStream fs;
BinaryWriter bw = null;
try
{
fs = new FileStream (strDataFile, FileMode .Create, FileAccess .Write, FileShare .Write);
bw = new BinaryWriter (fs);
bw .Write (nPagesWithData);
for (int i = 0; i < pages .Count; i++)
{
pages [i] .IntoFile (bw);
}
}
catch
{
string strText = "Can't write into file" + strDataFile;
MessageBox .Show (strText, "Problem on Saving", MessageBoxButtons .OK, MessageBoxIcon .Information);
}
finally
{
bw .Close ();
}
}
}
// ------------------------------------------------- ReadData
private void ReadData ()
{
pages .Clear ();
if (!File .Exists (strDataFile))
{
return;
}
FileStream fs;
BinaryReader br = null;
try
{
fs = new FileStream (strDataFile, FileMode .Open, FileAccess .Read);
br = new BinaryReader (fs);
int nPages = br .ReadInt32 ();
for (int i = 0; i < nPages; i++)
{
Data_Page data = null;
Data_Page .FromFile (this, br, out data);
if (data != null)
{
pages .Add (data);
}
}
}
finally
{
br .Close ();
}
}
// ----------------------------------------------------- Click_miOpen
private void Click_miOpen (object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog ();
dlg .Filter = strFilterBIN;
if (dlg .ShowDialog () == DialogResult .OK)
{
strDataFile = dlg .FileName;
ReadData ();
FillPagesList ();
if (pages .Count > 0)
{
listPages .Items [0] .Selected = true;
}
if (listSets .Items .Count > 0)
{
listSets .Items [0] .Selected = true;
}
}
}
// ------------------------------------------------- Click_miSave
private void Click_miSave (object sender, EventArgs e)
{
SaveData ();
}
// ------------------------------------------------- Click_miSaveAs
private void Click_miSaveAs (object sender, EventArgs e)
{
SaveFileDialog dlg = new SaveFileDialog ();
dlg .Filter = strFilterBIN;
if (dlg .ShowDialog () == DialogResult .OK)
{
strDataFile = dlg .FileName;
SaveData ();
}
}
const string nameSizes = "Sizes";
// ------------------------------------------------- DeleteRegistryEntry
private void DeleteRegistryEntry ()
{
try
{
Registry .CurrentUser .DeleteSubKey (Form_Main .strRegKey + strAddRegKey, false);
}
catch
{
}
finally
{
}
}
// ------------------------------------------------- SaveInfoToRegistry
private void SaveInfoToRegistry ()
{
string strkey = Form_Main .strRegKey + strAddRegKey;
RegistryKey regkey = null;
try
{
regkey = Registry .CurrentUser .OpenSubKey (strkey, true);
if (regkey == null)
{
regkey = Registry .CurrentUser .CreateSubKey (strkey);
}
regkey .SetValue (nameSizes, new string [] {ClientSize .Width .ToString (), // 0
ClientSize .Height .ToString (), // 1
listPages .Columns [0] .Width .ToString (), // 2
listPages .Columns [1] .Width .ToString (), // 3
listSets .Columns [0] .Width .ToString (), // 4
listSets .Columns [1] .Width .ToString (), // 5
listSets .Columns [2] .Width .ToString (), // 6
listNumbers .Columns [0] .Width .ToString (), // 7
listNumbers .Columns [1] .Width .ToString (), // 8
listNumbers .Columns [2] .Width .ToString (), // 9
listNumbers .Columns [3] .Width .ToString (), // 10
listNumbers .Columns [4] .Width .ToString (), // 11
listNumbers .Columns [5] .Width .ToString (), // 12
listStrings .Columns [0] .Width .ToString (), // 13
listStrings .Columns [1] .Width .ToString (), // 14
listStrings .Columns [2] .Width .ToString (), // 15
listStrings .Columns [3] .Width .ToString (), // 16
listABArrays .Columns [0] .Width .ToString (), // 17
listABArrays .Columns [1] .Width .ToString (), // 18
datagridXY .Columns [0] .Width .ToString (), // 19
datagridXY .Columns [1] .Width .ToString (), // 20
}, RegistryValueKind .MultiString);
groupPages .IntoRegistry (regkey, "GroupPages");
groupSets .IntoRegistry (regkey, "GroupSets");
groupNumbers .IntoRegistry (regkey, "GroupNumbers");
groupStrings .IntoRegistry (regkey, "GroupStrings");
groupXYArrays .IntoRegistry (regkey, "GroupArrays");
}
catch
{
}
finally
{
if (regkey != null) regkey .Close ();
}
}
// ------------------------------------------------- RestoreFromRegistry
private void RestoreFromRegistry ()
{
string strkey = Form_Main .strRegKey + strAddRegKey;
RegistryKey regkey = null;
try
{
bRestore = false;
regkey = Registry .CurrentUser .OpenSubKey (strkey, true);
if (regkey != null)
{
string [] strs = (string []) regkey .GetValue (nameSizes);
if (strs != null && strs .Length == 21)
{
ClientSize = Auxi_Convert .ToSize (strs, 0);
for (int i = 0; i < 2; i++)
{
listPages .Columns [i] .Width = Convert .ToInt32 (strs [i + 2]);
}
for (int i = 0; i < 3; i++)
{
listSets .Columns [i] .Width = Convert .ToInt32 (strs [i + 4]);
}
for (int i = 0; i < 6; i++)
{
listNumbers .Columns [i] .Width = Convert .ToInt32 (strs [i + 7]);
}
for (int i = 0; i < 4; i++)
{
listStrings .Columns [i] .Width = Convert .ToInt32 (strs [i + 13]);
}
for (int i = 0; i < 2; i++)
{
listABArrays .Columns [i] .Width = Convert .ToInt32 (strs [i + 17]);
}
for (int i = 0; i < 2; i++)
{
datagridXY .Columns [i] .Width = Convert .ToInt32 (strs [i + 19]);
}
}
groupPages = ElasticGroup .FromRegistry (this, regkey, "GroupPages", ctrlsGroupPages);
groupSets = ElasticGroup .FromRegistry (this, regkey, "GroupSets", ctrlsGroupSets);
groupNumbers = ElasticGroup .FromRegistry (this, regkey, "GroupNumbers", ctrlsGroupNumbers);
groupStrings = ElasticGroup .FromRegistry (this, regkey, "GroupStrings", ctrlsGroupStrings);
groupXYArrays = GroupABArrays .FromRegistry (this, regkey, "GroupArrays", ctrlsListArrays, ctrlsEditABArray);
if (groupPages != null && groupSets != null && groupNumbers != null && groupStrings != null && groupXYArrays != null)
{
groupListArrays = groupXYArrays .GroupList;
groupEditXYArray = groupXYArrays .GroupData;
bRestore = true;
}
}
}
catch
{
}
finally
{
if (regkey != null) regkey .Close ();
}
}
}
}