"Fossies" - the Fresh Open Source Software Archive

Member "imal-3.7.7b/xmtnimage49.cc" (23 Sep 2014, 18914 Bytes) of archive /linux/misc/imal-source.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "xmtnimage49.cc" see the Fossies "Dox" file reference documentation.

    1 //--------------------------------------------------------------------------//
    2 // xmtnimage49.cc                                                           //
    3 // filename callbacks                                                       //
    4 // Latest revision: 08-04-2008                                              //
    5 // Copyright (C) 2000 by Thomas J. Nelson                                   //
    6 // See xmtnimage.h for Copyright Notice                                     //
    7 //--------------------------------------------------------------------------//
    8 
    9 #include "xmtnimage.h"
   10 
   11 extern Globals     g;
   12 extern Image      *z;
   13 extern int         ci;
   14 char lestif_filename[FILENAMELENGTH] = "nothing";
   15 int toppos=1;
   16 int in_fscancelcb = 0;
   17 
   18 
   19 //--------------------------------------------------------------------//
   20 // filenamecb                                                         //
   21 // Calling routine must maintain a dynamic list of Widgets, then      //
   22 //   destroy them when finished.                                      //
   23 //--------------------------------------------------------------------//
   24 void filenamecb(Widget widget, XtP client_data, XmACB *call_data)
   25 {
   26    call_data=call_data;  // Keep compiler quiet
   27    Widget f,w,w3,dirmaskwidget,bb;
   28 
   29    XmString title, dir_mask, pathxms=NULL;
   30    int n, itemcount;
   31    Arg args[100];
   32    clickboxinfo *c = (clickboxinfo *)client_data;
   33    int wc = c->wc;
   34    Widget flist;
   35 
   36    int rx,ry,wx,wy; 
   37    uint keys;
   38    Window rwin, cwin; 
   39 
   40    ////  Find current position of main window & image number
   41    XQueryPointer(g.display,g.main_window,&rwin,&cwin,&rx,&ry,&wx,&wy,&keys);
   42    g.main_xpos = rx-wx;
   43    g.main_ypos = ry-wy;
   44 
   45    n = 0;
   46    XtSetArg(args[n], XmNdialogStyle, XmDIALOG_MODELESS); n++;
   47    XtSetArg(args[n], XmNdefaultPosition, False); n++;
   48    XtSetArg(args[n], XmNx, min(g.xres-380, g.main_xpos + 50)); n++;
   49    XtSetArg(args[n], XmNy, g.main_ypos - 50); n++;
   50    XtSetArg(args[n], XmNtitle, "File Selection"); n++;
   51    ////  Stop Motif from trying to grab another color if none are available.
   52    if(g.want_colormaps)  
   53    {    XtSetArg(args[n], XmNbackground, g.main_bcolor); n++;
   54         XtSetArg(args[n], XmNforeground, g.main_fcolor); n++;
   55    }
   56    w = bb = c->w[wc++] = XmCreateBulletinBoardDialog(widget,(char*)"Select File",args,n);
   57    c->form = bb;
   58    title = XmStringLtoRCreate((char*)"Filter",XmSTRING_DEFAULT_CHARSET);   
   59    if(c->dirmask)
   60         dir_mask = XmStringLtoRCreate(c->dirmask,XmSTRING_DEFAULT_CHARSET); 
   61    else
   62         dir_mask = XmStringLtoRCreate((char*)"*",XmSTRING_DEFAULT_CHARSET); 
   63 
   64    n = 0;
   65    XtSetArg(args[n], XmNhighlightThickness, 1); n++;  
   66    XtSetArg(args[n], XmNdirMask, dir_mask); n++;  
   67    XtSetArg(args[n], XmNresizable, True); n++;  
   68    XtSetArg(args[n], XmNfilterLabelString, title); n++; 
   69    if(c->path != NULL)
   70    {   XtSetArg(args[n], XmNdirectory, pathxms = XmStringLtoRCreate(c->path,XmSTRING_DEFAULT_CHARSET)); n++;
   71    }
   72    ////  Stop Motif from trying to grab another color if none are available.
   73    if(g.want_colormaps)  
   74    {    XtSetArg(args[n], XmNbackground, g.main_bcolor); n++;
   75         XtSetArg(args[n], XmNforeground, g.main_fcolor); n++;
   76    }
   77    f = c->w[wc++] = XmCreateFileSelectionBox(w, (char*)"FileSelector", args, n);
   78 
   79    Widget child;
   80    child = c->listwidget = XmFileSelectionBoxGetChild(f, XmDIALOG_LIST);
   81    if(c->type==MULTIPLE)
   82        XtVaSetValues(child, XmNselectionPolicy, XmMULTIPLE_SELECT, NULL);
   83     
   84    XtVaGetValues(child, XmNitemCount, &itemcount, NULL);
   85    toppos = min(toppos, itemcount);
   86   
   87    XtVaSetValues(child, XmNtopItemPosition, toppos, NULL);
   88 
   89    ////   The first pushbutton is automatically placed in the wrong
   90    ////   position, so an unused, unmanaged pushbutton must be added
   91    ////   to trick Motif.
   92    
   93    n = 0;
   94    ////  Stop Motif from trying to grab another color if none are available.
   95    if(g.want_colormaps)  
   96    {    XtSetArg(args[n], XmNbackground, g.main_bcolor); n++;
   97         XtSetArg(args[n], XmNforeground, g.main_fcolor); n++;
   98    }
   99    c->w[wc++] = XmCreatePushButton(f, (char*)"crudola", args, n);
  100 
  101    n = 0;
  102    XtSetArg(args[n], XmNchildPlacement, XmPLACE_BELOW_SELECTION); n++;
  103    ////  Stop Motif from trying to grab another color if none are available.
  104    if(g.want_colormaps)  
  105    {    XtSetArg(args[n], XmNbackground, g.main_bcolor); n++;
  106         XtSetArg(args[n], XmNforeground, g.main_fcolor); n++;
  107    }
  108    w3 = c->w[wc++] = XmCreatePushButton(f, (char*)"Chdir", args, n);
  109    XtManageChild(w3);
  110 
  111    ////  Set c->widget[0] to the fileselectionbox widget.
  112    ////  c->widget[1] is the 'filename' push button in dialog box.
  113 
  114    c->widget[0] = w; 
  115    XtAddCallback(f, XmNcancelCallback, (XtCBP)fscancelcb, (XtP)c);
  116    XtAddCallback(f, XmNokCallback, (XtCBP)fsokcb, (XtP)c); 
  117    XtAddCallback(bb, XmNunmapCallback, (XtCBP)fsunmapcb, (XtP)c);
  118 
  119    flist =  XmFileSelectionBoxGetChild(f, XmDIALOG_LIST);
  120    XtAddCallback(flist, XmNsingleSelectionCallback, (XtCBP)fsscb, (XtP)flist);
  121    XtAddCallback(flist, XmNmultipleSelectionCallback, (XtCBP)fsscb, (XtP)flist);
  122 
  123    XtAddCallback(w3, XmNactivateCallback, (XtCBP)fscdcb, (XtP)f);
  124    dirmaskwidget = XmFileSelectionBoxGetChild(f, XmDIALOG_FILTER_TEXT);
  125    XtAddCallback(dirmaskwidget, XmNvalueChangedCallback, (XtCBP)fsdirmaskcb, (XtP)c); 
  126 
  127    if(c->path != NULL) XmStringFree(pathxms);
  128    XmStringFree(title);
  129    XmStringFree(dir_mask);
  130    XtManageChild(f);
  131    XtManageChild(w);
  132 
  133    //// It is necessary to manually set the colors in each subwindow.
  134            
  135    w = XmFileSelectionBoxGetChild(f, XmDIALOG_LIST);
  136    XtVaSetValues(w, 
  137 #ifdef SOLARIS 
  138             XmNwidth, 400,
  139 #endif
  140             XmNscrollBarDisplayPolicy, XmSTATIC,  // Essential for Solaris
  141             NULL);
  142 
  143    ////  Stop Motif from trying to grab another color if none are available.
  144    if(g.want_colormaps)  
  145    {   
  146        w = XmFileSelectionBoxGetChild(f, XmDIALOG_APPLY_BUTTON);
  147        XtVaSetValues(w, XmNbackground, g.main_bcolor, XmNforeground, g.main_fcolor,NULL);
  148        w = XmFileSelectionBoxGetChild(f, XmDIALOG_CANCEL_BUTTON);
  149        XtVaSetValues(w, XmNbackground, g.main_bcolor, XmNforeground, g.main_fcolor,NULL);
  150        w = XmFileSelectionBoxGetChild(f, XmDIALOG_DEFAULT_BUTTON);
  151        XtVaSetValues(w, XmNbackground, g.main_bcolor, XmNforeground, g.main_fcolor,NULL);
  152        w = XmFileSelectionBoxGetChild(f, XmDIALOG_DIR_LIST);
  153        XtVaSetValues(w, XmNbackground, g.main_bcolor, XmNforeground, g.main_fcolor,NULL);
  154        w = XmFileSelectionBoxGetChild(f, XmDIALOG_DIR_LIST_LABEL);
  155        XtVaSetValues(w, XmNbackground, g.main_bcolor, XmNforeground, g.main_fcolor,NULL);
  156        w = XmFileSelectionBoxGetChild(f, XmDIALOG_FILTER_LABEL);
  157        XtVaSetValues(w, XmNbackground, g.main_bcolor, XmNforeground, g.main_fcolor,NULL);
  158        w = XmFileSelectionBoxGetChild(f, XmDIALOG_FILTER_TEXT);
  159        XtVaSetValues(w, XmNbackground, g.main_bcolor, XmNforeground, g.main_fcolor,NULL);
  160        w = XmFileSelectionBoxGetChild(f, XmDIALOG_HELP_BUTTON);
  161        XtVaSetValues(w, XmNbackground, g.main_bcolor, XmNforeground, g.main_fcolor,NULL);
  162        w = XmFileSelectionBoxGetChild(f, XmDIALOG_LIST);
  163        XtVaSetValues(w, XmNbackground, g.main_bcolor, XmNforeground, g.main_fcolor,NULL);
  164        w = XmFileSelectionBoxGetChild(f, XmDIALOG_LIST_LABEL);
  165        XtVaSetValues(w, XmNbackground, g.main_bcolor, XmNforeground, g.main_fcolor,NULL);
  166        w = XmFileSelectionBoxGetChild(f, XmDIALOG_OK_BUTTON);
  167        XtVaSetValues(w, XmNbackground, g.main_bcolor, XmNforeground, g.main_fcolor,NULL);
  168        w = XmFileSelectionBoxGetChild(f, XmDIALOG_SELECTION_LABEL);
  169        XtVaSetValues(w, XmNbackground, g.main_bcolor, XmNforeground, g.main_fcolor,NULL);
  170        w = XmFileSelectionBoxGetChild(f, XmDIALOG_SEPARATOR);
  171        XtVaSetValues(w, XmNbackground, g.main_bcolor, XmNforeground, g.main_fcolor,NULL);
  172        w = XmFileSelectionBoxGetChild(f, XmDIALOG_TEXT);
  173        XtVaSetValues(w, XmNbackground, g.main_bcolor, XmNforeground, g.main_fcolor,NULL);
  174        w = XmFileSelectionBoxGetChild(f, XmDIALOG_WORK_AREA);
  175        XtVaSetValues(w, XmNbackground, g.main_bcolor, XmNforeground, g.main_fcolor,NULL);
  176    }
  177    c->wc = wc;
  178    //// Don't delete widgets here, delete at end of getfilename(s).
  179 }
  180 
  181 
  182 //--------------------------------------------------------------------//
  183 //  fsscb                                                             //
  184 //--------------------------------------------------------------------//
  185 void fsscb(Widget w, XtP client_data, XmLCB *call_data)
  186 { 
  187    w=w; client_data=client_data;
  188    XmListCallbackStruct *ptr = call_data;
  189    int count = ptr->selected_item_count;
  190    char **tempstring=NULL;
  191    tempstring = new char *[count+1];
  192    XmStringGetLtoR(ptr->item, XmFONTLIST_DEFAULT_TAG, tempstring);
  193    if(strlen(tempstring[0])) strcpy(lestif_filename, tempstring[0]);
  194    delete[] tempstring;
  195 }
  196 
  197 
  198 //--------------------------------------------------------------------//
  199 // fsokcb - callback for "ok" button in file selection box.           //
  200 // Caller passes a clickboxinfo struct in client_data.                //
  201 // Widget2 must be set to a pushbutton Widget or to NULL.             // 
  202 // This is where memory is allocated for multifilename selector.      //
  203 // The list array must be freed with delete[].                        //
  204 // The filename strings must be freed with XtFree().                  //
  205 //--------------------------------------------------------------------//
  206 void fsokcb(Widget w, XtP client_data, XmFSBCB *call_data)
  207 {
  208    call_data=call_data;
  209    Widget selectiontext;  // XmText for user to type in a filename 
  210    XmStringTable xmstrings;
  211    int k;
  212    clickboxinfo *c = (clickboxinfo *)client_data;
  213    char *filename; 
  214    char *fname;
  215    Widget button;
  216 
  217    //// Should never happen - clickbox already deleted
  218    if(c->done)
  219    {    message("Error in fsokcb", BUG); 
  220         fscancelcb(w, client_data, call_data);
  221         return;
  222    }
  223 
  224    filename = new char[FILENAMELENGTH];
  225    filename[0]=0;
  226    
  227    if(c->type == MULTIPLE)
  228    {   
  229        c->count=0;
  230        XtVaGetValues(c->listwidget, XmNselectedItemCount, &c->count, NULL); 
  231 
  232        ////  This returns the XmList items themselves, not a copy. The 
  233        ////  XmStringTable is automatically created by FileSelectionBox.
  234        ////  The application must not free the XmStrings (see OSF p. 1-859).
  235        
  236        XtVaGetValues(c->listwidget, XmNselectedItems, &xmstrings, NULL);
  237 
  238        c->list = new char*[c->count+1];
  239        for(k=0;k<c->count;k++)
  240        {
  241             ////  This allocates memory for items in list, use XtFree to free it.
  242             XmStringGetLtoR(xmstrings[k], XmFONTLIST_DEFAULT_TAG, &c->list[k]);
  243        }
  244        if(c->count>0) 
  245        {    strcpy(c->title, c->list[0]);
  246             strcpy(filename, c->list[0]);
  247        }else 
  248        {       //// A single click selects the file, then a double click deselects
  249                //// it and then comes here with nothing in the list. So retaliate 
  250                //// by copying selected filename (set in fsscb) out of a global.
  251                //// Also, with lestif, the fileselector doesn't recognize the 'Enter" key.
  252             selectiontext = XmFileSelectionBoxGetChild(w, XmDIALOG_TEXT);
  253                //// First check if they typed something in the text widget.
  254             XtVaGetValues(selectiontext, XmNvalue, &fname, NULL);
  255             if(strlen(fname)) strcpy(filename, fname);
  256                //// If it got nothing or a directory, substitute previous selection.
  257                //// Lestif might have unselected it so copy from the global.
  258             if(!strlen(filename) || filename[(int)strlen(filename)-1]=='/') 
  259                   strcpy(filename, lestif_filename);
  260             c->list[0] = XtMalloc(FILENAMELENGTH);  // Free this with XtFree()
  261             remove_trailing_space(filename);
  262             if(strlen(filename)) strcpy(c->title, filename);
  263             if(strlen(filename)) strcpy(c->list[0], filename);
  264        }
  265    }
  266 
  267    ////  For single file mode, Motif puts filename in an editable text widget. 
  268    if(c->type == SINGLE)
  269    {    selectiontext = XmFileSelectionBoxGetChild(w, XmDIALOG_TEXT);
  270         XtVaGetValues(selectiontext, XmNvalue, &fname, NULL);
  271         if(strlen(fname)) strcpy(filename, fname);
  272         //// In case user clicks Ok without selecting a file
  273         if(!strlen(filename) || filename[(int)strlen(filename)-1]=='/') 
  274              strcpy(filename, lestif_filename);
  275         remove_trailing_space(filename);
  276         if(strlen(filename)) strcpy(c->title, filename);
  277         c->count=1;
  278    }
  279    XtVaGetValues(c->listwidget, XmNtopItemPosition, &toppos, NULL);
  280    XFlush(g.display);
  281 
  282    ////  Put the new filename on the pushbutton. 
  283    ////  The pushbutton's XmNresizable resource must be False, otherwise
  284    ////  Motif will use this as an excuse to resize the entire dialog box.
  285    ////  Unmanage c->calling widget, which is the bulletin board - not w,
  286    ////  which is the filenamewidget on top.
  287 
  288    ////  c->widget[1] is the 'filename' pushbutton in dialogbox.
  289    ////  If calling from somewhere else, this should be set to NULL.
  290      
  291    ////  Focus goes to OK button when file is selected, so pressing Enter
  292    ////  twice will load the image.
  293    
  294    if(c->form != NULL) XmProcessTraversal(c->form, XmTRAVERSE_NEXT_TAB_GROUP); 
  295 
  296    //// Put the name in the pushbutton widget if it exists
  297    button = c->widget[1];
  298    if(button && strlen(c->title) && XtIsManaged(button)) 
  299         set_widget_label(button, basefilename(filename));
  300 
  301    dialoginfo *a = (dialoginfo*)c->ptr[0];
  302    if(a && strlen(c->path)) strcpy(a->path, c->path);
  303 
  304    c->done = 1;                            // Set flag indicating done
  305    delete[] filename;
  306    fscancelcb(w, client_data, call_data);
  307    g.escape = 0;
  308 }
  309 
  310 
  311 //--------------------------------------------------------------------//
  312 // fscancelcb - callback for "cancel" button in file selection box.   //
  313 //--------------------------------------------------------------------//
  314 void fscancelcb(Widget w, XtP client_data, XmFSBCB *call_data)
  315 {
  316    int k;
  317    w=w; call_data=call_data;  // Keep compiler quiet
  318    in_fscancelcb = 1;
  319    clickboxinfo *c = (clickboxinfo *)client_data;
  320    if(c==NULL) return;
  321    if(c->widget[0] == NULL) return;
  322    if(c->widget[0] && XtIsManaged(c->widget[0])) XtUnmanageChild(c->widget[0]);
  323    for(k=0;k<c->wc;k++) 
  324         if(!c->done && c->w[k]) XtDestroyWidget(c->w[k]);
  325    in_fscancelcb = 0;
  326    c->form = 0;
  327    c->done = 1;                            // Set flag indicating done
  328    g.escape = 1;
  329 }
  330 
  331 
  332 //--------------------------------------------------------------------//
  333 // fsunmapcb - callback in case user deletes file selection box window//
  334 //--------------------------------------------------------------------//
  335 void fsunmapcb(Widget w, XtP client_data, XmFSBCB *call_data)
  336 {
  337   g.block = 0; g.waiting=0;g.busy=0;
  338   if(!in_fscancelcb) fscancelcb(w, client_data, call_data);
  339 }
  340 
  341 
  342 //--------------------------------------------------------------------//
  343 // fscdcb - callback for "chdir" button in file selection box.        //
  344 //--------------------------------------------------------------------//
  345 void fscdcb(Widget w, XtP client_data, XmFSBCB *call_data)
  346 {
  347    w=w; call_data=call_data;  // Keep compiler quiet
  348    Widget f = (Widget)client_data;
  349    char *dir;
  350    int len;
  351    dir = new char[1024];
  352    XmString xms = XmStringCreateLtoR(dir, XmSTRING_DEFAULT_CHARSET);
  353    XtVaGetValues(f, XmNdirectory,  &xms, NULL);       
  354    XmStringGetLtoR(xms, XmFONTLIST_DEFAULT_TAG, &dir);
  355    chdir(dir);
  356    len = strlen(dir)-1;            // eliminate trailing /
  357    if(dir[len]=='/') dir[len]=0;
  358    strcpy(g.currentdir,dir);
  359    XmStringFree(xms);
  360    delete[] dir;
  361 }
  362 
  363 
  364 //--------------------------------------------------------------------//
  365 // fsdirmaskcb - callback for changing dir mask in file selection box.//
  366 //--------------------------------------------------------------------//
  367 void fsdirmaskcb(Widget w, XtP client_data, XmFSBCB *call_data)
  368 {
  369    w=w; call_data=call_data;  // Keep compiler quiet
  370    clickboxinfo *c = (clickboxinfo *)client_data;  
  371    XmString xmstring;
  372    XtVaGetValues(XtParent(w), XmNdirMask,  &xmstring, NULL);       
  373    if(c->dirmask != NULL)
  374         XmStringGetLtoR(xmstring, XmFONTLIST_DEFAULT_TAG, &c->dirmask);
  375 
  376    XtVaGetValues(XtParent(w), XmNdirectory,  &xmstring, NULL);       
  377    if(c->path != NULL)
  378         XmStringGetLtoR(xmstring, XmFONTLIST_DEFAULT_TAG, &c->path);
  379    XmStringFree(xmstring);
  380 } 
  381 
  382 
  383 //--------------------------------------------------------------------//
  384 // getfilename                                                        //
  385 //--------------------------------------------------------------------//
  386 char *getfilename(char *oldtitle, char *path)
  387 {  
  388    return getfilename(oldtitle, path, NULL);
  389 }
  390 char *getfilename(char *oldtitle, char *path, Widget widget)
  391 { 
  392    static char dirmask[FILENAMELENGTH]="*";
  393    int ostate = g.state;
  394    g.state = MESSAGE;
  395    int k;
  396    clickboxinfo c;
  397    c.title = oldtitle;
  398    c.helptopic = 0;
  399    c.done      = 0;
  400    c.wc        = 0;
  401    c.w         = new Widget[20];
  402    c.f1 = null;
  403    c.f2 = null;
  404    c.f3 = null;
  405    c.f4 = null;
  406    c.f5 = null;
  407    c.f6 = null;
  408    c.f7 = null;
  409    c.f8 = null;
  410    c.wc = 0;
  411    c.form = NULL;
  412    c.path = path;
  413    c.type = SINGLE;
  414    c.list = (char**)NULL;
  415    c.dirmask = new char[FILENAMELENGTH];
  416    strcpy(c.dirmask, dirmask);
  417    for(k=0; k<20; k++){ c.widget[k]=0; c.ptr[k]=0; }
  418    c.widget[1] = widget;
  419 
  420    ////  This changes c.wc
  421    filenamecb(g.main_widget, &c, (XmACB*)NULL);  
  422    g.waiting++;
  423    g.block++;
  424    while(!c.done) XtAppProcessEvent (g.app, XtIMAll);
  425    g.block = max(0, g.block-1);
  426    g.waiting = max(0, g.waiting-1);
  427 
  428    //// widgets are destroyed in fscancelcb
  429    XFlush(g.display);
  430    strcpy(dirmask, c.dirmask);
  431    delete[] c.w;
  432    delete[] c.dirmask;
  433    c.wc = 0;
  434    g.state = ostate;
  435    if(strlen(c.title)>0) return c.title;
  436    else return oldtitle;
  437 }
  438 
  439 
  440 //--------------------------------------------------------------------//
  441 // getfilenames                                                       //
  442 //--------------------------------------------------------------------//
  443 void getfilenames(clickboxinfo *c)
  444 {  
  445    static int ingfn=0;
  446    if(c==NULL) return;
  447    int k;
  448    c->done      = 0;
  449    if(ingfn){ c->done=1; return; }
  450    c->wc        = 0;
  451    ingfn=1;
  452    static char dirmask[FILENAMELENGTH]="*";
  453    c->type      = MULTIPLE;
  454    c->dirmask   = new char[FILENAMELENGTH];
  455 
  456    ////  Delete any previous list in case user clicks twice
  457    ////  Calling routine must still delete final list when finished.
  458    if(c->list!=NULL && c->count)
  459    {    for(k=0; k<c->count; k++) XtFree(c->list[k]);
  460         delete[] c->list;
  461    }
  462    c->count     = 0;
  463    strcpy(c->dirmask, dirmask);
  464    ////  This changes c->wc, allocates and fills c->list, and sets c->count.
  465    ////  Calling routine must delete c->list.
  466    filenamecb(g.main_widget, c, (XmACB*)NULL);   
  467    strcpy(dirmask, c->dirmask);
  468    ingfn=0;
  469 }
  470