formatfontcolor.lzx

<!---
      @topic Incubator
      @subtopic Rich Text Editor
  -->
<library>
     
     <!-- dependencies  -->
     <include href="colorsquare.lzx"/>
     
     <!-- Data: Font Color
         inside of a state because datasets get instantiated upon application init
         the state delays instantiation until the RTE is used. -->
     <dataset name="fontcolors">
         <clr value="0x000000"/>
         <clr value="0x555555"/>
         <clr value="0x333399"/>
         <clr value="0x339999"/>
         <clr value="0x339966"/>
         <clr value="0xcccc33"/>
         <clr value="0xcc9933"/>
         <clr value="0xcc3300"/>
     </dataset>
     <!--- 
         A class which is used as a combobox item
     -->    
     <class name="colorswatch" extends="lzcombobox_item">
         <colorsquare swatchcolor="$path{'@value'}" drawsquare="true" x="6" y="3"/>
     </class>
     
     <!--- 
         A class which wraps up the font face combobox and associated data
     -->
     <class name="formatfontcolor" extends="lzcombobox" width="48" shownitems="8" style="sidebarbutton_style" itemclassname="colorswatch" itemdatapath="fontcolors:/clr" focusable="false" listwidth="${this.bkgnd.mid.width}">
         
         <attribute name="editor" value="$once{this.parent.editor}"/>
         <attribute name="toolbar" value="$once{this.parent}"/>
         
         <tooltip>Choose font color</tooltip>      
         
         <!---  @keywords private
             Set my initial value to be the editor's default font color.
             Register tool with toolbar -->
         <method name="init">
             super.init();
             toolbar.registerTool(this,"color");
         </method>

         <!-- When we get an editor to hook up to, make this menu's value
            match up to the default color of the editor. 
            Fixes LPP-4461: In rich text editor, font color combo box does 
            not update when cursor moves to different colored text 
            [bshine 08.09.2007] -->
         <handler name="oneditor" args="e">
             this.setValue(this.editor.defaultfontcolor, true);
             this.csq.setAttribute('fgcolor', this.editor.defaultfontcolor);             
         </handler>
         
         <!---  @keywords private
             apply state for late instantiation of local data -->
         <method name="construct" args="parent, args">
             super.construct(parent, args);
         </method>    
         <!--- When the user selects an item from the combo box, 
             create an object representing just the change in format.
             Give that object to the editor. -->
         <handler name="onselect">
                var color  = this.value; 
                
                this.csq.setAttribute('fgcolor', color);

                //------------------------------------------------------------
                // make sure that we call into editor if this combobox has
                // changed, i.e., it contains an initial value. -pk
                //------------------------------------------------------------
                if (this.changed && this.toolbar._passthruchanges) {                
                    this.editor.setFormatAttribute("color", this.getValue()); 
                    this.editor.delegateRestoreSelection(); 
                }
                
         </handler>
         
         <!--- method broadcast out by the toolbar for clearing tool's state -->
         <method name="reset">
             rollback();
         </method>
         
         <!--- method broadcast out by the toolbar for setting tool's state -->
         <method name="setState" args="state">
             this.setValue(state); 
         </method>
         
         <!-- Save the selection region before another widget gets focus. -->
         <handler name="onmouseover">          
             this.editor.saveSelectionRegion();
         </handler>
         <colorsquare x="11" y="3" name="csq" drawsquare="true">
             <setter name="fgcolor" args="color">
                 this.setAttribute('visible',  color != null );
                 if (this.visible) {
                 this.setAttribute('swatchcolor', color);
                 }
             </setter>
         </colorsquare>
     </class>
     
 </library>
<!-- * X_LZ_COPYRIGHT_BEGIN ***************************************************
* Copyright 2005-2009 Laszlo Systems, Inc. All Rights Reserved.               *
* Use is subject to license terms.                                            *
* X_LZ_COPYRIGHT_END ****************************************************** -->
<!-- @LZX_VERSION@                                                         -->

Cross References

Includes

Classes

Named Instances