void uiUnixFinishControl(uiControl *c) { g_object_ref_sink(GTK_WIDGET(uiControlHandle(c))); if (!isToplevel(c)) gtk_widget_show(GTK_WIDGET(uiControlHandle(c))); c->CommitShow = defaultCommitShow; c->CommitHide = defaultCommitHide; }
static void groupRelayout(uiGroup *g) { RECT r; int mx, mtop, mbottom; if (g->child == NULL) return; uiWindowsEnsureGetClientRect(g->hwnd, &r); groupMargins(g, &mx, &mtop, &mbottom); r.left += mx; r.top += mtop; r.right -= mx; r.bottom -= mbottom; uiWindowsEnsureMoveWindowDuringResize((HWND) uiControlHandle(g->child), r.left, r.top, r.right - r.left, r.bottom - r.top); }
void uiCheckboxSetChecked(uiControl *c, int checked) { struct checkbox *cc = (struct checkbox *) (c->data); GtkToggleButton *button; gboolean active; active = FALSE; if (checked) active = TRUE; // we need to inhibit sending of ::toggled because this WILL send a ::toggled otherwise button = GTK_TOGGLE_BUTTON(uiControlHandle(c)); g_signal_handler_block(button, cc->onToggledSignal); gtk_toggle_button_set_active(button, active); g_signal_handler_unblock(button, cc->onToggledSignal); }
void doResizes(void) { uiWindowsControl *w; HWND hwnd; RECT r; while (resizes->len != 0) { w = ptrArrayIndex(resizes, uiWindowsControl *, 0); ptrArrayDelete(resizes, 0); // don't clip content if content dynamically changed (tab page changed, etc.) ensureMinimumWindowSize(uiWindow(w)); hwnd = (HWND) uiControlHandle(uiControl(w)); if (GetClientRect(hwnd, &r) == 0) logLastError("error getting uiWindow client rect in doResizes()"); (*(w->Relayout))(w, r.left, r.top, r.right - r.left, r.bottom - r.top); // we used SWP_NOREDRAW; we need to queue a redraw ourselves // force all controls to be redrawn; this fixes things like the date-time picker's up-down not showing up until hovered over (and bypasses complications caused by WS_CLIPCHILDREN and WS_CLIPSIBLINGS, which we don't use but other controls might) if (RedrawWindow(hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN) == 0) logLastError("error redrawing controls after a resize in doResizes()"); } }
uiControl *uiNewCheckbox(const char *text) { uiControl *c; struct checkbox *cc; GtkWidget *widget; c = uiUnixNewControl(GTK_TYPE_CHECK_BUTTON, FALSE, FALSE, "label", text, NULL); widget = GTK_WIDGET(uiControlHandle(c)); cc = uiNew(struct checkbox); g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), cc); cc->onToggledSignal = g_signal_connect(widget, "toggled", G_CALLBACK(onToggled), c); cc->onToggled = defaultOnToggled; c->data = cc; return c; }
uiprivChild *uiprivNewChild(uiControl *child, uiControl *parent, GtkContainer *parentContainer) { uiprivChild *c; if (child == NULL) return NULL; c = uiprivNew(uiprivChild); c->c = child; c->widget = GTK_WIDGET(uiControlHandle(c->c)); c->oldhexpand = gtk_widget_get_hexpand(c->widget); c->oldhalign = gtk_widget_get_halign(c->widget); c->oldvexpand = gtk_widget_get_vexpand(c->widget); c->oldvalign = gtk_widget_get_valign(c->widget); uiControlSetParent(c->c, parent); uiUnixControlSetContainer(uiUnixControl(c->c), parentContainer, FALSE); c->parent = parentContainer; return c; }
static void windowRelayout(uiWindow *w) { uiWindowsSizing sizing; int x, y, width, height; RECT r; int mx, my; HWND child; if (w->child == NULL) return; x = 0; y = 0; uiWindowsEnsureGetClientRect(w->hwnd, &r); width = r.right - r.left; height = r.bottom - r.top; windowMargins(w, &mx, &my); x += mx; y += my; width -= 2 * mx; height -= 2 * my; child = (HWND) uiControlHandle(w->child); uiWindowsEnsureMoveWindowDuringResize(child, x, y, width, height); }
void uiCheckboxSetText(uiControl *c, const char *text) { gtk_button_set_label(GTK_BUTTON(uiControlHandle(c)), text); }
void osCommitDisable(uiControl *c) { EnableWindow((HWND) uiControlHandle(c), FALSE); }
static void formRelayout(uiForm *f) { RECT r; int x, y, width, height; int xpadding, ypadding; int nStretchy; int labelwid, stretchyht; int thiswid; int i; int minimumWidth, minimumHeight; uiWindowsSizing sizing; int labelht, labelyoff; int nVisible; if (f->controls->size() == 0) return; uiWindowsEnsureGetClientRect(f->hwnd, &r); x = r.left; y = r.top; width = r.right - r.left; height = r.bottom - r.top; // 0) get this Form's padding formPadding(f, &xpadding, &ypadding); // 1) get width of labels and height of non-stretchy controls // this will tell us how much space will be left for controls labelwid = 0; stretchyht = height; nStretchy = 0; nVisible = 0; for (struct formChild &fc : *(f->controls)) { if (!uiControlVisible(fc.c)) { ShowWindow(fc.label, SW_HIDE); continue; } ShowWindow(fc.label, SW_SHOW); nVisible++; thiswid = uiWindowsWindowTextWidth(fc.label); if (labelwid < thiswid) labelwid = thiswid; if (fc.stretchy) { nStretchy++; continue; } uiWindowsControlMinimumSize(uiWindowsControl(fc.c), &minimumWidth, &minimumHeight); fc.height = minimumHeight; stretchyht -= minimumHeight; } if (nVisible == 0) // nothing to do return; // 2) inset the available rect by the needed padding width -= xpadding; height -= (nVisible - 1) * ypadding; stretchyht -= (nVisible - 1) * ypadding; // 3) now get the width of controls and the height of stretchy controls width -= labelwid; if (nStretchy != 0) { stretchyht /= nStretchy; for (struct formChild &fc : *(f->controls)) { if (!uiControlVisible(fc.c)) continue; if (fc.stretchy) fc.height = stretchyht; } } // 4) get the y offset labelyoff = labelYOffset; uiWindowsGetSizing(f->hwnd, &sizing); uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &labelyoff); // 5) now we can position controls // first, make relative to the top-left corner of the container // also prefer left alignment on Windows x = labelwid + xpadding; y = 0; for (const struct formChild &fc : *(f->controls)) { if (!uiControlVisible(fc.c)) continue; labelht = labelHeight; uiWindowsGetSizing(f->hwnd, &sizing); uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &labelht); uiWindowsEnsureMoveWindowDuringResize(fc.label, 0, y + labelyoff - sizing.InternalLeading, labelwid, labelht); uiWindowsEnsureMoveWindowDuringResize((HWND) uiControlHandle(fc.c), x, y, width, fc.height); y += fc.height + ypadding; } }
static void defaultCommitHide(uiControl *c) { ShowWindow((HWND) uiControlHandle(c), SW_HIDE); }
void osCommitEnable(uiControl *c) { EnableWindow((HWND) uiControlHandle(c), TRUE); }
static void defaultCommitShow(uiControl *c) { ShowWindow((HWND) uiControlHandle(c), SW_SHOW); }
void osCommitEnable(uiControl *c) { gtk_widget_set_sensitive(GTK_WIDGET(uiControlHandle(c)), TRUE); }
static void defaultCommitHide(uiControl *c) { gtk_widget_hide(GTK_WIDGET(uiControlHandle(c))); }
void osCommitDisable(uiControl *c) { gtk_widget_set_sensitive(GTK_WIDGET(uiControlHandle(c)), FALSE); }
char *uiCheckboxText(uiControl *c) { return g_strdup(gtk_button_get_label(GTK_BUTTON(uiControlHandle(c)))); }
int uiCheckboxChecked(uiControl *c) { return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(uiControlHandle(c))) != FALSE; }
static void defaultCommitShow(uiControl *c) { gtk_widget_show(GTK_WIDGET(uiControlHandle(c))); }