The SRP Ribbon Control takes a brand new approach to setup. Other SRP ActiveX Controls tend to be very dynamic. In the SRP Tree Control, for example, you add and remove items at will. However, SRP Ribbon Controls are much more complex to set up and as such, lend themselves to a one-time static initialization. This doesn't mean you won't be able to do things at runtime, it's just that it will be a slightly different paradigm than what you might be used to.

For example, let's say you have a tab that only appears in specific circumstances. You might think the solution is to add that tab when the need arises and remove it when you're done. Instead, you add the tab during your initialization along with all the other tabs and simply making it invisible by default. Later, you make it visible when you need it. The reason is because creating a tab can be expensive since it might have a lot of controls on it. It's much more efficient to create the tab once and keep it memory. The same principle should be applied to groups, controls, and everything else. We want everything created at the beginning of your form's life, and to make this easier we use the power of XML to initialize the control. This means we can efficiently setup the entire ribbon in one single call.

Init with XML

You are accustomed to writing line after line of Set_Property statements to setup your SRP ActiveX Controls. During the development of the SRP Ribbon Control, it became quickly apparent that the same approach was far too cumbersome and inefficient. This is due, in part, to the fact that you can have controls within controls. Such a hierarchical architecture screamed for XML as a much preferred solution.

Now your CREATE event handler will typically require only two lines of code to initialize your ribbon: one to grab the XML from the database and one that passes the XML to the ribbon.

// Read the XML from a table and pass it to the Init method
SetupXml = Xlate("SETUP", "RIBBON_TEST", "", "X")
Send_Message(@Window:".OLE_RIBBON", "OLE.Init", SetupXml)

This greatly simplifies the creation code. Now, all you need to do is learn the XML structure. Note that the main page for the SRP Ribbon Control documentation has a section listing all supported XML tags. If you are new to the control, you'll want to start by looking at the <Control> tag, which is the root tag of the XML passed to the Init method.

Sample XML

Here is a sample XML using images that come with OpenInsight.

<Control Name="OLE_RIBBON" Window="NDW_RIBBON_TEST">

    <Commands>
        <Command Key="CHANGECASE" Caption="Change Case" SmallIcon="BMPS\menu_ChangeCase.bmp" Tooltip="Sets the selection to uppercase." />
        <Command Key="CLEARFORMATTING" Caption="Clear Formatting" SmallIcon="BMPS\menu_Unerase.bmp" Tooltip="Removes all text formatting." />
        <Command Key="CLOSE" Caption="Close" KeyboardTip="X" Tooltip="Closes the application." />
        <Command Key="COPY" Caption="Copy" KeyboardTip="C" Shortcut="Ctrl+C" SmallIcon="BMPS\Menu_editCopy.bmp" Tooltip="Copies the selection to the clipboard." />
        <Command Key="CUT" Caption="Cut" KeyboardTip="X" Shortcut="Ctrl+X" SmallIcon="BMPS\Menu_editCut.bmp" Tooltip="Copies the selection to the clipboard then deletes it." />
        <Command Key="FONTSIZEINCREASE" Caption="Increase Font Size" SmallIcon="BMPS\menu_MoveUp.bmp" Tooltip="Increases font size by one point." />
        <Command Key="FONTSIZEDECREASE" Caption="Decrease Font Size" SmallIcon="BMPS\menu_Movedown.bmp" Tooltip="Decreases font size by one point." />
        <Command Key="INFO" Caption="Info" KeyboardTip="I" SmallIcon="BMPS\menu_help.bmp" Tooltip="The document's metadata." />
        <Command Key="MINIMIZE" Caption="Minimize" Tooltip="Toggles the Ribbon." />
        <Command Key="OPEN" Caption="Open" KeyboardTip="O" SmallIcon="BMPS\menu_open.bmp" Tooltip="Opens a new document." />
        <Command Key="PASTE" Caption="Paste" Shortcut="Alt+F1" LargeIcon="BMPS\dbmanager.bmp" SmallIcon="BMPS\Menu_editPaste.bmp" Tooltip="Inserts text from the clipboard." />
        <Command Key="PASTEMERGE" Caption="Merge Formatting" Enabled="False" SmallIcon="BMPS\menu_MaxWidth.bmp" Tooltip="Inserts text from the clipboard using the current selection's formatting." />
        <Command Key="PASTETEXTONLY" Caption="Keep Text Only" SmallIcon="BMPS\menu_Font.bmp" Tooltip="Inserts text only from the clipboard." />
        <Command Key="PASTEWITHFORMAT" Caption="Keep Source Formatting" SmallIcon="BMPS\menu_ed9.bmp" Tooltip="Inserts formatted text from the clipboard." />
        <Command Key="PRINT" Caption="Print" KeyboardTip="P" SmallIcon="Images\16x16\print.png" Tooltip="Prints the document." />
        <Command Key="SAVE" Caption="Save" Enabled="False" SmallIcon="BMPS\menu_Save.bmp" Tooltip="Saves the document." />
        <Command Key="SAVEAS" Caption="Save As" KeyboardTip="A" Tooltip="Saves the document to the selected file." />
        <Command Key="UNDO" Caption="Undo" SmallIcon="BMPS\Menu_editUndo.bmp" Tooltip="Reverts the last change." />
    </Commands>

    <Tabs>
        <Tab Key="HOME" Caption="Home" KeyboardTip="H">
            <Group Key="CLIPBOARD" Caption="Clipboard">
                <SplitButton Key="PASTE" Command="PASTE">
                    <Button Key="PASTEMERGE" Command="PASTEMERGE" />
                    <Button Key="PASTETEXTONLY" Command="PASTETEXTONLY" />
                    <Button Key="PASTEWITHFORMAT" Command="PASTEWITHFORMAT" />
                </SplitButton>
                <Button Key="CUT" Command="CUT" />
                <Button Key="COPY" Command="COPY" />
            </Group>
            <Group Key="FONT" Caption="Font" OptionButton="true" GroupControls="true" Tooltip="Displays the Font Chooser.">
                <ComboBox Key="COB_FONTFACE" Tooltip="Sets the selection's\r\nfont family." EnableEdit="true">
                    <Item>Arial Black</Item>
                    <Item>Segoe UI</Item>
                    <Item>Tahoma</Item>
                </ComboBox>
                <ComboBox Key="COB_FONTSIZE" Width="32" Tooltip="Sets theselection's font size.">
                    <Item>8</Item>
                    <Item>9</Item>
                    <Item>10</Item>
                    <Item>11</Item>
                    <Item>12</Item>
                </ComboBox>
                <Button Key="BTN_FONTSIZEINCREASE" Command="FONTSIZEINCREASE" BeginGroup="true" />
                <Button Key="BTN_FONTSIZEDECREASE" Command="FONTSIZEDECREASE" />
                <Button Key="BTN_CHANGECASE" Command="CHANGECASE" BeginGroup="true" />
                <Button Key="BTN_CLEARFORMATTING" Command="CLEARFORMATTING" BeginGroup="true" />
            </Group>
            <Group Key="OTHERCONTROLS" Caption="Other Controls" OptionButton="true" GroupControls="true" Tooltip="These are other controls support by SRP Ribbon.">
                <CheckBox Key="CHB_TEST" Caption="Check Box" Shortcut="Ctrl+H" Tooltip="This is a check box." />
                <EditField Key="EDL_TEST" Hint="Edit Field" />
                <Label Key="STA_TEST" Caption="Label" Height="22" BeginGroup="true" />
                <DateField Key="DTF_TEST" Width="144" Height="22" Tooltip="This is a date field." />
            </Group>
        </Tab>
        <Tab Key="CUSTOMERS" Caption="Customers" KeyboardTip="I">
        </Tab>
        <Tab Key="INVENTORY" Caption="Inventory" KeyboardTip="I">
        </Tab>
        <Tab Key="USERS" Caption="Users" ContextColor="Red" ContextCaption="Administrator" Visible="true">
        </Tab>
        <Tab Key="SETTINGS" Caption="Settings" ContextColor="Red" ContextCaption="Administrator" Visible="true">
        </Tab>
    </Tabs>
    
    <QuickAccessControls>
        <Button Key="BTN_SAVE" Command="SAVE" />
        <Button Key="BTN_UNDO" Command="UNDO" />
    </QuickAccessControls>
    
    <Backstage>
        <Button Command="SAVE" />
        <Button Command="SAVEAS" />
        <Button Command="OPEN" />
        <Page Key="INFO" Command="INFO" />
        <Button Command="CLOSE" />
    </Backstage>
    
    <TabBarControls>
        <Button Key="BTN_MINIMIZE" Command="MINIMIZE" />
    </TabBarControls>
    
</Control>   
  • No labels