001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.swt.internal.theme;
011:
012: import org.eclipse.swt.*;
013: import org.eclipse.swt.graphics.*;
014:
015: public class Theme {
016:
017: Device device;
018:
019: public Theme(Device device) {
020: this .device = device;
021: }
022:
023: public Rectangle computeTrim(GC gc, DrawData data) {
024: checkTheme();
025: if (gc == null)
026: SWT.error(SWT.ERROR_NULL_ARGUMENT);
027: if (data == null)
028: SWT.error(SWT.ERROR_NULL_ARGUMENT);
029: if (gc.isDisposed())
030: SWT.error(SWT.ERROR_INVALID_ARGUMENT);
031: return data.computeTrim(this , gc);
032: }
033:
034: void checkTheme() {
035: if (isDisposed())
036: SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
037: }
038:
039: public void dispose() {
040: device = null;
041: }
042:
043: public void drawBackground(GC gc, Rectangle bounds, DrawData data) {
044: checkTheme();
045: if (gc == null)
046: SWT.error(SWT.ERROR_NULL_ARGUMENT);
047: if (bounds == null)
048: SWT.error(SWT.ERROR_NULL_ARGUMENT);
049: if (data == null)
050: SWT.error(SWT.ERROR_NULL_ARGUMENT);
051: if (gc.isDisposed())
052: SWT.error(SWT.ERROR_INVALID_ARGUMENT);
053: data.draw(this , gc, bounds);
054: }
055:
056: public void drawFocus(GC gc, Rectangle bounds, DrawData data) {
057: checkTheme();
058: if (gc == null)
059: SWT.error(SWT.ERROR_NULL_ARGUMENT);
060: if (bounds == null)
061: SWT.error(SWT.ERROR_NULL_ARGUMENT);
062: if (data == null)
063: SWT.error(SWT.ERROR_NULL_ARGUMENT);
064: if (gc.isDisposed())
065: SWT.error(SWT.ERROR_INVALID_ARGUMENT);
066: gc.drawFocus(bounds.x, bounds.y, bounds.width, bounds.height);
067: }
068:
069: public void drawImage(GC gc, Rectangle bounds, DrawData data,
070: Image image, int flags) {
071: checkTheme();
072: if (gc == null)
073: SWT.error(SWT.ERROR_NULL_ARGUMENT);
074: if (bounds == null)
075: SWT.error(SWT.ERROR_NULL_ARGUMENT);
076: if (data == null)
077: SWT.error(SWT.ERROR_NULL_ARGUMENT);
078: if (image == null)
079: SWT.error(SWT.ERROR_NULL_ARGUMENT);
080: if (gc.isDisposed())
081: SWT.error(SWT.ERROR_INVALID_ARGUMENT);
082: data.drawImage(this , image, gc, bounds);
083: }
084:
085: public void drawText(GC gc, Rectangle bounds, DrawData data,
086: String text, int flags) {
087: checkTheme();
088: if (gc == null)
089: SWT.error(SWT.ERROR_NULL_ARGUMENT);
090: if (bounds == null)
091: SWT.error(SWT.ERROR_NULL_ARGUMENT);
092: if (data == null)
093: SWT.error(SWT.ERROR_NULL_ARGUMENT);
094: if (text == null)
095: SWT.error(SWT.ERROR_NULL_ARGUMENT);
096: if (gc.isDisposed())
097: SWT.error(SWT.ERROR_INVALID_ARGUMENT);
098: data.drawText(this , text, flags, gc, bounds);
099: }
100:
101: public Rectangle getBounds(int part, Rectangle bounds, DrawData data) {
102: checkTheme();
103: if (bounds == null)
104: SWT.error(SWT.ERROR_NULL_ARGUMENT);
105: if (data == null)
106: SWT.error(SWT.ERROR_NULL_ARGUMENT);
107: return data.getBounds(part, bounds);
108: }
109:
110: public int getSelection(Point offset, Rectangle bounds,
111: RangeDrawData data) {
112: checkTheme();
113: if (offset == null)
114: SWT.error(SWT.ERROR_NULL_ARGUMENT);
115: if (bounds == null)
116: SWT.error(SWT.ERROR_NULL_ARGUMENT);
117: if (data == null)
118: SWT.error(SWT.ERROR_NULL_ARGUMENT);
119: return data.getSelection(offset, bounds);
120: }
121:
122: public int hitBackground(Point position, Rectangle bounds,
123: DrawData data) {
124: checkTheme();
125: if (position == null)
126: SWT.error(SWT.ERROR_NULL_ARGUMENT);
127: if (bounds == null)
128: SWT.error(SWT.ERROR_NULL_ARGUMENT);
129: if (data == null)
130: SWT.error(SWT.ERROR_NULL_ARGUMENT);
131: return data.hit(this , position, bounds);
132: }
133:
134: public boolean isDisposed() {
135: return device == null;
136: }
137:
138: public Rectangle measureText(GC gc, Rectangle bounds,
139: DrawData data, String text, int flags) {
140: checkTheme();
141: if (gc == null)
142: SWT.error(SWT.ERROR_NULL_ARGUMENT);
143: if (data == null)
144: SWT.error(SWT.ERROR_NULL_ARGUMENT);
145: if (text == null)
146: SWT.error(SWT.ERROR_NULL_ARGUMENT);
147: if (gc.isDisposed())
148: SWT.error(SWT.ERROR_INVALID_ARGUMENT);
149: return data.measureText(this, text, flags, gc, bounds);
150: }
151: }
|