Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="daddy"></param>
        static public void CreateToolbar(MainWindow daddy)
        {
            try
            {
                // On efface la toolbar de daddy
                if (daddy._shortcutToolstrip != null)
                {
                    daddy._shortcutToolstrip.Items.Clear();
                    daddy.Controls.Remove(daddy._shortcutToolstrip);
                    daddy._shortcutToolstrip = null;
                }

                // On recrée éventuellement la toolbar
                String   ids        = ConfigurationManager.AppSettings["toolbarids"];
                String[] sids       = ids.Split(';');
                int      indexcolor = 0;
                bool     special    = SpecialFeatures.SpecialFeaturesMgt.AreSpecialFeaturesEnabled();
                if (sids.Length != 0)
                {
                    List <ToolStripItem> tsi = new List <ToolStripItem>();
                    foreach (String id in sids)
                    {
                        if (String.IsNullOrEmpty(id))
                        {
                        }
                        else if (id == _sepTag)
                        {
                            //
                            // toolStripSeparator1
                            //
                            var toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
                            toolStripSeparator1.Name = "toolStripSeparator1";
                            toolStripSeparator1.Size = new System.Drawing.Size(6, 25);
                            tsi.Add(toolStripSeparator1);
                        }
                        else
                        {
                            //
                            // toolStripButton1
                            //
                            // _menuEntriesRequiringSpecialFeatures
                            String            lbl     = "???";
                            Object            menu    = MyTools.FindControl(daddy, id);
                            ToolStripMenuItem tsimenu = null;
                            bool docreate             = true;
                            if (menu != null)
                            {
                                tsimenu = menu as ToolStripMenuItem;
                                if (tsimenu != null)
                                {
                                    lbl = tsimenu.Text;

                                    if (!special)
                                    {
                                        foreach (var o in daddy._menuEntriesRequiringSpecialFeatures)
                                        {
                                            if (o == tsimenu)
                                            {
                                                docreate = false;
                                            }
                                        }
                                    }
                                }
                            }

                            if (docreate)
                            {
                                var toolStripButton1 = new System.Windows.Forms.ToolStripButton();
                                toolStripButton1.Text         = lbl;
                                toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
                                if ((daddy._imgMenus != null) && (daddy._imgMenus.ContainsKey(id)))
                                {
                                    toolStripButton1.Image = daddy._imgMenus[id];
                                }
                                else
                                {
                                    //toolStripButton1.Image = daddy._imgMenus["nomenuicon"];
                                    toolStripButton1.Image = MyTools.CreateToolbarImage(toolStripButton1.Text, (_colorandpen[indexcolor].Item2)?Color.White:Color.Black, Color.FromName(_colorandpen[indexcolor].Item1));
                                    indexcolor             = (indexcolor + 1) % (_colorandpen.Count);
                                }
                                toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
                                toolStripButton1.Name = id;
                                toolStripButton1.Tag  = id;
                                toolStripButton1.Size = new System.Drawing.Size(23, 22);

                                toolStripButton1.Click += new System.EventHandler(daddy.ToolStripButtonGenericClick);
                                tsi.Add(toolStripButton1);
                            }
                        }
                    }

                    if (tsi.Count != 0)
                    {
                        daddy._shortcutToolstrip = new System.Windows.Forms.ToolStrip();
                        //
                        // toolStrip1
                        //
                        daddy._shortcutToolstrip.Items.AddRange(tsi.ToArray());
                        daddy._shortcutToolstrip.Location = new System.Drawing.Point(0, 0);
                        daddy._shortcutToolstrip.Name     = "toolStrip1";
                        daddy._shortcutToolstrip.Size     = new System.Drawing.Size(827, 25);
                        daddy._shortcutToolstrip.TabIndex = 10;
                        daddy._shortcutToolstrip.Text     = "toolStrip1";

                        // Il faut s'insérer avant MenuStrip1
                        int pos = daddy.Controls.IndexOf(daddy.menuStrip1);
                        daddy.Controls.Add(daddy._shortcutToolstrip);
                        daddy.Controls.SetChildIndex(daddy._shortcutToolstrip, pos);
                    }
                }
            }
            catch (Exception) {}
        }
Example #2
0
        private void PopulateWithTSI(ListView lv, ToolStripMenuItem tsi, bool labelonly = false)
        {
            if ((tsi != null) && (tsi.Name != ""))             // Si on a un nom vide, de toute façon on ne sait rien faire
            {
                // On regarde si on est dans les golds et que nous ne sommes pas gold
                bool special = SpecialFeatures.SpecialFeaturesMgt.AreSpecialFeaturesEnabled();
                if (!special)
                {
                    foreach (var o in _daddy._menuEntriesRequiringSpecialFeatures)
                    {
                        if (o == tsi)
                        {
                            return;                     // Pas d'ajout de ce truc !
                        }
                    }
                }


                if ((tsi.DropDownItems.Count != 0) && (!labelonly))
                {
                    AddSeparator(lv);
                }

                // Et lui même
                String       lbl  = tsi.Text.Replace("&", "");
                ListViewItem item = lv.Items.Add(lbl);
                if (_daddy._imgMenus.ContainsKey(tsi.Name))
                {
                    item.ImageKey = tsi.Name;             // on a une icone
                }
                else
                {
                    _imageList.Images.Add(tsi.Name, MyTools.CreateToolbarImage(lbl, (_colorandpen[_indexColor].Item2)?Color.White:Color.Black, Color.FromName(_colorandpen[_indexColor].Item1)));
                    item.ImageKey = tsi.Name;             // on a créé une icone "nomenuicon";
                    _indexColor   = (_indexColor + 1) % (_colorandpen.Count);
                }

                if (!labelonly)
                {
                    item.Tag = tsi.Name;
                }
                else
                {
                    // Une tête de menu
                    item.Font = MyTools.ChangeFontStyle(item.Font, true, true);
                    //item.BackColor = Color.LightGreen;
                }

                if ((tsi.DropDownItems.Count != 0) && (!labelonly))
                {
                    item.Font = MyTools.ChangeFontStyle(item.Font, false, true);
                    item.Tag  = null;                    // Les menus ne sont pas ajoutables dans la toolbar
                }

                // Les entrées du menu
                foreach (var sub in tsi.DropDownItems)
                {
                    ToolStripMenuItem tsis = sub as ToolStripMenuItem;
                    if (tsis != null)
                    {
                        PopulateWithTSI(lv, tsis);
                    }
                    else
                    {
                        ToolStripSeparator tsp = sub as ToolStripSeparator;
                        if (tsp != null)
                        {
                            AddSeparator(lv);
                        }
                        else
                        {
                            // Un label ?
                            ToolStripLabel tsl = sub as ToolStripLabel;
                            if (tsl != null)
                            {
                                var tsli = lv.Items.Add(tsl.Text);
                                tsli.ImageKey = tsl.Name;
                                tsli.Font     = MyTools.ChangeFontStyle(tsli.Font, true, false);
                            }
                        }
                    }
                }
                // On ajoute un séparateur après pour isoler le menu
                if (tsi.DropDownItems.Count != 0)
                {
                    AddSeparator(lv);
                }
            }
        }