Ejemplo n.º 1
0
static void zbar_gtk_unrealize (GtkWidget *widget)
{
    if(GTK_WIDGET_MAPPED(widget))
        gtk_widget_unmap(widget);

    ZBarGtk *self = ZBAR_GTK(widget);
    if(!self->_private)
        return;
    ZBarGtkPrivate *zbar = ZBAR_GTK_PRIVATE(self->_private);

    if(zbar->video_enabled) {
        zbar->video_enabled = FALSE;
        GValue *msg = zbar_gtk_new_value(G_TYPE_INT);
        g_value_set_int(msg, 0);
        g_async_queue_push(zbar->queue, msg);
    }

    zbar_window_attach(zbar->window, NULL, 0);

    GTK_WIDGET_UNSET_FLAGS(widget, GTK_REALIZED);

    gdk_window_set_user_data(widget->window, NULL);
    gdk_window_destroy(widget->window);
    widget->window = NULL;
}
Ejemplo n.º 2
0
static void zbar_gtk_realize (GtkWidget *widget)
{
    ZBarGtk *self = ZBAR_GTK(widget);
    if(!self->_private)
        return;
    ZBarGtkPrivate *zbar = ZBAR_GTK_PRIVATE(self->_private);

    GTK_WIDGET_UNSET_FLAGS(widget, GTK_DOUBLE_BUFFERED);
    GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);

    GdkWindowAttr attributes;
    attributes.x = widget->allocation.x;
    attributes.y = widget->allocation.y;
    attributes.width = widget->allocation.width;
    attributes.height = widget->allocation.height;
    attributes.wclass = GDK_INPUT_OUTPUT;
    attributes.window_type = GDK_WINDOW_CHILD;
    attributes.event_mask = (gtk_widget_get_events(widget) |
                             GDK_EXPOSURE_MASK);

    widget->window = gdk_window_new(gtk_widget_get_parent_window(widget),
                                    &attributes,
                                    GDK_WA_X | GDK_WA_Y);
    gdk_window_set_user_data(widget->window, widget);
    gdk_window_set_back_pixmap(widget->window, NULL, TRUE);

    /* attach zbar_window to underlying X window */
    if(zbar_window_attach(zbar->window,
                           gdk_x11_drawable_get_xdisplay(widget->window),
                           gdk_x11_drawable_get_xid(widget->window)))
        zbar_window_error_spew(zbar->window, 0);
}
Ejemplo n.º 3
0
void zbar_window_destroy (zbar_window_t *w)
{
    /* detach */
    zbar_window_attach(w, NULL, 0);
    err_cleanup(&w->err);
    _zbar_mutex_destroy(&w->imglock);
    free(w);
}
Ejemplo n.º 4
0
static LRESULT CALLBACK win_handle_event (HWND hwnd,
                                          UINT message,
                                          WPARAM wparam,
                                          LPARAM lparam)
{
    zbar_processor_t *proc =
        (zbar_processor_t*)GetWindowLongPtr(hwnd, GWL_USERDATA);
    /* initialized during window creation */
    if(message == WM_NCCREATE) {
        proc = ((LPCREATESTRUCT)lparam)->lpCreateParams;
        assert(proc);
        SetWindowLongPtr(hwnd, GWL_USERDATA, (LONG_PTR)proc);
        proc->display = hwnd;

        zbar_window_attach(proc->window, proc->display, proc->xwin);
    }
    else if(!proc)
        return(DefWindowProc(hwnd, message, wparam, lparam));

    switch(message) {

    case WM_SIZE: {
        RECT r;
        GetClientRect(hwnd, &r);
        zprintf(3, "WM_SIZE %ldx%ld\n", r.right, r.bottom);
        assert(proc);
        zbar_window_resize(proc->window, r.right, r.bottom);
        InvalidateRect(hwnd, NULL, 0);
        return(0);
    }

    case WM_PAINT: {
        PAINTSTRUCT ps;
        BeginPaint(hwnd, &ps);
        if(zbar_window_redraw(proc->window)) {
            HDC hdc = GetDC(hwnd);
            RECT r;
            GetClientRect(hwnd, &r);
            FillRect(hdc, &r, GetStockObject(BLACK_BRUSH));
            ReleaseDC(hwnd, hdc);
        }
        EndPaint(hwnd, &ps);
        return(0);
    }

    case WM_CHAR: {
        _zbar_processor_handle_input(proc, wparam);
        return(0);
    }

    case WM_LBUTTONDOWN: {
        _zbar_processor_handle_input(proc, 1);
        return(0);
    }

    case WM_MBUTTONDOWN: {
        _zbar_processor_handle_input(proc, 2);
        return(0);
    }

    case WM_RBUTTONDOWN: {
        _zbar_processor_handle_input(proc, 3);
        return(0);
    }

    case WM_CLOSE: {
        zprintf(3, "WM_CLOSE\n");
        _zbar_processor_handle_input(proc, -1);
        return(1);
    }

    case WM_DESTROY: {
        zprintf(3, "WM_DESTROY\n");
        proc->display = NULL;
        zbar_window_attach(proc->window, NULL, 0);
        return(0);
    }
    }
    return(DefWindowProc(hwnd, message, wparam, lparam));
}