Beispiel #1
0
static gboolean listview_clicked ( widget *wid, xcb_button_press_event_t *xce, G_GNUC_UNUSED void *udata )
{
    listview *lv = (listview *) wid;
    lv->scrollbar_scroll = FALSE;
    if ( widget_enabled ( WIDGET ( lv->scrollbar ) ) && widget_intersect ( WIDGET ( lv->scrollbar ), xce->event_x, xce->event_y ) ) {
        // Forward to handler of scrollbar.
        xcb_button_press_event_t xce2 = *xce;
        xce->event_x        -= widget_get_x_pos ( WIDGET ( lv->scrollbar ) );
        xce->event_y        -= widget_get_y_pos ( WIDGET ( lv->scrollbar ) );
        lv->scrollbar_scroll = TRUE;
        return widget_clicked ( WIDGET ( lv->scrollbar ), &xce2 );
    }
    // Handle the boxes.
    unsigned int max = MIN ( lv->cur_elements, lv->req_elements - lv->last_offset );
    for ( unsigned int i = 0; i < max; i++ ) {
        widget *w = WIDGET ( lv->boxes[i] );
        if ( widget_intersect ( w, xce->event_x, xce->event_y ) ) {
            if ( ( lv->last_offset + i ) == lv->selected ) {
                if ( ( xce->time - lv->last_click ) < 200 ) {
                    // Somehow signal we accepted item.
                    lv->mouse_activated ( lv, xce, lv->mouse_activated_data );
                }
            }
            else {
                listview_set_selected ( lv, lv->last_offset + i );
            }
            lv->last_click = xce->time;
            return TRUE;
        }
    }
    return FALSE;
}
Beispiel #2
0
static gboolean listview_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme )
{
    listview *lv = (listview *) wid;
    if ( widget_enabled ( WIDGET ( lv->scrollbar ) ) && lv->scrollbar_scroll ) {
        xcb_motion_notify_event_t xle = *xme;
        xle.event_x -= wid->x;
        xle.event_y -= wid->y;
        widget_motion_notify ( WIDGET ( lv->scrollbar ), &xle );
        return TRUE;
    }

    return FALSE;
}
Beispiel #3
0
static void listview_draw ( widget *wid, cairo_t *draw )
{
    unsigned int offset = 0;
    listview     *lv    = (listview *) wid;
    if ( lv->scroll_type == LISTVIEW_SCROLL_CONTINIOUS ) {
        offset = scroll_continious ( lv );
    }
    else {
        offset = scroll_per_page ( lv );
    }
    // Set these all together to make sure they update consistently.
    scrollbar_set_max_value ( lv->scrollbar, lv->req_elements );
    scrollbar_set_handle_length ( lv->scrollbar, lv->cur_columns * lv->max_rows );
    if ( lv->reverse ) {
        scrollbar_set_handle ( lv->scrollbar, lv->req_elements - lv->selected - 1 );
    }
    else {
        scrollbar_set_handle ( lv->scrollbar, lv->selected  );
    }
    lv->last_offset = offset;
    int spacing_vert = distance_get_pixel ( lv->spacing, ORIENTATION_VERTICAL );
    int spacing_hori = distance_get_pixel ( lv->spacing, ORIENTATION_HORIZONTAL );

    int left_offset = widget_padding_get_left ( wid );
    int top_offset  = widget_padding_get_top ( wid );
    if ( lv->scrollbar->widget.index == 0 ) {
        left_offset += spacing_hori + lv->scrollbar->widget.w;
    }
    if ( lv->cur_elements > 0 && lv->max_rows > 0 ) {
        // Set new x/y possition.
        unsigned int max = MIN ( lv->cur_elements, lv->req_elements - offset );
        if ( lv->rchanged ) {
            unsigned int width = lv->widget.w - spacing_hori * ( lv->cur_columns - 1 );
            width -= widget_padding_get_padding_width ( wid );
            if ( widget_enabled ( WIDGET ( lv->scrollbar ) ) ) {
                width -= spacing_hori;
                width -= widget_get_width ( WIDGET ( lv->scrollbar ) );
            }
            unsigned int element_width = ( width ) / lv->cur_columns;
            for ( unsigned int i = 0; i < max; i++ ) {
                unsigned int ex = left_offset + ( ( i ) / lv->max_rows ) * ( element_width + spacing_hori );
                if ( lv->reverse ) {
                    unsigned int ey = wid->h - ( widget_padding_get_bottom ( wid ) + ( ( i ) % lv->max_rows ) * ( lv->element_height + spacing_vert ) ) - lv->element_height;
                    textbox_moveresize ( lv->boxes[i], ex, ey, element_width, lv->element_height );
                }
                else {
                    unsigned int ey = top_offset + ( ( i ) % lv->max_rows ) * ( lv->element_height + spacing_vert );
                    textbox_moveresize ( lv->boxes[i], ex, ey, element_width, lv->element_height );
                }

                update_element ( lv, i, i + offset, TRUE );
                widget_draw ( WIDGET ( lv->boxes[i] ), draw );
            }
            lv->rchanged = FALSE;
        }
        else {
            for ( unsigned int i = 0; i < max; i++ ) {
                update_element ( lv, i, i + offset, FALSE );
                widget_draw ( WIDGET ( lv->boxes[i] ), draw );
            }
        }
    }
    widget_draw ( WIDGET ( lv->scrollbar ), draw );
}
Beispiel #4
0
int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
{
//    box 20 by 40
    widget *wid= (widget*)g_malloc0(sizeof(widget)); 
    widget_resize ( wid, 20, 40);
    widget_move ( wid, 10, 10);
    // Getter, setter x pos
    //
    TASSERT( widget_get_x_pos ( wid )  == 10 );
    TASSERT( widget_get_y_pos ( wid )  == 10 );

    // Left of box
    TASSERT ( widget_intersect ( wid, 0, 0) == 0 );
    TASSERT ( widget_intersect ( wid, 0, 10) == 0 );
    TASSERT ( widget_intersect ( wid, 0, 25) == 0 );
    TASSERT ( widget_intersect ( wid, 0, 40) == 0 );
    TASSERT ( widget_intersect ( wid, 0, 50) == 0 );
    TASSERT ( widget_intersect ( wid, 9, 0) == 0 );
    TASSERT ( widget_intersect ( wid, 9, 10) == 0 );
    TASSERT ( widget_intersect ( wid, 9, 25) == 0 );
    TASSERT ( widget_intersect ( wid, 9, 40) == 0 );
    TASSERT ( widget_intersect ( wid, 9, 50) == 0 );
    TASSERT ( widget_intersect ( wid, 10, 0) == 0 );
    TASSERT ( widget_intersect ( wid, 10, 10) == 1 );
    TASSERT ( widget_intersect ( wid, 10, 25) == 1 );
    TASSERT ( widget_intersect ( wid, 10, 40) == 1 );
    TASSERT ( widget_intersect ( wid, 10, 50) == 0 );

    // Middle

    TASSERT ( widget_intersect ( wid, 25, 0) == 0 );
    TASSERT ( widget_intersect ( wid, 25, 10) == 1 );
    TASSERT ( widget_intersect ( wid, 25, 25) == 1 );
    TASSERT ( widget_intersect ( wid, 25, 40) == 1 );
    TASSERT ( widget_intersect ( wid, 25, 50) == 0 );

    // Right
    TASSERT ( widget_intersect ( wid, 29, 0) == 0 );
    TASSERT ( widget_intersect ( wid, 29, 10) == 1 );
    TASSERT ( widget_intersect ( wid, 29, 25) == 1 );
    TASSERT ( widget_intersect ( wid, 29, 40) == 1 );
    TASSERT ( widget_intersect ( wid, 29, 50) == 0 );

    TASSERT ( widget_intersect ( wid, 30, 0) == 0 );
    TASSERT ( widget_intersect ( wid, 30, 10) == 0 );
    TASSERT ( widget_intersect ( wid, 30, 25) == 0 );
    TASSERT ( widget_intersect ( wid, 30, 40) == 0 );
    TASSERT ( widget_intersect ( wid, 30, 50) == 0 );

    widget_move ( wid, 30, 30);
    // Left of box
    TASSERT ( widget_intersect ( wid, 10, 20) == 0 );
    TASSERT ( widget_intersect ( wid, 10, 30) == 0 );
    TASSERT ( widget_intersect ( wid, 10, 45) == 0 );
    TASSERT ( widget_intersect ( wid, 10, 60) == 0 );
    TASSERT ( widget_intersect ( wid, 10, 70) == 0 );
    TASSERT ( widget_intersect ( wid, 19, 20) == 0 );
    TASSERT ( widget_intersect ( wid, 19, 30) == 0 );
    TASSERT ( widget_intersect ( wid, 19, 45) == 0 );
    TASSERT ( widget_intersect ( wid, 19, 60) == 0 );
    TASSERT ( widget_intersect ( wid, 19, 70) == 0 );
    TASSERT ( widget_intersect ( wid, 30, 20) == 0 );
    TASSERT ( widget_intersect ( wid, 30, 30) == 1 );
    TASSERT ( widget_intersect ( wid, 30, 45) == 1 );
    TASSERT ( widget_intersect ( wid, 30, 60) == 1 );
    TASSERT ( widget_intersect ( wid, 30, 70) == 0 );

    // Middle

    TASSERT ( widget_intersect ( wid, 20+25,20+ 0) == 0 );
    TASSERT ( widget_intersect ( wid, 20+25,20+ 10) == 1 );
    TASSERT ( widget_intersect ( wid, 20+25,20+ 25) == 1 );
    TASSERT ( widget_intersect ( wid, 20+25,20+ 40) == 1 );
    TASSERT ( widget_intersect ( wid, 20+25,20+ 50) == 0 );

    TASSERT ( widget_intersect ( wid, 20+29, 20+0) == 0 );
    TASSERT ( widget_intersect ( wid, 20+29, 20+10) == 1 );
    TASSERT ( widget_intersect ( wid, 20+29, 20+25) == 1 );
    TASSERT ( widget_intersect ( wid, 20+29, 20+40) == 1 );
    TASSERT ( widget_intersect ( wid, 20+29, 20+50) == 0 );

    TASSERT ( widget_intersect ( wid, 20+30, 20+0) == 0 );
    TASSERT ( widget_intersect ( wid, 20+30, 20+10) == 0 );
    TASSERT ( widget_intersect ( wid, 20+30, 20+25) == 0 );
    TASSERT ( widget_intersect ( wid, 20+30, 20+40) == 0 );
    TASSERT ( widget_intersect ( wid, 20+30, 20+50) == 0 );

    // Right
    TASSERT ( widget_intersect ( wid, 20+29, 20+0) == 0 );
    TASSERT ( widget_intersect ( wid, 20+29, 20+10) == 1 );
    TASSERT ( widget_intersect ( wid, 20+29, 20+25) == 1 );
    TASSERT ( widget_intersect ( wid, 20+29, 20+40) == 1 );
    TASSERT ( widget_intersect ( wid, 20+29, 20+50) == 0 );

    TASSERT ( widget_intersect ( wid, 20+30, 20+0) == 0 );
    TASSERT ( widget_intersect ( wid, 20+30, 20+10) == 0 );
    TASSERT ( widget_intersect ( wid, 20+30, 20+25) == 0 );
    TASSERT ( widget_intersect ( wid, 20+30, 20+40) == 0 );
    TASSERT ( widget_intersect ( wid, 20+30, 20+50) == 0 );


    TASSERT ( widget_intersect ( wid, -100, -100) == 0);
    TASSERT ( widget_intersect ( wid, INT_MIN, INT_MIN) == 0);
    TASSERT ( widget_intersect ( wid, INT_MAX, INT_MAX) == 0);

    // Other wrappers.
    TASSERT ( widget_get_height ( wid ) ==  wid->h);
    TASSERT ( widget_get_width ( wid ) ==  wid->w);

    TASSERT ( widget_enabled ( wid ) == FALSE );
    widget_enable ( wid );
    TASSERT ( widget_enabled ( wid ) == TRUE );
    widget_disable ( wid );
    TASSERT ( widget_enabled ( wid ) == FALSE );
    // Null pointer tests.
    TASSERT ( widget_intersect ( NULL, 0, 0) == 0 );
    widget_move ( NULL, 0, 0 );
    TASSERT ( widget_get_height ( NULL ) ==  0);
    TASSERT ( widget_get_width ( NULL ) ==  0);
    TASSERT ( widget_enabled ( NULL ) == 0);
    widget_disable ( NULL );
    widget_enable ( NULL );
    widget_draw ( NULL, NULL );
    widget_free ( NULL );
    widget_resize ( NULL, 0, 0);
    widget_update ( NULL );
    widget_queue_redraw ( NULL );
    TASSERT (widget_need_redraw ( NULL ) == FALSE);
    widget_clicked ( NULL, NULL );
    widget_set_clicked_handler ( NULL, NULL, NULL );


    g_free(wid);
}