File: wmen_choice.c

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (359 lines) | stat: -rw-r--r-- 10,327 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/* Copyright ENPC */
/* wmchoice1.c
 * Scilab 
 *   Jean-Philippe Chancelier 
 *   Bugs and mail : Scilab@ENPC.fr 
 */

#include "wmen_scilab.h"

#ifdef WIN32
#include "../os_specific/win_mem_alloc.h" /* MALLOC */
#else
#include "../os_specific/sci_mem_alloc.h" /* MALLOC */
#endif

/* Function prototypes */
static void FillInPropertyPage( PROPSHEETPAGE* , int, LPSTR, DLGPROC);
static int  GetVal(HWND hDlg,int i,int j);


/* WARNING: it's not enough to change the following
 * define in order to increase the number of possible items 
 */

#define NPAGESMAX 10
#define NITEMMAXPAGE 3 

typedef struct {
  int  NItPg[NPAGESMAX];  /* Number of Items in page i; */
  int  NPages;            /* Number of Pages  */
  int  CPage;             /* The number of current page **/
  int  nv;                /** number of items **/
  int  ierr;
  char *label;
}  MChoice ;

static MChoice SciMChoice;        /** used to stored the MChoice data **/
#define MAX_STR MAX_PATH

int SciChoiceI(label,defval,nitems)
     char *label;
     int defval[], nitems;
{
  int rep,i;
  SciMChoice.nv = nitems;
  SciMChoice.ierr=0;
  SciMChoice.label = label;
  rep=mChoiceWindow();
  if (  rep == TRUE ) 
    {
      for ( i=0 ; i < nitems ; i++) 
	{
	  /*sciprint("Item %d choix %d\r\n",i+1,  
	    Everything[i]->choice.default_toggle +1); */
	  defval[i]= Everything[i]->choice.default_toggle +1;
	}
      return(TRUE);
    }
  else
    return(FALSE);
}

/****************************************************
 *   SciChoiceCreate(items,defval,nitems) 
 *   This fuction is used to create the required SciStuff  
 *   Object in order to call create_choices  
 *   from a simpler data structure in order to be able  
 *   to communicate with Scilab  
 *   char*  items[] = {     "Label1",      "choice1",      "choice2",...,NULL, 
 *                          "Label2",      "choice1",      "choice2",...,NULL} 
 *   les valeurs par defaut sont numerotes a partir de 1  
 *   int  defval[]={1,2,3,....} 
 *   nitems : number of labels 	 
 *   En sortie defval contient ce qu'on a choisit  
 ****************************************************/

int 
SciChoiceCreate(items,defval,nitems)
     char **items;
     int defval[];
     int nitems;
{
  int i,j;
  if ( Everything != (SciStuff **) NULL) 
    {
      /** someone is using toggles at the same time */
      return(-1);
    }
  Everything= (SciStuff **) MALLOC( (nitems+1)*sizeof(SciStuff *));
  if ( Everything == (SciStuff **) NULL) return(0);
  Everything[nitems]= (SciStuff *) NULL;
  for ( i=0 ; i < nitems ; i++) 
    {
      char **loc= items ;
      int numch=0;
      while ( *loc != (char *) NULL) { loc++;numch++; };
      numch--;
      if ( numch == 0) 
	{
	  sciprint("x_choices : There's no choice to the %d item\r\n",i);
	  return(0);
	};
      Everything[i]= (SciStuff *) MALLOC( sizeof(SciStuff));
      if ( Everything[i] == (SciStuff *) NULL) 
	{
	  return(0);
	}
      if ( AllocAndCopy(&(Everything[i]->choice.name),items[0]) == 0) 
	{
	  return(0);
	}
      if ( AllocAndCopy(&(Everything[i]->choice.text),items[0]) == 0) 
	{
	  return(0);
	}
      Everything[i]->choice.num_toggles= numch;
      Everything[i]->choice.default_toggle = Min(Max(0,defval[i]-1),numch-1);
      Everything[i]->data = (SciData *) MALLOC( numch*sizeof(SciData));
      if ( Everything[i]->data == (SciData *) NULL) 
	{
	  return(0);
	}
      for ( j = 0 ; j < numch ; j++) 
	{
	  char loc[8];
	  SciData *dataloc = Everything[i]->data ;
	  if ( AllocAndCopy(&(dataloc[j].name),items[j+1]) == 0) 
	    {
	      return(0);
	    }
	  sprintf(loc,"%d %d",i,j);
	  if ( AllocAndCopy(&(dataloc[j].cbinfo),loc) == 0) 
	    {
	      return(0);
	    }
	}
      items = items + numch+2;
    }
  return(1);
}



int AllocAndCopy(strh1,str2)
     char **strh1, *str2;
{
  *strh1= (char *) MALLOC((strlen(str2)+1)*sizeof(char));
  if ( *strh1 == (char *) NULL) return(0);
  strcpy(*strh1,str2);
  return(1);
}


int SciChoiceFree(int nitems) 
{
  int i,j;
  for ( i=0 ; i < nitems ; i++) 
    {
      for (j = 0 ; j < Everything[i]->choice.num_toggles ; j++) 
	{
	  SciData *dataloc = Everything[i]->data ;
	  FREE(dataloc[j].name);
	  FREE(dataloc[j].cbinfo);
	}
      FREE(Everything[i]->data) ;
      FREE(Everything[i]->choice.name);
      FREE(Everything[i]->choice.text);
    }
  FREE(Everything);
  Everything = NULL;
  return(0);
}


/**************************************
 *  FUNCTION: MChoicePage(HWND, UINT, UINT, LONG)
 *  PURPOSE:  Processes messages for "Your Information" page 
 *  MESSAGES:
 *	
 *	WM_INITDIALOG - intializes the page
 *	WM_NOTIFY - processes the notifications sent to the page
 **************************************/

static BOOL APIENTRY MChoicePage(HWND hDlg,UINT message,UINT wParam,LONG lParam)
{
  int i,j;
  switch (message)
    {
    case WM_INITDIALOG:
      for ( i=0 ; i < SciMChoice.NItPg[SciMChoice.CPage] ; i++ )
	{
	  SetDlgItemText(hDlg, IDE_MDTEXT1+i, 
			 Everything[SciMChoice.CPage*NITEMMAXPAGE+i]->choice.name);
	  for ( j=0 ; j < Everything[SciMChoice.CPage*NITEMMAXPAGE+i]->choice.num_toggles; j++ ) 
	    SendDlgItemMessage(hDlg,IDE_MD1+i , CB_ADDSTRING, 0, 
			       (LPARAM)((LPSTR) Everything[SciMChoice.CPage*NITEMMAXPAGE+i]->data[j].name));
	  SendDlgItemMessage(hDlg,IDE_MD1+i , CB_SETCURSEL, 
			     (LPARAM)((LPSTR) Everything[SciMChoice.CPage*NITEMMAXPAGE+i]->choice.default_toggle) ,
			     0L);
	}
      SetDlgItemText(hDlg, IDE_MDTIT, SciMChoice.label);
      break;
      /** sans effets pour l''instant 
    case WM_DRAWITEM:
      {
	  LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
	  DrawIcon(lpdis->hDC, 0, 0, 
	  (HICON)GetClassLong(GetParent(hDlg), GCL_HICON));
      }
      break;
	  **/
    case WM_NOTIFY:
      switch (((NMHDR FAR *) lParam)->code) 
	{
	case PSN_KILLACTIVE:
	  SetWindowLong(hDlg,	DWL_MSGRESULT, FALSE);
	  return 1;
	  break;
	case PSN_RESET:
	  /** cancel **/
	  SetWindowLong(hDlg,	DWL_MSGRESULT, FALSE);
	  break;
	case PSN_SETACTIVE:
	  if ( SciMChoice.CPage == 0 ) 
	    PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_NEXT);
	  if ( SciMChoice.CPage > 0 && SciMChoice.CPage < SciMChoice.NPages -1 ) 
	    PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_NEXT);
	  if ( SciMChoice.CPage == SciMChoice.NPages -1 && SciMChoice.CPage != 0 )
	    PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_FINISH);
	  if ( SciMChoice.CPage == SciMChoice.NPages -1 && SciMChoice.CPage == 0 )
	    PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_FINISH);
	  SendMessage(GetDlgItem(hDlg,0x3024 ), BM_SETSTYLE, (WPARAM)BS_PUSHBUTTON, MAKELONG(FALSE, 0));

	  /** Je ne sais pas pourquoi mais ce qui suit fait que le dernier menu est mal mis a jour 
	    avec gcwin32 avec VC++ ca marche : J'ai donc comment'e ce qui suit 
	    et mis le meme code plus haut au initdialog 
	    j'espere que ca ne fout pas la merde SciMChoice.CPageXXXXXX
	  for ( i =0 ; i < SciMChoice.NItPg[SciMChoice.CPage] ; i++)
	    SendMessage(GetDlgItem(hDlg, (IDE_MD1+i)), WM_SETTEXT, 0, 
			(LPARAM)SciMChoice.pszName[SciMChoice.CPage*NITEMMAXPAGE+i]);

	    **/
	  break;
	case PSN_WIZBACK:
	  for ( i =0 ; i < SciMChoice.NItPg[SciMChoice.CPage] ; i++) 
	    {
	      if ( GetVal(hDlg,i, SciMChoice.CPage*NITEMMAXPAGE+i) == 0) 
		SetWindowLong(hDlg,	DWL_MSGRESULT, FALSE);
	    }
	  SciMChoice.CPage--;
	  break;
	case PSN_WIZNEXT:
	  for ( i =0 ; i < SciMChoice.NItPg[SciMChoice.CPage] ; i++) 
	    {
	      if ( GetVal(hDlg,i, SciMChoice.CPage*NITEMMAXPAGE+i) == 0) 
		SetWindowLong(hDlg,	DWL_MSGRESULT, FALSE);
	    }
	  SciMChoice.CPage++;
	  break;
	case PSN_WIZFINISH:
	  for ( i =0 ; i < SciMChoice.NItPg[SciMChoice.CPage] ; i++) 
	    {
	      if ( GetVal(hDlg,i, SciMChoice.CPage*NITEMMAXPAGE+i) == 0) 
		SetWindowLong(hDlg,	DWL_MSGRESULT, FALSE);
	    }
	  break;
	default:
	  return FALSE;
    	}
      break;
    default:
      return FALSE;
    }
  return TRUE;   
}

/***/

static int GetVal(HWND hDlg,int i,int j)
{
  Everything[j]->choice.default_toggle = (UINT)SendDlgItemMessage(hDlg, (IDE_MD1+i), CB_GETCURSEL, 0, 0L);
  return(1);
}


/**************************************
 *  FUNCTION: FillInPropertyPage(PROPSHEETPAGE *, int, LPSTR, LPFN) 
 *  PURPOSE: Fills in the given PROPSHEETPAGE structure 
 *  COMMENTS:
 *      This function fills in a PROPSHEETPAGE structure with the
 *      information the system needs to create the page.
 **************************************/

static void FillInPropertyPage( PROPSHEETPAGE* psp, int idDlg, LPSTR pszProc, DLGPROC pfnDlgProc)
{
  psp->dwSize = sizeof(PROPSHEETPAGE);
  psp->dwFlags = 0;
  psp->hInstance =  hdllInstance;
#ifdef __GNUC__XXX
  psp->u1.pszTemplate = MAKEINTRESOURCE(idDlg);
  psp->u2.pszIcon = NULL;
#else 
  psp->pszTemplate = MAKEINTRESOURCE(idDlg);
  psp->pszIcon = NULL;
#endif
  psp->pfnDlgProc = pfnDlgProc;
  psp->pszTitle = pszProc;
  psp->lParam = 0;
}

/**************************************
 *    FUNCTION:   mChoiceWindow();
 * WARNING Th calling function must check 
 * the maximum number of pages 
 **************************************/

int mChoiceWindow(void)
{
  int i,lastitems;
  PROPSHEETPAGE psp[NPAGESMAX];
  PROPSHEETHEADER psh;
  HWND hwndOwner;
  if ( (hwndOwner = GetActiveWindow()) == NULL) 
    hwndOwner =  textwin.hWndParent;
  SciMChoice.NPages = SciMChoice.nv /  NITEMMAXPAGE;
  for ( i = 0 ; i < SciMChoice.NPages ; i++) 
    {
      SciMChoice.NItPg[i]= NITEMMAXPAGE;
      FillInPropertyPage( &psp[i], IDD_MCHOICE3, TEXT("Scilab Dialog"),
			  (DLGPROC) MChoicePage );
    }
  /** Items in the last page **/
  lastitems =  SciMChoice.nv % NITEMMAXPAGE;
  if ( lastitems != 0 ) 
    {
      SciMChoice.NPages++;
      SciMChoice.NItPg[SciMChoice.NPages-1]= lastitems ;
      FillInPropertyPage( &psp[SciMChoice.NPages-1], IDD_MCHOICE1+lastitems-1, 
			  TEXT("Scilab Dialog"), 
			  (DLGPROC)  MChoicePage);
    }
  SciMChoice.CPage = 0; 
  psh.dwSize = sizeof(PROPSHEETHEADER);
  psh.dwFlags = PSH_PROPSHEETPAGE | PSH_WIZARD | PSH_NOAPPLYNOW;
  psh.hwndParent = hwndOwner;
  psh.pszCaption = (LPSTR) TEXT("Review Wizard");
  psh.nPages = SciMChoice.NPages;
#ifdef __GNUC__XXX
  psh.u2.nStartPage = SciMChoice.CPage;
  psh.u3.ppsp = (LPCPROPSHEETPAGE) &psp;
#else 
  psh.nStartPage = SciMChoice.CPage;
  psh.ppsp = (LPCPROPSHEETPAGE) &psp;
#endif
  return (PropertySheet(&psh));
}