using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using xmlRecord;
using GraphicText;
using Mars_Mission;
public class classGraphicOutputPanel : Panel
{
VScrollBar vsb = new VScrollBar();
public PictureBox pic = new PictureBox();
GraphicText.classWordImage[] _cWordArray;
public classXmlRecord cLibXmlRecord;
public classGraphicText cLibGrTxt;
public classLib.classLib cLib;
TextBox txtPopUp = new TextBox();
Panel pnlNavigation = new Panel();
ComboBox cmbNavigation = new ComboBox();
Button nbtnavigation_Forward = new Button();
Button nbtnavigation_Backward = new Button();
public Button nbtnavigation_Home = new Button();
public Button btnEdit = new Button();
classWordImage wordUnderMouse;
public classFileContent cFileContent;
Cursor cOldCursor;
Cursor cLink = Cursors.Hand;
Point ptMousePos = new Point();
public bool bolDisposeOnEscape = false;
public static formEdit_HelpMenu frmEditHelpMenu;
public struct udtNavigation
{
public string filename;
public string heading;
}
udtNavigation[] uNavigation = new udtNavigation[0];
udtNavigation uHome = new udtNavigation();
int intCurrentPageIndex = 0;
bool bolIgnoreChangeToCmb = false;
formPopup frmPopUp;
public classGraphicOutputPanel()
{
cLibXmlRecord = formMarsMission.cLibXmlRecord;
cLibGrTxt = formMarsMission.cLibGrTxt;
cLib = formMarsMission.cLib;
Controls.Add(vsb);
vsb.ValueChanged += new EventHandler(vsb_ValueChanged);
vsb.Visible = true;
BackColor = Color.White;
Controls.Add(pic);
pic.Visible = true;
pnlNavigation.Text = "Navigation";
pnlNavigation.Controls.Add(cmbNavigation);
pnlNavigation.SizeChanged += new EventHandler(pnlNavigation_SizeChanged);
cmbNavigation.Location = new Point(5, 15);
cmbNavigation.Width = 250;
cmbNavigation.SelectedIndexChanged += new EventHandler(cmbNavigation_SelectedIndexChanged);
pnlNavigation.Controls.Add(nbtnavigation_Home);
nbtnavigation_Home.Text = "Home";
nbtnavigation_Home.AutoSizeMode = AutoSizeMode.GrowAndShrink;
nbtnavigation_Home.AutoSize = true;
nbtnavigation_Home.Visible = true;
nbtnavigation_Home.Click += new EventHandler(nbtnavigation_Home_Click);
nbtnavigation_Home.MouseWheel += new MouseEventHandler(nbtnavigation_Home_MouseWheel);
nbtnavigation_Home.KeyDown += new KeyEventHandler(nbtnavigation_Home_KeyDown);
pnlNavigation.Controls.Add(nbtnavigation_Backward);
nbtnavigation_Backward.Text = "Back";
nbtnavigation_Backward.AutoSizeMode = AutoSizeMode.GrowAndShrink;
nbtnavigation_Backward.AutoSize = true;
nbtnavigation_Backward.Visible = false;
nbtnavigation_Backward.Click += new EventHandler(nbtnavigation_Backward_Click);
pnlNavigation.Controls.Add(nbtnavigation_Forward);
nbtnavigation_Forward.Text = "Forward";
nbtnavigation_Forward.AutoSizeMode = AutoSizeMode.GrowAndShrink;
nbtnavigation_Forward.AutoSize = true;
nbtnavigation_Forward.Visible = false;
nbtnavigation_Forward.Click += new EventHandler(nbtnavigation_Forward_Click);
pnlNavigation.Controls.Add(btnEdit);
btnEdit.Text = "Edit";
btnEdit.AutoSizeMode = AutoSizeMode.GrowAndShrink;
btnEdit.AutoSize = true;
btnEdit.Click += new EventHandler(btnEdit_Click);
pnlNavigation.Width = nbtnavigation_Forward.Left + nbtnavigation_Forward.Width + 10;
pnlNavigation.Height = nbtnavigation_Forward.Top + nbtnavigation_Forward.Height + 5;
Controls.Add(pnlNavigation);
pnlNavigation.Location = new Point(5, 5);
pnlNavigation.Visible =true;
SizeChanged += new EventHandler(classGraphicOutputPanel_SizeChanged);
pic.MouseMove += new MouseEventHandler(pic_MouseMove);
pic.MouseEnter += new EventHandler(pic_MouseEnter);
pic.MouseLeave += new EventHandler(pic_MouseLeave);
pic.MouseClick += new MouseEventHandler(pic_MouseClick);
pic.MouseWheel += new MouseEventHandler(_MouseWheel);
frmPopUp = new formPopup();
frmPopUp.txt.Font = new Font("ms sans-serif", 14);
MouseWheel +=new MouseEventHandler(_MouseWheel);
nbtnavigation_Home.Focus();
}
bool _bolDisableNavigation = false;
public bool DisableNavigation
{
set { _bolDisableNavigation = value; }
get { return _bolDisableNavigation; }
}
static bool _bolEdit;
public bool bolEdit
{
get { return _bolEdit; }
set
{
btnEdit.Visible =
_bolEdit = value;
classGraphicOutputPanel_SizeChanged((object)this, new EventArgs());
}
}
void btnEdit_Click(object sender, EventArgs e)
{
if (DisableNavigation)
return;
if (frmEditHelpMenu == null)
{
frmEditHelpMenu = new formEdit_HelpMenu();
frmEditHelpMenu.Disposed += new EventHandler(frmEditHelpMenu_Disposed);
}
frmEditHelpMenu.loadfile(cFileContent.filename);
frmEditHelpMenu.Show();
}
void frmEditHelpMenu_Disposed(object sender, EventArgs e)
{
frmEditHelpMenu = null;
}
void nbtnavigation_Home_KeyDown(object sender, KeyEventArgs e)
{
}
void nbtnavigation_Home_MouseWheel(object sender, MouseEventArgs e)
{
_MouseWheel((object)this, e);
}
public void resetNavigation()
{
bolIgnoreChangeToCmb = true;
uHome.filename = cFileContent.filename;
uHome.heading = cFileContent.heading;
cmbNavigation.Items.Clear();
intCurrentPageIndex = 0;
cutNavigation();
addNavigationPage();
bolIgnoreChangeToCmb = false;
}
void addNavigationPage()
{
bolIgnoreChangeToCmb = true;
Array.Resize<udtNavigation>(ref uNavigation, uNavigation.Length + 1);
uNavigation[uNavigation.Length - 1].filename = cFileContent.filename;
uNavigation[uNavigation.Length - 1].heading = cFileContent.heading;
intCurrentPageIndex = uNavigation.Length - 1;
cmbNavigation.Items.Add(cFileContent.heading);
cmbNavigation.SelectedIndex = intCurrentPageIndex;
cmbNavigation.SelectedIndex = cmbNavigation.Items.Count - 1;
cmbNavigation.Text = cmbNavigation.Items[cmbNavigation.Items.Count - 1].ToString();
setButtonsVisible();
bolIgnoreChangeToCmb = false;
}
void setButtonsVisible()
{
nbtnavigation_Backward.Visible = (intCurrentPageIndex > 0);
nbtnavigation_Forward.Visible = (intCurrentPageIndex < uNavigation.Length - 1);
}
void cutNavigation()
{
if (intCurrentPageIndex >= 0 && intCurrentPageIndex < uNavigation.Length - 1)
{
Array.Resize<udtNavigation>(ref uNavigation, intCurrentPageIndex + 1);
bolIgnoreChangeToCmb = true;
cmbNavigation.Items.Clear();
for (int intItemCounter = 0; intItemCounter < uNavigation.Length; intItemCounter++)
cmbNavigation.Items.Add(uNavigation[intItemCounter].heading);
setButtonsVisible();
bolIgnoreChangeToCmb = false;
}
}
void cmbNavigation_SelectedIndexChanged(object sender, EventArgs e)
{
if (bolIgnoreChangeToCmb)
return;
int intSelIndex = cmbNavigation.SelectedIndex;
if (intSelIndex >= 0 && intSelIndex < uNavigation.Length)
{
loadFile(uNavigation[intSelIndex].filename);
intCurrentPageIndex = intSelIndex;
setButtonsVisible();
}
}
void nbtnavigation_Forward_Click(object sender, EventArgs e)
{
if (DisableNavigation)
return;
if (cmbNavigation.SelectedIndex < cmbNavigation.Items.Count)
cmbNavigation.SelectedIndex++;
}
void nbtnavigation_Backward_Click(object sender, EventArgs e)
{
if (DisableNavigation)
return;
if (cmbNavigation.SelectedIndex > 0)
cmbNavigation.SelectedIndex--;
}
void nbtnavigation_Home_Click(object sender, EventArgs e)
{
if (DisableNavigation)
return;
cmbNavigation.SelectedIndex = 0;
cutNavigation();
nbtnavigation_Home.Focus();
}
//void pic_GotFocus(object sender, EventArgs e)
//{
// txtKeyDown.Focus();
//}
void txtKeyDown_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Escape:
//if (bolDisposeOnEscape)
// mainForm.Dispose();
break;
}
}
public void _MouseWheel(object sender, MouseEventArgs e)
{
if (vsb.Visible)
{
if (e.Delta < 0)
{
if (vsb.Value + vsb.SmallChange <= vsb.Maximum - vsb.LargeChange)
vsb.Value += vsb.SmallChange;
else
vsb.Value = vsb.Maximum - vsb.LargeChange;
}
else if (e.Delta > 0)
{
if (vsb.Value - vsb.SmallChange >= vsb.Minimum)
vsb.Value -= vsb.SmallChange;
else
vsb.Value = vsb.Minimum;
}
}
}
void pic_MouseClick(object sender, MouseEventArgs e)
{
if (DisableNavigation
&& ((wordUnderMouse!= null && wordUnderMouse.eWordImageType != enuWordImageType.solution)
|| (wordUnderMouse == null)))
return;
if (wordUnderMouse != null)
{
switch (wordUnderMouse.eWordImageType)
{
case enuWordImageType.link:
string strFilenameAndDirectory = cLibXmlRecord.strWorkingDirectory + wordUnderMouse.strAddress + ".xml";
if (System.IO.File.Exists(strFilenameAndDirectory))
{
loadFile(wordUnderMouse.strAddress);
cutNavigation();
addNavigationPage();
}
else
{ // exit
if (DisableNavigation)
return;
if (frmEditHelpMenu == null)
{
frmEditHelpMenu = new formEdit_HelpMenu();
frmEditHelpMenu.Disposed += new EventHandler(frmEditHelpMenu_Disposed);
}
frmEditHelpMenu.newFile(wordUnderMouse.strAddress, cFileContent.filename);
frmEditHelpMenu.TopMost = true;
frmEditHelpMenu.Show();
}
break;
case enuWordImageType.solution:
frmPopUp.Owner = formMarsMission.frmMarsMission;
frmPopUp.showText(wordUnderMouse.strAddress);
break;
case enuWordImageType.image:
Form frmPic = new Form();
PictureBox pic = new PictureBox();
frmPic.Controls.Add(pic);
pic.SizeMode = PictureBoxSizeMode.AutoSize;
pic.Image = wordUnderMouse.bmp;
frmPic.Size = new Size(pic.Width + 15, pic.Height + 35);
frmPic.Text = wordUnderMouse.strText;
pic.Location = new Point(0, 0);
//frmPic.KeyDown += new KeyEventHandler(cLibLatin.frm_KeyDown);
frmPic.Show();
break;
case enuWordImageType.plain:
//formMarsMission.cLibSearchEngine.searchWord(cLib.removeNonAlpha(wordUnderMouse.strText));
break;
}
}
}
enum enuIcons { image, link, solution,latin, plain };
Cursor[] curIcons = new Cursor[5];
Cursor getCursor(enuIcons eIcon)
{
if (curIcons[(int)eIcon] != null)
return curIcons[(int)eIcon];
Bitmap bmpIcon = null;
switch (eIcon)
{
case enuIcons.image:
bmpIcon = new Bitmap(Mars_Mission.Properties.Resources.Picture_Icon);
break;
case enuIcons.latin:
bmpIcon = new Bitmap(Mars_Mission.Properties.Resources.Latin_Icon);
break;
case enuIcons.plain:
curIcons[(int)eIcon] = cOldCursor;
return curIcons[(int)eIcon];
case enuIcons.link:
bmpIcon = new Bitmap(Mars_Mission.Properties.Resources.Link_icon);
break;
case enuIcons.solution:
bmpIcon = new Bitmap (Mars_Mission.Properties.Resources.Solution_Icon);
break;
}
bmpIcon.MakeTransparent();
IntPtr ptrIcon = bmpIcon.GetHicon();
curIcons[(int)eIcon] = new Cursor(ptrIcon);
return curIcons[(int)eIcon];
}
void pic_MouseMove(object sender, MouseEventArgs e)
{ // reset the timer
ptMousePos = new Point(e.X, e.Y);
wordUnderMouse =cLibGrTxt.getWordUnderMouse(ptMousePos, cWordArray);
if (wordUnderMouse != null)
{
switch (wordUnderMouse.eWordImageType)
{
case enuWordImageType.image:
Cursor = getCursor(enuIcons.image);
break;
case enuWordImageType.link:
Cursor = getCursor(enuIcons.link);
break;
case enuWordImageType.plain:
Cursor = getCursor(enuIcons.plain);
break;
case enuWordImageType.flash:
frmPopUp.Owner = formMarsMission.frmMarsMission;
frmPopUp.TopMost = true;
frmPopUp.showText( wordUnderMouse.strAddress.Trim(), Color.LightSteelBlue );
break;
case enuWordImageType.solution:
Cursor = getCursor(enuIcons.solution);
break;
}
}
else
Cursor = cOldCursor;
}
void pic_MouseLeave(object sender, EventArgs e)
{
Cursor = cOldCursor;
}
void pic_MouseEnter(object sender, EventArgs e)
{
cOldCursor = Cursor;
}
public void loadFile(string strFilename)
{
cFileContent = cLibXmlRecord.getFileContent(strFilename);
cWordArray = cLibXmlRecord.getRecordWordImageArray(cFileContent, ref cLibGrTxt);
//mainForm.Text = (System.IO.Directory.GetCurrentDirectory().ToUpper().Contains("DEBUG") && false) ? strFilename : cFileContent.heading;
//strAudioFilename = cLibLatin.findAudioFile(cFileContent.heading);
//btnAudio.Visible = (strAudioFilename != null);
nbtnavigation_Home.Focus();
}
//void btnAudio_Click(object sender, EventArgs e)
//{
// cLibLatin.playAudio(strAudioFilename);
//}
public GraphicText.classWordImage[] cWordArray
{
get
{
return _cWordArray;
}
set
{
_cWordArray = value;
classGraphicOutputPanel_SizeChanged((object)this, new EventArgs());
}
}
void vsb_ValueChanged(object sender, EventArgs e)
{
if (pic.Height < vsb.Height)
{
pic.Top = vsb.Top;
vsb.Visible = false;
return;
}
vsb.Visible = true;
int intLowest = vsb.Top;
int intHighest = vsb.Top + vsb.Height - pic.Height;
pic.Top = intLowest + (int)((intHighest - intLowest) * ((double)vsb.Value / (double)(vsb.Maximum - vsb.LargeChange)));
pic.SendToBack();
}
void pnlNavigation_SizeChanged(object sender, EventArgs e)
{
//btnPopUp.Location = new Point(pnlNavigation.Width - nbtnavigation_Forward.Width - 5, cmbNavigation.Top);
//btnAudio.Location = new Point(btnPopUp.Left - btnAudio.Width - 5, cmbNavigation.Top);
btnEdit.Location = new Point(pnlNavigation.Width - nbtnavigation_Forward.Width - 5, cmbNavigation.Top);
btnEdit.Visible = _bolEdit;
nbtnavigation_Forward.Location = new Point((_bolEdit ? btnEdit.Left : pnlNavigation.Width) - nbtnavigation_Forward.Width - 5, cmbNavigation.Top);
nbtnavigation_Backward.Location = new Point(nbtnavigation_Forward.Left - nbtnavigation_Backward.Width - 5, cmbNavigation.Top);
nbtnavigation_Home.Location = new Point(nbtnavigation_Backward.Left - nbtnavigation_Home.Width - 5, cmbNavigation.Top);
cmbNavigation.Location = new Point(5, 15);
cmbNavigation.Width = nbtnavigation_Home.Left - 10;
}
void classGraphicOutputPanel_SizeChanged(object sender, EventArgs e)
{
if (cWordArray != null)
{
vsb.Left = Width - 5 - vsb.Width;
vsb.Top = pnlNavigation.Top + pnlNavigation.Height + 5;
vsb.Height = Height - 5 - vsb.Top;
Bitmap bmp = GraphicText.classGraphicText.putImageArrayOntoBitmap(vsb.Left - 10, cWordArray);
pnlNavigation.Width = Width - 10;
if (bmp != null)
{
pic.Image = bmp;
pic.Width = bmp.Width;
pic.Height = bmp.Height;
pic.Top = vsb.Top;
pic.Left = 5;
vsb.Maximum = 10000;
vsb.LargeChange = (int)((double)vsb.Height / (double)bmp.Height * (double)vsb.Maximum);
vsb.SmallChange = vsb.LargeChange / 8;
vsb.Value = 0;
vsb.Visible = (vsb.LargeChange < vsb.Maximum);
}
}
}
}
public class formPopup : Form
{
public TextBox txt = new TextBox();
public int intMaxWidth;
string _strText = "";
public formPopup()
{
Controls.Add(txt);
FormBorderStyle = FormBorderStyle.None;
ShowInTaskbar = false;
txt.Multiline = true;
txt.MouseLeave += new EventHandler(txt_MouseLeave);
txt.TextChanged += new EventHandler(txt_TextChanged);
txt.ForeColor = Color.Red;
txt.Visible = true;
txt.BorderStyle = BorderStyle.None;
intMaxWidth = Screen.PrimaryScreen.WorkingArea.Width / 2;
}
void txt_TextChanged(object sender, EventArgs e)
{
txt.Text = _strText;
}
void txt_MouseLeave(object sender, EventArgs e)
{
Visible = false;
}
public void showText(string strText) { showText(strText, Color.LightYellow); }
public void showText(string strText, Color clrBackground)
{
_strText = strText;
txt.Text = strText;
txt.Size = new Size(intMaxWidth - 10, 10000);
Top = Screen.PrimaryScreen.WorkingArea.Height + 10;
txt.Dock = DockStyle.None;
txt.BackColor = clrBackground;
Visible = true;
if (txt.Text.Length > 1)
{
int intSize_Width = intMaxWidth;
int intSize_Height = txt.Font.Height + 5;
Point ptEnd = txt.GetPositionFromCharIndex(txt.Text.Length - 1);
if (ptEnd.Y > txt.Font.Height)
{ // multiple lines
intSize_Height = ptEnd.Y + txt.Font.Height + 5;
}
else
{
intSize_Width = ptEnd.X + 20;
}
Size = new Size(intSize_Width, intSize_Height);
}
txt.Dock = DockStyle.Fill;
Visible = false;
Location = new Point(MousePosition.X - 5, MousePosition.Y - 5);
if (Width > Screen.PrimaryScreen.WorkingArea.Width)
{
Width = Screen.PrimaryScreen.WorkingArea.Width;
Left = 0;
}
else
{
if (Left + Width > Screen.PrimaryScreen.WorkingArea.Width)
Left = Screen.PrimaryScreen.WorkingArea.Width - Width;
if (Left < 0)
Left = 0;
}
if (Height > Screen.PrimaryScreen.WorkingArea.Height)
{
Height = Screen.PrimaryScreen.WorkingArea.Height;
Top = 0;
}
else
{
if (Top + Height > Screen.PrimaryScreen.WorkingArea.Height)
Top = Screen.PrimaryScreen.WorkingArea.Height - Height;
if (Top < 0)
Top = 0;
}
txt.SelectionLength = 0;
Visible = true;
}
}