static void nmt_editor_grid_size_request (NmtNewtWidget *widget, int *width, int *height) { NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (widget); NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data; NmtEditorGridFormState *state = get_form_state (widget); gboolean add_padding = FALSE; int i; g_free (priv->row_heights); priv->row_heights = g_new0 (int, priv->rows->len); *height = 0; for (i = 0; i < priv->rows->len; i++) { int lwidth, lheight, wwidth, wheight, ewidth, eheight; if (!nmt_newt_widget_get_visible (rows[i].widget)) continue; if (rows[i].label) { nmt_newt_widget_size_request (rows[i].label, &lwidth, &lheight); lwidth += priv->indent; state->col_widths[0] = MAX (state->col_widths[0], lwidth); nmt_newt_widget_size_request (rows[i].widget, &wwidth, &wheight); state->col_widths[1] = MAX (state->col_widths[1], wwidth); priv->row_heights[i] = wheight; add_padding = TRUE; } else { nmt_newt_widget_size_request (rows[i].widget, &wwidth, &wheight); priv->row_heights[i] = wheight; } if (rows[i].extra) { nmt_newt_widget_size_request (rows[i].extra, &ewidth, &eheight); state->col_widths[2] = MAX (state->col_widths[2], ewidth); priv->row_heights[i] = MAX (priv->row_heights[i], eheight); } *height += priv->row_heights[i]; } *width = state->col_widths[0] + state->col_widths[1] + state->col_widths[2]; if (add_padding) *width += 2; }
static void nmt_newt_button_box_size_allocate (NmtNewtWidget *widget, int x, int y, int width, int height) { NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (widget); NmtNewtWidget *child; int child_x, child_y, child_width, child_height; int i; child_x = x; child_y = y; for (i = 0; i < priv->start_buttons->len; i++) { child = priv->start_buttons->pdata[i]; nmt_newt_widget_size_request (child, &child_width, &child_height); if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL) { nmt_newt_widget_size_allocate (child, child_x, child_y, child_width, child_height); child_x += child_width + 1; } else { nmt_newt_widget_size_allocate (child, child_x, child_y, child_width, child_height); child_y += child_height + 1; } } if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL) child_x = x + width; else child_y = y + height; for (i = priv->end_buttons->len - 1; i >= 0; i--) { child = priv->end_buttons->pdata[i]; nmt_newt_widget_size_request (child, &child_width, &child_height); if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL) { nmt_newt_widget_size_allocate (child, child_x - child_width, child_y, child_width, child_height); child_x -= child_width + 1; } else { nmt_newt_widget_size_allocate (child, child_x, child_y - child_height, child_width, child_height); child_y -= child_height + 1; } } }
static void size_request_buttons (NmtNewtButtonBox *bbox, GPtrArray *buttons, int *width, int *height) { NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (bbox); int child_width, child_height; int i; for (i = 0; i < buttons->len; i++) { NmtNewtWidget *child = buttons->pdata[i]; nmt_newt_widget_size_request (child, &child_width, &child_height); if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL) { *width += child_width; if (i > 0) *width += 1; *height = MAX (*height, child_height); } else { *height += child_height; if (i > 0) *height += 1; *width = MAX (*width, child_width); } } }
static void nmt_newt_section_size_request (NmtNewtWidget *widget, int *width, int *height) { NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (widget); int border_width, border_height; g_return_if_fail (priv->header != NULL && priv->body != NULL); if (priv->show_border) nmt_newt_widget_size_request (priv->border_grid, &border_width, &border_height); nmt_newt_widget_size_request (priv->header, &priv->hwidth_req, &priv->hheight_req); nmt_newt_widget_size_request (priv->body, &priv->bwidth_req, &priv->bheight_req); *width = MAX (priv->hwidth_req, priv->bwidth_req) + 2; if (priv->open) *height = priv->hheight_req + priv->bheight_req + (priv->show_border ? 1 : 0); else *height = priv->hheight_req; }
static void nmt_newt_section_size_allocate (NmtNewtWidget *widget, int x, int y, int width, int height) { NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (widget); if (priv->show_border) { int border_height, border_width; adjust_border_for_allocation (priv, height); nmt_newt_widget_size_request (priv->border_grid, &border_height, &border_width); nmt_newt_widget_size_allocate (priv->border_grid, x, y, 1, height); nmt_newt_widget_size_allocate (priv->header, x + 2, y, width, priv->hheight_req); } else nmt_newt_widget_size_allocate (priv->header, x, y, width, priv->hheight_req); if (priv->open) { nmt_newt_widget_size_allocate (priv->body, x + 2, y + priv->hheight_req, width, height - priv->hheight_req); } }
static void nmt_newt_form_build (NmtNewtForm *form) { NmtNewtFormPrivate *priv = NMT_NEWT_FORM_GET_PRIVATE (form); int screen_height, screen_width, form_height, form_width; newtComponent *cos; int i; priv->dirty = FALSE; nmt_newt_widget_realize (NMT_NEWT_WIDGET (form)); nmt_newt_widget_size_request (priv->content, &form_width, &form_height); newtGetScreenSize (&screen_width, &screen_height); if (!priv->fixed_width) priv->width = MIN (form_width + 2 * priv->padding, screen_width - 2); if (!priv->fixed_height) priv->height = MIN (form_height + 2 * priv->padding, screen_height - 2); if (!priv->fixed_x) priv->x = (screen_width - form_width) / 2; if (!priv->fixed_y) priv->y = (screen_height - form_height) / 2; nmt_newt_widget_size_allocate (priv->content, priv->padding, priv->padding, priv->width - 2 * priv->padding, priv->height - 2 * priv->padding); if (priv->height - 2 * priv->padding < form_height) { newtComponent scroll_bar = newtVerticalScrollbar (priv->width - 1, 0, priv->height, NEWT_COLORSET_WINDOW, NEWT_COLORSET_ACTCHECKBOX); priv->form = newtForm (scroll_bar, NULL, NEWT_FLAG_NOF12); newtFormAddComponent (priv->form, scroll_bar); newtFormSetHeight (priv->form, priv->height - 2); } else priv->form = newtForm (NULL, NULL, NEWT_FLAG_NOF12); if (priv->escape_exits) newtFormAddHotKey (priv->form, NEWT_KEY_ESCAPE); cos = nmt_newt_widget_get_components (priv->content); for (i = 0; cos[i]; i++) newtFormAddComponent (priv->form, cos[i]); g_free (cos); if (priv->focus) { newtComponent fco; fco = nmt_newt_widget_get_focus_component (priv->focus); if (fco) newtFormSetCurrent (priv->form, fco); } #ifdef HAVE_NEWTFORMGETSCROLLPOSITION if (priv->scroll_position) newtFormSetScrollPosition (priv->form, priv->scroll_position); #endif newtOpenWindow (priv->x, priv->y, priv->width, priv->height, priv->title_lc); }
static void nmt_editor_grid_size_allocate (NmtNewtWidget *widget, int x, int y, int width, int height) { NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (widget); NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data; NmtEditorGridFormState *state = get_form_state (widget); int col0_width, col1_width, col2_width; int i, row; col0_width = state->col_widths[0] - priv->indent; col1_width = state->col_widths[1]; col2_width = state->col_widths[2]; for (i = row = 0; i < priv->rows->len; i++) { if (!nmt_newt_widget_get_visible (rows[i].widget)) continue; if (rows[i].label) { int lwidth, lheight, lx; if (rows[i].flags & NMT_EDITOR_GRID_ROW_LABEL_ALIGN_LEFT) lx = x; else { nmt_newt_widget_size_request (rows[i].label, &lwidth, &lheight); lx = x + col0_width - lwidth; } nmt_newt_widget_size_allocate (rows[i].label, lx, y + row, col0_width, priv->row_heights[i]); nmt_newt_widget_size_allocate (rows[i].widget, x + col0_width + 1, y + row, col1_width, priv->row_heights[i]); } else { nmt_newt_widget_size_allocate (rows[i].widget, x, y + row, col0_width + col1_width + 1, priv->row_heights[i]); } if (rows[i].extra) { int wwidth, wheight, ex; if (rows[i].flags & NMT_EDITOR_GRID_ROW_EXTRA_ALIGN_RIGHT) ex = x + col0_width + col1_width + 2; else { nmt_newt_widget_size_request (rows[i].widget, &wwidth, &wheight); ex = x + col0_width + wwidth + 2; } nmt_newt_widget_size_allocate (rows[i].extra, ex, y + row, col2_width, priv->row_heights[i]); } row += priv->row_heights[i]; } }
static void nmt_newt_popup_activated (NmtNewtWidget *widget) { NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE (widget); NmtNewtPopupEntry *entries = (NmtNewtPopupEntry *)priv->entries->data; NmtNewtForm *form; NmtNewtWidget *listbox, *ret; int button_x, button_y; int window_x, window_y; int list_w, list_h; int i, active; listbox = nmt_newt_listbox_new (priv->entries->len, 0); nmt_newt_widget_set_exit_on_activate (listbox, TRUE); for (i = 0; i < priv->entries->len; i++) nmt_newt_listbox_append (NMT_NEWT_LISTBOX (listbox), entries[i].label, NULL); nmt_newt_listbox_set_active (NMT_NEWT_LISTBOX (listbox), priv->active); nmt_newt_widget_set_padding (listbox, 1, 0, 1, 0); nmt_newt_widget_size_request (listbox, &list_w, &list_h); g_object_get (nmt_newt_widget_get_form (widget), "x", &window_x, "y", &window_y, NULL); newtComponentGetPosition (nmt_newt_component_get_component (NMT_NEWT_COMPONENT (widget)), &button_x, &button_y); /* (window_x + button_x) is the screen X coordinate of the newtComponent. A * newtButton labelled "Foo" is rendered as " <Foo>" (with a preceding * space), so the "F" is at (window_x + button_x + 2). We've added 1 column * of padding to the left of the listbox, so we need to position the popup * at (window_x + button_x + 1) in order for its text to be aligned with the * button's text. (The x and y coordinates given to NmtNewtForm are the * coordinates of the top left of the window content, ignoring the border * graphics.) */ window_x += button_x + 1; window_y += button_y - priv->active; form = g_object_new (NMT_TYPE_NEWT_FORM, "x", window_x, "y", window_y, "width", list_w, "height", list_h, "padding", 0, "escape-exits", TRUE, NULL); nmt_newt_form_set_content (form, listbox); ret = nmt_newt_form_run_sync (form); if (ret == listbox) active = nmt_newt_listbox_get_active (NMT_NEWT_LISTBOX (listbox)); else active = priv->active; g_object_unref (form); if (active != priv->active) { priv->active = active; g_object_notify (G_OBJECT (widget), "active"); g_object_notify (G_OBJECT (widget), "active-id"); nmt_newt_widget_needs_rebuild (widget); } NMT_NEWT_WIDGET_CLASS (nmt_newt_popup_parent_class)->activated (widget); }