THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 02/03/2005 at 18:15, xxxxxxxx wrote:
Okay, here's a start. Not sure how to coordinate the scrollbars with the UserArea size and number of items - i.e.: can't get UserArea GetWidth() and GetHeight() to work.
////////////////////////////////////////////////////////////////
// lvdialog.coh
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
class MyListItem
{
private:
var text;
var selected;
public:
MyListItem(txt);
GetText();
Select(tf);
IsSelected();
}
MyListItem::MyListItem(txt)
{
text = txt;
selected = FALSE;
}
MyListItem::GetText()
{
return text;
}
MyListItem::Select(tf)
{
selected = tf;
}
MyListItem::IsSelected()
{
return selected;
}
// MyUserArea ***************************************
class MyUserArea : GeUserArea
{
private:
var list;
var theDialog;
var width, height;
var cellHeight;
var frameHeight;
var offsetX, offsetY;
public:
MyUserArea(id,dlg);
Init();
Sized(w,h);
Draw(x1, y1, x2, y2);
InputEvent(msg);
GetOffsetX();
GetOffsetY();
GetVisibleX();
GetVisibleY();
SetList(list);
}
// Constructor
MyUserArea::MyUserArea(id,dlg)
{
super(id,dlg);
theDialog = dlg;
}
// GeUserArea.Init
MyUserArea::Init()
{
var fh = DrawGetFontHeight();
cellHeight = fh + (fh/2);
frameHeight = fh/4;
offsetX = offsetY = 0;
return TRUE;
}
// GeUserArea.Sized
MyUserArea::Sized(w, h)
{
width = w;
height = h;
return TRUE;
}
// GeUserArea.Draw
MyUserArea::Draw(x1, y1, x2, y2)
{
// No flicker
OffScreenOn();
SetClippingRegion(x1,y1,x2,y2);
// Clear area
DrawSetPen(vector(0.5));
DrawRectangle(x1,y1,x2,y2);
// Draw all List Items
var n;
for (n = 0; n < 10; n++)
{
if (list[n]->IsSelected())
DrawSetTextPen(vector(1.0), vector(0.5));
else
DrawSetTextPen(vector(0.0), vector(0.5));
DrawText(list[n]->GetText(), 8, (i*cellHeight)+frameHeight);
}
return TRUE;
}
// GeUserArea.InputEvent
MyUserArea::InputEvent(msg)
{
var dev = msg->GetData(BFM_INPUT_DEVICE);
if (dev == BFM_INPUT_MOUSE)
{
var chn = msg->GetData(BFM_INPUT_CHANNEL);
var qua = msg->GetData(BFM_INPUT_QUALIFIER);
var action = new(BaseContainer, BFM_ACTION);
action->SetData(BFM_ACTION_ID,GetId());
action->SetData(BFM_ACTION_VALUE,0);
var mx, my;
// Left Button
if (chn == BFM_INPUT_MOUSELEFT)
{
var n, j;
var pY;
var dc = msg->GetData(BFM_INPUT_DOUBLECLICK);
my = msg->GetData(BFM_INPUT_Y);
my = Global2LocalY(my);
// Is mouse over ListItem
for (n = 0; n < 10; n++)
{
pY = (n*cellHeight)+offsetY;
if ((my >= pY) && (my < (pY+cellHeight))) break;
}
// Do Something with ListItem
if (n < 10)
{
// Add to selection
if (qua == QSHIFT) list[n]->Select(TRUE);
// Remove from selection
else if (qua == QCTRL) list[n]->Select(FALSE);
// Remove all current selections, select this one
else
{
for (j = 0; j < 10; j++)
list[j]->Select(FALSE);
Redraw();
list[n]->Select(TRUE);
}
}
// Remove all current selections
else
{
for (j = 0; j < 10; j++)
list[j]->Select(FALSE);
}
Redraw();
SendParentMessage(action);
}
return TRUE;
}
return FALSE;
}
MyUserArea::GetOffsetX()
{
return offsetX;
}
MyUserArea::GetOffsetY()
{
return offsetY;
}
MyUserArea::GetVisibleX()
{
width;
}
MyUserArea::GetVisibleY()
{
var visible = (10 * cellHeight) - height;
if (visible <= 0) return 0;
return visible;
}
MyUserArea::SetList(ls)
{
list = ls;
}
// LVDialog ***************************************
enum
{
GROUP_MAIN = 4000,
GROUP_SCROLL,
ID_LVUSERAREA
}
// CLASS: List View Dialog
class LVDialog : GeDialog
{
private:
var a;
var userarea;
public:
LVDialog();
CreateLayout();
Init();
Message(msg);
Command(id, msg);
GetList();
}
// Constructor
LVDialog::LVDialog()
{
super(PLUGIN_MENU_ID);
a = new(array,10);
a[0] = new(MyListItem,"Item 1");
a[1] = new(MyListItem,"Item 2");
a[2] = new(MyListItem,"Item 3");
a[3] = new(MyListItem,"Item 4");
a[4] = new(MyListItem,"Item 5");
a[5] = new(MyListItem,"Item 6");
a[6] = new(MyListItem,"Item 7");
a[7] = new(MyListItem,"Item 8");
a[8] = new(MyListItem,"Item 9");
a[9] = new(MyListItem,"Long, Long, Long Item 10");
}
// Layout Dialog GUI
LVDialog::CreateLayout()
{
SetTitle(resource->GetString(PLUGIN_MENU_TEXT)+" v"+resource->GetString(PLUGIN_MENU_VERSION));
AddGroupBeginV(GROUP_MAIN,BFH_SCALEFIT|BFV_SCALEFIT,1,"",0);
{
AddGroupBorderSpace(4,4,4,4);
AddGroupSpace(4,4);
AddScrollGroupBegin(GROUP_SCROLL, BFH_SCALEFIT|BFV_SCALEFIT, SCROLLGROUP_VERT|SCROLLGROUP_HORIZ);
{
AddGroupBeginV(0,BFH_SCALEFIT|BFV_SCALEFIT,1,"",0);
{
AddGroupBorder(BORDER_IN);
AddUserArea(ID_LVUSERAREA, BFH_SCALEFIT|BFV_SCALEFIT, 0, 0);
userarea = new(MyUserArea,ID_LVUSERAREA,this);
}
AddGroupEnd();
}
AddScrollGroupEnd();
}
AddGroupEnd();
return TRUE;
}
LVDialog::Init()
{
userarea->SetList(a);
}
LVDialog::Message(msg)
{
return super::Message(msg);
}
LVDialog::Command(id, msg)
{
}
Again, it's a static list, but it should be straight forward to make it variable. You can also change the text background during selection if you like.