Patch level : 2.1 92

Files correlati     : librerie
Ricompilazione Demo : [ ]
Commento            :

0000216
Nell'anteprima non fuzionano gli acceleratori (Alt-S etc....)


git-svn-id: svn://10.65.10.50/trunk@12256 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2004-07-27 14:20:01 +00:00
parent 43bba26df9
commit 913613ac22
6 changed files with 185 additions and 65 deletions

View File

@ -1,6 +1,7 @@
#include <colors.h>
#include <expr.h>
#include <image.h>
#include <printer.h>
#include <recarray.h>
#include <relation.h>
#include <reprint.h>
@ -116,6 +117,15 @@ void TReport_font::create(const char* name, int size, XVT_FONT_STYLE_MASK style)
unmap();
}
void TReport_font::adapt(const TReport_font& oldfont, const TReport_font& newfont)
{
const int new_size = newfont.size() * _size / oldfont.size();
if (name() == oldfont.name() || name().blank())
create(newfont.name(), new_size, _style);
else
create(_name, new_size, _style);
}
void TReport_font::copy(const TReport_font& font)
{
create(font.name(), font.size(), font.style());
@ -361,6 +371,36 @@ void TReport_section::set_font(const TReport_font& f)
_font = new TReport_font(f);
}
void TReport_section::compute_print_font(const TReport_font& oldfont, const TReport_font& newfont)
{
if (has_font())
{
if (_print_font == NULL)
_print_font = new TReport_font;
*_print_font = font();
_print_font->adapt(oldfont, newfont);
}
for (int i = 0; i < items(); i++)
{
TReport_field& rf = field(i);
rf.compute_print_font(oldfont, newfont);
}
}
const TReport_font& TReport_section::print_font() const
{
const TReport_font* f = _print_font;
if (f == NULL)
{
TReport_section* father = father_section();
if (father == NULL)
f = &_report.print_font();
else
f = &father->print_font();
}
return *f;
}
const TString& TReport_section::prescript() const
{ return _prescript.get(); }
@ -592,7 +632,7 @@ void TReport_section::save(TXmlItem& root) const
if (grouped_by().not_empty())
item.AddChild("groupby") << grouped_by();
if (has_font())
font().save(item);
_font->save(item);
_prescript.save(item, "prescript");
_postscript.save(item, "postscript");
@ -665,18 +705,22 @@ void TReport_section::load(const TXmlItem& sec)
_postscript.load(sec, "postscript");
}
TReport_section::TReport_section(TReport& r, char t, int l)
: _report(r), _type(t), _level(l), _pos(0,0),
_size(0,0), _page_break(false), _hidden_if_needed(false), _keep_with_next(false),
_repeat(false), _hidden(false), _deactivated(false), _font(NULL),
_repeat(false), _hidden(false), _deactivated(false),
_font(NULL), _print_font(NULL),
_bgcolor(COLOR_WHITE), _fgcolor(COLOR_BLACK), _pattern(PAT_HOLLOW),
_border(0), _radius(0)
_border(0), _radius(0)
{ }
TReport_section::~TReport_section()
{
if (_font)
delete _font;
if (_print_font)
delete _print_font;
}
///////////////////////////////////////////////////////////
@ -929,8 +973,6 @@ const TRectangle& TReport_field::get_draw_rect() const
TRectangle& rct = ((TReport_field*)this)->_draw_rct;
if (dynamic_height())
{
// rct = _rct;
int h = 100;
TParagraph_string str(formatted_text(), rct.width()/100);
str.rtrim();
@ -941,7 +983,6 @@ const TRectangle& TReport_field::get_draw_rect() const
if (h > _rct.height())
h = _rct.height();
rct.set_height(h);
// return rct;
}
return rct;
}
@ -951,6 +992,23 @@ const TReport_font& TReport_field::font() const
return _font != NULL ? *_font : _section->font();
}
const TReport_font& TReport_field::print_font() const
{
return _print_font != NULL ? *_print_font : _section->print_font();
}
void TReport_field::compute_print_font(const TReport_font& oldfont, const TReport_font& newfont)
{
if (has_font())
{
if (_print_font == NULL)
_print_font = new TReport_font(font());
else
*_print_font = font();
_print_font->adapt(oldfont, newfont);
}
}
void TReport_field::set_font(const TReport_font& f)
{
if (_font != NULL)
@ -966,6 +1024,8 @@ void TReport_field::unmap_font()
{
if (_font != NULL)
_font->unmap();
if (_print_font != NULL)
_print_font->unmap();
}
const TString& TReport_field::prescript() const
@ -995,7 +1055,8 @@ void TReport_field::copy(const TReport_field& rf)
_rct = rf._rct;
set_dynamic_height(rf.dynamic_height());
_fgcolor = rf._fgcolor; _bgcolor = rf._bgcolor;
_border = rf._border; _radius = rf._radius; _pattern = rf._pattern;
_border = rf._border; _radius = rf._radius;
_pattern = rf._pattern; _shade_offset = rf._shade_offset;
_halign = rf._halign; _valign = rf._valign;
_picture = rf._picture; _field = rf._field;
_hidden = rf.hidden();
@ -1253,12 +1314,26 @@ bool TReport_field::print_tools(TBook& book) const
void TReport_field::print_rect(TBook& book) const
{
if (pattern() == PAT_SOLID && shade_offset() != 0)
{
book.set_pen(COLOR_GRAY, 0);
const COLOR color = blend_colors(section().back_color(), COLOR_BLACK, 0.5);
book.set_brush(color, PAT_SOLID);
TRectangle rct = get_draw_rect();
rct += TPoint(shade_offset(), shade_offset() * section().report().lpi() / font().cpi());
if (radius() > 0)
book.draw_round_rectangle(rct, radius());
else
book.draw_rectangle(rct);
}
if (print_tools(book))
{
const TRectangle& rct = get_draw_rect();
if (radius() > 0)
book.draw_round_rectangle(get_draw_rect(), radius());
book.draw_round_rectangle(rct, radius());
else
book.draw_rectangle(get_draw_rect());
book.draw_rectangle(rct);
}
}
@ -1310,7 +1385,7 @@ void TReport_field::print(TBook& book) const
print_rect(book);
if (!_picture.blank())
{
book.set_font(font());
book.set_font(print_font());
book.set_text_align(horizontal_alignment(), vertical_alignment());
book.set_text_color(fore_color(), back_color());
book.draw_text(get_draw_rect(), _picture);
@ -1329,7 +1404,7 @@ void TReport_field::print(TBook& book) const
const TString& str = formatted_text();
if (!str.blank())
{
book.set_font(font());
book.set_font(print_font());
book.set_text_align(horizontal_alignment(), vertical_alignment());
book.set_text_color(fore_color(), back_color());
book.draw_text(get_draw_rect(), str);
@ -1379,7 +1454,7 @@ void TReport_field::save(TXmlItem& root) const
set_col_attr(fld, "bg_color", back_color(), COLOR_WHITE);
set_col_attr(fld, "fg_color", fore_color(), COLOR_BLACK);
if (has_font())
font().save(fld);
_font->save(fld);
if (in_group(0))
fld.AddChild("groups") << groups();
@ -1404,6 +1479,8 @@ void TReport_field::save(TXmlItem& root) const
}
if (pattern() != PAT_SOLID)
fld.SetAttr("pattern", pattern());
else
fld.SetAttr("shade_offset", shade_offset());
fld.SetAttr("text", picture());
fld.SetAttr("codval", codval());
fld.SetAttr("link", link());
@ -1447,6 +1524,7 @@ bool TReport_field::load(const TXmlItem& fld)
set_border(fld.GetIntAttr("border"));
set_pattern((PAT_STYLE)fld.GetIntAttr("pattern", PAT_SOLID));
set_radius(fld.GetIntAttr("radius"));
set_shade_offset(fld.GetIntAttr("shade_offset"));
set_back_color(get_col_attr(fld, "bg_color", COLOR_WHITE));
set_fore_color(get_col_attr(fld, "fg_color", COLOR_BLACK));
set_horizontal_alignment(get_chr_attr(fld, "align", 'L'));
@ -1535,13 +1613,15 @@ int TReport_field::compare(const TSortable& s) const
TReport_field::TReport_field(TReport_section* sec)
: _section(sec), _id(0), _type('T'), _rct(0,0,1000,100),
_fgcolor(COLOR_BLACK), _bgcolor(COLOR_WHITE), _radius(0), _pattern(PAT_HOLLOW),
_border(0), _halign('L'), _valign('T'),_dynamic_height(false), _font(NULL),
_border(0), _halign('L'), _valign('T'),_dynamic_height(false),
_font(NULL), _print_font(NULL),
_hidden(false), _deactivated(false), _hide_zeroes(false), _selected(false),
_draw_hidden(false), _draw_deactivated(false)
{ }
TReport_field::TReport_field(const TReport_field& rf)
: _section(NULL), _font(NULL), _draw_hidden(false), _draw_deactivated(false)
: _section(NULL), _font(NULL), _print_font(NULL), _draw_hidden(false),
_draw_deactivated(false)
{
copy(rf);
@ -1551,6 +1631,8 @@ TReport_field::~TReport_field()
{
if (_font != NULL)
delete _font;
if (_print_font != NULL)
delete _print_font;
}
///////////////////////////////////////////////////////////
@ -1599,6 +1681,34 @@ int TReport::find_max_level(char type) const
return lev;
}
const TReport_font& TReport::print_font() const
{ return _use_printer_font ? _print_font : _font; }
int TReport::cpi() const
{
return _use_printer_font ? _print_font.cpi() : _font.cpi();
}
int TReport::lpi() const
{
return _use_printer_font ? printer().get_lines_per_inch() : _lpi;
}
void TReport::load_printer_font()
{
if (_use_printer_font)
{
const TPrinter& p = printer();
_print_font.create(p.fontname(), p.get_char_size(), XVT_FS_NONE);
FOR_EACH_ASSOC_OBJECT(_sections, h, k, o)
{
TReport_section* rs = (TReport_section*)o;
rs->compute_print_font(_font, _print_font);
}
}
}
bool TReport::set_recordset(TRecordset* rs)
{
if (_recordset != NULL)
@ -1778,6 +1888,7 @@ bool TReport::load(const char* fname)
{
_lpi = xml.GetIntAttr("lpi", 6);
_font.load(xml);
_use_printer_font = xml.GetBoolAttr("use_printer_font");
const TXmlItem* desc = xml.FindFirstChild("description");
if (desc != NULL)
@ -1831,11 +1942,12 @@ bool TReport::save(const char* fname) const
TXmlItem xml;
xml.SetTag("report");
xml.SetAttr("name", name);
xml.SetAttr("lpi", lpi());
xml.SetAttr("lpi", _lpi);
if (!_description.blank())
xml.AddChild("description") << _description;
xml.SetAttr("libraries", _include);
_font.save(xml);
xml.SetAttr("use_printer_font", use_printer_font() ? 1 : 0);
const char* sectype = "HBF";
for (int j = 0; j < 3; j++)
@ -2424,7 +2536,9 @@ void TReport::include_libraries(bool reload)
}
}
TReport::TReport() : _lpi(6), _include(15, ','), _recordset(NULL), _curr_field(NULL)
TReport::TReport()
: _lpi(6), _include(15, ','), _recordset(NULL), _curr_field(NULL),
_use_printer_font(false)
{
_expressions.set_report(this);
_prescript.set_description("PRESCRIPT");

View File

@ -57,6 +57,7 @@ public:
void save(TXmlItem& root) const;
bool load(const TXmlItem& root);
void adapt(const TReport_font& oldfont, const TReport_font& newfont);
void create(const char* name, int size, XVT_FONT_STYLE_MASK style);
TReport_font& operator=(const TReport_font& f) { copy(f); return *this; }
TReport_font();
@ -154,7 +155,7 @@ class TReport_section : public TArray
PAT_STYLE _pattern;
TReport_script _prescript, _postscript;
TReport_font* _font;
TReport_font *_font, *_print_font;
protected:
virtual const char* class_name() const { return "ReportSection"; }
@ -225,8 +226,11 @@ public:
bool has_font() const { return _font != NULL; }
const TReport_font& font() const;
const TReport_font& print_font() const;
void set_font(const TReport_font& f);
void unmap_font();
void compute_print_font(const TReport_font& oldfont, const TReport_font& newfont);
bool load_fields();
bool execute_prescript();
@ -249,7 +253,7 @@ class TReport_field : public TSortable
char _type; // Text, String, Numeric, Price, Valuta, Date, Line, Rectangle, Image
TRectangle _rct; // In centesimi
COLOR _fgcolor, _bgcolor;
int _border, _radius;
int _border, _radius, _shade_offset;
PAT_STYLE _pattern;
char _halign, _valign;
bool _dynamic_height;
@ -260,7 +264,7 @@ class TReport_field : public TSortable
TReport_script _prescript, _postscript;
TArray _list; // Elementi di un campo lista
TReport_font* _font;
TReport_font *_font, *_print_font;
bool _hidden, _deactivated, _hide_zeroes, _selected;
TRectangle _draw_rct; // In centesimi
@ -284,8 +288,10 @@ public:
bool has_font() const { return _font != NULL; }
const TReport_font& font() const;
const TReport_font& print_font() const;
void set_font(const TReport_font& f);
void unmap_font();
void compute_print_font(const TReport_font& oldfont, const TReport_font& newfont);
const TString& picture() const { return _picture; }
void set_picture(const char* str) { _picture = str; }
@ -363,6 +369,8 @@ public:
PAT_STYLE pattern() const { return _pattern; }
void set_radius(int r) { _radius = r; }
short radius() const { return _radius; }
void set_shade_offset(int s) { _shade_offset = s; }
short shade_offset() const { return _shade_offset; }
void set_horizontal_alignment(char a) { _halign = a; }
char horizontal_alignment() const { return _halign; }
@ -420,14 +428,15 @@ class TReport : public TAlex_virtual_machine
TAssoc_array _sections;
TFilename _path;
TString _description;
TReport_font _font;
int _lpi; // Lines per inch
TReport_font _font, _print_font; // Font
int _lpi; // Lines per inch
TToken_string _include;
TReport_script _prescript, _postscript;
TString_array _params;
TRecordset* _recordset;
TReport_expr_cache _expressions;
word _rep_page, _book_page;
bool _use_printer_font;
TReport_field* _curr_field;
protected:
@ -461,12 +470,17 @@ public:
virtual bool on_link(const TReport_link& link);
const TReport_font& font() const { return _font; }
const TReport_font& font() const { return _font; }
const TReport_font& print_font() const;
void set_use_printer_font(bool on) { _use_printer_font = on; }
bool use_printer_font() const { return _use_printer_font; }
void set_font(const TReport_font& f) { _font = f; }
void unmap_font();
void load_printer_font();
int cpi() const { return _font.cpi(); }
int lpi() const { return _lpi; }
int cpi() const;
int lpi() const;
void set_lpi(int lpi) { _lpi = lpi; }
bool set_recordset(const TString& sql);

View File

@ -15,36 +15,6 @@ static bool _print_aborted = false;
// Utility
///////////////////////////////////////////////////////////
bool advanced_set_draw_tools(TWindow& win, PAT_STYLE pat, int border, COLOR fore, COLOR back)
{
const bool has_pen = border > 0;
const bool has_brush = pat > PAT_HOLLOW && back != COLOR_WHITE;
const bool visible = has_pen || has_brush;
if (visible)
{
if (has_pen)
win.set_pen(fore, border, PAT_SOLID);
else
win.hide_pen();
if (has_brush)
win.set_brush(back, pat);
else
win.hide_brush();
}
return visible;
}
void advanced_draw_rect(TWindow& win, const RCT& r, PAT_STYLE pat, int border, COLOR fore, COLOR back, int radius)
{
if (advanced_set_draw_tools(win, pat, border, fore, back))
{
if (radius > 0)
xvt_dwin_draw_roundrect(win.win(), &r, radius, radius);
else
xvt_dwin_draw_rect(win.win(), (RCT*)&r);
}
}
void advanced_draw_justified_text(TWindow& win, const char* text, short x, short y, short dx)
{
TString txt(text); txt.rtrim();
@ -246,6 +216,7 @@ public:
TPrint_preview_window(int x, int y, int dx, int dy, WINDOW parent,
TWindowed_field* owner, TBook* book);
virtual ~TPrint_preview_window();
};
PNT TPrint_preview_window::log2dev(long lx, long ly) const
@ -532,10 +503,19 @@ bool TPrint_preview_window::on_key(KEY k)
TPrint_preview_window::TPrint_preview_window(int x, int y, int dx, int dy, WINDOW parent,
TWindowed_field* owner, TBook* book)
: TField_window(x, y, dx, dy, parent, owner), _book(book), _page(1), _zoom(100), _grid(true)
: TField_window(x, y, dx, dy, parent, owner), _book(book), _page(1), _zoom(100), _grid(false)
{
_pixmap = true;
update_scroll_range();
TConfig ini(CONFIG_GUI, "Preview");
_grid = ini.get_bool("Grid");
}
TPrint_preview_window::~TPrint_preview_window()
{
TConfig ini(CONFIG_GUI, "Preview");
ini.set("Grid", _grid ? "X" : "");
}
///////////////////////////////////////////////////////////
@ -949,9 +929,12 @@ bool TBook::print_page(TWindow& win, size_t page)
pw.alinks().destroy();
}
TString str(1024);
const int buffer_size = 1024;
TString str(buffer_size);
char* buffer = str.get_buffer();
TString stringona; // Testo completo di un campo
const streampos pos = _index.get_long(page);
ifstream ifs(_file);
ifs.seekg(pos);
@ -1099,14 +1082,16 @@ bool TBook::print_page(TWindow& win, size_t page)
if (str.starts_with("<rounded_rectangle"))
{
const int radius = get_xml_int(str, "radius", 0);
const TRectangle rr(0,0,radius,radius);
RCT re; win.log2dev(rr, re);
xvt_dwin_draw_roundrect(win.win(), &rct, re.right-re.left, re.bottom-re.top);
const int rad = (re.right-re.left) * lpi() / (cpi() * 2);
xvt_dwin_draw_roundrect(win.win(), &rct, rad, rad);
continue;
}
if (str == "<text>")
{
TString stringona;
stringona.cut(0);
while (!ifs.eof())
{
ifs.getline(buffer, str.size());
@ -1593,6 +1578,8 @@ bool TReport_book::init(TReport& rep)
return false;
_report = &rep;
if (_report->use_printer_font())
_report->load_printer_font();
const TPoint siz = page_size();
const TPoint res = page_res();

View File

@ -106,7 +106,7 @@ public:
};
bool advanced_set_draw_tools(TWindow& win, PAT_STYLE pat, int border, COLOR fore, COLOR back);
void advanced_draw_rect(TWindow& win, const RCT& r, PAT_STYLE pat, int border, COLOR fore, COLOR back, int radius);
void advanced_draw_rect(TWindow& win, const RCT& r, PAT_STYLE pat, int border, COLOR fore, COLOR back, int radius, int shade);
void advanced_draw_text(TWindow& win, const char* text, const RCT& r,
char halign, char valign);
void advanced_draw_paragraph(TWindow& win, TString& text, const RCT& r,

View File

@ -116,7 +116,7 @@ TSheet_control::TSheet_control(
// Calcolo larghezza massima tabella
TToken_string header(head);
TToken_string new_header(256);
TToken_string new_header(header.size());
int f_width = NUMBER_WIDTH; // Stima larghezza colonne fisse
int max_width = f_width; // Stima larghezza della colonna piu' grande
int lines_in_header = 1;
@ -140,7 +140,7 @@ TSheet_control::TSheet_control(
lines_in_header = 2;
}
const int at = testa.find('@');
const int at = testa.rfind('@');
int v = testa.len(); // Video width
if (at >= 0)
{

View File

@ -119,7 +119,7 @@ public:
void TXmlAttr::Write(ostream& outf) const
{
outf << '"';
print_on(outf);
WriteXmlString(outf, *this);
outf << '"';
}
@ -220,9 +220,14 @@ bool TXmlItem::GetWord(istream& inf, TString& str) const
int c = inf.get();
if (bIsString)
{
if (c >= '\0' && c <= ' ')
c = ' ';
str << char(c);
if (c == '&')
str << EscapeSequence(c, inf);
else
{
if (c >= '\0' && c <= ' ')
c = ' ';
str << char(c);
}
if (c == cFirstChar)
break;
}