~ubuntu-branches/ubuntu/raring/scilab/raring-proposed

« back to all changes in this revision

Viewing changes to modules/windows_tools/src/c/scilab_windows/console.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2012-08-30 14:42:38 UTC
  • mfrom: (1.4.7)
  • Revision ID: package-import@ubuntu.com-20120830144238-c1y2og7dbm7m9nig
Tags: 5.4.0-beta-3-1~exp1
* New upstream release
* Update the scirenderer dep
* Get ride of libjhdf5-java dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3
3
* Copyright (C) INRIA - Allan CORNET
4
 
 
4
*
5
5
* This file must be used under the terms of the CeCILL.
6
6
* This source file is licensed as described in the file COPYING, which
7
7
* you should have received as part of this distribution.  The terms
8
 
* are also available at    
 
8
* are also available at
9
9
* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10
10
*
11
11
*/
24
24
#include "version.h"
25
25
#include "strdup_windows.h"
26
26
/*--------------------------------------------------------------------------*/
27
 
#define NameConsole "Console" 
 
27
#define NameConsole "Console"
28
28
/*--------------------------------------------------------------------------*/
29
29
static CONSOLE_SCREEN_BUFFER_INFO csbiInfoSave;
30
30
static char ScilexConsoleName[MAX_PATH];
31
31
/*--------------------------------------------------------------------------*/
32
32
void UpdateConsoleColors(void)
33
33
{
34
 
        HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
35
 
        COORD Coord;
36
 
        DWORD cWritten;
37
 
 
38
 
        Coord.X=0;
39
 
        Coord.Y=0;
40
 
 
41
 
        FillConsoleOutputAttribute( hConsole,
42
 
                BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED|BACKGROUND_INTENSITY,
43
 
                csbiInfoSave.dwSize.X*csbiInfoSave.dwSize.Y,
44
 
                Coord,
45
 
                &cWritten); 
46
 
 
47
 
        SetConsoleTextAttribute(hConsole,BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED|BACKGROUND_INTENSITY);
 
34
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
 
35
    COORD Coord;
 
36
    DWORD cWritten;
 
37
 
 
38
    Coord.X = 0;
 
39
    Coord.Y = 0;
 
40
 
 
41
    FillConsoleOutputAttribute( hConsole,
 
42
                                BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY,
 
43
                                csbiInfoSave.dwSize.X * csbiInfoSave.dwSize.Y,
 
44
                                Coord,
 
45
                                &cWritten);
 
46
 
 
47
    SetConsoleTextAttribute(hConsole, BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY);
48
48
 
49
49
}
50
50
/*--------------------------------------------------------------------------*/
51
51
void SaveConsoleColors(void)
52
52
{
53
 
        GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfoSave); 
 
53
    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfoSave);
54
54
}
55
55
/*--------------------------------------------------------------------------*/
56
56
void RestoreConsoleColors(void)
57
57
{
58
 
        HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
59
 
        COORD Coord;
60
 
        DWORD cWritten;
61
 
 
62
 
        Coord.X=0;
63
 
        Coord.Y=0;
64
 
 
65
 
        FillConsoleOutputAttribute( hConsole,
66
 
                csbiInfoSave.wAttributes,
67
 
                csbiInfoSave.dwSize.X*csbiInfoSave.dwSize.Y,
68
 
                Coord,
69
 
                &cWritten);
70
 
        SetConsoleTextAttribute(hConsole,csbiInfoSave.wAttributes);
 
58
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
 
59
    COORD Coord;
 
60
    DWORD cWritten;
 
61
 
 
62
    Coord.X = 0;
 
63
    Coord.Y = 0;
 
64
 
 
65
    FillConsoleOutputAttribute( hConsole,
 
66
                                csbiInfoSave.wAttributes,
 
67
                                csbiInfoSave.dwSize.X * csbiInfoSave.dwSize.Y,
 
68
                                Coord,
 
69
                                &cWritten);
 
70
    SetConsoleTextAttribute(hConsole, csbiInfoSave.wAttributes);
71
71
}
72
72
/*--------------------------------------------------------------------------*/
73
73
void RenameConsole(void)
74
74
{
75
 
        HWND hScilex = NULL;
76
 
        char CurrentConsoleName[MAX_PATH];
77
 
        char CurrentConsoleNameTmp[MAX_PATH];
78
 
 
79
 
        GetConsoleTitle(CurrentConsoleName,MAX_PATH);
80
 
        strncpy(CurrentConsoleNameTmp,CurrentConsoleName,strlen(NameConsole));
81
 
        CurrentConsoleNameTmp[strlen(NameConsole)]='\0';
82
 
 
83
 
        if ( strcmp(CurrentConsoleNameTmp,NameConsole) != 0)     
84
 
        {
85
 
                wsprintf(ScilexConsoleName,"%s %s",NameConsole,SCI_VERSION_STRING);
86
 
                SetConsoleTitle(ScilexConsoleName);
87
 
        }
88
 
 
89
 
        hScilex = GetConsoleWindow();
90
 
        if (hScilex)
91
 
        {
92
 
                HMENU hmenuConsole = NULL;
93
 
                // Desactive croix dans la console
94
 
                hmenuConsole = GetSystemMenu(hScilex, FALSE);
95
 
                DeleteMenu(hmenuConsole, SC_CLOSE, MF_BYCOMMAND);
96
 
        }
 
75
    HWND hScilex = NULL;
 
76
    char CurrentConsoleName[MAX_PATH];
 
77
    char CurrentConsoleNameTmp[MAX_PATH];
 
78
 
 
79
    GetConsoleTitle(CurrentConsoleName, MAX_PATH);
 
80
    strncpy(CurrentConsoleNameTmp, CurrentConsoleName, strlen(NameConsole));
 
81
    CurrentConsoleNameTmp[strlen(NameConsole)] = '\0';
 
82
 
 
83
    if ( strcmp(CurrentConsoleNameTmp, NameConsole) != 0)
 
84
    {
 
85
        wsprintf(ScilexConsoleName, "%s %s", NameConsole, SCI_VERSION_STRING);
 
86
        SetConsoleTitle(ScilexConsoleName);
 
87
    }
 
88
 
 
89
    hScilex = GetConsoleWindow();
 
90
    if (hScilex)
 
91
    {
 
92
        HMENU hmenuConsole = NULL;
 
93
        // Desactive croix dans la console
 
94
        hmenuConsole = GetSystemMenu(hScilex, FALSE);
 
95
        DeleteMenu(hmenuConsole, SC_CLOSE, MF_BYCOMMAND);
 
96
    }
97
97
}
98
98
/*--------------------------------------------------------------------------*/
99
99
void RestoreExitButton(void)
100
100
{
101
 
        HWND hScilex = NULL;
102
 
        hScilex = GetConsoleWindow();
103
 
        if (hScilex)
104
 
        {
105
 
                HMENU hmenuConsole = NULL;
106
 
                // Active croix dans la console
107
 
                hmenuConsole = GetSystemMenu(hScilex, FALSE);
108
 
                AppendMenu( hmenuConsole, MF_BYCOMMAND, SC_CLOSE, "&Close Alt+F4" ); 
109
 
        }
 
101
    HWND hScilex = NULL;
 
102
    hScilex = GetConsoleWindow();
 
103
    if (hScilex)
 
104
    {
 
105
        HMENU hmenuConsole = NULL;
 
106
        // Active croix dans la console
 
107
        hmenuConsole = GetSystemMenu(hScilex, FALSE);
 
108
        AppendMenu( hmenuConsole, MF_BYCOMMAND, SC_CLOSE, "&Close Alt+F4" );
 
109
    }
110
110
}
111
111
/*--------------------------------------------------------------------------*/
112
112
void CreateScilabConsole(int ShowBanner)
113
113
{
114
 
        HWND hScilex=NULL;
115
 
 
116
 
        SetConsoleState(0);  /* Console DOS Cach�e par d�faut */
117
 
        AllocConsole();
118
 
 
119
 
        wsprintf(ScilexConsoleName,"%s %s (%d)",NameConsole,SCI_VERSION_STRING,getCurrentScilabId());
120
 
        SetConsoleTitle(ScilexConsoleName);
121
 
 
122
 
        CreateConsoleScreenBuffer(GENERIC_READ|GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CONSOLE_TEXTMODE_BUFFER,NULL);
123
 
        freopen("CONOUT$", "wb", stdout); /* redirect stdout --> CONOUT$*/
124
 
        freopen("CONOUT$", "wb", stderr); /* redirect stderr --> CONOUT$*/
125
 
 
126
 
        if (ShowBanner)
127
 
        {
128
 
                char line[80];
129
 
 
130
 
                strcpy(line,"        ___________________________________________\n");
131
 
                printf(line);
132
 
                wsprintf(line,"                         %s\n\n",SCI_VERSION_STRING);
133
 
                printf(line);
134
 
                strcpy(line,"                 Consortium Scilab (DIGITEO)\n");
135
 
                printf(line);
136
 
                strcpy(line,"               Copyright (c) 1989-2012 (INRIA)\n");
137
 
                printf(line);
138
 
                strcpy(line,"               Copyright (c) 1989-2007 (ENPC)\n");
139
 
                printf(line);
140
 
                strcpy(line,"        ___________________________________________\n\n");
141
 
                printf(line);
142
 
        }
143
 
 
144
 
        hScilex = GetConsoleWindow();
145
 
        if (hScilex)
146
 
        {
147
 
                HMENU hmenuConsole = NULL;
148
 
                // Desactive croix dans la console
149
 
                hmenuConsole=GetSystemMenu(hScilex, FALSE);
150
 
                DeleteMenu(hmenuConsole, SC_CLOSE, MF_BYCOMMAND);
151
 
 
152
 
                /* Cache la fenetre Console */
153
 
                ShowWindow(hScilex,SW_HIDE); 
154
 
        }
 
114
    HWND hScilex = NULL;
 
115
 
 
116
    SetConsoleState(0);  /* Console DOS Cach�e par d�faut */
 
117
    AllocConsole();
 
118
 
 
119
    wsprintf(ScilexConsoleName, "%s %s (%d)", NameConsole, SCI_VERSION_STRING, getCurrentScilabId());
 
120
    SetConsoleTitle(ScilexConsoleName);
 
121
 
 
122
    CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
 
123
    freopen("CONOUT$", "wb", stdout); /* redirect stdout --> CONOUT$*/
 
124
    freopen("CONOUT$", "wb", stderr); /* redirect stderr --> CONOUT$*/
 
125
 
 
126
    if (ShowBanner)
 
127
    {
 
128
        char line[80];
 
129
 
 
130
        strcpy(line, "        ___________________________________________\n");
 
131
        printf(line);
 
132
        wsprintf(line, "                         %s\n\n", SCI_VERSION_STRING);
 
133
        printf(line);
 
134
        strcpy(line, "                     Scilab Enterprises\n");
 
135
        printf(line);
 
136
        strcpy(line, "         Copyright (c) 2011-2012 (Scilab Enterprises)\n");
 
137
        printf(line);
 
138
        strcpy(line, "               Copyright (c) 1989-2012 (INRIA)\n");
 
139
        printf(line);
 
140
        strcpy(line, "               Copyright (c) 1989-2007 (ENPC)\n");
 
141
        printf(line);
 
142
        strcpy(line, "        ___________________________________________\n\n");
 
143
        printf(line);
 
144
    }
 
145
 
 
146
    hScilex = GetConsoleWindow();
 
147
    if (hScilex)
 
148
    {
 
149
        HMENU hmenuConsole = NULL;
 
150
        // Desactive croix dans la console
 
151
        hmenuConsole = GetSystemMenu(hScilex, FALSE);
 
152
        DeleteMenu(hmenuConsole, SC_CLOSE, MF_BYCOMMAND);
 
153
 
 
154
        /* Cache la fenetre Console */
 
155
        ShowWindow(hScilex, SW_HIDE);
 
156
    }
155
157
}
156
158
/*--------------------------------------------------------------------------*/
157
159
void CloseScilabConsole(void)
158
160
{
159
 
        fclose(stdout);
160
 
        fclose(stderr);
161
 
        FreeConsole();
 
161
    fclose(stdout);
 
162
    fclose(stderr);
 
163
    FreeConsole();
162
164
}
163
165
/*--------------------------------------------------------------------------*/
164
166
char *getScilexConsoleName(void)
165
167
{
166
 
        char *retName = NULL;
 
168
    char *retName = NULL;
167
169
 
168
 
        if (strlen(ScilexConsoleName) > 0)
169
 
        {
170
 
                retName = strdup(ScilexConsoleName);
171
 
        }
172
 
        return retName;
 
170
    if (strlen(ScilexConsoleName) > 0)
 
171
    {
 
172
        retName = strdup(ScilexConsoleName);
 
173
    }
 
174
    return retName;
173
175
}
174
176
/*--------------------------------------------------------------------------*/
175
177
int getXConsoleScreenSize(void)
176
178
{
177
 
        return (csbiInfoSave.srWindow.Right - csbiInfoSave.srWindow.Left);
 
179
    return (csbiInfoSave.srWindow.Right - csbiInfoSave.srWindow.Left);
178
180
}
179
181
/*--------------------------------------------------------------------------*/
180
182
int getYConsoleScreenSize(void)
181
183
{
182
 
        return (csbiInfoSave.srWindow.Bottom - csbiInfoSave.srWindow.Top);
 
184
    return (csbiInfoSave.srWindow.Bottom - csbiInfoSave.srWindow.Top);
183
185
}
184
186
/*--------------------------------------------------------------------------*/