Example #1
0
 /// <summary>
 /// Removes an item from the internal <c>Controls</c>
 /// collection.
 /// </summary>
 /// <param name="item"></param>
 protected void items_ItemRemoved(ToolbarItem item)
 {
     this.Controls.Remove(item);
 }
Example #2
0
 /// <summary>
 /// Gets the index of a toolbar item.
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public int IndexOf(ToolbarItem item)
 {
     return(this.List.IndexOf(item));
 }
Example #3
0
        /// <summary>
        /// Renders a table cell of a given toolbar item.
        /// </summary>
        /// <param name="item">Item to be rendered.</param>
        /// <param name="writer">Writer that streams output to the client.</param>
        protected void RenderItemCell(ToolbarItem item, HtmlTextWriter writer)
        {
            TableCell cell = new TableCell();

            cell.HorizontalAlign = item.HorizontalAlign;
            cell.VerticalAlign   = item.VerticalAlign;

            //ricardo ------
            cell.Wrap = false;

            cell.Attributes.Add("onmouseover", item.ItemCellMouseOver);
            cell.Attributes.Add("onmouseout", item.ItemCellMouseOut);

            //----------

            if (item is ToolbarSeparator)
            {
                //set separator height (custom if set or toolbar property)
                if (this.Orientation == ToolbarOrientation.Horizontal)
                {
                    //set the cell width on a horizontal toolbar
                    cell.Width = item.ItemCellDistance == Unit.Empty ? this.SeparatorCellDistance : item.ItemCellDistance;
                }
                else
                {
                    //set the cell height on a vertical toolbar
                    cell.Height = item.ItemCellDistance == Unit.Empty ? this.SeparatorCellDistance : item.ItemCellDistance;
                }

                //No mouse events for separator
                cell.Attributes.Add("onmouseover", "this.className=null;");
                cell.Attributes.Add("onmouseout", "this.className=null;");
                //No postback event for separator
                cell.Attributes.Add("onclick", "javascript:if(true)return false;");

                if (this.SeparatorImageUrl != String.Empty)
                {
                    Image img = new Image();
                    img.ImageUrl = this.SeparatorImageUrl;
                    cell.Controls.Add(img);
                }
                else
                {
                    cell.Text = "&nbsp;";
                }

                cell.RenderControl(writer);
            }
            else
            {
                if (this.Orientation == ToolbarOrientation.Horizontal)
                {
                    //set the cell width on a horizontal toolbar
                    cell.Width = item.ItemCellDistance == Unit.Empty ? this.ItemCellDistance : item.ItemCellDistance;
                }
                else
                {
                    //set the cell height on a vertical toolbar
                    cell.Height = item.ItemCellDistance == Unit.Empty ? this.ItemCellDistance : item.ItemCellDistance;
                }

                //-------------------------------------------------------
                //O evento click passou para a celula da toolbar
                //-------------------------------------------------------
                if (item is ToolbarImage)
                {
                    string onclick  = string.Empty;
                    string postback = string.Empty;

                    //If item is not blank add postback event
                    if (item.ItemId != "Blank" && item.ItemId != "None")
                    {
                        //Clear cellover
                        string cellClassName = " document.getElementById('CELL_" + ((ToolbarImage)item).ClientID + "').className = null; ";
                        //Disabled cell
                        string cellDisabled = " document.getElementById('CELL_" + ((ToolbarImage)item).ClientID + "').disabled = true; ";
                        //Set postback
                        postback = cellClassName + cellDisabled + Page.GetPostBackEventReference(((ToolbarImage)item));
                    }

                    //Add client script if exists
                    if (((ToolbarImage)item).ClientScript.Trim() != string.Empty)
                    {
                        onclick += ((ToolbarImage)item).ClientScript;
                    }

                    //trocar "return xpto();" por "if(!xpto())return;"
                    if (onclick.ToLower().IndexOf("return") >= 0)
                    {
                        int indexRet = onclick.ToLower().IndexOf("return");
                        onclick  = onclick.Remove(indexRet, 6);
                        onclick  = onclick.Insert(indexRet, "if(!");
                        indexRet = onclick.LastIndexOf(";");
                        if (indexRet >= 0)
                        {
                            onclick = onclick.Remove(indexRet, 1);
                        }
                        onclick += ")return;";
                    }

                    if (((ToolbarImage)item).CauseValidation)
                    {
                        onclick += "if (typeof(Page_ClientValidate) == 'function'){ if(Page_ClientValidate()){" + postback + "}} else {" + postback + "}";
                    }
                    else
                    {
                        onclick += postback;
                    }

                    if (onclick.Trim().Length != 0)
                    {
                        cell.Attributes.Add("onclick", onclick);
                    }

                    //ID da celula
                    cell.Attributes.Add("id", "CELL_" + item.ClientID);
                }
                //-------------------------------------------------------

                //render the item
                cell.RenderBeginTag(writer);
                item.RenderControl(writer);
                cell.RenderEndTag(writer);
            }
        }
Example #4
0
 /// <summary>
 /// Adds an item at a given position.
 /// </summary>
 /// <param name="index">Zero-based index of the item.</param>
 /// <param name="item">Item to be added.</param>
 public void Insert(int index, ToolbarItem item)
 {
     this.List.Insert(index, item);
 }