Changeset f2d6d44e in mainline
- Timestamp:
- 2021-09-22T09:52:01Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- be869b0
- Parents:
- 7572eb6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
r7572eb6 rf2d6d44e 39 39 #include <clipboard.h> 40 40 #include <errno.h> 41 #include <gfx/color.h> 42 #include <gfx/render.h> 41 43 #include <io/kbd_event.h> 42 44 #include <io/keycode.h> … … 49 51 #include <stdbool.h> 50 52 #include <types/common.h> 53 #include <ui/control.h> 51 54 #include <ui/fixed.h> 52 55 #include <ui/menu.h> … … 73 76 */ 74 77 typedef struct { 78 /** Base control object */ 79 struct ui_control *control; 80 81 /** Containing window */ 82 ui_window_t *window; 83 84 /** UI resource */ 85 struct ui_resource *res; 86 87 /** Pane rectangle */ 88 gfx_rect_t rect; 89 75 90 /* Pane dimensions */ 76 91 int rows, columns; … … 160 175 static char *prompt(char const *prompt, char const *init_value); 161 176 177 static errno_t pane_init(ui_window_t *, pane_t *); 178 static void pane_fini(pane_t *); 179 static ui_control_t *pane_ctl(pane_t *); 162 180 static void pane_text_display(void); 163 181 static void pane_row_display(void); … … 219 237 static void edit_edit_paste(ui_menu_entry_t *, void *); 220 238 239 static void pane_ctl_destroy(void *); 240 static errno_t pane_ctl_paint(void *); 241 static ui_evclaim_t pane_ctl_pos_event(void *, pos_event_t *); 242 243 /** Pabe control ops */ 244 ui_control_ops_t pane_ctl_ops = { 245 .destroy = pane_ctl_destroy, 246 .paint = pane_ctl_paint, 247 .pos_event = pane_ctl_pos_event 248 }; 249 250 221 251 int main(int argc, char *argv[]) 222 252 { … … 440 470 } 441 471 472 rc = pane_init(edit->window, &pane); 473 if (rc != EOK) { 474 printf("Error initializing pane.\n"); 475 return rc; 476 } 477 478 rc = ui_fixed_add(fixed, pane_ctl(&pane)); 479 if (rc != EOK) { 480 printf("Error adding control to layout.\n"); 481 return rc; 482 } 483 442 484 ui_window_add(edit->window, ui_fixed_ctl(fixed)); 443 485 return EOK; … … 456 498 static void edit_ui_destroy(edit_t *edit) 457 499 { 500 pane_fini(&pane); 458 501 ui_window_destroy(edit->window); 459 502 ui_destroy(edit->ui); … … 918 961 } 919 962 963 /** Initialize pane. 964 * 965 * TODO: Replace with pane_create() that allocates the pane. 966 * 967 * @param window Editor window 968 * @param pane Pane 969 * @return EOK on success or an error code 970 */ 971 static errno_t pane_init(ui_window_t *window, pane_t *pane) 972 { 973 errno_t rc; 974 gfx_rect_t arect; 975 976 rc = ui_control_new(&pane_ctl_ops, (void *) pane, &pane->control); 977 if (rc != EOK) 978 return rc; 979 980 pane->res = ui_window_get_res(window); 981 pane->window = window; 982 983 ui_window_get_app_rect(window, &arect); 984 pane->rect.p0.x = arect.p0.x; 985 pane->rect.p0.y = arect.p0.y + 1; 986 pane->rect.p1.x = arect.p1.x; 987 pane->rect.p1.y = arect.p1.y - 1; 988 989 return EOK; 990 } 991 992 /** Finalize pane. 993 * 994 * TODO: Replace with pane_destroy() that deallocates the pane. 995 * 996 * @param pane Pane 997 */ 998 static void pane_fini(pane_t *pane) 999 { 1000 ui_control_delete(pane->control); 1001 pane->control = NULL; 1002 } 1003 1004 /** Return base control object for a pane. 1005 * 1006 * @param pane Pane 1007 * @return Base UI cntrol 1008 */ 1009 static ui_control_t *pane_ctl(pane_t *pane) 1010 { 1011 return pane->control; 1012 } 1013 920 1014 static void pane_text_display(void) 921 1015 { … … 1168 1262 // console_set_pos(con, coord.column - pane.sh_column, 1169 1263 // coord.row - pane.sh_row); 1264 } 1265 1266 /** Destroy pane control. 1267 * 1268 * @param arg Argument (pane_t *) 1269 */ 1270 static void pane_ctl_destroy(void *arg) 1271 { 1272 pane_t *pane = (pane_t *)arg; 1273 1274 pane_fini(pane); 1275 } 1276 1277 /** Paint pane control. 1278 * 1279 * @param arg Argument (pane_t *) 1280 */ 1281 static errno_t pane_ctl_paint(void *arg) 1282 { 1283 pane_t *pane = (pane_t *)arg; 1284 gfx_color_t *color = NULL; 1285 gfx_context_t *gc; 1286 errno_t rc; 1287 1288 gc = ui_window_get_gc(pane->window); 1289 1290 rc = gfx_color_new_ega(0x01, &color); 1291 if (rc != EOK) 1292 goto error; 1293 1294 rc = gfx_set_color(gc, color); 1295 if (rc != EOK) 1296 goto error; 1297 1298 rc = gfx_fill_rect(gc, &pane->rect); 1299 if (rc != EOK) 1300 goto error; 1301 1302 rc = gfx_update(gc); 1303 if (rc != EOK) 1304 goto error; 1305 1306 gfx_color_delete(color); 1307 return EOK; 1308 error: 1309 if (color != NULL) 1310 gfx_color_delete(color); 1311 return rc; 1312 } 1313 1314 /** Handle pane control position event. 1315 * 1316 * @param arg Argument (pane_t *) 1317 * @param event Position event 1318 */ 1319 static ui_evclaim_t pane_ctl_pos_event(void *arg, pos_event_t *event) 1320 { 1321 return ui_unclaimed; 1170 1322 } 1171 1323
Note:
See TracChangeset
for help on using the changeset viewer.