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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [gnu/] [java/] [awt/] [peer/] [gtk/] [GtkFramePeer.java] - Blame information for rev 769

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 769 jeremybenn
/* GtkFramePeer.java -- Implements FramePeer with GTK
2
   Copyright (C) 1999, 2002, 2004, 2006, 2007 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.Image;
43
import java.awt.MenuBar;
44
import java.awt.Rectangle;
45
import java.awt.peer.FramePeer;
46
import java.awt.peer.MenuBarPeer;
47
 
48
public class GtkFramePeer extends GtkWindowPeer
49
    implements FramePeer
50
{
51
  private int menuBarHeight;
52
  private MenuBarPeer menuBar;
53
  native int getMenuBarHeight (MenuBarPeer bar);
54
  native void setMenuBarWidthUnlocked (MenuBarPeer bar, int width);
55
  native void setMenuBarWidth (MenuBarPeer bar, int width);
56
  native void setMenuBarPeer (MenuBarPeer bar);
57
  native void removeMenuBarPeer ();
58
  native void gtkFixedSetVisible (boolean visible);
59
 
60
  private native void maximize();
61
  private native void unmaximize();
62
  private native void iconify();
63
  private native void deiconify();
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
        // if component has already been validated, we need to revalidate.
81
        // otherwise, it will be validated when it is shown.
82
        if (awtComponent.isValid())
83
          awtComponent.validate ();
84
        gtkFixedSetVisible (true);
85
      }
86
    else if (bar != null && menuBar == null)
87
      {
88
        // We're adding a menubar where there was no menubar before.
89
        gtkFixedSetVisible (false);
90
        menuBar = (MenuBarPeer) bar.getPeer();
91
        setMenuBarPeer (menuBar);
92
        int menuBarWidth =
93
          awtComponent.getWidth () - insets.left - insets.right;
94
        if (menuBarWidth > 0)
95
          setMenuBarWidth (menuBar, menuBarWidth);
96
        menuBarHeight = getMenuBarHeight ();
97
        insets.top += menuBarHeight;
98
        // if component has already been validated, we need to revalidate.
99
        // otherwise, it will be validated when it is shown.
100
        if (awtComponent.isValid())
101
          awtComponent.validate ();
102
        gtkFixedSetVisible (true);
103
      }
104
    else if (bar != null && menuBar != null)
105
      {
106
        // We're swapping the menubar.
107
        gtkFixedSetVisible (false);
108
        removeMenuBarPeer();
109
        int oldHeight = menuBarHeight;
110
        int menuBarWidth =
111
          awtComponent.getWidth () - insets.left - insets.right;
112
        menuBar = (MenuBarPeer) bar.getPeer ();
113
        setMenuBarPeer (menuBar);
114
        if (menuBarWidth > 0)
115
          setMenuBarWidth (menuBar, menuBarWidth);
116
        menuBarHeight = getMenuBarHeight ();
117
        if (oldHeight != menuBarHeight)
118
          {
119
            insets.top += (menuBarHeight - oldHeight);
120
            awtComponent.validate ();
121
          }
122
        gtkFixedSetVisible (true);
123
      }
124
  }
125
 
126
  public void setBounds (int x, int y, int width, int height)
127
  {
128
    int menuBarWidth = width - insets.left - insets.right;
129
    if (menuBar != null && menuBarWidth > 0)
130
      setMenuBarWidth (menuBar, menuBarWidth);
131
 
132
    super.setBounds(x, y, width, height + menuBarHeight);
133
  }
134
 
135
  public void setResizable (boolean resizable)
136
  {
137
    // Call setSize; otherwise when resizable is changed from true to
138
    // false the frame will shrink to the dimensions it had before it
139
    // was resizable.
140
    setSize (awtComponent.getWidth() - insets.left - insets.right,
141
             awtComponent.getHeight() - insets.top - insets.bottom
142
             + menuBarHeight);
143
    gtkWindowSetResizable (resizable);
144
  }
145
 
146
  protected void postInsetsChangedEvent (int top, int left,
147
                                         int bottom, int right)
148
  {
149
    insets.top = top + menuBarHeight;
150
    insets.left = left;
151
    insets.bottom = bottom;
152
    insets.right = right;
153
  }
154
 
155
  public GtkFramePeer (Frame frame)
156
  {
157
    super (frame);
158
  }
159
 
160
  void create ()
161
  {
162
    // Create a normal decorated window.
163
    create (GDK_WINDOW_TYPE_HINT_NORMAL,
164
            !((Frame) awtComponent).isUndecorated ());
165
 
166
    Frame frame = (Frame) awtComponent;
167
 
168
    setMenuBar (frame.getMenuBar ());
169
 
170
    setTitle (frame.getTitle ());
171
    gtkWindowSetResizable (frame.isResizable ());
172
    setIconImage(frame.getIconImage());
173
  }
174
 
175
  native void nativeSetIconImage (GtkImage image);
176
 
177
  public void setIconImage (Image image)
178
  {
179
    if (image != null)
180
      {
181
        GtkImage gtkImage;
182
        if (image instanceof GtkImage)
183
          gtkImage = (GtkImage) image;
184
        else
185
          gtkImage = new GtkImage(image.getSource());
186
 
187
        if (gtkImage.isLoaded && ! gtkImage.errorLoading)
188
          nativeSetIconImage(gtkImage);
189
      }
190
  }
191
 
192
  protected void postConfigureEvent (int x, int y, int width, int height)
193
  {
194
    if (menuBar != null && width > 0)
195
      setMenuBarWidthUnlocked (menuBar, width);
196
 
197
    // Since insets.top already includes the MenuBar's height, we need
198
    // to subtract the MenuBar's height from the top inset.
199
    int frame_height = height - menuBarHeight;
200
 
201
    // Likewise, since insets.top includes the MenuBar height, we need
202
    // to add back the MenuBar height to the frame's y position.  If
203
    // no MenuBar exists in this frame, the MenuBar height will be 0.
204
    int frame_y = y + menuBarHeight;
205
 
206
    super.postConfigureEvent(x, frame_y, width, frame_height);
207
  }
208
 
209
  public int getState ()
210
  {
211
    return windowState;
212
  }
213
 
214
  public void setState (int state)
215
  {
216
    switch (state)
217
      {
218
        case Frame.NORMAL:
219
          if ((windowState & Frame.ICONIFIED) != 0)
220
            deiconify();
221
          if ((windowState & Frame.MAXIMIZED_BOTH) != 0)
222
            unmaximize();
223
          break;
224
        case Frame.ICONIFIED:
225
          iconify();
226
          break;
227
        case Frame.MAXIMIZED_BOTH:
228
          maximize();
229
      }
230
  }
231
 
232
  public void setMaximizedBounds (Rectangle r)
233
  {
234
 
235
  }
236
  public void setBoundsPrivate(int x, int y, int width, int height)
237
  {
238
    // TODO Auto-generated method stub
239
 
240
  }
241
 
242
  public boolean requestWindowFocus()
243
  {
244
    // TODO Auto-generated method stub
245
    return false;
246
  }
247
 
248
  public Rectangle getBoundsPrivate()
249
  {
250
    // TODO: Implement this properly.
251
    throw new InternalError("Not yet implemented");
252
  }
253
 
254
}

powered by: WebSVN 2.1.0

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