Patch level : 2.1 50

Files correlati     : reports
Ricompilazione Demo : [ ]
Commento            :


git-svn-id: svn://10.65.10.50/trunk@12120 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2004-05-27 10:55:07 +00:00
parent c030375ba0
commit b6d60057f4
5 changed files with 790 additions and 719 deletions

View File

@ -1081,7 +1081,6 @@ bool TAVM::execute(const TBytecode& cmdline)
if (_mon.is_open()) // Gestione debugger if (_mon.is_open()) // Gestione debugger
{ {
lock_preview_update(true);
TAVM_list_window& monitor = _mon.monitor(); TAVM_list_window& monitor = _mon.monitor();
monitor.set_bytecode(_bc, _ip, _user_words); monitor.set_bytecode(_bc, _ip, _user_words);
TAVM_stack_window& stacker = _mon.stacker(); TAVM_stack_window& stacker = _mon.stacker();
@ -1101,7 +1100,7 @@ bool TAVM::execute(const TBytecode& cmdline)
} }
break; break;
case K_QUIT: abort_printing(); case K_QUIT: abort_printing();
case K_F5 : _mon.close_modal(); lock_preview_update(false); break; case K_F5 : _mon.close_modal(); break;
default: break; default: break;
} }
} }
@ -1112,10 +1111,7 @@ bool TAVM::execute(const TBytecode& cmdline)
} }
if (_mon.is_open()) // Chiudi debugger if (_mon.is_open()) // Chiudi debugger
{
_mon.close_modal(); _mon.close_modal();
lock_preview_update(false);
}
//const bool ok = _bc != NULL; // Not aborted //const bool ok = _bc != NULL; // Not aborted
_bc = old_bc; _bc = old_bc;

View File

@ -3,13 +3,45 @@
#include <image.h> #include <image.h>
#include <recarray.h> #include <recarray.h>
#include <relation.h> #include <relation.h>
#include <report.h> #include <reprint.h>
#include <xml.h> #include <xml.h>
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// TReport_font // TReport_font
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
int compute_font_match(WINDOW win, int size, int ppi, int cpi)
{
const TString emme(cpi, 'M');
int mi = 0, ma = 2*size;
int best = 0, best_error = 0;
while (mi <= ma)
{
const int me = (mi+ma)/2;
XVT_FNTID fontid = xvt_font_create();
xvt_font_set_family(fontid, "Courier New");
xvt_font_set_size(fontid, me);
xvt_dwin_set_font(win, fontid);
const int width = xvt_dwin_get_text_width(win, emme, -1);
const int error = abs(width - ppi);
xvt_font_destroy(fontid);
if (best == 0 || error < best_error)
{
best = me;
best_error = error;
if (error == 0)
break;
}
if (width > ppi)
ma = me-1;
else
mi = me+1;
}
return best;
}
XVT_FNTID TReport_font::get_xvt_font(const TWindow& win) const XVT_FNTID TReport_font::get_xvt_font(const TWindow& win) const
{ {
if (win.win() != _win_mapped) if (win.win() != _win_mapped)
@ -22,33 +54,7 @@ XVT_FNTID TReport_font::get_xvt_font(const TWindow& win) const
const PNT pnt0 = win.log2dev(0,0); const PNT pnt0 = win.log2dev(0,0);
const PNT pnt1 = win.log2dev(cpi*100,100); const PNT pnt1 = win.log2dev(cpi*100,100);
const int ppi = pnt1.h - pnt0.h; const int ppi = pnt1.h - pnt0.h;
const TString emme(cpi, 'M'); const int best = compute_font_match(win.win(), (pnt1.v - pnt0.v), ppi, cpi);
int mi = 0, me = 0, ma = 2*(pnt1.v - pnt0.v);
int best = 0, best_error = 0;
while (mi <= ma)
{
me = (mi+ma)/2;
XVT_FNTID fontid = xvt_font_create();
xvt_font_set_family(fontid, "Courier New");
xvt_font_set_size(fontid, me);
xvt_dwin_set_font(win.win(), fontid);
const int width = xvt_dwin_get_text_width(win.win(), emme, -1);
const int error = abs(width - ppi);
xvt_font_destroy(fontid);
if (best == 0 || error < best_error)
{
best = me;
best_error = error;
if (error == 0)
break;
}
if (width > ppi)
ma = me-1;
else
mi = me+1;
}
nSize = cpi * best / _cpi; nSize = cpi * best / _cpi;
} }
@ -66,6 +72,31 @@ XVT_FNTID TReport_font::get_xvt_font(const TWindow& win) const
return _fontid; return _fontid;
} }
XVT_FNTID TReport_font::get_preview_font(const TWindow& win, const TPoint& res) const
{
if (win.win() != _win_mapped)
{
const int cpi = 120 / DEFAULT_FONT_SIZE;
const PNT pnt0 = win.log2dev(0,0);
const PNT pnt1 = win.log2dev(res.x,res.y);
const int ppi = pnt1.h - pnt0.h;
const int best = compute_font_match(win.win(), (pnt1.v - pnt0.v), ppi, cpi);
const int nSize = cpi * best / _cpi;
XVT_FNTID fontid = xvt_font_create();
xvt_font_set_family(fontid, (char*)(const char*)_name);
xvt_font_set_size(fontid, nSize);
xvt_font_set_style(fontid, _style);
TReport_font& myself = *(TReport_font*)this;
myself.unmap();
myself._fontid = fontid;
myself._win_mapped = win.win();
xvt_dwin_get_font_metrics(_win_mapped, &myself._leading, &myself._ascent, &myself._descent);
}
return _fontid;
}
void TReport_font::unmap() void TReport_font::unmap()
{ {
if (_fontid != NULL) if (_fontid != NULL)
@ -520,18 +551,6 @@ bool TReport_section::compute_rect(TRectangle& rct) const
return !rct.is_empty(); return !rct.is_empty();
} }
void TReport_section::draw(TWindow& win, TReport_draw_mode rdm) const
{
if (shown() && active())
{
for (int i = 0; i < items(); i++)
{
const TReport_field& f = field(i);
f.draw(win, rdm);
}
}
}
bool TReport_section::load_fields() bool TReport_section::load_fields()
{ {
const bool ok = active(); const bool ok = active();
@ -565,6 +584,18 @@ bool TReport_section::execute_prescript()
return ok; return ok;
} }
void TReport_section::print(TBook& book) const
{
if (shown() && active())
{
for (int i = 0; i < items(); i++)
{
const TReport_field& f = field(i);
f.print(book);
}
}
}
bool TReport_section::execute_postscript() bool TReport_section::execute_postscript()
{ {
bool ok = true; bool ok = true;
@ -1311,6 +1342,25 @@ void TReport_field::draw(TWindow& win, TReport_draw_mode rdm) const
} }
} }
bool TReport_field::print_tools(TBook& book) const
{
const bool has_pen = border() > 0;
const bool has_brush = (back_color() & 0xFFFFFF) != (COLOR_WHITE & 0xFFFFFF);
const bool visible = has_pen || has_brush;
if (visible)
{
book.set_pen(fore_color(), border()-1);
book.set_brush(back_color(), has_brush ? PAT_SOLID : PAT_HOLLOW);
}
return visible;
}
void TReport_field::print_rect(TBook& book) const
{
if (print_tools(book))
book.draw_rectangle(get_draw_rect());
}
void TReport_field::print(TBook& book) const void TReport_field::print(TBook& book) const
{ {
if (draw_hidden() || draw_deactivated()) if (draw_hidden() || draw_deactivated())
@ -1319,9 +1369,8 @@ void TReport_field::print(TBook& book) const
switch (_type) switch (_type)
{ {
case 'E': case 'E':
book.set_pen(fore_color(), border()); if (print_tools(book))
book.set_brush(back_color()); book.draw_ellipse(get_draw_rect());
book.draw_ellipse(get_draw_rect());
break; break;
case 'I': case 'I':
{ {
@ -1329,22 +1378,24 @@ void TReport_field::print(TBook& book) const
book.draw_image(get_draw_rect(), name); book.draw_image(get_draw_rect(), name);
if (border() > 0) if (border() > 0)
{ {
book.set_pen(fore_color(), border()); book.set_pen(fore_color(), border()-1);
book.set_brush(COLOR_WHITE); book.set_brush(COLOR_WHITE, PAT_HOLLOW);
book.draw_rectangle(get_draw_rect()); book.draw_rectangle(get_draw_rect());
} }
} }
break; break;
case 'L': case 'L':
book.set_pen(fore_color(), border()); if (border() > 0)
{
book.set_pen(fore_color(), border()-1);
book.draw_line(get_draw_rect()); book.draw_line(get_draw_rect());
}
break; break;
case 'R': case 'R':
book.set_pen(fore_color(), border()); print_rect(book);
book.set_brush(back_color());
book.draw_rectangle(get_draw_rect());
break; break;
case 'T': case 'T':
print_rect(book);
if (!_picture.blank()) if (!_picture.blank())
{ {
book.set_font(font()); book.set_font(font());
@ -1354,10 +1405,7 @@ void TReport_field::print(TBook& book) const
break; break;
default : default :
{ {
book.set_pen(fore_color(), border()); print_rect(book);
book.set_brush(back_color());
book.draw_rectangle(get_draw_rect());
const TString& str = formatted_text(); const TString& str = formatted_text();
if (!str.blank()) if (!str.blank())
{ {

View File

@ -47,6 +47,7 @@ public:
XVT_FONT_STYLE_MASK style() const { return _style; } XVT_FONT_STYLE_MASK style() const { return _style; }
int cpi() const { return _cpi; } int cpi() const { return _cpi; }
XVT_FNTID get_xvt_font(const TWindow& win) const; XVT_FNTID get_xvt_font(const TWindow& win) const;
XVT_FNTID get_preview_font(const TWindow& win, const TPoint& res) const;
void unmap(); void unmap();
int leading() const { return _leading; } int leading() const { return _leading; }
@ -63,45 +64,8 @@ public:
virtual ~TReport_font(); virtual ~TReport_font();
}; };
class TBook : public TObject
{
size_t _pages;
TPointer_array _index;
TFilename _file;
ofstream* _out;
TPoint _delta;
DRAW_CTOOLS _tools;
TReport_font _font;
TRectangle _rect;
protected:
void define_frame(const TRectangle& rect);
void do_text(const TString& str);
public:
void start_page();
void close_page();
void set_pen(COLOR color, int width = 0, int style = P_SOLID);
void set_brush(COLOR color, int pattern = PAT_SOLID);
void set_font(const TReport_font& font);
void set_text_color(COLOR color);
void set_text_align(char halign ='L', char valign = 'T');
void draw_rectangle(const TRectangle& rect);
void draw_ellipse(const TRectangle& rect);
void draw_line(const TRectangle& rect);
void draw_image(const TRectangle& rect, const char* filename);
void draw_text(const TRectangle& rect, const char* text);
void draw_link(const TRectangle& rect, const char* text, const char* link);
size_t pages() const { return _pages; }
bool draw_page(TWindow& win, size_t page);
TBook(const char* name);
virtual ~TBook();
};
class TBook;
class TReport; class TReport;
class TReport_field; class TReport_field;
@ -250,7 +214,7 @@ public:
bool load_fields(); bool load_fields();
bool execute_prescript(); bool execute_prescript();
bool execute_postscript(); bool execute_postscript();
void draw(TWindow& win, TReport_draw_mode mode) const; void print(TBook& book) const;
void save(TXmlItem& report) const; void save(TXmlItem& report) const;
void load(const TXmlItem& sec); void load(const TXmlItem& sec);
@ -394,6 +358,9 @@ public:
virtual void draw_text(TWindow& win, const char* text, TReport_draw_mode mode) const; virtual void draw_text(TWindow& win, const char* text, TReport_draw_mode mode) const;
virtual void draw(TWindow& win, TReport_draw_mode mode) const; virtual void draw(TWindow& win, TReport_draw_mode mode) const;
virtual bool print_tools(TBook& book) const;
virtual void print_rect(TBook& book) const;
virtual void print(TBook& book) const; virtual void print(TBook& book) const;
void save(TXmlItem& root) const; void save(TXmlItem& root) const;

File diff suppressed because it is too large Load Diff

View File

@ -5,96 +5,91 @@
#include <report.h> #include <report.h>
#endif #endif
class TPage_printer : public TWindow class TBook : public TObject
{ {
PRINT_RCD* _rcd; size_t _page, _pages;
long _pw, _ph, _phr, _pvr; // Printer width, height, horizontal and vertical resolution
TArray _links;
bool _links_sorted;
protected:
word _copies, _pagefrom, _pageto, _page, _lastprinted;
bool _page_is_open, _draw_grid;
TMask* _preview_mask; // owned object TPointer_array _index;
TWindow* _preview_window; // referenced object TFilename _file;
ofstream* _out;
bool _is_temporary;
DRAW_CTOOLS _tools;
TReport_font _font;
TRectangle _rect;
char _horizontal_alignment, _vertical_alignment;
virtual word pages() const { return 0; } size_t _pagefrom, _pageto, _copies;
virtual bool print_loop() pure;
private:
virtual TPoint dev2log(const PNT& p) const; // Never use this!
protected: protected:
virtual PNT log2dev(long lx, long ly) const; // Always override this! PRINT_RCD* _rcd;
long _ph, _pw, _pvr, _phr;
bool _page_is_open;
virtual const char* form_name() const; virtual void define_frame(const TRectangle& rect);
virtual const char* font_name() const; virtual bool init();
virtual int font_size() const;
virtual bool ask_pages();
virtual bool open_page();
virtual bool close_page();
bool page_in_range() const;
// Called by print(bool)
virtual bool do_print();
virtual bool do_preview();
public: public:
bool main_loop(); // Internal use only virtual bool open_page();
virtual void print_page(word page); // Inefficient default implementation virtual bool close_page();
virtual bool main_loop();
virtual TPoint page_size() const; void set_pen(COLOR color, int width = 0, PEN_STYLE style = P_SOLID);
virtual TPoint page_res() const; void set_brush(COLOR color, PAT_STYLE pattern = PAT_SOLID);
virtual word last_printed_page() { return _lastprinted; } void set_font(const TReport_font& font);
void set_text_color(COLOR fore, COLOR back = COLOR_WHITE, bool opaque = false);
void set_text_align(char halign ='L', char valign = 'T');
void draw_rectangle(const TRectangle& rect);
void draw_ellipse(const TRectangle& rect);
void draw_line(const TRectangle& rect);
void draw_image(const TRectangle& rect, const char* filename);
void draw_text(const TRectangle& rect, const char* text);
void draw_link(const TRectangle& rect, const char* text, const char* link);
virtual bool print(bool preview = false); TPoint page_size() const;
bool print_mode() const { return _preview_mask == NULL; } TPoint page_res() const;
bool preview_mode() const { return _preview_mask != NULL; } size_t page() const { return _page; }
size_t pages() const { return _pages; }
virtual bool print_page(TWindow& win, size_t page);
void toggle_preview_grid() { _draw_grid = !_draw_grid; } virtual bool print(size_t pagefrom = 0, size_t pageto = 0, size_t copies = 0);
bool show_preview_grid() const { return _draw_grid; } virtual bool preview();
bool print_or_preview(); // Calls one of the above
void add_link(TReport_link* link); TBook(const char* name);
const TReport_link* find_link(const PNT& pnt) const; virtual ~TBook();
virtual bool on_link(const TReport_link& lnk);
TPage_printer();
virtual ~TPage_printer();
}; };
class TReport_printer : public TPage_printer
class TReport_book : public TBook
{ {
TReport& _report; TReport* _report;
TPoint _delta;
long _logical_page_height, _logical_page_width; long _logical_page_height, _logical_page_width;
long _logical_foot_pos; long _logical_foot_pos;
bool _is_last_page, _page_break_allowed; bool _is_last_page, _page_break_allowed;
TPoint _delta;
protected: protected:
virtual const char* form_name() const;
virtual const char* font_name() const;
virtual int font_size() const;
virtual PNT log2dev(long x, long y) const;
virtual bool print_loop();
virtual void draw_preview_page();
virtual bool open_page(); virtual bool open_page();
virtual bool close_page(); virtual bool close_page();
TPoint log2dev(const TPoint& ptlog) const;
virtual void define_frame(const TRectangle& r);
bool init(TReport& rep);
long print_section(TReport_section& rs); long print_section(TReport_section& rs);
long print_section(char type, int level); long print_section(char type, int level);
void create_links(const TReport_section& rs); void create_links(const TReport_section& rs);
public: public:
virtual bool print(bool preview = false); bool add(TReport& report);
virtual bool on_link(const TReport_link& lnk);
virtual bool print(size_t pagefrom = 0, size_t pageto = 0, size_t copies = 0);
TReport_printer(TReport& r) : _report(r) { } TReport_book(const char* name = NULL) : TBook(name) { }
}; };
void lock_preview_update(bool yes);
void abort_printing(); void abort_printing();
#endif #endif