How to get the skin of an SWT widget?
I want to create an SWT Scale widget with two/multiple thumbs. The problem is that I want it to have the native skin on each platform and not a custom made skin.
Practically, I want to get the skin of every component of the widget and draw them myself.
Any ideas how to do that, or开发者_运维知识库 maybe an alternate solution?
Thanks!
SWT widgets don't have skins (as Swing widgets do), they are drawn by the native windowing toolkit (Win32, Gtk+, etc.).
Have a look on Riena Look and Feel: http://wiki.eclipse.org/Riena_Look_and_Feel
While Peter's answer is correct, you could try to take screenshots of Scale
with thumbs in different positions and overlay them. See http://tom-eclipse-dev.blogspot.com/2007/01/tableviewers-and-nativelooking.html for an example of this technique.
On Windows, before SWT implements API for drawing controls: first check if application is themed, and then use one or the other drawing API:
public void paintTheme(GC gc, Shell shell, Rectangle bounds)
RECT rect = new RECT();
rect.left = bounds.x;
rect.right = bounds.x + bounds.width;
rect.top = bounds.y;
rect.bottom = bounds.y + bounds.height;
if (OS.IsAppThemed()) {
int theme = OS.OpenThemeData(shell.handle, className);
OS.DrawThemeBackground(theme, gc.handle, partId, stateId, rect, null);
OS.CloseThemeData(theme);
} else {
OS.DrawFrameControl(gc.handle, rect, uType, uState);
}
}
You can find class names and part and state ids at http://msdn.microsoft.com/en-us/library/windows/desktop/bb773210%28v=vs.85%29.aspx and types and states for non-themed API at http://msdn.microsoft.com/en-us/library/dd162480%28v=vs.85%29.aspx
Please note that not all controls have non-themed type. I believe that the thumb for the scale should be a button in non themed applications.
Because the links above do not give you the values for the part, states and type values, I suggest getting them from the header files winuser.h and vsstyle.h.
Edit: for scale, in not themed applications I believe you have to use button for thumb. Also, I forgot to mention that this uses non documented API, and it is not portable.
精彩评论