Riaggiustata gestione stampanti, maschere e risorse

git-svn-id: svn://10.65.10.50/trunk@531 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
villa 1994-11-04 10:09:35 +00:00
parent 7deaba2654
commit 2a1f95ad3d
7 changed files with 160 additions and 123 deletions

@ -8,12 +8,11 @@
// in modo che la maschera sia compatibile
// con i metodi di ba2300, usati anche
// da printer
#define MSK_1_SAVE 112
#define MSK_1_SETUP 333
#define MSK_1_ISGRAPHICS 334
#define MSK_1_SIZE 335
#define MSK_1_LINES 336
#define MSK_1_NPAGES 337
#define MSK_1_FONT 338
#define MSK_1_PRINTERFILE prn.epf
#define MSK_1_NAMESFILE nms.epf

@ -1,71 +1,57 @@
#include <bagn001a.h>
PAGE "IMPOSTAZIONE STAMPANTE" -1 -1 76 10
PAGE "IMPOSTAZIONE STAMPANTE" -1 -1 76 13
RADIOBUTTON MSK_1_TYPE 16
RADIOBUTTON MSK_1_TYPE 70
BEGIN
PROMPT 1 1 "Stampa su..."
HELP "Selezionare il tipo di stampa"
ITEM "0|Stampante"
MESSAGE DISABLE,MSK_1_FILENAME|RESET,MSK_1_FILENAME
MESSAGE HIDE,MSK_1_FILENAME|RESET,MSK_1_FILENAME|SHOW,MSK_1_PRINTERS
MESSAGE ENABLE,MSK_1_PRINTERS
MESSAGE ENABLE,MSK_1_CODES
MESSAGE ENABLE,MSK_1_SIZE
MESSAGE ENABLE,MSK_1_SIZE
MESSAGE ENABLE,MSK_1_LINES
MESSAGE ENABLE,DLG_SETPRINT
ITEM "2|Visualizzazione"
MESSAGE HIDE,MSK_1_FILENAME|RESET,MSK_1_FILENAME
MESSAGE SHOW,MSK_1_PRINTERS|DISABLE,MSK_1_PRINTERS
MESSAGE DISABLE,MSK_1_CODES
MESSAGE DISABLE,MSK_1_SIZE
MESSAGE DISABLE,MSK_1_LINES
MESSAGE DISABLE,DLG_SETPRINT
ITEM "1|File"
MESSAGE ENABLE,MSK_1_FILENAME|DISABLE,MSK_1_PRINTERS
MESSAGE SHOW,MSK_1_FILENAME|HIDE,MSK_1_PRINTERS
MESSAGE ENABLE,MSK_1_CODES
MESSAGE DISABLE,MSK_1_SIZE
ITEM "2|Video"
MESSAGE DISABLE,MSK_1_FILENAME|RESET,MSK_1_FILENAME
MESSAGE DISABLE,MSK_1_PRINTERS
MESSAGE DISABLE,MSK_1_CODES
MESSAGE DISABLE,MSK_1_SIZE
MESSAGE DISABLE,MSK_1_LINES
MESSAGE DISABLE,DLG_SETPRINT
FLAGS "Z"
END
LIST MSK_1_PRINTERS 40
LIST MSK_1_PRINTERS 50
BEGIN
/* viene riempito runtime con nomi letti da config */
PROMPT 21 1 "Stampante "
/* viene riempito a run-time con nomi letti da config */
PROMPT 4 5 "Stampante "
HELP "Selezionare la stampante desiderata"
END
STRING MSK_1_FILENAME 40
STRING MSK_1_FILENAME 52
BEGIN
PROMPT 21 3 "Nome file "
PROMPT 4 5 "Nome file "
HELP "Inserire qui il nome del file in caso di stampa su file"
END
LIST MSK_1_CODES 40
BEGIN
PROMPT 21 5 "Tipo stampa "
PROMPT 4 6 "Tipo stampa "
/* pure */
HELP "Selezionare la modalita' nelle quale si desidera la stampa"
END
BUTTON MSK_1_SETUP 20 1
BEGIN
PROMPT 33 5 "Imposta stampante... "
HELP "Chiama l'Impostazione Stampante di Windows"
MESSAGE EXIT,MSK_1_SETUP
END
BOOLEAN MSK_1_SAVE
BEGIN
PROMPT 1 6 "Salva la configurazione"
HELP "Salva la configurazione corrente della stampante"
END
BOOLEAN MSK_1_ISGRAPHICS
BEGIN
PROMPT 1 7 "Stampa elementi grafici"
HELP "Stampa elementi grafici (linee, box, logo) se la stampante lo consente"
END
LIST MSK_1_SIZE 3
BEGIN
PROMPT 57 5 "Carattere "
PROMPT 32 6 "Carattere "
ITEM "7|7"
ITEM "8|8"
ITEM "10|10"
@ -77,7 +63,7 @@ END
LIST MSK_1_LINES 3
BEGIN
PROMPT 57 6 "Linee/Inch "
PROMPT 52 6 "Linee/Inch "
ITEM "4|4"
ITEM "5|5"
ITEM "6|6"
@ -87,21 +73,52 @@ BEGIN
ITEM "10|10"
HELP "Selezionare il numero di linee per pollice"
END
LIST MSK_1_FONT 10
BEGIN
PROMPT 4 6 "Font "
ITEM "1|Courier"
FLAGS "D"
END
NUMBER MSK_1_NPAGES 3 0
BEGIN
PROMPT 57 7 "N.o copie "
END
PROMPT 54 8 "N.o copie "
END
BOOLEAN MSK_1_ISGRAPHICS
BEGIN
PROMPT 4 8 "Stampa elementi grafici"
HELP "Stampa elementi grafici (linee, box, logo) se la stampante lo consente"
END
GROUPBOX DLG_NULL 74 4
BEGIN
PROMPT 1 9 ""
END
BUTTON DLG_SETPRINT 9 2
BEGIN
PROMPT -14 -2 "Imposta"
HELP "Chiama l'Impostazione Stampante di Windows"
MESSAGE EXIT,DLG_SETPRINT
END
BUTTON DLG_SAVEREC 9 2
BEGIN
PROMPT -24 -2 ""
MESSAGE EXIT,K_INS
END
BUTTON DLG_OK 9 2
BEGIN
PROMPT -12 -1 ""
PROMPT -34 -2 ""
END
BUTTON DLG_CANCEL 9 2
BEGIN
PROMPT -22 -1 ""
PROMPT -44 -2 ""
END
ENDPAGE

@ -564,6 +564,9 @@ TPush_button::TPush_button(short left, short top, short right, short bottom,
case DLG_PRINT:
capt = format("#%d", BMP_PRINT);
break;
case DLG_SETPRINT:
capt = format("#%d", BMP_SETPRINT);
break;
default:
break;
}

@ -78,6 +78,7 @@ ACCEL MENU_FILE "f" ALT
BMP_EDIT bitmap DISCARDABLE f:\p.due\bmp\edit.bmp
BMP_LINK bitmap DISCARDABLE f:\p.due\bmp\link.bmp
BMP_PRINT bitmap DISCARDABLE f:\p.due\bmp\print.bmp
BMP_SETPRINT bitmap DISCARDABLE f:\p.due\bmp\setprint.bmp
$$$
#endif

@ -27,6 +27,7 @@
#define DLG_EDIT 22 /* TAG del bottone Edit */
#define DLG_LINK 23 /* TAG del bottone Collega (applicazione) */
#define DLG_PRINT 24 /* TAG del bottone Stampa */
#define DLG_SETPRINT 25 /* TAG del bottone Imposta Stampa */
#define DLG_USER 100 /* TAG del primo controllo definito dall'utente */
/* @M

@ -1,5 +1,6 @@
#include <stdlib.h>
#include <xvt.h>
#include <urldefid.h>
#if XVT_OS==XVT_OS_SCOUNIX
#include <unistd.h>
@ -60,10 +61,10 @@ BOOLEAN TPrinter::start_winprint (long data)
{
PrDesc *pd = (PrDesc *) data;
TTextfile& txt = *(pd->_txt);
TPrintwin pw (pd->_prcd, txt, pd->_charsize);
TPrintwin pw(pd->_prcd, txt, pd->_charsize);
pw.print_background (pd->_graphics);
pw.do_print ();
return pw.aborted ();
pw.do_print();
return pw.aborted();
}
#endif
@ -619,19 +620,19 @@ bool printers_on_key (TMask_field & f, KEY key)
#if XVT_OS == XVT_OS_WIN
bool set_windows_print_device (TMask_field & f, KEY key)
bool set_windows_print_device (TMask_field& f, KEY key)
{
static char szDevice[80];
if (key == K_SPACE)
if (key == K_SPACE && f.mask().is_running())
{
if (MainApp()->printer().get_printrcd() != NULL)
free_print_rcd (MainApp ()->printer().get_printrcd ());
TToken_string & pn = MainApp()->printer().getprinternames ();
TString pdev (pn.get (atoi (f.get ())));
TString pdev (pn.get (atoi (f.get())));
GetProfileString ("devices", pdev, "", szDevice, sizeof (szDevice));
pdev << "," << szDevice;
// WriteProfileString("windows","device", pdev);
// madonna bona
// scrivi (e semmai lo si risistema poi)
WriteProfileString("windows", "device", pdev);
MainApp()->printer().set_printrcd(get_print_rcd (&(MainApp ()->printer ().get_printrcdsize ())));
MainApp()->printer().set_win_formlen();
}
@ -688,7 +689,7 @@ TPrinter::TPrinter()
// determine index of current default printer
for (int i = 0; i < pn2.items (); i++)
{
if (TString(dio.get(0)) == TString(pn2.get (i)))
if (TString(dio.get(0)) == TString(pn2.get(i)))
{
_curprn = i;
break;
@ -934,7 +935,7 @@ bool TPrinter::printrow (TPrintrow * rowtoprint)
return TRUE;
}
word TPrinter::rows_left () const
word TPrinter::rows_left() const
{
word left = _formlen - _currentrow - _footersize + 1;
if (_currentrow < 2)
@ -942,7 +943,7 @@ word TPrinter::rows_left () const
return left;
}
bool TPrinter ::print (TPrintrow & rowtoprint)
bool TPrinter::print(TPrintrow & rowtoprint)
{
bool ok = TRUE;
@ -951,42 +952,42 @@ bool TPrinter ::print (TPrintrow & rowtoprint)
// if (ok && _currentrow <= _headersize)
if (ok && _currentrow == 1)
ok = printheader ();
ok = printheader();
if (ok)
{
ok = printrow (&rowtoprint);
ok = printrow(&rowtoprint);
_currentrow++;
}
return ok;
}
bool TPrinter::printheader ()
bool TPrinter::printheader()
{
if (_headerhandler)
_headerhandler (*this);
bool ok = TRUE;
for (int i = 0; i < _headersize && ok; i++)
ok = printrow (getheaderline (i));
ok = printrow(getheaderline(i));
_currentrow = _headersize + 1;
return ok;
}
bool TPrinter::printfooter ()
bool TPrinter::printfooter()
{
if (_footerhandler)
_footerhandler (*this);
bool ok = TRUE;
for (int i = 0; i < _footersize && ok; i++)
ok = printrow (getfooterline (i));
ok = printrow(getfooterline(i));
#if XVT_OS != XVT_OS_WIN
if (ok)
printformfeed ();
printformfeed();
#endif
_currentrow = 1;
@ -995,79 +996,79 @@ bool TPrinter::printfooter ()
return ok;
}
bool TPrinter::skip (int linestoskip)
bool TPrinter::skip(int linestoskip)
{
int jumpline;
CHECK (linestoskip >= 0, "Linestoskip can't be negative");
jumpline = _currentrow + linestoskip;
return jump (jumpline);
return jump(jumpline);
}
bool TPrinter::jump (int jumpline)
bool TPrinter::jump(int jumpline)
{
int i = 0;
bool ok = TRUE;
CHECK (jumpline >= 0, "Jumpline can't be negative");
if (jumpline > _formlen - _footersize)
ok = formfeed ();
ok = formfeed();
else
for (i = _currentrow; i < jumpline; i++)
if (!printrow ())
if (!printrow())
ok = FALSE;
if (jumpline > _formlen - _footersize)
ok = FALSE;
return ok;
}
bool TPrinter::formfeed ()
bool TPrinter::formfeed()
{
const int lastrow = _formlen - _footersize;
for (; _currentrow <= lastrow; _currentrow++)
printrow ();
return printfooter ();
printrow();
return printfooter();
}
void TPrinter::reset ()
void TPrinter::reset()
{
resetheader ();
resetfooter ();
resetheader();
resetfooter();
_currentpage = 1;
_currentrow = 1;
_currentrow = 1;
}
bool TPrinter::printformfeed ()
bool TPrinter::printformfeed()
{
#if XVT_OS != XVT_OS_WIN
const PrinterDef & pd = get_description (_curprn);
const PrinterDef & pd = get_description(_curprn);
if (_printertype != screenvis && _hwformfeed)
fprintf (_fp, "%s", (const char *) pd._ffcode);
fprintf(_fp, "%s",(const char *)pd._ffcode);
#endif
return TRUE;
}
bool TPrinter::open ()
bool TPrinter::open()
{
// qui
#if XVT_OS==XVT_OS_SCOUNIX
if (_printertype == spoolprinter)
{
const PrinterDef & def = get_description (_curprn);
const PrinterDef & def = get_description(_curprn);
int pfd[2];
if (pipe (pfd) == -1)
if (pipe(pfd) == -1)
return error_box ("Impossibile creare processo di stampa " "(pipe)");
int ret = fork ();
int ret = fork();
if (ret == -1)
return error_box ("Impossibile creare processo di stampa " "(fork)");
return error_box("Impossibile creare processo di stampa " "(fork)");
if (ret == 0)
{
if (( :: close (0) != -1) && ( ::dup (pfd[0]) == 0) &&
( :: close (pfd[0]) == 0) && ( ::close (pfd[1]) != -1))
if ((::close(0) != -1) && (::dup(pfd[0]) == 0) &&
(::close(pfd[0]) == 0) && (::close(pfd[1]) != -1))
{
char s0[80];
@ -1084,12 +1085,12 @@ bool TPrinter::open ()
{
char *ws[4] =
{"lpr", "-s", s0, NULL};
execvp (ws[0], ws);
execvp(ws[0], ws);
}
exit (-1);
exit(-1);
}
}
if (( ::close (pfd[0]) == -1) || ((_fp = fdopen (pfd[1], "w")) == NULL))
if ((::close (pfd[0]) == -1) || ((_fp = fdopen(pfd[1], "w")) == NULL))
return error_box ("Impossibile creare processo di stampa" "(close)");
}
else
@ -1156,21 +1157,21 @@ void TPrinter::set()
}
((TList_field &) (mask.field (MSK_1_PRINTERS))).replace_items (pn1, pn2);
mask.hide(MSK_1_SETUP);
mask.hide(MSK_1_SIZE);
mask.hide(MSK_1_LINES);
mask.disable(DLG_SETPRINT);
if (!_multiple_copies) mask.hide(MSK_1_NPAGES);
pn1 = "";
pn2 = "";
for (i = 0; i < ((PrinterDef &)_printers[_curprn])._names.items (); i++)
for (i = 0; i < ((PrinterDef &)_printers[_curprn])._names.items(); i++)
{
pn1.add (format ("%d", i));
pn2.add ((TString &)((PrinterDef &) _printers[_curprn])._names[i]);
pn1.add(format ("%d", i));
pn2.add((TString &)((PrinterDef &) _printers[_curprn])._names[i]);
}
((TList_field &) (mask.field (MSK_1_CODES))).replace_items (pn1, pn2);
((TList_field &)(mask.field (MSK_1_CODES))).replace_items(pn1, pn2);
mask.set_handler (MSK_1_PRINTERS, printers_on_key);
if (_printertype == fileprinter)
mask.set (MSK_1_TYPE, "1");
@ -1179,17 +1180,17 @@ void TPrinter::set()
else
mask.set (MSK_1_TYPE, "0");
mask.set (MSK_1_PRINTERS, format ("%d", _curprn));
mask.set (MSK_1_CODES, format ("%d", _curcode));
mask.set (MSK_1_FILENAME, _printerfile);
mask.set(MSK_1_NPAGES, _ncopies);
mask.reset (MSK_1_SAVE);
mask.set(MSK_1_PRINTERS, format("%d", _curprn));
mask.set(MSK_1_CODES, format("%d", _curcode));
mask.set(MSK_1_FILENAME, _printerfile);
mask.set(MSK_1_NPAGES, _ncopies);
if (mask.run () == K_ESC)
KEY k;
if ((k = mask.run()) == K_ESC)
return;
if (mask.get_bool(MSK_1_SAVE))
if (k == K_INS) // premuto REGISTRA
mask.save();
// get user choices
@ -1232,7 +1233,9 @@ void TPrinter::set()
#else
_get_windows_printer_names (pn2);
_get_windows_printer_names(pn2);
char old_default[80];
GetProfileString ("windows", "device", ",,,", old_default, sizeof(old_default));
for (i = 0; i < pn2.items (); i++)
pn1.add(i);
@ -1257,54 +1260,66 @@ void TPrinter::set()
mask.set (MSK_1_TYPE, "0");
mask.set_handler (MSK_1_PRINTERS, set_windows_print_device);
mask.reset (MSK_1_SAVE);
KEY k;
int oldprn = _curprn;
while ((k = mask.run ()) != K_ESC && k != K_ENTER)
while ((k = mask.run ()) != K_ESC && k != K_ENTER && k != K_INS)
{
if (k == MSK_1_SETUP)
if (k == DLG_SETPRINT)
{
// l'handler setta default di windows a quella nel listbox e ribecca l'rcd
if (_print_rcd != NULL)
{
if (page_setup_dlg (_print_rcd))
{
if (page_setup_dlg(_print_rcd))
{
// see if user has changed printer
// determine index of currently selected printer
// ACTHUNG! Deep hacking of XVT internals! NON PORTABLE!
for (i = 0; i < pn2.items (); i++)
if (strcmp((const char *)(_print_rcd + 4), pn2.get (i)) == 0)
if (_print_rcd != NULL)
free_print_rcd (_print_rcd);
_print_rcd = get_print_rcd(&_print_rcd_size);
for (i = 0; i < pn2.items(); i++)
if (strcmp((const char *)(_print_rcd + 4), pn2.get(i)) == 0)
{
_curprn = i;
break;
}
mask.set (MSK_1_PRINTERS, pn1.get(_curprn));
set_win_formlen ();
}
mask.set(MSK_1_PRINTERS, pn1.get(_curprn));
set_win_formlen();
}
mask.set_focus ();
mask.set_focus();
}
else
beep ();
}
}
_curprn = atoi(mask.get(MSK_1_PRINTERS));
if (k == K_INS)
{
// tutto resta com'e'
mask.save ();
}
if (k == K_ESC || k == K_ENTER)
{
// riaggiusta stampante default windows come prima
// curprn e rcd sono quelle di prima
MainApp()->enable_menu_item(M_FILE_PG_SETUP);
WriteProfileString("windows","device", old_default);
}
if (k == K_ESC)
{
// rimetti come prima
// WriteProfileString("windows","device", pdev);
if (_print_rcd != NULL)
free_print_rcd (_print_rcd);
_curprn = oldprn;
_print_rcd = get_print_rcd(&_print_rcd_size);
set_win_formlen ();
MainApp()->enable_menu_item(M_FILE_PG_SETUP);
set_win_formlen();
return;
}
_curprn = atoi(mask.get(MSK_1_PRINTERS));
if (mask.get_bool(MSK_1_SAVE))
mask.save ();
_ncopies = atoi (mask.get (MSK_1_NPAGES));

@ -62,6 +62,7 @@
#define BMP_DELRECDN 154
#define BMP_NEWRECDN 155
#define BMP_QUITDN 164
#define BMP_SETPRINT 165
#endif