OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [gnu/] [java/] [awt/] [peer/] [gtk/] [GtkFramePeer.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* GtkFramePeer.java -- Implements FramePeer with GTK
2
   Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
 
39
package gnu.java.awt.peer.gtk;
40
 
41
import java.awt.Frame;
42
import java.awt.Graphics;
43
import java.awt.Image;
44
import java.awt.MenuBar;
45
import java.awt.Rectangle;
46
import java.awt.Window;
47
import java.awt.event.ComponentEvent;
48
import java.awt.event.PaintEvent;
49
import java.awt.image.ColorModel;
50
import java.awt.peer.FramePeer;
51
import java.awt.peer.MenuBarPeer;
52
 
53
public class GtkFramePeer extends GtkWindowPeer
54
    implements FramePeer
55
{
56
  private int menuBarHeight;
57
  private MenuBarPeer menuBar;
58
  native int getMenuBarHeight (MenuBarPeer bar);
59
  native void setMenuBarWidthUnlocked (MenuBarPeer bar, int width);
60
  native void setMenuBarWidth (MenuBarPeer bar, int width);
61
  native void setMenuBarPeer (MenuBarPeer bar);
62
  native void removeMenuBarPeer ();
63
  native void gtkFixedSetVisible (boolean visible);
64
 
65
  int getMenuBarHeight ()
66
  {
67
    return menuBar == null ? 0 : getMenuBarHeight (menuBar);
68
  }
69
 
70
  public void setMenuBar (MenuBar bar)
71
  {
72
    if (bar == null && menuBar != null)
73
      {
74
        // We're removing the menubar.
75
        gtkFixedSetVisible (false);
76
        menuBar = null;
77
        removeMenuBarPeer ();
78
        insets.top -= menuBarHeight;
79
        menuBarHeight = 0;
80
        awtComponent.validate ();
81
        gtkFixedSetVisible (true);
82
      }
83
    else if (bar != null && menuBar == null)
84
      {
85
        // We're adding a menubar where there was no menubar before.
86
        gtkFixedSetVisible (false);
87
        menuBar = (MenuBarPeer) ((MenuBar) bar).getPeer();
88
        setMenuBarPeer (menuBar);
89
        int menuBarWidth =
90
          awtComponent.getWidth () - insets.left - insets.right;
91
        if (menuBarWidth > 0)
92
          setMenuBarWidth (menuBar, menuBarWidth);
93
        menuBarHeight = getMenuBarHeight ();
94
        insets.top += menuBarHeight;
95
        awtComponent.validate ();
96
        gtkFixedSetVisible (true);
97
      }
98
    else if (bar != null && menuBar != null)
99
      {
100
        // We're swapping the menubar.
101
        gtkFixedSetVisible (false);
102
        removeMenuBarPeer();
103
        int oldHeight = menuBarHeight;
104
        int menuBarWidth =
105
          awtComponent.getWidth () - insets.left - insets.right;
106
        menuBar = (MenuBarPeer) ((MenuBar) bar).getPeer ();
107
        setMenuBarPeer (menuBar);
108
        if (menuBarWidth > 0)
109
          setMenuBarWidth (menuBar, menuBarWidth);
110
        menuBarHeight = getMenuBarHeight ();
111
        if (oldHeight != menuBarHeight)
112
          {
113
            insets.top += (menuBarHeight - oldHeight);
114
            awtComponent.validate ();
115
          }
116
        gtkFixedSetVisible (true);
117
      }
118
  }
119
 
120
  public void setBounds (int x, int y, int width, int height)
121
  {
122
    // prevent window_configure_cb -> awtComponent.setSize ->
123
    // peer.setBounds -> nativeSetBounds self-deadlock on GDK lock.
124
    if (Thread.currentThread() == GtkToolkit.mainThread)
125
      {
126
        int menuBarWidth = width - insets.left - insets.right;
127
        if (menuBar != null && menuBarWidth > 0)
128
          setMenuBarWidthUnlocked (menuBar, menuBarWidth);
129
 
130
        return;
131
      }
132
 
133
    int menuBarWidth = width - insets.left - insets.right;
134
    if (menuBar != null && menuBarWidth > 0)
135
      setMenuBarWidth (menuBar, menuBarWidth);
136
 
137
    nativeSetBounds (x, y,
138
                     width - insets.left - insets.right,
139
                     height - insets.top - insets.bottom
140
                     + menuBarHeight);
141
  }
142
 
143
  public void setResizable (boolean resizable)
144
  {
145
    // Call setSize; otherwise when resizable is changed from true to
146
    // false the frame will shrink to the dimensions it had before it
147
    // was resizable.
148
    setSize (awtComponent.getWidth() - insets.left - insets.right,
149
             awtComponent.getHeight() - insets.top - insets.bottom
150
             + menuBarHeight);
151
    gtkWindowSetResizable (resizable);
152
  }
153
 
154
  protected void postInsetsChangedEvent (int top, int left,
155
                                         int bottom, int right)
156
  {
157
    insets.top = top + menuBarHeight;
158
    insets.left = left;
159
    insets.bottom = bottom;
160
    insets.right = right;
161
  }
162
 
163
  public GtkFramePeer (Frame frame)
164
  {
165
    super (frame);
166
  }
167
 
168
  void create ()
169
  {
170
    // Create a normal decorated window.
171
    create (GDK_WINDOW_TYPE_HINT_NORMAL,
172
            !((Frame) awtComponent).isUndecorated ());
173
 
174
    Frame frame = (Frame) awtComponent;
175
 
176
    setMenuBar (frame.getMenuBar ());
177
 
178
    setTitle (frame.getTitle ());
179
    gtkWindowSetResizable (frame.isResizable ());
180
    setIconImage(frame.getIconImage());
181
  }
182
 
183
  native void nativeSetIconImage (GtkImage image);
184
 
185
  public void setIconImage (Image image)
186
  {
187
      if (image != null)
188
        {
189
          if (image instanceof GtkImage)
190
            nativeSetIconImage((GtkImage) image);
191
          else
192
            nativeSetIconImage(new GtkImage(image.getSource()));
193
        }
194
  }
195
 
196
  public Graphics getGraphics ()
197
  {
198
    Graphics g;
199
    if (GtkToolkit.useGraphics2D ())
200
      g = new GdkGraphics2D (this);
201
    else
202
      g = new GdkGraphics (this);
203
    g.translate (-insets.left, -insets.top);
204
    return g;
205
  }
206
 
207
  protected void postConfigureEvent (int x, int y, int width, int height)
208
  {
209
    int frame_width = width + insets.left + insets.right;
210
    // Since insets.top already includes the MenuBar's height, we need
211
    // to subtract the MenuBar's height from the top inset.
212
    int frame_height = height + insets.top + insets.bottom - menuBarHeight;
213
 
214
    if (frame_width != awtComponent.getWidth()
215
        || frame_height != awtComponent.getHeight())
216
      awtComponent.setSize(frame_width, frame_height);
217
 
218
    int frame_x = x - insets.left;
219
    // Likewise, since insets.top includes the MenuBar height, we need
220
    // to add back the MenuBar height to the frame's y position.  If
221
    // no MenuBar exists in this frame, the MenuBar height will be 0.
222
    int frame_y = y - insets.top + menuBarHeight;
223
 
224
    if (frame_x != awtComponent.getX()
225
        || frame_y != awtComponent.getY())
226
      {
227
        // awtComponent.setLocation(frame_x, frame_y);
228
      }
229
  }
230
 
231
  protected void postMouseEvent(int id, long when, int mods, int x, int y,
232
                                int clickCount, boolean popupTrigger)
233
  {
234
    super.postMouseEvent (id, when, mods,
235
                          x + insets.left, y + insets.top,
236
                          clickCount, popupTrigger);
237
  }
238
 
239
  protected void postExposeEvent (int x, int y, int width, int height)
240
  {
241
    if (!isInRepaint)
242
      q().postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT,
243
                                   new Rectangle (x + insets.left,
244
                                                  y + insets.top,
245
                                                  width, height)));
246
  }
247
 
248
  public int getState ()
249
  {
250
    return 0;
251
  }
252
 
253
  public void setState (int state)
254
  {
255
 
256
  }
257
 
258
  public void setMaximizedBounds (Rectangle r)
259
  {
260
 
261
  }
262
  public void setBoundsPrivate(int x, int y, int width, int height)
263
  {
264
    // TODO Auto-generated method stub
265
 
266
  }
267
  public void updateAlwaysOnTop()
268
  {
269
    // TODO Auto-generated method stub
270
 
271
  }
272
  public boolean requestWindowFocus()
273
  {
274
    // TODO Auto-generated method stub
275
    return false;
276
  }
277
}
278
 
279
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.