Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 162052 Details for
Bug 305864
[GTK] getItemHeight method of org.eclipse.swt.widgets.List returns a wrong Item height
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
snippet
ListItemSnippet.java (text/x-java), 3.00 KB, created by
Michael Seele
on 2010-03-15 11:17:22 EDT
(
hide
)
Description:
snippet
Filename:
MIME Type:
Creator:
Michael Seele
Created:
2010-03-15 11:17:22 EDT
Size:
3.00 KB
patch
obsolete
>package org.eclipse.swt.widgets; > >import org.eclipse.swt.SWT; >import org.eclipse.swt.graphics.Rectangle; >import org.eclipse.swt.internal.gtk.GdkRectangle; >import org.eclipse.swt.internal.gtk.OS; >import org.eclipse.swt.layout.FillLayout; > >public class ListItemSnippet { > > public static void main(String[] args) { > final Display display = new Display(); > final Shell shell = new Shell(display); > shell.setText("ListItemSnippet"); //$NON-NLS-1$ > shell.setLayout(new FillLayout()); > > final List list = new List(shell, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL); > > // list.setFont(new Font(display, "Arial", 10, SWT.NONE)); > > list.setData("name", "list"); //$NON-NLS-1$ //$NON-NLS-2$ > for (int i = 0; i < 100; i++) { > list.add("Item " + i); //$NON-NLS-1$ > } > shell.setBounds(100, 100, 150, 200); > shell.open(); > > new Thread() { > @Override > public void run() { > try { > Thread.sleep(1000); > } catch (InterruptedException e) { > e.printStackTrace(); > } > display.syncExec(new Runnable() { > public void run() { > for (int i = 0; i <= 6; i++) { > Rectangle realBounds = getRealBounds(list, i); > Rectangle realBoundsDisplay = list.getDisplay().map(list, null, realBounds); > System.err.println(i + ": " + getBounds(list, i) + " " + realBoundsDisplay + " >> " + realBounds); > } > } > }); > } > }.start(); > > while (!shell.isDisposed()) { > if (!display.readAndDispatch()) > display.sleep(); > } > display.dispose(); > } > > private static Rectangle getBounds(List list, int index) { > Rectangle listBounds = list.getClientArea(); > int itemHeight = list.getItemHeight(); > int y = 0; > ScrollBar verticalBar = list.getVerticalBar(); > if (verticalBar != null) { > double maxHeight = list.getItemCount() * itemHeight; > double scrollBarHeight = verticalBar.getMaximum() - verticalBar.getMinimum(); > double yOffset = (maxHeight * verticalBar.getSelection()) / scrollBarHeight; > y = (int) ((index * itemHeight) - yOffset); > } else { > int difference = index - list.getTopIndex(); > y = listBounds.y + (difference * itemHeight); > } > Rectangle rect = new Rectangle(listBounds.x, listBounds.y + y, listBounds.width, itemHeight); > return list.getDisplay().map(list.getParent(), null, rect); > } > > private static Rectangle getRealBounds(List list, int index) { > int /*long*/parentHandle = list.handle; > int /*long*/column = OS.gtk_tree_view_get_column(parentHandle, 0); > int /*long*/iter = OS.g_malloc(OS.GtkTreeIter_sizeof()); > OS.gtk_tree_model_get_iter_first(list.modelHandle, iter); > for (int i = 0; i < index; i++) { > OS.gtk_tree_model_iter_next(list.modelHandle, iter); > } > int /*long*/path = OS.gtk_tree_model_get_path(list.modelHandle, iter); > OS.gtk_widget_realize(parentHandle); > GdkRectangle rect = new GdkRectangle(); > OS.gtk_tree_view_get_cell_area(parentHandle, path, column, rect); > OS.gtk_tree_path_free(path); > OS.g_free(iter); > int width = OS.gtk_tree_view_column_get_visible(column) ? rect.width + 1 : 0; > return new Rectangle(rect.x, rect.y, width, rect.height + 1); > } > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 305864
:
162051
| 162052