Interactive Clips

This chapter assumes you've read and understood the chapter on Clips.  

What are Interactive Clips?
   Clips insert text in to your file. Standard clips insert fixed text defined by the clip content. Interactive clips allow you to modify the content of the clip definition before it is inserted into your file using clip macros. You do this by defining your clip macros to use various Windows controls such as text boxes, combo boxes and checkboxes.

How do they work?
   The basis of interactive clips is the control definition in the section [Macro definition] at the top of the .DEF file. This section contains all of the common definitions for all of the clips in this particular .DEF file. The clips macros are all stored at the top of the file so that they can be used in many clip definitions.

Note: When an interactive clip is called if no value is entered for a particular macro and that macro has no default value then nothing from that macro will be inserted in to your file; if you need an empty value for a particular macro you must enter a space.  

Clip Macro Format:
The clip macro format is as follows  
 
%control%=@x caption,text,default,options,delimiter,dialog_type  
 
%control%The name used in the clip body. The name must contain only alphanumeric characters - no spaces or punctuation characters.  
@x   Type of control. One of  
@-- = Separator  
@C = Combo box  
@D = Date dialog  
@E = Text box  
@F = Font selection dialog  
@K = Checkbox  
@L = Colour picker dialog  
@O = File Open dialog  
@P = Picture selection dialog  
@S = Directory selection dialog  
@T = Topstyle  
   See below for further details.  
captionThis text will appear as a label for the control in the dialog.  
textOptional fixed text that will be inserted into your file immediately the value you enter in to the control.  
defaultThe default value. This value will be used if you don't enter a value of your own in to the control. (optional)  
optionsDepends on the control used, see below (optional).  
delimiterThese optional Characters will be inserted around value entered into the control (optional). Note: If you use a value for 'text' (see above) this value will not be bracketed by the delimiters.  
dialog_type   Only used when @x = @O (optional). One of:  
A = Absolute path and slash type, or  
R = Relative path and slash type  
If this value is blank then and the file being edited is an HTML file then the path returned by the control will be relative to the file's path and the path delimiters will be slashes (/). Otherwise the path returned will be absolute and will use backslashes (\).  

If you need to include a comma in the value supplied, say, as 'default' or 'options' you need to enclude the comma in quotes.  

You don't need to include the optional items although you do need to include the correct number of separating commas if you want to include one of the latter optional items without supplying a value for an earlier one. Special chars or values with spaces would be entered inside double quotes.  

Control types:
@-- = Separator  
This produces separator line only  
 
@C = Combo box  
This produces a list of values from which the you can select one. The list is entered as a semicolon-separated list of values for the options parameter. If the values contain spaces then they must be enclosed in double quotes.  
 
Examples:  
%combo1%=@C Centering type:,CENTER=,left,left;right;center,"  
%RGB%=@C RGB color:,RGB=,,"255,255,255";"#FFFFFF";"FF;FF;FF";"FF FF FF","  
 
@D = Date dialog  
This produces a control that allows you to enter a date. The control also allows you to call up a calendar to use to select the date required.  
 
Example:  
%date1%=@D "Enter date:",Date=  
 
@E = Text box  
This is a normal edit textbox to enter general value. If your supply no control type in the clip macro definition, @E is assumed.  
 
@F = Font selection dialog  
This produces a combo box containing a list of all fonts installed on the system.  
 
Example:  
%fonts%=@F Font face:,font-face=,,,"  
 
@K = Checkbox  
This produces a simple checkbox control. If the value of Default is not blank then the control is initial checked.  
 
Examples:  
%check%=@K No shade,NoShade  
%check%=@K Remember,REMEMBER,,,!!!  
 
@L = Colour picker dialog  
This produces the standard Windows colour picker dialog.  
 
@O = File Open dialog  
This produces the standard Windows File Open dialog. The options parameter can contain file filters.  
 
Examples:  
%file%=@O Reference:,HREF=,,Html files (*.htm;*.html)|*.htm;*.html,"  
result: HREF="project/files/soubor.htm"  

%file%=@O File:,,,PAS files (*.pas)|*.pas,',A\  
result: 'c:\temp\soubor.pas'  

%file%=@O File:,,,C files (*.c)|*.pas,,R\\  
result: project\\source\\soubor.c  
 
 
@P = Picture selection dialog  
This produces the standard Windows Picture Open dialog.  
 
@S = Directory selection dialog  
This produces the standard Windows Directory Select dialog.  
 
@T = Topstyle  
This invokes the TopStyle CSS editor. Note: You must have previously installed TopStyle for this to work.  

Using clip macros.
You use the clip macros you have defined by simply inserting the clip macro name, bracketed by percent signs (eg %mymacro%) in the clip definition. You can use the same control name several times throughout a clip body. When you do the control appears only once in the dialog when the clip is called but the value entered is inserted to the every occurrence of control in clip body.  

When a clip is called that uses a clip macro, the dialog that is displayed has 3 buttons: OK, Repeat and Cancel. The function of the OK and Cancel buttons sis self-explanatory. The Repeat button functions a little like the OK button except that is does not dismiss the dialog. Instead the clip text is entered in to your document and the macro 'resets' itself so that you enter another set of values.  

Example 1:  

[Macro definition]  
%file%=@O Reference:,HREF=,,Html files (*.htm;*.html)|*.htm;*.html,"  
...  
[ahref | simple reference <a href=...>...</a>]  
<a %file%>|</a>  

When the clip is called you will see a file open dialog. Once a file is selected the inserted text will look something like:  

   <a HREF="choosen file.htm"></a>  

and cursor will be positioned then the "|" character appears in the clip definition.  

Example 2:  

[Macro definition]  
%proc%=@E Procedure name:  
%autor%=@E Author name:  
...  
[proc | procedure base]  
// Procedure: %proc%   
// Author: %autor%  
procedure %proc%;  
begin  
|  
end; {procedure %proc%}  

When the clip is called you will see a dialog with two text boxes. Once values for 'Procedure name' and 'Author name' are entered the result will look something like:  

   // Procedure: ShowDialog  
   // Author: Jan Fiala  
   procedure ShowDialog;   
   begin  
 
   end; {procedure ShowDialog}  

Note how the clip macro %proc% has been used more than once in the clip macro definition.  
 
Example 3:  

[Macro definition]  
%Number%=@E, Enter Number ," ,",,,  

[number | number with comma]  
%number%  

After calling the clip and pressing the Repeat button a number of times a series of numbers and commas will be inserted like this:  

   ,123, 456, 12, 5