001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Dmitry A. Durnev
019: * @version $Revision$
020: */package org.apache.harmony.awt.wtk.windows;
021:
022: import java.awt.Dimension;
023: import java.awt.Image;
024:
025: import org.apache.harmony.awt.nativebridge.windows.Win32;
026: import org.apache.harmony.awt.wtk.CursorFactory;
027: import org.apache.harmony.awt.wtk.NativeCursor;
028:
029: import org.apache.harmony.awt.nativebridge.windows.WindowsDefs;
030:
031: /**
032: * Implementation of CursorFactory for Windows platform.
033: */
034: public class WinCursorFactory extends CursorFactory {
035:
036: static final Win32 win32 = Win32.getInstance();
037:
038: final WinEventQueue eventQueue;
039:
040: /**
041: * Java to native type translation table:
042: * native id for LoadCursor(commented native id for LoadImage(from winuser.h)),
043: * commented Java cursor type
044: */
045: static final long[] predefined = {
046: WindowsDefs.IDC_ARROW/*OCR_NORMAL*/, /*DEFAULT_CURSOR*/
047: WindowsDefs.IDC_CROSS/*OCR_CROSS*/, /*CROSSHAIR_CURSOR*/
048: WindowsDefs.IDC_IBEAM/*OCR_IBEAM*/, /*TEXT_CURSOR*/
049: WindowsDefs.IDC_WAIT /*OCR_WAIT*/, /*WAIT_CURSOR*/
050: WindowsDefs.IDC_SIZENESW/*OCR_SIZENESW*/, /*SW_RESIZE_CURSOR*/
051: WindowsDefs.IDC_SIZENWSE/*OCR_SIZENWSE*/, /*SE_RESIZE_CURSOR*/
052: WindowsDefs.IDC_SIZENWSE/*OCR_SIZENWSE*/, /*NW_RESIZE_CURSOR*/
053: WindowsDefs.IDC_SIZENESW/*OCR_SIZENESW*/, /*NE_RESIZE_CURSOR*/
054: WindowsDefs.IDC_SIZENS/*OCR_SIZENS*/, /*N_RESIZE_CURSOR*/
055: WindowsDefs.IDC_SIZENS/*OCR_SIZENS*/, /*S_RESIZE_CURSOR*/
056: WindowsDefs.IDC_SIZEWE/*OCR_SIZEWE*/, /*W_RESIZE_CURSOR*/
057: WindowsDefs.IDC_SIZEWE/*OCR_SIZEWE*/, /*E_RESIZE_CURSOR*/
058: WindowsDefs.IDC_HAND/*OCR_HAND*/, /*HAND_CURSOR*/
059: WindowsDefs.IDC_SIZEALL/*OCR_SIZEALL*/, /*MOVE_CURSOR*/
060:
061: };
062:
063: WinCursorFactory(WinEventQueue eventQueue) {
064: this .eventQueue = eventQueue;
065: }
066:
067: /**
068: * @see org.apache.harmony.awt.wtk.CursorFactory#createCursor(int)
069: */
070: @Override
071: public NativeCursor createCursor(int type) {
072: if (type >= 0 && type < predefined.length) {
073: long hCursor = win32.LoadCursorW(0l, predefined[type]);
074: return new WinCursor(eventQueue, hCursor);
075: }
076: return null;
077: }
078:
079: /**
080: * @see org.apache.harmony.awt.wtk.CursorFactory#createCustomCursor(java.awt.Image, int, int)
081: */
082: @Override
083: public NativeCursor createCustomCursor(Image img, int xHotSpot,
084: int yHotSpot) {
085: long hCursor = WinIcons.createIcon(false, img, xHotSpot,
086: yHotSpot);
087: return new WinCursor(eventQueue, hCursor, false);
088: }
089:
090: /**
091: * @see org.apache.harmony.awt.wtk.CursorFactory#getBestCursorSize(int, int)
092: */
093: @Override
094: public Dimension getBestCursorSize(int prefWidth, int prefHeight) {
095: return new Dimension(win32
096: .GetSystemMetrics(WindowsDefs.SM_CXCURSOR), win32
097: .GetSystemMetrics(WindowsDefs.SM_CYCURSOR));
098: }
099:
100: /**
101: * @see org.apache.harmony.awt.wtk.CursorFactory#getMaximumCursorColors()
102: */
103: @Override
104: public int getMaximumCursorColors() {
105: long screenDC = win32.GetDC(0);
106: int nColors = win32.GetDeviceCaps(screenDC,
107: WindowsDefs.NUMCOLORS);
108: if (nColors < 0) {
109: //if device has more than 256 colors:
110: final int COLORS_PER_PLANE = 256;
111: int nPlanes = win32.GetDeviceCaps(screenDC,
112: WindowsDefs.PLANES);
113: nColors = COLORS_PER_PLANE * nPlanes;
114: }
115: win32.ReleaseDC(0, screenDC);
116: return nColors;
117: }
118: }
|