[GB.GTK]
* NEW: Printer.Default is a new property that returns the name of the default printer. * NEW: Printer.List is a new property that returns the list of the names of all available printers. [GB.QT4] * NEW: Printer.Default is a new property that returns the name of the default printer. * NEW: Printer.List is a new property that returns the list of the names of all available printers. git-svn-id: svn://localhost/gambas/trunk@5874 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
b60772bfad
commit
b8f97a8df4
4 changed files with 95 additions and 5 deletions
|
@ -273,11 +273,53 @@ BEGIN_PROPERTY(Printer_OutputFile)
|
|||
|
||||
END_PROPERTY
|
||||
|
||||
static bool find_default_printer(const char *name, bool def)
|
||||
{
|
||||
if (def)
|
||||
{
|
||||
GB.ReturnNewZeroString(name);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
BEGIN_PROPERTY(Printer_Default)
|
||||
|
||||
GB.ReturnNull();
|
||||
gPrinter::enumeratePrinters(find_default_printer);
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
static GB_ARRAY _list = NULL;
|
||||
|
||||
static bool add_printer(const char *name, bool def)
|
||||
{
|
||||
*((char **)GB.Array.Add(_list)) = GB.NewZeroString(name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BEGIN_PROPERTY(Printer_List)
|
||||
|
||||
GB_ARRAY array;
|
||||
|
||||
GB.Array.New(&array, GB_T_STRING, 0);
|
||||
_list = array;
|
||||
gPrinter::enumeratePrinters(add_printer);
|
||||
_list = NULL;
|
||||
GB.ReturnObject(array);
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
|
||||
|
||||
GB_DESC PrinterDesc[] =
|
||||
{
|
||||
GB_DECLARE("Printer", sizeof(CPRINTER)),
|
||||
|
||||
GB_STATIC_PROPERTY_READ("Default", "s", Printer_Default),
|
||||
GB_STATIC_PROPERTY_READ("List", "String[]", Printer_List),
|
||||
|
||||
GB_CONSTANT("Portrait", "i", GB_PRINT_PORTRAIT),
|
||||
GB_CONSTANT("Landscape", "i", GB_PRINT_LANDSCAPE),
|
||||
//GB_CONSTANT("ReversePortrait", "i", GB_PRINT_REVERSE_PORTRAIT),
|
||||
|
|
|
@ -702,3 +702,15 @@ void gPrinter::fixPrintDialog(GtkPrintUnixDialog *dialog)
|
|||
dump_tree(GTK_WIDGET(dialog), dialog);
|
||||
}
|
||||
|
||||
static gboolean find_all_printers(GtkPrinter *gtk_printer, bool (*callback)(const char *, bool))
|
||||
{
|
||||
if (strcmp(G_OBJECT_TYPE_NAME(gtk_printer_get_backend(gtk_printer)), "GtkPrintBackendFile"))
|
||||
return (*callback)(gtk_printer_get_name(gtk_printer), gtk_printer_is_default(gtk_printer));
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void gPrinter::enumeratePrinters(bool (*callback)(const char *, bool))
|
||||
{
|
||||
gtk_enumerate_printers((GtkPrinterFunc)find_all_printers, (gpointer)callback, NULL, TRUE);
|
||||
}
|
||||
|
|
|
@ -96,6 +96,8 @@ public:
|
|||
|
||||
static void fixPrintDialog(GtkPrintUnixDialog *dialog);
|
||||
static gPrinter *_current;
|
||||
|
||||
static void enumeratePrinters(bool (*callback)(const char *name, bool));
|
||||
|
||||
private:
|
||||
bool run(bool configure);
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include <QEventLoop>
|
||||
#include <QPrintDialog>
|
||||
#include <QPrinterInfo>
|
||||
|
||||
#include "gb.form.print.h"
|
||||
#include "gb.form.properties.h"
|
||||
|
@ -295,8 +296,12 @@ BEGIN_PROPERTY(Printer_PaperWidth)
|
|||
GB.ReturnFloat(floor((double)size.width() * 1E6) / 1E6);
|
||||
else
|
||||
{
|
||||
size.setWidth((qreal)VPROP(GB_FLOAT));
|
||||
PRINTER->setPaperSize(size, QPrinter::Millimeter);
|
||||
qreal width = (qreal)VPROP(GB_FLOAT);
|
||||
if (width != size.width())
|
||||
{
|
||||
size.setWidth(width);
|
||||
PRINTER->setPaperSize(size, QPrinter::Millimeter);
|
||||
}
|
||||
}
|
||||
|
||||
END_PROPERTY
|
||||
|
@ -309,8 +314,12 @@ BEGIN_PROPERTY(Printer_PaperHeight)
|
|||
GB.ReturnFloat(floor((double)size.height() * 1E6) / 1E6);
|
||||
else
|
||||
{
|
||||
size.setHeight((qreal)VPROP(GB_FLOAT));
|
||||
PRINTER->setPaperSize(size, QPrinter::Millimeter);
|
||||
qreal height = (qreal)VPROP(GB_FLOAT);
|
||||
if (height != size.height())
|
||||
{
|
||||
size.setHeight(height);
|
||||
PRINTER->setPaperSize(size, QPrinter::Millimeter);
|
||||
}
|
||||
}
|
||||
|
||||
END_PROPERTY
|
||||
|
@ -416,11 +425,37 @@ BEGIN_PROPERTY(Printer_OutputFile)
|
|||
|
||||
END_PROPERTY
|
||||
|
||||
BEGIN_PROPERTY(Printer_Default)
|
||||
|
||||
QPrinterInfo info = QPrinterInfo::defaultPrinter();
|
||||
|
||||
if (info.isNull())
|
||||
GB.ReturnNull();
|
||||
else
|
||||
GB.ReturnNewZeroString(info.printerName());
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
BEGIN_PROPERTY(Printer_List)
|
||||
|
||||
GB_ARRAY array;
|
||||
QList<QPrinterInfo> list = QPrinterInfo::availablePrinters();
|
||||
|
||||
GB.Array.New(&array, GB_T_STRING, list.length());
|
||||
for (int i = 0; i < list.length(); i++)
|
||||
*((char **)GB.Array.Get(array, i)) = GB.NewZeroString(list.at(i).printerName());
|
||||
|
||||
GB.ReturnObject(array);
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
GB_DESC PrinterDesc[] =
|
||||
{
|
||||
GB_DECLARE("Printer", sizeof(CPRINTER)),
|
||||
|
||||
GB_STATIC_PROPERTY_READ("Default", "s", Printer_Default),
|
||||
GB_STATIC_PROPERTY_READ("List", "String[]", Printer_List),
|
||||
|
||||
GB_CONSTANT("Portrait", "i", GB_PRINT_PORTRAIT),
|
||||
GB_CONSTANT("Landscape", "i", GB_PRINT_LANDSCAPE),
|
||||
//GB_CONSTANT("ReversePortrait", "i", GB_PRINT_REVERSE_PORTRAIT),
|
||||
|
@ -476,4 +511,3 @@ GB_DESC PrinterDesc[] =
|
|||
|
||||
GB_END_DECLARE
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue