From 10d04217ca062e11be3c629a12470384bc0f97e5 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 17 Mar 2009 11:02:30 +0000 Subject: [PATCH] Patch level : 10.0 260 Files correlati : xvaga.dll Ricompilazione Demo : [ ] Commento : Aggiunto supporto per le Property Grid git-svn-id: svn://10.65.10.50/trunk@18531 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/bagn007.uml | 50 +-- include/classes.h | 1 + include/colmask.h | 46 +-- include/colors.cpp | 350 +++++++---------- include/config.cpp | 132 +++++-- include/config.h | 15 +- include/mask.cpp | 38 +- include/smartcard.h | 4 +- include/treectrl.cpp | 894 ++++++++++--------------------------------- include/treectrl.h | 23 ++ xvaga/xvt.h | 8 + xvaga/xvt_type.h | 63 +-- xvaga/xvtctl.cpp | 291 ++++++++++++-- 13 files changed, 826 insertions(+), 1089 deletions(-) diff --git a/include/bagn007.uml b/include/bagn007.uml index ca4bdfcdf..58991396d 100755 --- a/include/bagn007.uml +++ b/include/bagn007.uml @@ -1,51 +1,27 @@ -PAGE "Colori delle righe di prima nota" -1 -1 42 10 +PAGE "Colori delle righe" -1 -1 42 10 -SPREADSHEET 101 -1 -3 +PROPERTIES DLG_USER 0 0 BEGIN - PROMPT 1 1 "Colori" - ITEM "Colore@32" - FLAGS "D" + PROMPT 0 0 "Colori" END -BUTTON 102 10 2 +ENDPAGE + +TOOLBAR "topbar" 0 0 0 2 + +BUTTON DLG_OK 2 2 BEGIN - PROMPT -13 -1 "A~zzera" + PROMPT 1 -1 "" END -BUTTON DLG_CANCEL 10 2 +BUTTON DLG_DELREC 2 2 BEGIN - PROMPT -23 -1 "" + PROMPT 2 -1 "A~zzera" END -BUTTON DLG_OK 10 2 +BUTTON DLG_CANCEL 2 2 BEGIN - PROMPT -33 -1 "" -END - -ENDPAGE - -ENDMASK - -PAGE "Colore" -1 -1 40 10 - -STRING 101 32 -BEGIN - PROMPT 1 1 "Tipo " -END - -BUTTON 100 14 2 -BEGIN - PROMPT 2 5 "~Sfondo" -END - -BUTTON 99 14 2 -BEGIN - PROMPT 22 5 "~Testo" -END - -BUTTON DLG_OK 14 2 -BEGIN - PROMPT -11 -1 "" + PROMPT 3 -1 "" END ENDPAGE diff --git a/include/classes.h b/include/classes.h index 7e8219c1f..22e6d9582 100755 --- a/include/classes.h +++ b/include/classes.h @@ -54,6 +54,7 @@ #define CLASS_GOLEM_CLIENT_FIELD 252 #define CLASS_OUTLOOK_FIELD 253 #define CLASS_SLIDER_FIELD 254 +#define CLASS_PROP_FIELD 255 #define CLASS_TOOL_FIELD 280 #define CLASS_BUTTON_TOOL 281 diff --git a/include/colmask.h b/include/colmask.h index 7531c779d..598136bc4 100755 --- a/include/colmask.h +++ b/include/colmask.h @@ -1,45 +1,35 @@ #ifndef __COLMASK_H #define __COLMASK_H +#ifndef __ASSOC_H +#include +#endif + +#ifndef __AUTOMASK_H +#include +#endif + #ifndef __COLORS_H #include #endif -#ifndef __VARMASK_H -#include -#endif - -class TColor_row_mask; -class TColor_object_props; - -class TSelect_color_mask : public TVariable_mask +class TSelect_color_mask : public TAutomask { - TColor_row_mask * _sheet_mask; - TArray _color_defs; - TFilename _mask_name; + TAssoc_array _color_defs; TString _paragraph; - - HIDDEN TMask * get_mask(int, TMask&); - TColor_object_props * row(int r) const { return (TColor_object_props *) _color_defs.objptr(r);} - int items() const { return _color_defs.items();} protected: - void init(const char * mask_name, const char * para = NULL); - static bool color_handler(TMask_field& f, KEY k); - static bool reset_handler(TMask_field& f, KEY k); - void save() const ; + virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); + void init(const char* mask_name, const char* para = NULL); + void save() const; public: - int add_color_def(const char * key, const char * prompt, COLOR back = NORMAL_BACK_COLOR, COLOR fore = NORMAL_COLOR); - void get_color_def(const char * key, COLOR & back, COLOR & fore) const ; - void get_cur_colors(COLOR & back, COLOR & fore) const ; - int key2pos(const char * key) const; - COLOR get_back_color(int pos) const; - COLOR get_fore_color(int pos) const; + void add_color(const char* key, const char* prompt, COLOR back, COLOR fore, COLOR def_back, COLOR def_fore); + void add_color_def(const char* key, const char* prompt, COLOR back = NORMAL_BACK_COLOR, COLOR fore = NORMAL_COLOR); + bool get_color(const char* key, COLOR& back, COLOR& fore) const; - TSelect_color_mask(const char * mask_name, const char * para = NULL); - TSelect_color_mask(const TSheet_field & field); - virtual ~TSelect_color_mask(); + TSelect_color_mask(const char* mask_name, const char* para = NULL); + // TSelect_color_mask(const TSheet_field& field); }; #endif diff --git a/include/colors.cpp b/include/colors.cpp index bc53b10d8..8fcd7db23 100755 --- a/include/colors.cpp +++ b/include/colors.cpp @@ -1,6 +1,8 @@ #include #include +#include #include +#include COLOR RGB2COLOR(unsigned char red, unsigned char green, unsigned char blue) { @@ -40,238 +42,186 @@ COLOR grayed_color(COLOR col) return RGB2COLOR(k, k, k); } -class TColor_row_mask : public TMask -{ -public: - virtual void update(); - TColor_row_mask(); - virtual ~TColor_row_mask() { } -}; - -/////////////////////////////////////////////////////////// -// TColor_row_mask -/////////////////////////////////////////////////////////// - -TColor_row_mask::TColor_row_mask() : TMask("bagn007", 1) -{ } - -void TColor_row_mask::update() -{ - TSheet_field* s = get_sheet(); - if (s == NULL) - return; - TSelect_color_mask& m = (TSelect_color_mask&)s->mask(); - COLOR back, fore; - m.get_cur_colors(back, fore); - - _pixmap = TRUE; - set_pen(COLOR_BLACK); - - RCT rct; field(100).get_rect(rct); - set_brush(back); - frame(rct.left, 2*rct.top - rct.bottom - CHARY/2, rct.right, rct.top - CHARY/2, 0); - - field(99).get_rect(rct); - set_brush(fore); - frame(rct.left, 2*rct.top - rct.bottom - CHARY/2, rct.right, rct.top - CHARY/2, 0); - - _pixmap = FALSE; -} - /////////////////////////////////////////////////////////// // TColor_object_props /////////////////////////////////////////////////////////// class TColor_object_props : public TObject { - TString _key; - TString _prompt; - COLOR _back; - COLOR _fore; - COLOR _back_def; - COLOR _fore_def; + COLOR _back, _fore, _back_def, _fore_def; -protected: public: - void set_key(const char * key) { _key = key; } - void set_prompt(const char * prompt) { _prompt = prompt; } void set_back(COLOR back) { _back = back; } void set_fore(COLOR fore) { _fore = fore; } + void set(COLOR back, COLOR fore) { set_back(back); set_fore(fore); } + void set_back_def(COLOR back) { _back_def = back; } void set_fore_def(COLOR fore) { _fore_def = fore; } + void set_def(COLOR back, COLOR fore) { set_back_def(back); set_fore_def(fore); } - const TString & get_key() const { return _key; } - const TString & get_prompt() const { return _prompt; } COLOR get_back() const { return _back; } COLOR get_fore() const { return _fore; } COLOR get_back_def() const { return _back_def; } COLOR get_fore_def() const { return _fore_def; } - - TColor_object_props(const char * key, const char * prompt, COLOR back, COLOR fore); - virtual ~TColor_object_props() {} + + TColor_object_props(COLOR back, COLOR fore); }; -TColor_object_props::TColor_object_props(const char * key, const char * prompt, COLOR back, COLOR fore) - : _key(key), _prompt(prompt), _back(back), _fore(fore), _back_def(back), _fore_def(fore) -{ -} +TColor_object_props::TColor_object_props(COLOR back, COLOR fore) + : _back(back), _fore(fore), _back_def(back), _fore_def(fore) +{ } /////////////////////////////////////////////////////////// // TSelect_color_mask /////////////////////////////////////////////////////////// - -bool TSelect_color_mask::color_handler(TMask_field& f, KEY k) +bool TSelect_color_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { - if (k == K_SPACE) - { - TMask& m = f.mask(); - TSelect_color_mask& cm = (TSelect_color_mask&)m.get_sheet()->mask(); - TSheet_field& s = cm.sfield(101); - const int cur = s.selected(); - - TColor_object_props & p = *cm.row(cur); - const bool use_back = f.dlg() == 100; - COLOR col = use_back ? p.get_back() : p.get_fore(); - - col = choose_color(col, m.win()); - if (col != COLOR_INVALID) - { - if (use_back) - p.set_back(col); - else - p.set_fore(col); - xvt_dwin_invalidate_rect(f.parent(), NULL); - m.set_focus(); - s.set_back_and_fore_color(p.get_back(), p.get_fore(), cur); - s.force_update(); - } - } - - return TRUE; -} - -bool TSelect_color_mask::reset_handler(TMask_field& f, KEY k) -{ - if (k == K_SPACE && f.yesno_box(TR("Si desidera azzerare tutti i colori?"))) - { - TSelect_color_mask& cm = (TSelect_color_mask&)f.mask(); - TSheet_field& s = cm.sfield(101); - const int items = cm.items(); - - for (int i = 0; i < items; i++) - { - TColor_object_props & p = *cm.row(i); - - const COLOR back = p.get_back_def(); - const COLOR fore = p.get_fore_def(); - p.set_back(back); - p.set_fore(fore); - s.set_back_and_fore_color(back, fore, i); - } - s.force_update(); - } - if (k == K_ENTER) + switch (o.dlg()) { - TSelect_color_mask& cm = (TSelect_color_mask&)f.mask(); - cm.save(); + case DLG_DELREC: + if (e == fe_button) + { + TProp_field& g = (TProp_field&)field(DLG_USER); + g.freeze(true); + TString name; + FOR_EACH_ASSOC_OBJECT(_color_defs, h, k, o) + { + const TColor_object_props& p = *(const TColor_object_props*)o; + name = k; name << "_Bg"; + g.set_property(name, p.get_back_def()); + name.rtrim(3); name << "_Fg"; + g.set_property(name, p.get_fore_def()); + } + g.freeze(false); + return false; + } + break; + case DLG_USER: + if (e == fe_init) + { + TProp_field& g = (TProp_field&)o; + g.freeze(true); + xvt_vobj_maximize(g.win().win()); + g.freeze(false); + } else + if (e == fe_close) + { + TProp_field& g = (TProp_field&)o; + TString name; + FOR_EACH_ASSOC_OBJECT(_color_defs, h, k, o) + { + TColor_object_props& p = *(TColor_object_props*)o; + name = k; name << "_Bg"; + p.set_back(g.get_color_property(name)); + name.rtrim(3); name << "_Fg"; + p.set_fore(g.get_color_property(name)); + } + save(); + } + break; + default: break; } - return TRUE; + return true; } -int TSelect_color_mask::add_color_def(const char* key, const char* prompt, COLOR back, COLOR fore) +void TSelect_color_mask::add_color(const char* key, const char* prompt, COLOR back, COLOR fore, COLOR def_back, COLOR def_fore) { - TColor_object_props * p = new TColor_object_props(key, prompt, back, fore); - TSheet_field& s = sfield(101); + TString80 name = key; + if (name.find(' ')>=0) + { + CHECKS(FALSE, "Lamentati con Guy se la variabile viene rifiutata ", key); + name.strip_double_spaces(); + name.replace(' ', '_'); + } - const int row = _color_defs.add(p); + TProp_field& g = (TProp_field&)field(DLG_USER); + + TColor_object_props* p = (TColor_object_props*)_color_defs.objptr(name); + if (p == NULL) + { + p = new TColor_object_props(def_back, def_fore); + _color_defs.add(name, p, true); - TToken_string& riga = s.row(-1); - riga << p->get_prompt(); + g.set_property(name, (char*)NULL, prompt); // Categoria + } + else + p->set_def(back, fore); + p->set(back, fore); - TString tmp(_mask_name) ; tmp << "_" << _paragraph; - TConfig conf(CONFIG_GUI, tmp); - - tmp = p->get_key(); - if (conf.exist(tmp)) - p->set_fore(conf.get_color(tmp)); - - tmp << "_Bg"; - if (conf.exist(tmp)) - p->set_back(conf.get_color(tmp)); + name << "_Bg"; + g.set_property(name, back, TR("Sfondo")); // Sfondo + name.rtrim(3); name << "_Fg"; + g.set_property(name, fore, TR("Testo")); // Testo +} - s.set_back_and_fore_color(p->get_back(), p->get_fore(), row); - return row; +void TSelect_color_mask::add_color_def(const char* key, const char* prompt, COLOR def_back, COLOR def_fore) +{ + COLOR back = def_back; + COLOR fore = def_fore; + + TConfig conf(CONFIG_GUI, _paragraph); // Ha una possibile personalizzazione? + conf.write_protect(); + if (!conf.new_paragraph()) + { + TString80 name = key; + fore = conf.get_color(name, NULL, -1, def_fore); + name << "_Bg"; + back = conf.get_color(name, NULL, -1, def_back); + } + + add_color(key, prompt, back, fore, def_back, def_fore); } -void TSelect_color_mask::get_color_def(const char * key, COLOR & back, COLOR & fore) const +bool TSelect_color_mask::get_color(const char* key, COLOR & back, COLOR & fore) const { - const int pos = key2pos(key); - - if (pos >= 0) + const TColor_object_props* p = (const TColor_object_props*)_color_defs.objptr(key); + if (p != NULL) { - back = get_back_color(pos); - fore = get_fore_color(pos); + back = p->get_back(); + fore = p->get_fore(); } else { back = NORMAL_BACK_COLOR; fore = NORMAL_COLOR; } + return p != NULL; } -int TSelect_color_mask::key2pos(const char * key) const -{ - const int items = _color_defs.items(); - - for (int i = 0; i < items; i++) - if (((TColor_object_props &) _color_defs[i]).get_key() == key) - return i; - return -1; -} - -COLOR TSelect_color_mask::get_back_color(int pos) const -{ - return ((TColor_object_props &) _color_defs[pos]).get_back(); -} - -COLOR TSelect_color_mask::get_fore_color(int pos) const -{ - return ((TColor_object_props &) _color_defs[pos]).get_fore(); -} - -TMask * TSelect_color_mask::get_mask(int, TMask& m) -{ - return ((TSelect_color_mask &) m.get_sheet()->mask())._sheet_mask; -} - -void TSelect_color_mask::get_cur_colors(COLOR & back, COLOR & fore) const -{ - TSheet_field& s = sfield(101); - int cur = s.selected(); - TColor_object_props & p = *row(cur); - - back = p.get_back(); - fore = p.get_fore(); -} - -void TSelect_color_mask::init(const char * mask_name, const char * para) +void TSelect_color_mask::init(const char* mask_name, const char* para) { - set_handler(102, reset_handler); - - _sheet_mask = new TColor_row_mask; - _sheet_mask->set_handler(99, color_handler); - _sheet_mask->set_handler(100, color_handler); - - TVariable_sheet_field& s = (TVariable_sheet_field&) sfield(101); - s.set_getmask(get_mask); - _mask_name = mask_name; - _mask_name.ext(""); - _paragraph = para; + const TFilename fn(mask_name); + _paragraph << fn.name_only() << '_' << para; + _paragraph.lower(); } -TSelect_color_mask::TSelect_color_mask(const TSheet_field & field) - : TVariable_mask("bagn007") +void TSelect_color_mask::save() const +{ + TConfig conf(CONFIG_GUI, _paragraph); + TString tmp; + + TAssoc_array& ass = (TAssoc_array&)_color_defs; // Fool const + FOR_EACH_ASSOC_OBJECT(ass, h, k, o) + { + const TColor_object_props& p = *(const TColor_object_props*)o; + + tmp = k; // tmp = p.get_key(); + if (same_color(p.get_fore(), p.get_fore_def())) + conf.remove(tmp); + else + conf.set_color(tmp, p.get_fore()); + + tmp << "_Bg"; + if (same_color(p.get_back(), p.get_back_def())) + conf.remove(tmp); + else + conf.set_color(tmp, p.get_back()); + } +} + +/* +TSelect_color_mask::TSelect_color_mask(const TSheet_field & field) : TAutomask("bagn007") { const TMask& m = field.mask(); TString16 para("Colors"); @@ -280,38 +230,10 @@ TSelect_color_mask::TSelect_color_mask(const TSheet_field & field) para << num; init(m.source_file(), para); } - -void TSelect_color_mask::save() const -{ - TString tmp(_mask_name) ; tmp << "_" << _paragraph; - TConfig conf(CONFIG_GUI, tmp); - const int items = _color_defs.items(); - - for (int i = 0; i < items; i++) - { - TColor_object_props & p = *row(i); - - tmp = p.get_key(); - if (p.get_fore() == p.get_fore_def()) - conf.remove(tmp); - else - conf.set_color(tmp, p.get_fore()); +*/ - tmp << "_Bg"; - if (p.get_back() == p.get_back_def()) - conf.remove(tmp); - else - conf.set_color(tmp, p.get_back()); - } -} - -TSelect_color_mask::TSelect_color_mask(const char * mask_name, const char * para) - : TVariable_mask("bagn007") +TSelect_color_mask::TSelect_color_mask(const char* mask_name, const char* para) + : TAutomask("bagn007") { init(mask_name, para); } - -TSelect_color_mask::~TSelect_color_mask() -{ - delete _sheet_mask; -} diff --git a/include/config.cpp b/include/config.cpp index c36bc59b6..775fc8168 100755 --- a/include/config.cpp +++ b/include/config.cpp @@ -333,7 +333,7 @@ char TConfig::get_char( const char* var, // @parm Variabile della quale ritornare il valore const char* section, // @parm Sezione della varaibile (default NULL) int index, // @parm Eventuale indice della varaibailie (default -1) - char def) // @parm Valore default della varaibile (default ' ') + char def) // @parm Valore default della variabile (default ' ') // @comm Passando

= 0 viene appeso al nome variabile per // implementare un array. @@ -684,21 +684,21 @@ int TConfig::for_each_paragraph(CONFIG_CALLBACK cfgcb, void* jolly) return count; } -TConfig::TConfig(int which_config, const char* paragraph) +static void cfg2file(int which_config, TFilename& file) { switch (which_config) { case CONFIG_DITTA: - _file = firm2dir(prefix().get_codditta()); - _file.add("ditta.ini"); - if (!_file.exist()) + file = firm2dir(prefix().get_codditta()); + file.add("ditta.ini"); + if (!file.exist()) { - TFilename oldfile = _file; + TFilename oldfile = file; const int pos = oldfile.find("ditta.ini"); oldfile.cut(pos); oldfile.add("prassid.ini"); // Old config file! if (oldfile.exist()) - fcopy(oldfile, _file); + fcopy(oldfile, file); } break; case CONFIG_STUDIO: @@ -706,35 +706,35 @@ TConfig::TConfig(int which_config, const char* paragraph) case CONFIG_GUI: case CONFIG_USER: case CONFIG_WST: - _file = firm2dir(-1); // Directory dati - _file.add("config"); // + Directory config - if (!_file.exist()) // Creala se necessario - make_dir(_file); + file = firm2dir(-1); // Directory dati + file.add("config"); // + Directory config + if (!file.exist()) // Creala se necessario + make_dir(file); switch (which_config) { case CONFIG_STUDIO: - _file.add("studio.ini"); - if (!_file.exist()) + file.add("studio.ini"); + if (!file.exist()) { - TFilename oldfile = _file; + TFilename oldfile = file; const int pos = oldfile.find("studio.ini"); oldfile.cut(pos); oldfile.add("prassis.ini"); // Old config file! if (oldfile.exist()) - fcopy(oldfile, _file); + fcopy(oldfile, file); } break; case CONFIG_STAMPE: - _file.add("print.ini"); + file.add("print.ini"); break; case CONFIG_GUI: { TFilename gui = "gui.ini"; if (gui.custom_path()) { - _file = gui; // I colori sono qui ... - break; // ... scavalca utente + file = gui; // I colori sono qui ... + break; // ... scavalca utente } } case CONFIG_USER: @@ -743,13 +743,13 @@ TConfig::TConfig(int which_config, const char* paragraph) if (u.blank()) u = ::dongle().administrator(); u.lower(); - _file.add(u); - _file.ext("ini"); - if (u != "admin" && !_file.exist()) + file.add(u); + file.ext("ini"); + if (u != "admin" && !file.exist()) { - TFilename prassi = _file.path(); + TFilename prassi = file.path(); prassi.add("admin.ini"); - fcopy(prassi, _file); + fcopy(prassi, file); } } break; @@ -759,26 +759,31 @@ TConfig::TConfig(int which_config, const char* paragraph) if (u.blank()) u = "localhost"; u.lower(); - _file.add(u); - _file.ext("ini"); + file.add(u); + file.ext("ini"); } default: break; } break; case CONFIG_FCONV: - _file = "fconv.ini"; + file = "fconv.ini"; break; case CONFIG_INSTALL: - _file = CGetCampoIni(); + file = CGetCampoIni(); break; case CONFIG_OEM: - _file = "setup/oem.ini"; + file = "setup/oem.ini"; break; default: NFCHECK("Chi usa questo strano .ini?"); break; } +} + +TConfig::TConfig(int which_config, const char* paragraph) +{ + cfg2file(which_config, _file); init(_file, paragraph); } @@ -792,7 +797,7 @@ TConfig::TConfig(const char *fn, const char* pa) TConfig::~TConfig() { // il distruttore riscrive il file con le modifiche se necessario - if (_dirty) + if (_dirty && !_write_protected) _write_file(); } @@ -800,14 +805,67 @@ TConfig::~TConfig() // Utilities /////////////////////////////////////////////////////////// +#define DECLARE_VARNAME(name, idx) const char* varname = idx >= 0 ? (const char*)(get_tmp_string() << name << '(' << idx << ')') : name +#define DECLARE_FILENAME(cfg) TFilename filename; cfg2file(cfg, filename) + +const TString& ini_get_string(const char* file, const char* paragraph, const char* name, const char* defval, int idx) +{ + DECLARE_VARNAME(name, idx); + TString& tmp = get_tmp_string(); + const int len = xvt_sys_get_profile_string(file, paragraph, varname, defval, tmp.get_buffer(), tmp.size()); + if (len > tmp.size()) + { + tmp.get_buffer(len); + xvt_sys_get_profile_string(file, paragraph, varname, defval, tmp.get_buffer(), tmp.size()); + } + return tmp; +} + +bool ini_set_string(const char* file, const char* paragraph, const char* name, const char* val, int idx) +{ + DECLARE_VARNAME(name, idx); + return xvt_sys_set_profile_string(file, paragraph, varname, val) != 0; +} + +int ini_get_int(const char* file, const char* paragraph, const char* name, int defval, int idx) +{ + DECLARE_VARNAME(name, idx); + return xvt_sys_get_profile_int(file, paragraph, varname, defval); +} + +bool ini_set_int(const char* file, const char* paragraph, const char* name, int val, int idx) +{ + TString16 value; value << val; + return ini_set_string(file, paragraph, name, value, idx); +} + +const TString& ini_get_string(int cfg, const char* paragraph, const char* name, const char* defval, int idx) +{ + DECLARE_FILENAME(cfg); + return ini_get_string(filename, paragraph, name, defval, idx); +} + +bool ini_set_string(int cfg, const char* paragraph, const char* name, const char* val, int idx) +{ + DECLARE_FILENAME(cfg); + return ini_set_string(filename, paragraph, name, val); +} + +int ini_get_int(int cfg, const char* paragraph, const char* name, int defval, int idx) +{ + DECLARE_FILENAME(cfg); + return ini_get_int(filename, paragraph, name, defval, idx); +} + +bool ini_set_int(int cfg, const char* paragraph, const char* name, int val, int idx) +{ + DECLARE_FILENAME(cfg); + return ini_set_int(filename, paragraph, name, val, idx); +} + const TString& get_oem_info(const char* varname) { - TConfig ini(CONFIG_OEM, "MAIN"); - const int oem = ini.get_int("OEM", NULL, -1); - if (oem >= 0) - { - TString8 str; str.format("OEM_%d", oem); - return get_tmp_string() = ini.get(varname, str); - } - return EMPTY_STRING; + static int oem = ini_get_int(CONFIG_OEM, "MAIN", "OEM"); + TString8 para; para.format("OEM_%d", oem); + return ini_get_string(CONFIG_OEM, para, varname); } diff --git a/include/config.h b/include/config.h index 7f7187680..9b977a261 100755 --- a/include/config.h +++ b/include/config.h @@ -5,7 +5,6 @@ #include #endif -// class ofstream; class TConfig; // questo sara' il principale, per ora non c'e' @@ -177,6 +176,18 @@ public: virtual ~TConfig(); }; -const TString& get_oem_info(const char* varname); +// Low level utilities +int ini_get_int (const char* file, const char* para, const char* name, int defval = 0, int idx = -1); +const TString& ini_get_string(const char* file, const char* para, const char* name, const char* defval = "", int idx = -1); +bool ini_set_int (const char* file, const char* para, const char* name, int val, int idx = -1); +bool ini_set_string(const char* file, const char* para, const char* name, const char* val, int idx = -1); + +// High level utilities +int ini_get_int (int cfg, const char* para, const char* name, int defval = 0, int idx = -1); +const TString& ini_get_string(int cfg, const char* para, const char* name, const char* defval = "", int idx = -1); +bool ini_set_int (int cfg, const char* para, const char* name, int val, int idx = -1); +bool ini_set_string(int cfg, const char* para, const char* name, const char* val, int idx = -1); + +const TString& get_oem_info(const char* varname); // ini_get_string(CONFIG_OEM, "OEM_?", varname); #endif diff --git a/include/mask.cpp b/include/mask.cpp index 5501d9a33..4e631692c 100755 --- a/include/mask.cpp +++ b/include/mask.cpp @@ -879,12 +879,17 @@ void TMask::handler(WINDOW w, EVENT* ep) break; case WC_HSCROLL: case WC_VSCROLL: - if (id2pos(ep->v.ctl.id) >= 0) // potrebbero non avere un controllo associato - field(ep->v.ctl.id).on_key(K_SPACE); - break; + if (id2pos(ep->v.ctl.id) < 0) // potrebbero non avere un controllo associato + break; + // fall down case WC_HSLIDER: case WC_VSLIDER: - field(ep->v.ctl.id).on_key(K_SPACE); + case WC_PROPGRID: + { + TMask_field& f = field(ep->v.ctl.id); + f.set_focusdirty(); + f.on_key(K_SPACE); + } break; default: break; @@ -1059,24 +1064,25 @@ int TMask::win2page(WINDOW w) const TMask_field* TMask::parse_field(TScanner& scanner) { const TString& k = scanner.key(); - if (k == "ST") return new TEdit_field(this); - if (k == "NU") return new TReal_field(this); - if (k == "DA") return new TDate_field(this); if (k == "BO") return new TBoolean_field(this); - if (k == "TE") return new TText_field(this); + if (k == "BR") return new TBrowsefile_field(this); if (k == "BU") return new TButton_field(this); + if (k == "CL") return new TGolem_client_field(this); + if (k == "CU") return new TCurrency_field(this); + if (k == "DA") return new TDate_field(this); + if (k == "GO") return new TGolem_field(this); if (k == "GR") return new TGroup_field(this); if (k == "LI") return new TList_field(this); - if (k == "RA") return new TRadio_field(this); - if (k == "CU") return new TCurrency_field(this); if (k == "ME") return new TMemo_field(this); - if (k == "ZO") return new TZoom_field(this); - if (k == "GO") return new TGolem_field(this); - if (k == "BR") return new TBrowsefile_field(this); - if (k == "SP") return new TSheet_field(this); - if (k == "TR") return new TTree_field(this); - if (k == "CL") return new TGolem_client_field(this); + if (k == "NU") return new TReal_field(this); + if (k == "PR") return new TProp_field(this); + if (k == "RA") return new TRadio_field(this); if (k == "SL") return new TSlider_field(this); + if (k == "SP") return new TSheet_field(this); + if (k == "ST") return new TEdit_field(this); + if (k == "TE") return new TText_field(this); + if (k == "TR") return new TTree_field(this); + if (k == "ZO") return new TZoom_field(this); return NULL; } diff --git a/include/smartcard.h b/include/smartcard.h index 163429dce..06b7a07d3 100755 --- a/include/smartcard.h +++ b/include/smartcard.h @@ -50,8 +50,8 @@ public: bool card_connected() const { return _card_connected; } const bool with_card(const TMask & m) { return m.get_bool(_check_field); } - smartcard_error connect_card(); - smartcard_error disconnect_card(); + smartcard_error connect_card(); + smartcard_error disconnect_card(); smartcard_error read(); smartcard_error write() const ; diff --git a/include/treectrl.cpp b/include/treectrl.cpp index c754f9a98..564801c0a 100755 --- a/include/treectrl.cpp +++ b/include/treectrl.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -196,697 +197,6 @@ TWindowed_field::~TWindowed_field() delete _win; } -#ifdef AGA_TREE - -/////////////////////////////////////////////////////////// -// TNode_info -/////////////////////////////////////////////////////////// - -class TNode_info : public TSortable -{ -public: - bool _valid : 1; - bool _enabled : 1; - bool _expandable : 1; - bool _expanded : 1; - TString _id; - long _plusx; - long _startx; - long _endx; - - const TNode_info& operator =(const TNode_info& ni) - { - _valid = ni._valid; - _enabled = ni._enabled; - _expanded = ni._expanded; - _expandable = ni._expandable; - _id = ni._id; - _plusx = ni._plusx; - _startx = ni._startx; - _endx = ni._endx; - return ni; - } - - virtual int compare(const TSortable& s) const - { - const TNode_info& ni = (const TNode_info&)s; - return _id.compare(ni._id); - } - - virtual bool ok() const { return _valid; } - void reset() { _valid = false; } - - TNode_info() : _valid(false) { } - virtual ~TNode_info() { } -}; - -class TNode_info_array : public TObject -{ - TArray _data; - -public: - int last() const; - int find(const TNode_info& ni) const; - TNode_info& operator[](int index); - const TNode_info& operator[](int index) const - { return (const TNode_info&)_data[index]; } - void reset(); -}; - -TNode_info& TNode_info_array::operator[](int index) -{ - CHECKD(index >= 0, "Bad index ", index); - TNode_info* ni = (TNode_info*)_data.objptr(index); - if (ni == NULL) - { - ni = new TNode_info; - _data.add(ni, index); - } - return *ni; -} - -void TNode_info_array::reset() -{ - for (int i = _data.last(); i >= 0; i = _data.pred(i)) - ((TNode_info*)_data.objptr(i))->reset(); -} - -int TNode_info_array::last() const -{ - int i; - for (i = _data.last(); i >= 0; i = _data.pred(i)) - if (_data[i].ok()) - break; - return i; -} - -int TNode_info_array::find(const TNode_info& ni) const -{ - int i; - for (i = last(); i >= 0; i = _data.pred(i)) - { - if (((TNode_info*)_data.objptr(i))->compare(ni) == 0) - break; - } - return i; -} - -/////////////////////////////////////////////////////////// -// TTree_window -/////////////////////////////////////////////////////////// - -class TTree_window : public TField_window -{ - TTree* _tree; - bool _hide_leaves; - long _first_line; // Prima riga disegnata - TNode_info_array _node_info; - TNode_info _curr_info; // Nodo attualmente selezionato - TAuto_token_string _header; - int _headlines; - - /*static*/ int _row_height; - static bool _tree_locked; - -protected: // TWindow - virtual void update(); - virtual bool on_key(KEY key); - virtual void handler(WINDOW win, EVENT* ep); - - int row_height() const { return _row_height; } - PNT log2dev(long x, long y) const; - TPoint dev2log(const PNT& p) const; - -protected: // Internal use - static bool callback_draw_node(TTree& node, void* jolly, word); - void update_header(); - void draw_plus_minus(); - void draw_text(int x, int y, const TString& str); - - int info2index(const TNode_info& ni) const; - bool index2info(long index, TNode_info& ni); - -public: - TTree* tree() const { return _tree; } - void set_tree(TTree* tree) { _tree = tree; _first_line = -1; } - void hide_leaves(bool yes) { _hide_leaves = yes; } - bool select_current(); - bool goto_selected(); - void set_header(const char* head); - void set_row_height(int rh); - - TTree_window(int x, int y, int dx, int dy, - WINDOW parent, TTree_field* owner); - virtual ~TTree_window() { } -}; - -bool TTree_window::_tree_locked = false; - -const int TABX = 3; - -struct TUpdate_info -{ - TTree_window* _win; - TToken_string _str; - long _x, _y; - long _firsty, _lasty; - long _jolly; - int _headlines; - TNode_info_array* _node_info; - TNode_info* _curr_info; -}; - - -PNT TTree_window::log2dev(long x, long y) const -{ - if (_headlines > 0) - y += _headlines; - - if (autoscrolling()) - { - if (_pixmap) - { - x -= origin().x * CHARX; - y -= origin().y * _row_height; - } - else - { - x -= origin().x; - y -= origin().y; - } - } - - PNT pnt; pnt.h = (int)x; pnt.v = (int)y; - - if (!_pixmap) - { - pnt.h *= CHARX; - pnt.v *= _row_height; - } - - return pnt; -} - -TPoint TTree_window::dev2log(const PNT& dp) const -{ - PNT p = dp; - - if (_headlines > 0) - p.v -= _headlines * _row_height; - - TPoint pnt(_pixmap ? p.h : p.h/CHARX, _pixmap ? p.v : p.v/_row_height); - return pnt; -} - -void TTree_window::draw_text(int x, int y, const TString& str) -{ - int start = 0, pos = 0; - while (pos >= 0) - { - pos = str.find(" ", start); - const TString& mid = str.sub(start, pos); - if (!mid.blank()) - stringat(x + start, y, mid); - start = pos+2; - } -} - -bool TTree_window::callback_draw_node(TTree& node, void* jolly, word when) -{ - TUpdate_info* ui = (TUpdate_info*)jolly; - - if (when == SCAN_PRE_ORDER) - { - if (ui->_y >= ui->_firsty && ui->_y <= ui->_lasty) - { - node.curr_id(ui->_str); - const bool is_selected = ui->_str == ui->_curr_info->_id; - const bool is_enabled = node.enabled(); - const bool is_marked = node.marked(); - int text_len = 0; - if (node.get_description(ui->_str)) - { - text_len = ui->_str.len(); - if (is_selected) - ui->_win->set_color(FOCUS_COLOR, FOCUS_BACK_COLOR); - else - ui->_win->set_color(is_enabled ? NORMAL_COLOR : DISABLED_COLOR, - is_marked ? REQUIRED_BACK_COLOR : NORMAL_BACK_COLOR); - ui->_win->draw_text(int(ui->_x+2), int(ui->_y), ui->_str); - } - - const int ry = int(ui->_y - ui->_firsty); - int by; - - for (by = ry-1; by >= 0; by--) - { - long rx = (*ui->_node_info)[by]._startx; - if (rx < ui->_x) - break; - } - - const PNT p = ui->_win->log2dev(ui->_x, ui->_y); - const WINDOW win = ui->_win->win(); - ui->_win->set_pen(DISABLED_BACK_COLOR); - - const int rh = ui->_win->row_height(); - - PNT q; - q.h = p.h; q.v = p.v + rh/2; - xvt_dwin_draw_set_pos(win, q); - q.h -= TABX*CHARX - 3*CHARX/2; - xvt_dwin_draw_line(win, q); - q.v = (by+1+ui->_headlines)*rh; - - xvt_dwin_draw_line(win, q); - - TImage* bmp = node.image(is_selected); - if (bmp) - { - const int x = p.h; - const int y = p.v + (rh - bmp->height()) / 2; - if (is_enabled) - bmp->draw(win, x, y); - else - { - TImage dis(*bmp); - for (int j = dis.height()-1; j >= 0; j--) - for (int i = dis.width() - (j&1 ? 2 : 1); i >= 0; i-=2) - dis.set_pixel(i, j, NORMAL_BACK_COLOR); - dis.draw(win, x, y); - } - } - - TNode_info& ni = (*ui->_node_info)[ry]; - node.curr_id(ni._id); - ni._valid = true; - ni._startx = ui->_x; - ni._endx = ui->_x + text_len + 2; - ni._enabled = is_enabled; - ni._expandable = is_enabled && node.has_son(); - if (ni._expandable) - { - ni._plusx = ui->_x - TABX + 1; - ni._expanded = node.expanded(); - } - else - { - ni._plusx = 0; - ni._expanded = false; - } - } - ui->_y++; - - ui->_x += TABX; - if (ui->_x > ui->_jolly) - ui->_jolly = ui->_x; - } else - if (when == SCAN_IN_ORDER) - { - ui->_x -= TABX; - if (ui->_y > ui->_lasty) - return true; - } - - return false; -} - -void TTree_window::draw_plus_minus() -{ - const long firsty = origin().y; - const int last_drawn = _node_info.last(); - for (int i = last_drawn; i >= 0; i--) - { - TNode_info& ni = _node_info[i]; - if (ni._plusx > 0) - { - if (ni._expanded) - { - bool spudorato = i == last_drawn; // Falso espandibile - if (!spudorato) - { - const TNode_info& nni = _node_info[i+1]; - spudorato = nni._startx <= ni._startx; - } - if (spudorato) - { - ni._expandable = false; - ni._expanded = false; - ni._plusx = 0; - continue; - } - } - - WINDOW w = win(); - PNT r = log2dev(ni._plusx, firsty + i); - r.v += _row_height/2; - r.h += CHARX/2; - - RCT rct; - rct.left = r.h - 4; - rct.top = r.v - 4; - rct.right = r.h + 5; - rct.bottom = r.v + 5; - set_pen(NORMAL_COLOR); - set_brush(NORMAL_BACK_COLOR); - xvt_dwin_draw_rect(w, &rct); - - PNT f, t; - f.h = rct.left+2; f.v = r.v; - t.h = rct.right+-2; t.v = r.v; - xvt_dwin_draw_set_pos(w, f); - xvt_dwin_draw_line(w, t); - - if (!ni._expanded) - { - f.h = r.h; f.v = rct.top+2; - t.h = r.h; t.v = rct.bottom-2; - xvt_dwin_draw_set_pos(w, f); - xvt_dwin_draw_line(w, t); - } - } - } -} - -void TTree_window::set_header(const char* head) -{ - _header = head; - _headlines = _header.items(); -} - -void TTree_window::update_header() -{ - if (_headlines > 0) - { - autoscroll(false); - set_brush(MASK_BACK_COLOR); - bar(0,-_headlines,columns(),0); - autoscroll(true); - set_opaque_text(false); - for (int i = 0; i < _headlines; i++) - { - const TFixed_string str(_header.get(i)); - draw_text(2, int(origin().y+i-_headlines), str); - } - } -} - -void TTree_window::update() -{ - TField_window::update(); - - if (_tree == NULL) - return; - - update_header(); - - TUpdate_info ui; - ui._win = this; - ui._x = 0; - ui._y = 0; - ui._firsty = origin().y; - ui._lasty = ui._firsty + rows(); - ui._jolly = 0; - ui._headlines = _headlines; - ui._node_info = &_node_info; - ui._curr_info = &_curr_info; - - bool ok = false; - if (_first_line > 0) - { - const long index = origin().y - _first_line; - TNode_info ni; - if (index2info(index, ni)) - { - ok = _tree->goto_node(ni._id); - ui._x = ni._startx; - ui._y = ui._firsty; - } - } - if (!ok) - { - ok = _tree->goto_root(); - if (!ok) - return; - } - - _node_info.reset(); - set_opaque_text(true); - - word flags = SCAN_PRE_ORDER | SCAN_IN_ORDER | SCAN_IGNORING_UNEXPANDED; - if (_hide_leaves) flags |= SCAN_IGNORING_LEAVES; - - _tree->scan_depth_first(callback_draw_node, &ui, flags); - while (ui._y < ui._lasty) - { - if (_tree->goto_father()) - { - ui._x -= TABX; - if (_tree->goto_rbrother()) - _tree->scan_depth_first(callback_draw_node, &ui, flags); - } - else - break; - } - draw_plus_minus(); - - set_scroll_max(ui._jolly+columns(), ui._y); - _first_line = ui._firsty; -} - -// Fa diventare il nodo corrente selezionato -bool TTree_window::select_current() -{ - if (_tree) - _tree->curr_id(_curr_info._id); - return _tree != NULL; -} - -// Salta al nodo correntemente selezionato -bool TTree_window::goto_selected() -{ - bool ok = false; - if (_tree) - ok = _tree->goto_node(_curr_info._id); - return ok; -} - -void TTree_window::set_row_height(int rh) -{ - if (rh <= 0) - rh = CHARY+2; - _row_height = rh; -} - -int TTree_window::info2index(const TNode_info& info) const -{ - return _node_info.find(info); -} - -bool TTree_window::index2info(long index, TNode_info& ni) -{ - bool ok = false; - const int last = _node_info.last(); - - if (index == -1) - { - if (index2info(0, ni) && _tree->goto_node(ni._id)) - { - ok = _tree->goto_lbrother(); - if (!ok) - { - ok = _tree->goto_father(); - ni._startx -= TABX; - } - if (ok) - _tree->curr_id(ni._id); - } - } else - if (index == last+1 && last >= 0) - { - if (index2info(last, ni) && _tree->goto_node(ni._id)) - { - ok = _tree->expanded() && _tree->goto_firstson(); - if (ok && _hide_leaves && !_tree->has_son()) - { - _tree->goto_node(ni._id); // Ritorno al padre perche' ignoro le foglie - ok = false; - } - if (!ok) - { - ok = _tree->goto_rbrother(); - ni._startx += TABX; - } - if (ok) - { - _tree->curr_id(ni._id); - } - } - } else - if (index >= 0 && index <= last) - { - TNode_info& info = _node_info[int(index)]; - ok = info.ok(); - if (ok) - ni = info; - } - - return ok; -} - -bool TTree_window::on_key(KEY key) -{ - if (_tree == NULL || _tree_locked) - return false; - - if (key == K_RIGHT) - { - if (_tree->goto_node(_curr_info._id) && - !_tree->expanded() && _tree->has_son()) - key = K_ENTER; - else - key = K_DOWN; - } - - if (key == K_LEFT) - { - if (_tree->goto_node(_curr_info._id) && - _tree->expanded()) - key = K_ENTER; - else - key = K_UP; - } - - if (key == K_UP || key == K_DOWN) - { - _tree_locked = true; - int index = info2index(_curr_info); - if (key == K_UP) - index--; - else - index++; - - bool ok = false; - bool scroll = false; - - TNode_info ni; - if (index2info(index, ni)) - { - ok = _tree->goto_node(ni._id); - scroll = ok && (index < 0 || index > _node_info.last()); - } - else - { - const int index = key == K_UP ? 0 : _node_info.last(); - ok = index2info(index, ni) && _tree->goto_node(ni._id); - } - - if (ok && _curr_info != ni) - { - _tree->curr_id(_curr_info._id); - owner().on_key(K_SPACE); - if (!scroll) - { - force_update(); - do_events(); - } - } - - _tree_locked = false; - if (!scroll) - return true; - } - - if (key == K_ENTER) - { - _tree_locked = true; - if (_tree->goto_node(_curr_info._id)) - { - if (_tree->has_son()) - { - bool ok; - if (_tree->expanded()) - ok = _tree->shrink(); - else - ok = _tree->expand(); - if (ok) - { - force_update(); - do_events(); - // Make sure of being well positioned after the redraw!!! - _tree->goto_node(_curr_info._id); - } - } - owner().on_key(K_CTRL + K_SPACE); - } - _tree_locked = false; - } - - return TField_window::on_key(key); -} - -void TTree_window::handler(WINDOW win, EVENT* ep) -{ - switch(ep->type) - { - case E_MOUSE_DBL: - case E_MOUSE_DOWN: - if (_tree && !_tree_locked) - { - _tree_locked = true; - const TPoint lp = dev2log(ep->v.mouse.where); - const int c = (int)lp.x; - const int r = (int)lp.y; - - TNode_info ni; - bool ok = index2info(r, ni); - if (ok && (c == ni._plusx || (c >= ni._startx && c < ni._endx)) && - _tree->goto_node(ni._id)) - { - if (c == ni._plusx || (ni._expandable && ep->type == E_MOUSE_DBL && c <= ni._plusx+3)) - { - if (_tree->expanded()) - ok = _tree->shrink(); - else - ok = _tree->expand(); - if (ok) - { - owner().on_key(K_SHIFT + K_SPACE); // Expansion - owner().on_key(K_SPACE); // Selection - } - } - else - { - KEY key = K_SPACE; - if (ep->type == E_MOUSE_DBL) - key += K_CTRL; // Double click selection - owner().on_key(key); - } - if (ok) - { - _curr_info = ni; - force_update(); - } - } - _tree_locked = false; - } - break; - default: - TField_window::handler(win, ep); - break; - } -} - -TTree_window::TTree_window(int x, int y, int dx, int dy, - WINDOW parent, TTree_field* owner) - : TField_window(x, y, dx, dy, parent, owner), _tree(NULL), - _hide_leaves(false), _headlines(0) -{ - set_row_height(-1); // Compute default row height -} - -#else - /////////////////////////////////////////////////////////// // TControl_host_window /////////////////////////////////////////////////////////// @@ -1233,8 +543,6 @@ TTree_window::TTree_window(int x, int y, int dx, int dy, NULL, NULL, NULL, 0, CHARY+2); } -#endif - /////////////////////////////////////////////////////////// // TTree_field /////////////////////////////////////////////////////////// @@ -1595,3 +903,203 @@ bool TSlider_field::parse_item(TScanner& scanner) TSlider_field::TSlider_field(TMask* m) : TWindowed_field(m), _buddy(0), _range_min(ZERO), _range_max(CENTO) { } + + +/////////////////////////////////////////////////////////// +// TProp_window +/////////////////////////////////////////////////////////// + +class TProp_window : public TField_window +{ +public: + TProp_window(int x, int y, int dx, int dy, WINDOW parent, TProp_field* owner); +}; + +TProp_window::TProp_window(int x, int y, int dx, int dy, WINDOW parent, TProp_field* owner) + : TField_window(0, 0, 0, 0, NULL, NULL) +{ + XVT_COLOR_COMPONENT xcc[8]; memset(xcc, 0, sizeof(xcc)); + xcc[0].type = XVT_COLOR_BACKGROUND; + xcc[0].color = NORMAL_BACK_COLOR; + xcc[1].type = XVT_COLOR_FOREGROUND; + xcc[1].color = NORMAL_COLOR; + xcc[2].type = XVT_COLOR_HIGHLIGHT; + xcc[2].color = FOCUS_BACK_COLOR; + xcc[3].type = XVT_COLOR_SELECT; + xcc[3].color = FOCUS_COLOR; + xcc[4].type = XVT_COLOR_BLEND; + xcc[4].color = MASK_BACK_COLOR; + xcc[5].type = XVT_COLOR_TROUGH; + xcc[5].color = DISABLED_BACK_COLOR; + + set_owner(owner); + WIN_DEF wd; memset(&wd, 0, sizeof(wd)); + wd.rct = resize_rect(x, y, dx, dy, wd.wtype, parent); + wd.wtype = WC_PROPGRID; + wd.ctlcolors = xcc; + wd.v.ctl.ctrl_id = owner->dlg(); + + set_win(xvt_ctl_create_def(&wd, parent, 0L)); +} + +word TProp_field::class_id() const +{ return CLASS_PROP_FIELD; } + +bool TProp_field::is_kind_of(word cid) const +{ return cid == CLASS_PROP_FIELD || TWindowed_field::is_kind_of(cid); } + +void TProp_field::freeze(bool on) +{ + if (on) + xvt_prop_suspend(win().win()); + else + xvt_prop_restart(win().win()); +} + +bool TProp_field::set_property(const char* name, const char* value, const char* label) +{ + WINDOW pg = win().win(); + XVT_TREEVIEW_NODE node = NULL; + if (name != NULL && value == NULL && label != NULL) + node = xvt_prop_add(pg, NULL, name, NULL, label); // Category! + else + { + if (label && *label) + node = xvt_prop_add(pg, "string", name, value, label); // Add property + else + { + node = xvt_prop_find(win().win(), name); + if (node) + xvt_prop_set_data(pg, node, value); // Set property + } + } + return node != NULL; +} + +bool TProp_field::set_property(const char* name, long value, const char* label) +{ + bool done = false; + TString16 str; str << value; + if (label && *label) + done = xvt_prop_add(win().win(), "long", name, str, label) != NULL; + else + done = set_property(name, str, label); + return done; +} + +bool TProp_field::set_property(const char* name, COLOR value, const char* label) +{ + bool done = false; + TString16 str; str << long(value & 0xFFFFFF); + if (label && *label) + done = xvt_prop_add(win().win(), "color", name, str, label) != NULL; + else + done = set_property(name, str, label); + return done; +} + +const TString& TProp_field::get_property(const char* name) const +{ + WINDOW pg = win().win(); + XVT_TREEVIEW_NODE node = xvt_prop_find(pg, name); + if (node) + { + TString& tmp = get_tmp_string(); + const int len = xvt_prop_get_data(pg, node, tmp.get_buffer(), tmp.size()); + if (len > tmp.size()) + xvt_prop_get_data(pg, node, tmp.get_buffer(len), len); + return tmp; + } + return EMPTY_STRING; +} + +long TProp_field::get_long_property(const char* name) const +{ return atol(get_property(name)); } + +COLOR TProp_field::get_color_property(const char* name) const +{ + COLOR col = COLOR_INVALID; + const TString& tmp = get_property(name); + if (tmp.full()) + { + col = atol(tmp); + if (col == 0) + col = COLOR_BLACK; + } + return col; +} + +static TString_array _items; + +bool TProp_field::parse_item(TScanner& scanner) +{ + if (scanner.key() == "IT") + { + const TString80 label = dictionary_translate(scanner.string()); + TString16 type = scanner.pop(); + TString80 name, value; + if (type.starts_with("IT")) + { + type.cut(0); + scanner.push(); + } + else + { + const TString& line = scanner.line(); + int equal = line.find('='); + if (equal < 0) equal = line.find(' '); + if (equal > 0) + { + name = line.left(equal); name.trim(); + value = line.mid(equal+1); value.trim(); + if (value[0] == '"') { value.rtrim(1); value.ltrim(1); } + } + else + { + name.trim(); + value.cut(0); + } + type.cut(2); + } + + TToken_string* item = new TToken_string; + item->add(type); item->add(name); item->add(value); item->add(label,3); + _items.add(item); + return true; + } + return TWindowed_field::parse_item(scanner); +} + +TField_window* TProp_field::create_window(int x, int y, int dx, int dy, WINDOW parent) +{ + TProp_window* pw = new TProp_window(x, y, dx, dy, parent, this); + if (!_items.empty()) + { + WINDOW pg = pw->win(); + xvt_prop_suspend(pg); + TString8 type; + TString80 name, value, label; + FOR_EACH_ARRAY_ROW(_items, i, row) + { + row->get(0, type); row->get(1, name); + row->get(2, value); row->get(3, label); + if (type.full()) + { + if (type == "CO") + xvt_prop_add(pg, "color", name, value, label); else + if (type == "NU" || type == "CU") + xvt_prop_add(pg, "long", name, value, label); + else + xvt_prop_add(pg, "string", name, value, label); + } + else + xvt_prop_add(pg, "", "", "", label); + } + xvt_prop_restart(pg); + _items.destroy(); + } + return pw; +} + +TProp_field::TProp_field(TMask* m) : TWindowed_field(m) +{ } diff --git a/include/treectrl.h b/include/treectrl.h index 6af90c3d0..1a055eb35 100755 --- a/include/treectrl.h +++ b/include/treectrl.h @@ -125,4 +125,27 @@ public: virtual ~TSlider_field() { } }; + +class TProp_field : public TWindowed_field +{ +protected: + virtual TField_window* create_window(int x, int y, int dx, int dy, WINDOW parent); + virtual bool parse_item(TScanner& scanner); + +public: + virtual word class_id() const; + virtual bool is_kind_of(word cid) const; + + void freeze(bool on); + bool set_property(const char* name, const char* value, const char* label = NULL); + bool set_property(const char* name, COLOR value, const char* label = NULL); + bool set_property(const char* name, long value, const char* label = NULL); + + const TString& get_property(const char* name) const; + COLOR get_color_property(const char* name) const; + long get_long_property(const char* name) const;; + + TProp_field(TMask* m); +}; + #endif diff --git a/xvaga/xvt.h b/xvaga/xvt.h index 6b23b1ca6..d986d3d10 100755 --- a/xvaga/xvt.h +++ b/xvaga/xvt.h @@ -456,6 +456,14 @@ XVTDLL BOOLEAN xvt_odbc_free_connection(XVT_ODBC handle); XVTDLL ULONG xvt_odbc_execute(XVT_ODBC handle, const char* sql, ODBC_CALLBACK cb, void* jolly); XVTDLL BOOLEAN xvt_odbc_driver(XVT_ODBC handle, char* str, int max_size); +XVTDLL XVT_TREEVIEW_NODE xvt_prop_add(WINDOW win, const char* type, const char* name, const char* value, const char* label); +XVTDLL XVT_TREEVIEW_NODE xvt_prop_find(WINDOW win, const char* name); +XVTDLL int xvt_prop_get_string(WINDOW win, XVT_TREEVIEW_NODE node, char* label, int maxlen); +XVTDLL int xvt_prop_get_data(WINDOW win, XVT_TREEVIEW_NODE node, char* value, int maxlen); +XVTDLL BOOLEAN xvt_prop_restart(WINDOW win); +XVTDLL BOOLEAN xvt_prop_set_data(WINDOW win, XVT_TREEVIEW_NODE node, const char* value); +XVTDLL BOOLEAN xvt_prop_suspend(WINDOW win); + XVTDLL BOOLEAN xvt_mail_send(const char* to, const char* cc, const char* ccn, const char* subject, const char* msg, const char* attach, BOOLEAN ui); diff --git a/xvaga/xvt_type.h b/xvaga/xvt_type.h index 617530a51..c55e9592f 100755 --- a/xvaga/xvt_type.h +++ b/xvaga/xvt_type.h @@ -199,42 +199,43 @@ SC_THUMBTRACK /* thumb tracking */ typedef enum { /* type of window */ -W_NONE, /* marker for end of WIN_DEF array */ -W_DOC, /* document window */ -W_PLAIN, /* window with plain border */ -W_DBL, /* window with double border */ -W_PRINT, /* XVT internal use only */ -W_TASK, /* task window */ -W_SCREEN, /* screen window */ -W_NO_BORDER, /* no border */ -W_PIXMAP, /* pixmap */ -W_MODAL, /* modal window */ -WD_MODAL, /* modal dialog */ -WD_MODELESS, /* modeless dialog */ +W_NONE, /* marker for end of WIN_DEF array */ +W_DOC, /* document window */ +W_PLAIN, /* window with plain border */ +W_DBL, /* window with double border */ +W_PRINT, /* XVT internal use only */ +W_TASK, /* task window */ +W_SCREEN, /* screen window */ +W_NO_BORDER, /* no border */ +W_PIXMAP, /* pixmap */ +W_MODAL, /* modal window */ +WD_MODAL, /* modal dialog */ +WD_MODELESS, /* modeless dialog */ WC_PUSHBUTTON, /* button control */ WC_RADIOBUTTON, /* radio button control */ -WC_CHECKBOX, /* check box control */ -WC_HSCROLL, /* horizontal scrollbar control */ -WC_VSCROLL, /* vertical scrollbar control */ +WC_CHECKBOX, /* check box control */ +WC_HSCROLL, /* horizontal scrollbar control */ +WC_VSCROLL, /* vertical scrollbar control */ //WC_EDIT, /* edit control */ commentato perche' rompe le scatole -WC_TEXT, /* static text control */ -WC_LBOX, /* list box control */ +WC_TEXT, /* static text control */ +WC_LBOX, /* list box control */ WC_LISTBUTTON, /* button with list */ WC_CHECKBUTTON, /* check button control */ -WC_LISTEDIT, /* edit with field list */ -WC_GROUPBOX, /* group box */ -WC_TEXTEDIT, /* text edit object */ -WC_ICON, /* icon control */ -WO_TE, /* text edit */ -WC_HGAUGE, /* horizontal progress bar */ -WC_VGAUGE, /* vertical progress bar */ -WC_NOTEBK, /* notebook control */ -WC_HTML, /* HTML control */ -WC_TREE, /* tree view */ -WC_OUTLOOKBAR, /* Barra di outlook */ -WC_HSLIDER, /* horizontal slider control */ -WC_VSLIDER, /* vertical slider control */ -WC_POPUP /* list of listedit control or popup menu */ +WC_LISTEDIT, /* edit with field list */ +WC_GROUPBOX, /* group box */ +WC_TEXTEDIT, /* text edit object */ +WC_ICON, /* icon control */ +WO_TE, /* text edit */ +WC_HGAUGE, /* horizontal progress bar */ +WC_VGAUGE, /* vertical progress bar */ +WC_NOTEBK, /* notebook control */ +WC_HTML, /* HTML control */ +WC_TREE, /* tree view */ +WC_OUTLOOKBAR, /* Barra di outlook */ +WC_HSLIDER, /* horizontal slider control */ +WC_VSLIDER, /* vertical slider control */ +WC_POPUP, /* list of listedit control or popup menu */ +WC_PROPGRID, /* property grid */ } WIN_TYPE; typedef enum { diff --git a/xvaga/xvtctl.cpp b/xvaga/xvtctl.cpp index a1a733be9..42710a4b5 100755 --- a/xvaga/xvtctl.cpp +++ b/xvaga/xvtctl.cpp @@ -7,6 +7,7 @@ #include #include #include +#include /////////////////////////////////////////////////////////// // Utility functions @@ -215,6 +216,15 @@ public: TwxPopUp(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size); }; +class TwxPropertyGrid : public wxPropertyGrid +{ + DECLARE_EVENT_TABLE() +protected: + void OnPropertyChanged(wxPropertyGridEvent& evt); +public: + TwxPropertyGrid(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style); +}; + WINDOW xvt_ctl_create_def(WIN_DEF* win_def_p, WINDOW parent_win, long app_data) { wxASSERT(win_def_p != NULL); @@ -296,17 +306,24 @@ WINDOW xvt_ctl_create_def(WIN_DEF* win_def_p, WINDOW parent_win, long app_data) win = (WINDOW)tlb; } break; + case WC_OUTLOOKBAR: + { + long style = 0; + TwxOutlookBar* tob = new TwxOutlookBar(pParent, id, rct.GetPosition(), rct.GetSize(), style); + win = (WINDOW)tob; + } + break; case WC_POPUP: { TwxPopUp* tpu = new TwxPopUp(pParent, id, rct.GetPosition(), rct.GetSize()); win = (WINDOW)tpu; } break; - case WC_OUTLOOKBAR: + case WC_PROPGRID: { - long style = 0; - TwxOutlookBar* tob = new TwxOutlookBar(pParent, id, rct.GetPosition(), rct.GetSize(), style); - win = (WINDOW)tob; + long flags = wxPG_BOLD_MODIFIED | wxPG_SPLITTER_AUTO_CENTER | wxPG_DESCRIPTION | wxPG_TOOLTIPS; + TwxPropertyGrid* pg = new TwxPropertyGrid(pParent, id, rct.GetPosition(), rct.GetSize(), flags); + win = (WINDOW)pg; } break; default: @@ -363,33 +380,54 @@ void xvt_ctl_set_colors(WINDOW win, const XVT_COLOR_COMPONENT* colors, XVT_COLOR { if (action == XVT_COLOR_ACTION_SET) { - for (int i = 0; colors[i].type; i++) + wxPropertyGrid* pg = wxDynamicCast(w, wxPropertyGrid); + if (pg != NULL) { - CAST_COLOR(colors[i].color, rgb); - switch(colors[i].type) + for (int i = 0; colors[i].type; i++) { - case XVT_COLOR_BACKGROUND: w->SetOwnBackgroundColour(rgb); break; - case XVT_COLOR_FOREGROUND: w->SetOwnForegroundColour(rgb); break; - case XVT_COLOR_HIGHLIGHT: + CAST_COLOR(colors[i].color, rgb); + switch(colors[i].type) { - TwxPopUp* tpu = wxDynamicCast(w, TwxPopUp); - if (tpu != NULL) - tpu->SetSelectForeColor(rgb); + case XVT_COLOR_BACKGROUND: pg->SetCellBackgroundColour(rgb); break; + case XVT_COLOR_FOREGROUND: pg->SetCellTextColour(rgb); pg->SetCaptionForegroundColour(rgb); break; + case XVT_COLOR_HIGHLIGHT : pg->SetSelectionBackground(rgb); break; + case XVT_COLOR_SELECT : pg->SetSelectionForeground(rgb); break; + case XVT_COLOR_BLEND : pg->SetCaptionBackgroundColour(rgb); pg->SetMarginColour(rgb); break; + case XVT_COLOR_TROUGH : pg->SetEmptySpaceColour(rgb); break; + default : break; } - break; - case XVT_COLOR_SELECT: + } + } + else + { + for (int i = 0; colors[i].type; i++) + { + CAST_COLOR(colors[i].color, rgb); + switch(colors[i].type) { - TwxPopUp* tpu = wxDynamicCast(w, TwxPopUp); - if (tpu != NULL) - tpu->SetSelectBackColor(rgb); + case XVT_COLOR_BACKGROUND: w->SetOwnBackgroundColour(rgb); break; + case XVT_COLOR_FOREGROUND: w->SetOwnForegroundColour(rgb); break; + case XVT_COLOR_HIGHLIGHT: + { + TwxPopUp* tpu = wxDynamicCast(w, TwxPopUp); + if (tpu != NULL) + tpu->SetSelectForeColor(rgb); + } + break; + case XVT_COLOR_SELECT: + { + TwxPopUp* tpu = wxDynamicCast(w, TwxPopUp); + if (tpu != NULL) + tpu->SetSelectBackColor(rgb); + } + break; + case XVT_COLOR_BLEND: + if (!w->IsKindOf(CLASSINFO(wxButton))) + w->SetOwnBackgroundColour(rgb); + break; + default: + break; } - break; - case XVT_COLOR_BLEND: - if (!w->IsKindOf(CLASSINFO(wxButton))) - w->SetOwnBackgroundColour(rgb); - break; - default: - break; } } } @@ -1713,12 +1751,12 @@ TwxPopUp::TwxPopUp(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wx m_clrBack = GetSelectionBackground(); const wxFont font = parent->GetFont(); - m_nRowHeight = abs(font.GetPixelSize().y) + 8; + m_nRowHeight = abs(font.GetPixelSize().y) + 4; } static int RoundPopupHeight(int list_h, int row_h) { - const int rem = list_h % row_h; + const int rem = list_h % (row_h+1); if (rem > 0) list_h -= rem; return list_h; @@ -1743,12 +1781,12 @@ MENU_TAG xvt_list_popup(WINDOW parent_win, const RCT* ownrct, const MENU_ITEM* m } const wxFont font = parent->GetFont(); - const int nRowHeight = abs(font.GetPixelSize().y)+8; + const int nRowHeight = abs(font.GetPixelSize().y)+4; const wxRect rctClient = parent->GetClientRect(); const int nBottom = rctClient.GetBottom(); wxPoint pos(ownrct->right-width, ownrct->bottom); - wxSize size(width, items*nRowHeight); + wxSize size(width, items*nRowHeight+2); if (pos.y + size.y > nBottom) // La lista deborda di sotto? { @@ -2076,3 +2114,198 @@ void xvt_dwin_draw_tool(WINDOW win, int x, int y, int rid, int size) dc.DrawBitmap(bmp, x, y); } } + +/////////////////////////////////////////////////////////// +// wxPropertyGrid +/////////////////////////////////////////////////////////// + +#include + +BEGIN_EVENT_TABLE(TwxPropertyGrid, wxPropertyGrid) + EVT_PG_CHANGED(wxID_ANY, TwxPropertyGrid::OnPropertyChanged) +END_EVENT_TABLE(); + +void TwxPropertyGrid::OnPropertyChanged(wxPropertyGridEvent& evt) +{ + TwxWindow* win = wxDynamicCast(GetParent(), TwxWindow); + if (win != NULL && !IsFrozen()) + { + EVENT e; memset(&e, 0, sizeof(EVENT)); + e.type = E_CONTROL; + e.v.ctl.id = evt.GetId(); + e.v.ctl.ci.v.treeview.sgl_click = TRUE; + e.v.ctl.ci.v.treeview.node = evt.GetProperty(); + e.v.ctl.ci.type = WC_PROPGRID; + e.v.ctl.ci.win = WINDOW(this); + win->DoXvtEvent(e); + } +} + +TwxPropertyGrid::TwxPropertyGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) + : wxPropertyGrid(parent, id, pos, size, style) +{ } + +static BOOLEAN xvt_prop_freeze(WINDOW win, BOOLEAN on) +{ + wxPropertyGrid* pg = wxDynamicCast((wxObject*)win, wxPropertyGrid); + const BOOLEAN ok = pg != NULL && on != BOOLEAN(pg->IsFrozen()); + if (ok) + { + if (on) + pg->Freeze(); + else + { + pg->Thaw(); + pg->Refresh(); + } + } + return ok; +} + +BOOLEAN xvt_prop_restart(WINDOW win) +{ return xvt_prop_freeze(win, FALSE); } + +BOOLEAN xvt_prop_suspend(WINDOW win) +{ return xvt_prop_freeze(win, TRUE); } + +static wxColour STR2COLOUR(const char* value) +{ + wxColour col; + + if (value && *value) + { + if (*value == '(') + value++; + if (isdigit(*value)) + { + int r, g, b; + const int n = sscanf(value, "%d,%d,%d", &r, &g, &b); + if (n == 3) + col = wxColour(r, g, b); + else + col = wxColour(r & 0xFFFFFF); + } + else + col = wxColour(value); // Black, White, Yellow, ... + } + return col; +} + +BOOLEAN xvt_prop_set_data(WINDOW win, XVT_TREEVIEW_NODE node, const char* value) +{ + wxPropertyGrid* pg = wxDynamicCast((wxObject*)win, wxPropertyGrid); + if (pg != NULL) + { + wxPGProperty* pgp = wxDynamicCast((wxObject*)node, wxPGProperty); + if (pgp != NULL) + { + const wxString strType = pgp->GetType(); + if (strType == "wxColour") + { + wxColourPropertyValue val(STR2COLOUR(value)); + wxVariant& var = pgp->GetValueRef(); + var = ((wxColourProperty*)pgp)->DoTranslateVal(val); + } + else + { + if (strType == "long" || strType == "int") + pgp->SetValue(atol(value)); + else + pgp->SetValue(value); + } + return TRUE; + } + } + return FALSE; +} + +XVT_TREEVIEW_NODE xvt_prop_add(WINDOW win, const char* type, const char* name, const char* value, const char* label) +{ + wxPropertyGrid* pg = wxDynamicCast((wxObject*)win, wxPropertyGrid); + if (pg != NULL) + { + wxPGProperty* pgp = pg->GetPropertyByName(name); + if (pgp == NULL) + { + const wxString strLabel = (label && *label) ? label : name; + if (type && *type > ' ') + { + switch (toupper(*type)) + { + case 'C': pgp = new wxColourProperty(strLabel, name, STR2COLOUR(value)); break; + case 'I': + case 'L': pgp = new wxIntProperty(strLabel, name, atol(value)); break; + default : pgp = new wxStringProperty(strLabel, name, value); break; + } + } + else + pgp = new wxPropertyCategory(strLabel, name); + pg->Append(pgp); + } + else + xvt_prop_set_data(win, pgp, value); + return pgp; + } + return NULL; +} + +XVT_TREEVIEW_NODE xvt_prop_find(WINDOW win, const char* name) +{ + XVT_TREEVIEW_NODE node = NULL; + wxPropertyGrid* pg = wxDynamicCast((wxObject*)win, wxPropertyGrid); + if (pg != NULL) + node = pg->GetPropertyByName(name); + return node; +} + +int xvt_prop_get_string(WINDOW win, XVT_TREEVIEW_NODE node, char* label, int maxlen) +{ + int len = -1; + wxPropertyGrid* pg = wxDynamicCast((wxObject*)win, wxPropertyGrid); + if (pg != NULL) + { + const wxPGProperty* pgp = wxDynamicCast((wxObject*)node, wxPGProperty); + if (pgp != NULL) + { + const wxString& str = pgp->GetLabel(); + if (label && maxlen > 0) + { + wxStrncpy(label, str, maxlen); + label[maxlen-1] = '\0'; + } + len = str.Len(); + } + } + return len; +} + +int xvt_prop_get_data(WINDOW win, XVT_TREEVIEW_NODE node, char* value, int maxlen) +{ + int len = -1; + wxPropertyGrid* pg = wxDynamicCast((wxObject*)win, wxPropertyGrid); + if (pg != NULL) + { + const wxPGProperty* pgp = wxDynamicCast((wxObject*)node, wxPGProperty); + if (pgp != NULL) + { + wxString str = pgp->GetValueAsString(); + wxString strType = pgp->GetType(); + + if (strType == "wxColour") + { + strType = "color"; + int r, g, b; wxSscanf(str, "(%d,%d,%d)", &r, &g, &b); + COLOR rgb = XVT_MAKE_COLOR(r, g, b); + if (rgb == 0) rgb = COLOR_BLACK; + str.Printf("%ld", rgb); + } + len = str.Len(); + if (value != NULL && maxlen > 0) + { + wxStrncpy(value, str, maxlen); + value[maxlen-1] = '\0'; + } + } + } + return len; +}