« Return to Thread: How to embed a Checkbox into the FXTable?

Re: How to embed a Checkbox into the FXTable?

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 Jeroen,

Based on your suggestion, I create the following code for drawing sth on the cell.
////////////////////////////////////////////////////////////////////////////////////
class FXAPI FXCheckboxTableItem : public FXTableItem {
    FXDECLARE(FXCheckboxTableItem)

private:
    FXCheckboxTableItem(const FXCheckboxTableItem&);
    FXCheckboxTableItem& operator=(const FXCheckboxTableItem&);
protected:
    FXCheckboxTableItem(){}
    virtual void drawContent(const FXTable* table,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;

public:
    /// Construct new table item
    FXCheckboxTableItem(const FXString& label, bool isChecked, FXIcon* ic=NULL,void* ptr=NULL);
   
    /// Create input control for editing this item
    virtual FXWindow *getControlFor(FXTable* table);
   
    /// Set value from input control
    virtual void setFromControl(FXWindow *control);
   
    void setChecked(bool isChecked)
    {
        m_isChecked = isChecked;
    }
   
    bool isChecked() const
    {
        return m_isChecked;
    }

protected:   
    FXString     m_label;
    bool         m_isChecked;
    FXIcon*      m_icon;
};
/////////////////////////////////////////////////////////////
#include "FXCheckboxTableItem.h"

// Object implementation
FXIMPLEMENT(FXCheckboxTableItem,FXTableItem,NULL,0)

FXCheckboxTableItem::FXCheckboxTableItem(const FXString& label, bool isChecked, FXIcon* ic/*=NULL*/,void* ptr/*=NULL*/ )
: m_label(label), m_isChecked(isChecked), m_icon(ic)
{
}

// Create input control for editing this item
FXWindow * FXCheckboxTableItem::getControlFor( FXTable* table )
{
    register FXCheckButton *checkbox;
    register FXuint justify=0;

    checkbox=new FXCheckButton(table,m_label,this,NULL, ICON_BEFORE_TEXT|LAYOUT_SIDE_TOP);
    if(state&LEFT) justify|=JUSTIFY_LEFT;
    if(state&RIGHT) justify|=JUSTIFY_RIGHT;
    if(state&TOP) justify|=JUSTIFY_TOP;
    if(state&BOTTOM) justify|=JUSTIFY_BOTTOM;
    checkbox->create();
    checkbox->setJustify(justify);
    checkbox->setFont(table->getFont());
    checkbox->setBackColor(table->getBackColor());
    checkbox->setTextColor(table->getTextColor());

    return checkbox;   
}

void FXCheckboxTableItem::setFromControl( FXWindow *control )
{
    register FXCheckButton *check=static_cast<FXCheckButton*>(control);
    m_isChecked = check->getCheck();
}

void FXCheckboxTableItem::drawContent(const FXTable* table,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const
{
    FXRectangle rect(0, 0, 17, 17);

    dc.setForeground(FXRGB(0, 255, 0));
    dc.setBackground(FXRGB(255, 0, 0));
    dc.fillRectangle(rect.x, rect.y, rect.w, rect.h);  
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Here is the problem,
The function FXCheckboxTableItem::drawContent is called by FXTableItem::draw.

However, I didn't see the expected drawn rectangle shown up.

Please see the attached images for detail.
1>
edit.PNG, in edit mode, the checkbox is shown correctly.
2>
However, in draw.png, the expected drawn rectangle doesn't show up.

Do you know which part of the drawContent is wrong?

Many thanks.




From: Jeroen van der Zijp <jeroen@...>
To: foxgui-users@...; Feng Feng <askfoxtoolkit@...>
Sent: Wednesday, June 17, 2009 10:55:25 PM
Subject: Re: [Foxgui-users] How to embed a Checkbox into the FXTable?

On Wednesday 17 June 2009, Feng Feng wrote:
> Hello all,
>
> I need to create a table with the column filled with Checkbox.
>
> How do I implement this customized table? Any example?

What you want is a custom cell type.  One standard provided custom cell
type is FXComboTableItem, derived from FXTableItem.

Custom items may overload some of the functionality in FXTableItem; for
example, drawContent().  The basic FXTableItem draw() function is split
into drawBackground(), drawPattern(), drawContent() and then drawBorders().

Each of these are overloadable, but my suggestion is to only overload
drawContent().

Next, when the user clicks on the item to edit it, the FXTableItem's
getControlFor() API is called, its purpose is to create a widget to
edit the cell contents.  The standard FXTableItem's implementation
makes a FXTextField, sets the appropriate text justification options,
and fills the contents of the FXTextField with the value of the cell.

The control is placed over the cell by the FXTable.  After the user is
done with editing, the items setFromControl() is called.  The default
implementation grabs the text from the FXTextField and sticks it into
the cell.

The code in FXTable.{h,cpp} for implementing the FXComboTableItem may
be worth looking at to see how to implement a custom item.


    - Jeroen




--
+----------------------------------------------------------------------------+
| Copyright (C) 22:40 06/17/2009 Jeroen van der Zijp.  All Rights Reserved. |
+----------------------------------------------------------------------------+




------------------------------------------------------------------------------
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

edit.PNG (25K) Download Attachment
draw.PNG (25K) Download Attachment

 « Return to Thread: How to embed a Checkbox into the FXTable?