1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
[Author]
[Introduction]
[fli_parse_geometry()]
[fli_apply_geometry()]
[Example]
[Introduction]
@C4@i@lIntroduction
The `geometry' functions of the fli library are two functions which parse a
geometry string and apply it to a given form. Typically, the functions are
called when a geometry string is retrieved from the commandline or from an
app-defaults file.
[Author]
@C4@i@lAuthor
Karel Kubat (karel@icce.rug.nl)
[fli_parse_geometry()]
@C4@i@lfli_parse_geometry()
This function parses a geometry strings and returns the resulting values for
the width/height and/or x-position/y-position via its arguments. The caller
then typically applies the values to a form (this is what fli_apply_geometry()
does).
@iFunction prototype
int fli_parse_geometry (char const *geom, int *x, int *y,
int *w, int *h);
@iArguments
char const *geom: the geometry string
int *x, int *y: integers to receive x/y position, when the string
conforms to "+value+value" (the + can be also a -)
int *w, int *h: integers to receive the width/height, when the string
conforms to "valuexvalue"
@iReturn value
The return value is a bitmask of the following values:
FLI_WH_PARSED - a width and height were parsed from the string
FLI_XY_PARSED - an x and y position were parsed
FLI_WHXY_PARSED - both of the above were parsed
The return value is zero when neither of the above were found in the
geometry string.
[fli_apply_geometry()]
@C4@i@lfli_apply_geometry()
This function calls fli_parse_geometry() to convert a string to numeric
values, and then calls the appropriate XForms functions to apply the values to
a form. The caller can inspect the return value in order to determine the
right argument to fl_show_form() when displaying the form.
@iFunction prototype
int fli_apply_geometry (FL_FORM *form, char const *geom);
@iArguments
FL_FORM *form: the form to which the geometry setting should be applied
char const *geom: the geometry specification
@iReturn value:
The return value is a bitmask of the following values:
FLI_WH_PARSED - a width and height were parsed from the string
and applied to the form
FLI_XY_PARSED - an x and y position were parsed and applied
FLI_WHXY_PARSED - both of the above were parsed and applied
The return value is zero when neither of the above were found in the
geometry string.
[Example]
@C4@i@lExample
Typically, you will want to parse a geometry string and apply it to a form.
The result of the parsing of a string informs you whether the string contained
a position definition (x/y defined), a size definition (width/height), or
both.
Let's assume that when no geometry is defined, you want free placing (with
position and size variability). A definition in the string that states the
size then results in placement where only the position is free; a string that
states the position results in placement where only the size is free. A string
that defines both, results in a placement where neither the size nor position
are free. You'd then use the following mapping of geometry parsing vs.
placement of the window:
@f Geometry string parsed as.. Placing of form as..
@f ----------------------------------------------------
@f FLI_WH_PARSED FL_PLACE_SIZE
@f FLI_XY_PARSED FL_PACE_POSITION
@f FLI_WHXY_PARSED FL_PLACE_GEOMETRY
@f neither of the above FL_PLACE_FREE
This is illustrated in the following code sample:
extern char
geometry []; /* some geometry string */
extern FL_FORM
*myform; /* some form */
int
result; /* what's in the string */
/* parse the string and apply it to a form */
result = fli_apply_geometry (myform, geometry);
/* now display the form */
switch (result)
{
case FLI_XY_PARSED: /* string defines only position */
fl_show_form (myform, FL_PLACE_POSITION,
FL_FULLBORDER, "title");
break;
case FLI_WH_PARSED: /* string defines width and height */
fl_show_form (myform, FL_PLACE_SIZE,
FL_FULLBORDER, "title");
break;
case FLI_WHXY_PARSED:
fl_show_form (myform,
FL_PLACE_GEOMETRY, FL_FULLBORDER, "title");
break;
default:
/* invalid geometry string */
fl_show_form (myform, FL_PLACE_FREE,
FL_FULLBORDER, "title");
}
Naturally, other examples are possible. E.g., you might always wish to allow
resizing, whether an initial size was defined in a geometry string or not. In
that case, you'd use FL_PLACE_POSITION even when the string parsing returns
FLI_WH_PARSED.
|