How to embed a Checkbox into the FXTable?

View: New views
7 Messages — Rating Filter:   Alert me  

How to embed a Checkbox into the FXTable?

by Feng Feng :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

I need to create a table with the column filled with Checkbox.

How do I implement this customized table? Any example?

Thank you



------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Foxgui-users mailing list
Foxgui-users@...
https://lists.sourceforge.net/lists/listinfo/foxgui-users

Re: How to embed a Checkbox into the FXTable?

by Jeroen van der Zijp :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Foxgui-users mailing list
Foxgui-users@...
https://lists.sourceforge.net/lists/listinfo/foxgui-users

Re: How to embed a Checkbox into the FXTable?

by Feng Feng :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

I have read the implementation code for FXComboTableItem.
However, it doesn't tell me how to always display the control in the cell.

table->setItem(0, 0, new FXComboTableItem("item1\nitem2\nitem3", NULL, NULL));

FXComboTableItem only displays a Combo whenever the cell is in edit mode. I need to know how to
always display the Combo in the cell rather than just in edit mode.

Thank you



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


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Foxgui-users mailing list
Foxgui-users@...
https://lists.sourceforge.net/lists/listinfo/foxgui-users

Re: How to embed a Checkbox into the FXTable?

by Jeroen van der Zijp :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Friday 19 June 2009, you wrote:
> Hello Jeroen,
>
> I have read the implementation code for FXComboTableItem.
> However, it doesn't tell me how to always display the control in the cell.
>
> table->setItem(0, 0, new FXComboTableItem("item1\nitem2\nitem3", NULL, NULL));
>
> FXComboTableItem only displays a Combo whenever the cell is in edit mode. I need to know how to
> always display the Combo in the cell rather than just in edit mode.

You don't want to do that since having one widget for every cell would be *very* expensive.

What you want to do is overload the drawContent() in the FXTableItem and make it draw what
you'd like to see when the cell is not being edited.


        - Jeroen




------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Foxgui-users mailing list
Foxgui-users@...
https://lists.sourceforge.net/lists/listinfo/foxgui-users

Re: How to embed a Checkbox into the FXTable?

by Feng Feng :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

Is there an easy way that I can draw the CheckBox on a cell without directly copying the implementation code from FXCheckButton::onPaint

Thank you



From: Jeroen van der Zijp <jeroen@...>
To: Feng Feng <askfoxtoolkit@...>
Cc: FOX Users <foxgui-users@...>
Sent: Friday, June 19, 2009 10:22:26 AM
Subject: Re: [Foxgui-users] How to embed a Checkbox into the FXTable?

On Friday 19 June 2009, you wrote:
> Hello Jeroen,
>
> I have read the implementation code for FXComboTableItem.
> However, it doesn't tell me how to always display the control in the cell.
>
> table->setItem(0, 0, new FXComboTableItem("item1\nitem2\nitem3", NULL, NULL));
>
> FXComboTableItem only displays a Combo whenever the cell is in edit mode. I need to know how to
> always display the Combo in the cell rather than just in edit mode.

You don't want to do that since having one widget for every cell would be *very* expensive.

What you want to do is overload the drawContent() in the FXTableItem and make it draw what
you'd like to see when the cell is not being edited.


    - Jeroen





------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Foxgui-users mailing list
Foxgui-users@...
https://lists.sourceforge.net/lists/listinfo/foxgui-users

Re: How to embed a Checkbox into the FXTable?

by Feng Feng :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

Re: How to embed a Checkbox into the FXTable?

by Jeroen van der Zijp :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Friday 19 June 2009, you wrote:

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


Your coordinate system, basically.

FXTable sets the cells clip rectangle, then calls cells draw() API with the rectangle relative to
the top-left corner of the FXTable.  The x,y,w,h are the rectangle occupied by the cell.

The solution is clear:

FXRectangle rect(x+offx, y+offy, 17, 17);

with offx, offy being the amount of offset relative to the top/left of the cell corner
where you want your rectangle.  My suggestion is to compute that based on content-
layout flags as provided by the cell justify and layout options...


                - Jeroen

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