示例#1
0
static int TXT_TableSelectable(TXT_UNCAST_ARG(table))
{
    TXT_CAST_ARG(txt_table_t, table);
    int i;

    // Is the currently-selected cell selectable?

    if (SelectableCell(table, table->selected_x, table->selected_y))
    {
        return 1;
    }

    // Find the first selectable cell and set selected_x, selected_y.

    for (i = 0; i < table->num_widgets; ++i)
    {
        if (IsActualWidget(table->widgets[i])
         && TXT_SelectableWidget(table->widgets[i]))
        {
            ChangeSelection(table, i % table->columns, i / table->columns);
            return 1;
        }
    }

    // No selectable widgets exist within the table.

    return 0;
}
示例#2
0
static int TXT_ScrollPaneSelectable(TXT_UNCAST_ARG(scrollpane))
{
    TXT_CAST_ARG(txt_scrollpane_t, scrollpane);

    // If scroll bars are displayed, the scroll pane must be selectable
    // so that we can use the arrow keys to scroll around.

    if (NeedsScrollbars(scrollpane))
    {
        return 1;
    }

    // Otherwise, whether this is selectable depends on the child widget.

    return TXT_SelectableWidget(scrollpane->child);
}
示例#3
0
static int SelectableCell(txt_table_t *table, int x, int y)
{
    txt_widget_t *widget;
    int i;

    if (x < 0 || x >= table->columns)
    {
        return 0;
    }

    i = y * table->columns + x;

    if (i >= 0 && i < table->num_widgets)
    {
        widget = table->widgets[i];
        return IsActualWidget(widget)
            && TXT_SelectableWidget(widget)
            && widget->visible;
    }

    return 0;
}
示例#4
0
static void TXT_TableMousePress(TXT_UNCAST_ARG(table), int x, int y, int b)
{
    TXT_CAST_ARG(txt_table_t, table);
    txt_widget_t *widget;
    int i;

    for (i=0; i<table->num_widgets; ++i)
    {
        widget = table->widgets[i];

        // NULL widgets are spacers

        if (IsActualWidget(widget))
        {
            if (x >= widget->x && x < (signed) (widget->x + widget->w)
             && y >= widget->y && y < (signed) (widget->y + widget->h))
            {
                // This is the widget that was clicked!

                // Select the cell if the widget is selectable

                if (TXT_SelectableWidget(widget))
                {
                    ChangeSelection(table, i % table->columns,
                                           i / table->columns);
                }

                // Propagate click

                TXT_WidgetMousePress(widget, x, y, b);

                break;
            }
        }
    }
}
示例#5
0
static int TXT_TableKeyPress(TXT_UNCAST_ARG(table), int key)
{
    TXT_CAST_ARG(txt_table_t, table);
    int selected;
    int rows;

    rows = TableRows(table);

    // Send to the currently selected widget first

    selected = table->selected_y * table->columns + table->selected_x;

    if (selected >= 0 && selected < table->num_widgets)
    {
        if (IsActualWidget(table->widgets[selected])
         && TXT_SelectableWidget(table->widgets[selected])
         && TXT_WidgetKeyPress(table->widgets[selected], key))
        {
            return 1;
        }
    }

    if (key == KEY_TAB)
    {
        int dir;
        int i;

        dir = TXT_GetModifierState(TXT_MOD_SHIFT) ? -1 : 1;

        // Cycle through all widgets until we find one that can be selected.
        for (i = table->selected_y * table->columns + table->selected_x + dir;
             i >= 0 && i < table->num_widgets;
             i += dir)
        {
            if (IsActualWidget(table->widgets[i])
             && TXT_SelectableWidget(table->widgets[i]))
            {
                ChangeSelection(table, i % table->columns, i / table->columns);
                return 1;
            }
        }

        return 0;
    }

    if (key == KEY_DOWNARROW)
    {
        int new_x, new_y;

        // Move cursor down to the next selectable widget

        for (new_y = table->selected_y + 1; new_y < rows; ++new_y)
        {
            new_x = FindSelectableColumn(table, new_y, table->selected_x);

            if (new_x >= 0)
            {
                // Found a selectable widget in this column!

                ChangeSelection(table, new_x, new_y);

                return 1;
            }
        }
    }

    if (key == KEY_UPARROW)
    {
        int new_x, new_y;

        // Move cursor up to the next selectable widget

        for (new_y = table->selected_y - 1; new_y >= 0; --new_y)
        {
            new_x = FindSelectableColumn(table, new_y, table->selected_x);

            if (new_x >= 0)
            {
                // Found a selectable widget in this column!

                ChangeSelection(table, new_x, new_y);

                return 1;
            }
        }
    }

    if (key == KEY_LEFTARROW)
    {
        int new_x;

        // Move cursor left

        for (new_x = table->selected_x - 1; new_x >= 0; --new_x)
        {
            if (SelectableCell(table, new_x, table->selected_y))
            {
                // Found a selectable widget!

                ChangeSelection(table, new_x, table->selected_y);

                return 1;
            }
        }
    }

    if (key == KEY_RIGHTARROW)
    {
        int new_x;

        // Move cursor left

        for (new_x = table->selected_x + 1; new_x < table->columns; ++new_x)
        {
            if (SelectableCell(table, new_x, table->selected_y))
            {
                // Found a selectable widget!

                ChangeSelection(table, new_x, table->selected_y);

                return 1;
            }
        }
    }

    return 0;
}