[fxruby-users] FXTable, SEL_REPLACED and modal dialogs, 2nd

Philippe Lang philippe.lang at attiksystem.ch
Mon May 4 11:27:08 EDT 2009


fxruby-users-bounces at rubyforge.org wrote:

> Hi again, and sorry for the previous incomplete message.
> 
> I'm using the SEL_REPLACE event in FXTable to check at run-time that
> the values entered by the user are correct. In case of an error, I
> tried to show the error with an FXMessageBox modal dialog, like in
> the following test code:   
> 
> ----------------------------------------------
> #!/usr/bin/ruby
> 
> require 'fox16'
> 
> include Fox
> 
> class MyWindow < FXMainWindow
> 
>   def initialize(app)
> 
>     super(app, "Window", nil, nil, DECOR_ALL, 0, 0, 600, 350)
> 
>     # Menu bar stretched along the top of the main window
>     menubar = FXMenuBar.new(self, LAYOUT_SIDE_TOP|LAYOUT_FILL_X)
> 
>     # File menu
>     filemenu = FXMenuPane.new(self)
>     FXMenuTitle.new(menubar, "&File", nil, filemenu)
>     FXMenuCommand.new(filemenu, "&Quit\tCtl-Q\tQuit the application",
>         nil, app, FXApp::ID_QUIT)
> 
>     # Table
>     f = FXHorizontalFrame.new(self, LAYOUT_FILL_X|LAYOUT_FILL_Y)
>     t = FXTable.new(f, nil, 0,
> TABLE_COL_SIZABLE|LAYOUT_FILL_X|LAYOUT_FILL_Y)
>     t.connect(SEL_REPLACED, method(:onReplaced))
> 
>     t.visibleRows = 3
>     t.visibleColumns = 3
>     t.setTableSize(3, 3)
> 
>   end
> 
>   def create
>     super
>     show(PLACEMENT_SCREEN)
>   end
> 
>   def onReplaced(sender, sel, data)
>     FXMessageBox.information(self, MBOX_OK, "Error", "This is an error
> message.")
>   end
> 
> end
> 
> if __FILE__ == $0
>   application = FXApp.new("Attik System", "FXRuby Test")
>   MyWindow.new(application)
>   application.create
>   application.run
> end
> ----------------------------------------------
> 
> FXRuby or maybe fox itself gets confused after the modal dialog has
> been 
> closed: although the mouse button has been released, FXTable cells
> selection follow the mouse. 
> 
> To reproduce the problem, do the following:
> 
> 1) Click in a cell.
> 2) Type something in this cell.
> 3) Press TAB or click on another cell. An error message appears.
> Close it. 4) Move your cursor around on the table cells. Here is the
> problem. 
> 
> Is that a bug? And if yes, is there a workaround maybe? The only
> solution I found for this problem, is to use a non-modal dialog. No
> problem in this case.  

Hi,

I took time today to track the bug I mentionned a few months ago. It is
a problem at the Fox level, apparently due to the way selections can be
extended in an FXTable.

I have commented out both "mode=MOUSE_SELECT;" lines in
FXTable::onLeftBtnPress, and the problem disapeared. But as a
side-effect, it is not possible to extend selections in FXTable objects
anymore.

=========================================
// Pressed button
long FXTable::onLeftBtnPress(FXObject*,FXSelector,void* ptr){
  FXEvent* event=(FXEvent*)ptr;
  FXTablePos tablepos;
  flags&=~FLAG_TIP;
  handle(this,FXSEL(SEL_FOCUS_SELF,0),ptr);
  if(isEnabled()){
    grab();
    if(target &&
target->tryHandle(this,FXSEL(SEL_LEFTBUTTONPRESS,message),ptr)) return
1;

    // Cell being clicked on
    tablepos.row=rowAtY(event->win_y);
    tablepos.col=colAtX(event->win_x);

    // Outside table
    if(tablepos.row<0 || tablepos.row>=nrows || tablepos.col<0 ||
tablepos.col>=ncols){
      setCurrentItem(current.row,current.col,true);
      return 1;
      }

    // Change current item
    setCurrentItem(tablepos.row,tablepos.col,TRUE);

    // Select or deselect
    if(event->state&SHIFTMASK){
      if(0<=anchor.row && 0<=anchor.col){
        if(isItemEnabled(anchor.row,anchor.col)){
          extendSelection(current.row,current.col,TRUE);
          }
        }
      else{
        setAnchorItem(current.row,current.col);
        if(isItemEnabled(current.row,current.col)){
          extendSelection(current.row,current.col,TRUE);
          }
        }
      //mode=MOUSE_SELECT;     <== HERE
      }
/*
    else if(event->state&CONTROLMASK){
      if(isItemEnabled(current.row,current.col)){
//        toggleItem(current.row,current.col,TRUE);
        }
      setAnchorItem(current.row,current.col);
      mode=MOUSE_SELECT;
      }
*/
    else{
      if(isItemEnabled(current.row,current.col)){
        killSelection(TRUE);
        setAnchorItem(current.row,current.col);
        extendSelection(current.row,current.col,TRUE);
        }
      else{
        setAnchorItem(current.row,current.col);
        }
      //mode=MOUSE_SELECT; 	 <== HERE
      }
    flags&=~FLAG_UPDATE;
    flags|=FLAG_PRESSED;
    return 1;
    }
  return 0;
  }
=========================================

I couldn't find for the moment a patch that allows the user to extend
his selection. Jeroen, maybe you have an idea?

Best regards,

Philippe



Note:
-----

To debug, I simply added a line in the TableWindows Fox test project:

// Replaced
long TableWindow::onTableReplaced(FXObject*,FXSelector,void* ptr){
  FXTableRange *tr=(FXTableRange*)ptr;
  FXTRACE((10,"SEL_REPLACED fm.row=%d, fm.col=%d to.row=%d,
to.col=%d\n",tr->fm.row,tr->fm.col,tr->to.row,tr->to.col));

  FXMessageBox::error(this,MBOX_OK,"Error","This is a modal error
message");

  return 1;
  }


More information about the fxruby-users mailing list