205 }
206 xSetVisible(true);
207 toFront();
208 }
209
210 /************************************************
211 *
212 * Implementation of abstract methods
213 *
214 ************************************************/
215
216 /**
217 * Menu bar is always root window in menu window's
218 * hierarchy
219 */
220 protected XBaseMenuWindow getParentMenuWindow() {
221 return null;
222 }
223
224 /**
225 * @see XBaseMenuWindow.map
226 */
227 protected MappingData map() {
228 XMenuItemPeer[] itemVector = copyItems();
229 int itemCnt = itemVector.length;
230 XMenuItemPeer helpMenu = this.helpMenu;
231 int helpMenuPos = -1;
232 //find helpMenu and move it to the end of array
233 if (helpMenu != null) {
234 //Fixed 6270847: PIT: HELP menu is not shown at the right place when normal menus added to MB are removed, XToolkit
235 for (int i = 0; i < itemCnt; i++) {
236 if (itemVector[i] == helpMenu) {
237 helpMenuPos = i;
238 break;
239 }
240 }
241 if (helpMenuPos != -1 && helpMenuPos != itemCnt - 1) {
242 System.arraycopy(itemVector, helpMenuPos + 1, itemVector, helpMenuPos, itemCnt - 1 - helpMenuPos);
243 itemVector[itemCnt - 1] = helpMenu;
244 }
245 }
275 nextOffset = Math.max(nextOffset, this.width - itemWidth - BAR_SPACING_RIGHT);
276 }
277 Rectangle bounds = new Rectangle(nextOffset, BAR_SPACING_TOP, itemWidth, itemHeight);
278 //text should be centered vertically in menu item's bounds
279 int y = (maxHeight + dim.height) / 2 - metrics.getTextBaseline();
280 Point textOrigin = new Point(nextOffset + BAR_ITEM_MARGIN_LEFT, BAR_SPACING_TOP + BAR_ITEM_MARGIN_TOP + y);
281 nextOffset += itemWidth + BAR_ITEM_SPACING;
282 item.map(bounds, textOrigin);
283 } else {
284 Rectangle bounds = new Rectangle(nextOffset, BAR_SPACING_TOP, 0, 0);
285 Point textOrigin = new Point(nextOffset + BAR_ITEM_MARGIN_LEFT, BAR_SPACING_TOP + BAR_ITEM_MARGIN_TOP);
286 }
287 }
288 XMenuItemPeer mappedVector[] = new XMenuItemPeer[mappedCnt];
289 System.arraycopy(itemVector, 0, mappedVector, 0, mappedCnt);
290 MappingData mappingData = new MappingData(mappedVector, BAR_SPACING_TOP + itemHeight + BAR_SPACING_BOTTOM);
291 return mappingData;
292 }
293
294 /**
295 * @see XBaseMenuWindow.getSubmenuBounds
296 */
297 protected Rectangle getSubmenuBounds(Rectangle itemBounds, Dimension windowSize) {
298 Rectangle globalBounds = toGlobal(itemBounds);
299 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
300 Rectangle res;
301 res = fitWindowBelow(globalBounds, windowSize, screenSize);
302 if (res != null) {
303 return res;
304 }
305 res = fitWindowAbove(globalBounds, windowSize, screenSize);
306 if (res != null) {
307 return res;
308 }
309 res = fitWindowRight(globalBounds, windowSize, screenSize);
310 if (res != null) {
311 return res;
312 }
313 res = fitWindowLeft(globalBounds, windowSize, screenSize);
314 if (res != null) {
315 return res;
345
346 /**
347 * Returns true if framePeer is not null and is enabled
348 * Used to fix 6185057: Disabling a frame does not disable
349 * the menus on the frame, on solaris/linux
350 */
351 boolean isFramePeerEnabled() {
352 if (framePeer != null) {
353 return framePeer.isEnabled();
354 }
355 return false;
356 }
357
358 /************************************************
359 *
360 * Overriden XBaseMenuWindow functions
361 *
362 ************************************************/
363
364 /**
365 * @see XBaseMenuWindow.doDispose()
366 */
367 protected void doDispose() {
368 super.doDispose();
369 XToolkit.targetDisposedPeer(menuBarTarget, this);
370 }
371
372 /************************************************
373 *
374 * Overriden XWindow general-purpose functions
375 *
376 ************************************************/
377
378 /**
379 * For menu bars this function is called from framePeer's
380 * reshape(...) and updateChildrenSizes()
381 */
382 public void reshape(int x, int y, int width, int height) {
383 if ((width != this.width) || (height != this.height)) {
384 resetMapping();
385 }
386 super.reshape(x, y, width, height);
387 }
388
389 /**
390 * Performs ungrabbing of input
391 * @see XBaseWindow.ungrabInputImpl()
392 */
393 void ungrabInputImpl() {
394 selectItem(null, false);
395 super.ungrabInputImpl();
396 postPaintEvent();
397 }
398
399 /************************************************
400 *
401 * Overriden XWindow painting & printing
402 *
403 ************************************************/
404 public void paintPeer(Graphics g) {
405 resetColors();
406 /* Calculate menubar dimension. */
407 int width = getWidth();
408 int height = getHeight();
409
410 flush();
411 //Fill background of rectangle
|
205 }
206 xSetVisible(true);
207 toFront();
208 }
209
210 /************************************************
211 *
212 * Implementation of abstract methods
213 *
214 ************************************************/
215
216 /**
217 * Menu bar is always root window in menu window's
218 * hierarchy
219 */
220 protected XBaseMenuWindow getParentMenuWindow() {
221 return null;
222 }
223
224 /**
225 * @see XBaseMenuWindow#map
226 */
227 protected MappingData map() {
228 XMenuItemPeer[] itemVector = copyItems();
229 int itemCnt = itemVector.length;
230 XMenuItemPeer helpMenu = this.helpMenu;
231 int helpMenuPos = -1;
232 //find helpMenu and move it to the end of array
233 if (helpMenu != null) {
234 //Fixed 6270847: PIT: HELP menu is not shown at the right place when normal menus added to MB are removed, XToolkit
235 for (int i = 0; i < itemCnt; i++) {
236 if (itemVector[i] == helpMenu) {
237 helpMenuPos = i;
238 break;
239 }
240 }
241 if (helpMenuPos != -1 && helpMenuPos != itemCnt - 1) {
242 System.arraycopy(itemVector, helpMenuPos + 1, itemVector, helpMenuPos, itemCnt - 1 - helpMenuPos);
243 itemVector[itemCnt - 1] = helpMenu;
244 }
245 }
275 nextOffset = Math.max(nextOffset, this.width - itemWidth - BAR_SPACING_RIGHT);
276 }
277 Rectangle bounds = new Rectangle(nextOffset, BAR_SPACING_TOP, itemWidth, itemHeight);
278 //text should be centered vertically in menu item's bounds
279 int y = (maxHeight + dim.height) / 2 - metrics.getTextBaseline();
280 Point textOrigin = new Point(nextOffset + BAR_ITEM_MARGIN_LEFT, BAR_SPACING_TOP + BAR_ITEM_MARGIN_TOP + y);
281 nextOffset += itemWidth + BAR_ITEM_SPACING;
282 item.map(bounds, textOrigin);
283 } else {
284 Rectangle bounds = new Rectangle(nextOffset, BAR_SPACING_TOP, 0, 0);
285 Point textOrigin = new Point(nextOffset + BAR_ITEM_MARGIN_LEFT, BAR_SPACING_TOP + BAR_ITEM_MARGIN_TOP);
286 }
287 }
288 XMenuItemPeer mappedVector[] = new XMenuItemPeer[mappedCnt];
289 System.arraycopy(itemVector, 0, mappedVector, 0, mappedCnt);
290 MappingData mappingData = new MappingData(mappedVector, BAR_SPACING_TOP + itemHeight + BAR_SPACING_BOTTOM);
291 return mappingData;
292 }
293
294 /**
295 * @see XBaseMenuWindow#getSubmenuBounds
296 */
297 protected Rectangle getSubmenuBounds(Rectangle itemBounds, Dimension windowSize) {
298 Rectangle globalBounds = toGlobal(itemBounds);
299 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
300 Rectangle res;
301 res = fitWindowBelow(globalBounds, windowSize, screenSize);
302 if (res != null) {
303 return res;
304 }
305 res = fitWindowAbove(globalBounds, windowSize, screenSize);
306 if (res != null) {
307 return res;
308 }
309 res = fitWindowRight(globalBounds, windowSize, screenSize);
310 if (res != null) {
311 return res;
312 }
313 res = fitWindowLeft(globalBounds, windowSize, screenSize);
314 if (res != null) {
315 return res;
345
346 /**
347 * Returns true if framePeer is not null and is enabled
348 * Used to fix 6185057: Disabling a frame does not disable
349 * the menus on the frame, on solaris/linux
350 */
351 boolean isFramePeerEnabled() {
352 if (framePeer != null) {
353 return framePeer.isEnabled();
354 }
355 return false;
356 }
357
358 /************************************************
359 *
360 * Overriden XBaseMenuWindow functions
361 *
362 ************************************************/
363
364 /**
365 * @see XBaseMenuWindow#doDispose()
366 */
367 protected void doDispose() {
368 super.doDispose();
369 XToolkit.targetDisposedPeer(menuBarTarget, this);
370 }
371
372 /************************************************
373 *
374 * Overriden XWindow general-purpose functions
375 *
376 ************************************************/
377
378 /**
379 * For menu bars this function is called from framePeer's
380 * reshape(...) and updateChildrenSizes()
381 */
382 public void reshape(int x, int y, int width, int height) {
383 if ((width != this.width) || (height != this.height)) {
384 resetMapping();
385 }
386 super.reshape(x, y, width, height);
387 }
388
389 /**
390 * Performs ungrabbing of input
391 * @see XBaseWindow#ungrabInputImpl()
392 */
393 void ungrabInputImpl() {
394 selectItem(null, false);
395 super.ungrabInputImpl();
396 postPaintEvent();
397 }
398
399 /************************************************
400 *
401 * Overriden XWindow painting & printing
402 *
403 ************************************************/
404 public void paintPeer(Graphics g) {
405 resetColors();
406 /* Calculate menubar dimension. */
407 int width = getWidth();
408 int height = getHeight();
409
410 flush();
411 //Fill background of rectangle
|