From 7abff04a8503314fb5273ce997931b4c808523db Mon Sep 17 00:00:00 2001 From: guy Date: Wed, 10 May 1995 15:40:06 +0000 Subject: [PATCH] Gestione dei font di stampa git-svn-id: svn://10.65.10.50/trunk@1355 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/bagn001a.uml | 27 +- include/maskfld.h | 1162 +++++++++++++++++++++--------------------- include/printer.cpp | 283 +++++----- include/printer.h | 29 +- include/printwin.cpp | 97 ++-- 5 files changed, 835 insertions(+), 763 deletions(-) diff --git a/include/bagn001a.uml b/include/bagn001a.uml index aa4d66854..db3fe6608 100755 --- a/include/bagn001a.uml +++ b/include/bagn001a.uml @@ -12,6 +12,7 @@ BEGIN MESSAGE ENABLE,MSK_1_CODES MESSAGE ENABLE,MSK_1_SIZE MESSAGE ENABLE,MSK_1_LINES + MESSAGE ENABLE,MSK_1_FONT MESSAGE ENABLE,DLG_SETPRINT ITEM "2|Visualizzazione" MESSAGE HIDE,MSK_1_FILENAME @@ -19,6 +20,7 @@ BEGIN MESSAGE DISABLE,MSK_1_CODES MESSAGE DISABLE,MSK_1_SIZE MESSAGE DISABLE,MSK_1_LINES + MESSAGE DISABLE,MSK_1_FONT MESSAGE DISABLE,DLG_SETPRINT ITEM "1|File su disco" MESSAGE SHOW,MSK_1_FILENAME @@ -26,6 +28,7 @@ BEGIN MESSAGE ENABLE,MSK_1_CODES MESSAGE DISABLE,MSK_1_SIZE MESSAGE DISABLE,MSK_1_LINES + MESSAGE DISABLE,MSK_1_FONT MESSAGE DISABLE,DLG_SETPRINT FLAGS "Z" END @@ -35,6 +38,7 @@ BEGIN /* viene riempito a run-time con nomi letti da config */ PROMPT 4 5 "Stampante " HELP "Selezionare il tipo di stampante desiderata" + FLAGS "G" END STRING MSK_1_FILENAME 52 @@ -51,17 +55,20 @@ LIST MSK_1_CODES 40 BEGIN PROMPT 4 6 "Tipo stampa " HELP "Modalita' nelle quale si desidera la stampa" + FLAGS "H" END +LIST MSK_1_FONT 2 16 +BEGIN + PROMPT 4 6 "Font " + HELP "Font di stampa su video o stampante" + ITEM "Courier|Courier" +END + LIST MSK_1_SIZE 3 BEGIN PROMPT 31 6 "Carattere " -// ITEM "7|7" - ITEM "8|8" - ITEM "10|10" ITEM "12|12" - ITEM "15|15" - ITEM "17|17" HELP "Dimensioni del carattere di stampa" END @@ -78,15 +85,7 @@ BEGIN HELP "Numero di linee per pollice" END -LIST MSK_1_FONT 10 -BEGIN - PROMPT 4 6 "Font " - HELP "Font di stampa su video o stampante" - ITEM "1|Courier" - FLAGS "D" -END - -NUMBER MSK_1_NPAGES 3 0 +NUMBER MSK_1_NPAGES 3 BEGIN PROMPT 54 8 "N.o copie " HELP "Numero di copie da fare" diff --git a/include/maskfld.h b/include/maskfld.h index 3f96e9279..b5bbd47f7 100755 --- a/include/maskfld.h +++ b/include/maskfld.h @@ -1,581 +1,581 @@ -/* $Id: maskfld.h,v 1.27 1995-04-10 15:10:08 nik Exp $ */ -#ifndef __MASKFLD_H -#define __MASKFLD_H - -#ifndef __REAL_H -#include -#endif - -#ifndef __SCANNER_H -#include -#endif - -class TMask_field; - -class TRelation; // __RELATION_H -class TCursor; -class TFieldref; -class TArray_sheet; // __SHEET_H - -// @T -typedef bool (*CONTROL_HANDLER)(TMask_field& field, KEY key); -// @END - -enum CheckType { CHECK_NONE, CHECK_NORMAL, CHECK_REQUIRED }; -enum CheckTime { RUNNING_CHECK, STARTING_CHECK, FINAL_CHECK }; - -// @C -// Classe TMask_field : public TObject -// @END - -class TMask_field : public TObject -{ - // @DPRIV - friend class TMask; - - TMask* _mask; // The mask the control belongs to - - TString _help; // Help message - TFieldref* _field; // Corresponding field on the file - TBit_array _keys; // The keys the field belongs to - TBit_array _groups; // The groups the field belongs to - - // nuovo - TToken_string _userdata; // User Data - -protected: - // @DPROT - static int _x, _y; // Coordinate of the control - static int _width; // Size of the control - static TString80 _prompt; - CONTROL_HANDLER _handler; - - int _size; // Max length of the string - - WINDOW _win; // Window of the control (not its parent!) - WINDOW _promptwin; // Prompt of the control - short _dlg; // Identifier of the control - - int _validate_func; // Number of validation function - TArray _validate_parms; // Parameters for validation function - TArray _message; // Messages to send on modify - - struct TField_Flags - { - bool automagic : 1; - bool dirty : 2; // Modified during run ? - bool enabled : 1; // Is editable - bool enable_default : 1; - bool firm : 1; // Is the current firm ? - bool focusdirty : 1; // Modified during focus ? - bool ghost : 1; - bool password : 1; - bool persistent : 1; - bool rightjust : 1; - bool roman : 1; // Is a Roman number ? - bool shown : 1; // Is visible - bool show_default : 1; - bool trim : 1; // Trim the string - bool uppercase : 1; - bool exchange : 1; // Value exchange - bool zerofilled : 1; - - TField_Flags(); - char update(const char*); - } _flags; - - void construct(TScanner& scanner, WINDOW parent); - void construct(short id, const char* prompt, int x, int y, int len, - WINDOW parent, const char* flags = "", int width = 0); - - virtual WINDOW win() const { return _win; } - - WINDOW wincreate(WIN_TYPE ct, short dx, short dy, - const char* title, WINDOW parent, long flags); - int create_prompt(WINDOW parent, int width = 0, int heigth = 1); - - long default_flags() const; - - virtual void parse_head(TScanner& scanner); - virtual bool parse_item(TScanner& scanner); - - virtual void create(WINDOW parent); - virtual void destroy(); - virtual void highlight() const; - - virtual const char* get_window_data() const; - virtual void set_window_data(const char* data); - virtual void set_field_data(const char* data); - virtual const char* get_field_data() const; - virtual void exchange(bool show_value, const real& n) {} - - bool do_message(int n); - -public: - // @FPUB - short atodlg(const char* s) const; - - WINDOW parent() const; - short dlg() const { return _dlg; } - - virtual bool ok() const; - - bool dirty() const { return _flags.dirty; } - bool focusdirty() const { return _flags.focusdirty; } - void set_focusdirty(bool d = TRUE) { _flags.focusdirty = d; } - void set_dirty(bool d = TRUE); - void set_justify(bool r) { _flags.rightjust = r; } - - virtual const char* class_name() const; - virtual word class_id() const; - - int size() const { return _size; } - - bool roman() const { return _flags.roman; } - bool automagic() const { return _flags.automagic; } - bool ghost() const { return _flags.ghost; } - bool exchangeable() const { return _flags.exchange; } - - virtual bool has_check() const { return FALSE;} - virtual bool has_query() const { return FALSE;} - virtual bool has_message() const { return _message.items() > 0; } - - virtual CheckType check_type() const { return CHECK_NONE; } - bool required() const { return check_type() == CHECK_REQUIRED; } - virtual bool check(CheckTime = RUNNING_CHECK) { return TRUE;} - - virtual void reset(); - - virtual void enable(bool on = TRUE); - void disable() { enable(FALSE); } - bool enabled() const { return _flags.enabled; } - void enable_default(); - bool enabled_default() const { return _flags.enable_default; } - - virtual void show(bool on = TRUE); - void hide() { show(FALSE); } - bool shown() const { return _flags.shown; } - void show_default(); - - bool active() const; // Is visible and enabled? - - void set_handler(CONTROL_HANDLER handler) { _handler = handler; } - - bool is_edit() const; - bool to_check(KEY k, bool checkrun = FALSE) const; - - virtual bool on_hit(); - virtual bool on_key(KEY key); - virtual bool test_focus_change(); - - void set(const char* s); - TString& get() const; - - TToken_string& custom_data() { return _userdata; }; - - virtual const char* picture_data(const char* data, bool video); - virtual const char* warning() { return "";} - - virtual bool autoload(const TRelation* r = NULL); - bool autosave(TRelation* r = NULL) const; - - void undo(); - - const char* prompt() const; - void set_prompt(const char* p); - - bool in_key(byte key) const { return _keys[key]; } - void set_key(byte key) { _keys.set(long(key)); _keys.set(0L);} - word last_key() const; - - bool in_group(byte group) const { return _groups[group]; } - void set_group(byte group) { _groups.set(long(group)); _groups.set(0L);} - - const TFieldref* field() const { return _field; } - - void set_focus() const; - void send_key(KEY k, short to); - - // set focus, message-box, set focus - bool message_box(const char* fmt, ...) const; - bool warning_box(const char* fmt, ...) const; - bool error_box(const char* fmt, ...) const; - bool yesno_box(const char* fmt, ...) const; - KEY yesnocancel_box(const char* fmt, ...) const; - - TMask& mask() const { return *_mask; } - TMask_field(TMask* mask); - virtual ~TMask_field(); -}; - - -// @C -// Classe TEdit_field : public TMask_field -// -// @END - -class TEdit_field : public TMask_field -{ - friend class TBrowse; - friend class TList_sheet; - friend class TBrowse_sheet; - -protected: - // @DPROT - TString256 _str; - TString16 _picture; - TString _warning; - CheckType _check; // Accettabilita' di valori nulli - bool _forced; - bool _check_enabled; // Abilitato - - TBrowse* _browse; - TList_sheet* _sheet; - WINDOW _buttonwin; - - const TBrowse* get_browse(TScanner& scanner) const; - - virtual word class_id() const; - virtual void parse_head(TScanner& scanner); - virtual bool parse_item(TScanner& scanner); - - virtual void create(WINDOW parent); - virtual void destroy(); - - bool validate(KEY k); - - virtual void set_window_data(const char* data); - virtual void set_field_data(const char* data); - virtual const char* get_field_data() const; - bool default_error_box() const; - -public: - // @FPUB - virtual bool on_hit(); - virtual bool on_key(KEY key); - virtual bool has_check() const; - virtual bool has_query() const { return _browse || _sheet;} - virtual const char* picture_data(const char* data, bool video); - virtual const char * warning() { return _warning;} - virtual void show(bool on = TRUE); - virtual void enable(bool on = TRUE); - virtual CheckType check_type() const { return _check; } - void check_type(CheckType c) { _check = c; } - - bool forced() const { return _forced;} - virtual bool check(CheckTime = RUNNING_CHECK); - TBrowse* browse() const { return _browse;} - TList_sheet* sheet() const { return _sheet;} - void enable_check(bool on = TRUE) ; - bool check_enabled() const { return _check_enabled;} - - const char* format(const char* data); - const char* picture() const { return _picture; } - - TEdit_field(TMask* mask); - virtual ~TEdit_field(); -}; - - -/////////////////////////////////////////////////////////// -// TBrowse -/////////////////////////////////////////////////////////// - -class TBrowse -{ - TEdit_field* _fld; // The field owning the sheet - TRelation* _relation; // Main relation - TCursor* _cursor; // Cursor on the relation - TString _insert; - TString _filter; - long _rec; - bool _secondary; - bool _checked; - - TToken_string _head, _items; - TToken_string _inp_id, _inp_fn; - TToken_string _out_id, _out_fn; - -protected: - void do_output(CheckTime = RUNNING_CHECK); - void do_clear(); - bool do_insert(); - - TMask_field& field(short n) const; - TToken_string& create_siblings(TToken_string& siblings); - -public: - int inputs(); - int do_input(bool filter = FALSE); // Serve ai TCursor_sheet - - TBrowse(TEdit_field* f, TRelation* r, int key = 1, const char* filter = ""); - TBrowse(TEdit_field* f, TCursor* c); - ~TBrowse(); - - void parse_join(TScanner& scanner); - void parse_input(TScanner& scanner); - void parse_display(TScanner& scanner); - void parse_output(TScanner& scanner); - void parse_insert(TScanner& scanner); - bool parse_copy(const TString& what, const TBrowse& b); - - void set_insert(const char* s) { _insert = s;} - const TString& get_insert() const { return _insert;} - const TString& get_filter() const { return _filter;} - - TEdit_field& field() const { return *_fld; } - - bool check(CheckTime = RUNNING_CHECK); - bool empty_check(); - const TToken_string& head() const { return _head;} - const TToken_string& items() const { return _items;} - TCursor* cursor() const { return _cursor;} - bool checked() const { return _checked;} - bool secondary() const { return _secondary;} - - KEY run(); -}; - -/////////////////////////////////////////////////////////// -// TList_sheet -/////////////////////////////////////////////////////////// - -class TList_sheet -{ - TEdit_field* _fld; // The field owning the sheet - TArray_sheet* _sheet; // sheet with data; - int _row; - - TToken_string _inp_id; - TToken_string _out_id; - -protected: - int do_input(); - void do_output(CheckTime = RUNNING_CHECK); - bool do_insert(); - TMask_field& field(short id) const; - -public: - TList_sheet(TEdit_field* f, const char* caption, const char* head); - ~TList_sheet(); - - void parse_input(TScanner& scanner); - void read_item(TScanner& scanner); - void parse_output(TScanner& scanner); - TArray_sheet* sheet() { return _sheet; } - TEdit_field& field() const { return *_fld; } - - bool check(CheckTime = RUNNING_CHECK); - - KEY run(); -}; - -// @C -// class TReal_field : public TEdit_field -// @END - -class TReal_field : public TEdit_field -{ - int _decimals; - -protected: - // @FPROT - virtual word class_id() const; - - virtual const char* get_window_data() const; - virtual void set_window_data(const char* data); - virtual void exchange(bool show_value, const real& n); - - virtual void create(WINDOW parent); - virtual void parse_head(TScanner& scanner); - virtual bool on_key(KEY key); - virtual bool autoload(const TRelation* r); - -public: - // @FPUB - - void set_decimals(int d); // Set precision & picture - int decimals() const { return _decimals; } // Get precision - - TReal_field(TMask* mask); -}; - - -// @C -// class TDate_field : public TEdit_field -//@END - -class TDate_field : public TEdit_field -{ -protected: - // @FPROT - const char* format_data(const char* data,bool* changed=NULL); - - virtual word class_id() const; - virtual void create(WINDOW parent); - virtual bool on_key(KEY key); - virtual const char* get_window_data() const; - virtual void set_window_data(const char* data); - virtual const char* picture_data(const char* data, bool video); - -public: - // @FPUB - void parse_head(TScanner& scanner); - TDate_field(TMask* mask); -}; - - -// @C -// class TBoolean_field : public TMask_field -// @END - -class TBoolean_field : public TMask_field -{ -protected: - // @DPROT - bool _on; - - virtual word class_id() const; - - virtual void create(WINDOW parent); - virtual const char* get_window_data() const; - virtual void set_window_data(const char* data); - virtual void set_field_data(const char* data = NULL); - virtual const char* get_field_data() const; - virtual bool parse_item(TScanner& scanner); - virtual void enable(bool on); - virtual bool on_hit(); - virtual bool on_key(KEY key); - -public: - // @FPUB - TBoolean_field(TMask* mask); -}; - - -// @C -// class TList_field : public TMask_field -// @END - -class TList_field : public TMask_field -{ - // @FPRIV - void add_list(); - -protected: - // @FPROT - TToken_string _values; - TToken_string _codes; - TString80 _str; - - virtual word class_id() const; - - virtual void set_window_data(const char* data); - virtual const char* get_window_data() const; - virtual void set_field_data(const char* data = NULL); - virtual const char* get_field_data() const; - - virtual void create(WINDOW parent); - - virtual void current(int n); - virtual int current() const; - - int str2curr(const char* data); - virtual bool on_hit(); - virtual bool on_key(KEY key); - virtual void read_item(TScanner& scanner); - - virtual void parse_head(TScanner& scanner); - virtual bool parse_item(TScanner& scanner); - -public: - // @FPUB - TList_field(TMask* mask); - virtual void replace_items(const char* codes, const char* values); - virtual void add_item(const char* code_value); - virtual void delete_item(const char* code); - int items() const; -}; - - -// @C -// class TRadio_field : public TList_field -// @END - -class TRadio_field : public TList_field -{ - enum { MAX_RADIO = 8 }; - - // @FPRIV - int _nitems; - int _active_item; - WINDOW _radio_ctl_win[MAX_RADIO]; - -protected: - // @FPROT - virtual word class_id() const; - virtual void create(WINDOW parent); - virtual void destroy(); - virtual void enable(bool on); - virtual void show(bool on); - - virtual void current(int n); - virtual int current() const; - WINDOW win() const { return _radio_ctl_win[_active_item]; } - -public: - // @FPUB - TRadio_field(TMask* mask); - - void check_radiobutton(WINDOW checked); - bool move_focus(int d); -}; - - - -// @C -// class TButton_field : public TMask_field -// @END - -class TButton_field : public TMask_field -{ - KEY _virtual_key, _exit_key; - -protected: - // @FPROT - virtual word class_id() const; - virtual void create(WINDOW parent); - - void parse_head(TScanner& scanner); - bool parse_item(TScanner& scanner); - virtual void enable(bool); - virtual void show(bool); - virtual bool on_key(KEY key); - -public: - // @FPUB - TButton_field(TMask* mask); - KEY virtual_key() const { return _virtual_key; } - KEY exit_key() const { return _exit_key; } -}; - - -// @C -// class TGroup_field : public TMask_field -// @END - -class TGroup_field : public TMask_field -{ -protected: - // @DPROT - virtual void parse_head(TScanner& scanner); - virtual void create(WINDOW parent); - virtual void set_window_data(const char* data); - virtual void set_field_data(const char* data); - -public: - // @FPUB - TGroup_field(TMask* mask); -}; - -#endif // __MASKFLD_H +/* $Id: maskfld.h,v 1.28 1995-05-10 15:39:56 guy Exp $ */ +#ifndef __MASKFLD_H +#define __MASKFLD_H + +#ifndef __REAL_H +#include +#endif + +#ifndef __SCANNER_H +#include +#endif + +class TMask_field; + +class TRelation; // __RELATION_H +class TCursor; +class TFieldref; +class TArray_sheet; // __SHEET_H + +// @T +typedef bool (*CONTROL_HANDLER)(TMask_field& field, KEY key); +// @END + +enum CheckType { CHECK_NONE, CHECK_NORMAL, CHECK_REQUIRED }; +enum CheckTime { RUNNING_CHECK, STARTING_CHECK, FINAL_CHECK }; + +// @C +// Classe TMask_field : public TObject +// @END + +class TMask_field : public TObject +{ + // @DPRIV + friend class TMask; + + TMask* _mask; // The mask the control belongs to + + TString _help; // Help message + TFieldref* _field; // Corresponding field on the file + TBit_array _keys; // The keys the field belongs to + TBit_array _groups; // The groups the field belongs to + + // nuovo + TToken_string _userdata; // User Data + +protected: + // @DPROT + static int _x, _y; // Coordinate of the control + static int _width; // Size of the control + static TString80 _prompt; + CONTROL_HANDLER _handler; + + int _size; // Max length of the string + + WINDOW _win; // Window of the control (not its parent!) + WINDOW _promptwin; // Prompt of the control + short _dlg; // Identifier of the control + + int _validate_func; // Number of validation function + TArray _validate_parms; // Parameters for validation function + TArray _message; // Messages to send on modify + + struct TField_Flags + { + bool automagic : 1; + bool dirty : 2; // Modified during run ? + bool enabled : 1; // Is editable + bool enable_default : 1; + bool firm : 1; // Is the current firm ? + bool focusdirty : 1; // Modified during focus ? + bool ghost : 1; + bool password : 1; + bool persistent : 1; + bool rightjust : 1; + bool roman : 1; // Is a Roman number ? + bool shown : 1; // Is visible + bool show_default : 1; + bool trim : 1; // Trim the string + bool uppercase : 1; + bool exchange : 1; // Value exchange + bool zerofilled : 1; + + TField_Flags(); + char update(const char*); + } _flags; + + void construct(TScanner& scanner, WINDOW parent); + void construct(short id, const char* prompt, int x, int y, int len, + WINDOW parent, const char* flags = "", int width = 0); + + virtual WINDOW win() const { return _win; } + + WINDOW wincreate(WIN_TYPE ct, short dx, short dy, + const char* title, WINDOW parent, long flags); + int create_prompt(WINDOW parent, int width = 0, int heigth = 1); + + long default_flags() const; + + virtual void parse_head(TScanner& scanner); + virtual bool parse_item(TScanner& scanner); + + virtual void create(WINDOW parent); + virtual void destroy(); + virtual void highlight() const; + + virtual const char* get_window_data() const; + virtual void set_window_data(const char* data); + virtual void set_field_data(const char* data); + virtual const char* get_field_data() const; + virtual void exchange(bool show_value, const real& n) {} + + bool do_message(int n); + +public: + // @FPUB + short atodlg(const char* s) const; + + WINDOW parent() const; + short dlg() const { return _dlg; } + + virtual bool ok() const; + + bool dirty() const { return _flags.dirty; } + bool focusdirty() const { return _flags.focusdirty; } + void set_focusdirty(bool d = TRUE) { _flags.focusdirty = d; } + void set_dirty(bool d = TRUE); + void set_justify(bool r) { _flags.rightjust = r; } + + virtual const char* class_name() const; + virtual word class_id() const; + + int size() const { return _size; } + + bool roman() const { return _flags.roman; } + bool automagic() const { return _flags.automagic; } + bool ghost() const { return _flags.ghost; } + bool exchangeable() const { return _flags.exchange; } + + virtual bool has_check() const { return FALSE;} + virtual bool has_query() const { return FALSE;} + virtual bool has_message() const { return _message.items() > 0; } + + virtual CheckType check_type() const { return CHECK_NONE; } + bool required() const { return check_type() == CHECK_REQUIRED; } + virtual bool check(CheckTime = RUNNING_CHECK) { return TRUE;} + + virtual void reset(); + + virtual void enable(bool on = TRUE); + void disable() { enable(FALSE); } + bool enabled() const { return _flags.enabled; } + void enable_default(); + bool enabled_default() const { return _flags.enable_default; } + + virtual void show(bool on = TRUE); + void hide() { show(FALSE); } + bool shown() const { return _flags.shown; } + void show_default(); + + bool active() const; // Is visible and enabled? + + void set_handler(CONTROL_HANDLER handler) { _handler = handler; } + + bool is_edit() const; + bool to_check(KEY k, bool checkrun = FALSE) const; + + virtual bool on_hit(); + virtual bool on_key(KEY key); + virtual bool test_focus_change(); + + void set(const char* s); + TString& get() const; + + TToken_string& custom_data() { return _userdata; }; + + virtual const char* picture_data(const char* data, bool video); + virtual const char* warning() { return "";} + + virtual bool autoload(const TRelation* r = NULL); + bool autosave(TRelation* r = NULL) const; + + void undo(); + + const char* prompt() const; + void set_prompt(const char* p); + + bool in_key(byte key) const { return _keys[key]; } + void set_key(byte key) { _keys.set(long(key)); _keys.set(0L);} + word last_key() const; + + bool in_group(byte group) const { return _groups[group]; } + void set_group(byte group) { _groups.set(long(group)); _groups.set(0L);} + + const TFieldref* field() const { return _field; } + + void set_focus() const; + void send_key(KEY k, short to); + + // set focus, message-box, set focus + bool message_box(const char* fmt, ...) const; + bool warning_box(const char* fmt, ...) const; + bool error_box(const char* fmt, ...) const; + bool yesno_box(const char* fmt, ...) const; + KEY yesnocancel_box(const char* fmt, ...) const; + + TMask& mask() const { return *_mask; } + TMask_field(TMask* mask); + virtual ~TMask_field(); +}; + + +// @C +// Classe TEdit_field : public TMask_field +// +// @END + +class TEdit_field : public TMask_field +{ + friend class TBrowse; + friend class TList_sheet; + friend class TBrowse_sheet; + +protected: + // @DPROT + TString256 _str; + TString16 _picture; + TString _warning; + CheckType _check; // Accettabilita' di valori nulli + bool _forced; + bool _check_enabled; // Abilitato + + TBrowse* _browse; + TList_sheet* _sheet; + WINDOW _buttonwin; + + const TBrowse* get_browse(TScanner& scanner) const; + + virtual word class_id() const; + virtual void parse_head(TScanner& scanner); + virtual bool parse_item(TScanner& scanner); + + virtual void create(WINDOW parent); + virtual void destroy(); + + bool validate(KEY k); + + virtual void set_window_data(const char* data); + virtual void set_field_data(const char* data); + virtual const char* get_field_data() const; + bool default_error_box() const; + +public: + // @FPUB + virtual bool on_hit(); + virtual bool on_key(KEY key); + virtual bool has_check() const; + virtual bool has_query() const { return _browse || _sheet;} + virtual const char* picture_data(const char* data, bool video); + virtual const char * warning() { return _warning;} + virtual void show(bool on = TRUE); + virtual void enable(bool on = TRUE); + virtual CheckType check_type() const { return _check; } + void check_type(CheckType c) { _check = c; } + + bool forced() const { return _forced;} + virtual bool check(CheckTime = RUNNING_CHECK); + TBrowse* browse() const { return _browse;} + TList_sheet* sheet() const { return _sheet;} + void enable_check(bool on = TRUE) ; + bool check_enabled() const { return _check_enabled;} + + const char* format(const char* data); + const char* picture() const { return _picture; } + + TEdit_field(TMask* mask); + virtual ~TEdit_field(); +}; + + +/////////////////////////////////////////////////////////// +// TBrowse +/////////////////////////////////////////////////////////// + +class TBrowse +{ + TEdit_field* _fld; // The field owning the sheet + TRelation* _relation; // Main relation + TCursor* _cursor; // Cursor on the relation + TString _insert; + TString _filter; + long _rec; + bool _secondary; + bool _checked; + + TToken_string _head, _items; + TToken_string _inp_id, _inp_fn; + TToken_string _out_id, _out_fn; + +protected: + void do_output(CheckTime = RUNNING_CHECK); + void do_clear(); + bool do_insert(); + + TMask_field& field(short n) const; + TToken_string& create_siblings(TToken_string& siblings); + +public: + int inputs(); + int do_input(bool filter = FALSE); // Serve ai TCursor_sheet + + TBrowse(TEdit_field* f, TRelation* r, int key = 1, const char* filter = ""); + TBrowse(TEdit_field* f, TCursor* c); + ~TBrowse(); + + void parse_join(TScanner& scanner); + void parse_input(TScanner& scanner); + void parse_display(TScanner& scanner); + void parse_output(TScanner& scanner); + void parse_insert(TScanner& scanner); + bool parse_copy(const TString& what, const TBrowse& b); + + void set_insert(const char* s) { _insert = s;} + const TString& get_insert() const { return _insert;} + const TString& get_filter() const { return _filter;} + + TEdit_field& field() const { return *_fld; } + + bool check(CheckTime = RUNNING_CHECK); + bool empty_check(); + const TToken_string& head() const { return _head;} + const TToken_string& items() const { return _items;} + TCursor* cursor() const { return _cursor;} + bool checked() const { return _checked;} + bool secondary() const { return _secondary;} + + KEY run(); +}; + +/////////////////////////////////////////////////////////// +// TList_sheet +/////////////////////////////////////////////////////////// + +class TList_sheet +{ + TEdit_field* _fld; // The field owning the sheet + TArray_sheet* _sheet; // sheet with data; + int _row; + + TToken_string _inp_id; + TToken_string _out_id; + +protected: + int do_input(); + void do_output(CheckTime = RUNNING_CHECK); + bool do_insert(); + TMask_field& field(short id) const; + +public: + TList_sheet(TEdit_field* f, const char* caption, const char* head); + ~TList_sheet(); + + void parse_input(TScanner& scanner); + void read_item(TScanner& scanner); + void parse_output(TScanner& scanner); + TArray_sheet* sheet() { return _sheet; } + TEdit_field& field() const { return *_fld; } + + bool check(CheckTime = RUNNING_CHECK); + + KEY run(); +}; + +// @C +// class TReal_field : public TEdit_field +// @END + +class TReal_field : public TEdit_field +{ + int _decimals; + +protected: + // @FPROT + virtual word class_id() const; + + virtual const char* get_window_data() const; + virtual void set_window_data(const char* data); + virtual void exchange(bool show_value, const real& n); + + virtual void create(WINDOW parent); + virtual void parse_head(TScanner& scanner); + virtual bool on_key(KEY key); + virtual bool autoload(const TRelation* r); + +public: + // @FPUB + + void set_decimals(int d); // Set precision & picture + int decimals() const { return _decimals; } // Get precision + + TReal_field(TMask* mask); +}; + + +// @C +// class TDate_field : public TEdit_field +//@END + +class TDate_field : public TEdit_field +{ +protected: + // @FPROT + const char* format_data(const char* data,bool* changed=NULL); + + virtual word class_id() const; + virtual void create(WINDOW parent); + virtual bool on_key(KEY key); + virtual const char* get_window_data() const; + virtual void set_window_data(const char* data); + virtual const char* picture_data(const char* data, bool video); + +public: + // @FPUB + void parse_head(TScanner& scanner); + TDate_field(TMask* mask); +}; + + +// @C +// class TBoolean_field : public TMask_field +// @END + +class TBoolean_field : public TMask_field +{ +protected: + // @DPROT + bool _on; + + virtual word class_id() const; + + virtual void create(WINDOW parent); + virtual const char* get_window_data() const; + virtual void set_window_data(const char* data); + virtual void set_field_data(const char* data = NULL); + virtual const char* get_field_data() const; + virtual bool parse_item(TScanner& scanner); + virtual void enable(bool on); + virtual bool on_hit(); + virtual bool on_key(KEY key); + +public: + // @FPUB + TBoolean_field(TMask* mask); +}; + + +// @C +// class TList_field : public TMask_field +// @END + +class TList_field : public TMask_field +{ + // @FPRIV + void add_list(); + +protected: + // @FPROT + TToken_string _values; + TToken_string _codes; + TString _str; + + virtual word class_id() const; + + virtual void set_window_data(const char* data); + virtual const char* get_window_data() const; + virtual void set_field_data(const char* data = NULL); + virtual const char* get_field_data() const; + + virtual void create(WINDOW parent); + + virtual void current(int n); + virtual int current() const; + + int str2curr(const char* data); + virtual bool on_hit(); + virtual bool on_key(KEY key); + virtual void read_item(TScanner& scanner); + + virtual void parse_head(TScanner& scanner); + virtual bool parse_item(TScanner& scanner); + +public: + // @FPUB + TList_field(TMask* mask); + virtual void replace_items(const char* codes, const char* values); + virtual void add_item(const char* code_value); + virtual void delete_item(const char* code); + int items() const; +}; + + +// @C +// class TRadio_field : public TList_field +// @END + +class TRadio_field : public TList_field +{ + enum { MAX_RADIO = 8 }; + + // @FPRIV + int _nitems; + int _active_item; + WINDOW _radio_ctl_win[MAX_RADIO]; + +protected: + // @FPROT + virtual word class_id() const; + virtual void create(WINDOW parent); + virtual void destroy(); + virtual void enable(bool on); + virtual void show(bool on); + + virtual void current(int n); + virtual int current() const; + WINDOW win() const { return _radio_ctl_win[_active_item]; } + +public: + // @FPUB + TRadio_field(TMask* mask); + + void check_radiobutton(WINDOW checked); + bool move_focus(int d); +}; + + + +// @C +// class TButton_field : public TMask_field +// @END + +class TButton_field : public TMask_field +{ + KEY _virtual_key, _exit_key; + +protected: + // @FPROT + virtual word class_id() const; + virtual void create(WINDOW parent); + + void parse_head(TScanner& scanner); + bool parse_item(TScanner& scanner); + virtual void enable(bool); + virtual void show(bool); + virtual bool on_key(KEY key); + +public: + // @FPUB + TButton_field(TMask* mask); + KEY virtual_key() const { return _virtual_key; } + KEY exit_key() const { return _exit_key; } +}; + + +// @C +// class TGroup_field : public TMask_field +// @END + +class TGroup_field : public TMask_field +{ +protected: + // @DPROT + virtual void parse_head(TScanner& scanner); + virtual void create(WINDOW parent); + virtual void set_window_data(const char* data); + virtual void set_field_data(const char* data); + +public: + // @FPUB + TGroup_field(TMask* mask); +}; + +#endif // __MASKFLD_H diff --git a/include/printer.cpp b/include/printer.cpp index d048cbb64..5f91856bc 100755 --- a/include/printer.cpp +++ b/include/printer.cpp @@ -382,8 +382,8 @@ bool PrinterDef::read (const char *name, FILE * fd) else if (l == "Code") { TToken_string code (r); - _names.add (TString (code.get ())); - _codes.add (TString (code.get ())); + _names.add ( code.get() ); + _codes.add ( code.get() ); } else if (l == "Form feed") { @@ -509,9 +509,13 @@ TPrintrow & TPrintrow::put(const char *str, int position, int len) { if (len < 1) len = strlen (str); - + + bool jumped = TRUE; if (position < 0) + { position = _lastpos; + jumped = FALSE; + } char bg = 'w', fg = 'n'; for (int i = 0; i < len; i++) @@ -556,13 +560,13 @@ TPrintrow & TPrintrow::put(const char *str, int position, int len) } break; case 'B': - _currentstyle = boldstyle; + _currentstyle |= boldstyle; break; case 'I': - _currentstyle = italicstyle; + _currentstyle |= italicstyle; break; case 'U': - _currentstyle = underlinedstyle; + _currentstyle |= underlinedstyle; break; case 'R': _currentstyle = normalstyle; @@ -626,11 +630,11 @@ TPrintrow & TPrintrow::put(const char *str, int position, int len) ////////// TPRINTER ////////// -bool printers_on_key (TMask_field & f, KEY key) +HIDDEN bool printer_handler (TMask_field & f, KEY key) { if (key == K_SPACE) { - TToken_string pn1 (10), pn2 (20); + TToken_string pn1(10), pn2(80); const PrinterDef & def = printer().get_description(atoi(f.get ())); const char *s; @@ -699,23 +703,75 @@ void TPrinter::set_win_formlen(WINDOW prwin) // Handler della maschera di setup HIDDEN bool set_windows_print_device (TMask_field& f, KEY key) { - if (key == K_SPACE && f.mask().is_running()) + if (key == K_SPACE) { TPrinter& pr = printer(); + TToken_string& pn = pr.getprinternames (); + TString80 pdev (pn.get(atoi (f.get()))); // Nome stampante corrente + char szDevice[80]; - TToken_string & pn = pr.getprinternames (); - TString pdev (pn.get (atoi (f.get()))); GetProfileString ("devices", pdev, "", szDevice, sizeof (szDevice)); pdev << "," << szDevice; + // scrivi (e semmai lo si risistema poi) WriteProfileString("windows", "device", pdev); pr.set_printrcd(); pr.set_win_formlen(); + + const int MAX_FAMILIES = 128; + char* family[MAX_FAMILIES]; + const int num_families = (int)xvt_fmap_get_families(pr.get_printrcd(), family, MAX_FAMILIES); + TToken_string pn1(256), pn2(256); + for (int i = 0; i < num_families; i++) + { + pn1.add(family[i]); + pn2.add(family[i]); + } + + TMask& m = f.mask(); + TList_field& lst = (TList_field&)m.field(MSK_1_FONT); + + lst.replace_items(pn1, pn2); + lst.set(printer().fontname()); } return TRUE; } +HIDDEN bool font_handler(TMask_field& f, KEY key) +{ + if (key == K_SPACE) + { + const char* family = f.get(); + const int MAXSIZES = 32; + long sizes[MAXSIZES]; + BOOLEAN scalable; + const int num_sizes = (int)xvt_fmap_get_family_sizes(printer().get_printrcd(), + (char*)family, sizes, &scalable, MAXSIZES); + + TToken_string pn1(80), pn2(80); + + if (scalable) + for (int i = 4; i <= 32; i++) + { + pn1.add(i); + pn2.add(i); + } + else + for (int i = 0; i < num_sizes; i++) + { + pn1.add(sizes[i]); + pn2.add(sizes[i]); + } + + TList_field& lst = (TList_field&)f.mask().field(MSK_1_SIZE); + const TString16 old(lst.get()); + lst.replace_items(pn1, pn2); + lst.set(old); + } + return TRUE; +} + #endif TPrinter::TPrinter() @@ -729,7 +785,6 @@ TPrinter::TPrinter() { _footerhandler = _headerhandler = NULL; _linkhandler = NULL; - _config = "printer.ini"; _curprn = 0; // first in list if no default is specified _curcode = 0; // first in list if no default is specified @@ -747,13 +802,9 @@ TPrinter::TPrinter() _multiple_copies = main_app().class_id() == CLASS_PRINT_APPLICATION; // read configuration file - read_configuration (_config); + read_configuration (); #if XVT_OS == XVT_OS_WIN - TConfig cnf (CONFIG_GENERAL, "Print"); - _ch_size = cnf.get_int("Size", NULL, -1, 12); - _lines_per_inch = cnf.get_int("Lines", NULL, -1, 6); - // xvt_print_open (); set_win_formlen (); @@ -766,11 +817,8 @@ TPrinter::TPrinter() GetProfileString ("devices", pdev, "", szDevice, sizeof(szDevice)); pdev.add(szDevice); - // get printer names - TToken_string pn2(1024); - _get_windows_printer_names(pn2); - - const TString80 p1(pdev.get(0)); + const TString80 p1(pdev.get(0)); // current printer + TToken_string& pn2 = getprinternames(); // get printer names _curprn = pn2.get_pos(p1); CHECKS(_curprn >= 0, "Can't find printer ", (const char*)p1); @@ -782,18 +830,20 @@ TPrinter::TPrinter() TToken_string& TPrinter::getprinternames () { // per ora va solo in windows -#if XVT_OS == XVT_OS_WIN - _get_windows_printer_names (_printer_names); +#if XVT_OS == XVT_OS_WIN + if (_printer_names.empty()) + _get_windows_printer_names(_printer_names); #endif return _printer_names; } -void TPrinter::read_configuration(const char *conf) +void TPrinter::read_configuration() { - - FILE *cnfp = fopen (conf, "r"); +#if XVT_OS == XVT_OS_SCOUNIX + const char* const config = "printer.ini"; + FILE *cnfp = fopen (config, "r"); if (cnfp == NULL) - fatal_box ("Impossibile aprire il file %s", (const char *) _config); + fatal_box ("Impossibile aprire il file %s", config); for (int i = 0; !feof (cnfp); i++) { @@ -822,53 +872,60 @@ void TPrinter::read_configuration(const char *conf) } fclose (cnfp); - TFilename s ("printer.def"); -#if XVT_OS == XVT_OS_SCOUNIX - s << '.' << getuid (); #endif - if (fexist (s)) + + TConfig prini(CONFIG_USER, "Printer"); + + const int what = prini.get_int("Type", NULL, -1, 0); // Tipo stampante + _curprn = prini.get_int("Number", NULL, -1, 0); // Numero stampante corrente + _printerfile = prini.get("File", NULL, -1, ""); // File di stampa + _curcode = prini.get_int("Codes", NULL, -1, 0); // Codici di stampa + _fontname = prini.get("Font", NULL, -1, XVT_FFN_FIXED); // Nome del font + _ch_size = prini.get_int("Size", NULL, -1, 12); // Dimensione del font + _lines_per_inch = prini.get_int("Lines", NULL, -1, 6); // Linee per pollice + _isgraphics = prini.get_bool("Graphic", NULL, -1, FALSE); // Grafica attiva + + if (_printerfile.empty()) { - TScanner sc (s); - TToken_string t (sc.line ()); - int where_print = t.get_int (1); - t = sc.line (); - _curprn = t.get_int(1); - t = sc.line (); - _printerfile = t.get (1); - t = sc.line (); - _curcode = t.get_int (1); -#if XVT_OS != XVT_OS_WIN - PrinterDef & def = (PrinterDef &) get_description (_curprn); -#endif - switch (where_print) - { - case 0: // stampante -#if XVT_OS == XVT_OS_WIN - _printertype = winprinter; + _printerfile.tempdir(); +#if XVT_OS == XVT_OS_SCOUNIX + _printerfile << '/'; #else - switch (atoi (def._printertype)) - { - case 0: - _printertype = normprinter; - break; - case 1: - _printertype = localprinter; - break; - case 2: - _printertype = spoolprinter; - break; - } -#endif + _printerfile << '\\'; +#endif + } + + switch (what) + { + case 0: +#if XVT_OS == XVT_OS_WIN + _printertype = winprinter; +#else + PrinterDef & def = (PrinterDef &) get_description (_curprn); + switch (atoi (def._printertype)) + { + case 1: + _printertype = localprinter; break; - case 1: // file - _printertype = fileprinter; + case 2: + _printertype = spoolprinter; break; - case 2: // video - _printertype = screenvis; - _curcode = 0; + default: + _printertype = normprinter; break; } - } +#endif + break; + case 1: // file + _printertype = fileprinter; + break; + case 2: // video + _printertype = screenvis; + _curcode = 0; + break; + default: + break; + } } TPrinter::~TPrinter () @@ -1236,29 +1293,15 @@ _currentpage = 1; return _isopen = TRUE; } + void TPrinter::set() { main_app().disable_menu_item (M_FILE_PG_SETUP); - TMask mask ("bagn001a"); - TToken_string pn1 (50), pn2 (100); - int i; - - if (_printerfile.empty()) - { - _printerfile.tempdir(); -#if XVT_OS == XVT_OS_SCOUNIX - _printerfile << '/'; -#else - _printerfile << '\\'; -#endif - } + TMask mask("bagn001a"); - TFilename defile("printer.def"); -#if XVT_OS == XVT_OS_SCOUNIX - defile << format (".%d", getuid ()); -#endif - mask.set_workfile(defile); + TToken_string pn1(50), pn2(100); + int i; mask.set(MSK_1_FILENAME, _printerfile); mask.set(MSK_1_NPAGES, _ncopies); @@ -1278,9 +1321,7 @@ void TPrinter::set() if (!_multiple_copies) mask.hide(MSK_1_NPAGES); - pn1 = ""; - pn2 = ""; - + pn1 = pn2 = ""; for (i = 0; i < ((PrinterDef &)_printers[_curprn])._names.items(); i++) { pn1.add(i); @@ -1288,9 +1329,8 @@ void TPrinter::set() } ((TList_field &)(mask.field (MSK_1_CODES))).replace_items(pn1, pn2); -#if XVT_OS == XVT_OS_WIN - mask.xvt_win_set_handler (MSK_1_PRINTERS, printers_on_key); -#endif + mask.xvt_win_set_handler (MSK_1_PRINTERS, printer_handler); + if (_printertype == fileprinter) mask.set (MSK_1_TYPE, "1"); else if (_printertype == screenvis) @@ -1299,7 +1339,10 @@ void TPrinter::set() mask.set (MSK_1_TYPE, "0"); mask.set(MSK_1_PRINTERS, _curprn); + + mask.show(MSK_1_CODES); mask.set(MSK_1_CODES, _curcode); + KEY k; if ((k = mask.run()) == K_ESC) @@ -1346,23 +1389,27 @@ void TPrinter::set() } #else - - _get_windows_printer_names(pn2); + mask.set_handler (MSK_1_PRINTERS, set_windows_print_device); + mask.set_handler (MSK_1_FONT, font_handler); + + pn2 = getprinternames(); char old_default[80]; GetProfileString ("windows", "device", ",,,", old_default, sizeof(old_default)); for (i = 0; i < pn2.items (); i++) pn1.add(i); - ((TList_field &) (mask.field (MSK_1_PRINTERS))).replace_items(pn1, pn2); - mask.set(MSK_1_PRINTERS, pn1.get(_curprn)); + TList_field& plst = (TList_field&)mask.field (MSK_1_PRINTERS); + plst.replace_items(pn1, pn2); + plst.set(pn1.get(_curprn)); - mask.hide(MSK_1_CODES); - if (!_multiple_copies) mask.hide(MSK_1_NPAGES); - - mask.set(MSK_1_ISGRAPHICS, _isgraphics ? "X" : ""); + mask.set(MSK_1_FONT, _fontname); mask.set(MSK_1_SIZE, _ch_size); mask.set(MSK_1_LINES, _lines_per_inch); + mask.set(MSK_1_ISGRAPHICS, _isgraphics ? "X" : ""); + + if (!_multiple_copies) + mask.hide(MSK_1_NPAGES); if (_printertype == fileprinter) mask.set (MSK_1_TYPE, "1"); @@ -1371,8 +1418,6 @@ void TPrinter::set() else mask.set (MSK_1_TYPE, "0"); - mask.set_handler (MSK_1_PRINTERS, set_windows_print_device); - KEY k; int oldprn = _curprn; @@ -1399,22 +1444,12 @@ void TPrinter::set() } } - _curprn = atoi(mask.get(MSK_1_PRINTERS)); - - if (k == K_INS) - { - // tutto resta com'e' - mask.save (); - TConfig cnf (CONFIG_GENERAL, "Print"); - cnf.set("Size", mask.get(MSK_1_SIZE), "12"); - cnf.set("Lines", mask.get(MSK_1_LINES), "6"); - } if (k == K_ESC || k == K_ENTER) { // riaggiusta stampante default windows come prima // curprn e rcd sono quelle di prima main_app().enable_menu_item(M_FILE_PG_SETUP); - WriteProfileString("windows","device", old_default); + WriteProfileString("windows", "device", old_default); } if (k == K_ESC) { @@ -1424,6 +1459,7 @@ void TPrinter::set() return; } + _curprn = atoi(mask.get(MSK_1_PRINTERS)); _ncopies = atoi (mask.get (MSK_1_NPAGES)); switch (atoi (mask.get (MSK_1_TYPE))) @@ -1442,10 +1478,27 @@ void TPrinter::set() break; } - _isgraphics = mask.get_bool (MSK_1_ISGRAPHICS); - _ch_size = mask.get_int (MSK_1_SIZE); + _fontname = mask.get(MSK_1_FONT); + + const int cs = mask.get_int(MSK_1_SIZE); + if (cs > 4) _ch_size = cs; + _lines_per_inch = mask.get_int (MSK_1_LINES); + _isgraphics = mask.get_bool (MSK_1_ISGRAPHICS); set_win_formlen (); + + if (k == K_INS) + { + TConfig prini(CONFIG_USER, "Printer"); + prini.set("Type", _printertype); // Tipo stampante + prini.set("Number", _curprn); // Numero stampante corrente + prini.set("File", _printerfile); // File di stampa + prini.set("Codes", _curcode); // Codici di stampa + prini.set("Font", _fontname); // Nome del font + prini.set("Size", _ch_size); // Dimensione del font + prini.set("Lines", _lines_per_inch); // Linee per pollice + prini.set("Graphic", _isgraphics ? "X" : ""); // Grafica attiva + } #endif diff --git a/include/printer.h b/include/printer.h index d544e60a2..cbc7d113e 100755 --- a/include/printer.h +++ b/include/printer.h @@ -15,12 +15,14 @@ // @DPUB -enum TPrintstyle { +enum TPrintstyle +{ normalstyle = 0, boldstyle = 1, underlinedstyle = 2, - italicstyle = 3 - }; + italicstyle = 4, + jumpstyle = 64; +}; enum TPrtype { normprinter = 0, @@ -83,19 +85,17 @@ class PrinterDef : public TObject TString _filtername; // filter for the pipe (UNIX only) TString _devicename; // name of print device char _atstr[4][10]; // attribute codes for the current printer - TArray _codes; // print codes - TArray _names; // name of print codes + TString_array _codes; // print codes + TString_array _names; // name of print codes TString _ffcode; // formfeed code for the current printer TString _nlcode; // special newline code for the current printer public: bool read(const char* name, FILE* fd); // read description from file; bool isdefault(); // name matches "Default" - const char* get_codenames(word i) const { return i < (word) _names.items() ? (const char*)(TString&)_names[i] : NULL; } - const char* get_codes(word i) const { return i < (word) _codes.items() ? (const char*)(TString&)_codes[i] : NULL; } - PrinterDef() : _printername(10), _filtername(10), - _ffcode("\f"), _nlcode("\n") - {} + const char* get_codenames(word i) const { return i < (word)_names.items() ? (const char*)_names.row(i) : NULL; } + const char* get_codes(word i) const { return i < (word)_codes.items() ? (const char*)_codes.row(i) : NULL; } + PrinterDef() : _printername(10), _filtername(10), _ffcode("\f"), _nlcode("\n") {} }; @@ -133,7 +133,6 @@ class TPrinter : public TObject TViswin* _vf; // pointer to file visualizer TTextfile _txt; - TFilename _config; // name of the configuration file TFilename _exportfile; // name of export file int _headersize; int _footersize; @@ -145,7 +144,10 @@ class TPrinter : public TObject int _formlen; // length of the logic page int _formwidth; // size of the logic page int _currentrow; // next row to print + + TString80 _fontname; // Font name int _ch_size; // Font height + word _currentpage; // logic page containing _currentrow word _frompage; // first page to print (normally 0) word _topage; // last page to print (normally = USHRT_MAX) @@ -191,7 +193,7 @@ protected: virtual char newline() { return '\n'; } bool printrow (TPrintrow* rowtoprint=NULL); // base methods for printing bool printformfeed (); - void read_configuration(const char* cfg); + void read_configuration(); bool printheader(); bool printfooter(); @@ -206,7 +208,6 @@ public: static BOOLEAN XVT_CALLCONV1 start_winprint(long); #endif - void set_config_file (const char * ffile) { _config = ffile ; } void set_from_page (word from) { _frompage = from; } void set_to_page (word to) { _topage = to; } void set_hwff (bool hwff) { _hwformfeed = hwff; } @@ -304,7 +305,9 @@ public: int get_horz_offset() const { return _horz_offset; } int get_dots_per_line() const { return _dots_per_line; } bool isgraphics() const { return _isgraphics; } + int get_char_size() const { return _ch_size; } + char* fontname() const { return (char*)(const char*)_fontname; } // bookmarks int set_bookmark(const char* txt, int father = -1); diff --git a/include/printwin.cpp b/include/printwin.cpp index 38289f6f4..50ad47c2e 100755 --- a/include/printwin.cpp +++ b/include/printwin.cpp @@ -6,17 +6,27 @@ HIDDEN int LEN_SPACES(WINDOW win, int x) { HIDDEN long w = 0L; + if (x < 0) + { + x = 80; + w = 0L; + } if (w == 0L) { - TString256 spc; spc.spaces(256); - w = xvt_dwin_get_text_width(win,(char*)(const char*)spc,256); + TString256 spc; spc.fill('M', 132); + w = xvt_dwin_get_text_width(win,(char*)(const char*)spc, 132); } - const int k = int((w*x) >> 8); + const int k = int((w*x) / 132); #ifdef DBG - TString256 spc; spc.spaces(x); - const int k1 = xvt_dwin_get_text_width(win,(char*)(const char*)spc,x); - CHECK(k == k1, "Maguire disagrees"); + static bool error_on = TRUE; + if (error_on) + { + TString256 spc; spc.fill('M', x); + const int k1 = xvt_dwin_get_text_width(win,(char*)(const char*)spc,x); + if (k != k1) + error_on = error_box("Maguire disagrees: %d != %d", k, k1); + } #endif return k; @@ -148,34 +158,43 @@ void TPrintwin::paint_background(long j) void TPrintwin::paint_row(long j) { - char line[257]; - - const char* cp; int pos = 0; - int pixpos = 0; - int row = (int)(j % _formlen); + const int row = (int)(j % _formlen); + const int y = row*_chary + _chary - _descent + _vofs; paint_background(j); - strcpy(line,_txt.line(j)); _txt.read_line(j); - while(cp = _txt.piece()) + int pos = 0; + + const char* cp; + while((cp = _txt.piece()) != NULL) { - pos += strlen(cp); #if XVT_OS != XVT_OS_SCOUNIX int st = _txt.get_style(); long bg = trans_color(_txt.get_background()); long fg = trans_color(_txt.get_foreground()); - set_font(XVT_FFN_FIXED, st, _char_size); + set_font(printer().fontname(), st, _char_size); set_color(fg,bg); #else set_color(COLOR_BLACK, COLOR_WHITE); #endif - xvt_dwin_draw_text(win(), - pixpos + _hofs, - row*_chary + _chary - _descent + _vofs, - (char *)cp, -1); - pixpos = xvt_dwin_get_text_width(win(), line, pos); + + const char* end = NULL; + for (const char* begin = cp; *begin; begin = end) + { + for (; *begin == ' '; begin++) + pos++; + + int len = 0; + for (end = begin; *end > ' ' || (*end && *(end+1) > ' '); end++) + len++; + + if (*begin > ' ') + xvt_dwin_draw_text(win(), _hofs + LEN_SPACES(win(), pos), y, (char*)begin, len); + + pos += len; + } } } @@ -212,7 +231,7 @@ bool TPrintwin::do_print() && (rct = xvt_print_get_next_band()) != NULL) { set_font(XVT_FFN_SYSTEM, XVT_FS_NONE, _char_size); - set_font(XVT_FFN_FIXED, XVT_FS_NONE, _char_size); + set_font(printer().fontname(), XVT_FS_NONE, _char_size); #ifdef DBG long size1 = xvt_dwin_get_font_size_mapped(win()); CHECK(size == size1, "Failed to set font. xvt bugs???"); @@ -235,33 +254,31 @@ TPrintwin::TPrintwin(TTextfile& txt) _printrcd = p.get_printrcd(); WINDOW prwin = xvt_print_create_win(_printrcd, (char*)(const char*)main_app().title()); + if (prwin == NULL_WIN) + { + _aborted = TRUE; + return; + } set_win(prwin); #endif + _char_size = p.get_char_size(); - - set_font(XVT_FFN_FIXED, XVT_FS_NONE, _char_size); + set_font(p.fontname(), XVT_FS_NONE, _char_size); + LEN_SPACES(win(), -1); // force update #if XVT_OS != XVT_OS_SCOUNIX p.set_win_formlen(prwin); // Calcola offset e altre misure pagina -#endif - - _inited = TRUE; + + xvt_dwin_get_font_metrics(prwin, &_lead, &_ascent, &_descent); + _bg = &p.getbgdesc(); + _chary = p.get_dots_per_line(); + _hofs = p.get_horz_offset(); + _vofs = p.get_vert_offset(); +#endif + _formlen = p.formlen(); _formwidth = p.formwidth(); -#if XVT_OS != XVT_OS_SCOUNIX - if (prwin != NULL_WIN) - { - xvt_dwin_get_font_metrics(prwin, &_lead, &_ascent, &_descent); - - _bg = &p.getbgdesc(); - - _chary = p.get_dots_per_line(); - _hofs = p.get_horz_offset(); - _vofs = p.get_vert_offset(); - } - else _aborted = TRUE; -#endif - LEN_SPACES(win(), 50); //debug + _inited = TRUE; }