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

« back to all changes in this revision

Viewing changes to routines/menusX/xmen_dialog.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
/*******************************************************
 
5
 * XWindow part for dialog 
 
6
 *******************************************************/
 
7
 
 
8
extern void ShellFormCreate();
 
9
extern void C2F(cvstr)();
 
10
static  int ok_Flag_sci; 
 
11
int DialogWindow();
 
12
 
 
13
extern char *dialog_str ;
 
14
extern SciDialog ScilabDialog;
 
15
 
 
16
static XtCallbackProc DialogOk();
 
17
static XtCallbackProc DialogCancel();
 
18
 
 
19
 
 
20
/**********************************************************
 
21
 * The dialog command OK callback 
 
22
 **********************************************************/
 
23
 
 
24
static XtCallbackProc DialogOk(w, client_data, call_data) 
 
25
     Widget w;
 
26
     XtPointer client_data, call_data;  
 
27
 
28
  Arg args[1];
 
29
  Cardinal iargs=0;
 
30
  Widget dialog = (Widget) client_data;
 
31
  char *lstr;
 
32
  iargs=0;
 
33
  XtSetArg(args[iargs], XtNstring, &lstr);iargs++;
 
34
  XtGetValues( dialog, args, iargs);
 
35
  dialog_str=(char *) MALLOC( (strlen(lstr)+1)*(sizeof(char)));
 
36
  if (dialog_str != 0)
 
37
    { int ind ;
 
38
      strcpy(dialog_str,lstr);
 
39
      ind = strlen(dialog_str) - 1 ;
 
40
      if (dialog_str[ind] == '\n') dialog_str[ind] = '\0' ;
 
41
      ok_Flag_sci= 1;
 
42
    }
 
43
  else 
 
44
    {
 
45
      Scistring("Malloc : No more place");
 
46
      ok_Flag_sci= -1;
 
47
    }
 
48
  return(0);
 
49
 
 
50
}
 
51
 
 
52
/**********************************************************
 
53
 * The cancel command callback 
 
54
 **********************************************************/
 
55
 
 
56
static XtCallbackProc   DialogCancel(w,client_data,callData)
 
57
     Widget w;
 
58
     XtPointer client_data, callData;   
 
59
 
60
  ok_Flag_sci = -1;
 
61
  return(0);
 
62
}
 
63
 
 
64
/**********************************************************
 
65
 * Dialog Widget creation 
 
66
 **********************************************************/
 
67
 
 
68
int  DialogWindow()
 
69
{
 
70
  Dimension height,top,bot;
 
71
  int lines =1 ;
 
72
  char *p;
 
73
  Arg args[10];
 
74
  Cardinal iargs = 0;
 
75
  Widget shell,dialog,dialogpanned,label,okbutton,wid,labelviewport,cform;
 
76
  static Display *dpy = (Display *) NULL;
 
77
  
 
78
  ShellFormCreate("dialogShell",&shell,&dialogpanned,&dpy);
 
79
  
 
80
  /* Create a Viewport+Label and resize it */
 
81
  
 
82
  ViewpLabelCreate(dialogpanned,&label,&labelviewport,ScilabDialog.description);
 
83
  
 
84
  iargs=0;
 
85
  XtSetArg(args[iargs], XtNstring ,ScilabDialog.init) ; iargs++;
 
86
  dialog = XtCreateManagedWidget("ascii",asciiTextWidgetClass,dialogpanned, args, iargs);
 
87
  
 
88
  /** Changing the height of the widget **/
 
89
  p= ScilabDialog.init;
 
90
  while ( *p != '\0' ) { if ( *p == '\n' ) lines++;p++;};
 
91
 
 
92
  iargs=0;
 
93
  XtSetArg(args[iargs], XtNheight ,&height) ; iargs++;
 
94
  XtSetArg(args[iargs], XtNtopMargin ,&top) ; iargs++;
 
95
  XtSetArg(args[iargs], XtNbottomMargin ,&bot) ; iargs++;
 
96
  XtGetValues(dialog,args,iargs);  
 
97
  height -= (top+bot);
 
98
  height *= lines;
 
99
  height += (top+bot);
 
100
  iargs=0;
 
101
  XtSetArg(args[iargs], XtNheight ,height) ; iargs++;
 
102
  XtSetValues(dialog,args,iargs);  
 
103
 
 
104
 
 
105
  iargs=0;
 
106
  cform = XtCreateManagedWidget("cform",formWidgetClass,dialogpanned,args,iargs);
 
107
  
 
108
  ButtonCreate(cform,&okbutton,(XtCallbackProc)DialogOk,
 
109
               (XtPointer) dialog,ScilabDialog.pButName[0],"ok");
 
110
  ButtonCreate(cform,&wid,(XtCallbackProc)DialogCancel,
 
111
               (XtPointer) NULL,ScilabDialog.pButName[1],"cancel");
 
112
  
 
113
  XtMyLoop(shell,dpy,0,&ok_Flag_sci);
 
114
  if (ok_Flag_sci == -1)
 
115
    {
 
116
      return(FALSE);
 
117
    }
 
118
  else
 
119
    {
 
120
      return(TRUE);
 
121
    }
 
122
}
 
123
 
 
124
 
 
125