Next: Browser Remarks, Previous: Other Browser Routines, Up: Browser Object [Contents][Index]

#### 19.3.5 Browser Attributes

Never use the boxtype `FL_NO_BOX` for browsers.

The first color argument (`col1`) to `fl_set_object_color()` controls the color of the browser’s box, the second (`col2`) the color of the selection. The text color is the same as the label color, `obj->lcol`.

To set the font size used inside the browser use

    void fl_set_browser_fontsize(FL_OBJECT *obj, int size);

To set the font style used inside the browser use

    void fl_set_browser_fontstyle(FL_OBJECT *obj, int style);

See Label Attributes and Fonts, for details on font sizes and styles.

It is possible to change the appearance of individual lines in the browser. Whenever a line starts with the symbol `'@'` the next letter indicates the special characteristics associated with this line. The following possibilities exist at the moment:

`f`

  Fixed width font.

`n`

  Normal (Helvetica) font.

`t`

  Times-Roman like font.

`b`

  Boldface modifier.

`i`

  Italics modifier.

`l`

  Large (new size is `FL_LARGE_SIZE`).

`m`

  Medium (new size is `FL_MEDIUM_SIZE`).

`s`

  Small (new size is `FL_SMALL_SIZE`).

`L`

  Large (new size = current size + 6)

`M`

  Medium (new size = current size + 4)

`S`

  Small (new size = current size - 2).

`c`

  Centered.

`r`

  Right aligned.

`_`

  Draw underlined text.

`-`

  An engraved separator. Text following `'-'` is ignored.

`C`

  The next number indicates the color index for this line.

`N`

  Non-selectable line (in selectable browsers).

`' '`

  (a space character) Does nothing, can be used to separate between the digits specifying a color (following `"@C"`, see above) and the text of a line starting with a digit.

`@@`

  Regular `'@'` character.

The modifiers (bold and itatic) work by adding `FL_BOLD_STYLE` and `FL_ITALIC_STYLE` to the current active font index to look up the font in the font table (you can modify the table using `fl_set_font_name()` or `fl_set_font_name_f()`).

More than one option can be used by putting them next to each other. For example, `"@C1@l@f@b@cTitle"` will give you the red, large, bold fixed font, centered word `"Title"`. As you can see the font change requests accumulate and the order is important, i.e., `"@f@b@i"` gives you a fixed bold italic font while `"@b@i@f"` gives you a (plain) fixed font.

Depending on the font size and style lines may have different heights.

In some cases the character `'@'` might need to be placed at the beginning of the lines without introducing the special meaning mentioned above. In this case you can use `"@@"` or change the special character to something other than `'@'` using the following routine

    void fl_set_browser_specialkey(FL_OBJECT *obj, int key);

To align different text fields on a line, tab characters (`'\t'`) can be embedded in the text. See `fl_set_tabstop()` on how to set tabstops.

There are two functions to turn the scrollbars on and off:

    void fl_set_browser_hscrollbar(FL_OBJECT *obj, int how);
    void fl_set_browser_vscrollbar(FL_OBJECT *obj, int how);

`how` can be set to the following values:

`FL_ON`

  Always on.

`FL_OFF`

  Always off.

`FL_AUTO`

  On only when needed (i.e., there are more lines/chars than could be shown at once in the browser).

`FL_AUTO` is the default.

Please note that when you switch the scrollbars off the text can’t be scrolled by the user anymore at all (i.e., also not using methods that don’t use scrollbars, e.g., using the cursor keys).

Sometimes, it may be desirable for the application to obtain the scrollbar positions when they change (e.g., to use the scrollbars of one browser to control other browsers). There are two ways to achieve this. You can use these functions:

    typedef void (*FL_BROWSER_SCROLL_CALLBACK)(FL_OBJECT *, int, void *);
    void fl_set_browser_hscroll_callback(FL_OBJECT *obj,
                                         FL_BROWSER_SCROLL_CALLBACK cb,
                                         void *cb_data);
    void fl_set_browser_vscroll_callback(FL_OBJECT *obj,
                                         FL_BROWSER_SCROLL_CALLBACK cb,
                                         void *cb_data);

After scroll callbacks are set whenever the scrollbar changes position the callback function is called as

    cb(ob, offset, cb_data);

The first argument to the callback function `cb` is the browser object, the second argument is the new xoffset for the horizontal scrollbar or the new top line for the vertical scrollbar. The third argument is the callback data specified as the third argument in the function calls to install the callback.

To uninstall a scroll callback, use a `NULL` pointer as the callback function.

As an alternative you could request that the browser object gets returned (or a callback invoked) when the the scrollbar positions are changed. This can be done e.g., by passing `FL_RETURN_CHANGED` (if necessary `OR`’ed with flags for also returning on selection/deselections). Within the code for dealing with the event you could check if this is a change event by using the function

    int fl_get_object_return_state(FL_OBJECT *obj);

and test if `FL_RETURN_CHANGED` is set in the return value (by just logically `AND`’ing both) and then handle the change.

By default, the scrollbar size is based on the relation between the size of the browser and the size of the text. To change the default, use the following routine

    void fl_set_browser_scrollbarsize(FL_OBJECT *obj, int hh, int vw);

where `hh` is the horizontal scrollbar height and `vw` is the vertical scrollbar width. Use 0 to indicate the default.

The default scrollbar type is `FL_THIN_SCROLLBAR`. There are two ways you can change the default. One way is to use `fl_set_defaults()` or `fl_set_scrollbar_type()` to set the application wide default, another way is to use `fl_get_object_component()` to get the object handle to the scrollbars and change the the object type forcibly. The first method is preferable because the user can override the setting via resources. Although the second method of changing the scrollbar type is not recommended, the object handle obtained can be useful in changing the scrollbar colors etc.

Finally there is a routine that can be used to obtain the browser size in pixels for the text area

    void fl_get_browser_dimension(FL_OBJECT *obj, FL_Coord *x, FL_Coord *y,
                                  FL_COORD *w, FL_COORD *h);

where `x` and `y` are measured from the top-left corner of the form (or the smallest enclosing window). To establish the relationship between the text area (a function of scrollbar size, border with and text margin), you can compare the browser size and text area size.

Finally, the functions

    int fl_get_browser_scrollbar_repeat(FL_OBJECT *obj);
    void fl_set_browser_scrollbar_repeat(FL_OBJECT *obj, int millisec);

allows to determine and control the time delay (in milliseconds) between jumps of the scrollbar knob when the mouse button is kept pressed down on the scrollbar outside of the knobs area. The default value is 100 ms. The delay for the very first jump is twice that long in order to avoid jumping to start too soon when only a single click was intended but the user is a bit slow in releasing the mouse button.

Next: Browser Remarks, Previous: Other Browser Routines, Up: Browser Object [Contents][Index]