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

Re: How to embed a Checkbox into the FXTable?

by Jeroen van der Zijp :: Rate this Message:

Reply to Author | View in Thread

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

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