*/
void dlg_refresh(union control *ctrl, void *dlg);
-/*
- * It's perfectly possible that individual controls might need to
- * allocate or store per-dialog-instance data, so here's a
- * mechanism.
- *
- * `dlg_get_privdata' and `dlg_set_privdata' allow the user to get
- * and set a void * pointer associated with the control in
- * question. `dlg_alloc_privdata' will allocate memory, store a
- * pointer to that memory in the private data field, and arrange
- * for it to be automatically deallocated on dialog cleanup.
- */
-void *dlg_get_privdata(union control *ctrl, void *dlg);
-void dlg_set_privdata(union control *ctrl, void *dlg, void *ptr);
-void *dlg_alloc_privdata(union control *ctrl, void *dlg, size_t size);
-
/*
* Standard helper functions for reading a controlbox structure.
*/
NSTableView *tableview;
NSScrollView *scrollview;
int nradiobuttons;
- void *privdata;
- int privdata_needs_free;
};
static int fe_ctrl_cmp_by_ctrl(void *av, void *bv)
c->scrollview = nil;
c->radiobuttons = NULL;
c->nradiobuttons = 0;
- c->privdata = NULL;
- c->privdata_needs_free = FALSE;
return c;
}
static void fe_ctrl_free(struct fe_ctrl *c)
{
- if (c->privdata_needs_free)
- sfree(c->privdata);
sfree(c->radiobuttons);
sfree(c);
}
}
}
}
-
-void *dlg_get_privdata(union control *ctrl, void *dv)
-{
- struct fe_dlg *d = (struct fe_dlg *)dv;
- struct fe_ctrl *c = fe_ctrl_byctrl(d, ctrl);
- return c->privdata;
-}
-
-void dlg_set_privdata(union control *ctrl, void *dv, void *ptr)
-{
- struct fe_dlg *d = (struct fe_dlg *)dv;
- struct fe_ctrl *c = fe_ctrl_byctrl(d, ctrl);
- c->privdata = ptr;
- c->privdata_needs_free = FALSE;
-}
-
-void *dlg_alloc_privdata(union control *ctrl, void *dv, size_t size)
-{
- struct fe_dlg *d = (struct fe_dlg *)dv;
- struct fe_ctrl *c = fe_ctrl_byctrl(d, ctrl);
- /*
- * This is an internal allocation routine, so it's allowed to
- * use smalloc directly.
- */
- c->privdata = smalloc(size);
- c->privdata_needs_free = TRUE;
- return c->privdata;
-}
struct uctrl {
union control *ctrl;
GtkWidget *toplevel;
- void *privdata;
- int privdata_needs_free;
GtkWidget **buttons; int nbuttons; /* for radio buttons */
GtkWidget *entry; /* for editbox, filesel, fontsel */
GtkWidget *button; /* for filesel, fontsel */
dp->byctrl = NULL;
while ( (uc = index234(dp->bywidget, 0)) != NULL) {
del234(dp->bywidget, uc);
- if (uc->privdata_needs_free)
- sfree(uc->privdata);
sfree(uc->buttons);
sfree(uc);
}
return ret;
}
-void *dlg_get_privdata(union control *ctrl, void *dlg)
-{
- struct dlgparam *dp = (struct dlgparam *)dlg;
- struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
- return uc->privdata;
-}
-
-void dlg_set_privdata(union control *ctrl, void *dlg, void *ptr)
-{
- struct dlgparam *dp = (struct dlgparam *)dlg;
- struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
- uc->privdata = ptr;
- uc->privdata_needs_free = FALSE;
-}
-
-void *dlg_alloc_privdata(union control *ctrl, void *dlg, size_t size)
-{
- struct dlgparam *dp = (struct dlgparam *)dlg;
- struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
- /*
- * This is an internal allocation routine, so it's allowed to
- * use smalloc directly.
- */
- uc->privdata = smalloc(size);
- uc->privdata_needs_free = FALSE;
- return uc->privdata;
-}
-
union control *dlg_last_focused(union control *ctrl, void *dlg)
{
struct dlgparam *dp = (struct dlgparam *)dlg;
uc = snew(struct uctrl);
uc->ctrl = ctrl;
- uc->privdata = NULL;
- uc->privdata_needs_free = FALSE;
uc->buttons = NULL;
uc->entry = NULL;
#if !GTK_CHECK_VERSION(2,4,0)
dp->fixed_pitch_fonts = flag;
}
-struct perctrl_privdata {
- union control *ctrl;
- void *data;
- int needs_free;
-};
-
-static int perctrl_privdata_cmp(void *av, void *bv)
-{
- struct perctrl_privdata *a = (struct perctrl_privdata *)av;
- struct perctrl_privdata *b = (struct perctrl_privdata *)bv;
- if (a->ctrl < b->ctrl)
- return -1;
- else if (a->ctrl > b->ctrl)
- return +1;
- return 0;
-}
-
void dp_init(struct dlgparam *dp)
{
dp->nctrltrees = 0;
memset(dp->shortcuts, 0, sizeof(dp->shortcuts));
dp->hwnd = NULL;
dp->wintitle = dp->errtitle = NULL;
- dp->privdata = newtree234(perctrl_privdata_cmp);
dp->fixed_pitch_fonts = TRUE;
}
void dp_cleanup(struct dlgparam *dp)
{
- struct perctrl_privdata *p;
-
- if (dp->privdata) {
- while ( (p = index234(dp->privdata, 0)) != NULL ) {
- del234(dp->privdata, p);
- if (p->needs_free)
- sfree(p->data);
- sfree(p);
- }
- freetree234(dp->privdata);
- dp->privdata = NULL;
- }
sfree(dp->wintitle);
sfree(dp->errtitle);
}
-
-void *dlg_get_privdata(union control *ctrl, void *dlg)
-{
- struct dlgparam *dp = (struct dlgparam *)dlg;
- struct perctrl_privdata tmp, *p;
- tmp.ctrl = ctrl;
- p = find234(dp->privdata, &tmp, NULL);
- if (p)
- return p->data;
- else
- return NULL;
-}
-
-void dlg_set_privdata(union control *ctrl, void *dlg, void *ptr)
-{
- struct dlgparam *dp = (struct dlgparam *)dlg;
- struct perctrl_privdata tmp, *p;
- tmp.ctrl = ctrl;
- p = find234(dp->privdata, &tmp, NULL);
- if (!p) {
- p = snew(struct perctrl_privdata);
- p->ctrl = ctrl;
- p->needs_free = FALSE;
- add234(dp->privdata, p);
- }
- p->data = ptr;
-}
-
-void *dlg_alloc_privdata(union control *ctrl, void *dlg, size_t size)
-{
- struct dlgparam *dp = (struct dlgparam *)dlg;
- struct perctrl_privdata tmp, *p;
- tmp.ctrl = ctrl;
- p = find234(dp->privdata, &tmp, NULL);
- if (!p) {
- p = snew(struct perctrl_privdata);
- p->ctrl = ctrl;
- p->needs_free = FALSE;
- add234(dp->privdata, p);
- }
- assert(!p->needs_free);
- p->needs_free = TRUE;
- /*
- * This is an internal allocation routine, so it's allowed to
- * use smalloc directly.
- */
- p->data = smalloc(size);
- return p->data;
-}