Amiga print UI

svn path=/trunk/netsurf/; revision=9655
This commit is contained in:
Chris Young 2009-11-01 14:53:04 +00:00
parent 90012b487a
commit 019eff10c1
10 changed files with 342 additions and 11 deletions

View File

@ -248,7 +248,7 @@ PDFNS:PDF...
IFF:IFF... IFF:IFF...
OpenFile:Open local file... OpenFile:Open local file...
About:About... About:About...
PrintNS:Print PrintNS:Print...
# Edit menu # Edit menu
# #

View File

@ -248,7 +248,7 @@ PDFNS:PDF...
IFF:IFF... IFF:IFF...
OpenFile:Open local file... OpenFile:Open local file...
About:About... About:About...
PrintNS:Print PrintNS:Print...
# Edit menu # Edit menu
# #

View File

@ -248,7 +248,7 @@ PDFNS:PDF...
IFF:IFF... IFF:IFF...
OpenFile:Open local file... OpenFile:Open local file...
About:About... About:About...
PrintNS:Print PrintNS:Print...
# Edit menu # Edit menu
# #

View File

@ -248,7 +248,7 @@ PDFNS:PDF...
IFF:IFF... IFF:IFF...
OpenFile:Open local file... OpenFile:Open local file...
About:About... About:About...
PrintNS:Print PrintNS:Print...
# Edit menu # Edit menu
# #

View File

@ -836,6 +836,23 @@ void ami_handle_msg(void)
continue; 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) else if(node->Type == AMINS_GUIOPTSWINDOW)
{ {
if(ami_gui_opts_event()) if(ami_gui_opts_event())
@ -1549,6 +1566,7 @@ void gui_multitask(void)
ami_handle_msg(); ami_handle_msg();
ami_handle_appmsg(); ami_handle_appmsg();
ami_handle_applib();
ami_arexx_handle(); 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 schedule_run checks every event, really they need to be sorted so only
the first event needs to be run on each signal. */ the first event needs to be run on each signal. */
if(active) if(active)
{ {
gui_multitask(); gui_multitask();
@ -2748,8 +2767,8 @@ void ami_do_redraw(struct gui_window_2 *g)
{ {
content_redraw(c, -hcurrent, content_redraw(c, -hcurrent,
-vcurrent, -vcurrent,
(width / g->bw->scale) - hcurrent, width - hcurrent,
(height / g->bw->scale) - vcurrent, height - vcurrent,
0,0,width, 0,0,width,
height, height,
g->bw->scale,0xFFFFFF); g->bw->scale,0xFFFFFF);

View File

@ -576,7 +576,7 @@ void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item)
case 9: // print case 9: // print
ami_update_pointer(gwin->win,GUI_POINTER_WAIT); 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); ami_update_pointer(gwin->win,GUI_POINTER_DEFAULT);
break; break;

View File

@ -33,6 +33,7 @@ enum
AMINS_FINDWINDOW, AMINS_FINDWINDOW,
AMINS_HISTORYWINDOW, AMINS_HISTORYWINDOW,
AMINS_GUIOPTSWINDOW, AMINS_GUIOPTSWINDOW,
AMINS_PRINTWINDOW,
AMINS_FETCHER, AMINS_FETCHER,
}; };

View File

@ -42,6 +42,7 @@ extern bool option_faster_scroll;
extern bool option_scale_quality; extern bool option_scale_quality;
extern bool option_ask_overwrite; extern bool option_ask_overwrite;
extern int option_printer_unit; extern int option_printer_unit;
extern int option_print_scale;
extern bool option_startup_no_window; extern bool option_startup_no_window;
extern bool option_close_no_quit; extern bool option_close_no_quit;
@ -68,6 +69,7 @@ bool option_faster_scroll = true; \
bool option_scale_quality = false; \ bool option_scale_quality = false; \
bool option_ask_overwrite = false; \ bool option_ask_overwrite = false; \
int option_printer_unit = 0; \ int option_printer_unit = 0; \
int option_print_scale = 100; \
bool option_startup_no_window = false; \ bool option_startup_no_window = false; \
bool option_close_no_quit = false; \ bool option_close_no_quit = false; \
@ -94,6 +96,7 @@ bool option_close_no_quit = false; \
{ "scale_quality", OPTION_BOOL, &option_scale_quality}, \ { "scale_quality", OPTION_BOOL, &option_scale_quality}, \
{ "ask_overwrite", OPTION_BOOL, &option_ask_overwrite}, \ { "ask_overwrite", OPTION_BOOL, &option_ask_overwrite}, \
{ "printer_unit", OPTION_INTEGER, &option_printer_unit}, \ { "printer_unit", OPTION_INTEGER, &option_printer_unit}, \
{ "print_scale", OPTION_INTEGER, &option_print_scale}, \
{ "startup_no_window", OPTION_BOOL, &option_startup_no_window}, \ { "startup_no_window", OPTION_BOOL, &option_startup_no_window}, \
{ "close_no_quit", OPTION_BOOL, &option_close_no_quit}, { "close_no_quit", OPTION_BOOL, &option_close_no_quit},

View File

@ -24,19 +24,32 @@
#include "amiga/print.h" #include "amiga/print.h"
#include "utils/messages.h" #include "utils/messages.h"
#include "utils/utils.h" #include "utils/utils.h"
#include "amiga/utf8.h"
#include <proto/utility.h>
#include <proto/iffparse.h>
#include <proto/dos.h>
#include <proto/intuition.h> #include <proto/intuition.h>
#include <proto/Picasso96API.h> #include <proto/Picasso96API.h>
#include <devices/printer.h> #include <devices/printer.h>
#include <devices/prtbase.h> #include <devices/prtbase.h>
#include <prefs/prefhdr.h>
#include <prefs/printertxt.h>
#include <libraries/gadtools.h>
#include <proto/window.h> #include <proto/window.h>
#include <proto/layout.h> #include <proto/layout.h>
#include <proto/integer.h>
#include <proto/label.h>
#include <proto/chooser.h>
#include <proto/fuelgauge.h> #include <proto/fuelgauge.h>
#include <classes/window.h> #include <classes/window.h>
#include <gadgets/fuelgauge.h> #include <gadgets/fuelgauge.h>
#include <gadgets/layout.h> #include <gadgets/layout.h>
#include <gadgets/integer.h>
#include <gadgets/chooser.h>
#include <images/label.h>
#include <reaction/reaction_macros.h> #include <reaction/reaction_macros.h>
@ -69,11 +82,296 @@ struct ami_printer_info
struct Window *win; 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; 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; double height, print_height;
float scale = option_print_scale / 100.0;
if(!ami_print_info.msgport) return; 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 = 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_width = ami_print_info.PED->ped_MaxXDots;
ami_print_info.ps->page_height = ami_print_info.PED->ped_MaxYDots; 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); print_set_up(c, &amiprinter, ami_print_info.ps, &height);

View File

@ -22,7 +22,17 @@
struct content; 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); bool ami_print_cont(void);
struct MsgPort *ami_print_init(void); struct MsgPort *ami_print_init(void);
void ami_print_free(void); void ami_print_free(void);