home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / text / tex / pastex / source / driver / show / amiga / messwin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-04  |  12.3 KB  |  533 lines

  1. /*
  2. **    This file generated by localize 2.9 (AmigaDOS 2.1) from messwin.c
  3. */
  4. #include "defines.h"
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <graphics/gfxbase.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/intuitionbase.h>
  11. #include <libraries/dos.h>
  12.  
  13. #ifdef AZTEC_C
  14. #  include <functions.h>
  15. #endif
  16.  
  17. #include "globals.h"
  18.  
  19. #include <stdlib.h>
  20. #include <clib/intuition_protos.h>
  21. #include <clib/dos_protos.h>
  22. #include <clib/graphics_protos.h>
  23. #include <clib/exec_protos.h>
  24.  
  25. #include <pragmas/intuition_pragmas.h>
  26. #include <pragmas/dos_pragmas.h>
  27. #include <pragmas/graphics_pragmas.h>
  28. #include <pragmas/exec_pragmas.h>
  29.  
  30. #include "amscreen.h"
  31.  
  32. #include "amscreen.i"
  33. #include "amkey.i"
  34. #include "messwin.i"
  35. #include "globals.i"
  36. #include "help.i"
  37. #include "am_menu.i"
  38.  
  39.  
  40. /*
  41.  * Fuer die locale-Library:
  42.  *
  43.  * Hier duerfen *nur* die MSG_#? Nummern eingebunden werden!
  44.  * Achtung:
  45.  * Es muss/sollte 'multiple-include' erlaubt sein!
  46.  */
  47. #include "local.i"
  48.  
  49. #undef  CATCOMP_ARRAY
  50. #undef  CATCOMP_BLOCK
  51. #undef  CATCOMP_STRINGS
  52. #define CATCOMP_NUMBERS
  53. #include "localstr.h"
  54.  
  55.  
  56.  
  57. /*******************************************************************************/
  58. /*                 M E S S W I N D O W                   */
  59. /*******************************************************************************/
  60.  
  61. extern UBYTE sig_messwin;
  62. extern short FullPageLeftEdge;
  63. extern short FullPageTopEdge;
  64. extern short FullPageWidth;
  65. extern short FullPageHeight;
  66.  
  67.  
  68. short MessWinXpos;    /* wird in OpenS() auf -1 gesetzt */
  69. short MessWinYpos;
  70.  
  71. struct Window        *MessWin = NULL;    /* = NULL wichtig, damit wird gearbeitet! */
  72.  
  73.  
  74. static float MessWinHOff;
  75. static float MessWinVOff;
  76. static float MessWinSavetyX;
  77. static float MessWinSavetyY;
  78.  
  79. static void DrawRect(struct RastPort * rp, short x0, short y0, short x1, short y1);
  80.  
  81.  
  82.  
  83. #define MESS_WIN_WIDTH        168
  84. #define MESS_WIN_HEIGHT        68
  85. #define MESS_WIN_LINES        3
  86.  
  87.  
  88. void ToggleMessWin(WORD MouseX, WORD MouseY)
  89. {
  90.   if (!is_messwin) {
  91.     /* das set_messwin wird in der Open Fkt. gemacht.. */
  92.     if (is_dvif) {
  93.       OpenMessWin();
  94.       if (MouseX != -1) {
  95.         WorkMessWin(MouseX, MouseY, FALSE, FALSE);
  96.       }
  97.     }
  98.     else {
  99.       Message(MSG_NO_DVI_FILE);
  100.     }
  101.   }
  102.   else {
  103.     /* das unset_messwin wird in der Close Fkt. gemacht.. */
  104.     WorkMessWin(MouseX, MouseY, FALSE, TRUE);    // Maus hoch
  105.     CloseMessWin();
  106.   }
  107. }
  108.  
  109. void OpenMessWin(void)
  110. {
  111.   struct NewWindow new_win;
  112.   //struct TextAttr textAttr;
  113.   UWORD XSize, YSize;
  114.  
  115.   if (MessWin != NULL) {
  116.     return;
  117.   }
  118.   
  119. #if 0
  120.   if (win2 != NULL) {
  121.     AskFont(win2->RPort, &textAttr);
  122.     YSize = textAttr.ta_YSize;
  123.   }
  124.   else {
  125.     return;    /* naja, sollt eigentlich nicht vorkommen */
  126.   }
  127. #endif
  128.  
  129.   if (win2 == NULL) {
  130.     return;    /* naja, sollt eigentlich nicht vorkommen */
  131.   }
  132.   
  133.   XSize = GfxBase->DefaultFont->tf_XSize;
  134.   YSize = GfxBase->DefaultFont->tf_YSize;
  135.  
  136.   if (MessWinXpos == -1) {
  137.     new_win.LeftEdge = win2->LeftEdge + win2->BorderLeft + 3;
  138.     new_win.TopEdge  = win2->TopEdge + HeightWinTitle + 3;
  139.   }
  140.   else {
  141.     new_win.LeftEdge = MessWinXpos;
  142.     new_win.TopEdge  = MessWinYpos;
  143.   }
  144.   new_win.Width = MESS_WIN_WIDTH+win2->BorderLeft+win2->BorderRight + 21*(XSize-8);
  145.   new_win.Height = win2->BorderTop+win2->BorderBottom+ 6*YSize + 21+4 - 8;    /* ist zwar unlogisch.. */
  146.   new_win.DetailPen = 0;
  147.   new_win.BlockPen = 1; 
  148.   new_win.Title = GetTeXString(MSG_MEASURE_WINDOW);
  149.   new_win.Flags = WFLG_DEPTHGADGET | WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_NOCAREREFRESH | WFLG_RMBTRAP;
  150.   new_win.IDCMPFlags = IDCMP_CLOSEWINDOW | IDCMP_RAWKEY | ((is_amigaguide) ? IDCMP_GADGETHELP : 0);
  151.   new_win.Type = CUSTOMSCREEN;
  152.   if (!is_os2 && !is_ownscr) {
  153.     new_win.Type = WBENCHSCREEN;
  154.   }
  155.   new_win.FirstGadget = NULL;
  156.   new_win.CheckMark = NULL;
  157.   new_win.Screen = screen;
  158.   new_win.BitMap = NULL;
  159.   if (is_amigaguide) {
  160.     MessWin = (struct Window *)OpenWindowTags(&new_win, WA_HelpGroupWindow, win2, TAG_DONE);
  161.   }
  162.   else {
  163.     MessWin = (struct Window *)OpenWindow(&new_win);
  164.   }
  165.   if (MessWin == NULL) {
  166.     unset_messwin;
  167.     Warning(MSG_CANT_OPEN_MESSWIN);
  168.   }
  169.   else {
  170.     set_messwin;        /* MessWin ist da! */
  171.     sig_messwin = MessWin->UserPort->mp_SigBit;
  172.     SetAPen(MessWin->RPort, 1);
  173.     
  174.     SetUpMessWin(FALSE);
  175.  
  176.     add_mmove;
  177.     MyModifyIDCMP(MOUSEMOVE, 0L);
  178.   }
  179.   
  180.   MessWinHOff = hoffset_in * 1000 / mag * 72.27;    /* Speed Improvement */
  181.   MessWinVOff = voffset_in * 1000 / mag * 72.27;
  182.   MessWinSavetyX = (((float)SAVETY_BITS_X / (float)hconvresolution) * 1000.0 / mag) * 72.27 ;
  183.   MessWinSavetyY = (((float)SAVETY_BITS_Y / (float)vconvresolution) * 1000.0 / mag) * 72.27 ;
  184.   
  185.   set_checked_os_menu();
  186. }
  187.  
  188.  
  189. void SetUpMessWin(int delta)
  190. {
  191.   register struct RastPort *rp;
  192.   int x,y;
  193.   UWORD XSize, YSize;
  194.   float hin, vin;
  195.   char str[30];
  196.   char * ptr;
  197.  
  198.   hin = hoffset_in * 1000 / mag;
  199.   vin = voffset_in * 1000 / mag;
  200.  
  201.   if (MessWin != NULL) {
  202.     rp = MessWin->RPort;
  203.     XSize = rp->Font->tf_XSize;
  204.     YSize = rp->Font->tf_YSize;
  205.     x = MessWin->BorderLeft + 3;
  206.     y = MessWin->BorderTop + 3 + YSize;                /* Y + 3 */
  207.     ptr = GetTeXString(MSG_MESSWIN_WIDTH);
  208.     Move(rp, x, y);
  209.     Text(rp, ptr, strlen(ptr));
  210.     y += YSize + 3;                        /* 2Y + 6 */
  211.     if (is_unit_in) {
  212.       sprintf(str,"%4.1f in",(float)pwidth_pt / 72.27 - hin);
  213.     }
  214.     else {
  215.       if (is_unit_cm) {
  216.         sprintf(str,"%4.1f cm",(float)pwidth_pt / 28.54 - hin * 2.54);
  217.       }
  218.       else {
  219.         sprintf(str,"%6d pt",pwidth_pt - (long)(hin * 72.27));
  220.       }
  221.     }
  222.     Move(rp, x+2, y);
  223.     Text(rp,str,(long)strlen(str));
  224.     y += YSize + 5;                        /* 3Y + 11 */
  225.     ptr = GetTeXString(MSG_MESSWIN_HEIGHT);
  226.     Move(rp, x, y);
  227.     Text(rp, ptr, strlen(ptr));
  228.     y += YSize + 3;                        /* 4Y + 14 */
  229.     Move(rp, x+2, y);
  230.     if (is_unit_in) {
  231.       sprintf(str,"%4.1f in",(float)pheight_pt / 72.27 - vin);
  232.     }
  233.     else {
  234.       if (is_unit_cm) {
  235.         sprintf(str,"%4.1f cm",(float)pheight_pt / 28.54 - vin * 2.54);
  236.       }
  237.       else {
  238.         sprintf(str,"%6d pt",pheight_pt - (long)(vin * 72.27));
  239.       }
  240.     }
  241.     Text(rp,str,(long)strlen(str));
  242.  
  243.     x = MessWin->BorderLeft + 90 + 10*(XSize - 8);
  244.     y = MessWin->BorderTop + 3 + YSize;                /* Y + 3 */
  245.     Move(rp, x, y);
  246.     if (delta) {
  247.       ptr = GetTeXString(MSG_MESSWIN_DEL_X);
  248.       Text(rp, ptr, strlen(ptr));
  249.     }
  250.     else {
  251.       ptr = GetTeXString(MSG_MESSWIN_X);
  252.       Text(rp, ptr, strlen(ptr));
  253.     }
  254.     y += 2*YSize + 8;                        /* 3Y + 11 */
  255.     Move(rp, x, y);
  256.     if (delta) {
  257.       ptr = GetTeXString(MSG_MESSWIN_DEL_Y);
  258.       Text(rp, ptr, strlen(ptr));
  259.     }
  260.     else {
  261.       ptr = GetTeXString(MSG_MESSWIN_Y);
  262.       Text(rp, ptr, strlen(ptr));
  263.     }
  264.  
  265.     x = MessWin->BorderLeft +3;
  266.     y += 2*YSize + 10;                        /* 5Y + 21 */
  267.     Move(rp, x, y);
  268.     sprintf(str, GetTeXString(MSG_MESSWIN_MAG), mag);
  269.     Text(rp, str, (long)strlen(str));
  270.   }
  271. }
  272.  
  273.  
  274. void CloseMessWin(void)
  275. {
  276.   if (MessWin != NULL) {
  277.     sub_mmove;
  278.     if (!is_mmove){
  279.       MyModifyIDCMP(0L, MOUSEMOVE);
  280.     }
  281.     MessWinXpos = MessWin->LeftEdge;    /* merke die alte Position */
  282.     MessWinYpos = MessWin->TopEdge;
  283.     CloseWindow(MessWin);
  284.     MessWin = NULL;
  285.     unset_messwin;
  286.   }
  287.  
  288.   set_checked_os_menu();
  289. }
  290.  
  291. static void DrawRect(struct RastPort * rp, short x0, short y0, short x1, short y1)
  292. {
  293.   short X0, Y0, X1, Y1;
  294.  
  295.   Move(rp, x0, y0);
  296.   Draw(rp, x0, y1);
  297.   Draw(rp, x1, y1);
  298.   Draw(rp, x1, y0);
  299.   Draw(rp, x0, y0);
  300.  
  301.   if (x0 < x1) {
  302.     X0 = x0+1;
  303.     X1 = x1-1;
  304.   }
  305.   else {
  306.     X0 = x0-1;
  307.     X1 = x1+1;
  308.   }
  309.   if (y0 < y1) {
  310.     Y0 = y0+1;
  311.     Y1 = y1-1;
  312.   }
  313.   else {
  314.     Y0 = y0-1;
  315.     Y1 = y1+1;
  316.   }
  317.  
  318.   Move(rp, X0, Y0);
  319.   Draw(rp, X0, Y1);
  320.   Move(rp, X1, Y1);
  321.   Draw(rp, X1, Y0);
  322. }
  323.  
  324.  
  325. void WorkMessWin(int mx, int my, int down, int up)
  326. {
  327.   register struct RastPort *rp;
  328.   int x,y;
  329.   UWORD XSize, YSize;
  330.   char *str, buf[30];
  331.   float xpos, ypos;
  332.   int outX, outY;
  333.   struct RastPort * wrp;
  334.   short  mmx, mmy;
  335.   static float oldxpos, oldypos;
  336.   static short oldmx, oldmy;
  337.   static short lastmx, lastmy;
  338.   static short is_down;
  339.   static short has_paint;    // Gummiband ist gezeichnet?
  340.   
  341.   if (!down) {
  342.     // wenn das nicht gerade der Klick nach unten ist, dann wird
  343.     // die aktuellere Maus-Position aus der Window Struktur verwendet.
  344.     mx = win2->MouseX;
  345.     my = win2->MouseY;
  346.   }
  347.  
  348.   if (MessWin != NULL) {
  349.   
  350.     /* zuerst, falls down, das Gummiband loeschen/neuzeichnen */
  351.  
  352.     wrp = win2->RPort;
  353.     mmx = mx;
  354.     if (mx < win2->BorderLeft) {
  355.       mmx = win2->BorderLeft;
  356.     }
  357.     if (mx >= win2->Width-win2->BorderRight) {
  358.       mmx = win2->Width-win2->BorderRight-1;
  359.     }
  360.     mmy = my;
  361.     if (my < win2->BorderTop) {
  362.       mmy = win2->BorderTop;
  363.     }
  364.     if (my >= win2->Height-win2->BorderBottom) {
  365.       mmy = win2->Height-win2->BorderBottom-1;
  366.     }
  367.  
  368.     if (down)  {
  369.       if (has_paint) {        // Huch...!! (kann mal vorkommen) Wegen middle-menu und hide
  370.         SetDrMd(wrp, COMPLEMENT);
  371.         DrawRect(wrp, oldmx, oldmy, lastmx, lastmy);
  372.       }
  373.       oldmx = mmx;
  374.       oldmy = mmy;
  375.       lastmx = lastmy = -1;
  376.       has_paint = FALSE;
  377.     }
  378.     if (is_down)  {
  379.       if (lastmx != mmx || lastmy != mmy) {
  380.         SetDrMd(wrp, COMPLEMENT);
  381.         if (lastmx > 0 && lastmy > 0 && has_paint) {
  382.           DrawRect(wrp, oldmx, oldmy, lastmx, lastmy);
  383.         }
  384.         
  385.         DrawRect(wrp, oldmx, oldmy, mmx, mmy);
  386.         
  387.         lastmx = mmx;
  388.         lastmy = mmy;
  389.         has_paint = TRUE;
  390.       }
  391.     }
  392.     if (up && has_paint)  {
  393.       SetDrMd(wrp, COMPLEMENT);
  394.       DrawRect(wrp, oldmx, oldmy, lastmx, lastmy);
  395.  
  396.       lastmx = lastmy = -1;
  397.       has_paint = FALSE;
  398.     }
  399.  
  400.  
  401.     /* nun den Text formatieren/ausgeben */
  402.  
  403.     rp = MessWin->RPort;
  404.     XSize = rp->Font->tf_XSize;
  405.     YSize = rp->Font->tf_YSize;
  406.     x = MessWin->BorderLeft + 85 + 10*(XSize - 8);
  407.     y = MessWin->BorderTop + 3 + YSize;
  408.     y += YSize + 3;
  409.     
  410.  
  411.     if (down) {
  412.       SetUpMessWin(TRUE);
  413.       is_down = TRUE;
  414.     }
  415.     if (up) {
  416.       SetUpMessWin(FALSE);
  417.       is_down = FALSE;
  418.     }
  419.  
  420.     if (is_show) {
  421.       xpos = ((mx - FullPageLeftEdge) * ((float)pwidth_pt + MessWinSavetyX)) / FullPageWidth;
  422.       ypos = ((my - FullPageTopEdge) * ((float)pheight_pt + MessWinSavetyY)) / FullPageHeight;
  423.       outX = (mx < FullPageLeftEdge || mx > FullPageLeftEdge + FullPageWidth);
  424.       outY = (my < FullPageTopEdge  || my > FullPageTopEdge + FullPageHeight);
  425.     }
  426.     else {
  427.       outX = (mx < Page_LeftPoint || mx >= Page_RightPoint);
  428.       outY = (my < Page_TopPoint  || my >= Page_BottomPoint);
  429.       xpos = ((float)(static_x_Koo + mx - Page_LeftPoint) * ((float)pwidth_pt +    MessWinSavetyX)) / (float)wx;
  430.       ypos = ((float)(static_y_Koo + my - Page_TopPoint) * ((float)pheight_pt +    MessWinSavetyY)) / (float)wy;
  431.     }
  432.  
  433.     xpos -= MessWinHOff;    /* diese Variablen werden beim Fenster oeffnen berechnet */
  434.     ypos -= MessWinVOff;
  435.     
  436.  
  437.     if (down){
  438.       oldxpos = xpos;
  439.       oldypos = ypos;
  440.     }
  441.     if (is_down) {
  442.       xpos = xpos - oldxpos;
  443.       ypos = ypos - oldypos;
  444.     }
  445.  
  446.     if (outX) {
  447.       str = "         ";
  448.     }
  449.     else {
  450.       if (is_unit_in) {
  451.         sprintf(buf,"%6.2f in",(float)xpos / 72.27);
  452.       }
  453.       else {
  454.         if (is_unit_cm) {
  455.           sprintf(buf,"%6.2f cm",(float)xpos / 28.54);
  456.         }
  457.         else {
  458.           sprintf(buf,"%6d pt",(long)xpos);
  459.         }
  460.       }
  461.       str = &(buf[0]);
  462.     }
  463.     Move(rp, x+2, y);
  464.     Text(rp,str,(long)strlen(str));
  465.  
  466.     y += YSize + 5;
  467.     y += YSize + 3;
  468.     if (outY) {
  469.       str = "         ";
  470.     }
  471.     else {
  472.       if (is_unit_in) {
  473.         sprintf(buf,"%6.2f in",(float)ypos / 72.27);
  474.       }
  475.       else {
  476.         if (is_unit_cm) {
  477.           sprintf(buf,"%6.2f cm",(float)ypos / 28.54);
  478.         }
  479.         else {
  480.           sprintf(buf,"%6d pt",(long)ypos);
  481.         }
  482.       }
  483.       str = &(buf[0]);
  484.     }
  485.     Move(rp, x+2, y);
  486.     Text(rp,str,(long)strlen(str));
  487.   }
  488. }
  489.  
  490.  
  491. long MessWinMsg(void)
  492. {
  493.   struct IntuiMessage *msg;
  494.   ULONG msg_class;
  495.   UWORD    Code,Qualifier;
  496.   WORD    MouseX, MouseY;
  497.   int cont = 1;
  498.   long ex = 0;
  499.  
  500.   if (MessWin == NULL) {
  501.     return ex;
  502.   }
  503.  
  504.   while(cont && (msg = (struct IntuiMessage *)GetMsg(MessWin->UserPort))!=NULL) {
  505.  
  506.     msg_class    = msg->Class;
  507.     Code      = msg->Code;
  508.     Qualifier    = msg->Qualifier;
  509.     MouseX    = msg->MouseX;
  510.     MouseY    = msg->MouseY;
  511.  
  512.     switch (msg_class) {
  513.       case IDCMP_CLOSEWINDOW:
  514.       cont = 0;
  515.       break;
  516.       case IDCMP_RAWKEY:
  517.     ex = work_with_raw_key(Code, Qualifier, MouseX, MouseY);
  518.     break;
  519.       case IDCMP_GADGETHELP:
  520.         work_with_gadgethelp(msg);
  521.         break;
  522.     }
  523.  
  524.     ReplyMsg(&(msg->ExecMessage));
  525.   }
  526.   if (!cont) {
  527.     WorkMessWin(MouseX, MouseY, FALSE, TRUE);    // Maus hoch
  528.     CloseMessWin();
  529.   }
  530.   
  531.   return ex;
  532. }
  533.