From 019eff10c1d68c80593d3fa6fedf1f6428fcff63 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 1 Nov 2009 14:53:04 +0000 Subject: [PATCH] Amiga print UI svn path=/trunk/netsurf/; revision=9655 --- !NetSurf/Resources/de/Messages | 2 +- !NetSurf/Resources/en/Messages | 2 +- !NetSurf/Resources/fr/Messages | 2 +- !NetSurf/Resources/nl/Messages | 2 +- amiga/gui.c | 23 ++- amiga/menu.c | 2 +- amiga/object.h | 1 + amiga/options.h | 3 + amiga/print.c | 304 ++++++++++++++++++++++++++++++++- amiga/print.h | 12 +- 10 files changed, 342 insertions(+), 11 deletions(-) diff --git a/!NetSurf/Resources/de/Messages b/!NetSurf/Resources/de/Messages index 22bbc7ee8..0f4722bab 100644 --- a/!NetSurf/Resources/de/Messages +++ b/!NetSurf/Resources/de/Messages @@ -248,7 +248,7 @@ PDFNS:PDF... IFF:IFF... OpenFile:Open local file... About:About... -PrintNS:Print +PrintNS:Print... # Edit menu # diff --git a/!NetSurf/Resources/en/Messages b/!NetSurf/Resources/en/Messages index e5bac5b91..55f5b191d 100644 --- a/!NetSurf/Resources/en/Messages +++ b/!NetSurf/Resources/en/Messages @@ -248,7 +248,7 @@ PDFNS:PDF... IFF:IFF... OpenFile:Open local file... About:About... -PrintNS:Print +PrintNS:Print... # Edit menu # diff --git a/!NetSurf/Resources/fr/Messages b/!NetSurf/Resources/fr/Messages index 747cfec6f..6d8fe304c 100644 --- a/!NetSurf/Resources/fr/Messages +++ b/!NetSurf/Resources/fr/Messages @@ -248,7 +248,7 @@ PDFNS:PDF... IFF:IFF... OpenFile:Open local file... About:About... -PrintNS:Print +PrintNS:Print... # Edit menu # diff --git a/!NetSurf/Resources/nl/Messages b/!NetSurf/Resources/nl/Messages index f7ff90eb5..3c28db983 100644 --- a/!NetSurf/Resources/nl/Messages +++ b/!NetSurf/Resources/nl/Messages @@ -248,7 +248,7 @@ PDFNS:PDF... IFF:IFF... OpenFile:Open local file... About:About... -PrintNS:Print +PrintNS:Print... # Edit menu # diff --git a/amiga/gui.c b/amiga/gui.c index 5dbff0395..3ad072100 100755 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -836,6 +836,23 @@ void ami_handle_msg(void) continue; } } + else if(node->Type == AMINS_PRINTWINDOW) + { + if(ami_print_event((struct ami_print_window *)gwin)) + { + if(IsMinListEmpty(window_list)) + { + /* last window closed, so exit */ + ami_try_quit(); + } + break; + } + else + { + node = nnode; + continue; + } + } else if(node->Type == AMINS_GUIOPTSWINDOW) { if(ami_gui_opts_event()) @@ -1549,6 +1566,7 @@ void gui_multitask(void) ami_handle_msg(); ami_handle_appmsg(); + ami_handle_applib(); ami_arexx_handle(); } @@ -1565,6 +1583,7 @@ void gui_poll(bool active) schedule_run checks every event, really they need to be sorted so only the first event needs to be run on each signal. */ + if(active) { gui_multitask(); @@ -2748,8 +2767,8 @@ void ami_do_redraw(struct gui_window_2 *g) { content_redraw(c, -hcurrent, -vcurrent, - (width / g->bw->scale) - hcurrent, - (height / g->bw->scale) - vcurrent, + width - hcurrent, + height - vcurrent, 0,0,width, height, g->bw->scale,0xFFFFFF); diff --git a/amiga/menu.c b/amiga/menu.c index ff6201c98..f4c29839c 100755 --- a/amiga/menu.c +++ b/amiga/menu.c @@ -576,7 +576,7 @@ void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item) case 9: // print ami_update_pointer(gwin->win,GUI_POINTER_WAIT); - ami_print(gwin->bw->current_content); + ami_print_ui(gwin->bw->current_content); ami_update_pointer(gwin->win,GUI_POINTER_DEFAULT); break; diff --git a/amiga/object.h b/amiga/object.h index d48e8918f..82d01098d 100755 --- a/amiga/object.h +++ b/amiga/object.h @@ -33,6 +33,7 @@ enum AMINS_FINDWINDOW, AMINS_HISTORYWINDOW, AMINS_GUIOPTSWINDOW, + AMINS_PRINTWINDOW, AMINS_FETCHER, }; diff --git a/amiga/options.h b/amiga/options.h index 333c8a57d..c1976aef5 100644 --- a/amiga/options.h +++ b/amiga/options.h @@ -42,6 +42,7 @@ extern bool option_faster_scroll; extern bool option_scale_quality; extern bool option_ask_overwrite; extern int option_printer_unit; +extern int option_print_scale; extern bool option_startup_no_window; extern bool option_close_no_quit; @@ -68,6 +69,7 @@ bool option_faster_scroll = true; \ bool option_scale_quality = false; \ bool option_ask_overwrite = false; \ int option_printer_unit = 0; \ +int option_print_scale = 100; \ bool option_startup_no_window = false; \ bool option_close_no_quit = false; \ @@ -94,6 +96,7 @@ bool option_close_no_quit = false; \ { "scale_quality", OPTION_BOOL, &option_scale_quality}, \ { "ask_overwrite", OPTION_BOOL, &option_ask_overwrite}, \ { "printer_unit", OPTION_INTEGER, &option_printer_unit}, \ +{ "print_scale", OPTION_INTEGER, &option_print_scale}, \ { "startup_no_window", OPTION_BOOL, &option_startup_no_window}, \ { "close_no_quit", OPTION_BOOL, &option_close_no_quit}, diff --git a/amiga/print.c b/amiga/print.c index bc9bc5a5c..6e040666f 100644 --- a/amiga/print.c +++ b/amiga/print.c @@ -24,19 +24,32 @@ #include "amiga/print.h" #include "utils/messages.h" #include "utils/utils.h" +#include "amiga/utf8.h" +#include +#include +#include #include #include #include #include +#include +#include +#include + #include #include - +#include +#include +#include #include #include #include #include +#include +#include +#include #include @@ -69,11 +82,296 @@ struct ami_printer_info struct Window *win; }; +enum +{ + PGID_MAIN=0, + PGID_PRINTER, + PGID_SCALE, + PGID_COPIES, + PGID_PRINT, + PGID_CANCEL, + PGID_LAST +}; + +#define IFFPrefChunkCnt 2 +static LONG IFFPrefChunks[] = +{ + ID_PREF, ID_PRHD, + ID_PREF, ID_PDEV, +}; + struct ami_printer_info ami_print_info; -void ami_print(struct content *c) +CONST_STRPTR gadlab[PGID_LAST]; +CONST_STRPTR printers[11]; + +void ami_print_ui_setup(void) +{ + 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")); +} + +void ami_print_ui_free(void) +{ + int i; + + for(i = 0; i++; i < PGID_LAST) + if(gadlab[i]) FreeVec((APTR)gadlab[i]); + + for(i = 0; i++; i < 10) + if(printers[i]) FreeVec((APTR)printers[i]); +} + +BOOL ami_print_readunit(CONST_STRPTR filename, char name[], + 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; +} + +void ami_print_ui(struct content *c) +{ + char filename[30]; + int i; + + struct ami_print_window *pw = AllocVec(sizeof(struct ami_print_window), + MEMF_PRIVATE | MEMF_CLEAR); + + pw->c = c; + + printers[0] = AllocVec(50, MEMF_PRIVATE | MEMF_CLEAR); + 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; + printers[i] = AllocVec(50, MEMF_PRIVATE | MEMF_CLEAR); + if(!ami_print_readunit(filename, (void *)printers[i], 50, i)) + { + FreeVec((void *)printers[i]); + printers[i] = NULL; + break; + } + + } + + ami_print_ui_setup(); + + pw->objects[OID_MAIN] = WindowObject, + WA_ScreenTitle, nsscreentitle, + WA_Title, gadlab[PGID_PRINT], + WA_Activate, TRUE, + WA_DepthGadget, TRUE, + WA_DragBar, TRUE, + WA_CloseGadget, TRUE, + WA_SizeGadget, FALSE, + WA_CustomScreen, scrn, + WINDOW_SharedPort, sport, + WINDOW_UserData, pw, + WINDOW_IconifyGadget, FALSE, + WINDOW_Position, WPOS_CENTERSCREEN, + WINDOW_ParentGroup, pw->gadgets[PGID_MAIN] = VGroupObject, + LAYOUT_AddChild, ChooserObject, + GA_ID, PGID_PRINTER, + GA_RelVerify, TRUE, + GA_TabCycle, TRUE, + CHOOSER_LabelArray, printers, + CHOOSER_Selected, option_printer_unit, + 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, + LAYOUT_AddChild, pw->gadgets[PGID_SCALE] = IntegerObject, + GA_ID, PGID_SCALE, + GA_RelVerify, TRUE, + GA_TabCycle, TRUE, + INTEGER_Number, option_print_scale, + 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, + LAYOUT_AddChild, pw->gadgets[PGID_PRINT] = ButtonObject, + GA_ID, PGID_PRINT, + GA_RelVerify,TRUE, + GA_Text, gadlab[PGID_PRINT], + GA_TabCycle,TRUE, + ButtonEnd, + CHILD_WeightedHeight,0, + LAYOUT_AddChild, pw->gadgets[GID_CANCEL] = ButtonObject, + GA_ID, PGID_CANCEL, + GA_RelVerify, TRUE, + GA_Text, gadlab[PGID_CANCEL], + GA_TabCycle,TRUE, + ButtonEnd, + LayoutEnd, + CHILD_WeightedHeight,0, + EndGroup, + EndWindow; + + pw->win = (struct Window *)RA_OpenWindow(pw->objects[OID_MAIN]); + + pw->node = AddObject(window_list, AMINS_PRINTWINDOW); + pw->node->objstruct = pw; +} + +void ami_print_close(struct ami_print_window *pw) +{ + DisposeObject(pw->objects[OID_MAIN]); + DelObject(pw->node); + + ami_print_ui_free(); +} + +BOOL ami_print_event(struct ami_print_window *pw) +{ + /* return TRUE if window destroyed */ + ULONG class,result; + uint16 code; + struct content *c; + int copies; + + while((result = RA_HandleInput(pw->objects[OID_MAIN],&code)) != WMHI_LASTMSG) + { + switch(result & WMHI_CLASSMASK) // class + { + case WMHI_GADGETUP: + switch(result & WMHI_GADGETMASK) + { + case PGID_PRINT: + GetAttr(INTEGER_Number, pw->gadgets[PGID_SCALE], + (ULONG *)&option_print_scale); + GetAttr(INTEGER_Number, pw->gadgets[PGID_COPIES], + (ULONG *)&copies); + GetAttr(CHOOSER_Selected, pw->gadgets[PGID_PRINTER], + (ULONG *)&option_printer_unit); + + 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; +} + +void ami_print(struct content *c, int copies) { double height, print_height; + float scale = option_print_scale / 100.0; if(!ami_print_info.msgport) return; @@ -97,7 +395,7 @@ void ami_print(struct content *c) ami_print_info.ps = print_make_settings(PRINT_DEFAULT, c->url, &nsfont); ami_print_info.ps->page_width = ami_print_info.PED->ped_MaxXDots; ami_print_info.ps->page_height = ami_print_info.PED->ped_MaxYDots; - ami_print_info.ps->scale = 1.0; + ami_print_info.ps->scale = scale; print_set_up(c, &amiprinter, ami_print_info.ps, &height); diff --git a/amiga/print.h b/amiga/print.h index 95f2ef896..3afa9e688 100755 --- a/amiga/print.h +++ b/amiga/print.h @@ -22,7 +22,17 @@ struct content; -void ami_print(struct content *c); +struct ami_print_window { + struct Window *win; + Object *objects[OID_LAST]; + struct Gadget *gadgets[GID_LAST]; + struct nsObject *node; + struct content *c; +}; + +void ami_print(struct content *c, int copies); +void ami_print_ui(struct content *c); +BOOL ami_print_event(struct ami_print_window *pw); bool ami_print_cont(void); struct MsgPort *ami_print_init(void); void ami_print_free(void);