Bug 332887 SWT Snippets use incorrect positioning
Quoting from Steve Northover's SWT book, section 4.2: "Very often, the location of the client area within the control is (0, 0), but this is not always the case. Figure 4.3 shows the client area of two group boxes from different platforms, with Windows on the left and GTK on the right. On Windows, the location of the client area is (3, 13). On GTK, it is (0, 0)". Therefore, portable SWT code should never position widgets relative to (0, 0) but relative to the parent's client area. While on most platforms, the assumption is true, it is not in Eclipse RAP. Unfortunately, a couple of the official SWT snippets show this bad practice, which causes incorrect layouting in RAP. An example is Snippet40: Shell shell = new Shell (display); Composite c1 = new Composite (shell, SWT.BORDER); c1.setSize (100, 100); Composite c2 = new Composite (shell, SWT.BORDER); c2.setBounds (100, 0, 100, 100); To be fully portable, this code should be rewritten to: Shell shell = new Shell (display); Rectangle clientArea = shell.getClientArea(); Composite c1 = new Composite (shell, SWT.BORDER); c1.setBounds (clientArea.x, clientArea.y, 100, 100); Composite c2 = new Composite (shell, SWT.BORDER); c2.setBounds (clientArea.x + 100, clientArea.y, 100, 100);
examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet40.java
/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.snippets;
 
/*
 * Menu example snippet: create a popup menu (set in multiple controls)
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 */
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
public class Snippet40 {