Diff for /books/www/chapters/ch07.html between versions 1.1 and 1.2

version 1.1, 2002/09/17 21:10:35 version 1.2, 2002/09/23 15:23:31
Line 2 Line 2
 <HEAD><TITLE>Chapter 7</TITLE></HEAD><BODY BGCOLOR=WHITE><H2>Chapter 7</H2>  <HEAD><TITLE>Chapter 7</TITLE></HEAD><BODY BGCOLOR=WHITE><H2>Chapter 7</H2>
 <H1><A NAME="77027"></A> Extending the UI with XBL</H1>  <H1><A NAME="77027"></A> Extending the UI with XBL</H1>
 <P>You now know that XUL is the basic tool set for creating your application interface, but even it has limitations. It is just a finite set of widgets that your programming needs may transcend. If you find that you reimplement many of the same groups of widgets in different applications, or if you want to  <!--INDEX XBL (eXtensible Binding Language) --> extend your application's interface in some other way, you will find the eXtensible Binding Language (XBL) an invaluable tool.  <P>You now know that XUL is the basic tool set for creating your application interface, but even it has limitations. It is just a finite set of widgets that your programming needs may transcend. If you find that you reimplement many of the same groups of widgets in different applications, or if you want to  <!--INDEX XBL (eXtensible Binding Language) --> extend your application's interface in some other way, you will find the eXtensible Binding Language (XBL) an invaluable tool.
<P>This chapter describes what XBL is and how it is used. Basically, XBL provides a way to attach new content or behavior to your application by using XBL bindings. XBL can extend, add to, and reorganize user interfaces. XBL can also help you organize scattered XUL code into a set of self-contained widgets that make building and maintaining your Mozilla application much easier. <A HREF="appc.htm#77003">Appendix C</A> provides a reference for the XBL element set, with which new elements can be created.<P>This chapter describes what XBL is and how it is used. Basically, XBL provides a way to attach new content or behavior to your application by 
 using XBL bindings. XBL can extend, add to, and reorganize user interfaces. XBL can also help you organize scattered XUL code into a set of self-contained widgets that make building and maintaining your Mozilla application much easier. <A HREF="appc.html#77003">Appendix C</A> provides a reference for the XBL element set, with which new elements can be created.
 <H2><A NAME="77028"></A> What Is XBL?</H2>  <H2><A NAME="77028"></A> What Is XBL?</H2>
 <P>XBL is an XML markup  <!--INDEX XBL (eXtensible Binding Language):overview --> language invented specifically for creating widgets. XBL looks similar to XUL, and may even contain XUL or HTML and other markup (see the <A HREF="#77031">"Namespaces and XBL</A>" section later in this chapter for more information about how other markup is used in XBL bindings), but its purpose is different. Flexibility and interoperability are the point of XBL.  <P>XBL is an XML markup  <!--INDEX XBL (eXtensible Binding Language):overview --> language invented specifically for creating widgets. XBL looks similar to XUL, and may even contain XUL or HTML and other markup (see the <A HREF="#77031">"Namespaces and XBL</A>" section later in this chapter for more information about how other markup is used in XBL bindings), but its purpose is different. Flexibility and interoperability are the point of XBL.
 <P>If the XUL <TT>textbox</TT> is inadequate, for example, you can use XBL to create and attach a new widget called <TT>&lt;datafield/&gt;</TT>, possibly based on <TT>textbox</TT>, that provides special attributes and functionality for validating input data against a database.  <P>If the XUL <TT>textbox</TT> is inadequate, for example, you can use XBL to create and attach a new widget called <TT>&lt;datafield/&gt;</TT>, possibly based on <TT>textbox</TT>, that provides special attributes and functionality for validating input data against a database.
Line 589  return list.selectedItem.getAttribute('l Line 590  return list.selectedItem.getAttribute('l
 <P>On its own, the button can display text with the <TT>value</TT> attribute and an image with the <TT>src</TT> attribute. Usually, this is sufficient, and you can color the button and change the text font with CSS. But you may want to take advantage of inherent behaviors in other elements or inherit from other bindings. Mozilla buttons are a mix of <TT>&lt;box&gt;</TT>, <TT>&lt;text&gt;</TT>, and <TT>&lt;image&gt;</TT> elements, and they take on the characteristics of each.  <P>On its own, the button can display text with the <TT>value</TT> attribute and an image with the <TT>src</TT> attribute. Usually, this is sufficient, and you can color the button and change the text font with CSS. But you may want to take advantage of inherent behaviors in other elements or inherit from other bindings. Mozilla buttons are a mix of <TT>&lt;box&gt;</TT>, <TT>&lt;text&gt;</TT>, and <TT>&lt;image&gt;</TT> elements, and they take on the characteristics of each.
 <H2><A NAME="77064"></A> Event Handling</H2>  <H2><A NAME="77064"></A> Event Handling</H2>
 <P><I>Event handlers</I> are attributes that listen  <!--INDEX event handling:XBL;XBL (eXtensible Binding Language):event handling --> for events. They intercept events raised by certain user actions, such as button clicks. When intercepted, control is given to the application to carry out some functionality.  <P><I>Event handlers</I> are attributes that listen  <!--INDEX event handling:XBL;XBL (eXtensible Binding Language):event handling --> for events. They intercept events raised by certain user actions, such as button clicks. When intercepted, control is given to the application to carry out some functionality.
<P>Mouse and keyboard actions are included in these events. XBL uses all events that are available on an element in XUL and calls them by their name, minus the <TT>on</TT> prefix. Thus, for example, the <TT>onmouseclick</TT> event handler becomes <TT>mouseclick</TT> in XBL. Refer to <A HREF="appc.htm#77003">Appendix C</A> for a full list of these events, which also describes the difference between XUL and XBL event handling.<P>Mouse and keyboard actions are included in these events. XBL uses all events that are available on an element in XUL and calls them by their 
 name, minus the <TT>on</TT> prefix. Thus, for example, the <TT>onmouseclick</TT> event handler becomes <TT>mouseclick</TT> in XBL. Refer to <A HREF="appc.html#77003">Appendix C</A> for a full list of these events, which also describes the difference between XUL and XBL event handling.
 <P>The <TT> <!--INDEX handler element, XBL --> &lt;handler&gt;</TT> element contains a single event. Sets of individual <TT>&lt;handler&gt;</TT> elements need to be included in a <TT>&lt;handlers&gt;</TT> element. The event that sets off the action is contained in the <TT>event</TT> attribute.  <P>The <TT> <!--INDEX handler element, XBL --> &lt;handler&gt;</TT> element contains a single event. Sets of individual <TT>&lt;handler&gt;</TT> elements need to be included in a <TT>&lt;handlers&gt;</TT> element. The event that sets off the action is contained in the <TT>event</TT> attribute.
 <PRE>&lt;handlers&gt;  <PRE>&lt;handlers&gt;
 &lt;handler event="mousedown" action="dumpString('hello', 'there!')" /&gt;  &lt;handler event="mousedown" action="dumpString('hello', 'there!')" /&gt;

Removed from v.1.1  
changed lines
  Added in v.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>