using System;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
using XtremeCommandBars;

namespace RibbonSample
{
	internal class frmMain : System.Windows.Forms.Form
	{
	#region Windows Form Designer generated code 
		public frmMain() : base()
		{
			//This call is required by the Windows Form Designer.
			InitializeComponent();
		}
		//Form overrides dispose to clean up the component list.
		protected override void Dispose(bool Disposing)
		{
			if (Disposing)
			{
				if (components != null)
					components.Dispose();
			}
			base.Dispose(Disposing);
		}
		//Required by the Windows Form Designer
		private System.ComponentModel.IContainer components;
		public System.Windows.Forms.ToolTip ToolTip1;
		private System.Windows.Forms.RichTextBox txtClient;
		private AxXtremeCommandBars.AxImageManager ImageManagerGalleryStyles;
		public AxXtremeCommandBars.AxCommandBars CommandBars;
		//NOTE: The following procedure is required by the Windows Form Designer
		//It can be modified using the Windows Form Designer.
		//Do not modify it using the code editor.
		[System.Diagnostics.DebuggerStepThrough()]
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmMain));
			this.ToolTip1 = new System.Windows.Forms.ToolTip(this.components);
			this.CommandBars = new AxXtremeCommandBars.AxCommandBars();
			this.txtClient = new System.Windows.Forms.RichTextBox();
			this.ImageManagerGalleryStyles = new AxXtremeCommandBars.AxImageManager();
			((System.ComponentModel.ISupportInitialize)(this.CommandBars)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.ImageManagerGalleryStyles)).BeginInit();
			this.SuspendLayout();
			// 
			// CommandBars
			// 
			this.CommandBars.Enabled = true;
			this.CommandBars.Location = new System.Drawing.Point(16, 8);
			this.CommandBars.Name = "CommandBars";
			this.CommandBars.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("CommandBars.OcxState")));
			this.CommandBars.Size = new System.Drawing.Size(24, 24);
			this.CommandBars.TabIndex = 1;
			this.CommandBars.ResizeEvent += new System.EventHandler(this.CommandBars_ResizeEvent);
			this.CommandBars.Execute += new AxXtremeCommandBars._DCommandBarsEvents_ExecuteEventHandler(this.CommandBars_Execute);
			this.CommandBars.Customization += new AxXtremeCommandBars._DCommandBarsEvents_CustomizationEventHandler(this.CommandBars_Customization);
			this.CommandBars.UpdateEvent += new AxXtremeCommandBars._DCommandBarsEvents_UpdateEventHandler(this.CommandBars_UpdateEvent);
			this.CommandBars.ResizeClient += new AxXtremeCommandBars._DCommandBarsEvents_ResizeClientEventHandler(this.CommandBars_ResizeClient);
			// 
			// txtClient
			// 
			this.txtClient.Location = new System.Drawing.Point(128, 72);
			this.txtClient.Name = "txtClient";
			this.txtClient.Size = new System.Drawing.Size(592, 376);
			this.txtClient.TabIndex = 2;
			this.txtClient.Text = "";
			this.txtClient.MouseUp += new System.Windows.Forms.MouseEventHandler(this.txtClient_MouseUp);
			// 
			// ImageManagerGalleryStyles
			// 
			this.ImageManagerGalleryStyles.Enabled = true;
			this.ImageManagerGalleryStyles.Location = new System.Drawing.Point(64, 8);
			this.ImageManagerGalleryStyles.Name = "ImageManagerGalleryStyles";
			this.ImageManagerGalleryStyles.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("ImageManagerGalleryStyles.OcxState")));
			this.ImageManagerGalleryStyles.Size = new System.Drawing.Size(24, 24);
			this.ImageManagerGalleryStyles.TabIndex = 3;
			// 
			// frmMain
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(960, 551);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.ImageManagerGalleryStyles,
																		  this.txtClient,
																		  this.CommandBars});
			this.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Location = new System.Drawing.Point(4, 23);
			this.Name = "frmMain";
			this.Text = "RibbonBar Sample";
			this.Load += new System.EventHandler(this.frmMain_Load);
			this.Closed += new System.EventHandler(this.frmMain_Closed);
			((System.ComponentModel.ISupportInitialize)(this.CommandBars)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.ImageManagerGalleryStyles)).EndInit();
			this.ResumeLayout(false);

		}
	#endregion

        // Test code

        private Bitmap DrawFirst()
        {
            Bitmap bmp = new Bitmap(50, 50);
            Graphics gfx = Graphics.FromImage(bmp);
            gfx.DrawLine(new Pen(Color.Black), 5, 5, 45, 45);
            gfx.Dispose();
            return bmp;
        }

        private Bitmap DrawSecond()
        {
            Bitmap bmp = new Bitmap(50, 50);
            Graphics gfx = Graphics.FromImage(bmp);
            gfx.DrawLine(new Pen(Color.Red), 5, 45, 45, 5);
            gfx.Dispose();
            return bmp;
        }
        // ---

		private bool bShowTableContextTabs;
		private bool bShowChartContextTabs;
		public Point CurrentMousePosition;
		private int SelectedStyle;
		int[] FontSizes = new int[] {0, 11, 13, 16};

		public XtremeCommandBars.CommandBarGalleryItems ItemsStyles;
		public XtremeCommandBars.CommandBarGalleryItems GalleryShapeItems;
		public XtremeCommandBars.CommandBarGalleryItems GalleryColorItems;
		public XtremeCommandBars.CommandBarGalleryItems GalleryLargeColorItems;
		public XtremeCommandBars.CommandBarsGlobalSettings CommandBarsGlobalSettings;

		private XtremeCommandBars.RibbonBar RibbonBar()
		{
			return (XtremeCommandBars.RibbonBar)CommandBars.ActiveMenuBar;
		}

		private void CommandBars_Customization(object eventSender, AxXtremeCommandBars._DCommandBarsEvents_CustomizationEvent eventArgs)
		{
			eventArgs.options.ShowRibbonQuickAccessPage = true;

			XtremeCommandBars.CommandBarControls cmbControls = null;
			cmbControls = CommandBars.DesignerControls;
			XtremeCommandBars.CommandBarControl cmbControl = null;

			if (cmbControls.Count == 0)
			{
				string tempCaption1 = "&New";
				bool tempBeginGroup2 = false;
				string tempDescriptionText3 = "Create a new document";
				string tempCategory4 = "File";
				cmbControl = cmbControls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_FILE_NEW, tempCaption1, tempBeginGroup2, tempDescriptionText3);
				cmbControl.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonAutomatic;
				cmbControl.Category = tempCategory4;

				string tempCaption5 = "&Open";
				bool tempBeginGroup6 = false;
				string tempDescriptionText7 = "Open an existing document";
				cmbControl = cmbControls.Add(XtremeCommandBars.XTPControlType.xtpControlButton,  ID.ID_FILE_OPEN,  tempCaption5,  tempBeginGroup6,  tempDescriptionText7);
				cmbControl.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonAutomatic;
				cmbControl.Category = tempCategory4;

				string tempCaption9 = "&Save";
				bool tempBeginGroup10 = false;
				string tempDescriptionText11 = "Save the active document";
				cmbControl = cmbControls.Add(XtremeCommandBars.XTPControlType.xtpControlButton,  ID.ID_FILE_SAVE,  tempCaption9,  tempBeginGroup10,  tempDescriptionText11);
				cmbControl.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonAutomatic;
				cmbControl.Category = tempCategory4;

				string tempCaption13 = "&Print";
				bool tempBeginGroup14 = false;
				string tempDescriptionText15 = "Print the active document";
				cmbControl = cmbControls.Add(XtremeCommandBars.XTPControlType.xtpControlButton,  ID.ID_FILE_PRINT,  tempCaption13,  tempBeginGroup14,  tempDescriptionText15);
				cmbControl.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonAutomatic;
				cmbControl.Category = tempCategory4;

				string tempCaption17 = "Print Set&up";
				bool tempBeginGroup18 = false;
				string tempDescriptionText19 = "Print Setup";
				cmbControl = cmbControls.Add(XtremeCommandBars.XTPControlType.xtpControlButton,  ID.ID_FILE_PRINT_SETUP,  tempCaption17,  tempBeginGroup18,  tempDescriptionText19);
				cmbControl.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonAutomatic;
				cmbControl.Category = tempCategory4;

				string tempCaption21 = "Cu&t";
				bool tempBeginGroup22 = false;
				string tempDescriptionText23 = "Cut the selection and put it on the Clipboard";
				string tempCategory24 = "Edit";
				cmbControl = cmbControls.Add(XtremeCommandBars.XTPControlType.xtpControlButton,  ID.ID_EDIT_CUT,  tempCaption21,  tempBeginGroup22,  tempDescriptionText23);
				cmbControl.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonAutomatic;
				cmbControl.Category = tempCategory4;

				string tempCaption25 = "&Copy";
				bool tempBeginGroup26 = false;
				string tempDescriptionText27 = "Copy the selection and put it on the Clipboard";
				cmbControl = cmbControls.Add(XtremeCommandBars.XTPControlType.xtpControlButton,  ID.ID_EDIT_COPY,  tempCaption25,  tempBeginGroup26,  tempDescriptionText27);
				cmbControl.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonAutomatic;
				cmbControl.Category = tempCategory24;

				string tempCaption29 = "&Paste";
				bool tempBeginGroup30 = false;
				string tempDescriptionText31 = "Insert Clipboard contents";
				cmbControl = cmbControls.Add(XtremeCommandBars.XTPControlType.xtpControlButton,  ID.ID_EDIT_PASTE,  tempCaption29,  tempBeginGroup30,  tempDescriptionText31);
				cmbControl.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonAutomatic;
				cmbControl.Category = tempCategory24;

				string tempCaption33 = "Bold";
				bool tempBeginGroup34 = false;
				string tempDescriptionText35 = "";
				string tempCategory36 = "Format";
				cmbControl = cmbControls.Add(XtremeCommandBars.XTPControlType.xtpControlButton,  ID.ID_CHAR_BOLD,  tempCaption33,  tempBeginGroup34,  tempDescriptionText35);
				cmbControl.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonAutomatic;
				cmbControl.Category = tempCategory24;

				string tempCaption37 = "Italic";
				bool tempBeginGroup38 = false;
				string tempDescriptionText39 = "";
				cmbControl = cmbControls.Add(XtremeCommandBars.XTPControlType.xtpControlButton,  ID.ID_CHAR_ITALIC,  tempCaption37,  tempBeginGroup38,  tempDescriptionText39);
				cmbControl.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonAutomatic;
				cmbControl.Category = tempCategory36;

				string tempCaption41 = "Underline";
				bool tempBeginGroup42 = false;
				string tempDescriptionText43 = "";
				cmbControl = cmbControls.Add(XtremeCommandBars.XTPControlType.xtpControlButton,  ID.ID_CHAR_UNDERLINE,  tempCaption41,  tempBeginGroup42,  tempDescriptionText43);
				cmbControl.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonAutomatic;
				cmbControl.Category = tempCategory36;

				string tempCaption45 = "Align Left";
				bool tempBeginGroup46 = false;
				string tempDescriptionText47 = "";
				cmbControl = cmbControls.Add(XtremeCommandBars.XTPControlType.xtpControlButton,  ID.ID_PARA_LEFT,  tempCaption45,  tempBeginGroup46,  tempDescriptionText47);
				cmbControl.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonAutomatic;
				cmbControl.Category = tempCategory36;

				string tempCaption49 = "Center";
				bool tempBeginGroup50 = false;
				string tempDescriptionText51 = "";
				cmbControl = cmbControls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_PARA_CENTER, tempCaption49, tempBeginGroup50, tempDescriptionText51);
				cmbControl.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonAutomatic;
				cmbControl.Category = tempCategory36;

				string tempCaption53 = "Align Right";
				bool tempBeginGroup54 = false;
				string tempDescriptionText55 = "";
				cmbControl = cmbControls.Add(XtremeCommandBars.XTPControlType.xtpControlButton,  ID.ID_PARA_RIGHT,  tempCaption53,  tempBeginGroup54,  tempDescriptionText55);
				cmbControl.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonAutomatic;
				cmbControl.Category = tempCategory36;

				string tempCaption57 = "About";
				bool tempBeginGroup58 = false;
				string tempDescriptionText59 = "";
				string tempCategory60 = "Help";
				cmbControl = cmbControls.Add(XtremeCommandBars.XTPControlType.xtpControlButton,  ID.ID_APP_ABOUT,  tempCaption57,  tempBeginGroup58,  tempDescriptionText59);
				cmbControl.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonAutomatic;
				cmbControl.Category = tempCategory60;
			}
		}

		private void CommandBars_Execute(object eventSender, AxXtremeCommandBars._DCommandBarsEvents_ExecuteEvent eventArgs)
		{

			switch (eventArgs.control.Id)
			{	
                case 19999:
                    MessageBox.Show("Please look in gallery\nAfter 5 second icons will change");
                    Timer timer = new Timer();
			        timer.Interval = 5000;
			        timer.Tick += delegate
			                          {
			                              gal.Items.Icons.RemoveIcon(1);
			                              gal.Items.Icons.RemoveIcon(2);
			                              gal.Items.Icons.RemoveIcon(3);
			                              gal.Items.Icons.AddBitmap(DrawSecond().GetHbitmap().ToInt32(), 1,
			                                                        XTPImageState.xtpImageNormal, false);
			                              gal.Items.Icons.AddBitmap(DrawSecond().GetHbitmap().ToInt32(), 2,
			                                                        XTPImageState.xtpImageNormal, false);
			                              gal.Items.Icons.AddBitmap(DrawSecond().GetHbitmap().ToInt32(), 3,
			                                                        XTPImageState.xtpImageNormal, false);
                                          timer.Stop();
			                          };
                    timer.Start();
                    
			        break;
				case (int)XtremeCommandBars.XTPCommandBarsSpecialCommands.XTP_ID_RIBBONCUSTOMIZE:
					CommandBars.ShowCustomizeDialog(3);
					break;
				case ID.ID_APP_ABOUT:
					CommandBars.AboutBox();
					break;
				case ID.ID_THEME_OFFICE2003:
					CommandBars.VisualTheme = XtremeCommandBars.XTPVisualTheme.xtpThemeOffice2003;
					CommandBars.ToolTipContext.Style = XtremeCommandBars.XTPToolTipStyle.xtpToolTipLuna;
					break;
				case ID.ID_THEME_OFFICE2007:
					CommandBars.VisualTheme = XtremeCommandBars.XTPVisualTheme.xtpThemeOffice2007;
					CommandBars.ToolTipContext.Style = XtremeCommandBars.XTPToolTipStyle.xtpToolTipOffice2007;
					break;
				case ID.ID_CHAR_BOLD:
					txtClient.SelectionFont = new Font(txtClient.Font.FontFamily, txtClient.Font.Size, txtClient.SelectionFont.Style ^ System.Drawing.FontStyle.Bold);
					break;
				case ID.ID_CHAR_ITALIC:
					txtClient.SelectionFont = new Font(txtClient.Font.FontFamily, txtClient.Font.Size, txtClient.SelectionFont.Style ^ System.Drawing.FontStyle.Italic);
					break;
				case ID.ID_CHAR_UNDERLINE:
					txtClient.SelectionFont = new Font(txtClient.Font.FontFamily, txtClient.Font.Size, txtClient.SelectionFont.Style ^ System.Drawing.FontStyle.Underline);
					break;
				case ID.ID_PARA_LEFT:
					txtClient.SelectionAlignment = HorizontalAlignment.Left;
					break;
				case ID.ID_PARA_CENTER:
					txtClient.SelectionAlignment = HorizontalAlignment.Center;
					break;
				case ID.ID_PARA_RIGHT:
					txtClient.SelectionAlignment = HorizontalAlignment.Right;
					break;
				case ID.ID_APP_EXIT:
					this.Close();
					break;
				case ID.ID_VIEW_RULER: 
				case ID.ID_VIEW_ACTINBAR: 
				case ID.ID_VIEW_GRIDLINES: 
				case ID.ID_VIEW_PROPERTIES:
				case ID.ID_VIEW_DOCUMENTMAP:
				case ID.ID_VIEW_THUMBNAILS:
					eventArgs.control.Checked = !eventArgs.control.Checked;
					break;
				case ID.ID_ILLUSTRATION_CHART:
					bShowChartContextTabs = !bShowChartContextTabs;
					break;
				case ID.ID_TABLE_NEW:
				case ID.ID_TABLE_INSERTTABLE:
					bShowTableContextTabs = !bShowTableContextTabs;
					break;
				case (int)XtremeCommandBars.XTPCommandBarsSpecialCommands.XTP_ID_RIBBONCONTROLTAB:
					System.Diagnostics.Debug.WriteLine("Selected Tab has Changed");
					break;
				case ID.ID_GALLERY_STYLES:
					XtremeCommandBars.ICommandBarGallery Gallery;
					Gallery = eventArgs.control as XtremeCommandBars.ICommandBarGallery;
            		
					if (Gallery.SelectedItem != null)
					{
						SelectedStyle = Gallery.SelectedItem.Id;
					}						
					break;
				case ID.ID_OPTIONS_STYLEBLACK:
					{
						CommandBarsGlobalSettings = new XtremeCommandBars.CommandBarsGlobalSettings();
						string stylesDir = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\..\\Styles\\";
						CommandBarsGlobalSettings.Office2007Images = stylesDir + "Office2007Black.dll";
						CommandBars.PaintManager.RefreshMetrics();
						CommandBars.RecalcLayout();
					}
					break;
				case ID.ID_OPTIONS_STYLEBLUE:
					CommandBarsGlobalSettings = new XtremeCommandBars.CommandBarsGlobalSettings();
					CommandBarsGlobalSettings.Office2007Images = "";
					CommandBars.PaintManager.RefreshMetrics();
					CommandBars.RecalcLayout();
					break;
				case ID.ID_OPTIONS_STYLEAQUA:
					{
						CommandBarsGlobalSettings = new XtremeCommandBars.CommandBarsGlobalSettings();
						string stylesDir = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\..\\Styles\\";
						CommandBarsGlobalSettings.Office2007Images =  stylesDir + "Office2007Aqua.dll";
						CommandBars.PaintManager.RefreshMetrics();
						CommandBars.RecalcLayout();
					}
					break;
				case ID.ID_OPTIONS_STYLESILVER:
					{
						CommandBarsGlobalSettings = new XtremeCommandBars.CommandBarsGlobalSettings();
						string stylesDir = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\..\\Styles\\";
						CommandBarsGlobalSettings.Office2007Images =  stylesDir + "Office2007Silver.dll";
						CommandBars.PaintManager.RefreshMetrics();
						CommandBars.RecalcLayout();
					}
					break;
				case ID.ID_OPTIONS_ANIMATION:
					RibbonBar().EnableAnimation = (RibbonBar().EnableAnimation == true ? false : true);
					break;
				case ID.ID_OPTIONS_RTL:			
					CommandBars.CtlRightToLeft = (CommandBars.CtlRightToLeft == true ? false : true);
					CommandBars.RecalcLayout();
					break;
				case ID.ID_TEXT_HIGHLIGHTCOLORSELECTOR:
					XtremeCommandBars.CommandBarControlColorSelector ColorControlSelector = (XtremeCommandBars.CommandBarControlColorSelector)eventArgs.control;
					txtClient.SelectionColor = System.Drawing.ColorTranslator.FromOle((int)ColorControlSelector.Color);
					break;
				case ID.ID_TEXT_HIGHLIGHTCOLOR:
					XtremeCommandBars.CommandBarPopupColor ColorControl = (XtremeCommandBars.CommandBarPopupColor)eventArgs.control;
					txtClient.SelectionColor = System.Drawing.ColorTranslator.FromOle((int)ColorControl.Color);
					break;
				case ID.ID_PARA_INDENTLEFT:
				case ID.ID_PARA_INDENTRIGHT:
				case ID.ID_PARA_SPACINGBEFORE:
				case ID.ID_PARA_SPACINGAFTER:
					break;
				case ID.ID_OPTIONS_FONT_SYSTEM: 
				case ID.ID_OPTIONS_FONT_NORMAL: 
				case ID.ID_OPTIONS_FONT_LARGE: 
				case ID.ID_OPTIONS_FONT_EXTRALARGE:
					int newFontHeight = FontSizes[eventArgs.control.Id - ID.ID_OPTIONS_FONT_SYSTEM];
					RibbonBar().FontHeight = newFontHeight;
					break;
				case ID.ID_OPTIONS_FONT_AUTORESIZEICONS:					
					CommandBars.PaintManager.AutoResizeIcons = !CommandBars.PaintManager.AutoResizeIcons;
					CommandBars.RecalcLayout();
					RibbonBar().RedrawBar();
					break;
				default:
					MessageBox.Show(eventArgs.control.Caption + " clicked", "Button Clicked");
					break;	
			};
		}

		private void CommandBars_ResizeEvent(object sender, System.EventArgs e)
		{
			int left = 0;
			int top = 0;
			int right = 0;
			int bottom = 0;
			CommandBars.GetClientRect(out left, out top, out right, out bottom);
			txtClient.SetBounds(left + 30, top + 30, right - left - 60, bottom - top - 60);
		}

		private void CommandBars_UpdateEvent(object eventSender, AxXtremeCommandBars._DCommandBarsEvents_UpdateEvent eventArgs)
		{
			switch (eventArgs.control.Id)
			{	
				case ID.ID_THEME_OFFICE2003:
					eventArgs.control.Checked = CommandBars.VisualTheme == XtremeCommandBars.XTPVisualTheme.xtpThemeOffice2003;
					break;
				case ID.ID_THEME_OFFICE2007:
					eventArgs.control.Checked = CommandBars.VisualTheme == XtremeCommandBars.XTPVisualTheme.xtpThemeOffice2007;
					break;
				case ID.ID_CHAR_BOLD:
					eventArgs.control.Checked = txtClient.SelectionFont.Bold;
					break;
				case ID.ID_CHAR_ITALIC:
					eventArgs.control.Checked = txtClient.SelectionFont.Italic;
					break;
				case ID.ID_CHAR_UNDERLINE:
					eventArgs.control.Checked = txtClient.SelectionFont.Underline;
					break;
				case ID.ID_PARA_LEFT:
					eventArgs.control.Checked = txtClient.SelectionAlignment == HorizontalAlignment.Left;
					break;
				case ID.ID_PARA_CENTER:
					eventArgs.control.Checked = txtClient.SelectionAlignment == HorizontalAlignment.Center;
					break;
				case ID.ID_PARA_RIGHT:
					eventArgs.control.Checked = txtClient.SelectionAlignment == HorizontalAlignment.Right;
					break;
				case ID.ID_EDIT_CUT:
					eventArgs.control.Enabled = ! (txtClient.SelectionLength == 0);
					break;
				case ID.ID_EDIT_COPY:
					eventArgs.control.Enabled = ! (txtClient.SelectionLength == 0);
					break;
				case (int)XtremeCommandBars.XTPCommandBarsSpecialCommands.XTP_ID_RIBBONCONTROLTAB:
					RibbonBar().FindTab(ID.ID_TAB_TABLEDESIGN).Visible = bShowTableContextTabs;
					RibbonBar().FindTab(ID.ID_TAB_TABLELAYOUT).Visible = bShowTableContextTabs;

					RibbonBar().FindTab(ID.ID_TAB_CHARTDESIGN).Visible = bShowChartContextTabs;
					RibbonBar().FindTab(ID.ID_TAB_CHARTLAYOUT).Visible = bShowChartContextTabs;
					RibbonBar().FindTab(ID.ID_TAB_CHARTFORMAT).Visible = bShowChartContextTabs;
					break;
				case ID.ID_OPTIONS_ANIMATION:
					eventArgs.control.Checked = CommandBars.ActiveMenuBar.EnableAnimation;
					break;
				case ID.ID_OPTIONS_RTL:
					eventArgs.control.Checked =	CommandBars.CtlRightToLeft;
					break;
				case ID.ID_GALLERY_STYLES:
					XtremeCommandBars.CommandBarGallery Gallery;
					Gallery = (XtremeCommandBars.CommandBarGallery)eventArgs.control;
					Gallery.CheckedItem = SelectedStyle;
					break;
				case ID.ID_TEXT_HIGHLIGHTCOLORSELECTOR:
					XtremeCommandBars.CommandBarControlColorSelector ColorControlSelector = 
						eventArgs.control as XtremeCommandBars.CommandBarControlColorSelector;
					if (ColorControlSelector != null) ColorControlSelector.Color = (txtClient.SelectionColor != System.Drawing.Color.Black ? (uint)System.Drawing.ColorTranslator.ToOle(txtClient.SelectionColor) : 0);
					break;
				case ID.ID_TEXT_HIGHLIGHTCOLOR:
					XtremeCommandBars.CommandBarPopupColor ColorControl =
						eventArgs.control as XtremeCommandBars.CommandBarPopupColor;
					if (ColorControl != null) ColorControl.Color = (uint)System.Drawing.ColorTranslator.ToOle(txtClient.SelectionColor);
					break;
				case ID.ID_OPTIONS_FONT_SYSTEM: 
				case ID.ID_OPTIONS_FONT_NORMAL: 
				case ID.ID_OPTIONS_FONT_LARGE: 
				case ID.ID_OPTIONS_FONT_EXTRALARGE:
					int newFontHeight = FontSizes[eventArgs.control.Id - ID.ID_OPTIONS_FONT_SYSTEM];
					eventArgs.control.Checked = (RibbonBar().FontHeight == newFontHeight ? true : false);
					break;
				case ID.ID_OPTIONS_FONT_AUTORESIZEICONS:					
					eventArgs.control.Checked = CommandBars.PaintManager.AutoResizeIcons;
					break;
			};
			
		}

		private void frmMain_Load(object eventSender, System.EventArgs eventArgs)
		{
			LoadIcons();
			CreateRibbonBar();

			CommandBars.KeyBindings.Add(ID.FCONTROL, System.Convert.ToInt32('N'), ID.ID_FILE_NEW);
			CommandBars.KeyBindings.Add(ID.FCONTROL, System.Convert.ToInt32('O'), ID.ID_FILE_OPEN);
			CommandBars.KeyBindings.Add(ID.FCONTROL, System.Convert.ToInt32('S'), ID.ID_FILE_SAVE);
			CommandBars.KeyBindings.Add(ID.FCONTROL, System.Convert.ToInt32('X'), ID.ID_EDIT_CUT);
			CommandBars.KeyBindings.Add(ID.FCONTROL, System.Convert.ToInt32('C'), ID.ID_EDIT_COPY);
			CommandBars.KeyBindings.Add(ID.FCONTROL, System.Convert.ToInt32('V'), ID.ID_EDIT_PASTE);



			XtremeCommandBars.StatusBar StatusBar = null;
			StatusBar = CommandBars.StatusBar;
			StatusBar.Visible = true;

			StatusBar.AddPane(0);
			StatusBar.AddPane(ID.ID_INDICATOR_CAPS);
			StatusBar.AddPane(ID.ID_INDICATOR_NUM);
			StatusBar.AddPane(ID.ID_INDICATOR_SCRL);

			RibbonBar().EnableFrameTheme();

			CommandBars.Options.KeyboardCuesShow = XtremeCommandBars.XTPKeyboardCuesShow.xtpKeyboardCuesShowWindowsDefault;

			bShowTableContextTabs = false;
			bShowChartContextTabs = false;

			CommandBars.EnableCustomization(true);
			CommandBars.LoadCommandBars("Codejock Software ActiveX Demos", System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, "Layout");

		}

		public string ResourcePath()
		{
			string strExePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);

			if (System.IO.Directory.Exists(strExePath + "\\..\\res"))
				return strExePath + "\\..\\res\\";

			if (System.IO.Directory.Exists(strExePath + "\\..\\..\\res"))
				return strExePath + "\\..\\..\\res\\";

			return strExePath + "\\res\\";
		}

		private void LoadIcons()
		{
			CommandBars.Options.UseSharedImageList = false;

			string resDir = ResourcePath();

			CommandBars.Icons.LoadBitmap(resDir + "GroupIcons.bmp", new int[] {ID.ID_GROUP_CLIPBOARD, ID.ID_GROUP_FONT, ID.ID_GROUP_PARAGRAPH, ID.ID_GROUP_FIND}, XtremeCommandBars.XTPImageState.xtpImageNormal);
			CommandBars.Icons.LoadBitmap(resDir + "GroupParagraph.bmp", new int[] {ID.ID_INSERT_BULLET, ID.ID_INSERT_NUMBERING, ID.ID_INSERT_LIST, ID.ID_PARA_DECREASEINDENT, ID.ID_PARA_INCREASEINDENT, ID.ID_PARA_SORT, ID.ID_PARA_SHOWMARKS, ID.ID_PARA_LEFT, ID.ID_PARA_CENTER, ID.ID_PARA_RIGHT, ID.ID_PARA_JUSTIFY, ID.ID_PARA_LINESPACING, ID.ID_PARA_SHADING, ID.ID_BORDERS_NOBORDER}, XtremeCommandBars.XTPImageState.xtpImageNormal);
			CommandBars.Icons.LoadBitmap(resDir + "GroupClipboard.bmp", new int[] {ID.ID_EDIT_PASTE, ID.ID_EDIT_CUT, ID.ID_EDIT_COPY, ID.ID_FORMAT_PAINTER}, XtremeCommandBars.XTPImageState.xtpImageNormal);
			CommandBars.Icons.LoadBitmap(resDir + "GroupFont.bmp", new int[] {ID.ID_FONT_GROW, ID.ID_FONT_SHRINK, ID.ID_FONT_CLEAR, ID.ID_CHAR_BOLD, ID.ID_CHAR_ITALIC, ID.ID_CHAR_UNDERLINE, ID.ID_CHAR_STRIKETHROUGH, ID.ID_TEXT_SUBSCRIPT, ID.ID_TEXT_SUPERSCRIPT, ID.ID_TEXT_CHANGECASE, ID.ID_TEXT_COLOR, ID.ID_TEXT_HIGHLIGHTCOLOR}, XtremeCommandBars.XTPImageState.xtpImageNormal);
			CommandBars.Icons.LoadBitmap(resDir + "GroupFind.bmp", new int[] {ID.ID_EDIT_FIND, ID.ID_EDIT_REPLACE, ID.ID_EDIT_GOTO, ID.ID_EDIT_SELECT}, XtremeCommandBars.XTPImageState.xtpImageNormal);
			CommandBars.Icons.LoadBitmap(resDir + "InsertTab.bmp", new int[] {ID.ID_PAGES_NEW, ID.ID_PAGES_COVER, ID.ID_PAGES_BREAK, ID.ID_INSERT_HEADER, ID.ID_INSERT_FOOTER, ID.ID_INSERT_PAGENUMBER, ID.ID_TEXT_PARTS, ID.ID_TEXT_WORDART, ID.ID_TEXT_DROPCAP, ID.ID_ILLUSTRATION_GRAPHIC, ID.ID_ILLUSTRATION_CLIPART, ID.ID_ILLUSTRATION_CLIPART, ID.ID_ILLUSTRATION_CHART, ID.ID_INSERT_HYPERLINK, ID.ID_INSERT_BOOKMARK, ID.ID_INSERT_CROSS_REFERENCE, ID.ID_TEXT_SIGNATURE, ID.ID_TEXT_DATETIME, ID.ID_TEXT_INSERTOBJECT}, XtremeCommandBars.XTPImageState.xtpImageNormal);
			CommandBars.Icons.LoadBitmap(resDir + "SmallIcons.bmp", new int[] {ID.ID_FILE_NEW, ID.ID_FILE_OPEN, ID.ID_FILE_SAVE, ID.ID_EDIT_CUT, ID.ID_EDIT_COPY, ID.ID_EDIT_PASTE, ID.ID_FILE_PRINT, ID.ID_APP_ABOUT}, XtremeCommandBars.XTPImageState.xtpImageNormal);
			CommandBars.Icons.LoadBitmap(resDir + "LargeIcons.bmp", new int[] {ID.ID_EDIT_PASTE, ID.ID_EDIT_FIND, ID.ID_PAGES_NEW, ID.ID_PAGES_COVER, ID.ID_PAGES_BREAK, ID.ID_TABLE_NEW, ID.ID_ILLUSTRATION_PICTURE, ID.ID_ILLUSTRATION_GRAPHIC, ID.ID_ILLUSTRATION_CHART, ID.ID_INSERT_HEADER, ID.ID_INSERT_FOOTER, ID.ID_INSERT_PAGENUMBER, ID.ID_TEXT_TEXTBOX, ID.ID_TEXT_PARTS, ID.ID_TEXT_WORDART, ID.ID_TEXT_DROPCAP, ID.ID_SYMBOL_EQUATIONS, ID.ID_SYMBOL_SYMBOL}, XtremeCommandBars.XTPImageState.xtpImageNormal);
			CommandBars.Icons.LoadBitmap(resDir + "LayoutTabLarge.bmp", new int[] {ID.ID_THEMES_THEMES, ID.ID_PAGE_MARGINS, ID.ID_PAGE_ORIENTATION, ID.ID_PAGE_SIZE, ID.ID_PAGE_COLUMNS, ID.ID_PAGE_WATERMARK, ID.ID_PAGE_COLOR, ID.ID_PAGE_BORDERS, ID.ID_ARRANGE_POSITION, ID.ID_ARRANGE_TEXTWRAPPING}, XtremeCommandBars.XTPImageState.xtpImageNormal);
			CommandBars.Icons.LoadBitmap(resDir + "LayoutTab.bmp", new int[] {ID.ID_THEMES_COLORS, ID.ID_THEMES_FONTS, ID.ID_THEMES_EFFECTS, ID.ID_PAGE_ORIENTATION, ID.ID_PAGE_SIZE, ID.ID_PAGE_COLUMNS, ID.ID_PAGE_BREAKS, ID.ID_PAGE_LINENUMBERS, ID.ID_PAGE_HYPHENATATION, ID.ID_PAGE_WATERMARK, ID.ID_PAGE_COLOR, ID.ID_PAGE_BORDERS, ID.ID_ARRANGE_FRONT, ID.ID_ARRANGE_BACK, ID.ID_ARRANGE_ALIGN, ID.ID_ARRANGE_GROUP, ID.ID_ARRANGE_UNGROUP, ID.ID_ARRANGE_ROTATE}, XtremeCommandBars.XTPImageState.xtpImageNormal);
			CommandBars.Icons.LoadBitmap(resDir + "shiny-gear.png", ID.ID_SYSTEM_ICON, XtremeCommandBars.XTPImageState.xtpImageNormal);
			CommandBars.Icons.LoadIcon(resDir + "GroupPopup.ico", ID.ID_GROUP_POPUPICON, XtremeCommandBars.XTPImageState.xtpImageNormal);
			CommandBars.Icons.LoadBitmap(resDir + "GroupPageParagraph.png", new int[] {ID.ID_PARA_INDENTLEFT, ID.ID_PARA_INDENTRIGHT, ID.ID_PARA_SPACINGBEFORE, ID.ID_PARA_SPACINGAFTER}, XtremeCommandBars.XTPImageState.xtpImageNormal);

			XtremeCommandBars.ToolTipContext ToolTipContext = null;
			ToolTipContext = CommandBars.ToolTipContext;
			ToolTipContext.Style = XtremeCommandBars.XTPToolTipStyle.xtpToolTipOffice2007;
			ToolTipContext.ShowTitleAndDescription(true, XtremeCommandBars.XTPToolTipIcon.xtpToolTipIconNone);
			ToolTipContext.SetMargin(2, 2, 2, 2);
			ToolTipContext.MaxTipWidth = 180;
		}

	    private CommandBarGallery gal;
		private void CreateRibbonBar()
		{
			XtremeCommandBars.RibbonTab TabPageLayout = null;
			XtremeCommandBars.RibbonTab TabWrite = null;
			XtremeCommandBars.RibbonTab TabInsert = null;
			XtremeCommandBars.RibbonTab TabView = null;
			XtremeCommandBars.RibbonGroup GroupParagraph = null;
			XtremeCommandBars.RibbonGroup GroupPageParagraph = null;
			XtremeCommandBars.RibbonGroup GroupClipboard = null;
			XtremeCommandBars.RibbonGroup GroupFont = null;
			XtremeCommandBars.RibbonGroup GroupFormatting = null;
			XtremeCommandBars.RibbonGroup GroupTable = null;
			XtremeCommandBars.RibbonGroup GroupFind = null;
			XtremeCommandBars.RibbonGroup GroupPages = null;
			XtremeCommandBars.RibbonGroup GroupIllustrations = null;
			XtremeCommandBars.RibbonGroup GroupText = null;
			XtremeCommandBars.RibbonGroup GroupLinks = null;
			XtremeCommandBars.RibbonGroup GroupHeader = null;
			XtremeCommandBars.RibbonGroup GroupSymbols = null;
			XtremeCommandBars.RibbonGroup GroupStyles = null;
			XtremeCommandBars.RibbonGroup GroupShapes = null;
			XtremeCommandBars.RibbonGroup ViewGroup = null;
			XtremeCommandBars.RibbonTab ChartTabs = null;
			XtremeCommandBars.RibbonTab TableTabs = null;
			XtremeCommandBars.RibbonTab TabReview = null;
			XtremeCommandBars.CommandBarPopup ControlPaste = null;
			XtremeCommandBars.CommandBarControl Control = null;
			XtremeCommandBars.CommandBarPopup ControlSelect = null;
			XtremeCommandBars.CommandBarPopup ControlPicture = null;
			XtremeCommandBars.CommandBarPopup ControlNew = null;
			XtremeCommandBars.CommandBarPopup ControlCover = null;
			XtremeCommandBars.CommandBarPopup ControlPageNumber = null;
			XtremeCommandBars.CommandBarPopup ControlEquations = null;
			XtremeCommandBars.CommandBarPopup ControlTable = null;
			XtremeCommandBars.CommandBarPopup ControlDocumentParts = null;
			XtremeCommandBars.CommandBarPopup ControlTextBox = null;
			XtremeCommandBars.CommandBarPopup ControlPopup = null;
			XtremeCommandBars.CommandBarPopup ControlOptions = null;

			XtremeCommandBars.RibbonBar RibbonBar = null;
			RibbonBar = CommandBars.AddRibbonBar("The Ribbon");
			RibbonBar.EnableDocking(XtremeCommandBars.XTPToolBarFlags.xtpFlagStretched);

			XtremeCommandBars.CommandBarPopup ControlFile = null;
			XtremeCommandBars.CommandBarPopup ControlTheme = null;
			XtremeCommandBars.CommandBarControl ControlAbout = null;

			ControlFile = RibbonBar.AddSystemButton();
			ControlFile.IconId = ID.ID_SYSTEM_ICON;
			ControlFile.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_FILE_NEW, "&New", false, false);
			ControlFile.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_FILE_OPEN, "&Open...", false, false);
			ControlFile.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_FILE_SAVE, "&Save", false, false);
			ControlFile.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_FILE_SAVE_AS, "Save &As...", false, false);
			Control = ControlFile.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_FILE_PRINT, "&Print", false, false);
			Control.BeginGroup = true;
			ControlFile.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_FILE_PRINT_PREVIEW, "Print Pre&view", false, false);
			ControlFile.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_FILE_PRINT_SETUP, "Pr&int Setup...", false, false);
			Control = ControlFile.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_FILE_MRU_FILE1, "Recent File", false, false);
			Control.BeginGroup = true;
			Control.Enabled = false;
			Control = ControlFile.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_APP_EXIT, "E&xit", false, false);
			Control.BeginGroup = true;

			ControlOptions = (XtremeCommandBars.CommandBarPopup)RibbonBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, 0, "Options", -1, false);
			ControlOptions.Flags = XtremeCommandBars.XTPControlFlags.xtpFlagRightAlign;

			ControlPopup = (XtremeCommandBars.CommandBarPopup)ControlOptions.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, 0, "Styles", -1, false);
			ControlPopup.CommandBar.Controls.Add (XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_OPTIONS_STYLEBLUE, "Luna (blue)", -1, false);
			ControlPopup.CommandBar.Controls.Add (XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_OPTIONS_STYLEBLACK, "Obsidian (black)", -1, false);
			ControlPopup.CommandBar.Controls.Add (XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_OPTIONS_STYLESILVER, "Silver", -1, false);
			ControlPopup.CommandBar.Controls.Add (XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_OPTIONS_STYLEAQUA, "Office 12 (aqua)", -1, false);

			ControlPopup = (XtremeCommandBars.CommandBarPopup)ControlOptions.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, 0, "Font", -1, false);
			ControlPopup.CommandBar.Controls.Add (XtremeCommandBars.XTPControlType.xtpControlRadioButton, ID.ID_OPTIONS_FONT_SYSTEM, "System Default", -1, false);			
			Control = ControlPopup.CommandBar.Controls.Add (XtremeCommandBars.XTPControlType.xtpControlRadioButton, ID.ID_OPTIONS_FONT_NORMAL, "Normal", -1, false);
			Control.BeginGroup = true;
			ControlPopup.CommandBar.Controls.Add (XtremeCommandBars.XTPControlType.xtpControlRadioButton, ID.ID_OPTIONS_FONT_LARGE, "Large", -1, false);
			ControlPopup.CommandBar.Controls.Add (XtremeCommandBars.XTPControlType.xtpControlRadioButton, ID.ID_OPTIONS_FONT_EXTRALARGE, "Extra Large", -1, false);
			Control = ControlPopup.CommandBar.Controls.Add (XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_OPTIONS_FONT_AUTORESIZEICONS, "Auto Resize Icons", -1, false);
			Control.BeginGroup = true;

			ControlOptions.CommandBar.Controls.Add (XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_OPTIONS_RTL, "Right To Left", -1, false);
			ControlOptions.CommandBar.Controls.Add (XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_OPTIONS_ANIMATION, "Animation", -1, false);


			ControlAbout = RibbonBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_APP_ABOUT, "&About", false, false);
			ControlAbout.Flags = XtremeCommandBars.XTPControlFlags.xtpFlagRightAlign;

            // Test code
		    RibbonTab TestTab = RibbonBar.InsertTab(-1, "TEST");
		    RibbonGroup TestGroup = TestTab.Groups.AddGroup("test", 0);
            CommandBarPopup b1 = (CommandBarPopup)TestGroup.Add(XTPControlType.xtpControlButtonPopup, 0, "test1", false, false);
            CommandBarButton b2 = (CommandBarButton)TestGroup.Add(XTPControlType.xtpControlButton, 19999, "test2", false, false);

            gal = (CommandBarGallery)b1.CommandBar.Controls.Add(XTPControlType.xtpControlGallery, 1, "", false, false);
            gal.Items = CommandBars.CreateGalleryItems(1901);
            gal.Items.ItemWidth = 50;
            gal.Items.ItemHeight = 50;
            gal.Items.AddItem(1, "first");
            gal.Items.AddItem(2, "second");
            gal.Items.AddItem(3, "third");
            gal.Items.Icons.AddBitmap(DrawFirst().GetHbitmap().ToInt32(), 1, XTPImageState.xtpImageNormal, false);
            gal.Items.Icons.AddBitmap(DrawFirst().GetHbitmap().ToInt32(), 2, XTPImageState.xtpImageNormal, false);
            gal.Items.Icons.AddBitmap(DrawFirst().GetHbitmap().ToInt32(), 3, XTPImageState.xtpImageNormal, false);
            // -------------

			TabWrite = RibbonBar.InsertTab(0, "&Home");
			TabWrite.Id = ID.ID_TAB_WRITE;			
	
			GroupClipboard = TabWrite.Groups.AddGroup("&Clipboard", ID.ID_GROUP_CLIPBOARD);

			ControlPaste = (XtremeCommandBars.CommandBarPopup)GroupClipboard.Add(XtremeCommandBars.XTPControlType.xtpControlSplitButtonPopup, ID.ID_EDIT_PASTE, "&Paste", false, false);
			ControlPaste.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_EDIT_PASTE, "&Paste", false, false);
			ControlPaste.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_EDIT_PASTE_SPECIAL, "&Paste Special", false, false);
			GroupClipboard.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_EDIT_CUT, "&Cut", false, false);
			GroupClipboard.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_EDIT_COPY, "&Copy", false, false);
			Control = GroupClipboard.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_FORMAT_PAINTER, "Format Painter", false, false);
			Control.Enabled = false;
			GroupClipboard.ShowOptionButton = true;
			GroupClipboard.ControlGroupOption.TooltipText = "Show clipboard dialog";
			GroupClipboard.IconId = ID.ID_EDIT_PASTE;

			GroupFont = TabWrite.Groups.AddGroup("&Font", ID.ID_GROUP_FONT);
			GroupFont.ControlsGrouping = true;

			XtremeCommandBars.CommandBar ComboPopup;
			XtremeCommandBars.CommandBarGallery GalleryFont;
			XtremeCommandBars.CommandBarGalleryItems ItemsFont;

			ItemsFont = CommandBars.CreateGalleryItems(ID.ID_FONT_FACE);
			ItemsFont.ItemWidth = 0;
			ItemsFont.ItemHeight = 26;

			ItemsFont.AddLabel("Recently Used Fonts");
			ItemsFont.AddItem(1, "Arial");
			ItemsFont.AddItem(2, "Tahoma");

			ItemsFont.AddLabel("All Fonts");

			FontFamily[] fontFamilies;
			System.Drawing.Text.InstalledFontCollection installedFontCollection = new System.Drawing.Text.InstalledFontCollection();
			fontFamilies = installedFontCollection.Families;

			for (int i = 1; i < fontFamilies.Length; i++) 
			{
				ItemsFont.AddItem(i, fontFamilies[i].Name);
			}

			XtremeCommandBars.CommandBarComboBox Combo = null;
			Combo = (XtremeCommandBars.CommandBarComboBox)GroupFont.Add(XtremeCommandBars.XTPControlType.xtpControlComboBox, ID.ID_FONT_FACE, "", false, false);
			Combo.DropDownListStyle = true;
			Combo.Width = 130;
			Combo.Text = "Tahoma";
			Combo.AutoComplete = true;

			ComboPopup = CommandBars.Add("Combo Popup", XtremeCommandBars.XTPBarPosition.xtpBarComboBoxGalleryPopup);

			GalleryFont = (XtremeCommandBars.CommandBarGallery)ComboPopup.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlGallery, ID.ID_FONT_FACE, "", -1, false);
			GalleryFont.Width = 290;
			GalleryFont.Height = 508;

			GalleryFont.Items = ItemsFont;
			Combo.CommandBar = ComboPopup;

			XtremeCommandBars.CommandBarGallery GallerySize;
			XtremeCommandBars.CommandBarGalleryItems ItemsSize;

			ItemsSize = CommandBars.CreateGalleryItems(ID.ID_FONT_SIZE);
			ItemsSize.ItemWidth = 0;
			ItemsSize.ItemHeight = 17;
			ItemsSize.AddItem(8, "8");
			ItemsSize.AddItem(9, "9");
			ItemsSize.AddItem(10, "10");
			ItemsSize.AddItem(11, "11");
			ItemsSize.AddItem(12, "12");
			ItemsSize.AddItem(14, "14");
			ItemsSize.AddItem(16, "16");
			ItemsSize.AddItem(18, "18");
			ItemsSize.AddItem(20, "20");
			ItemsSize.AddItem(22, "22");
			ItemsSize.AddItem(24, "24");
			ItemsSize.AddItem(26, "26");
			ItemsSize.AddItem(28, "28");
			ItemsSize.AddItem(36, "36");
			ItemsSize.AddItem(48, "48");
			ItemsSize.AddItem(72, "72");

			Combo = (XtremeCommandBars.CommandBarComboBox)GroupFont.Add(XtremeCommandBars.XTPControlType.xtpControlComboBox, ID.ID_FONT_SIZE, "", false, false);
			Combo.DropDownListStyle = true;
			Combo.Width = 50;
			Combo.Text = "10";

			ComboPopup = CommandBars.Add("Combo Popup", XtremeCommandBars.XTPBarPosition.xtpBarComboBoxGalleryPopup);
			GallerySize = (XtremeCommandBars.CommandBarGallery)ComboPopup.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlGallery, ID.ID_FONT_SIZE, "", -1, false);
			GallerySize.Width = 42;
			GallerySize.Height = 16 * 17;

			GallerySize.Items = ItemsSize;
			Combo.CommandBar = ComboPopup;

			Control = GroupFont.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_FONT_GROW, "Grow Font", false, false);
			Control.BeginGroup = true;
			GroupFont.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_FONT_SHRINK, "Shrink Font", false, false);

			Control = GroupFont.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_FONT_CLEAR, "Clear Formatting", false, false);
			Control.BeginGroup = true;

			Control = GroupFont.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_CHAR_BOLD, "&Bold", false, false);
			Control.BeginGroup = true;
			GroupFont.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_CHAR_ITALIC, "&Italic", false, false);
			GroupFont.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_CHAR_UNDERLINE, "&Underline", false, false);
			GroupFont.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_CHAR_STRIKETHROUGH, "&Strikethrough", false, false);

			Control = GroupFont.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_TEXT_SUBSCRIPT, "Subscript", false, false);
			Control.BeginGroup = true;
			Control.Enabled = false;
			Control = GroupFont.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_TEXT_SUBSCRIPT, "Subscript", false, false);
			Control.Enabled = false;
			Control = GroupFont.Add(XtremeCommandBars.XTPControlType.xtpControlButtonPopup, ID.ID_TEXT_SUPERSCRIPT, "Superscript", false, false);
			Control.Enabled = false;
			Control = GroupFont.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_TEXT_CHANGECASE, "Change case", false, false);
			Control.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonIcon;

			Control = GroupFont.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_TEXT_COLOR, "Color", false, false);
			Control.BeginGroup = true;
			Control.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonIcon;

			XtremeCommandBars.CommandBar GalleryColorsPopupBar;
			GalleryColorsPopupBar = CommandBars.Add("Colors", XtremeCommandBars.XTPBarPosition.xtpBarPopup);
			GalleryColorItems = CreateColorsGallery();
			GalleryColorItems.DrawItem += new XtremeCommandBars.ICommandBarGalleryItemsEvents_DrawItemEventHandler(this.GalleryColorItems_DrawItem);

			XtremeCommandBars.CommandBarPopup tempPopup = (XtremeCommandBars.CommandBarPopup)Control;
			tempPopup.CommandBar = GalleryColorsPopupBar;

			XtremeCommandBars.CommandBarGallery GalleryColors;
			GalleryColors = (XtremeCommandBars.CommandBarGallery)GalleryColorsPopupBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlGallery, ID.ID_GALLERY_COLORS, "Colors", -1, false);
			GalleryColors.Width = 170;
			GalleryColors.Height = 80;
			GalleryColors.ShowScrollBar = false;
			GalleryColors.Items = GalleryColorItems;
			GalleryColors.Items.ItemHeight = 17;
			GalleryColors.Items.ItemWidth = 17;

			GalleryLargeColorItems = CreateLargeColorsGallery();
			GalleryLargeColorItems.DrawItem += new XtremeCommandBars.ICommandBarGalleryItemsEvents_DrawItemEventHandler(this.GalleryColorItems_DrawItem);
			XtremeCommandBars.CommandBarGallery GalleryLargeColors;
			GalleryLargeColors = (XtremeCommandBars.CommandBarGallery)GalleryColorsPopupBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlGallery, ID.ID_GALLERY_LARGE_COLORS_POPUP, "Large Colors", -1, false);
			GalleryLargeColors.Width = 170;
			GalleryLargeColors.Height = 70;
			GalleryLargeColors.ShowScrollBar = false;
			GalleryLargeColors.Items = GalleryLargeColorItems;
			GalleryLargeColors.Items.ItemHeight = 32;
			GalleryLargeColors.Items.ItemWidth = 32;

			GalleryColorsPopupBar.EnableAnimation = true;

			XtremeCommandBars.CommandBarPopupColor ControlPopupColor;
			ControlPopupColor = (XtremeCommandBars.CommandBarPopupColor)CommandBars.CreateCommandBarControl("CXTPControlPopupColor");
			ControlPopupColor.Id = ID.ID_TEXT_HIGHLIGHTCOLOR;
			ControlPopupColor.TooltipText = "Highlight Color";
			ControlPopupColor.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonIcon;

			GroupFont.AddControl((XtremeCommandBars.CommandBarControl)ControlPopupColor, false);

			XtremeCommandBars.CommandBar PopupColor;
			PopupColor = CommandBars.Add("Color Popup", XtremeCommandBars.XTPBarPosition.xtpBarPopup);
			PopupColor.SetPopupToolBar(true);
			ControlPopupColor.CommandBar = PopupColor;

			Control = PopupColor.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, 0, "Auto", false, false);
			Control.Width = 148;

			XtremeCommandBars.CommandBarControlColorSelector ControlColorSelector;
			ControlColorSelector = (XtremeCommandBars.CommandBarControlColorSelector)CommandBars.CreateCommandBarControl("CXTPControlColorSelector");
			ControlColorSelector.Id = ID.ID_TEXT_HIGHLIGHTCOLORSELECTOR;

			PopupColor.Controls.AddControl((XtremeCommandBars.CommandBarControl)ControlColorSelector, false);

			Control = PopupColor.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, 0, "More Colors...", false, false);
			Control.Width = 148;

			GroupFont.ShowOptionButton = true;
			GroupFont.ControlGroupOption.TooltipText = "Show font dialog";


			GroupParagraph = TabWrite.Groups.AddGroup("&Paragraph", ID.ID_GROUP_PARAGRAPH);
			GroupParagraph.ControlsGrouping = true;

			GroupParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlSplitButtonPopup, ID.ID_INSERT_BULLET, "Bullet", false, false);
			GroupParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlSplitButtonPopup, ID.ID_INSERT_NUMBERING, "Numbering", false, false);
			GroupParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlSplitButtonPopup, ID.ID_INSERT_LIST, "List", false, false);
			Control = GroupParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_PARA_DECREASEINDENT, "Decrease Indent", false, false);
			Control.BeginGroup = true;
			GroupParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_PARA_INCREASEINDENT, "Increase Indent", false, false);

			Control = GroupParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_PARA_SORT, "Sort", false, false);
			Control.BeginGroup = true;
			Control = GroupParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_PARA_SHOWMARKS, "Show/Hide Marks", false, false);
			Control.BeginGroup = true;

			Control = GroupParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_PARA_LEFT, "&Left", false, false);
			Control.BeginGroup = true;
			GroupParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_PARA_CENTER, "&Center", false, false);
			GroupParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_PARA_RIGHT, "&Right", false, false);
			GroupParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_PARA_JUSTIFY, "&Justify", false, false);

			Control = GroupParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlButtonPopup, ID.ID_PARA_LINESPACING, "Line Spaceing", false, false);
			Control.BeginGroup = true;
			Control = GroupParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlSplitButtonPopup, ID.ID_PARA_SHADING, "Shading", false, false);
			Control.BeginGroup = true;
			Control = GroupParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlSplitButtonPopup, ID.ID_BORDERS_NOBORDER, "No Border", false, false);
			Control.BeginGroup = true;

			GroupParagraph.ShowOptionButton = true;

			GroupStyles = TabWrite.Groups.AddGroup("&Styles", ID.ID_GROUP_STYLES);
			XtremeCommandBars.CommandBarGallery GalleryStyles;

			ItemsStyles = CommandBars.CreateGalleryItems(ID.ID_GALLERY_STYLES);
			ItemsStyles.Icons = ImageManagerGalleryStyles.Icons;
			ItemsStyles.ItemWidth = 72;
			ItemsStyles.ItemHeight = 56;
			
			for (int i = 1; i <= 16; i++)
			{
				ItemsStyles.AddItem(i, "");
			}
			
			GalleryStyles = (XtremeCommandBars.CommandBarGallery)GroupStyles.Add(XtremeCommandBars.XTPControlType.xtpControlGallery, ID.ID_GALLERY_STYLES, "Styles", -1, false);
			GalleryStyles.Width = 235;
			GalleryStyles.SetItemsMargin(0, 1, 0, 1);
			GalleryStyles.ShowLabels = false;
			GalleryStyles.ShowBorders = true;
			GalleryStyles.Items = ItemsStyles;
						
			XtremeCommandBars.CommandBar GalleryPopupBar;
			GalleryPopupBar = CommandBars.Add("Styles", XtremeCommandBars.XTPBarPosition.xtpBarPopup);
			
			GalleryStyles.CommandBar = GalleryPopupBar;
			
			GalleryStyles = (XtremeCommandBars.CommandBarGallery)GalleryPopupBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlGallery, ID.ID_GALLERY_STYLES, "Styles", -1, false);
			GalleryStyles.Width = 235 + 72;
			GalleryStyles.Height = 56 * 3 + 2;
			GalleryStyles.Items = ItemsStyles;

			GroupFind = TabWrite.Groups.AddGroup("&Find", ID.ID_GROUP_FIND);
			GroupFind.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_EDIT_FIND, "&Find", false, false);
			GroupFind.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_EDIT_REPLACE, "&Replace", false, false);
			GroupFind.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_EDIT_GOTO, "&Goto", false, false);

			ControlSelect = (XtremeCommandBars.CommandBarPopup)GroupFind.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_EDIT_SELECT, "&Select", false, false);
			ControlSelect.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_EDIT_SELECT_ALL, "&Select All", false, false);
			Control = ControlSelect.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_EDIT_SELECT_OBJECTS, "&Select Objects", false, false);
			Control.Enabled = false;
			Control = ControlSelect.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_EDIT_SELECT_MULTIPLE_OBJECTS, "Select Multiple Objects", false, false);
			Control.Enabled = false;

			TabInsert = RibbonBar.InsertTab(1, "&Insert");
			TabInsert.Id = ID.ID_TAB_INSERT;

			GalleryShapeItems = CreateShapesGallery();

			GroupShapes = TabInsert.Groups.AddGroup("&Shapes", 0);
			
			XtremeCommandBars.CommandBarGallery GalleryShapes;
			GalleryShapes = (XtremeCommandBars.CommandBarGallery)GroupShapes.Add(XtremeCommandBars.XTPControlType.xtpControlGallery, ID.ID_GALLERY_SHAPES, "", -1, false);
			GalleryShapes.Width = 138;
			GalleryShapes.Height = 60;
			GalleryShapes.ShowBorders = true;
			GalleryShapes.ShowScrollBar = true;
			GalleryShapes.SetItemsMargin(0, -1, 0, -1);
			GalleryShapes.ShowLabels = false;
			GalleryShapes.Items = GalleryShapeItems;
			GalleryShapes.Items.ItemHeight = 20;
			GalleryShapes.Items.ItemWidth = 20;

			XtremeCommandBars.CommandBar GalleryShapesPopupBar;
			GalleryShapesPopupBar = CommandBars.Add("Shapes", XtremeCommandBars.XTPBarPosition.xtpBarPopup);

			GalleryShapes.CommandBar = GalleryShapesPopupBar;

			GalleryShapes = (XtremeCommandBars.CommandBarGallery)GalleryShapesPopupBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlGallery, ID.ID_GALLERY_SHAPES, "Shapes", -1, false);
			GalleryShapes.Width = 210;
			GalleryShapes.Height = 200;
			GalleryShapes.Items = GalleryShapeItems;

			GroupPages = TabInsert.Groups.AddGroup("&Pages", 0);
			ControlNew = (XtremeCommandBars.CommandBarPopup)GroupPages.Add(XtremeCommandBars.XTPControlType.xtpControlSplitButtonPopup, ID.ID_PAGES_NEW, "&New Page", false, false);
			ControlNew.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_NEWPAGE_BLANKPAGE, "&Blank Page", false, false);
			ControlNew.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_NEWPAGE_SELECTION, "&Save Selection as New Page", false, false);
			ControlCover = (XtremeCommandBars.CommandBarPopup)GroupPages.Add(XtremeCommandBars.XTPControlType.xtpControlSplitButtonPopup, ID.ID_PAGES_COVER, "Cover Page", false, false);
			ControlCover.DescriptionText = "Insert a fully-formatted cover page. You fill in the title, author, date, and other information.";
			ControlCover.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_COVERPAGE_REMOVECURRENTCOVERPAGE, "&Remove Current Cover Page", false, false);
			ControlCover.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_COVERPAGE_SAVESELECTIONASNEWCOVERPAGE, "&Save Selectio as New Cover Page", false, false);
			GroupPages.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_PAGES_BREAK, "Page Break", false, false);

			GroupTable = TabInsert.Groups.AddGroup("&Table", 0);
			ControlTable = (XtremeCommandBars.CommandBarPopup)GroupTable.Add(XtremeCommandBars.XTPControlType.xtpControlButtonPopup, ID.ID_TABLE_NEW, "&Table", false, false);
			ControlTable.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_TABLE_INSERTTABLE, "&Insert Table..", false, false);
			ControlTable.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_TABLE_DRAWTABLE, "Dra&w Table", false, false);
			ControlTable.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_TABLE_CONVERTTEXTTOTABLE, "Con&vert Text to Table...", false, false);

			GroupIllustrations = TabInsert.Groups.AddGroup("&Illustrations", 0);
			ControlPicture = (XtremeCommandBars.CommandBarPopup)GroupIllustrations.Add(XtremeCommandBars.XTPControlType.xtpControlSplitButtonPopup, ID.ID_ILLUSTRATION_PICTURE, "&Picture", false, false);
			ControlPicture.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_ILLUSTRATION_PICTURE, "&Picture...", false, false);
			ControlPicture.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_ILLUSTRATION_CLIPART, "&Clip Art...", false, false);
			ControlPicture.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_ILLUSTRATION_FROMCAMERA, "From &Scanner or Camera...", false, false);
			GroupIllustrations.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_ILLUSTRATION_GRAPHIC, "Graphic", false, false);
			GroupIllustrations.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_ILLUSTRATION_CHART, "&Chart", false, false);

			GroupLinks = TabInsert.Groups.AddGroup("&Links", 0);
			GroupLinks.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_INSERT_HYPERLINK, "Hyperlink", false, false);
			GroupLinks.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_INSERT_BOOKMARK, "&Bookmark", false, false);
			GroupLinks.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_INSERT_CROSS_REFERENCE, "Cross-reference", false, false);

			GroupHeader = TabInsert.Groups.AddGroup("&Header && Footer", ID.ID_GROUP_HEADERANDFOOTER);
			GroupHeader.ShowOptionButton = true;
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupHeader.Add(XtremeCommandBars.XTPControlType.xtpControlButtonPopup, ID.ID_INSERT_HEADER, "Header", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupHeader.Add(XtremeCommandBars.XTPControlType.xtpControlButtonPopup, ID.ID_INSERT_FOOTER, "Footer", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			ControlPageNumber = (XtremeCommandBars.CommandBarPopup)GroupHeader.Add(XtremeCommandBars.XTPControlType.xtpControlButtonPopup, ID.ID_INSERT_PAGENUMBER, "Page Number", false, false);
			ControlPageNumber.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_PAGENUMBER_FORMATPAGENUMBERS, "&Format Page Numbers", false, false);
			ControlPageNumber.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_PAGENUMBER_REMOVEPAGENUMBERS, "&Remove Page Numbers", false, false);

			GroupText = TabInsert.Groups.AddGroup("&Text", 0);
			GroupText.IconId = ID.ID_GROUP_POPUPICON;
			ControlTextBox = (XtremeCommandBars.CommandBarPopup)GroupText.Add(XtremeCommandBars.XTPControlType.xtpControlButtonPopup, ID.ID_TEXT_TEXTBOX, "Text Box", false, false);
			ControlTextBox.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_TEXTBOX_DRAWTEXTBOX, "&Draw Text Box", false, false);
			ControlTextBox.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_TEXTBOX_SAVESELECTIONASNEWTEXTBOX, "&Save Selection as New Text Box", false, false);
			ControlDocumentParts = (XtremeCommandBars.CommandBarPopup)GroupText.Add(XtremeCommandBars.XTPControlType.xtpControlSplitButtonPopup, ID.ID_TEXT_PARTS, "Document Parts", false, false);
			ControlDocumentParts.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_DOCUMENTPARTS_AUTOTEXT, "AutoText", false, false);
			ControlDocumentParts.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_DOCUMENTPARTS_PROPERTY, "Property", false, false);
			ControlDocumentParts.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_DOCUMENTPARTS_FIELD, "Field...", false, false);
			ControlDocumentParts.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_DOCUMENTPARTS_BUILDINGBLOCKORGANIZER, "Building Block Organizer", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupText.Add(XtremeCommandBars.XTPControlType.xtpControlButtonPopup, ID.ID_TEXT_WORDART, "Wordart", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupText.Add(XtremeCommandBars.XTPControlType.xtpControlButtonPopup, ID.ID_TEXT_DROPCAP, "Drop Cap", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);

			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupText.Add(XtremeCommandBars.XTPControlType.xtpControlSplitButtonPopup, ID.ID_TEXT_SIGNATURE, "Signature Line", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			GroupText.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_TEXT_DATETIME, "Date && Time", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupText.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_TEXT_INSERTOBJECT, "Insert Object", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);

			GroupSymbols = TabInsert.Groups.AddGroup("&Symbols", 0);
			GroupSymbols.IconId = ID.ID_GROUP_POPUPICON;
			ControlEquations = (XtremeCommandBars.CommandBarPopup)GroupSymbols.Add(XtremeCommandBars.XTPControlType.xtpControlButtonPopup, ID.ID_SYMBOL_EQUATIONS, "Equations", false, false);
			ControlEquations.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_EQUATIONS_MATH, "&Math", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupSymbols.Add(XtremeCommandBars.XTPControlType.xtpControlButtonPopup, ID.ID_SYMBOL_SYMBOL, "Symbol", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);

			TabPageLayout = RibbonBar.InsertTab(2, "&Page Layout");
			TabPageLayout.Id = ID.ID_TAB_PAGELAYOUT;

			XtremeCommandBars.RibbonGroup GroupPageSetup = null;
			XtremeCommandBars.RibbonGroup GroupThemes = null;
			XtremeCommandBars.RibbonGroup GroupPageBackground = null;
			XtremeCommandBars.RibbonGroup GroupArrange = null;

			GroupThemes = TabPageLayout.Groups.AddGroup("Themes", 0);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupThemes.Add(XtremeCommandBars.XTPControlType.xtpControlSplitButtonPopup, ID.ID_THEMES_THEMES, "Themes", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupThemes.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_THEMES_COLORS, "Colors", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupThemes.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_THEMES_FONTS, "Fonts", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupThemes.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_THEMES_EFFECTS, "Effects", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);


			GroupPageSetup = TabPageLayout.Groups.AddGroup("Page Setup", 0);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupPageSetup.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_PAGE_MARGINS, "Margins", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupPageSetup.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_PAGE_ORIENTATION, "Orientation", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupPageSetup.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_PAGE_SIZE, "Size", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupPageSetup.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_PAGE_COLUMNS, "Columns", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupPageSetup.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_PAGE_BREAKS, "Breaks", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupPageSetup.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_PAGE_LINENUMBERS, "Line Numbers", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupPageSetup.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_PAGE_HYPHENATATION, "Hyphenatation", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);

			GroupPageParagraph = TabPageLayout.Groups.AddGroup("Paragraph", 0);
			Control = (XtremeCommandBars.CommandBarControl)GroupPageParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlLabel, 0, "Indent", false, false);
			Control.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonCaption;

			XtremeCommandBars.CommandBarEdit ControlEdit;
			ControlEdit = (XtremeCommandBars.CommandBarEdit)GroupPageParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlEdit, ID.ID_PARA_INDENTLEFT, "Left:", false, false);
			ControlEdit.Width = 133;
			ControlEdit.ShowSpinButtons = true;

			ControlEdit = (XtremeCommandBars.CommandBarEdit)GroupPageParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlEdit, ID.ID_PARA_INDENTRIGHT, "Right:", false, false);
			ControlEdit.Width = 133;
			ControlEdit.ShowSpinButtons = true;

			Control = GroupPageParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlLabel, 0, "Spacing", false, false);
			Control.Style = XtremeCommandBars.XTPButtonStyle.xtpButtonCaption;
			Control.BeginGroup = true;

			ControlEdit = (XtremeCommandBars.CommandBarEdit)GroupPageParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlEdit, ID.ID_PARA_SPACINGBEFORE, "Before:", false, false);
			ControlEdit.Width = 133;
			ControlEdit.ShowSpinButtons = true;

			ControlEdit = (XtremeCommandBars.CommandBarEdit)GroupPageParagraph.Add(XtremeCommandBars.XTPControlType.xtpControlEdit, ID.ID_PARA_SPACINGAFTER, "After:", false, false);
			ControlEdit.Width = 133;
			ControlEdit.ShowSpinButtons = true;

			GroupArrange = TabPageLayout.Groups.AddGroup("Arrange", 0);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupArrange.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_ARRANGE_POSITION, "Position", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupArrange.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_ARRANGE_TEXTWRAPPING, "Text Wrapping", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupArrange.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_ARRANGE_FRONT, "Bring to Front", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupArrange.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_ARRANGE_BACK, "Send to Back", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupArrange.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_ARRANGE_ALIGN, "Align", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupArrange.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_ARRANGE_GROUP, "Group", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);
			GroupArrange.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_ARRANGE_UNGROUP, "Ungroup", false, false);
			ControlPopup = (XtremeCommandBars.CommandBarPopup)GroupArrange.Add(XtremeCommandBars.XTPControlType.xtpControlPopup, ID.ID_ARRANGE_ROTATE, "Rotate", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 1", false, false);
			ControlPopup.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_SAMPLE_MENU_ITEM, "Item 2", false, false);


			RibbonBar.InsertTab(3, "&References");
			RibbonBar.InsertTab(4, "&Mailings");

			TabReview = RibbonBar.InsertTab(5, "&Review");
			TabReview.Color = XtremeCommandBars.XTPRibbonTabContextColor.xtpRibbonTabContextColorPurple;
			TabReview.Id = ID.ID_TAB_REVIEW;

			TabView = RibbonBar.InsertTab(6, "&View");
			TabView.Id = ID.ID_TAB_VIEW;

			ViewGroup = TabView.Groups.AddGroup("&Show/Hide", ID.ID_GROUP_SHOWHIDE);
			ViewGroup.Add(XtremeCommandBars.XTPControlType.xtpControlCheckBox, ID.ID_VIEW_RULER, "Ruler", false, false);
			ViewGroup.Add(XtremeCommandBars.XTPControlType.xtpControlCheckBox, ID.ID_VIEW_GRIDLINES, "GridLines", false, false);
			ViewGroup.Add(XtremeCommandBars.XTPControlType.xtpControlCheckBox, ID.ID_VIEW_PROPERTIES, "Properties", false, false);
			ViewGroup.Add(XtremeCommandBars.XTPControlType.xtpControlCheckBox, ID.ID_VIEW_DOCUMENTMAP, "Document Map", false, false);
			ViewGroup.Add(XtremeCommandBars.XTPControlType.xtpControlCheckBox, ID.ID_VIEW_THUMBNAILS, "Thumbnails", false, false);
			ViewGroup.Add(XtremeCommandBars.XTPControlType.xtpControlCheckBox, ID.ID_VIEW_ACTINBAR, "Document Action Bar", false, false);

			TableTabs = RibbonBar.InsertTab(7, "&Design");
			TableTabs.Id = ID.ID_TAB_TABLEDESIGN;
			TableTabs.ContextCaption = "Table Tools";
			TableTabs.Color = XtremeCommandBars.XTPRibbonTabContextColor.xtpRibbonTabContextColorOrange;
			TableTabs = RibbonBar.InsertTab(8, "&Layout");
			TableTabs.Id = ID.ID_TAB_TABLELAYOUT;
			TableTabs.ContextCaption = "Table Tools";
			TableTabs.Color = XtremeCommandBars.XTPRibbonTabContextColor.xtpRibbonTabContextColorOrange;

			TableTabs = RibbonBar.InsertTab(9, "&Design");
			TableTabs.ContextCaption = "Chart Tools";
			TableTabs.Id = ID.ID_TAB_CHARTDESIGN;
			TableTabs.Color = XtremeCommandBars.XTPRibbonTabContextColor.xtpRibbonTabContextColorGreen;
			TableTabs = RibbonBar.InsertTab(10, "&Layout");
			TableTabs.ContextCaption = "Chart Tools";
			TableTabs.Id = ID.ID_TAB_CHARTLAYOUT;
			TableTabs.Color = XtremeCommandBars.XTPRibbonTabContextColor.xtpRibbonTabContextColorGreen;
			TableTabs = RibbonBar.InsertTab(11, "&Format");
			TableTabs.ContextCaption = "Chart Tools";
			TableTabs.Id = ID.ID_TAB_CHARTFORMAT;
			TableTabs.Color = XtremeCommandBars.XTPRibbonTabContextColor.xtpRibbonTabContextColorGreen;


			RibbonBar.QuickAccessControls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_FILE_NEW, "&New", false, false);
			RibbonBar.QuickAccessControls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_EDIT_COPY, "&Copy", false, false);
			RibbonBar.QuickAccessControls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_FILE_PRINT, "&Print", false, false);
		}
    
		private void GalleryColorItems_DrawItem(int hdc, XtremeCommandBars.CommandBarGallery Gallery, XtremeCommandBars.CommandBarGalleryItem Item, int x, int y, int cx, int cy, bool Enabled, bool Selected, bool Pressed, bool Checked, ref object Handled)
		{
			if (Item.Label)
			{
				return;
			}
    
			DrawColorItems(hdc, Item, x, y, cx, cy, Enabled, Selected, Pressed, Checked);
			Handled = true;
		}

		private void GalleryLargeColorItems_DrawItem(int hdc, XtremeCommandBars.CommandBarGallery Gallery, XtremeCommandBars.CommandBarGalleryItem Item, int x, int y, int cx, int cy, bool Enabled, bool Selected, bool Pressed, bool Checked, ref object Handled)
		{
			if (Item.Label)
			{
				return;
			}
			
			DrawColorItems(hdc, Item, x, y, cx, cy, Enabled, Selected, Pressed, Checked);
			Handled = true;
		}

		private void DrawColorItems(int hdc, XtremeCommandBars.CommandBarGalleryItem Item, int x, int y, int cx, int cy, bool Enabled, bool Selected, bool Pressed, bool Checked)
		{
			CommandBars.PaintManager.DrawRectangle(hdc, x, y, cx, cy, false, Pressed, Enabled, Checked, false, XtremeCommandBars.XTPBarType.xtpBarTypeNormal, XtremeCommandBars.XTPBarPosition.xtpBarComboBoxGalleryPopup);
			
			SolidBrush hBrush;
			Rectangle setrect;
			System.Drawing.Graphics g = System.Drawing.Graphics.FromHdc(new IntPtr(hdc));			

			if (Selected)
			{
				using(hBrush = new SolidBrush(Color.FromArgb(242, 148, 54)))
				{
					setrect = new Rectangle(x + 2, y + 2, cx - 4, cy - 4);
					g.FillRectangle(hBrush, setrect);
				}

				using(hBrush = new SolidBrush(Color.FromArgb(255, 226, 148)))
				{
					setrect = new Rectangle(x + 3, y + 3, cx - 6, cy - 6);
					g.FillRectangle(hBrush, setrect);
				}
			}
			else
			{
				using(hBrush = new SolidBrush(Color.FromArgb(197, 197, 197)))
				{
					setrect = new Rectangle(x + 2, y + 2, cx - 4, cy - 4);
					g.FillRectangle(hBrush, setrect);
				}
			}

			using (hBrush = new SolidBrush(System.Drawing.Color.FromArgb((int)Item.Tag)))
			{
				setrect = Selected ? new Rectangle(x + 4, y + 4, cx - 8,  cy - 8) :
					new Rectangle(x + 3, y + 3, cx - 6, cy - 6);
				g.FillRectangle(hBrush, setrect);		
			}

			g.Dispose();
		}

		private XtremeCommandBars.CommandBarGalleryItems CreateColorsGallery()
		{
			XtremeCommandBars.CommandBarGalleryItems Gallery;
			Gallery = CommandBars.CreateGalleryItems(ID.ID_GALLERY_COLORS);

			XtremeCommandBars.CommandBarGalleryItem GalleryItem;
			GalleryItem = Gallery.AddLabel("Theme Colors");

			GalleryItem = Gallery.AddItem(6200, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(255, 255, 255).ToArgb();
			GalleryItem = Gallery.AddItem(6201, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
			GalleryItem = Gallery.AddItem(6202, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(31, 73, 125).ToArgb();
			GalleryItem = Gallery.AddItem(6203, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(238, 236, 225).ToArgb();
			GalleryItem = Gallery.AddItem(6204, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(79, 129, 189).ToArgb();
			GalleryItem = Gallery.AddItem(6205, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(192, 80, 77).ToArgb();
			GalleryItem = Gallery.AddItem(6206, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(155, 187, 89).ToArgb();
			GalleryItem = Gallery.AddItem(6207, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(128, 100, 162).ToArgb();
			GalleryItem = Gallery.AddItem(6208, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(75, 172, 198).ToArgb();
			GalleryItem = Gallery.AddItem(6209, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(247, 150, 70).ToArgb();

			GalleryItem = Gallery.AddLabel("Standard Colors");

			GalleryItem = Gallery.AddItem(6400, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(192, 0, 0).ToArgb();
			GalleryItem = Gallery.AddItem(6401, "");
			GalleryItem.Tag = System.Drawing.Color.Red.ToArgb();
			GalleryItem = Gallery.AddItem(6402, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(255, 192, 0).ToArgb();
			GalleryItem = Gallery.AddItem(6403, "");
			GalleryItem.Tag = System.Drawing.Color.Yellow.ToArgb();
			GalleryItem = Gallery.AddItem(6404, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(146, 208, 80).ToArgb();
			GalleryItem = Gallery.AddItem(6405, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(0, 176, 80).ToArgb();
			GalleryItem = Gallery.AddItem(6406, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(0, 176, 240).ToArgb();
			GalleryItem = Gallery.AddItem(6407, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(0, 112, 192).ToArgb();
			GalleryItem = Gallery.AddItem(6408, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(0, 32, 96).ToArgb();
			GalleryItem = Gallery.AddItem(6409, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(112, 48, 160).ToArgb();

			return Gallery;
		}

		private XtremeCommandBars.CommandBarGalleryItems CreateLargeColorsGallery()
		{
			XtremeCommandBars.CommandBarGalleryItems Gallery;
			XtremeCommandBars.CommandBarGalleryItem GalleryItem;
			Gallery = CommandBars.CreateGalleryItems(ID.ID_GALLERY_LARGE_COLORS_POPUP);

			GalleryItem = Gallery.AddItem(6423, "");
			GalleryItem.Tag = System.Drawing.Color.Yellow.ToArgb();
			GalleryItem = Gallery.AddItem(6420, "");
			GalleryItem.Tag = System.Drawing.Color.Green.ToArgb();
			GalleryItem = Gallery.AddItem(6421, "");
			GalleryItem.Tag = System.Drawing.Color.Cyan.ToArgb();
			GalleryItem = Gallery.AddItem(6422, "");
			GalleryItem.Tag = System.Drawing.Color.Magenta.ToArgb();
			GalleryItem = Gallery.AddItem(6424, "");
			GalleryItem.Tag = System.Drawing.Color.Blue.ToArgb();
			GalleryItem = Gallery.AddItem(6425, "");
			GalleryItem.Tag = System.Drawing.Color.Red.ToArgb();
			GalleryItem = Gallery.AddItem(6426, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(0, 0, 128).ToArgb();
			GalleryItem = Gallery.AddItem(6427, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(0, 128, 128).ToArgb();
			GalleryItem = Gallery.AddItem(6428, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(0, 128, 0).ToArgb();
			GalleryItem = Gallery.AddItem(6429, "");
			GalleryItem.Tag = System.Drawing.Color.FromArgb(128, 0, 128).ToArgb();

			return Gallery;
		}

		private XtremeCommandBars.CommandBarGalleryItems CreateShapesGallery()
		{
			XtremeCommandBars.CommandBarGalleryItems GalleryShapeItems;
			GalleryShapeItems = CommandBars.CreateGalleryItems(ID.ID_GALLERY_SHAPES);

			XtremeCommandBars.CommandBarGalleryItem GalleryItem;
			GalleryItem = GalleryShapeItems.AddLabel("Lines");

			int nShape;
			for (nShape = 6000; nShape <= 6011; nShape++)
			{
				GalleryShapeItems.AddItem(nShape, "");
			}

			GalleryItem = GalleryShapeItems.AddLabel("Basic Shapes");
			for (nShape = 6012; nShape <= 6043; nShape++)
			{
				GalleryShapeItems.AddItem(nShape, "");
			}

			GalleryItem = GalleryShapeItems.AddLabel("Block Arrows");
			for (nShape = 6044; nShape <= 6070; nShape++)
			{
				GalleryShapeItems.AddItem(nShape, "");
			}

			GalleryItem = GalleryShapeItems.AddLabel("Flowchart");
			for (nShape = 6071; nShape <= 6098; nShape++)
			{
				GalleryShapeItems.AddItem(nShape, "");
			}

			GalleryItem = GalleryShapeItems.AddLabel("Callouts");
			for (nShape = 6099; nShape <= 6118; nShape++)
			{
				GalleryShapeItems.AddItem(nShape, "");
			}			

			GalleryItem = GalleryShapeItems.AddLabel("Stars and Banners");
			for (nShape = 6119; nShape <= 6134; nShape++)
			{
				GalleryShapeItems.AddItem(nShape, "");
			}	

			nShape = 0;

			int [] shapesIconArray;
			shapesIconArray = new int[135];

			for (nShape = 0; nShape < 135; nShape++)
			{
				shapesIconArray[nShape] = (nShape + 6000);
			}	

			string resDir = ResourcePath();

			GalleryShapeItems.Icons.LoadBitmap(resDir + "GalleryShapes.bmp", shapesIconArray, XtremeCommandBars.XTPImageState.xtpImageNormal);

			return GalleryShapeItems;
		}

		private void frmMain_Closed(object eventSender, System.EventArgs eventArgs)
		{
			CommandBars.SaveCommandBars("Codejock Software ActiveX Demos", System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, "Layout");
		}

		private void CommandBars_ResizeClient(object sender, AxXtremeCommandBars._DCommandBarsEvents_ResizeClientEvent e)
		{
			Refresh();
		}

		protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
		{
			int left = 0;
			int top = 0;
			int right = 0;
			int bottom = 0;
			CommandBars.GetClientRect(out left, out top, out right, out bottom);
			//
			//			System.Drawing.Image pic = null;
			//			pic = System.Drawing.Image.FromFile("../\\res\\ClientFace.bmp");
			//
			//			pevent.Graphics.DrawImage(pic, left, top, right - left, bottom - top);

			IntPtr hdc = new IntPtr();
			hdc = pevent.Graphics.GetHdc();
			
			CommandBars.PaintManager.FillWorkspace(hdc.ToInt32(), left, top, right - left, bottom - top);

			pevent.Graphics.ReleaseHdc(hdc);
		}

		[STAThread]
		static void Main()
		{
			Application.Run(new frmMain());
		}

		private void txtClient_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			XtremeCommandBars.CommandBar Popup = null;
			XtremeCommandBars.CommandBarControl Control = null;
			if (e.Button == MouseButtons.Right)
			{
				BringToFront();

				Popup = CommandBars.Add("Popup", XtremeCommandBars.XTPBarPosition.xtpBarPopup);
				Popup.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_EDIT_CUT, "Cu&t", -1, false);
				Popup.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_EDIT_COPY, "&Copy", -1, false);
				Popup.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_EDIT_PASTE, "&Paste", -1, false);

				Control = Popup.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_CONTEXT_FONT, "&Font...", -1, false);
				Control.BeginGroup = true;

				Control = Popup.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_PARA_PARAGRAPH, "&Paragraph...", -1, false);
				Control.BeginGroup = true;

				Popup.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ID.ID_INSERT_BULLET, "Bullets", -1, false);
				
				Popup.ShowPopup(XtremeCommandBars.XTPTrackPopupFlags.TPM_RIGHTBUTTON, null, null);
			}				
		}
	}
}