I'm sending attached a simplified version of an application I did in the past for the first fltk-utf8.

I think it can help the test and be used as an example with multi page printing.

If soemone want's to refine it and  send back I'll apreciate it.
# data file for the Fltk User Interface Designer (fluid)
version 1.0300 
header_name {.h} 
code_name {.cxx}
decl {\#include <FL/Fl_Double_Window.H>} {public global
} 

decl {\#include <FL/Fl_Input.H>} {public global
} 

decl {\#include <FL/Fl_Help_View.H>} {public global
} 

decl {\#include <FL/Fl_Table.H>
\#include <FL/Fl_Printer.H>} {public global
} 

decl {\#include <FL/Fl_Printer.H>} {public global
} 

decl {\#include <string>} {public global
} 

decl {\#include <sstream>} {public global
} 

decl {template<typename T>
void show_create(T*& aptr) {
  if (!aptr) aptr = new T();
  aptr->show();
}} {
  comment {This template checks if the pointer is already assigned,
if not it creates a new object.} public global
} 

Function {validate_product_id(Fl_Input *o, void *v)} {return_type void
} {
  code {//printf("Hello, World!\\n");} {}
} 

class DAD_Base_Window {
  comment {This is the base class for all application windows and is used to 
hold common code/functionality.} open : {public Fl_Double_Window}
} {
  decl {DAD_Base_Window *callee;} {protected local
  }
  Function {DAD_Base_Window(int X, int Y, int W, int H, const char *L) : 
Fl_Double_Window(X, Y, W, H, L)} {open
  } {
    code {callee = NULL;} {}
  }
  Function {DAD_Base_Window(int W, int H, const char *L):Fl_Double_Window(0, 0, 
W, H, L)} {open
  } {
    code {//printf("Hello, World!\\n");} {}
  }
  Function {make_window_when_null(DAD_Base_Window &aref)} {open return_type 
{static DAD_Base_Window*}
  } {
    code {//if (!aref) aref = 
return &aref;} {}
  }
} 

widget_class DAD_Invoice_Print {
  label {Invoice Print} open
  xywh {145 62 658 698} type Double color 7 resizable
  class Fl_Double_Window visible
} {
  Fl_Scroll pi_scroll {open
    xywh {3 6 650 689} color 7
  } {
    Fl_Group pageA4 {open
      xywh {20 10 628 685} color 7
    } {
      Fl_Box logo {
        label FLTK
        image {../help/logotipo-santiagopidal-s.bmp} xywh {33 20 200 41} 
labeltype SHADOW_LABEL labelfont 3 labelsize 47 align 148
      }
      Fl_Box companyBox {
        label {FLTK (pronounced "fulltick") is a cross-platform C++ GUI toolkit 
for UNIX®/Linux® (X11), Microsoft® Windows®, and MacOS® X. FLTK provides 
modern GUI functionality without the bloat and supports 3D graphics via 
OpenGL® and its built-in GLUT emulation.}
        xywh {28 66 308 80} labelfont 2 labelsize 12 align 149
      }
      Fl_Group invoiceNumber {open
        xywh {347 20 285 40} box BORDER_BOX color 7
      } {
        Fl_Box {} {
          xywh {347 20 285 20} box BORDER_BOX color 47
        }
        Fl_Box {} {
          xywh {492 20 1 40} box FLAT_BOX color 0
        }
        Fl_Box {} {
          label DATE
          xywh {492 20 139 20} labelfont 1 labelsize 12
        }
      }
      Fl_Box {} {
        xywh {347 65 285 85} box SHADOW_BOX color 7 labelfont 1 labelsize 16 
align 21
      }
      Fl_Box {} {
        xywh {28 615 605 30} box BORDER_BOX color 7
      }
      Fl_Box notesBox {
        label {FLTK is provided under the terms of the GNU Library Public 
License, Version 2 with exceptions that allow for static linking.}
        xywh {28 648 605 37} labelfont 2 labelsize 12 align 149
      }
      Fl_Box {} {
        xywh {28 160 605 20} box BORDER_BOX color 47
      }
      Fl_Box {} {
        label CODE
        xywh {28 160 55 20} labelfont 9 labelsize 10
      }
      Fl_Box {} {
        label DESCRIPTION
        xywh {85 160 332 20} labelfont 9 labelsize 10
      }
      Fl_Box {} {
        label {QTY.}
        xywh {420 160 42 20} labelfont 9 labelsize 10
      }
      Fl_Box {} {
        label PRICE
        xywh {461 160 64 20} labelfont 9 labelsize 10
      }
      Fl_Box {} {
        label {DISC.}
        xywh {524 160 43 20} labelfont 9 labelsize 10
      }
      Fl_Box {} {
        label SUBTOTAL
        xywh {567 160 65 20} labelfont 9 labelsize 10
      }
      Fl_Box {} {
        xywh {28 596 605 20} box BORDER_BOX color 47
      }
      Fl_Box {} {
        xywh {217 596 1 49} box FLAT_BOX color 0
      }
      Fl_Box {} {
        xywh {349 596 1 49} box FLAT_BOX color 0
      }
      Fl_Box {} {
        xywh {488 596 1 49} box FLAT_BOX color 0
      }
      Fl_Box {} {
        label SUBTOTAL
        xywh {92 595 125 20} labelfont 1 labelsize 12
      }
      Fl_Box {} {
        label {V.A.T. %}
        xywh {219 595 129 20} labelfont 1 labelsize 12
      }
      Fl_Box {} {
        label {TOTAL V.A.T.}
        xywh {348 595 140 20} labelfont 1 labelsize 12
      }
      Fl_Box {} {
        label TOTAL
        xywh {488 595 144 20} labelfont 1 labelsize 12
      }
      Fl_Box invoice_lines_box {
        image {/home/mingo/dadbiz-1.8/dadbiz/help/alfarero2.bmp} xywh {28 179 
605 406} box BORDER_BOX color 7
      }
      Fl_Box {} {
        xywh {82 160 1 425} box FLAT_BOX color 0
      }
      Fl_Box {} {
        xywh {420 160 1 425} box FLAT_BOX color 0
      }
      Fl_Box {} {
        xywh {461 160 1 425} box FLAT_BOX color 0
      }
      Fl_Box {} {
        xywh {524 160 1 425} box FLAT_BOX color 0
      }
      Fl_Box {} {
        xywh {566 160 1 425} box FLAT_BOX color 0
      }
      Fl_Box {} {
        xywh {92 596 1 49} box FLAT_BOX color 0
      }
      Fl_Box {} {
        label PAGE
        xywh {28 596 65 20} labelfont 1 labelsize 12
      }
      Fl_Group printDataGroup {open
        xywh {20 10 628 637}
      } {
        Fl_Box invoiceTypeBox {
          label {Invoice Nº}
          xywh {350 20 139 20} labelfont 1 labelsize 12
        }
        Fl_Box numberBox {
          label {2010/4687}
          xywh {350 40 139 20} labelfont 5 labelsize 15 align 16
        }
        Fl_Box dateBox {
          label {01/03/2010}
          xywh {496 40 133 20} labelfont 5 labelsize 15 align 16
        }
        Fl_Box clientBox {
          label {Domingo Alvarez Duarte
50.566.789-L
c/ Felicidad, 34 4ºB
29999 - Málaga
Málaga - Spain}
          xywh {349 66 277 82} labelsize 12 align 84
        }
        Fl_Group dataLinesGroup {open
          xywh {28 179 605 407} align 16
        } {
          Fl_Box codeBox {
            label {123
345
567
675
567
}
            xywh {29 180 52 404} labelfont 4 labelsize 11 align 21
          }
          Fl_Box descriptionBox {
            label {Ceramica
Barro
Card
France
Debit
AZULEJOS BLANCOS 15X15/45 PRODESCO
ESMALTE  DE ALTA TEMPERATURA ANARANJADO 0-6002}
            xywh {86 180 332 404} labelfont 4 labelsize 11 align 85
          }
          Fl_Box quantityBox {
            label {123
345
567
675
567
}
            xywh {422 180 38 404} labelfont 4 labelsize 11 align 25
          }
          Fl_Box priceBox {
            label {12.456,88
345
567
675
567
}
            xywh {463 180 61 404} labelfont 4 labelsize 11 align 25
          }
          Fl_Box discountBox {
            label {123
345
567
675
567
}
            xywh {526 180 39 404} labelfont 4 labelsize 11 align 25
          }
          Fl_Box lineTotalBox {
            label {23.456,90
345
567
675
567
}
            xywh {568 180 63 404} labelfont 4 labelsize 11 align 25
          }
        }
        Fl_Group {} {open
          xywh {28 595 609 52}
        } {
          Fl_Box invoicePageBox {
            label {1/1}
            xywh {28 618 65 25} labelfont 5 labelsize 15
          }
          Fl_Box fisrtTotalBox {
            label {12.345,78}
            xywh {95 618 120 25} labelfont 5 labelsize 15
          }
          Fl_Box vatPercentageBox {
            label 16
            xywh {223 618 125 25} labelfont 5 labelsize 15
          }
          Fl_Box vatAmountBox {
            label {12.345,78}
            xywh {350 618 138 25} labelfont 5 labelsize 15
          }
          Fl_Box totalBox {
            label {12.345,78}
            xywh {488 618 144 25} labelfont 5 labelsize 15
          }
        }
      }
    }
  }
} 

widget_class DAD_Main_Window {
  label {DADBIZ Sales & Inventory} open
  xywh {8 28 336 286} type Double
  class DAD_Base_Window visible
} {
  decl {DAD_Invoice_Print *sales_invoice;} {public local
  }
  decl {std::string  str_code, str_description, str_quantity, str_price, 
str_discount, str_line_total;} {protected local
  }
  Function {~DAD_Main_Window()} {open return_type virtual
  } {
    code {delete sales_invoice;} {}
  }
  code {sales_invoice = NULL;} {}
  Fl_Tabs tabs {open
    xywh {10 11 315 266}
  } {
    Fl_Group tabSales {
      label Sales open
      xywh {10 43 315 234} color 127 labelsize 20
    } {
      Fl_Button btnPreview {
        label {Invoice Preview}
        callback {show_create(sales_invoice);
generate_invoice();}
        xywh {30 61 275 55} box PLASTIC_UP_BOX labeltype SHADOW_LABEL labelfont 
3 labelsize 32 align 16
      }
      Fl_Counter pageCount {
        label Pages
        xywh {60 161 220 30} labeltype SHADOW_LABEL labelfont 3 labelsize 31 
align 1 minimum 1 maximum 20 step 1 value 1 textsize 32
      }
      Fl_Button btnPrint {
        label {Print Invoice}
        callback {print_invoice()}
        xywh {30 201 275 55} box PLASTIC_UP_BOX labeltype SHADOW_LABEL 
labelfont 3 labelsize 32
      }
    }
    Fl_Group tabBuys {
      label Buys open
      xywh {10 43 315 234} color 174 labelsize 20 hide
    } {}
    Fl_Group tabConfig {
      label Config open
      xywh {10 44 315 232} labelsize 20 hide
    } {}
  }
  Function {generate_invoice()} {open return_type void
  } {
    code {std::ostringstream  ss_code, ss_description, ss_quantity, ss_price, 
ss_discount, ss_line_total;
double dbl_subtotal, dbl_vat, dbl_vat_total, dbl_total;

dbl_subtotal = dbl_vat_total = dbl_total = 0.0;
dbl_vat = 16.0;

for(int i=1; i < 28; i++){
        int icode = i * 1000;
        double line_price = i * 1.53;
        double dbl_line_total = (line_price * i) ;

        dbl_subtotal += dbl_line_total;

        ss_code << icode << "\\n";
        ss_description << "Implementantion of function " << icode << "\\n";
        ss_quantity << i << "\\n";
        ss_price << line_price << "\\n";
        //ss_discount << 5 << "\\n";
        ss_line_total << dbl_line_total << "\\n";
}

str_code = ss_code.str();
str_description = ss_description.str();
str_quantity = ss_quantity.str();
str_price = ss_price.str();
str_discount = ss_discount.str();
str_line_total = ss_line_total.str();
sales_invoice->codeBox->label(str_code.c_str());
sales_invoice->descriptionBox->label(str_description.c_str());
sales_invoice->quantityBox->label(str_quantity.c_str());
sales_invoice->priceBox->label(str_price.c_str());
sales_invoice->discountBox->label(str_discount.c_str());
sales_invoice->lineTotalBox->label(str_line_total.c_str());} {}
  }
  Function {print_invoice()} {open return_type void
  } {
    code {int pages = pageCount->value();
show_create(sales_invoice);
generate_invoice();

Fl::wait();

std::ostringstream ss_page;

Fl_Printer printer;
//p.page(Fl_Printer::A4);
//p.place(g, 70, 70, p->page_width() - 140, p->page_height() - 140,  
FL_ALIGN_CENTER);
int w, h;
printer.start_job(1);

for(int i=1; i <= pages; i++) {
  Fl::wait();
  if( printer.start_page() ) return;
  printer.printable_rect(&w,&h);
  // scale the printer device so that the window fits on the page
  float scale = 1;
  if (sales_invoice->pageA4->w() > w || sales_invoice->pageA4->h() > h) {
    scale = (float)w/sales_invoice->pageA4->w();
    if ((float)h/sales_invoice->pageA4->h() < scale)
        scale = (float)h/sales_invoice->pageA4->h();
    printer.scale(scale, scale);
  }
    ss_page.str("");
    ss_page << i << "/" << pages;
    sales_invoice->invoicePageBox->label(ss_page.str().c_str());
        printer.print_widget(sales_invoice->pageA4);
        printer.end_page();
}
printer.end_job();} {selected
    }
  }
} 

Function {} {open
} {
  code {DAD_Main_Window* w = new DAD_Main_Window();
w->show(argc, argv);} {}
} 
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to