Clipboard Inheritance®

This section contains the following topics:

Clipboard Inheritance® Overview

Clipboard Inheritance enables the transferring of objects from one place to another using the clipboard to create new instances that inherit the code of the original objects. Code for the new instances can be added that affects only the new instances, and code of the original instances can be modified, affecting both instances.

For example, you may want to create a group of controls that are needed by the SlickEdit® File Open dialog to allow the user to specify the various supported file formats. SlickEdit supports the following file formats:

  • DOS - Each line is separated with a carriage return, followed by linefeed.

  • Macintosh® - Each line is separated with a carriage return only.

  • UNIX - Each line is separated with a linefeed only.

  • Record width - A user-specified number of bytes placed in each line.

  • Separator character - A single user-specified line separator character.

The following partial dialog box can be used to handle the file formats of SlickEdit.

Example:

// The names of the controls do not need to be declared.
 
// The names of the radio button controls are ctlopendos, ctlopenmac, ctlopenunix,
// ctlopenauto.
 
// The first text box is named ctlopenlinesep and the text box below it is named
// ctlopenwidth.
 
defeventtab form1;
 
// Define the lbutton_up event for the DOS radio button. This function will
// get called when any of the radio buttons get turned on. The event
// table automatically created here is called form1.ctlopendos.
ctlopendos.lbutton_up()
{
    // Set the text displayed in both text boxes to nothing so the users
    // knows that the radio button format has been chosen.
    ctlopenlinesep.p_text='';
    ctlopenwidth.p_text='';
}
 
static zap_radio_buttons()
{
    ctlopendos.p_value=0;
    ctlopenmac.p_value=0;
    ctlopenunix.p_value=0;
    ctlopenauto.p_value=0;
 
}
 
// Define the on_change event for the first text box. For a text box, the 
// on_change event gets called when the user modifies the text in the text box.
// The event table automatically created here is form1.ctlopenlinesep.
ctlopenlinesep.on_change()
{
    if (p_text!='') {
       ctlopenwidth.p_text=''; // Clear out the other text boxes text.
       zap_radio_buttons();    // Turn off all the radio buttons.
    }
}
// Define the on_change event for the second text box. The event table
// automatically created here is form1.ctlopenwidth.
ctlopenwidth.on_change()
{
    if (p_text!='') {
       ctlopenlinesep.p_text=''; // Clear out the other text boxes text.
       zap_radio_buttons();      // Turn off all the radio buttons.
    }
}

Only the first radio button ctlopendos has an event handler defined. The other radio buttons use the form1.ctlopendos event table. This can be accomplished in the dialog editor using Clipboard Inheritance or, if the radio buttons are already created, you can set the p_eventtab property of the other radio buttons to form1.ctlopendos.

To use Clipboard Inheritance:

  1. Write the lbutton_up event code for the DOS radio button.

  2. Copy the DOS radio button to the clipboard.

  3. Paste it back onto the dialog box within the frame.

  4. Set the p_caption property for the new radio button to MAC.

Either of these methods can be used to fill an event table. When the ctlopendos.lbutton_up() function gets called, it gets and sets the properties of controls that exist on this dialog box.

Clipboard Inheritance® Example

For the Open dialog, Clipboard Inheritance® was created by copying controls to the clipboard and pasting them.

The Open File dialog box has the form name _edit_form. This dialog box is created by copying the _open_form dialog box (code links and all) to the clipboard, pasting it, and then adding the Find File button and the advanced controls. The _open_file form can be thought of as the base File Open dialog box class. It is used for all other File Open and Save As operations except for opening files for editing which requires additional controls. The inherited code from the base class File Open dialog required no changes except for the OK button. For this, the OK button code was replaced with new code. The Find File displays a dialog box which has all of the same advanced controls. The advanced controls were taken from the Open File dialog box (_edit_form) and all its related controls, and copied onto the Find File dialog box. The only additional code required was for the OK button, which was needed to return the results of the advanced options to the caller.

The following statement highlights the syntax for linking one event table to another:

      
    defeventtab dlgbox2.textbox1 _inherit dlgbox1.textbox1
    
    

Dialog Box Inheritance Order

Each control in Slick-C® has two properties, called p_eventtab and p_eventtab2. The p_eventtab property defines the user level 1 inheritance. User level 1 inheritance permits the modification of the event handlers for one specific instance of a control without affecting any other (except when Clipboard Inheritance® is used). The dialog editor automatically inserts the necessary function declaration code so that you need to only add statements within the function. After you write the event handler and load the new code, the p_eventtab property displayed in the Properties list box is updated to reflect that you have defined a user level 1 event table.

The p_eventtab2 property defines the user level 2 inheritance. User level 2 inheritance is typically used to affect all controls of a specific type. Normally, the dialog editor sets these properties for you when a control is created. For example, when you create a combo box control with the dialog editor, the p_eventtab2 property is automatically set to _ul2_combobx. The _ul2_combobx event table defines the default processing used by every combo box. The user level 1 event handler receives an on_change event (sent from the user level 2 code) when the text in the combo box changes.

SlickEdit® uses a pre-defined inheritance order called Dialog Box Inheritance Order. When a control receives an event, the following search begins to determine which event handler should get control:

  1. IF and ONLY if the event SlickEdit® is searching for is a key event, check the dialog box user level 1 inheritance on the frame of the dialog box.

  2. Check current control's user level 1 inheritance.

  3. Check current control's user level 2 inheritance.

  4. Check automatic inheritance. Only the text box, combo box, and editor window can have any automatic inheritance. This is how your emulation is supported in these controls.

  5. Check the dialog box frame user level 1 inheritance.

  6. Check the dialog box frame user level 2 inheritance.

  7. Check dialog manager inheritance.

As soon as an event handler is found, the search stops and the event handler is executed. Each inheritance level can have up to 20 linked event tables. This limit is only to avoid infinite event table link loops. At run time it is possible, but unusual, to change all inheritance links and event tables for any object. The eventtab_inherit function can be used to get or set an event table inheritance link.