001: /*
002: * @(#)QtFramePeer.java 1.26 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027: package sun.awt.qt;
028:
029: import sun.awt.peer.FramePeer;
030: import java.awt.*;
031: import java.awt.event.*;
032: import java.awt.Image.*;
033:
034: /**
035: * QtFramePeer.java
036: *
037: * @author Nicholas Allen
038: */
039:
040: class QtFramePeer extends QtWindowPeer implements FramePeer {
041: private static native void initIDs();
042:
043: public native void setState(int state);
044:
045: public native int getState();
046:
047: static {
048: initIDs();
049: }
050:
051: QtFramePeer(QtToolkit toolkit, Frame target) {
052: super (toolkit, target);
053: setTitle(target.getTitle());
054: setResizable(target.isResizable());
055: }
056:
057: protected native void create(QtComponentPeer parentPeer,
058: boolean isUndecorated);
059:
060: protected void create(QtComponentPeer parentPeer) {
061: create(parentPeer, ((Frame) target).isUndecorated());
062: }
063:
064: protected native void setTitleNative(String title);
065:
066: public void setTitle(String title) {
067: if (title != null)
068: setTitleNative(title);
069: }
070:
071: public void setIconImage(Image im) {
072: }
073:
074: public void setMenuBar(MenuBar mb) {
075: QtMenuBarPeer peer = (QtMenuBarPeer) toolkit
076: .getMenuComponentPeer(mb);
077: setMenuBarNative(peer);
078: }
079:
080: private native void setMenuBarNative(QtMenuBarPeer peer);
081:
082: /**
083: * Called to inform the Frame that it has moved.
084: */
085: private void handleMoved() {
086: toolkit.postEvent(new ComponentEvent(target,
087: ComponentEvent.COMPONENT_MOVED));
088: }
089:
090: /** Calculates the insets using any values appropriate (such as borders). */
091: Insets calculateInsets() {
092: return new Insets(topBorder + menuBarHeight, leftBorder,
093: bottomBorder, rightBorder);
094: }
095:
096: /**
097: * Allows callback from the Qt native layer to update the menu bar height
098: * as well as the insets.
099: */
100: private void updateMenuBarHeight(int h) {
101: menuBarHeightDelta = h - menuBarHeight;
102: menuBarHeight = h;
103: setInsets(calculateInsets(), true);
104: }
105:
106: // 6182409: Window.pack does not work correctly.
107: // FramePeer has this notion of menu bar.
108: protected int getHeightDelta() {
109: return super .getHeightDelta() + menuBarHeightDelta;
110: }
111:
112: // 6182409: Window.pack does not work correctly.
113: // FramePeer has this notion of menu bar.
114: protected void resetInsetsDeltas() {
115: super .resetInsetsDeltas();
116: menuBarHeightDelta = 0;
117: }
118:
119: private int menuBarHeight = 0;
120: private int menuBarHeightDelta = 0;
121: }
|