About TableListRowComp::mouseUp()


#1

Hi Jules,

I have a TableListBox derived class that I use like an horizontal ListBox, so that it always has a single row and a continuosly variable number of columns. I would like to receive TableListBoxModel::backgroundClicked() notifications, so I would suggest to change the TableListRowComp::mouseUp() method from:

[code] void mouseUp (const MouseEvent& e)
{
if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
{
owner.selectRowsBasedOnModifierKeys (row, e.mods);

        const int columnId = owner.getHeader()->getColumnIdAtX (e.x);

        if (columnId != 0 && owner.getModel() != 0)
            owner.getModel()->cellClicked (row, columnId, e);
    }
}[/code]

to:

[code] void mouseUp (const MouseEvent& e)
{
if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
{
owner.selectRowsBasedOnModifierKeys (row, e.mods);

        const int columnId = owner.getHeader()->getColumnIdAtX (e.x);

        if (owner.getModel() != 0)
        {
            if (columnId != 0)
                owner.getModel()->cellClicked (row, columnId, e);
            else
                owner.getModel()->backgroundClicked();
        }
    }
}[/code]

What do you think?


#2

I’m not sure I approve of the way you’re mis-using the TableListBox, but your point is a good one! A cleaner way to do it would be to limit the width of the row component though, so that mouse events on the background would actually go straight to the background, rather than bodging the row components to pass them through.

E.g. adding a hit-test:

bool hitTest (int x, int) { return owner.getHeader().getColumnIdAtX (x) != 0; }


#3

Adding this hitTest() method to TableListRowComp has the effect to call ListBoxModel::listBoxItemClicked().
Is this what you intended?


#4

No, but I hadn’t tested it yet, it was just a suggestion. I’ll take a look when I get chance.