Programming Guide


Version 1.
5

 

 

 

 

 

 


1     Programming Guide. 4

1.1       Controls and Commands. 4

1.2       XML Configuration. 4

1.3       IWebBrowser2. 5

1.4       Object Model 5

1.4.1      ControlC. 5

1.4.2      ToolBandC. 6

1.4.3      CommandC. 6

1.4.4      CommandSetC. 7

1.4.5      ToolBandContextC. 7

1.4.6      ToolBandHookC. 8

1.5       Interfaces. 9

1.6       Getting Started. 9

1.6.1      Project Classes. 10

1.6.2      Built-in Commands. 11

1.6.3      Project Files. 11

1.6.4      Framework includes files. 12

1.6.5      Framework library files. 12

1.7       Adding Controls to a Toolbar 12

1.7.1      Implementing a “Go Home” Button. 12

1.7.2      Implementing a “Search Google” Combo-Box. 13

1.7.3      Implementing “Find & Highlight “ Buttons. 15

1.8       Using Built-in Commands. 17

1.8.1      Navigate. 17

1.8.2      JavaScript 18

1.8.3      VBScript 19

1.8.4      Toolband.ToolbarLayout 20

1.8.5      FindNext 20

1.8.6      FindPrevious. 20

1.8.7      Highlight 21

1.8.8      Execute. 21

1.8.9      Elevation. 22

1.8.10        Html 23

2     Reference. 24

2.1       Classes. 24

2.1.1      class CommandC. 24

2.1.2      class CommandContainerI 28

2.1.3      class CommandI 29

2.1.4      class CommandObserverI 33

2.1.5      class CommandPointerSetC. 33

2.1.6      class CommandSetC. 34

2.1.7      class CommandSetI 35

2.1.8      class CommandWithEventsC. 37

2.1.9      class ControlC. 37

2.1.10        class ControlCollectionI 38

2.1.11        class ControlI 39

2.1.12        class ControlPointerSetC. 41

2.1.13        class ToolBandContextC. 42

2.1.14        class ToolBandHookC. 46

2.1.15        class ToolBandC. 47

2.1.16        class ToolBandI 47

2.2       Functions. 48

2.2.1      CreateButtonControl 48

2.2.2      CreateComboBoxControl 48

2.2.3      CreateEditControl 49

2.2.4      CreateLabelControl 49

2.2.5      CreateMenuControl 49

2.2.6      CreateReadOnlyControl 50

2.2.7      CreateHtmlControl 50

2.2.8      CreateSeparatorControl 51

2.2.9      XmlGetNodeAttribute. 51

2.2.10        XmlGetNodeValue. 52

3     XML Configuration. 53

3.1       An Example. 53

3.2       Tags and Attributes. 53

3.2.1      <toolbar>. 53

3.2.2      <menu>. 54

3.2.3      <button>. 55

3.2.4      <label>. 55

3.2.5      <edit>. 56

3.2.6      <read-only>. 57

3.2.7      <combo-box>. 57

3.2.8      <separator>. 58

 

1       Programming Guide

1.1     Controls and Commands

 

There are two key concepts to understand when programming within the Diodia ToolbarCreator framework: Controls and Commands.

 

Controls are what the user sees in the toolbar, i.e. the buttons, the labels, the combo-boxes, etc..

 

Controls will not do or display anything unless they are associated with a command. Once a control is associated with a command the control can execute the command and display information about the command.

 

Commands serve a dual purpose: State and functionality.

 

State in the sense that when a control displays a text string, or when a button is enabled or disabled, then this is just the control reflecting the state of a command.

 

Functionality in the sense that whenever a toolbar does something it is because a command has been executed.

 

In other words, the controls are the UI layer of a toolbar and the commands are the functionality/model layer.

 

The two layers are completely separated. Communication between the two layers goes through a few well-defined interfaces.

 

Implementing a toolbar means implementing the commands. The controls are implemented by the framework.

1.2     XML Configuration

 

Controls and commands are associated through an XML configuration file. The XML file simply lists the controls in the toolbar in order, and associates each control with a named command.

1.3     IWebBrowser2

 

The IWebBrowser2 interface and the interfaces associated with the DHTML document object model are very important when programming within the Diodia ToolbarCreator framework since all access to the Internet Explorer goes through these interfaces. More information is available at http://msdn.microsoft.com.

1.4     Object Model

 

The ToolbarCreator object model is very simple. It consists of 6 classes: ControlC, ToolBandC, CommandC, CommandSetC, ToolBandContextC and ToolBandHookC. Each class is described briefly in the following.

1.4.1   ControlC

 

Control objects represent toolbar buttons etc.. The framework supports 7 different controls types: Menu, button, label, edit, read-only, combo-box and separator.

 

Menu

A menu control implements a pop-up menu. Multiple levels of sub-menus are supported.

 

Button

Three different button sub-types exist:

1.    Push-button: A regular button executing a command.

2.    Toggle-button: An on/off button.

3.    Mixed-button: A combination of a push-button and a menu.

Push-buttons and toggle-buttons can be placed directly in a toolbar or in menus, where they act as menu entries. Mixed buttons can only be placed directly in a toolbar.

Button controls placed directly in a toolbar can display a bitmap, a text string or both. Button controls placed in a menu can only display a text string.

 

Label

A label is a fixed text string displayed in the toolbar.

 

Edit

An edit control is a text field where text can be entered.

 

Read-only

A read-only control is a text field displaying text that can’t be edited. Read-only controls are usually displaying status information.

 

Combo-box

A combo-box is a combination of an edit-control and a drop-down list. Two combo-box subtypes exist: Regular and fixed-list. In a regular combo-box text can be typed into the edit control. In a fixed-list combo-box the user must choose between a fixed set of items.

 

Separator

A separator is a vertical line displayed in the toolbar. Separators are used to give the visual appearance that controls are grouped together.

 

ControlC objects are implemented entirely by the framework.

1.4.2   ToolBandC

 

A toolbar is created by adding controls to a toolband object.

 

The toolband object is responsible for drawing the toolbar on the screen.

ToolBandC objects are implemented entirely by the framework.

1.4.3   CommandC

 

Command objects implement the actual functionality of a toolbar.

 

Command objects are activated e.g. when the user clicks on a button in the toolbar, or when he selects an item in a combo-box.

 

 

Examples of commands could be a “Go Home” command or a “Search Google” command:

 

The class CommandC implements basic command functionality such as the ability to be executed and a command name attribute.

 

All commands created for a specific toolbar are derived from class CommandC.

1.4.4   CommandSetC

 

The command set object stores a set of command objects.

 

CommandSetC objects are implemented entirely by the framework.

1.4.5   ToolBandContextC

 

The toolband context object glues everything together.

 

 

The class ToolBandContextC implements basic toolband context functionality such as the ability to store command objects and a reference to the Internet Explorer.

 

A specific toolbar always derives a more specialized context class from class ToolBandContextC.

 

The derived context creates command objects for the specific toolbar and defines the toolbar layout.

1.4.6   ToolBandHookC

 

The toolband hook object is the link between the Internet Explorer and the toolbar.

 

The Internet Explorer queries the toolbar for information through various interfaces on the hook, e.g. the width and height of the toolbar. All the interfaces are implemented by the framework, so usually you don’t have to worry about the hook.

 

However, if you want to do something in response to Internet Explorer events, such as “new page opened”, then you must add functionality to the hook.

1.5     Interfaces

 

The objects model also defines a set of interfaces through which the objects communicate. They are:

 

   CommandContainerI

   CommandI

   CommandObserverI

   CommandSetI

   ControlCollectionI

   ControlI

   ToolBandI

1.6     Getting Started

To create a new toolbar first run Diodia ToolbarCreator. The following assumes that a new toolbar called MyToolbar has been created.

 

Visual Studio Projects

 

Diodia ToolbarCreator generates a Visual Studio 2005 project and a corresponding solution file:

 

 

The Visual Studio project includes all the basic functionality required of an Internet Explorer toolbar.

 

The project contains four build configurations: Debug, Release, Unicode Debug and Unicode Release.

 

The project can be built immediately. The result is a simple toolbar that illustrates the available controls.

 

Output from build

 

A toolbar is just a single self-registering dll. Visual Studio registers the dll automatically when a project is built.

 

The dll must be registered with e.g. regsvr32.exe if the dll is installed on another PC:

 

  1. Right-click on the dll, select “Open with…” and choose the program regsvr32.exe, usually located in C:\Windows\System32,
  2. or execute
        C:\Windows\System32\regsvr32 <path to dll>
    from a shell,

 

Typically an installation program will install and register the dll. A Visual Studio 2005 Setup Project can be used.

1.6.1   Project Classes

 

A specific toolbar needs to implement a toolband context, a toolband hook and a set of commands specific to this exact toolbar.

 

The context and the hook are pre-implemented by the classes ContextC and HookC, respectively.

 

The context contains the command set to which new commands are added.

 

Internet Explorer events are handled by adding functionality to the hook.

 

The initial Visual Studio project implements six sample commands:

 

 

The commands can be used as templates when the actual commands of the toolbar are implemented.

1.6.2   Built-in Commands

The framework comes with a small set of built-in commands that make it easier to implement common functionality, for example link buttons.

 

The built-in commands are

 

 

The sample project illustrates how to use the built-in commands. A few lines must be uncommented in the configuration file ToolbarLayout.xml to activate some of the examples.

1.6.3   Project Files

 

The Visual Studio projects contain the following files:

 

Header files:  

  Commands.h: Class definitions for the toolbar commands.

  ContextC.h: Class definition for the specialized toolband context.

  HookC.h: Class definition for the specialized toolband hook.

  Resource.h: Resource constants.

  StdAfx.h: Standard includes.

   

Source files:  

  Commands.cpp: Implementation of the toolbar commands.

  Context.cpp: Implementation of the specialized toolband context object.

  Hook.cpp: Implementation of the specialized toolband hook.

  Framework.cpp: Framework initialization.

  MyToolbar.def: Standard library definition file.

  MyToolbar.idl: COM interface definitions.

  StdAfx.xpp: Makes precompiled headers.

   

Resource files:  

  *.bmp: Bitmaps for the toolbar buttons.

  manifest.xml: Manifest enabling Windows XP visual styles.

  MyToolbar.rc: Resource script with strings, dialogs, etc..

  MyToolbar.rgs: Registry script for dll self-registration.

  ToolbandLayout.xml: XML configuration file defining the toolbar layout.
  hello.js: A small JavaScript that can be activated from the toolbar.

1.6.4   Framework includes files

 

Framework include files are located in the sub-directory include.

1.6.5   Framework library files

 

Framework library files are located in the sub-directory lib8. Both release and debug versions of the library files are included.

1.7     Adding Controls to a Toolbar

1.7.1   Implementing a “Go Home” Button

To add a “Go Home” button to a toolbar you follow these steps:

1)    Implement the “Go Home” command object.

2)    Add the “Go Home” command to the command set in the context.

3)    Insert a button control in the toolbar.

4)    Associate the button control with the “Go Home” command.

 

All in all, fewer than 20 lines of C++ source code and 1 line of XML configuration.

 

The first step is to implement the “Go Home” command object.

 

Command objects are derived from the class CommandC, which implements basic command functionality.

The “Go Home” command object is declared as:

 

   class GoHomeCmdC : public CommandC

   {

    public:

                    GoHomeCmdC();

      virtual void  Execute();

   };


Each command must have a unique name, which is defined in the commands constructor:

 

   GoHomeCmdC::GoHomeCmdC()

   {

      // set unique command name

      SetId("MyToolbar.GoHome");

      // make the command initially enabled

      SetSensitive(true);

   }


Once a button is associated with the command, and the button is clicked, the framework calls the command’s Execute() method. The command object can use the mWebBrowser member variable to navigate the Internet Explorer to its home page:

 

   void GoHomeCmdC::Execute()

   {

      // mWebBrowser is the Internet Explorer’s IWebBrowser2 interface

      mWebBrowser->GoHome();

   }


The next step is to make the command known to the framework. This is done by adding the command to the context’s command set from the context’s Initialize() method:

 

   void ContextC::Initialize()

   {

      :

      AddCommand(new GoHomeCmdC);

   }

 

Finally, a button control is inserted in the toolbar and associated with the “Go Home” command by adding a <button> tag to the toolbar’s XML configuration file:

 

   <?xml version="1.0" encoding="ISO-8859-1"?>

   <toolband xmlns="http://www.diodia.com/toolband" name="MyToolbar">

      :

      <button command="MyToolbar.GoHome" caption="Home"/>
   </
toolband>

1.7.2   Implementing a “Search Google” Combo-Box

The first step is to implement the “Search Google” command object:

 

   class SearchGoogleCmdC : public CommandC

   {

    public:

                    SearchGoogleCmdC();

      virtual void  Apply(CString Text);

   };


The drop-down list with previous search phrases would normally be initialized in the constructor, but in this example the command does not save the history, i.e. the history is lost when the Internet Explorer exits.

 

   SearchGoogleCmdC::SearchGoogleCmdC()

   {

      // set unique command name

      SetId("MyToolbar.SearchGoogle");

      // make the command initially enabled

      SetSensitive(true);

   }

 

The Apply() method is overridden instead of the Execute() method because the command is to be associated with a combo-box. The framework calls Apply() when the user enters text or selects an item in the combo-box:

 

   void SearchGoogleCmdC::Apply(CString Text)

   {

      // create the query URL

      variant_t Url = CString("http://www.google.com/search?q=") + Text;

 

      // navigate to Google's search page

      mWebBrowser->Navigate2(&Url, NULL, NULL, NULL, NULL);

 

      // add the query to the search history, if it’s not already there

      const ItemList *List = GetItemList();

      for (unsigned Idx = 0; Idx < List->mList.size(); Idx++)

         if (List->mList[Idx] == Text)

            return;

 

      // the search history is saved in the commands item list

      AddItem(Text);

   }

 

The “Search Google” command is added to the context’s command set:

 

   void ContextC::Initialize()

   {

      :

      AddCommand(new SearchGoogleCmdC);

   }

 

And finally, a combo-box control is inserted in the toolbar and associated with the “Search Google” command by adding a <combo-box> tag to the toolbar’s XML configuration file:

 

   <?xml version="1.0" encoding="ISO-8859-1"?>

   <toolband xmlns="http://www.diodia.com/toolband" name="MyToolbar">

      :

      <combo-box command="MyToolbar.SearchGoogle" width="200"/>
   </
toolband>

1.7.3   Implementing “Find & Highlight “ Buttons

The Google Toolbar adds a new button to the toolbar for each word or phrase contained in a query when a search is performed. Each button finds the next occurrence of a word or a phrase on the current web page.


To implement similar “Find & Highlight” buttons for the “Search Google” combo-box described in the previous example, first implement a “Find & Highlight” command object:

 

   class FindAndHighlightCmdC : public CommandC

   {

    public:

      FindAndHighlightCmdC(const char *Find);

      virtual void Execute();

 

   protected:

      std::string  mFind;

   };


The word to find and highlight is saved in the command constructor. The word is also incorporated in the command name to make the command name unique:

 

   FindAndHighlightCmdC::FindAndHighlightCmdC(const char *Find)

   {

      mFind = Find;

      SetId((std::string("MyToolbar.") + Find).c_str());

      SetSensitive(true);

   }

 

The commands Execute() method uses the mWebBrowser member, i.e. the IWebBrowser2 interface and the Internet Explorers object model, to find and highlight a word. The details are omitted here:

 

   void FindAndHighlightCmdC::Execute()

   {

      // use mWebBrowser member to find and highlight mFind

      :
   }

 

Find and highlight buttons are added at the end of the toolbar when a search is performed. This example just adds a single button finding and highlighting the entire query string. A proper implementation would split the query into individual words and phrases, and add a button for each.

 

A new member function maintaining the find and highlight buttons is added to the “Search Google” command object. Members keeping track of the current buttons are also added:

 

   class SearchGoogleCmdC : public CommandC

   {

    public:

                    SearchGoogleCmdC();

      virtual void  Apply(CString Text);

 

    protected:

      void         UpdateFindButtons(const char *Query);

 

      CommandPointerSetC mCommands;

      ControlPointerSetC mControls;

   };

 

The control collection interface on the toolband object is used to add the search button at the end of the toolbar. If the toolbar contains a button from a previous search then this button is deleted first: 

 

   void SearchGoogleCmdC::UpdateFindButtons(const char *Query)

   {

      ToolBandI  *ToolBand = mContext->GetToolBand();

      int         Idx;

 

      // first delete the old search buttons (there can be at most one)

      for (Idx = 0; Idx < mControls.GetSize(); Idx++)

         ToolBand->GetControlCollection()->DeleteControl(mControls[Idx]);

      mControls.Clear();

      for (Idx = 0; Idx < mCommands.GetSize(); Idx++)

         mContext->DeleteCommand(mCommands[Idx]);

      mCommands.Clear();

 

      // create a new search command and a new search button

      CommandC *FindCmd = new FindAndHighlightCmdC(Query);

      ControlI *FindButton = CreateButtonControl(FindCmd, Query);

 

      // save command and button, so we can delete later

      mCommands.AddCommand(FindCmd);

      mControls.AddControl(FindButton);

 

      // add the command to the toolband context

      mContext->AddCommand(FindCmd);

 

      // add the new button to the toolband (there is only one)

      for (Idx = 0; Idx < mControls.GetSize(); Idx++)

         ToolBand->GetControlCollection()->AddControl(mControls[Idx]);

   }

 

Finally, the UpdateSearchButton() is called when a search is performed, i.e. from the Apply() method of the “Search Google” command.

 

   void SearchGoogleCmdC::Apply(CString Text)

   {

      // create the query URL

      variant_t Url = CString("http://www.google.com/search?q=") + Text;

 

      // navigate to Google's search page

      mWebBrowser->Navigate2(&Url, NULL, NULL, NULL, NULL);

 

      const ItemList *List = GetItemList();

      for (unsigned Idx = 0; Idx < List->mList.size(); Idx++)

         if (List->mList[Idx] == Text)

            return;

 

     // add the query to drop-down list

     AddItem(Text);

 

     // add Find & Highlight buttons

     UpdateFindButtons(Text);

   }

 

1.8     Using Built-in Commands

1.8.1   Navigate

The Navigate command is used to open web pages.

 

In its simplest form it can be used to create a button that opens a specific web site. This is done by adding a button tag to the toolbar configuration file:

 

    <button command="Navigate"
            url="
http://www.cnn.com/"
            caption="CNN"/>

 

By default the Navigate command opens the web page in the same window, but a target frame can be specified. The button defined below opens the same web page in a new window:

 

    <button command="Navigate"
            url="
http://www.cnn.com/"
            target="_blank"
            caption="CNN"/>

 

The navigate command can also be associated with an edit control or a combo-box control. For example, a Navigate command associated with a “search box” edit control can be used to open a web page with search results.

 

The URL to the search results includes the search phrase, which in this case is the text displayed in the edit control.

 

To specify where in the URL to insert the search phrase a pattern is used. The pattern has the form ##ControlId##.

 

ControlId indicates which control to get the search phrase from. So to make the search box work, an id must be assigned to the “search box” edit control.

 

The “search box” therefore looks like this in the toolbar configuration file:

 

  <edit command="Navigate"
        id="SearchBox"
        width="100"
        url="
http://www.google.com/search?q=##SearchBox##"/>

 

The same principle makes it possible to create “search buttons” by using Navigate commands.

 

For example, suppose you want the edit control to search on Google by default, but sometimes you want to search on Yahoo instead.

 

This can be achieved this by creating a button next to the edit control that gets its search phrase from the edit control by using the id of the edit control. For example:

 

  <button command="Navigate"
          url="http://search.yahoo.com/search?p=##SearchBox##"
          caption="Search Yahoo"/>

1.8.2   JavaScript

The JavaScript command can execute a piece of JavaScript on the current web page.

 

The code to execute is specified in the script attribute on the control activating the JavaScript command:

 

  <button command="JavaScript"
          script="alert('Hello!');"
          caption="Run Script..."/>

 

If the code to execute is more than a few statements then it can be placed in a file. The file must have the extension .js and it must be included in the toolbar dll as a HTML resource.

 

  <button command="JavaScript"
          script="hello.js"
          caption=" Run Script..."/>

 

The sample toolbar generated by toolbar creator illustrates this.

 

The framework can either run the script once in the innermost frame on the current web page, or once in each frame on the web page. This is of course only relevant if the web page contains frames.

 

To run the script once, define a function called diodia_run_once() in the script file. For example:

 

   function diodia_run_once()

   {

     alert("Hello!");

   }

 

To run the script in all frame, define a function called diodia_run_in_all_frames() in the script file. For example:

 

   function diodia_run_in_all_frames()

   {

     alert("Hello!");

   }

1.8.3   VBScript

The VBScript command is similar to the JavaScript command, except it executes VBScript instead of JavaScript.

 

  <button command="VBScript"
          script='MsgBox "Hello!"'
          caption="Run Script..."/>

 

VBScript files must have extension .vb or .vbs.

 

The framework calls either the sub routine diodia_run_once or diodia_run_in_all_frames, so one of these must be defined in the script file. For example:

 

  Sub diodia_run_once()

     MsgBox "Hello!"

  End Sub

1.8.4   Toolband.ToolbarLayout

The Toolband.ToolbarLayout command opens the customize dialog. The dialog lets the user disable toolbar controls:

 

  <button command="ToolBand.ToolbarLayout"
          caption="Customize..."/>

 

1.8.5   FindNext

The FindNext command finds the next occurrence of a text string on the current web page.

 

The pattern attribute contains the text string to search for, or alternatively, the id of an edit or combo-box control to retrieve the text string from. The id must be enclosed in ##.

 

Example:

 

  <edit command="Navigate"
        id="SearchBox"
        width="100"
        url="
http://www.google.com/search?q=##SearchBox##"/>

  <
button command="FindNext"

          pattern="##SearchBox##"

          caption="Find Next"

          tooltip="Find Next"

          image="203"/>

 

1.8.6   FindPrevious

The FindPrevious command finds the previous occurrence of a text string on the current web page.

 

The pattern attribute contains the text string to search for, or alternatively, the id of an edit or combo-box control to retrieve the text string from. The id must be enclosed in ##.

 

Example:

 

  <edit command="Navigate"
        id="SearchBox"
        width="100"
        url="
http://www.google.com/search?q=##SearchBox##"/>

  <
button command="FindPrevious"

          pattern="##SearchBox##"

          caption="Find Previous"

          tooltip="Find Previous"

          image="204"/>

 

1.8.7   Highlight

The Highlight command highlights all occurrence of a text string on the current web page.

 

The pattern attribute contains the text string to highlight, or alternatively, the id of an edit or combo-box control to retrieve the text string from. The id must be enclosed in ##.

 

The color attribute contains the color to highlight with.

 

Example:

 

  <edit command="Navigate"
        id="SearchBox"
        width="100"
        url="
http://www.google.com/search?q=##SearchBox##"/>

  <
button command="Highlight"

          pattern="##SearchBox##"

          caption="Highlight"

          tooltip="Highlight"

          image="205"

          color="yellow"

          toggle-button="yes"/>

 

1.8.8   Execute

 

The Execute command launches an application.

 

The parameter attribute contains the file name of the application to launch.

 

Example:

 

    <button command="Execute"

            parameter="Calc.exe"

            caption="Calculator"

            tooltip="Calculator"

            image="206"/>

 

Note: Using the Execute command requires elevation support, even on Windows XP. See 1.8.9 for details.

1.8.9   Elevation

On Windows Vista the Internet Explorer is usually in protected mode, which basically means that browser add-ins can’t access the local file system directly. To learn more about protected mode, see here: http://msdn.microsoft.com/en-us/library/bb250462.aspx  

 

Accessing the local file system requires elevation through a broker process. The ToolbarCreator framework offers some basic support for elevation through the broker application, DiodiaBroker.exe, which is available for download from our web site.

 

If DiodiaBroker.exe is installed in the same directory as the toolbar dll, and has the proper elevation policy, then the Execute command (see 1.8.8) and the ToolbarContextC method ElevateShellExecute( ) (see 2.1.13) can be used.

 

Follow these steps to enable elevation in the framework:

1) Download DiodiaBroker.exe from http://www.diodia.com/DiodiaBroker.zip.

2) Include DiodiaBroker.exe in your toolbar setup project.
3) Find the GUID of the broker for your toolbar in the file Framework.cpp, i.e. the string value returned by the function GetHelperGuid( ).

4) Make your setup project create the proper elevation policy for the broker by creating values in the registry key:

 

  HKEY_LOCAL_MACHINE\

  SOFTWARE\

  Microsoft\

  Internet Explorer\

  Low Rights\

  ElevationPolicy\

  <broker GUID>

 

The values to create are:

 

  AppName="DiodiaBroker.exe"   (STRING)

  AppPath="[TARGETDIR]"          (STRING)

  Policy=00000003                     (DWORD)

 

1.8.10                      Html

 

The Html command holds HTML text to be displayed in an HTML control.

 

The HTML text to display is specified by attributes on the associated HTML control, either as a URL or as HTML text directly.

 

Examples:

 

  <html command="Html"
        id="LayoutTest.Html.2"
       
width="100"
       
url="http://www.diodia.com/html_control_test.htm"/>

 

  <html command="Html"
        id="LayoutTest.Html.1"
        width="100">
    <![CDATA[
    <html>
      <head>
        <meta http-equiv="Content-Type"
              content="text/html; charset=UTF-8"/>
      </head>
      <body bgcolor="#eeebdc"
            topmargin="4"
            leftmargin="2">
        <p align="top">
          <b><font face="Arial" size="1">HTML Example</font></b>
        </p>
      </body>
    <html>
   
]]>
  </
html>

                                         

2       Reference

2.1     Classes

2.1.1   class CommandC

CommandC is the base class for all command objects.

 

Interfaces:

 

Methods:

 

Overridables

 

Attributes:

2.1.2   class CommandContainerI

Interface providing access to a toolband context from a toolband. Used while a toolbar is being initialized.

 

Methods:

2.1.3   class CommandI

The interface is implemented by command objects, and provides access to commands from toolbands and controls.

 

Types:

 

Methods:

2.1.4   class CommandObserverI

The interface is implemented by control objects. Controls are notified about state changes in commands through the command observer interface.

 

Used internally only.

2.1.5   class CommandPointerSetC

 

Stores a set of pointers to commands. A command pointer set can be used to keep track of commands created dynamically, for example “Highlight and Word Find” commands.

 

Methods:

2.1.6   class CommandSetC

 

Stores a set of uniquely named command objects. A toolband context aggregates a command set.

 

Interfaces:

 

Types:

 

Methods:

Overridables:

Attributes:

2.1.7   class CommandSetI

Interface providing access to the commands in a command set.

 

Types:

 

Methods:


2.1.8   class CommandWithEventsC

CommandWithEventsC is a specialization of class CommandC. It supports all the features of CommandC, as well as handing of web browser events.

 

Methods:

 

2.1.9   class ControlC

ControlC implements control objects, i.e. menus, buttons, combo-boxes, etc..

The class is used internally only. Controls are manipulated through the ControlI interface.

2.1.10                      class ControlCollectionI

The interface is implemented by toolband objects and menu controls. it makes it possible to dynamically change the controls in a toolbar or a menu.

 

Methods:


2.1.11                      class ControlI

The interface is implemented by control objects, and provides access to controls from toolbands.

Types:

 

 

Methods:

2.1.12                      class ControlPointerSetC

 

Stores a set of pointers to controls. A control pointer set can be used to keep track of controls created dynamically, for example “Find&Highlight” buttons.

 

Methods:

2.1.13                      class ToolBandContextC

ToolBandContextC is base class for a specialized toolband context.

 

The toolband context glues everything together.

 

Interfaces:

 

Methods:

 

Overridables:

Attributes:

2.1.14                      class ToolBandHookC

ToolBandHookC is base class for a specialized toolband hook.

 

The toolband hook is the channel through which the Internet Explorer communicates with a toolbar.

 

Interfaces:

Methods:

Overridables:

 

Attributes:

 

2.1.15                      class ToolBandC

The class implements the toolband object, which is responsible for drawing the toolbar on the screen.

The class is used internally only.

2.1.16                      class ToolBandI

The interface is implemented by toolband objects, and provides access to toolbands from toolband contexts.

Methods:

2.2     Functions

2.2.1   CreateButtonControl

Creates a new button control, which can be added to a toolbar or a menu through a control collection interface.

 

- Parameters:
      Command: The command object to associate with the button.
      Text: The caption to display on the button.


- Note: To associate a bitmap with a button, use SetBitmapId() on the command object associated with the button. To make the button display the bitmap, use SetMode() from the ControlI interface after creating the button.


- Note: To create a toggle button, use SetFlags() from the ControlI interface after creating the button.

2.2.2   CreateComboBoxControl

Creates a new combo-box control, which can be added to a toolbar through a control collection interface.

 

 

- Parameters:
      Command: The command object to associate with the control.

      List: Items to add to the drop-down list separated by ##, for example "Red##Green##Blue".


- Note: To make the combo-box automatically adjust its size when the Internet Explorer is resized, use SetFlags() from the ControlI interface after creating the combo-box.


Note: To create a fixed width combo-box, use SetWidth() from the ControlI interface after creating the combo-box.


- Note: To prevent users from entering text in the combo-box, i.e. to make the combo-box display a fixed list of items, use SetFlags() from the ControlI interface after creating the combo-box.

2.2.3   CreateEditControl

Creates a new edit control, which can be added to a toolbar through a control collection interface.

 

 

- Parameters:
      Command: The command object to associate with the control.


- Note: To make the edit control automatically adjust its size when the Internet Explorer is resized, use SetFlags() from the ControlI interface after creating the edit control.


Note: To create a fixed width edit control, use SetWidth() from the ControlI interface after creating the edit control.

2.2.4   CreateLabelControl

Creates a new label control, which can be added to a toolbar through a control collection interface.

 

 

- Parameters:
      Command: The command object to associate with the label. May be NULL if the label is a fixed text string that never changes.

      Text: The label to display.

2.2.5   CreateMenuControl

Creates a new menu control, which can be added to a toolbar or a menu through a control collection interface.

 

 

- Parameters:
      Command: The command object to associate with the menu. If Command == NULL then an ordinary menu is created. If Command != NULL then a mixed button (i.e. a combination of a button and a menu) is created,.
      Text: The caption to display on the menu.


- Note: To associate a bitmap with a menu, use SetBitmapId() on the command object associated with the menu. To make the menu also display the bitmap, use SetMode() from the ControlI interface after creating the button. Bitmaps cannot be associated with sub-menus.

2.2.6   CreateReadOnlyControl

Creates a new read-only control, which can be added to a toolbar through a control collection interface.

 

 

- Parameters:
      Command: The command object to associate with the control.


- Note: To make the read-only control automatically adjust its size when the Internet Explorer is resized, use SetFlags() from the ControlI interface after creating the read-only control.


Note: To create a fixed width read-only control, use SetWidth() from the ControlI interface after creating the read-only control.

2.2.7   CreateHtmlControl

Creates a new HTML control, which can be added to a toolbar through a control collection interface.

 

 

- Parameters:
      Command: The command object to associate with the control. Use SetText( ) on the command object to specify either a URL or some HTML text to display in the HTML control.


- Note: To make the HTML control automatically adjust its size when the Internet Explorer is resized, use SetFlags() from the ControlI interface after creating the read-only control.


Note: To create a fixed width HTML control, use SetWidth() from the ControlI interface after creating the read-only control.

2.2.8   CreateSeparatorControl

Creates a new separator control, which can be added to a toolbar or a menu through a control collection interface.

 

2.2.9   XmlGetNodeAttribute

Returns the value of an attribute from an XML DOM node.

 


- Parameters:
      Node: The DOM node to get an attribute value from.

      Name: The name of the attribute.

 

- Usage: Typically used to get a value from the toolbar configuration file from within a command.

- Example: The Navigate command is used like this in the toolbar configuration file:

    <button command="Navigate"
            url="http://www.cnn.com/"
            caption="CNN"/>

The Navigate command can get the value of the url attribute by calling XmlGetNodeAttribute():


    void NavigateCmdC::Execute(ControlI *Control)

    {

       CString      Url;

       variant_t    vtUrl;

 

       Url = XmlGetNodeAttribute(Control->GetNode(), "url");
       vtUrl = bstr_t(Url);

 

       mWebBrowser->Navigate2(&vtUrl, &vtMissing,
                              &vtMissing, &vtMissing, &vtMissing);

    }

2.2.10                      XmlGetNodeValue

Returns the content of an XML DOM node.

 


- Parameters:
      Node: The DOM node to get the content from.

 

- Usage: Typically used to get a value from the toolbar configuration file from within a command.

- Example: The command ExampleCmd is used like this in the toolbar configuration file:

    <button command="ExampleCmd" caption="Example">
       Here is some text!
    </
button>

The command can get the content of the button tag by calling XmlGetNodeValue():


    void ExampleCmdC::Execute(ControlI *Control)

    {

       CString      Text;

 

       Text = XmlGetNodeValue(Control->GetNode());

       /* Text is now “Here is some text!” */
       :

    }

 

3       XML Configuration

3.1     An Example

The layout of a toolbar is described by an XML file.

 

The XML file is basically an ordered list of the controls in the toolbar. Each control is associated with a named command, and perhaps a caption and a bitmap image.

 

The XML file below describes a toolbar with three controls: A menu with three entries, a “Go Home” button and a “Search Google” combo-box:

 

   <?xml version="1.0" encoding="ISO-8859-1"?>

   <toolband xmlns="http://www.diodia.com/toolband" name="MyToolbar">

 

      <menu image="209">

         <button command="MyToolbar.GoHome" caption="My Home Page"/>

         <button command="MyToolbar.Help" caption="Help..."/>

         <button command="MyToolbar.About" caption="About..."/>

      </menu>

  

      <button command="MyToolbar.GoHome"
             
 image="210"
             
 caption="Home"
             
 show-caption="yes"/>

      <separator/>

 

      <combo-box command="MyToolbar.SearchGoogle"
                
 caption="Search Google"
                
 width="220"
                
 auto-size="yes"
                
 fixed-list="no"/>

 

   </toolband>

3.2     Tags and Attributes

3.2.1   <toolbar>

Description: Encapsulates the complete toolbar definition.

 

Attributes:

 

Example:

 

   <toolband xmlns="http://www.diodia.com/toolband" name="MyToolbar">

   

   </toolband>

3.2.2   <menu>

Description: Inserts a menu control in a toolbar, or a sub-menu in a menu, and encapsulates the items in the menu.

 

Attributes:

 

Notes:

 

Example:

 

   <menu image="211"

         caption="MyMenu"
        
show-caption="yes">

  

   </menu>

3.2.3   <button>

Description: Inserts a button control in a toolbar, or a menu item in a menu.

 

Attributes:

 

Notes:

 

Example:

 

   <button command="MyToolbar.GoHome"
         
 image="210"
         
 caption="Home"
         
 show-caption="yes"

           toggle-button="no"/>

3.2.4   <label>

Description: Inserts a label control in a toolbar.

 

Attributes:

 

Notes:

 

Example:

   <label caption="Background color:"/>

3.2.5   <edit>

Description: Inserts an edit control in a toolbar.

 

Attributes:

 

Examples:

 

   <edit command="MyToolbar.Find"

         caption="Find"

         width="200"

         auto-size="yes"/>

 

   <edit command="Navigate"

         id="MyToolbar.SearchBox"

         parameter="www.google.com/search?q=##MyToolbar.SearchBox##"

         caption="SearchBox"

         width="200"