~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to routines/menusX/xmen_Utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright ENPC */
 
2
#include "men_scilab.h"
 
3
 
 
4
#define MAXLISTLINE 30  /* Maximum number of line in a List widget Viewport */
 
5
#define MAXLISTCOLS 120 /* Maximum number of columns in a List widget Viewport */
 
6
#define MAXLABLINE 10  /* Maximum number of line in a List widget Viewport */
 
7
#define MAXLABCOLS 120 /* Maximum number of columns in a List widget Viewport */
 
8
#define MAXASCLINE 30  /* Maximum number of line in anascii widget  */
 
9
#define MAXASCCOLS 120 /* Maximum number of columns in an ascii widget Viewport */
 
10
#define ScrThickness 10 /* ScrollbarThickness maximizer */
 
11
 
 
12
#define char_height(font) ((font)->max_bounds.ascent+(font)->max_bounds.descent)
 
13
#define char_width(font) ((font)->max_bounds.width)
 
14
 
 
15
 
 
16
extern int set_cmap __PARAMS((Window w)); 
 
17
extern void DisplayInit __PARAMS((char *string,Display **dpy,Widget *toplevel));
 
18
 
 
19
extern XtAppContext app_con;
 
20
/** int ok_Flag_sci = 0; **/
 
21
 
 
22
static   Arg args[10];
 
23
static   Cardinal iargs = 0;
 
24
 
 
25
 
 
26
 
 
27
/*****************************************************************
 
28
 * generic function used for all the Scilab transient `menus' 
 
29
 *****************************************************************/
 
30
 
 
31
/********************************************************
 
32
 *a special loop when inside transient menu shells 
 
33
 * we want to exit the loop when ok_Flag_sci != 0 
 
34
 *******************************************************/
 
35
 
 
36
void XtMyLoop(w,dpy,flag,ok_Flag)
 
37
     Widget w;
 
38
     Display *dpy;
 
39
     int flag;
 
40
     int *ok_Flag;
 
41
{
 
42
  Atom   wmDeleteWindow;
 
43
  XEvent event;
 
44
  *ok_Flag = 0;
 
45
  /*  XtPopup(w,XtGrabExclusive);*/
 
46
  XtPopup(w,XtGrabNone); 
 
47
 
 
48
  if ( flag ==1 ) 
 
49
    {
 
50
      /** used in men_choice to get the scilab graphic colormap */
 
51
      set_cmap(XtWindow(w));
 
52
      /** if scilab graphic window has a private colormap we must redraw 
 
53
        the xchoice widget **/
 
54
    }
 
55
  /* On ignore les delete envoyes par le Window Manager */
 
56
  wmDeleteWindow = XInternAtom(XtDisplay(w),"WM_DELETE_WINDOW", False);
 
57
  XSetWMProtocols(XtDisplay(w),XtWindow(w), &wmDeleteWindow, 1);
 
58
  for (;;) {
 
59
    XtAppNextEvent(app_con,&event);
 
60
    XtDispatchEvent(&event);
 
61
    if ( *ok_Flag != 0) break;
 
62
  }
 
63
  XtDestroyWidget(w);  
 
64
  XFlush(dpy);
 
65
  XSync(dpy,0);
 
66
}
 
67
 
 
68
/********************************************************
 
69
 * creates a transient shell+a form Widget 
 
70
 * #define SHELL_TYPE wmShellWidgetClass 
 
71
 ********************************************************/
 
72
 
 
73
#define SHELL_TYPE transientShellWidgetClass 
 
74
 
 
75
void 
 
76
ShellFormCreate(shellname,shell,form,dpyh)
 
77
     char shellname[];
 
78
     Display **dpyh;
 
79
     Widget *shell,*form;
 
80
{
 
81
  static  Widget toplevel,hpaned;
 
82
  DisplayInit("",dpyh,&toplevel);
 
83
 
 
84
  *shell = XtCreatePopupShell(shellname,SHELL_TYPE,toplevel,
 
85
                             (Arg *) NULL,(Cardinal)ZERO);
 
86
  hpaned = XtCreateManagedWidget("hpaned",panedWidgetClass,*shell,
 
87
                             (Arg *) NULL,(Cardinal)ZERO);
 
88
 
 
89
  *form = XtCreateManagedWidget("paned",panedWidgetClass,hpaned,
 
90
                             (Arg *) NULL,(Cardinal)ZERO);
 
91
}
 
92
 
 
93
 
 
94
/********************************************************
 
95
 * just add a button and it's callback 
 
96
 ********************************************************/
 
97
 
 
98
int ButtonCreate(parentW,button,callback,data,label,name)
 
99
     Widget parentW,*button;
 
100
     char label[],name[];
 
101
     XtCallbackProc callback;
 
102
     XtPointer data;
 
103
{
 
104
  iargs=0;
 
105
  XtSetArg(args[iargs], XtNlabel,label); iargs++;
 
106
  *button=XtCreateManagedWidget(name,commandWidgetClass,parentW,args,iargs);
 
107
  XtAddCallback(*button, XtNcallback,callback ,(XtPointer) data);  
 
108
  return(0);
 
109
}
 
110
 
 
111
/********************************************************
 
112
 * This function creates a labelwidget inside a vieportwidget 
 
113
 *  and resizes the labelwidget not to exceed max values 
 
114
 * [ the viewport will have the scrollbars ] 
 
115
 * the function return the two widgets and the width and height 
 
116
 * Reste un point obscur doit on fixer le with/height du viewport ou du label ?
 
117
 * parentW is the widget inside which the viewport/label is inserted 
 
118
 ********************************************************/
 
119
 
 
120
 
 
121
int ViewpLabelCreate(parentW,labelW,viewportW,description)
 
122
     Widget parentW;
 
123
     Widget *labelW,*viewportW;
 
124
     char description[];
 
125
{
 
126
  iargs=0;
 
127
  *viewportW = XtCreateManagedWidget("labelviewport",viewportWidgetClass,parentW,args,iargs);
 
128
  iargs = 0;
 
129
  XtSetArg(args[iargs], XtNlabel, description); iargs++;
 
130
  *labelW=XtCreateManagedWidget("label",labelWidgetClass,*viewportW,args, iargs);
 
131
  return(0);
 
132
}
 
133
 
 
134
  
 
135
/********************************************************
 
136
 * This function creates a listwidget inside a vieportwidget 
 
137
 *  and resizes the listwidget not to exceed max values 
 
138
 * [ the viewport will have the scrollbars ] 
 
139
 * the function return the two widgets and the width and height 
 
140
 * Reste un point obscur doit on fixer le with/height du viewport ou du list ?
 
141
 * parentW is the widget inside which the viewport/list is inserted 
 
142
 ********************************************************/
 
143
 
 
144
 
 
145
int ViewpListCreate(parentW,listW,viewportW,strings,nstr)
 
146
     Widget parentW;
 
147
     Widget *listW,*viewportW;
 
148
     char **strings;
 
149
     int nstr;
 
150
{
 
151
  iargs=0;
 
152
  /* create chooseviewport and chooselist widgets */
 
153
  *viewportW = XtCreateManagedWidget("listviewport",viewportWidgetClass,
 
154
                                         parentW,args,iargs);
 
155
  iargs = 0;
 
156
  XtSetArg(args[iargs], XtNlist, strings); iargs++;
 
157
  *listW=XtCreateManagedWidget("list",listWidgetClass,*viewportW,
 
158
                             args,iargs);
 
159
  return(0);
 
160
}
 
161
 
 
162
/********************************************************
 
163
 *
 
164
 * Computes the label Widget size of a label widget 
 
165
 * filled with a string of nchar per lines and nlines 
 
166
 ********************************************************/
 
167
 
 
168
int LabelSize(label,nchar,nlines,width,height)
 
169
     Widget label;
 
170
     int nchar,nlines;
 
171
     Dimension *width,*height;
 
172
{
 
173
  Dimension la_iheight=10 , la_iwidth=10;
 
174
  XFontStruct *temp_font = (XFontStruct *) NULL;
 
175
  iargs=0;
 
176
  XtSetArg(args[iargs],XtNfont, &temp_font);  iargs++;
 
177
  XtSetArg(args[iargs],XtNinternalHeight, &la_iheight);  iargs++;
 
178
  XtSetArg(args[iargs],XtNinternalWidth, &la_iwidth);  iargs++;
 
179
  XtGetValues(label, args, iargs);
 
180
  *height = nlines*(char_height(temp_font) + 0)+ (int) 2*la_iheight + ScrThickness ;
 
181
  *width  = nchar*Max(char_width(temp_font),1) + (int) 2*la_iwidth  + ScrThickness;
 
182
  return(0);
 
183
}
 
184
 
 
185
/********************************************************
 
186
 *Computes the ascii Widget size of an ascii widget 
 
187
 * filled with a string of nchar per lines and nlines 
 
188
 * with restriction on lines and cols 
 
189
 ********************************************************/
 
190
 
 
191
int AsciiSize(ascii,nchar,nlines,width,height)
 
192
     Widget ascii;
 
193
     int nchar,nlines;
 
194
     Dimension *width,*height;
 
195
{
 
196
  Dimension rmarg,lmarg,topmarg,botmarg;
 
197
  XFontStruct *temp_font = (XFontStruct *) NULL;
 
198
  iargs=0;
 
199
  XtSetArg(args[iargs],XtNfont, &temp_font);  iargs++;
 
200
  XtSetArg(args[iargs],XtNrightMargin, &rmarg);  iargs++;
 
201
  XtSetArg(args[iargs],XtNleftMargin, &lmarg);  iargs++;
 
202
  XtSetArg(args[iargs],XtNtopMargin, &topmarg);  iargs++;
 
203
  XtSetArg(args[iargs],XtNbottomMargin, &botmarg);  iargs++;
 
204
  XtGetValues(ascii, args, iargs);
 
205
  *height=Min(nlines,MAXASCLINE)*(char_height(temp_font)+0) + topmarg+botmarg + ScrThickness;
 
206
  *width=Min(nchar,MAXASCCOLS)*Max(char_width(temp_font),1) + rmarg+lmarg + ScrThickness;
 
207
  return(0);
 
208
}
 
209
 
 
210
/********************************************************
 
211
 * Set a lable widget label and size : size is greater 
 
212
 *  than the size needed by str 
 
213
 ********************************************************/
 
214
 
 
215
 
 
216
int SetLabel(label,str,width,height)
 
217
     Widget label;
 
218
     char str[];
 
219
     Dimension width,height;
 
220
{
 
221
  iargs=0;
 
222
  XtSetArg(args[iargs], XtNwidth ,width) ; iargs++;
 
223
  XtSetArg(args[iargs], XtNheight ,height) ; iargs++;
 
224
  XtSetArg(args[iargs], XtNlabel ,str) ; iargs++;
 
225
  XtSetValues(label, args, iargs);
 
226
  return(0);
 
227
}
 
228
 
 
229
/********************************************************
 
230
 * Set an ascii Widget strin and size 
 
231
 ********************************************************/
 
232
 
 
233
int SetAscii(ascii,str,width,height)
 
234
     Widget ascii;
 
235
     char str[];
 
236
     Dimension width,height;
 
237
{
 
238
  iargs=0;
 
239
  XtSetArg(args[iargs], XtNwidth ,width) ; iargs++;
 
240
  XtSetArg(args[iargs], XtNheight ,height) ; iargs++;
 
241
  XtSetArg(args[iargs], XtNstring ,str) ; iargs++;
 
242
  XtSetValues(ascii, args, iargs);
 
243
  return(0);
 
244
}
 
245