dialog.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /*
  2. * Exports and types from dialog.c.
  3. */
  4. /*
  5. * This is the big union which defines a single control, of any
  6. * type.
  7. *
  8. * General principles:
  9. * - _All_ pointers in this structure are expected to point to
  10. * dynamically allocated things, unless otherwise indicated.
  11. * - `char' fields giving keyboard shortcuts are expected to be
  12. * NO_SHORTCUT if no shortcut is desired for a particular control.
  13. * - The `label' field can often be NULL, which will cause the
  14. * control to not have a label at all. This doesn't apply to
  15. * checkboxes and push buttons, in which the label is not
  16. * separate from the control.
  17. */
  18. #define NO_SHORTCUT '\0'
  19. enum {
  20. CTRL_TEXT, /* just a static line of text */
  21. CTRL_EDITBOX, /* label plus edit box */
  22. CTRL_RADIO, /* label plus radio buttons */
  23. CTRL_CHECKBOX, /* checkbox (contains own label) */
  24. CTRL_BUTTON, /* simple push button (no label) */
  25. CTRL_LISTBOX, /* label plus list box */
  26. CTRL_COLUMNS, /* divide window into columns */
  27. CTRL_FILESELECT, /* label plus filename selector */
  28. CTRL_FONTSELECT, /* label plus font selector */
  29. CTRL_TABDELAY /* see `tabdelay' below */
  30. };
  31. /*
  32. * Many controls have `intorptr' unions for storing user data,
  33. * since the user might reasonably want to store either an integer
  34. * or a void * pointer. Here I define a union, and two convenience
  35. * functions to create that union from actual integers or pointers.
  36. *
  37. * The convenience functions are declared as inline if possible.
  38. * Otherwise, they're declared here and defined when this header is
  39. * included with DEFINE_INTORPTR_FNS defined. This is a total pain,
  40. * but such is life.
  41. */
  42. typedef union { void *p; int i; } intorptr;
  43. #ifndef INLINE
  44. intorptr I(int i);
  45. intorptr P(void *p);
  46. #endif
  47. #if defined DEFINE_INTORPTR_FNS || defined INLINE
  48. #ifdef INLINE
  49. #define PREFIX INLINE
  50. #else
  51. #define PREFIX
  52. #endif
  53. PREFIX intorptr I(int i) { intorptr ret; ret.i = i; return ret; }
  54. PREFIX intorptr P(void *p) { intorptr ret; ret.p = p; return ret; }
  55. #undef PREFIX
  56. #endif
  57. /*
  58. * Each control has an `int' field specifying which columns it
  59. * occupies in a multi-column part of the dialog box. These macros
  60. * pack and unpack that field.
  61. *
  62. * If a control belongs in exactly one column, just specifying the
  63. * column number is perfectly adequate.
  64. */
  65. #define COLUMN_FIELD(start, span) ( (((span)-1) << 16) + (start) )
  66. #define COLUMN_START(field) ( (field) & 0xFFFF )
  67. #define COLUMN_SPAN(field) ( (((field) >> 16) & 0xFFFF) + 1 )
  68. union control;
  69. /*
  70. * The number of event types is being deliberately kept small, on
  71. * the grounds that not all platforms might be able to report a
  72. * large number of subtle events. We have:
  73. * - the special REFRESH event, called when a control's value
  74. * needs setting
  75. * - the ACTION event, called when the user does something that
  76. * positively requests action (double-clicking a list box item,
  77. * or pushing a push-button)
  78. * - the VALCHANGE event, called when the user alters the setting
  79. * of the control in a way that is usually considered to alter
  80. * the underlying data (toggling a checkbox or radio button,
  81. * moving the items around in a drag-list, editing an edit
  82. * control)
  83. * - the SELCHANGE event, called when the user alters the setting
  84. * of the control in a more minor way (changing the selected
  85. * item in a list box).
  86. * - the CALLBACK event, which happens after the handler routine
  87. * has requested a subdialog (file selector, font selector,
  88. * colour selector) and it has come back with information.
  89. */
  90. enum {
  91. EVENT_REFRESH,
  92. EVENT_ACTION,
  93. EVENT_VALCHANGE,
  94. EVENT_SELCHANGE,
  95. EVENT_CALLBACK
  96. };
  97. typedef void (*handler_fn)(union control *ctrl, dlgparam *dp,
  98. void *data, int event);
  99. #define STANDARD_PREFIX \
  100. int type; \
  101. char *label; \
  102. bool tabdelay; \
  103. int column; \
  104. handler_fn handler; \
  105. intorptr context; \
  106. intorptr helpctx; \
  107. union control *align_next_to
  108. union control {
  109. /*
  110. * The first possibility in this union is the generic header
  111. * shared by all the structures, which we are therefore allowed
  112. * to access through any one of them.
  113. */
  114. struct {
  115. int type;
  116. /*
  117. * Every control except CTRL_COLUMNS has _some_ sort of
  118. * label. By putting it in the `generic' union as well as
  119. * everywhere else, we avoid having to have an irritating
  120. * switch statement when we go through and deallocate all
  121. * the memory in a config-box structure.
  122. *
  123. * Yes, this does mean that any non-NULL value in this
  124. * field is expected to be dynamically allocated and
  125. * freeable.
  126. *
  127. * For CTRL_COLUMNS, this field MUST be NULL.
  128. */
  129. char *label;
  130. /*
  131. * If `tabdelay' is non-zero, it indicates that this
  132. * particular control should not yet appear in the tab
  133. * order. A subsequent CTRL_TABDELAY entry will place it.
  134. */
  135. bool tabdelay;
  136. /*
  137. * Indicate which column(s) this control occupies. This can
  138. * be unpacked into starting column and column span by the
  139. * COLUMN macros above.
  140. */
  141. int column;
  142. /*
  143. * Most controls need to provide a function which gets
  144. * called when that control's setting is changed, or when
  145. * the control's setting needs initialising.
  146. *
  147. * The `data' parameter points to the writable data being
  148. * modified as a result of the configuration activity; for
  149. * example, the PuTTY `Conf' structure, although not
  150. * necessarily.
  151. *
  152. * The `dlg' parameter is passed back to the platform-
  153. * specific routines to read and write the actual control
  154. * state.
  155. */
  156. handler_fn handler;
  157. /*
  158. * Almost all of the above functions will find it useful to
  159. * be able to store a piece of `void *' or `int' data.
  160. */
  161. intorptr context;
  162. /*
  163. * For any control, we also allow the storage of a piece of
  164. * data for use by context-sensitive help. For example, on
  165. * Windows you can click the magic question mark and then
  166. * click a control, and help for that control should spring
  167. * up. Hence, here is a slot in which to store per-control
  168. * data that a particular platform-specific driver can use
  169. * to ensure it brings up the right piece of help text.
  170. */
  171. intorptr helpctx;
  172. /*
  173. * Setting this to non-NULL coerces two controls to have their
  174. * y-coordinates adjusted so that they can sit alongside each
  175. * other and look nicely aligned, even if they're different
  176. * heights.
  177. *
  178. * Set this field on the _second_ control of the pair (in
  179. * terms of order in the data structure), so that when it's
  180. * instantiated, the first one is already there to be referred
  181. * to.
  182. */
  183. union control *align_next_to;
  184. } generic;
  185. struct {
  186. STANDARD_PREFIX;
  187. union control *ctrl;
  188. } tabdelay;
  189. struct {
  190. STANDARD_PREFIX;
  191. } text;
  192. struct {
  193. STANDARD_PREFIX;
  194. char shortcut; /* keyboard shortcut */
  195. /*
  196. * Percentage of the dialog-box width used by the edit box.
  197. * If this is set to 100, the label is on its own line;
  198. * otherwise the label is on the same line as the box
  199. * itself.
  200. */
  201. int percentwidth;
  202. bool password; /* details of input are hidden */
  203. /*
  204. * A special case of the edit box is the combo box, which
  205. * has a drop-down list built in. (Note that a _non_-
  206. * editable drop-down list is done as a special case of a
  207. * list box.)
  208. *
  209. * Don't try setting has_list and password on the same
  210. * control; front ends are not required to support that
  211. * combination.
  212. */
  213. bool has_list;
  214. /*
  215. * Edit boxes tend to need two items of context, so here's
  216. * a spare.
  217. */
  218. intorptr context2;
  219. } editbox;
  220. struct {
  221. STANDARD_PREFIX;
  222. /*
  223. * `shortcut' here is a single keyboard shortcut which is
  224. * expected to select the whole group of radio buttons. It
  225. * can be NO_SHORTCUT if required, and there is also a way
  226. * to place individual shortcuts on each button; see below.
  227. */
  228. char shortcut;
  229. /*
  230. * There are separate fields for `ncolumns' and `nbuttons'
  231. * for several reasons.
  232. *
  233. * Firstly, we sometimes want the last of a set of buttons
  234. * to have a longer label than the rest; we achieve this by
  235. * setting `ncolumns' higher than `nbuttons', and the
  236. * layout code is expected to understand that the final
  237. * button should be given all the remaining space on the
  238. * line. This sounds like a ludicrously specific special
  239. * case (if we're doing this sort of thing, why not have
  240. * the general ability to have a particular button span
  241. * more than one column whether it's the last one or not?)
  242. * but actually it's reasonably common for the sort of
  243. * three-way control you get a lot of in PuTTY: `yes'
  244. * versus `no' versus `some more complex way to decide'.
  245. *
  246. * Secondly, setting `nbuttons' higher than `ncolumns' lets
  247. * us have more than one line of radio buttons for a single
  248. * setting. A very important special case of this is
  249. * setting `ncolumns' to 1, so that each button is on its
  250. * own line.
  251. */
  252. int ncolumns;
  253. int nbuttons;
  254. /*
  255. * This points to a dynamically allocated array of `char *'
  256. * pointers, each of which points to a dynamically
  257. * allocated string.
  258. */
  259. char **buttons; /* `nbuttons' button labels */
  260. /*
  261. * This points to a dynamically allocated array of `char'
  262. * giving the individual keyboard shortcuts for each radio
  263. * button. The array may be NULL if none are required.
  264. */
  265. char *shortcuts; /* `nbuttons' shortcuts; may be NULL */
  266. /*
  267. * This points to a dynamically allocated array of
  268. * intorptr, giving helpful data for each button.
  269. */
  270. intorptr *buttondata; /* `nbuttons' entries; may be NULL */
  271. } radio;
  272. struct {
  273. STANDARD_PREFIX;
  274. char shortcut;
  275. } checkbox;
  276. struct {
  277. STANDARD_PREFIX;
  278. char shortcut;
  279. /*
  280. * At least Windows has the concept of a `default push
  281. * button', which gets implicitly pressed when you hit
  282. * Return even if it doesn't have the input focus.
  283. */
  284. bool isdefault;
  285. /*
  286. * Also, the reverse of this: a default cancel-type button,
  287. * which is implicitly pressed when you hit Escape.
  288. */
  289. bool iscancel;
  290. } button;
  291. struct {
  292. STANDARD_PREFIX;
  293. char shortcut; /* keyboard shortcut */
  294. /*
  295. * Height of the list box, in approximate number of lines.
  296. * If this is zero, the list is a drop-down list.
  297. */
  298. int height; /* height in lines */
  299. /*
  300. * If this is set, the list elements can be reordered by
  301. * the user (by drag-and-drop or by Up and Down buttons,
  302. * whatever the per-platform implementation feels
  303. * comfortable with). This is not guaranteed to work on a
  304. * drop-down list, so don't try it!
  305. */
  306. bool draglist;
  307. /*
  308. * If this is non-zero, the list can have more than one
  309. * element selected at a time. This is not guaranteed to
  310. * work on a drop-down list, so don't try it!
  311. *
  312. * Different non-zero values request slightly different
  313. * types of multi-selection (this may well be meaningful
  314. * only in GTK, so everyone else can ignore it if they
  315. * want). 1 means the list box expects to have individual
  316. * items selected, whereas 2 means it expects the user to
  317. * want to select a large contiguous range at a time.
  318. */
  319. int multisel;
  320. /*
  321. * Percentage of the dialog-box width used by the list box.
  322. * If this is set to 100, the label is on its own line;
  323. * otherwise the label is on the same line as the box
  324. * itself. Setting this to anything other than 100 is not
  325. * guaranteed to work on a _non_-drop-down list, so don't
  326. * try it!
  327. */
  328. int percentwidth;
  329. /*
  330. * Some list boxes contain strings that contain tab
  331. * characters. If `ncols' is greater than 0, then
  332. * `percentages' is expected to be non-zero and to contain
  333. * the respective widths of `ncols' columns, which together
  334. * will exactly fit the width of the list box. Otherwise
  335. * `percentages' must be NULL.
  336. *
  337. * There should never be more than one column in a
  338. * drop-down list (one with height==0), because front ends
  339. * may have to implement it as a special case of an
  340. * editable combo box.
  341. */
  342. int ncols; /* number of columns */
  343. int *percentages; /* % width of each column */
  344. /*
  345. * Flag which can be set to false to suppress the horizontal
  346. * scroll bar if a list box entry goes off the right-hand
  347. * side.
  348. */
  349. bool hscroll;
  350. } listbox;
  351. struct {
  352. STANDARD_PREFIX;
  353. char shortcut;
  354. /*
  355. * `filter' dictates what type of files will be selected by
  356. * default; for example, when selecting private key files
  357. * the file selector would do well to only show .PPK files
  358. * (on those systems where this is the chosen extension).
  359. *
  360. * The precise contents of `filter' are platform-defined,
  361. * unfortunately. The special value NULL means `all files'
  362. * and is always a valid fallback.
  363. *
  364. * Unlike almost all strings in this structure, this value
  365. * is NOT expected to require freeing (although of course
  366. * you can always use ctrl_alloc if you do need to create
  367. * one on the fly). This is because the likely mode of use
  368. * is to define string constants in a platform-specific
  369. * header file, and directly reference those. Or worse, a
  370. * particular platform might choose to cast integers into
  371. * this pointer type...
  372. */
  373. char const *filter;
  374. /*
  375. * Some systems like to know whether a file selector is
  376. * choosing a file to read or one to write (and possibly
  377. * create).
  378. */
  379. bool for_writing;
  380. /*
  381. * On at least some platforms, the file selector is a
  382. * separate dialog box, and contains a user-settable title.
  383. *
  384. * This value _is_ expected to require freeing.
  385. */
  386. char *title;
  387. } fileselect;
  388. struct {
  389. /* In this variant, `label' MUST be NULL. */
  390. STANDARD_PREFIX;
  391. int ncols; /* number of columns */
  392. int *percentages; /* % width of each column */
  393. /*
  394. * Every time this control type appears, exactly one of
  395. * `ncols' and the previous number of columns MUST be one.
  396. * Attempting to allow a seamless transition from a four-
  397. * to a five-column layout, for example, would be way more
  398. * trouble than it was worth. If you must lay things out
  399. * like that, define eight unevenly sized columns and use
  400. * column-spanning a lot. But better still, just don't.
  401. *
  402. * `percentages' may be NULL if ncols==1, to save space.
  403. */
  404. } columns;
  405. struct {
  406. STANDARD_PREFIX;
  407. char shortcut;
  408. } fontselect;
  409. };
  410. #undef STANDARD_PREFIX
  411. /*
  412. * `controlset' is a container holding an array of `union control'
  413. * structures, together with a panel name and a title for the whole
  414. * set. In Windows and any similar-looking GUI, each `controlset'
  415. * in the config will be a container box within a panel.
  416. *
  417. * Special case: if `boxname' is NULL, the control set gives an
  418. * overall title for an entire panel of controls.
  419. */
  420. struct controlset {
  421. char *pathname; /* panel path, e.g. "SSH/Tunnels" */
  422. char *boxname; /* internal short name of controlset */
  423. char *boxtitle; /* title of container box */
  424. int ncolumns; /* current no. of columns at bottom */
  425. size_t ncontrols; /* number of `union control' in array */
  426. size_t ctrlsize; /* allocated size of array */
  427. union control **ctrls; /* actual array */
  428. };
  429. typedef void (*ctrl_freefn_t)(void *); /* used by ctrl_alloc_with_free */
  430. /*
  431. * This is the container structure which holds a complete set of
  432. * controls.
  433. */
  434. struct controlbox {
  435. size_t nctrlsets; /* number of ctrlsets */
  436. size_t ctrlsetsize; /* ctrlset size */
  437. struct controlset **ctrlsets; /* actual array of ctrlsets */
  438. size_t nfrees;
  439. size_t freesize;
  440. void **frees; /* array of aux data areas to free */
  441. ctrl_freefn_t *freefuncs; /* parallel array of free functions */
  442. };
  443. struct controlbox *ctrl_new_box(void);
  444. void ctrl_free_box(struct controlbox *);
  445. /*
  446. * Standard functions used for populating a controlbox structure.
  447. */
  448. /* Set up a panel title. */
  449. struct controlset *ctrl_settitle(struct controlbox *,
  450. const char *path, const char *title);
  451. /* Retrieve a pointer to a controlset, creating it if absent. */
  452. struct controlset *ctrl_getset(struct controlbox *, const char *path,
  453. const char *name, const char *boxtitle);
  454. void ctrl_free_set(struct controlset *);
  455. void ctrl_free(union control *);
  456. /*
  457. * This function works like `malloc', but the memory it returns
  458. * will be automatically freed when the controlbox is freed. Note
  459. * that a controlbox is a dialog-box _template_, not an instance,
  460. * and so data allocated through this function is better not used
  461. * to hold modifiable per-instance things. It's mostly here for
  462. * allocating structures to be passed as control handler params.
  463. *
  464. * ctrl_alloc_with_free also allows you to provide a function to free
  465. * the structure, in case there are other dynamically allocated bits
  466. * and pieces dangling off it.
  467. */
  468. void *ctrl_alloc(struct controlbox *b, size_t size);
  469. void *ctrl_alloc_with_free(struct controlbox *b, size_t size,
  470. ctrl_freefn_t freefunc);
  471. /*
  472. * Individual routines to create `union control' structures in a controlset.
  473. *
  474. * Most of these routines allow the most common fields to be set
  475. * directly, and put default values in the rest. Each one returns a
  476. * pointer to the `union control' it created, so that final tweaks
  477. * can be made.
  478. */
  479. /* `ncolumns' is followed by that many percentages, as integers. */
  480. union control *ctrl_columns(struct controlset *, int ncolumns, ...);
  481. union control *ctrl_editbox(struct controlset *, const char *label,
  482. char shortcut, int percentage, intorptr helpctx,
  483. handler_fn handler,
  484. intorptr context, intorptr context2);
  485. union control *ctrl_combobox(struct controlset *, const char *label,
  486. char shortcut, int percentage, intorptr helpctx,
  487. handler_fn handler,
  488. intorptr context, intorptr context2);
  489. /*
  490. * `ncolumns' is followed by (alternately) radio button titles and
  491. * intorptrs, until a NULL in place of a title string is seen. Each
  492. * title is expected to be followed by a shortcut _iff_ `shortcut'
  493. * is NO_SHORTCUT.
  494. */
  495. union control *ctrl_radiobuttons(struct controlset *, const char *label,
  496. char shortcut, int ncolumns, intorptr helpctx,
  497. handler_fn handler, intorptr context, ...);
  498. union control *ctrl_pushbutton(struct controlset *, const char *label,
  499. char shortcut, intorptr helpctx,
  500. handler_fn handler, intorptr context);
  501. union control *ctrl_listbox(struct controlset *, const char *label,
  502. char shortcut, intorptr helpctx,
  503. handler_fn handler, intorptr context);
  504. union control *ctrl_droplist(struct controlset *, const char *label,
  505. char shortcut, int percentage, intorptr helpctx,
  506. handler_fn handler, intorptr context);
  507. union control *ctrl_draglist(struct controlset *, const char *label,
  508. char shortcut, intorptr helpctx,
  509. handler_fn handler, intorptr context);
  510. union control *ctrl_filesel(struct controlset *, const char *label,
  511. char shortcut, const char *filter, bool write,
  512. const char *title, intorptr helpctx,
  513. handler_fn handler, intorptr context);
  514. union control *ctrl_fontsel(struct controlset *, const char *label,
  515. char shortcut, intorptr helpctx,
  516. handler_fn handler, intorptr context);
  517. union control *ctrl_text(struct controlset *, const char *text,
  518. intorptr helpctx);
  519. union control *ctrl_checkbox(struct controlset *, const char *label,
  520. char shortcut, intorptr helpctx,
  521. handler_fn handler, intorptr context);
  522. union control *ctrl_tabdelay(struct controlset *, union control *);
  523. /*
  524. * Routines the platform-independent dialog code can call to read
  525. * and write the values of controls.
  526. */
  527. void dlg_radiobutton_set(union control *ctrl, dlgparam *dp, int whichbutton);
  528. int dlg_radiobutton_get(union control *ctrl, dlgparam *dp);
  529. void dlg_checkbox_set(union control *ctrl, dlgparam *dp, bool checked);
  530. bool dlg_checkbox_get(union control *ctrl, dlgparam *dp);
  531. void dlg_editbox_set(union control *ctrl, dlgparam *dp, char const *text);
  532. char *dlg_editbox_get(union control *ctrl, dlgparam *dp); /* result must be freed by caller */
  533. /* The `listbox' functions can also apply to combo boxes. */
  534. void dlg_listbox_clear(union control *ctrl, dlgparam *dp);
  535. void dlg_listbox_del(union control *ctrl, dlgparam *dp, int index);
  536. void dlg_listbox_add(union control *ctrl, dlgparam *dp, char const *text);
  537. /*
  538. * Each listbox entry may have a numeric id associated with it.
  539. * Note that some front ends only permit a string to be stored at
  540. * each position, which means that _if_ you put two identical
  541. * strings in any listbox then you MUST not assign them different
  542. * IDs and expect to get meaningful results back.
  543. */
  544. void dlg_listbox_addwithid(union control *ctrl, dlgparam *dp,
  545. char const *text, int id);
  546. int dlg_listbox_getid(union control *ctrl, dlgparam *dp, int index);
  547. /* dlg_listbox_index returns <0 if no single element is selected. */
  548. int dlg_listbox_index(union control *ctrl, dlgparam *dp);
  549. bool dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index);
  550. void dlg_listbox_select(union control *ctrl, dlgparam *dp, int index);
  551. void dlg_text_set(union control *ctrl, dlgparam *dp, char const *text);
  552. void dlg_filesel_set(union control *ctrl, dlgparam *dp, Filename *fn);
  553. Filename *dlg_filesel_get(union control *ctrl, dlgparam *dp);
  554. void dlg_fontsel_set(union control *ctrl, dlgparam *dp, FontSpec *fn);
  555. FontSpec *dlg_fontsel_get(union control *ctrl, dlgparam *dp);
  556. /*
  557. * Bracketing a large set of updates in these two functions will
  558. * cause the front end (if possible) to delay updating the screen
  559. * until it's all complete, thus avoiding flicker.
  560. */
  561. void dlg_update_start(union control *ctrl, dlgparam *dp);
  562. void dlg_update_done(union control *ctrl, dlgparam *dp);
  563. /*
  564. * Set input focus into a particular control.
  565. */
  566. void dlg_set_focus(union control *ctrl, dlgparam *dp);
  567. /*
  568. * Change the label text on a control.
  569. */
  570. void dlg_label_change(union control *ctrl, dlgparam *dp, char const *text);
  571. /*
  572. * Return the `ctrl' structure for the most recent control that had
  573. * the input focus apart from the one mentioned. This is NOT
  574. * GUARANTEED to work on all platforms, so don't base any critical
  575. * functionality on it!
  576. */
  577. union control *dlg_last_focused(union control *ctrl, dlgparam *dp);
  578. /*
  579. * Find out whether a particular control is currently visible.
  580. */
  581. bool dlg_is_visible(union control *ctrl, dlgparam *dp);
  582. /*
  583. * During event processing, you might well want to give an error
  584. * indication to the user. dlg_beep() is a quick and easy generic
  585. * error; dlg_error() puts up a message-box or equivalent.
  586. */
  587. void dlg_beep(dlgparam *dp);
  588. void dlg_error_msg(dlgparam *dp, const char *msg);
  589. /*
  590. * This function signals to the front end that the dialog's
  591. * processing is completed, and passes an integer value (typically
  592. * a success status).
  593. */
  594. void dlg_end(dlgparam *dp, int value);
  595. /*
  596. * Routines to manage a (per-platform) colour selector.
  597. * dlg_coloursel_start() is called in an event handler, and
  598. * schedules the running of a colour selector after the event
  599. * handler returns. The colour selector will send EVENT_CALLBACK to
  600. * the control that spawned it, when it's finished;
  601. * dlg_coloursel_results() fetches the results, as integers from 0
  602. * to 255; it returns nonzero on success, or zero if the colour
  603. * selector was dismissed by hitting Cancel or similar.
  604. *
  605. * dlg_coloursel_start() accepts an RGB triple which is used to
  606. * initialise the colour selector to its starting value.
  607. */
  608. void dlg_coloursel_start(union control *ctrl, dlgparam *dp,
  609. int r, int g, int b);
  610. bool dlg_coloursel_results(union control *ctrl, dlgparam *dp,
  611. int *r, int *g, int *b);
  612. /*
  613. * This routine is used by the platform-independent code to
  614. * indicate that the value of a particular control is likely to
  615. * have changed. It triggers a call of the handler for that control
  616. * with `event' set to EVENT_REFRESH.
  617. *
  618. * If `ctrl' is NULL, _all_ controls in the dialog get refreshed
  619. * (for loading or saving entire sets of settings).
  620. */
  621. void dlg_refresh(union control *ctrl, dlgparam *dp);
  622. /*
  623. * Standard helper functions for reading a controlbox structure.
  624. */
  625. /*
  626. * Find the index of next controlset in a controlbox for a given
  627. * path, or -1 if no such controlset exists. If -1 is passed as
  628. * input, finds the first. Intended usage is something like
  629. *
  630. * for (index=-1; (index=ctrl_find_path(ctrlbox, index, path)) >= 0 ;) {
  631. * ... process this controlset ...
  632. * }
  633. */
  634. int ctrl_find_path(struct controlbox *b, const char *path, int index);
  635. int ctrl_path_elements(const char *path);
  636. /* Return the number of matching path elements at the starts of p1 and p2,
  637. * or INT_MAX if the paths are identical. */
  638. int ctrl_path_compare(const char *p1, const char *p2);