xref: /AOO41X/test/testcommon/source/org/openoffice/test/vcl/widgets/VclMenu.java (revision 57caf934cc4bd0c33eda07ea95aabaebabf812db)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package org.openoffice.test.vcl.widgets;
25 
26 import org.openoffice.test.vcl.client.Constant;
27 
28 /**
29  * Define VCL menu on a window
30  *
31  */
32 public class VclMenu extends VclWidget {
33 
34     private VclControl window = null;
35 
VclMenu(VclApp app)36     public VclMenu(VclApp app) {
37         super(app);
38     }
39 
40     /**
41      * Construct the menu on the given window
42      *
43      * @param window
44      */
VclMenu(VclControl window)45     public VclMenu(VclControl window) {
46         super(window.app);
47         this.window = window;
48     }
49 
50     /**
51      * Returns the numbers of menu items (including the menu separators)
52      *
53      * @return Number of menu items in a menu . -1 : Return value error
54      *
55      */
getItemCount()56     public int getItemCount() {
57         use();
58         return ((Long) app.caller.callCommand(Constant.RC_MenuGetItemCount)).intValue();
59     }
60 
61     /**
62      * Return the menu item at the n-th index
63      *
64      * @param index
65      * @return null when the item is separator
66      */
getItem(int index)67     public VclMenuItem getItem(int index) {
68         use();
69         long id = ((Long) app.caller.callCommand(Constant.RC_MenuGetItemId, new Object[] { new Integer(index + 1) })).intValue();
70         if (id == 0)
71             return null;
72         return new VclMenuItem(this, (int) id);
73     }
74 
use()75     protected void use() {
76         if (window != null) {
77             window.useMenu();
78         }
79     }
80 }
81