home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / text / tex / pastex / source / driver / show / amiga / amscreen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-14  |  152.2 KB  |  5,674 lines

  1. #ifdef AMIGA
  2.  
  3. /*******************************************************************/
  4. /*                                                                 */
  5. /*  amscreen.c    Screenroutinen fuer den Bildschirmtreiber        */
  6. /*                showdvi                                          */
  7. /*                                                                 */
  8. /*                von Georg Hessmann                               */
  9. /*                11.07.88                                         */
  10. /*                                                                 */
  11. /*  void Open_Showdvi()                                            */
  12. /*  void close_all_bild()                                          */
  13. /*  void clear_bild()                                              */
  14. /*  int  ShowPage()                                                */
  15. /*  long *Init_all(long,long)                                      */
  16. /*                                                                 */
  17. /*******************************************************************/
  18.  
  19. #include "defines.h"
  20. #undef DEBUG
  21. #undef BACKGROUND
  22. #undef CATCH
  23. #define CATCH_ZERO
  24.  
  25.  
  26. /* #define DOS_DOSASL_H */
  27.  
  28. #include <sprof.h>
  29.  
  30. #include <stdio.h>
  31. #include <signal.h>
  32. #include <dos.h>
  33.  
  34.  
  35. #include <exec/types.h>
  36. #include <dos/dos.h>
  37. #include <dos/dostags.h>
  38. #include <dos/notify.h>
  39. #include <graphics/gfxbase.h>
  40. #include <graphics/scale.h>
  41. #include <graphics/gfxmacros.h>
  42. #include <graphics/layers.h>
  43. #include <intuition/intuitionbase.h>
  44. #include <intuition/intuition.h>
  45. #include <intuition/imageclass.h>
  46. #include <libraries/dos.h>
  47. #include <libraries/asl.h>
  48. #include <exec/execbase.h>
  49. #include <exec/tasks.h>
  50. #include <exec/memory.h>
  51. #include <devices/timer.h>
  52. #include <devices/printer.h>
  53. #include <libraries/dosextens.h>
  54. #include <libraries/dos.h>
  55. #include <workbench/icon.h>
  56. #include <workbench/workbench.h>
  57. #include <exec/devices.h>
  58. #include <devices/console.h>
  59.  
  60. #ifdef AZTEC_C
  61. #  include <functions.h>
  62. #endif
  63.  
  64. #include "globals.h"
  65.  
  66. #ifdef ANSI
  67. #  include <string.h>
  68. #  include <stdlib.h>
  69. #endif
  70.  
  71. #include <clib/intuition_protos.h>
  72. #include <clib/graphics_protos.h>
  73. #include <clib/layers_protos.h>
  74. #include <clib/exec_protos.h>
  75. #include <clib/dos_protos.h>
  76. #include <clib/timer_protos.h>
  77. #include <clib/diskfont_protos.h>
  78. #include <clib/alib_protos.h>
  79. #include <clib/gadtools_protos.h>
  80. #include <clib/wb_protos.h>
  81.  
  82. #include <pragmas/exec_pragmas.h>
  83. #include <pragmas/intuition_pragmas.h>
  84. #include <pragmas/layers_pragmas.h>
  85. #include <pragmas/icon_pragmas.h>
  86. #include <pragmas/wb_pragmas.h>
  87. #include <pragmas/dos_pragmas.h>
  88. #include <pragmas/gadtools_pragmas.h>
  89. #include <pragmas/graphics_pragmas.h>
  90. #include <pragmas/diskfont_pragmas.h>
  91. #include <pragmas/req.h>
  92.  
  93. #ifndef MTYPE_APPWINDOW
  94. # define MTYPE_APPWINDOW        7    /* msg from an app window */
  95. #endif
  96.  
  97. #include "version.h"
  98. #include "gad_def.h"
  99. #include "amscreen.h"
  100. #include "amprint.h"
  101. #include "minrexx.h"
  102. #include "arexx.h"
  103. #include "searchwin.h"
  104.  
  105. #include "bitmap.h"
  106. extern struct bitmap    map;
  107.  
  108. #include "amscreen.i"
  109. #include "amkey.i"
  110. #include "showdvi.i"
  111. #include "gadget.i"
  112. #include "messwin.i"
  113. #include "amprhelp.i"
  114. #include "am_requ.i"
  115. #include "am_menu.i"
  116. #include "dvihand.i"
  117. #include "globals.i"
  118. #include "config.i"
  119. #include "liste.i"
  120. #include "prefwin.i"
  121. #include "local.i"
  122. #include "help.i"
  123. #include "search.i"
  124. #include "fast_cp.i"    // SetRule()
  125. #include "searchwin.i"
  126. #include "fullpage.i"
  127.  
  128.  
  129. /* #include "pgscroll.i" */
  130. /* #include "swin.i" */
  131.  
  132. #include "newcli.i"
  133.  
  134. #if defined(APP_WINDOW)
  135. # include "app_win.i"
  136. #else
  137. # include "app_icon.i"
  138. #endif
  139.  
  140.  
  141. #if defined(ARP_LIBRARY)
  142. # include "small_arp.h"
  143. #endif
  144. #if defined(REQ_LIBRARY)
  145. # include <libraries/reqbase.h>
  146. #endif
  147.  
  148.  
  149.  
  150. /*
  151.  * Fuer die locale-Library:
  152.  *
  153.  * Hier duerfen *nur* die MSG_#? Nummern eingebunden werden!
  154.  * Achtung:
  155.  * Es muss/sollte 'multiple-include' erlaubt sein!
  156.  */
  157. #include "local.i"
  158.  
  159. #undef  CATCOMP_ARRAY
  160. #undef  CATCOMP_BLOCK
  161. #undef  CATCOMP_STRINGS
  162. #define CATCOMP_NUMBERS
  163. #include "localstr.h"
  164.  
  165.  
  166.  
  167.  
  168. /* lokale Funktionen */
  169. static void *OLib            Args((char *name, int vers, int required));
  170. static void OpenLib            Args((void));
  171. static void CloseLib             Args((void));
  172. static void InitBoopsi            Args((void));
  173. static void FreeBoopsi            Args((void));
  174. static void MyNewObject            Args((struct Image ** img,
  175.                           ULONG tag,
  176.                           char * str));
  177. static void MyDisposeObject        Args((APTR * obj));
  178. static void CPUBlit            Args((WORD SrcX, WORD SrcY, WORD DestX, WORD DestY, 
  179.                         WORD XSize, WORD YSize));
  180. static void CloseS            Args((void));
  181. static void CloseWin2            Args((void));
  182. static void CloseRastPort        Args((void));
  183. static int  test_anz_windows        Args((void));
  184. static void OpenRastPort        Args((void));
  185. static void close_fonts            Args((void));
  186. static void open_fonts            Args((void));
  187. static void OpenS            Args((void));
  188. static void OpenWin2            Args((void));
  189. #if 0
  190. static void DeleteTimer            Args((struct timerequest *timermsg));
  191. static void NewTimeRequest        Args((void));
  192. static struct timerequest *CreateTimer    Args((void));
  193. #endif
  194. static void start_print_page        Args((void));
  195. static void check_print_page        Args((void));
  196. static void __inline win_mov        Args((const long dx,
  197.                           const long dy,
  198.                           const long x,
  199.                           const long y));
  200. static ULONG GetWBModeID        Args((void));
  201. static int get_screen_dimension        Args((long *width,
  202.                           long *height,
  203.                           short *lace));
  204. static void set_resolution        Args((void));
  205. static void set_i_window_size        Args((void));
  206.  
  207. static int  InitDVINotify        Args((void));
  208. static int  EndDVINotify        Args((void));
  209. static long work_with_main_app_win    Args((void));
  210. static long intui_message        Args((void));
  211. static long scroll            Args((void));
  212. static void save_active_window        Args((void));
  213. static /*__stdargs*/ long  arexx_disp    Args((struct RexxMsg *msg,
  214.                           struct rexxCommandList *dat,
  215.                           char *p));
  216. static void sighandling            Args((int i));
  217. static void DeleteShowDVIVars        Args((void));
  218.  
  219. #ifdef CATCH
  220. static void onGURU            Args((void));
  221. #endif
  222.  
  223.  
  224.  
  225. static int is_cyber = 0;
  226. static int WidthSysDepthGadget = 0;
  227.  
  228. /*----------------------------------------------------------------------*/
  229. struct Screen        *screen  = NULL;
  230. struct Window        *win2    = NULL;
  231. struct AppWindow     *MainAppWin = NULL;    // AppWin bzgl. win2, falls screen ein WBSCR ist
  232. struct MsgPort        *MainAppWinMsgPort = NULL;
  233.  
  234. struct IntuitionBase    * IntuitionBase     = NULL;
  235. struct GfxBase        * GfxBase     = NULL;
  236. struct ArpBase        * ArpBase     = NULL;
  237. struct Library        * DiskfontBase   = NULL;
  238. struct Library        * WorkbenchBase     = NULL;
  239. struct Library        * IconBase     = NULL;
  240. struct Library        * GadToolsBase     = NULL;
  241. struct Library         * AslBase     = NULL;
  242. struct Library          * AmigaGuideBase = NULL;
  243. struct Library          * UtilityBase    = NULL;
  244. struct Library        * LayersBase     = NULL;
  245.  
  246. #if defined(REQ_LIBRARY)
  247.  struct ReqLib        *ReqBase    = NULL;
  248. #endif
  249.  
  250. struct Library        *ConsoleDevice  = NULL;
  251. struct IOStdReq     ConsoleReq;
  252.  
  253.  
  254.  
  255.  
  256. struct BitMap        BitMapWin;
  257. struct RastPort        myRastPort;
  258. #if 0
  259. struct timerequest    *TimeRequest = NULL;
  260. #endif
  261.  
  262. extern struct MsgPort    *printerPort;    /* aus util/amprhelp.c */
  263. extern union printerIO    *request;
  264.  
  265. extern long        current_page_phy;
  266. extern long        current_page;
  267.  
  268. extern DVIFILE         *dvifp;         /* DVI file pointer                    */
  269.  
  270.  
  271. extern struct Window    *MessWin;
  272. extern short         MessWinXpos;    /* wird in OpenS() auf -1 gesetzt */
  273. extern short         MessWinYpos;
  274.  
  275.  
  276.  
  277.  
  278. char task_name[]    = "ShowDVI-Task";        /* new task name */
  279. char *old_task_name    = NULL;                /* old task name */
  280. struct Window        *oldactiveWindow = NULL;    /* was active window */
  281.  
  282.  
  283. #if 0
  284. #define T_REPLYPORT    TimeRequest->tr_node.io_Message.mn_ReplyPort
  285. #endif
  286.  
  287. long wx,wy;                /* Breite-Hoehe der BitMap !!    */
  288.  
  289. long static_x_Koo,            /* akt. Anzeigekoo. der Bitmap    */
  290.      static_y_Koo;
  291.  
  292. /*
  293.  * Die folgenden 4 Variablen geben an, welcher Berei des Windows
  294.  * tatsaechlich von der Seite belegt wird.
  295.  * Normalerweise entsprechen die 4 Punkte den Window-Borders.
  296.  * Eben dann wenn eine Seite in keiner Richtung ganz in das Window
  297.  * passt. Wenn dem nicht so ist, dann geben die Werte eben an, wo
  298.  * die Seite dargestellt werden soll.
  299.  *
  300.  * Belegt werden die Werte in set_i_window_size();
  301.  *
  302.  * Benoetigt werden die Werte ueberall in den Anzeigefunktionen 
  303.  * und im Backfill Hook.
  304.  *
  305.  */
  306.  
  307. extern WORD Page_LeftPoint;
  308. extern WORD Page_RightPoint;
  309. extern WORD Page_TopPoint;
  310. extern WORD Page_BottomPoint;
  311.  
  312.  
  313.  
  314. short width_left_border;
  315. short width_right_border;
  316. short HeightScreenTitle;    
  317. short HeightWinTitle;
  318.  
  319. /* wird fuer das MEss-Window benoetigt */
  320. short FullPageLeftEdge;
  321. short FullPageTopEdge;
  322. short FullPageWidth;
  323. short FullPageHeight;
  324. short FullPageScreenXPos;    /* da war vor dem full-page der Screen */
  325. short FullPageScreenYPos;
  326.  
  327.  
  328. /* Variablen fuer die Full-Page */
  329. static struct BitMap   BitMapFullPage;
  330. static struct RastPort RastPortFullPage;
  331. static short BitMapFullPageWidth, BitMapFullPageHeight;
  332.  
  333. static struct Window *old_Win_Ptr_Requester = NULL;    /* aus der Taskstruktur */
  334.  
  335. static short    win_need_refresh = FALSE;    /* gesetzt bei neuem RPort, verwendet vor scroll() */
  336.  
  337. static struct NotifyRequest notify;
  338.  
  339. static int IsScreenReOpend;
  340.  
  341.  
  342. /*
  343.  * Zum IFF-Speichern der Seite
  344.  */
  345. #include "iff/ilbmapp.h"
  346. static struct ILBMInfo ilbm;
  347. static UWORD           bw_ctable[2] = { 0x0FFF, 0x0000 };
  348.  
  349.  
  350.  
  351. struct state show_state;    /* Anzeigezustand            */
  352.     /*  is_lace  == FALSE        Anzeige im LACE-Modus?        */
  353.     /*  is_show  == FALSE        full-page Anzeigemodus?        */
  354.     /*  is_gadg  == FALSE        Anzeige mit Scrollbars?        */
  355.     /*  is_print == FALSE        Laeuft ein Ausdruck?            */
  356.     /*  is_timer == FALSE        Laeuft ein Timer Event?        */
  357.     /*  is_pscro == FALSE        Pagescrollingmodus?            */
  358.     /*  is_colre == FALSE      Color Requester am Bildschirm    */
  359.     /*  is_about == FALSE      About-Requester am Bildschirm    */
  360.     /*  is_dvif  == FALSE       No DVI-File loadet            */
  361.     /*  ...               und vieles vieles mehr        */
  362.     /*  set_xxx           Aktivieren des jeweiligen Modi    */
  363.     /*  unset_xxx           Loeschen des jeweiligen Modi        */
  364.     /*  toggle_xxx           Umschalten des jeweiligen Modi    */
  365.  
  366.  
  367.  
  368.  
  369.  
  370. struct BoopsiObj BObj;    /* Boopsi Object/Images */
  371.  
  372.  
  373. struct current_color current_col;
  374. struct current_color default_col = { 3, 2, 2, 6, 7, 8, 13, 13, 13, 13, 0, 0};
  375.  
  376.  
  377. short    x_scr_width,        /* aktuelle Screen Breite-Hoehe        */ 
  378.     x_scr_height,
  379.     x_win_width,        /* aktuelle Window Breite-Hoehe        */
  380.     x_win_height,
  381.     x_win_i_width,        /* aktuelle 'innen' Window Breite-Hoehe    */
  382.     x_win_i_height;        /* abzueglich Scrollbar, falls vorhanden*/
  383.  
  384. #define winiw    x_win_i_width
  385. #define winih    x_win_i_height
  386.  
  387.  
  388. static short old_win_pos_x;    /* wird benoetigt um festzustellen, ob    */
  389. static short old_win_pos_y;    /* das Window verschoben wurde.        */
  390.  
  391.  
  392. char  PubScreenName[MAXPUBSCREENNAME+1];
  393. char  MyPubScreenName[MAXPUBSCREENNAME+1];
  394.  
  395.  
  396. struct TextFont    *font8;
  397. struct TextFont    *font11;
  398.  
  399. struct TextAttr    txtAttr8;
  400. struct TextAttr    txtAttr11;
  401. struct TextAttr txtAttr;        /* TxtAttr fuer Menues oder sonstiges */
  402. struct TextAttr GadtxtAttr;        /* TxtAttr fuer die Gadgets in der Wintow-Kopf-Zeile */
  403.  
  404. #define FONTNAME8    "topaz.font"
  405. #define FONTYSIZE8    8
  406. #define FONTXSIZE8    8        /* stimmt doch, oder? */
  407. #define FONTSTYLE8    FS_NORMAL
  408. #define FONTFLAGS8    FPF_ROMFONT
  409.  
  410. #define FONTNAME11    "topaz.font"
  411. #define FONTYSIZE11    11
  412. #define FONTXSIZE11    8        /* stimmt doch, oder? */
  413. #define FONTSTYLE11    FS_NORMAL
  414. #define FONTFLAGS11    FPF_DISKFONT
  415.  
  416.  
  417. /* wird fuer auto-load-again gebraucht */
  418. static short is_new_dvifile = TRUE;    /* das erste File ist immer ein neues File */
  419.  
  420.  
  421. int    background = FALSE;        /* start mit 'run' */
  422.  
  423. #ifdef BACKGROUND
  424. long _stack       = MIN_STACK_SIZE;    /* Stack space for the created task        */
  425. char *_procname       = "ShowDVI-Task";    /* Name of the process to be created        */
  426. long _priority       = 0;            /* The priority to create the process at    */
  427. long _BackGroundIO = 0;            /* The flag to indicate an I/O requirement    */
  428. #endif
  429.  
  430. #ifdef CATCH
  431. extern void *_ONGURU;
  432. #endif
  433.  
  434. static int timer_wait_ticks;    /* wait intervalls fou clearing message */
  435.  
  436. UBYTE sig_print, sig_timer, sig_win, sig_app, sig_appwin, sig_aboutwin, sig_messwin, 
  437.     sig_prefwin, sig_notify, sig_screenclose, sig_searchwin;
  438. ULONG sig_amigaguide_long;
  439.  
  440. #define SIG_PRINT    ((unsigned long)(1<<sig_print))       /* Ende der Hardcopy    */
  441. #define SIG_TIMER    ((unsigned long)(1<<sig_timer))       /* Ablauf des Timers    */
  442. #define SIG_WIN        ((unsigned long)(1<<sig_win))         /* Normale IntuiMess    */
  443. #define SIG_APP        ((unsigned long)(1<<sig_app))         /* WB-Application Message    */
  444. #define SIG_APPWIN    ((unsigned long)(1<<sig_appwin))      /* App-Win Message    */
  445. #define SIG_ABOUTWIN    ((unsigned long)(1<<sig_aboutwin))    /* About-Win Message    */
  446. #define SIG_MESSWIN    ((unsigned long)(1<<sig_messwin))     /* Messure-Win Message    */
  447. #define SIG_PREFWIN    ((unsigned long)(1<<sig_prefwin))     /* Preference-Win Message    */
  448. #define SIG_SEARCHWIN    ((unsigned long)(1<<sig_searchwin))   /* Preference-Win Message    */
  449. #define SIG_NOTIFY    ((unsigned long)(1<<sig_notify))      /* Notify Signal         */
  450. #define SIG_SCREENCLOSE    ((unsigned long)(1<<sig_screenclose)) /* Screen schliesen?    */
  451. #define SIG_MAINAPPWIN    ((unsigned long)(1<<MainAppWinMsgPort->mp_SigBit))   /* AppWin2 */
  452. #define SIG_AMIGAGUIDE    (sig_amigaguide_long)              /* AmigaGuide Signal      */
  453.  
  454.     /* Alle sigs mit 0 vorbelegt, nur sig_win ist immer != 0    */
  455.  
  456. long SIG_REXX;                       /* ARexx Command arrives    */
  457.  
  458.  
  459. /*----------------------------------------------------------------------*/
  460.  
  461.  
  462. static void __asm MySetABPenDrMd(register __a1 struct RastPort *, register __d0 ULONG, register __d1 ULONG, register __d2 ULONG);
  463.  
  464. static void __asm MySetABPenDrMd(register __a1 struct RastPort * rp, register __d0 ULONG a, register __d1 ULONG b, register __d2 ULONG dr)
  465. {
  466.   if (GfxBase->LibNode.lib_Version >= 39) SetABPenDrMd(rp, a, b, dr);
  467.   else {
  468.     SetAPen(rp, a); SetBPen(rp, b); SetDrMd(rp, dr);
  469.   }
  470. }
  471.  
  472.  
  473. /*----------------------------------------------------------------------*/
  474.  
  475.  
  476. static void *OLib(char *name, int vers, int required)
  477. {
  478.   void *ret;
  479.   
  480.   ret = OpenLibrary(name, vers);
  481.   
  482.   if (ret == NULL) {
  483.     if (required) {
  484.       Fatal(10, MSG_NO_LIBRARY, name, vers);
  485.     }
  486.     else {
  487.       Warning(MSG_NO_LIBRARY, name, vers);
  488.     }
  489.   }
  490.   
  491.   return ret;
  492. }
  493.  
  494.  
  495.  
  496. static void OpenLib(void)
  497. {
  498.   IntuitionBase = (struct IntuitionBase *)OLib("intuition.library", 0, TRUE);
  499.   if (IntuitionBase->LibNode.lib_Version < 36L) {
  500.     unset_os2;
  501.   }
  502.   else {
  503.     set_os2;
  504.     if (IntuitionBase->LibNode.lib_Version > 38L) {
  505.       set_os3;
  506.     }
  507.   }
  508.   GfxBase = (struct GfxBase *)OLib(GRAPHICSNAME, 0, TRUE);
  509.   LayersBase = OLib("layers.library", 0, TRUE);
  510.   DiskfontBase = OLib("diskfont.library", 0, TRUE);
  511.  
  512.   memset(&ConsoleReq,0 ,sizeof(ConsoleReq));
  513.   if (!OpenDevice("console.device",-1L, &ConsoleReq, 0L)) {
  514.     ConsoleDevice = &(ConsoleReq.io_Device->dd_Library);
  515.   }
  516.   else {
  517.     Fatal(20, MSG_NO_CONSOLE_DEVICE);
  518.   }
  519.  
  520.   if (is_os2) {
  521.     WorkbenchBase = OLib(WORKBENCH_NAME, 0, TRUE);
  522.     IconBase = OLib(ICONNAME, 0, TRUE);
  523.     GadToolsBase = OLib("gadtools.library", 0, TRUE);
  524.     AslBase = OLib(AslName, 0, TRUE);
  525.     if (AslBase->lib_Version >= 38L) {
  526.       set_os21;
  527.     }
  528.     AmigaGuideBase = OLib("amigaguide.library", 39, FALSE);    // ACHTUNG bei PROFILING!!
  529.     UtilityBase    = OLib("utility.library", 0, TRUE);
  530.   }
  531. #if defined(ARP_LIBRARY)
  532.   ArpBase = (struct ArpBase *)OLib(ArpName, 0, FALSE);
  533.   if (ArpBase == NULL) unset_arp;
  534. #else
  535.   unset_arp;
  536. #endif
  537. #if defined(REQ_LIBRARY)
  538.   ReqBase = OLib("req.library", 0, FALSE);
  539. #endif
  540.  
  541.   // Signal fuer das Screen Schliesen allozieren
  542.   if (is_os2) {
  543.     sig_screenclose = AllocSignal(-1);
  544.     if (sig_screenclose == -1) {
  545.       Fatal(20, MSG_NO_SIGNAL);
  546.     }
  547.   }
  548. }
  549.  
  550.  
  551. static void CloseLib(void)
  552. {
  553.   if (is_os2) {
  554.     FreeSignal(sig_screenclose);
  555.  
  556.     if (WorkbenchBase != NULL) {
  557.       CloseLibrary(WorkbenchBase);
  558.       WorkbenchBase = NULL;
  559.     }
  560.     if (IconBase != NULL) {
  561.       CloseLibrary(IconBase);
  562.       IconBase = NULL;
  563.     }
  564.     if (GadToolsBase != NULL) {
  565.       CloseLibrary(GadToolsBase);
  566.       GadToolsBase = NULL;
  567.     }
  568.     if (AslBase != NULL) {
  569.       CloseLibrary(AslBase);
  570.       AslBase = NULL;
  571.     }
  572.     if (AmigaGuideBase) {
  573.       CloseLibrary(AmigaGuideBase);
  574.       AmigaGuideBase = NULL;
  575.     }
  576.     if (UtilityBase) {
  577.       CloseLibrary(UtilityBase);
  578.       UtilityBase = NULL;
  579.     }
  580.   }
  581.  
  582.   if (ConsoleDevice != NULL) {
  583.     CloseDevice(&ConsoleReq);
  584.     ConsoleDevice = NULL;
  585.   }
  586.  
  587.   if (DiskfontBase != NULL) {
  588.     CloseLibrary(DiskfontBase);
  589.     DiskfontBase = NULL;
  590.   }
  591.   if (GfxBase != NULL) {
  592.     CloseLibrary((struct Library *)GfxBase);
  593.     GfxBase = NULL;
  594.   }
  595.   if (IntuitionBase != NULL) {
  596.     CloseLibrary((struct Library *)IntuitionBase);
  597.     IntuitionBase = NULL;
  598.   }
  599. #if defined(ARP_LIBRARY)
  600.   if (is_arp && ArpBase != NULL) {
  601.     unset_arp;
  602.     CloseLibrary(&(ArpBase->LibNode));
  603.     ArpBase = NULL;
  604.   }
  605. #endif
  606. #if defined(REQ_LIBRARY)
  607.   if (ReqBase != NULL) {
  608.     CloseLibrary((struct Library *)ReqBase);
  609.     ReqBase = NULL;
  610.   }
  611. #endif
  612. }
  613.  
  614.  
  615.  
  616.  
  617. /* allocate all objects in 'BoopsiObj' Muss jedesmal nach OpenS() gemacht werden! */
  618. static void InitBoopsi(void)
  619. {
  620.   if (is_os2 && screen != NULL) {
  621.     MyNewObject(&BObj.LArrImage, LEFTIMAGE, "LEFTIMAGE");
  622.     MyNewObject(&BObj.RArrImage, RIGHTIMAGE, "RIGHTIMAGE");
  623.     MyNewObject(&BObj.UArrImage, UPIMAGE, "UPIMAGE");
  624.     MyNewObject(&BObj.DArrImage, DOWNIMAGE, "DOWNIMAGE");
  625.     MyNewObject(&BObj.SizeImage, SIZEIMAGE, "SIZEIMAGE");
  626.  
  627.   }
  628. }
  629.  
  630.  
  631.  
  632.  
  633. /* deallocate all objects in 'BoopsiObj' Muss jedesmal vor CloseS() gemacht werden! */
  634. static void FreeBoopsi(void)
  635. {
  636.   if (is_os2 && screen != NULL) {
  637.     MyDisposeObject((APTR*)&BObj.LArrImage);
  638.     MyDisposeObject((APTR*)&BObj.RArrImage);
  639.     MyDisposeObject((APTR*)&BObj.UArrImage);
  640.     MyDisposeObject((APTR*)&BObj.DArrImage);
  641.     MyDisposeObject((APTR*)&BObj.SizeImage);
  642.   }
  643. }
  644.  
  645.  
  646.  
  647. static struct TagItem NewObjTags[] =
  648.   {
  649.         { SYSIA_DrawInfo,    0L    },
  650.         { SYSIA_Which,    0L    },
  651.         { TAG_DONE,        0L    }
  652.   };
  653.  
  654.  
  655. static void MyNewObject(struct Image ** img, ULONG tag, char * str)
  656. {
  657.   NewObjTags[0].ti_Data = (ULONG)SDVI_DRI;
  658.   NewObjTags[1].ti_Data = tag;
  659.   if (!( *img = NewObjectA(NULL, "sysiclass", NewObjTags))) {
  660.     Fatal(20, MSG_NO_NEW_OBJECT, str);
  661.   }
  662. }
  663.  
  664.  
  665. static void MyDisposeObject(APTR * obj)
  666. {
  667.   if (*obj) {
  668.     DisposeObject(*obj);
  669.     *obj = NULL;
  670.   }
  671. }
  672.  
  673.  
  674.  
  675.  
  676. void FreeChipPuffRP(void)
  677. {
  678.   if (show_state.ChipPuffBM) {
  679.     if (FALSE && is_os3) {
  680.       // siehe eins tiefer
  681.       FreeBitMap(show_state.ChipPuffBM);
  682.     }
  683.     else {
  684.       FreeRaster(show_state.ChipPuffBM->Planes[0], show_state.ChipPuffBM->BytesPerRow*8, show_state.ChipPuffBM->Rows);
  685.       xfree(show_state.ChipPuffBM);
  686.     }
  687.     show_state.ChipPuffBM = NULL;
  688.   }
  689. }
  690.  
  691.  
  692. void AllocChipPuffRP(void)
  693. {
  694.   if (FALSE && is_os3) {
  695.     // ich brauch eine Bitmap, die 8 identische Planes hat...also nix mit AllocBitmap!!
  696.     show_state.ChipPuffBM = AllocBitMap(win2->Width, win2->Height, 1, BMF_CLEAR, win2->RPort->BitMap);
  697.   }
  698.   else {
  699.     show_state.ChipPuffBM = xmalloc(sizeof(struct BitMap));
  700.     InitBitMap(show_state.ChipPuffBM, 8, win2->Width, win2->Height);
  701.     show_state.ChipPuffBM->Planes[0] = AllocRaster(show_state.ChipPuffBM->BytesPerRow*8, show_state.ChipPuffBM->Rows);
  702.     if (!show_state.ChipPuffBM->Planes[0]) {
  703.       xfree(show_state.ChipPuffBM);
  704.       show_state.ChipPuffBM = NULL;
  705.     }
  706.   }
  707.  
  708.   if (!show_state.ChipPuffBM) Fatal(19, MSG_NO_MEM);
  709.   
  710.   { // mache 8 identische Planes (um eine schwarze Schrift zu erzeugen)
  711.     int i;
  712.     for (i=1; i<8; i++) {
  713.       show_state.ChipPuffBM->Planes[i] = show_state.ChipPuffBM->Planes[0];
  714.     }
  715.   }
  716.  
  717.   InitRastPort(&show_state.ChipPuffRP);
  718.   show_state.ChipPuffRP.BitMap = show_state.ChipPuffBM;
  719.  
  720.   D(bug("ChipPuffBM alloziert, Breite: %ld, Hoehe: %ld, Tiefe: %ld\n", 
  721.         show_state.ChipPuffBM->BytesPerRow*8, show_state.ChipPuffBM->Rows, show_state.ChipPuffBM->Depth));
  722. }
  723.  
  724.  
  725. static void CPUBlit(WORD SrcX, WORD SrcY, WORD DestX, WORD DestY, WORD XSize, WORD YSize)
  726. {
  727.   int i;
  728.   struct BitMap * src  = myRastPort.BitMap;
  729.   struct BitMap * dest = show_state.ChipPuffBM;
  730.   long bSrcX, bDestX, bXSize;
  731.   long aSrcX, aDestX;
  732.   
  733.   if (DestY+YSize >= dest->Rows) {
  734.     D(bug("CPUBlit: Zu hoch! DestY: %ld, YSize: %ld, Hoehe: %ld\n", DestY, YSize, dest->Rows));
  735.     YSize = dest->Rows - DestY-1;
  736.     if (YSize < 0) return;
  737.   }
  738.   if (DestX/8+(XSize+15)/8 >= dest->BytesPerRow) {
  739.     D(bug("CPUBlit: Zu breit! DestX: %ld, XSize: %ld, Breite: %ld\n", DestX, XSize, dest->BytesPerRow*8));
  740.     XSize = (dest->BytesPerRow-1)*8 - DestX - 1;    // BPRow-1 wg. +15
  741.     if (XSize < 0) return;
  742.   }
  743.   
  744.   bSrcX  = SrcX  / 8;
  745.   bDestX = DestX / 8;
  746.   bXSize = (XSize + 15) / 8;    // +15 wg. Verschnitt vorne und hinten
  747.   aSrcX  = SrcX  & 7;
  748.   aDestX = DestX & 7;     
  749.   
  750.   
  751.   
  752.   /* 
  753.   D(bug("CPUBlit SX: %ld, SY: %ld, DX: %ld, DY: %ld, XS: %ld, YS: %ld, aSX: %ld, aDX: %ld\n", 
  754.     SrcX, SrcY, DestX, DestY, XSize, YSize, aSrcX, aDestX));
  755.   */
  756.   
  757.   for (i=0; i<YSize; i++) {
  758.     CopyMem(((char *)src->Planes[0])  + (SrcY+i)  * src->BytesPerRow  + bSrcX, 
  759.             ((char *)dest->Planes[0]) + (DestY+i) * dest->BytesPerRow + bDestX,
  760.             bXSize);
  761.   }
  762.  
  763.  
  764. #ifdef WEG
  765.   MySetABPenDrMd(win2->RPort, show_state.APen, show_state.BPen, JAM2);
  766.   { register long x = DestX+(aSrcX-aDestX);
  767.     BltTemplate(show_state.ChipPuffRP.BitMap->Planes[0]+DestY*show_state.ChipPuffRP.BitMap->BytesPerRow+x/16, x%16, myRastPort.BitMap->BytesPerRow, win2->RPort, DestX, DestY, XSize, YSize);
  768.   }
  769.   return;
  770. #endif
  771.  
  772.   { register long x = DestX+(aSrcX-aDestX);
  773.     register long y = DestY;
  774.     MySetABPenDrMd(win2->RPort, show_state.APen, (is_bhook) ? show_state.BPen : 0, JAM2);
  775.     BltTemplate(show_state.ChipPuffRP.BitMap->Planes[0]+y*show_state.ChipPuffRP.BitMap->BytesPerRow+(x/16)*2, x%16,
  776.         show_state.ChipPuffRP.BitMap->BytesPerRow,
  777.         win2->RPort, DestX, DestY, XSize, YSize);
  778.   }
  779.  
  780. #ifdef OLD_BLIT
  781.   //ClipBlit(&show_state.ChipPuffRP, DestX+(aSrcX-aDestX), DestY, win2->RPort, DestX, DestY, XSize, YSize, 0xC0);
  782.  
  783.   if (is_bhook) {
  784.     SafeSetWriteMask(win2->RPort, 0x02);
  785.     ClipBlit(&show_state.ChipPuffRP, DestX+(aSrcX-aDestX), DestY, win2->RPort, DestX, DestY, XSize, YSize, 0x30);
  786.   }
  787.   SafeSetWriteMask(win2->RPort, 0x01);
  788.   ClipBlit(&show_state.ChipPuffRP, DestX+(aSrcX-aDestX), DestY, win2->RPort, DestX, DestY, XSize, YSize, 0xC0);
  789.   SafeSetWriteMask(win2->RPort, 0xff);
  790. #endif
  791. }
  792.  
  793.  
  794.  
  795. static void CloseS(void)
  796. {
  797.   FreeBoopsi();        /* deallocate all in 'BoopsiObj' */
  798.  
  799.   if (screen != NULL) {
  800.     if (is_os2) {
  801.       if (SDVI_VI != NULL) {
  802.         FreeVisualInfo(SDVI_VI);
  803.         SDVI_VI = NULL;
  804.       }
  805.       if (SDVI_DRI) {
  806.         FreeScreenDrawInfo(screen, SDVI_DRI);
  807.         SDVI_DRI = NULL;
  808.       }
  809.     }
  810.     if (is_otherpubscr) {
  811.       UnlockPubScreen(NULL, screen);
  812.     }
  813.     else {
  814.       if (is_myscr) {    /* ich hab den Screen geoeffnet, also schliess ich ihn auch wieder */
  815.         if (is_os2) {
  816.           if (CloseScreen(screen)) {
  817.             screen = NULL;
  818.           }
  819.           else {
  820.             ULONG ret_sigs;
  821.             Okay1(GetTeXString(MSG_CANT_CLOSE_SCREEN));
  822.             
  823.             printf("sig: %d, SIG: %x\n", sig_screenclose, SIG_SCREENCLOSE);
  824.         printf("vor wait %x\n", SIG_SCREENCLOSE | SIGBREAKF_CTRL_C);
  825.         PROFILE_OFF();
  826.           ret_sigs = Wait(SIG_SCREENCLOSE | SIGBREAKF_CTRL_C);
  827.           PROFILE_ON();
  828.           printf("nach sigs: %x\n", ret_sigs);
  829.  
  830.             if (CloseScreen(screen)) {
  831.               // wenn ich den Screen immer noch nicht schliessen kann, so geb ich es auf :-(
  832.               // eigentlich sollte da man wohl eine Schleife machen bis CloseScreen()
  833.               // endlich mal funktioniert... 
  834.               screen = NULL;
  835.               printf("ist zu\n");
  836.             }
  837.             // bei CTRL-C wird auch aufgegeben auf den Screen zu warten...
  838.             // also VORSICHT
  839.           }
  840.         }
  841.         else {
  842.           CloseScreen(screen);
  843.           screen = NULL;
  844.         }
  845.       }
  846.       unset_myscr;    /* naja, jetzt ist es ganz sicher nicht mehr mein Screen */
  847.     }
  848.   }
  849. }
  850.  
  851.  
  852.  
  853. static void CloseWin2(void)
  854. {
  855.   struct Process *proc;
  856.   struct IntuiMessage *msg;
  857.  
  858.   if (win2 != NULL) {
  859.  
  860.     StopHelp();
  861.  
  862.     FreeChipPuffRP();
  863.  
  864.     /* AppWin loeschen */
  865.     if (MainAppWinMsgPort) {
  866.       struct Message * msg;
  867.       if (MainAppWin) {
  868.         RemoveAppWindow(MainAppWin);
  869.         MainAppWin = NULL;
  870.       }
  871.       while(msg = GetMsg(MainAppWinMsgPort)) ReplyMsg(msg);
  872.       DeleteMsgPort(MainAppWinMsgPort);
  873.       MainAppWinMsgPort = NULL;
  874.     }
  875.     
  876.     unblock_win2();    // falls das Window blockiert ist (siehe am_requ.c)
  877.  
  878.     win2->Flags |= WFLG_RMBTRAP;        /* Menue verbieten */
  879.     ClearMenuStrip(win2);
  880.     MyModifyIDCMP(0, IDCMP_MENUVERIFY);
  881.     
  882.     Remove_scroll_gadgets(TRUE);    // kein refresh
  883.  
  884.     proc = (struct Process *)FindTask(0);
  885.     proc->pr_WindowPtr = (APTR)old_Win_Ptr_Requester;
  886.  
  887.     Forbid();                    /* nun alle Messages wegbringen */
  888.     do {
  889.       msg = (struct IntuiMessage *)GetMsg(win2->UserPort);
  890.       if (msg != NULL) {
  891.         if (msg->Class == IDCMP_MENUVERIFY && msg->Code == MENUHOT) {
  892.           msg->Code = MENUCANCEL;
  893.         }
  894.         ReplyMsg(&(msg->ExecMessage));
  895.       }
  896.     } while (msg != NULL);
  897.     
  898.     /* erst nachher alles wegnehmen... sonst gibt's keinen UserPort mehr :) */
  899.     MyModifyIDCMP(0L, ~1L);
  900.     Permit();
  901.  
  902. #if 0
  903.     WakeUpWin(win2);
  904. #endif
  905.     CloseWindow(win2);
  906.     win2 = NULL;
  907.   }
  908. }
  909.  
  910. static void CloseRastPort(void)
  911. {
  912.   if (BitMapWin.Planes[0] != NULL) {
  913.     if (is_bmfast) {
  914.       FreeMem(BitMapWin.Planes[0], (wx+7)/8*wy);
  915.     }
  916.     else {
  917.       FreeRaster(BitMapWin.Planes[0],wx,wy);
  918.     }
  919.     BitMapWin.Planes[0] = NULL;
  920.   }
  921. }
  922.  
  923. /* testet, ob der Screen geschlossen werden kann, wird auch von OpenCloseScreen verwendet */
  924. int can_i_exit(void)
  925. {
  926.   int anz;
  927.   struct Process *spectask;
  928.  
  929.   if (!is_myscr || is_otherpubscr) {
  930.     return TRUE;    /* ich muss keinen Screen schliessen */
  931.   }
  932.  
  933.   anz = test_anz_windows();
  934.  
  935.   if (is_about) anz--;        /* ziehe meine Windows ab */
  936.   if (MessWin != NULL) anz--;
  937.   if (is_prefwin != NULL) anz--;
  938.   if (SearchWin != NULL) anz--;
  939.  
  940.   if (anz > 1) {
  941.     // SpecialHost nur vertreiben, wenn wirklich kein anderes Window mehr da ist
  942.     if (anz == 2) {    // win2 + SpecialHost
  943.       if ((spectask = (struct Process *)FindTask("SpecialHost")) != NULL) {
  944.         Signal(&(spectask->pr_Task), SIGBREAKF_CTRL_E);    /* SpecialHost to WorkBench */
  945.         Delay(2);        /* SpecialHost braucht etwas Zeit.. */
  946.       }
  947.     }
  948.     anz = test_anz_windows();
  949.     if (is_about) anz--;        /* ziehe meine Windows ab */
  950.     if (MessWin != NULL) anz--;
  951.     if (is_prefwin != NULL) anz--;
  952.     if (anz > 1) {
  953.       Message(MSG_CLOSE_WINDOWS);
  954.       beep();
  955.       return FALSE;        /* no exit now! */
  956.     }
  957.     else {
  958.       return TRUE;
  959.     }
  960.   }
  961.   else {
  962.     return TRUE;        /* you can exit the prog */
  963.   }
  964. }
  965.  
  966. static int test_anz_windows(void)
  967. {
  968.   if (screen == NULL || !is_ownscr) {
  969.     return 0;
  970.   }
  971.   else {
  972.     int nr;
  973.     struct Window *w;
  974.     ULONG lck;
  975.     long en_ab = Enable_Abort;
  976.  
  977.     Enable_Abort = 0;    /* no break */
  978.     lck = LockIBase(0L);
  979.     for (nr=0, w=screen->FirstWindow; w != NULL; nr++, w = w->NextWindow);
  980.     UnlockIBase(lck);
  981.     Enable_Abort = en_ab;
  982.     return nr;
  983.   }
  984. }
  985.  
  986. static void OpenRastPort(void)
  987. {
  988.   D(bug("OpenRastPort wx: %ld, wy: %ld\n", wx, wy));
  989.   
  990.   unset_bmcpu;
  991.   unset_scrollras;
  992.  
  993.   InitBitMap(&BitMapWin,7L,wx,wy);
  994.   if (is_village || is_alwbmfast) {
  995.     // wir sind auf dem VGA Screen -- es wird kein CHIP-Mem benoetigt
  996.     // oder aber wir wollen unbedingt fast-ram
  997.     BitMapWin.Planes[0] = AllocMem((wx+7)/8*wy, MEMF_PUBLIC|MEMF_ANY|MEMF_CLEAR);
  998.     set_bmfast;                // use fast mem for the page bitmap
  999.   }
  1000.   else {
  1001.     BitMapWin.Planes[0] = AllocRaster(wx,wy);
  1002.     unset_bmfast;    // use chip mem for the pae bitmap
  1003.     if (!BitMapWin.Planes[0]) {
  1004.       BitMapWin.Planes[0] = AllocMem((wx+7)/8*wy, MEMF_PUBLIC|MEMF_ANY|MEMF_CLEAR);
  1005.       set_bmfast;
  1006.     }
  1007.   }
  1008.  
  1009.   if (!BitMapWin.Planes[0]) Fatal(10, MSG_CANT_ALLOC_BITMAP);
  1010.   
  1011.   { // Damit ich das auch in andere Planes reinkopieren kann
  1012.     // welche Plane verwendet wird, wird ueber SetWriteMask() entschieden!
  1013.     int i;
  1014.     for (i=1; i<7; i++) {
  1015.       BitMapWin.Planes[i] = BitMapWin.Planes[0];
  1016.     }
  1017.     BitMapWin.Planes[7] = NULL;    // nur 7 Planes identisch, wg. PICASSO Treiber (chunky)
  1018.   }
  1019.  
  1020.   if (is_bmfast) {
  1021.     set_scrollras;
  1022.     if (!is_village) {
  1023.       set_bmcpu;
  1024.       if (win2 && !show_state.ChipPuffBM) {
  1025.         AllocChipPuffRP();
  1026.       }
  1027.     }
  1028.   }
  1029.   
  1030.   InitRastPort(&myRastPort);
  1031.   myRastPort.BitMap = &BitMapWin;
  1032.  
  1033.   if (!is_bmfast) SetRast(&myRastPort,0);
  1034.  
  1035.   D(bug("ShowDVI: Allociere Bitmap im %s-RAM.\n", is_bmfast ? "Fast" : "Chip"));
  1036. }
  1037.  
  1038.  
  1039. void init_screen_colors(void)
  1040. {
  1041.   struct ColorMap *cmap;
  1042.   short *coltab;
  1043.   struct Screen bufscr;
  1044.  
  1045.  
  1046.   if (is_clwbcol && GetScreenData(&bufscr, sizeof(bufscr), WBENCHSCREEN, NULL)) {
  1047.  
  1048.     cmap = bufscr.ViewPort.ColorMap;
  1049.     coltab = (short *)cmap->ColorTable;
  1050.     
  1051.     current_col.red_0   = (coltab[0] & 0x0F00) >> 8;
  1052.     current_col.green_0 = (coltab[0] & 0x00F0) >> 4;
  1053.     current_col.blue_0  =  coltab[0] & 0x000F;
  1054.     current_col.red_1   = (coltab[1] & 0x0F00) >> 8;
  1055.     current_col.green_1 = (coltab[1] & 0x00F0) >> 4;
  1056.     current_col.blue_1  =  coltab[1] & 0x000F;
  1057.     current_col.red_2   = (coltab[2] & 0x0F00) >> 8;
  1058.     current_col.green_2 = (coltab[2] & 0x00F0) >> 4;
  1059.     current_col.blue_2  =  coltab[2] & 0x000F;
  1060.     current_col.red_3   = (coltab[3] & 0x0F00) >> 8;
  1061.     current_col.green_3 = (coltab[3] & 0x00F0) >> 4;
  1062.     current_col.blue_3  =  coltab[3] & 0x000F;
  1063.   }
  1064.   else {
  1065.     /* Setzen der aktuellen (default) Farbwerte */
  1066.     current_col = default_col;
  1067.   }
  1068. }
  1069.  
  1070. void set_screen_colors(void)
  1071. {
  1072.   if (screen != NULL) {
  1073.     SetRGB4(&(screen->ViewPort),0,(long)current_col.red_0,(long)current_col.green_0,
  1074.                     (long)current_col.blue_0);
  1075.     SetRGB4(&(screen->ViewPort),1,(long)current_col.red_1,(long)current_col.green_1,
  1076.                     (long)current_col.blue_1);
  1077.     if (is_col4) {
  1078.       SetRGB4(&(screen->ViewPort),2,(long)current_col.red_2,(long)current_col.green_2,
  1079.                         (long)current_col.blue_2);
  1080.       SetRGB4(&(screen->ViewPort),3,(long)current_col.red_3,(long)current_col.green_3,
  1081.                         (long)current_col.blue_3);
  1082.     }
  1083.   }
  1084. }
  1085.  
  1086. #if 0    /* nur fuer eigenen color-requester (und der kommt nicht mehr) */
  1087. void set_temp_screen_colors(void)
  1088. {
  1089.   SetRGB4(&(screen->ViewPort),0,(long)current_col.red_t0,
  1090.             (long)current_col.green_t0, (long)current_col.blue_t0);
  1091.   SetRGB4(&(screen->ViewPort),1,(long)current_col.red_t1,
  1092.             (long)current_col.green_t1, (long)current_col.blue_t1);
  1093. }
  1094. #endif
  1095.  
  1096.  
  1097. static void close_fonts(void)
  1098. {
  1099.   if (font8 != NULL) {
  1100.     CloseFont(font8);
  1101.   }
  1102.   if (font11 != NULL) {
  1103.     CloseFont(font11);
  1104.   }
  1105. }
  1106.  
  1107. static void open_fonts(void)
  1108. {
  1109.   txtAttr8.ta_Name  = FONTNAME8;
  1110.   txtAttr8.ta_YSize = FONTYSIZE8;
  1111.   txtAttr8.ta_Style = FONTSTYLE8;
  1112.   txtAttr8.ta_Flags = FONTFLAGS8;
  1113.   if (DiskfontBase != NULL && (font8 = OpenFont(&txtAttr8)) == NULL) {
  1114.     font8 = OpenDiskFont(&txtAttr8);
  1115.   }
  1116.  
  1117.   txtAttr11.ta_Name  = FONTNAME11;
  1118.   txtAttr11.ta_YSize = FONTYSIZE11;
  1119.   txtAttr11.ta_Style = FONTSTYLE11;
  1120.   txtAttr11.ta_Flags = FONTFLAGS11;
  1121.   if (DiskfontBase != NULL) {
  1122.     font11 = OpenDiskFont(&txtAttr11);
  1123.     if (font11->tf_XSize != FONTXSIZE11 || font11->tf_YSize != FONTYSIZE11) {
  1124.       CloseFont(font11);
  1125.       font11 = NULL;
  1126.     }
  1127.   }
  1128.   else {
  1129.     font11 = NULL;
  1130.   }
  1131.   if (font11 != NULL) {        /* wird fuer das OS Menue verwendet */
  1132.     txtAttr = txtAttr11;    /* struct Assignment! */
  1133.   }
  1134.   else {
  1135.     txtAttr = txtAttr8;        /* struct Assignment! */
  1136.   }
  1137. }
  1138.  
  1139.  
  1140.  
  1141.  
  1142. static ULONG    scr_oserror = 0L;
  1143.  
  1144. /* I accept the default pens, but have to
  1145.  * pass something to get the new look.
  1146.  */
  1147. static UWORD    mypens[] = {
  1148.     0, 1, (UWORD)~0                /* just detail and block    */
  1149. };
  1150.  
  1151. static UWORD mypens4col[] =
  1152. {
  1153.     0, /* DETAILPEN */
  1154.     1, /* BLOCKPEN    */
  1155.     1, /* TEXTPEN    */
  1156.     2, /* SHINEPEN    */
  1157.     1, /* SHADOWPEN    */
  1158.     3, /* FILLPEN    */
  1159.     1, /* FILLTEXTPEN    */
  1160.     0, /* BACKGROUNDPEN    */
  1161.     2, /* HIGHLIGHTTEXTPEN    */
  1162.  
  1163.     1, /* BARDETAILPEN    */
  1164.     2, /* BARBLOCKPEN    */
  1165.     1, /* BARTRIMPEN    */
  1166.  
  1167.     (UWORD)~0,
  1168. };
  1169.  
  1170. static UWORD mypens2col[] =
  1171. {
  1172.     0, /* DETAILPEN */
  1173.     1, /* BLOCKPEN    */
  1174.     1, /* TEXTPEN    */
  1175.     0, /* SHINEPEN    */
  1176.     1, /* SHADOWPEN    */
  1177.     1, /* FILLPEN    */
  1178.     0, /* FILLTEXTPEN    */
  1179.     0, /* BACKGROUNDPEN    */
  1180.     0, /* HIGHLIGHTTEXTPEN    */
  1181.  
  1182.     1, /* BARDETAILPEN    */
  1183.     0, /* BARBLOCKPEN    */
  1184.     1, /* BARTRIMPEN    */
  1185.  
  1186.     (UWORD)~0,
  1187. };
  1188.  
  1189. static struct TagItem pub_screen_tags[] = {
  1190.                           { SA_DisplayID,   DEFAULT_MONITOR_ID        },
  1191.                           { SA_PubName,        (ULONG)MyPubScreenName    },
  1192.                           { SA_PubSig,        -1                },
  1193.                           { SA_Type,        PUBLICSCREEN        },
  1194.                           { SA_ErrorCode,   (ULONG)&scr_oserror        },
  1195.                           { SA_Pens,        (ULONG)mypens        },
  1196.                           { SA_Overscan,    OSCAN_TEXT            },
  1197.                           { SA_SysFont,     1L                },
  1198.                           { SA_FullPalette, TRUE            },
  1199. //                          { SA_Interleaved, TRUE            },
  1200.                           { TAG_DONE,       0L                }
  1201.         };
  1202.  
  1203. static struct TagItem nor_screen_tags[] = {
  1204.                           { SA_DisplayID,   DEFAULT_MONITOR_ID    },
  1205.                           { SA_ErrorCode,   (ULONG)&scr_oserror    },
  1206.                           { SA_Pens,        (ULONG)mypens    },
  1207.                           { SA_Overscan,    OSCAN_TEXT        },
  1208.                           { SA_SysFont,     1L            },
  1209.                           { SA_FullPalette, TRUE        },
  1210. //                          { SA_Interleaved, TRUE        },
  1211.                           { TAG_DONE,       0L            }
  1212.         };
  1213.  
  1214. static struct TagItem viTags[] = { {TAG_DONE, 0L} };
  1215.  
  1216.  
  1217. static void OpenS(void)
  1218. {
  1219.   static char  * DefTitle = NULL;
  1220.  
  1221.   struct NewScreen new_scr;
  1222.   
  1223.   if (DefTitle == NULL) DefTitle = strdup(GetCopy());
  1224.  
  1225.   if (is_ownscr) {
  1226.   
  1227.     if (screen = LockPubScreen(MyPubScreenName)) {
  1228.       set_otherpubscr;        // PubScr ist nicht von mir geoeffnet!
  1229.       unset_myscr;        // ist nicht mein Screen!
  1230.       MessageStr(NULL);
  1231.     }
  1232.     else {
  1233.       unset_otherpubscr;    // PubScr ist von mir! (bzw. wird von mir sein)
  1234.   
  1235.  
  1236. #if 0 // Wozu denn das????
  1237.       /* Bastle mir ein Pen-Array: Kopiere das Array der Workbench */
  1238.       { struct Screen * WBScreen;
  1239.         WBScreen = LockPubScreen("Workbench");
  1240.         if (WBScreen) {
  1241.           struct DrawInfo * WBDrawInfo = GetScreenDrawInfo(WBScreen);
  1242.           if (WBDrawInfo) {
  1243.             int size = WBDrawInfo->dri_NumPens * sizeof(UWORD);
  1244.             if (MyOwnScreenPens) free(MyOwnScreenPens);
  1245.             MyOwnScreenPens = xmalloc(size);
  1246.             CopyMem(WBDrawInfo->dri_Pens, MyOwnScreenPens, size);
  1247.             FreeScreenDrawInfo(WBScreen, WBDrawInfo);
  1248.           }
  1249.           UnlockPubScreen(NULL, WBScreen);
  1250.         }
  1251.       }
  1252. #endif
  1253.  
  1254.  
  1255.       new_scr.LeftEdge  = 0;
  1256.       new_scr.TopEdge   = 0;
  1257.       new_scr.Width     = x_scr_width;
  1258.       new_scr.Height    = x_scr_height;
  1259.       if (is_col4) {
  1260.         new_scr.Depth     = 2;
  1261.         new_scr.DetailPen = 0;
  1262.         new_scr.BlockPen  = 1;
  1263.       }
  1264.       else {
  1265.         new_scr.Depth     = 1;
  1266.         new_scr.DetailPen = 0;
  1267.         new_scr.BlockPen  = 1;
  1268.       }
  1269.       if (is_lace) {
  1270.         new_scr.ViewModes = HIRES | LACE;
  1271.       }
  1272.       else {
  1273.         new_scr.ViewModes = HIRES ;
  1274.       }
  1275.     
  1276.       if (is_pubscr) {
  1277.         new_scr.Type = PUBLICSCREEN;
  1278.       }
  1279.       else {
  1280.         new_scr.Type = CUSTOMSCREEN;
  1281.       }
  1282.       
  1283.       if (is_os2 && show_state.screen_size_x != 0 && show_state.screen_size_y != 0) {
  1284.         new_scr.Type |= AUTOSCROLL;        /* machen wir halt immer dann autoscroll... */
  1285.       }
  1286.       
  1287.       new_scr.Font = NULL;        /* &txtAttr8; */
  1288.       new_scr.DefaultTitle = DefTitle;  /* Copyright-String */
  1289.       new_scr.Gadgets = NULL;
  1290.       new_scr.CustomBitMap = NULL;
  1291.       
  1292.       if (is_os2) {
  1293.         struct TagItem *tags;
  1294.   
  1295.         if (is_pubscr) {
  1296.           tags = &(pub_screen_tags[0]);
  1297.           // Signal zwecks sicherem schliessen zuweisen
  1298.           tags[0].ti_Data = sig_screenclose;
  1299.           if (is_col4) tags[5].ti_Data = (ULONG)mypens4col;
  1300.           else tags[5].ti_Data = (ULONG)mypens2col;
  1301.         }
  1302.         else {
  1303.           tags = &(nor_screen_tags[0]);
  1304.           if (is_col4) tags[2].ti_Data = (ULONG)mypens4col;
  1305.           else tags[2].ti_Data = (ULONG)mypens2col;
  1306.         }
  1307.         tags[0].ti_Data = get_DisplayID();
  1308.         screen = OpenScreenTagList(&new_scr, tags);
  1309.       }
  1310.       else {
  1311.         screen = OpenScreen(&new_scr);
  1312.       }
  1313.     
  1314.       if (screen == NULL) {
  1315.         if (is_os2) {
  1316.           long strnum;
  1317.           switch (scr_oserror) {
  1318.               case 0:            strnum = MSG_SCRERR_NOERR;
  1319.                         break;
  1320.               case OSERR_NOMONITOR:    strnum = MSG_SCRERR_NOMONITOR;
  1321.                       break;
  1322.           case OSERR_NOCHIPS:    strnum = MSG_SCRERR_NOCHIPS;
  1323.                       break;
  1324.           case OSERR_NOMEM:    strnum = MSG_SCRERR_NOMEM;
  1325.                       break;
  1326.           case OSERR_NOCHIPMEM:    strnum = MSG_SCRERR_NOCHIPMEM;
  1327.                       break;
  1328.           case OSERR_PUBNOTUNIQUE:strnum = MSG_SCRERR_PUBNOTUNIQUE;
  1329.                       break;
  1330.           case OSERR_UNKNOWNMODE:    strnum = MSG_SCRERR_UNKNOWNMODE;
  1331.                       break;
  1332.           default:        strnum = MSG_SCRERR_DEFAULT;
  1333.                         break;
  1334.           }
  1335.           Fatal(5,MSG_CANT_OPEN_SCR_NAME, GetTeXString(strnum));
  1336.         }
  1337.         else {
  1338.           FatalStr(5,"can't open screen!");
  1339.         }
  1340.       }
  1341.       set_myscr;            /* screen variable is *my* screen */
  1342.     }
  1343.  
  1344.     //printf("BPR: %d, width: %d\n", screen->RastPort.BitMap->BytesPerRow, screen->Width);
  1345.  
  1346.   }    /* own screen */
  1347.   else {
  1348.     unset_myscr;        /* screen is not from me opened */
  1349.     if (is_os2) {
  1350.       screen = LockPubScreen(PubScreenName);
  1351.       if (screen == NULL) {
  1352.         Warning(MSG_CANT_FIND_SCR_USE_WB, PubScreenName);
  1353.         strcpy(PubScreenName, "Workbench");
  1354.         screen = LockPubScreen(PubScreenName);
  1355.         if (screen == NULL) {
  1356.           Fatal(15, MSG_CANT_LOCK_PBSCR);
  1357.         }
  1358.       }
  1359.       /* eigentlich sollte UnlockPubScreen() erst nach OpenWin2() aufgerufen werden! */
  1360.       /* aber derzeit bin ich noch zu feige dazu (Deadlock...)                 */
  1361.       UnlockPubScreen(NULL, screen);
  1362.     }
  1363.     else {
  1364.       FatalStr(20, "Kein eigener Screen funktioniert derzeit noch nicht unter 1.3!");
  1365.     }
  1366.   }
  1367.   
  1368.   if (screen->RastPort.BitMap->Depth > 1) {
  1369.     set_col4;
  1370.   }
  1371.   else {
  1372.     unset_col4;
  1373.   }
  1374.  
  1375.   HeightScreenTitle = (long)screen->BarHeight+1;    /* mal sehen... */
  1376.   
  1377.   if (is_os2) {
  1378.     if (is_pubscr && is_myscr) {
  1379.       PubScreenStatus( screen, 0L );        /* mache ihn PUBLIC! */
  1380.     }
  1381.     SDVI_VI = GetVisualInfoA(screen, viTags);
  1382.     if (!SDVI_VI) Fatal(10, MSG_CANT_GET_VI);
  1383.  
  1384.     SDVI_DRI = GetScreenDrawInfo(screen);
  1385.     if (!SDVI_DRI) Fatal(10, MSG_CANT_GET_DI);
  1386.   }
  1387.   
  1388. #if 0
  1389.   if (HeightScreenTitle > 11 && font11 != NULL) {
  1390.     /* dann koennen wir topaz 11 nehmen */
  1391.     GadtxtAttr = txtAttr11;    /* Struktur-Assignment! */
  1392.   }
  1393.   else {
  1394.     /* bleiben wir bei topaz 8 */
  1395.     GadtxtAttr = txtAttr8;    /* Struktur-Assignment! */
  1396.   }
  1397. #else
  1398.   /* Ich nehm doch immer topaz 8 */
  1399.   GadtxtAttr = txtAttr8;    /* Struktur-Assignment! */
  1400. #endif
  1401.  
  1402.   /* wichtig, dies wird von set_resolution() nachgeholt */
  1403.   if (is_ownscr) {
  1404.     if (show_state.window_size_own_scr_y == -1) {
  1405.       x_win_height = x_scr_height - ((show_state.window_pos_own_scr_y != -1) ? show_state.window_pos_own_scr_y : HeightScreenTitle);
  1406.     }
  1407.   }
  1408.   else {
  1409.     if (show_state.window_size_y == -1) {
  1410.       x_win_height = x_scr_height - ((show_state.window_pos_y != -1) ? show_state.window_pos_y : HeightScreenTitle);
  1411.     }
  1412.   }
  1413.  
  1414.   if (is_ownscr && !is_otherpubscr) {
  1415.     SetRast(&(screen->RastPort),0);  /* screen loeschen */
  1416.     set_screen_colors();
  1417.     ShowTitle(screen, TRUE);
  1418.   }
  1419.  
  1420.  
  1421.   /*
  1422.    * Normalerweise wird immer nur mit ClipBlit() gescrollt.
  1423.    * Das ist etwas schneller und sieht auch besser aus.
  1424.    * Nur bei Village bzw. bei der Picasso wird ScrollRaster()
  1425.    * gemacht, da dies durch den Picasso Blitter viel schneller ist!
  1426.    */
  1427.  
  1428.   unset_scrollras;
  1429.   unset_village;
  1430.  
  1431.   { /* ***  VILLAGE  *** */
  1432.     long dummy;
  1433.     char * modename = GetModeIDName(INVALID_ID, &dummy);
  1434.     /* der gelieferte String ist gueltig bis zum naechsten GetModeIDName() Aufruf! */
  1435.     
  1436.     if (!strnicmp("DOMINO", modename, 6)) {
  1437.       set_village;
  1438.       //unset_scrollras;    // Domino hat keinen Blitter, also alte Methode
  1439.       D(bug("ShowDVI: DOMINO Screen! Lege die Bitmap in's Fast-RAM. (Mode: %s)\n", modename));
  1440.     }
  1441.     else if (!strnicmp("PICASSO", modename, 7)) {
  1442.       set_village;
  1443.       set_scrollras;
  1444.       D(bug("ShowDVI: PICASSO Screen! Lege die Bitmap in's Fast-RAM. (Mode: %s) (vill: %ld)\n", modename, is_village));
  1445.     }
  1446.     else if (!strnicmp("CyBER", modename, 4)) {
  1447.       set_village;
  1448.       is_cyber = 1;
  1449.       set_scrollras;
  1450.       D(bug("ShowDVI: CyBERvision Screen! Lege die Bitmap in's Fast-RAM. (Mode: %s) (vill: %ld)\n", modename, is_village));
  1451.     }
  1452.   }
  1453.  
  1454.   
  1455.   MessWinXpos = -1; /* Merker dafuer, dass alte MessWin-Positionen nun ungueltig sind */
  1456.  
  1457.   /* muss gemacht werden, nachdem dri und vi fest stehen */
  1458.   InitBoopsi();            /* allocate all in 'struct BoopsiObj'    */
  1459. }
  1460.  
  1461.  
  1462.  
  1463.  
  1464.  
  1465. struct HookMsg {
  1466.   struct Layer      * layer;
  1467.   struct Rectangle    bounds;
  1468.   LONG                offsetx;
  1469.   LONG                offsety;
  1470. };
  1471.  
  1472. static ULONG __asm hookEntry( register __a0 struct Hook * h, 
  1473.                   register __a2 void * o, 
  1474.                   register __a1 void * msg )
  1475. {
  1476.   putreg(REG_A4, (long)h->h_Data);  
  1477.   return ((*(ULONG (* __stdargs)(struct RastPort *, struct HookMsg *))h->h_SubEntry)(o, msg));
  1478. }
  1479.  
  1480. static struct Hook BackHook;
  1481. static struct RastPort BackHookRP;
  1482.  
  1483.  
  1484. static void __stdargs BackHookFunc(struct RastPort * rp, struct HookMsg * msg)
  1485. {
  1486.   WORD MinX, MinY, MaxX, MaxY;
  1487.  
  1488.   set_i_window_size();        // ein bischen aufwenig :-((
  1489.  
  1490.   MinX = (msg->bounds.MinX < Page_LeftPoint)   ? Page_LeftPoint   : msg->bounds.MinX;
  1491.   MinY = (msg->bounds.MinY < Page_TopPoint)    ? Page_TopPoint    : msg->bounds.MinY;
  1492.   MaxX = (msg->bounds.MaxX > Page_RightPoint)  ? Page_RightPoint  : msg->bounds.MaxX;
  1493.   MaxY = (msg->bounds.MaxY > Page_BottomPoint) ? Page_BottomPoint : msg->bounds.MaxY;
  1494.  
  1495.   if (MaxX > MinX && MaxY > MinY) {
  1496.     //D(bug("BHF() MinX: %ld, MaxX: %ld, MinY: %ld, MaxY: %ld\n", MinX, MaxX, MinY, MaxY));
  1497.     RectFill(&BackHookRP, MinX, MinY, MaxX, MaxY);
  1498.   }
  1499. }
  1500.  
  1501.  
  1502.  
  1503.  
  1504. static int sleep_counter = 0;
  1505.  
  1506.  
  1507. static struct TagItem win2_tags[] = 
  1508.   {
  1509.               { WA_MenuHelp,     TRUE    },
  1510.               { WA_MouseQueue,   5L        },    /* 5 messages... */
  1511.               { WA_RptQueue,     1L        },
  1512.               { WA_AutoAdjust,   TRUE    },
  1513.               { WA_NewLookMenus, TRUE    },
  1514.                           { TAG_DONE,        0L        }
  1515.   };
  1516.  
  1517.  
  1518. static void OpenWin2(void)
  1519. {
  1520.   struct Process *proc;
  1521.   struct NewWindow new_win; 
  1522.   int hgrp;
  1523.   
  1524.  
  1525.   if (is_ownscr) {  
  1526.     new_win.LeftEdge = ((show_state.window_pos_own_scr_x == -1)
  1527.                 ? WIN_X_KOO
  1528.                 : show_state.window_pos_own_scr_x);
  1529.     new_win.TopEdge = ((show_state.window_pos_own_scr_y == -1)
  1530.                 ? WIN_Y_KOO-((is_os2) ? 0 : 1)
  1531.                 : show_state.window_pos_own_scr_y);
  1532.   }
  1533.   else {
  1534.     new_win.LeftEdge = ((show_state.window_pos_x == -1)
  1535.                 ? WIN_X_KOO
  1536.                 : show_state.window_pos_x);
  1537.     new_win.TopEdge = ((show_state.window_pos_y == -1)
  1538.                 ? WIN_Y_KOO-((is_os2) ? 0 : 1)
  1539.                 : show_state.window_pos_y);
  1540.   }
  1541.   new_win.Width = x_win_width;
  1542.   new_win.Height = x_win_height;
  1543.   if (is_col4) {
  1544.     new_win.DetailPen = 0;
  1545.     new_win.BlockPen = 1; 
  1546.   }
  1547.   else {
  1548.     new_win.DetailPen = 0;
  1549.     new_win.BlockPen = 1; 
  1550.   }
  1551.   new_win.Title = "ShowDVI V" SHOWDVI_VERSION;
  1552.   new_win.Flags = WFLG_CLOSEGADGET | WFLG_DEPTHGADGET | WFLG_ACTIVATE | WFLG_DRAGBAR |
  1553.         WFLG_REPORTMOUSE | WFLG_RMBTRAP | WFLG_SIZEGADGET | WFLG_SIZEBBOTTOM;
  1554.  
  1555.   if (is_smartwin) new_win.Flags |= WFLG_SMART_REFRESH;
  1556.   else             new_win.Flags |= WFLG_SIMPLE_REFRESH;
  1557.   
  1558.   /**
  1559.   if (!is_osmenu) {
  1560.     new_win.Flags |= WFLG_RMBTRAP;
  1561.   }
  1562.   **/
  1563.  
  1564.   new_win.IDCMPFlags = IDCMP_FLAGS;
  1565.   if (IntuitionBase->LibNode.lib_Version > 36) {
  1566.     new_win.IDCMPFlags |= IDCMP_MENUHELP | IDCMP_CHANGEWINDOW;
  1567.   }
  1568.  
  1569.   if (is_pubscr && is_os2) {            /* naja, unter os_2 ist doch alles pubscr.. */
  1570.     new_win.Type = PUBLICSCREEN;
  1571.   }
  1572.   else {
  1573.     if (is_ownscr) {
  1574.       new_win.Type = CUSTOMSCREEN;
  1575.     }
  1576.     else {
  1577.       new_win.Type = WBENCHSCREEN;
  1578.     }
  1579.   }
  1580.   
  1581.   new_win.FirstGadget = (struct Gadget *)NULL; /* werden spaeter hinzugefuehrt */
  1582.   new_win.CheckMark = NULL;
  1583.   new_win.Screen = screen;
  1584.   new_win.BitMap = NULL;
  1585.   new_win.MinWidth = 370;
  1586.   new_win.MinHeight = 4*HEIGHT_UD_ARROW+HEIGHT_SCROLL+45;
  1587.   new_win.MaxWidth = 65535;
  1588.   new_win.MaxHeight = 65535;
  1589.  
  1590.   hgrp = GetHelpNum(); //(AbortRun Test)
  1591.   //hgrp = -1;
  1592.   
  1593.   if (hgrp != -1) new_win.IDCMPFlags |= IDCMP_GADGETHELP;
  1594.   show_state.aktIDCMP = new_win.IDCMPFlags;    /* !! */
  1595.   
  1596.   if (is_os2) {
  1597.     win2 = OpenWindowTags(&new_win, WA_MenuHelp,     TRUE,
  1598.                     WA_MouseQueue,   5L,
  1599.                     WA_RptQueue,     1L,    
  1600.                     WA_AutoAdjust,   TRUE,
  1601.                     WA_NewLookMenus, TRUE,
  1602.         (hgrp == -1) ? TAG_IGNORE : WA_HelpGroup,    hgrp,
  1603.                     TAG_DONE);
  1604.   }
  1605.   else {
  1606.     win2 = OpenWindow(&new_win);
  1607.   }
  1608.  
  1609.   if (win2 == NULL) {
  1610.      Fatal (5,MSG_CANT_OPEN_WIN);
  1611.   }
  1612.   
  1613.   sleep_counter = 0;
  1614.  
  1615.   MySetABPenDrMd(win2->RPort, show_state.APen, show_state.BPen, JAM2);
  1616.  
  1617.   if (is_bhook) {
  1618.     // ohne BHook geht es zwar auch, dann flackert das Bild aber beim Scrollen ganz häßlich!
  1619.  
  1620.     // erstmal alles fuellen
  1621.     fill_block(win2->BorderLeft, win2->BorderTop, 
  1622.            win2->Width - win2->BorderRight - win2->BorderLeft + 1,  
  1623.            win2->Height - win2->BorderBottom - win2->BorderTop + 1, 2);
  1624.  
  1625.     BackHookRP       = *win2->RPort;
  1626.     BackHookRP.Layer = NULL;
  1627.     SetAPen(&BackHookRP, show_state.BPen);
  1628.     SetDrMd(&BackHookRP, JAM1);
  1629.  
  1630.     // Installiere einen Backfill Hook
  1631.     BackHook.h_Entry    = (unsigned long (* )()) hookEntry;
  1632.     BackHook.h_SubEntry = (ULONG (* )()) BackHookFunc;
  1633.     BackHook.h_Data     = (void *)getreg(REG_A4);
  1634.     (void)InstallLayerHook(win2->WLayer, &BackHook);
  1635.   }
  1636.   
  1637.   if (hgrp != -1) StartHelp(screen, win2);
  1638.  
  1639.   /* So, nun nochmal screen setzen...zur Sicherheit */
  1640.   screen = win2->WScreen;        /* wg. FallBack */
  1641.   x_scr_width = screen->Width;
  1642.   x_scr_height = screen->Height;
  1643.   x_win_width = win2->Width;        /* wg. AutoAdjust */
  1644.   x_win_height = win2->Height;
  1645.   ScreenToFront(screen);        /* falls irgend ein PubScr */
  1646.   
  1647.   /* requester-window */
  1648.   proc = (struct Process *)FindTask(0);
  1649.   old_Win_Ptr_Requester = (struct Window *)proc->pr_WindowPtr;
  1650.   proc->pr_WindowPtr = (APTR)win2;
  1651.  
  1652.   sig_win = win2->UserPort->mp_SigBit;
  1653. #ifdef DEBUG
  1654.   if (DeBug) printf("Signal NR Window: %d\n",(int)sig_win);
  1655. #endif
  1656.  
  1657.   width_left_border  = win2->BorderLeft;
  1658.   width_right_border = win2->BorderRight;
  1659.   HeightWinTitle = win2->BorderTop;
  1660.  
  1661.   /* wird benoetigt um festzustellen, ob das Win. verschoben wurde */
  1662.   old_win_pos_x = win2->LeftEdge;
  1663.   old_win_pos_y = win2->TopEdge;
  1664.  
  1665.   // nach OpenWindow bis ier her gehen 56 Bytes verloren!
  1666.   // es geht nix verloren, wenn man hgrp auf -1 setzt! (siehe StartHelp()) (AbortRun)
  1667.  
  1668.   init_os_menu();
  1669.   SetDosMenu();
  1670.   
  1671.   win2->Flags &= ~WFLG_RMBTRAP;        /* jetzt Menue freigeben */
  1672.   
  1673.   
  1674.   /** nun noch ein App-Window daraus machen, falls der Screen ein WB-Screen ist */
  1675.   if (screen->Flags | WBENCHSCREEN) {
  1676.     if ((MainAppWinMsgPort = CreateMsgPort())) {
  1677.       MainAppWin = AddAppWindowA(0, 0, win2, MainAppWinMsgPort, NULL);
  1678.     }
  1679.   }
  1680.   else {
  1681.     MainAppWin        = NULL;
  1682.     MainAppWinMsgPort = NULL;
  1683.   }
  1684.  
  1685.   // 0 Bytes (AbortRun)
  1686.  
  1687.   /* falls is_bmcpu muss nun noch die Puffer-Bitmap alloziert werden */
  1688.   if (is_bmcpu) {
  1689.     AllocChipPuffRP();
  1690.   }
  1691.  
  1692.   { struct Gadget * g = win2->FirstGadget;
  1693.     while (g && g->GadgetType != GTYP_WDEPTH) g = g->NextGadget;
  1694.     if (g) WidthSysDepthGadget = g->Width;
  1695.     else   WidthSysDepthGadget = 20;
  1696.   }
  1697. }
  1698.  
  1699.  
  1700.  
  1701. static struct Requester block_req;
  1702. static int win2_blocked = FALSE;
  1703.  
  1704. void block_win2(void)
  1705. {
  1706.   if (!win2_blocked) {
  1707.     (void)memset(&block_req, 0, sizeof(block_req));
  1708.     win2_blocked = Request(&block_req, win2);
  1709.   }
  1710. }
  1711.  
  1712. void unblock_win2(void)
  1713. {
  1714.   if (win2_blocked) {
  1715.     EndRequest(&block_req, win2);
  1716.     win2_blocked = FALSE;
  1717.   }
  1718. }
  1719.  
  1720.  
  1721. /****
  1722. #define SPRITE_DATA_SIZE    24
  1723. #define SPRITE_HEIGHT        11
  1724. #define SPRITE_WIDTH        12
  1725. ***/
  1726. #define SPRITE_DATA_SIZE    48
  1727. #define SPRITE_HEIGHT        16
  1728. #define SPRITE_WIDTH        15
  1729.  
  1730. static const USHORT __chip SleepPointerData[] = {
  1731.     0x0000, 0x0000,    /* vert. and horiz. start posn. */
  1732.     0x0400,    0x07C0,
  1733.     0x0000,    0x07C0,
  1734.     0x0100,    0x0380,
  1735.     0x0000,    0x07E0,
  1736.     0x07C0,    0x1FF8,
  1737.     0x1FF0,    0x3FEC,
  1738.     0x3FF8,    0x7FDE,
  1739.     0x3FF8,    0x7FBE,
  1740.     0x7FFC,    0xFF7F,
  1741.     0x7EFC,    0xFFFF,
  1742.     0x7FFC,    0xFFFF,
  1743.     0x3FF8,    0x7FFE,
  1744.     0x3FF8,    0x7FFE,
  1745.     0x1FF0,    0x3FFC,
  1746.     0x07C0,    0x1FF8,
  1747.     0x0000,    0x07E0,
  1748.     0x0000, 0x0000,    /* reserved, must be NULL */
  1749. };
  1750.  
  1751.  
  1752. void sleep_pointer(void)
  1753. {
  1754.   if (win2) {
  1755.     sleep_counter++;
  1756.  
  1757.     if (sleep_counter == 1) {
  1758.       if (is_os3) {
  1759.         SetWindowPointer(win2, WA_BusyPointer, TRUE, WA_PointerDelay, TRUE, TAG_DONE);
  1760.       }
  1761.       else {
  1762.         SetPointer(win2,(UWORD *)SleepPointerData,SPRITE_HEIGHT,SPRITE_WIDTH,0,0);
  1763.       }
  1764.       block_win2();
  1765.     }
  1766.   }
  1767. }
  1768.  
  1769. void clear_pointer(void)
  1770. {
  1771.   if (win2) {
  1772.     sleep_counter--;
  1773.     
  1774.     if (sleep_counter == 0) {
  1775.       unblock_win2();
  1776.       ClearPointer(win2);
  1777.     }
  1778.   }
  1779. }
  1780.  
  1781. void SetupMargin(void)
  1782. {
  1783.   const long widthin  = (long)(((float)pwidth_pt  / 72.27 + ((float)SAVETY_BITS_X / (float)hconvresolution) * 1000.0 / (float)mag) * 1000.0 + 0.5);
  1784.   const long heightin = (long)(((float)pheight_pt / 72.27 + ((float)SAVETY_BITS_Y / (float)vconvresolution) * 1000.0 / (float)mag) * 1000.0 + 0.5);
  1785.  
  1786.   show_state.margin_x = static_x_Koo * widthin / wx; 
  1787.   show_state.margin_y = static_y_Koo * heightin / wy;
  1788.   set_margin;
  1789.   
  1790.   Message(MSG_SET_MARGIN);
  1791.  
  1792.  
  1793. #if 0
  1794.   static short OffX = -6;
  1795.   static short OffY = -6;
  1796.   
  1797.   if (is_tmpmargin) {
  1798.     Message(MSG_CANCEL_MARGIN_SETTING);
  1799.     clear_pointer();
  1800.     unset_tmpmargin;
  1801.     return;
  1802.   }
  1803.  
  1804.   set_tmpmargin;        // erst noch auf Klick warten
  1805.   
  1806.   Message(MSG_SET_MARGIN_SETTING);
  1807.  
  1808. #if 0
  1809.   if (margin_sprite_data == NULL) {
  1810.     #include <libraries/iffparse.h>
  1811.     struct Library * IFFParseBase = OpenLibrary("iffparse.library", 37);
  1812.  
  1813.     if (IFFParseBase) {
  1814.       const char * defname = "TeX:config/MarginPointer.iff";
  1815.       struct IFFHandle * iff;
  1816.       BPTR iffstream;
  1817.       
  1818.       iff = AllocIFF();
  1819.       iffstream = Open(defname, MODE_OLDFILE);
  1820.       if (iffstream && iff) {
  1821.         iff->iff_Stream = iffstream;
  1822.         iff->iff_Flags  = IFFF_READ;
  1823.         InitIFFasDOS(iff);
  1824.         if (OpenIFF(&iff, IFFF_READ) == 0) {
  1825.           struct StoredProperty * sp;
  1826.           
  1827.           sp = FindProp(iff, MAKE_ID('I','L','B','M'));
  1828.  
  1829.           CloseIFF(iff);
  1830.         }
  1831.       }
  1832.       if (iff) FreeIFF(iff);
  1833.       CloseLibrary(IFFParseBase);
  1834.     }
  1835.   }
  1836. #endif
  1837.  
  1838.   if (margin_sprite_data != NULL) {
  1839.     SetPointer(win2, margin_sprite_data, MARGIN_SPRITE_HEIGHT, MARGIN_SPRITE_WIDTH, OffX, OffY);
  1840.   }
  1841. #endif
  1842. }
  1843.  
  1844.  
  1845. void MyModifyIDCMP(ULONG add, ULONG sub)
  1846. {
  1847.   register ULONG act = show_state.aktIDCMP;
  1848.   BOOL ret;
  1849.   
  1850.   if (win2 == NULL) return;
  1851.  
  1852.   act = (act | add) & (~sub);
  1853.   if (act != show_state.aktIDCMP) {    /* hat sich wirklich was geaendert? */
  1854.     show_state.aktIDCMP = act;
  1855.   
  1856.     ret = ModifyIDCMP(win2, act);
  1857.     if (IntuitionBase->LibNode.lib_Version >= 37 && ret == NULL) {
  1858.       FatalStr(20, "Can't ModifyIDCMP(%x)!", act);
  1859.     }
  1860.   }
  1861. }
  1862.  
  1863.  
  1864. /*************   T I M E R *******************************************/
  1865.  
  1866.  
  1867. /* Aufruf aus globals.c */
  1868. void AddTimeRequest(void)
  1869. {
  1870.   if (screen != NULL && win2 != NULL) {
  1871.     /* set_timer; */
  1872.     if (timer_wait_ticks == 0) {
  1873.       MyModifyIDCMP(IDCMP_INTUITICKS, 0L);
  1874.       add_inticks;
  1875.     }
  1876.     timer_wait_ticks = WAIT_TIME_TICKS;
  1877.   }
  1878. }
  1879.  
  1880.  
  1881. /***********    P R I N T   --   H A R D C O P Y    ******************/
  1882.  
  1883. static void start_print_page(void)
  1884. {
  1885.   unsigned short ph_inch, pw_inch;
  1886.  
  1887. #ifdef DEBUG
  1888.   if (DeBug) printf("Print: sizex: %d, sizey: %d, ptx: %d, pty: %d\n",
  1889.                 wx,wy,pwidth_pt,pheight_pt);
  1890. #endif
  1891.  
  1892.   ToDo = DO_PDEVICE;
  1893.  
  1894.   sig_print = (UBYTE)InitPrinterDevice();
  1895.  
  1896.   if (sig_print != 255) {
  1897.  
  1898. #  ifdef DEBUG
  1899.     if (DeBug) printf("Signal NR fuer Print: %d\n",(int)sig_print);
  1900. #  endif
  1901.  
  1902.     set_print;
  1903.     write_status();        /* Index fuer Print */
  1904.  
  1905.     ph_inch = (unsigned short)((float)pheight_pt * 1000.0 / 72.27 + 0.5);
  1906.     pw_inch = (unsigned short)((float)pwidth_pt  * 1000.0 / 72.27 + 0.5);
  1907.  
  1908.     PrintRastPort(&myRastPort,
  1909.             (ULONG)(screen->ViewPort.Modes & 0x0000FFFF),
  1910.             (USHORT)wx, (USHORT)wy,
  1911.             pw_inch, ph_inch);
  1912.  
  1913.   }
  1914. }
  1915.  
  1916. static void check_print_page(void)
  1917. {
  1918.   EndPrintRastPort();
  1919.   ClosePrinterDevice();
  1920.   unset_print;
  1921.  
  1922.   write_status();
  1923. }
  1924.  
  1925.  
  1926. /* Struktur fuer den Print-Requester */
  1927. static struct EasyStruct PrintES = {
  1928.     sizeof (struct EasyStruct),
  1929.     0,
  1930.     NULL,
  1931.     NULL,
  1932.     NULL
  1933. };
  1934.  
  1935.  
  1936. void abort_print_page(void)
  1937. {
  1938.   if (!CheckIO((struct IORequest *)request)) {
  1939.     AbortIO((struct IORequest *)request);
  1940.     PROFILE_OFF();
  1941.     (void)Wait(SIG_PRINT);
  1942.     PROFILE_ON();
  1943.   }
  1944.   while (GetMsg(printerPort) != NULL) ;    /* neu 13-feb-91 */
  1945.  
  1946.   prnzero();                /* Drucker initialisieren */
  1947.   ClosePrinterDevice();
  1948.   unset_print;
  1949.  
  1950.   write_status();
  1951. }
  1952.  
  1953. void printing(void)
  1954. {
  1955.   if (is_print) {
  1956.     if (is_os2) {
  1957.       PrintES.es_Title        = GetTeXString(MSG_SHOWDVI_MESSAGE);
  1958.       PrintES.es_TextFormat   = GetTeXString(MSG_ABORT_PRINT_PAGE);
  1959.       PrintES.es_GadgetFormat = GetTeXString(MSG_OK_CANCEL_REQSTRING);
  1960.       if (!EasyRequestArgs(win2, &PrintES, NULL, NULL)) {
  1961.         return;
  1962.       }
  1963.     }
  1964.     Message(MSG_ABORT_PRINT);
  1965.     beep();
  1966.     abort_print_page();
  1967.     Message(MSG_PRINT_IS_ABORTED);
  1968.     set_checked_os_menu();
  1969.   }
  1970.   else {
  1971.     Message(MSG_PRINT_CUR_PAGE);
  1972.     set_checked_os_menu();
  1973.     start_print_page();
  1974.   }
  1975.   write_status();
  1976. }
  1977.  
  1978.  
  1979. /****************** Window Operationen *****************************/
  1980.  
  1981. void fill_block(short x,short y, short dx, short dy, short color)
  1982.                     /* i.e. clear the blatt_ok_gadget */
  1983.                     /* color 1: fill, color 0: clear  */
  1984. {
  1985.   struct RastPort *rp;
  1986.  
  1987.   if (win2 != NULL) {
  1988.     rp = win2->RPort;
  1989.     SetAPen(rp,(long)color);
  1990.     SetDrMd(rp,JAM1); 
  1991.     RectFill(rp,(long)x,(long)y,(long)(x+dx),(long)(y+dy));   /* loeschen */
  1992.     SetAPen(rp, 1);
  1993.   }
  1994. }
  1995.  
  1996.  
  1997. /* clear unused parts of the screen (if bitmap smaller than window) */
  1998. /* and refresh all gadgets in the window... */
  1999. void refresh_screen(void)
  2000. {
  2001.   RefreshWindowFrame(win2);
  2002.  
  2003. #if 0
  2004.   if (!is_os2) {
  2005.     /* Ziehe elfte Pixelreihe */
  2006.     struct RastPort *rp = win2->RPort;
  2007.     SetAPen(rp, 1);
  2008.     Move (rp, 0, HeightWinTitle-1);
  2009.     Draw (rp, x_win_width-1, HeightWinTitle-1);
  2010.     /* draw left border (verbreitern von 2 auf 4 Pixel) */
  2011.     fill_block((short)2,(short)HeightWinTitle-1,
  2012.             (short)(width_left_border-2-1) /* == 2  (??) */,
  2013.             (short)x_win_height-2-1,(short)1);
  2014.   }
  2015. #endif
  2016.  
  2017.  
  2018. #if 0 // ?????????????
  2019.  
  2020.   if (is_gadg) {
  2021.     if (x_win_i_width < x_win_width - WIDTH_SCROLL_BAR - width_left_border 
  2022.             - width_right_border + ((is_os2) ? 6 : 1)) {
  2023.       /* Inneres kleiner als Window, ScrollBar weiter links */
  2024.       fill_block((short)(x_win_i_width+WIDTH_SCROLL_BAR+width_left_border+width_right_border-((is_os2)?6+4:1)),
  2025.           (short)HeightWinTitle,
  2026.          (short)(x_win_width - WIDTH_SCROLL_BAR-x_win_i_width-width_left_border-width_right_border
  2027.                 -((is_os2)?6-11:1)),
  2028.          (short)(x_win_height-HeightWinTitle-2-1),(short)0);
  2029.                     /* height_lower_border ^^ */
  2030.       /* ganz rechten Border verdicken (OS < 2.0) */
  2031.       if (!is_os2) {
  2032.         fill_block((short)(x_win_width-width_right_border), (short)HeightWinTitle,
  2033.            (short)width_right_border-1, (short)(x_win_height-HeightWinTitle-1), (short)1);
  2034.       }
  2035.     }
  2036.     if (x_win_i_height < x_win_height - HeightWinTitle - HEIGHT_SCROLL_BAR) {
  2037.       fill_block((short)width_left_border, (short)(x_win_i_height+HeightWinTitle+HEIGHT_SCROLL_BAR),
  2038.          (short)(x_win_width-width_left_border-width_right_border-1),
  2039.          (short)(x_win_height-x_win_i_height-HeightWinTitle-HEIGHT_SCROLL_BAR-2-1),
  2040.          (short)0);
  2041.          /* height_lower_border ^^ (loescht border mit ?????? was soll das) */
  2042.          /* Border nicht mitloeschen, aber neu zeichnen */
  2043.       /* draw bottom border (ganz unten) */
  2044.       fill_block((short)width_left_border, (short)(x_win_height-2),
  2045.          (short)x_win_width-width_left_border-width_right_border,
  2046.          (short)2, (short)1);
  2047.       /* zeichne Leiste unter dem vert-SBar. (nur fuer OS >= 2.0) */
  2048.       if (is_os2) {
  2049.         fill_block((short)width_left_border, (short)(x_win_i_height+HeightWinTitle+HEIGHT_SCROLL_BAR-2),
  2050.            (short)x_win_i_width-2*(WIDTH_X_GADGETS), (short)1, (short)1);
  2051.       }
  2052.     }
  2053.     /* Border nachziehen, neben SBar */
  2054.     fill_block((short)(x_win_i_width+WIDTH_SCROLL_BAR-((is_os2)?4:0)+width_left_border),
  2055.          (short)HeightWinTitle,
  2056.          (short)(is_os2) ? width_right_border-1 : 2,    /* nicht so FETT unter 1.3 */
  2057.          (short)(x_win_i_height+HEIGHT_SCROLL_BAR-1),(short)1);
  2058.   }
  2059.   else {
  2060.     if (x_win_i_width < x_win_width - width_left_border - width_right_border+((is_os2)?4:0)) {
  2061.       fill_block((short)(x_win_i_width+width_left_border-((is_os2)?2:0)),(short)HeightWinTitle,
  2062.          (short)(x_win_width - width_left_border - width_right_border - x_win_i_width),
  2063.          (short)(x_win_height-HeightWinTitle-2-1),(short)0);
  2064.                     /* height_lower_border ^^ */
  2065.       /* zeichne rechten SBar neu (nur OS < 2.0) */
  2066.       if (!is_os2) {
  2067.         fill_block((short)(x_win_width-width_right_border), (short)HeightWinTitle,
  2068.            (short)width_right_border-1, (short)(x_win_height-HeightWinTitle-1), (short)1);
  2069.       }
  2070.     }
  2071.     if (x_win_i_height < x_win_height - HeightWinTitle-1) {
  2072.       fill_block((short)width_left_border, (short)(x_win_i_height+HeightWinTitle),
  2073.          (short)x_win_width-width_left_border-width_right_border-1,
  2074.                (short)(x_win_height-x_win_i_height-HeightWinTitle-2-1), (short)0);
  2075.                   /* height_lower_border ^^ */
  2076.     /* HEHH da wird ja der Border mit weggeloescht */
  2077.     }
  2078.     /* draw right border IST ZU LANG */
  2079.     fill_block((short)(x_win_i_width+width_left_border),(short)HeightWinTitle,
  2080.         (short)width_right_border,
  2081.         (short)(x_win_i_height+2),(short)1);
  2082.     /* draw bottom border IST ZU LANG */
  2083.     fill_block((short)width_left_border, (short)(x_win_i_height+HeightWinTitle),
  2084.          (short)x_win_i_width-width_left_border+width_right_border,
  2085.          (short)2, (short)1);
  2086.     /* draw bottom border (ganz unten) */
  2087.     fill_block((short)width_left_border, (short)(x_win_height-2),
  2088.          (short)x_win_width-width_left_border-width_right_border,
  2089.          (short)2, (short)1);
  2090.   }
  2091. #endif
  2092.  
  2093. }
  2094.  
  2095.  
  2096.  
  2097. #define MAXMESSAGESTRING    150
  2098. static char MessageString[MAXMESSAGESTRING];    /* Buffer for Messages! */
  2099.  
  2100. int write_screen(char *str)                /* KEIN static */
  2101. {
  2102.   WORD len;
  2103.  
  2104.   if (screen != NULL && win2 != NULL) {
  2105.     len = TextLength(&(screen->RastPort), str, strlen(str));
  2106.     if (len < screen->Width - 30) {    /* -30.. naja fuer die Gadgets halt... */
  2107.       strncpy(MessageString, str, MAXMESSAGESTRING);
  2108.       SetWindowTitles(win2, (char *)-1, MessageString);
  2109.     }
  2110.     return TRUE;
  2111.   }
  2112.   else {
  2113.     return FALSE;
  2114.   }
  2115. }
  2116.  
  2117. #if 0
  2118. void write_screen_counter(int nr)            /* KEIN static */
  2119. {
  2120.   char str[8];
  2121.   struct RastPort *rp;
  2122.   int len;
  2123.   WORD TopEdge;
  2124.   static long oldcounter = -1;
  2125.  
  2126.   if (win2 != NULL) {
  2127.     rp = win2->RPort;
  2128.     SetAPen(rp,1);
  2129.     TopEdge = (HeightWinTitle - rp->Font->tf_YSize) / 2;
  2130.     SetDrMd(rp,COMPLEMENT);
  2131.     if (oldcounter >= 0){
  2132.       Move(rp, WR_COUNTER_LEFT, TopEdge + rp->Font->tf_YSize);
  2133.       sprintf(str,"%4d",oldcounter);
  2134.       len = strlen(str);
  2135.       if (len>4) {
  2136.          str[4] = (char)0;
  2137.       }
  2138.       Text(rp,str,(long)strlen(str));
  2139.     }
  2140.     SetDrMd(rp,JAM1); 
  2141. #if 0
  2142.     RectFill(rp, WR_COUNTER_LEFT, TopEdge, WR_COUNTER_LEFT+32L, TopEdge+rp->Font->tf_YSize);    /* loeschen */
  2143. #endif
  2144.     if (nr >= 0) { 
  2145.       SetAPen(rp,0L);
  2146.       Move(rp, WR_COUNTER_LEFT, TopEdge + rp->Font->tf_YSize);
  2147.       sprintf(str,"%4d",nr);
  2148.       len = strlen(str);
  2149.       if (len>4) {
  2150.          str[4] = (char)0;
  2151.       }
  2152.       Text(rp,str,(long)strlen(str));
  2153.     }
  2154.     oldcounter = nr;
  2155.   }
  2156. }
  2157. #endif
  2158.  
  2159. void write_status(void)                    /* KEIN static (wg. amkey) */
  2160. {
  2161.   static char TitleBuf[256];
  2162.   static char FNameBuf[200];
  2163.   int again = TRUE;
  2164.   int last  = FALSE;
  2165.  
  2166.   if (win2) {
  2167.  
  2168.     FNameBuf[sizeof(FNameBuf)-1] = '\0';  
  2169.     strncpy(FNameBuf, filename, sizeof(FNameBuf)-1);
  2170.   
  2171.     do {
  2172.       char * ptr;
  2173.       int count = take_counter(0);
  2174.       int sec = get_secundary(current_page_phy);
  2175.       char buf[24];
  2176.  
  2177.       if (is_dvif) {
  2178.         sprintf(TitleBuf, GetTeXString(MSG_WIN_HEADER_FILE), 
  2179.               FNameBuf, current_page_phy, max_page_number);
  2180.  
  2181.         if (current_page != current_page_phy || sec != 0) {
  2182.           if (sec != 0) {
  2183.             sprintf(buf, "«%d.%d»  ", current_page, sec);
  2184.           }
  2185.           else {
  2186.             sprintf(buf, "«%d»  ", current_page);
  2187.           }
  2188.         }
  2189.         else {
  2190.           buf[0] = '\0';
  2191.         }
  2192.         strcat(TitleBuf, buf);
  2193.       }
  2194.       else {
  2195.         sprintf(TitleBuf, GetTeXString(MSG_WIN_HEADER_NO_FILE), SHOWDVI_VERSION, COMPILER);
  2196.       }
  2197.  
  2198.       if (count != -1) {
  2199.         sprintf(buf, "[%d]  ", count);
  2200.         strcat(TitleBuf, buf);
  2201.       }
  2202.  
  2203.       if (is_print || is_usephy || is_show) {
  2204.         ptr = TitleBuf + strlen(TitleBuf);
  2205.         *ptr++ = '(';
  2206.         if (is_print)  *ptr++ = 'P';
  2207.         if (is_usephy) *ptr++ = 'Y';
  2208.         if (is_show)   *ptr++ = 'F';
  2209.         *ptr++ = ')';
  2210.         *ptr   = '\0';
  2211.       }
  2212.  
  2213.       sec = (win2->Width - WidthSysDepthGadget*3 - 20) - TextLength(&screen->RastPort, TitleBuf, strlen(TitleBuf));    // Differenz
  2214.       
  2215.       if (is_dvif && sec < 0 && !last) {
  2216.         char * psl = strchr(FNameBuf, '/');
  2217.  
  2218.         if (psl) {
  2219.           char * pdd = strchr(FNameBuf, ':');
  2220.           
  2221.           if (pdd) {
  2222.             if (psl - pdd < 5) {
  2223.               psl = strchr(psl+1, '/');
  2224.             }
  2225.             if (psl) {
  2226.               int i;
  2227.               pdd[1] = '.';
  2228.               pdd[2] = '.';
  2229.               pdd[3] = '.';
  2230.               for (i=0; psl[i] && i < 50; i++) {
  2231.                 pdd[i+4] = psl[i];
  2232.               }
  2233.               pdd[i+4] = '\0';
  2234.             }
  2235.             else {
  2236.               psl = strrchr(filename, '/');
  2237.               if (psl) {
  2238.                 // dann nur noch der Filename alleine
  2239.                 strncpy(FNameBuf, psl+1, sizeof(FNameBuf)-1);
  2240.               }
  2241.               last = TRUE;
  2242.             }
  2243.           }
  2244.         }
  2245.         else {
  2246.           again = FALSE;
  2247.         }
  2248.       }
  2249.       else {
  2250.         again = FALSE;
  2251.       }
  2252.  
  2253.     } while (again);
  2254.  
  2255.     SetWindowTitles(win2, TitleBuf, (UBYTE *)-1);    /* refresh ?? */
  2256.   }
  2257. #if 0
  2258.   struct RastPort *rp;
  2259.   static char str[4] = "   ";
  2260.   WORD TopEdge;
  2261.   LONG penno;
  2262.  
  2263.   if (win2 != NULL) {
  2264.       rp = win2->RPort;
  2265.       TopEdge = (HeightWinTitle - rp->Font->tf_YSize) / 2;
  2266.       penno = ReadPixel(rp, WR_STATUS_LEFT-1, TopEdge);
  2267.       if (penno == -1) penno = 1;
  2268.       SetDrMd(rp,JAM1);
  2269.       SetAPen(rp, penno);
  2270.       Move(rp, WR_STATUS_LEFT, TopEdge + rp->Font->tf_YSize);
  2271.       Text(rp,str,3);
  2272. #if 0
  2273.       RectFill(rp, WR_STATUS_LEFT, TopEdge, WR_STATUS_LEFT+24L,TopEdge+rp->Font->tf_YSize);   /* loeschen */
  2274. #endif
  2275.       SetAPen(rp,0);
  2276.       Move(rp, WR_STATUS_LEFT, TopEdge + rp->Font->tf_YSize);
  2277.       str[0] = (is_print)  ? 'P' : ' ';
  2278.       str[1] = (is_usephy) ? 'Y' : ' ';
  2279.       str[2] = (is_show)   ? 'F' : ' ';
  2280.       str[3] = '\0';
  2281.       Text(rp,str,3);
  2282.       write_screen_counter(take_counter(0));
  2283.    }
  2284. #endif
  2285. }
  2286.  
  2287.  
  2288. /* Wie ClipBlit(), nur dass etwas mit den Planes getrickst wird um ein schwarz auf weiss zu erreichen */
  2289. static __inline void ClipIt(const long destx, const long desty, const long x, const long y, const long dx, const long dy)
  2290. {
  2291.   MySetABPenDrMd(win2->RPort, show_state.APen, (is_bhook) ? show_state.BPen : 0, JAM2);
  2292.   BltTemplate(myRastPort.BitMap->Planes[0]+y*myRastPort.BitMap->BytesPerRow+(x/16)*2, x%16, myRastPort.BitMap->BytesPerRow, win2->RPort, destx, desty, dx, dy);
  2293.  
  2294. #ifdef OLD_BLIT
  2295.   if (is_bhook) {
  2296.     SafeSetWriteMask(win2->RPort, 0x02);
  2297.     ClipBlit(&myRastPort, x, y, win2->RPort, destx, desty, dx, dy, 0x30);
  2298.   }
  2299.   SafeSetWriteMask(win2->RPort, 0x01);
  2300.   ClipBlit(&myRastPort, x, y, win2->RPort, destx, desty, dx, dy, 0xC0);
  2301.   SafeSetWriteMask(win2->RPort, 0xff);
  2302. #endif
  2303. }
  2304.  
  2305.  
  2306. static void win_mov(const long dx, const long dy, const long x, const long y)
  2307. {
  2308. #if 0
  2309.   const long winiw = win2->Width - win2->BorderLeft - win2->BorderRight;
  2310.   const long winih = win2->Height - win2->BorderTop - win2->BorderBottom;
  2311. #endif
  2312.  
  2313.   /*
  2314.    *   destx/desty geben den linken/oberen Punkt an.
  2315.    *   Dadurch wird, wenn noetig, das Bild zentriert.
  2316.    */
  2317.   const long destx = win2->BorderLeft + ((winiw > wx) ? ((winiw-wx) / 2) : 0);
  2318.   const long desty = win2->BorderTop  + ((winih > wy) ? ((winih-wy) / 2) : 0);
  2319.   
  2320.   //D(bug("bmfast: %ld, bmcpu: %ld, scrollras: %ld, vill: %ld\n",
  2321.   //    is_bmfast, is_bmcpu, is_scrollras, is_village));
  2322.  
  2323.  
  2324.  
  2325.   if (is_scrollras && (dx != 0 || dy != 0) && abs(dx) < winiw && abs(dy) < winih) {
  2326.  
  2327.     if (!is_bhook) SafeSetWriteMask(win2->RPort, 1);        // *nur* Plane 0 scrollen
  2328.  
  2329.     /*
  2330.      * Den umstaendlichen Weg ueber ScrollRaster() gehen wir nur wenn
  2331.      * is_scrollras gesetzt ist. Dies ist vor allem bei der PICASSO der
  2332.      * Fall.
  2333.      * Doch auch dann wird das nur gemacht, wenn es kein 'show' ist und
  2334.      * wenn nicht mit ALT grosse Spruenge gemacht werden. 
  2335.      */
  2336.   
  2337.     /*
  2338.      * Es wird immer nur eine Plane gescrollt ---time is money---
  2339.      */
  2340.     if (is_os3) {
  2341.       ScrollWindowRaster(win2, dx, dy,
  2342.         win2->BorderLeft, win2->BorderTop,
  2343.         win2->BorderLeft+winiw-1, win2->BorderTop+winih-1);
  2344.     }
  2345.     else {
  2346.       ScrollRaster(win2->RPort, dx, dy,
  2347.         win2->BorderLeft, win2->BorderTop,
  2348.         win2->BorderLeft+winiw-1, win2->BorderTop+winih-1);
  2349.       if (win2->RPort->Layer->Flags & LAYERREFRESH) {
  2350.         BeginRefresh(win2);
  2351.         /* kopiere *alles* nochmal! (urgs) */
  2352.         if (is_bmcpu && show_state.ChipPuffBM) {
  2353.           CPUBlit(x, y, destx, desty, (winiw > wx) ? wx : winiw, (winih > wy) ? wy : winih);
  2354.         }
  2355.         else {
  2356.           ClipIt(destx, desty, x, y, (winiw > wx) ? wx : winiw, (winih > wy) ? wy : winih);
  2357. /*
  2358.           ClipBlit(&myRastPort, x, y, win2->RPort, destx, desty,
  2359.              (winiw > wx) ? wx : winiw, (winih > wy) ? wy : winih, 0xC0);
  2360. */
  2361.         }
  2362.         EndRefresh(win2, TRUE);
  2363.       }
  2364.     }
  2365.  
  2366.     if (is_bmcpu && show_state.ChipPuffBM) {
  2367.       if (dx > 0) {
  2368.         CPUBlit(x+winiw-dx, y, destx+winiw-dx, desty, dx, (winih > wy) ? wy : winih);
  2369.       }
  2370.       if (dx < 0) {
  2371.         CPUBlit(x, y, destx, desty, -dx, (winih > wy) ? wy : winih);
  2372.       }
  2373.       if (dy > 0) {
  2374.         CPUBlit(x, y+winih-dy, destx, desty+winih-dy, (winiw > wx) ? wx : winiw, dy);
  2375.       }
  2376.       if (dy < 0) {
  2377.         CPUBlit(x, y, destx, desty, (winiw > wx) ? wx : winiw, -dy);
  2378.       }
  2379.     }
  2380.     else {
  2381.       if (dx > 0) {
  2382.         ClipIt(destx+winiw-dx, desty, x+winiw-dx, y, dx, (winih > wy) ? wy : winih);
  2383.         // ClipBlit(&myRastPort, x+winiw-dx, y, win2->RPort, destx+winiw-dx, desty, dx, (winih > wy) ? wy : winih, 0xC0);
  2384.       }
  2385.       if (dx < 0) {
  2386.         ClipIt(destx, desty, x, y, -dx, (winih > wy) ? wy : winih);
  2387.         // ClipBlit(&myRastPort, x, y, win2->RPort, destx, desty, -dx, (winih > wy) ? wy : winih, 0xC0);
  2388.       }
  2389.       if (dy > 0) {
  2390.         ClipIt(destx, desty+winih-dy, x, y+winih-dy, (winiw > wx) ? wx : winiw, dy);
  2391.         // ClipBlit(&myRastPort, x, y+winih-dy, win2->RPort, destx, desty+winih-dy, (winiw > wx) ? wx : winiw, dy, 0xC0);
  2392.       }
  2393.       if (dy < 0) {
  2394.         ClipIt(destx, desty, x, y, (winiw > wx) ? wx : winiw, -dy);
  2395.         // ClipBlit(&myRastPort, x, y, win2->RPort, destx, desty, (winiw > wx) ? wx : winiw, -dy, 0xC0);
  2396.       }
  2397.     }
  2398.  
  2399.     SafeSetWriteMask(win2->RPort, 0xFF);        // alle Planes wieder einschalten
  2400.   }
  2401.   else {
  2402.  
  2403.     if (is_bmcpu && show_state.ChipPuffBM) {
  2404.       CPUBlit(x, y, destx, desty, (winiw > wx) ? wx : winiw, (winih > wy) ? wy : winih);
  2405.     }
  2406.     else {
  2407.       ClipIt(destx, desty, x, y, (winiw > wx) ? wx : winiw, (winih > wy) ? wy : winih);
  2408. /*
  2409.       ClipBlit(&myRastPort, x, y, win2->RPort, destx, desty,
  2410.             (winiw > wx) ? wx : winiw, (winih > wy) ? wy : winih, 0xC0);
  2411.       SafeSetWriteMask(win2->RPort, 0x02);
  2412.       ClipBlit(&myRastPort, x, y, win2->RPort, destx, desty,
  2413.             (winiw > wx) ? wx : winiw, (winih > wy) ? wy : winih, 0x30);
  2414. */
  2415.     }
  2416.   }
  2417. }
  2418.  
  2419. void window_show(void)
  2420. {
  2421.   set_i_window_size();
  2422.  
  2423.   if (x_win_i_width > wx) {
  2424.     // Window loeschen, da moeglicherweise erst neuerdings so viel sichtbar
  2425.     // spich gerade ist auf 44dpi gewechselt worden
  2426.  
  2427.     fill_block(win2->BorderLeft, win2->BorderTop, Page_LeftPoint-win2->BorderLeft-1, x_win_i_height-1, 0);
  2428.     fill_block(Page_RightPoint, win2->BorderTop, win2->Width-Page_RightPoint-win2->BorderRight-1, x_win_i_height-1, 0);
  2429.  
  2430.     static_x_Koo = 0;    // ganz links anzeigen
  2431.   }
  2432.   if (x_win_i_height > wy) {
  2433.     fill_block(win2->BorderLeft, win2->BorderTop, x_win_i_width-1, Page_TopPoint-win2->BorderTop-1, 0);
  2434.     fill_block(win2->BorderLeft, Page_BottomPoint, x_win_i_width-1, win2->Height-Page_BottomPoint-win2->BorderBottom-1, 0);
  2435.  
  2436.     static_y_Koo = 0;    // ganz oben anzeigen
  2437.   }
  2438.  
  2439.   win_mov(0, 0, static_x_Koo, static_y_Koo);
  2440. }
  2441.  
  2442. void window_plus_sbar_move(int dx, int dy)        /* KEIN static */
  2443. {  
  2444. #if 0
  2445.   const long winiw = win2->Width - win2->BorderLeft - win2->BorderRight;
  2446.   const long winih = win2->Height - win2->BorderTop - win2->BorderBottom;
  2447. #endif
  2448.  
  2449.   register int xa,ya;
  2450.   register int xh, yh;
  2451.  
  2452.   // dx zum x-Wert addieren und Grenzen beachten
  2453.   if (wx < winiw) {
  2454.     xa = xh = 0;
  2455.   }
  2456.   else {
  2457.     xa = static_x_Koo;
  2458.     xh = xa + dx;
  2459.     if (xh > wx-winiw) xh = wx-winiw;
  2460.     else if (xh < 0)   xh = 0;
  2461.   }
  2462.  
  2463.   // dy zum y-Wert addieren und Grenzen beachten
  2464.   if (wy < winih) {
  2465.     ya = yh = 0;
  2466.   }
  2467.   else {
  2468.     ya = static_y_Koo;
  2469.     yh = ya + dy;
  2470.     if (yh > wy-winih) yh = wy-winih;
  2471.     else if (yh < 0)   yh = 0;
  2472.   }
  2473.  
  2474.   // falls sich die Koo. geaendert haben, dann neu anzeigen
  2475.   if (!(xh == xa && yh == ya)) {
  2476.       win_mov(xh-static_x_Koo, yh-static_y_Koo, xh, yh);
  2477.       static_x_Koo = xh;
  2478.       static_y_Koo = yh;
  2479.  
  2480.       if (xh != xa) {
  2481.     ModifyXPot();
  2482.       }
  2483.       if (yh != ya) {
  2484.     ModifyYPot();
  2485.      CheckUpDownBorderGad();        /* Teste oben/unten */
  2486.       }
  2487.   }
  2488. }
  2489.  
  2490. void window_move(const int dx, const int dy)
  2491. {  
  2492. #if 0
  2493.   const long winiw = win2->Width - win2->BorderLeft - win2->BorderRight;
  2494.   const long winih = win2->Height - win2->BorderTop - win2->BorderBottom;
  2495. #endif
  2496.  
  2497.   register int xa, ya;
  2498.   register int xh, yh;
  2499.  
  2500.   // dx zum x-Wert addieren und Grenzen beachten
  2501.   if (wx < winiw) {
  2502.     xa = xh = 0;
  2503.   }
  2504.   else {
  2505.     xa = static_x_Koo;
  2506.     xh = xa + dx;
  2507.     if (xh > wx-winiw) xh = wx-winiw;
  2508.     else if (xh < 0)   xh = 0;
  2509.   }
  2510.  
  2511.   // dy zum y-Wert addieren und Grenzen beachten
  2512.   if (wy < winih) {
  2513.     ya = yh = 0;
  2514.   }
  2515.   else {
  2516.     ya = static_y_Koo;
  2517.     yh = ya + dy;
  2518.     if (yh > wy-winih) yh = wy-winih;
  2519.     else if (yh < 0)   yh = 0;
  2520.   }
  2521.  
  2522.   if (!(xh == xa && yh == ya)) {
  2523.       win_mov(xh-static_x_Koo, yh-static_y_Koo, xh, yh);
  2524.       static_x_Koo = xh;
  2525.       static_y_Koo = yh;
  2526.   }
  2527. }
  2528.  
  2529. void window_set_x (int x)                /* KEIN static */
  2530. {
  2531. #if 0
  2532.   const long winiw = win2->Width - win2->BorderLeft - win2->BorderRight;
  2533. #endif
  2534.  
  2535.   register int xh;
  2536.  
  2537.   // x als x-Wert nehmen und Grenzen beachten
  2538.   if (wx < winiw) {
  2539.     xh = 0;
  2540.   }
  2541.   else {
  2542.     xh = x;
  2543.     if (xh > wx-winiw) xh = wx-winiw;
  2544.     else if (xh < 0)   xh = 0;
  2545.   }
  2546.  
  2547.   win_mov(xh-static_x_Koo, 0, xh, static_y_Koo);
  2548.   static_x_Koo = xh;
  2549. }
  2550.  
  2551. void window_set_y (int y)                /* KEIN static */
  2552. {
  2553. #if 0
  2554.   const long winih = win2->Height - win2->BorderTop - win2->BorderBottom - 1;
  2555. #endif
  2556.  
  2557.   register int yh;
  2558.  
  2559.   // y als y-Wert nehmen und Grenzen beachten
  2560.   if (wy < winih) {
  2561.     yh = 0;
  2562.   }
  2563.   else {
  2564.     yh = y;
  2565.     if (yh > wy-winih) yh = wy-winih;
  2566.     else if (yh < 0)   yh = 0;
  2567.   }
  2568.  
  2569.   win_mov(0, yh-static_y_Koo, static_x_Koo, yh);
  2570.   static_y_Koo = yh;
  2571. }
  2572.  
  2573.  
  2574.  
  2575. /***************    R E S O L U T I O N    **************************/
  2576.  
  2577.  
  2578. static ULONG GetWBModeID(void)
  2579. {
  2580.   struct Screen *scr;
  2581.   ULONG ret = INVALID_ID;
  2582.   
  2583.   if (is_os2) {
  2584.     scr = LockPubScreen(NULL);
  2585.     if (scr != NULL) {
  2586.       ret = GetVPModeID(&(scr->ViewPort));
  2587.       UnlockPubScreen(NULL, scr);
  2588.     }
  2589.   }
  2590.   
  2591.   return ret;
  2592. }
  2593.  
  2594. // nicht static, da es als Default-Wert fuer GetScreenMode benoetigt wird
  2595. ULONG get_DisplayID(void)
  2596. {
  2597.   ULONG DisplayID = INVALID_ID;
  2598.  
  2599.   if (is_numeric) DisplayID = show_state.DisplayID;
  2600.  
  2601.   if (is_wbmode) {
  2602.     DisplayID = GetWBModeID();
  2603.   }
  2604.   
  2605.   if (DisplayID == INVALID_ID) {
  2606.     if (is_pal) {
  2607.       DisplayID = PAL_MONITOR_ID | ((is_lace) ? HIRESLACE_KEY : HIRES_KEY);
  2608.     }
  2609.     else if (is_ntsc) {
  2610.       DisplayID = NTSC_MONITOR_ID | ((is_lace) ? HIRESLACE_KEY : HIRES_KEY);
  2611.     }
  2612.     else if (is_prod) {
  2613.       DisplayID = VGA_MONITOR_ID | ((is_lace) ? VGAPRODUCTLACE_KEY : VGAPRODUCT_KEY);
  2614.     }
  2615.     else if (is_a2024) {
  2616.       DisplayID = A2024_MONITOR_ID | ((is_lace) ? A2024TENHERTZ_KEY : A2024FIFTEENHERTZ_KEY);
  2617.     }
  2618.     else {
  2619.       DisplayID = DEFAULT_MONITOR_ID | ((is_lace) ? HIRESLACE_KEY : HIRES_KEY);
  2620.     }
  2621.   }
  2622.   
  2623.   return DisplayID;
  2624. }
  2625.  
  2626.  
  2627. /* liefert den String zu einem DisplayID */
  2628. /* bei INVALID_ID wird der ID des aktuellen Screens zurueckgeliefert */
  2629. /* in lace wird zurueckgegeben, ob der Mode interlaced ist oder nicht */
  2630. char * GetModeIDName(ULONG id, long * lace)
  2631. {
  2632.   static char Name[DISPLAYNAMELEN+1];
  2633.  
  2634.   if (id == INVALID_ID) {
  2635.     id = GetVPModeID(&(screen->ViewPort));
  2636.   }
  2637.   
  2638.   if (id == INVALID_ID || ModeNotAvailable(id)) {
  2639.     return GetTeXString(MSG_UNAVAILABLE_MODE);
  2640.   }
  2641.   else {
  2642.    struct DisplayInfo DispInfo;
  2643.    struct NameInfo NameInfo;
  2644.     if (GetDisplayInfoData(NULL, (UBYTE *)&NameInfo, sizeof(struct NameInfo), DTAG_NAME, id)) {
  2645.       strcpy(Name, NameInfo.Name);
  2646.       if (GetDisplayInfoData(NULL, (UBYTE *)&DispInfo, sizeof(struct DisplayInfo), DTAG_DISP, id)) {
  2647.         *lace = DispInfo.PropertyFlags & DIPF_IS_LACE;
  2648.       }
  2649.       return Name;
  2650.     }
  2651.     else {
  2652.       return GetTeXString(MSG_UNKNOWN_MODE_NAME);
  2653.     }
  2654.   }
  2655. }
  2656.  
  2657.  
  2658. int get_default_screen_dimension(long *width, long *height, short *lace)
  2659. {
  2660.   struct Screen hscr;
  2661.   struct Rectangle Rect;
  2662.   ULONG DisplayID;
  2663.   int res;
  2664.  
  2665.   if (is_os2) {
  2666.     if (!is_ownscr) {
  2667.       struct Screen *scr;
  2668.       scr = LockPubScreen(PubScreenName);
  2669.       if (scr == NULL) {
  2670.         Warning(MSG_CANT_FIND_SCR_USE_WB, PubScreenName);
  2671.         strcpy(PubScreenName, "Workbench");
  2672.         scr = LockPubScreen(PubScreenName);
  2673.         if (scr == NULL) {
  2674.           Fatal(15, MSG_CANT_LOCK_PBSCR);
  2675.         }
  2676.       }
  2677.       /* DisplayID = GetVPModeID(&(scr->ViewPort)); */
  2678.       *width = scr->Width;
  2679.       *height = scr->Height;
  2680.       *lace = (short)(scr->ViewPort.Modes & LACE);
  2681.       UnlockPubScreen(NULL, scr);
  2682.       res = TRUE;
  2683.     }
  2684.     else {    /* eigener Screen */
  2685.       DisplayID = get_DisplayID();
  2686.       res = QueryOverscan(DisplayID, &Rect, OSCAN_TEXT);
  2687.       if (res) {
  2688.         *width  = Rect.MaxX - Rect.MinX + 1;
  2689.         *height = Rect.MaxY - Rect.MinY + 1;
  2690.         *lace   = is_lace;
  2691.       }
  2692.     }
  2693.   }
  2694.   else {
  2695.     res = GetScreenData((char *)&hscr, (long)sizeof(hscr), (long)WBENCHSCREEN,
  2696.                 IntuitionBase->ActiveScreen);
  2697.     if (res) {
  2698.       *width  = hscr.Width;
  2699.       *height = hscr.Height;
  2700.       *lace   = (short)(hscr.ViewPort.Modes & LACE);
  2701.     }
  2702.   }
  2703.   return res;
  2704. }
  2705.  
  2706.  
  2707. static int get_screen_dimension(long *width, long *height, short *lace)
  2708. {
  2709.   int res;
  2710.  
  2711.   if (show_state.screen_size_x > 0 && show_state.screen_size_y > 0) {
  2712.     *width  = show_state.screen_size_x;
  2713.     *height = show_state.screen_size_y;
  2714.     *lace   = is_lace;
  2715.     res = TRUE;
  2716.   }
  2717.   else {
  2718.     res = get_default_screen_dimension(width, height, lace);
  2719.   }
  2720.   return (res);
  2721. }
  2722.  
  2723.  
  2724. static void set_resolution(void)
  2725. {
  2726.   long width, height;
  2727.   short was_lace;
  2728.  
  2729.   if (get_screen_dimension(&width, &height, &was_lace)) {
  2730.       if (!is_ownscr) {
  2731.         x_scr_width = width;
  2732.         x_scr_height = height;
  2733.       }
  2734.       else {
  2735.     x_scr_width = width;
  2736.     if (was_lace && is_lace) {
  2737.       x_scr_height = height;
  2738.     }
  2739.     else {
  2740.       if (was_lace) {
  2741.         x_scr_height = height/2;
  2742.       }
  2743.       else {
  2744.         if (is_lace) {
  2745.           x_scr_height = height*2;
  2746.         }
  2747.         else {
  2748.           x_scr_height = height;
  2749.         }
  2750.       }
  2751.     }
  2752.       }
  2753.   }
  2754.   else {                /* can't get screen-data ?? */
  2755.     x_scr_width  = NTSC_SCR_WIDTH;    /* minimal size */
  2756.     x_scr_height = NTSC_SCR_HEIGHT;
  2757.   }
  2758.  
  2759.   /* check fom minimal size */
  2760.   if (x_scr_width  < NTSC_SCR_WIDTH)  x_scr_width  = NTSC_SCR_WIDTH;
  2761.   if (x_scr_height < NTSC_SCR_HEIGHT) x_scr_height = NTSC_SCR_HEIGHT;
  2762.  
  2763.   if ((is_ownscr && show_state.window_size_own_scr_x == -1) || (!is_ownscr && show_state.window_size_x == -1)) {
  2764.     if (is_ownscr) {
  2765.       x_win_width  = x_scr_width  - ((show_state.window_pos_own_scr_x != -1) ? show_state.window_pos_own_scr_x : 0);
  2766.     } 
  2767.     else {
  2768.       x_win_width  = x_scr_width  - ((show_state.window_pos_x != -1) ? show_state.window_pos_x : 0);
  2769.     }
  2770.   }
  2771.   else {
  2772.     x_win_width  = (is_ownscr) ? show_state.window_size_own_scr_x : show_state.window_size_x;
  2773.   }
  2774.  
  2775.   if ((is_ownscr && show_state.window_size_own_scr_y == -1) || (!is_ownscr && show_state.window_size_y == -1)) {
  2776.     if (screen == NULL) {
  2777.       if (is_ownscr) {
  2778.         x_win_height = x_scr_height - ((show_state.window_pos_own_scr_y != -1) ? show_state.window_pos_own_scr_y : 0);
  2779.             /* der Rest wird spaeter in OpenS() gemacht */
  2780.       }
  2781.       else {
  2782.         x_win_height = x_scr_height - ((show_state.window_pos_y != -1) ? show_state.window_pos_y : 0);
  2783.       }
  2784.     }
  2785.     else {
  2786.       x_win_height = x_scr_height - HeightScreenTitle;
  2787.     }
  2788.   }
  2789.   else {
  2790.     x_win_height  = (is_ownscr) ? show_state.window_size_own_scr_y : show_state.window_size_y;
  2791.   }
  2792. }
  2793.  
  2794.  
  2795. static void set_i_window_size(void)
  2796. {
  2797.   const long c_winiw = win2->Width - win2->BorderLeft - win2->BorderRight;
  2798.   const long c_winih = win2->Height - win2->BorderTop - win2->BorderBottom;
  2799.  
  2800.   if (winiw > wx) {
  2801.     Page_LeftPoint    = win2->BorderLeft + (c_winiw-wx) / 2;
  2802.     Page_RightPoint   = Page_LeftPoint + wx - 1;
  2803.   }
  2804.   else {
  2805.     Page_LeftPoint    = win2->BorderLeft;
  2806.     Page_RightPoint   = win2->Width - win2->BorderRight - 1;    // ??
  2807.   }
  2808.  
  2809.   if (winih > wy) {
  2810.     Page_TopPoint     = win2->BorderTop  + (c_winih-wy) / 2;
  2811.     Page_BottomPoint  = Page_TopPoint + wy -1;
  2812.   }
  2813.   else {
  2814.     Page_TopPoint     = win2->BorderTop;
  2815.     Page_BottomPoint  = win2->Height - win2->BorderBottom - 1;    // ??
  2816.   }
  2817.   
  2818.   x_win_i_width  = c_winiw;
  2819.   x_win_i_height = c_winih;
  2820. }
  2821.  
  2822.  
  2823. #if 0    /* wird nicht mehr gebraucht */
  2824. void ChangeScreenSize(short new_width, short new_height)
  2825. {
  2826.   show_state.screen_size_x = new_width;
  2827.   show_state.screen_size_y = new_height;
  2828.   CloseOpenScreen(FALSE, FALSE, TRUE);
  2829. }
  2830. #endif
  2831.  
  2832.  
  2833. void CloseOpenScreen(int change_lace, int change_color, int change_size)
  2834. {
  2835.   int was_about, was_messwin, was_fullpage, was_prefwin, was_pscro, was_searchwin;
  2836.   short messX, messY;
  2837.  
  2838.   was_about = was_messwin = was_fullpage = was_prefwin = was_pscro = was_searchwin = FALSE;
  2839.  
  2840.   if (is_about) {
  2841.     AboutWinDown();    /* das ist schliesslich auch ein Window */
  2842.     was_about = TRUE;
  2843.   }
  2844.   if (is_messwin) {
  2845.     /* falls nur die Farben geaendert werden, alte Pos. beibehalten */
  2846.     CloseMessWin();
  2847.     messX = MessWinXpos;    /* merke die alte Position */
  2848.     messY = MessWinYpos;
  2849.     was_messwin = TRUE;
  2850.   }
  2851.   
  2852.   if (SearchWin) {
  2853.     CloseSearchWin();
  2854.     was_searchwin = TRUE;
  2855.   }
  2856.   
  2857.   if (is_prefwin) {
  2858.     ClosePrefWin();
  2859.     was_prefwin = TRUE;
  2860.   }
  2861.   
  2862.   if (is_show) {
  2863.     was_fullpage = TRUE;
  2864.     show_full_page(TRUE);    /* aus (no_refresh == TRUE) */
  2865.   }
  2866.  
  2867.   if (!can_i_exit()) {        // testet die Windows, vertreibt SpecialHost und macht Msg.
  2868.     return;
  2869.   }
  2870.  
  2871.   if (screen!=NULL) {
  2872. #if !defined(REQ_LIBRARY)
  2873.     remove_col_request();
  2874. #endif
  2875.     AboutWinDown();
  2876.     CloseWin2();
  2877.     CloseS();
  2878.   }
  2879.  
  2880.  
  2881.   if (change_lace) {
  2882.     toggle_lace;
  2883.   }
  2884.   if (change_color) {
  2885.     toggle_col4;
  2886.   }
  2887.   if (change_size) {
  2888.     //free_images();
  2889.   }
  2890.  
  2891.  
  2892.   set_resolution();
  2893.   
  2894.   if (change_size) {
  2895.     //init_images();
  2896.   }
  2897.  
  2898.  
  2899.   IsScreenReOpend = TRUE;
  2900.  
  2901.   OpenS();
  2902.   
  2903.  
  2904.   /*
  2905.    * Nun, wenn der Screen ein Village-Screen ist und wenn die Bitmap in Chip ist,
  2906.    * dann muss nach Fast umkopiert werden.
  2907.    * Wenn der Screen kein village-Screen ist, und die Bitmap in Fast ist,
  2908.    * dann muss nach Chip kopiert werden.
  2909.    * Ausser, wenn ohnehin per CPU kopiert werden soll.
  2910.    */
  2911.  
  2912.   if (is_bmfast && !is_village) {
  2913.     set_bmcpu;
  2914.     set_scrollras;
  2915.   }
  2916.  
  2917. #if 0   
  2918.   /*
  2919.    * ACHTUNG!!
  2920.    *
  2921.    * Das funktioniert noch nicht, wenn ich von Chip nach Fast oder umgekehrt wechsle,
  2922.    * dann geht das Bild floeten. Erst nach einem zusaetzlichen Aufloesungsswitch ist
  2923.    * es wieder da!
  2924.    *
  2925.    */
  2926.  
  2927.   if ((is_village && !is_bmfast) || (!is_village && is_bmfast && !is_bmcpu)) {
  2928.     struct BitMap OldBitMapWin = BitMapWin;
  2929.     unsigned long BytesToCopy = BitMapWin.BytesPerRow * BitMapWin.Rows;
  2930.     
  2931.     D(bug("vor  OpenRP vill: %ld, bmfast: %ld, bmcpu: %ld\n", is_village, is_bmfast, is_bmcpu));
  2932.  
  2933.     /*
  2934.      * Wenn village, dann oeffnet OpenRastPort() im Fast, ansonsten in Chip.    
  2935.      */
  2936.     OpenRastPort();
  2937.     
  2938.     D(bug("nach OpenRP vill: %ld, bmfast: %ld, bmcpu: %ld\n", is_village, is_bmfast, is_bmcpu));
  2939.  
  2940.     if (!BitMapWin.Planes[0]) Fatal(10, MSG_CANT_ALLOC_BITMAP);
  2941.  
  2942.     if (BytesToCopy & 3) {
  2943.       CopyMem(OldBitMapWin.Planes[0], BitMapWin.Planes[0], BytesToCopy);
  2944.     }
  2945.     else {
  2946.       CopyMemQuick(OldBitMapWin.Planes[0], BitMapWin.Planes[0], BytesToCopy);
  2947.     }
  2948.     
  2949.     D(bug("kopiere die Plane, bmfast ist nun: %ld\n", is_bmfast));
  2950.  
  2951. /*
  2952.  *     Achtung: Das zurueck kopieren geht nicht...liegt moeglicherweise an DOMINO!!!!!
  2953.  */
  2954.  
  2955.     /*
  2956.      *  Wenn nun bmfast, dann war's vorher Chip...
  2957.      */
  2958.     if (is_bmfast) {
  2959.       FreeRaster(OldBitMapWin.Planes[0],wx,wy);
  2960.     }
  2961.     else {
  2962.       FreeMem(OldBitMapWin.Planes[0], (wx+7)/8*wy);
  2963.     }
  2964.   }
  2965. #endif
  2966.  
  2967.  
  2968.  
  2969.   OpenWin2();
  2970.   set_i_window_size();
  2971.   init_gad();
  2972.  
  2973.   Add_system_gadgets();
  2974.  
  2975.   Set_PgPotGadRange();
  2976.   Set_PgGadPageCur();
  2977.  
  2978.   if (is_gadg) {
  2979. #if 0
  2980.     /*
  2981.      * Pot/Body werden schon in init_gad gesetzt
  2982.      */
  2983.     if (!is_pscro) {
  2984.           const long winih = win2->Height - win2->BorderTop - win2->BorderBottom - 1;
  2985.       //i = (int)((winih * (long)(poty_Gad.UserData)) / (long)wy);
  2986.       //poty_Image_1.Height = (SHORT)i;
  2987.       //poty_Image_2.Height = (SHORT)i;
  2988.       poty_PropInfo.VertPot =
  2989.        (USHORT)(((long)(static_y_Koo)<<16)/(wy-winih+1L));
  2990.       poty_PropInfo.VertBody = (USHORT)((long)((long)MAXBODY * winih)/(long)wy);
  2991.       //set_zahl((int)999);    /* setzt die Images */
  2992.     }
  2993. #endif
  2994.     Add_scroll_gadgets(FALSE);    /* no_refresh == FALSE */
  2995.   }
  2996.   
  2997.   /* setup the things */
  2998.   write_status();
  2999.  
  3000. #if 0
  3001.   if (is_pscro) {
  3002.     AddGadget(win2, &pgscroll_ok_Gad, PGSCROLL_OK_GAD_NR);
  3003.     AddGadget(win2, &pgscroll_no_Gad, PGSCROLL_NO_GAD_NR);
  3004.     /* i = (int)(poty_Gad.Height / max_page_number); */
  3005.     i = (int)((int)poty_Gad.UserData / max_page_number);
  3006.     if (max_page_number <100) {
  3007.       if (i<24) i=24;
  3008.     }
  3009.     else {
  3010.       if (i<35) i=35;
  3011.     }
  3012.     poty_Image_1.Height = (SHORT)i;
  3013.     poty_Image_2.Height = (SHORT)i;
  3014.     if (max_page_number == 0) Fatal(20,MSG_INTERNAL_ERROR);
  3015.     poty_PropInfo.VertPot = (USHORT)page_to_pot(current_page);
  3016.     poty_PropInfo.VertBody = (USHORT)(MAXBODY/max_page_number-1);
  3017.     set_zahl((int)current_page);
  3018.   }
  3019. #endif
  3020.   /* RefreshGadgets(&first_Page_Gad,win2,NULL); */
  3021.  
  3022.   refresh_screen();
  3023.   if (is_gadg) {        /* setzt die Grenzen richtig */
  3024.     window_plus_sbar_move(0,0);
  3025.   }
  3026.   else {
  3027.     window_move(0,0);
  3028.   }
  3029.   window_show();
  3030.   
  3031.   if (was_fullpage) {
  3032.     show_full_page(TRUE);
  3033.   }
  3034.   
  3035.   if (was_searchwin) {
  3036.     OpenSearchWin();
  3037.   }
  3038.   
  3039.   if (was_about) {
  3040.     AboutWinUp();
  3041.   }
  3042.   if (was_messwin) {
  3043.     if (!change_lace) {
  3044.       MessWinXpos = messX;    /* alte Position zurueck */
  3045.       MessWinYpos = messY;
  3046.       /* eigentlich muesste nur die Y-Pos restored werden */
  3047.     }
  3048.     OpenMessWin();
  3049.   }
  3050.   if (was_prefwin) {
  3051.     OpenPrefWin();
  3052.   }
  3053.  
  3054.   /* setze os_menu richtig */
  3055.   set_checked_os_menu();
  3056.   
  3057.   { long width, height;
  3058.     short lace;
  3059.     if (get_default_screen_dimension(&width, &height, &lace)) {
  3060.       if (width == show_state.screen_size_x && height == show_state.screen_size_y) {
  3061.         show_state.screen_size_x = 0;
  3062.         show_state.screen_size_y = 0;
  3063.       }
  3064.     }
  3065.   }
  3066. }
  3067.  
  3068.  
  3069. void ToggleColorDepth(void)
  3070. {
  3071.   CloseOpenScreen(FALSE, TRUE, FALSE);
  3072. }
  3073.  
  3074.  
  3075. void change_resolution(void)
  3076. {
  3077.   CloseOpenScreen(TRUE, FALSE, FALSE);
  3078. }
  3079.  
  3080.  
  3081. void toggle_scrollbar(int no_refresh)
  3082. {
  3083.   toggle_gadg;
  3084.   set_resolution();
  3085.   set_i_window_size();
  3086.  
  3087.   if (is_gadg) {
  3088.     init_gad();
  3089.     Add_scroll_gadgets(no_refresh);
  3090.   }
  3091.   else {
  3092. #if 0
  3093.     if (is_pscro) {
  3094.       long dummy;
  3095.       blatt_ok_gad(&dummy);
  3096.       unset_tusephy; /* wird leider von der blatt_ok_gad Funktion gesetzt */
  3097.     }
  3098. #endif
  3099.     Remove_scroll_gadgets(no_refresh);
  3100. #if 0
  3101.     /* und nun bei col4 muessen noch die Ueberreste geloescht werden, fuer den Fall, dass   */
  3102.     /* die Bitmap groesser wird. Fall einmal die Fenstergroesse mit geaendert wird, so wird */
  3103.     /* das nicht mehr benoetigt.                                  */
  3104.     fill_block(potx_Gad.LeftEdge, potx_Gad.TopEdge,
  3105.         2*potx_left_Gad.Width+potx_Gad.Width, potx_Gad.Height, 0);
  3106.     fill_block(poty_up2_Gad.LeftEdge, poty_up2_Gad.TopEdge, poty_up2_Gad.Width,
  3107.         4*poty_up2_Gad.Height+poty_Gad.Height, 0);
  3108.  
  3109.     RefreshWindowFrame(win2);    /* flacker flacker.. naja aber sonst ist der Rahmen weg */
  3110. #endif
  3111.     
  3112.     {
  3113.       // nun Koo. neu setzen...dabei Grenzen beachten
  3114. #if 0
  3115.       const long winiw = win2->Width - win2->BorderLeft - win2->BorderRight;
  3116.       const long winih = win2->Height - win2->BorderTop - win2->BorderBottom;
  3117. #endif
  3118.  
  3119.       if (wx < winiw) static_x_Koo = 0;
  3120.       else if (static_x_Koo + winiw > wx) static_x_Koo = wx - winiw;
  3121.       if (wy < winih) static_y_Koo = 0;
  3122.       else if (static_y_Koo + winih > wy) static_y_Koo = wy - winih;
  3123.     }
  3124.   }
  3125.  
  3126.   if (!no_refresh) {
  3127.     RefreshWindowFrame(win2);
  3128.     //refresh_screen();
  3129.     window_show();
  3130.   }
  3131.  
  3132.   /* setze os_menu richtig */
  3133.   set_checked_os_menu();
  3134. }
  3135.  
  3136.  
  3137.  
  3138.  
  3139. /*********************    F U L L   P A G E    **********************/
  3140.  
  3141.  
  3142. #define FPAGE_ABS HeightWinTitle
  3143.  
  3144.  
  3145. void display_full_page(void)
  3146. {
  3147.   /* kopiere die FullPage in den Window-Rastport */
  3148.  
  3149.   MySetABPenDrMd(win2->RPort, show_state.APen, (is_bhook) ? show_state.BPen : 0, JAM2);
  3150.   BltTemplate(RastPortFullPage.BitMap->Planes[0], 0,
  3151.         RastPortFullPage.BitMap->BytesPerRow, win2->RPort, FullPageLeftEdge, FullPageTopEdge, FullPageWidth, FullPageHeight);
  3152.  
  3153. #ifdef OLD_BLIT
  3154.   if (is_bhook) {
  3155.     SafeSetWriteMask(win2->RPort, 0x02);
  3156.     ClipBlit(&RastPortFullPage, 0, 0, win2->RPort, FullPageLeftEdge, FullPageTopEdge, FullPageWidth, FullPageHeight, 0x30);
  3157.   }
  3158.   SafeSetWriteMask(win2->RPort, 0x01);
  3159.   ClipBlit(&RastPortFullPage, 0, 0, win2->RPort, FullPageLeftEdge, FullPageTopEdge, FullPageWidth, FullPageHeight, 0xC0);
  3160.   SafeSetWriteMask(win2->RPort, 0xff);
  3161. #endif
  3162.  
  3163. #if 0
  3164.   // alt, ohne black-white
  3165.   ClipBlit(&RastPortFullPage,0,0,win2->RPort,FullPageLeftEdge,FullPageTopEdge,FullPageWidth,FullPageHeight,192);
  3166. #endif
  3167.  
  3168.   if (is_dotbord) {
  3169.     DrawDottedBorder(FALSE, TRUE);    /* nun wieder Border zeichnen */
  3170.   }
  3171. }
  3172.  
  3173.  
  3174. void show_full_page(int no_refresh)
  3175. {
  3176.   register struct RastPort *rp;
  3177.   int p_width, p_height;
  3178.   float x;
  3179.   static int war_gadg;
  3180.   long xk, yk;
  3181.   short vis_width, vis_height;            /* soviel ist sichtbar */
  3182.   short max_show_width, max_show_height;    /* soviel kann maximal verwendet werden */
  3183.   /* wenn nicht alles sichtbar, bewege ich den Screen ganz nach links oben!! */
  3184.  
  3185.  
  3186.   if (!is_show) {
  3187.     set_show;
  3188.     write_status();
  3189.     sleep_pointer();
  3190.  
  3191.     if (is_gadg /* && wx > x_win_i_width */) {    /* dazu muessten die SBar's disabeld werden! */
  3192.        toggle_scrollbar(no_refresh);    /* SBar ausschalten */
  3193.        //toggle_scrollbar(TRUE);        /* SBar ausschalten */
  3194.        // Beim Scroll-Bar ausschalten auf keinen Fall einen Refresh machen!
  3195.        war_gadg=TRUE;
  3196.     }
  3197.     else {
  3198.        war_gadg=FALSE;
  3199.     }
  3200.     if (is_dotbord) {
  3201.       unset_show;
  3202.       DrawDottedBorder(FALSE, TRUE);    /* toggle = FALSE (ausschalten aber is_ lassen) */
  3203.       set_show;
  3204.     }
  3205.  
  3206.  
  3207.         vis_width  = screen->Width+1;        // das ergibt 801 (bei screenw 800) (siehe unten)
  3208.         vis_height = screen->Height+1;
  3209.  
  3210.         if (is_os2) {
  3211.           if (is_village && !is_ownscr) {
  3212.             // Wir sind auf der Graphikkarte
  3213.             // vis_* stimmt mit dem des Screens ueberein
  3214.             //printf("beep\n");
  3215.           }
  3216.           else {
  3217.             struct ViewPort *vp;
  3218.             ULONG modeID;
  3219.             struct DimensionInfo DimInfo;
  3220.             
  3221.             vp = &(screen->ViewPort);
  3222.             if ((modeID = GetVPModeID(vp)) != INVALID_ID) {
  3223.               GetDisplayInfoData(NULL, (UBYTE *)&DimInfo, sizeof(DimInfo), DTAG_DIMS, modeID);
  3224.               vis_width  = DimInfo.TxtOScan.MaxX + 1;    // das ergibt nun nur 800!! (siehe oben)
  3225.               vis_height = DimInfo.TxtOScan.MaxY + 1;
  3226.             }
  3227.           }
  3228.         }
  3229.         
  3230.     FullPageScreenXPos = 0;
  3231.     FullPageScreenYPos = 0;
  3232.         if (is_os2 && show_state.screen_size_x != 0) {
  3233.           /* ich setze den Screen IMMER ganz nach links oben! */
  3234.       FullPageScreenXPos = screen->LeftEdge;
  3235.       FullPageScreenYPos = screen->TopEdge;
  3236.           MoveScreen(screen, -screen->LeftEdge, -screen->TopEdge);
  3237.         }
  3238.         
  3239.  
  3240.         {
  3241. #if 0
  3242.           const long winiw = win2->Width - win2->BorderLeft - win2->BorderRight;
  3243.           const long winih = win2->Height - win2->BorderTop - win2->BorderBottom;
  3244. #endif
  3245.  
  3246.           if (winiw < vis_width-width_left_border) {
  3247.             max_show_width = winiw;
  3248.           }
  3249.           else {
  3250.             max_show_width = vis_width-width_left_border;
  3251.           }
  3252.           if (winih < vis_height-HeightWinTitle-HeightScreenTitle) {
  3253.             max_show_height = winih;
  3254.           }
  3255.           else {
  3256.             max_show_height = vis_height-HeightWinTitle-HeightScreenTitle;
  3257.           }
  3258.           
  3259.           if (max_show_width > wx)  max_show_width  = wx;
  3260.           if (max_show_height > wy) max_show_height = wy;
  3261.         }
  3262.  
  3263.  
  3264.     p_height = max_show_height - (FPAGE_ABS * 2);
  3265.  
  3266.     /* eine erste Vorberechnung, dient nur zur Bestimmung von p_height */
  3267.     x = (float)p_height/(float)wy;
  3268.     p_width = (int)((float)wx * x);
  3269.  
  3270.     D(bug("full-screen: is_lace: %ld, is_numeric: %ld\n", is_lace, is_numeric));
  3271.  
  3272. #ifdef UEBERKRAMPF
  3273.  
  3274.     // wozu bittesehr wird hier p_WIDTH verwendet??
  3275.     p_width = (is_lace) ? p_width : p_width * 2;
  3276.  
  3277.     if (p_width >= max_show_width) {
  3278.       p_width = max_show_width - (FPAGE_ABS * 2);
  3279.       x = (float)p_width/(float)wx;
  3280.       p_height = (int)((float)wy*x);
  3281.     }
  3282. #endif
  3283.     
  3284.     /* correct aspect ratio */
  3285.     {
  3286.  
  3287.     /*
  3288.          *            scr_width    /  scr_height
  3289.      *  ratio =   ---------   /   ----------
  3290.          *              mon_x    /      mon_y
  3291.          *
  3292.          */
  3293.  
  3294.        const float ratio =
  3295.               ((float)show_state.monitor_size_y * (float)vis_width) /
  3296.              ((float)show_state.monitor_size_x * (float)vis_height);
  3297.  
  3298.        p_width = ((float)wx * (float)p_height / (float)wy) * ratio;
  3299.  
  3300.        /*
  3301.        printf("wx: %d, wy: %d, scr_h: %d, scr_w: %d, mon_x: %d, mon_y: %d\n", wx, wy,
  3302.         vis_height, vis_width, show_state.monitor_size_x, show_state.monitor_size_y);
  3303.        printf("p_h: %d, ratio: %f, p_width: %d\n", p_height, ratio, p_width);
  3304.        printf("Aspect orig: %f, Aspect small: %f\n", (float)wx/(float)wy, (float)p_width/(float)p_height);
  3305.        */
  3306.  
  3307.        if (p_width >= max_show_width) {
  3308.          p_width = max_show_width - (FPAGE_ABS * 2);
  3309.        }
  3310.     }
  3311.  
  3312.  
  3313.  
  3314.     xk = (max_show_width - p_width) / 2;
  3315.     yk = FPAGE_ABS-1+(max_show_height - p_height) / 2;
  3316.  
  3317.  
  3318.     rp  = win2->RPort;
  3319.  
  3320.         InitBitMap(&BitMapFullPage,7L,p_width,p_height);
  3321.         BitMapFullPage.Planes[0] = AllocRaster(p_width, p_height);
  3322.         if (BitMapFullPage.Planes[0] == NULL) {  
  3323.        Fatal(10,MSG_NO_CHIPMEM);
  3324.         }
  3325.  
  3326.         { int i;
  3327.           for (i=1; i<7; i++) {
  3328.             BitMapFullPage.Planes[i] = BitMapFullPage.Planes[0];
  3329.           }
  3330.           BitMapFullPage.Planes[7] = NULL;    // nur 7 Planes identisch, wg. PICASSO Treiber (chunky)
  3331.         }
  3332.  
  3333.         InitRastPort(&RastPortFullPage);
  3334.         RastPortFullPage.BitMap = &BitMapFullPage;
  3335.         SetRast(&RastPortFullPage,0);
  3336.         BitMapFullPageWidth  = p_width;
  3337.     BitMapFullPageHeight = p_height;
  3338.  
  3339. #if 0
  3340.     fpage_bytes = ((p_width+15)/16)*p_height*2;
  3341.     fpage = AllocMem(fpage_bytes,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  3342.     if (fpage == NULL) {
  3343.       Fatal(10,MSG_NO_CHIPMEM);
  3344.     }
  3345. #endif
  3346.  
  3347.     Message(MSG_BUILD_FULL_PAGE);
  3348.     make_full_page(rp, xk, yk, p_width, p_height, (unsigned short *)(BitMapFullPage.Planes[0]));
  3349.  
  3350.  
  3351.     /* loesche Bildschirm */
  3352.     {
  3353. #if 0
  3354.           const long winiw = win2->Width - win2->BorderLeft - win2->BorderRight;
  3355.           const long winih = win2->Height - win2->BorderTop - win2->BorderBottom;
  3356. #endif
  3357.       fill_block(width_left_border, HeightWinTitle, winiw-1, winih-1, 0);
  3358.     }
  3359.     /* SBars sind schon aus => innere Groese muesste reichen zu loeschen */
  3360.  
  3361.  
  3362.     /* wird fuer das Mess-Window benoetigt */
  3363.       FullPageLeftEdge = xk;
  3364.       FullPageTopEdge  = yk;
  3365.       FullPageWidth      = p_width;
  3366.       FullPageHeight     = p_height;
  3367.  
  3368.  
  3369.     if (!no_refresh) {
  3370.       /* und nun wird die Bitmap einkopiert... */
  3371.       display_full_page();
  3372.       }
  3373.     
  3374.     clear_pointer();
  3375.     MessageStr(NULL);
  3376.   }
  3377.   else
  3378.   {
  3379.         if (BitMapFullPage.Planes[0] != NULL) {
  3380.           FreeRaster(BitMapFullPage.Planes[0], BitMapFullPageWidth, BitMapFullPageHeight);
  3381.           BitMapFullPage.Planes[0] = NULL;
  3382.         }
  3383.     if (is_dotbord) {
  3384.       set_show;
  3385.       DrawDottedBorder(FALSE, no_refresh);    /* kein Toggle.. (loesche FullPage) */
  3386.       unset_show;
  3387.       DrawDottedBorder(FALSE, no_refresh);    /* kein Toggle.. (zeichne neu) */
  3388.     }
  3389.     unset_show;
  3390.  
  3391.         if (is_os2 && show_state.screen_size_x != 0 && screen->LeftEdge == 0 && screen->TopEdge == 0) {
  3392.           /* setzt den Screen wieder dahin zurueck, wo er war */
  3393.           MoveScreen(screen, FullPageScreenXPos, FullPageScreenYPos);
  3394.         }
  3395.  
  3396.     write_status();
  3397.     if (war_gadg) {
  3398.       toggle_scrollbar(no_refresh);
  3399.     }
  3400.     if (!no_refresh) {
  3401.           if (is_gadg) {        /* setzt die Grenzen richtig */
  3402.             window_plus_sbar_move(0,0);
  3403.           }
  3404.           else {
  3405.             window_move(0,0);
  3406.           }
  3407.       window_show();
  3408.     }
  3409.   }
  3410. }
  3411.  
  3412.  
  3413.  
  3414. void DrawDottedBorder(int toggle, int no_refresh)
  3415. {
  3416.   register struct RastPort *rp;
  3417.   long lx, ly, lxx, lyy;
  3418.   float widthin, heightin;    /* full width/height */
  3419.  
  3420.   if (toggle) {
  3421.     toggle_dotbord;
  3422.   }
  3423.  
  3424.   if (win2 != NULL) {
  3425.   
  3426.     widthin  = (float)pwidth_pt  / 72.27 + ((float)SAVETY_BITS_X / (float)hconvresolution) * 1000.0 / (float)mag;
  3427.     heightin = (float)pheight_pt / 72.27 + ((float)SAVETY_BITS_Y / (float)vconvresolution) * 1000.0 / (float)mag;
  3428.  
  3429.     if (is_show) {
  3430.  
  3431.       rp = win2->RPort;
  3432.       SetAPen(rp, 1);
  3433.       SetDrPt(rp, 0xAAAA);    // gfxmacros.h
  3434.       SetDrMd(rp, JAM1 | COMPLEMENT);
  3435.  
  3436.       lx  = (long)((float)(hoffset_in_fix * FullPageWidth) / widthin + 0.5);
  3437.       ly  = (long)((float)(voffset_in_fix * FullPageHeight) / heightin + 0.5);
  3438.       lxx = (long)((((float)pwidth_pt  / 72.27) * (float)FullPageWidth) / widthin + 0.5);
  3439.       lyy = (long)((((float)pheight_pt / 72.27) * (float)FullPageHeight) / heightin + 0.5);
  3440.  
  3441.       lx  = FullPageLeftEdge + lx;
  3442.       ly  = FullPageTopEdge + ly;
  3443.       lxx = FullPageLeftEdge + lxx;
  3444.       lyy = FullPageTopEdge + lyy;
  3445.  
  3446.       Move (rp, FullPageLeftEdge+1, ly+1);
  3447.       Draw (rp, FullPageLeftEdge+FullPageWidth-1, ly+1);
  3448.       Move (rp, FullPageLeftEdge+1, lyy-1);
  3449.       Draw (rp, FullPageLeftEdge+FullPageWidth-1, lyy-1);
  3450.       
  3451.       Move (rp, lx+1, FullPageTopEdge+1);
  3452.       Draw (rp, lx+1, FullPageTopEdge+FullPageHeight-2);
  3453.       Move (rp, lxx-1, FullPageTopEdge+1);
  3454.       Draw (rp, lxx-1, FullPageTopEdge+FullPageHeight-2);
  3455.  
  3456.       SetDrMd(rp, JAM1);
  3457.       SetDrPt(rp, 0xFFFF);    // gfxmacros.h
  3458.     }
  3459.     else {
  3460.       float MessWinSavetyX = (((float)SAVETY_BITS_X / (float)hconvresolution) * 1000.0 / mag) * 72.27 ;
  3461.       float MessWinSavetyY = (((float)SAVETY_BITS_Y / (float)vconvresolution) * 1000.0 / mag) * 72.27 ;
  3462.  
  3463.       rp = &myRastPort;
  3464.  
  3465.       SafeSetWriteMask(rp, 0x01);
  3466.  
  3467.       if (resolution < 85) {
  3468.         SetDrPt(rp, 0xAAAA);    // gfxmacros.h
  3469.       }
  3470.       else {
  3471.         SetDrPt(rp, 0x3030);    // gfxmacros.h
  3472.       }
  3473.       SetDrMd(rp, JAM1 | COMPLEMENT);
  3474.  
  3475.       lx = (long)((float)(hoffset_in_fix * wx) / widthin + 0.5);
  3476.       ly = (long)((float)(voffset_in_fix * wy) / heightin + 0.5);
  3477.       //lxx = (long)(((((float)pwidth_pt)  / 72.27) * (float)wx) / widthin + 0.5);
  3478.       //lyy = (long)(((((float)pheight_pt) / 72.27) * (float)wy) / heightin + 0.5);
  3479.       lxx = paper_width;
  3480.       lyy = paper_height;
  3481.  
  3482.       Move (rp, 1, ly+1);
  3483.       Draw (rp, wx-1, ly+1);
  3484.       Move (rp, 1, lyy-1);
  3485.       Draw (rp, wx-1, lyy-1);
  3486.       
  3487.       Move (rp, lx+1, 1);
  3488.       Draw (rp, lx+1, wy-2);
  3489.       Move (rp, lxx-1, 1);
  3490.       Draw (rp, lxx-1, wy-2);
  3491.  
  3492.       if (!no_refresh) {
  3493.         window_show();
  3494.       }
  3495.       SetDrMd(rp, JAM1);
  3496.       SetDrPt(rp, 0xFFFF);    // gfxmacros.h
  3497.  
  3498.       SafeSetWriteMask(rp, 0xFF);
  3499.     }
  3500.  
  3501.     if (toggle) {
  3502.       set_checked_os_menu();    /* setze Menue korrekt */
  3503.     }
  3504.   }
  3505. }
  3506.  
  3507.  
  3508. /* liefert den Pfad zum file, falls file=="" dann Pfad des akt. Verz. */
  3509. void getdir(char *file, char *dir)
  3510. {
  3511.   BPTR lck = Lock(file, ACCESS_READ);
  3512.   __aligned struct FileInfoBlock fib;
  3513.  
  3514.   if (lck) {
  3515.     if (Examine(lck, &fib)) {
  3516.       if (NameFromLock(lck, dir, 199)) {
  3517.         if (fib.fib_DirEntryType > 0 && fib.fib_DirEntryType != ST_SOFTLINK) {
  3518.           // es ist schon ein Directory, also unveraendert uebergeben
  3519.         }
  3520.         else {
  3521.           // weg mit dem File Part
  3522.           *FilePart(dir) = '\0';
  3523.         }
  3524.       }
  3525.       else {
  3526.         *dir = '\0';    // keine Lust fuer Mords-Fehlermeldungen
  3527.       }
  3528.     }
  3529.     else {
  3530.       *dir = '\0';    // keine Lust fuer Mords-Fehlermeldungen
  3531.     }
  3532.     UnLock(lck);
  3533.   }
  3534.   else {
  3535.     FatalStr(20, "getdir: Can't lock file \"%s\"", file);
  3536.   }
  3537.  
  3538.  
  3539. #if 0
  3540.   BPTR lock, lock1;
  3541.   char strh[250], *h;
  3542.   struct FileInfoBlock *fib;
  3543.   struct Process *pr;
  3544.  
  3545.  
  3546.   if (*file == '\0') {
  3547.     pr = (struct Process *)FindTask(NULL);
  3548.     if (pr->pr_CurrentDir == NULL) {
  3549.       strcpy(dir,"SYS:");
  3550.       return;
  3551.     }
  3552.     else {
  3553.       lock = DupLock(pr->pr_CurrentDir);
  3554.     }
  3555.   }
  3556.   else {
  3557.     lock = Lock(file,ACCESS_READ);
  3558.   }
  3559.  
  3560.   if (lock==(BPTR)NULL) {
  3561.      Fatal(5,"can't find file \"%s\" to examine!",file);
  3562.   }
  3563.  
  3564.   fib = (struct FileInfoBlock *)xmalloc((unsigned)sizeof(struct FileInfoBlock));
  3565.  
  3566.   dir[0]='\0';
  3567.   if (Examine(lock,fib) == 0) {
  3568.     Fatal(5,"can't examine file!");
  3569.   }
  3570.  
  3571.   if (file[0] == '\0' || fib->fib_DirEntryType > 0 ) {    /* aktuelles Verz. oder Dir.*/
  3572.      strcpy(dir, fib->fib_FileName);
  3573.      strcat(dir,"/");
  3574.   }
  3575.   lock1 = ParentDir(lock);
  3576.   UnLock((BPTR)lock);
  3577.   lock = lock1;
  3578.   while (lock!=(BPTR)NULL)
  3579.    {
  3580.     if (Examine(lock,fib)==0) {
  3581.        Fatal(5,"can't examine file!");
  3582.     }
  3583.     else {
  3584.        strcpy(strh,fib->fib_FileName);
  3585.        strcat(strh,"/");
  3586.        strcat(strh,dir);
  3587.        strcpy(dir,strh);
  3588.     }
  3589.     lock1 = ParentDir(lock);
  3590.     UnLock((BPTR)lock);
  3591.     lock = lock1;
  3592.    }
  3593.   h = strchr(dir,'/');
  3594.   if (h != NULL) {
  3595.     h[0] = ':';
  3596.   }
  3597.   xfree((char *)fib);
  3598. #endif
  3599. }
  3600.  
  3601. int is_dir(char *file)
  3602. {
  3603.   BPTR lck = Lock(file, ACCESS_READ);
  3604.   __aligned struct FileInfoBlock fib;
  3605.   int ret = FALSE;
  3606.  
  3607.   if (lck) {
  3608.     if (Examine(lck, &fib)) {
  3609.       ret = fib.fib_DirEntryType > 0 && fib.fib_DirEntryType != ST_SOFTLINK;
  3610.     }
  3611.     UnLock(lck);
  3612.   }
  3613.   return ret;
  3614.  
  3615. #if 0
  3616.   struct FileLock *lock;
  3617.   struct FileInfoBlock *fib;
  3618.   int is = FALSE;
  3619.  
  3620.   fib = (struct FileInfoBlock *)xmalloc((unsigned)sizeof(struct FileInfoBlock));
  3621.   lock = (struct FileLock *)Lock(file,ACCESS_READ);
  3622.  
  3623.   if (lock!=NULL) {
  3624.     if (Examine((BPTR)lock,fib)!=0) {
  3625.       if (fib->fib_DirEntryType>0) {
  3626.         is = TRUE;
  3627.       }
  3628.     }
  3629.     UnLock((BPTR)lock);
  3630.   }
  3631.   xfree((char *)fib);
  3632.   return (is);
  3633. #endif
  3634. }
  3635.  
  3636.  
  3637.  
  3638. void SavePageIFF(char * name)
  3639. {
  3640.   int clip;
  3641.   int mode;
  3642.  
  3643.   clip = *name == 'C' && name[1] == 'L' && name[2] == 'I' && name[3] == 'P';
  3644.  
  3645.   memset(&ilbm, 0, sizeof(ilbm));
  3646.   ilbm.ParseInfo.iff = AllocIFF();
  3647.   if (!ilbm.ParseInfo.iff) {
  3648.     Fatal(10, MSG_NO_MEM);
  3649.   }
  3650.   
  3651.   mode = GetVPModeID(&(screen->ViewPort));
  3652.   if (saveilbm(&ilbm, myRastPort.BitMap, mode,
  3653.         wx, wy, wx, wy, bw_ctable, 2, 4, 0, 0, NULL, NULL, name)) {
  3654.     if (clip) Warning( MSG_CANT_SAVE_TO_CLIP);
  3655.     else      Warning( MSG_CANT_SAVE_TO_IFF, name);
  3656.   }
  3657.   FreeIFF(ilbm.ParseInfo.iff);
  3658. }
  3659.  
  3660.  
  3661.  
  3662. int is_newer_dvi_file(void)        /* kein static! (arexx.c) */
  3663. {
  3664.   static struct DateStamp date_cur_file;
  3665.   struct FileLock *lock;
  3666.   __aligned struct FileInfoBlock fib;
  3667.   int ret = FALSE;
  3668.  
  3669.   if (is_new_dvifile) {
  3670.     is_new_dvifile = FALSE;
  3671.     date_cur_file.ds_Days   = MAXINT;
  3672.     date_cur_file.ds_Minute = MAXINT;
  3673.     date_cur_file.ds_Tick   = MAXINT;
  3674.   }
  3675.  
  3676.   lock =  (struct FileLock *)Lock(filename,ACCESS_READ);
  3677.  
  3678.   if (lock != NULL) {
  3679.     if (Examine((BPTR)lock, &fib)!=0) {
  3680.           ret = (CompareDates(&date_cur_file, &(fib.fib_Date)) > 0);
  3681.     }
  3682.     date_cur_file = fib.fib_Date;    /* zyklische Zuweisung. Passt nach dem ersten Mal */
  3683.     UnLock((BPTR)lock);
  3684.   }
  3685.   return ret;
  3686. }
  3687.  
  3688.  
  3689. /* Initialisiere Notify auf das aktuelle DVI File */
  3690. static int InitDVINotify(void)
  3691. {
  3692.   int suc;
  3693.   char fehler[62];
  3694.  
  3695.   if (DOSBase->dl_lib.lib_Version < 37L) {    /* notify mach ich erst ab Version 37.x */
  3696.     return FALSE;
  3697.   }
  3698.   if (is_notify) {    /* falls schon ein Notify laeuft, wird dies erst beendet */
  3699.     EndDVINotify();
  3700.   }
  3701.   if (!is_autoag) {    /* wenn kein autoag -> dann auch kein notify */
  3702.     return FALSE;
  3703.   }
  3704.  
  3705.   sig_notify = AllocSignal(-1);
  3706.   if (sig_notify == -1) {
  3707.     Warning(MSG_NO_SIGNAL);
  3708.     return FALSE;
  3709.   }
  3710.  
  3711.   notify.nr_Name = filename;
  3712.   notify.nr_FullName = NULL;
  3713.   notify.nr_UserData = NULL;
  3714.   notify.nr_Flags = NRF_SEND_SIGNAL;     /* | NRF_NOTIFY_INITIAL; */
  3715.   notify.nr_stuff.nr_Signal.nr_Task = FindTask(NULL);
  3716.   notify.nr_stuff.nr_Signal.nr_SignalNum = sig_notify;
  3717.  
  3718.   suc = StartNotify(¬ify);
  3719.   if (suc != DOSTRUE) {
  3720.     if (Fault(IoErr(), "Error", fehler, 61)) {
  3721.       WarningStr(fehler);
  3722.       //MySimpleRequest(1, NULL, NULL, NULL, NULL, GetTeXString(MSG_CANT_NOTIFY), filename, fehler);
  3723.     }
  3724.     return FALSE;
  3725.   }
  3726.   set_notify;
  3727.   return TRUE;
  3728. }
  3729.  
  3730. /* Beende Notify */
  3731. static int EndDVINotify(void)
  3732. {
  3733.   if (is_os2) {
  3734.     if (is_notify) {
  3735.       EndNotify(¬ify);
  3736.     }
  3737.     if (sig_notify > 0) {
  3738.       FreeSignal(sig_notify);
  3739.     }
  3740.     unset_notify;
  3741.     return TRUE;
  3742.   }
  3743.   return FALSE;
  3744. }
  3745.  
  3746. void ToggleAutoAgain(void)
  3747. {
  3748.   toggle_autoag;
  3749.   if (!is_autoag) EndDVINotify();
  3750.   else InitDVINotify();
  3751. }
  3752.  
  3753.  
  3754.  
  3755.  
  3756. void set_Gadgets_to_fname(void)            /* KEIN static / kein refresh */
  3757. {
  3758. #if 0
  3759.   char fname[250], currentdir[250], *tptr;
  3760.  
  3761.   if (filename[0]=='\0') {  /* kein filename => kein Aendern der Gadgets noetig */
  3762.      return;
  3763.   }
  3764.   if (is_dir(filename)) {  /* nur ein Directory */
  3765.      strcpy((char *)((struct StringInfo *)(dir_Gad.SpecialInfo))->Buffer, filename);
  3766.      strcpy((char *)((struct StringInfo *)(dir_Gad.SpecialInfo))->UndoBuffer, filename);
  3767.      *((struct StringInfo *)(fil_Gad.SpecialInfo))->Buffer = (char)0;
  3768.      *((struct StringInfo *)(fil_Gad.SpecialInfo))->UndoBuffer = (char)0;
  3769.   }     
  3770.   else
  3771.   {
  3772.     strcpy(fname, filename);
  3773.     /* zuerst Extension abspalten */
  3774.     tptr = strrchr(fname, '.');
  3775.     if (tptr != NULL) {
  3776.        *tptr = (char)0;
  3777.     }
  3778.     /* nun noch Direct. abspalten */
  3779.     tptr = strrchr(fname, '/');
  3780.     if (tptr == NULL) {
  3781.        tptr = strrchr(fname, ':');
  3782.        if (tptr == NULL) {
  3783.          /* es exist. gar kein Direct. Teil */
  3784.          getdir("",currentdir);    /* path of the current dir */
  3785.          strcpy((char *)((struct StringInfo *)(dir_Gad.SpecialInfo))->Buffer, currentdir);
  3786.          strcpy((char *)((struct StringInfo *)(dir_Gad.SpecialInfo))->UndoBuffer, currentdir);
  3787.          strcpy((char *)((struct StringInfo *)(fil_Gad.SpecialInfo))->Buffer, fname);
  3788.          strcpy((char *)((struct StringInfo *)(fil_Gad.SpecialInfo))->UndoBuffer, fname);
  3789.        }
  3790.     }
  3791.     if (tptr != NULL) {
  3792.        strcpy((char *)((struct StringInfo *)(fil_Gad.SpecialInfo))->Buffer, tptr+1);
  3793.        strcpy((char *)((struct StringInfo *)(fil_Gad.SpecialInfo))->UndoBuffer, tptr+1);
  3794.        if (*tptr == '/') {
  3795.       *tptr = (char)0;
  3796.        }
  3797.        else {    /* Dir. Teil endet mit ':', soll erhalten bleiben */
  3798.       tptr++;
  3799.       *tptr = (char)0;
  3800.        }
  3801.        strcpy((char *)((struct StringInfo *)(dir_Gad.SpecialInfo))->Buffer, fname);
  3802.        strcpy((char *)((struct StringInfo *)(dir_Gad.SpecialInfo))->UndoBuffer, fname);
  3803.     }
  3804.   }
  3805.   /* NO refresh */
  3806. #endif
  3807. }
  3808.  
  3809.  
  3810. void set_int_gad()            /* KEIN static / KEIN refresh */
  3811. {
  3812. #if 0
  3813.   struct StringInfo *si;
  3814.   char *iBuf, *iuBuf;
  3815.   struct RastPort *rp;
  3816.   char str[8];
  3817.   long nr, len;
  3818.   long TopEdge;
  3819.   static long secundary = 0;
  3820.  
  3821.   si = (struct StringInfo *)int_Gad.SpecialInfo;    /* Seitennummer eintragen */
  3822.   iBuf = (char *)si->Buffer;
  3823.   iuBuf = (char *)si->UndoBuffer;
  3824.  
  3825.   rp = win2->RPort;
  3826.   TopEdge = (HeightWinTitle - rp->Font->tf_YSize) / 2;
  3827.  
  3828.   /* alte Zahl löschen */
  3829.   SetAPen(rp,1);
  3830.   if (secundary > 0) {
  3831.     SetDrMd(rp,COMPLEMENT);
  3832.     Move(rp, WR_SECUNDARY_LEFT,  TopEdge + rp->Font->tf_YSize);
  3833.     sprintf(str,"%d",secundary);
  3834.     len = strlen(str);
  3835.     if (len>4) {
  3836.        str[4] = (char)0;
  3837.     }
  3838.     Text(rp,str,(long)strlen(str));
  3839.     SetDrMd(rp, JAM1);
  3840.   }
  3841.   
  3842.   SetAPen(rp,0L);
  3843.  
  3844.   if (is_usephy) {
  3845.     sprintf(iBuf,"%d",current_page_phy);
  3846.     sprintf(iuBuf,"%d",current_page_phy);
  3847.     si->LongInt = (long)current_page_phy;
  3848.   }
  3849.   else {
  3850.     sprintf(iBuf,"%d",current_page);
  3851.     sprintf(iuBuf,"%d",current_page);
  3852.     si->LongInt = (long)current_page;
  3853.  
  3854.     if (win2 != NULL) {
  3855.       if ((nr = get_secundary(current_page_phy)) > 0) {
  3856.         Move(rp, WR_SECUNDARY_LEFT, TopEdge + rp->Font->tf_YSize);
  3857.         sprintf(str,"%d",nr);
  3858.         len = strlen(str);
  3859.         if (len>4) {
  3860.            str[4] = (char)0;
  3861.         }
  3862.         Text(rp,str,(long)strlen(str));
  3863.       }
  3864.       secundary = nr;
  3865.     }
  3866.   }
  3867. #endif
  3868. }
  3869.  
  3870. #if 0
  3871. static void page_scroll(int dx, int dy)
  3872. {
  3873.   long page;
  3874.  
  3875.   if (is_gadg) {
  3876.       if (dy != 0) {
  3877.       page = pot_to_page((long)poty_PropInfo.VertPot);
  3878.       switch (dy) {
  3879.         case -SCROLL_Y_NORM:
  3880.         case -SCROLL_Y_NORM_R:
  3881.         case -SCROLL_Y_NORM_R-1:        // im col4 Fall
  3882.         case -SCROLL_Y_SHIFT:
  3883.         case -SCROLL_Y_SHIFT_R:
  3884.            page--;
  3885.            if (page < 1) page = 1;
  3886.            break;
  3887.         case SCROLL_Y_NORM:
  3888.         case SCROLL_Y_NORM_R:
  3889.         case SCROLL_Y_NORM_R+1:            // im col4 Fall
  3890.         case SCROLL_Y_SHIFT:
  3891.         case SCROLL_Y_SHIFT_R:
  3892.            page++;
  3893.            if (page > max_page_number) page = max_page_number;
  3894.            break;
  3895.         default     :
  3896.            if (dy == -wy) {
  3897.              page = 1;
  3898.            }
  3899.            else if (dy == wy) {
  3900.                   page = max_page_number;
  3901.                 }
  3902.            break;
  3903.       }
  3904.       poty_PropInfo.VertPot = (USHORT)page_to_pot(page);
  3905.       set_zahl((int)page);
  3906.       ModifyYPot();
  3907.       /* RefreshGadgets(&poty_Gad,win2,NULL); */
  3908.       Delay(2);
  3909.     }
  3910.   }
  3911.  
  3912.   if (is_gadg) {
  3913.      window_plus_sbar_move(dx,0);
  3914.   }
  3915.   else {
  3916.      window_move(dx,0);
  3917.   }
  3918. }
  3919. #endif
  3920.  
  3921.  
  3922.  
  3923. static long work_with_main_app_win(void)
  3924. {
  3925.   struct AppMessage * msg;
  3926.   long ex = 0;
  3927.  
  3928.   while (ex == 0L && (msg = (struct AppMessage *)GetMsg(MainAppWinMsgPort)) != NULL) {
  3929.     if (msg->am_Type == MTYPE_APPWINDOW && msg->am_ID == 0) {
  3930.       int i;
  3931.       struct WBArg * arg = msg->am_ArgList;
  3932.  
  3933.       // bei mehreren Args such ich s lange, bis einmal ex != 0
  3934.       for (i=0; ex == 0 && i<msg->am_NumArgs; i++) {
  3935.         ex = CheckAppArgName(arg[i].wa_Name, arg[i].wa_Lock);
  3936.       }
  3937.     }
  3938.     ReplyMsg((struct Message *)msg);
  3939.   }
  3940.   
  3941.   if (ex != 0L) {
  3942.     OpenNewDVI(filename, FALSE);
  3943.     ScreenToFront(screen);
  3944.     make_show_active();
  3945.   }
  3946.  
  3947.   return ex;
  3948. }
  3949.  
  3950.  
  3951. static long intui_message(void)
  3952. {
  3953.   static long        current_gadget = -1;
  3954.  
  3955.   struct IntuiMessage     *msg;
  3956.   ULONG         msg_Class;
  3957.   UWORD            Code,Qualifier;
  3958.   long            ex = 0L, ret;
  3959.   UWORD            sel;
  3960.   struct MenuItem     *ItemAdr;
  3961.   WORD            MouseX, MouseY;
  3962.   WORD            IMouseX, IMouseY;    // aus IBase...ist aktueller
  3963.   ULONG            secs, mics;
  3964.   struct Gadget        *m_gad;
  3965.   int            is_mouse_moved = FALSE;
  3966.  
  3967.  
  3968.  
  3969.   while (ex == 0L && (msg = (struct IntuiMessage *)GetMsg(win2->UserPort)) != NULL) {
  3970.   
  3971.     struct IntuiMessage copy_msg = *msg;    // komplett kopieren!
  3972.  
  3973.     msg_Class  = msg->Class;
  3974.     Code    = msg->Code;
  3975.     MouseX  = msg->MouseX;
  3976.     MouseY  = msg->MouseY;
  3977.     IMouseX = IntuitionBase->MouseX-win2->LeftEdge;
  3978.     IMouseY = IntuitionBase->MouseY-win2->TopEdge;
  3979.     //D(bug("msgM X: %3ld, Y: %3ld, IntM: X: %3ld, Y: %3ld, DX: %3ld, DY: %3ld\n", 
  3980.     //    MouseX, MouseY, IMouseX, IMouseY, MouseX-IMouseX, MouseY-IMouseY));
  3981.     secs   = msg->Seconds;
  3982.     mics   = msg->Micros;
  3983.     m_gad  = (struct Gadget *)msg->IAddress;
  3984.     Qualifier = msg->Qualifier;
  3985.     
  3986.     if (msg_Class == IDCMP_MENUVERIFY) {
  3987.       if (Code == MENUHOT) {
  3988.         if (!is_osmenu && MouseY >= HeightWinTitle) {
  3989.           msg->Code = Code = MENUCANCEL;
  3990.         }
  3991.       }
  3992.     }
  3993.     
  3994.     ReplyMsg(&(msg->ExecMessage));
  3995.     msg = NULL;
  3996.  
  3997.  
  3998.     switch (msg_Class) {
  3999.       case IDCMP_INTUITICKS:
  4000.            if (timer_wait_ticks > 0) {
  4001.              timer_wait_ticks--;
  4002.              if (timer_wait_ticks == 0) {
  4003.                ULONG lck;
  4004.                sub_inticks;
  4005.                if (!is_inticks) {
  4006.                  MyModifyIDCMP(0L, IDCMP_INTUITICKS);
  4007.                }
  4008.                lck = LockIBase(0L);
  4009.                if (IntuitionBase->ActiveWindow == win2) {
  4010.                  UnlockIBase(lck);
  4011.                  MessageStr(NULL);        /* refresh title */
  4012.                  unset_titref;
  4013.                }
  4014.                else {
  4015.                  UnlockIBase(lck);
  4016.                  set_titref;        /* merken, dass zu refreshen ist */
  4017.                }
  4018.              }
  4019.            }
  4020.            if (current_gadget != -1) {    /* Scrollbar Bewegungen */
  4021.              follow_pot_gad(current_gadget);
  4022.            }
  4023.            if (MessWin != NULL) {
  4024.              WorkMessWin(MouseX, MouseY, FALSE, FALSE);
  4025.            }
  4026.            is_mouse_moved = FALSE;    /* update ist gerade erfolgt */
  4027.            break;
  4028.           case IDCMP_MENUVERIFY:
  4029.       case IDCMP_MOUSEBUTTONS: 
  4030.            if ((Code == MENUCANCEL) ||
  4031.                (Code == MENUDOWN && !is_osmenu) || 
  4032.                (Code == MIDDLEDOWN && is_midmenu)) {
  4033.              ret = show_menu(Code, MouseX, MouseY);
  4034.                     /* ret ==  0 normal        */
  4035.                     /* ret ==  5 no action     */
  4036.                     /* ret == -1 Seite zurueck */
  4037.                     /* ret ==  1 Seite vor     */
  4038.                     /* ret == -2 Textanfang    */
  4039.                     /* ret ==  2 Textende      */
  4040.                     /* ret == 10 Programmende  */
  4041.                     /* ret ==  3 neues DVI-F.  */
  4042.                      if ((ret != 0)&&(ret != 5)) {
  4043.                        ex = KOMM+(long)ret;
  4044.                        /** warum beim Menu immer nach oben springen ??? 
  4045.                        if (ret == -1 || ret == 1 || ret == -2 || ret == 2) {
  4046.                          static_y_Koo = 0;
  4047.                        }
  4048.                        **/
  4049.                      }    
  4050.                      else {
  4051.                        if (ret == 0) {
  4052.              if (is_pscro) {
  4053.                //page_scroll(0,0);
  4054.              }
  4055.              else {
  4056.                if (is_gadg) {    /* setzt die Grenzen richtig */
  4057.                  window_plus_sbar_move(0,0);
  4058.                }
  4059.                else {
  4060.                  window_move(0,0);
  4061.                }
  4062.              }
  4063.                        } /* setzt auch die Scrollbars richtig */
  4064.                      }
  4065.            }
  4066.            else {
  4067.              /* linke Mausetaste wird bisher nicht benoetigt */
  4068.              /* (oder rechte Mausetaste, falls etwas schiefgegangen ist) */
  4069.  
  4070. #if 0             
  4071.              if (is_tmpmargin) {
  4072.                // wir warten auf den Klick um den Rand zu setzen
  4073.                // widthin : inch * 1000 (Groesse inklusive des Offsets)
  4074.                long xpos, ypos;
  4075.                long widthin  = (long)(((float)pwidth_pt  / 72.27 + ((float)SAVETY_BITS_X / (float)hconvresolution) * 1000.0 / (float)mag) * 1000.0 + 0.5);
  4076.                long heightin = (long)(((float)pheight_pt / 72.27 + ((float)SAVETY_BITS_Y / (float)vconvresolution) * 1000.0 / (float)mag) * 1000.0 + 0.5);
  4077.  
  4078.                if (MouseX < win2->BorderLeft) MouseX = win2->BorderLeft;
  4079.                if (MouseY < win2->BorderTop)  MouseY = win2->BorderTop;
  4080.                xpos = MouseX - win2->BorderLeft + static_x_Koo;
  4081.                ypos = MouseY - win2->BorderTop + static_y_Koo;
  4082.  
  4083.                show_state.margin_x = xpos * widthin / wx; 
  4084.                show_state.margin_y = ypos * heightin / wy;
  4085.  
  4086.                clear_pointer();
  4087.                unset_tmpmargin;
  4088.                set_margin;
  4089.                
  4090.                Message(MSG_MARGIN_SET);
  4091.              }
  4092.              else {
  4093.                if (is_messwin) {
  4094.                  WorkMessWin(MouseX, MouseY, Code == SELECTDOWN, Code == SELECTUP);
  4095.                }
  4096.              }
  4097. #endif
  4098.              if (is_messwin) {
  4099.                WorkMessWin(MouseX, MouseY, Code == SELECTDOWN, Code == SELECTUP);
  4100.              }
  4101.            }
  4102.                    break;
  4103.  
  4104.           case IDCMP_GADGETDOWN: 
  4105.            current_gadget = m_gad->GadgetID;
  4106.            ex = down_gad(current_gadget, m_gad, secs, mics);
  4107.            if (current_gadget == POTX_GAD_NR || current_gadget == POTY_GAD_NR
  4108.                 || current_gadget == PG_POT_GAD_NR) {
  4109.              /* das haette eigentlich mit FOLLOWMOUSE funktionieren muessen!!     */
  4110.              /* Es geht inzwischen auch...ich bekomme MOUSEMOVE Events...     */
  4111.              /* wohl aber irgendwie zu wenige...also mach ich trotzdem noch     */
  4112.              /* ein paar Intui-Ticks dazu :)                     */
  4113.              MyModifyIDCMP(IDCMP_MOUSEMOVE | IDCMP_INTUITICKS, 0L);
  4114.              add_mmove;
  4115.              add_inticks;    /* zur besseren Ansprechung auf Mausbewegungen */
  4116.            }
  4117.            else {
  4118.              current_gadget = -1;    /* alle Gadgets die kein FOLLOWMOUSE brauchen */
  4119.            }
  4120.  
  4121.            /* Falls Doppelklick auf einen der Pfeiltasten */
  4122.                if (ex == KOMM-1) {
  4123.                  set_jmpdown;
  4124.                }
  4125.                else if (ex == KOMM+1) {
  4126.                      set_jmpup;
  4127.                }
  4128.             break;
  4129.  
  4130.           case IDCMP_GADGETUP: 
  4131.            if (current_gadget == POTX_GAD_NR || current_gadget == POTY_GAD_NR ||
  4132.             current_gadget == PG_POT_GAD_NR) {
  4133.              /* das haette eigentlich mit FOLLOWMOUSE funktionieren muessen!! */
  4134.              /* tut's ja im Prinzip auch */
  4135.              sub_mmove;
  4136.              if (!is_mmove) {
  4137.                MyModifyIDCMP(0L, IDCMP_MOUSEMOVE);
  4138.              }
  4139.              sub_inticks;
  4140.              if (!is_inticks) {
  4141.                MyModifyIDCMP(0L, IDCMP_INTUITICKS);
  4142.              }
  4143.            }
  4144.                    current_gadget = -1;
  4145.            ex = check_gad(m_gad);
  4146.                    break;
  4147.  
  4148.       case IDCMP_MOUSEMOVE: 
  4149.            is_mouse_moved = TRUE;
  4150.            if (current_gadget != -1) {
  4151.              follow_pot_gad(current_gadget);
  4152.            }
  4153.            else {
  4154.              if (MessWin != NULL) {
  4155.                WorkMessWin(MouseX, MouseY, FALSE, FALSE);
  4156.              }
  4157.            }
  4158.              break;
  4159.  
  4160.           case IDCMP_CLOSEWINDOW:
  4161.                if (real_prog_end()) {
  4162.                  Enable_Abort = 0;
  4163.                      ex = KOMM+10L; 
  4164.                }
  4165.                    break;
  4166.  
  4167.       case IDCMP_CHANGEWINDOW:
  4168.              if (win2->LeftEdge != old_win_pos_x) {
  4169.                if (is_ownscr) {
  4170.                  show_state.window_pos_own_scr_x = win2->LeftEdge;
  4171.                }
  4172.                else {
  4173.                  show_state.window_pos_x = win2->LeftEdge;
  4174.                }
  4175.              }
  4176.              if (win2->TopEdge != old_win_pos_y) {
  4177.                if (is_ownscr) {
  4178.                  show_state.window_pos_own_scr_y = win2->TopEdge;
  4179.                }
  4180.                else {
  4181.                  show_state.window_pos_y = win2->TopEdge;
  4182.                }
  4183.              }
  4184.            break;
  4185.  
  4186.           case IDCMP_NEWSIZE:
  4187.                  set_i_window_size();
  4188.                  init_gad();
  4189.                  if (is_show){
  4190.                    show_full_page(TRUE);     /* ausschalten */
  4191.                    show_full_page(TRUE);     /* einschalten ohne Refresh (RefWin kommt noch) */
  4192.                    //show_full_page(FALSE);     /* einschalten mit Refresh */
  4193.                    
  4194.                    display_full_page();               // Seite einkopieren...
  4195.                  }
  4196.                  else {
  4197. #if 0
  4198.              const long winiw = win2->Width - win2->BorderLeft - win2->BorderRight;
  4199.              const long winih = win2->Height - win2->BorderTop - win2->BorderBottom;
  4200. #endif
  4201.  
  4202.              if (is_gadg) {        /* setzt die Grenzen richtig */
  4203.                window_plus_sbar_move(0,0);
  4204.                      RefreshGadgets(&potx_left_Gad, win2, NULL); /* Refresh bis zum Ende!! */
  4205.              }
  4206.              else {
  4207.               window_move(0,0);
  4208.              }
  4209.  
  4210.              // Loesche Window-Inneres, falls neu zentriert werden muss
  4211.              if (winiw > wx || winih > wy) {
  4212.                fill_block(win2->BorderLeft, win2->BorderTop, winiw-1, winih-1, 0);
  4213.              }
  4214.  
  4215.              window_show();
  4216.                  }
  4217.                  /* speichere neue Groesse ab */
  4218.                  if (is_ownscr) {
  4219.                    show_state.window_size_own_scr_x = win2->Width;
  4220.                    show_state.window_size_own_scr_y = win2->Height;
  4221.                  }
  4222.                  else {
  4223.                    show_state.window_size_x = win2->Width;
  4224.                    show_state.window_size_y = win2->Height;
  4225.                  }
  4226.                  
  4227.                  /* Puffer-RastPort wieder auf den neuesten Stand bringen */
  4228.                  if (is_bmcpu) {
  4229.                    FreeChipPuffRP();
  4230.                    AllocChipPuffRP();
  4231.                  }
  4232.                  
  4233.                  write_status();
  4234.            break;
  4235.  
  4236.       case IDCMP_REFRESHWINDOW:
  4237.                  BeginRefresh(win2);
  4238.                  if (is_show) {
  4239.              /* und nun wird die Bitmap einkopiert... */
  4240.                    display_full_page();               // Seite einkopieren...
  4241.                  }
  4242.                  else {
  4243.                    window_show();            /* nur einfach neu anzigen */
  4244.                  }
  4245.                  EndRefresh(win2, TRUE);
  4246.            break;
  4247.  
  4248.           case IDCMP_INACTIVEWINDOW:
  4249.                  if (is_messwin) {
  4250.              WorkMessWin(MouseX, MouseY, FALSE, TRUE);    // Maus hoch
  4251.            }
  4252.            break;
  4253.  
  4254.           case IDCMP_ACTIVEWINDOW:
  4255.            write_status();
  4256.            if (is_autoag && !is_notify && is_dvif && is_newer_dvi_file()) {
  4257.              /* than: load file again */
  4258.              OpenNewDVI(filename, FALSE);
  4259.              ex = KOMM + 3;
  4260.            }
  4261.            if (is_titref) {
  4262.              ULONG lck;        /* zur Sicherheit nochmal ein test, ob das Window (immer noch) active ist */
  4263.              lck = LockIBase(0L);
  4264.              if (IntuitionBase->ActiveWindow == win2) {
  4265.                UnlockIBase(lck);
  4266.                MessageStr(NULL);        /* refresh title */
  4267.                unset_titref;
  4268.              }
  4269.              else {
  4270.                UnlockIBase(lck);
  4271.              }
  4272.            }
  4273.            break;
  4274.  
  4275.       case IDCMP_MENUPICK:
  4276.              if (!is_osmenu) {
  4277.                /* Um AMIGA-A zu erlauben, wurde VERIFY weggemacht. Nun muss es wieder hin. */
  4278.                MyModifyIDCMP(IDCMP_MENUVERIFY, 0);    /* MENUVERIFY wieder hin */
  4279.              }
  4280.  
  4281.            if (is_messwin) {
  4282.              WorkMessWin(MouseX, MouseY, FALSE, TRUE);    // Maus hoch
  4283.            }
  4284.  
  4285.            ex = KOMM + 5;
  4286.            sel = Code;
  4287.            
  4288.            IsScreenReOpend = FALSE;
  4289.  
  4290.                    /* Reply muss vor work_with.. wg. toggle-lace */
  4291.            while (sel != MENUNULL && !IsScreenReOpend) {
  4292.              // sel != 0 ... es gibt kein Menu 0,0,0  !!
  4293.              // aber wird schon mit IsScreenReOpend abgefangen...
  4294.              ex = work_with_os_menu(MENUNUM(sel), ITEMNUM(sel), SUBNUM(sel));
  4295.              if (!IsScreenReOpend) {
  4296.                ItemAdr = ItemAddress(win2->MenuStrip, sel);
  4297.                sel = ItemAdr->NextSelect;
  4298.              }
  4299.            }
  4300.  
  4301.            if (ex == KOMM + 5) {
  4302.              ex = 0;
  4303.            }
  4304.            break;
  4305.  
  4306.       case IDCMP_MENUHELP:
  4307.              sel = Code;
  4308.              if (is_amigaguide) {
  4309.                /* AmigaGuide Hilfe (os3) */
  4310.                ItemAdr = ItemAddress (win2->MenuStrip, Code);
  4311.                if (ItemAdr) {
  4312.                        do_menu_help(sel, ItemAdr->Flags & CHECKED, ItemAdr->Flags & ITEMENABLED, !(ItemAdr->Flags & ITEMTEXT));
  4313.                }
  4314.                else {
  4315.                        do_menu_help(sel, 0, 0, 0);
  4316.                }
  4317. #if 0
  4318.              if (ItemAdr) {
  4319.                /* Get the context ID */
  4320.                long id = (LONG) MENU_USERDATA (ItemAdr);
  4321.  
  4322.                /* Adjust for being selected */
  4323.                if (ItemAdr->Flags & CHECKED) id++;
  4324.  
  4325.                        do_menu_help(sel, ItemAdr->Flags & CHECKED);
  4326.                }
  4327. #endif
  4328.              }
  4329.              else {
  4330.                /* normale Requester-Hilfe */
  4331.                  work_with_os_help_menu(MENUNUM(sel), ITEMNUM(sel), SUBNUM(sel));
  4332.                }
  4333.            break;
  4334.  
  4335.         case IDCMP_GADGETHELP:
  4336.            work_with_gadgethelp(©_msg);
  4337.            break;
  4338.  
  4339.           case IDCMP_RAWKEY:
  4340.            ex = work_with_raw_key(Code, Qualifier, MouseX, MouseY);
  4341.            if (MessWin != NULL) WorkMessWin(MouseX, MouseY, FALSE, FALSE);
  4342.                    break;
  4343.       case IDCMP_IDCMPUPDATE:
  4344.                 // Bisher hibt es nur das Boopsi Gad links unten das diese Message erzeugt
  4345.                if (Qualifier == 0) {
  4346.                  // Test--quasi auf Gadgetup..will hier nicht forlaufend neue Seiten aufbauen
  4347.                  if (Code != current_page_phy) {
  4348.                    // dann springe auf diese (phy) Seite
  4349.                    set_tusephy;    /* temp use of physical number */
  4350.                ex = Code;    /* kein 0 Hack...da immer phy Nummer */
  4351.                  }
  4352.                }
  4353.            break;
  4354.           default:
  4355.            FatalStr(20, "Unknown Intui-Message %d/%d\n", msg_Class, Code);
  4356.            break;
  4357.      }     /* switch */
  4358.      
  4359.  
  4360.      // ACHTUNG: Darf *NICHT* nach hinten verlegt werden, da ja moeglicherweise das Window geschlossen wird.
  4361.      // ReplyMsg(&(msg->ExecMessage));    // ACHTUNG: ist nach hinten verlagert
  4362.  
  4363.  
  4364.      if (is_print && ex != 0) {
  4365.        Message(MSG_NOT_WHILE_PRINTING);
  4366.        beep();
  4367.        ex = 0;
  4368.      }
  4369.   }
  4370.  
  4371.   if (is_mouse_moved) {
  4372.     if (current_gadget != -1) {
  4373.       follow_pot_gad(current_gadget);
  4374.     }
  4375.     if (MessWin != NULL) {
  4376.       WorkMessWin(MouseX, MouseY, FALSE, FALSE);
  4377.     }
  4378.   }
  4379.  
  4380.   
  4381.   return ex;        /* ex == -1 => go to page 0 */
  4382. }
  4383.  
  4384. /*
  4385.  ***********************************************************************
  4386.  *    M A I N  -  F u n k t i o n    --->     W A I T     <----
  4387.  ***********************************************************************
  4388.  */
  4389. static long scroll(void)
  4390. {
  4391.   register long ex;
  4392.   unsigned long signals;
  4393.   unsigned long ret_sigs;
  4394.   /* struct MsgPort    *mp; fuer das alte Timer Zeuks... */
  4395.  
  4396.   clear_pointer();
  4397.   
  4398.   /* nun muessten alle is_* richtig gesetzt sein, also update des Menues */
  4399.   set_checked_os_menu();
  4400.  
  4401.   /* und nun endlich: refresh des ganzen */
  4402.   if (is_gadg) RefreshGadgets(&potx_Gad,win2,NULL);  /* erstes Gadget in der Liste (von potx und poty :) */
  4403.  
  4404.  
  4405.   /* Setze IDCMP_MENUVERIFY falls pop_up gesetzt ist */
  4406.   if (!is_osmenu) {
  4407.     MyModifyIDCMP(IDCMP_MENUVERIFY, 0);
  4408.   }
  4409.  
  4410.  
  4411.   /* zuerst ueberall Mal schaun, ob was noch aussteht */
  4412. #if defined(APP_WINDOW)
  4413.   ex = work_with_app_win();
  4414. #else
  4415.   ex = work_with_app_icon();
  4416. #endif
  4417.  
  4418.   /* intui_message muss recht frue abgefragt werden (wg. MENUVERIFY) !! */
  4419.   if (ex == 0L) {
  4420.     ex = intui_message();        /* schau schon mal nach Messages */
  4421.   }
  4422.   if (ex == 0L && MainAppWin) {        /* ist win2 ein AppWin */
  4423.     ex = work_with_main_app_win();
  4424.   }
  4425.   if (ex == 0L) {
  4426.       /* ok("Rexx Message..."); */
  4427.       ex = dispRexxPort();                /* REXX */
  4428.   }
  4429.  
  4430.   /* Schleife ueber Messages innerhalb einer Seite */
  4431.   while (ex == 0L) {
  4432.   
  4433.     signals = ((is_print) ? SIG_PRINT : 0L)            |
  4434.               ((is_appwin) ? SIG_APP | SIG_APPWIN : 0L)        |
  4435.               ((is_about) ? SIG_ABOUTWIN : 0L)            |
  4436.               ((MessWin != NULL) ? SIG_MESSWIN : 0L)        |
  4437.               ((SearchWin) ? SIG_SEARCHWIN : 0L)        |
  4438.               ((is_prefwin) ? SIG_PREFWIN : 0L)            |
  4439.               ((is_notify) ? SIG_NOTIFY : 0L)            |
  4440.               ((MainAppWin) ? SIG_MAINAPPWIN : 0L)        |
  4441.               ((is_amigaguide) ? SIG_AMIGAGUIDE : 0L)        |
  4442.               SIGBREAKF_CTRL_C                    |
  4443.               SIGBREAKF_CTRL_E                    |
  4444.               SIGBREAKF_CTRL_F                    |
  4445.               SIG_TIMER                        |
  4446.               SIG_REXX                        |
  4447.               SIG_WIN;
  4448.  
  4449.     //((is_os2 && is_myscr) ? SIG_SCREENCLOSE : 0L)        |
  4450.  
  4451.     PROFILE_OFF();
  4452.     ret_sigs = Wait(signals);        /*------- W A I T -------*/
  4453.     PROFILE_ON();
  4454.  
  4455.     if (Enable_Abort && (ret_sigs & SIGBREAKF_CTRL_C)) {    /* CTR-C */
  4456.       if (can_i_exit()) {
  4457.         if (!is_osmenu) MyModifyIDCMP(0, IDCMP_MENUVERIFY);
  4458.     if (is_print) { 
  4459.       abort_print_page();
  4460.     }
  4461.     CXBRK();        /* lattice ^C funktion */
  4462.       }
  4463.     }
  4464.  
  4465.     if (ret_sigs & SIG_REXX) {
  4466.       /* ok("Rexx Message..."); */
  4467.       ex = dispRexxPort();                /* REXX */
  4468.     }
  4469.  
  4470.     if (ret_sigs & SIGBREAKF_CTRL_E) {            /* CTR-E */
  4471.       WindowToFront(win2);
  4472.       ScreenToFront(screen);
  4473.       make_show_active();
  4474.     }
  4475.  
  4476.     if (ret_sigs & SIGBREAKF_CTRL_F) {            /* CTR-F */
  4477.       WindowToFront(win2);
  4478.       ScreenToFront(screen);
  4479.       make_show_active();
  4480.       if (access(filename,4) == 0) {
  4481.         char *p = strrchr(filename,'.');
  4482.         if (p != NULL && stricmp(p,".dvi") == 0 && is_dvif) {    /* nur is_dvif ?? */
  4483.           OpenNewDVI(filename, FALSE);
  4484.           ex = KOMM + 3;        /* neues File, Name nicht geaendert. */
  4485.         }
  4486.       }
  4487.     }
  4488.  
  4489.     if (is_print && (ret_sigs & SIG_PRINT)) {            /* PRINT */
  4490.       check_print_page();
  4491.       MessageStr(NULL);
  4492.     }
  4493.  
  4494.     if (ex == 0 && (is_notify &&(ret_sigs & SIG_NOTIFY))) {    /* Notify Signal */
  4495.       if (is_newer_dvi_file()) {        /* das File muss sich auch wirklich geaendert haben */
  4496.         if (access(filename,4) == 0) {        /* es koennte ja sein, dass es bereits neu geladen wurde */
  4497.           char *p = strrchr(filename,'.');
  4498.           if (p != NULL && stricmp(p,".dvi") == 0 && is_dvif) {    /* nur is_dvif ?? */
  4499.             BPTR lock;
  4500.             lock = Lock(filename, ACCESS_READ);    /* Hoffnung, damit zu verhindern, dass mir jemand das File wieder wegschnappt... */
  4501.             if (lock != NULL) {
  4502.               OpenNewDVI(filename, FALSE);
  4503.               UnLock(lock);
  4504.               ex = KOMM + 3;        /* neues File, Name nicht geaendert. */
  4505.             }
  4506.           }
  4507.         }
  4508.       }
  4509.     }
  4510.     
  4511.  
  4512.     if (ret_sigs && SIG_SCREENCLOSE) {
  4513.       // wuesste nicht, was hier nun zu tun waere
  4514.       // ich will den Screen nun mal niht schliessen!! :-)
  4515.       //printf("Debug: SIG_SCREENCLOSE arrived!\nsig: %ld\nSIG: %lx\nret_sigs: %lx", sig_screenclose, SIG_SCREENCLOSE, ret_sigs);
  4516.       // iwrd staendig aufgerufen...????
  4517.     }
  4518.     
  4519.     if (ex == 0 && (ret_sigs & SIG_AMIGAGUIDE)) {
  4520.       ex = work_with_help();
  4521.     }
  4522.  
  4523.  
  4524.     if (ex == 0 && (MainAppWin && (ret_sigs & SIG_MAINAPPWIN))) {
  4525.       ex = work_with_main_app_win();
  4526.     }
  4527.  
  4528.  
  4529.     if (ex == 0 && (is_about && (ret_sigs & SIG_ABOUTWIN))) {    /* About-Window */
  4530.       ex = AboutWinMsg();
  4531.     }
  4532.     
  4533.     if (ex == 0 && (ret_sigs & (SIG_APP | SIG_APPWIN))) {    /* WB-App-Win */
  4534. #if defined(APP_WINDOW)
  4535.       ex = work_with_app_win();
  4536. #else
  4537.       ex = work_with_app_icon();
  4538. #endif
  4539.     }
  4540.  
  4541.     if (ex == 0 && is_messwin && (ret_sigs & SIG_MESSWIN)) {    /* Messuring-Window */
  4542.       /* die is_messwin Abfrage *muss* sein, da */
  4543.       /* sonst das SIG_ nicht gueltig ist! */
  4544.       ex = MessWinMsg();
  4545.     }
  4546.     
  4547.     if (ex == 0 && is_prefwin && (ret_sigs & SIG_PREFWIN)) {    /* Preference-Window */
  4548.       ex = DoPrefWin();
  4549.     }
  4550.     
  4551.     if (ex == 0 && SearchWin && (ret_sigs & SIG_SEARCHWIN)) {    /* Preference-Window */
  4552.       char SBuf[100] = "";
  4553.       enum SearchActions sr;
  4554.       if (InSearchMode) {
  4555.         sr = DoSearchWin(NULL, 0);
  4556.       }
  4557.       else {
  4558.         sr = DoSearchWin(SBuf, sizeof(SBuf)-1);
  4559.       }
  4560.       if (sr == SEARCHWIN_ACTION_SEARCH) {
  4561.         ex = KOMM + StartSearch(SO_StartSearchAgain);
  4562.       }
  4563.     }
  4564.     
  4565.     if (ex == 0 && (ret_sigs & SIG_WIN)) {            /* INTUI - IDCMP */
  4566.       ex = intui_message();
  4567.     }
  4568.  
  4569.   }    /* end while (ex == 0 ) */
  4570.  
  4571.  
  4572.     /* ret == -1        go to page 0 !!    */
  4573.     /* ret <  KOMM -  2 ret = Seite        */
  4574.     /* ret == KOMM +  5 no action        */
  4575.     /* ret == KOMM -  1 Seite zurueck    */
  4576.     /* ret == KOMM +  1 Seite vor        */
  4577.     /* ret == KOMM -  2 Textanfang        */
  4578.     /* ret == KOMM +  2 Textende        */
  4579.     /* ret == KOMM + 10 Programmende    */
  4580.     /* ret == KOMM +  3 selbes File nochm.    */
  4581.     /* ret == KOMM +  4 neues DVI-F.    */
  4582.  
  4583.  
  4584.   /* Loesche IDCMP_MENUVERIFY (darf nicht so lange gesetzt sein) */
  4585.   if (!is_osmenu) {
  4586.     MyModifyIDCMP(0, IDCMP_MENUVERIFY);
  4587.   }
  4588.  
  4589.  
  4590.   if (ex == KOMM+10L) {     /* Programmende ? */
  4591.     Enable_Abort = 0;        /* nur zur Sicherheit! Nun kein ^C mehr */
  4592.     if (is_print) { 
  4593.       abort_print_page();
  4594.     }
  4595.   }
  4596.   
  4597.   /* Wenn neues File geladen wird, dann werden die derzeitigen Raender ungueltig */
  4598.   if (ex == KOMM+4) {    // neues DVI-File
  4599.     unset_margin;
  4600.     show_state.margin_x = 0;
  4601.     show_state.margin_y = 0;
  4602.   }
  4603.  
  4604.   sleep_pointer();
  4605.   return ex;
  4606. }
  4607. /*******************************************************************/
  4608.  
  4609.  
  4610. void clear_bild(void)            /* KEIN static */
  4611. {
  4612.   // Im Such-Modus wird nicht wirklich ein neues Bild aufgebaut
  4613.   if (InSearchMode) return;
  4614.  
  4615.   if (is_bmfast) {
  4616.     long len = (wx+7)/8*wy;
  4617.     long pad = len & 3;
  4618.     long i;
  4619.     long * ptr = (long *)myRastPort.BitMap->Planes[0];
  4620.  
  4621.     D(bug("ClearBild: Länge: %ld, pad: %ld\n", len, pad));
  4622.  
  4623.     for (i=0; i<len/4; i++) *(ptr + i) = 0L;
  4624.     if (pad > 0) memset(ptr+i, 0, pad);
  4625.   }
  4626.   else {
  4627.     SetRast(&myRastPort,0L);
  4628.   }
  4629.  
  4630.   if ((!is_bmfast || is_village) && !is_cyber) {
  4631.     /* und nun einen Rand zeichnen */
  4632.     MySetABPenDrMd(&myRastPort, show_state.APen, show_state.APen, JAM1);
  4633.     SetDrPt(&myRastPort, 0xFFFF);    // gfxmacros.h
  4634.  
  4635.     Move(&myRastPort, 0,    0);
  4636.     Draw(&myRastPort, wx-1, 0);
  4637.     Draw(&myRastPort, wx-1, wy-1);
  4638.     Draw(&myRastPort, 0,    wy-1);
  4639.     Draw(&myRastPort, 0,    0);
  4640.     
  4641.     D(bug("ClearBild: Move/Draw\n"));
  4642.   }
  4643.   else {
  4644.     register int i;
  4645.     char * ptr = (char *)(myRastPort.BitMap->Planes[0]);
  4646.     long rlen  = myRastPort.BitMap->BytesPerRow;
  4647.  
  4648.     for (i=0; i<wy; i++) {
  4649.       *(ptr + i     * myRastPort.BitMap->BytesPerRow)    = 0x80;
  4650.       *(ptr + (i+1) * myRastPort.BitMap->BytesPerRow -1) = 0x01;
  4651.     }
  4652.     for (i=0; i<rlen; i++) {
  4653.       *(ptr             + i) = 0xFF;
  4654.       *(ptr+(wy-1)*rlen + i) = 0xFF;
  4655.     }
  4656.  
  4657.     D(bug("ClearBild: handmade\n"));
  4658.   }
  4659. }
  4660.  
  4661.  
  4662. /* saves pointer to current active window */
  4663. static void save_active_window(void)
  4664. {
  4665.   oldactiveWindow = IntuitionBase->ActiveWindow;
  4666. }
  4667.  
  4668. /* make old window active again */
  4669. void make_old_active(void)
  4670. {
  4671.   /* das ist etwas buggy...vielleicht sollte ich diese Funktion ganz herausnehmen?? */
  4672.   /* Ich fummle bei einem nicht mir gehoerenden Window rum :-(( */
  4673.   struct Window * fwin;
  4674.   struct Screen * fscr;
  4675.   int found = FALSE;
  4676.  
  4677.   if (oldactiveWindow != NULL) {
  4678.     ULONG lck;
  4679.     lck = LockIBase(0L);
  4680.     fscr = IntuitionBase->FirstScreen;
  4681.     while (fscr && !found) {
  4682.       fwin = fscr->FirstWindow;
  4683.       while (fwin && !found) {
  4684.         if (fwin == oldactiveWindow) {
  4685.           found = TRUE;
  4686.         }
  4687.         else {
  4688.           fwin = fwin->NextWindow;
  4689.         }
  4690.       }
  4691.       if (!found) fscr = fscr->NextScreen;
  4692.     }
  4693.     Forbid();
  4694.     UnlockIBase(lck);
  4695.     if (found) ActivateWindow(oldactiveWindow);
  4696.     Permit();
  4697.   }
  4698. }
  4699.  
  4700. /* make showdvi active and saves old active window */
  4701. void make_show_active(void)
  4702. {
  4703.   save_active_window();
  4704.   if (win2 != NULL) ActivateWindow(win2);
  4705. }
  4706.  
  4707.  
  4708. /* ARexx  Dispatcher */
  4709. static /*__stdargs*/ long arexx_disp(struct RexxMsg *msg, struct rexxCommandList *dat, char *p)
  4710. {
  4711.   long (*userfunc)(struct RexxMsg *, char *);
  4712.   long ret = 0;
  4713.  
  4714.   if (dat->userdata != NULL) {
  4715.     userfunc = (long (*)(struct RexxMsg *, char *))dat->userdata;
  4716.     ret = userfunc(msg, p);
  4717.     return ret;
  4718.   }
  4719.  
  4720.   replyRexxCmd(msg, 20L, 10L, NULL);
  4721.  
  4722.   return ret;
  4723. }
  4724.  
  4725.  
  4726. /* exit-proc ***********
  4727. int exit_procedure(int ret)
  4728. {
  4729.   close_all_bild();
  4730.   return ret;
  4731. }
  4732. ***********************/
  4733.  
  4734.  
  4735. /*********************************************************/
  4736. /* SCHNITTSTELLE zu den anderen Modulen :                */
  4737.  
  4738.  
  4739. void beep(void)
  4740. {
  4741.   if (screen != NULL && is_beep) {
  4742.     DisplayBeep(screen);
  4743.   }
  4744. }
  4745.  
  4746.  
  4747. /* return: print help? */
  4748. int init_task_name(int argc, char **argv)
  4749. {
  4750.   struct Process *my_proc;
  4751.   int rexx_result;
  4752.   char rexx_command[150];
  4753.  
  4754. #ifndef BACKGROUND
  4755.   struct CommandLineInterface *cli;
  4756.   /* long stack_size; */
  4757. #endif
  4758.  
  4759.   /*====*/
  4760.   ArpBase = NULL;        
  4761.   unset_arp;            /* default: no ARP-library found        */
  4762.   OpenLib();             /* open Intuition,Gfx... and Arp libraries    */
  4763.  
  4764.   font8 = font11 = NULL;    /* init Pointers             */
  4765.  
  4766.   BitMapFullPage.Planes[0]=NULL;/* init Full-Page bitmap!!!        */
  4767.  
  4768.   timer_wait_ticks = 0;        /* init INTUI TICK counter        */
  4769.   /*====*/
  4770.  
  4771.  
  4772. #ifndef BACKGROUND
  4773.   // feststellen, ob mit run gestartet
  4774.   background = FALSE;  
  4775.   my_proc =(struct Process *)FindTask(NULL);
  4776.   if (my_proc != NULL /*&& my_proc->pr_TaskNum != 0*/) {    /* cli-process */
  4777.     cli = (struct CommandLineInterface *)(my_proc->pr_CLI << 2);
  4778.     if (cli != NULL) {
  4779.       /* stack_size = cli->cli_DefaultStack << 2; */        /* in bytes */
  4780.       background = (cli->cli_Background != DOSFALSE);
  4781.     }
  4782.   }
  4783. #endif
  4784.  
  4785.  
  4786.   if ((my_proc = (struct Process *)FindTask(task_name)) != NULL) {
  4787.     // es laeuft schon ein ShowDVI :: nun estmal die Optionen parsen
  4788.     char * fptr;
  4789.  
  4790.     fptr = DecodeArgs( argc, argv );
  4791.  
  4792.     Signal(&(my_proc->pr_Task),SIGBREAKF_CTRL_E);    /* screen to front */
  4793.    
  4794.     if (fptr) {
  4795.       // Filename wurde uebergeben 
  4796.       BPTR lck;
  4797.       char fpuf[200], * ptr;
  4798.       
  4799.       strncpy(fpuf, fptr, sizeof(fpuf)-6);
  4800.       ptr = strrchr(fpuf, '.');
  4801.  
  4802.       // in fpuf den Namen etwas verschoenern:
  4803.       // - ein .tex durch ein .dvi ersetzen
  4804.       // - falls keine Extension ein .dvi anhaengen (falls das File dann existiert)
  4805.       // Danach dann noch den kompletten Pfad daraus machen, da das erste ShowDVI 
  4806.       // vermutlich aus einem anderen Dir. aufgerufen wurde.
  4807.  
  4808.       if (!ptr) {      
  4809.         // gar keine Extension
  4810.         ptr = fpuf + strlen(fpuf);    // zeigt auf das Null-Byte
  4811.         strcpy(ptr, ".dvi");
  4812.         lck = Lock(fpuf, ACCESS_READ);
  4813.         if (!lck) {
  4814.           *ptr = '\0';    // mit .dvi gibt es das File nicht, also wieder weg damit
  4815.         }
  4816.         else {
  4817.           UnLock(lck);
  4818.           lck = NULL;
  4819.         }
  4820.       }
  4821.       else {
  4822.         if (!stricmp(ptr, ".tex")) {
  4823.           // .tex --> ersetzen
  4824.           strcpy(ptr, ".dvi");
  4825.         }
  4826.       }
  4827.       
  4828.       lck = Lock(fpuf, ACCESS_READ);
  4829.       if (lck) {
  4830.         if (!NameFromLock(lck, fpuf, sizeof(fpuf)-1)) {
  4831.           // wuaehh...nun mag ich nicht mehr
  4832.           strncpy(fpuf, fptr, sizeof(fpuf)-6);
  4833.         }
  4834.         UnLock(lck);
  4835.         lck = NULL;
  4836.       }
  4837.       
  4838.       sprintf(rexx_command, "address \"showdvi\" \"loadnew %s\"", fpuf);
  4839.  
  4840.       if (!call_rexx(rexx_command, &rexx_result)) {
  4841.         Warning(MSG_AREXX_COMM_START_FAILED);
  4842.         AbortRun(5);                    /* end of programm */
  4843.       }
  4844.       else {
  4845.         if (rexx_result != 0) {
  4846.           Warning(MSG_AREXX_COMM_FAILED, rexx_command, rexx_result);
  4847.           AbortRun(5);                    /* end of programm */
  4848.         }
  4849.       }
  4850.     }
  4851.  
  4852.     AbortRun(0);                    /* end of programm */
  4853.   }
  4854.  
  4855.  
  4856.   my_proc =(struct Process *)FindTask(NULL);
  4857.   if (my_proc != NULL) {
  4858.     old_task_name = my_proc->pr_Task.tc_Node.ln_Name;    /* save task name */
  4859.     my_proc->pr_Task.tc_Node.ln_Name = task_name;    /* change task name */
  4860.   }
  4861.  
  4862. #ifdef CATCH
  4863.   _ONGURU = (void *)onGURU;
  4864. #endif
  4865.  
  4866.  
  4867. #ifdef CATCH_ZERO
  4868.   (void)signal( SIGFPE ,(void (*)(int))sighandling);
  4869. #endif
  4870.  
  4871.   return 0;    /* keine Hilfe...alles geht normal weiter */
  4872. }
  4873.  
  4874.  
  4875. static void sighandling(int i)
  4876. {
  4877.   Fatal(20,MSG_DIV_ZERO);
  4878. }
  4879.  
  4880. #ifdef CATCH
  4881. static void onGURU(void)
  4882. {
  4883.   close_all_bild();
  4884.   if (g_logfp != NULL) {
  4885.     fclose(g_logfp);
  4886.   }
  4887. }
  4888. #endif
  4889.  
  4890.  
  4891.  
  4892. void SetShowDVIVars(char *name)
  4893. {
  4894.   char *f, *d;
  4895.   int len;
  4896.  
  4897.   if (is_os2) {
  4898.     if (!is_dir(name)) {
  4899.       if ((f = strrchr(name, '/')) == NULL) {
  4900.         f = strchr(name, ':');
  4901.         if (f == NULL) f = name;
  4902.       }
  4903.  
  4904.       /* *ohne* .dvi Endung!! */
  4905.       if (!SetVar("ShowDVI-file", f+1, strlen(f+1)-4, GVF_LOCAL_ONLY)) {
  4906.         Warning(MSG_CANT_SET_VARIABLE, "ShowDVI-file");
  4907.       }
  4908.  
  4909.       if (f == NULL) {
  4910.         d = "";
  4911.         len = 0;
  4912.       }
  4913.       else {
  4914.         d = name;
  4915.         len = f - d + 1;
  4916.       }
  4917.       if (!SetVar("ShowDVI-dir", d, len, GVF_LOCAL_ONLY)) {
  4918.         Warning(MSG_CANT_SET_VARIABLE, "ShowDVI-dir");
  4919.       }
  4920.     }
  4921.   }
  4922. }
  4923.  
  4924. static void DeleteShowDVIVars(void)
  4925. {
  4926.   if (is_os2) {
  4927.     DeleteVar("ShowDVI-file", GVF_LOCAL_ONLY);
  4928.     DeleteVar("ShowDVI-dir", GVF_LOCAL_ONLY);
  4929.   }
  4930. }
  4931.  
  4932.  
  4933.  
  4934. char *GetCurrentPubScr(void)
  4935. {
  4936.   if (is_ownscr) {
  4937.     return &(MyPubScreenName[0]);
  4938.   }
  4939.   else {
  4940.     return &(PubScreenName[0]);
  4941.   }
  4942. }
  4943.  
  4944.  
  4945.  
  4946. void Init_ShowDVI(void)        /* VERY first procedure!! */
  4947. {
  4948. #if 0
  4949.   /* das muss schon in init_task_name gemacht werden, sonst Aerger bei doppel-Start!! */
  4950.   ArpBase = NULL;        
  4951.   unset_arp;            /* default: no ARP-library found        */
  4952.   OpenLib();             /* open Intuition,Gfx... and Arp libraries    */
  4953.  
  4954.   font8 = font11 = NULL;    /* init Pointers             */
  4955.  
  4956.   BitMapFullPage.Planes[0]=NULL;/* init Full-Page bitmap!!!        */
  4957.  
  4958.   timer_wait_ticks = 0;        /* init INTUI TICK counter        */
  4959. #endif
  4960.  
  4961.   if (SysBase->LibNode.lib_Version < 37) exit(20);
  4962.  
  4963.   set_lace;            /* default: interlace            */
  4964.   set_gadg;            /* default: scrollbars            */
  4965.   unset_show;            /* default: not in full-screen modus    */
  4966.   unset_timer;            /* default: no timer request is running    */
  4967.   unset_pscro;            /* default: not in page-scroll modus    */
  4968.   unset_colre;            /* default: no color-req. on the screen    */
  4969.   unset_about;            /* default: no about-req. on the screen */
  4970.   unset_dvif;            /* default: no DVI-File loadet jet    */
  4971.   unset_ndvif;            /* default: no new DVI-File loadet jet    */
  4972.   set_beep;            /* default: beep on warnings        */
  4973.   unset_escex;            /* default: no exit on ESC        */
  4974.   set_imenu;            /* default: intelligent menu! :-)    */
  4975.   set_bmenu;            /* default: big (topaz 11) menu        */
  4976.   set_unit_in;            /* default: used unit = inch        */
  4977.   unset_mesu;            /* default: no mesuring            */
  4978.   unset_jmpup;            /* default: jump not to top of page    */
  4979.   unset_jmpdown;        /* default: jump not to bottom of page    */
  4980.   undef_scrmode;        /* default: no 2.0 screen mode        */
  4981.   set_osmenu;            /* default: use pull-down menu        */
  4982.   unset_autoag;            /* default: no auto load again        */
  4983.   unset_notify;            /* default: no notify mechanism        */
  4984.   unset_messwin;        /* default: no mess-window open        */
  4985.   clear_mmove;            /* default: no MOUSEMOVE IDCMP flag    */
  4986.   set_col4;            /* default: use 4 color screen        */
  4987.   set_clwbcol;            /* default: clone the wb colors        */
  4988.   unset_midmenu;        /* default: don't use middle pop-up menu*/
  4989.   unset_titref;            /* default: no title to refresh        */
  4990.   unset_quickex;        /* default: no immediately exit        */
  4991.   unset_chres;            /* default: resolution is not changed    */
  4992.   unset_dotbord;        /* default: no border line        */
  4993.   unset_prefwin;        /* default: no preference window up    */
  4994.   set_ownscr;            /* default: use own screen        */
  4995.   unset_myscr;            /* default: screen is not (jet) my scr  */
  4996.   unset_village;        /* default: we are not on a vga screen    */
  4997.   unset_scrollras;        /* default: use ClipBlit()        */
  4998.   unset_bmfast;            /* default: bitmap in chip ram        */
  4999.   unset_alwbmfast;        /* default: use Chip-RAM        */
  5000.   unset_bmcpu;            /* default: use blitter for bm copy    */
  5001.   set_smartwin;            /* default: use smart-refresh window    */
  5002.   unset_margin;            /* default: no margins set        */
  5003.   unset_amigaguide;        /* default: AmigaGuide ist nicht bereit */
  5004.   unset_bhook;            /* default: no Backfill Hook            */
  5005.  
  5006.  
  5007.   set_wbmode;            // DisplayID == Workbench
  5008.   
  5009.   show_state.APen = 1;        /* black on white */
  5010.   show_state.BPen = 2;
  5011.   
  5012.   strcpy(PubScreenName, "Workbench");
  5013.   strcpy(MyPubScreenName, "ShowDVI-PubScr");
  5014.   
  5015.   show_state.ChipPuffBM = NULL; /* ungleich NULL wenn is_bmcpu */
  5016.   InitRastPort(&show_state.ChipPuffRP);
  5017.  
  5018.  
  5019.   if (is_os2) {
  5020.     set_appwin;            /* default: under >= 2.0: app-window!    */
  5021.     set_pubscr;            /* default: under >= 2.0: public-screen    */
  5022.   }
  5023.   else {
  5024.     unset_appwin;        /* default: under < 2.0: no app-window    */
  5025.     unset_pubscr;
  5026.   }
  5027.  
  5028.   app_icon_name = DEFAULT_APP_ICON_NAME;
  5029.   show_state.AppIconX = 0;    /* default: no specific AppIcon position*/
  5030.   show_state.AppIconY = 0;
  5031.  
  5032.   (void)clear_counter(0);    /* set the page-jump-counter to '-1'    */
  5033.  
  5034.   /* set default screen size. 0 0 => clone workbench screen */
  5035.   show_state.screen_size_x = 0;
  5036.   show_state.screen_size_y = 0;
  5037.  
  5038.   /* set default window pos/size, -1 -1 is the default */
  5039.   show_state.window_size_x = 600;
  5040.   show_state.window_size_y = 180;
  5041.   show_state.window_pos_x = 0;
  5042.   show_state.window_pos_y = 0;
  5043.  
  5044.   show_state.window_size_own_scr_x = -1;
  5045.   show_state.window_size_own_scr_y = -1;
  5046.   show_state.window_pos_own_scr_x = -1;
  5047.   show_state.window_pos_own_scr_y = -1;
  5048.  
  5049.   show_state.menu_res_lines = 5;/* default: nr. of new res-menu lines    */
  5050.   show_state.mres[0] = 120;
  5051.   show_state.mres[1] = 100;
  5052.   show_state.mres[2] =  91;
  5053.   show_state.mres[3] =  83;
  5054.   show_state.mres[4] =  44;
  5055.  
  5056.   /* default aspect-ratio (640x400) */
  5057.   show_state.monitor_size_x = 4;
  5058.   show_state.monitor_size_y = 3;
  5059.   
  5060.   /* default margins: no margins */
  5061.   show_state.margin_x = 0;
  5062.   show_state.margin_y = 0;
  5063.   
  5064.  
  5065.   /* Setzen der aktuellen (default) Farbwerte */
  5066.   init_screen_colors();
  5067.  
  5068.   /* Wie werden die Seitennummern interpretiert */
  5069.   unset_usephy;            /* use logical numbers by default    */
  5070.   unset_tusephy;        /* no tmp physical numbers (!pscro)    */
  5071.   
  5072.   /* default command for the 'r' command */
  5073.   show_state.command = "TeX:s/ShowDVI.sh";
  5074.   
  5075.   /* default script for the start of the TeX-server */
  5076.   show_state.arexxstart = "rx TeX-server.rexx";
  5077.  
  5078.  
  5079.   /* ###############  read configuration-file  ################# */
  5080.   if (!read_config_file()) {
  5081.     Warning(MSG_ERROR_IN_CONFIG_FILE);
  5082.   }
  5083.  
  5084.   /* Ueberschreibe lace bei wbmode || bei is_numeric */
  5085.   if (is_wbmode || is_numeric) {
  5086.     long mode_lace = FALSE;
  5087.     ULONG id;
  5088.     
  5089.     if (is_wbmode) id = GetWBModeID();
  5090.     else id = show_state.DisplayID;        // is_numeric
  5091.  
  5092.     (void)GetModeIDName(id, &mode_lace);
  5093.     
  5094.     if (mode_lace) set_lace;
  5095.     else unset_lace;
  5096.   }
  5097.   
  5098.   if (is_clwbcol) {
  5099.     /* nun die Farben nochmal setzen */
  5100.     init_screen_colors();
  5101.   }
  5102.  
  5103.   if (!is_os2) {
  5104.     unset_appwin;        /* < 2.0 => no app-win available    */
  5105.   }
  5106.   if (!is_autoag) {
  5107.     unset_notify;        /* notify only if auto-again is active */
  5108.   }
  5109.   
  5110.   if (!is_ownscr) {
  5111.     show_state.screen_size_x = show_state.screen_size_y = 0;
  5112.   }
  5113.   
  5114.   InitHelpFirst();
  5115. }
  5116.  
  5117.  
  5118.  
  5119. void Open_ShowDVI(int isDVIfile)    /* !!!first procedure!!! */
  5120.   /* isDVIfile: BOOL gibt an, ob gleich am Anfang ein DVI-File geladen wird */
  5121. {
  5122.   long i;
  5123.   
  5124.   // wenn ein PubScreen Name als Arg uebergeben wurde, dann nimm diesen
  5125.   if (ArgPubname) {  
  5126.     struct Screen * pscr = LockPubScreen(ArgPubname);
  5127.     if (pscr) {
  5128.       unset_ownscr;
  5129.       strncpy(PubScreenName, ArgPubname, sizeof(PubScreenName)-1);
  5130.       UnlockPubScreen(NULL, pscr);
  5131.     }
  5132.     else {
  5133.       set_ownscr;
  5134.       strncpy(MyPubScreenName, ArgPubname, sizeof(MyPubScreenName)-1);
  5135.     }
  5136.   }
  5137.  
  5138.   if (isDVIfile) {
  5139.     set_dvif;        /* das wird zwar auch noch mal in showdvi.c/ReadFile() gemacht... */
  5140.   }            /* aber hier ist's irgendwie sinnvoller */
  5141.   else {
  5142.     unset_dvif;
  5143.   }
  5144.  
  5145.   for (i=0; i < show_state.menu_res_lines && show_state.mres[i] != resolution; i++);
  5146.   if (i == show_state.menu_res_lines) {
  5147.     show_state.mres[i] = resolution;
  5148.     show_state.menu_res_lines++;
  5149.   }
  5150.  
  5151.   wx = wy = 0;
  5152.   set_resolution();        /* initialize the size of screen/wind.    */
  5153.   
  5154.   save_active_window();        /* saves current active window        */
  5155.  
  5156.   open_fonts();            /* open the fonts topaz 8 and topaz 11    */
  5157.   init_menu();            /* alloc memory for the menu        */
  5158.   InitFileReq();        /* initialize filerequest structure    */
  5159.   OpenS();            /* open screen                */
  5160.  
  5161.   OpenWin2();            /* open display window            */
  5162.  
  5163.   // 0 Bytes, wenn hgrp auf -1 ist (AbortRun)
  5164.  
  5165.   set_i_window_size();
  5166.   wx = x_win_i_width;        /* Vorabdefinition fuer init_gad    */
  5167.   wy = x_win_i_height;
  5168.  
  5169.   sleep_pointer();        /* set mouse to zz            */
  5170.  
  5171.   init_gad();            /* set sizes and locations of gadgets    */
  5172.  
  5173.   Add_system_gadgets();        /* add +,++,-,... gadgets         */
  5174.   if (is_gadg) {
  5175.     Add_scroll_gadgets(FALSE);    /* add scrollbars with refresh        */
  5176.   }
  5177.   
  5178.   set_i_window_size();
  5179.   wx = x_win_i_width;        /* nun zuruecksetzen            */
  5180.   wy = x_win_i_height;
  5181.  
  5182.   // 264 Bytes, wenn hgrp=-1 (AbortRun)
  5183.   //AbortRun(0);
  5184.   
  5185.   // ########### refresh_screen();        /* refrsh screen (window)        */
  5186.   
  5187.   if (is_appwin) {
  5188. #if defined(APP_WINDOW)
  5189.     if (!setup_app_win(&sig_app, &sig_appwin)) {
  5190.       unset_appwin;
  5191.     }
  5192. #else
  5193.     if (!setup_app_icon(&sig_app)) {
  5194.       sig_appwin = 0;    /* koennte man auch loeschen */
  5195.       unset_appwin;
  5196.     }
  5197. #endif
  5198.   }
  5199.  
  5200. #if 0
  5201.   TimeRequest = CreateTimer();    /* open timerdevice            */
  5202.   if (TimeRequest == NULL) {
  5203.     Warning("Can't open Timer-Device!");
  5204.   }
  5205.   /*** wenn TimeRequest==NULL => keine Panik, geht auch so!! ***/
  5206. #endif
  5207.  
  5208.   SIG_REXX = upRexxPort("showdvi", rcl, "sd", &arexx_disp);
  5209.  
  5210. #if 0
  5211.   getdir("",direct);        /* Pfadname des aktuellen Verzeichnisses */
  5212.   strcpy((char *)((struct StringInfo *)(dir_Gad.SpecialInfo))->Buffer, direct);
  5213.   strcpy((char *)((struct StringInfo *)(dir_Gad.SpecialInfo))->UndoBuffer, direct);
  5214.   //RefreshGadgets(&dir_Gad,win2,NULL);        /* refresh all gadgets    */
  5215.   RefreshGList(&dir_Gad,win2,NULL,2);        /* Test: Nur 2 Gadgets refreshen  */
  5216. #endif
  5217.  
  5218. #if 0
  5219.   NewTimeRequest();        /* start timer                */
  5220. #endif
  5221.  
  5222.   if (is_autoag && is_dvif) {
  5223.     (void)InitDVINotify();        /* ob's geht oder nicht ist egal */
  5224.                     /* autoag geht auf jeden Fall */
  5225.     (void)is_newer_dvi_file();        /* initialisiere das Datum...*/
  5226.   }
  5227.   
  5228. #ifdef BETACOPYRIGHT
  5229.   Warning(MSG_BETA_VERSION);
  5230. #endif
  5231. }
  5232.  
  5233.  
  5234. void close_all_bild(void)
  5235. {
  5236.   struct Task *my_task;
  5237.  
  5238.   /* Speicher der Full-Page-Bitmap freigeben */
  5239.   if (BitMapFullPage.Planes[0] != NULL) {
  5240. #if 0
  5241.     if (is_bmfast) {
  5242.       FreeMem(BitMapFullPage.Planes[0], (wx+7)/8*wy);    // <-- das kann doch nie gestimmt haben??
  5243.     }
  5244.     else {
  5245.       FreeRaster(BitMapFullPage.Planes[0], BitMapFullPageWidth, BitMapFullPageHeight);
  5246.     }
  5247. #endif
  5248.     // FullPage ist immer mit AllocRaster() alloziert!
  5249.     FreeRaster(BitMapFullPage.Planes[0], BitMapFullPageWidth, BitMapFullPageHeight);
  5250.     BitMapFullPage.Planes[0] = NULL;
  5251.   }
  5252.  
  5253.   if (is_print) {         /* */
  5254.     abort_print_page();
  5255.   }
  5256.  
  5257.   // Notfiy beenden/freigeben (Signal)
  5258.   EndDVINotify();
  5259.  
  5260.  
  5261. #if defined(APP_WINDOW)
  5262.   clear_app_win();
  5263. #else
  5264.   clear_app_icon();
  5265. #endif
  5266.   dnRexxPort();                    /* close REXX port */
  5267. #if 0
  5268.   DeleteTimer(TimeRequest);
  5269. #endif
  5270.   free_menu();
  5271.   FreeFileReq();
  5272.   CloseRastPort();
  5273.   clear_pointer();
  5274. #if !defined(REQ_LIBRARY)
  5275.   remove_col_request();
  5276. #endif
  5277.   CloseSearchWin();
  5278.   CloseMessWin();
  5279.   ClosePrefWin();
  5280.   AboutWinDown();
  5281.   CloseWin2();
  5282.   FreeHelpLast();    // schliesst etwaiges Amiga-Guide Fenster
  5283.   
  5284.   DeleteShowDVIVars();
  5285.  
  5286.   if (is_myscr && test_anz_windows() > 0 && !is_os2) {
  5287.     MessageStr("FATAL!!!  Close screen with window!?!?!?\n");    /*###########*/
  5288.     LoggingStr("FATAL!!!  Close screen with window!?!?!?\n");    /*###########*/
  5289.     beep();
  5290.   }
  5291.   else {
  5292.     CloseS();
  5293.   }
  5294.   
  5295.   close_fonts();
  5296.   my_task = FindTask(NULL);
  5297.   if (my_task != NULL && old_task_name != NULL) {    /* restore task name */
  5298.     my_task->tc_Node.ln_Name = old_task_name;
  5299.   }
  5300.   CloseLib();
  5301. }
  5302.  
  5303.  
  5304. long *Init_all(int pix_length, int map_width)
  5305. {
  5306.   CloseRastPort();
  5307.   wx = map_width * 8; /* in pixel */
  5308.   wy = pix_length;    /* in pixel */
  5309.  
  5310.  
  5311. /** 
  5312.   static_x_Koo = 0;  that's not good!
  5313.   static_y_Koo = 0;  bleibt sonst nicht an der selben Stelle bei 'load file again' usw.
  5314. **/
  5315.  
  5316.   if (wx & 0x0000000F != 0) {        // % 16
  5317.     Fatal(20, MSG_INTERNAL_ERROR_W_ARG, GetTeXString(MSG_WRONG_MAP_WIDTH));
  5318.   }
  5319. #ifdef DEBUG
  5320.   if (DeBug) {
  5321.      Warning("MAP Breite/Hoehe = %d/%d",wx,wy);
  5322.   }
  5323. #endif
  5324.  
  5325.  
  5326.  
  5327.  
  5328.   set_resolution();        /* set to map-size (if map smaller than screen) */
  5329.   set_i_window_size();
  5330.   init_gad();            /* geaenderte Groesse beruecksichtigen */
  5331.  
  5332. #if 0
  5333.   /* und nun bei col4 muessen noch die Ueberreste geloescht werden, fuer den Fall, dass   */
  5334.   /* die Bitmap groesser wird. Fall einmal die Fenstergroesse mit geaendert wird, so wird */
  5335.   /* das nicht mehr benoetigt.                                  */
  5336.   /* loesche Bildschirm IGITTTTT */
  5337.   fill_block((short)width_left_border,(short)HeightWinTitle,
  5338.             (short)x_win_i_width+poty_up2_Gad.Width-1,
  5339.             (short)x_win_i_height+potx_Gad.Height-1,(short)0);
  5340.   refresh_screen();
  5341. #else
  5342.   win_need_refresh = TRUE;    /* wird erst direkt vor dem erneutem scroll() gemacht */
  5343. #endif
  5344.  
  5345.   OpenRastPort();
  5346.  
  5347. #ifdef FONTS_IN_CHIPMEM
  5348.   /** initialisieren der Bitmap fuer Char-Kopieren */
  5349.   InitBitMap(©_char_bm,1L,1,1);
  5350. #endif
  5351.  
  5352.   return((long *)BitMapWin.Planes[0]);
  5353. }
  5354.  
  5355.  
  5356. long ShowPage(int same_page)
  5357. {
  5358.   long ret;
  5359.   short error;
  5360.   static int static_was_show = 0;
  5361.   static int file_again = FALSE;
  5362.   /* same_page: 0 normal, 1: bin auf selber Seite geblieben */
  5363.  
  5364.  
  5365.   if (InSearchMode) {
  5366.     if (SearchFoundRect) {
  5367.       // es wurde auf dieser Seite etwas gefunden
  5368.       InSearchMode = FALSE;
  5369.       // SearchFoundRect = NULL; (1)
  5370.       SearchFoundPage = current_page_phy;
  5371.       if (SearchWin) SetWindowTitles(SearchWin, GetTeXString(MSG_SEARCHWIN_FOUND), (UBYTE *)-1);
  5372.       return KOMM + 7;        // end search (Springt auf SearchFoundPage)
  5373.     }
  5374.     else {
  5375.       // es wurde nix gefunden, also weitersuchen
  5376.       enum SearchActions sr = DoSearchWin(NULL, 0);
  5377.       
  5378.       if (current_page_phy == SearchStartPage || sr == SEARCHWIN_ACTION_CLOSE || sr == SEARCHWIN_ACTION_CANCEL) {
  5379.         // bin einmal ganz rum und hab nix gefunden
  5380.         ReEnableSearchWin();
  5381.         InSearchMode = FALSE;
  5382.         SearchFoundPage = (current_page_phy == SearchStartPage) ? SearchStartPage : current_page_phy;
  5383.         if (current_page_phy == SearchStartPage) {
  5384.           Message(MSG_SEARCH_STRING_NOT_FOUND, SearchPattern);
  5385.         }
  5386.         else {
  5387.           Message(MSG_SEARCH_STRING_CANCELED);
  5388.         }
  5389.         return KOMM + 7;    // end search (Springt auf SearchFoundPage)
  5390.       }
  5391.       return KOMM + 6;
  5392.     }
  5393.   }
  5394.   else {
  5395.     if (SearchFoundRect) {
  5396.       // es wurde vorhin etwas gefunden, der SuchMode wurde in (1) abgeschaltet, das Rechteck gibt es aber noch.
  5397.       // die Seite wo was gefunden wurde ist nun aufgebaut. Jetzt wird in das Rechteck was gemalt und dann das Rechteck geloescht.
  5398.       long row      = SearchFoundRect->MinY - 1;
  5399.       long num_rows = SearchFoundRect->MaxY - SearchFoundRect->MinY + 2;
  5400.       long col      = (SearchFoundRect->MinX + 7) / 8;
  5401.       long num_cols = (SearchFoundRect->MaxX - col*8) / 8;
  5402.       
  5403.       long map_width = map.width / 8;
  5404.       
  5405.       char * bmp_ptr = ((char *)map.pixptr) + row * map_width + col;
  5406.  
  5407.       int i, j;
  5408.       
  5409.       long l_bits = SearchFoundRect->MinX & 7;
  5410.       long r_bits = SearchFoundRect->MaxX & 7;
  5411.       
  5412.       for (i=0; i<num_rows; i++) {
  5413.         if (l_bits > 0) bmp_ptr[-1] ^= (1<<(8-l_bits)) - 1;
  5414.         for (j=0; j<num_cols; j++) bmp_ptr[j] ^= 0xFF;
  5415.         if (r_bits > 0) bmp_ptr[num_cols] ^= ~((1<<(8-r_bits)) - 1);
  5416.         bmp_ptr += map_width;
  5417.       }
  5418.       
  5419.       if (static_y_Koo > SearchFoundRect->MinY) {
  5420.         int dy = SearchFoundRect->MinY - static_y_Koo - 10;
  5421.         if (is_gadg) window_plus_sbar_move(0, dy);
  5422.         else         window_move(0, dy);
  5423.       }
  5424.       if (static_y_Koo + x_win_i_height < SearchFoundRect->MaxY) {
  5425.         int dy = SearchFoundRect->MaxY - x_win_i_height - static_y_Koo + 10;
  5426.         if (is_gadg) window_plus_sbar_move(0, dy);
  5427.         else         window_move(0, dy);
  5428.       }
  5429.  
  5430.       ReEnableSearchWin();
  5431.       SearchFoundRect = NULL;    // nun ist's endlich vorbei mit der Sucherei
  5432.     }
  5433.   }
  5434.  
  5435.  
  5436.  
  5437.   use_phy_number = is_usephy;
  5438.   unset_tusephy;        /* set if page number via pscro */
  5439.  
  5440.   if (is_messwin) {  
  5441.     SetUpMessWin(FALSE);    /* no delta */
  5442.   }
  5443.   if (!same_page && is_dotbord) {        /* das sollte nur einmal pro Seite gemacht werden! */
  5444.     DrawDottedBorder(FALSE, TRUE);        /* no_refresh .. TRUE */
  5445.   }
  5446.  
  5447.   if (win_need_refresh) {
  5448.     /* und nun bei col4 muessen noch die Ueberreste geloescht werden, fuer den Fall, dass   */
  5449.     /* die Bitmap groesser wird. Fall einmal die Fenstergroesse mit geaendert wird, so wird */
  5450.     /* das nicht mehr benoetigt.                                  */
  5451.     /* loesche Bildschirm IGITTTTT */
  5452.  
  5453.     /* zum Test wird mal so geloescht... */
  5454.     //fill_block((short)width_left_border,(short)HeightWinTitle,
  5455.     //            (short)x_win_i_width-1,(short)x_win_i_height-1,(short)0);
  5456. #if 0
  5457.     fill_block((short)width_left_border,(short)HeightWinTitle,
  5458.                 (short)x_win_i_width+poty_up2_Gad.Width-1,
  5459.                 (short)x_win_i_height+potx_Gad.Height-1,(short)0);
  5460. #endif
  5461.     // ich moechte den Bildschirm nicht loeschen muessen...
  5462.     // es muss reichen, dass ich ein win_show einfach darueber setze.
  5463.     // Moeglicherweise gibt es Probleme bei kleiner-groesser werdenden RPorts
  5464.     // doch das muss ohnehin ueberarbeitet werden...
  5465.     // Die Scrollbars muessen immer an den Fensterraendern bleiben!
  5466.     refresh_screen();
  5467.     win_need_refresh = FALSE;
  5468.   }
  5469.  
  5470.  
  5471.   do {        /* while (error != 0) */
  5472.  
  5473.     error = 0;
  5474.     
  5475.     if (is_dvif) {
  5476.       //pgscroll_Gad.Flags &= ~GFLG_DISABLED;
  5477.     }
  5478.  
  5479.     Set_PgGadPageCur();
  5480.  
  5481. #if 0
  5482.     set_int_gad();            /* no refresh */
  5483.  
  5484.     set_Gadgets_to_fname();        /* no refresh */
  5485. #endif
  5486.  
  5487.     if (is_dvif && dvifp != NULL) {  
  5488.       TempCloseDVI(dvifp);
  5489.     }
  5490.     unset_ndvif;
  5491.  
  5492.  
  5493.     if (is_gadg) {
  5494.       static_x_Koo = HFindScrollerTop();
  5495.       static_y_Koo = VFindScrollerTop();
  5496.     }
  5497.  
  5498.  
  5499.     // Nun gilt es die Seite neu zu positionieren:
  5500.     //
  5501.     // Auch im Full-Page Modus setze ich die Seitenposition neu.
  5502.     //
  5503.     // Ansonsten wird gechecked, ob ein Margin gesetzt ist.
  5504.     // Wenn nicht, dann wird ganz nach links oben gescrolled.
  5505.     // Wenn doch, dann wird an diesen Punkt gescrolled.
  5506.     // Wobei margin_(x|y) in 1000'tel Inch definiert ist.
  5507.     //
  5508.     // An den Margin-Punkt wird nur bei jmpup gesprungen.
  5509.  
  5510.     if (!same_page) {
  5511.       if (is_jmpup) {
  5512.         if (is_margin) {
  5513.           static_x_Koo = show_state.margin_x * hconvresolution / 1000;
  5514.           static_y_Koo = show_state.margin_y * vconvresolution / 1000;
  5515.         }
  5516.         else {
  5517.           static_y_Koo = 0;
  5518.         }
  5519.         unset_jmpup;
  5520.       }
  5521.       if (is_jmpdown) {
  5522.         if (is_margin) {
  5523.           static_x_Koo = show_state.margin_x * hconvresolution / 1000;
  5524.         }
  5525.         static_y_Koo = wy;
  5526.         unset_jmpdown;
  5527.       }
  5528.     }
  5529.     else {
  5530.       unset_jmpup;
  5531.       unset_jmpdown;
  5532.     }
  5533.     
  5534.     if (static_x_Koo < 0) static_x_Koo = 0;
  5535.     if (static_y_Koo < 0) static_y_Koo = 0;
  5536.  
  5537.  
  5538.     /* set scrollbars */
  5539.     VSetScrollerValues();
  5540.     HSetScrollerValues();
  5541.  
  5542.  
  5543.     if (static_was_show == 1) {
  5544.       show_full_page(TRUE);          /* show-Modus einschalten */
  5545.       // Seite einkopieren...
  5546.       display_full_page();               // Seite einkopieren...
  5547.     }
  5548.     else {
  5549.       if (is_gadg) {
  5550.         window_plus_sbar_move(0, 0);    /* setze den Scrollbar richtig */
  5551.       }
  5552.       else {
  5553.         window_move(0, 0);        /* setzt static_{x,y}_Koo richtig */
  5554.       }
  5555.       window_show();            /* loescht noch zusaetzlich was...zeigt aber zum 2.ten Mal an */
  5556.     }
  5557.  
  5558. #if 0
  5559.     else {
  5560.     
  5561.       long lx = static_x_Koo, lxx;
  5562.       long ly = 0;    /* soll ich hoch springen?? */
  5563.  
  5564.       if (is_dvif && (is_new_dvifile || is_chres)) {
  5565.         /* Zentriere den Text, bzw. gehe an den linken Rand */
  5566.         const float widthin  = (float)pwidth_pt  / 72.27 + ((float)SAVETY_BITS_X / (float)hconvresolution) * 1000.0 / (float)mag;
  5567.         
  5568.         ly = -wy;    /* wenn obige Bedingung gegeben ist -> hoch springen */
  5569.         lx = (long)((float)(hoffset_in_fix * wx) / widthin + 0.5);
  5570.         lxx = (long)((((float)pwidth_pt / 72.27) * (float)wx) / widthin + 0.5);
  5571.  
  5572.         /* printf("widthin: %f, lx: %ld, lxx: %ld, x_win_i_width: %ld", widthin, lx, lxx, x_win_i_width); */
  5573.  
  5574.         if (lxx - lx < x_win_i_width) {
  5575.           /* Wenn das innere ganz auf den Screen passt, dann zentrieren! */
  5576.           lx -= (x_win_i_width - (lxx - lx)) / 2;
  5577.         }
  5578.         else {
  5579.           lx -= 5;
  5580.         }
  5581.  
  5582.       }
  5583.  
  5584.       if (is_gadg) {        /* setzt die Grenzen richtig */
  5585.         /* springe auf (lx,0) */
  5586.         if (same_page) {
  5587.           window_plus_sbar_move(0, 0);            /* sind delta Werte! */
  5588.         }
  5589.         else {
  5590.           window_plus_sbar_move(lx-static_x_Koo, ly);    /* sind delta Werte! */
  5591.         }
  5592.         
  5593.       }
  5594.       else {
  5595.         if (same_page) {
  5596.           window_move(0, 0);
  5597.         }
  5598.         else {
  5599.           window_move(lx-static_x_Koo, ly);
  5600.         }
  5601.       }
  5602.       // wird dieser Refresh wirklich benoetigt? Wird doch auch in scroll() gemacht...
  5603.       // window_show();        /* anzeigen <-> refresh */
  5604.     }
  5605. #endif
  5606.  
  5607.     unset_chres;    /* nun ist's aus mit der neuen resolution   */
  5608.               /* bzw. die Info. wird nicht mehr benoetigt */
  5609.  
  5610.  
  5611.     write_status();    /* neue Seitennummer anzeigen */
  5612.  
  5613.     /* ######################################################################### */
  5614.     ret = scroll();                    /* ### main function ### */
  5615.     /* ######################################################################### */
  5616.  
  5617.  
  5618.  
  5619.     if (is_show) {
  5620.       static_was_show = 1;
  5621.       show_full_page(TRUE);  /* show-Modus ausschalten */
  5622.       set_show;
  5623.       write_status();        /* NAJA */
  5624.       unset_show;
  5625.     }
  5626.     else {
  5627.       static_was_show = 0;
  5628.     }
  5629.  
  5630.  
  5631.     /* hab ich ein load-file-again gemacht, wird fuer das zenter in scroll gebraucht */
  5632.     file_again = (ret == KOMM + 3);
  5633.     
  5634.     if (ret == KOMM + 4 && is_autoag && is_notify) {
  5635.       InitDVINotify();    /* notify auf das neue File ausrichten */
  5636.     }
  5637.  
  5638.     if (ret == KOMM + 4 || !is_autoag) {  /* wird fuer das auto-load-again gebraucht! */
  5639.       is_new_dvifile = TRUE;          /* KOMM + 4 == neues DVI-File laden */
  5640.     }                      /* !is_autoag damit das Datum immer richtig gesetzt wird */
  5641.  
  5642.     if (!is_dvif && ret != KOMM+10 && ret != KOMM+4) {
  5643.       error = 1;
  5644.       Message(MSG_NO_DVI_FILE);
  5645.     }
  5646.     else {
  5647.       if (is_dvif && !is_ndvif) {        /* No new DVI-File */
  5648.         TempOpenDVI(&dvifp);
  5649.         if (dvifp == NULL) {
  5650.           unset_dvif;            /* no DVI loadet */
  5651.           Message(MSG_DVI_FILE_LOST);
  5652.           beep();
  5653.           error = 1;
  5654.         }
  5655.       }
  5656.     }
  5657.  
  5658.     if (dvifp == NULL) {        /* savety */
  5659.       unset_dvif;
  5660.     }
  5661.  
  5662.   } while (error != 0);
  5663.   
  5664.   if (ret == -1) {
  5665.     ret = 0;            /* go to page 0 !! */
  5666.   }
  5667.  
  5668.   use_phy_number = (is_usephy || is_tusephy);
  5669.   
  5670.   return ret;
  5671. }
  5672.  
  5673. #endif
  5674.