Click here to Skip to main content
15,891,473 members
Articles / Programming Languages / C#

The Favalias Application

Rate me:
Please Sign up or sign in to vote.
4.92/5 (27 votes)
30 Sep 20037 min read 70.8K   2.6K   52  
Favalias application enables you to manage your favorites web sites in an XML file and to launch your favorites application using aliases. You can also make your own addins (in any .NET language) to call your own code.
// Jean-Christophe Magnon
// jcmag@yahoo.com
#region Copyright � 2003 The Favalias Group
/*
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the
 * use of this software.
 *
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, subject to the following restrictions:
 *
 * 1. The origin of this software must not be misrepresented; you must not claim
 * that you wrote the original software. If you use this software in a product,
 * an acknowledgment in the product documentation is required, as shown here:
 *
 * Portions Copyright � 2003 The Favalias Group (http://sourceforge.net/projects/favalias).
 *
 * 2. Altered source versions must be plainly marked as such, and must not be 
 * misrepresented as being the original software.
 * 
 * 3. This notice may not be removed or altered from any source distribution.
*/
#endregion

#region Namespaces
using Favalias.Controllers;
using Favalias.DataSets;
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.IO;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Xsl;
using Toub.Threading;
using MenuItemClass = Favalias.Common.UIControls.RichMenuItem;//System.Windows.Forms.MenuItem;

#endregion

namespace Favalias.Forms.Matrix
{
	/// <summary>
	/// Main Form
	/// </summary>
	public class FormFavalias : Favalias.Forms.FormFavalias
	{
		#region Fields
		#region Code
		
		private static readonly log4net.ILog _log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
		private Point mouseOffset;
		private bool isMouseDown = false;
		
		#endregion

		#region UI
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.PictureBox pBoxExit;
		private System.Windows.Forms.ContextMenu contextMenuFavorites;
		private System.Windows.Forms.ContextMenu contextMenuAddinsAliases;
		private System.Windows.Forms.ContextMenu contextMenuMyAliases;
		private System.Windows.Forms.ContextMenu contextMenuOptions;
		private System.Windows.Forms.ContextMenu contextMenuHelp;
		private System.Windows.Forms.PictureBox pBoxFavorites;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.PictureBox pBoxMyAliases;
		private System.Windows.Forms.PictureBox pBoxAddinsAliases;
		private System.Windows.Forms.PictureBox pBoxOptions;
		private System.Windows.Forms.PictureBox pBoxHelp;
		
		
		#endregion

		#endregion

		#region Properties
		protected override bool SerializeSize
		{
			get
			{
				return false;
			}
		}
		#endregion

		#region Initialization
		public FormFavalias() : base()
		{
			
		}
		
		protected override void initializeMyMenuItems()
		{
			InitializeComponent();
			contextMenuAddinsAliases = new System.Windows.Forms.ContextMenu();
			contextMenuFavorites = new System.Windows.Forms.ContextMenu();
			contextMenuMyAliases = new System.Windows.Forms.ContextMenu();
			contextMenuOptions = new System.Windows.Forms.ContextMenu();
			contextMenuHelp = new System.Windows.Forms.ContextMenu();
			
			this.contextMenuHelp.MenuItems.AddRange(new MenuItemClass[]{this.menuDoc, this.menuAbout});
			this.contextMenuOptions.MenuItems.AddRange(new MenuItemClass[]{ this.menuPreferences, this.menuEditFavorites, this.menuEditAliases, this.menuEditAddins
																					  // ,this.menuViewLog,
																					   ,this.menuTransparent});
		}
		
		#region IDisposable Members
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#endregion

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormFavalias));
			this.pBoxExit = new System.Windows.Forms.PictureBox();
			this.pBoxFavorites = new System.Windows.Forms.PictureBox();
			this.label1 = new System.Windows.Forms.Label();
			this.pBoxMyAliases = new System.Windows.Forms.PictureBox();
			this.pBoxAddinsAliases = new System.Windows.Forms.PictureBox();
			this.pBoxOptions = new System.Windows.Forms.PictureBox();
			this.pBoxHelp = new System.Windows.Forms.PictureBox();
			this.SuspendLayout();
			// 
			// pBoxExit
			// 
			this.pBoxExit.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.pBoxExit.BackColor = System.Drawing.Color.Transparent;
			this.pBoxExit.Cursor = System.Windows.Forms.Cursors.Hand;
			this.pBoxExit.Image = ((System.Drawing.Image)(resources.GetObject("pBoxExit.Image")));
			this.pBoxExit.Location = new System.Drawing.Point(208, 0);
			this.pBoxExit.Name = "pBoxExit";
			this.pBoxExit.Size = new System.Drawing.Size(13, 13);
			this.pBoxExit.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
			this.pBoxExit.TabIndex = 3;
			this.pBoxExit.TabStop = false;
			this.toolTip1.SetToolTip(this.pBoxExit, "Go to taskbar");
			this.pBoxExit.Click += new System.EventHandler(this.pBoxExit_Click);
			// 
			// completionCombo1
			// 
			this.completionCombo1.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.completionCombo1.LimitToList = true;
			this.completionCombo1.Location = new System.Drawing.Point(14, 68);
			this.completionCombo1.Name = "completionCombo1";
			this.completionCombo1.Size = new System.Drawing.Size(195, 21);
			this.completionCombo1.Sorted = true;
			this.completionCombo1.TabIndex = 2;
			this.completionCombo1.TabStop = false;
			// 
			// pBoxFavorites
			// 
			this.pBoxFavorites.BackColor = System.Drawing.Color.Transparent;
			this.pBoxFavorites.Image = ((System.Drawing.Image)(resources.GetObject("pBoxFavorites.Image")));
			this.pBoxFavorites.Location = new System.Drawing.Point(14, 32);
			this.pBoxFavorites.Name = "pBoxFavorites";
			this.pBoxFavorites.Size = new System.Drawing.Size(41, 39);
			this.pBoxFavorites.TabIndex = 10;
			this.pBoxFavorites.TabStop = false;
			this.pBoxFavorites.Visible = false;
			this.pBoxFavorites.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pBoxFavorites_MouseUp);
			this.pBoxFavorites.MouseLeave += new System.EventHandler(this.pBoxFavorites_MouseLeave);
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.Color.Transparent;
			this.label1.Font = new System.Drawing.Font("Tahoma", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.ForeColor = System.Drawing.Color.White;
			this.label1.Location = new System.Drawing.Point(66, 89);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(144, 16);
			this.label1.TabIndex = 11;
			// 
			// pBoxMyAliases
			// 
			this.pBoxMyAliases.BackColor = System.Drawing.Color.Transparent;
			this.pBoxMyAliases.Image = ((System.Drawing.Image)(resources.GetObject("pBoxMyAliases.Image")));
			this.pBoxMyAliases.Location = new System.Drawing.Point(48, 30);
			this.pBoxMyAliases.Name = "pBoxMyAliases";
			this.pBoxMyAliases.Size = new System.Drawing.Size(35, 33);
			this.pBoxMyAliases.TabIndex = 12;
			this.pBoxMyAliases.TabStop = false;
			this.pBoxMyAliases.Visible = false;
			this.pBoxMyAliases.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pBoxMyAliases_MouseUp);
			this.pBoxMyAliases.MouseLeave += new System.EventHandler(this.pBoxMyAliases_MouseLeave);
			// 
			// pBoxAddinsAliases
			// 
			this.pBoxAddinsAliases.BackColor = System.Drawing.Color.Transparent;
			this.pBoxAddinsAliases.Image = ((System.Drawing.Image)(resources.GetObject("pBoxAddinsAliases.Image")));
			this.pBoxAddinsAliases.Location = new System.Drawing.Point(80, 42);
			this.pBoxAddinsAliases.Name = "pBoxAddinsAliases";
			this.pBoxAddinsAliases.Size = new System.Drawing.Size(34, 20);
			this.pBoxAddinsAliases.TabIndex = 13;
			this.pBoxAddinsAliases.TabStop = false;
			this.pBoxAddinsAliases.Visible = false;
			this.pBoxAddinsAliases.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pBoxAddinsAliases_MouseUp);
			this.pBoxAddinsAliases.MouseLeave += new System.EventHandler(this.pBoxAddinsAliases_MouseLeave);
			// 
			// pBoxOptions
			// 
			this.pBoxOptions.BackColor = System.Drawing.Color.Transparent;
			this.pBoxOptions.Image = ((System.Drawing.Image)(resources.GetObject("pBoxOptions.Image")));
			this.pBoxOptions.Location = new System.Drawing.Point(116, 33);
			this.pBoxOptions.Name = "pBoxOptions";
			this.pBoxOptions.Size = new System.Drawing.Size(32, 30);
			this.pBoxOptions.TabIndex = 14;
			this.pBoxOptions.TabStop = false;
			this.pBoxOptions.Visible = false;
			this.pBoxOptions.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pBoxOptions_MouseUp);
			this.pBoxOptions.MouseLeave += new System.EventHandler(this.pBoxOptions_MouseLeave);
			// 
			// pBoxHelp
			// 
			this.pBoxHelp.BackColor = System.Drawing.Color.Transparent;
			this.pBoxHelp.Image = ((System.Drawing.Image)(resources.GetObject("pBoxHelp.Image")));
			this.pBoxHelp.Location = new System.Drawing.Point(157, 31);
			this.pBoxHelp.Name = "pBoxHelp";
			this.pBoxHelp.Size = new System.Drawing.Size(37, 38);
			this.pBoxHelp.TabIndex = 15;
			this.pBoxHelp.TabStop = false;
			this.pBoxHelp.Visible = false;
			this.pBoxHelp.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pBoxHelp_MouseUp);
			this.pBoxHelp.MouseLeave += new System.EventHandler(this.pBoxHelp_MouseLeave);
			// 
			// FormFavalias
			// 
			this.AllowDrop = true;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.BackColor = System.Drawing.Color.LightSteelBlue;
			this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
			this.CausesValidation = false;
			this.ClientSize = new System.Drawing.Size(222, 102);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.completionCombo1);
			this.Controls.Add(this.pBoxExit);
			this.Controls.Add(this.pBoxHelp);
			this.Controls.Add(this.pBoxOptions);
			this.Controls.Add(this.pBoxAddinsAliases);
			this.Controls.Add(this.pBoxMyAliases);
			this.Controls.Add(this.pBoxFavorites);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.KeyPreview = true;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "FormFavalias";
			this.Opacity = 0.20000000298023224;
			this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Favalias";
			this.TopMost = true;
			this.TransparencyKey = System.Drawing.Color.Magenta;
			this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.FormFavalias_MouseDown);
			this.Paint += new System.Windows.Forms.PaintEventHandler(this.FormFavalias_Paint);
			this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.FormFavalias_MouseUp);
			this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.FormFavalias_MouseMove);
			this.ResumeLayout(false);

		}
		#endregion

		#endregion		

		#region Form Event Handlers
		
		private void FormFavalias_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			GraphicsPath myPath  = new GraphicsPath();
			myPath.AddRectangle(new Rectangle(0, 0, 222, 102));
			this.Region = new Region(myPath);
		}

		private void FormFavalias_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			int xOffset;
			int yOffset;

			if (e.Button == MouseButtons.Left) 
			{
				xOffset = -e.X;
				yOffset = -e.Y;
				mouseOffset = new Point(xOffset, yOffset);
				isMouseDown = true;
			}
		}

		private void FormFavalias_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (isMouseDown) 
			{
				Point mousePos = Control.MousePosition;
				mousePos.Offset(mouseOffset.X, mouseOffset.Y);
				Location = mousePos;
			}
			else
			{
				hidePictureBoxes();
				if(e.X > pBoxFavorites.Location.X && e.X < (pBoxFavorites.Location.X + pBoxFavorites.Width)
					&& e.Y > pBoxFavorites.Location.Y && e.Y < (pBoxFavorites.Location.Y + pBoxFavorites.Height))
				{
					pBoxFavorites.Visible = true;
					label1.Text = "Favorites";
				}
				else if(e.X > pBoxMyAliases.Location.X && e.X < (pBoxMyAliases.Location.X + pBoxMyAliases.Width)
					&& e.Y > pBoxMyAliases.Location.Y && e.Y < (pBoxMyAliases.Location.Y + pBoxMyAliases.Height))
				{
					pBoxMyAliases.Visible = true;
					label1.Text = "My aliases";
				}
				else if(e.X > pBoxAddinsAliases.Location.X && e.X < (pBoxAddinsAliases.Location.X + pBoxAddinsAliases.Width)
					&& e.Y > pBoxAddinsAliases.Location.Y && e.Y < (pBoxAddinsAliases.Location.Y + pBoxAddinsAliases.Height))
				{
					pBoxAddinsAliases.Visible = true;
					label1.Text = "Addins aliases";
				}
				else if(e.X > pBoxOptions.Location.X && e.X < (pBoxOptions.Location.X + pBoxOptions.Width)
					&& e.Y > pBoxOptions.Location.Y && e.Y < (pBoxOptions.Location.Y + pBoxOptions.Height))
				{
					pBoxOptions.Visible = true;
					label1.Text = "Options";
				}
				else if(e.X > pBoxHelp.Location.X && e.X < (pBoxHelp.Location.X + pBoxHelp.Width)
					&& e.Y > pBoxHelp.Location.Y && e.Y < (pBoxHelp.Location.Y + pBoxHelp.Height))
				{
					pBoxHelp.Visible = true;
					label1.Text = "Help";
				}
			}
		}

		private void FormFavalias_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (e.Button == MouseButtons.Left) 
			{
				isMouseDown = false;
			}

		}
		#endregion

		#region Utilities
		
		private void hidePictureBoxes()
		{
			pBoxAddinsAliases.Visible = false;
			pBoxFavorites.Visible = false;
			pBoxHelp.Visible = false;
			pBoxMyAliases.Visible = false;
			pBoxOptions.Visible = false;
		}

		#endregion

		#region Favalias.Forms.FormFavalias overrides
		protected override void clearAliasesMenus()
		{
			contextMenuAddinsAliases.MenuItems.Clear();
			contextMenuMyAliases.MenuItems.Clear();
		}
		
		protected override void addItemInCustomAliasesMenu(MenuItemClass item)
		{
			contextMenuMyAliases.MenuItems.Add(item);
		}
		protected override void addItemInAddinAliasesMenu(MenuItemClass item)
		{
			contextMenuAddinsAliases.MenuItems.Add(item);
		}

		protected override void clearFavoritesMenu()
		{
			contextMenuFavorites.MenuItems.Clear();
		}

		protected override void addItemInFavoriteMenu(MenuItemClass item)
		{
			contextMenuFavorites.MenuItems.Add(item);
		}

		protected override void addStaticItemsInFavoriteMenu(MenuItemClass[] items)
		{
			this.contextMenuFavorites.MenuItems.AddRange(items);
		}

		#endregion

		#region PictureBoxes
		private void pBoxExit_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void pBoxAddinsAliases_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			contextMenuAddinsAliases.Show(pBoxAddinsAliases, (new Point(e.X, e.Y)));
			Invalidate(true);
		}

		private void pBoxMyAliases_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			contextMenuMyAliases.Show(pBoxMyAliases, (new Point(e.X, e.Y)));
			Invalidate(true);
		}

		private void pBoxOptions_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			contextMenuOptions.Show(pBoxOptions, (new Point(e.X, e.Y)));
			Invalidate(true);
		}

		private void pBoxFavorites_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			contextMenuFavorites.Show(pBoxFavorites, (new Point(e.X, e.Y)));
			Invalidate(true);
		}

		private void pBoxHelp_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			contextMenuHelp.Show(pBoxHelp, (new Point(e.X, e.Y)));
			Invalidate(true);
		}

		private void pBoxHelp_MouseLeave(object sender, System.EventArgs e)
		{
			deactivatePictureBox(pBoxHelp);
		}

		private void pBoxFavorites_MouseLeave(object sender, System.EventArgs e)
		{
			deactivatePictureBox(pBoxFavorites);
		}

		private void pBoxMyAliases_MouseLeave(object sender, System.EventArgs e)
		{
			deactivatePictureBox(pBoxMyAliases);
		}

		private void pBoxAddinsAliases_MouseLeave(object sender, System.EventArgs e)
		{
			deactivatePictureBox(pBoxAddinsAliases);
		}

		private void pBoxOptions_MouseLeave(object sender, System.EventArgs e)
		{
			deactivatePictureBox(pBoxOptions);
		}

		private void deactivatePictureBox(PictureBox pb)
		{
			pb.Visible = false;
			label1.Text = "";
		}
		#endregion
		


		

		
		

		

	

		
	}

	
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
France France
I am an MCSD.NET and MCT. I give a lot of Microsoft Trainings (www.bdcworld.com) in France.

Comments and Discussions