Aggiunta gestione DDE nei golem

Aggiunti campi memo alle maschere
Aggiunto metodo on_idle alle finestre


git-svn-id: svn://10.65.10.50/trunk@1484 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1995-06-19 08:13:19 +00:00
parent 1145d25263
commit 42adacd51a
15 changed files with 367 additions and 51 deletions

View File

@ -35,6 +35,7 @@
#define CLASS_BUTTON_FIELD 27
#define CLASS_SHEET_FIELD 28
#define CLASS_BROWSEFILE_FIELD 29
#define CLASS_MEMO_FIELD 30
#define CLASS_GOLEM 200

View File

@ -1,3 +1,4 @@
#include <io.h>
#include <stdlib.h>
#include <xvt.h>
@ -116,6 +117,8 @@ void TConfig::_write_file()
if (_file[0] > 'B' || _file[1] != ':') // Non creare il .bak su dischetto
{
while (access(_file, 02) != 0)
message_box("Il file %s e' gia' in uso", (const char*)_file);
TFilename bak(_file); bak.ext("bak");
rename(_file, bak);
}

View File

@ -1,3 +1,4 @@
#include <applicat.h>
#include <config.h>
#include <execp.h>
#include <golem.h>
@ -203,3 +204,88 @@ bool TGolem::import()
return ok == FL_OK;
}
#if XVT_OS == XVT_OS_WIN
#define STRICT
#include <windows.h>
#include <dde.h>
///////////////////////////////////////////////////////////
// DDE
///////////////////////////////////////////////////////////
static TDDE* DDEWIN = NULL;
HIDDEN BOOLEAN hook(HWND hwnd,
UINT msg,
UINT wparam,
ULONG lparam,
long* ret)
{
switch (msg)
{
case WM_DDE_ACK:
DDEWIN->set_server(wparam);
GlobalDeleteAtom(LOWORD(lparam));
GlobalDeleteAtom(HIWORD(lparam));
*ret = TRUE;
break;
default:
break;
}
return TRUE;
}
TDDE::TDDE()
: _old_hook(NULL), _server(0)
{
CHECK(DDEWIN == NULL, "Non puoi lanciare due DDE, bestia!");
create(0, 0, 0, 0, "DDE", WSF_INVISIBLE, W_PLAIN, NULL_WIN);
_hwnd = (word)xvt_vobj_get_attr(win(), ATTR_NATIVE_WINDOW);
DDEWIN = this;
}
TDDE::~TDDE()
{
terminate();
DDEWIN = NULL;
}
bool TDDE::initiate(const char* app, const char* topic)
{
CHECK(_old_hook == NULL, "Non puoi iniziare due connessioni DDE");
_old_hook = xvt_vobj_get_attr(NULL_WIN, ATTR_EVENT_HOOK);
xvt_vobj_set_attr(NULL_WIN, ATTR_EVENT_HOOK, (long)hook);
_server = 0;
ATOM a_app = GlobalAddAtom(app);
ATOM a_topic = GlobalAddAtom(topic);
SendMessage(HWND_BROADCAST, WM_DDE_INITIATE, (WORD)_hwnd, MAKELPARAM(a_app, a_topic));
GlobalDeleteAtom(a_app);
GlobalDeleteAtom(a_topic);
return _server != 0;
}
bool TDDE::execute(const char* cmd) const
{
HGLOBAL hg = GlobalAlloc(GMEM_DDESHARE, strlen(cmd)+1);
char* c = (char*)GlobalLock(hg);
strcpy(c, cmd);
GlobalUnlock(hg);
return PostMessage((HWND)_server, WM_DDE_EXECUTE, (WORD)_hwnd, MAKELPARAM(0, hg));
}
void TDDE::terminate()
{
if (_old_hook)
{
xvt_vobj_set_attr(NULL_WIN, ATTR_EVENT_HOOK, _old_hook);
_old_hook = NULL;
PostMessage((HWND)_server, (WORD)_hwnd, WM_DDE_TERMINATE, 0L);
}
}
#endif

View File

@ -1,8 +1,8 @@
#ifndef __GOLEM_H
#define __GOLEM_H
#ifndef __STRINGS_H
#include <strings.h>
#ifndef __WINDOW_H
#include <window.h>
#endif
#ifndef __CONFIG_H
@ -50,4 +50,21 @@ public:
virtual ~TGolem();
};
class TDDE : public TWindow
{
word _hwnd;
word _server;
long _old_hook;
public:
void set_server(word s) { _server = s; }
bool initiate(const char* app, const char* topic);
bool execute(const char* cmd) const;
void terminate();
TDDE();
virtual ~TDDE();
};
#endif

View File

@ -128,6 +128,7 @@ void TMask::handler(WINDOW win, EVENT* ep)
xvt_draw_rect(win, r, MASK_LIGHT_COLOR, MASK_DARK_COLOR, 1);
}
else xvt_dwin_clear(win, MASK_DARK_COLOR);
xvt_tx_process_event(win, ep);
#else
xvt_dwin_clear(win, MASK_BACK_COLOR);
#endif
@ -145,11 +146,9 @@ void TMask::handler(WINDOW win, EVENT* ep)
stop_run(K_AUTO_ENTER);
break;
case DLG_CANCEL :
// if (test_focus_change(ep->v.ctl.ci.win))
stop_run(K_ESC);
break;
case DLG_QUIT :
// if (test_focus_change(ep->v.ctl.ci.win))
stop_run(K_FORCE_CLOSE);
break;
case DLG_F9:
@ -166,7 +165,22 @@ void TMask::handler(WINDOW win, EVENT* ep)
break;
}
break;
default:
default:
if (_focus >= 0 && _focus < fields() && fld(_focus).class_id() == CLASS_MEMO_FIELD)
{
bool ok = TRUE;
if (ep->type == E_CHAR)
{
const KEY k = e_char_to_key(ep);
ok = k != K_TAB && k != K_BTAB;
if (ok) fld(_focus).set_dirty();
}
if (ok)
{
ok = xvt_tx_process_event(win, ep) == TRUE;
if (ok) return;
}
}
break;
}
TWindow::handler(win, ep);
@ -516,23 +530,20 @@ bool TMask::check_fields()
void TMask::get_mask_fields()
{
TString256 window_data;
for (int i = 0; i < fields(); i++)
{
TMask_field& f = fld(i);
const int acqua = f.class_id();
if (acqua != CLASS_FIELD && acqua != CLASS_BUTTON_FIELD && acqua != CLASS_SHEET_FIELD)
const char* fd = f.get_field_data();
if (fd != NULL) // NULL per testi fissi, bottoni e sheets
{
window_data = f.get_window_data();
const char* wd = f.get_window_data();
CHECKD(wd, "NULL window data in field ", f.dlg());
if (f.dirty() == TRUE)
{
const char* fd = f.get_field_data();
CHECK(fd, "NULL pointer comparison");
if (window_data == fd)
if (strcmp(wd, fd) == 0)
f.set_dirty(FALSE);
}
f.set_field_data(window_data);
f.set_field_data(wd);
}
}
}
@ -848,7 +859,7 @@ TMask_field* TMask::parse_field(TScanner& scanner)
return new TSheet_field(this);
}
if (scanner.key() == "BR") return new TBrowsefile_field(this);
if (scanner.key() == "ME") return new TMemo_field(this);
return NULL;
}
@ -1220,6 +1231,20 @@ void TMask::on_firm_change()
}
void TMask::on_idle()
{
if (_focus >= 0 && _focus < fields())
{
const word acqua = fld(_focus).class_id();
if (acqua == CLASS_SHEET_FIELD)
{
TSheet_field& s = (TSheet_field&)fld(_focus);
s.on_idle();
}
}
}
void TMask::send_key(KEY key, short to, TMask_field* from)
{
if (to == 0)
@ -1329,6 +1354,15 @@ WINDOW TMask::add_radio(short id, int page, const char* prompt, int x,
return ((TMask_field*)f)->win();
}
WINDOW TMask::add_memo(short id, int page, const char* prompt, int x, int y,
int dx, int dy, const char* flags)
{
TMemo_field* f = new TMemo_field(this);
f->construct(id, prompt, x, y, dy, _pagewin[page], flags, dx);
_field.add(f);
return ((TMask_field*)f)->win();
}
bool TMask::save(bool append) const
{
@ -1406,3 +1440,5 @@ void TMask::set_exchange(bool show_value, const real& n)
_exchange = nuo; // Update current exchange
main_app().end_wait();
}

View File

@ -112,6 +112,8 @@ public:
int dx = 9, int dy = 1, const char* flags = "");
WINDOW add_radio(short id, int page, const char* prompt, int x, int y,
int dx, const char* codes, const char* items, const char* flags = "");
WINDOW add_memo (short id, int page, const char* prompt, int x, int y,
int dx = 78, int dy = 4, const char* flags = "");
int fields() const { return _field.items(); }
int sheets() const { return _sheets; }
@ -152,6 +154,7 @@ public:
void disable_starting_check() { _should_check = FALSE;}
virtual bool on_key(KEY key);
virtual void on_idle();
void on_firm_change();
void enable(short fld_id, bool on = TRUE); // Abilita un campo

View File

@ -1,6 +1,7 @@
#include <xvt.h>
#include <applicat.h>
#include <colors.h>
#include <defmask.h>
#include <execp.h>
#include <golem.h>
@ -441,6 +442,14 @@ const char* TMask_field::prompt() const
return _prompt;
}
// Certified 90%
void TMask_field::set_field(const TString& fr)
{
if (_field != NULL)
*_field = fr;
else
_field = new TFieldref(fr, 0);
}
// Certified 100%
void TMask_field::reset()
@ -2531,7 +2540,8 @@ const char* TDate_field::format_data(const char* datum, bool* ch)
changed = TRUE;
}
else
if (data == "OGGI") changed = TRUE;
if (data == "OGGI")
changed = TRUE;
if (changed) data = gstring;
}
}
@ -3238,10 +3248,126 @@ void TGroup_field::create(WINDOW parent)
wincreate(WC_GROUPBOX, _width, _size, _prompt, parent, f);
}
void TGroup_field::set_window_data(const char* data)
{ xvt_set_title(win(), data); }
void TGroup_field::set_field_data(const char* data)
{ xvt_set_title(win(), data); }
///////////////////////////////////////////////////////////
// TMemo_field
///////////////////////////////////////////////////////////
TMemo_field::TMemo_field(TMask* mask) : TMask_field(mask), _te(BAD_TXEDIT)
{}
TMemo_field::~TMemo_field()
{
_te = BAD_TXEDIT;
}
void TMemo_field::parse_head(TScanner& scanner)
{
_width = scanner.integer();
_size = scanner.integer();
}
void TMemo_field::create(WINDOW parent)
{
const short dx = _width;
const short dy = _size-1;
TMask_field::create(parent);
WIN_DEF wd;
wd.wtype = WO_TE;
wd.rct = resize_rect(_x, _y+1, dx, dy, WC_EDIT, parent);
wd.text = NULL;
wd.units = U_PIXELS;
wd.v.tx.attrib = TX_NOMENU | TX_BORDER | TX_AUTOHSCROLL | TX_AUTOVSCROLL;
wd.v.tx.font_id = xvt_dwin_get_font(win());
wd.v.tx.margin = wd.rct.right - wd.rct.left;
wd.v.tx.limit = 256;
wd.v.tx.tx_id = dlg();
_te = xvt_tx_create_def(&wd, parent, NULL);
CHECK(_te != BAD_TXEDIT, "Can't create a memo field");
enable_default(); // Setta colori default
}
void TMemo_field::highlight() const
{
xvt_tx_set_active(_te);
}
bool TMemo_field::on_key(KEY k)
{
return TMask_field::on_key(k);
}
void TMemo_field::enable(bool on)
{
TMask_field::enable(on);
unsigned attr = xvt_tx_get_attr(_te);
if (on)
{
xvt_tx_set_colors(_te, NORMAL_COLOR, COLOR_BLACK, NORMAL_BACK_COLOR);
attr &= ~TX_READONLY;
}
else
{
xvt_tx_set_colors(_te, DISABLED_COLOR, COLOR_BLACK, DISABLED_BACK_COLOR);
attr |= TX_READONLY;
}
xvt_tx_set_attr(_te, attr);
}
void TMemo_field::show(bool on)
{
TMask_field::show(on);
}
bool TMemo_field::autoload(const TRelation* r)
{
const TFieldref* f = field();
xvt_tx_clear(_te);
if (f != NULL)
{
TTextfile txt;
r->lfile(f->file()).get_memo(f->name(), txt);
for (T_LNUM i = 0; i < (T_LNUM)txt.lines(); i++)
xvt_tx_add_par(_te, i, (char*)txt.line(i));
return i > 0;
}
return FALSE;
}
bool TMemo_field::autosave(TRelation* r) const
{
const TFieldref* f = field();
if (dirty() && f != NULL)
{
const T_PNUM para = xvt_tx_get_num_pars(_te);
TTextfile txt;
TString256 line;
for (T_PNUM p = 0; p < para; p++)
{
const T_LNUM lines = xvt_tx_get_num_par_lines(_te, p);
for (T_LNUM l = 0; l < lines; l++)
{
unsigned len;
xvt_tx_get_line(_te, p, A_LOCK, l, &len);
const char* s = xvt_tx_get_line(_te, p, A_GET, l, &len);
CHECK(s, "Null memo line");
line.strncpy(s, len);
xvt_tx_get_line(_te, p, A_UNLOCK, l, &len);
txt.append(line);
}
}
r->lfile(f->file()).put(f->name(), txt);
return para > 0;
}
return FALSE;
}

View File

@ -1,4 +1,4 @@
/* $Id: maskfld.h,v 1.29 1995-05-10 16:12:43 guy Exp $ */
/* $Id: maskfld.h,v 1.30 1995-06-19 08:13:03 guy Exp $ */
#ifndef __MASKFLD_H
#define __MASKFLD_H
@ -177,7 +177,7 @@ public:
virtual const char* warning() { return "";}
virtual bool autoload(const TRelation* r = NULL);
bool autosave(TRelation* r = NULL) const;
virtual bool autosave(TRelation* r = NULL) const;
void undo();
@ -192,6 +192,7 @@ public:
void set_group(byte group) { _groups.set(long(group)); _groups.set(0L);}
const TFieldref* field() const { return _field; }
void set_field(const TString& fr);
void set_focus() const;
void send_key(KEY k, short to);
@ -222,8 +223,8 @@ class TEdit_field : public TMask_field
protected:
// @DPROT
TString256 _str;
TString16 _picture;
TString _str;
TString _picture;
TString _warning;
CheckType _check; // Accettabilita' di valori nulli
bool _forced;
@ -560,22 +561,41 @@ public:
};
// @C
// class TGroup_field : public TMask_field
// @END
class TGroup_field : public TMask_field
{
protected:
// @DPROT
virtual void parse_head(TScanner& scanner);
virtual void create(WINDOW parent);
virtual void set_window_data(const char* data);
virtual void set_field_data(const char* data);
public:
// @FPUB
TGroup_field(TMask* mask);
};
class TMemo_field : public TMask_field
{
TXEDIT _te;
protected: // TMask_field
virtual word class_id() const { return CLASS_MEMO_FIELD; }
virtual const char* class_name() const { return "MEMO"; }
virtual void create(WINDOW parent);
virtual void parse_head(TScanner& scanner);
virtual bool autoload(const TRelation* r = NULL);
virtual bool autosave(TRelation* r = NULL) const;
virtual void highlight() const;
virtual void enable(bool on);
virtual void show(bool on);
virtual bool on_key(KEY k);
public:
TMemo_field(TMask* mask);
virtual ~TMemo_field();
};
#endif // __MASKFLD_H

View File

@ -37,10 +37,11 @@ class TSpreadsheet : public TWindow
int _cur_row, _cur_rec, _cur_col; // Current cell
bool _row_dirty; // Current row changed
bool _check_enabled; // Perform OFF_ROW and OFF_CELL checks
bool _update; // It's safe to update the display
int _needs_update;
void init();
friend void XVT_CALLCONV1 xiev_handler(XI_OBJ *itf, XI_EVENT *xiev);
protected:
void list_handler(XI_EVENT *xiev);
@ -55,6 +56,7 @@ protected:
bool notify(int row, KEY k);
void notify_change();
void on_idle();
public:
void update(int row);
@ -117,7 +119,8 @@ TSpreadsheet::TSpreadsheet(short x, short y, short dx, short dy,
TSheet_field* o)
: _mask(maskname, maskno), _notify(NULL), _edit_field(NULL),
_owner(o), _cur_row(0), _cur_col(0), _active(TRUE),
_row_dirty(FALSE), _check_enabled(TRUE), _firstfocus(TRUE), _update(TRUE)
_row_dirty(FALSE), _check_enabled(TRUE), _firstfocus(TRUE),
_needs_update(-1)
{
const int NUMBER_WIDTH = 3;
const int MAX_COL = 32;
@ -361,17 +364,6 @@ void TSpreadsheet::update_rec(int rec)
XI_OBJ row;
XI_MAKE_ROW(&row, _list, riga);
xi_cell_request(&row); // Update internal values
/*
if (_update)
{
XI_OBJ cell;
for (int c = 1; c < _columns; c++)
{
XI_MAKE_CELL(&cell, _list, riga, c);
xi_set_text(&cell, xi_get_text(&cell, NULL, -1));
}
}
*/
}
}
@ -456,8 +448,7 @@ void TSpreadsheet::update(int row)
if (row < 0)
{
xi_cell_request(_list); // Force updatde
if (_update)
xi_scroll(_list, XI_SCROLL_FIRST);
xi_scroll(_list, XI_SCROLL_FIRST);
}
else
update_rec(row);
@ -679,11 +670,8 @@ void TSpreadsheet::list_handler(XI_EVENT *xiev)
bool ok = sheet_mask().check_fields();
if (ok)
{
const int next = _cur_rec + (_lastab == K_TAB ? +1 : -1);
_update = rec2row(next) >= 0; // Disable update if next record is not visible
mask2str(_cur_rec); // Update sheet with mask contents
ok = notify(_cur_rec, K_ENTER); // Notify edit
_update = TRUE; // Reenable update
}
if (ok)
{
@ -727,7 +715,7 @@ void TSpreadsheet::list_handler(XI_EVENT *xiev)
if (c->on_key(c->is_edit() ? K_TAB : K_SPACE) == FALSE) // Test it
xiev->refused = *nuo != '\0';
else
mask2str(_cur_rec); // Update sheet row
mask2str(_cur_rec); // Update sheet row
}
_check_enabled = TRUE;
}
@ -756,7 +744,7 @@ void TSpreadsheet::list_handler(XI_EVENT *xiev)
xiev->refused = TRUE;
}
}
break;
break;
case E_CHAR:
if (_edit_field)
{
@ -813,7 +801,7 @@ void TSpreadsheet::list_handler(XI_EVENT *xiev)
if (xi_move_focus(_itf))
dispatch_e_char(parent(), k == K_ENTER ? K_TAB : K_BTAB);
break;
case K_CTRL+K_PREV:
case K_CTRL+K_PREV:
xi_scroll(_list, XI_SCROLL_PGUP);
break;
case K_CTRL+K_NEXT:
@ -1033,10 +1021,19 @@ void TSpreadsheet::mask2str(int rec)
#endif
}
#if XVT_OS == XVT_OS_WIN
update(rec);
CHECK(_needs_update == -1 || _needs_update == rec, "Can't update two records");
_needs_update = rec;
#endif
}
void TSpreadsheet::on_idle()
{
if (_needs_update >= 0)
{
update_rec(_needs_update);
_needs_update = -1;
}
}
// Certified 50%
void TSpreadsheet::enable_cell(int row, int column, bool on)
@ -1393,6 +1390,13 @@ bool TSheet_field::on_key(KEY k)
return TMask_field::on_key(k);
}
void TSheet_field::on_idle()
{
#if XVT_OS == XVT_OS_WIN
_sheet->on_idle();
#endif
}
void TSheet_field::exchange(bool show_value, const real& nuo)
{
TMask& m = sheet_mask();

View File

@ -37,6 +37,8 @@ public:
virtual void reset();
virtual void enable(bool on);
void on_idle();
void destroy(int r = -1); // Destroy row
void force_update(int r = -1);// Update data/screen

View File

@ -27,6 +27,7 @@
#define LIST LI
#define LISTFILE LI
#define MESSAGE ME
#define MEMO ME
#define MASK MA
#define NUMBER NU
#define NONE NO

View File

@ -33,7 +33,8 @@ HIDDEN bool remove_menu_item(MENU_ITEM* menu, MENU_TAG id, bool ismbar)
{
if (mn->tag == id)
{
do {
do
{
xvt_mem_rep((DATA_PTR)mn, (DATA_PTR)(mn+1), sizeof(MENU_ITEM), 1);
mn++;
}
@ -129,7 +130,7 @@ void TWindow_manager::destroy()
void TWindow_manager::lock_handle()
{
CHECK(_lowhandle == NULL, "Can't relock low handle");
_lowhandle = fopen("prassi.ini", "r");
_lowhandle = fopen("bagn001a.msk", "r");
CHECK(_lowhandle != NULL, "Can't lock low handle");
}
@ -546,6 +547,11 @@ void TWindow::handler(WINDOW win, EVENT* ep)
}
}
void TWindow::on_idle()
{
// Non c'e' niente da fare qui, ma non si puo' mai sapere
}
TPoint TWindow::size() const
{

View File

@ -150,6 +150,7 @@ public:
virtual void open(); // Mostra la finestra
virtual void close(); // Nasconde la finestra
virtual bool can_be_closed() const; // Puo' essere chiusa brutalmente?
virtual void on_idle(); // Non c'e' piu' niente da fare!
void iconize() const;
void maximize() const;

View File

@ -443,6 +443,14 @@ void TEvent_manager::pop()
_begin = (++_begin) % MAX; // Other events may occur!
xvt_win_dispatch_event(_w[i], &_e[i]);
}
WINDOW cw = cur_win();
if (cw != NULL_WIN)
{
TWindow* w = (TWindow*)xvt_vobj_get_data(cw);
CHECK(w != NULL, "Can't idle NULL window");
w->on_idle();
}
}
void do_events()

View File

@ -55,6 +55,8 @@ WINDOW xvt_create_window
void dispatch_e_scroll(WINDOW win, KEY key);
void xvt_set_font(WINDOW win, const char* family, int style, int dim = 0);
XVT_FNTID xvt_default_font();
void xvt_set_front_control(WINDOW win);
const char* xvt_get_title(WINDOW win);
void xvt_set_title(WINDOW win, const char* title);