widget.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #ifndef __WIDGET_H
  2. #define __WIDGET_H
  3. #include "dialog.h" /* Widget */
  4. #define C_BOOL 1
  5. #define C_CHANGE 2
  6. /* Please note that the first element in all the widgets is a */
  7. /* widget variable of type Widget. We abuse this fact everywhere */
  8. #define HIDDEN_BUTTON 0
  9. #define NARROW_BUTTON 1
  10. #define NORMAL_BUTTON 2
  11. #define DEFPUSH_BUTTON 3
  12. /* button callback */
  13. typedef int (*bcback) (int);
  14. typedef struct WButton {
  15. Widget widget;
  16. int action; /* what to do when pressed */
  17. int selected; /* button state */
  18. unsigned int flags; /* button flags */
  19. char *text; /* text of button */
  20. int hotkey; /* hot KEY */
  21. int hotpos; /* offset hot KEY char in text */
  22. bcback callback; /* Callback function */
  23. } WButton;
  24. typedef struct WRadio {
  25. Widget widget;
  26. unsigned int state; /* radio button state */
  27. int pos, sel;
  28. int count; /* number of members */
  29. const char **texts; /* texts of labels */
  30. int upper_letter_is_hotkey; /* If true, then the capital letter is a hk */
  31. } WRadio;
  32. typedef struct WCheck {
  33. Widget widget;
  34. unsigned int state; /* check button state */
  35. char *text; /* text of check button */
  36. int hotkey; /* hot KEY */
  37. int hotpos; /* offset hot KEY char in text */
  38. } WCheck;
  39. typedef struct WGauge {
  40. Widget widget;
  41. int shown;
  42. int max;
  43. int current;
  44. } WGauge;
  45. GList *history_get (const char *input_name);
  46. void history_put (const char *input_name, GList *h);
  47. char *show_hist (GList *history, int widget_y, int widget_x);
  48. typedef struct {
  49. Widget widget;
  50. int point; /* cursor position in the input line */
  51. int mark; /* The mark position */
  52. int first_shown; /* Index of the first shown character */
  53. int current_max_len; /* Maximum length of input line */
  54. int field_len; /* Length of the editing field */
  55. int color; /* color used */
  56. int first; /* Is first keystroke? */
  57. int disable_update; /* Do we want to skip updates? */
  58. int is_password; /* Is this a password input line? */
  59. unsigned char *buffer; /* pointer to editing buffer */
  60. GList *history; /* The history */
  61. int need_push; /* need to push the current Input on hist? */
  62. char **completions; /* Possible completions array */
  63. int completion_flags; /* INPUT_COMPLETE* bitwise flags(complete.h) */
  64. char *history_name; /* name of history for loading and saving */
  65. } WInput;
  66. /* For history load-save functions */
  67. #define INPUT_LAST_TEXT ((char *) 2)
  68. #define HISTORY_FILE_NAME ".mc/history"
  69. typedef struct {
  70. Widget widget;
  71. int auto_adjust_cols; /* compute widget.cols from strlen(text)? */
  72. char *text;
  73. int transparent; /* Paint in the default color fg/bg */
  74. } WLabel;
  75. typedef struct WLEntry {
  76. char *text; /* Text to display */
  77. int hotkey;
  78. void *data; /* Client information */
  79. struct WLEntry *next;
  80. struct WLEntry *prev;
  81. } WLEntry;
  82. struct WListbox;
  83. typedef struct WListbox WListbox;
  84. typedef int (*lcback) (WListbox *);
  85. /* Callback should return one of the following values */
  86. enum {
  87. LISTBOX_CONT, /* continue */
  88. LISTBOX_DONE /* finish dialog */
  89. };
  90. struct WListbox {
  91. Widget widget;
  92. WLEntry *list; /* Pointer to the circular double linked list. */
  93. WLEntry *top; /* The first element displayed */
  94. WLEntry *current; /* The current element displayed */
  95. int pos; /* Cur. pos, must be kept in sync with current */
  96. int count; /* Number of items in the listbox */
  97. int width;
  98. int height; /* Size of the widget */
  99. int allow_duplicates; /* Do we allow duplicates on the list? */
  100. int scrollbar; /* Draw a scrollbar? */
  101. lcback cback; /* The callback function */
  102. int cursor_x, cursor_y; /* Cache the values */
  103. };
  104. typedef struct WGroupbox {
  105. Widget widget;
  106. char *title;
  107. } WGroupbox;
  108. typedef void (*buttonbarfn)(void *);
  109. typedef struct {
  110. Widget widget;
  111. int visible; /* Is it visible? */
  112. struct {
  113. char *text;
  114. buttonbarfn function;
  115. void *data;
  116. } labels [10];
  117. } WButtonBar;
  118. /* Constructors */
  119. WButton *button_new (int y, int x, int action, int flags, const char *text,
  120. bcback callback);
  121. WRadio *radio_new (int y, int x, int count, const char **text, int use_hotkey);
  122. WCheck *check_new (int y, int x, int state, const char *text);
  123. WInput *input_new (int y, int x, int color, int len, const char *text, const char *histname);
  124. WLabel *label_new (int y, int x, const char *text);
  125. WGauge *gauge_new (int y, int x, int shown, int max, int current);
  126. WListbox *listbox_new (int x, int y, int width, int height, lcback callback);
  127. WGroupbox *groupbox_new (int x, int y, int width, int height, const char *title);
  128. /* Input lines */
  129. void winput_set_origin (WInput *i, int x, int field_len);
  130. cb_ret_t handle_char (WInput *in, int c_code);
  131. int is_in_input_map (WInput *in, int c_code);
  132. void update_input (WInput *in, int clear_first);
  133. void new_input (WInput *in);
  134. int push_history (WInput *in, const char *text);
  135. void stuff (WInput *in, const char *text, int insert_extra_space);
  136. void input_disable_update (WInput *in);
  137. void input_set_prompt (WInput *in, int field_len, const char *prompt);
  138. void input_enable_update (WInput *in);
  139. void input_set_point (WInput *in, int pos);
  140. void input_show_cursor (WInput *in);
  141. void assign_text (WInput *in, const char *text);
  142. cb_ret_t input_callback (WInput *in, widget_msg_t msg, int parm);
  143. /* Labels */
  144. void label_set_text (WLabel *label, const char *text);
  145. /* Gauges */
  146. void gauge_set_value (WGauge *g, int max, int current);
  147. void gauge_show (WGauge *g, int shown);
  148. /* Buttons */
  149. void button_set_text (WButton *b, const char *text);
  150. /* Listbox manager */
  151. WLEntry *listbox_get_data (WListbox *l, int pos);
  152. /* search text int listbox entries */
  153. WLEntry *listbox_search_text (WListbox *l, const char *text);
  154. void listbox_select_entry (WListbox *l, WLEntry *dest);
  155. void listbox_select_by_number (WListbox *l, int n);
  156. void listbox_select_last (WListbox *l, int set_top);
  157. void listbox_remove_current (WListbox *l, int force);
  158. void listbox_remove_list (WListbox *l);
  159. void listbox_get_current (WListbox *l, char **string, char **extra);
  160. enum append_pos {
  161. LISTBOX_APPEND_AT_END, /* append at the end */
  162. LISTBOX_APPEND_BEFORE, /* insert before current */
  163. LISTBOX_APPEND_AFTER /* insert after current */
  164. };
  165. char *listbox_add_item (WListbox *l, enum append_pos pos, int
  166. hotkey, const char *text, void *data);
  167. /* Hintbar routines */
  168. /* Buttonbar routines */
  169. WButtonBar *buttonbar_new (int visible);
  170. WButtonBar *find_buttonbar (Dlg_head *h);
  171. typedef void (*voidfn)(void);
  172. void define_label (Dlg_head *, int index, const char *text, voidfn);
  173. void define_label_data (Dlg_head *h, int idx, const char *text,
  174. buttonbarfn cback, void *data);
  175. void redraw_labels (Dlg_head *h);
  176. void buttonbar_hint (WButtonBar *bb, const char *s);
  177. #endif /* __WIDGET_H */