1 /* 2 * Copyright (c)2004 Cat's Eye Technologies. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 11 * Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in 13 * the documentation and/or other materials provided with the 14 * distribution. 15 * 16 * Neither the name of Cat's Eye Technologies nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 31 * OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 /* 35 * curses_widget.h 36 * $Id: curses_widget.h,v 1.5 2005/02/08 07:49:03 cpressey Exp $ 37 */ 38 39 #include "curses_form.h" 40 41 #ifndef __CURSES_WIDGET_H 42 #define __CURSES_WIDGET_H 43 44 typedef enum { 45 CURSES_LABEL, 46 CURSES_TEXTBOX, 47 CURSES_BUTTON, 48 CURSES_PROGRESS, 49 CURSES_CHECKBOX, 50 CURSES_LISTBOX 51 } widget_t; 52 53 struct curses_widget { 54 struct curses_widget *next; /* chain of widgets in form */ 55 struct curses_widget *prev; 56 57 struct curses_form *form; /* form in which widget lives */ 58 59 unsigned int x; /* x pos of widget in form, 0 = left edge */ 60 unsigned int y; /* y pos of widget in form, 0 = top edge */ 61 unsigned int width; /* width of widget */ 62 unsigned int type; /* CURSES_* type of widget */ 63 char *text; /* for labels, textboxes, buttons */ 64 unsigned int size; /* for textboxes, allocated size of text */ 65 unsigned int curpos; /* for textboxes, cursor position */ 66 unsigned int offset; /* for textboxes, first displayed char */ 67 int editable; /* for textboxes, text is editable */ 68 int obscured; /* for textboxes, text is ****'ed out */ 69 int amount; /* for progress bars, sliders, checkboxes */ 70 int spin; /* for progress bars */ 71 char *tooltip; /* short help text displayed on statusbar */ 72 char accel; /* 'accelerator' - shortcut key */ 73 int flags; /* flags */ 74 75 int user_id; /* misc integer */ 76 void *userdata; /* misc pointer */ 77 78 /* callback for when widget is clicked */ 79 /* for buttons */ 80 int (*click_cb)(struct curses_widget *); 81 }; 82 83 #define CURSES_WIDGET_CENTER 1 /* auto center this widget? */ 84 #define CURSES_WIDGET_WIDEN 2 /* auto widen this widget? */ 85 86 struct curses_widget *curses_widget_new(unsigned int, unsigned int, 87 unsigned int, widget_t, 88 const char *, 89 unsigned int, unsigned int); 90 void curses_widget_free(struct curses_widget *); 91 void curses_widget_draw(struct curses_widget *); 92 void curses_widget_draw_tooltip(struct curses_widget *); 93 int curses_widget_can_take_focus(struct curses_widget *); 94 void curses_widget_tooltip_set(struct curses_widget *, const char *); 95 int curses_widget_set_click_cb(struct curses_widget *, 96 int (*)(struct curses_widget *)); 97 int curses_widget_click(struct curses_widget *); 98 99 int curses_textbox_advance_char(struct curses_widget *); 100 int curses_textbox_retreat_char(struct curses_widget *); 101 int curses_textbox_home(struct curses_widget *); 102 int curses_textbox_end(struct curses_widget *); 103 int curses_textbox_insert_char(struct curses_widget *, char); 104 int curses_textbox_backspace_char(struct curses_widget *); 105 int curses_textbox_delete_char(struct curses_widget *); 106 int curses_textbox_set_text(struct curses_widget *, const char *); 107 108 int curses_checkbox_toggle(struct curses_widget *); 109 110 int curses_progress_spin(struct curses_widget *); 111 112 #endif /* !__CURSES_WIDGET_H */ 113