2009-08-23 19:59:41 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-01-19 02:13:32 +03:00
|
|
|
#include "amiga/os3support.h"
|
|
|
|
|
2016-04-20 17:54:18 +03:00
|
|
|
#include <string.h>
|
2009-11-01 17:53:04 +03:00
|
|
|
#include <proto/utility.h>
|
|
|
|
#include <proto/iffparse.h>
|
|
|
|
#include <proto/dos.h>
|
2009-08-30 14:14:16 +04:00
|
|
|
#include <proto/intuition.h>
|
2009-08-23 19:59:41 +04:00
|
|
|
#include <proto/Picasso96API.h>
|
|
|
|
#include <devices/printer.h>
|
|
|
|
#include <devices/prtbase.h>
|
|
|
|
|
2009-11-01 17:53:04 +03:00
|
|
|
#include <prefs/prefhdr.h>
|
|
|
|
#include <prefs/printertxt.h>
|
|
|
|
#include <libraries/gadtools.h>
|
|
|
|
|
2009-08-30 14:14:16 +04:00
|
|
|
#include <proto/window.h>
|
|
|
|
#include <proto/layout.h>
|
2009-11-01 17:53:04 +03:00
|
|
|
#include <proto/integer.h>
|
|
|
|
#include <proto/label.h>
|
|
|
|
#include <proto/chooser.h>
|
2009-08-30 14:14:16 +04:00
|
|
|
#include <proto/fuelgauge.h>
|
|
|
|
#include <classes/window.h>
|
|
|
|
#include <gadgets/fuelgauge.h>
|
|
|
|
#include <gadgets/layout.h>
|
2009-11-01 17:53:04 +03:00
|
|
|
#include <gadgets/integer.h>
|
|
|
|
#include <gadgets/chooser.h>
|
|
|
|
#include <images/label.h>
|
2009-08-30 14:14:16 +04:00
|
|
|
|
|
|
|
#include <reaction/reaction_macros.h>
|
|
|
|
|
2014-10-16 12:55:01 +04:00
|
|
|
#include "utils/nsoption.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
2016-06-06 10:59:23 +03:00
|
|
|
#include "utils/nsurl.h"
|
2016-05-30 23:05:57 +03:00
|
|
|
#include "netsurf/plotters.h"
|
2016-05-30 13:31:35 +03:00
|
|
|
#include "netsurf/layout.h"
|
2016-05-30 14:07:16 +03:00
|
|
|
#include "netsurf/mouse.h"
|
2016-05-30 13:01:40 +03:00
|
|
|
#include "netsurf/window.h"
|
2016-06-06 10:59:23 +03:00
|
|
|
#include "netsurf/content.h"
|
|
|
|
#include "desktop/printer.h"
|
|
|
|
#include "desktop/print.h"
|
2014-10-16 12:55:01 +04:00
|
|
|
|
|
|
|
#include "amiga/plotters.h"
|
2016-04-24 21:04:48 +03:00
|
|
|
#include "amiga/font.h"
|
2014-10-16 12:55:01 +04:00
|
|
|
#include "amiga/gui.h"
|
2015-01-26 03:05:01 +03:00
|
|
|
#include "amiga/libs.h"
|
2015-01-19 02:13:32 +03:00
|
|
|
#include "amiga/misc.h"
|
2014-10-16 12:55:01 +04:00
|
|
|
#include "amiga/print.h"
|
|
|
|
#include "amiga/utf8.h"
|
|
|
|
|
2009-08-23 19:59:41 +04:00
|
|
|
bool ami_print_begin(struct print_settings *ps);
|
|
|
|
bool ami_print_next_page(void);
|
|
|
|
void ami_print_end(void);
|
|
|
|
bool ami_print_dump(void);
|
2009-08-30 14:14:16 +04:00
|
|
|
void ami_print_progress(void);
|
2010-04-10 23:36:53 +04:00
|
|
|
void ami_print_close_device(void);
|
2009-08-23 19:59:41 +04:00
|
|
|
|
2018-09-27 01:53:49 +03:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
POID_MAIN = 0,
|
|
|
|
POID_LAST,
|
|
|
|
PGID_MAIN,
|
|
|
|
PGID_PRINTER,
|
|
|
|
PGID_SCALE,
|
|
|
|
PGID_COPIES,
|
|
|
|
PGID_PRINT,
|
|
|
|
PGID_CANCEL,
|
|
|
|
PGID_STATUS,
|
|
|
|
PGID_LAST
|
|
|
|
};
|
|
|
|
|
2009-08-23 19:59:41 +04:00
|
|
|
const struct printer amiprinter = {
|
|
|
|
&amiplot,
|
|
|
|
ami_print_begin,
|
|
|
|
ami_print_next_page,
|
|
|
|
ami_print_end,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ami_printer_info
|
|
|
|
{
|
|
|
|
struct gui_globals *gg;
|
2011-09-03 02:10:20 +04:00
|
|
|
struct IODRPTagsReq *PReq;
|
2009-08-23 19:59:41 +04:00
|
|
|
struct PrinterData *PD;
|
|
|
|
struct PrinterExtendedData *PED;
|
|
|
|
struct MsgPort *msgport;
|
2010-03-28 19:51:05 +04:00
|
|
|
struct hlcache_handle *c;
|
2009-08-29 18:00:57 +04:00
|
|
|
struct print_settings *ps;
|
2009-08-23 19:59:41 +04:00
|
|
|
int page;
|
2009-08-29 18:00:57 +04:00
|
|
|
int pages;
|
2018-09-27 01:53:49 +03:00
|
|
|
Object *gadgets[PGID_LAST];
|
|
|
|
Object *objects[POID_LAST];
|
2009-08-30 14:14:16 +04:00
|
|
|
struct Window *win;
|
2009-08-23 19:59:41 +04:00
|
|
|
};
|
|
|
|
|
2016-12-31 03:37:59 +03:00
|
|
|
struct ami_print_window {
|
|
|
|
struct ami_generic_window w;
|
|
|
|
struct Window *win;
|
2018-09-27 01:53:49 +03:00
|
|
|
Object *objects[POID_LAST];
|
|
|
|
Object *gadgets[PGID_LAST];
|
2016-12-31 03:37:59 +03:00
|
|
|
struct hlcache_handle *c;
|
|
|
|
};
|
|
|
|
|
2009-11-01 17:53:04 +03:00
|
|
|
#define IFFPrefChunkCnt 2
|
|
|
|
static LONG IFFPrefChunks[] =
|
|
|
|
{
|
|
|
|
ID_PREF, ID_PRHD,
|
|
|
|
ID_PREF, ID_PDEV,
|
|
|
|
};
|
|
|
|
|
2011-09-03 02:10:20 +04:00
|
|
|
static struct ami_printer_info ami_print_info;
|
2009-08-23 19:59:41 +04:00
|
|
|
|
2011-09-03 02:10:20 +04:00
|
|
|
static CONST_STRPTR gadlab[PGID_LAST];
|
|
|
|
static STRPTR printers[11];
|
2009-11-01 17:53:04 +03:00
|
|
|
|
2016-12-31 03:37:59 +03:00
|
|
|
static BOOL ami_print_event(void *w);
|
|
|
|
|
|
|
|
static const struct ami_win_event_table ami_print_table = {
|
|
|
|
ami_print_event,
|
|
|
|
NULL, /* we don't explicitly close the print window on quit (or at all???) */
|
|
|
|
};
|
|
|
|
|
2014-11-11 02:43:26 +03:00
|
|
|
static void ami_print_ui_setup(void)
|
2009-11-01 17:53:04 +03:00
|
|
|
{
|
|
|
|
gadlab[PGID_PRINTER] = (char *)ami_utf8_easy((char *)messages_get("Printer"));
|
|
|
|
gadlab[PGID_SCALE] = (char *)ami_utf8_easy((char *)messages_get("Scale"));
|
|
|
|
gadlab[PGID_COPIES] = (char *)ami_utf8_easy((char *)messages_get("Copies"));
|
|
|
|
gadlab[PGID_PRINT] = (char *)ami_utf8_easy((char *)messages_get("ObjPrint"));
|
|
|
|
gadlab[PGID_CANCEL] = (char *)ami_utf8_easy((char *)messages_get("Cancel"));
|
|
|
|
}
|
|
|
|
|
2014-11-11 02:43:26 +03:00
|
|
|
static void ami_print_ui_free(void)
|
2009-11-01 17:53:04 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2014-11-11 02:43:26 +03:00
|
|
|
for(i = 0; i < PGID_LAST; i++) {
|
2016-11-20 00:40:32 +03:00
|
|
|
if(gadlab[i]) free((APTR)gadlab[i]);
|
2014-11-11 02:43:26 +03:00
|
|
|
}
|
2009-11-01 17:53:04 +03:00
|
|
|
|
2014-11-11 02:43:26 +03:00
|
|
|
for(i = 0; i < 10; i++) {
|
2016-11-20 00:40:32 +03:00
|
|
|
if(printers[i]) free(printers[i]);
|
2014-11-11 02:43:26 +03:00
|
|
|
}
|
2009-11-01 17:53:04 +03:00
|
|
|
}
|
|
|
|
|
2014-11-11 02:43:26 +03:00
|
|
|
static BOOL ami_print_readunit(CONST_STRPTR filename, char name[],
|
2009-11-01 17:53:04 +03:00
|
|
|
uint32 namesize, int unitnum)
|
|
|
|
{
|
|
|
|
/* This is a modified version of a function from the OS4 SDK.
|
|
|
|
* The README says "You can use it in your application",
|
|
|
|
* no licence is specified. (c) 1999 Amiga Inc */
|
|
|
|
|
|
|
|
BPTR fp;
|
|
|
|
BOOL ok;
|
|
|
|
struct IFFHandle *iff;
|
|
|
|
struct ContextNode *cn;
|
|
|
|
struct PrefHeader phead;
|
|
|
|
struct PrinterDeviceUnitPrefs pdev;
|
|
|
|
|
|
|
|
SNPrintf(name,namesize,"Unit %ld",unitnum);
|
|
|
|
fp = Open(filename, MODE_OLDFILE);
|
|
|
|
if (fp)
|
|
|
|
{
|
|
|
|
iff = AllocIFF();
|
|
|
|
if (iff)
|
|
|
|
{
|
|
|
|
iff->iff_Stream = fp;
|
|
|
|
InitIFFasDOS(iff);
|
|
|
|
|
|
|
|
if (!OpenIFF(iff, IFFF_READ))
|
|
|
|
{
|
|
|
|
if (!ParseIFF(iff, IFFPARSE_STEP))
|
|
|
|
{
|
|
|
|
cn = CurrentChunk(iff);
|
|
|
|
if (cn->cn_ID == ID_FORM && cn->cn_Type == ID_PREF)
|
|
|
|
{
|
|
|
|
if (!StopChunks(iff, IFFPrefChunks, IFFPrefChunkCnt))
|
|
|
|
{
|
|
|
|
ok = TRUE;
|
|
|
|
while (ok)
|
|
|
|
{
|
|
|
|
if (ParseIFF(iff, IFFPARSE_SCAN))
|
|
|
|
break;
|
|
|
|
cn = CurrentChunk(iff);
|
|
|
|
if (cn->cn_Type == ID_PREF)
|
|
|
|
{
|
|
|
|
switch (cn->cn_ID)
|
|
|
|
{
|
|
|
|
case ID_PRHD:
|
|
|
|
if (ReadChunkBytes(iff, &phead, sizeof(struct PrefHeader)) != sizeof(struct PrefHeader))
|
|
|
|
{
|
|
|
|
ok = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (phead.ph_Version != 0)
|
|
|
|
{
|
|
|
|
ok = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ID_PDEV:
|
|
|
|
if (ReadChunkBytes(iff, &pdev, sizeof(pdev)) == sizeof(pdev))
|
|
|
|
{
|
|
|
|
if (pdev.pd_UnitName[0])
|
|
|
|
strcpy(name,pdev.pd_UnitName);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CloseIFF(iff);
|
|
|
|
}
|
|
|
|
FreeIFF(iff);
|
|
|
|
}
|
|
|
|
Close(fp);
|
|
|
|
}
|
|
|
|
else return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-03-28 19:51:05 +04:00
|
|
|
void ami_print_ui(struct hlcache_handle *c)
|
2009-11-01 17:53:04 +03:00
|
|
|
{
|
|
|
|
char filename[30];
|
|
|
|
int i;
|
|
|
|
|
2016-11-20 00:40:32 +03:00
|
|
|
struct ami_print_window *pw = calloc(1, sizeof(struct ami_print_window));
|
2009-11-01 17:53:04 +03:00
|
|
|
|
|
|
|
pw->c = c;
|
|
|
|
|
2016-11-20 00:40:32 +03:00
|
|
|
printers[0] = calloc(1, 50);
|
2009-11-01 17:53:04 +03:00
|
|
|
ami_print_readunit("ENV:Sys/printer.prefs", printers[0], 50, 0);
|
|
|
|
|
|
|
|
strcpy(filename,"ENV:Sys/printerN.prefs");
|
|
|
|
for (i = 1; i < 10; i++)
|
|
|
|
{
|
|
|
|
filename[15] = '0' + i;
|
2016-11-20 00:40:32 +03:00
|
|
|
printers[i] = malloc(50);
|
2011-09-03 02:10:20 +04:00
|
|
|
if(!ami_print_readunit(filename, printers[i], 50, i))
|
2009-11-01 17:53:04 +03:00
|
|
|
{
|
2016-11-20 00:40:32 +03:00
|
|
|
free(printers[i]);
|
2009-11-01 17:53:04 +03:00
|
|
|
printers[i] = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ami_print_ui_setup();
|
|
|
|
|
2018-09-27 01:53:49 +03:00
|
|
|
pw->objects[POID_MAIN] = WindowObj,
|
2014-11-16 19:40:41 +03:00
|
|
|
WA_ScreenTitle, ami_gui_get_screen_title(),
|
2009-11-01 17:53:04 +03:00
|
|
|
WA_Title, gadlab[PGID_PRINT],
|
|
|
|
WA_Activate, TRUE,
|
|
|
|
WA_DepthGadget, TRUE,
|
|
|
|
WA_DragBar, TRUE,
|
|
|
|
WA_CloseGadget, TRUE,
|
|
|
|
WA_SizeGadget, FALSE,
|
2019-05-10 22:59:30 +03:00
|
|
|
WA_PubScreen, ami_gui_get_screen(),
|
2019-05-10 23:59:03 +03:00
|
|
|
WINDOW_SharedPort, ami_gui_get_shared_msgport(),
|
2009-11-01 17:53:04 +03:00
|
|
|
WINDOW_UserData, pw,
|
|
|
|
WINDOW_IconifyGadget, FALSE,
|
|
|
|
WINDOW_Position, WPOS_CENTERSCREEN,
|
2015-01-26 03:05:01 +03:00
|
|
|
WINDOW_ParentGroup, pw->gadgets[PGID_MAIN] = LayoutVObj,
|
2009-11-01 17:53:04 +03:00
|
|
|
LAYOUT_AddChild, ChooserObject,
|
|
|
|
GA_ID, PGID_PRINTER,
|
|
|
|
GA_RelVerify, TRUE,
|
|
|
|
GA_TabCycle, TRUE,
|
|
|
|
CHOOSER_LabelArray, printers,
|
2012-03-22 13:34:34 +04:00
|
|
|
CHOOSER_Selected, nsoption_int(printer_unit),
|
2009-11-01 17:53:04 +03:00
|
|
|
ChooserEnd,
|
|
|
|
CHILD_Label, LabelObject,
|
|
|
|
LABEL_Text, gadlab[PGID_PRINTER],
|
|
|
|
LabelEnd,
|
|
|
|
LAYOUT_AddChild, IntegerObject,
|
|
|
|
GA_ID, PGID_COPIES,
|
|
|
|
GA_RelVerify, TRUE,
|
|
|
|
GA_TabCycle, TRUE,
|
|
|
|
INTEGER_Number, 1,
|
|
|
|
INTEGER_Minimum, 1,
|
|
|
|
INTEGER_Maximum, 100,
|
|
|
|
INTEGER_Arrows, TRUE,
|
|
|
|
IntegerEnd,
|
|
|
|
CHILD_Label, LabelObject,
|
|
|
|
LABEL_Text, gadlab[PGID_COPIES],
|
|
|
|
LabelEnd,
|
|
|
|
LAYOUT_AddChild, HGroupObject,
|
|
|
|
LAYOUT_LabelColumn, PLACETEXT_RIGHT,
|
2015-01-26 03:05:01 +03:00
|
|
|
LAYOUT_AddChild, pw->gadgets[PGID_SCALE] = IntegerObj,
|
2009-11-01 17:53:04 +03:00
|
|
|
GA_ID, PGID_SCALE,
|
|
|
|
GA_RelVerify, TRUE,
|
|
|
|
GA_TabCycle, TRUE,
|
2012-03-22 13:34:34 +04:00
|
|
|
INTEGER_Number, nsoption_int(print_scale),
|
2009-11-01 17:53:04 +03:00
|
|
|
INTEGER_Minimum, 0,
|
|
|
|
INTEGER_Maximum, 100,
|
|
|
|
INTEGER_Arrows, TRUE,
|
|
|
|
IntegerEnd,
|
|
|
|
CHILD_WeightedWidth, 0,
|
|
|
|
CHILD_Label, LabelObject,
|
|
|
|
LABEL_Text, "%",
|
|
|
|
LabelEnd,
|
|
|
|
LayoutEnd,
|
|
|
|
CHILD_Label, LabelObject,
|
|
|
|
LABEL_Text, gadlab[PGID_SCALE],
|
|
|
|
LabelEnd,
|
|
|
|
LAYOUT_AddChild, HGroupObject,
|
2015-01-26 03:05:01 +03:00
|
|
|
LAYOUT_AddChild, pw->gadgets[PGID_PRINT] = ButtonObj,
|
2009-11-01 17:53:04 +03:00
|
|
|
GA_ID, PGID_PRINT,
|
|
|
|
GA_RelVerify,TRUE,
|
|
|
|
GA_Text, gadlab[PGID_PRINT],
|
|
|
|
GA_TabCycle,TRUE,
|
|
|
|
ButtonEnd,
|
|
|
|
CHILD_WeightedHeight,0,
|
2018-09-27 01:53:49 +03:00
|
|
|
LAYOUT_AddChild, pw->gadgets[PGID_CANCEL] = ButtonObj,
|
2009-11-01 17:53:04 +03:00
|
|
|
GA_ID, PGID_CANCEL,
|
|
|
|
GA_RelVerify, TRUE,
|
|
|
|
GA_Text, gadlab[PGID_CANCEL],
|
|
|
|
GA_TabCycle,TRUE,
|
|
|
|
ButtonEnd,
|
|
|
|
LayoutEnd,
|
|
|
|
CHILD_WeightedHeight,0,
|
|
|
|
EndGroup,
|
|
|
|
EndWindow;
|
|
|
|
|
2018-09-27 01:53:49 +03:00
|
|
|
pw->win = (struct Window *)RA_OpenWindow(pw->objects[POID_MAIN]);
|
2016-12-31 03:37:59 +03:00
|
|
|
ami_gui_win_list_add(pw, AMINS_PRINTWINDOW, &ami_print_table);
|
2009-11-01 17:53:04 +03:00
|
|
|
}
|
|
|
|
|
2014-11-11 02:43:26 +03:00
|
|
|
static void ami_print_close(struct ami_print_window *pw)
|
2009-11-01 17:53:04 +03:00
|
|
|
{
|
2018-09-27 01:53:49 +03:00
|
|
|
DisposeObject(pw->objects[POID_MAIN]);
|
2016-12-31 03:37:59 +03:00
|
|
|
ami_gui_win_list_remove(pw);
|
2009-11-01 17:53:04 +03:00
|
|
|
|
|
|
|
ami_print_ui_free();
|
|
|
|
}
|
|
|
|
|
2016-12-31 03:37:59 +03:00
|
|
|
static BOOL ami_print_event(void *w)
|
2009-11-01 17:53:04 +03:00
|
|
|
{
|
|
|
|
/* return TRUE if window destroyed */
|
2016-12-31 03:37:59 +03:00
|
|
|
struct ami_print_window *pw = (struct ami_print_window *)w;
|
2014-11-11 02:43:26 +03:00
|
|
|
ULONG result;
|
2009-11-01 17:53:04 +03:00
|
|
|
uint16 code;
|
2010-03-28 19:51:05 +04:00
|
|
|
struct hlcache_handle *c;
|
2009-11-01 17:53:04 +03:00
|
|
|
int copies;
|
2012-03-22 13:34:34 +04:00
|
|
|
int print_scale;
|
|
|
|
int printer_unit;
|
2009-11-01 17:53:04 +03:00
|
|
|
|
2018-09-27 01:53:49 +03:00
|
|
|
while((result = RA_HandleInput(pw->objects[POID_MAIN],&code)) != WMHI_LASTMSG)
|
2009-11-01 17:53:04 +03:00
|
|
|
{
|
|
|
|
switch(result & WMHI_CLASSMASK) // class
|
|
|
|
{
|
|
|
|
case WMHI_GADGETUP:
|
|
|
|
switch(result & WMHI_GADGETMASK)
|
|
|
|
{
|
|
|
|
case PGID_PRINT:
|
|
|
|
GetAttr(INTEGER_Number, pw->gadgets[PGID_SCALE],
|
2012-03-22 13:34:34 +04:00
|
|
|
(ULONG *)&print_scale);
|
2009-11-01 17:53:04 +03:00
|
|
|
GetAttr(INTEGER_Number, pw->gadgets[PGID_COPIES],
|
|
|
|
(ULONG *)&copies);
|
|
|
|
GetAttr(CHOOSER_Selected, pw->gadgets[PGID_PRINTER],
|
2012-03-22 13:34:34 +04:00
|
|
|
(ULONG *)&printer_unit);
|
|
|
|
|
|
|
|
nsoption_set_int(print_scale, print_scale);
|
|
|
|
nsoption_set_int(printer_unit, printer_unit);
|
2009-11-01 17:53:04 +03:00
|
|
|
|
|
|
|
c = pw->c;
|
|
|
|
ami_print_close(pw);
|
|
|
|
ami_print(c, copies);
|
|
|
|
return TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PGID_CANCEL:
|
|
|
|
ami_print_close(pw);
|
|
|
|
return TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WMHI_CLOSEWINDOW:
|
|
|
|
ami_print_close(pw);
|
|
|
|
return TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-03-28 19:51:05 +04:00
|
|
|
void ami_print(struct hlcache_handle *c, int copies)
|
2009-08-23 19:59:41 +04:00
|
|
|
{
|
2019-05-07 23:45:40 +03:00
|
|
|
double height;
|
2012-03-22 13:34:34 +04:00
|
|
|
float scale = nsoption_int(print_scale) / 100.0;
|
2009-08-23 19:59:41 +04:00
|
|
|
|
2014-02-07 21:45:00 +04:00
|
|
|
if(ami_print_info.msgport == NULL)
|
|
|
|
ami_print_init();
|
2015-01-19 02:13:32 +03:00
|
|
|
#ifdef __amigaos4__
|
2009-08-23 19:59:41 +04:00
|
|
|
if(!(ami_print_info.PReq =
|
|
|
|
(struct IODRPTagsReq *)AllocSysObjectTags(ASOT_IOREQUEST,
|
|
|
|
ASOIOR_Size, sizeof(struct IODRPTagsReq),
|
|
|
|
ASOIOR_ReplyPort, ami_print_info.msgport,
|
|
|
|
ASO_NoTrack, FALSE,
|
|
|
|
TAG_DONE))) return;
|
2015-01-19 02:13:32 +03:00
|
|
|
#else
|
|
|
|
if(!(ami_print_info.PReq =
|
|
|
|
(struct IODRPTagsReq *)CreateIORequest(ami_print_info.msgport,
|
|
|
|
sizeof(struct IODRPTagsReq)))) return;
|
|
|
|
#endif
|
2009-08-23 19:59:41 +04:00
|
|
|
|
2012-03-22 13:34:34 +04:00
|
|
|
if(OpenDevice("printer.device", nsoption_int(printer_unit),
|
2009-08-29 18:00:57 +04:00
|
|
|
(struct IORequest *)ami_print_info.PReq, 0))
|
|
|
|
{
|
2016-05-01 16:00:47 +03:00
|
|
|
amiga_warn_user("CompError","printer.device");
|
2009-08-29 18:00:57 +04:00
|
|
|
return;
|
|
|
|
}
|
2009-08-23 19:59:41 +04:00
|
|
|
|
|
|
|
ami_print_info.PD = (struct PrinterData *)ami_print_info.PReq->io_Device;
|
|
|
|
ami_print_info.PED = &ami_print_info.PD->pd_SegmentData->ps_PED;
|
|
|
|
|
2016-04-24 21:04:48 +03:00
|
|
|
ami_print_info.ps = print_make_settings(PRINT_DEFAULT, nsurl_access(hlcache_handle_get_url(c)), ami_layout_table);
|
2009-08-29 18:00:57 +04:00
|
|
|
ami_print_info.ps->page_width = ami_print_info.PED->ped_MaxXDots;
|
|
|
|
ami_print_info.ps->page_height = ami_print_info.PED->ped_MaxYDots;
|
2009-11-01 17:53:04 +03:00
|
|
|
ami_print_info.ps->scale = scale;
|
2017-02-13 03:18:32 +03:00
|
|
|
ami_print_info.ps->priv = ami_print_info.gg;
|
2009-08-23 19:59:41 +04:00
|
|
|
|
2010-04-10 23:36:53 +04:00
|
|
|
if(!print_set_up(c, &amiprinter, ami_print_info.ps, &height))
|
|
|
|
{
|
2016-05-01 16:00:47 +03:00
|
|
|
amiga_warn_user("PrintError","print_set_up() returned false");
|
2010-04-10 23:36:53 +04:00
|
|
|
ami_print_close_device();
|
|
|
|
return;
|
|
|
|
}
|
2009-08-23 19:59:41 +04:00
|
|
|
|
2009-08-29 18:00:57 +04:00
|
|
|
height *= ami_print_info.ps->scale;
|
|
|
|
ami_print_info.pages = height / ami_print_info.ps->page_height;
|
|
|
|
ami_print_info.c = c;
|
|
|
|
|
2009-08-30 14:14:16 +04:00
|
|
|
ami_print_progress();
|
|
|
|
|
2009-08-29 18:00:57 +04:00
|
|
|
while(ami_print_cont()); /* remove while() for async printing */
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ami_print_cont(void)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
if(ami_print_info.page <= ami_print_info.pages)
|
|
|
|
{
|
|
|
|
print_draw_next_page(&amiprinter, ami_print_info.ps);
|
|
|
|
ami_print_dump();
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print_cleanup(ami_print_info.c, &amiprinter, ami_print_info.ps);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct MsgPort *ami_print_init(void)
|
|
|
|
{
|
|
|
|
ami_print_info.msgport = AllocSysObjectTags(ASOT_PORT,
|
|
|
|
ASO_NoTrack,FALSE,
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
return ami_print_info.msgport;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ami_print_free(void)
|
|
|
|
{
|
2014-02-07 21:45:00 +04:00
|
|
|
FreeSysObject(ASOT_PORT, ami_print_info.msgport);
|
|
|
|
ami_print_info.msgport = NULL;
|
2009-08-23 19:59:41 +04:00
|
|
|
}
|
|
|
|
|
2009-08-29 18:00:57 +04:00
|
|
|
struct MsgPort *ami_print_get_msgport(void)
|
|
|
|
{
|
|
|
|
return ami_print_info.msgport;
|
|
|
|
}
|
|
|
|
|
2009-08-23 19:59:41 +04:00
|
|
|
bool ami_print_begin(struct print_settings *ps)
|
|
|
|
{
|
2017-02-13 20:46:20 +03:00
|
|
|
ami_print_info.gg = ami_plot_ra_alloc(ami_print_info.PED->ped_MaxXDots,
|
2016-01-25 03:01:55 +03:00
|
|
|
ami_print_info.PED->ped_MaxYDots,
|
2017-02-13 21:09:43 +03:00
|
|
|
true, false);
|
2017-02-13 21:27:37 +03:00
|
|
|
if(!ami_print_info.gg) return false;
|
2009-08-23 19:59:41 +04:00
|
|
|
|
|
|
|
ami_print_info.page = 0;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ami_print_next_page(void)
|
|
|
|
{
|
|
|
|
ami_print_info.page++;
|
|
|
|
|
2018-09-27 01:53:49 +03:00
|
|
|
RefreshSetGadgetAttrs((struct Gadget *)ami_print_info.gadgets[PGID_STATUS],
|
2009-08-30 14:14:16 +04:00
|
|
|
ami_print_info.win, NULL,
|
|
|
|
FUELGAUGE_Level, ami_print_info.page,
|
|
|
|
TAG_DONE);
|
2009-08-29 18:00:57 +04:00
|
|
|
return true;
|
2009-08-23 19:59:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ami_print_end(void)
|
|
|
|
{
|
2017-02-13 20:46:20 +03:00
|
|
|
ami_plot_ra_free(ami_print_info.gg);
|
2018-09-27 01:53:49 +03:00
|
|
|
DisposeObject(ami_print_info.objects[POID_MAIN]);
|
2009-08-29 18:00:57 +04:00
|
|
|
|
2010-04-10 23:36:53 +04:00
|
|
|
ami_print_close_device();
|
2014-02-07 21:45:00 +04:00
|
|
|
ami_print_free();
|
2010-04-10 23:36:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ami_print_close_device(void)
|
|
|
|
{
|
2011-09-03 02:10:20 +04:00
|
|
|
CloseDevice((struct IORequest *)ami_print_info.PReq);
|
2009-08-29 18:00:57 +04:00
|
|
|
FreeSysObject(ASOT_IOREQUEST,ami_print_info.PReq);
|
2009-08-23 19:59:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ami_print_dump(void)
|
|
|
|
{
|
2009-08-23 20:40:28 +04:00
|
|
|
ami_print_info.PReq->io_Command = PRD_DUMPRPORT;
|
2009-08-23 19:59:41 +04:00
|
|
|
ami_print_info.PReq->io_Flags = 0;
|
|
|
|
ami_print_info.PReq->io_Error = 0;
|
2017-02-13 21:27:37 +03:00
|
|
|
ami_print_info.PReq->io_RastPort = ami_plot_ra_get_rastport(ami_print_info.gg);
|
2009-08-23 19:59:41 +04:00
|
|
|
ami_print_info.PReq->io_ColorMap = NULL;
|
|
|
|
ami_print_info.PReq->io_Modes = 0;
|
|
|
|
ami_print_info.PReq->io_SrcX = 0;
|
|
|
|
ami_print_info.PReq->io_SrcY = 0;
|
|
|
|
ami_print_info.PReq->io_SrcWidth = ami_print_info.PED->ped_MaxXDots;
|
|
|
|
ami_print_info.PReq->io_SrcHeight = ami_print_info.PED->ped_MaxYDots;
|
|
|
|
ami_print_info.PReq->io_DestCols = ami_print_info.PED->ped_MaxXDots;
|
|
|
|
ami_print_info.PReq->io_DestRows = ami_print_info.PED->ped_MaxYDots;
|
|
|
|
ami_print_info.PReq->io_Special = 0;
|
|
|
|
|
2011-09-03 02:10:20 +04:00
|
|
|
DoIO((struct IORequest *)ami_print_info.PReq); /* SendIO for async printing */
|
2009-08-23 19:59:41 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-08-30 14:14:16 +04:00
|
|
|
|
|
|
|
void ami_print_progress(void)
|
|
|
|
{
|
2018-09-27 01:53:49 +03:00
|
|
|
ami_print_info.objects[POID_MAIN] = WindowObj,
|
2014-11-16 19:40:41 +03:00
|
|
|
WA_ScreenTitle, ami_gui_get_screen_title(),
|
2009-08-30 14:14:16 +04:00
|
|
|
WA_Title, messages_get("Printing"),
|
|
|
|
WA_Activate, TRUE,
|
|
|
|
WA_DepthGadget, TRUE,
|
|
|
|
WA_DragBar, TRUE,
|
|
|
|
WA_CloseGadget, FALSE,
|
|
|
|
WA_SizeGadget, TRUE,
|
2019-05-10 22:59:30 +03:00
|
|
|
WA_PubScreen, ami_gui_get_screen(),
|
2009-08-30 14:14:16 +04:00
|
|
|
//WINDOW_SharedPort,sport,
|
|
|
|
WINDOW_UserData, &ami_print_info,
|
|
|
|
WINDOW_IconifyGadget, FALSE,
|
|
|
|
WINDOW_LockHeight,TRUE,
|
|
|
|
WINDOW_Position, WPOS_CENTERSCREEN,
|
2018-09-27 01:53:49 +03:00
|
|
|
WINDOW_ParentGroup, ami_print_info.gadgets[PGID_MAIN] = LayoutVObj,
|
|
|
|
LAYOUT_AddChild, ami_print_info.gadgets[PGID_STATUS] = FuelGaugeObj,
|
|
|
|
GA_ID,PGID_STATUS,
|
2009-08-30 14:14:16 +04:00
|
|
|
FUELGAUGE_Min,0,
|
|
|
|
FUELGAUGE_Max,ami_print_info.pages,
|
|
|
|
FUELGAUGE_Level,0,
|
|
|
|
FUELGAUGE_Ticks,11,
|
|
|
|
FUELGAUGE_ShortTicks,TRUE,
|
|
|
|
FUELGAUGE_Percent,TRUE,
|
|
|
|
FUELGAUGE_Justification,FGJ_CENTER,
|
|
|
|
FuelGaugeEnd,
|
|
|
|
CHILD_NominalSize,TRUE,
|
|
|
|
CHILD_WeightedHeight,0,
|
|
|
|
/*
|
2018-09-27 01:53:49 +03:00
|
|
|
LAYOUT_AddChild, ami_print_info.gadgets[PGID_CANCEL] = ButtonObj,
|
|
|
|
GA_ID,PGID_CANCEL,
|
2009-08-30 14:14:16 +04:00
|
|
|
GA_Disabled,TRUE,
|
|
|
|
GA_RelVerify,TRUE,
|
|
|
|
GA_Text,messages_get("Abort"),
|
|
|
|
GA_TabCycle,TRUE,
|
|
|
|
ButtonEnd,
|
|
|
|
*/
|
|
|
|
EndGroup,
|
|
|
|
EndWindow;
|
|
|
|
|
2018-09-27 01:53:49 +03:00
|
|
|
ami_print_info.win = (struct Window *)RA_OpenWindow(ami_print_info.objects[POID_MAIN]);
|
2009-08-30 14:14:16 +04:00
|
|
|
}
|
2015-01-26 03:05:01 +03:00
|
|
|
|