From 0c6e21e4b5ddfdd9cbf0245770d9d83a78055725 Mon Sep 17 00:00:00 2001 From: guy Date: Fri, 27 Feb 2009 09:13:47 +0000 Subject: [PATCH] Patch level : 10.0 Files correlati : tutti Ricompilazione Demo : [ ] Commento : Ridefinito meglio metodo virtuale error_box degli spreadsheet per rendere nuovamente compilabili i programmi. la gestione delle righe colorate e' ancora incompleta. git-svn-id: svn://10.65.10.50/trunk@18371 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/colors.cpp | 64 +++---------------- include/config.cpp | 22 ++++--- include/maskfld.cpp | 11 ++-- include/maskfld.h | 10 +-- include/msksheet.cpp | 147 ++++++++++++++++++++++++------------------- include/msksheet.h | 3 +- 6 files changed, 118 insertions(+), 139 deletions(-) diff --git a/include/colors.cpp b/include/colors.cpp index 5112c3100..bc53b10d8 100755 --- a/include/colors.cpp +++ b/include/colors.cpp @@ -5,36 +5,15 @@ COLOR RGB2COLOR(unsigned char red, unsigned char green, unsigned char blue) { COLOR def = XVT_MAKE_COLOR(red, green, blue); - -/* -#ifndef DBG - // Se nel colore non compare l'indice cerca di calcolarlo - const unsigned char color_index = (unsigned char)(def >> 12); - if (color_index <= 0x0 || color_index > 0xF) - { - const COLOR native_color[11] = { COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_CYAN, - COLOR_MAGENTA, COLOR_YELLOW, COLOR_BLACK, COLOR_DKGRAY, - COLOR_GRAY, COLOR_LTGRAY, COLOR_WHITE }; - def &= 0x00FFFFFF; - for (int c = 0; c < 11; c++) - { - // Confronta solo la terna R,G,B - if (def == (native_color[c] & 0x00FFFFFF)) - { - def = native_color[c]; - break; - } - } - } -#endif -*/ - + if (def == 0) def = COLOR_BLACK; // Per non confonderlo col colore 0, default per XI return def; } COLOR choose_color(COLOR col, WINDOW win) { - return xvt_dm_post_choose_color(win, col); + COLOR def = xvt_dm_post_choose_color(win, col); + if (def == 0) def = COLOR_BLACK; // Per non confonderlo col colore 0, default per XI + return def; } COLOR blend_colors(COLOR col1, COLOR col2, double perc) @@ -49,8 +28,7 @@ COLOR blend_colors(COLOR col1, COLOR col2, double perc) const byte r = byte(r1 * perc + r2*(1.0-perc)); const byte g = byte(g1 * perc + g2*(1.0-perc)); const byte b = byte(b1 * perc + b2*(1.0-perc)); - - return XVT_MAKE_COLOR(r, g, b); + return RGB2COLOR(r, g, b); } COLOR grayed_color(COLOR col) @@ -59,33 +37,13 @@ COLOR grayed_color(COLOR col) const unsigned int g = XVT_COLOR_GET_GREEN(col); const unsigned int b = XVT_COLOR_GET_BLUE(col); const unsigned int k = (unsigned int)(0.299 * r + 0.587 * g + 0.114 * b); - return XVT_MAKE_COLOR(k, k, k); + return RGB2COLOR(k, k, k); } -/* -unsigned int color_distance(COLOR col1, COLOR col2) -{ - if (same_color(col1, col2)) - return 0; - - const int r1 = XVT_COLOR_GET_RED(col1); - const int g1 = XVT_COLOR_GET_GREEN(col1); - const int b1 = XVT_COLOR_GET_BLUE(col1); - const int r2 = XVT_COLOR_GET_RED(col2); - const int g2 = XVT_COLOR_GET_GREEN(col2); - const int b2 = XVT_COLOR_GET_BLUE(col2); - const int r = abs(r1-r2); - const int g = abs(g1-g2); - const int b = abs(b1-b2); - return (r > g && r > b) ? r : (g > b ? g : b); -} -*/ - class TColor_row_mask : public TMask { public: virtual void update(); - TColor_row_mask(); virtual ~TColor_row_mask() { } }; @@ -94,10 +52,8 @@ public: // TColor_row_mask /////////////////////////////////////////////////////////// -TColor_row_mask::TColor_row_mask() - : TMask("bagn007", 1) -{ -} +TColor_row_mask::TColor_row_mask() : TMask("bagn007", 1) +{ } void TColor_row_mask::update() { @@ -218,14 +174,12 @@ bool TSelect_color_mask::reset_handler(TMask_field& f, KEY k) if (k == K_ENTER) { TSelect_color_mask& cm = (TSelect_color_mask&)f.mask(); - cm.save(); } return TRUE; } -int TSelect_color_mask::add_color_def(const char * key, const char * prompt, COLOR back, COLOR fore) - +int TSelect_color_mask::add_color_def(const char* key, const char* prompt, COLOR back, COLOR fore) { TColor_object_props * p = new TColor_object_props(key, prompt, back, fore); TSheet_field& s = sfield(101); diff --git a/include/config.cpp b/include/config.cpp index 5db989d00..c36bc59b6 100755 --- a/include/config.cpp +++ b/include/config.cpp @@ -425,14 +425,22 @@ COLOR TConfig::get_color( // @xref // { - const char* c = get(var, section, index); - if (*c) + TToken_string s(get(var, section, index), ','); + if (s.full()) { - TToken_string s(c, ','); - const byte r = (byte)s.get_int(); - const byte g = (byte)s.get_int(); - const byte b = (byte)s.get_int(); - def = RGB2COLOR(r, g, b); + if (s.find(',') > 0) + { + const byte r = (byte)s.get_int(); + const byte g = (byte)s.get_int(); + const byte b = (byte)s.get_int(); + def = RGB2COLOR(r, g, b); + } + else + { + def = atol(s); + if (def == 0L) + def = COLOR_BLACK; + } } else { diff --git a/include/maskfld.cpp b/include/maskfld.cpp index aa64da5af..aedd2a99e 100755 --- a/include/maskfld.cpp +++ b/include/maskfld.cpp @@ -624,10 +624,11 @@ bool TMask_field::error_box( { build_msg(); - if (mask().is_sheetmask() && !mask().is_running()) - mask().get_sheet()->error_box(_msg); + TMask& m = mask(); + if (m.is_sheetmask() && !m.is_running()) + m.get_sheet()->error_box(_msg); else - mask().post_error_message(_msg, 3); + m.post_error_message(_msg, 3); return false; } @@ -4782,11 +4783,11 @@ const char* TList_field::raw2win(const char* data) const TToken_string& codes = ((TList_field*)this)->_codes; TToken_string& value = ((TList_field*)this)->_values; - TString80 str = data; // data puo' venire da una TToken_string::get + TString256 str = data; // data puo' venire da una TToken_string::get int pos = codes.get_pos(str); if (pos < 0 && (str.blank() || str == "0")) { - str = codes.get(0); + codes.get(0, str); if (str.blank() || str == "0") pos = 0; } diff --git a/include/maskfld.h b/include/maskfld.h index d2b674409..be19dd223 100755 --- a/include/maskfld.h +++ b/include/maskfld.h @@ -387,15 +387,15 @@ public: virtual void set_focus() const; // @cmember Crea una message-box relativamente al campo (chiama ) - bool message_box(const char* fmt, ...) const; + virtual bool message_box(const char* fmt, ...) const; // @cmember Crea una warning-box relativamente al campo (chiama ) - bool warning_box(const char* fmt, ...) const; + virtual bool warning_box(const char* fmt, ...) const; // @cmember Crea una error-box relativamente al campo (chiama ) - bool error_box(const char* fmt, ...) const; + virtual bool error_box(const char* fmt, ...) const; // @cmember Crea una yesno-box relativamente al campo (chiama ) - bool yesno_box(const char* fmt, ...) const; + virtual bool yesno_box(const char* fmt, ...) const; // @cmember Crea una yesnocancel-box relativamente al campo (chiama ) - KEY yesnocancel_box(const char* fmt, ...) const; + virtual KEY yesnocancel_box(const char* fmt, ...) const; void update_flags(const char * f, bool reset = false); // @cmember Ritorna per riferimento la maschera di appartenenza del campo diff --git a/include/msksheet.cpp b/include/msksheet.cpp index ba0ef36ae..a6e0a2287 100755 --- a/include/msksheet.cpp +++ b/include/msksheet.cpp @@ -15,23 +15,31 @@ extern "C" #include #include #include +#include class TCell_property : public TObject { COLOR _back, _fore; public: - void set(COLOR back, COLOR fore) { _back = back; _fore = fore;} - void get(COLOR & back, COLOR & fore) const { back = _back; fore = _fore;} - + void set(COLOR back, COLOR fore) { _back = back; _fore = fore; } + bool get(COLOR& back, COLOR& fore) const; TCell_property(); - virtual ~TCell_property() { } }; - -TCell_property::TCell_property() - : _back(NORMAL_BACK_COLOR), _fore(NORMAL_COLOR) -{ + +bool TCell_property::get(COLOR& back, COLOR& fore) const +{ + if (_back != COLOR_INVALID && _fore != COLOR_INVALID) + { + back = _back; + fore = _fore; + return true; + } + return false; } + +TCell_property::TCell_property() : _back(COLOR_INVALID), _fore(COLOR_INVALID) +{ } class TRow_property : public TObject { @@ -42,7 +50,7 @@ class TRow_property : public TObject public: void set(int col, COLOR back, COLOR fore); - void get(int col, COLOR & back, COLOR & fore) const; + bool get(int col, COLOR & back, COLOR & fore) const; void set_height(int h) { _height = h; } int height() const { return _height; } @@ -54,7 +62,7 @@ public: }; TRow_property::TRow_property() - : _back(0), _fore(0), _height(-1), _cell_prop(NULL) + : _back(COLOR_INVALID), _fore(COLOR_INVALID), _height(-1), _cell_prop(NULL) { } @@ -75,9 +83,9 @@ void TRow_property::set(int col, COLOR back, COLOR fore) if (_cell_prop == NULL) _cell_prop = new TArray; - TCell_property * p = (TCell_property *) _cell_prop->objptr(col); + TCell_property* p = (TCell_property*)_cell_prop->objptr(col); - if (back == COLOR_INVALID && fore == COLOR_INVALID) + if (back == COLOR_INVALID || fore == COLOR_INVALID) { if (p != NULL) _cell_prop->destroy(col); @@ -94,19 +102,24 @@ void TRow_property::set(int col, COLOR back, COLOR fore) } } -void TRow_property::get(int col, COLOR & back, COLOR & fore) const +bool TRow_property::get(int col, COLOR & back, COLOR & fore) const { if (col >= 0) // Lascia stare la colonna del numero riga { - back = _back; - fore = _fore; if (_cell_prop != NULL) { const TCell_property* cp = (const TCell_property*)_cell_prop->objptr(col); - if (cp != NULL) - cp->get(back, fore); + if (cp != NULL && cp->get(back, fore)) + return true; + } + if (_back != COLOR_INVALID && _fore != COLOR_INVALID) + { + back = _back; + fore = _fore; + return true; } } + return false; } /////////////////////////////////////////////////////////// @@ -330,7 +343,7 @@ public: // @cmember Setta i colori di una riga void set_back_and_fore_color(COLOR back, COLOR fore, int row, int col); // @cmember Legge i colori di una riga - void get_back_and_fore_color(COLOR& back, COLOR& fore, int row, int col); + bool get_back_and_fore_color(COLOR& back, COLOR& fore, int row, int col); // @cmember Ritorna la maschera che appartiene allo spreadsheet TMask& sheet_mask() const; @@ -383,7 +396,7 @@ public: { _notify = n; } // @cmember aggiunge una riga bool add_row_auto(); - bool error_box(const char * msg); + bool error_box(const char* msg); // @cmember Costruttore TSpreadsheet(WINDOW parent, short dlg, short x, short y, short dx, short dy, const char* maskname, int maskno, const char* head, TSheet_field* owner); @@ -826,10 +839,8 @@ void TSpreadsheet::set_focus_cell(int riga, int colonna) xvt_vobj_raise(par); } - XI_OBJ cell; - XI_MAKE_CELL(&cell, _obj, riga, colonna); - - xi_set_focus(&cell); + XI_OBJ cell; XI_MAKE_CELL(&cell, _obj, riga, colonna); + xi_set_focus(&cell); if (rec != _cur_rec) { @@ -1090,7 +1101,7 @@ bool TSpreadsheet::event_handler(XI_OBJ* itf, XI_EVENT *xiev) { const long rec = xiev->v.cell_request.rec; const int maxlen = xiev->v.cell_request.len; - char numrig[8]; + const char* src = NULL; int nm; XI_OBJ** obj = xi_get_member_list(xiev->v.cell_request.list, &nm); @@ -1158,25 +1169,22 @@ bool TSpreadsheet::event_handler(XI_OBJ* itf, XI_EVENT *xiev) if (cell_disabled(rec, col)) { xiev->v.cell_request.back_color = DISABLED_BACK_COLOR; + xiev->v.cell_request.color = DISABLED_COLOR; xiev->v.cell_request.attrib &= ~XI_ATR_ENABLED; } else { -// XI_OBJ * obj = xi_get_focus(itf); - -// if (obj->type != XIT_CELL || obj->v.cell.column != num || -// obj->v.cell.row != xiev->v.cell_request.rec) -// { - COLOR back, fore; - get_back_and_fore_color(back, fore, rec, col); - - if (back != COLOR_INVALID && back != NORMAL_BACK_COLOR) - xiev->v.cell_request.back_color = back; - if (fore != COLOR_INVALID && fore != NORMAL_COLOR) - xiev->v.cell_request.color = fore; - if (xiev->v.cell_request.back_color == 0 && f->required()) - xiev->v.cell_request.back_color = REQUIRED_BACK_COLOR; -// } + // Non impostare il colore per la cella correntemente col focus + if (xiev->v.cell_request.rec != _cur_rec && xiev->v.cell_request.col_nbr != _cur_col) + { + const bool bfc = get_back_and_fore_color(xiev->v.cell_request.back_color, + xiev->v.cell_request.color, rec, col); + if (!bfc && f->required()) + { + xiev->v.cell_request.back_color = REQUIRED_BACK_COLOR; + xiev->v.cell_request.color = 0; + } + } if (e->has_query_button()) // Metto il bottone sulle celle attive { @@ -1189,14 +1197,14 @@ bool TSpreadsheet::event_handler(XI_OBJ* itf, XI_EVENT *xiev) } } else + { xiev->v.cell_request.back_color = DISABLED_BACK_COLOR; + xiev->v.cell_request.color = DISABLED_COLOR; + } } } else - { - sprintf(numrig, "%d", rec+1); - src = numrig; - } + src = format("%d", rec+1); // Numero riga char* dst = xiev->v.cell_request.s; if (src && *src) @@ -2082,8 +2090,6 @@ void TSpreadsheet::set_back_and_fore_color(COLOR back, COLOR fore, int row, int if (col >= FIRST_FIELD) col = cid2index(col); -// if (back != COLOR_INVALID || fore != COLOR_INVALID) -// { int first, last; if (row < 0) { @@ -2093,21 +2099,25 @@ void TSpreadsheet::set_back_and_fore_color(COLOR back, COLOR fore, int row, int else first = last = row; - const bool crea = back != NORMAL_BACK_COLOR || fore != NORMAL_COLOR; + if (col < 0 && same_color(back, NORMAL_BACK_COLOR) && same_color(fore, NORMAL_COLOR)) + back = fore = COLOR_INVALID; + + const bool crea = back != COLOR_INVALID && fore != COLOR_INVALID; + CHECK(!((back==COLOR_INVALID)^(fore== COLOR_INVALID)), "Coppia di colori mal assortita"); for (int r = first; r <= last; r++) { TRow_property* prop = get_property(r, crea); if (prop) prop->set(col, back, fore); } -// } } -void TSpreadsheet::get_back_and_fore_color(COLOR& back, COLOR& fore, int row, int col) +bool TSpreadsheet::get_back_and_fore_color(COLOR& back, COLOR& fore, int row, int col) { - TRow_property* prop = get_property(row, FALSE); + TRow_property* prop = get_property(row, false); if (prop != NULL) - prop->get(col, back, fore); + return prop->get(col, back, fore); + return false; } // @doc INTERNAL @@ -2505,25 +2515,28 @@ bool TSpreadsheet::add_row_auto() { int rec = -1; + TMask& om = owner().mask(); + const bool omrun = om.is_running(); if (items() > 0 && !owner().append()) { - if (owner().mask().focus_field().dlg() == id()) + if (om.focus_field().dlg() == id()) rec = _cur_rec + 1; else rec = 0; } - ok = insert(rec, true, true) >= 0; + ok = insert(rec, omrun, true) >= 0; if (ok) { _cell_dirty = _row_dirty = false; - owner().mask().notify_focus_field(id()); + if (omrun) + om.notify_focus_field(id()); } } } return ok; } -bool TSpreadsheet::error_box(const char * msg) +bool TSpreadsheet::error_box(const char* msg) { _check_enabled = false; xvt_dm_post_speech(msg, 0, TRUE); @@ -3017,23 +3030,22 @@ TMask& TSheet_field::sheet_row_mask(int /* row */) const { return sheet_mask(); } - bool TSheet_field::on_hit() { - if (!mask().is_running()) // Inizializzazione maschera + TMask& m = mask(); + if (!m.is_running()) // Inizializzazione maschera { TSpreadsheet* s = (TSpreadsheet*)_ctl; + if (s->auto_append() && items() == 0 && !m.query_mode()) + s->add_row_auto(); // Inserisco automaticamente la prima riga vuota nello sheet force_update(); if (items() > 0) { - mask().notify_focus_field(dlg()); // Fa' credere alla maschera che ha il focus ... - select(0, -2, TRUE); // ... cosi' la set_focus_cell funziona bene + m.notify_focus_field(dlg()); // Fa' credere alla maschera che ha il focus ... + select(0, -2, TRUE); // ... cosi' la set_focus_cell funziona bene } - else - if (s->auto_append()) - s->add_row_auto(); set_dirty(FALSE); } @@ -3515,9 +3527,14 @@ bool TSheet_field::esporta() const return true; } -bool TSheet_field::error_box(const char * msg) -{ - TSpreadsheet& s = (TSpreadsheet&)*_ctl; - return s.error_box(msg); +bool TSheet_field::error_box(const char* fmt, ...) const +{ + char msg[256]; + va_list argptr; + va_start(argptr,fmt); + _vsnprintf(msg,sizeof(msg),fmt,argptr); + va_end(argptr); + msg[255] = '\0'; + return ((TSpreadsheet*)_ctl)->error_box(msg); } diff --git a/include/msksheet.h b/include/msksheet.h index 3dca846be..e3807614f 100755 --- a/include/msksheet.h +++ b/include/msksheet.h @@ -281,8 +281,7 @@ public: bool esporta() const; - bool error_box(const char * msg); - + virtual bool error_box(const char* fmt, ...) const; // @cmember Costruttore TSheet_field(TMask* m);