Patch level : 4.0

Files correlati     :
Ricompilazione Demo : [ ]
Commento            :
Corretta e migliorata gestione campi read only


git-svn-id: svn://10.65.10.50/trunk@15195 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2007-04-06 14:46:40 +00:00
parent af7b085f90
commit 238527b5ba
9 changed files with 223 additions and 229 deletions

View File

@ -163,10 +163,10 @@ HIDDEN void paint_background(WINDOW win)
if (ADVANCED_GRAPHICS)
{ // Disegna ombra
const int k = max(BIGY/24, 1);
xvt_dwin_set_fore_color(win, DISABLED_COLOR);
xvt_dwin_set_fore_color(win, MASK_LIGHT_COLOR);
xvt_dwin_draw_text(win, x+k, y+k, t, -1);
}
xvt_dwin_set_fore_color(win, NORMAL_COLOR);
xvt_dwin_set_fore_color(win, MASK_DARK_COLOR);
xvt_dwin_draw_text(win, x, y, t, -1);
xvtil_set_font(win, NULL, XVT_FS_NONE);

View File

@ -1002,6 +1002,7 @@ unsigned long TControl::flags2attr(const char* flags) const
case 'C': attrib |= XI_ATR_HCENTER; break;
case 'D': attrib &= ~XI_ATR_ENABLED; break;
case 'H': attrib &= ~XI_ATR_VISIBLE; break;
case 'L': attrib |= XI_ATR_READONLY; break;
case 'R': attrib |= XI_ATR_RJUST; break;
default : break;
}
@ -1348,8 +1349,8 @@ void TField_control::create(WINDOW win, short cid,
short left, short top, short width, short height, short maxlen,
const char* flags, const char* text, bool button)
{
CHECK(!in_create, "Nested control creation");
in_create = true;
const short fcid = cid > 0 ? cid + 2000 : cid - 2000;
XI_OBJ_DEF* frm_def = xi_add_form_def(NULL, fcid, fcid);
frm_def->app_data = (long)this;
@ -2242,7 +2243,7 @@ bool TDropDownList::select(int i, bool force)
{
if (_open) xi_set_text(_obj, ""); // Altrimenti a volte ridisegna male!
xi_set_text(_obj, (char*)_values.get(i));
TListbox_control* listbox = (TListbox_control *)xi_get_app_data(_obj);
TListbox_control* listbox = (TListbox_control*)xi_get_app_data(_obj);
listbox->notify_key(K_SPACE);
}
else

View File

@ -1,11 +1,8 @@
#include <defmask.h>
#include <form.h>
#include <msksheet.h>
#include <printer.h>
#ifndef __DEFMASK_H
#include <defmask.h>
#endif
#include "../ba/bafrm.h"
// per lo sheet di edit campi
@ -628,8 +625,8 @@ void TPrint_section::print_on(TRectype& prof)
typedef struct
{
char name_1[80]; // Fontname old
char name_2[80]; // Fontname new
TString80 name_1; // Fontname old
TString80 name_2; // Fontname new
int size_1; // size (height) of old font
int size_2; // size (height) of new font
real ratio; // ratio (width_old_font/width_new_font)
@ -642,9 +639,9 @@ BOOLEAN wpr(long data)
long width_old,width_new;
TString spc(128, 'm');
xvtil_set_font(prwin,st->name_1, XVT_FS_NONE, st->size_1);
width_old = xvt_dwin_get_text_width(prwin,(char*)(const char*)spc, 128);
width_old = xvt_dwin_get_text_width(prwin, spc, spc.len());
xvtil_set_font(prwin,st->name_2, XVT_FS_NONE, st->size_2);
width_new = xvt_dwin_get_text_width(prwin,(char*)(const char*)spc, 128);
width_new = xvt_dwin_get_text_width(prwin,spc, spc.len());
st->ratio = (double)width_old / (double)width_new;
xvt_vobj_destroy(prwin);
@ -672,9 +669,9 @@ bool TPrint_section::repos_fields(const char* name, int size)
rt = TRUE;
s_data prm;
prm.size_1=ps.form().fontsize();
strcpy(prm.name_1,ps.form().fontname());
prm.name_1 = ps.form().fontname();
prm.size_2=size;
strcpy(prm.name_2,name);
prm.name_2 = name;
prm.ratio = 1.0;
// Next 3 lines may be changed
xvt_print_open();

View File

@ -6,10 +6,13 @@
#include <diction.h>
#include <msksheet.h>
#include <prefix.h>
#include <recarray.h>
#include <relation.h>
#include <urldefid.h>
#include <utility.h>
#include <user.h>
#define DLG_PAGETAGS 31000
HIDDEN const char* const MASK_EXT = "msk";
@ -99,26 +102,39 @@ TMask::TMask(const char* title, int pages, int cols, int rows,
cols, rows, title, this, pages > 1);
}
void TMask::set_locking(TBit_array & read_only, TToken_string & fields, bool on)
void TMask::set_locking(TBit_array& read_only, TToken_string& list, bool on)
{
FOR_EACH_TOKEN(fields, fld)
{
short id = 0;
if (real::is_natural(fld))
id = atoi(fld);
else
{
TMask_field * f = find_by_fieldname(fld);
if (f != NULL)
id = f->dlg();
}
if (id > 0)
{
const int pos = id2pos(id);
if (pos >= 0)
read_only.set(pos, on);
}
if (list.find('*') >= 0)
{
if (on)
{
read_only.set(fields());
read_only.set();
}
else
read_only.reset();
}
else
{
FOR_EACH_TOKEN(list, fld)
{
const TFixed_string id(fld);
if (id[0] == '-' || id.ends_with("@")) // Gestione gruppi
{
const int grp = abs(atoi(fld));
FOR_EACH_MASK_FIELD((*this), pos, f)
{
if (f->in_group(grp))
read_only.set(pos, on);
}
}
else
{
const int pos = field2pos(fld);
if (pos >= 0)
read_only.set(pos, on);
}
}
}
}
@ -191,33 +207,43 @@ void TMask::read_mask(
TFilename prof;
if (make_profile_name(prof))
{
// Costruisce la lista dei gruppi di appartenenza dell'utente
TString_array users_and_groups;
for (TString u = user(); u.full(); u = cache().get(LF_USER, u, USR_GROUPNAME))
users_and_groups.add(u);
TConfig ini(prof);
TString16 para(user()); para << "_Locks";
if (ini.set_paragraph(para))
{
const int items = fields();
TBit_array read_only(items);
TAuto_token_string fields(ini.get("Lock"));
if (fields == "*")
read_only.set();
else
set_locking(read_only, fields);
fields = ini.get("Unlock");
set_locking(read_only, fields, false);
FOR_EACH_ARRAY_ROW_BACK(users_and_groups, c, utonto)
{
*utonto << "_Locks";
if (ini.set_paragraph(*utonto))
{
TBit_array read_only;
TAuto_token_string lfields(ini.get("Lock"));
TAuto_token_string ufields(ini.get("Unlock"));
if (ufields.find("*")>=0)
{
set_locking(read_only, lfields, true);
}
else
{
set_locking(read_only, lfields, true);
set_locking(read_only, ufields, false);
}
for (int j = 0; j < items; j++) if (read_only[j])
{
TMask_field& f = fld(j);
if (f.is_loadable())
f.set_read_only(true);
}
FOR_EACH_MASK_FIELD((*this), j, f)
{
if (f->is_loadable())
{
const bool ro = read_only[j];
if (f->read_only() != ro)
f->set_read_only(ro);
}
}
}
}
}
}
}
}
}
void TMask::add_field(TMask_field* f)
@ -608,16 +634,32 @@ TMask_field& TMask::field(short id) const
return fld(pos);
}
TMask_field* TMask::find_by_fieldname(const char* fieldname) const
int TMask::field2pos(const char* fieldname) const
{
for (int i = fields()-1; i >= 0; i--)
const int id = atoi(fieldname);
int i;
for (i = fields()-1; i >= 0; i--)
{
TMask_field& f = fld(i);
const TFieldref* fr = f.field();
if (fr && fr->name() == fieldname)
return &f;
if (id == 0)
{
const TFieldref* fr = f.field();
if (fr != NULL && fr->name() == fieldname)
break;
}
else
{
if (f.dlg() == id)
break;
}
}
return NULL;
return i;
}
TMask_field* TMask::find_by_fieldname(const char* fieldname) const
{
const int i = field2pos(fieldname);
return i >= 0 ? &fld(i) : NULL;
}
TEdit_field& TMask::efield(short id) const
@ -1520,43 +1562,29 @@ void TMask::show_default(
} else field(fld_id).show_default();
}
void TMask::autoload(const TRelation& r)
{
const int max = fields();
for (int i = 0; i < max; i++)
{
TMask_field& f = fld(i);
if (f.is_loadable())
((TLoadable_field&)f).autoload(r);
}
FOR_EACH_MASK_FIELD((*this), i, f) if (f->is_loadable())
((TLoadable_field*)f)->autoload(r);
}
void TMask::autosave(TRelation& r) const
{
const int max = fields();
for (int i = 0; i < max; i++)
FOR_EACH_MASK_FIELD((*this), i, f) if (f->is_loadable())
{
TMask_field& f = fld(i);
if (f.is_loadable())
bool save = f->shown();
if (!save && f->is_editable())
{
TLoadable_field& l = (TLoadable_field&)f;
bool save = f.shown();
if (!save && f.is_editable())
// tenta di effettuare il save dei campi Edit hidden:
// salva il nuovo valore solo se il precedente era blank
if (f->field() != NULL)
{
// tenta di effettuare il save dei campi Edit hidden:
// salva il nuovo valore solo se il precedente era blank
TEditable_field& e = (TEditable_field&)f;
if (e.field() != NULL)
{
const char* str = l.field()->read(r);
save = *str == '\0';
}
}
if (save)
l.autosave(r);
const char* str = f->field()->read(r);
save = *str == '\0';
}
}
if (save)
((TLoadable_field*)f)->autosave(r);
}
}
@ -2127,10 +2155,15 @@ void TMask::copy_values(
bool TMask::make_profile_name(TFilename& f) const
{
f =::firm2dir(-1); // Directory dati
f.add("config"); // Directory config
f.add(source_file().name()); // Nome Maschera
f.ext("ini"); // Estensione
f = source_file().name();
f.ext("ini");
if (!f.custom_path()) // Prova a cercare la configurazione in custom ...
{ // ... altrimenti riprova in config
f =::firm2dir(-1); // Directory dati
f.add("config"); // Directory config
f.add(source_file().name()); // Nome Maschera
f.ext("ini"); // Estensione
}
return f.exist();
}

View File

@ -151,7 +151,7 @@ public:
virtual ~TMask();
// @cmember Imposta i bit di read_only
void set_locking(TBit_array & read_only, TToken_string & fields, bool on = true);
void set_locking(TBit_array & read_only, TToken_string & fields, bool on);
// @cmember Legge la maschera da file
void read_mask(const char* name, int num, int max);
@ -255,6 +255,8 @@ public:
// @cmember Converte un identificatore di campo nella sua posizione
int id2pos(short id) const;
// @cmember Cerca la posizione di un campo per nome
int field2pos(const char* fieldname) const;
// @cmember Ritorna il campo i-esimo della maschera
TMask_field& fld(int i) const
{ return (TMask_field&)_field[i]; }

View File

@ -12,14 +12,12 @@
#include <recset.h>
#include <relapp.h>
#include <sheet.h>
#include <tabutil.h>
#include <text.h>
#include <urldefid.h>
#include <utility.h>
#include <validate.h>
#include <virtkeyb.h>
#include <xvtility.h>
#include <nditte.h>
// @doc INTERNAL
@ -95,7 +93,7 @@ char TMask_field::TField_Flags::update(const char* f, bool reset)
case 'I':
break; // reserved for sheetfield insert
case 'L':
read_only = reset; break;
read_only = !reset; break;
case 'M':
roman = !reset; break;
case 'P':
@ -142,7 +140,8 @@ void TMask_field::update_flags(const char* f, bool reset)
{
_flags.update(f, reset);
show(shown());
enable(enabled());
enable(enabled());
set_read_only(read_only());
}
TMask_field::TMask_field(TMask* m)
@ -1715,22 +1714,20 @@ bool TBoolean_field::on_key(KEY key)
{
switch (key)
{
case K_SPACE:
get_window_data();
set_dirty();
on_hit();
return TRUE;
break;
case K_F2:
if (!read_only())
{
set("");
set_dirty();
}
return TRUE;
break;
default:
return TEditable_field::on_key(key);
case K_SPACE:
get_window_data();
set_dirty();
on_hit();
return TRUE;
case K_F2:
if (!read_only())
{
set("");
set_dirty();
}
return TRUE;
default:
return TEditable_field::on_key(key);
}
return FALSE;
}
@ -3174,32 +3171,23 @@ bool TEdit_field::parse_item(TScanner& scanner)
int key = 1;
TRelation* r = NULL;
const int logicnum = scanner.integer();
TString16 tabmaskname;
TString16 tablename = scanner.pop();
const int logicnum = table2logic(tablename);
if (logicnum > 0)
{
TDir d; d.get(logicnum);
if (fexist(d.filename())) // Controlla l'esistenza del file
r = new TRelation(logicnum);
#ifdef DBG
else
yesnofatal_box("Impossibile creare una USE sul file %s",d.filename());
#endif
}
else
{
tabmaskname = scanner.pop();
#ifdef DBG
if (tabmaskname.len() > 4)
return yesnofatal_box("'%s' non e' una tabella valida: %d",
(const char*)tabmaskname, dlg());
#endif
TDir d; d.get(TTable::name2log(tabmaskname));
if (fexist(d.filename())) // Controlla l'esistenza del file
r = new TRelation(tabmaskname);
{
if (logicnum >= LF_TABGEN && logicnum <= LF_TAB)
r = new TRelation(tablename);
else
r = new TRelation(logicnum);
}
}
else
error_box("Il campo %d usa il file o tabella non valida %s",
dlg(), (const char*)tablename);
if (scanner.popkey() == "KE")
{
@ -3234,10 +3222,10 @@ bool TEdit_field::parse_item(TScanner& scanner)
}
scanner.push();
if (tabmaskname.not_empty())
if (tablename.not_empty())
{
tabmaskname.insert("MTB", 0);
browse()->set_insert(tabmaskname);
tablename.insert("MTB", 0);
browse()->set_insert(tablename);
}
_check_enabled = TRUE;
}
@ -3451,12 +3439,10 @@ void TEdit_field::set_read_only(bool r)
}
}
// Filtro magico sulle ditte esistenti
HIDDEN bool firm_filter(const TRelation* rel)
{
const long firm = rel->curr().get_long("CODDITTA");
const long firm = rel->curr().get_long(NDT_CODDITTA);
return prefix().exist(firm);
}

View File

@ -23,8 +23,8 @@ word TIndwin::measure_text(TToken_string& s, word& maxlen) const
// Certified 70%
TIndwin::TIndwin(long tot, const char* txt, bool cancel, bool bar, int div)
: _text(NULL), _cancel(NULL),
_bar(0), _flags(0x0), _max(tot), _status(0L)
: _text(NULL), _cancel(NULL), _gauge(NULL_WIN), _bar(0),
_flags(0x0), _max(tot), _status(0L)
{
TToken_string testo(txt, '\n');
word maxlen = div;
@ -43,8 +43,15 @@ TIndwin::TIndwin(long tot, const char* txt, bool cancel, bool bar, int div)
if (bar)
{
RCT r; _text->get_rect(r);
WIN_DEF wd; memset(&wd, 0, sizeof(wd));
wd.wtype = WC_HGAUGE;
RCT& r = wd.rct;
_text->get_rect(r);
_bar = r.bottom + CHARY;
get_bar_rct(r);
_gauge = xvt_ctl_create_def(&wd, win(), tot);
}
if (cancel)
@ -75,17 +82,13 @@ void TIndwin::set_text(
testo.replace('\n', '\r');
_text->set_caption(testo);
#endif
if (_bar)
{
RCT r; get_bar_rct(r);
xvt_dwin_invalidate_rect(win(), &r);
}
}
void TIndwin::setmax(long m)
{
_max = m <= 0 ? 1 : m;
if (_gauge)
xvt_sbar_set_range(_gauge, HVGAUGE, 0, _max);
_start_time = clock();
}
@ -143,86 +146,60 @@ void TIndwin::update_bar()
_status = _max;
_flags |= IND_FINISHED;
}
// Percentuale raggiunta finora
const double prc = (double)_status / (double)_max;
// Rettangolo contenente l'intera barra
RCT r; get_bar_rct(r);
set_font();
if (ADVANCED_GRAPHICS)
if (prc > 0)
{
const WINDOW w = win();
RCT b = r;
// Rettangolo scavato
const int thick = 1;
xi_draw_3d_rect((XinWindow)w, (XinRect*)&b, TRUE, thick,
MASK_LIGHT_COLOR, MASK_BACK_COLOR, MASK_DARK_COLOR);
xvt_rect_inflate(&b, -thick, -thick);
b.right = b.left + int((b.right-b.left)*prc + 0.5);
const unsigned long elapsed_time = (clock() - _start_time)/CLOCKS_PER_SEC;
const unsigned long total_time = (unsigned long)(elapsed_time / prc + 0.5);
TString8 str_res, str_tot;
sec2str(total_time - elapsed_time, str_res);
sec2str(total_time, str_tot);
const int lasti = (b.bottom-b.top)/2;
for (int i = 0; i <= lasti; i++)
{
const short cy = b.top + (b.bottom-b.top)/4;
RCT g = b; g.bottom = cy;
xvt_dwin_draw_gradient_linear(w, &g, BTN_LIGHT_COLOR, BTN_BACK_COLOR, 90);
g = b; g.top = cy;
xvt_dwin_draw_gradient_linear(w, &g, BTN_DARK_COLOR, BTN_LIGHT_COLOR, 90);
}
TString80 n;
n.format("%d%% - %s %s - %s %s", int(prc*100.0+0.5),
TR("Tempo residuo"), str_res.get_buffer(),
TR("Tempo totale"), str_tot.get_buffer());
RCT b; get_bar_rct(b);
b.top = b.bottom+2; b.bottom = b.top + CHARY;
if (prc > 0)
{
const unsigned long elapsed_time = (clock() - _start_time)/CLOCKS_PER_SEC;
const unsigned long total_time = (unsigned long)(elapsed_time / prc + 0.5);
TString8 str_res, str_tot;
sec2str(total_time - elapsed_time, str_res);
sec2str(total_time, str_tot);
TString80 n;
n.format("%d%% - %s %s - %s %s", int(prc*100.0+0.5),
TR("Tempo residuo"), str_res.get_buffer(),
TR("Tempo totale"), str_tot.get_buffer());
b = r;
b.top = b.bottom+2;
b.bottom = b.top + CHARY;
CBRUSH brush; brush.pat = PAT_SOLID; brush.color = MASK_BACK_COLOR;
xvt_dwin_set_cbrush(w, &brush);
xvt_dwin_set_std_cpen(w, TL_PEN_HOLLOW);
xvt_dwin_draw_rect(w, &b);
xvt_dwin_set_clip(w, NULL);
set_color(NORMAL_COLOR, MASK_BACK_COLOR);
set_opaque_text(TRUE);
xvt_dwin_draw_text(w, r.left, r.bottom+CHARY-1, n, -1);
}
WINDOW w = win();
CBRUSH brush; brush.pat = PAT_SOLID; brush.color = MASK_BACK_COLOR;
xvt_dwin_set_cbrush(w, &brush);
xvt_dwin_set_std_cpen(w, TL_PEN_HOLLOW);
xvt_dwin_draw_rect(w, &b);
xvt_dwin_set_clip(w, NULL);
set_color(NORMAL_COLOR, MASK_BACK_COLOR);
set_opaque_text(TRUE);
set_font();
xvt_dwin_draw_text(w, b.left, b.bottom-1, n, -1);
}
else
{
// Rettangolo in rilievo
RCT b = r;
b.right = b.left + int((r.right-r.left)*prc);
xi_draw_3d_rect((XinWindow)win(), (XinRect*)&b, FALSE, 2,
BTN_LIGHT_COLOR, BTN_BACK_COLOR, BTN_DARK_COLOR);
// Rettangolo scavato
b.left = b.right; b.right = r.right;
xi_draw_3d_rect((XinWindow)win(), (XinRect*)&b, TRUE, 2,
BTN_LIGHT_COLOR, BTN_BACK_COLOR, BTN_DARK_COLOR);
char n[8]; sprintf(n, "%d%%", int(prc * 100.0 + 0.5));
xvt_dwin_draw_text(win(), r.left+r.right/2-CHARX, (r.bottom+r.top+CHARY)/2-3, n, -1);
}
check_stop();
}
void TIndwin::update()
{
if (_bar)
if (_gauge != NULL_WIN)
update_bar();
}
bool TIndwin::setstatus(long l)
{
if (l < 0)
{
NFCHECK("Negative progind status");
l = 0;
}
_status = l > _max ? _max : l;
if (_gauge != NULL_WIN)
xvt_sbar_set_pos(_gauge, HVGAUGE, _status);
return !iscancelled();
}
bool TIndwin::on_key(KEY k)
{
if (k == K_ESC && _cancel)
@ -248,22 +225,16 @@ TProgind::TProgind(long max, const char* txt, bool cancel, bool bar, int div)
bool TProgind::setstatus(long l)
{
if (l < 0)
{
NFCHECK("Negative progind status");
l = 0;
}
_status = l > _max ? _max : l;
if (clock() > _next_update)
const bool ok = TIndwin::setstatus(l);
if (ok && clock() > _next_update)
{
update();
do_events();
_next_update = clock()+CLOCKS_PER_SEC; // Prossimo aggiornamento tra un secondo
}
return !iscancelled();
return ok;
}
// TTimerind ------------------------------------------------------------

View File

@ -33,6 +33,7 @@ class TIndwin : public TWindow
// @cmember:(INTERNAL) Bottone "Annulla"
TControl* _cancel;
// @cmember:(INTERNAL) Movimento della barra e percentuale
WINDOW _gauge;
int _bar;
// @cmember:(INTERNAL) ora inizio elaborazione
unsigned long _start_time;
@ -92,6 +93,8 @@ public:
// @cmember Setta il valore massimo della barra d'attesa
void setmax(long m);
virtual bool setstatus(long l);
// @cmember Costruttore
TIndwin(long max, const char* txt, bool cancel = TRUE, bool bar = TRUE, int div = 60);
// @cmember Distruttore
@ -111,7 +114,7 @@ class TProgind : public TIndwin
// @access Public Member
public:
// @cmember Setta lo stato della barra d'attesa
bool setstatus(long l);
virtual bool setstatus(long l);
// @cmember Aggiorna la barra d'attesa aggiungendo l'incremento fatto dell'applicazione
bool addstatus(long l)
{ return setstatus(_status+l); }

View File

@ -1,5 +1,6 @@
#define USR_USERNAME "USERNAME"
#define USR_USERDESC "USERDESC"
#define USR_GROUPNAME "GROUPNAME"
#define USR_PASSWORD "PASSWORD"
#define USR_DATAPWD "DATAPWD"
#define USR_ISGROUP "ISGROUP"