1 /*
2  * Motif
3  *
4  * Copyright (c) 1987-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22 */
23 /*
24  * HISTORY
25 */
26 #ifdef REV_INFO
27 #ifndef lint
28 static char rcsid[] = "$TOG: wsm_cb.c /main/8 1997/05/02 10:05:18 dbl $"
29 #endif
30 #endif
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <Xm/Xm.h>
34 #include <Xm/TextF.h>
35 #include <Xm/Text.h>
36 #include <Xm/List.h>
37 #include <Xm/ToggleB.h>
38 #include <Xm/PushB.h>
39 
40 #include "wsm.h"
41 #include "wsmStruct.h"
42 #include "wsm_ui.h"
43 #include "wsmDebug.h"
44 #include "xrmLib.h"
45 #include "wsm_cb.h"
46 #include "command_ui.h"
47 #include "wsm_create.h"
48 
49 extern Boolean wsm_shown;
50 extern Widget shell;
51 extern WSM_UI* wsm_ui;
52 extern Boolean connected;
53 extern Boolean mwm_gone;
54 extern Widget fromField;
55 extern Widget toField;
56 extern Space* all_space;
57 extern Space* current_space;
58 extern Space* space_list;
59 extern char *file_name;
60 
61 Boolean copy_mode = True;
62 
63 /**********************************************************************/
64 /*                        WSM Dialog Interface                       */
65 /**********************************************************************/
66 void
InitializeInterface(WSM_UI * wsm_ui)67 InitializeInterface(WSM_UI* wsm_ui)
68 {
69   int num_rooms = GetNumberSpaces();
70   int max_num_rooms = 20;
71 
72   wsm_ui->space_button = (Widget*) XtMalloc(max_num_rooms*sizeof(Widget));
73   wsm_ui->num_space_buttons = num_rooms;
74   wsm_ui->from_option_button = (Widget*) XtMalloc(max_num_rooms*sizeof(Widget));
75   wsm_ui->to_option_button = (Widget*)XtMalloc((max_num_rooms +1)*sizeof(Widget));
76   wsm_ui->from_space = NULL;
77   wsm_ui->to_space = NULL;
78 }
79 
80 void
HideWsm()81 HideWsm()
82 {
83     wsm_shown = False;
84     ShowWsmCommand();
85 /*  XtPopdown(XtParent(XtParent(wsm_ui->wsm_row_column)));*/
86   XtPopdown(XtParent(wsm_ui->configure_form));
87   XtPopdown(XtParent(wsm_ui->name_form));
88   XtPopdown(XtParent(wsm_ui->delete_form));
89   XtPopdown(XtParent(wsm_ui->save_as_form));
90   XtUnmapWidget(shell);
91 }
92 
93 
94 
95 void
ShowWsm()96 ShowWsm()
97 {
98     wsm_shown = True;
99     ShowWsmCommand();
100 /*  XtPopup(XtParent(XtParent(wsm_ui->wsm_row_column)),XtGrabNone);*/
101   XtMapWidget(shell);
102 }
103 
104 /**********************************************************************/
105 /*                       Workspace Panel                              */
106 /**********************************************************************/
107 
108 Widget
CreateWorkspacePanel(Widget shell,WSM_UI * wsm_ui,Boolean show_menu)109 CreateWorkspacePanel(Widget shell, WSM_UI* wsm_ui, Boolean show_menu)
110 {
111   Widget parent;
112   XmString xmstr;
113   int i;
114   Space *space;
115   parent = CreateWorkspacePanelBX(shell,wsm_ui, show_menu);
116 
117   space = space_list;
118   for (i = 0; space != NULL && i < wsm_ui->num_space_buttons; i++)
119     {
120       xmstr = XmStringCreateLtoR(space->name, XmSTRING_DEFAULT_CHARSET);
121       XtVaSetValues(wsm_ui->space_button[i],XmNlabelString,xmstr,NULL);
122       XmStringFree(xmstr);
123       space = space->next;
124     }
125   return parent;
126 }
127 
128 void
CreateNewSpaceButton(int i,char * name,WSM_UI * wsm_ui)129 CreateNewSpaceButton(int i, char *name, WSM_UI *wsm_ui)
130 {
131   int argcnt;
132   Arg args[15];
133   XmString xmstr;
134   int user_data = i+1;
135   argcnt = 0;
136   XtSetArg(args[argcnt], XmNindicatorSize, 20); argcnt++;
137   XtSetArg(args[argcnt], XmNspacing, 10); argcnt++;
138   XtSetArg(args[argcnt], XmNuserData, user_data); argcnt++;
139   XtSetArg(args[argcnt], XmNlabelString,
140 	   (xmstr=XmStringCreateLtoR(name,XmSTRING_DEFAULT_CHARSET))); argcnt++;
141   XtSetArg(args[argcnt], XmNrecomputeSize, True); argcnt++;
142   wsm_ui->space_button[i] = XtCreateWidget("pushButton",
143 					   xmToggleButtonWidgetClass,
144 					   wsm_ui->wsm_row_column,
145 					   args,
146 					   argcnt);
147   XmStringFree( xmstr );
148 
149   XtAddCallback(wsm_ui->space_button[i], XmNvalueChangedCallback,
150 		SendLeaveRoomCB, (XtPointer)wsm_ui);
151   XtManageChild(wsm_ui->space_button[i]);
152 
153 }
154 
155 
156 /* ARGSUSED */
157 void
SendLeaveRoomCB(Widget w,XtPointer client,XtPointer call)158 SendLeaveRoomCB(Widget w, XtPointer client, XtPointer call)
159 {
160   int wsm_index;
161   Space *space;
162   XmToggleButtonCallbackStruct *toggle_struct = (XmToggleButtonCallbackStruct*)call;
163 
164   XtVaGetValues(w,XmNuserData, &wsm_index,NULL);
165   if (connected && !mwm_gone)
166     {
167       if (toggle_struct->set)
168 	{
169 	  space = GetSpaceFromID(wsm_index -1);
170 	  if (space != NULL)
171 	    (void) SendLeaveRoom(space);
172 	}
173     }
174   if (mwm_gone && current_space != NULL)
175       XmToggleButtonSetState(wsm_ui->space_button[GetSpaceID(current_space)],True,True);
176 }
177 
178 /* ARGSUSED */
179 void
NewActivateCB(Widget w,XtPointer client,XtPointer call)180 NewActivateCB(Widget w, XtPointer client, XtPointer call)
181 {
182   static int i = 0;
183   char str[20];
184   WSM_UI *wsm_ui = (WSM_UI*)client;
185   Space *space;
186 
187   if (i == 0)
188     {
189       for (i = 1, space = space_list; space != NULL; i++, space = space->next);
190     }
191   sprintf(str,"Room%d",i++);
192   space = CreateSpace(XrmStringToQuark(str),str);
193   CreateNewSpaceButton(wsm_ui->num_space_buttons,str, wsm_ui);
194   CreateFromOptionButton(wsm_ui->num_space_buttons,str);
195   CreateToOptionButton(wsm_ui->num_space_buttons,str);
196 #ifndef _NO_CLIENT_COMMAND
197   AddSpaceCommand(space);
198 #endif
199   wsm_ui->num_space_buttons++;
200   UpdateSpaceList(wsm_ui->delete_list);
201   UpdateSpaceList(wsm_ui->name_list);
202   UpdateSpaceList(wsm_ui->background_list);
203 #ifndef _NO_OCCUPY_DIALOG
204   UpdateSpaceList(wsm_ui->occupy_list);
205 #endif
206 }
207 
208 /* ARGSUSED */
209 void
HideActivateCB(Widget w,XtPointer client,XtPointer call)210 HideActivateCB(Widget w, XtPointer client, XtPointer call)
211 {
212 
213   HideWsm();
214 
215 }
216 
217 /* ARGSUSED */
218 void
SaveActivateCB(Widget w,XtPointer client,XtPointer call)219 SaveActivateCB(Widget w, XtPointer client, XtPointer call)
220 {
221 
222   SendSaveWsm(file_name);
223 }
224 
225 
226 /* ARGSUSED */
227 void
ExitCB(Widget w,XtPointer client,XtPointer call)228 ExitCB(Widget w, XtPointer client, XtPointer call)
229 {
230 
231   ManageAllWindowsAndExit();
232 
233 }
234 
235 
236 /**********************************************************************/
237 /*                        WSM Configure CBs                           */
238 /**********************************************************************/
239 
240 
241 void
CreateFromOptionButton(int i,char * name)242 CreateFromOptionButton(int i, char *name)
243 {
244   int argcnt;
245   Arg args[15];
246   XmString xmstr;
247 
248   argcnt = 0;
249   XtSetArg(args[argcnt], XmNuserData, i+1); argcnt++;
250   XtSetArg(args[argcnt], XmNrecomputeSize, True); argcnt++;
251   XtSetArg(args[argcnt], XmNlabelString,
252 	   (xmstr=XmStringCreateLtoR(name, XmSTRING_DEFAULT_CHARSET))); argcnt++;
253   wsm_ui->from_option_button[i] = XtCreateWidget("fromWorkspace1Button",
254 						 xmPushButtonWidgetClass,
255 						 XtParent(wsm_ui->from_option_button[0]),
256 						 args,
257 						 argcnt);
258   XmStringFree( xmstr );
259 
260   XtAddCallback(wsm_ui->from_option_button[i], XmNactivateCallback,
261 		FromWorkspaceCB, (XtPointer)wsm_ui);
262   XtManageChild(wsm_ui->from_option_button[i]);
263 }
264 
265 
266 
267 void
CreateToOptionButton(int i,char * name)268 CreateToOptionButton(int i, char *name)
269 {
270   int argcnt;
271   Arg args[15];
272   XmString xmstr[2];
273 
274   xmstr[0] = XmStringCreateSimple(name);
275   XtVaSetValues(wsm_ui->to_option_button[i],
276 		XmNuserData, i+1,
277 		XmNlabelString, xmstr[0],
278 		NULL);
279 
280   XmStringFree(xmstr[0]);
281   argcnt = 0;
282   XtSetArg(args[argcnt], XmNuserData, 0); argcnt++;
283   XtSetArg(args[argcnt], XmNlabelString,
284 	   (xmstr[1]=XmStringCreateLtoR("All Workspaces", XmSTRING_DEFAULT_CHARSET))); argcnt++;
285   wsm_ui->to_option_button[i+1] = XtCreateWidget("fromWorkspace1Button",
286 						 xmPushButtonWidgetClass,
287 						 XtParent(wsm_ui->to_option_button[0]),
288 						 args,
289 						 argcnt);
290   XmStringFree( xmstr[1] );
291 
292   XtAddCallback(wsm_ui->to_option_button[i+1], XmNactivateCallback,
293 		ToWorkspaceCB, (XtPointer)wsm_ui);
294   XtManageChild(wsm_ui->to_option_button[i+1]);
295 }
296 
297 void
UpdateList(Widget list,Space * s)298 UpdateList(Widget list,Space *s)
299 {
300 
301  char *str;
302  XmString xmstr;
303  WorkWindowList *w_list;
304 
305  w_list = s->w_list;
306 
307 
308  XmListDeleteAllItems(list);
309  while (w_list != NULL)
310    {
311      if (_WSMGetConfigFormatType(w_list->work_win->window) == WSM_WINDOW_FMT)
312        {
313 	 str = (char*) XtMalloc((strlen(w_list->work_win->name) + 15) * sizeof(char));
314 	 sprintf(str,"0x%x %s",(unsigned)w_list->work_win->window, w_list->work_win->name);
315 
316 	 xmstr = XmStringCreateLocalized(str);
317 	 XmListAddItemUnselected(list,xmstr,0);
318 	 XmStringFree(xmstr);
319 	 XtFree(str);
320        }
321      w_list = w_list->next;
322    }
323 
324 }
325 
326 void
UpdateBothList(Space * s)327 UpdateBothList(Space *s)
328 {
329   if(connected)
330     {
331       if (wsm_ui->from_space == s)
332 	UpdateList(wsm_ui->from_list,s);
333       if (wsm_ui->to_space == s)
334 	UpdateList(wsm_ui->to_list,s);
335     }
336 }
337 
338 
339 
340 void
UpdateButtons(WorkWindow * w_window)341 UpdateButtons(WorkWindow *w_window)
342 {
343   if (w_window == wsm_ui->w_window)
344     {
345       if (w_window->linked)
346 	XmToggleButtonSetState(wsm_ui->link_toggle,True,True);
347       else
348 	XmToggleButtonSetState(wsm_ui->copy_toggle,True,True);
349       if (w_window->s_list->next == NULL || w_window->window == 0 ||
350 	  _WSMGetConfigFormatType(w_window->window) == WSM_ICON_FMT)
351 	XtVaSetValues(wsm_ui->delete_button,XmNsensitive,False,NULL);
352       else
353 	XtVaSetValues(wsm_ui->delete_button,XmNsensitive,True,NULL);
354       if (w_window->window == 0 ||
355 	  _WSMGetConfigFormatType(w_window->window) == WSM_ICON_FMT ||
356 	  wsm_ui->to_space == all_space)
357 	XtVaSetValues(wsm_ui->move_button,XmNsensitive,False,NULL);
358       else
359 	XtVaSetValues(wsm_ui->move_button,XmNsensitive,True,NULL);
360     }
361 }
362 
363 void
CreateConfigureCB(Widget w,XtPointer client,XtPointer call)364 CreateConfigureCB(Widget w, XtPointer client, XtPointer call)
365 {
366   WSM_UI *wsm_ui = (WSM_UI*)client;
367   int space_id = -1;
368   if (connected )
369     {
370       if (wsm_ui->from_space == NULL && wsm_ui->to_space == NULL)
371 	{
372 	    wsm_ui->from_space = current_space;
373 	    wsm_ui->to_space = current_space;
374 	    UpdateBothList(current_space);
375 	    space_id = GetSpaceID(current_space);
376 	    if (space_id != -1)
377 	      {
378 		XtVaSetValues(wsm_ui->from_option_menu,
379 			      XmNmenuHistory, wsm_ui->from_option_button[space_id],
380 			      NULL);
381 		XtVaSetValues(wsm_ui->to_option_menu,
382 			      XmNmenuHistory, wsm_ui->to_option_button[space_id],
383 			      NULL);
384 	      }
385 	}
386     }
387   XtManageChild(wsm_ui->configure_form);
388   XtPopup(XtParent(wsm_ui->configure_form), XtGrabNone);
389 
390 }
391 
392 /* ARGSUSED */
393 void
MoveCB(Widget w,XtPointer client,XtPointer call)394 MoveCB(Widget w, XtPointer client, XtPointer call)
395 {
396   int pos_count = 0;
397   int *pos_list;
398   int i;
399 			WorkWindow *w_window;
400   WSM_UI *wsm_ui = (WSM_UI*)client;
401 
402   if (XmListGetSelectedPos(wsm_ui->from_list,&pos_list, &pos_count))
403     {
404       for (i = 0; i < pos_count; i++)
405 	{
406 	  w_window = GetWorkWindowID(wsm_ui->from_space,pos_list[i]-1);
407 	  if (w_window != NULL)
408 	    MoveWindow(w_window, wsm_ui->from_space, wsm_ui->to_space);
409 	}
410     }
411   if (pos_count > 0) XtFree((XtPointer)pos_list);
412 }
413 
414 
415 /* ARGSUSED */
416 void
DeleteCB(Widget w,XtPointer client,XtPointer call)417 DeleteCB(Widget w, XtPointer client, XtPointer call)
418 {
419   int pos_count = 0;
420   int *pos_list;
421   WorkWindow *w_window;
422   WSM_UI *wsm_ui = (WSM_UI*)client;
423 
424   if (XmListGetSelectedPos(wsm_ui->from_list,&pos_list, &pos_count))
425     {
426       w_window = GetWorkWindowID(wsm_ui->from_space,pos_list[0]-1);
427       if (w_window != NULL)
428 	DeleteWindow(w_window, wsm_ui->from_space);
429     }
430   if (pos_count > 0) XtFree((XtPointer)pos_list);
431 }
432 
433 
434 /* ARGSUSED */
435 void
ToWorkspaceCB(Widget w,XtPointer client,XtPointer call)436 ToWorkspaceCB(Widget w, XtPointer client, XtPointer call)
437 {
438   WSM_UI *wsm_ui = (WSM_UI*)client;
439   int room_num = 0;
440   Space *space;
441 
442   XtVaGetValues(w,XmNuserData,&room_num, NULL);
443   if (room_num != 0)
444       space = GetSpaceFromID(room_num-1);
445   else
446       space = all_space;
447   if (space != NULL)
448     {
449       wsm_ui->to_space = space;
450       UpdateList(wsm_ui->to_list,space);
451       if (space == all_space)
452 	XtVaSetValues(wsm_ui->move_button,XmNsensitive,False,NULL);
453       else
454 	XtVaSetValues(wsm_ui->move_button,XmNsensitive,True,NULL);
455     }
456   else PRINT("not found %d\n", room_num);
457 }
458 
459 /* ARGSUSED */
460 void
FromWorkspaceCB(Widget w,XtPointer client,XtPointer call)461 FromWorkspaceCB(Widget w, XtPointer client, XtPointer call)
462 {
463 
464   WSM_UI *wsm_ui = (WSM_UI*)client;
465   int room_num;
466   Space *space;
467 
468   XtVaGetValues(w,XmNuserData,&room_num, NULL);
469   space = GetSpaceFromID(room_num-1);
470   if (space != NULL)
471     {
472       wsm_ui->from_space = space;
473       UpdateList(wsm_ui->from_list,space);
474     }
475   else PRINT("Not Found %d\n", room_num);
476 
477 }
478 
479 void
Copy(WSM_UI * wsm_ui)480 Copy(WSM_UI* wsm_ui)
481 {
482   int pos_count = 0;
483   int *pos_list;
484   int i;
485   WorkWindow *w_window;
486   if (XmListGetSelectedPos(wsm_ui->from_list,&pos_list, &pos_count))
487     {
488 #ifdef DEBUG
489 /*      PRINT("%d copy %d from %s to %s\n", pos_count, pos_list[0], from_space, to_space);*/
490 #endif
491       for (i = 0; i < pos_count; i++)
492 	{
493 	  w_window = GetWorkWindowID(wsm_ui->from_space,pos_list[i] - 1);
494 	  if (w_window != NULL)
495 	    CopyWindow(w_window, wsm_ui->from_space,wsm_ui->to_space);
496 	}
497     }
498   if (pos_count > 0) XtFree((XtPointer)pos_list);
499 }
500 
501 void
Link(WSM_UI * wsm_ui)502 Link(WSM_UI* wsm_ui)
503 {
504   int pos_count = 0;
505   int *pos_list;
506   WorkWindow *w_window;
507   int i;
508   if (XmListGetSelectedPos(wsm_ui->from_list,&pos_list, &pos_count))
509     {
510 #ifdef DEBUG
511 /*      PRINT("%d copy %d from %s to %s\n", pos_count, pos_list[0], from_space, to_space);*/
512 #endif
513       for (i = 0; i < pos_count ; i++)
514 	{
515 	  w_window = GetWorkWindowID(wsm_ui->from_space, pos_list[i]-1);
516 	  if (w_window != NULL)
517 	    LinkWindow(w_window, wsm_ui->from_space, wsm_ui->to_space);
518 	}
519     }
520   if (pos_count > 0) XtFree((XtPointer)pos_list);
521 }
522 
523 /* ARGSUSED */
524 void
OccupyCB(Widget w,XtPointer client,XtPointer call)525 OccupyCB(Widget w, XtPointer client,XtPointer  call)
526 {
527   WSM_UI *wsm_ui = (WSM_UI*)client;
528   Boolean copy_set;
529   XtVaGetValues(wsm_ui->copy_toggle, XmNset,&copy_set,NULL);
530   if (copy_set)
531     Copy(wsm_ui);
532   else Link(wsm_ui);
533 }
534 
535 
536 
537 
538 void
WindowModeCB(Widget w,XtPointer client,XtPointer call)539 WindowModeCB(Widget w,XtPointer client,XtPointer call)
540 {
541   WSM_UI *wsm_ui = (WSM_UI*)client;
542   XtVaSetValues(wsm_ui->from_list,XmNselectionPolicy,XmSINGLE_SELECT,NULL);
543 }
544 
545 
546 
547 void
ClientModeCB(Widget w,XtPointer client,XtPointer call)548 ClientModeCB(Widget w,XtPointer client,XtPointer call)
549 {
550   WSM_UI *wsm_ui = (WSM_UI*)client;
551   XtVaSetValues(wsm_ui->from_list,XmNselectionPolicy,XmMULTIPLE_SELECT,NULL);
552 }
553 
554 
555 void
SelectFromListCB(Widget w,XtPointer client,XtPointer call)556 SelectFromListCB(Widget w,XtPointer client,XtPointer call)
557 {
558   WSM_UI *wsm_ui = (WSM_UI*)client;
559   int pos_count = 0;
560   int *pos_list;
561   WorkWindow *w_window;
562 
563   if (XmListGetSelectedPos(wsm_ui->from_list,&pos_list, &pos_count))
564     {
565       w_window = GetWorkWindowID(wsm_ui->from_space,pos_list[0]-1);
566       if (w_window != NULL)
567 	{
568 	  wsm_ui->w_window = w_window;
569 	  UpdateButtons(w_window);
570 	}
571     }
572   if (pos_count > 0) XtFree((XtPointer)pos_list);
573 }
574 
575 
576 
577 
578 void
MultSelectFromListCB(Widget w,XtPointer client,XtPointer call)579 MultSelectFromListCB(Widget w,XtPointer client,XtPointer call)
580 {
581   WSM_UI *wsm_ui = (WSM_UI*)client;
582   XmListCallbackStruct *list_call = (XmListCallbackStruct *)call;
583   int pos_count = 0;
584   int *pos_list;
585   WorkWindow *w_window;
586   int *select_ids;
587   int num_select;
588   int i;
589   int item_pos = list_call->item_position;
590   Boolean doit = False;
591   PRINT("item pos %d\n",item_pos);
592 
593   w_window = GetWorkWindowID(wsm_ui->from_space,item_pos-1);
594   if (w_window != NULL)
595     {
596       wsm_ui->w_window = w_window;
597       UpdateButtons(w_window);
598       GetWorkWindowClientIDs(item_pos-1, wsm_ui->from_space,&select_ids,&num_select);
599 
600       if (XmListGetSelectedPos(wsm_ui->from_list,&pos_list, &pos_count))
601 	{
602 	  for (i = 0; i < pos_count; i++)
603 	    {
604 	      if (pos_list[i] == item_pos)
605 		doit = True;
606 	    }
607 	  if (doit)
608 	    for (i = 0; i < pos_count; i++)
609 	      {
610 		if (pos_list[i] != item_pos)
611 		  XmListDeselectPos(wsm_ui->from_list,pos_list[i]);
612 	      }
613 	}
614       if (num_select > 0)
615 	{
616 	  for (i = 0; i < num_select; i++)
617 	    {
618 	      if (select_ids[i] != item_pos -1)
619 		{
620 		  XmListSelectPos(w,select_ids[i] +1,False);
621 		}
622 	    }
623 	}
624       if (pos_count > 0) XtFree((XtPointer)pos_list);
625     }
626 }
627 
628 
629 
630 void
SelectToListCB(Widget w,XtPointer client,XtPointer call)631 SelectToListCB(Widget w, XtPointer client,XtPointer call)
632 {
633   WSM_UI *wsm_ui = (WSM_UI*)client;
634   int pos_count = 0;
635   int *pos_list;
636 
637 /*  XmListDeselectAllItems(wsm_ui->to_list);*/
638 
639   if (XmListGetSelectedPos(wsm_ui->to_list,&pos_list, &pos_count))
640     {
641       XmListDeselectPos(wsm_ui->to_list,pos_list[0]);
642     }
643   if (pos_count > 0) XtFree((XtPointer)pos_list);
644 }
645 
646 
647 
648 /* ARGSUSED */
649 void
DismissConfigureCB(Widget w,XtPointer client,XtPointer call)650 DismissConfigureCB(Widget w,XtPointer  client, XtPointer call)
651 {
652 
653   WSM_UI *wsm_ui = (WSM_UI*)client;
654 
655    XtPopdown(XtParent(wsm_ui->configure_form));
656 }
657 
658 /**********************************************************************/
659 /*                        WSM Name Workspace CBs                      */
660 /**********************************************************************/
661 
662 /* ARGSUSED */
663 void
CreateNameCB(Widget w,XtPointer client,XtPointer call)664 CreateNameCB(Widget w, XtPointer client, XtPointer call)
665 {
666 
667   WSM_UI *wsm_ui = (WSM_UI*)client;
668 
669   if (connected )
670     {
671       UpdateSpaceList(wsm_ui->name_list);
672     }
673 
674   XtManageChild(wsm_ui->name_form);
675   XmListSelectPos(wsm_ui->name_list,1,True);
676 
677   XtPopup(XtParent(wsm_ui->name_form), XtGrabNone);
678 
679 }
680 
681 
682 void
UpdateSpaceList(Widget list)683 UpdateSpaceList(Widget list)
684 {
685   XmString xmstr;
686   Space *s = space_list;
687 
688   XmListDeleteAllItems(list);
689   while (s != NULL)
690    {
691      xmstr = XmStringCreateLtoR(s->name, XmSTRING_DEFAULT_CHARSET);
692      XmListAddItem(list,xmstr,0);
693      XmStringFree(xmstr);
694      s = s->next;
695    }
696 
697 }
698 
699 
700 void
SelectNameSpaceCB(Widget w,XtPointer client,XtPointer call)701 SelectNameSpaceCB(Widget w, XtPointer client, XtPointer call)
702 {
703   WSM_UI *wsm_ui = (WSM_UI*)client;
704   int pos_count = 0;
705   int *pos_list;
706   Space *space;
707 
708   if (XmListGetSelectedPos(wsm_ui->name_list,&pos_list, &pos_count))
709     {
710       space = GetSpaceFromID(pos_list[0]-1);
711       if (space != NULL)
712 	{
713 	  XmTextSetString(wsm_ui->name_text,space->name);
714 	  XmTextSetString(wsm_ui->pixmap_text,space->pixmap_name);
715 	}
716     }
717   if (pos_count > 0) XtFree((XtPointer)pos_list);
718 }
719 
720 
721 void
ChangeSpaceName(WSM_UI * wsm_ui,Space * space,int wsm_index)722 ChangeSpaceName(WSM_UI* wsm_ui,Space *space,int wsm_index)
723 {
724   XmString xmstr;
725 
726   xmstr = XmStringCreateLtoR(space->name, XmSTRING_DEFAULT_CHARSET);
727   XtVaSetValues(wsm_ui->space_button[wsm_index],XmNlabelString,xmstr,NULL);
728   XtVaSetValues(wsm_ui->from_option_button[wsm_index],XmNlabelString,xmstr,NULL);
729   XtVaSetValues(wsm_ui->to_option_button[wsm_index],XmNlabelString,xmstr,NULL);
730   XmStringFree(xmstr);
731   UpdateSpaceList(wsm_ui->name_list);
732   UpdateSpaceList(wsm_ui->delete_list);
733   UpdateSpaceList(wsm_ui->background_list);
734 #ifndef _NO_OCCUPY_DIALOG
735   UpdateSpaceList(wsm_ui->occupy_list);
736 #endif
737 
738 }
739 
740 /* ARGSUSED */
741 void
NameActivateCB(Widget w,XtPointer client,XtPointer call)742 NameActivateCB(Widget w, XtPointer client, XtPointer call)
743 {
744   XmProcessTraversal(wsm_ui->pixmap_text,XmTRAVERSE_CURRENT);
745 
746 }
747 
748 
749 /* ARGSUSED */
750 void
NameOkActivateCB(Widget w,XtPointer client,XtPointer call)751 NameOkActivateCB(Widget w, XtPointer client, XtPointer call)
752 {
753   WSM_UI *wsm_ui = (WSM_UI*)client;
754   Space *space;
755   int pos_count = 0;
756   int *pos_list;
757   char *old_name;
758   char *str;
759   if (XmListGetSelectedPos(wsm_ui->name_list,&pos_list, &pos_count))
760     {
761       space = GetSpaceFromID(pos_list[0]-1);
762       if (space != NULL)
763 	{
764 	  PRINT("change name for space %s\n",space->name);
765 	  old_name = (char*) XtMalloc(strlen((space->name) +1)*sizeof(char));
766 	  strcpy(old_name,space->name);
767 	  str = XmTextGetString(wsm_ui->name_text);
768 	  if (strlen(str) < MAX_LENGTH)
769 	    {
770 	      strcpy(space->name,str);
771 	      if (strcmp(old_name,space->name) != 0)
772 		{
773 		  PRINT("Change name to %s\n",space->name);
774 		  ChangeSpaceName(wsm_ui,space,pos_list[0]-1);
775 #ifndef _NO_CLIENT_COMMAND
776 		  ChangeSpaceCommandName(space);
777 #endif
778 		}
779 	    }
780 	  XtFree(str);
781 	  XtFree(old_name);
782 #ifndef _NO_PIXMAP
783 	  str = XmTextGetString(wsm_ui->pixmap_text);
784 	  if (strcmp(str,"None")!=0 && strcmp(str,"none") != 0 &&
785 	      strcmp(str,space->pixmap_name) != 0)
786 	    if (SetSpaceLabelPixmap(space,str))
787 	      {
788 		XtVaSetValues(wsm_ui->space_button[GetSpaceID(space)],
789 			      XmNlabelPixmap,space->pixmap_label,
790 			      XmNlabelType, XmPIXMAP,
791 			      NULL);
792 	      }
793 	  XtFree(str);
794 	  XmListSelectPos(wsm_ui->name_list,pos_list[0],True);
795 /*	  XtPopdown(XtParent(wsm_ui->name_form));*/
796 #endif
797 	}
798     }
799   if (pos_count > 0) XtFree((XtPointer)pos_list);
800 
801 }
802 
803 
804 
805 
806 /* ARGSUSED */
807 void
DismissNameCB(Widget w,XtPointer client,XtPointer call)808 DismissNameCB(Widget w, XtPointer client, XtPointer call)
809 {
810 
811   WSM_UI *wsm_ui = (WSM_UI*)client;
812    XtPopdown(XtParent(wsm_ui->name_form));
813 }
814 
815 
816 
817 
818 /**********************************************************************/
819 /*                        WSM Background Workspace CBs                      */
820 /**********************************************************************/
821 
822 /* ARGSUSED */
823 void
CreateBackgroundCB(Widget w,XtPointer client,XtPointer call)824 CreateBackgroundCB(Widget w, XtPointer client, XtPointer call)
825 {
826 
827   WSM_UI *wsm_ui = (WSM_UI*)client;
828 
829   if (connected )
830     {
831       UpdateSpaceList(wsm_ui->background_list);
832     }
833    XtManageChild(wsm_ui->background_form);
834   XmListSelectPos(wsm_ui->background_list,1,True);
835   XtPopup(XtParent(wsm_ui->background_form), XtGrabNone);
836 
837 }
838 
839 void
SelectBackgroundSpaceCB(Widget w,XtPointer client,XtPointer call)840 SelectBackgroundSpaceCB(Widget w, XtPointer client, XtPointer call)
841 {
842   WSM_UI *wsm_ui = (WSM_UI*)client;
843   int pos_count = 0;
844   int *pos_list;
845   Space *space;
846 
847   if (XmListGetSelectedPos(wsm_ui->background_list,&pos_list, &pos_count))
848     {
849       space = GetSpaceFromID(pos_list[0]-1);
850       if (space != NULL)
851 	{
852 	  XmTextSetString(wsm_ui->background_text,space->background);
853 	}
854     }
855   if (pos_count > 0) XtFree((XtPointer)pos_list);
856 }
857 
858 
859 /* ARGSUSED */
860 void
BackgroundActivateCB(Widget w,XtPointer client,XtPointer call)861 BackgroundActivateCB(Widget w, XtPointer client, XtPointer call)
862 {
863   Space *space;
864   int pos_count = 0;
865   int *pos_list;
866   char *str;
867   if (XmListGetSelectedPos(wsm_ui->background_list,&pos_list, &pos_count))
868     {
869       space = GetSpaceFromID(pos_list[0]-1);
870       if (space != NULL)
871 	{
872 	  str = XmTextGetString(wsm_ui->background_text);
873 /*	  SendChangeSpaceBackground(space);*/
874 	  if (str[0] != '"')
875 	    {
876 	      if (SetSpacePixel(space,str))
877 		{
878 		  XtVaSetValues(wsm_ui->space_button[GetSpaceID(space)],
879 				XmNbackground,space->pixel,
880 				XmNunselectColor,space->pixel,
881 				NULL);
882 		  if (space == current_space)
883 		    SetSpaceBackground(space);
884 		}
885 	    }
886 	  else
887 	    {
888 	      if (SetSpacePixmap(space,str+1))
889 		{
890 		  if (space == current_space)
891 		    SetSpaceBackground(space);
892 		}
893 	    }
894 	  XtFree(str);
895 	  XmListSelectPos(wsm_ui->background_list,pos_list[0],True);
896 /*	  XtPopdown(XtParent(wsm_ui->background_form));*/
897 	}
898     }
899   if (pos_count > 0) XtFree((XtPointer)pos_list);
900 
901 }
902 
903 
904 /* ARGSUSED */
905 void
DismissBackgroundCB(Widget w,XtPointer client,XtPointer call)906 DismissBackgroundCB(Widget w, XtPointer client, XtPointer call)
907 {
908 
909   WSM_UI *wsm_ui = (WSM_UI*)client;
910    XtPopdown(XtParent(wsm_ui->background_form));
911 }
912 
913 
914 /**********************************************************************/
915 /*                        WSM Delete Workspace CBs                    */
916 /**********************************************************************/
917 /* ARGSUSED */
918 void
CreateDeleteCB(Widget w,XtPointer client,XtPointer call)919 CreateDeleteCB(Widget w, XtPointer client, XtPointer call)
920 {
921  WSM_UI *wsm_ui = (WSM_UI*)client;
922 
923   if (connected )
924     {
925       UpdateSpaceList(wsm_ui->delete_list);
926     }
927 
928   XtManageChild(wsm_ui->delete_form);
929   XtPopup(XtParent(wsm_ui->delete_form), XtGrabNone);
930 }
931 
932 
933 /* ARGSUSED */
934 void
DismissDeleteCB(Widget w,XtPointer client,XtPointer call)935 DismissDeleteCB(Widget w, XtPointer client, XtPointer call)
936 {
937   WSM_UI *wsm_ui = (WSM_UI*)client;
938    XtPopdown(XtParent(wsm_ui->delete_form));
939 
940 }
941 
942 
943 /* ARGSUSED */
944 void
DeleteActivateCB(Widget w,XtPointer client,XtPointer call)945 DeleteActivateCB(Widget w, XtPointer client, XtPointer call)
946 {
947   Space *space;
948   int pos_count = 0;
949   int *pos_list;
950   int i;
951   WSM_UI *wsm_ui = (WSM_UI*)client;
952 
953   if (XmListGetSelectedPos(wsm_ui->delete_list,&pos_list, &pos_count))
954     {
955       space = GetSpaceFromID(pos_list[0]-1);
956       if (space != NULL)
957 	{
958 #ifndef _NO_CLIENT_COMMAND
959 	  RemoveSpaceCommand(pos_list[0]-1);
960 #endif
961 	  RemoveSpace(space);
962 	  XtDestroyWidget(wsm_ui->space_button[pos_list[0]-1]);
963 	  XtDestroyWidget(wsm_ui->from_option_button[pos_list[0]-1]);
964 	  XtDestroyWidget(wsm_ui->to_option_button[pos_list[0]-1]);
965 	  for (i = pos_list[0]-1; i < wsm_ui->num_space_buttons-1; i++)
966 	    {
967 	      wsm_ui->space_button[i] = wsm_ui->space_button[i+1];
968 	      XtVaSetValues(wsm_ui->space_button[i], XmNuserData,i+1,NULL);
969 	      wsm_ui->from_option_button[i] = wsm_ui->from_option_button[i+1];
970 	      XtVaSetValues(wsm_ui->from_option_button[i],XmNuserData,i+1,NULL);
971 	      wsm_ui->to_option_button[i] = wsm_ui->to_option_button[i+1];
972 	      XtVaSetValues(wsm_ui->to_option_button[i],XmNuserData,i+1,NULL);
973 	    }
974 	  wsm_ui->to_option_button[i] = wsm_ui->to_option_button[i+1];
975 	  wsm_ui->num_space_buttons--;
976 	  UpdateSpaceList(wsm_ui->delete_list);
977 	  UpdateSpaceList(wsm_ui->name_list);
978 	  UpdateSpaceList(wsm_ui->background_list);
979 #ifndef _NO_OCCUPY_DIALOG
980 	  UpdateSpaceList(wsm_ui->occupy_list);
981 #endif
982 	}
983     }
984   if (pos_count > 0) XtFree((XtPointer)pos_list);
985 }
986 
987 
988 
989 
990 
991 
992 void
SelectDeleteCB(Widget w,XtPointer client,XtPointer call)993 SelectDeleteCB(Widget w, XtPointer client, XtPointer call)
994 {
995   WSM_UI *wsm_ui = (WSM_UI*)client;
996   int pos_count = 0;
997   int *pos_list;
998   Space *space;
999   WorkWindowList *w_list;
1000 
1001   if (XmListGetSelectedPos(wsm_ui->delete_list,&pos_list, &pos_count))
1002     {
1003       space = GetSpaceFromID(pos_list[0]-1);
1004       if (space != NULL)
1005 	{
1006 	  w_list = space->w_list;
1007 	  while (w_list != NULL)
1008 	    {
1009 	      if (w_list->work_win->s_list->next == NULL)
1010 		{
1011 		  XtVaSetValues(wsm_ui->ok_button,XmNsensitive,False,NULL);
1012 		  return;
1013 		}
1014 	      w_list = w_list->next;
1015 	    }
1016 	  XtVaSetValues(wsm_ui->ok_button,XmNsensitive,True,NULL);
1017 	}
1018     }
1019   if (pos_count > 0) XtFree((XtPointer)pos_list);
1020 }
1021 
1022 
1023 /**********************************************************************/
1024 /*                        Save As CBs                      */
1025 /**********************************************************************/
1026 
1027 
1028 void
SaveAsCB(Widget w,XtPointer client,XtPointer call)1029 SaveAsCB(Widget w, XtPointer client, XtPointer call)
1030 {
1031   WSM_UI *wsm_ui = (WSM_UI*)client;
1032 
1033    XtManageChild(wsm_ui->save_as_form);
1034   XtPopup(XtParent(wsm_ui->save_as_form),XtGrabNone);
1035 }
1036 
1037 /* ARGSUSED */
1038 void
SaveAsOkCB(Widget w,XtPointer client,XtPointer call)1039 SaveAsOkCB(Widget w, XtPointer client, XtPointer call)
1040 {
1041   WSM_UI *wsm_ui = (WSM_UI*)client;
1042   int new_length;
1043   char *new_file_name;
1044   char *home_name;
1045   new_file_name = XmTextGetString(wsm_ui->save_as_text);
1046   if (strcmp(new_file_name,"")!= 0)
1047     {
1048       if (new_file_name[0] != '/')
1049 	{
1050 	  home_name = getenv("HOME");
1051 	  new_length = strlen(home_name) + 1 + strlen(new_file_name) + 2;
1052 	  file_name = XtRealloc(file_name, new_length * sizeof(char));
1053 	  strcpy(file_name,home_name);
1054 	  strcat(file_name, "/");
1055 	  strcat(file_name,new_file_name);
1056 	}
1057       else
1058 	{
1059 	  new_length = strlen(new_file_name) + 1;
1060 	  file_name = XtRealloc(file_name, new_length * sizeof(char));
1061 	  strcpy(file_name,new_file_name);
1062 	}
1063 
1064       SendSaveWsm(file_name);
1065       XtPopdown(XtParent(wsm_ui->save_as_form));
1066       XtFree((XtPointer)new_file_name);
1067     }
1068 }
1069 
1070 
1071 /* ARGSUSED */
1072 void
DismissSaveAsCB(Widget w,XtPointer client,XtPointer call)1073 DismissSaveAsCB(Widget w, XtPointer  client, XtPointer call)
1074 {
1075   WSM_UI *wsm_ui = (WSM_UI*)client;
1076 
1077    XtPopdown(XtParent(wsm_ui->save_as_form));
1078 }
1079 
1080 
1081 
1082 
1083 /**********************************************************************/
1084 /*                        WSM Occupy Workspace CBs                    */
1085 /**********************************************************************/
1086 
1087 
1088 void
UpdateOccupySpaceList(Widget list)1089 UpdateOccupySpaceList(Widget list)
1090 {
1091   XmString xmstr;
1092   Space *s = space_list;
1093 
1094   XmListDeleteAllItems(list);
1095   while (s != NULL)
1096    {
1097      xmstr = XmStringCreateLtoR(s->name, XmSTRING_DEFAULT_CHARSET);
1098      XmListAddItem(list,xmstr,0);
1099      XmStringFree(xmstr);
1100      s = s->next;
1101    }
1102 
1103 }
1104 
1105 /* ARGSUSED */
1106 
1107 void
CreateOccupy(WorkWindow * w_window)1108 CreateOccupy(WorkWindow *w_window)
1109 {
1110   wsm_ui->occupy_window = w_window;
1111   if (connected )
1112     {
1113       UpdateSpaceList(wsm_ui->occupy_list);
1114     }
1115 
1116   if (w_window->linked)
1117     XmToggleButtonSetState(wsm_ui->link_occupy_toggle,True,True);
1118   else
1119     XmToggleButtonSetState(wsm_ui->copy_occupy_toggle,True,True);
1120   XtManageChild(wsm_ui->occupy_form);
1121   XtPopup(XtParent(wsm_ui->occupy_form), XtGrabNone);
1122 }
1123 
1124 
1125 /* ARGSUSED */
1126 void
DismissOccupyCB(Widget w,XtPointer client,XtPointer call)1127 DismissOccupyCB(Widget w, XtPointer client, XtPointer call)
1128 {
1129   WSM_UI *wsm_ui = (WSM_UI*)client;
1130    XtPopdown(XtParent(wsm_ui->occupy_form));
1131 
1132 }
1133 
1134 
1135 /* ARGSUSED */
1136 void
OccupyActivateCB(Widget w,XtPointer client,XtPointer call)1137 OccupyActivateCB(Widget w, XtPointer client, XtPointer call)
1138 {
1139   Space *space;
1140   int pos_count = 0;
1141   int *pos_list;
1142   int i;
1143   WSM_UI *wsm_ui = (WSM_UI*)client;
1144 
1145   if (XmListGetSelectedPos(wsm_ui->occupy_list,&pos_list, &pos_count))
1146     {
1147       for (i = 0; i < pos_count; i++)
1148 	{
1149 	  space = GetSpaceFromID(pos_list[i] - 1);
1150 	  if (space != NULL)
1151 	    {
1152 		if (copy_mode)
1153 		{
1154 		    PRINT("Copy to space: %s\n", space->name);
1155 		    CopyWindow(wsm_ui->occupy_window,current_space,space);
1156 		}
1157 		else
1158 		{
1159 		    PRINT("Link to space: %s\n", space->name);
1160 		    LinkWindow(wsm_ui->occupy_window,current_space,space);
1161 		}
1162 	    }
1163 	  else PRINT("Space == NULL\n");
1164 	}
1165     }
1166   if (pos_count > 0) XtFree((XtPointer)pos_list);
1167   XtPopdown(XtParent(wsm_ui->occupy_form));
1168 }
1169 
1170 
1171 
1172 
1173 
1174 
1175 void
SelectOccupyCB(Widget w,XtPointer client,XtPointer call)1176 SelectOccupyCB(Widget w, XtPointer client, XtPointer call)
1177 {
1178   WSM_UI *wsm_ui = (WSM_UI*)client;
1179   int pos_count = 0;
1180   int *pos_list;
1181   Space *space;
1182   WorkWindowList *w_list;
1183 
1184   if (XmListGetSelectedPos(wsm_ui->occupy_list,&pos_list, &pos_count))
1185     {
1186       space = GetSpaceFromID(pos_list[0]-1);
1187       if (space != NULL)
1188 	{
1189 
1190 	}
1191     }
1192   if (pos_count > 0) XtFree((XtPointer)pos_list);
1193 }
1194 
1195 
1196 
1197 void
CopyModeCB(Widget w,XtPointer client,XtPointer call)1198 CopyModeCB(Widget w,XtPointer client,XtPointer call)
1199 {
1200   WSM_UI *wsm_ui = (WSM_UI*)client;
1201   copy_mode = XmToggleButtonGetState(w);
1202 }
1203 
1204 
1205 
1206 void
LinkModeCB(Widget w,XtPointer client,XtPointer call)1207 LinkModeCB(Widget w,XtPointer client,XtPointer call)
1208 {
1209   WSM_UI *wsm_ui = (WSM_UI*)client;
1210   copy_mode = XmToggleButtonGetState(w);
1211 }
1212