home *** CD-ROM | disk | FTP | other *** search
/ swCHIP 1991 January / swCHIP_95-1.bin / utility / gsview13 / src / gvpm.h < prev    next >
C/C++ Source or Header  |  1995-12-09  |  13KB  |  476 lines

  1. /* Copyright (C) 1993, 1994, 1995, Russell Lang.  All rights reserved.
  2.   
  3.   This file is part of GSview.
  4.   
  5.   This program is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the GSview Free Public Licence 
  9.   (the "Licence") for full details.
  10.   
  11.   Every copy of GSview must include a copy of the Licence, normally in a 
  12.   plain ASCII text file named LICENCE.  The Licence grants you the right 
  13.   to copy, modify and redistribute GSview, but only under certain conditions 
  14.   described in the Licence.  Among other things, the Licence requires that 
  15.   the copyright notice and this notice be preserved on all copies.
  16. */
  17.  
  18. /* gvpm.h */
  19. /* Header includes for PM GSview */
  20.  
  21. #define INCL_DOS
  22. #define INCL_WIN
  23. #define INCL_GPI
  24. #define INCL_DOSERRORS
  25. #include <os2.h>
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <ctype.h>
  30. #include <io.h>
  31. #include <fcntl.h>
  32. #include <sys/types.h>
  33. #include <sys/stat.h>
  34. #include <time.h>
  35. #ifdef __BORLANDC__
  36. #include <dir.h>
  37. #include <process.h>
  38. #endif
  39. #define NeedFunctionPrototypes 1
  40. #include "gvcrc.h"
  41. #include "gdevpm.h"
  42.  
  43.  
  44. #ifndef RC_INVOKED
  45.  
  46. typedef unsigned short WORD;
  47. typedef unsigned long DWORD;
  48. #include "ps.h"
  49.  
  50. #define MAXSTR 256    /* maximum file name length and general string length */
  51. #define PROFILE_SIZE 2048
  52. #define DEFAULT_GSCOMMAND "gsos2.exe"
  53. #define DEFAULT_RESOLUTION 96.0
  54. #define DEFAULT_ZOOMRES 300.0
  55. #define HELPFILE "gvpm.hlp"
  56. #define INIFILE "gvpm.ini"
  57. #define INISECTION "Options"
  58. #define DEVSECTION "Devices"
  59. #define EOLSTR "\r\n"
  60. #define CW_USEDEFAULT 32768
  61. #define COPY_BUF_SIZE 4096
  62. /* don't have to worry about segments/selectors */
  63. #define GVFAR
  64. #define GVHUGE
  65. #define IDYES MBID_YES
  66. #define IDOK  MBID_OK
  67. #define IDCANCEL  MBID_CANCEL
  68.  
  69. #define WM_GSUPDATING  WM_USER+GS_UPDATING
  70. #define WM_GSSYNC      WM_USER+GS_SYNC
  71. #define WM_GSPAGE      WM_USER+GS_PAGE
  72. #define WM_GSCLOSE     WM_USER+GS_CLOSE
  73. #define WM_GSERROR     WM_USER+GS_ERROR
  74. #define WM_GSPALCHANGE WM_USER+GS_PALCHANGE
  75. #define WM_GSBEGIN     WM_USER+GS_BEGIN
  76. #define WM_GSEND       WM_USER+GS_END
  77. #define WM_GSPRNEXIT   WM_USER+GS_PALCHANGE+10
  78.  
  79. #define ID_STATUSBAR   100
  80. #define ID_BUTTONBAR   101
  81.  
  82. #ifndef min
  83. #define min(x,y)  ( (x) < (y) ? (x) : (y) )
  84. #endif
  85. #ifndef max
  86. #define max(x,y)  ( (x) > (y) ? (x) : (y) )
  87. #endif
  88.  
  89. /* program details */
  90. typedef struct tagPROG {
  91.     BOOL    valid;
  92.     FILE    *input;        /* pipe to stdin */
  93.     ULONG    session_id;
  94.     PID        process_id;
  95. } PROG;
  96.  
  97. /* bitmap details */
  98. typedef struct tagBM {
  99.     BOOL    valid;
  100.     BOOL    old_bmp;    /* bitmap type */
  101.     PBITMAPINFO2 pbmi;        /* pointer to bitmap info */
  102.     PBYTE    bits;        /* pointer to bitmap bits */
  103.     int        width;
  104.     int        height;
  105.     int        planes;
  106.     int        depth;
  107.     int        palsize;
  108.     int     palimportant;
  109.     int        old_width;
  110.     int        old_height;
  111.     int        old_planes;
  112.     int        old_depth;
  113.     int        old_palsize;
  114.     int        old_palimportant;
  115. } BMAP;
  116.  
  117. typedef struct document PSDOC;
  118.  
  119. typedef struct tagPSBBOX {
  120.     int    llx;
  121.     int    lly;
  122.     int    urx;
  123.     int    ury;
  124.     int    valid;
  125. } PSBBOX;
  126.  
  127. typedef struct tagGV {
  128.     PID        pid;        /* process id of GSview */
  129.     char        id[MAXSTR];    /* string id of GSview */
  130.     HQUEUE        queue;        /* queue for messages from GS */
  131.     HEV        next_event;    /* semaphore for Next Page */
  132.     HMTX        bmp_mutex;    /* mutex for access to bitmap */
  133.     HQUEUE        term_queue;    /* termination queue for child sessions */
  134.     char        term_queue_name[MAXSTR];  /* termination queue name */
  135. } GVIEW;
  136.  
  137. typedef struct tagPSFILE {
  138.     BOOL    ignore_dsc;    /* true if DSC to be ignored */
  139.     PSDOC    *doc;        /* DSC structure.  NULL if not DSC */
  140.     int     pagenum;    /* current page number */
  141.     char     name[MAXSTR];    /* name of selected document file */
  142.     FILE     *file;        /* selected file */
  143.     BOOL    ctrld;        /* TRUE if file starts with ^D */
  144.     int     preview;    /* preview type IDS_EPSF, IDS_EPSI, etc. */
  145. #ifdef _Windows
  146.     struct    ftime datetime;    /* time/date of selected file */
  147. #else
  148.     time_t    datetime;    /* time/date of selected file */
  149. #endif
  150.     long    length;        /* length of selected file */
  151.     char    previous_name[MAXSTR];
  152.     BOOL    previous_was_dsc;
  153.     long    previous_begintrailer;
  154.     long    previous_endtrailer;
  155.     BOOL    ispdf;        /* true if PDF document */
  156.     char     pdftemp[MAXSTR]; /* name of temporary DSC file */
  157. } PSFILE;
  158.  
  159. /* options that are saved in INI file */
  160. typedef struct tagOPTIONS {
  161.     char    gscommand[MAXSTR];
  162.     int    gsversion;
  163.     POINTL    img_origin;
  164.     POINTL    img_size;
  165.     BOOL    img_max;
  166.     int    unit;
  167.     BOOL    quick;
  168.     BOOL    settings;
  169.     BOOL    button_show;
  170.     BOOL    fit_page;
  171.     BOOL    safer;
  172.     int    media;
  173.     char    medianame[32];
  174.     int    user_width;
  175.     int    user_height;
  176.     BOOL    epsf_clip;
  177.     BOOL    epsf_warn;
  178.     BOOL    redisplay;
  179.     BOOL    ignore_dsc;
  180.     BOOL    show_bbox;
  181.     int    orientation;
  182.     BOOL    swap_landscape;
  183.     float    xdpi;
  184.     float    ydpi;
  185.     float    zoom_xdpi;
  186.     float    zoom_ydpi;
  187.     int    depth;
  188.     BOOL    save_dir;
  189.     char    device_name[32];
  190.     char    device_resolution[32];
  191.     char    printer_port[32];
  192. } OPTIONS;
  193.  
  194. typedef struct tagDISPLAY {
  195.     BOOL    abort;
  196.     BOOL    busy;
  197.     ULONG    id;
  198.     HEV    done;
  199.     int    width;
  200.     int    height;
  201.     LONG    planes;
  202.     LONG    bitcount;
  203.     BOOL    do_endfile;    
  204.     BOOL    do_resize;
  205.     BOOL    do_display;
  206.     BOOL    epsf_clipped;    /* display is clipped to bbox */
  207.     int    zoom_xoffset;    /* in 1/72" */
  208.     int    zoom_yoffset;
  209.     POINTL    offset;    
  210.     BOOL    saved;        /* interpreter state saved */
  211.     BOOL    page;        /* GS_PAGE received */
  212.     BOOL    sync;        /* GS_SYNC received */
  213.     BOOL    end;        /* GS_END received */
  214.     LONG    hasPalMan;    /* Palette Manager */
  215.     BOOL    hpal_exists;
  216.     HPAL    hpal;
  217. } DISPLAY;
  218.  
  219. typedef struct tagPRINTER {
  220.     PROG    prog;        /* Ghostscript program doing printing */
  221.     char    cfname[MAXSTR]; /* file storing command line options */
  222.     char    fname[MAXSTR];    /* file storing temporary postscript */
  223.     ULONG    tid;        /* Thread ID which waits for GS to exit */
  224. } PRINTER;
  225.  
  226. struct prfentry {
  227.     char *name;
  228.     char *value;
  229.     struct prfentry *next;
  230. };
  231.  
  232. struct prfsection {
  233.     char *name;
  234.     struct prfentry *entry;
  235.     struct prfsection *next;
  236. };
  237.  
  238. struct prop_item_s {
  239.     char    name[MAXSTR];
  240.     char    value[MAXSTR];
  241. };
  242.  
  243. typedef struct tagPROFILE {
  244.     char *name;
  245.     FILE *file;
  246.     BOOL changed;
  247.     struct prfsection *section;
  248. } PROFILE;
  249.  
  250. /* button bar */
  251. struct button {
  252.     int    id;
  253.     RECTL    rect;
  254.     HBITMAP    hbitmap;
  255.     char    str[16];
  256.     struct button *next;
  257. };
  258. extern struct button *buttonhead, *buttontail;
  259. extern BOOL button_down;
  260. extern struct button *button_current;
  261. extern POINTL button_shift;
  262. extern POINTL button_size;
  263.  
  264. extern BOOL debug;            /* /D command line option used */
  265. extern FILE *debug_file;        /* for gs input logging */
  266. struct page_list_s {
  267.     int current;    /* index of current selection */
  268.     BOOL multiple;    /* true if multiple selection allowed */
  269.     BOOL *select;    /* array of selection flags */
  270. };
  271. extern struct page_list_s page_list;
  272.  
  273. #define SOUND_PAGE 0
  274. #define SOUND_NOPAGE 1
  275. #define SOUND_NONUMBER 2
  276. #define SOUND_NOTOPEN 3
  277. #define SOUND_ERROR 4
  278. #define SOUND_TIMEOUT 5
  279. #define SOUND_START 6
  280. #define SOUND_EXIT 7
  281. #define NUMSOUND 8
  282. struct sound_s {
  283.     char *entry;        /* profile entry */
  284.     int title;        /* Resource string */
  285.     char file[MAXSTR];    /* empty, "beep", or .WAV sound to play */
  286. };
  287. extern struct sound_s sound[NUMSOUND];
  288. #define BEEP "beep"        /* profile entry for a speaker beep */
  289. typedef ULONG (* PFN_MciPlayFile)(HWND hwndOwner, PSZ pszFile, ULONG ulFlags,
  290.     PSZ pszTitle, HWND hwndViewport);
  291. extern PFN_MciPlayFile pfnMciPlayFile;
  292.  
  293. extern char szAppName[MAXSTR];
  294. extern char szHelpTopic[MAXSTR];
  295. extern char szExePath[MAXSTR];
  296. extern char szHelpFile[MAXSTR];
  297. extern char szWait[MAXSTR];
  298. extern char szFindText[MAXSTR];
  299. extern char szIniFile[MAXSTR];
  300. extern char szMMini[MAXSTR];
  301. extern char previous_filename[MAXSTR];    /* to remember name between file dlg boxes */
  302. extern const char szScratch[];    /* temporary filename prefix */
  303. extern ULONG os_version;
  304. extern HAB hab;
  305. extern HWND hwnd_frame;
  306. extern HWND hwnd_bmp;
  307. extern HWND hwnd_status;
  308. extern HWND hwnd_button;
  309. extern HWND hwnd_help;
  310. extern HWND hwnd_modeless;        /* any modeless dialog box */
  311. extern HWND hptr_crosshair;
  312. extern POINTL buttonbar;
  313. extern POINTL statusbar;
  314. extern POINTL info_file;
  315. extern POINTL info_page;
  316. extern RECTL info_coord;
  317. extern BOOL waiting;
  318. extern TID queue_tid;
  319. extern TID term_tid;
  320. VOID APIENTRY queue_thread(ULONG unused);
  321. VOID APIENTRY term_thread(ULONG unused);
  322. MRESULT EXPENTRY ClientWndProc(HWND, ULONG, MPARAM, MPARAM);
  323. MRESULT EXPENTRY FrameWndProc(HWND, ULONG, MPARAM, MPARAM);
  324. MRESULT EXPENTRY StatusWndProc(HWND, ULONG, MPARAM, MPARAM);
  325. MRESULT EXPENTRY ButtonWndProc(HWND, ULONG, MPARAM, MPARAM);
  326. extern PFNWP OldFrameWndProc;
  327.  
  328.  
  329. extern PROG gsprog;
  330. extern PROG pdfconv;
  331. extern OPTIONS option;
  332. extern PSFILE psfile; 
  333. extern GVIEW gsview;
  334. extern DISPLAY display;
  335. extern PRINTER printer;
  336. extern BMAP bitmap;
  337. extern PSDOC *doc;
  338. extern int page_extra;
  339. extern int page_skip;
  340. extern BOOL changed_version;
  341. extern BOOL zoom;
  342.  
  343. extern PSBBOX bbox;
  344.  
  345. /* in gvpm.c */
  346. void copy_clipboard(void);
  347. void update_scroll_bars(void);
  348. BOOL get_cursorpos(float *x, float *y);
  349.  
  350. /* in gvpinit.c */
  351. APIRET gsview_init(int argc, char *argv[]);
  352. void show_buttons(void);
  353.  
  354. /* in gvcmisc.c */
  355. void error_message(char *str);
  356. void info_init(HWND hwnd);
  357. void read_profile(void);
  358. void write_profile(void);
  359.  
  360. /* in gvpmisc.c */
  361. BOOL SetDlgItemText(HWND hwnd, int id, char *str);
  362. void post_close(void);
  363. void get_help(void);
  364. int message_box(char *str, int icon);
  365. void check_menu_item(int menuid, int itemid, BOOL checked);
  366. int get_menu_string(int menuid, int itemid, char *str, int len);
  367. int load_string(int id, char *str, int len);
  368. void play_system_sound(char *id);
  369. void play_sound(int i);
  370. void info_wait(BOOL flag);
  371. void send_prolog(FILE *f, int resource);
  372. void profile_create_section(PROFILE *prf, char *section, int id);
  373. int _chdir(char *dirname);
  374. char * _getcwd(char *dirname, int size);
  375.  
  376. /* in gvcdisp.c */
  377. void transform_cursorpos(float *x, float *y);
  378. void transform_point(float *x, float *y);
  379. void itransform_point(float *x, float *y);
  380. int get_paper_size_index(void);
  381. void gs_size(void);
  382. void gs_resize(void);
  383. void gs_magnify(float scale);
  384. void gsview_orientation(int new_orientation);
  385. void gsview_media(int new_media);
  386. void gsview_unit(int new_unit);
  387. void gsview_endfile(void);
  388. void gsview_openfile(char *filename);
  389. void gsview_select(void);
  390. void gsview_selectfile(char *filename);
  391. void gsview_display(void);
  392. void gsview_displayfile(char *filename);
  393. void send_orientation_prolog(FILE *f);
  394. void send_epswarn_prolog(FILE *f);
  395. void fix_orientation(FILE *f);
  396. FILE * gp_open_scratch_file(const char *prefix, char *fname, const char *mode);
  397. BOOL dfreopen(void);
  398. void dfclose(void);
  399. BOOL dsc_scan(char *filename);
  400. void dsc_getpages(FILE *f, int first, int last);
  401. void dsc_header(FILE *f);
  402. void dsc_dopage(void);
  403. void dsc_skip(int skip);
  404. int map_page(int page);
  405. BOOL do_output(void);
  406.  
  407. /* in gvpdisp.c */
  408. BOOL exec_pgm(char *name, char *arg, BOOL withpipe, PROG* prog);
  409. void stop_pgm(PROG* prog);
  410. void cleanup_pgm(PROG *prog);
  411. BOOL pdf_convert(char *name, char *arg, PROG* prog);
  412. BOOL gs_open(void);
  413. BOOL gs_close(void);
  414. void next_page(void);
  415. BOOL psfile_changed(void);
  416. void psfile_savestat(void);
  417. BOOL is_pipe_done(void);    /* true if pipe has just been reset */
  418.  
  419. /* in gvccmd.c */
  420. int gsview_command(int command);
  421. BOOL not_open(void);
  422. BOOL not_dsc(void);
  423. void gserror(UINT id, char *str, UINT icon, int sound);
  424. void pserror(char *str);
  425. int not_implemented(void);
  426. void gsview_check_usersize(void);
  427. int gsview_depth_to_menu(int depth);
  428.  
  429. /* in gvpdlg.c */
  430. BOOL get_filename(char *filename, BOOL save, int filter, int title, int help);
  431. BOOL get_string(char *, char *);
  432. BOOL get_page(int *, BOOL);
  433. void show_info(void);
  434. void show_about(void);
  435. BOOL get_bbox(void);
  436. void change_sounds(void);
  437. void gs_showmess(void);
  438. int gs_addmess(char *str, int count);
  439.  
  440. /* in gvcprf.c */
  441. PROFILE * profile_open(char *filename);
  442. int profile_read_string(PROFILE *prf, char *section, char *entry, char *def, char *buffer, int len);
  443. BOOL profile_write_string(PROFILE *prf, char *section, char *entry, char *value);
  444. BOOL profile_close(PROFILE *prf);
  445.  
  446. /* in gvceps.c */
  447. void extract_doseps(int);
  448. void make_eps_metafile(void);
  449. void make_eps_tiff(int);
  450. void make_eps_interchange(BOOL calc_bbox);
  451. void ps_to_eps(void);
  452. void paste_to_file(void);
  453. void clip_convert(void);
  454.  
  455. /* in gvcprn.c */
  456. void gsview_spool(char *, char *);
  457. void psfile_extract(FILE *f);
  458. char *get_devices(void);
  459. void print_cleanup(void);
  460. void gsview_saveas(void);
  461. void gsview_extract(void);
  462. struct prop_item_s * get_properties(char *device);
  463. BOOL gsview_cprint(BOOL to_file, char *cfname, char *optfname);
  464.  
  465. /* in gvwprn.c */
  466. int gp_printfile(char *filename, char *port);
  467. void gsview_print(BOOL);
  468. extern char not_defined[];
  469.  
  470. /* in gvctext.c */
  471. void gsview_text_extract(void);
  472. void gsview_text_find(void);
  473. void gsview_text_findnext(void);
  474.  
  475. #endif
  476.