1*e6e6073dSLiu Zhe /************************************************************** 2*e6e6073dSLiu Zhe * 3*e6e6073dSLiu Zhe * Licensed to the Apache Software Foundation (ASF) under one 4*e6e6073dSLiu Zhe * or more contributor license agreements. See the NOTICE file 5*e6e6073dSLiu Zhe * distributed with this work for additional information 6*e6e6073dSLiu Zhe * regarding copyright ownership. The ASF licenses this file 7*e6e6073dSLiu Zhe * to you under the Apache License, Version 2.0 (the 8*e6e6073dSLiu Zhe * "License"); you may not use this file except in compliance 9*e6e6073dSLiu Zhe * with the License. You may obtain a copy of the License at 10*e6e6073dSLiu Zhe * 11*e6e6073dSLiu Zhe * http://www.apache.org/licenses/LICENSE-2.0 12*e6e6073dSLiu Zhe * 13*e6e6073dSLiu Zhe * Unless required by applicable law or agreed to in writing, 14*e6e6073dSLiu Zhe * software distributed under the License is distributed on an 15*e6e6073dSLiu Zhe * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*e6e6073dSLiu Zhe * KIND, either express or implied. See the License for the 17*e6e6073dSLiu Zhe * specific language governing permissions and limitations 18*e6e6073dSLiu Zhe * under the License. 19*e6e6073dSLiu Zhe * 20*e6e6073dSLiu Zhe *************************************************************/ 21*e6e6073dSLiu Zhe 22*e6e6073dSLiu Zhe 23*e6e6073dSLiu Zhe 24*e6e6073dSLiu Zhe package org.openoffice.test.vcl.widgets; 25*e6e6073dSLiu Zhe 26*e6e6073dSLiu Zhe import org.openoffice.test.vcl.client.Constant; 27*e6e6073dSLiu Zhe 28*e6e6073dSLiu Zhe /** 29*e6e6073dSLiu Zhe * Proxy used to access Vcl Combo Box 30*e6e6073dSLiu Zhe * 31*e6e6073dSLiu Zhe */ 32*e6e6073dSLiu Zhe public class VclComboBox extends VclControl { 33*e6e6073dSLiu Zhe VclComboBox(VclApp app, String id)34*e6e6073dSLiu Zhe public VclComboBox(VclApp app, String id) { 35*e6e6073dSLiu Zhe super(app, id); 36*e6e6073dSLiu Zhe } 37*e6e6073dSLiu Zhe 38*e6e6073dSLiu Zhe /** 39*e6e6073dSLiu Zhe * Get the item count 40*e6e6073dSLiu Zhe */ getItemCount()41*e6e6073dSLiu Zhe public int getItemCount() { 42*e6e6073dSLiu Zhe return ((Long) invoke(Constant.M_GetItemCount)).intValue(); 43*e6e6073dSLiu Zhe } 44*e6e6073dSLiu Zhe 45*e6e6073dSLiu Zhe /** 46*e6e6073dSLiu Zhe * Get the text of the index-th item. 47*e6e6073dSLiu Zhe * @index The index starts from 0. 48*e6e6073dSLiu Zhe */ getItemText(int index)49*e6e6073dSLiu Zhe public String getItemText(int index) { 50*e6e6073dSLiu Zhe return (String) invoke(Constant.M_GetItemText, new Object[] {index + 1}); 51*e6e6073dSLiu Zhe } 52*e6e6073dSLiu Zhe 53*e6e6073dSLiu Zhe /** 54*e6e6073dSLiu Zhe * Get the index of the selected item. 55*e6e6073dSLiu Zhe * @index The index starts from 0. 56*e6e6073dSLiu Zhe */ getSelIndex()57*e6e6073dSLiu Zhe public int getSelIndex() { 58*e6e6073dSLiu Zhe int index = ((Long) invoke(Constant.M_GetSelIndex)).intValue(); 59*e6e6073dSLiu Zhe return index - 1; 60*e6e6073dSLiu Zhe } 61*e6e6073dSLiu Zhe 62*e6e6073dSLiu Zhe /** 63*e6e6073dSLiu Zhe * Get the text of the selected item. 64*e6e6073dSLiu Zhe */ getSelText()65*e6e6073dSLiu Zhe public String getSelText() { 66*e6e6073dSLiu Zhe return (String) invoke(Constant.M_GetSelText); 67*e6e6073dSLiu Zhe } 68*e6e6073dSLiu Zhe 69*e6e6073dSLiu Zhe /** 70*e6e6073dSLiu Zhe * Get the text in the combo box 71*e6e6073dSLiu Zhe */ getText()72*e6e6073dSLiu Zhe public String getText() { 73*e6e6073dSLiu Zhe // Fix: Use M_Caption to get the text. M_GetText does not work 74*e6e6073dSLiu Zhe return (invoke(Constant.M_Caption)).toString(); 75*e6e6073dSLiu Zhe } 76*e6e6073dSLiu Zhe 77*e6e6073dSLiu Zhe /** 78*e6e6073dSLiu Zhe * Get the text of all items 79*e6e6073dSLiu Zhe */ getItemsText()80*e6e6073dSLiu Zhe public String[] getItemsText() { 81*e6e6073dSLiu Zhe int count = getItemCount(); 82*e6e6073dSLiu Zhe String[] res = new String[count]; 83*e6e6073dSLiu Zhe for (int i = 0; i < count; i++) { 84*e6e6073dSLiu Zhe res[i] = getItemText(i); 85*e6e6073dSLiu Zhe } 86*e6e6073dSLiu Zhe return res; 87*e6e6073dSLiu Zhe } 88*e6e6073dSLiu Zhe 89*e6e6073dSLiu Zhe /** 90*e6e6073dSLiu Zhe * Select the index-th item. 91*e6e6073dSLiu Zhe * @index The index starts from 0. 92*e6e6073dSLiu Zhe */ select(int index)93*e6e6073dSLiu Zhe public void select(int index) { 94*e6e6073dSLiu Zhe invoke(Constant.M_Select, new Object[] {index + 1}); 95*e6e6073dSLiu Zhe } 96*e6e6073dSLiu Zhe 97*e6e6073dSLiu Zhe /** 98*e6e6073dSLiu Zhe * Select the item with the given text 99*e6e6073dSLiu Zhe */ select(String text)100*e6e6073dSLiu Zhe public void select(String text) { 101*e6e6073dSLiu Zhe invoke(Constant.M_Select, new Object[] {text}); 102*e6e6073dSLiu Zhe } 103*e6e6073dSLiu Zhe 104*e6e6073dSLiu Zhe /** 105*e6e6073dSLiu Zhe * Sets no selection in a list (Sometimes this corresponds to the first 106*e6e6073dSLiu Zhe * entry in the list) 107*e6e6073dSLiu Zhe * 108*e6e6073dSLiu Zhe */ setNoSelection()109*e6e6073dSLiu Zhe public void setNoSelection() { 110*e6e6073dSLiu Zhe invoke(Constant.M_SetNoSelection); 111*e6e6073dSLiu Zhe } 112*e6e6073dSLiu Zhe 113*e6e6073dSLiu Zhe /** 114*e6e6073dSLiu Zhe * Set the text of the combo box 115*e6e6073dSLiu Zhe */ setText(String text)116*e6e6073dSLiu Zhe public void setText(String text) { 117*e6e6073dSLiu Zhe invoke(Constant.M_SetText, new Object[] {text}); 118*e6e6073dSLiu Zhe } 119*e6e6073dSLiu Zhe 120*e6e6073dSLiu Zhe /** 121*e6e6073dSLiu Zhe * Check if the list box has the specified item 122*e6e6073dSLiu Zhe * @param str 123*e6e6073dSLiu Zhe * @return 124*e6e6073dSLiu Zhe */ hasItem(String str)125*e6e6073dSLiu Zhe public boolean hasItem(String str) { 126*e6e6073dSLiu Zhe int len = getItemCount(); 127*e6e6073dSLiu Zhe for (int i = 0; i < len; i++) { 128*e6e6073dSLiu Zhe String text = getItemText(i); 129*e6e6073dSLiu Zhe if (str.equals(text)) 130*e6e6073dSLiu Zhe return true; 131*e6e6073dSLiu Zhe } 132*e6e6073dSLiu Zhe return false; 133*e6e6073dSLiu Zhe } 134*e6e6073dSLiu Zhe } 135