« Return to Thread: New issue related to embed a checkbox into table cell

Re: New issue related to embed a checkbox into table cell

by Feng Feng :: Rate this Message:

Reply to Author | View in Thread

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hello Daniel,

Thank you very much for your code. It works pretty well for me.

However, I have three questions for you

1> Should we call "check->create();" in CheckTableItem::CheckTableItem

Without changing your code, I use the following statement to insert a new cell.
    table->setItem(2,1, new CheckTableItem(table, NULL, NULL));
After I run the application, the warning message as follows is shown,

FXCheckButton::create trying to create window before creating parent window

After I comment out the line "check->create();", the code works great

2> Why should we call the following statement in the function onCheck

Target->handle(this, FXSEL(SEL_REPLACED,Selector), &tablerange);

3> The return of the function getCheck may be changed as FXuchar.

Thank you again for your kindness to share your code.
-Feng


From: Daniel Stine <robodanny@...>
To: foxgui-users@...
Sent: Tuesday, June 23, 2009 6:19:17 AM
Subject: [Foxgui-users] New issue related to embed a checkbox into table cell

Feng,

It's funny, but I just recently solved this same problem in an
entirely different way.
I subclassed FXTableItem and embedded a real FXCheckbox in the item.
Works for me.

//---------------------------------------------------------------
//
//  Derived checkbox table item
//
//---------------------------------------------------------------
class CheckTableItem : public FXTableItem
{
    FXDECLARE(CheckTableItem)

  protected:

    CheckTableItem() {}

  private:

    FXTable        *Table;
    FXObject        *Target;
    FXSelector        Selector;

    FXCheckButton  *check;

    virtual void drawContent(const FXTable* table,FXDC& dc,FXint
x,FXint y,FXint w,FXint h) const;

  public:

    long onCheck(FXObject *, FXSelector, void *);

    enum {
    ID_CHECK = 1,
    ID_LAST
    };

  public:

    CheckTableItem(FXTable *table, FXIcon *ic=NULL, void *ptr=NULL);
    virtual ~CheckTableItem(void) { delete check; }

    void setCheck(FXbool state=TRUE, FXbool notify=FALSE) {
check->setCheck(state, notify); }
    FXbool getCheck() const { return check->getCheck(); }
};


//---------------------------------------------------------------
//    CheckTableItem
//---------------------------------------------------------------
FXDEFMAP(CheckTableItem) CheckTableItemMap[] = {
  FXMAPFUNC(SEL_COMMAND, CheckTableItem::ID_CHECK, CheckTableItem::onCheck),
};

FXIMPLEMENT(CheckTableItem, FXTableItem, CheckTableItemMap,
ARRAYNUMBER(CheckTableItemMap))

// Construct new table item
CheckTableItem::CheckTableItem(FXTable *table, FXIcon *ic, void *ptr):
    FXTableItem(FXString::null,ic,ptr)
{
    Table = table;
    Target = table->getTarget();
    Selector = table->getSelector();
    check = new FXCheckButton(table, FXString::null, this, ID_CHECK);
    check->setBackColor(table->getBackColor());
    check->create();
}

//
//    drawContent - override
//
void CheckTableItem::drawContent(const FXTable *table, FXDC &dc,
    FXint x, FXint y, FXint w, FXint h) const
{
    check->position(x+1,y+1,w-2,h-2);
    return;
}

//
//    onCheck
//
long CheckTableItem::onCheck(FXObject *, FXSelector, void *vp)
{
    if (Target) {
    FXTableRange tablerange;
    tablerange.fm.row = tablerange.to.row = Table->rowAtY(check->getY());
    tablerange.fm.col = tablerange.to.col = Table->colAtX(check->getX());
//fxmessage("[%d,%d] = %p\n", tablerange.fm.row, tablerange.fm.col, vp);
    Target->handle(this, FXSEL(SEL_REPLACED,Selector), &tablerange);
    }
    return 1;
}







> Date: Mon, 22 Jun 2009 09:20:46 -0700 (PDT)
> From: Feng Feng <askfoxtoolkit@...>
> Subject: [Foxgui-users] New issue related to embed a checkbox into
>        table cell
> To: foxgui-users@...
> Message-ID: <711576.78275.qm@...>
> Content-Type: text/plain; charset="us-ascii"
>
> Hello all,
>
> Question part one:
> Based on previous comments & helps, I use the following method to embed a checkbox into table cell.
>

------------------------------------------------------------------------------
Are you an open source citizen? Join us for the Open Source Bridge conference!
Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250.
Need another reason to go? 24-hour hacker lounge. Register today!
http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org
_______________________________________________
Foxgui-users mailing list
Foxgui-users@...
https://lists.sourceforge.net/lists/listinfo/foxgui-users


------------------------------------------------------------------------------

_______________________________________________
Foxgui-users mailing list
Foxgui-users@...
https://lists.sourceforge.net/lists/listinfo/foxgui-users

 « Return to Thread: New issue related to embed a checkbox into table cell