home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fonts 1 / freshfonts1.bin / programs / amiga / pastex / src / specialhost / specialwin.c < prev    next >
C/C++ Source or Header  |  1991-07-25  |  34KB  |  1,409 lines

  1. /* *** specialwin.c *** */
  2.  
  3.  
  4. #include "specialhost.h"
  5.  
  6. static struct TextFont    *font = NULL;
  7. static struct TextAttr    txtAttr;
  8.  
  9. #include "specialwin.h"
  10.  
  11.  
  12.  
  13. /**------------------*** Icon Data ***------------------**/
  14.  
  15. static USHORT  __chip imageData1[] = {
  16.  0x0000, 0x0000, 0x0000, 0x0000,
  17.  0x0000, 0x0000, 0x0000, 0x0001,
  18.  0x0000, 0x0000, 0x0000, 0x0001,
  19.  0x0000, 0x0000, 0x0000, 0x0001,
  20.  0x0000, 0x0000, 0x0000, 0x0001,
  21.  0x0000, 0x0000, 0x0000, 0x0001,
  22.  0x0000, 0x0000, 0x0000, 0x0001,
  23.  0x0000, 0x0000, 0x0000, 0x0001,
  24.  0x0000, 0x0000, 0x0000, 0x0001,
  25.  0x0000, 0x0000, 0x0000, 0x0001,
  26.  0x0000, 0x0000, 0x0000, 0x0001,
  27.  0x0000, 0x0000, 0x0000, 0x0001,
  28.  0x0000, 0x0000, 0x0000, 0x0001,
  29.  0x0000, 0x0000, 0x0000, 0x0001,
  30.  0x0000, 0x0000, 0x07FE, 0x0001,
  31.  0x0100, 0x0000, 0x0402, 0x0001,
  32.  0x0380, 0x0000, 0x07FE, 0x0001,
  33.  0x0540, 0x0000, 0x0402, 0x0001,
  34.  0x0100, 0x0000, 0x01DC, 0x0001,
  35.  0x0000, 0x0000, 0x0402, 0x0001,
  36.  0x0100, 0x0000, 0x07DA, 0x0001,
  37.  0x0100, 0x0000, 0x0400, 0x0001,
  38.  0x0100, 0x0000, 0x07DA, 0x0001,
  39.  0x0100, 0x00F7, 0x4402, 0x0001,
  40.  0x0100, 0x00C0, 0x41DA, 0x0001,
  41.  0x0100, 0x0092, 0x4402, 0x0001,
  42.  0x0100, 0x00A4, 0xC7FE, 0x0001,
  43.  0x011F, 0xF8C9, 0x4402, 0x0001,
  44.  0x0115, 0x5892, 0x47FE, 0x00C1,
  45.  0x011A, 0xA8A4, 0xC402, 0x0061,
  46.  0x1FFF, 0xFFFF, 0xFFFF, 0xFFF1,
  47.  0x0100, 0x0000, 0x0000, 0x0061,
  48.  0x0100, 0x0000, 0x0000, 0x00C1,
  49.  0x0000, 0x0000, 0x0000, 0x0001,
  50.  0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF,
  51. /**/
  52.  0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
  53.  0x8000, 0x0000, 0x0000, 0x0000,
  54.  0x8000, 0x0000, 0x0000, 0x0000,
  55.  0x8000, 0x0000, 0x0000, 0x0000,
  56.  0x8FFC, 0x0E1C, 0x0000, 0x0000,
  57.  0x88C4, 0x0B34, 0x0000, 0x0000,
  58.  0x80C0, 0x01E0, 0x0000, 0x0000,
  59.  0x80CF, 0xC0C0, 0x7800, 0x0000,
  60.  0x80CC, 0x41E0, 0x0000, 0x0000,
  61.  0x80CC, 0x0B34, 0x0000, 0x0000,
  62.  0x80CF, 0x8E1C, 0x0000, 0x0000,
  63.  0x800C, 0x0000, 0x0000, 0x0000,
  64.  0x800C, 0x4000, 0x0000, 0x0000,
  65.  0x800F, 0xC000, 0x0000, 0x0000,
  66.  0x8000, 0x0000, 0x07FE, 0x0000,
  67.  0x8100, 0x0000, 0x0402, 0x0000,
  68.  0x8380, 0x0000, 0x07FE, 0x0000,
  69.  0x8540, 0x0000, 0x0402, 0x0000,
  70.  0x8301, 0xC38F, 0x0FFF, 0x8800,
  71.  0x8102, 0x2448, 0x9526, 0x4800,
  72.  0x8182, 0x0448, 0x17FE, 0x4800,
  73.  0x8141, 0xC78F, 0x1427, 0xC800,
  74.  0x8120, 0x2408, 0x17FE, 0x4800,
  75.  0x8112, 0x24FF, 0xD526, 0x4900,
  76.  0x8109, 0xC4CF, 0x4FFE, 0x4F00,
  77.  0x8100, 0x0092, 0x4402, 0x0000,
  78.  0x8100, 0x00A4, 0xC7FE, 0x0000,
  79.  0x811F, 0xF8C9, 0x4402, 0x0000,
  80.  0x8115, 0x5892, 0x47FE, 0x00C0,
  81.  0x811A, 0xA8A4, 0xC402, 0x0060,
  82.  0x9FFF, 0xFFFF, 0xFFFF, 0xFFF0,
  83.  0x8100, 0x0000, 0x0000, 0x0060,
  84.  0x8100, 0x0000, 0x0000, 0x00C0,
  85.  0x8000, 0x0000, 0x0000, 0x0000,
  86.  0x0000, 0x0000, 0x0000, 0x0000,
  87. /**/
  88.  };
  89.  
  90. struct Image image1 = {
  91.   0,            /* LeftEdge */
  92.   0,            /* TopEdge */
  93.   ICON_WIDTH,        /* Width */
  94.   ICON_HEIGHT,        /* Height */
  95.   2,            /* Depth */
  96.   NULL,            /* ImageData */
  97.   0x3,            /* PlanePick */
  98.   0x0,            /* PlaneOnOff */
  99.   0,            /* [NextImage] */
  100.  };
  101.  
  102.  
  103.  
  104.  
  105. struct scroll_win  {
  106.     struct    scroll_text    *top;        /* first viewed line */
  107.     struct    scroll_text    *first_free;
  108.         long        number;        /* number of used lines in buffer */
  109.         long        displayed;    /* number of displayed lines */
  110.   };
  111.  
  112. struct scroll_text {
  113.         char        *line;
  114.     struct  scroll_text    *next_line;
  115.     struct  scroll_text    *prev_line;
  116.         short        is_first;    /* is first line in buffer */
  117.         short        is_last;    /* is last line in buffer */
  118.   };
  119.  
  120. #ifdef LATTICE
  121. extern    long    _stack;
  122. extern    char *    _procname;
  123. extern    long    _priority;
  124. extern    long    _BackGroundIO;
  125. extern    BPTR    _Backstdout;
  126. #endif
  127.  
  128. struct Library        *IFFBase    = NULL;
  129. struct GfxBase        *GfxBase    = NULL;
  130. struct IntuitionBase    *IntuitionBase    = NULL;
  131.  
  132. extern struct MsgPort         *special_port;
  133. extern IFFFILE            ifffile;
  134. extern struct BitMap        *bmap;
  135. extern short            use_blitter;
  136. extern short            invert_bmap;
  137. extern short            is_os2;
  138. extern short            ECS_chips;
  139.  
  140. static short            use_pubscr = FALSE;
  141.  
  142. static struct Window        *win = NULL;
  143. static UBYTE            sig_win;
  144. static struct Window        *icon = NULL;
  145. static struct scroll_win    swin;
  146. static           int        display_len;
  147. static           int        lines_to_show;
  148. static          int        height_char;
  149. static          int        width_char;
  150. static          int        icon_x_pos;
  151. static          int        icon_y_pos;
  152. static          int        win_x_pos;
  153. static          int        win_y_pos;
  154. static          int        win_width;
  155. static          int        win_height;
  156. static          int        win_title_height;
  157.  
  158. static          char        copyright[] = "SpecialHost Version "VERSION", last compiled: "__DATE__;
  159. static          char        PubScreenName[] = "ShowDVI-PubScr";
  160.  
  161.  
  162. static struct TagItem         pub_window_tags[] = {
  163.             { WA_ScreenTitle,    &(copyright[0])        },
  164.             { WA_AutoAdjust,    TRUE            },
  165.             { WA_PubScreenName,    &(PubScreenName[0])    },
  166.             { WA_PubScreenFallBack,    TRUE            },
  167.             { TAG_DONE,        0L            }
  168.         };
  169.  
  170.  
  171.  
  172. static void    OpenI            (void);
  173. static void    OpenG            (void);
  174. static void    OpenLib            (void);
  175. static void    CloseLib        (void);
  176. static void    CloseWin        (void);
  177. static int    get_wb_screen_data    (int *BarHeight);
  178. static void    CloseTopaz        (void);
  179. static void    OpenTopaz        (void);
  180. static void    CloseIcon        (void);
  181. static UBYTE    OpenIcon        (void);
  182. static UBYTE    OpenWin            (void);
  183. static UBYTE    ReOpenAll        (int draw_modus, int base_dpi);
  184. static void    refresh_draw_modus    (int draw_modus, int base_dpi);
  185. static void    set_picture_draw_modus    (long nr, int *draw_modus, int *base_dpi);
  186. static void    DrawWin            (void);
  187. static long    keys            (struct IntuiMessage *msg);
  188. static void    getShowDVI        (void);
  189. static long    WindowMessage        (int *draw_modus, int *base_dpi);
  190. static void    init_text        (void);
  191. static void    DisplayText        (void);
  192. static void    ScrollUp        (void);
  193. static void    ScrollDown        (void);
  194. static FILE    *OpenConfigFile        (char *name, char *modus);
  195. static void    ReadConfig        (int *draw_modus, int *base_dpi);
  196. static void    SaveConfig        (int draw_modus, int base_dpi);
  197.  
  198.  
  199.  
  200.  
  201. void close_all(void)
  202. {
  203.   close_port_bitm();
  204.   CloseWin();
  205.   CloseIcon();
  206.   CloseTopaz();
  207.   CloseLib();
  208.   if (_Backstdout) {
  209.     Close(_Backstdout);
  210.     _Backstdout = NULL;
  211.   }
  212. }
  213.  
  214. void Fatal(int nr)
  215. {
  216.   long ret;
  217.   char *message;
  218.   char str[64];
  219.   
  220.   switch (nr) {
  221.     case NO_INTUI:
  222.         message = "can't open Intuition-Library!";
  223.         ret = 20;
  224.         break;
  225.     case NO_GFX:
  226.         message = "can't open Graphics-Library!";
  227.         ret = 20;
  228.         break;
  229.     case LINE_TO_LONG:
  230.         message = "line too long!!!";
  231.         ret = 20;
  232.         break;
  233.     case NO_WIN:
  234.         message = "can't open window!";
  235.         ret = 15;
  236.         break;
  237.     case NO_ICON:
  238.         message = "can't open icon-window!";
  239.         ret = 15;
  240.         break;
  241.     case NO_MEMORY:
  242.         message = "not enough memory!";
  243.         ret = 15;
  244.         break;
  245.     case NOT_FIRST:
  246.     message = "SpecialHost already running!";
  247.     ret = 5;
  248.     break;
  249.     case NO_PORT:
  250.         message = "can't open message-port!";
  251.         ret = 10;
  252.         break;
  253.     case NO_MESSAGE:
  254.         message = "signal without message??";
  255.         ret = 15;
  256.         break;
  257.     case NO_MEM:
  258.         message = "no memory!";
  259.         ret = 10;
  260.         break;
  261.     case NO_OK_BIT:
  262.         message = "expect AC_OK_BITMAP!";
  263.         ret = 10;
  264.         break;
  265.     default:
  266.         message = "unknown error!?";
  267.         ret = 20;
  268.         break;
  269.   }
  270.   sprintf(str, "Fatal: %s\n", message);
  271.  
  272.   if (_Backstdout) {
  273.     Write(_Backstdout, str, strlen(str));
  274.   }
  275.   else {
  276.     if (win != NULL) {
  277.       pline(message);    /* a little bit hacky!!!! */
  278.       Delay(50);
  279.     }
  280.   }
  281.  
  282.   close_all();
  283.   exit(ret);
  284. }
  285.  
  286. static void OpenI(void)
  287. {
  288.   IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
  289.   if (IntuitionBase==NULL) {
  290.     Fatal(NO_INTUI);
  291.   }
  292.   is_os2 = IntuitionBase->LibNode.lib_Version >= 36L;
  293. }
  294.  
  295. static void OpenG(void)
  296. {
  297.   GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
  298.   if (GfxBase==NULL) {
  299.     Fatal(NO_GFX);
  300.   }
  301.   if (is_os2) {
  302.     ECS_chips = GfxBase->ChipRevBits0;
  303.   }
  304. }
  305.  
  306. static void OpenLib(void)
  307. {
  308. #ifndef LATTICE
  309.   int bytes;
  310. #endif
  311.  
  312.   OpenI();
  313.   OpenG();
  314.  
  315. #ifdef LATTICE
  316.   image1.ImageData = (USHORT *)&imageData1;
  317. #else
  318.   bytes = ICON_HEIGHT * ICON_WIDTH * 2 / 8;
  319.   image1.ImageData = AllocMem(bytes, MEMF_CHIP | MEMF_PUBLIC);
  320.   if (image1.ImageData == NULL) {
  321.     Fatal(NO_MEMORY);
  322.   }
  323.   memcpy((char *)image1.ImageData, (char *)imageData1, bytes);
  324. #endif
  325. }
  326.  
  327. static void CloseLib(void)
  328. {
  329. #ifndef LATTICE
  330.   if (image1.ImageData) != NULL) {
  331.     FreeMem(image1.ImageData, ICON_HEIGHT * ICON_WIDTH * 2 / 8);
  332.   }
  333. #endif
  334.  
  335.   if (IFFBase != NULL) CloseLibrary(IFFBase);
  336.   if (IntuitionBase != NULL) CloseLibrary((stru