Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/edit/edit.c

    r3c22438a r994f87b  
    11/*
    2  * Copyright (c) 2026 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * Copyright (c) 2012 Martin Sucha
    44 * All rights reserved.
     
    240240static void edit_ui_destroy(edit_t *);
    241241
    242 static void edit_wnd_resize(ui_window_t *, void *);
    243242static void edit_wnd_close(ui_window_t *, void *);
    244243static void edit_wnd_focus(ui_window_t *, void *, unsigned);
     
    247246
    248247static ui_window_cb_t edit_window_cb = {
    249         .resize = edit_wnd_resize,
    250248        .close = edit_wnd_close,
    251249        .focus = edit_wnd_focus,
     
    365363        edit_ui_destroy(&edit);
    366364        return 0;
    367 }
    368 
    369 /** Set menu bar rectangle.
    370  *
    371  * Set the menu bar rectangle based on editor window dimensions.
    372  * Used when window is created or resized.
    373  *
    374  * @param edit Editor
    375  */
    376 static void edit_menubar_set_rect(edit_t *edit)
    377 {
    378         gfx_rect_t arect;
    379         gfx_rect_t rect;
    380 
    381         ui_window_get_app_rect(edit->window, &arect);
    382 
    383         rect.p0 = arect.p0;
    384         rect.p1.x = arect.p1.x;
    385         rect.p1.y = arect.p0.y + 1;
    386         ui_menu_bar_set_rect(edit->menubar, &rect);
    387 }
    388 
    389 /** Set status bar rectangle.
    390  *
    391  * Set the status bar rectangle based on editor window dimensions.
    392  * Used when window is created or resized.
    393  *
    394  * @param edit Editor
    395  */
    396 static void edit_status_set_rect(edit_t *edit)
    397 {
    398         gfx_rect_t arect;
    399         gfx_rect_t rect;
    400 
    401         ui_window_get_app_rect(edit->window, &arect);
    402         rect.p0.x = arect.p0.x;
    403         rect.p0.y = arect.p1.y - 1;
    404         rect.p1 = arect.p1;
    405         ui_label_set_rect(edit->status, &rect);
    406365}
    407366
     
    436395        ui_menu_entry_t *mssep = NULL;
    437396        ui_menu_entry_t *mgoto = NULL;
     397        gfx_rect_t arect;
     398        gfx_rect_t rect;
    438399
    439400        rc = ui_create(UI_CONSOLE_DEFAULT, &edit->ui);
     
    621582        ui_menu_entry_set_cb(mgoto, edit_search_go_to_line, (void *) edit);
    622583
    623         edit_menubar_set_rect(edit);
     584        ui_window_get_app_rect(edit->window, &arect);
     585
     586        rect.p0 = arect.p0;
     587        rect.p1.x = arect.p1.x;
     588        rect.p1.y = arect.p0.y + 1;
     589        ui_menu_bar_set_rect(edit->menubar, &rect);
    624590
    625591        rc = ui_fixed_add(fixed, ui_menu_bar_ctl(edit->menubar));
     
    647613        }
    648614
    649         edit_status_set_rect(edit);
     615        rect.p0.x = arect.p0.x;
     616        rect.p0.y = arect.p1.y - 1;
     617        rect.p1 = arect.p1;
     618        ui_label_set_rect(edit->status, &rect);
    650619
    651620        rc = ui_fixed_add(fixed, ui_label_ctl(edit->status));
     
    12331202}
    12341203
    1235 static void pane_set_rect(pane_t *pane)
    1236 {
     1204/** Initialize pane.
     1205 *
     1206 * TODO: Replace with pane_create() that allocates the pane.
     1207 *
     1208 * @param window Editor window
     1209 * @param pane Pane
     1210 * @return EOK on success or an error code
     1211 */
     1212static errno_t pane_init(ui_window_t *window, pane_t *pane)
     1213{
     1214        errno_t rc;
    12371215        gfx_rect_t arect;
    12381216
    1239         ui_window_get_app_rect(pane->window, &arect);
     1217        pane->control = NULL;
     1218        pane->color = NULL;
     1219        pane->sel_color = NULL;
     1220
     1221        rc = ui_control_new(&pane_ctl_ops, (void *) pane, &pane->control);
     1222        if (rc != EOK)
     1223                goto error;
     1224
     1225        rc = gfx_color_new_ega(0x07, &pane->color);
     1226        if (rc != EOK)
     1227                goto error;
     1228
     1229        rc = gfx_color_new_ega(0x1e, &pane->sel_color);
     1230        if (rc != EOK)
     1231                goto error;
     1232
     1233        pane->res = ui_window_get_res(window);
     1234        pane->window = window;
     1235
     1236        ui_window_get_app_rect(window, &arect);
    12401237        pane->rect.p0.x = arect.p0.x;
    12411238        pane->rect.p0.y = arect.p0.y + 1;
     
    12451242        pane->columns = pane->rect.p1.x - pane->rect.p0.x;
    12461243        pane->rows = pane->rect.p1.y - pane->rect.p0.y;
    1247 }
    1248 
    1249 /** Initialize pane.
    1250  *
    1251  * TODO: Replace with pane_create() that allocates the pane.
    1252  *
    1253  * @param window Editor window
    1254  * @param pane Pane
    1255  * @return EOK on success or an error code
    1256  */
    1257 static errno_t pane_init(ui_window_t *window, pane_t *pane)
    1258 {
    1259         errno_t rc;
    1260 
    1261         pane->control = NULL;
    1262         pane->color = NULL;
    1263         pane->sel_color = NULL;
    1264 
    1265         rc = ui_control_new(&pane_ctl_ops, (void *) pane, &pane->control);
    1266         if (rc != EOK)
    1267                 goto error;
    1268 
    1269         rc = gfx_color_new_ega(0x07, &pane->color);
    1270         if (rc != EOK)
    1271                 goto error;
    1272 
    1273         rc = gfx_color_new_ega(0x1e, &pane->sel_color);
    1274         if (rc != EOK)
    1275                 goto error;
    1276 
    1277         pane->res = ui_window_get_res(window);
    1278         pane->window = window;
    1279 
    1280         pane_set_rect(pane);
     1244
    12811245        return EOK;
    12821246error:
     
    12921256
    12931257        return rc;
    1294 }
    1295 
    1296 static void pane_resize(pane_t *pane)
    1297 {
    1298         pane_set_rect(pane);
    1299 
    1300         /* Scroll in case cursor is now outside of the editor pane. */
    1301         caret_move_relative(0, 0, dir_before, true);
    1302 
    1303         pane_caret_display(pane);
    13041258}
    13051259
     
    23962350}
    23972351
    2398 /** Window was resized.
    2399  *
    2400  * @param window Window
    2401  * @param arg Argument (edit_t *)
    2402  */
    2403 static void edit_wnd_resize(ui_window_t *window, void *arg)
    2404 {
    2405         edit_t *edit = (edit_t *) arg;
    2406 
    2407         edit_menubar_set_rect(edit);
    2408         edit_status_set_rect(edit);
    2409         pane_resize(&pane);
    2410 }
    2411 
    24122352/** Window close request
    24132353 *
Note: See TracChangeset for help on using the changeset viewer.