39 |
package gnu.java.awt.peer.gtk; |
package gnu.java.awt.peer.gtk; |
40 |
|
|
41 |
import java.awt.Component; |
import java.awt.Component; |
42 |
|
import java.awt.Container; |
43 |
import java.awt.Frame; |
import java.awt.Frame; |
44 |
import java.awt.Graphics; |
import java.awt.Graphics; |
45 |
import java.awt.Graphics2D; |
import java.awt.Graphics2D; |
59 |
private MenuBarPeer menuBar; |
private MenuBarPeer menuBar; |
60 |
native int getMenuBarHeight (MenuBarPeer bar); |
native int getMenuBarHeight (MenuBarPeer bar); |
61 |
|
|
62 |
|
int getMenuBarHeight () |
63 |
|
{ |
64 |
|
return menuBar == null ? 0 : getMenuBarHeight (menuBar); |
65 |
|
} |
66 |
|
|
67 |
native void setMenuBarPeer (MenuBarPeer bar); |
native void setMenuBarPeer (MenuBarPeer bar); |
68 |
native void removeMenuBarPeer (); |
native void removeMenuBarPeer (); |
69 |
native void moveLayout (int offset); |
native void gtkFixedMove (int offset); |
70 |
native void gtkLayoutSetVisible (boolean vis); |
native void gtkFixedSetVisible (boolean visible); |
71 |
|
|
72 |
public void setMenuBar (MenuBar bar) |
public void setMenuBar (MenuBar bar) |
73 |
{ |
{ |
74 |
if (bar == null) |
if (bar == null && menuBar != null) |
|
{ |
|
|
if (menuBar != null) |
|
75 |
{ |
{ |
76 |
gtkLayoutSetVisible(false); |
// We're removing the menubar. |
77 |
removeMenuBarPeer(); |
gtkFixedSetVisible (false); |
78 |
menuBar = null; |
menuBar = null; |
79 |
moveLayout(menuBarHeight); |
removeMenuBarPeer (); |
80 |
insets.top -= menuBarHeight; |
insets.top -= menuBarHeight; |
81 |
menuBarHeight = 0; |
menuBarHeight = 0; |
82 |
awtComponent.doLayout(); |
awtComponent.validate (); |
83 |
gtkLayoutSetVisible(true); |
gtkFixedSetVisible (true); |
84 |
} |
} |
85 |
} |
else if (bar != null && menuBar == null) |
|
else |
|
|
{ |
|
|
gtkLayoutSetVisible(false); |
|
|
int oldHeight = 0; |
|
|
if (menuBar != null) |
|
86 |
{ |
{ |
87 |
|
// We're adding a menubar where there was no menubar before. |
88 |
|
gtkFixedSetVisible (false); |
89 |
|
menuBar = (MenuBarPeer) ((MenuBar) bar).getPeer(); |
90 |
|
setMenuBarPeer (menuBar); |
91 |
|
menuBarHeight = getMenuBarHeight (); |
92 |
|
insets.top += menuBarHeight; |
93 |
|
awtComponent.validate (); |
94 |
|
gtkFixedSetVisible (true); |
95 |
|
} |
96 |
|
else if (bar != null && menuBar != null) |
97 |
|
{ |
98 |
|
// We're swapping the menubar. |
99 |
|
gtkFixedSetVisible (false); |
100 |
removeMenuBarPeer(); |
removeMenuBarPeer(); |
101 |
oldHeight = menuBarHeight; |
int oldHeight = menuBarHeight; |
102 |
insets.top -= menuBarHeight; |
menuBar = (MenuBarPeer) ((MenuBar) bar).getPeer (); |
103 |
|
setMenuBarPeer (menuBar); |
104 |
|
menuBarHeight = getMenuBarHeight (); |
105 |
|
if (oldHeight != menuBarHeight) |
106 |
|
{ |
107 |
|
insets.top += (menuBarHeight - oldHeight); |
108 |
|
awtComponent.validate (); |
109 |
|
} |
110 |
|
gtkFixedSetVisible (true); |
111 |
} |
} |
|
menuBar = (MenuBarPeer) ((MenuBar) bar).getPeer(); |
|
|
setMenuBarPeer(menuBar); |
|
|
menuBarHeight = getMenuBarHeight (menuBar); |
|
|
if (oldHeight != menuBarHeight) |
|
|
moveLayout(oldHeight - menuBarHeight); |
|
|
insets.top += menuBarHeight; |
|
|
awtComponent.doLayout(); |
|
|
gtkLayoutSetVisible(true); |
|
|
} |
|
112 |
} |
} |
113 |
|
|
114 |
public void setBounds (int x, int y, int width, int height) |
public void setBounds (int x, int y, int width, int height) |
236 |
|
|
237 |
protected void postExposeEvent (int x, int y, int width, int height) |
protected void postExposeEvent (int x, int y, int width, int height) |
238 |
{ |
{ |
239 |
q.postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT, |
if (!isInRepaint) |
240 |
new Rectangle (x + insets.left, |
q.postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT, |
241 |
y + insets.top, |
new Rectangle (x + insets.left, |
242 |
width, height))); |
y + insets.top, |
243 |
|
width, height))); |
244 |
} |
} |
245 |
|
|
246 |
public int getState () |
public int getState () |