[fxruby-users] FXTable copy/paste issue

Lars Kanis lars at greiz-reinsdorf.de
Wed Jul 4 16:11:12 UTC 2012


2012/7/1 William Parsons <wbparsons at alum.mit.edu>:
> I suspect this is a FOX rather than fxruby issue.

Yes, you're right, it is a libfox issue. There is a hard coded split
in fox/src/FXTable.cpp#1528 that is used for pasting from the
clipboard. Columns are separated by "\t" or "," and rows by "\n". I
verified this for libfox-1.6.45 and for 1.7.33.

In order to work around this limitation you may do the insertion from
clipboard by yourself. You could do this by deriving FXTable. This
works for Linux. For other OS you may have to try alternatives to
FXTable.utf8Type as seen in src/FXTable.cpp.

  class MyFXTable < Fox::FXTable
    include Responder
    def initialize(*args, &block)
      super
      FXMAPFUNC(SEL_COMMAND, FXTable::ID_PASTE_SEL, 'onCmdPasteSel')
    end
    def onCmdPasteSel(sender, sel, ptr)
      data = getDNDData(FROM_CLIPBOARD, FXTable.utf8Type)
      if data && anythingSelected?
        rows_cols = data.split("\n").map{|l| l.split("\t") }
        row_nr = selStartRow
        max_cols = 0
        rows_cols.each do |cols|
          col_nr = selStartColumn
          cols.each do |text|
            setItemText( row_nr, col_nr, text)
            col_nr += 1
          end
          row_nr += 1
          max_cols = [max_cols, cols.length].max
        end
        selectRange(selStartRow, selStartRow+rows_cols.length-1,
selStartColumn, selStartColumn+max_cols-1)
      end
    end
  end


You may file a bug on the fox toolkit?

--
Regards,
Lars


More information about the fxruby-users mailing list