home *** CD-ROM | disk | FTP | other *** search
/ M.u.C.S. Disc 2000 / MUCS2000.iso / anwend / qed453 / src / projekt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-07  |  43.2 KB  |  1,973 lines

  1. #include <dirent.h>
  2. #include <keycodes.h>
  3. #include <support.h>
  4. #include <stat.h>
  5. #include <time.h>
  6.  
  7. #include "global.h"
  8. #include "aktion.h"
  9. #include "av.h"
  10. #include "ausgabe.h"
  11. #include "clipbrd.h"
  12. #include "comm.h"
  13. #include "dd.h"
  14. #include "edit.h"
  15. #include "event.h"
  16. #include "kurzel.h"
  17. #include "file.h"
  18. #include "find.h"
  19. #include "icon.h"
  20. #include "memory.h"
  21. #include "menu.h"
  22. #include "options.h"
  23. #include "printer.h"
  24. #include "rsc.h"
  25. #include "set.h"
  26. #include "text.h"
  27. #include "window.h"
  28. #include "projekt.h"
  29.  
  30.  
  31. /* exprortierte Variablen **************************************************/
  32. int        prj_type;
  33. PATH        def_prj_path;
  34.  
  35. /****** DEFINES ************************************************************/
  36.  
  37. #define KIND    (NAME|CLOSER|MOVER|INFO|SIZER|UPARROW|DNARROW|VSLIDE|SMALLER)
  38. #define FLAGS    (WI_FONTSIZE|WI_REDRAW)
  39.  
  40. #define TEMP_LINK 101
  41.  
  42. /****** TYPES **************************************************************/
  43.  
  44. typedef struct            /* für Dreaddir */
  45. {
  46.     long        inode;
  47.     FILENAME name;
  48. } DIRENTRY;
  49.  
  50. /****** VAR ****************************************************************/
  51. static int    do_find_icon;
  52. static PATH    df_path;
  53. static int    def_icon;                        /* Icon für Defaultprojekt */
  54.  
  55. /****** FUNCTIONS **********************************************************/
  56.  
  57. static void    p_icon_exist        (int icon, SET actions);
  58. static bool    p_icon_test            (int icon, int action);
  59. static int    p_icon_edit            (int icon, int action);
  60. static bool    p_icon_drag            (int icon, int source);
  61. static void    draw_line            (WINDOWP window, int line);
  62. static void    wi_draw                (WINDOWP window, GRECT *d);
  63. static void    wi_click             (WINDOWP window, int m_x, int m_y, int bstate, int kstate, int breturn);
  64. static void    wi_unclick            (WINDOWP window);
  65. static bool    wi_key                (WINDOWP window, int kstate, int kreturn);
  66. static void    wi_snap                (WINDOWP window, GRECT *new, int mode);
  67. static void    wi_iconify            (WINDOWP window);
  68. static void    wi_uniconify        (WINDOWP window);
  69. static bool    find_files            (char *pfad, bool rekursiv, char *df_muster, int icon, int tmp_icon);
  70. static void    get_prj_line        (int link, int line, char *str);
  71. static int    del_from_projekt    (int link, int line);
  72. static bool    open_prj             (int icon);
  73. static void    destruct             (int icon);
  74. static void    crt_prj                (WINDOWP window);
  75. static int    crt_new_prj            (char *filename);
  76. static void    info_projekt        (int icon);
  77. static void    select_def_prj     (void);
  78.  
  79. /*****************************************************************************/
  80.  
  81. /*
  82.  * do_for_prj()
  83.  *    bei DO_OPEN, DO_DELETE und Info-Scan -> Aktion auf Projekt selbst
  84. */
  85. static void do_for_prj(int icon, SET s, int (*do_it)(int,int), bool verbose)
  86. {
  87.     TEXTP     t_ptr, t_ptr2;
  88.     ZEILEP     lauf;
  89.     int        min, i, anz, soll, erg;
  90.     PATH        name, prj;
  91.     FILENAME file;
  92.     char        *p;
  93.     
  94.     t_ptr = get_text(icon);
  95.     if (t_ptr->namenlos)
  96.         strcpy(prj, t_ptr->filename);
  97.     else
  98.         file_name(t_ptr->filename, prj, FALSE);
  99.     strcat(prj, ": ");
  100.     p = strrchr(prj, ' ') + 1;                        /* p zeigt auf das Ende */
  101.     
  102.     if (verbose)
  103.     {
  104.         t_ptr2 = get_text(icon);
  105.         if (t_ptr2->namenlos)
  106.             strcpy(file, t_ptr2->filename);
  107.         else
  108.             file_name(t_ptr2->filename,file, FALSE);
  109.         strcpy(p, file);
  110.         start_aktion(prj, TRUE, setcard(s));
  111.     }
  112.  
  113.     min = setmin(s);
  114.     /* So wg. DO_DELETE */
  115.     for (i=setmax(s); i>=min; i--)
  116.     {
  117.         if (setin(s,i))
  118.         {
  119.             lauf = get_line(&t_ptr->text,i);
  120.             lauf->info |= MARKED;
  121.         }
  122.     }
  123.     soll = setcard(s);
  124.     anz = i = 0;
  125.     while (TRUE)
  126.     {
  127.         lauf = get_line(&t_ptr->text,i);
  128.         if (lauf == NULL) 
  129.             break;
  130.         if (IS_MARKED(lauf))
  131.         {
  132.             anz++;
  133.             lauf->info &= (~MARKED);                /* sonst Endlosschleife */
  134.             if (verbose)
  135.             {
  136.                 get_prj_line(icon,i,name);
  137.                 if (name[0] == EOS) 
  138.                     break;
  139.                 file_name(name,file, FALSE);
  140.                 strcpy(p, file);
  141.                 if (!do_aktion(prj, anz))
  142.                 {
  143.                     if (anz < soll && note(1, 2, BREAK) == 1) 
  144.                         break;
  145.                     else
  146.                         redraw_aktion();
  147.                 }
  148.             }
  149.             erg = (*do_it)(icon,i);
  150.             if (erg < 0) 
  151.                 break;
  152.         }
  153.         else
  154.             i++;
  155.     }
  156.     lauf = FIRST(&t_ptr->text);
  157.     while (!IS_TAIL(lauf))
  158.     {
  159.         lauf->info &= (~MARKED);
  160.         NEXT(lauf);
  161.     }
  162.     if (verbose) 
  163.         end_aktion();
  164. }
  165.  
  166. /*
  167.  * bei Sub-Info und Find -> Aktion auf Element(e) des Projekts
  168. */
  169. static bool do_find(int icon);
  170.  
  171. static void do_for_prj2(int icon, SET s, int aktion, bool verbose)
  172. {
  173.     int        i, t_icon, anz, soll, antw;
  174.     TEXTP     t_ptr, t_ptr2;
  175.     PATH        name, prj;
  176.     FILENAME file;
  177.     char        *p;
  178.     
  179.     t_ptr = new_text(TEMP_LINK);                    /* Temp-Text zum Laden der Elemente */
  180.     if (t_ptr == NULL) 
  181.         return;
  182.  
  183.     if (verbose)
  184.     {
  185.         t_ptr2 = get_text(icon);                    /* Name des Projekts ermitteln */
  186.         if (t_ptr2->namenlos)
  187.             strcpy(file, t_ptr2->filename);
  188.         else
  189.             file_name(t_ptr2->filename,file, FALSE);
  190.         
  191.         strcpy(prj, file);
  192.         strcat(prj, ": ");
  193.         p = strrchr(prj, ' ') + 1;                    /* p zeigt auf das Ende */
  194.         strcpy(p, file);
  195.         start_aktion(prj, TRUE, setcard(s));
  196.     }
  197.  
  198.     soll = setcard(s);
  199.     for (i=setmin(s),anz=0; anz<soll; i++)
  200.     {
  201.         if (setin(s,i))
  202.         {
  203.             anz++;
  204.             get_prj_line(icon,i,name);
  205.             if (name[0] == EOS) 
  206.                 break;
  207.             file_name(name, file, FALSE);
  208.  
  209.             t_icon = text_still_loaded(name);
  210.             if (t_icon < 0)
  211.             {
  212.                 set_text_name(t_ptr, name, FALSE);
  213.                 antw = load(t_ptr, FALSE);
  214.                 if (antw != 0)
  215.                     open_error(name, antw);
  216.                 t_icon = TEMP_LINK;            
  217.             }
  218. /*
  219.             do_it(t_icon);
  220. */
  221.             switch (aktion)
  222.             {
  223.                 case DO_INFO :
  224.                     info_edit(t_icon);
  225.                     break;
  226.                 
  227.                 case DO_FIND :
  228.                     t_ptr2 = get_text(t_icon);
  229.                     if ((ff_mask[0] == EOS) || filematch(t_ptr2->filename, ff_mask, t_ptr2->filesys))
  230.                         do_find(t_icon);
  231.                     else
  232.                         file[0] = EOS;            /* nicht in Aktion-Box eintragen! */
  233.                     break;
  234.  
  235.                 default:
  236.                     debug("do_for_prj2(): unbekannte Aktion %d\n", aktion);
  237.                     break;
  238.             }            
  239.  
  240.             if (t_icon == TEMP_LINK) 
  241.                 clear_text(t_ptr);
  242.  
  243.             if (verbose)
  244.             {
  245.                 if (file[0] != EOS)
  246.                     strcpy(p, file);
  247.                 if (!do_aktion(prj, anz))
  248.                 {
  249.                     if (anz < soll && note(1, 2, BREAK) == 1) 
  250.                         break;
  251.                     else
  252.                         redraw_aktion();
  253.                 }
  254.             }
  255.         }
  256.     }
  257.     destruct_text(t_ptr);
  258.     if (verbose)
  259.         end_aktion();
  260. }
  261.  
  262. static bool delete_prj(int icon)
  263. {
  264.     TEXTP     t_ptr = get_text(icon);
  265.     int        antw;
  266.     FILENAME name;
  267.  
  268.     if (t_ptr->moved!=0)
  269.     {
  270.         if (quick_close)
  271.             antw = 1;
  272.         else
  273.         {
  274.             if (t_ptr->namenlos)
  275.                 strcpy(name, t_ptr->filename);
  276.             else
  277.                 file_name(t_ptr->filename, name, FALSE);
  278.             antw = snote(1, 3, MOVED, name);
  279.         }
  280.         if (antw == 1)
  281.         {
  282.             if (do_icon(icon,DO_SAVE)<0)
  283.                 return (FALSE);
  284.         }
  285.         if (antw == 3) 
  286.             return(FALSE);
  287.     }
  288.     return (TRUE);
  289. }
  290.  
  291. static void chg_prj_name(int icon)
  292. {
  293.     WINDOWP         window;
  294.     FILENAME     name;
  295.     TEXTP         t_ptr = get_text(icon);
  296.  
  297.     file_name(t_ptr->filename, name, TRUE);
  298.     window = get_window (icon);
  299.     set_wtitle(window, name);
  300. }
  301.  
  302. /***************************************************************************/
  303. /* Operation vorhanden ?                                                                    */
  304. /***************************************************************************/
  305.  
  306. static void p_icon_exist(int icon, SET actions)
  307. {
  308.     setclr(actions);
  309.     if (icon & SUB_ICON)
  310.     {
  311.         setincl(actions,DO_OPEN);
  312.         setincl(actions,DO_DELETE);
  313.         setincl(actions,DO_INFO);
  314.         setincl(actions,DO_HELP);
  315.     }
  316.     else
  317.     {
  318.         WINDOWP window = get_window(icon);
  319.         TEXTP t_ptr = get_text(icon);
  320.  
  321.         if ((window->flags & WI_ICONIFIED) || (window->flags & WI_SHADED))
  322.         {
  323.             setincl(actions, DO_DELETE);
  324.         }
  325.         else
  326.         {
  327.             if (window->flags & WI_OPEN)
  328.                 setincl(actions, DO_CLOSE);
  329.             setincl(actions, DO_DELETE);
  330.             setincl(actions, DO_SELALL);
  331.             setincl(actions, DO_OPEN);
  332.             setincl(actions, DO_INFO);
  333.             setincl(actions, DO_FIND);
  334.             if (!t_ptr->namenlos)
  335.                 setincl(actions, DO_ABAND);
  336.             setincl(actions, DO_SAVE);
  337.             setincl(actions, DO_SAVENEW);
  338.             setincl(actions, DO_UPDATE);
  339.             setincl(actions, DO_PRINT);
  340.             setincl(actions, DO_HELP);
  341.             setincl(actions, DO_ADD);
  342.             if (t_ptr->moved)
  343.                 setincl(actions, DO_AUTOSAVE);
  344.         }
  345.     }
  346. }
  347.  
  348. /***************************************************************************/
  349. /* Operation testen                                                                            */
  350. /***************************************************************************/
  351.  
  352. static bool p_icon_test(int icon, int action)
  353. {
  354.     bool    erg;
  355.  
  356.     if (icon & SUB_ICON)        /* Aktion auf selektierten Eintrag */
  357.     {
  358.         switch(action)
  359.         {
  360.             case DO_OPEN:    
  361.                 erg = TRUE; 
  362.                 break;
  363.             case DO_DELETE:    
  364.                 erg = TRUE; 
  365.                 break;
  366.             case DO_INFO:    
  367.                 erg = TRUE; 
  368.                 break;
  369.             case DO_HELP:    
  370.                 erg = TRUE; 
  371.                 break;
  372.             default:    
  373.                 erg = FALSE;
  374.         }
  375.     }
  376.     else                            /* Aktion auf Projekt selbst */
  377.     {
  378.         FILENAME name;
  379.         TEXTP     t_ptr = get_text(icon);
  380.  
  381.         switch(action)
  382.         {
  383.             case DO_SELALL:
  384.                 erg = TRUE; 
  385.                 break;
  386.             case DO_CLOSE:
  387.             case DO_DELETE:    
  388.                 erg = delete_prj(icon); 
  389.                 break;
  390.             case DO_OPEN:
  391.                 erg = TRUE; 
  392.                 break;
  393.             case DO_INFO:
  394.                 erg = TRUE; 
  395.                 break;
  396.             case DO_FIND:
  397.                 erg = findfile_dial(t_ptr->filename, TRUE); 
  398.                 break;
  399.             case DO_ABAND:
  400.                 if (t_ptr->namenlos)
  401.                     erg = FALSE;
  402.                 else
  403.                 {
  404.                     erg = TRUE;
  405.                     if (!ist_leer(&t_ptr->text) && t_ptr->moved!=0)
  406.                     {
  407.                         file_name(t_ptr->filename, name, FALSE);
  408.                         erg = (snote(1, 2, ABANDON, name) == 1);
  409.                     }
  410.                 }
  411.                 break;
  412.             case DO_SAVE:
  413.                 erg = TRUE; 
  414.                 break;
  415.             case DO_SAVENEW:
  416.                 erg = TRUE; 
  417.                 break;
  418.             case DO_UPDATE :
  419.                 erg = TRUE; 
  420.                 break;
  421.             case DO_PRINT    :
  422.                 erg = TRUE; 
  423.                 break;
  424.             case DO_HELP    :
  425.                 erg = TRUE; 
  426.                 break;
  427.             case DO_ADD     :
  428.                 erg = findfile_dial(df_path, FALSE);
  429.                 break;
  430.             case DO_AUTOSAVE :
  431.                 if (as_prj && t_ptr->moved)
  432.                 {
  433.                     int    btn;
  434.                     long    min;
  435.  
  436.                     min = (int)((time(NULL) - t_ptr->asave) / 60L);
  437.                     if (min >= as_prj_min)
  438.                     {
  439.                         if (as_prj_ask)                /* Nachfrage ? */
  440.                         {
  441.                             FILENAME     name;
  442.  
  443.                             if (t_ptr->namenlos)
  444.                                 strcpy(name, t_ptr->filename);
  445.                             else
  446.                                 file_name(t_ptr->filename, name, FALSE);
  447.                             Bconout(2, 7);
  448.                             btn = snote(2, 3, ASAVEASK, name);
  449.                             if (btn == 1)
  450.                                 as_prj = FALSE;
  451.                         }
  452.                         else
  453.                             btn = 2;
  454.  
  455.                         t_ptr->asave = time(NULL);
  456.                         erg = (btn == 2);
  457.                     }
  458.                     else
  459.                         erg = FALSE;
  460.                 }
  461.                 else
  462.                 {
  463.                     t_ptr->asave = time(NULL);
  464.                     erg = FALSE;
  465.                 }
  466.                 break;
  467.             default:
  468.                 erg = FALSE;
  469.         }
  470.     }
  471.     return erg;
  472. }
  473.  
  474. /***************************************************************************/
  475. /* Operation durchführen                                                                    */
  476. /***************************************************************************/
  477.  
  478. static int do_open(int prj_icon, int i)
  479. {
  480.     PATH    name;
  481.     int    icon;
  482.     bool    prj;
  483.  
  484.     get_prj_line(prj_icon, i, name);
  485.     prj = filematch(name, "*.QPJ", -1);
  486.     if (prj)
  487.     {
  488.         if (shift_pressed())
  489.             return load_edit(name, FALSE);            /* Laden als Text und öffnen */
  490.         else
  491.             return load_projekt(name);                    /* Laden als Projekt und öffnen */
  492.     }
  493.     else
  494.     {
  495.         icon = load_edit(name, FALSE);                /* Laden als Text und öffnen */
  496.         return icon;
  497.     }
  498. }
  499.  
  500. static bool do_find(int icon)
  501. {
  502.     int    erg = 0;
  503.     TEXTP t_ptr = get_text(icon);
  504.  
  505.     erg = start_find(t_ptr,TRUE);
  506.     if (erg == 1)
  507.         add_to_projekt(do_find_icon, t_ptr->filename, TRUE);
  508.     return (erg != -1);
  509. }
  510.  
  511. static int p_icon_edit(int icon, int action)
  512. {
  513.     PATH    name;
  514.     int    erg;
  515.  
  516.     erg = 0;
  517.     if (icon & SUB_ICON)
  518.     {
  519.         WINDOWP     window;
  520.         SET        help;
  521.  
  522.         icon &= (~SUB_ICON);
  523.         window = get_window(icon);
  524.         if (sel_window==window)
  525.             setcpy(help,sel_objs);
  526.         else
  527.             setclr(help);
  528.         switch (action)
  529.         {
  530.             case DO_OPEN    :
  531.                 do_for_prj(icon,help,do_open,FALSE);
  532.                 break;
  533.             case DO_DELETE    :
  534.                 do_for_prj(icon,help,del_from_projekt,FALSE);
  535.                 break;
  536.             case DO_INFO    :
  537.                 do_for_prj2(icon, help, DO_INFO, FALSE);
  538.                 break;
  539.             case DO_HELP    :
  540.                 erg = call_hyp(rsc_string(HYPPRJSTR));
  541.                 break;
  542.         }
  543.         erg = 1;
  544.     }
  545.     else
  546.     {
  547.         TEXTP     t_ptr = get_text(icon);
  548.         WINDOWP     window = get_window(icon);
  549.         int        i;
  550.         SET        help;
  551.         FILENAME file;
  552.         PATH        h;
  553.  
  554.         switch(action)
  555.         {
  556.             case DO_CLOSE    :
  557.             case DO_DELETE    :
  558.                 if (icon == def_icon)
  559.                 {
  560.                     def_icon = -1;
  561.                     set_def_prj();
  562.                 }
  563.                 destruct(icon);
  564.                 erg = 1;
  565.                 break;
  566.             case DO_SELALL :
  567.                 if (window != sel_window)
  568.                     unclick_window();
  569.                 if (!ist_leer(&t_ptr->text))
  570.                 {
  571.                     sel_window = window;
  572.                     for (i = (int) t_ptr->text.lines; (--i)>=0; )
  573.                         setincl(sel_objs,i);
  574.                     redraw_window(window,&window->work);
  575.                 }
  576.                 erg = 1;
  577.                 break;
  578.             case DO_OPEN    :
  579.                 if (!open_prj (icon))
  580.                     erg = -1;
  581.                 else
  582.                     erg = 1;
  583.                 break;
  584.             case DO_INFO    :
  585.                 info_projekt(icon);
  586.                 erg = 1;
  587.                 break;
  588.             case DO_FIND    :
  589.                 setclr(help);
  590.                 for (i = (int) t_ptr->text.lines; (--i)>=0; )
  591.                     setincl(help,i);
  592.                 do_find_icon = crt_new_prj("");
  593.                 if (do_find_icon < 0)
  594.                     break;
  595.                 if (do_icon(do_find_icon, DO_OPEN) < 0)
  596.                 {
  597.                     note(1, 0, NOWINDOW);
  598.                     icon_edit(icon, DO_DELETE);
  599.                     break;
  600.                 }
  601.                 do_for_prj2(icon, help, DO_FIND, TRUE);
  602.                 t_ptr = get_text(do_find_icon);
  603.                 if (t_ptr->moved)                                    /* etwas gefunden? */
  604.                 {
  605.                     t_ptr->moved = 0;
  606.                     window = get_window(do_find_icon);
  607.                     if (t_ptr->namenlos)
  608.                         strcpy(h, t_ptr->filename);
  609.                     else
  610.                         file_name(t_ptr->filename, h, TRUE);
  611.                     change_window(window, h, FALSE);
  612.                     set_sliders(window, VERTICAL, SLPOS+SLSIZE);
  613.                     redraw_window(window,&window->work);
  614.                 }
  615.                 else
  616.                     icon_edit(do_find_icon, DO_DELETE);    /* wenn nicht, gleich wieder zu */
  617.                 erg = 1;
  618.                 break;
  619.             case DO_ABAND    :
  620.                 strcpy(name, t_ptr->filename);
  621.                 desire_y = window->doc.y+1;
  622.                 close_window(window);
  623.                 destruct_text(t_ptr);
  624.                 del_icon(icon);
  625.                 icon = load_projekt(name);
  626.                 if (icon > 0)
  627.                 {
  628.                     t_ptr = get_text(icon);
  629.                     if (t_ptr!=NULL)
  630.                     {
  631.                         i = (int) (desire_y - window->doc.y);
  632.                         arrow_window(window,WA_DNLINE,i);
  633.                         restore_edit();
  634.                         open_prj(icon);
  635.  
  636.                         memset(msgbuff, 0, (int) sizeof(msgbuff));
  637.                         msgbuff[0] = WM_TOPPED;
  638.                         msgbuff[3] = window->handle;
  639.                         send_msg(gl_apid);
  640.         
  641.                         erg = 1;
  642.                     }
  643.                 }
  644.                 break;
  645.             case DO_SAVE    :
  646.                 if (!t_ptr->namenlos)
  647.                 {
  648.                     if (save(t_ptr) < 0)
  649.                         erg = -1;
  650.                     else
  651.                     {
  652.                         file_name(t_ptr->filename, h, TRUE);
  653.                         change_window(window, h, FALSE);
  654.                         erg = 1;
  655.                     }
  656.                     break;
  657.                 }
  658.                 /* Bei Namenlos zu DO_SAVENEW */
  659.             case DO_SAVENEW:
  660.                 if (!t_ptr->namenlos)
  661.                     strcpy(name, t_ptr->filename);
  662.                 else
  663.                     strcpy(name, "");
  664.                 if (save_new(name, "*.qpj", rsc_string(SAVEPRJSTR)))
  665.                 {
  666.                     set_extension(name,"qpj");
  667.                     if ((erg=save_as(t_ptr,name))==0)
  668.                     {
  669.                         if (t_ptr->namenlos || note(1, 2, GETNAME) == 1)
  670.                         {
  671.                             set_text_name(t_ptr, name, FALSE);
  672.                             chg_prj_name(icon);
  673.                             t_ptr->moved = 0;
  674.                             t_ptr->file_date_time = file_time(name,NULL,NULL);
  675.                             t_ptr->readonly = file_readonly(name);
  676.                         }
  677.                         file_name(t_ptr->filename, h, TRUE);
  678.                         change_window(window, h, FALSE);
  679.                         erg = 1;
  680.                     }
  681.                 }
  682.                 break;
  683.             case DO_UPDATE :
  684.                 redraw_window(window, &window->work);
  685.                 erg = 1;
  686.                 break;
  687.             case DO_PRINT    :
  688.                 if (t_ptr->namenlos)
  689.                     strcpy(file, t_ptr->filename);
  690.                 else
  691.                     file_name(t_ptr->filename, file, FALSE);
  692.                 if (prn_start_dial(NULL))
  693.                     txt_drucken(file,t_ptr);
  694.                 erg = 1;
  695.                 break;
  696.             case DO_HELP    :
  697.                 erg = call_hyp(rsc_string(HYPPRJSTR));
  698.                 break;
  699.             case DO_ADD :
  700.                 if (df_path[0]!=EOS)             /* Pfad durchsuchen */
  701.                 {
  702.                     graf_mouse(HOURGLASS, NULL);
  703.                     strcpy(h, df_path);
  704. /*
  705.                     if (fs_case_sens(df_path) == NO_CASE)
  706.                         str_toupper(ff_mask);
  707. */
  708.                     find_files(h, ff_rekursiv, ff_mask, icon, TEMP_LINK);
  709.                     graf_mouse(ARROW, NULL);
  710.                     redraw_window(window, &window->work);
  711.                 }
  712.                 break;
  713.             case DO_AUTOSAVE:
  714.                 p_icon_edit(icon, DO_SAVE);
  715.                 break;
  716.         }
  717.     }
  718.     return erg;
  719. }
  720.  
  721. /***************************************************************************/
  722. /* Ein Icon wurde auf ein Projekt-Icon geschoben                                    */
  723. /***************************************************************************/
  724.  
  725. static bool p_icon_drag(int icon, int source)
  726. {
  727.     WINDOWP     window = get_window(icon);
  728.     bool    erg = FALSE;
  729.     PATH        h;
  730.  
  731.      if ((window->flags & WI_ICONIFIED) || (window->flags & WI_SHADED))
  732.          return FALSE;
  733.  
  734.     switch (source)
  735.     {
  736.         case DRAGDROP_FILE :
  737.             if (drag_filename[0] != EOS)
  738.             {
  739.                 erg = add_to_projekt(icon, drag_filename, TRUE);
  740.                 drag_filename[0] = EOS;
  741.             }
  742.             break;
  743.         case DRAGDROP_PATH :
  744.             if (drag_filename[0] != EOS)
  745.             {
  746.                 strcpy(df_path, drag_filename);
  747.                 erg = findfile_dial(df_path, FALSE);
  748.                 if (erg)
  749.                 {
  750.                     graf_mouse(HOURGLASS, NULL);
  751.                     strcpy(h, df_path);
  752. /*
  753.                     if (fs_case_sens(df_path) == NO_CASE)
  754.                         str_toupper(ff_mask);
  755. */
  756.                     find_files(h, ff_rekursiv, ff_mask, icon, TEMP_LINK);
  757.                     graf_mouse(ARROW, NULL);
  758.                     redraw_window(window, &window->work);
  759.                 }
  760.                 drag_filename[0] = EOS;
  761.             }
  762.             break;
  763.         case DRAGDROP_DATA :
  764.             Bconout(2, 7);
  765.             erg = FALSE;
  766.             break;
  767.         default:
  768.             if (debug_level)
  769.                 debug("projekt.p_icon_drag(): Unbekannter Mode %d\n", source);
  770.     }
  771.     return erg;
  772. }
  773. /***************************************************************************/
  774.  
  775. /*
  776.  * Dateien für Projekt suchen.
  777.  */
  778. static bool find_files(char *pfad, bool rekursiv, char *df_muster, int icon, int tmp_icon)
  779. {
  780.     TEXTP t_ptr;
  781.     char     *ptr;
  782.     bool    raus;
  783.     int    t_icon;
  784.     PATH    suchPfad;
  785.     DIR    *dh;
  786.  
  787.     if (s_str[0] != EOS)
  788.     {
  789.         t_ptr = new_text(tmp_icon);
  790.         if (t_ptr == NULL) 
  791.             return FALSE;
  792.     }
  793.     strcpy(suchPfad, pfad);
  794.     ptr = pfad + strlen(pfad);
  795.     dh = opendir(suchPfad);
  796.     if (dh != NULL)
  797.     {
  798.         struct dirent    *entry;
  799.         struct stat        st;
  800.  
  801.         do_find_icon = icon;
  802.         if (dh < 0)
  803.             return FALSE;
  804.         raus = FALSE;
  805.         entry = readdir(dh);
  806.         while (entry != NULL && !raus)
  807.         {
  808.             strcpy(ptr, entry->d_name);
  809.             if (stat(pfad, &st) == 0)
  810.             {
  811.                 if ((rekursiv) && (st.st_mode & S_IFDIR) && strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))
  812.                 {
  813.                     strcat(ptr, "\\");
  814.                     raus = find_files(pfad, rekursiv, df_muster, icon, tmp_icon + 1);
  815.                 }
  816.  
  817.                 if (!(st.st_mode & S_IFDIR) && filematch(entry->d_name, df_muster, -1))
  818.                 {
  819.                     if (s_str[0] != EOS)
  820.                     {
  821.                         if ((t_icon = text_still_loaded(pfad)) < 0)
  822.                         {
  823.                             set_text_name(t_ptr, pfad, FALSE);
  824.                             if (load(t_ptr, FALSE) < 0)
  825.                                 if (note(2, 0, BREAK) == 1)
  826.                                     break;
  827.                             if (!do_find(tmp_icon))
  828.                                 raus = TRUE;
  829.                             clear_text(t_ptr);
  830.                         }
  831.                         else
  832.                         {
  833.                             if (!do_find(t_icon))
  834.                                 raus = TRUE;
  835.                         }
  836.                     }
  837.                     else
  838.                         add_to_projekt(icon, pfad, TRUE);
  839.                 }
  840.             }
  841.             entry = readdir(dh);
  842.             if (check_for_abbruch() && note(1, 2, BREAK) == 1)
  843.                 raus = TRUE;
  844.         } /* while */
  845.         if (entry != NULL)
  846.             raus = TRUE;
  847.         closedir(dh);
  848.         if (s_str[0] != EOS)
  849.             destruct_text(t_ptr);
  850.         return raus;
  851.     }
  852.     return FALSE;
  853. }
  854.  
  855. /***************************************************************************/
  856.  
  857. static void get_prj_line(int link, int line, char *str)
  858. {
  859.     TEXTP     t_ptr = get_text(link);
  860.     ZEILEP    lauf;
  861.  
  862.     lauf = get_line(&t_ptr->text,line);
  863.     if (lauf != NULL)
  864.         strcpy(str, TEXT(lauf));
  865.     else
  866.         str[0] = EOS;
  867. }
  868.  
  869. /***************************************************************************/
  870.  
  871. static int del_from_projekt (int link, int line)
  872. {
  873.     TEXTP     t_ptr = get_text(link);
  874.     ZEILEP    lauf;
  875.     FILENAME    name;
  876.     
  877.     lauf = get_line(&t_ptr->text,line);
  878.     if (lauf!=NULL)
  879.     {
  880.         WINDOWP window = get_window(link);
  881.  
  882.         unclick_window();
  883.         if (t_ptr->text.lines>1)
  884.         {
  885.             col_delete(&t_ptr->text, lauf);
  886.             window->doc.h--;
  887.             set_sliders(window, VERTICAL, SLPOS+SLSIZE);
  888.             redraw_window(window,&window->work);
  889.         }
  890.         else
  891.         {
  892.             REALLOC(&lauf,0,-lauf->len);
  893.             redraw_window(window,&window->work);
  894.         }
  895.         t_ptr->moved++;
  896.         if (t_ptr->namenlos)
  897.             strcpy(name, t_ptr->filename);
  898.         else
  899.             file_name(t_ptr->filename, name, TRUE);
  900.         change_window(window, name, TRUE);                /* '*' in den Titel */
  901.     }
  902.     return 1;
  903. }
  904.  
  905. bool add_to_projekt (int link, char *name, bool draw)
  906. {
  907.     int        erg, i;
  908.     TEXTP     t_ptr = get_text(link);
  909.     PATH        file;
  910.  
  911. /*
  912.     if (fs_case_sens(name) == NO_CASE)
  913.         str_toupper(name);
  914. */
  915.     strcpy(file,name);
  916. /*
  917.     if (!make_normalpath(file)) 
  918.         return FALSE;
  919. */
  920.     erg = 1; 
  921.     i = 0;
  922.     get_prj_line(link,i,file);
  923.  
  924.     /* Beim Vergleich case-ignore, damit GROSS und klein hintereinander kommen */
  925.     while (file[0] != EOS && (erg = stricmp(file, name)) < 0)
  926.     {
  927.         i++;
  928.         get_prj_line(link,i,file);
  929.     }
  930.     if (erg)             /* noch nicht vorhanden */
  931.     {
  932.         WINDOWP window = get_window(link);
  933.  
  934.         if (ist_leer(&t_ptr->text))
  935.         {
  936.             INSERT(&FIRST(&t_ptr->text),0,(int)strlen(name),name);
  937.             window->doc.h++;
  938.         }
  939.         else
  940.         {
  941.             ZEILEP new, lauf;
  942.  
  943.             if (i==0)
  944.                 lauf = &t_ptr->text.head;
  945.             else
  946.                 lauf= get_line(&t_ptr->text,i-1);
  947.             new = new_col(name,(int)strlen(name));
  948.             col_insert(lauf,new);
  949.             t_ptr->text.lines++;
  950.             window->doc.h++;
  951.             if (draw)
  952.                 set_sliders(window, VERTICAL, SLPOS+SLSIZE);
  953.         }
  954.         if (draw)
  955.             redraw_window(window,&window->work);
  956.         t_ptr->moved++;
  957.         if (t_ptr->namenlos)
  958.             strcpy(file, t_ptr->filename);
  959.         else
  960.             file_name(t_ptr->filename, file, TRUE);
  961.         change_window(window, file, TRUE);                    /* '*' in den Titel */
  962.         return TRUE;
  963.     }
  964.     return FALSE;
  965. }
  966.  
  967. int load_projekt(char *name)
  968. /* return: <=0 wurde nicht geladen */
  969. /*           0    weitere Texte versuchen sinnvoll */
  970. /*           <0    weiter Texte versuchen nicht sinnvoll */
  971. {
  972.     int        err, icon;
  973.     WINDOWP     window;
  974.     FILENAME datei;
  975.     PATH        path;
  976.     TEXTP     t_ptr;
  977.     ZEILEP    lauf;
  978.  
  979.     store_path(name);
  980.  
  981.     split_filename(name, path, datei);
  982.     if ((icon = text_still_loaded(name)) >= 0)    /* schon geladen */
  983.     {
  984.         if (do_icon(icon, DO_OPEN) < 0)                /* nur Fenster auf */
  985.             note(1, 0, NOWINDOW);
  986.         return icon;
  987.     }
  988.     icon = crt_new_prj(name);
  989.     if (icon<0)
  990.     {
  991.         note(1, 0, NOTEXT);
  992.         return -1;
  993.     }
  994.     t_ptr = get_text(icon);;
  995.     if ((err = load(t_ptr, TRUE)) == -33)        /* File not Found */
  996.     {
  997.         if (path_exists(path))
  998.         {
  999.             if (snote(1, 2, NEWTEXT, datei) == 2)
  1000.             {
  1001.                 icon_edit(icon,DO_DELETE);
  1002.                 return 0;
  1003.             }
  1004.         }
  1005.         else
  1006.         {
  1007.             snote(1, 0, READERR, datei);
  1008.             icon_edit(icon,DO_DELETE);
  1009.             return 0;
  1010.         }
  1011.     }
  1012.     else if (err)                                        /* anderer Fehler */
  1013.     {
  1014.         snote(1, 0, READERR, datei);
  1015.         icon_edit(icon,DO_DELETE);
  1016.         return 0;
  1017.     }
  1018.  
  1019.     window = get_window(icon);
  1020.     window->doc.y = 0;
  1021.  
  1022.     if (err == 0)                    /* nur wenn fehlerfrei geladen wurde! */
  1023.     {
  1024.         /* Zeilenenden säubern */
  1025.         strip_endings(t_ptr);
  1026.     
  1027.         /* Leerzeilen entfernen */
  1028.         lauf = FIRST(&t_ptr->text);
  1029.         while (!IS_TAIL(lauf))
  1030.         {
  1031.             ZEILEP    l = lauf->nachf;
  1032.     
  1033.             if (lauf->len == 0)
  1034.             {
  1035.                 col_delete(&t_ptr->text, lauf);
  1036.                 t_ptr->moved++;
  1037.             }
  1038.             lauf = l;
  1039.         }
  1040.     
  1041.         if (t_ptr->moved)
  1042.         {
  1043.             file_name(t_ptr->filename, datei, TRUE);
  1044.             change_window(window, datei, TRUE);
  1045.         }
  1046.     }
  1047.  
  1048.     window->doc.h = t_ptr->text.lines;
  1049.     if (do_icon(icon,DO_OPEN) < 0)
  1050.     {
  1051.         note(1, 0, NOWINDOW);
  1052.         icon_edit(icon,DO_DELETE);
  1053.         icon = -2;
  1054.     }
  1055.  
  1056.     if (strcmp(name, def_prj_path) == 0)        /* Default-Prj wurde geladen */
  1057.     {
  1058.         def_icon = icon;
  1059.         set_def_prj();
  1060.     }
  1061.     return icon;
  1062. }
  1063.  
  1064. static void destruct(int icon)
  1065. {
  1066.     TEXTP     t_ptr = get_text(icon);
  1067.     WINDOWP     window = get_window(icon);
  1068.  
  1069.     close_window(window);
  1070.     destruct_text(t_ptr);
  1071.     del_icon(icon);
  1072.     do_all_icon(prj_type,DO_UPDATE);     /* Projekte updaten */
  1073. }
  1074.  
  1075. /***************************************************************************/
  1076. /* Anlegen eines neuen Projekts                                                            */
  1077. /***************************************************************************/
  1078.  
  1079. int new_projekt(void)
  1080. {
  1081.     int    icon;
  1082.  
  1083.     icon = crt_new_prj("");
  1084.     if (icon < 0)
  1085.     {
  1086.         note(1, 0,NOTEXT);
  1087.         return -1;
  1088.     }
  1089.     if (do_icon(icon, DO_OPEN) < 0)
  1090.     {
  1091.         note(1, 0, NOWINDOW);
  1092.         icon_edit(icon, DO_DELETE);
  1093.         icon = -3;
  1094.     }
  1095.     return icon;
  1096. }
  1097.  
  1098. int crt_new_prj(char *filename)
  1099. {
  1100.     WINDOWP    win;
  1101.     bool        namenlos;
  1102.     TEXTP     t_ptr;
  1103.     PATH        name;
  1104.  
  1105.     strcpy(name, filename);
  1106.     if (name[0] == EOS)
  1107.     {
  1108.         strcpy(name, rsc_string(NAMENLOS));
  1109.         namenlos = TRUE;
  1110.     }
  1111.     else
  1112.         namenlos = FALSE;
  1113.  
  1114.     /* Fenster anlegen */
  1115.     win = create_window(KIND, CLASS_PROJEKT, crt_prj);
  1116.     if (win == NULL)
  1117.         return -1;
  1118.     if (!add_icon(prj_type, win->handle))
  1119.         return -1;
  1120.  
  1121.     /* Text kreiern */
  1122.     t_ptr = new_text(win->handle);
  1123.     if (t_ptr == NULL)
  1124.     {
  1125.         del_icon(win->handle);
  1126.         return -1;
  1127.     }
  1128.     set_text_name(t_ptr, name, namenlos);
  1129.  
  1130.     if (t_ptr->namenlos)
  1131.         strcpy(name, t_ptr->filename);
  1132.     else
  1133.         file_name(t_ptr->filename, name, TRUE);
  1134.     set_wtitle(win, name);
  1135.     set_winfo(win, "");
  1136.  
  1137.     if (!namenlos)
  1138.         do_all_icon(prj_type,DO_UPDATE);     /* Projekte updaten */
  1139.  
  1140.     t_ptr->asave = time(NULL);
  1141.  
  1142.     return win->handle;
  1143. }
  1144.  
  1145. /***************************************************************************/
  1146. /* Kreieren eines Fensters                                                                 */
  1147. /***************************************************************************/
  1148. static void crt_prj(WINDOWP window)
  1149. {
  1150.     int    initw, inith;
  1151.  
  1152.     if (window->work.g_w == 0 || window->work.g_h == 0)
  1153.     {
  1154.         /* Keine Grö₧e bekannt. */
  1155.         initw  = font_wcell * 13;
  1156.         inith  = (gl_desk.g_h / font_hcell) * font_hcell - 7 * font_hcell;
  1157.         window->work.g_x    = (font_wcell + 2) * 8;
  1158.         window->work.g_y    = 60;
  1159.         window->work.g_w    = initw;
  1160.         window->work.g_h    = inith;
  1161.     }
  1162.     
  1163.     window->flags        = FLAGS;
  1164.     window->doc.w        = 13;
  1165.     window->doc.h        = 0;
  1166.     window->xfac        = font_wcell;
  1167.     window->yfac        = font_hcell;
  1168.     window->w_width    = initw/font_wcell;
  1169.     window->w_height    = inith/font_hcell;
  1170.     window->draw        = wi_draw;
  1171.     window->click        = wi_click;
  1172.     window->unclick    = wi_unclick;
  1173.     window->key         = wi_key;
  1174.     window->snap        = wi_snap;
  1175.     window->iconify    = wi_iconify;
  1176.     window->uniconify = wi_uniconify;
  1177. }
  1178.  
  1179. /***************************************************************************/
  1180. /* Öffnen des Objekts                                                                        */
  1181. /***************************************************************************/
  1182. static bool open_prj (int icon)
  1183. {
  1184.     bool    ok = TRUE;
  1185.     WINDOWP     window = get_window(icon);
  1186.  
  1187.     if (window->flags & WI_ICONIFIED)
  1188.         uniconify_window(window, NULL);
  1189.     else if (window->flags & WI_SHADED)
  1190.         shade_window(window, -1);
  1191.     else if (window->flags & WI_OPEN)
  1192.         top_window (window);
  1193.     else
  1194.         ok = open_window (window);
  1195.     return ok;
  1196. }
  1197.  
  1198. /***************************************************************************/
  1199.  
  1200. static void draw_line (WINDOWP window, int line)
  1201. {
  1202.     TEXTP t_ptr;
  1203.     GRECT    r;
  1204.  
  1205.     t_ptr = get_text(window->handle);
  1206.     if (line >= t_ptr->text.lines) 
  1207.         return;
  1208.     line -= (int)window->doc.y;
  1209.     if (line < 0) 
  1210.         return;
  1211.     if (line>=window->w_height) return;
  1212.     r.g_x = window->work.g_x;
  1213.     r.g_y = window->work.g_y + line * font_hcell;
  1214.     r.g_w = window->work.g_w;
  1215.     r.g_h = font_hcell;
  1216.     redraw_window(window, &r);
  1217. }
  1218.  
  1219. static void wi_draw (WINDOWP window, GRECT *d)
  1220. {
  1221.     ZEILEP lauf;
  1222.     TEXTP t_ptr;
  1223.     int    line, y, x, i, link;
  1224.     PATH    name, str;
  1225.  
  1226.     set_clip(TRUE,d);
  1227.     line = (int)window->doc.y;
  1228.     y = window->work.g_y;
  1229.     x = window->work.g_x;
  1230.     i = window->w_height;
  1231.     if (d->g_y > y)
  1232.     {
  1233.         int anz;
  1234.  
  1235.         anz = (d->g_y - y) / font_hcell;
  1236.         line += anz;
  1237.         y += anz * font_hcell;
  1238.         i -= anz;
  1239.     }
  1240.     if (d->g_y + d->g_h < window->work.g_y + window->work.g_h)
  1241.     {
  1242.         int anz;
  1243.  
  1244.         anz = ((window->work.g_y + window->work.g_h)-(d->g_y + d->g_h)) / font_hcell;
  1245.         i -= anz;
  1246.     }
  1247.     link = window->handle;
  1248.     t_ptr = get_text(link);
  1249.     lauf = get_line(&t_ptr->text,line);
  1250.     if (lauf!=NULL)
  1251.     {
  1252.         while ((--i)>=0)
  1253.         {
  1254.             get_prj_line(link, line, str);
  1255.             if (str[0] == EOS)
  1256.             {
  1257.                 i++;
  1258.                 break;
  1259.             }
  1260.  
  1261.             if (text_still_loaded(str) >= 0) 
  1262.                 name[0] = '*';
  1263.             else 
  1264.                 name[0] = ' ';
  1265.             make_shortpath(str, name + 1, window->w_width - 1);
  1266.             if (window == sel_window && setin(sel_objs,line))
  1267.                 out_sb(x, y, window->work.g_w, name);
  1268.             else
  1269.                 out_s(x, y, window->work.g_w, name);
  1270.             line++;
  1271.             y += font_hcell;
  1272.         }
  1273.     }
  1274.     for (; (--i)>=0; y += font_hcell)
  1275.         fill_area(x, y, window->work.g_w, font_hcell, bg_color);
  1276. }
  1277.  
  1278. /***************************************************************************/
  1279. int drag_box(int x, int y, int w, int h, int *m_x, int *m_y, int *bstate, int *kstate)
  1280. {
  1281.     int    wh, d;
  1282.     
  1283.     graf_mouse(FLAT_HAND, NULL);
  1284.     graf_dragbox(w, h, x, y, gl_desk.g_x, gl_desk.g_y, gl_desk.g_w, gl_desk.g_h, &d, &d);
  1285.     graf_mouse(ARROW, NULL);
  1286.     graf_mkstate(m_x, m_y, bstate, kstate);
  1287.     wh = wind_find(*m_x, *m_y);
  1288.     return wh;
  1289. }
  1290.  
  1291. static void    wi_click (WINDOWP window, int m_x, int m_y, int bstate, int kstate, int breturn)
  1292. {
  1293.     int        y;
  1294.     GRECT        *s = &window->work;
  1295.     PATH        str;
  1296.     SET        new_obj;
  1297.     
  1298.     if (bstate & 2)                                /* Rechtsklick */
  1299.         return;
  1300.  
  1301.     if (!inside(m_x, m_y, s))
  1302.         return;
  1303.  
  1304.     if (sel_window != window)
  1305.         unclick_window();
  1306.     set_winfo(window,"");
  1307.  
  1308.     y = (int)(window->doc.y) + (m_y - s->g_y) / font_hcell;
  1309.     get_prj_line(window->handle, y, str);
  1310.     if (str[0] == EOS)
  1311.         return;
  1312.  
  1313.     setclr(new_obj);
  1314.     setincl(new_obj, y);                                    /* Aktuelles Objekt */
  1315.  
  1316.     if (kstate & (K_RSHIFT|K_LSHIFT))
  1317.     {
  1318.         setxor(sel_objs, new_obj);
  1319.         if (setcmp(sel_objs, NULL))
  1320.             sel_window = NULL;
  1321.         else
  1322.             sel_window = window;
  1323.         draw_line (window, y);
  1324.         if (!setin (sel_objs, y))
  1325.         {
  1326.             graf_mkstate(&m_x, &m_y, &bstate, &kstate);
  1327.             if (bstate & 1)                        /* Immernoch gedrückt ? */
  1328.                 evnt_button(1, 1, 0, &m_x, &m_y, &bstate, &kstate);
  1329.             return;
  1330.         }
  1331.     }
  1332.     else                                                         /* noch nicht angeklickt */
  1333.     {
  1334.         graf_mkstate(&m_x, &m_y, &bstate, &kstate);
  1335.         if (!(bstate & 1))                                /* Immernoch gedrückt -> nichts tun */
  1336.         {
  1337.             bool    re_sel;
  1338.  
  1339.             re_sel = setcmp(new_obj, sel_objs);
  1340.             unclick_window ();                            /* Alle Objekte löschen */
  1341.  
  1342.             /* re_sel ist TRUE, wenn ein Eintrag zum zweiten Mal selektiert wurde
  1343.              * -> wieder deselektieren.
  1344.             */
  1345.             if (!re_sel)
  1346.             {
  1347.                 setincl(sel_objs, y);
  1348.                 sel_window = window;
  1349.             }
  1350.             draw_line(window, y);
  1351.         }
  1352.     }
  1353.     if (breturn == 1 && (bstate & 1))                /* Zieh-Operation */
  1354.     {
  1355.         GRECT        first;
  1356.         int        num_objs, i, obj;
  1357.         WINDOWP    qed_win;
  1358.  
  1359.         graf_mkstate(&m_x, &m_y, &bstate, &kstate);
  1360.         if (!(bstate & 1))
  1361.             return;                                             /* Immernoch gedrückt ? */
  1362.  
  1363.         if (window == sel_window)
  1364.             setcpy(new_obj, sel_objs);
  1365.         num_objs = 0;
  1366.         for (i = 0; i < window->w_height; i++)
  1367.         {
  1368.             if (setin(new_obj, i + (int)window->doc.y))
  1369.             {
  1370.                 if (num_objs == 0)        /* Abmessungen des ersten merken */
  1371.                 {
  1372.                     first.g_x = s->g_x;
  1373.                     first.g_y = s->g_y + (i * font_hcell);
  1374.                     first.g_w = s->g_w;
  1375.                 }
  1376.                 num_objs++;
  1377.             }
  1378.         }
  1379.         obj = drag_box(first.g_x, first.g_y, first.g_w, font_hcell * num_objs, &m_x, &m_y, &bstate, &kstate);
  1380.         qed_win = get_window(obj);
  1381.         if (qed_win)                                                /* eigenes Fenster */
  1382.         {
  1383.             if (qed_win != window && (qed_win->class == CLASS_PROJEKT ||
  1384.                                               qed_win->class == CLASS_EDIT))
  1385.             {
  1386.                 drag_data_size = num_objs;
  1387.                 for (i = 0; i < window->w_height; i++)
  1388.                     if (setin(new_obj, i + (int)window->doc.y))
  1389.                     {
  1390.                         get_prj_line(window->handle, i + (int)window->doc.y, drag_filename);
  1391.                         if (drag_filename[0] == EOS)
  1392.                             break;
  1393.                         if ((kstate & K_ALT) || (qed_win->class == CLASS_PROJEKT))
  1394.                             icon_drag(qed_win->handle, DRAGDROP_FILE);
  1395.                         if (kstate & (K_LSHIFT|K_RSHIFT))
  1396.                             icon_drag(qed_win->handle, DRAGDROP_PATH);
  1397.                     }
  1398.                 drag_data_size = 0;
  1399.             }
  1400.         }
  1401.         else                                                            /* fremdes Fenster */
  1402.         {
  1403.             /* 
  1404.              * Bisher wird immer an den Desktop geschickt,
  1405.              * aber nur, wenn dieser AV_DRAG_ON_WINDOW kann.
  1406.             */
  1407.             if ((av_shell_id >= 0) && (av_shell_status & 512))
  1408.             {        
  1409.                 if (num_objs > 1)
  1410.                 {
  1411.                     drag_data_size = (long)num_objs * sizeof(PATH);
  1412.                     drag_data = (char *)malloc(drag_data_size);
  1413.                     strcpy(drag_data, "");
  1414.                 }
  1415.                 else
  1416.                 {
  1417.                     drag_data_size = 0L;
  1418.                     drag_data = NULL;
  1419.                 }
  1420.                     
  1421.                 i = check_avobj(m_x, m_y);
  1422.                 if (i == 1 || i == 2)                        /* Papierkorb/Shredder */
  1423.                 {
  1424.                     setcpy(sel_objs, new_obj);
  1425.                     do_icon(window->handle+SUB_ICON, DO_DELETE);
  1426.                 }
  1427.                 else
  1428.                 {
  1429.                     for (i=0; i<window->w_height; i++)
  1430.                     {
  1431.                         if (setin(new_obj, i + (int)window->doc.y))
  1432.                         {
  1433.                             get_prj_line(window->handle, i + (int)window->doc.y, drag_filename);
  1434.                             if (drag_filename[0] != EOS)
  1435.                             {
  1436.                                 if (num_objs > 1)
  1437.                                 {
  1438.                                     if (drag_data[0] != EOS)
  1439.                                         strcat(drag_data, " ");
  1440.                                     strcat(drag_data, drag_filename);
  1441.                                 }
  1442.                                 /*    else steht das Arg in drag_filename */
  1443.                             }
  1444.                         }
  1445.                     } /* for */
  1446.     
  1447.                     if (num_objs > 1)
  1448.                         send_avdrag(obj, m_x, m_y, kstate, DRAGDROP_DATA);
  1449.                     else
  1450.                         send_avdrag(obj, m_x, m_y, kstate, DRAGDROP_PATH);
  1451.                 }
  1452.                 if (drag_data_size > 0)
  1453.                 {
  1454.                     free(drag_data);
  1455.                     drag_data_size = 0;
  1456.                 }
  1457.             } /* if av_ */
  1458.         } /* if !my_window */
  1459.     }
  1460.     if (breturn == 2)                                        /* Doppelklick */
  1461.     {
  1462.         unclick_window();
  1463.         sel_window = window;
  1464.         setincl(sel_objs,y);
  1465.         draw_line(window,y);
  1466.         graf_mkstate(&m_x, &m_y, &bstate, &kstate);
  1467.         if (bstate & 1)                                    /* Immernoch gedrückt ? */
  1468.             evnt_button(1, 1, 0, &m_x, &m_y, &bstate, &kstate);
  1469.         do_icon(window->handle + SUB_ICON, DO_OPEN);
  1470.     }
  1471. }
  1472.  
  1473. /***************************************************************************/
  1474.  
  1475. static void wi_unclick (WINDOWP window)
  1476. {
  1477.     SET    help;
  1478.     int    i, max;
  1479.  
  1480.     setcpy(help,sel_objs);
  1481.     setclr(sel_objs);
  1482.     max = setmax(help);
  1483.     for (i=setmin(help); i<=max; i++)
  1484.         if (setin(help,i))
  1485.             draw_line(window,i);
  1486.     set_winfo(window,"");
  1487. }
  1488.  
  1489. /***************************************************************************/
  1490.  
  1491. static void sel_line(WINDOWP window, int line)
  1492. {
  1493.     if (sel_window!=NULL)
  1494.         unclick_window();
  1495.     sel_window = window;
  1496.     setincl(sel_objs,line);
  1497.     draw_line(window,line);
  1498.     line -= (int) window->doc.y;
  1499.     if (line<0)
  1500.         arrow_window(window,WA_UPLINE,-line);
  1501.     else
  1502.     {
  1503.         line -= (window->w_height-1);
  1504.         if (line>0)
  1505.             arrow_window(window,WA_DNLINE,line);
  1506.     }
  1507. }
  1508.  
  1509.  
  1510. static void shift_up(WINDOWP window)
  1511. {
  1512.     int    i;
  1513.  
  1514.     if (window->doc.h == 0)
  1515.         return;
  1516.     if (sel_window == window)
  1517.     {
  1518.         i = setmin(sel_objs);
  1519.         if (i == 0)
  1520.             return ;
  1521.         i -= window->w_height;
  1522.         if (i < 0)
  1523.             i = 0;
  1524.         sel_line(window,i);
  1525.     }
  1526.     else
  1527.         sel_line(window, (int)window->doc.h-1);
  1528. }
  1529.  
  1530. static void shift_down(WINDOWP window)
  1531. {
  1532.     int    i;
  1533.  
  1534.     if (window->doc.h == 0)
  1535.         return ;
  1536.     if (sel_window == window)
  1537.     {
  1538.         i = setmin(sel_objs);
  1539.         if (i == window->doc.h - 1)
  1540.             return ;
  1541.         i += window->w_height;
  1542.         if (i >= window->doc.h)
  1543.             i = (int) window->doc.h - 1;
  1544.         sel_line(window,i);
  1545.     }
  1546.     else
  1547.         sel_line(window,0);
  1548. }
  1549.  
  1550. static bool    wi_key(WINDOWP window, int kstate, int kreturn)
  1551. {
  1552.     bool    erg;
  1553.     int    nkey, i;
  1554.     int    ascii_code;
  1555.     bool    shift, ctrl, alt;
  1556.     
  1557.     /* Key konvertieren */    
  1558.     nkey = gem_to_norm(kstate, kreturn);
  1559.     nkey &= ~(NKF_RESVD|NKF_SHIFT|NKF_CTRL|NKF_CAPS);
  1560.     ascii_code = nkey & 0x00FF;
  1561.     shift = (kstate & (K_RSHIFT|K_LSHIFT)) != 0;
  1562.     ctrl = (kstate & K_CTRL) != 0;
  1563.     alt = (kstate & K_ALT) != 0;
  1564.     
  1565.     /* Damit F-Tasten zum System-Desktop kommen! */
  1566.     if ((kreturn >= 0x3B00 && kreturn <= 0x4400) ||
  1567.          (kreturn >= 0x5400 && kreturn <= 0x5D00))
  1568.         return FALSE;
  1569.  
  1570.     erg = FALSE;
  1571.     if ((nkey & NKF_FUNC) && shift)
  1572.     {
  1573.         nkey &= ~NKF_FUNC;
  1574.         switch (nkey)
  1575.         {
  1576.             case NK_CLRHOME :
  1577.                 v_slider(window, 1000);
  1578.                 sel_line(window, (int)window->doc.h - 1);
  1579.                 erg = TRUE;
  1580.                 break;
  1581.             case NK_UP    :
  1582.                 shift_up(window);
  1583.                 erg = TRUE;
  1584.                 break;
  1585.             case NK_DOWN:
  1586.                 shift_down(window);
  1587.                 erg = TRUE;
  1588.                 break;
  1589.             default:
  1590.                 erg = FALSE;
  1591.                 break;
  1592.         }
  1593.     }
  1594.     else if (nkey & NKF_FUNC)
  1595.     {
  1596.         nkey &= ~NKF_FUNC;
  1597.         switch (nkey)
  1598.         {
  1599.             case NK_RET :
  1600.             case (NK_ENTER|NKF_NUM) :
  1601.                 do_icon(window->handle + SUB_ICON, DO_OPEN);
  1602.                 erg = TRUE;
  1603.                 break;
  1604.             case NK_CLRHOME :
  1605.                 v_slider(window, 0);
  1606.                 sel_line(window,0);
  1607.                 erg = TRUE;
  1608.                 break;
  1609.             case NK_UP :
  1610.                 if (window->doc.h == 0)
  1611.                     break;
  1612.                 if (sel_window == window)
  1613.                 {
  1614.                     i = setmin(sel_objs);
  1615.                     if (i == 0)
  1616.                         break;
  1617.                     i--;
  1618.                     if (i < 0)
  1619.                         i = 0;
  1620.                     sel_line(window,i);
  1621.                 }
  1622.                 else
  1623.                     sel_line(window, (int)window->doc.h - 1);
  1624.                 erg = TRUE;
  1625.                 break;
  1626.             case NK_DOWN:
  1627.                 if (window->doc.h == 0)
  1628.                     break;
  1629.                 if (sel_window == window)
  1630.                 {
  1631.                     i = setmin(sel_objs);
  1632.                     if (i==window->doc.h-1)
  1633.                         break;
  1634.                     i++;
  1635.                     if (i >= window->doc.h)
  1636.                         i = (int) window->doc.h-1;
  1637.                     sel_line(window,i);
  1638.                 }
  1639.                 else
  1640.                     sel_line(window,0);
  1641.                 erg = TRUE;
  1642.                 break;
  1643.             case NK_HELP :
  1644.                 erg = FALSE;                /* DO_HELP wird von key_global verteilt */
  1645.                 break;
  1646.             case NK_M_PGUP:                /* Mac: page up -> shift-up */
  1647.                 shift_up(window);
  1648.                 erg = TRUE;
  1649.                 break;
  1650.             case NK_M_PGDOWN:                /* Mac: page down -> shift-down */
  1651.                 shift_down(window);
  1652.                 erg = TRUE;
  1653.                 break;
  1654.             case NK_M_END:                    /* Mac: end -> shift-home */
  1655.                 v_slider(window, 1000);
  1656.                 sel_line(window, (int)window->doc.h - 1);
  1657.                 erg = TRUE;
  1658.                 break;
  1659.             case NK_DEL :
  1660.                 do_icon(window->handle + SUB_ICON, DO_DELETE);
  1661.                 erg = TRUE;
  1662.                 break;
  1663.             default:
  1664.                 if (!ctrl && !alt && !shift && ascii_code)
  1665.                 {
  1666.                     if (sel_window == window)
  1667.                         unclick_window();
  1668.                     else
  1669.                         set_winfo(window,"");
  1670.                     erg = TRUE;
  1671.                 }
  1672.                 else
  1673.                     erg = FALSE;
  1674.                 break;
  1675.         }
  1676.     }
  1677.     else
  1678.     {
  1679.         int        l;
  1680.         FILENAME name;
  1681.         PATH        str, info;
  1682.         char        asc;
  1683.         
  1684.         /* Auto-Locator */
  1685. /*
  1686.         asc = nkc_toupper(ascii_code);
  1687. */
  1688.         asc =ascii_code;
  1689.         strcpy(info, window->info);
  1690.         l = (int)strlen(info);
  1691.         info[l++] = asc;
  1692.         info[l] = EOS;
  1693.         i = 0;
  1694.         do
  1695.         {
  1696.             get_prj_line(window->handle,i,str);
  1697.             i++;
  1698.             if (str[0] == EOS)
  1699.                 break;
  1700.             file_name(str,name, FALSE);
  1701. /*
  1702.             str_toupper(name);
  1703. */
  1704.         }
  1705.         while (strnicmp(name, info, l) != 0);
  1706.         if (str[0]!=EOS)
  1707.         {
  1708.             sel_line(window,i-1);
  1709.             set_winfo(window,info);
  1710.         }
  1711.         erg = TRUE;
  1712.     }
  1713.     return erg;
  1714. }
  1715.  
  1716. /***************************************************************************/
  1717.  
  1718. static void    wi_snap(WINDOWP window, GRECT *new, int mode)
  1719. {
  1720.     int w, ex, pxy[8];
  1721.  
  1722.     /* zunächst Platz für min. 1+Filename+1 im Fenster */
  1723.     vqt_extent(vdi_handle, "x", pxy);
  1724.     ex = pxy[2] - pxy[0];
  1725.     w = new->g_w;
  1726.     if (w < 14 * ex)
  1727.         w = 14 * ex;
  1728.  
  1729.     /* nun noch Platz für Fenstertitel (1+8+1) */
  1730.     if (w < gl_wchar * 10)
  1731.         w = gl_wchar * 10;
  1732.  
  1733.     new->g_w = w;
  1734. }
  1735.  
  1736.  
  1737. static void wi_iconify(WINDOWP window)
  1738. {
  1739.     TEXTP     t_ptr = get_text(window->handle);
  1740.     FILENAME short_name;
  1741.  
  1742.     if (t_ptr->namenlos)
  1743.         strcpy(short_name, t_ptr->filename);
  1744.     else
  1745.         make_shortpath(t_ptr->filename, short_name, 8);
  1746.     set_wtitle(window, short_name);
  1747. }
  1748.  
  1749.  
  1750. static void wi_uniconify(WINDOWP window)
  1751. {
  1752.     TEXTP     t_ptr = get_text(window->handle);
  1753.     FILENAME name;
  1754.  
  1755.     if (t_ptr->namenlos)
  1756.         strcpy(name, rsc_string(NAMENLOS));
  1757.     else
  1758.         file_name(t_ptr->filename, name, TRUE);
  1759.     set_wtitle(window, name);
  1760. }
  1761.  
  1762. /***************************************************************************/
  1763. /* Info des Objekts                                                                            */
  1764. /***************************************************************************/
  1765.  
  1766. static long     i_len, i_bytes;
  1767. static int        i_anz, i_icon;
  1768.     
  1769. static int count(int icon, int i)
  1770. {
  1771.     PATH    name;
  1772.  
  1773.     i_anz++;
  1774.     get_prj_line(icon, i, name);
  1775.     if ((icon = text_still_loaded(name))>=0)
  1776.     {
  1777.         TEXTP t_ptr;
  1778.  
  1779.         t_ptr = get_text(icon);
  1780.         i_bytes += textring_bytes(&t_ptr->text);
  1781.         i_len += t_ptr->text.lines;
  1782.         return 1;
  1783.     }
  1784.     else
  1785.     {
  1786.         long    b,l;
  1787.         int    antw;
  1788.  
  1789.         antw = infoload(name,&b,&l);
  1790.         i_bytes += b;
  1791.         i_len += l;
  1792.         return (antw == 0) ? 1 : 0;
  1793.     }
  1794. }
  1795.  
  1796. static void info_projekt(int icon)
  1797. {
  1798.     char     str[32], date[11];
  1799.     TEXTP t_ptr = get_text(icon);
  1800.     int    r_anz, i, antw;
  1801.     SET    all;
  1802.     bool    close = FALSE;
  1803.     MDIAL    *dial;
  1804.     
  1805.     set_state(prjinfo, IPRJSCAN, DISABLED, FALSE);
  1806.     i_icon = icon;
  1807.     make_shortpath(t_ptr->filename, str, 30);
  1808.     set_string(prjinfo, PRJNAME, str);         /* Name mit Pfad */
  1809.     if (ist_leer(&t_ptr->text))
  1810.         r_anz = 0;
  1811.     else
  1812.         r_anz = (int)t_ptr->text.lines;
  1813.     set_int(prjinfo, PRJFILES, r_anz);        /* Dateien-Anzahl */
  1814.     set_string(prjinfo, PRJLEN , "??");     /* Länge in Bytes unbekannt */
  1815.     set_string(prjinfo, PRJZEILE , "??");    /* Länge in Zeilen unbekannt */
  1816.     if (t_ptr->namenlos)
  1817.     {
  1818.         strcpy(str, "");
  1819.         strcpy(date, "--");
  1820.     }
  1821.     else
  1822.         file_time (t_ptr->filename, date, str);
  1823.     set_string(prjinfo, PRJDATUM, date);    /* Datum */
  1824.     set_string(prjinfo, PRJZEIT, str);         /* Uhrzeit */
  1825.  
  1826.     dial = open_mdial(prjinfo, 0);
  1827.     if (dial != NULL)
  1828.     {
  1829.         while (!close)
  1830.         {
  1831.             antw = do_mdial(dial) & 0x7fff;
  1832.             switch (antw)
  1833.             {
  1834.                 case IPRJSCAN:
  1835.                     if (ist_leer(&t_ptr->text))
  1836.                         r_anz = 0;
  1837.                     else
  1838.                         r_anz = (int) t_ptr->text.lines;
  1839.                     i_anz = 0;
  1840.                     i_bytes = 0;
  1841.                     i_len = 0;
  1842.                     setclr(all);
  1843.                     for (i = r_anz; (--i)>=0; )
  1844.                         setincl(all, i);
  1845.                     do_for_prj(i_icon, all, count, TRUE);
  1846.                     if (r_anz == i_anz)                                    /* alle durchlaufen */
  1847.                         ltoa(i_bytes, str, 10);
  1848.                     else
  1849.                         str[0] = EOS;
  1850.                     set_string(prjinfo, PRJLEN , str);             /* Länge in Bytes */
  1851.                     if (r_anz == i_anz)
  1852.                         ltoa(i_len, str, 10);
  1853.                     else
  1854.                         str[0] = EOS;
  1855.                     set_string (prjinfo, PRJZEILE , str);        /* Länge in Zeilen */
  1856.                     if (r_anz == i_anz)                                /* alle durchlaufen */
  1857.                         set_state(prjinfo, IPRJSCAN, DISABLED, TRUE);
  1858.                     set_state(prjinfo, IPRJSCAN, SELECTED, FALSE);
  1859.                     redraw_mdobj(dial, 0);
  1860.                     break;
  1861.         
  1862.                 default:
  1863.                     close = TRUE;
  1864.                     break;
  1865.             }
  1866.         }
  1867.         set_state(prjinfo, antw, SELECTED, FALSE);
  1868.         close_mdial(dial);
  1869.     }
  1870. }
  1871.  
  1872. /******************************************************************************/
  1873. /* Default-Projekt                                                                                */
  1874. /******************************************************************************/
  1875.  
  1876. void    open_def_prj(void)
  1877. {
  1878.     if (def_prj_path[0] != EOS && shift_pressed())    /* altes abmelden */
  1879.     {
  1880.         def_prj_path[0] = EOS;
  1881.         def_icon = -1;
  1882.     }
  1883.     else if (def_prj_path[0] != EOS)                 /* bekanntes öffnen */
  1884.         load_projekt(def_prj_path);
  1885.     else
  1886.         select_def_prj();                                 /* nix bekannt, also auswählen */
  1887.     set_def_prj();                                         /* Menü anpassen */
  1888. }
  1889.  
  1890.  
  1891. void    add_to_def(void)
  1892. {
  1893.     WINDOWP w;
  1894.  
  1895.     w = real_top();
  1896.     if (w == NULL)
  1897.         return;
  1898.     if (w->handle != def_icon)
  1899.     {
  1900.         TEXTP t_ptr = get_text(w->handle);
  1901.  
  1902.         if (!t_ptr->namenlos)
  1903.             add_to_projekt(def_icon, t_ptr->filename, TRUE);
  1904.     }
  1905. }
  1906.  
  1907.  
  1908. static void    select_def_prj(void)
  1909. {
  1910.     PATH    name = "";
  1911.  
  1912.     if (select_single(name, "*.qpj", rsc_string(DEFPRJ2STR)))
  1913.     {
  1914.         strcpy(def_prj_path, name);
  1915.         load_projekt(def_prj_path);
  1916.     }
  1917. }
  1918.  
  1919.  
  1920. void set_def_prj(void)
  1921. {
  1922.     FILENAME n = "";
  1923.  
  1924.     if (def_icon == -1 || def_prj_path[0] == EOS)
  1925.     {
  1926.         menu_ienable(menu, MTAKEPRJ, FALSE);
  1927.         menu_icheck(menu, MPROJEKT, FALSE);
  1928.     }
  1929.     else
  1930.     {
  1931.         menu_ienable(menu, MTAKEPRJ, TRUE);
  1932.         menu_icheck(menu, MPROJEKT, TRUE);
  1933.     }
  1934.  
  1935.     /* Name ins Menü eintragen */
  1936.     if (def_prj_path[0] != EOS)
  1937.         file_name(def_prj_path, n, FALSE);
  1938.     else
  1939.         strcpy(n, rsc_string(DEFPRJSTR));
  1940.     fillup_menu(MPROJEKT, n, 2);
  1941. }
  1942.  
  1943. void find_on_disk(void)
  1944. {
  1945.     int    icon;
  1946.     TEXTP    t_ptr;
  1947.     
  1948.     icon = crt_new_prj("");
  1949.     if (icon < 0) 
  1950.         return;
  1951.     if (do_icon(icon, DO_OPEN) < 0)
  1952.     {
  1953.         note(1, 0, NOWINDOW);
  1954.         icon_edit(icon, DO_DELETE);
  1955.     }
  1956.     do_icon(icon, DO_ADD);
  1957.     t_ptr = get_text(icon);
  1958.     if (!t_ptr->moved)            /* nichts gefunden */
  1959.         icon_edit(icon, DO_DELETE);
  1960. }
  1961.  
  1962. /******************************************************************************/
  1963. /* Initialisierung                                                                                */
  1964. /******************************************************************************/
  1965.  
  1966. void init_projekt(void)
  1967. {
  1968.     get_path(df_path, 0);                            /* Aktuellen Pfad holen */
  1969.     prj_type = decl_icon_type(p_icon_test, p_icon_edit, p_icon_exist, p_icon_drag);
  1970.     def_prj_path[0] = EOS;
  1971.     def_icon = -1;
  1972. }
  1973.