KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > internal > theme > GroupDrawData


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.swt.internal.theme;
12
13 import org.eclipse.swt.graphics.*;
14 import org.eclipse.swt.internal.win32.*;
15
16 public class GroupDrawData extends DrawData {
17     public int headerWidth;
18     public int headerHeight;
19     public Rectangle headerArea;
20     
21 public GroupDrawData() {
22     state = new int[1];
23 }
24
25 static final int GROUP_HEADER_X = 9;
26 static final int GROUP_HEADER_PAD = 2;
27 void draw(Theme theme, GC gc, Rectangle bounds) {
28     if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
29         int hTheme = OS.OpenThemeData(0, getClassId());
30         RECT rect = new RECT ();
31         rect.left = bounds.x;
32         rect.right = bounds.x + bounds.width;
33         rect.top = bounds.y + this.headerHeight / 2;
34         rect.bottom = bounds.y + bounds.height;
35         int headerX = bounds.x + GROUP_HEADER_X, headerY = bounds.y;
36         int savedDC = OS.SaveDC(gc.handle);
37         OS.ExcludeClipRect (gc.handle, headerX - GROUP_HEADER_PAD, headerY, headerX + this.headerWidth + GROUP_HEADER_PAD, headerY + this.headerHeight);
38         int[] part = getPartId(DrawData.WIDGET_WHOLE);
39         OS.DrawThemeBackground(hTheme, gc.handle, part[0], part[1], rect, null);
40         OS.RestoreDC(gc.handle, savedDC);
41         Rectangle headerArea = this.headerArea;
42         if (headerArea != null) {
43             headerArea.x = headerX;
44             headerArea.y = headerY;
45             headerArea.width = this.headerWidth;
46             headerArea.height = this.headerHeight;
47         }
48         Rectangle clientArea = this.clientArea;
49         if (clientArea != null) {
50             RECT contentRect = new RECT();
51             OS.GetThemeBackgroundContentRect(hTheme, gc.handle, part[0], part[1], rect, contentRect);
52             clientArea.x = contentRect.left;
53             clientArea.y = contentRect.top;
54             clientArea.width = contentRect.right - contentRect.left;
55             clientArea.height = contentRect.bottom - contentRect.top;
56         }
57         OS.CloseThemeData(hTheme);
58     }
59 }
60
61 int[] getPartId(int part) {
62     int state = this.state[part];
63     int iPartId = OS.BP_GROUPBOX, iStateId = OS.GBS_NORMAL;
64     if ((state & DrawData.DISABLED) != 0) iStateId = OS.GBS_DISABLED;
65     return new int[]{iPartId, iStateId};
66 }
67
68 int hit(Theme theme, Point position, Rectangle bounds) {
69     return bounds.contains(position) ? DrawData.WIDGET_WHOLE : DrawData.WIDGET_NOWHERE;
70 }
71
72 }
73
Popular Tags