Example #1
0
int GLcreatewidget (
    Gwidget_t *parent, Gwidget_t *widget, int attrn, Gwattr_t *attrp
) {
    PIXsize_t ps;
    DWORD wflags;
    char *s;
    int ai;

    if (!parent) {
        Gerr (POS, G_ERRNOPARENTWIDGET);
        return -1;
    }
    wflags = WS_CHILDWINDOW;
    WLU->func = NULL;
    ps.x = ps.y = MINLWSIZE;
    s = "";
    for (ai = 0; ai < attrn; ai++) {
        switch (attrp[ai].id) {
        case G_ATTRSIZE:
            GETSIZE (attrp[ai].u.s, ps, MINLWSIZE);
            break;
        case G_ATTRBORDERWIDTH:
            wflags |= WS_BORDER;
            break;
        case G_ATTRTEXT:
            s = attrp[ai].u.t;
            break;
        case G_ATTRWINDOWID:
            Gerr (POS, G_ERRCANNOTSETATTR1, "windowid");
            return -1;
        case G_ATTREVENTCB:
            WLU->func = attrp[ai].u.func;
            break;
        case G_ATTRUSERDATA:
            widget->udata = attrp[ai].u.u;
            break;
        default:
            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
            return -1;
        }
    }
    Gadjustwrect (parent, &ps);
    if (!(widget->w = CreateWindow (
        "LabelClass", s, wflags, 0, 0, ps.x, ps.y,
        parent->w, (HMENU) (widget - &Gwidgets[0]), hinstance, NULL
    ))) {
        Gerr (POS, G_ERRCANNOTCREATEWIDGET);
        return -1;
    }
    ShowWindow (widget->w, SW_SHOW);
    UpdateWindow (widget->w);
    if (parent && parent->type == G_ARRAYWIDGET)
        Gawinsertchild (parent, widget);
    return 0;
}
Example #2
0
int GLsetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {
    Gwidget_t *parent;
    PIXsize_t ps;
    RECT r;
    DWORD wflags1;
    int ai;

    parent = (widget->pwi == -1) ? NULL : &Gwidgets[widget->pwi];
    wflags1 = SWP_NOMOVE | SWP_NOZORDER;
    for (ai = 0; ai < attrn; ai++) {
        switch (attrp[ai].id) {
        case G_ATTRSIZE:
            GETSIZE (attrp[ai].u.s, ps, MINLWSIZE);
            Gadjustwrect (parent, &ps);
            SetWindowPos (widget->w, (HWND) NULL, 0, 0, ps.x, ps.y, wflags1);
            r.top = r.left = 0;
            r.bottom = ps.y, r.right = ps.x;
            InvalidateRect (widget->w, NULL, FALSE);
            break;
        case G_ATTRBORDERWIDTH:
            Gerr (POS, G_ERRCANNOTSETATTR2, "borderwidth");
            return -1;
        case G_ATTRTEXT:
            SetWindowText (widget->w, attrp[ai].u.t);
            GetClientRect (widget->w, &r);
            InvalidateRect (widget->w, &r, TRUE);
            break;
        case G_ATTRWINDOWID:
            Gerr (POS, G_ERRCANNOTSETATTR2, "windowid");
            return -1;
        case G_ATTREVENTCB:
            attrp[ai].u.func = WLU->func;
            break;
        case G_ATTRUSERDATA:
            widget->udata = attrp[ai].u.u;
            break;
        default:
            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
            return -1;
        }
    }
    return 0;
}
Example #3
0
int GBsetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {
    Gwidget_t *parent;
    PIXsize_t ps;
    DWORD wflags1;
    int ai;

    parent = (widget->pwi == -1) ? NULL : &Gwidgets[widget->pwi];
    wflags1 = SWP_NOMOVE | SWP_NOZORDER;
    for (ai = 0; ai < attrn; ai++) {
        switch (attrp[ai].id) {
        case G_ATTRSIZE:
            GETSIZE (attrp[ai].u.s, ps, MINBWSIZE);
            Gadjustwrect (parent, &ps);
            SetWindowPos (widget->w, (HWND) NULL, 0, 0, ps.x, ps.y, wflags1);
            break;
        case G_ATTRBORDERWIDTH:
            Gerr (POS, G_ERRCANNOTSETATTR2, "borderwidth");
            return -1;
        case G_ATTRTEXT:
            SetWindowText (widget->w, attrp[ai].u.t);
            break;
        case G_ATTRWINDOWID:
            Gerr (POS, G_ERRCANNOTSETATTR2, "windowid");
            return -1;
        case G_ATTRBUTTONCB:
            WBU->func = attrp[ai].u.func;
            break;
        case G_ATTRUSERDATA:
            widget->udata = attrp[ai].u.u;
            break;
        default:
            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
            return -1;
        }
    }
    return 0;
}
Example #4
0
static void handleresize (Gwidget_t *widget) {
    Gwidget_t *parent, *child;
    PIXsize_t ps1, ps2;
    PIXpoint_t po;
    DWORD wflags1, wflags2;
    RECT r;
    int dx, dy, wi, i;

    wflags1 = SWP_NOMOVE | SWP_NOZORDER;
    wflags2 = SWP_NOSIZE | SWP_NOZORDER;
    GetWindowRect (widget->w, &r);
    ps1.x = r.right - r.left, ps1.y = r.bottom - r.top;
    ps2 = ps1;
    /* first, take care of parent */
    parent = (widget->pwi == -1) ? NULL : &Gwidgets[widget->pwi];
    if (!parent)
        goto handlechildren;
    switch (parent->type) {
    case G_VIEWWIDGET:
        Gadjustwrect (parent, &ps1);
        if (ps1.x != ps2.x || ps1.y != ps2.y) {
            Gnocallbacks = TRUE;
            SetWindowPos (widget->w, (HWND) NULL, 0, 0, ps1.x, ps1.y, wflags1);
            Gnocallbacks = FALSE;
        }
        break;
    case G_ARRAYWIDGET:
        Gnocallbacks = TRUE;
        Gawresize (parent);
        Gnocallbacks = FALSE;
        break;
    case G_SCROLLWIDGET:
        Gnocallbacks = TRUE;
        for (i = 0; i  < 2; i++) {
            Gadjustwrect (parent, &ps1);
            if (ps1.x > ps2.x || ps1.y > ps2.y)
                SetWindowPos (
                    widget->w, (HWND) NULL, 0, 0, ps1.x, ps1.y, wflags1
                );
            GetClientRect (parent->w, &r);
            ps2.x = r.right - r.left, ps2.y = r.bottom - r.top;
            dx = max (0, ps1.x - ps2.x);
            dy = max (0, ps1.y - ps2.y);
            SetScrollRange (parent->w, SB_HORZ, 0, dx, TRUE);
            SetScrollRange (parent->w, SB_VERT, 0, dy, TRUE);
            po.x = GetScrollPos (parent->w, SB_HORZ);
            po.y = GetScrollPos (parent->w, SB_VERT);
            po.x = min (po.x, dx);
            po.x = max (po.x, 0);
            SetScrollPos (parent->w, SB_HORZ, po.x, TRUE);
            po.y = min (po.y, dy);
            po.y = max (po.y, 0);
            SetScrollPos (parent->w, SB_VERT, po.y, TRUE);
            SetWindowPos (widget->w, (HWND) NULL, -po.x, -po.y, 0, 0, wflags2);
            ps2 = ps1;
        }
        Gnocallbacks = FALSE;
        break;
    }

handlechildren:
    for (wi = 0; wi < Gwidgetn; wi++) {
        child = &Gwidgets[wi];
        if (child->inuse && child->pwi == widget - &Gwidgets[0])
            break;
    }
    if (wi == Gwidgetn)
        return;
    GetWindowRect (child->w, &r);
    ps1.x = r.right - r.left, ps1.y = r.bottom - r.top;
    ps2 = ps1;
    switch (widget->type) {
    case G_VIEWWIDGET:
        Gadjustwrect (widget, &ps1);
        if (ps1.x != ps2.x || ps1.y != ps2.y)
            SetWindowPos (child->w, (HWND) NULL, 0, 0, ps1.x, ps1.y, wflags1);
        break;
    case G_ARRAYWIDGET:
        Gawresize (widget);
        break;
    case G_SCROLLWIDGET:
        Gadjustwrect (widget, &ps1);
        if (ps1.x > ps2.x || ps1.y > ps2.y)
            SetWindowPos (child->w, (HWND) NULL, 0, 0, ps1.x, ps1.y, wflags1);
        GetClientRect (widget->w, &r);
        ps2.x = r.right - r.left, ps2.y = r.bottom - r.top;
        dx = max (0, ps1.x - ps2.x);
        dy = max (0, ps1.y - ps2.y);
        SetScrollRange (widget->w, SB_HORZ, 0, dx, TRUE);
        SetScrollRange (widget->w, SB_VERT, 0, dy, TRUE);
        po.x = GetScrollPos (widget->w, SB_HORZ);
        po.y = GetScrollPos (widget->w, SB_VERT);
        po.x = min (po.x, dx);
        po.x = max (po.x, 0);
        SetScrollPos (widget->w, SB_HORZ, po.x, TRUE);
        po.y = min (po.y, dy);
        po.y = max (po.y, 0);
        SetScrollPos (widget->w, SB_VERT, po.y, TRUE);
        SetWindowPos (child->w, (HWND) NULL, -po.x, -po.y, 0, 0, wflags2);
        break;
    }
}
Example #5
0
int GAcreatewidget (
    Gwidget_t *parent, Gwidget_t *widget, int attrn, Gwattr_t *attrp
) {
    PIXsize_t ps;
    DWORD wflags;
    int mode, ai;

    if (!parent) {
        Gerr (POS, G_ERRNOPARENTWIDGET);
        return -1;
    }
    wflags = WS_CHILDWINDOW;
    mode = G_AWVARRAY;
    WAU->func = NULL;
    ps.x = ps.y = MINAWSIZE;
    for (ai = 0; ai < attrn; ai++) {
        switch (attrp[ai].id) {
        case G_ATTRSIZE:
            GETSIZE (attrp[ai].u.s, ps, MINAWSIZE);
            break;
        case G_ATTRBORDERWIDTH:
            wflags |= WS_BORDER;
            break;
        case G_ATTRMODE:
            if (strcmp ("horizontal", attrp[ai].u.t) == 0)
                mode = G_AWHARRAY;
            else if (strcmp ("vertical", attrp[ai].u.t) == 0)
                mode = G_AWVARRAY;
            else {
                Gerr (POS, G_ERRBADATTRVALUE, attrp[ai].u.t);
                return -1;
            }
            break;
        case G_ATTRLAYOUT:
            if (strcmp ("on", attrp[ai].u.t) == 0) {
                Gawsetmode (widget, FALSE);
                WAU->mode = G_AWHARRAY;
            } else if (strcmp ("off", attrp[ai].u.t) == 0) {
                Gawsetmode (widget, TRUE);
                WAU->mode = G_AWHARRAY;
            } else {
                Gerr (POS, G_ERRBADATTRVALUE, attrp[ai].u.t);
                return -1;
            }
            break;
        case G_ATTRWINDOWID:
            Gerr (POS, G_ERRCANNOTSETATTR1, "windowid");
            return -1;
        case G_ATTRRESIZECB:
            WAU->func = attrp[ai].u.func;
            break;
        case G_ATTRUSERDATA:
            widget->udata = attrp[ai].u.u;
            break;
        default:
            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
            return -1;
        }
    }
    Gawinitialize (widget, mode);
    Gadjustwrect (parent, &ps);
    if (!(widget->w = CreateWindow (
        "ArrayClass", "array", wflags, 0, 0, ps.x,
        ps.y, parent->w, (HMENU) (widget - &Gwidgets[0]),
        hinstance, NULL
    ))) {
        Gerr (POS, G_ERRCANNOTCREATEWIDGET);
        return -1;
    }
    ShowWindow (widget->w, SW_SHOW);
    UpdateWindow (widget->w);
    if (parent && parent->type == G_ARRAYWIDGET)
        Gawinsertchild (parent, widget);
    return 0;
}