Home » U++ Library support » U++ Widgets - General questions or Mixed problems » Problem with ColumnList (with example) [BUG/FIXED]
Problem with ColumnList (with example) [BUG/FIXED] [message #5748] |
Thu, 12 October 2006 19:20  |
James Thomas
Messages: 26 Registered: June 2006
|
Promising Member |
|
|
I hope I'm not asking an obvious question (again ), but I'm having serious problems with ColumnList. I can't get it to work properly at all.
In the example below I fill a list box with entries and after every selection I count the number of selected entries and display it in an EditInt ctrl. However, the behaviour of the list is very strange.
When you click on an item the selection callback is triggered and the item is highlighted, but when I check the items it appears that none has actually been selected. When you hold down the Ctrl or Shift key it correctly registers the selection but the row is not highlighted (unless you use Shift in which case it only highlight the anchor item). This is obviously completely wrong and happens both in single and multi-select modes.
#include <CtrlLib/CtrlLib.h>
class AWindow : public TopWindow {
public:
typedef AWindow CLASSNAME;
Option _optMulti;
ColumnList _List;
Label _Label;
EditInt _intSelCount;
AWindow()
{
Ctrl::LogPos p = GetPos();
p.x.SetB(228);
p.y.SetB(356);
SetPos(p);
_List.LeftPosZ(4, 220).TopPosZ(32, 292);
_intSelCount.LeftPosZ(176, 48).TopPosZ(328, 19);
_Label.SetLabel("Number of items selected:").LeftPosZ(48, 124).TopPosZ(328, 19);
_optMulti.SetLabel("Multi-Select").LeftPosZ(4, 76).TopPosZ(8, 15);
Add(_List);
Add(_intSelCount);
Add(_Label);
Add(_optMulti);
_List.Columns(1);
_List.Multi(false);
_List.WhenSelection = THISBACK(Selection);
String s = "Spam ";
for (int i = 0; i < 20; i++) {
_List.Add(s + AsString(i));
}
_intSelCount.SetData(0);
_intSelCount.SetEditable(false);
_optMulti <<= THISBACK(MultiChange);
}
void Selection()
{
int cnt = 0;
for (int i = 0; i < _List.GetCount(); i++) {
if (_List.IsSelected(i))
cnt++;
}
_intSelCount.SetData(cnt);
}
void MultiChange()
{
_List.Multi(_optMulti.Get());
}
};
GUI_APP_MAIN
{
AWindow w;
w.Run();
}
I suspect I've done something wrong, since this seems like a rather obvious problem, but then I looked at the code in ColumnList.cpp:
void ColumnList::LeftDown(Point p, dword flags) {
int i = GetDragColumn(p.x);
if(i >= 0) {
ci = i;
dx = p.x - GetColumnCx(0) * (i + 1);
mpos = p.x;
SetCapture();
Refresh(mpos - dx, 0, 1, GetSize().cy);
}
else {
int anchor = cursor;
SetWantFocus();
PointDown(p);
p.y %= cy;
p.x %= GetColumnCx(0);
if(cursor >= 0) {
if(flags & K_SHIFT && anchor >= 0) {
ShiftSelect(anchor, cursor);
WhenLeftClickPos(p);
return;
}
else
if(flags & K_CTRL) {
if(anchor >= 0 && !IsSelection())
SelectOne(anchor, true);
SelectOne(cursor, !IsSelected(cursor));
WhenLeftClickPos(p);
return;
}
}
ClearSelection();
WhenLeftClickPos(p);
}
}
And it looks like SelectOne is never called unless Ctrl or Shift are held down. It is still a mystery to me how the row can be highlighted though.
What's going on?
(tested on Dev-2, but the ColumnList source looks the same in 605)
[Updated on: Mon, 16 October 2006 18:04] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sun Apr 27 18:37:52 CEST 2025
Total time taken to generate the page: 0.03506 seconds
|