Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 49617 - Table row doesn't stay colored as selected when editor is displayed on Linux
Summary: Table row doesn't stay colored as selected when editor is displayed on Linux
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.0   Edit
Hardware: PC Linux-GTK
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Felipe Heidrich CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 51584 74769 81430 87450 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-01-07 05:11 EST by Miroslav Halas CLA
Modified: 2006-05-31 16:21 EDT (History)
6 users (show)

See Also:


Attachments
working (I think) on gtk 2.2.1 (5.43 KB, image/pjpeg)
2004-01-07 10:51 EST, Grant Gayed CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Miroslav Halas CLA 2004-01-07 05:11:21 EST
BUG in Fedora Core 1 Linux with SWT 3.0M6 and below. If the background color 
is set then the row will not appear as selected if it is edited (different 
behaviour from other rows) The problem is that I need to set the background 
color because for example before I set the background color to Green and now
I want to restore it. It should appear as selected when edited (that is the 
behaviour on windows) but it is not.

Here is the snippet adapted from the standard code.

package com.abmira.swt.snippets.control.table;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;

public class TableEditor2
{
   public static void main(String[] args)
   {
      Display display = new Display();
      Shell shell = new Shell(display);
      shell.setLayout(new FillLayout());
      final Table table = new Table(shell, SWT.BORDER | SWT.MULTI);
      table.setLinesVisible(true);
      for (int i = 0; i < 3; i++)
      {
         TableColumn column = new TableColumn(table, SWT.NONE);
         column.setWidth(100);
      }
      for (int i = 0; i < 3; i++)
      {
         TableItem item = new TableItem(table, SWT.NONE);
         item.setText(new String[] { "" + i, "" + i, "" + i });
         if (i == 1)
         {
            // BUG in Fedora Core 1 Linux with SWT 3.0M6 and below
            // If the background color is set then the row will not appear as
            // selected if it is edited (different behaviour from other rows)
            // The problem is that I need to set the background color because
            // for example before I set the background color to Green and now
            // I want to restore it. It should be selected when edited (that 
is 
            // the behaviour on windows) but it is not
            item.setBackground(item.getDisplay().getSystemColor(
                  SWT.COLOR_LIST_BACKGROUND));                           
         }
      }
      final TableEditor editor = new TableEditor(table);
      editor.horizontalAlignment = SWT.LEFT;
      editor.grabHorizontal = true;
      table.addListener(SWT.MouseDown, new Listener()
      {
         public void handleEvent(Event event)
         {
            Rectangle clientArea = table.getClientArea();
            Point pt = new Point(event.x, event.y);
            int index = table.getTopIndex();
            while (index < table.getItemCount())
            {
               boolean visible = false;
               final TableItem item = table.getItem(index);
               for (int i = 0; i < table.getColumnCount(); i++)
               {
                  Rectangle rect = item.getBounds(i);
                  if (rect.contains(pt))
                  {
                     final int column = i;
                     final Text text = new Text(table, SWT.NONE);
                     Listener textListener = new Listener()
                     {
                        public void handleEvent(final Event e)
                        {
                           switch (e.type)
                           {
                              case SWT.FocusOut :
                                 item.setText(column, text.getText());
                                 text.dispose();
                                 break;
                              case SWT.Traverse :
                                 switch (e.detail)
                                 {
                                    case SWT.TRAVERSE_RETURN :
                                       item.setText(column, text.getText());
                                       //FALL THROUGH
                                    case SWT.TRAVERSE_ESCAPE :
                                       text.dispose();
                                       e.doit = false;
                                 }
                                 break;
                           }
                        }
                     };
                     text.addListener(SWT.FocusOut, textListener);
                     text.addListener(SWT.Traverse, textListener);
                     editor.setEditor(text, item, i);
                     text.setText(item.getText(i));
                     text.selectAll();
                     text.setFocus();
                     return;
                  }
                  if (!visible && rect.intersects(clientArea))
                  {
                     visible = true;
                  }
               }
               if (!visible)
                  return;
               index++;
            }
         }
      });
      shell.pack();
      shell.open();
      while (!shell.isDisposed())
      {
         if (!display.readAndDispatch())
            display.sleep();
      }
      display.dispose();
   }
}
Comment 1 Grant Gayed CLA 2004-01-07 10:49:55 EST
Assuming I understand the problem, this works for me.  I'll attach an image 
next that shows what I see.  I tried with gtk 2.0.6 and 2.2.1.  Does my 
screenshot not mirror what you see?

Changing OS to Linux-GTK.
Comment 2 Grant Gayed CLA 2004-01-07 10:51:46 EST
Created attachment 7341 [details]
working (I think) on gtk 2.2.1
Comment 3 Grant Gayed CLA 2004-01-12 11:22:56 EST
FH please try this with gtk 2.2.4.
Comment 4 Felipe Heidrich CLA 2004-01-12 12:44:13 EST
Well, if I understood the problem, Grant's screenshot shows the bug!
In the screenshot, the background of the middle row should be dark blue (or
whatever the highlight color is) instead of green. Am I right ?

Comment 5 Felipe Heidrich CLA 2004-01-12 12:48:34 EST
Another test case.
Run the code below, select the Row 0 and then click on the button, note that row
0 preserves the selection background. Repeat the process selecting Row 1, note
that when you select the button Row 1 changes the background back to green
instead of preserving the selection color.

public static void main (String[] args) {
	Display display = new Display();
	Shell shell = new Shell(display);
	Table table = new Table(shell, SWT.BORDER | SWT.MULTI);
	for (int i = 0; i < 3; i++) {
		TableItem item = new TableItem(table, SWT.NONE);
		item.setText("Row " + i);
	}
	table.getItem(1).setBackground(display.getSystemColor(SWT.COLOR_GREEN));
	table.setBounds(10, 10, 350, 200);
	Button button = new Button (shell, SWT.PUSH);
	button.setText("Here");
	button.setBounds(10, 220, 60, 30);
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
Comment 6 Miroslav Halas CLA 2004-01-23 15:51:14 EST
Yes you are correct. Also after setting it to green set it back to 
SWT.COLOR_LIST_BACKGROUND. It will not show with selected color when selected 
again. I am doing it on Fedora Core 1.
Comment 7 Felipe Heidrich CLA 2004-02-13 11:56:58 EST
*** Bug 51584 has been marked as a duplicate of this bug. ***
Comment 8 Felipe Heidrich CLA 2004-10-04 12:35:41 EDT
*** Bug 74769 has been marked as a duplicate of this bug. ***
Comment 9 Felipe Heidrich CLA 2004-10-04 12:37:13 EDT
Bug#30994 is probably the same problem.
Comment 10 Billy Biggs CLA 2004-10-05 16:39:47 EDT
The patch here fixes the problem for me:

http://bugzilla.gnome.org/show_bug.cgi?id=154611
Comment 11 Billy Biggs CLA 2004-10-05 17:57:22 EDT
I think bug 30994 is a different problem.
Comment 12 Darin Swanson CLA 2004-12-16 13:10:37 EST
*** Bug 81430 has been marked as a duplicate of this bug. ***
Comment 13 Billy Biggs CLA 2005-02-12 11:51:20 EST
The patch was included upstream and I verified that this problem no longer
occurs on GTK+ 2.6.0 and higher.  Maybe we should just disable setting the
background colour at all on older versions?
Comment 14 Steve Northover CLA 2005-02-14 11:36:14 EST
I thought we had already done this.
Comment 15 Darin Swanson CLA 2005-03-08 21:36:19 EST
*** Bug 87450 has been marked as a duplicate of this bug. ***
Comment 16 Steve Northover CLA 2006-05-31 16:21:49 EDT
Bug is in GTK and fixed in later versions.  We WONTFIX this.