home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / XAP / XFILEMAN / XFILEMAN.TAR / xfilemanager / workspace.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-24  |  28.5 KB  |  1,067 lines

  1. /*
  2.  * Copyright 1993 by Ove Kalkan, Cremlingen, Germany
  3.  *
  4.  * Permission to use, copy, modify, distribute and sell this software and it's
  5.  * documentation for any purpose is hereby granted without fee, rpovided that
  6.  * the above copyright notice and this permission appear in supporting
  7.  * documentation, and that the name of Ove Kalkan not to be used in
  8.  * advertising or publicity pertaining to distributiopn of the software without
  9.  * specific, written prior permission. Ove Kalkan makes no representations
  10.  * about the suitability of this software for any purpose. It is provided
  11.  * as is without express or implied warranty.
  12.  *
  13.  * OVE KALKAN DISPLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  14.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABLILITY AND FITNESS, IN NO
  15.  * EVENT SHALL OVE KALKAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  16.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  17.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18.  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19.  * PERFORMANCE OF THIS SOFTWARE.
  20.  *
  21.  * $Header: filename,v 1.0 yyyy/mm/dd hh:mm:ss loginname Exp $
  22.  */
  23.  
  24. #include "global.h"
  25.  
  26. /*
  27.  * Globale Variablen
  28.  */
  29.  
  30. static    Widget        ws_shell;
  31. static    Widget        etext1, etext2, etext3, etext4;
  32. static    Widget        et1, et2, et3, save_but;
  33.  
  34.  
  35. /*********************************************************
  36.  * name:    makeWorkspaceWindow
  37.  * description:    Erzeugt das Fenster eines Workspaces, in dem der
  38.  *        Benutzer Programme nach belieben ablegen kann, ohne
  39.  *        das eine Operation im Filesystem dazu ausgefuehrt
  40.  *        werden muesste.
  41.  *        Es ist hauptsaechlich dazu gedacht, ausfuehrbare
  42.  *        Programme dort abzulegen, um dann spaeter Dateien
  43.  *        mittels Drag&Drop darauf ziehen zu koennen.
  44.  * input:    Widget    parent    - Parentwidget, im Falle des
  45.  *                  singleWindow-Modes die Pane
  46.  *        WS_Glyph    - der Workspace
  47.  * output:    none
  48.  * author:    Ove Kalkan
  49.  * date:    29.6.93
  50.  *********************************************************/
  51. void        makeWorkspaceWindow (Widget parent, WS_Glyph *ws)
  52. {
  53.     Arg    args[10];
  54.     Widget    vp;
  55.     Widget    dummy, form, but;
  56.  
  57.     ws->shell = parent;
  58.  
  59.     /*
  60.      * Eine Form erzeugen und darauf den Workspacebereich und einige
  61.      * Controllelemente anbringen.
  62.      */
  63.     dummy = XtVaCreateManagedWidget ("workspace_pane", panedWidgetClass,
  64.                       parent,
  65.                       XtNorientation, XtorientVertical,
  66.                       NULL);
  67.  
  68.     /*
  69.      * Auf der Pane eine Form fuer das Workspace-Iconmenu erzeugen
  70.      */
  71.     if (defaults.multi_window)
  72.         form = XtVaCreateManagedWidget("workspace_form",formWidgetClass,dummy,
  73.                         XtNshowGrip,FALSE,
  74.                         NULL);
  75.     else {
  76.         form = XtVaCreateManagedWidget("workspace_form",formWidgetClass,dummy,
  77.                         XtNshowGrip,FALSE,
  78.                         NULL);
  79.         but = XtVaCreateManagedWidget("dummy",simpleWidgetClass,form,
  80.                         XtNwidth,1,
  81.                         XtNheight,32,
  82.                         XtNborderWidth,0,
  83.                         NULL);
  84.     }
  85.     ws_bar = form;
  86.  
  87.     if (!defaults.multi_window)
  88.         ws->shell = dummy;
  89.  
  90.     /*
  91.      * Einen Viewport fuer den Workspace erzeugen
  92.      */
  93.     if (defaults.multi_window)
  94.         XtSetArg(args[0],XtNwidth, 640);
  95.     else
  96.         XtSetArg(args[0],XtNwidth,250);
  97.     XtSetArg(args[1],XtNheight,100);
  98.     XtSetArg(args[2],XtNallowHoriz, TRUE);
  99.     XtSetArg(args[3],XtNallowVert, TRUE);
  100.     XtSetArg(args[4],XtNforceBars, TRUE);
  101.     XtSetArg(args[5],XtNuseBottom, TRUE);
  102.     XtSetArg(args[6],XtNuseRight, TRUE);
  103.     vp = XtCreateManagedWidget("viewport", viewportWidgetClass,
  104.                    dummy, args,7);
  105.  
  106.     /*
  107.      * Auf den Viewport kommt nun das Simple fuer den Workspace
  108.      */
  109.     ws->window = XtCreateWidget("ws_simple", simpleWidgetClass,
  110.                     vp, args, 2);
  111.     XtOverrideTranslations(ws->window, XtParseTranslationTable(
  112.                     "<Leave>: leave-window()\n\
  113.                     <Enter>: enter-window()\n\
  114.                         <Expose>: refresh-ws() \n\
  115.                     <Btn1Down>: clear-multi() start-single()\n\
  116.                     <Btn1Motion>: follow-single()\n\
  117.                     <Btn1Up>: end-single()"));
  118.     XtOverrideTranslations(ws->shell, XtParseTranslationTable("<Configure>: reset-ws()"));
  119. }
  120.  
  121.  
  122. /*********************************************************
  123.  * name:    resetWS
  124.  * description:    Neuanordnen der Icons nach einem Reset
  125.  * input:    Widget w - nur zum checken
  126.  * output:    none
  127.  * author:    Ove Kalkan
  128.  * date:    29.6.93
  129.  *********************************************************/
  130. XtActionProc    resetWS      (Widget w, XConfigureEvent *e, 
  131.                 String *s, Cardinal *c)
  132. {
  133.     int        i;
  134.     Dimension    wi,hi;
  135.     Widget        vp;
  136.     Dimension    sw,sh;
  137.  
  138.     /* Breite vom Viewport abhaengig machen */
  139.     vp = XtParent(workspace.window);
  140.     XtVaGetValues(vp,XtNwidth,&wi,
  141.              XtNheight,&hi,
  142.              NULL);
  143.  
  144.     sw = wi;
  145.     sh = hi;
  146.  
  147.     for (i = 0; i < workspace.wse_count; i++) {
  148.         if (workspace.wse[i]->x + 100 > sw)
  149.             sw = workspace.wse[i]->x + 100;
  150.         if (workspace.wse[i]->y + 30 + workspace.wse[i]->h > sh)
  151.             sh = workspace.wse[i]->y + 30 + workspace.wse[i]->h;
  152.     }
  153. /*
  154.     XClearWindow(XtDisplay(toplevel),XtWindow(workspace.window));
  155.     refreshWS(workspace.window,NULL,NULL,NULL);
  156.  
  157. */    /*
  158.      * XtResizeWidget causes trouble on some displays
  159.      */
  160.     XtVaSetValues(workspace.window, XtNwidth,sw,
  161.                     XtNheight,sh,
  162.                     NULL);
  163.  
  164.     /*
  165.      * Groesse der Shell holen, damit sie beim naechsten Mal
  166.      * wieder hergestellt werden kann.
  167.      */
  168.     XtVaGetValues(workspace.shell,  XtNwidth, &wi,
  169.                     XtNheight, &hi,
  170.                     XtNx, &sw,
  171.                     XtNy, &sh,
  172.                     NULL);
  173.     workspace.fx = sw; workspace.fx = sh;
  174.     workspace.fw = wi, workspace.fh = hi;
  175. }
  176.  
  177.  
  178. /*********************************************************
  179.  * name:    refreshWS
  180.  * description:    Neuzeichnen des Workspaces nach einem
  181.  *        Exposeevent
  182.  * input:    Widget w - nur zum checken
  183.  * output:    none
  184.  * author:    Ove Kalkan
  185.  * date:    29.6.93
  186.  *********************************************************/
  187. XtActionProc    refreshWS      (Widget w, XExposeEvent *e, 
  188.                 String *s, Cardinal *c)
  189. {
  190.     if (w == workspace.window && workspace.wse_count > 0) {
  191.         int    i;
  192.         Boolean b;
  193.  
  194.         /*
  195.          * Alle notwendigen Icons neuzeichnen
  196.          */
  197.         for (i = 0; i < workspace.wse_count; i++) {
  198.             b = (i == selc_w ? TRUE : FALSE);
  199.             drawWSE (&workspace,i,b,b);
  200.         }
  201.     }
  202. }
  203.  
  204.  
  205. /*********************************************************
  206.  * name:    addWSEtoWS
  207.  * description:    Neuen Eintrag am Workspace anfuegen
  208.  * input:    WS_Glyph *ws    - Workspace
  209.  *        char    *label    - label
  210.  *        char    *file    - filename
  211.  *        char    *path    - pfad
  212.  *        char    *icon    - iconfile
  213.  * output:    none
  214.  * author:    Ove Kalkan
  215.  * date:    29.6.1993
  216.  *********************************************************/
  217. void    addWSEtoWS (WS_Glyph *ws, char *label,
  218.             char *file, char *icon,
  219.             Boolean can_arg, Boolean must_arg, Boolean do_ask,
  220.             int    x, int y)
  221. {
  222.     WSE_Glyph    *wse;
  223.  
  224.     /*
  225.      * Speicher fuer den Workspaceeintrag holen
  226.      */
  227.     ws->wse_count++;
  228.     if (!(wse = (WSE_Glyph *) malloc(sizeof(WSE_Glyph))))
  229.         FATAL_ERROR("addWSEtoWS: malloc failed");
  230.     if (!ws->wse) {
  231.         if (!(ws->wse = (WSE_Glyph **) malloc(sizeof(WSE_Glyph *))))
  232.             FATAL_ERROR ("addWSEtoWS: malloc failed");
  233.     }
  234.     else {
  235.         if (!(ws->wse = (WSE_Glyph **) realloc((void *) ws->wse,
  236.                             sizeof(WSE_Glyph *)*ws->wse_count)))
  237.             FATAL_ERROR ("addWSEtoWS: realloc failed");
  238.     }
  239.  
  240.     /*
  241.      * Workspaceeintrag fuellen
  242.      */
  243.     wse->x = x;
  244.     wse->y = y;
  245.     wse->label = label;
  246.     wse->file = file;
  247.     wse->pmap = (Pixmap) NULL;
  248.     /*
  249.      * Nach Pixmap suchen
  250.      */
  251.     {     int    w,h;
  252.  
  253.         wse->shape = (Pixmap) NULL;
  254.         if (icon)
  255.             wse->pmap = ReadPixmapFromFile(icon,&w,&h);
  256.         if (!wse->pmap) {
  257.             h = 16;
  258.             w = 16;
  259.         }
  260.         else {
  261.             wse->shape = smap;
  262.         }
  263.         wse->w = w; wse->h = h;
  264.     }
  265.  
  266.     wse->pmap_file = icon;
  267.     wse->can_arg = can_arg;
  268.     wse->must_arg = must_arg;
  269.     wse->do_ask = do_ask;
  270.     ws->wse[ws->wse_count - 1] = wse;
  271. }
  272.  
  273.  
  274.  
  275.  
  276. /*********************************************************
  277.  * name:    readWorkspace
  278.  * description:    Initialisiert einen Workspace mit den
  279.  *        Settings aus dem angegebenen File
  280.  * input:    WS_Glyph *ws    - Workspace
  281.  *        char    *file    - Settingsfile
  282.  * output:    none
  283.  * author:    Ove Kalkan
  284.  * date:    29.6.93
  285.  *********************************************************/
  286. void    readWorkspace  (WS_Glyph *ws, char *file)
  287. {
  288.     char    filename[255];
  289.     char    *home = getenv("HOME");
  290.     FILE    *fp;
  291.  
  292.     /*
  293.      * Workspacefiles oeffnen falls vorhanden
  294.      */
  295.     if (strcmp(home,"/"))
  296.         sprintf(filename,"%s/.wsrc",home);
  297.     else
  298.         sprintf(filename,"/.wsrc");
  299.  
  300.     if ((fp = fopen(filename,"r")) || (fp = fopen(DEFAULT_WORKSPACE,"r"))) {
  301.         int    width,items;
  302.         int    i;
  303.         char    s[1024];
  304.         char    *back;
  305.  
  306.         s[1023] = '\0';
  307.         while ((back = fgets(s,1023,fp)) && (s[0] == '#' || s[0] == '\n'));
  308.         if (back) {
  309.             sscanf(s,"%d %d %d %d %d %d",&width,&items,&ws->fx,&ws->fy,&ws->fw,&ws->fh);
  310.             ws->width = width;
  311.             ws->wse_count = 0;
  312.             ws->wse = NULL;
  313.             if (!ws->fw)    ws->fw = 600;
  314.             if (!ws->fh)    ws->fh = 80;
  315.         }
  316.         else items = 0;
  317.         /* Einzelnen Eintraege lesen */
  318.         i = 0;
  319.         while (i < items) {
  320.             char    *sss, *ss;
  321.             char    *label, *file, *pmap_file;
  322.             int    x,y,can_arg,must_arg,do_ask;
  323.  
  324.             ss = s;
  325.             fgets(s,1023,fp);
  326.             /*
  327.              * Label holen
  328.              */
  329.             if (s[0] != '#' && s[0] != '\n') {
  330.                 if ((sss = strchr(ss,':'))) {
  331.                     *sss = '\0';
  332.                     if (!(label = (char *) malloc (strlen(ss)+1)))
  333.                         FATAL_ERROR("Read WS: Malloc failed");
  334.                     sprintf(label,"%s",ss);
  335.                     ss = sss + 1;
  336.                     /*
  337.                      * Ausfuehrbares Programm holen
  338.                      */
  339.                     if ((sss = strchr(ss,':'))) {
  340.                         *sss = '\0';
  341.                         if (!(file = (char *) malloc (strlen(ss)+1)))
  342.                             FATAL_ERROR("Read WS: Malloc failed");
  343.                         sprintf(file,"%s",ss);
  344.                         ss = sss + 1;
  345.                         sscanf(ss,"%d%d",&x,&y);
  346.                         ss = strchr(ss,':') + 1;
  347.     
  348.                         /*
  349.                          * Icon-filenamen holen
  350.                          */
  351.                         pmap_file = NULL;
  352.                         if ((sss = strchr(ss,':'))) {
  353.                             *sss = '\0';
  354.                             if (strlen(ss)) {
  355.                                 if (!(pmap_file = (char *) malloc (strlen(ss)+1)))
  356.                                     FATAL_ERROR("Read WS: Malloc failed");
  357.                                 sprintf(pmap_file,"%s",ss);
  358.                             }
  359.                             ss = sss;
  360.                         }
  361.                         ss++;
  362.                         sscanf(ss,"%d %d %d",&can_arg,&must_arg,&do_ask);
  363.                         addWSEtoWS(ws,label,file,pmap_file,
  364.                                 can_arg,must_arg,do_ask,x,y);
  365.                         i++;
  366.                     }
  367.                 }
  368.             }
  369.         }
  370.         fclose(fp);
  371.     }
  372.     else {    /* Default Workspace nehmen */
  373. #ifdef    HAVE_XPM
  374. #ifdef    hpux
  375.         ws->wse_count = 0;
  376.         ws->width = 6;
  377.         ws->wse = NULL;
  378.         ws->fx = 0;
  379.         ws->fy = 0;
  380.         ws->fw = 700;
  381.         ws->fh = 90;
  382.         addWSEtoWS(ws,"File Viewer","xmore","xmore.xpm",TRUE,FALSE,TRUE,70,20);
  383.         addWSEtoWS(ws,"Editor","xedit","xedit.xpm",TRUE,FALSE,TRUE,200,20);
  384.         addWSEtoWS(ws,"News","/users/kalkan/bin/xrnj",NULL,FALSE,FALSE,FALSE,70,80);
  385.         addWSEtoWS(ws,"Mailtool","xmail",NULL,FALSE,FALSE,FALSE,70,140);
  386.         addWSEtoWS(ws,"WaisQ","xwaisq",NULL,FALSE,FALSE,FALSE,200,140);
  387.         addWSEtoWS(ws,"XV","xv","file_pix.xpm",TRUE,TRUE,TRUE,70,200);
  388.         addWSEtoWS(ws,"Compress","gzip","file_compressed.xpm",TRUE,TRUE,TRUE,70,260);
  389.         addWSEtoWS(ws,"Uncompress","gunzip","file_compressed.xpm",TRUE,TRUE,TRUE,200,260);
  390.         addWSEtoWS(ws,"XFig","xfig","file_graph.xpm",TRUE,FALSE,TRUE,70,320);
  391. #else
  392.         ws->wse_count = 0;
  393.         ws->width = 6;
  394.         ws->wse = NULL;
  395.         addWSEtoWS(ws,"File Viewer","xmore","file_text.xpm",TRUE,FALSE,TRUE,70,20);
  396.         addWSEtoWS(ws,"Editor","xedit","file_dvi.xpm",TRUE,FALSE,TRUE,200,20);
  397.         addWSEtoWS(ws,"WaisQ","xwaisq",NULL,FALSE,FALSE,FALSE,70,80);
  398.         addWSEtoWS(ws,"XV","xv","file_pix.xpm",TRUE,TRUE,TRUE,70,140);
  399.         addWSEtoWS(ws,"XFig","xfig","file_graph.xpm",TRUE,FALSE,TRUE,200,140);
  400.         addWSEtoWS(ws,"Compress","gzip","file_compressed.xpm",TRUE,TRUE,TRUE,70,200);
  401.         addWSEtoWS(ws,"Uncompress","gunzip","file_compressed.xpm",TRUE,TRUE,TRUE,70,200);
  402. #endif
  403. #else
  404. #ifdef    hpux
  405.         ws->wse_count = 0;
  406.         ws->width = 6;
  407.         ws->wse = NULL;
  408.         ws->fx = 0;
  409.         ws->fy = 0;
  410.         ws->fw = 700;
  411.         ws->fh = 90;
  412.         addWSEtoWS(ws,"File Viewer","xmore","text.xbm",TRUE,FALSE,TRUE,70,20);
  413.         addWSEtoWS(ws,"Editor","xedit",NULL,TRUE,FALSE,TRUE,200,20);
  414.         addWSEtoWS(ws,"News","/users/kalkan/bin/xrnj",NULL,FALSE,FALSE,FALSE,70,80);
  415.         addWSEtoWS(ws,"Mailtool","xmail",NULL,FALSE,FALSE,FALSE,70,140);
  416.         addWSEtoWS(ws,"WaisQ","xwaisq",NULL,FALSE,FALSE,FALSE,200,140);
  417.         addWSEtoWS(ws,"XV","xv","file_pix.xbm",TRUE,TRUE,TRUE,70,200);
  418.         addWSEtoWS(ws,"Compress","gzip","file_compressed.xbm",TRUE,TRUE,TRUE,70,240);
  419.         addWSEtoWS(ws,"Uncompress","gunzip","file_compressed.xbm",TRUE,TRUE,TRUE,200,240);
  420.         addWSEtoWS(ws,"XFig","xfig","file_graph.xbm",TRUE,FALSE,TRUE,70,300);
  421. #else
  422.         ws->wse_count = 0;
  423.         ws->width = 6;
  424.         ws->wse = NULL;
  425.         addWSEtoWS(ws,"File Viewer","xmore","file_text.xbm",TRUE,FALSE,TRUE,70,20);
  426.         addWSEtoWS(ws,"Editor","xedit","file_dvi.xbm",TRUE,FALSE,TRUE,200,20);
  427.         addWSEtoWS(ws,"WaisQ","xwaisq",NULL,FALSE,FALSE,FALSE,70,80);
  428.         addWSEtoWS(ws,"XV","xv","file_pix.xbm",TRUE,TRUE,TRUE,70,140);
  429.         addWSEtoWS(ws,"XFig","xfig","file_graph.xbm",TRUE,FALSE,TRUE,200,140);
  430.         addWSEtoWS(ws,"Compress","gzip","file_compressed.xbm",TRUE,TRUE,TRUE,70,200);
  431.         addWSEtoWS(ws,"Uncompress","gunzip","file_compressed.xbm",TRUE,TRUE,TRUE,200,200);
  432. #endif
  433. #endif
  434.     }
  435. /*    if (defaults.multi_window)
  436.         XtConfigureWidget(ws->shell,ws->fx,ws->fy,
  437.                   ws->fw,ws->fh,0);
  438.  
  439. */}
  440.  
  441.  
  442.  
  443. /*********************************************************
  444.  * name:    init_editWSE
  445.  * description:    oeffnet ein Fenster zum Editieren oder Neuerzeugen von
  446.  *        Eintraegen fuer den Workspace
  447.  * input:    none
  448.  * output:    none
  449.  * author:    Ove Kalkan
  450.  * date:    22.7.1993
  451.  *********************************************************/
  452. void    init_editWSE(void)
  453. {
  454.     Widget        form;
  455.     WSE_Glyph    *g = NULL;
  456.     Widget        label,icon;
  457.  
  458.     if (selc_fo && selc_f < 16000 && GRAB) {    /* Executable wurde draufgezogen */
  459.         char    *d = getPath(selc_fo->dir);
  460.         char    s[1024];
  461.  
  462.         if (strcmp(d,"/"))
  463.             sprintf(s,"%s/%s",d,selc_fo->file[selc_f]->name);
  464.         else
  465.             sprintf(s,"/%s",selc_fo->file[selc_f]->name);
  466.         free(d);
  467.         if (!(d = (char *) malloc (strlen(s)+1)))
  468.             FATAL_ERROR("initEditWS: Malloc failed");
  469.         sprintf(d,"%s",s);
  470.         addWSEtoWS(&workspace,selc_fo->file[selc_f]->name,d,
  471.                 NULL,TRUE,FALSE,TRUE,100,100);
  472.         selc_ws = &workspace;
  473.         selc_w = workspace.wse_count - 1;
  474.         refreshWS(workspace.window,NULL,NULL,NULL);
  475.     }
  476.     if (selc_w < 16000 && selc_ws)
  477.         g = selc_ws->wse[selc_w];
  478.  
  479.     /*
  480.      * Alte Shell zerstoeren, falls sie noch existiert
  481.      */
  482.     if (ws_shell)
  483.         XtDestroyWidget(ws_shell);
  484.     ws_shell = XtVaCreatePopupShell("wse_shell",topLevelShellWidgetClass,
  485.                     toplevel,
  486.                     XtNallowShellResize,TRUE,
  487.                     XtNtitle,"Xfilemanager - Workspaceeditor",
  488.                     NULL);
  489.  
  490.     /*
  491.      * Form darauf erzeugen
  492.      */
  493.     form = XtVaCreateManagedWidget ("dialog_form", formWidgetClass, ws_shell,
  494.                     NULL);
  495.     /*
  496.      * Den Simple fuer das Icon erstellen
  497.      */
  498.     icon = XtVaCreateManagedWidget ("dialog_icon", iconWidgetClass, form,
  499.                     XtNtop, XtChainTop,
  500.                     XtNbottom, XtChainTop,
  501.                     XtNright, XtChainLeft,
  502.                     XtNleft, XtChainLeft,
  503.                     XtNimageWidth, 32,
  504.                     XtNimageHeight, 32,
  505.                     XtNborderWidth, 0,
  506.                     XtNimage,Icon_WSE_PM,
  507.                     NULL);
  508.  
  509.     /*
  510.      * den Label darauf erzeugen, der sagt, das es sich hierbei um
  511.      * eine Verschiebe-Aktion handelt
  512.      */
  513.     label = XtVaCreateManagedWidget ("info_title", labelWidgetClass, form,
  514.                     XtNtop, XtChainTop,
  515.                     XtNbottom, XtChainTop,
  516.                     XtNright, XtChainLeft,
  517.                     XtNleft, XtChainLeft,
  518.                     XtNborderWidth, 0,
  519.                     XtNfromHoriz, icon,
  520.                     XtNlabel,"Workspace Entry Editor",
  521.                     NULL);
  522.  
  523.     /*
  524.      * Feld fuer Label erzeugen
  525.      */
  526.     label = XtVaCreateManagedWidget ("label_label", labelWidgetClass, form,
  527.                     XtNtop, XtChainTop,
  528.                     XtNbottom, XtChainTop,
  529.                     XtNright, XtChainLeft,
  530.                     XtNleft, XtChainLeft,
  531.                     XtNborderWidth, 0,
  532.                     XtNlabel,"Label :",
  533.                     XtNjustify,XtJustifyRight,
  534.                     XtNwidth,100,
  535.                     XtNfromVert,icon,
  536.                     NULL);
  537.     etext1 = XtVaCreateManagedWidget ("label_label", asciiTextWidgetClass, form,
  538.                     XtNtop, XtChainTop,
  539.                     XtNbottom, XtChainTop,
  540.                     XtNright, XtChainRight,
  541.                     XtNleft, XtChainLeft,
  542.                     XtNstring,(g ? g->label : NULL),
  543.                     XtNresize, XawtextResizeWidth,
  544.                     XtNfromVert,icon,
  545.                     XtNfromHoriz, label,
  546.                     XtNeditType, XawtextEdit,
  547.                     XtNwidth,180,
  548.                     XtNresizable, TRUE,
  549.                     NULL);
  550.     XtOverrideTranslations(etext1, XtParseTranslationTable(
  551.                     "<Key>Return: no-op()"));
  552.  
  553.     /*
  554.      * Feld fuer Label erzeugen
  555.      */
  556.     label = XtVaCreateManagedWidget ("label_label", labelWidgetClass, form,
  557.                     XtNtop, XtChainTop,
  558.                     XtNbottom, XtChainTop,
  559.                     XtNright, XtChainLeft,
  560.                     XtNleft, XtChainLeft,
  561.                     XtNborderWidth, 0,
  562.                     XtNlabel,"Executable :",
  563.                     XtNjustify,XtJustifyRight,
  564.                     XtNwidth,100,
  565.                     XtNfromVert,label,
  566.                     NULL);
  567.     etext2 = XtVaCreateManagedWidget ("label_label", asciiTextWidgetClass, form,
  568.                     XtNtop, XtChainTop,
  569.                     XtNbottom, XtChainTop,
  570.                     XtNright, XtChainRight,
  571.                     XtNleft, XtChainLeft,
  572.                     XtNstring,(g ? g->file : NULL),
  573.                     XtNresize, XawtextResizeWidth,
  574.                     XtNfromVert,etext1,
  575.                     XtNfromHoriz, label,
  576.                     XtNeditType, XawtextEdit,
  577.                     XtNwidth,180,
  578.                     XtNresizable, TRUE,
  579.                     NULL);
  580.     XtOverrideTranslations(etext2, XtParseTranslationTable(
  581.                     "<Key>Return: no-op()"));
  582.  
  583.     /*
  584.      * Feld fuer Label erzeugen
  585.      */
  586.     label = XtVaCreateManagedWidget ("icon_label", labelWidgetClass, form,
  587.                     XtNtop, XtChainTop,
  588.                     XtNbottom, XtChainTop,
  589.                     XtNright, XtChainLeft,
  590.                     XtNleft, XtChainLeft,
  591.                     XtNborderWidth, 0,
  592.                     XtNlabel,"Iconfile :",
  593.                     XtNjustify,XtJustifyRight,
  594.                     XtNwidth,100,
  595.                     XtNfromVert,label,
  596.                     NULL);
  597.     etext3 = XtVaCreateManagedWidget ("label_label", asciiTextWidgetClass, form,
  598.                     XtNtop, XtChainTop,
  599.                     XtNbottom, XtChainTop,
  600.                     XtNright, XtChainRight,
  601.                     XtNleft, XtChainLeft,
  602.                     XtNstring,(g ? g->pmap_file : NULL),
  603.                     XtNresize, XawtextResizeWidth,
  604.                     XtNfromVert,etext2,
  605.                     XtNfromHoriz, label,
  606.                     XtNeditType, XawtextEdit,
  607.                     XtNwidth,180,
  608.                     XtNresizable, TRUE,
  609.                     NULL);
  610.     XtOverrideTranslations(etext3, XtParseTranslationTable(
  611.                     "<Key>Return: no-op()"));
  612.  
  613.     /*
  614.      * Feld fuer CanArgLabel erzeugen
  615.      */
  616.     label = XtVaCreateManagedWidget ("icon_label", labelWidgetClass, form,
  617.                     XtNtop, XtChainTop,
  618.                     XtNbottom, XtChainTop,
  619.                     XtNright, XtChainLeft,
  620.                     XtNleft, XtChainLeft,
  621.                     XtNborderWidth, 0,
  622.                     XtNlabel,"Can be Droptarget :",
  623.                     XtNjustify,XtJustifyRight,
  624.                     XtNwidth,150,
  625.                     XtNfromVert,label,
  626.                     XtNvertDistance, 12,
  627.                     NULL);
  628.     et1 = XtVaCreateManagedWidget ("toggle", toggleWidgetClass, form,
  629.                     XtNtop, XtChainTop,
  630.                     XtNbottom, XtChainTop,
  631.                     XtNright, XtChainLeft,
  632.                     XtNleft, XtChainLeft,
  633.                     XtNwidth,20,
  634.                     XtNfromVert,etext3,
  635.                     XtNfromHoriz, label,
  636.                     XtNstate,(g ? g->can_arg : TRUE),
  637.                     XtNvertDistance, 10,
  638.                     XtNlabel," ",
  639.                     NULL);
  640.  
  641.     /*
  642.      * Feld fuer MustArgLabel erzeugen
  643.      */
  644.     label = XtVaCreateManagedWidget ("icon_label", labelWidgetClass, form,
  645.                     XtNtop, XtChainTop,
  646.                     XtNbottom, XtChainTop,
  647.                     XtNright, XtChainLeft,
  648.                     XtNleft, XtChainLeft,
  649.                     XtNborderWidth, 0,
  650.                     XtNlabel,"Must be Droptarget :",
  651.                     XtNjustify,XtJustifyRight,
  652.                     XtNwidth,150,
  653.                     XtNfromVert,et1,
  654.                     NULL);
  655.     et2 = XtVaCreateManagedWidget ("toggle", toggleWidgetClass, form,
  656.                     XtNtop, XtChainTop,
  657.                     XtNbottom, XtChainTop,
  658.                     XtNright, XtChainLeft,
  659.                     XtNleft, XtChainLeft,
  660.                     XtNwidth,20,
  661.                     XtNfromVert,et1,
  662.                     XtNfromHoriz, label,
  663.                     XtNstate,(g ? g->must_arg : FALSE),
  664.                     XtNlabel," ",
  665.                     NULL);
  666.  
  667.     /*
  668.      * Feld fuer DoAskLabel erzeugen
  669.      */
  670.     label = XtVaCreateManagedWidget ("icon_label", labelWidgetClass, form,
  671.                     XtNtop, XtChainTop,
  672.                     XtNbottom, XtChainTop,
  673.                     XtNright, XtChainLeft,
  674.                     XtNleft, XtChainLeft,
  675.                     XtNborderWidth, 0,
  676.                     XtNlabel,"Ask before Execute :",
  677.                     XtNjustify,XtJustifyRight,
  678.                     XtNwidth,150,
  679.                     XtNfromVert,et2,
  680.                     NULL);
  681.     et3 = XtVaCreateManagedWidget ("toggle", toggleWidgetClass, form,
  682.                     XtNtop, XtChainTop,
  683.                     XtNbottom, XtChainTop,
  684.                     XtNright, XtChainLeft,
  685.                     XtNleft, XtChainLeft,
  686.                     XtNwidth,20,
  687.                     XtNfromVert,et2,
  688.                     XtNfromHoriz, label,
  689.                     XtNstate,(g ? g->do_ask : FALSE),
  690.                     XtNlabel," ",
  691.                     NULL);
  692.  
  693.     /*
  694.      * Zum Schluss noch eine Form fuer die Buttons erzeugen
  695.      */
  696.     form = XtVaCreateManagedWidget("wse_form", formWidgetClass, form,
  697.                     XtNleft,XawChainLeft,
  698.                     XtNright,XawChainRight,
  699.                     XtNbottom,XawChainBottom,
  700.                     XtNtop,XawChainBottom,
  701.                     XtNfromVert,label,
  702.                     XtNvertDistance,20,
  703.                     XtNborderWidth,0,
  704.                     NULL);
  705.     /*
  706.      * Darauf jetzt noch einige Buttons erzeugen
  707.      */
  708.     label = XtVaCreateManagedWidget("wse_hide", commandWidgetClass, form,
  709.                     XtNleft, XawChainLeft,
  710.                     XtNright, XawChainLeft,
  711.                     XtNlabel, "  Hide  ",
  712.                     NULL);
  713.     XtAddCallback (label,XtNcallback,(XtCallbackProc) hide_wsshell,NULL);
  714.  
  715.     label = XtVaCreateManagedWidget("wse_reset", commandWidgetClass, form,
  716.                     XtNleft, XawChainRight,
  717.                     XtNright, XawChainRight,
  718.                     XtNlabel, " Reset ",
  719.                     XtNfromHoriz, label,
  720.                     XtNhorizDistance, 50,
  721.                     NULL);
  722.     XtAddCallback (label,XtNcallback,(XtCallbackProc) reset_wsshell,NULL);
  723.  
  724.     save_but = XtVaCreateManagedWidget("wse_save", commandWidgetClass, form,
  725.                     XtNleft, XawChainRight,
  726.                     XtNright, XawChainRight,
  727.                     XtNlabel, "  Save  ",
  728.                     XtNfromHoriz, label,
  729.                     NULL);
  730.     XtAddCallback (save_but,XtNcallback,(XtCallbackProc) save_wsshell,NULL);
  731.  
  732.     label = XtVaCreateManagedWidget("wse_apply", commandWidgetClass, form,
  733.                     XtNleft, XawChainRight,
  734.                     XtNright, XawChainRight,
  735.                     XtNlabel, " Apply  ",
  736.                     XtNfromHoriz, save_but,
  737.                     NULL);
  738.     XtAddCallback (label,XtNcallback,(XtCallbackProc) apply_wsshell,NULL);
  739.  
  740.  
  741.     XtManageChild(ws_shell);
  742. }
  743.  
  744. /*********************************************************
  745.  * name:    init_deleteWSE
  746.  * description:    oeffnet ein Fenster zum Loeschen von
  747.  *        Eintraegen des Workspace
  748.  * input:    none
  749.  * output:    none
  750.  * author:    Ove Kalkan
  751.  * date:    22.7.1993
  752.  *********************************************************/
  753. void    init_deleteWSE(void)
  754. {
  755.     Widget    but;
  756.  
  757.     /*
  758.      * Dialog-Fenster erzeugen
  759.      */
  760.     but = makeDialog(0,"","",NULL,NULL,"Remove Workspace Entry?",TRUE,TRUE,Icon_WSD_PM);
  761.  
  762.     XtAddCallback(but,XtNcallback,(XtCallbackProc) wse_delete_cb,NULL);
  763.  
  764.     /*
  765.      * Zum Schluss die Dialogshell managen
  766.      */
  767.     XtManageChild (dialog);
  768. }
  769.  
  770.  
  771. /*********************************************************
  772.  * name:    saveWorkspace
  773.  * description:    Sichern eines Workspaces um ihn spaeter wieder
  774.  *        verwenden zu koennen.
  775.  * input:    WS_Glyph *ws    - Der Workspace
  776.  * output:    none
  777.  * author:    Ove Kalkan
  778.  * date:    21.7.1993
  779.  *********************************************************/
  780. void    saveWorkspace (WS_Glyph *ws)
  781. {
  782.     FILE    *fp;
  783.     char    *home = getenv("HOME");
  784.     char    filename[255];
  785.     Dimension    x,y;
  786.  
  787.     /*
  788.      * zunaechst den Filenamen generieren
  789.      */
  790.     if (strcmp(home,"/"))
  791.         sprintf(filename,"%s/.wsrc",home);
  792.     else
  793.         sprintf(filename,"/.wsrc");
  794.  
  795.     XtVaGetValues(ws->shell,XtNx,&x, XtNy,&y, NULL);
  796.     ws->fx = x;
  797.     ws->fy = y;
  798.  
  799.     /*
  800.      * Versuchen, das File zu oeffnen
  801.      */
  802.     if ((fp = fopen(filename,"w"))) {
  803.         int    i;
  804.         /*
  805.          * Workspace rausschreiben
  806.          */
  807.         fprintf(fp,"%d %d %d %d %d %d\n",ws->width,ws->wse_count,ws->fx,ws->fy,
  808.                          ws->fw,ws->fh);
  809.         for (i = 0; i < ws->wse_count; i++) {
  810.             WSE_Glyph *g = ws->wse[i];
  811.  
  812.             fprintf(fp,"%s:%s:%d %d:%s:%d %d %d\n",
  813.                     g->label,g->file,g->x,g->y,
  814.                     g->pmap_file,g->can_arg,g->must_arg,g->do_ask);
  815.         }
  816.         fclose(fp);
  817.     }
  818.     else
  819.         WARNING("Cannot save Workspace");
  820. }
  821.  
  822.  
  823.  
  824. /*********************************************************
  825.  * name:    hide_wsshell
  826.  * description:    Loeschen der Workspace_Edit-Shell
  827.  * input:    none
  828.  * output:    none
  829.  * author:    Ove Kalkan
  830.  * date:    22.7.1993
  831.  *********************************************************/
  832. void    hide_wsshell (void)
  833. {
  834.     XtDestroyWidget (ws_shell);
  835.     ws_shell = NULL;
  836. }
  837.  
  838.  
  839.  
  840. /*********************************************************
  841.  * name:    reset_wsshell
  842.  * description:    Ruecksetzen der Eintraege im Workspace Editor
  843.  * input:    none
  844.  * output:    none
  845.  * author:    Ove Kalkan
  846.  * date:    22.7.1993
  847.  *********************************************************/
  848. void    reset_wsshell (void)
  849. {
  850.     if (selc_ws && selc_w < 16000) {
  851.         WSE_Glyph    *g = selc_ws->wse[selc_w];
  852.  
  853.         XtVaSetValues(etext1,XtNstring,g->label,NULL);
  854.         XtVaSetValues(etext2,XtNstring,g->file,NULL);
  855.         XtVaSetValues(etext3,XtNstring,g->pmap_file,NULL);
  856.         XtVaSetValues(et1,XtNstate,g->can_arg,NULL);
  857.         XtVaSetValues(et2,XtNstate,g->must_arg,NULL);
  858.         XtVaSetValues(et3,XtNstate,g->do_ask,NULL);
  859.     }
  860.     else {
  861.         XtVaSetValues(etext1,XtNstring,NULL,NULL);
  862.         XtVaSetValues(etext2,XtNstring,NULL,NULL);
  863.         XtVaSetValues(etext3,XtNstring,NULL,NULL);
  864.         XtVaSetValues(et1,XtNstate,TRUE,NULL);
  865.         XtVaSetValues(et2,XtNstate,FALSE,NULL);
  866.         XtVaSetValues(et3,XtNstate,TRUE,NULL);
  867.     }
  868. }
  869.  
  870.  
  871. /*********************************************************
  872.  * name:    save_wsshell
  873.  * description:    sichern des Workspaces
  874.  * input:    none
  875.  * output:    none
  876.  * author:    Ove Kalkan
  877.  * date:    22.7.1993
  878.  *********************************************************/
  879. void    save_wsshell (void)
  880. {
  881.     saveWorkspace(&workspace);
  882.     WORKSPACE_CHANGED = FALSE;
  883. }
  884.  
  885.  
  886. /*********************************************************
  887.  * name:    apply_wsshell
  888.  * description:    Aufnehmen oder Aendern eines Eintrages
  889.  * input:    none
  890.  * output:    none
  891.  * author:    Ove Kalkan
  892.  * date:    22.7.1993
  893.  *********************************************************/
  894. void    apply_wsshell (void)
  895. {
  896.     char    *a1,*a2,*a3;
  897.     Boolean    b1,b2,b3;
  898.  
  899.     /*
  900.      * Werte und Strings von den Widgets holen
  901.      */
  902.     XtVaGetValues(etext1,XtNstring,&a1,NULL);
  903.     XtVaGetValues(etext2,XtNstring,&a2,NULL);
  904.     XtVaGetValues(etext3,XtNstring,&a3,NULL);
  905.     XtVaGetValues(et1,XtNstate,&b1,NULL);
  906.     XtVaGetValues(et2,XtNstate,&b2,NULL);
  907.     XtVaGetValues(et3,XtNstate,&b3,NULL);
  908.  
  909.     /*
  910.      * Label und Executable muessen vorhanden sein
  911.      */
  912.     if (!strlen(a1)) {
  913.         WARNING("Error: Missing Label");
  914.         return;
  915.     }
  916.     if (!strlen(a2)) {
  917.         WARNING("Error: Missing Executable");
  918.         return;
  919.     }
  920.  
  921.     if (selc_ws && selc_w < 16000) {    /* Alten Eintrag modifizieren */
  922.         WSE_Glyph    *g = selc_ws->wse[selc_w];
  923.  
  924.         /*
  925.          * Speicher neu beschaffen und Werte sichern
  926.          */
  927.         if (!(g->label = (char *) realloc((void *) g->label,
  928.                           strlen(a1)+1)))
  929.             FATAL_ERROR("apply_shell: realloc1 failed.");
  930.         if (!(g->file = (char *) realloc((void *) g->file,
  931.                           strlen(a2)+1)))
  932.             FATAL_ERROR("apply_shell: realloc2 failed.");
  933.         sprintf(g->label,"%s",a1);
  934.         sprintf(g->file,"%s",a2);
  935.         if (strlen(a3)) {
  936.             if (!g->pmap) {
  937.                 if (!(g->pmap_file = (char *) malloc(strlen(a3)+1)))
  938.                     FATAL_ERROR("apply_shell: nmalloc3 failed.");
  939.             }
  940.             else {
  941.                 if (!(g->pmap_file = (char *) realloc((void *) g->pmap_file,
  942.                                   strlen(a3)+1)))
  943.                     FATAL_ERROR("apply_shell: realloc3 failed.");
  944.             }
  945.             sprintf(g->pmap_file,"%s",a3);
  946.         }
  947.         else {
  948.             if (g->pmap_file)
  949.                 free(g->pmap_file);
  950.             g->pmap_file = NULL;
  951.         }
  952.         g->can_arg = b1;
  953.         g->must_arg = b2;
  954.         g->do_ask = b3;
  955.  
  956.         /*
  957.          * Pixmap neu laden und darstellen
  958.          */
  959.         if (g->pmap)
  960.             XFreePixmap(XtDisplay(toplevel),g->pmap);
  961.         g->pmap = (Pixmap) NULL;
  962.         {     int    w,h;
  963.  
  964.             g->shape = (Pixmap) NULL;
  965.             if (g->pmap_file)
  966.                 g->pmap = ReadPixmapFromFile(g->pmap_file,&w,&h);
  967.             if (!g->pmap) {
  968.                 h = 16;
  969.                 w = 16;
  970.             }
  971.             else
  972.                 g->shape = smap;
  973.             g->w = w; g->h = h;
  974.         }
  975.         XClearWindow(XtDisplay(workspace.window),XtWindow(workspace.window));
  976.         refreshWS(workspace.window,NULL,NULL,NULL);
  977.     }
  978.     else {    /* Neuen Eintrag erstellen */
  979.         char    *label,*file,*pmap_file;
  980.  
  981.         if (!(label = (char *) malloc(strlen(a1)+1)))
  982.             FATAL_ERROR("apply_shell: malloc1 failed.");
  983.         if (!(file = (char *) malloc(strlen(a2)+1)))
  984.             FATAL_ERROR("apply_shell: malloc2 failed.");
  985.         sprintf(label,"%s",a1);
  986.         sprintf(file,"%s",a2);
  987.         if (strlen(a3)) {
  988.             if (!(pmap_file = (char *) malloc(strlen(a3)+1)))
  989.                 FATAL_ERROR("apply_shell: malloc3 failed.");
  990.             sprintf(pmap_file,"%s",a3);
  991.         }
  992.         else
  993.             pmap_file = NULL;
  994.         addWSEtoWS(&workspace,label,file,pmap_file,b1,b2,b3,10,10);
  995.         selc_ws = &workspace;
  996.         selc_w = workspace.wse_count - 1;
  997.         refreshWS(workspace.window,NULL,NULL,NULL);
  998.     }
  999. }
  1000.  
  1001.  
  1002.  
  1003. /*********************************************************
  1004.  * name:    wse_delete_cb
  1005.  * description:    loeschen eines Eintrags aus dem Workspace
  1006.  * input:    None
  1007.  * output:    None
  1008.  * author:    Ove Kalkan
  1009.  * date:    28.7.1993
  1010.  *********************************************************/
  1011. void    wse_delete_cb(void)
  1012. {
  1013.     int    i;
  1014.  
  1015.     XUngrabPointer(XtDisplay(toplevel),CurrentTime);
  1016.     XtDestroyWidget (dialog);
  1017.     dialog = NULL;
  1018.     workspace.wse_count--;
  1019.  
  1020.     for (i = selc_w; i < workspace.wse_count; i++)
  1021.         workspace.wse[i] = workspace.wse[i+1];
  1022.  
  1023.     selc_ws = NULL;
  1024.     selc_w = 16000;
  1025.     XClearWindow(XtDisplay(workspace.window),XtWindow(workspace.window));
  1026.     refreshWS(workspace.window,NULL,NULL,NULL);
  1027. }
  1028.  
  1029.  
  1030.  
  1031. /*********************************************************
  1032.  * name:    PlaceWorkspaceIcons
  1033.  * description:    Anordnen der WorkspaceIcons in einem Workspace-Fenster.
  1034.  * input:    none
  1035.  * output:    none
  1036.  * author:    Ove Kalkan
  1037.  * date:    12.8.1993
  1038.  *********************************************************/
  1039. void    PlaceWorkspaceIcons(void)
  1040. {
  1041.     Dimension    nw,nh;
  1042.     int        i,j,k;
  1043.  
  1044.     if (WORKSPACE_CHANGED) {
  1045.         WORKSPACE_CHANGED = FALSE;
  1046.         WARNING("The Workspace has been changed\nfor last save.\nPress the arrange-button again to\nforce the workspace-cleanup.");
  1047.         return;
  1048.     }
  1049.     XtVaGetValues(XtParent(workspace.window),XtNwidth,&nw,NULL);
  1050.  
  1051.     j = 0; k = 0;
  1052.     for (i = 0; i < workspace.wse_count; i++) {
  1053.         workspace.wse[i]->x = defaults.icon_grid*(j + 0.5);
  1054.         workspace.wse[i]->y = defaults.icon_grid*(k + 0.5);
  1055.         j++;
  1056.         if ((j + 1) * defaults.icon_grid > nw) {
  1057.             j = 0;
  1058.             k++;
  1059.         }
  1060.     }
  1061.     nw = (nw + defaults.icon_grid - 1)%defaults.icon_grid;
  1062.     nh = (k + 1)*defaults.icon_grid;
  1063.  
  1064.     XtVaSetValues(workspace.window,XtNwidth,nw,XtNheight,nh,NULL);
  1065.     XClearWindow(XtDisplay(workspace.window),XtWindow(workspace.window));
  1066.     refreshWS(workspace.window,NULL,NULL,NULL);
  1067. }