2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008 - INRIA - Vincent COUVERT (java version)
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
15 #include "localization.h"
16 #include "CallMessageBox.h"
18 #include "getPropertyAssignedValue.h"
20 #include "messageboxoptions.h"
22 /*--------------------------------------------------------------------------*/
23 int sci_messagebox(char *fname, unsigned long fname_len)
27 /* Used to read input arguments */
28 int nbRow = 0, nbCol = 0;
29 int nbRowButtons = 0, nbColButtons = 0;
30 int nbRowMessage = 0, nbColMessage = 0;
32 char **buttonsTextAdr = 0;
33 char **messageAdr = 0;
35 char **modalOptionAdr = 0;
38 /* Used to write output argument */
39 int buttonNumberAdr = 0;
45 /* Message to be displayed */
46 if (VarType(1) == sci_strings)
48 GetRhsVar(1, MATRIX_OF_STRING_DATATYPE, &nbRowMessage, &nbColMessage, &messageAdr);
52 Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
56 /* Title to be displayed */
59 if (VarType(2) == sci_strings)
61 GetRhsVar(2, MATRIX_OF_STRING_DATATYPE, &nbRow, &nbCol, &titleAdr);
62 if (nbRow * nbCol != 1)
64 Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 2);
67 /* The title argument can be used to give the modal option */
68 if (isModalOption(titleAdr[0]))
70 modalOptionAdr = titleAdr;
76 Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2);
81 /* Icon to be displayed */
84 if (VarType(3) == sci_strings)
86 GetRhsVar(3, MATRIX_OF_STRING_DATATYPE, &nbRow, &nbCol, &iconAdr);
87 if (nbRow * nbCol == 1)
89 /* The icon argument can be used to give the modal option or the buttons names */
90 if (isModalOption(iconAdr[0]))
92 modalOptionAdr = (char **)iconAdr;
95 else if (!isIconName(iconAdr[0]))
97 buttonsTextAdr = (char **)iconAdr;
103 else /* More than one string --> buttons names */
105 buttonsTextAdr = (char **)iconAdr;
106 nbRowButtons = nbRow;
107 nbColButtons = nbCol;
114 Scierror(999, _("%s: Wrong type for input argument #%d: A string or a string vector expected.\n"), fname, 3);
122 if (VarType(4) == sci_strings)
124 GetRhsVar(4, MATRIX_OF_STRING_DATATYPE, &nbRowButtons, &nbColButtons, &buttonsTextAdr);
125 if (nbRow * nbCol == 1)
127 /* The buttons names argument can be used to give the modal option */
128 if (isModalOption(buttonsTextAdr[0]))
130 modalOptionAdr = buttonsTextAdr;
131 buttonsTextAdr = NULL;
137 Scierror(999, _("%s: Wrong type for input argument #%d: A string or a string vector expected.\n"), fname, 3);
145 if (VarType(5) == sci_strings)
147 GetRhsVar(5, MATRIX_OF_STRING_DATATYPE, &nbRow, &nbCol, &modalOptionAdr);
148 if (nbRow * nbCol != 1)
150 Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 5);
156 Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 5);
160 /* Create the Java Object */
161 messageBoxID = createMessageBox();
164 setMessageBoxMultiLineMessage(messageBoxID, messageAdr, nbColMessage * nbRowMessage);
167 if (titleAdr != NULL)
169 setMessageBoxTitle(messageBoxID, titleAdr[0]);
173 setMessageBoxTitle(messageBoxID, _("Scilab Message"));
179 setMessageBoxIcon(messageBoxID, iconAdr[0]);
183 if (buttonsTextAdr != NULL)
185 setMessageBoxButtonsLabels(messageBoxID, buttonsTextAdr, nbColButtons * nbRowButtons);
189 if (modalOptionAdr != NULL)
191 setMessageBoxModal(messageBoxID, !stricmp(modalOptionAdr[0], "modal"));
195 setMessageBoxModal(messageBoxID, FALSE);
198 /* Display it and wait for a user input */
199 messageBoxDisplayAndWait(messageBoxID);
201 /* Return the index of the button selected */
205 /* Read the user answer */
206 buttonNumber = getMessageBoxSelectedButton(messageBoxID);
210 CreateVar(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE, &nbRow, &nbCol, &buttonNumberAdr);
211 *stk(buttonNumberAdr) = buttonNumber;
223 /*--------------------------------------------------------------------------*/