New issue related to embed a checkbox into table cell

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

New issue related to embed a checkbox into table cell

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,

Question part one:
Based on previous comments & helps, I use the following method to embed a checkbox into table cell.

// FXCheckboxTableItem : public FXTableItem
FXCheckboxTableItem::FXCheckboxTableItem(FXApp* app, const FXString& label, bool isChecked, void* ptr/*=NULL*/)
: m_app(app), m_label(label), m_isChecked(isChecked)
{
    checkbox_no_icon=new FXBMPIcon(m_app,checkbox_no_bmp,0,IMAGE_ALPHAGUESS);
    checkbox_no_icon->create();
    checkbox_yes_icon=new FXBMPIcon(m_app,checkbox_yes_bmp,0,IMAGE_ALPHAGUESS);
    checkbox_yes_icon->create();
    setIcon(checkbox_no_icon); // default icon is uncheck image
}

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();

    if (m_isChecked)
    {
        setIcon(checkbox_yes_icon); // a picture captured when a checkbox is check
    }
    else
    {
        setIcon(checkbox_no_icon); // a picture captured when a checkbox is uncheck
    }   
}

Now new problems are as follows:

Expected actions: whenever the user single-clicks the cell, then the icon switches between yes and no icons.

Current actions: The user has to double-click the cell in order to change the icon from yes to no or no to yes icons.
The major reason of this problem is that when the user double-clicks the cell, then the cell enters Edit mode that in turn triggers the setFromControl and getControlFor.

Is there a way that I can use so that
1> double clicks the cell does nothing
2> single  clicks the cell will switch between two icons


Question part two:
I also try to catch the selection event, however, the code is not called by the selection
FXDEFMAP(FXCheckboxTableItem) FXCheckboxTableItemMap[]={
    FXMAPFUNC(SEL_LEFTBUTTONPRESS,  0, FXCheckboxTableItem::onItemSelected),
    FXMAPFUNC(SEL_DESELECTED,       0, FXCheckboxTableItem::onItemDeselected),
};

// Object implementation
FXIMPLEMENT(FXCheckboxTableItem,FXTableItem,FXCheckboxTableItemMap,ARRAYNUMBER(FXCheckboxTableItemMap))

// Leave window
long FXCheckboxTableItem::onItemSelected(FXObject* sender,FXSelector sel,void* ptr)
{

    return 1;
}

// Leave window
long FXCheckboxTableItem::onItemDeselected(FXObject* sender,FXSelector sel,void* ptr)
{
    return 1;
}

Thank you again.



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

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

by Hardy, Stephen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think you might need to look at subclassing FXTable itself.  Then, you can intercept mouse events etc.

For your problem with needing double click to change a checkbox, what you need to do is intercept mouse movement (SEL_MOTION) messages, in your subclassed FXTable, and use them to automatically set an item to be editable as soon as the mouse moves over the the table items.  You can be clever and just do this for your FXCheckboxTableItem items, rather than all items.

Regards,
SJH


> -----Original Message-----
> From: Feng Feng [mailto:askfoxtoolkit@...]
> Sent: Monday, June 22, 2009 9:21 AM
> To: foxgui-users@...
> Subject: [Foxgui-users] New issue related to embed a checkbox into
> table cell
>
> Hello all,
>
> Question part one:
> Based on previous comments & helps, I use the following method to embed
> a checkbox into table cell.
>
> // FXCheckboxTableItem : public FXTableItem
> FXCheckboxTableItem::FXCheckboxTableItem(FXApp* app, const FXString&
> label, bool isChecked, void* ptr/*=NULL*/)
> : m_app(app), m_label(label), m_isChecked(isChecked)
> {
>     checkbox_no_icon=new
> FXBMPIcon(m_app,checkbox_no_bmp,0,IMAGE_ALPHAGUESS);
>     checkbox_no_icon->create();
>     checkbox_yes_icon=new
> FXBMPIcon(m_app,checkbox_yes_bmp,0,IMAGE_ALPHAGUESS);
>     checkbox_yes_icon->create();
>     setIcon(checkbox_no_icon); // default icon is uncheck image
> }
>
> 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();
>
>     if (m_isChecked)
>     {
>         setIcon(checkbox_yes_icon); // a picture captured when a
> checkbox is check
>     }
>     else
>     {
>         setIcon(checkbox_no_icon); // a picture captured when a
> checkbox is uncheck
>     }
> }
>
> Now new problems are as follows:
>
> Expected actions: whenever the user single-clicks the cell, then the
> icon switches between yes and no icons.
>
> Current actions: The user has to double-click the cell in order to
> change the icon from yes to no or no to yes icons.
> The major reason of this problem is that when the user double-clicks
> the cell, then the cell enters Edit mode that in turn triggers the
> setFromControl and getControlFor.
>
> Is there a way that I can use so that
> 1> double clicks the cell does nothing
> 2> single  clicks the cell will switch between two icons
>
>
> Question part two:
> I also try to catch the selection event, however, the code is not
> called by the selection
> FXDEFMAP(FXCheckboxTableItem) FXCheckboxTableItemMap[]={
>     FXMAPFUNC(SEL_LEFTBUTTONPRESS,  0,
> FXCheckboxTableItem::onItemSelected),
>     FXMAPFUNC(SEL_DESELECTED,       0,
> FXCheckboxTableItem::onItemDeselected),
> };
>
> // Object implementation
> FXIMPLEMENT(FXCheckboxTableItem,FXTableItem,FXCheckboxTableItemMap,ARRA
> YNUMBER(FXCheckboxTableItemMap))
>
> // Leave window
> long FXCheckboxTableItem::onItemSelected(FXObject* sender,FXSelector
> sel,void* ptr)
> {
>
>     return 1;
> }
>
> // Leave window
> long FXCheckboxTableItem::onItemDeselected(FXObject* sender,FXSelector
> sel,void* ptr)
> {
>     return 1;
> }
>
> Thank you again.
>
>


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