1 /*=========================================================================== 2 * 3 * PUBLIC DOMAIN NOTICE 4 * National Center for Biotechnology Information 5 * 6 * This software/database is a "United States Government Work" under the 7 * terms of the United States Copyright Act. It was written as part of 8 * the author's official duties as a United States Government employee and 9 * thus cannot be copyrighted. This software/database is freely available 10 * to the public for use. The National Library of Medicine and the U.S. 11 * Government have not placed any restriction on its use or reproduction. 12 * 13 * Although all reasonable efforts have been taken to ensure the accuracy 14 * and reliability of the software and data, the NLM and the U.S. 15 * Government do not and cannot warrant the performance or results that 16 * may be obtained by using this software or data. The NLM and the U.S. 17 * Government disclaim all warranties, express or implied, including 18 * warranties of performance, merchantability or fitness for any particular 19 * purpose. 20 * 21 * Please cite the author in any work or product based on this material. 22 * 23 * =========================================================================== 24 * 25 */ 26 #ifndef _h_tui_widget_ 27 #define _h_tui_widget_ 28 29 #include <tui/tui.h> 30 #include <tui/tui_dlg.h> 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 #define MAX_GRID_COLS 256 37 #define MAX_GRID_ROWS 128 38 39 rc_t draw_highlighted( struct KTUI * tui, uint32_t x, uint32_t y, uint32_t w, 40 tui_ac * ac, tui_ac * hl_ac, const char * caption ); 41 42 rc_t DlgPaint( struct KTUI * tui, int x, int y, int w, int h, KTUI_color c ); 43 rc_t DlgWrite( struct KTUI * tui, int x, int y, const tui_ac * ac, const char * s, uint32_t l ); 44 45 rc_t DrawVScroll( struct KTUI * tui, tui_rect * r, uint64_t count, uint64_t value, 46 KTUI_color c_bar, KTUI_color c_sel ); 47 rc_t DrawHScroll( struct KTUI * tui, tui_rect * r, uint64_t count, uint64_t value, 48 KTUI_color c_bar, KTUI_color c_sel ); 49 50 rc_t draw_background( struct KTUI * tui, bool focused, tui_point * p, 51 int w, int h, KTUI_color bg ); 52 53 54 /* ****************************************************************************************** */ 55 56 typedef uint32_t KTUI_Widget_type; 57 enum 58 { 59 KTUIW_label = 0, 60 KTUIW_tabhdr, 61 KTUIW_button, 62 KTUIW_checkbox, 63 KTUIW_input, 64 KTUIW_radiobox, 65 KTUIW_list, 66 KTUIW_progress, 67 KTUIW_spinedit, 68 KTUIW_grid 69 }; 70 71 72 struct KTUIWidget; 73 struct KTUIDlg; 74 75 typedef void ( * draw_cb ) ( struct KTUIWidget * w ); 76 typedef void ( * init_cb ) ( struct KTUIWidget * w ); 77 typedef bool ( * event_cb ) ( struct KTUIWidget * w, tui_event * event, bool hotkey ); 78 79 typedef struct KTUIWidget 80 { 81 struct KTUIDlg * dlg; /* pointer to dialog they belong to */ 82 struct KTUI * tui; /* pointer to the hw-specific layer */ 83 struct KTUIPalette * palette; /* where the colors come from */ 84 uint32_t id; /* a unique id... */ 85 uint32_t page_id; /* the page of the parent the widget belongs to */ 86 KTUI_Widget_type wtype; /* what type of widget it is... */ 87 uint32_t vector_idx; /* where in the vector it is inserted */ 88 tui_rect r; /* - a rect where it appears */ 89 90 KTUI_color bg_override; /* the color if the background is different from palette */ 91 bool bg_override_flag; 92 93 KTUI_color fg_override; /* the color if the forground is different from palette */ 94 bool fg_override_flag; 95 96 char * caption; /* - a caption */ 97 98 draw_cb on_draw; /* know how to draw itself */ 99 event_cb on_event; /* know how to handle events */ 100 uint64_t ints[ 8 ]; /* 8 internal 'state' integers */ 101 102 bool can_focus; /* can it be focused */ 103 bool focused; /* does it have focus... */ 104 bool visible; /* is it visible */ 105 bool changed; /* has the widget changed */ 106 107 /* different value types, according to the widget type one is used: */ 108 109 /* in case of a checkbox */ 110 bool bool_value; 111 112 /* in case of a spin-edit */ 113 int64_t int64_value; 114 int64_t int64_min; 115 int64_t int64_max; 116 117 /* in case of a percent-bar */ 118 int32_t percent; 119 int32_t precision; 120 121 /* for the input-string */ 122 char * txt; 123 size_t txt_length; 124 125 /* for Radio-Box / ListBox */ 126 VNamelist * strings; 127 uint64_t selected_string; 128 129 /* for Grid */ 130 TUIWGrid_data * grid_data; 131 132 } KTUIWidget; 133 134 135 rc_t TUI_MakeWidget ( KTUIWidget ** self, struct KTUIDlg * dlg, uint32_t id, KTUI_Widget_type wtype, 136 const tui_rect * r, draw_cb on_draw, event_cb on_event ); 137 138 void TUI_DestroyWidget( struct KTUIWidget * self ); 139 140 const tui_ac * GetWidgetPaletteEntry ( struct KTUIWidget * self, KTUIPa_entry what ); 141 struct KTUIPalette * CopyWidgetPalette( struct KTUIWidget * self ); 142 rc_t ReleaseWidgetPalette( struct KTUIWidget * self ); 143 144 rc_t RedrawWidget( KTUIWidget * w ); 145 146 rc_t RedrawWidgetAndPushEvent( KTUIWidget * w, 147 KTUIDlg_event_type ev_type, uint64_t value_1, uint64_t value_2, void * ptr_0 ); 148 149 rc_t GetWidgetRect ( struct KTUIWidget * self, tui_rect * r ); 150 rc_t SetWidgetRect ( struct KTUIWidget * self, const tui_rect * r, bool redraw ); 151 152 rc_t GetWidgetPageId ( struct KTUIWidget * self, uint32_t * id ); 153 rc_t SetWidgetPageId ( struct KTUIWidget * self, uint32_t id ); 154 155 rc_t SetWidgetCanFocus( struct KTUIWidget * self, bool can_focus ); 156 rc_t GetWidgetAc( struct KTUIWidget * self, KTUIPa_entry pa_entry, tui_ac * ac ); 157 rc_t GetWidgetHlAc( struct KTUIWidget * self, KTUIPa_entry pa_entry, tui_ac * ac ); 158 159 const char * GetWidgetCaption ( struct KTUIWidget * self ); 160 rc_t SetWidgetCaption ( struct KTUIWidget * self, const char * caption ); 161 162 bool GetWidgetVisible ( struct KTUIWidget * self ); 163 rc_t SetWidgetVisible ( struct KTUIWidget * self, bool visible, bool * redraw ); 164 165 bool GetWidgetChanged ( struct KTUIWidget * self ); 166 rc_t SetWidgetChanged ( struct KTUIWidget * self, bool changed ); 167 168 bool GetWidgetBoolValue ( struct KTUIWidget * self ); 169 rc_t SetWidgetBoolValue ( struct KTUIWidget * self, bool value ); 170 171 rc_t SetWidgetBg ( struct KTUIWidget * self, KTUI_color value ); 172 rc_t ReleaseWidgetBg ( struct KTUIWidget * self ); 173 174 rc_t SetWidgetFg ( struct KTUIWidget * self, KTUI_color value ); 175 rc_t ReleaseWidgetFg ( struct KTUIWidget * self ); 176 177 int64_t GetWidgetInt64Value ( struct KTUIWidget * self ); 178 rc_t SetWidgetInt64Value ( struct KTUIWidget * self, int64_t value ); 179 180 int64_t GetWidgetInt64Min ( struct KTUIWidget * self ); 181 rc_t SetWidgetInt64Min ( struct KTUIWidget * self, int64_t value ); 182 183 int64_t GetWidgetInt64Max ( struct KTUIWidget * self ); 184 rc_t SetWidgetInt64Max ( struct KTUIWidget * self, int64_t value ); 185 186 int32_t GetWidgetPercent ( struct KTUIWidget * self ); 187 rc_t SetWidgetPercent ( struct KTUIWidget * self, int32_t value ); 188 189 int32_t GetWidgetPrecision ( struct KTUIWidget * self ); 190 rc_t SetWidgetPrecision ( struct KTUIWidget * self, int32_t value ); 191 192 int32_t CalcWidgetPercent( int64_t value, int64_t max, uint32_t precision ); 193 194 const char * GetWidgetText ( struct KTUIWidget * self ); 195 rc_t SetWidgetText ( struct KTUIWidget * self, const char * txt ); 196 197 size_t GetWidgetTextLength ( struct KTUIWidget * self ); 198 rc_t SetWidgetTextLength ( struct KTUIWidget * self, size_t new_length ); 199 rc_t SetWidgetCarretPos ( struct KTUIWidget * self, size_t new_pos ); 200 rc_t SetWidgetAlphaMode ( struct KTUIWidget * self, uint32_t alpha_mode ); 201 202 rc_t AddWidgetString ( struct KTUIWidget * self, const char * txt ); 203 rc_t AddWidgetStrings ( struct KTUIWidget * self, VNamelist * src ); 204 const char * GetWidgetStringByIdx ( struct KTUIWidget * self, uint32_t idx ); 205 rc_t RemoveWidgetStringByIdx ( struct KTUIWidget * self, uint32_t idx ); 206 rc_t RemoveAllWidgetStrings ( struct KTUIWidget * self ); 207 uint32_t GetWidgetStringCount ( struct KTUIWidget * self ); 208 uint32_t HasWidgetString( struct KTUIWidget * self, const char * txt ); 209 uint32_t GetWidgetSelectedString( struct KTUIWidget * self ); 210 rc_t SetWidgetSelectedString ( struct KTUIWidget * self, uint32_t selection ); 211 212 TUIWGrid_data * GetWidgetGridData( struct KTUIWidget * self ); 213 rc_t SetWidgetGridData( struct KTUIWidget * self, TUIWGrid_data * grid_data, bool cached ); 214 215 #ifdef __cplusplus 216 } 217 #endif 218 219 #endif /* _h_tui_widget_ */ 220