sheet.cpp Cambiato nome da get_focus_id in low_get_focus_id

stack.cpp   Corretto aggiornamento dello stack pointer
strings.*   Aggiunto nuovo tipo di get alle TToken_string


git-svn-id: svn://10.65.10.50/trunk@6588 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1998-05-04 08:12:15 +00:00
parent cc4fd2a9da
commit b86fbf2f4c
4 changed files with 191 additions and 55 deletions

View File

@ -1146,7 +1146,7 @@ void TSheet::on_idle()
{
if (_select_row >= 0)
{
const short focus_id = get_focus_id(win());
const short focus_id = low_get_focus_id(win());
_sheet->select(_select_row);
if (focus_id == _sheet->id())
_sheet->set_focus_rec(-1);

View File

@ -27,5 +27,6 @@ TObject& TStack::peek(int depth) const
bool TStack::destroy_base()
{
if (_sp > 0) _sp--;
return _data.destroy(0, TRUE);
}

View File

@ -4,8 +4,8 @@
#include <stdarg.h>
#include <strstrea.h>
#include <real.h>
#include <regexp.h>
#include <strings.h>
#include <utility.h>
// @doc EXTERNAL
@ -34,6 +34,8 @@ class TString512 : public TFixed_string
char _str512[513];
public:
char* get_buffer();
TString512() : TFixed_string(_str512, 513) { }
const TString& operator =(const char* s);
const TString& operator =(const TString& s) { return operator =((const char*)s); }
@ -45,6 +47,8 @@ public:
class TString512 : public TString
{
public:
char* get_buffer();
TString512() : TString(512) { }
const TString& operator =(const char* s);
const TString& operator =(const TString& s) { return operator =((const char*)s); }
@ -53,26 +57,36 @@ public:
#endif
const TString& TString512::operator =(const char* s)
{
#ifdef FOXPRO
char* TString512::get_buffer()
{
if (_size == 0)
{
#ifdef DBG
NFCHECK("Tentativo d'uso di una stringa statica non inizializzata.");
#endif
#ifdef FOXPRO
_str = _str512;
_size = 512;
}
#else
_str = new char[_size = 512];
#endif
}
return _str;
}
const TString& TString512::operator =(const char* s)
{
if (_size == 0)
get_buffer();
return set(s);
}
void TString512::strncpy(const char* s, int n)
{
#ifdef FOXPRO
if (_size == 0)
{
_str = _str512;
_size = 512;
}
get_buffer();
#ifdef FOXPRO
TFixed_string::strncpy(s, n);
#else
if (n > _size)
@ -82,7 +96,7 @@ void TString512::strncpy(const char* s, int n)
#endif
}
HIDDEN TString512 spark;
HIDDEN TString512 _spark;
inline bool is_space(char c)
{ return c >= '\t' && c <= ' '; }
@ -235,13 +249,13 @@ TString& TString::operator <<(double n)
// Appends an object to the string
// Certified 50%
// The object should be completely storable in spark
// The object should be completely storable in _spark
TString& TString::operator <<(const TObject& obj)
{
ostrstream out(spark.get_buffer(), spark.size());
ostrstream out(_spark.get_buffer(), _spark.size());
obj.print_on(out);
out << ends;
return operator <<(spark);
return operator <<(_spark);
}
@ -375,6 +389,17 @@ int TString::find(
return p ? int(p - _str) : -1;
}
int TString::rfind(
char c) const // @parm Carattere da cercare
// @syntax rfind(char c);
//
{
const char* p = strrchr(_str, c);
return p ? int(p - _str) : -1;
}
#if XVT_OS == XVT_OS_SCOUNIX
HIDDEN char* strstr(const char* string1, const char* string2)
@ -427,8 +452,8 @@ const TString& TString::left(
// @rdesc Ritorna l'indirizzo della stringa contenente i <p count> caratteri da sinistra
{
spark.strncpy(_str, count);
return spark;
_spark.strncpy(_str, count);
return _spark;
}
// Certified 99%
@ -442,8 +467,8 @@ const TString& TString::right(
{
int from = len()-count;
if (from < 0) from = 0;
spark = _str + from;
return spark;
_spark = _str + from;
return _spark;
}
@ -470,8 +495,8 @@ const TString& TString::mid(
if (from > l) from = l;
if (count < 0 || from+count>l)
count = l-from;
spark.strncpy(&_str[from], count);
return spark;
_spark.strncpy(&_str[from], count);
return _spark;
}
@ -567,7 +592,7 @@ TString& TString::rtrim(
int count) // @parm Indica il numero di caratteri da eliminare.
// Se uguale a 0 elimina tutti gli spazi da destra
// @comm Controlla se <p count> e' 0. Se non lo Š pone il fine stringa alla
// @comm Controlla se <p count> e' 0. Se non lo e' pone il fine stringa alla
// posizione <p count>; altrimenti controlla se gli ultimi caratteri
// sono spazi e li elimina fino a che non trova un carattere diverso da ' '
//
@ -627,6 +652,8 @@ int TString::compare(
bool ignorecase) const // @parm Ignorare la differenza maiuscolo/minuscolo (default FALSE)
{
int res;
if (s == NULL) s = "";
if (ignorecase)
{
if (max < 0)
@ -685,9 +712,9 @@ TString& TString::right_just(
{
if (n < 0) n = size();
trim();
spark = _str;
_spark = _str;
fill(c, n);
overwrite(spark, n-spark.len());
overwrite(_spark, n-_spark.len());
return *this;
}
@ -707,10 +734,10 @@ TString& TString::center_just(
{
if (n < 0) n = size();
trim();
spark = _str;
_spark = _str;
fill(c, n);
const int p = (n-spark.len()) >> 1;
overwrite(spark, p);
const int p = (n-_spark.len()) >> 1;
overwrite(_spark, p);
return *this;
}
@ -730,9 +757,9 @@ TString& TString::left_just(
{
if (n < 0) n = size();
trim();
spark = _str;
_spark = _str;
fill(c, n);
overwrite(spark, 0);
overwrite(_spark, 0);
return *this;
}
@ -762,7 +789,7 @@ TString& TString::picture(
return *this;
}
// Certified 90% (spark size limited)
// Certified 90% (_spark size limited)
// @doc EXTERNAL
// @mfunc Manda un output formattato alla stringa oggetto
@ -775,12 +802,12 @@ TString& TString::format(
{
va_list pars;
va_start(pars, fmt);
const int tot = vsprintf((char*)(const char*)spark, fmt, pars);
const int tot = vsprintf(_spark.get_buffer(), fmt, pars);
va_end(pars);
CHECK(tot >= 0 && tot < spark.size(), "Ue'! Quanto scrivi?");
CHECK(tot >= 0 && tot < _spark.size(), "Ue'! Quanto scrivi?");
if (tot > size()) resize(tot, FALSE);
strcpy(_str, spark);
strcpy(_str, _spark);
return *this;
}
@ -892,9 +919,9 @@ TString& TString::insert(
{
const int l = strlen(s);
make_room(l);
mid(pos); // Scrivi in spark la stringa da pos in poi
mid(pos); // Scrivi in _spark la stringa da pos in poi
overwrite(s, pos); // Aggiungi s
strcpy(&_str[pos+l], spark); // Aggiungi spark
strcpy(&_str[pos+l], _spark); // Aggiungi _spark
}
return *this;
}
@ -966,7 +993,7 @@ TString& TFixed_string::format(
// @comm Funziona come la funzione "sprintf" standard del C e ritorna la
// stringa formattata con i parametri passati.
// <nl>E' piu' efficiente di <mf TString::format> poiche' non usa spark
// <nl>E' piu' efficiente di <mf TString::format> poiche' non usa _spark
{
va_list pars;
va_start(pars, fmt);
@ -1019,8 +1046,8 @@ const char* TFilename::name() const
if (_str[i] == '/' || _str[i] == '\\' || _str[i] == ':')
break;
spark.strncpy(&_str[i+1], start-i);
return spark;
_spark.strncpy(&_str[i+1], start-i);
return _spark;
}
// Certified 95%
@ -1032,8 +1059,8 @@ const char* TFilename::path() const
for (int i = start; i >= 0; i--)
if (_str[i] == '/' || _str[i] == '\\' || _str[i] == ':')
break;
spark.strncpy(_str, i+1);
return spark;
_spark.strncpy(_str, i+1);
return _spark;
}
@ -1344,7 +1371,7 @@ const char* TToken_string::get()
// @mfunc Ritorna un Token
//
// @rdesc Ritorne la stringa identificata dal Token passato come parametro <p n>
// @rdesc Ritorna la stringa alla posizione <p n>
const char* TToken_string::get(
int n) // @parm Token da ritornare (0 = primo, -1 = prossimo, -2 = ultimo, n = n-simo)
@ -1377,13 +1404,13 @@ const char* TToken_string::get(
char* p = strchr(s, _separator);
if (p == NULL)
{
spark = s;
_spark = s;
_last = -1;
}
else
{
*p = '\0';
spark = s;
_spark = s;
*p = _separator;
_last = (int)((const char*)p - _str) + 1;
}
@ -1394,10 +1421,9 @@ const char* TToken_string::get(
return NULL;
}
return spark;
return _spark;
}
// Certified 99%
// @doc EXTERNAL
@ -1430,7 +1456,93 @@ long TToken_string::get_long(int n)
}
// Certified 70%
// const TToken_string new age!
// @rdesc Ritorna TRUE se e' stata trovata una stringa alla posizione <p n>
bool TToken_string::get(
int n, // @parm Posizione del token da ritornare (0 = primo, -1 = prossimo, -2 = ultimo, n = n-simo)
TString& tok) const // @parm Stringa da ritornare
// @syntax const char* get(TString& str, int n);
//
// @xref <mf TToken_string::get_char>
{
CHECK(_separator, "Corrupted TToken_string: NULL separator");
if (n < 0)
{
const char* sep = strrchr(_str, _separator);
tok = sep ? sep+1 : _str;
return tok.not_empty();
}
int sep = 0;
for (const char* s = _str; *s && sep < n; s++)
if (*s == _separator) sep++;
bool found = sep == n;
if (found)
{
char* p = strchr(s, _separator);
if (p == NULL)
{
tok = s;
found = tok.not_empty();
}
else
{
*p = '\0';
tok = s;
*p = _separator;
}
}
return found;
}
bool TToken_string::get(
int n, // @parm Posizione del token da ritornare (0 = primo, -1 = prossimo, -2 = ultimo, n = n-simo)
char& tok) const // @parm char da ritornare
{
TString16 str;
bool found = get(n, str);
tok = found ? str[0] : '\0';
return found;
}
bool TToken_string::get(
int n, // @parm Posizione del token da ritornare (0 = primo, -1 = prossimo, -2 = ultimo, n = n-simo)
int& tok) const // @parm int da ritornare
{
TString16 str;
bool found = get(n, str);
tok = found ? atoi(str) : 0;
return found;
}
bool TToken_string::get(
int n, // @parm Posizione del token da ritornare (0 = primo, -1 = prossimo, -2 = ultimo, n = n-simo)
long& tok) const // @parm long da ritornare
{
TString16 str;
bool found = get(n, str);
tok = found ? atol(str) : 0L;
return found;
}
bool TToken_string::get(
int n, // @parm Posizione del token da ritornare (0 = primo, -1 = prossimo, -2 = ultimo, n = n-simo)
real& tok) const // @parm real da ritornare
{
TString80 str;
bool found = get(n, str);
if (found)
tok = real(str);
else
tok = ZERO;
return found;
}
// Certified 90%
bool TToken_string::set_item(const char* v, int n)
{
CHECK(_separator, "Corrupted TToken_string: NULL separator");
@ -1450,9 +1562,9 @@ bool TToken_string::set_item(const char* v, int n)
int e = find(_separator, i);
if (e < 0) e = len();
spark = &_str[e]; // Salva items seguenti
_spark = &_str[e]; // Salva items seguenti
cut(i); // Considera solo items precedenti
*this << v << spark; // Aggiunge item desiderato e seguenti
*this << v << _spark; // Aggiunge item desiderato e seguenti
return TRUE;
}
@ -1476,17 +1588,15 @@ int TToken_string::get_pos(long n)
return get_pos(s);
}
// Certified 90%
bool TToken_string::empty_items() const
{
for (const char* c = _str; *c; c++)
if (!is_space(*c) && *c != _separator) return FALSE;
if (!is_space(*c) && *c != _separator)
return FALSE;
return TRUE;
}
// Certified 80%
int TToken_string::items() const
{
@ -1531,7 +1641,7 @@ void TToken_string::add(
if (_last < 0) _last = 0;
}
// Certified 0%
// Certified 100%
void TToken_string::add(char c, int pos)
{
const char s[2] = { c, '\0' };
@ -1547,6 +1657,8 @@ void TToken_string::add(long n, int pos)
add(s, pos);
}
// Adds an integer value to the token string
// Certified 100%
void TToken_string::add(int n, int pos)
{
char s[16];

View File

@ -97,8 +97,10 @@ public:
// @cmember Controlla se la stringa e' vuota o contiene solo whitespace (TRUE se vuota)
bool blank() const;
// @cmember Ritorna la posizione del carattere char nell'oggetto TString
// @cmember Ritorna la posizione della prima occorrenza carattere char nell'oggetto TString
int find(char, int from = 0) const;
// @cmember Ritorna la posizione dell'ultima occorrenza carattere char nell'oggetto TString
int rfind(char) const;
// @cmember Ritorna la posizione della stringa s nell'oggetto TString
int find(const char* s, int from = 0) const;
// @cmember Sostituisce le occorrenze di <p find_char> col carattere <p replace_char>
@ -435,6 +437,8 @@ public:
const TFilename& tempdir();
};
// Forward declaration for TToken_string::get(int n, real& r) const
class real;
// @doc EXTERNAL
@ -494,6 +498,7 @@ public:
void add(int n, int pos = -1);
// @cmember Toglie la stringa di posizione pos
void destroy(int pos);
// @cmember Ritorna il prossimo token
const char* get();
// @cmember Ritorna un token
@ -504,6 +509,19 @@ public:
int get_int(int n = -1);
// @cmember Ritorna un intero esteso (chiama <mf TToken_string::get>)
long get_long(int n = -1);
// TToken_string new age: const methods;
// @cmember Ritorna l'ennesimo token
bool get(int n, TString& tok) const;
// @cmember Ritorna l'ennesimo char
bool get(int n, char& tok) const;
// @cmember Ritorna l'ennesimo int
bool get(int n, int& tok) const;
// @cmember Ritorna l'ennesimo long
bool get(int n, long& tok) const;
// @cmember Ritorna l'ennesimo real
bool get(int n, real& tok) const;
// @cmember Ritorna la posizione dell'item s
int get_pos(const char* s);
// @cmember Ritorna la posizione dell'item s
@ -514,9 +532,14 @@ public:
bool empty_items() const;
};
#define FOR_EACH_TOKEN(__tok, __str) \
#define FOR_EACH_TOKEN(__tok, __str) \
for (const char* __str = __tok.get(0); __str; __str = __tok.get())
#define FOR_EACH_TOKEN_STRING(__tok, __count, __str) \
TString __str; \
for (int __count = 0; __tok.get(__count, __str); __count++)
///////////////////////////////////////////////////////////
// DES Paragraph
///////////////////////////////////////////////////////////