GUI module ported to api_scilab. test_run("gui")
[scilab.git] / scilab / modules / gui / sci_gateway / cpp / sci_getinstalledlookandfeels.cpp
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2008 - INRIA - Allan CORNET
4  *
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
10  *
11  */
12
13 #include "LookAndFeelManager.hxx"
14
15 extern "C"
16 {
17 #include <stdlib.h>
18 #include "gw_gui.h"
19 #include "api_scilab.h"
20 #include "getScilabJavaVM.h"
21 #include "Scierror.h"
22 #include "localization.h"
23 #include "GiwsException.hxx"
24     /*--------------------------------------------------------------------------*/
25     int sci_getinstalledlookandfeels(char *fname, unsigned long fname_len)
26     {
27         SciErr sciErr;
28         CheckInputArgument(pvApiCtx, 0, 0);
29         CheckOutputArgument(pvApiCtx, 1, 1);
30
31         org_scilab_modules_gui_utils::LookAndFeelManager * lnf = 0;
32         try
33         {
34             lnf = new org_scilab_modules_gui_utils::LookAndFeelManager(getScilabJavaVM());
35         }
36         catch (const GiwsException::JniException & e)
37         {
38             Scierror(999, _("%s: A Java exception arisen:\n%s"), fname, e.whatStr().c_str());
39             return 1;
40         }
41
42         if (lnf)
43         {
44             char **lookandfeels = NULL;
45             int nbElems = 0;
46             int nbCol = 0;
47
48             lookandfeels = lnf->getInstalledLookAndFeels();
49             nbElems = lnf->numbersOfInstalledLookAndFeels();
50
51             nbCol = 1;
52
53             sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbElems, nbCol, lookandfeels);
54             if (sciErr.iErr)
55             {
56                 printError(&sciErr, 0);
57                 Scierror(999, _("%s: Memory allocation error.\n"), fname);
58                 return 1;
59             }
60
61             if (lookandfeels)
62             {
63                 int i = 0;
64
65                 for (i = 0; i < nbElems; i++)
66                 {
67                     if (lookandfeels[i])
68                     {
69                         delete[]lookandfeels[i];
70                     }
71                 }
72                 delete[]lookandfeels;
73                 lookandfeels = NULL;
74             }
75             delete lnf;
76
77             AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
78             returnArguments(pvApiCtx);
79         }
80         else
81         {
82             Scierror(999, _("%s: No more memory.\n"), fname);
83         }
84         return 0;
85     }
86     /*--------------------------------------------------------------------------*/
87 }
88
89 /* END OF extern "C" */
90 /*--------------------------------------------------------------------------*/