home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / gfx / misc / imagefx_sdk / sas / examples / printer / skeleton.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-02  |  9.8 KB  |  397 lines

  1. /*
  2.  * Sample Printer Module
  3.  *
  4.  * (Note that this will only work under ImageFX 1.50 and above.)
  5.  *
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <clib/dos_protos.h>
  10. #include <scan/modall.h>
  11.  
  12.  
  13. /**********************************************************************\
  14.  
  15.                            Language Indexes
  16.  
  17. \**********************************************************************/
  18.  
  19. #define TXT(i)             GetStr((i), Default_Strings[(i)])
  20.  
  21. enum {
  22.    TXT_PrintBar,           /* Printer */
  23.    TXT_ModuleName,         /* Skeleton */
  24.    TXT_PrintLabel,         /* Print */
  25.    TXT_ModuleLabel,        /* Module: */
  26.    TXT_COUNT
  27. };
  28.  
  29. char *Default_Strings[] = {
  30.    "Printing",
  31.    "Skeleton",
  32.    "Print",
  33.    "Module:"
  34. };
  35.  
  36. /**********************************************************************\
  37.  
  38.                          GED Gadget Functions
  39.  
  40. \**********************************************************************/
  41.  
  42. /*
  43.  * This function will be called when the user clicks on the Print
  44.  * button.  Normally one would take the main image buffer and output
  45.  * it to some sort of hardcopy device.
  46.  *
  47.  */
  48. int __saveds PrintCode (GedButtonProto)
  49. {
  50.    struct Buffer *buf;
  51.  
  52.    if (buf = ObtainBuffer(0)) {
  53.  
  54.       BeginBar(TXT(TXT_PrintBar), 1, FALSE);
  55.  
  56.       /*
  57.        * This example does nothing.
  58.        */
  59.       Delay(10);
  60.  
  61.       EndBar(NULL);
  62.  
  63.       ReleaseBuffer(buf);
  64.    }
  65.    else {
  66.       Error();
  67.    }
  68.  
  69.    return(0);
  70. }
  71.  
  72. /**********************************************************************\
  73.  
  74.                          GED GUI Description
  75.  
  76. \**********************************************************************/
  77.  
  78. enum {
  79.    ID_Module = 1,
  80.    ID_Print
  81. };
  82.  
  83. struct NewGad newGads[] = {
  84.       /* button to change the scan module */
  85.     { Button_ID, ID_Module, 16,24,102,12, TXT_ModuleName, ChangePrinter,0, NULL, 0,'\0',NULL,0  },
  86.        /* button to initiate scanning */
  87.     { Button_ID, ID_Print, 16,62,102,12, TXT_PrintLabel, PrintCode,0, NULL, 0,'\0',NULL,0 },
  88.        /* text labelling the change-module gadget above */
  89.     { Text_ID, 0, 67,15,0,0, TXT_ModuleLabel, NULL,0,NULL, 2,0,2,0  },
  90.     { End_ID }
  91. };
  92.  
  93. /**********************************************************************\
  94.  
  95.                              Housekeeping
  96.  
  97. \**********************************************************************/
  98.  
  99. BOOL clear_text = FALSE;
  100.  
  101. /*
  102.  * PM_Init()
  103.  *
  104.  * Module initialization function.  ImageFX will call this function
  105.  * when the module is first loaded into memory (once).  Return TRUE
  106.  * if all goes well or FALSE on failure.
  107.  *
  108.  * We need to do a little bit of voodoo magic with the text strings
  109.  * to make the Ged stuff work right.
  110.  *
  111.  */
  112. int __saveds PM_Init (void)
  113. {
  114.    if (ModuleBase->Text == NULL) {
  115.       clear_text = TRUE;
  116.       ModuleBase->Text = Default_Strings;
  117.    }
  118.    return(TRUE);
  119. }
  120.  
  121. /*
  122.  * PM_Cleanup()
  123.  *
  124.  * Cleanup any and all resources, memory, or whatever allocated
  125.  * in the SM_Init() function above.  ImageFX will call this function
  126.  * just before unloading the module.
  127.  *
  128.  */
  129. void __saveds PM_Cleanup (void)
  130. {
  131.    if (clear_text) ModuleBase->Text = NULL;
  132. }
  133.  
  134. /*
  135.  * PM_Show()
  136.  *
  137.  * This function is called when ImageFX displays this module's
  138.  * GUI onscreen.  This can be used as an indicator of when the
  139.  * user "enters" this module (to bring up additional screens or
  140.  * whatever).
  141.  *
  142.  * The window argument is a pointer to ImageFX's main window
  143.  * (where all of this module's gadgets have been added).
  144.  *
  145.  * Return TRUE on success or FALSE on failure.
  146.  *
  147.  */
  148. int __saveds __asm PM_Show (register __a0 struct Window *window)
  149. {
  150.    return(TRUE);
  151. }
  152.  
  153. /*
  154.  * PM_Clear()
  155.  *
  156.  * This function is called when ImageFX is removing this module's
  157.  * GUI from the display.  This can be used as an indicator of when
  158.  * the user "leaves" this module.  Generally you should 'undo' whatever
  159.  * it is you did in the SM_Show() function above.
  160.  *
  161.  * The window argument is a pointer to ImageFX's main window
  162.  * (where all of this module's gadgets have been added).
  163.  *
  164.  */
  165. void __saveds __asm PM_Clear (register __a0 struct Window *window)
  166. {
  167. }
  168.  
  169. /**********************************************************************\
  170.  
  171.                           Preferences Handling
  172.  
  173. \**********************************************************************/
  174.  
  175. /*
  176.  * This structure defines the format for your preferences.  ImageFX
  177.  * will store this structure in the user's prefs files.
  178.  */
  179. struct MyPrefs {
  180.    short Stuff[4];
  181.    LONG  Reserved[8];   /* Always a good idea to reserve some space */
  182. };
  183.  
  184. /*
  185.  * PM_LoadPrefs()
  186.  *
  187.  * Configure your module based on the settings in the supplied
  188.  * preferences structure.  Note that your module does not necessarily
  189.  * have to be displayed for this function to be called, so make sure
  190.  * that your gadgets exist before fiddling with them.  Return TRUE
  191.  * on success, or FALSE on failure.
  192.  *
  193.  */
  194. BOOL __saveds __asm PM_LoadPrefs (register __a0 struct MyPrefs *prefs)
  195. {
  196.    return(TRUE);
  197. }
  198.  
  199. /*
  200.  * PM_SavePrefs()
  201.  *
  202.  * Store your current module configuration into the supplied
  203.  * preferences structure.  ImageFX will then save it to disk.
  204.  *
  205.  */
  206. BOOL __saveds __asm PM_SavePrefs (register __a0 struct MyPrefs *prefs)
  207. {
  208.    return(TRUE);
  209. }
  210.  
  211. /**********************************************************************\
  212.  
  213.                               Miscellaneous
  214.  
  215. \**********************************************************************/
  216.  
  217. /*
  218.  * PM_HandleMMove()
  219.  *
  220.  * Called whenever a MOUSEMOVE event is received by ImageFX that it
  221.  * does not understand.  You can use this to process events for your
  222.  * own windows that you open.
  223.  *
  224.  * The message passed to you is a copy, DO NOT REPLY TO IT!
  225.  *
  226.  * You should return 1 if you knew how to deal with the event, or
  227.  * 0 if you ignored it.
  228.  *
  229.  * You must set the XF_MOUSETRAP flag in your ModuleBase's ExtFlags
  230.  * field (in the UserOpen function below) to use this feature.
  231.  *
  232.  */
  233. int __saveds __asm PM_HandleMMove (register __a0 struct IntuiMessage *msg)
  234. {
  235.    return(0);
  236. }
  237.  
  238. /*
  239.  * PM_HandleMButton()
  240.  *
  241.  * Called whenever a MOUSEBUTTON event is received by ImageFX that it
  242.  * does not understand.  You can use this to process events for your
  243.  * own windows that you open.
  244.  *
  245.  * The message passed to you is a copy, DO NOT REPLY TO IT!
  246.  *
  247.  * You should return 1 if you knew how to deal with the event, or
  248.  * 0 if you ignored it.
  249.  *
  250.  * You must set the XF_MOUSETRAP flag in your ModuleBase's ExtFlags
  251.  * field (in the UserOpen function below) to use this feature.
  252.  *
  253.  */
  254. int __saveds __asm PM_HandleMButton (register __a0 struct IntuiMessage *msg)
  255. {
  256.    return(0);
  257. }
  258.  
  259. /*
  260.  * PM_ChangeNotify()
  261.  *
  262.  * Called whenever the main buffer in ImageFX changes (eg. when the
  263.  * user loads or creates a new image).  This can be used to update
  264.  * display fields that depend on the image in some way.
  265.  *
  266.  * You must set the XF_LOADNOTIFY flag in your ModuleBase's ExtFlags
  267.  * field (in the UserOpen function below) to use this feature.
  268.  *
  269.  * (Requires ImageFX 1.50 or later.)
  270.  *
  271.  */
  272. void __saveds PM_ChangeNotify (void)
  273. {
  274. }
  275.  
  276. /**********************************************************************\
  277.  
  278.                              Arexx Functions
  279.  
  280. \**********************************************************************/
  281.  
  282. /*
  283.  * Sample Arexx command handler.  All printer modules should have a
  284.  * command that starts printing.  This one simply calls the Print
  285.  * gadget's code handler to do the printing.  You should probably
  286.  * do better return code handling.
  287.  */
  288. static int __saveds __stdargs Arexx_Go (ArexxProto)
  289. {
  290.    PrintCode(NULL, NULL, 0);
  291.    return(0);
  292. }
  293.  
  294. /*
  295.  * This table defines all the Arexx commands we understand.  The
  296.  * user sends us Arexx commands via. the ImageFX "PRINTER" command.
  297.  * We must supply a pointer to this table in the UserOpen()
  298.  * function below.
  299.  */
  300. static RXCMD MyRexxCommands[] = {
  301.    { "PRINT",      Arexx_Go,      "" },
  302.    { NULL }
  303. };
  304.  
  305. /**********************************************************************\
  306.  
  307.                          Standard Module Stuff
  308.  
  309. \**********************************************************************/
  310.  
  311.  
  312. /*
  313.  * Function table.  Referenced in "lib.o".
  314.  *
  315.  * The first four entries are the standard library vectors, defined
  316.  * in "lib.o", the remaining entries define functions specific to
  317.  * this module.
  318.  *
  319.  * The table ends with -1.
  320.  *
  321.  */
  322. ULONG FuncTable[] = {
  323.    (ULONG) LibOpen,
  324.    (ULONG) LibClose,
  325.    (ULONG) LibExpunge,
  326.    (ULONG) LibNull,
  327.  
  328.    (ULONG) PM_Init,
  329.    (ULONG) PM_Cleanup,
  330.    (ULONG) PM_Show,
  331.    (ULONG) PM_Clear,
  332.  
  333.    (ULONG) PM_LoadPrefs,
  334.    (ULONG) PM_SavePrefs,
  335.  
  336.    (ULONG) PM_HandleMMove,
  337.    (ULONG) PM_HandleMButton,
  338.  
  339.    (ULONG) PM_ChangeNotify,
  340.  
  341.    (ULONG) 0,              /* reserved */
  342.    (ULONG) 0,              /* reserved */
  343.    (ULONG) 0,              /* reserved */
  344.  
  345.    (ULONG) -1L
  346. };
  347.  
  348. /*
  349.  * ID string for this module.  References in "lib.o".
  350.  *
  351.  * Should be given in the standard 2.0 version string style.
  352.  */
  353. UBYTE LibraryID[] = "$VER: Untitled 1.00.00 (19.6.92)";
  354.  
  355. /*
  356.  * Type of module.  Referenced in "lib.o".
  357.  *
  358.  * Should be one of the NT_* defines in <scan/mod.h>
  359.  *
  360.  */
  361. UBYTE LibraryType = NT_PRINTER;
  362.  
  363. /*
  364.  * Module initialization code.  Referenced by "lib.o".
  365.  *
  366.  * This is where you would initialize the ModuleBase structure that
  367.  * is passed to you.
  368.  *
  369.  * Returns TRUE if all went well, or FALSE if something went wrong and
  370.  * the module open should fail.
  371.  *
  372.  */
  373. LONG __saveds __stdargs UserOpen (struct ModuleBase *modbase)
  374. {
  375.    modbase->NewGad = newGads;                   /* GUI */
  376.    modbase->Language = "Printer_Skeleton";      /* Language tag */
  377.    modbase->LangCount = TXT_COUNT;              /* Number of texts */
  378.    modbase->CmdTable = MyRexxCommands;          /* Arexx cmd table */
  379.    modbase->PrefID = 'PSKL';                    /* Preferences tag */
  380.    modbase->PrefLen = sizeof(struct MyPrefs);   /* Size of prefs data */
  381.    return(TRUE);
  382. }
  383.  
  384. /*
  385.  * Module cleanup code.  Referenced by "lib.o".
  386.  *
  387.  * This should cleanup anything you allocated or opened in UserOpen()
  388.  * above.
  389.  *
  390.  * Always return TRUE.
  391.  *
  392.  */
  393. LONG __saveds __stdargs UserClose (struct ModuleBase *modbase)
  394. {
  395.    return(TRUE);
  396. }
  397.