From d100bb385bc472f7d90ee0569f7ad8528418a319 Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 2 Jan 1995 09:33:00 +0000 Subject: [PATCH] Aggiunto menu alle TWindow e ampliati i TForm git-svn-id: svn://10.65.10.50/trunk@810 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/bagn001a.uml | 15 +- include/colors.h | 8 + include/config.cpp | 35 +- include/config.h | 14 +- include/controls.cpp | 2170 ++++++++++++++++++++++-------------------- include/defmask.h | 4 +- include/form.cpp | 27 +- include/mask.cpp | 6 +- include/maskfld.cpp | 48 +- include/prassi.ver | 2 +- include/relapp.cpp | 5 +- include/sheet.cpp | 18 +- include/validate.cpp | 18 +- include/window.cpp | 12 +- include/window.h | 5 +- include/xvtility.cpp | 84 +- include/xvtility.h | 4 +- 17 files changed, 1329 insertions(+), 1146 deletions(-) diff --git a/include/bagn001a.uml b/include/bagn001a.uml index 4bb504dd2..2fb7fe1be 100755 --- a/include/bagn001a.uml +++ b/include/bagn001a.uml @@ -65,13 +65,6 @@ BEGIN HELP "Dimensioni del carattere di stampa" END -BOOLEAN MSK_1_ISGRAPHICS -BEGIN - PROMPT 4 8 "Stampa elementi grafici" - HELP "Indicare se stampare elementi grafici (linee, box, logo) quando la stampante lo consente" -END - - LIST MSK_1_LINES 3 BEGIN PROMPT 52 6 "Linee/Inch " @@ -104,7 +97,13 @@ BEGIN PROMPT 4 8 "Salva configurazione" HELP "Indicare se stampare elementi grafici (linee, box, logo) quando la stampante lo consente" END - + +BOOLEAN MSK_1_ISGRAPHICS +BEGIN + PROMPT 4 9 "Stampa elementi grafici" + HELP "Indicare se stampare elementi grafici (linee, box, logo) quando la stampante lo consente" +END + GROUPBOX DLG_NULL 74 4 BEGIN PROMPT 1 9 "" diff --git a/include/colors.h b/include/colors.h index 965285cb8..e5bffc494 100755 --- a/include/colors.h +++ b/include/colors.h @@ -1,6 +1,11 @@ #ifndef __COLORS_H #define __COLORS_H +#ifndef XVT_INCL +#include +#endif + +extern COLOR MASK_COLOR; extern COLOR MASK_BACK_COLOR; extern COLOR NORMAL_COLOR; extern COLOR NORMAL_BACK_COLOR; @@ -9,5 +14,8 @@ extern COLOR DISABLED_BACK_COLOR; extern COLOR FOCUS_COLOR; extern COLOR FOCUS_BACK_COLOR; +const COLOR COLOR_DKCYAN = MAKE_COLOR(0,128,128); +const COLOR COLOR_DKYELLOW = MAKE_COLOR(128,128, 0); + #endif diff --git a/include/config.cpp b/include/config.cpp index 993a68fe3..00535191e 100755 --- a/include/config.cpp +++ b/include/config.cpp @@ -118,34 +118,51 @@ bool TConfig::exist(const char* var, int index) return _data.is_key(vvar); } -TString& TConfig::get(const char* var, const char* section, int index) +TString& TConfig::get(const char* var, const char* section, int index, const char* def) { // ritorna valore di variabile nella sezione corrente o in // quella specificata static TFixed_string s(__tmp_string, 256); - TString vvar(var); if (index != -1) vvar << '(' << index << ')'; + TString80 vvar(var); if (index != -1) vvar << '(' << index << ')'; _check_paragraph(section); if (_data.is_key(vvar)) s = (TString&)_data[vvar]; else - s = ""; + s = def; return s; } -long TConfig::get_long(const char* var, const char* section, int index) -{ - return atol(get(var,section,index)); +long TConfig::get_long(const char* var, const char* section, int index, long def) +{ + const char* n = get(var,section,index); + return *n ? atol(n) : def; } -bool TConfig::get_bool(const char* var, const char* section, int index) -{ - const TString& s = get(var, section, index).upper(); +bool TConfig::get_bool(const char* var, const char* section, int index, bool def) +{ + if (def) strcpy(__tmp_string, "X"); + else *__tmp_string = '\0'; + + const TString& s = get(var, section, index, __tmp_string).upper(); return s != "" && (s == "X" || s == "ON" || s == "YES" || s == "OK" || s == "TRUE"); } +COLOR TConfig::get_color(const char* var, const char* section, int index, COLOR def) +{ + const char* c = get(var, section, index); + if (*c) + { + TToken_string s(c, ','); + const int r = atoi(s.get()); + const int g = atoi(s.get()); + const int b = atoi(s.get()); + def = MAKE_COLOR(r, g, b); + } + return def; +} bool TConfig::set(const char* var, const char* value, const char* section, bool force, int index) diff --git a/include/config.h b/include/config.h index daec0ca76..c939d12c7 100755 --- a/include/config.h +++ b/include/config.h @@ -1,5 +1,9 @@ #ifndef __CONFIG_H -#define __CONFIG_H +#define __CONFIG_H + +#ifndef XVT_INCL +#include +#endif #ifndef __ASSOC_H #include @@ -40,13 +44,15 @@ public: // quella specificata; se non c'e' ritorna "" // passando index >=0 viene appeso al nome variabile per // implementare un mezzo cazzo di array - TString& get(const char* var, const char* section = NULL, int index = -1); + TString& get(const char* var, const char* section = NULL, int index = -1, const char* def = ""); // questa ritorna 0 se non c'e', il che e' un po' sfigotto - long get_long(const char* var, const char* section = NULL, int index = -1); + long get_long(const char* var, const char* section = NULL, int index = -1, long def = 0L); // questa ritorna FALSE se non c'e', il che e' ancora piu' sfigotto - bool get_bool(const char* var, const char* section = NULL, int index = -1); + bool get_bool(const char* var, const char* section = NULL, int index = -1, bool def = FALSE); + + COLOR get_color(const char* var, const char* section = NULL, int index = -1, COLOR def = 0); // setta variabile nella sezione corrente o specificata // se force == TRUE crea la sezione/variabile se non esiste; altrimenti diff --git a/include/controls.cpp b/include/controls.cpp index 5d1511858..288b91c20 100755 --- a/include/controls.cpp +++ b/include/controls.cpp @@ -1,1056 +1,1114 @@ -extern "C" -{ -#include -#include -#include -} - -#if XVT_OS != XVT_OS_WIN -#error "This file should be compiled for Windows only" -#endif - -#include -#include -#include -#include -#include - -#include - -/////////////////////////////////////////////////////////// -// TPicture_array -/////////////////////////////////////////////////////////// - -class TPicture_array -{ - enum { MAXPIC = 128 }; - PICTURE _picture[MAXPIC]; - -public: - PICTURE getbmp(short id); - PICTURE operator[](short id) { return _picture[id-BMP_OK]; } - void reset(); - - TPicture_array(); - ~TPicture_array() { reset(); } -}; - - -PICTURE TPicture_array::getbmp(short id) -{ - const int i = id-BMP_OK; - CHECKD(i >= 0 && i < MAXPIC, "Control ID out of range", id); - - if (_picture[i] != NULL) - { - if (i < 100) return _picture[i]; - picture_free(_picture[i]); - } - _picture[i] = cpb_picture_load(id); - - if (_picture[i] == NULL) - error_box("Can't load picture %d", id); - - return _picture[i]; -} - - -TPicture_array::TPicture_array() -{ - memset(_picture, 0, sizeof(_picture)); -} - -void TPicture_array::reset() -{ - for (int i = 0; i < MAXPIC; i++) - if (_picture[i] != NULL) - { - picture_free(_picture[i]); - _picture[i] = NULL; - } -} - - -/////////////////////////////////////////////////////////// -// Static data and functions -/////////////////////////////////////////////////////////// - -HIDDEN TControl* creating = NULL; -HIDDEN long ctl_flags; -HIDDEN WINDOW _hdc; -HIDDEN RCT _client; -HIDDEN TPicture_array cpb; - -HIDDEN void get_geometry(WINDOW win) -{ - get_client_rect(win, &_client); - _client.right--; _client.bottom--; - _hdc = win; -} - -HIDDEN void set_creation_args(WIN_CREATION_ARGS *a) -{ - long& flags = a->win_flags; - if (ctl_flags & CTL_FLAG_DISABLED) flags |= WSF_DISABLED; - if (ctl_flags & CTL_FLAG_INVISIBLE) flags |= WSF_INVISIBLE; - - switch(creating->id()) - { - case -2: - flags |= WSF_DISABLED; - break; - default:break; - } -} - -void xvt_draw_rect(WINDOW win, const RCT& rect, COLOR lt, COLOR rb, short depth) -{ - RCT r = rect; - - CPEN pen; - pen.width = 1; - pen.pat = PAT_SOLID; - pen.style = P_SOLID; - pen.color = lt; - - for (short d = 0; d < depth;) - { - win_set_cpen(win, &pen); - - PNT p; // Current vertex of the rectangle - - bool drawed = FALSE; - if (lt != COLOR_LTGRAY) - { - p.h = r.left; p.v = r.bottom; - win_move_to(win, p); - - p.v = r.top; - win_draw_line(win, p); - p.h = r.right; - win_draw_line(win, p); - drawed = TRUE; - } - - if (rb != COLOR_LTGRAY) - { - if (pen.color != rb) - { - pen.color = rb; - win_set_cpen(win, &pen); - } - if (!drawed) - { - p.h = r.right; p.v = r.top; - win_move_to(win, p); - } - p.v = r.bottom; - win_draw_line(win, p); - p.h = r.left; - win_draw_line(win, p); - } - - if (++d < depth) - { - r.left++; r.top++; - r.right--; r.bottom--; - } - } -} - - -void TControl::create( - short left, short top, short right, short bottom, const char* title, - WINDOW parent, long flags, long app_data, short id) -{ - bool bold = *title == '@'; - if (bold) title += 2; - - const int prop_count = 1; - const char* prop_list[prop_count+1] = { title, NULL }; - - _id = id; - _caption = title; _caption.strip("~"); - _disabled = (flags & CTL_FLAG_DISABLED) != 0; - _checked = (flags & CTL_FLAG_CHECKED) != 0; - _multiple = (flags & CTL_FLAG_MULTIPLE) != 0; - _focused = FALSE; - - creating = this; - ctl_flags = flags; - _win = xvtcm_create(id, left, top, right, bottom, - prop_count, (char**)prop_list, parent, - 0, 0, NULL, handler, set_creation_args); - CHECKD(_win, "Can't create control ", id); - - creating = NULL; - set_app_data(_win, app_data); - xvt_set_font(_win, FF_FIXED, bold ? FS_BOLD : 0); -} - - -// Virtual destructor needed to make derived descrutors live! -TControl::~TControl() -{} - - -long TControl::handler(WINDOW win, EVENT* ep) -{ - static bool tracking = FALSE; - static bool pressed = FALSE; - - if (ep->type == E_CREATE) - xvtcm_eh_start(win, ep); - - TControl** model = (TControl**)xvtcm_get_model(win, sizeof(TControl*)); - CHECK(model, "Can't get the model"); - - TControl*& cc = *model; - if (ep->type == E_CREATE) - { - CHECK(creating, "Can't create a NULL control"); - cc = creating; - } - CHECK(cc, "Can't handle a NULL control"); - - if (creating == NULL) switch(ep->type) - { - case E_FOCUS: - cc->focus((bool)ep->v.active); - case E_UPDATE: - cc->update(); - break; - case E_MOUSE_DOWN: - trap_mouse(win); - tracking = pressed = TRUE; - cc->mouse_down(ep->v.mouse.where); - break; - case E_CHAR: - { - const KEY key = e_char_to_key(ep); - switch(key) - { - case K_SPACE: - cc->mouse_up(); - break; - default: - dispatch_e_char(get_parent(win), key); - break; - } - } - break; - case E_MOUSE_MOVE: - if (tracking) - { - RCT r; - get_client_rect(win, &r); - if (pt_in_rect(&r, ep->v.mouse.where)) - { - if (!pressed) - { - cc->mouse_down(ep->v.mouse.where); - pressed = TRUE; - } - } - else - { - if (pressed) - { - cc->update(); - pressed = FALSE; - } - } - } - break; - case E_MOUSE_UP: - if (tracking) - { - release_mouse(); - tracking = FALSE; - if (pressed) - { - cc->mouse_up(); - pressed = FALSE; - } - } - break; - case E_DESTROY: - delete *model; - *model = NULL; - xvtcm_eh_end(win, ep); - break; - default: - break; - } - - return 0L; -} - -void TControl::enable(bool on) -{ - if (on == disabled()) - { - _disabled = !on; - update(); - enable_window(win(), on); - } -} - -void TControl::check(bool on) -{ - _checked = on; -} - -void TControl::update() const -{ - if (_win != _hdc) - get_geometry(_win); - clear_window(_hdc, MASK_BACK_COLOR); - win_set_fore_color(_hdc, disabled() ? COLOR_GRAY : COLOR_BLACK); -} - -/////////////////////////////////////////////////////////// -// TText -/////////////////////////////////////////////////////////// - -class TText : public TControl -{ -protected: - virtual WIN_TYPE type() const { return WC_TEXT; } - virtual void update() const; - -public: - TText(short left, short top, short right, short bottom, - const char* caption, WINDOW parent, - long flags, long app_data, short id); -}; - -TText::TText(short left, short top, short right, short bottom, - const char* caption, WINDOW parent, - long flags, long app_data, short id) -{ - create(left, top+1, right, bottom-1, caption, parent, flags, app_data, id); -} - -void TText::update() const -{ - TControl::update(); - win_set_fore_color(_hdc, COLOR_BLACK); - win_draw_text(_hdc, _client.left, _client.top+BASEY, (char*)caption(), -1); -} - -/////////////////////////////////////////////////////////// -// TGroup -/////////////////////////////////////////////////////////// - -class TGroup : public TText -{ -protected: - virtual WIN_TYPE type() const { return WC_GROUPBOX; } - virtual void update() const; - void draw_round_rect(const RCT& r, COLOR c) const; - -public: - TGroup(short left, short top, short right, short bottom, - const char* caption, WINDOW parent, - long flags, long app_data, short id); -}; - -TGroup::TGroup(short left, short top, short right, short bottom, - const char* caption, WINDOW parent, - long flags, long app_data, short id) -: TText(left, top, right, bottom, caption, parent, flags | CTL_FLAG_DISABLED, app_data, - (id < 0) ? -2 : id) -{} - -void TGroup::draw_round_rect(const RCT& r, COLOR c) const -{ - CPEN pen; - pen.width = 2; - pen.pat = PAT_SOLID; - pen.style = P_SOLID; - pen.color = c; - win_set_cpen(_hdc, &pen); - - CBRUSH brush = { PAT_HOLLOW, MASK_BACK_COLOR }; - win_set_cbrush(_hdc, &brush); - win_draw_roundrect(_hdc, (RCT*)&r, ROWY, ROWY); -} - -void TGroup::update() const -{ - TText::update(); - - RCT r = _client; - r.top += CHARY; - r.right-=4; r.bottom-=ROWY/2; - if (multiple()) - { - r.left++; r.top++; r.right--; r.bottom--; - draw_round_rect(r, COLOR_BLUE); - } - else - { - xvt_draw_rect(_hdc, r, COLOR_GRAY, COLOR_CYAN); - } -} - -/////////////////////////////////////////////////////////// -// Button -/////////////////////////////////////////////////////////// - -class TButton : public TControl -{ -protected: - enum { DEPTH = 2 }; - - virtual WIN_TYPE type() const { return WC_PUSHBUTTON; } - virtual void update() const; - virtual void mouse_down(PNT where); - virtual void mouse_up(); - virtual void check(bool on); - virtual void draw_pressed(bool pressed) const; - -public: - TButton(short left, short top, short right, short bottom, - const char* caption,WINDOW parent, - long flags, long app_data, short id); -}; - - -TButton::TButton(short left, short top, short right, short bottom, - const char* caption, WINDOW parent, - long flags, long app_data, short id) -{ - create(left, top, right, bottom, caption, parent, flags, app_data, id); -} - - -void TButton::draw_pressed(bool pressed) const -{ - get_geometry(win()); - - clear_window(_hdc, COLOR_LTGRAY); - RCT r = _client; - xvt_draw_rect(_hdc, r, COLOR_BLACK, COLOR_BLACK); - - COLOR lt = pressed ? COLOR_GRAY : COLOR_WHITE; - COLOR rb = pressed ? COLOR_LTGRAY : COLOR_GRAY; - - for (int i = DEPTH; i--;) - { - r.left++; r.top++; r.right--; r.bottom--; - xvt_draw_rect(_hdc, r, lt, rb); - if (i == 1) lt = COLOR_LTGRAY; - } -} - - -void TButton::update() const -{ - TControl::update(); - draw_pressed(checked()); -} - -void TButton::mouse_down(PNT) -{ - draw_pressed(!checked()); -} - -void TButton::mouse_up() -{ - draw_pressed(checked()); - - EVENT e; // Notification message - e.type = E_CONTROL; - e.v.ctl.id = id(); - e.v.ctl.ci.type = type(); - e.v.ctl.ci.win = win(); - dispatch_event(get_parent(win()), &e); -} - -void TButton::check(bool on) -{ - TControl::check(on); - draw_pressed(on); -} - -/////////////////////////////////////////////////////////// -// TPush button -/////////////////////////////////////////////////////////// - -class TPush_button : public TButton -{ - PICTURE _picup, _picdn; - byte _dx, _dy; - int _accel; - -protected: - void draw_pressed(bool pressed) const; - void update() const; - -public: - TPush_button(short left, short top, short right, short bottom, - const char* caption, WINDOW parent, - long flags, long app_data, short id); - virtual ~TPush_button(); -}; - -TPush_button::TPush_button(short left, short top, short right, short bottom, - const char* capt, WINDOW parent, - long flags, long app_data, short id) -: TButton(left-(id == DLG_F9), top, right, bottom, - capt, parent, flags, app_data, id), - _picup(0L), _picdn(0L) -{ - switch(id) - { - - case DLG_OK: - if (strcmp("Conferma", caption()) == 0) - capt = format("#%d", BMP_OK); - break; - case DLG_CANCEL: - if (strcmp("Annulla", caption()) == 0) - capt = format("#%d", BMP_CANCEL); - break; - case DLG_QUIT: - capt = format("#%d#%d", BMP_QUIT, BMP_QUITDN); - break; - case DLG_SELECT: - capt = format("#%d", BMP_SELECT); - break; - case DLG_DELREC: - capt = format("#%d#%d", BMP_DELREC, BMP_DELRECDN); - break; - case DLG_NEWREC: - if (strcmp("Nuovo", caption()) == 0) // Puo' essere Gestione - capt = format("#%d#%d", BMP_NEWREC, BMP_NEWRECDN); - break; - case DLG_STOPREC: - capt = format("#%d", BMP_STOPREC); - break; - /* - case DLG_FIRSTREC: - capt = format("#%d", BMP_FIRSTREC); - break; - case DLG_PREVREC: - capt = format("#%d", BMP_PREVREC); - break; - case DLG_NEXTREC: - capt = format("#%d", BMP_NEXTREC); - break; - case DLG_LASTREC: - capt = format("#%d", BMP_LASTREC); - break; - */ - case DLG_SAVEREC: - capt = format("#%d#%d", BMP_SAVEREC, BMP_SAVERECDN); - break; - case DLG_FINDREC: - capt = format("#%d", BMP_FINDREC); - break; - case DLG_F9: - capt = format("#%d", BMP_SEARCH); - break; - case DLG_LINK: - capt = format("#%d", BMP_LINK); - break; - case DLG_EDIT: - capt = format("#%d", BMP_EDIT); - break; - case DLG_PRINT: - capt = format("#%d", BMP_PRINT); - break; - case DLG_SETPRINT: - capt = format("#%d", BMP_SETPRINT); - break; - default: - break; - } - - const int height = bottom-top; - const int width = right-left; - - const char* diesis = strchr(capt, '#'); - if (diesis != NULL) - { - int pid = atoi(++diesis); - _picup = cpb.getbmp(pid); - diesis = strchr(diesis, '#'); - if (diesis != NULL) - { - pid = atoi(++diesis); - _picdn = cpb.getbmp(pid); - } - - RCT r; - cpb_get_picture_size(_picup, &r); - _dx = byte((width-r.right+1) >> 1); - _dy = byte((height-r.bottom) >> 1); - _accel = -1; - } - else - { - TFixed_string c(capt); - _accel = c.find('~'); - if (_accel > 0) - _accel *= CHARX; - - _dx = (width - win_get_text_width(win(), (char*)caption(), -1)) >> 1; - _dy = byte((height-CHARY)/2 + BASEY - DEPTH); - } -} - -TPush_button::~TPush_button() -{ -} - -void TPush_button::draw_pressed(bool pressed) const -{ - TButton::draw_pressed(pressed); - - const int p = pressed ? DEPTH : 0; - if (_picup) - { - const PICTURE pic = (pressed && _picdn) ? _picdn : _picup; - cpb_win_picture_draw_at(_hdc, pic, _dx+p, _dy+p); - } - else - { - const char* t = caption(); - - win_set_fore_color(_hdc, COLOR_WHITE); - win_draw_text(_hdc, _dx+p+1, _dy+p+1, (char*)t, -1); - if (_accel >= 0) - win_draw_text(_hdc, _dx+_accel+p+1, _dy+p+3, "_", 1); - - const COLOR c = disabled() ? DISABLED_COLOR : NORMAL_COLOR; - win_set_fore_color(_hdc, c); - win_draw_text(_hdc, _dx+p, _dy+p, (char*)t, -1); - if (_accel >= 0) - win_draw_text(_hdc, _dx+_accel+p, _dy+p+2, "_", 1); - } -} - -void TPush_button::update() const -{ - draw_pressed(FALSE); - if (focused() && id() != DLG_F9) - { - CPEN pen; - pen.width = 1; - pen.pat = PAT_SOLID; - pen.style = P_SOLID; - pen.color = COLOR_RED; - win_set_cpen(_hdc, &pen); - CBRUSH brush = { PAT_HOLLOW, COLOR_WHITE }; - win_set_cbrush(_hdc, &brush); - win_draw_rect(_hdc, &_client); - } else - if (disabled() && _picup) - { - CPEN pen; - pen.width = 1; - pen.pat = PAT_SOLID; - pen.style = P_SOLID; - pen.color = COLOR_LTGRAY; - win_set_cpen(_hdc, &pen); - - const int sx = _client.left+DEPTH+1; - const int sy = _client.top+DEPTH+1; - const int ex = _client.right-DEPTH-1; - const int ey = _client.bottom-DEPTH-1; - - for (int i = sx; i < ex; i += 2) - { - PNT p = { sy, i }; - win_move_to(_hdc, p); - p.v = ey; - win_draw_line(_hdc, p); - } - for (i = sy; i < ey; i += 2) - { - PNT p = { i, sx }; - win_move_to(_hdc, p); - p.h = ex; - win_draw_line(_hdc, p); - } - } -} - -/////////////////////////////////////////////////////////// -// TPage_button -/////////////////////////////////////////////////////////// - -class TPage_button : public TControl -{ - enum { height = 19, width = 32 }; - byte _flag; - -protected: - virtual void update() const; - virtual void mouse_down(PNT where); - virtual void mouse_up(); - -public: - TPage_button(WINDOW parent, byte flag); - byte get_flag() const { return _flag; } - void set_flag(byte f); -}; - -TPage_button::TPage_button(WINDOW parent, byte flag) : _flag(flag) -{ - RCT r; get_client_rect(parent, &r); - create(r.right-width, r.bottom-height, r.right, r.bottom, - "", parent, 0L, 0L, DLG_PAGE); - cpb.getbmp(BMP_BOOK1 + flag -1); -} - -void TPage_button::mouse_down(PNT where) -{ - check(where.h < (width>>1)); -} - -void TPage_button::mouse_up() -{ - dispatch_e_char(get_parent(win()), checked() ? K_PREV : K_NEXT); -} - -void TPage_button::update() const -{ - TControl::update(); - if (_flag) - cpb_win_picture_draw_at(_hdc, cpb[BMP_BOOK1 + _flag -1], 0, 0); -} - -void TPage_button::set_flag(byte f) -{ - _flag = f; - update(); -} - -/////////////////////////////////////////////////////////// -// TTag_button -/////////////////////////////////////////////////////////// - -class TTag_button : public TControl -{ - enum { height = 12, width = 32 }; - byte _curr; - byte _page; - byte _pages; - - WINDOW _parent; - -protected: - virtual void update() const; - virtual void mouse_down(PNT where); - virtual void mouse_up(); - -public: - TTag_button(WINDOW parent, byte p, byte tot); - byte get_pages() const { return _pages; } - void set_pages(byte p); -}; - -TTag_button::TTag_button(WINDOW parent, byte p, byte tot) -: _parent(parent), _page(p), _pages(tot), _curr(p) -{ - RCT r; get_client_rect(parent, &r); - create(0, 0, r.right, CHARY, "", parent,0L,0L, DLG_PAGETAGS); -} - -void TTag_button::update() const -{ - get_geometry(win()); - clear_window(_hdc, COLOR_GRAY); - - for (int i = 0; i < _pages; i++) - { - RCT r; set_rect(&r, width*i, 0, width*(i+1), _client.bottom+4); - CBRUSH b = { PAT_SOLID, (i == _page) ? MASK_BACK_COLOR : COLOR_GRAY }; - win_set_cbrush(_hdc, &b); - win_set_std_cpen(_hdc, TL_PEN_BLACK); - win_draw_rect(_hdc, &r); - - if (i == _page) -#ifdef __CTL3D__ - xvt_draw_rect(_hdc, r, COLOR_WHITE, COLOR_GRAY); -#else - xvt_draw_rect(_hdc, r, COLOR_CYAN, COLOR_GRAY); -#endif - - char n[4]; sprintf(n, "%d", i+1); - win_draw_text(_hdc, (width-CHARX)/2 + i*width, BASEY, n, -1); - } - - CPEN pen; - pen.width = 1; - pen.pat = PAT_SOLID; - pen.style = P_SOLID; -#ifdef __CTL3D__ - pen.color = COLOR_WHITE; -#else - pen.color = COLOR_CYAN; -#endif - win_set_cpen(_hdc, &pen); - - PNT p = { _client.bottom, 0 }; - win_move_to(_hdc, p); - p.h = width*_page; - win_draw_line(_hdc, p); - p.h += width+1; - win_move_to(_hdc, p); - p.h = _client.right; - win_draw_line(_hdc, p); -} - -void TTag_button::mouse_down(PNT where) -{ - _curr = where.h / width; - if (_curr >= _pages) _curr = _pages-1; else - if (_curr < 0) _curr = 0; -} - -void TTag_button::mouse_up() -{ - if (_curr != _page) - dispatch_e_char(_parent, K_CTRL + K_F1 + _curr); -} - -void TTag_button::set_pages(byte p) -{ - _pages = p; - update(); -} - -/////////////////////////////////////////////////////////// -// Checkbox -/////////////////////////////////////////////////////////// - -class TCheckbox : public TButton -{ - static int _dy; - -protected: - virtual WIN_TYPE type() const; - virtual void draw_pressed(bool pressed) const; - virtual void update() const; - - int radio() const { return multiple() ? 1 : 0; } - -public: - TCheckbox(short left, short top, short right, short bottom, - const char* caption, WINDOW parent, - long flags, long app_data, short id); - virtual ~TCheckbox(); -}; - -int TCheckbox::_dy = -1; - -TCheckbox::TCheckbox( - short left, short top, short right, short bottom, - const char* caption, WINDOW parent, - long flags, long app_data, short id) -: TButton(left, top, right, bottom, - caption, parent, flags, app_data, id) -{ - if (_dy < 0) - { - cpb.getbmp(BMP_CHECK_ON); - cpb.getbmp(BMP_CHECK_OFF); - cpb.getbmp(BMP_RADIO_ON); - PICTURE p = cpb.getbmp(BMP_RADIO_OFF); - - RCT r; - cpb_get_picture_size(p, &r); - _dy = BASEY - r.bottom + 2; - } -} - - -TCheckbox::~TCheckbox() -{ -} - - -WIN_TYPE TCheckbox::type() const -{ - return multiple() ? WC_RADIOBUTTON : WC_CHECKBOX; -} - - -void TCheckbox::draw_pressed(bool pressed) const -{ - get_geometry(win()); - PICTURE pic; - if (radio()) - pic = pressed ? cpb[BMP_RADIO_ON] : cpb[BMP_RADIO_OFF]; - else - pic = pressed ? cpb[BMP_CHECK_ON] : cpb[BMP_CHECK_OFF]; - cpb_win_picture_draw_at(_hdc, pic, _client.left, _client.top+_dy); -} - - -void TCheckbox::update() const -{ - TButton::update(); - - const int x = _client.left+20; - const int y = _client.top + BASEY; - - if (focused()) - { -#if XVT_OS == XVT_OS_WIN - RECT r; - r.left = x-2; r.top = _client.top; - r.right = _client.right-CHARX; r.bottom = y+3; - - HWND hwnd = (HWND)get_value(_hdc, ATTR_NATIVE_WINDOW); - HDC hdc = GetDC(hwnd); - DrawFocusRect(hdc, &r); - ReleaseDC(hwnd, hdc); -#endif - } - - win_draw_text(_hdc, x, y, (char*)caption(), -1); -} - -/////////////////////////////////////////////////////////// -// User functions -/////////////////////////////////////////////////////////// - -WINDOW xvt_create_checkbox( - short left, short top, short right, short bottom, - const char* caption, - WINDOW parent, - long flags, - long app_data, - int id) -{ - TCheckbox* cb = new TCheckbox(left, top, right, bottom, - caption, parent, - flags, app_data, id); - - // It'll destroy itself automagically :-) - - return cb->win(); -} - -WINDOW xvt_create_radiobutton( - short left, short top, short right, short bottom, - const char* caption, - WINDOW parent, - long flags, - long app_data, - int id) -{ - flags |= CTL_FLAG_MULTIPLE; - TCheckbox* cb = new TCheckbox(left, top, right, bottom, - caption, parent, - flags, app_data, id); - - // It'll destroy itself automagically :-) - return cb->win(); -} - - -WINDOW xvt_create_pushbutton( - short left, short top, short right, short bottom, - const char* caption, - WINDOW parent, - long flags, - long app_data, - int id) -{ - TControl* pb; - - switch (id) - { - case DLG_PAGE: - pb = new TPage_button(parent, (byte)flags); - break; - case DLG_PAGETAGS: - pb = new TTag_button(parent, (byte)flags, (byte)app_data); - break; - default: - if (bottom-top > (CHARY<<1)) - { - top += BASEY>>1; - bottom -= BASEY>>1; - } - pb = new TPush_button(left, top, right, bottom, - caption, parent, - flags, app_data, id); - } - - // It'll destroy itself automagically :-) - return pb->win(); -} - - -WINDOW xvt_create_text( - short left, short top, short right, short bottom, - const char* caption, - WINDOW parent, - long flags, - long app_data, - int id) -{ - TText* cb = new TText(left, top, right, bottom, - caption, parent, - flags, app_data, id); - // It'll destroy itself automagically :-) - return cb->win(); -} - - -WINDOW xvt_create_groupbox( - short left, short top, short right, short bottom, - const char* caption, - WINDOW parent, - long flags, - long app_data, - int id) -{ - TGroup* cb = new TGroup(left, top, right, bottom, - caption, parent, - flags, app_data, id); - // It'll destroy itself automagically :-) - return cb->win(); -} - - -void free_controls_bmp() -{ - cpb.reset(); -} - - -TControl* TControl::WINDOW2TControl(WINDOW win) -{ - TControl** model = (TControl**)xvtcm_get_model(win, 0); - CHECK(model && *model, "Can't get the model from a window"); - return *model; -} - -void xvt_change_page_tags(WINDOW pag, bool on, WINDOW tag, byte p) -{ - if (pag != NULL_WIN) - { - TPage_button* pb = (TPage_button*)TControl::WINDOW2TControl(pag); - byte f = pb->get_flag(); - if (on) f |= 0x1; - else f &= 0x2; - pb->set_flag(f); - } - - if (tag != NULL_WIN) - { - TTag_button* pt = (TTag_button*)TControl::WINDOW2TControl(tag); - pt->set_pages(p); - } -} - - +extern "C" +{ +#include +#include +#include +} + +#if XVT_OS != XVT_OS_WIN +#error "This file should be compiled for Windows only" +#endif + +#include +#include +#include +#include +#include + +#include + +/////////////////////////////////////////////////////////// +// TPicture_array +/////////////////////////////////////////////////////////// + +class TPicture_array +{ + enum { MAXPIC = 128 }; + PICTURE _picture[MAXPIC]; + +public: + PICTURE getbmp(short id, bool convert = FALSE); + PICTURE operator[](short id) { return _picture[id-BMP_OK]; } + void reset(); + + TPicture_array(); + ~TPicture_array() { reset(); } +}; + + +HIDDEN byte COLOR2PIC(COLOR c) +{ + byte b; + switch (c) + { + case COLOR_DKYELLOW: + b = 0x03; break; + case COLOR_DKCYAN: + b = 0x06; break; + case COLOR_CYAN: + b = 0xF8; break; + case COLOR_YELLOW: + b = 0xFB; break; + default: + b = 0x00; break; + } + return b; +} + + +PICTURE xvt_picture_load(short id, bool convert) +{ + PICTURE cpb = cpb_picture_load(id); + + if (convert && MASK_BACK_COLOR != COLOR_DKCYAN) + { + const byte newdk = COLOR2PIC(MASK_BACK_COLOR); + const byte newlt = COLOR2PIC(MASK_COLOR); + const PICTURE old = cpb; + RCT r; cpb_get_picture_size(old, &r); + long size; + char* buf = picture_lock(old, &size); + CHECK(buf, "Out of memory in picture_load"); + cpb = picture_make(buf, size, &r); + const int first = 14; + const int last = first + r.right*r.bottom; + for (int i = first; i < last; i++) switch(buf[i]) + { + case 0x06: + buf[i] = newdk; break; + case 0xF8: + buf[i] = newlt; break; + default: + break; + } + picture_unlock(old); + picture_free(old); + } + + return cpb; +} + + +PICTURE TPicture_array::getbmp(short id, bool convert) +{ + const int i = id-BMP_OK; + CHECKD(i >= 0 && i < MAXPIC, "Control ID out of range", id); + + if (_picture[i] != NULL) + { + if (i < 100) return _picture[i]; + picture_free(_picture[i]); + } + _picture[i] = xvt_picture_load(id, convert); + + if (_picture[i] == NULL) + error_box("Can't load picture %d", id); + + return _picture[i]; +} + + +TPicture_array::TPicture_array() +{ + memset(_picture, 0, sizeof(_picture)); +} + +void TPicture_array::reset() +{ + for (int i = 0; i < MAXPIC; i++) + if (_picture[i] != NULL) + { + picture_free(_picture[i]); + _picture[i] = NULL; + } +} + + +/////////////////////////////////////////////////////////// +// Static data and functions +/////////////////////////////////////////////////////////// + +HIDDEN TControl* creating = NULL; +HIDDEN long ctl_flags; +HIDDEN WINDOW _hdc; +HIDDEN RCT _client; +HIDDEN TPicture_array cpb; + +HIDDEN void get_geometry(WINDOW win) +{ + get_client_rect(win, &_client); + _client.right--; _client.bottom--; + _hdc = win; +} + +HIDDEN void set_creation_args(WIN_CREATION_ARGS *a) +{ + long& flags = a->win_flags; + if (ctl_flags & CTL_FLAG_DISABLED) flags |= WSF_DISABLED; + if (ctl_flags & CTL_FLAG_INVISIBLE) flags |= WSF_INVISIBLE; + + switch(creating->id()) + { + case -2: + flags |= WSF_DISABLED; + break; + default:break; + } +} + +void xvt_draw_rect(WINDOW win, const RCT& rect, COLOR lt, COLOR rb, short depth) +{ + RCT r = rect; + + CPEN pen; + pen.width = 1; + pen.pat = PAT_SOLID; + pen.style = P_SOLID; + pen.color = lt; + + for (short d = 0; d < depth;) + { + win_set_cpen(win, &pen); + + PNT p; // Current vertex of the rectangle + + bool drawed = FALSE; + if (lt != COLOR_LTGRAY) + { + p.h = r.left; p.v = r.bottom; + win_move_to(win, p); + + p.v = r.top; + win_draw_line(win, p); + p.h = r.right; + win_draw_line(win, p); + drawed = TRUE; + } + + if (rb != COLOR_LTGRAY) + { + if (pen.color != rb) + { + pen.color = rb; + win_set_cpen(win, &pen); + } + if (!drawed) + { + p.h = r.right; p.v = r.top; + win_move_to(win, p); + } + p.v = r.bottom; + win_draw_line(win, p); + p.h = r.left; + win_draw_line(win, p); + } + + if (++d < depth) + { + r.left++; r.top++; + r.right--; r.bottom--; + } + } +} + + +void TControl::create( + short left, short top, short right, short bottom, const char* title, + WINDOW parent, long flags, long app_data, short id) +{ + bool bold = *title == '@'; + if (bold) title += 2; + + const int prop_count = 1; + const char* prop_list[prop_count+1] = { title, NULL }; + + _id = id; + _caption = title; _caption.strip("~"); + _disabled = (flags & CTL_FLAG_DISABLED) != 0; + _checked = (flags & CTL_FLAG_CHECKED) != 0; + _multiple = (flags & CTL_FLAG_MULTIPLE) != 0; + _focused = FALSE; + + creating = this; + ctl_flags = flags; + _win = xvtcm_create(id, left, top, right, bottom, + prop_count, (char**)prop_list, parent, + 0, 0, NULL, handler, set_creation_args); + CHECKD(_win, "Can't create control ", id); + + creating = NULL; + set_app_data(_win, app_data); + xvt_set_font(_win, FF_FIXED, bold ? FS_BOLD : 0); +} + + +// Virtual destructor needed to make derived descrutors live! +TControl::~TControl() +{} + + +long TControl::handler(WINDOW win, EVENT* ep) +{ + static bool tracking = FALSE; + static bool pressed = FALSE; + + if (ep->type == E_CREATE) + xvtcm_eh_start(win, ep); + + TControl** model = (TControl**)xvtcm_get_model(win, sizeof(TControl*)); + CHECK(model, "Can't get the model"); + + TControl*& cc = *model; + if (ep->type == E_CREATE) + { + CHECK(creating, "Can't create a NULL control"); + cc = creating; + } + CHECK(cc, "Can't handle a NULL control"); + + if (creating == NULL) switch(ep->type) + { + case E_FOCUS: + cc->focus((bool)ep->v.active); + case E_UPDATE: + cc->update(); + break; + case E_MOUSE_DOWN: + trap_mouse(win); + tracking = pressed = TRUE; + cc->mouse_down(ep->v.mouse.where); + break; + case E_CHAR: + { + const KEY key = e_char_to_key(ep); + switch(key) + { + case K_SPACE: + cc->mouse_up(); + break; + default: + dispatch_e_char(get_parent(win), key); + break; + } + } + break; + case E_MOUSE_MOVE: + if (tracking) + { + RCT r; + get_client_rect(win, &r); + if (pt_in_rect(&r, ep->v.mouse.where)) + { + if (!pressed) + { + cc->mouse_down(ep->v.mouse.where); + pressed = TRUE; + } + } + else + { + if (pressed) + { + cc->update(); + pressed = FALSE; + } + } + } + break; + case E_MOUSE_UP: + if (tracking) + { + release_mouse(); + tracking = FALSE; + if (pressed) + { + cc->mouse_up(); + pressed = FALSE; + } + } + break; + case E_DESTROY: + delete *model; + *model = NULL; + xvtcm_eh_end(win, ep); + break; + default: + break; + } + + return 0L; +} + +void TControl::enable(bool on) +{ + if (on == disabled()) + { + _disabled = !on; + update(); + enable_window(win(), on); + } +} + +void TControl::check(bool on) +{ + _checked = on; +} + +void TControl::update() const +{ + if (_win != _hdc) + get_geometry(_win); + clear_window(_hdc, MASK_BACK_COLOR); + win_set_fore_color(_hdc, disabled() ? COLOR_GRAY : COLOR_BLACK); +} + +/////////////////////////////////////////////////////////// +// TText +/////////////////////////////////////////////////////////// + +class TText : public TControl +{ +protected: + virtual WIN_TYPE type() const { return WC_TEXT; } + virtual void update() const; + +public: + TText(short left, short top, short right, short bottom, + const char* caption, WINDOW parent, + long flags, long app_data, short id); +}; + +TText::TText(short left, short top, short right, short bottom, + const char* caption, WINDOW parent, + long flags, long app_data, short id) +{ + create(left, top+1, right, bottom-1, caption, parent, flags, app_data, id); +} + +void TText::update() const +{ + TControl::update(); + win_set_fore_color(_hdc, COLOR_BLACK); + win_draw_text(_hdc, _client.left, _client.top+BASEY, (char*)caption(), -1); +} + +/////////////////////////////////////////////////////////// +// TGroup +/////////////////////////////////////////////////////////// + +class TGroup : public TText +{ +protected: + virtual WIN_TYPE type() const { return WC_GROUPBOX; } + virtual void update() const; + void draw_round_rect(const RCT& r, COLOR c) const; + +public: + TGroup(short left, short top, short right, short bottom, + const char* caption, WINDOW parent, + long flags, long app_data, short id); +}; + +TGroup::TGroup(short left, short top, short right, short bottom, + const char* caption, WINDOW parent, + long flags, long app_data, short id) +: TText(left, top, right, bottom, caption, parent, flags | CTL_FLAG_DISABLED, app_data, + (id < 0) ? -2 : id) +{} + +void TGroup::draw_round_rect(const RCT& r, COLOR c) const +{ + CPEN pen; + pen.width = 2; + pen.pat = PAT_SOLID; + pen.style = P_SOLID; + pen.color = c; + win_set_cpen(_hdc, &pen); + + CBRUSH brush = { PAT_HOLLOW, MASK_BACK_COLOR }; + win_set_cbrush(_hdc, &brush); + win_draw_roundrect(_hdc, (RCT*)&r, ROWY, ROWY); +} + +void TGroup::update() const +{ + TText::update(); + + RCT r = _client; + r.top += CHARY; + r.right-=4; r.bottom-=ROWY/2; + if (multiple()) + { + r.left++; r.top++; r.right--; r.bottom--; + draw_round_rect(r, COLOR_BLUE); + } + else + { + xvt_draw_rect(_hdc, r, COLOR_GRAY, MASK_COLOR); + } +} + +/////////////////////////////////////////////////////////// +// Button +/////////////////////////////////////////////////////////// + +class TButton : public TControl +{ +protected: + enum { DEPTH = 2 }; + + virtual WIN_TYPE type() const { return WC_PUSHBUTTON; } + virtual void update() const; + virtual void mouse_down(PNT where); + virtual void mouse_up(); + virtual void check(bool on); + virtual void draw_pressed(bool pressed) const; + +public: + TButton(short left, short top, short right, short bottom, + const char* caption,WINDOW parent, + long flags, long app_data, short id); +}; + + +TButton::TButton(short left, short top, short right, short bottom, + const char* caption, WINDOW parent, + long flags, long app_data, short id) +{ + create(left, top, right, bottom, caption, parent, flags, app_data, id); +} + + +void TButton::draw_pressed(bool pressed) const +{ + get_geometry(win()); + + clear_window(_hdc, COLOR_LTGRAY); + RCT r = _client; + xvt_draw_rect(_hdc, r, COLOR_BLACK, COLOR_BLACK); + + COLOR lt = pressed ? COLOR_GRAY : COLOR_WHITE; + COLOR rb = pressed ? COLOR_LTGRAY : COLOR_GRAY; + + for (int i = DEPTH; i--;) + { + r.left++; r.top++; r.right--; r.bottom--; + xvt_draw_rect(_hdc, r, lt, rb); + if (i == 1) lt = COLOR_LTGRAY; + } +} + + +void TButton::update() const +{ + TControl::update(); + draw_pressed(checked()); +} + +void TButton::mouse_down(PNT) +{ + draw_pressed(!checked()); +} + +void TButton::mouse_up() +{ + draw_pressed(checked()); + + EVENT e; // Notification message + e.type = E_CONTROL; + e.v.ctl.id = id(); + e.v.ctl.ci.type = type(); + e.v.ctl.ci.win = win(); + dispatch_event(get_parent(win()), &e); +} + +void TButton::check(bool on) +{ + TControl::check(on); + draw_pressed(on); +} + +/////////////////////////////////////////////////////////// +// TPush button +/////////////////////////////////////////////////////////// + +class TPush_button : public TButton +{ + PICTURE _picup, _picdn; + byte _dx, _dy; + int _accel; + +protected: + void draw_pressed(bool pressed) const; + void update() const; + +public: + TPush_button(short left, short top, short right, short bottom, + const char* caption, WINDOW parent, + long flags, long app_data, short id); + virtual ~TPush_button(); +}; + +TPush_button::TPush_button(short left, short top, short right, short bottom, + const char* capt, WINDOW parent, + long flags, long app_data, short id) +: TButton(left-(id == DLG_F9), top, right, bottom, + capt, parent, flags, app_data, id), + _picup(0L), _picdn(0L) +{ + switch(id) + { + + case DLG_OK: + if (strcmp("Conferma", caption()) == 0) + capt = format("#%d", BMP_OK); + break; + case DLG_CANCEL: + if (strcmp("Annulla", caption()) == 0) + capt = format("#%d", BMP_CANCEL); + break; + case DLG_QUIT: + capt = format("#%d#%d", BMP_QUIT, BMP_QUITDN); + break; + case DLG_SELECT: + capt = format("#%d", BMP_SELECT); + break; + case DLG_DELREC: + capt = format("#%d#%d", BMP_DELREC, BMP_DELRECDN); + break; + case DLG_NEWREC: + if (strcmp("Nuovo", caption()) == 0) // Puo' essere Gestione + capt = format("#%d#%d", BMP_NEWREC, BMP_NEWRECDN); + break; + case DLG_STOPREC: + capt = format("#%d", BMP_STOPREC); + break; + /* + case DLG_FIRSTREC: + capt = format("#%d", BMP_FIRSTREC); + break; + case DLG_PREVREC: + capt = format("#%d", BMP_PREVREC); + break; + case DLG_NEXTREC: + capt = format("#%d", BMP_NEXTREC); + break; + case DLG_LASTREC: + capt = format("#%d", BMP_LASTREC); + break; + */ + case DLG_SAVEREC: + capt = format("#%d#%d", BMP_SAVEREC, BMP_SAVERECDN); + break; + case DLG_FINDREC: + capt = format("#%d", BMP_FINDREC); + break; + case DLG_F9: + capt = format("#%d", BMP_SEARCH); + break; + case DLG_LINK: + capt = format("#%d", BMP_LINK); + break; + case DLG_EDIT: + capt = format("#%d", BMP_EDIT); + break; + case DLG_PRINT: + capt = format("#%d", BMP_PRINT); + break; + case DLG_SETPRINT: + capt = format("#%d", BMP_SETPRINT); + break; + default: + break; + } + + const int height = bottom-top; + const int width = right-left; + + const char* diesis = strchr(capt, '#'); + if (diesis != NULL) + { + int pid = atoi(++diesis); + _picup = cpb.getbmp(pid); + diesis = strchr(diesis, '#'); + if (diesis != NULL) + { + pid = atoi(++diesis); + _picdn = cpb.getbmp(pid); + } + + RCT r; + cpb_get_picture_size(_picup, &r); + _dx = byte((width-r.right+1) >> 1); + _dy = byte((height-r.bottom) >> 1); + _accel = -1; + } + else + { + TFixed_string c(capt); + _accel = c.find('~'); + if (_accel > 0) + _accel *= CHARX; + + _dx = (width - win_get_text_width(win(), (char*)caption(), -1)) >> 1; + _dy = byte((height-CHARY)/2 + BASEY - DEPTH); + } +} + +TPush_button::~TPush_button() +{ +} + +void TPush_button::draw_pressed(bool pressed) const +{ + TButton::draw_pressed(pressed); + + const int p = pressed ? DEPTH : 0; + if (_picup) + { + const PICTURE pic = (pressed && _picdn) ? _picdn : _picup; + cpb_win_picture_draw_at(_hdc, pic, _dx+p, _dy+p); + } + else + { + const char* t = caption(); + + win_set_fore_color(_hdc, COLOR_WHITE); + win_draw_text(_hdc, _dx+p+1, _dy+p+1, (char*)t, -1); + if (_accel >= 0) + win_draw_text(_hdc, _dx+_accel+p+1, _dy+p+3, "_", 1); + + const COLOR c = disabled() ? DISABLED_COLOR : NORMAL_COLOR; + win_set_fore_color(_hdc, c); + win_draw_text(_hdc, _dx+p, _dy+p, (char*)t, -1); + if (_accel >= 0) + win_draw_text(_hdc, _dx+_accel+p, _dy+p+2, "_", 1); + } +} + +void TPush_button::update() const +{ + draw_pressed(FALSE); + if (focused() && id() != DLG_F9) + { + CPEN pen; + pen.width = 1; + pen.pat = PAT_SOLID; + pen.style = P_SOLID; + pen.color = COLOR_RED; + win_set_cpen(_hdc, &pen); + CBRUSH brush = { PAT_HOLLOW, COLOR_WHITE }; + win_set_cbrush(_hdc, &brush); + win_draw_rect(_hdc, &_client); + } else + if (disabled() && _picup) + { + CPEN pen; + pen.width = 1; + pen.pat = PAT_SOLID; + pen.style = P_SOLID; + pen.color = COLOR_LTGRAY; + win_set_cpen(_hdc, &pen); + + const int sx = _client.left+DEPTH+1; + const int sy = _client.top+DEPTH+1; + const int ex = _client.right-DEPTH-1; + const int ey = _client.bottom-DEPTH-1; + + for (int i = sx; i < ex; i += 2) + { + PNT p = { sy, i }; + win_move_to(_hdc, p); + p.v = ey; + win_draw_line(_hdc, p); + } + for (i = sy; i < ey; i += 2) + { + PNT p = { i, sx }; + win_move_to(_hdc, p); + p.h = ex; + win_draw_line(_hdc, p); + } + } +} + +/////////////////////////////////////////////////////////// +// TPage_button +/////////////////////////////////////////////////////////// + +class TPage_button : public TControl +{ + enum { height = 19, width2 = 16, width = 32 }; + byte _flag; + +protected: + virtual void update() const; + virtual void mouse_down(PNT where); + virtual void mouse_up(); + +public: + TPage_button(WINDOW parent, byte flag); + byte get_flag() const { return _flag; } + void set_flag(byte f); +}; + +TPage_button::TPage_button(WINDOW parent, byte flag) : _flag(flag) +{ + RCT r; get_client_rect(parent, &r); + const int w = (flag == 3) ? width : width2; + if (flag == 2) r.right -= w; + + create(r.right-w, r.bottom-height, r.right, r.bottom, + "", parent, 0L, 0L, DLG_PAGE); + cpb.getbmp(BMP_BOOK1 + flag -1, flag == 3); +} + +void TPage_button::mouse_down(PNT where) +{ + bool p; + switch (_flag) + { + case 1: + p = FALSE; break; + case 2: + p = TRUE; + default: + p = where.h < (width2); break; + } + check(p); +} + +void TPage_button::mouse_up() +{ + dispatch_e_char(get_parent(win()), checked() ? K_PREV : K_NEXT); +} + +void TPage_button::update() const +{ + TControl::update(); + if (_flag) + cpb_win_picture_draw_at(_hdc, cpb[BMP_BOOK1 + _flag -1], 0, 0); +} + +void TPage_button::set_flag(byte f) +{ + _flag = f; + update(); +} + +/////////////////////////////////////////////////////////// +// TTag_button +/////////////////////////////////////////////////////////// + +class TTag_button : public TControl +{ + enum { height = 12, width = 32 }; + byte _curr; + byte _page; + byte _pages; + + WINDOW _parent; + +protected: + virtual void update() const; + virtual void mouse_down(PNT where); + virtual void mouse_up(); + +public: + TTag_button(WINDOW parent, byte p, byte tot); + byte get_pages() const { return _pages; } + void set_pages(byte p); +}; + +TTag_button::TTag_button(WINDOW parent, byte p, byte tot) +: _parent(parent), _page(p), _pages(tot), _curr(p) +{ + RCT r; get_client_rect(parent, &r); + create(0, 0, r.right, CHARY, "", parent,0L,0L, DLG_PAGETAGS); +} + +void TTag_button::update() const +{ + get_geometry(win()); + clear_window(_hdc, COLOR_GRAY); + + for (int i = 0; i < _pages; i++) + { + RCT r; set_rect(&r, width*i, 0, width*(i+1), _client.bottom+4); + CBRUSH b = { PAT_SOLID, (i == _page) ? MASK_BACK_COLOR : COLOR_GRAY }; + win_set_cbrush(_hdc, &b); + win_set_std_cpen(_hdc, TL_PEN_BLACK); + win_draw_rect(_hdc, &r); + + if (i == _page) + xvt_draw_rect(_hdc, r, MASK_COLOR, COLOR_GRAY); + + char n[4]; sprintf(n, "%d", i+1); + win_draw_text(_hdc, (width-CHARX)/2 + i*width, BASEY, n, -1); + } + + CPEN pen; + pen.width = 1; + pen.pat = PAT_SOLID; + pen.style = P_SOLID; + pen.color = MASK_COLOR; + win_set_cpen(_hdc, &pen); + + PNT p = { _client.bottom, 0 }; + win_move_to(_hdc, p); + p.h = width*_page; + win_draw_line(_hdc, p); + p.h += width+1; + win_move_to(_hdc, p); + p.h = _client.right; + win_draw_line(_hdc, p); +} + +void TTag_button::mouse_down(PNT where) +{ + _curr = where.h / width; + if (_curr >= _pages) _curr = _pages-1; else + if (_curr < 0) _curr = 0; +} + +void TTag_button::mouse_up() +{ + if (_curr != _page) + dispatch_e_char(_parent, K_CTRL + K_F1 + _curr); +} + +void TTag_button::set_pages(byte p) +{ + _pages = p; + update(); +} + +/////////////////////////////////////////////////////////// +// Checkbox +/////////////////////////////////////////////////////////// + +class TCheckbox : public TButton +{ + static int _dy; + +protected: + virtual WIN_TYPE type() const; + virtual void draw_pressed(bool pressed) const; + virtual void update() const; + + int radio() const { return multiple() ? 1 : 0; } + +public: + TCheckbox(short left, short top, short right, short bottom, + const char* caption, WINDOW parent, + long flags, long app_data, short id); + virtual ~TCheckbox(); +}; + +int TCheckbox::_dy = -1; + +TCheckbox::TCheckbox( + short left, short top, short right, short bottom, + const char* caption, WINDOW parent, + long flags, long app_data, short id) +: TButton(left, top, right, bottom, + caption, parent, flags, app_data, id) +{ + if (_dy < 0) + { + cpb.getbmp(BMP_CHECK_ON, TRUE); + cpb.getbmp(BMP_CHECK_OFF, TRUE); + cpb.getbmp(BMP_RADIO_ON, TRUE); + PICTURE p = cpb.getbmp(BMP_RADIO_OFF, TRUE); + + RCT r; + cpb_get_picture_size(p, &r); + _dy = BASEY - r.bottom + 2; + } +} + + +TCheckbox::~TCheckbox() +{ +} + + +WIN_TYPE TCheckbox::type() const +{ + return multiple() ? WC_RADIOBUTTON : WC_CHECKBOX; +} + + +void TCheckbox::draw_pressed(bool pressed) const +{ + get_geometry(win()); + PICTURE pic; + if (radio()) + pic = pressed ? cpb[BMP_RADIO_ON] : cpb[BMP_RADIO_OFF]; + else + pic = pressed ? cpb[BMP_CHECK_ON] : cpb[BMP_CHECK_OFF]; + cpb_win_picture_draw_at(_hdc, pic, _client.left, _client.top+_dy); +} + + +void TCheckbox::update() const +{ + TButton::update(); + + const int x = _client.left+20; + const int y = _client.top + BASEY; + + if (focused()) + { +#if XVT_OS == XVT_OS_WIN + RECT r; + r.left = x-2; r.top = _client.top; + r.right = _client.right-CHARX; r.bottom = y+3; + + HWND hwnd = (HWND)get_value(_hdc, ATTR_NATIVE_WINDOW); + HDC hdc = GetDC(hwnd); + DrawFocusRect(hdc, &r); + ReleaseDC(hwnd, hdc); +#endif + } + + win_draw_text(_hdc, x, y, (char*)caption(), -1); +} + +/////////////////////////////////////////////////////////// +// User functions +/////////////////////////////////////////////////////////// + +WINDOW xvt_create_checkbox( + short left, short top, short right, short bottom, + const char* caption, + WINDOW parent, + long flags, + long app_data, + int id) +{ + TCheckbox* cb = new TCheckbox(left, top, right, bottom, + caption, parent, + flags, app_data, id); + + // It'll destroy itself automagically :-) + + return cb->win(); +} + +WINDOW xvt_create_radiobutton( + short left, short top, short right, short bottom, + const char* caption, + WINDOW parent, + long flags, + long app_data, + int id) +{ + flags |= CTL_FLAG_MULTIPLE; + TCheckbox* cb = new TCheckbox(left, top, right, bottom, + caption, parent, + flags, app_data, id); + + // It'll destroy itself automagically :-) + return cb->win(); +} + + +WINDOW xvt_create_pushbutton( + short left, short top, short right, short bottom, + const char* caption, + WINDOW parent, + long flags, + long app_data, + int id) +{ + TControl* pb; + + switch (id) + { + case DLG_PAGE: + pb = new TPage_button(parent, (byte)flags); + break; + case DLG_PAGETAGS: + pb = new TTag_button(parent, (byte)flags, (byte)app_data); + break; + default: + if (bottom-top > (CHARY<<1)) + { + top += BASEY>>1; + bottom -= BASEY>>1; + } + pb = new TPush_button(left, top, right, bottom, + caption, parent, + flags, app_data, id); + } + + // It'll destroy itself automagically :-) + return pb->win(); +} + + +WINDOW xvt_create_text( + short left, short top, short right, short bottom, + const char* caption, + WINDOW parent, + long flags, + long app_data, + int id) +{ + TText* cb = new TText(left, top, right, bottom, + caption, parent, + flags, app_data, id); + // It'll destroy itself automagically :-) + return cb->win(); +} + + +WINDOW xvt_create_groupbox( + short left, short top, short right, short bottom, + const char* caption, + WINDOW parent, + long flags, + long app_data, + int id) +{ + TGroup* cb = new TGroup(left, top, right, bottom, + caption, parent, + flags, app_data, id); + // It'll destroy itself automagically :-) + return cb->win(); +} + + +void free_controls_bmp() +{ + cpb.reset(); +} + + +TControl* TControl::WINDOW2TControl(WINDOW win) +{ + TControl** model = (TControl**)xvtcm_get_model(win, 0); + CHECK(model && *model, "Can't get the model from a window"); + return *model; +} + +void xvt_change_page_tags(WINDOW pag, bool on, WINDOW tag, byte p) +{ + if (pag != NULL_WIN) + { + TPage_button* pb = (TPage_button*)TControl::WINDOW2TControl(pag); + byte f = pb->get_flag(); + if (on) f |= 0x1; + else f &= 0x2; + pb->set_flag(f); + } + + if (tag != NULL_WIN) + { + TTag_button* pt = (TTag_button*)TControl::WINDOW2TControl(tag); + pt->set_pages(p); + } +} + + diff --git a/include/defmask.h b/include/defmask.h index 9ef3b42a3..165cc357d 100755 --- a/include/defmask.h +++ b/include/defmask.h @@ -60,8 +60,9 @@ CHECK_FIELD esegue il check su di un altro campo campo FILENAME_FUNC controlla se la stringa e' un nome di file - ZEROFILL_FUNC riempie di zeri i numeri fino a n caratteri + ZEROFILL_FUNC riempie di zeri i numeri fino a n caratteri n.ro di caratteri + ALPHA_FUNC accetta solo caratteri alfabetici */ #define EXPR_FUNC 0 2 @@ -84,6 +85,7 @@ #define CHECK_FIELD 17 1 #define FILENAME_FUNC 18 0 #define ZEROFILL_FUNC 19 1 +#define ALPHA_FUNC 20 0 #define VALEXPR VALIDATE EXPR_FUNC #define NUM_EXPR VALEXPR 0 diff --git a/include/form.cpp b/include/form.cpp index 01699cd9a..7bfdbacad 100755 --- a/include/form.cpp +++ b/include/form.cpp @@ -152,6 +152,7 @@ public: void disable() { enable(FALSE); } TForm_item(TPrint_section* section); + virtual ~TForm_item() {} }; @@ -187,12 +188,11 @@ void TForm_item::print_on(ostream& out) const void TForm_item::print_body(ostream& out) const { + out << " KEY \"" << _desc << "\"\n"; + if (_y >= 0) out << " PROMPT " << _x << ' ' << _y << " \"" << _prompt << "\"\n"; - if (_desc.not_empty()) - out << " KEY \"" << _desc << "\"\n"; - if (_group.ones()) out << " GROUP " << _group << "\n"; @@ -466,6 +466,7 @@ protected: public: TForm_string(TPrint_section* section) : TForm_item(section) {} + virtual ~TForm_string() {} }; bool TForm_string::parse_item(TScanner& scanner) @@ -597,6 +598,7 @@ protected: public: TForm_number(TPrint_section* section) : TForm_string(section) {} + virtual ~TForm_number() {} }; @@ -634,6 +636,7 @@ protected: public: TForm_date(TPrint_section* section); + virtual ~TForm_date() {} }; @@ -678,6 +681,7 @@ protected: public: TForm_list(TPrint_section* section); + virtual ~TForm_list() {} }; TForm_list::TForm_list(TPrint_section* section) @@ -792,6 +796,21 @@ bool TForm_list::update() return ok; } +/////////////////////////////////////////////////////////// +// TForm_group +/////////////////////////////////////////////////////////// + +class TForm_group : public TForm_item +{ +protected: + virtual const char* class_name() const { return "GRUPPO"; } + virtual bool parse_head(TScanner&) { return TRUE; } + virtual bool update() { return TRUE; } + +public: + TForm_group(TPrint_section* section) : TForm_item(section) {}; + virtual ~TForm_group() {} +}; /////////////////////////////////////////////////////////// // TPrint_section @@ -840,6 +859,8 @@ TForm_item* TPrint_section::parse_item(const TString& s) return new TForm_date(this); if (s == "LI") return new TForm_list(this); + if (s == "GR") + return new TForm_group(this); CHECKS(NULL, "Campo di stampa sconosciuto: ", (const char*)s); return NULL; diff --git a/include/mask.cpp b/include/mask.cpp index c1dab76b9..c427c25e4 100755 --- a/include/mask.cpp +++ b/include/mask.cpp @@ -119,11 +119,7 @@ void TMask::handler(WINDOW win, EVENT* ep) { clear_window(win, MASK_BACK_COLOR); RCT r; get_client_rect(win, &r); -#ifdef __CTL3D__ - xvt_draw_rect(win, r, COLOR_WHITE, COLOR_GRAY, 1); -#else - xvt_draw_rect(win, r, COLOR_CYAN, COLOR_GRAY, 1); -#endif + xvt_draw_rect(win, r, MASK_COLOR, COLOR_GRAY, 1); } else clear_window(win, COLOR_GRAY); #else diff --git a/include/maskfld.cpp b/include/maskfld.cpp index 366cf9ffd..7c249d365 100755 --- a/include/maskfld.cpp +++ b/include/maskfld.cpp @@ -1,4 +1,4 @@ -// $Id: maskfld.cpp,v 1.65 1994-12-28 11:01:21 guy Exp $ +// $Id: maskfld.cpp,v 1.66 1995-01-02 09:32:42 guy Exp $ #include #include @@ -532,7 +532,7 @@ HIDDEN void modify_list(bool add, TMask_field& f, TToken_string& msg) } -// Certified 90% +// Certified 99% HIDDEN const char* copy_value(TToken_string& msg, const TString& val) { int from = msg.get_int()-1; @@ -542,6 +542,30 @@ HIDDEN const char* copy_value(TToken_string& msg, const TString& val) return val.sub(from, to); } +HIDDEN void run_app(const TMask& mask, TToken_string& msg) +{ + TFilename a(msg.get(1)); + + for (const char* m = msg.get(); m; m = msg.get()) + { + a << ' '; + for (const char* f = m; f; f++) + { + if (*f == '#') + { + const int id = atoi(++f); + a << mask.get(id); + break; + } + else + a << *f; + } + } + TExternal_app app(a); + app.run(); +} + + void TMask_field::send_key(KEY k, short to) { mask().send_key(k, to, this); @@ -551,7 +575,7 @@ void TMask_field::send_key(KEY k, short to) // Certified 90% bool TMask_field::do_message(int num) { - const int MAX_CMD = 14; + const int MAX_CMD = 15; static const char* commands[MAX_CMD] = { "ADD", // 0 @@ -566,8 +590,9 @@ bool TMask_field::do_message(int num) "HIDE", // 9 "PUSH", // 10 "RESET", // 11 - "SHOW", // 12 - "UNDO" // 13 + "RU", // 12 + "SHOW", // 13 + "UNDO" // 14 }; TToken_string* message = (TToken_string*)_message.objptr(num); @@ -607,7 +632,13 @@ bool TMask_field::do_message(int num) { mask().stop_run(atoi(dlg)); continue; - } + } else + if (cmd == 12) + { + run_app(mask(), msg); + continue; + } + short fld = (dlg && dlg[0] > ' ') ? atodlg(dlg) : 0; bool broadcast = dlg && strchr(dlg, '@'); @@ -636,9 +667,9 @@ bool TMask_field::do_message(int num) key = K_SPACE; break; case 11: key = K_F2; break; - case 12: - key = 11000+'s'; break; case 13: + key = 11000+'s'; break; + case 14: key = K_F3; break; default: key = atoi(value); @@ -774,6 +805,7 @@ bool TMask_field::on_key(KEY key) message_box(_help); else beep(); + set_focus(); break; case K_F2: if (is_edit()) set(""); diff --git a/include/prassi.ver b/include/prassi.ver index d92bb8775..a7057f176 100755 --- a/include/prassi.ver +++ b/include/prassi.ver @@ -1 +1 @@ -#define VERSION 1.2 +#define VERSION 1.3 diff --git a/include/relapp.cpp b/include/relapp.cpp index 148335c78..e88084dcb 100755 --- a/include/relapp.cpp +++ b/include/relapp.cpp @@ -1,4 +1,4 @@ -// $Id: relapp.cpp,v 1.41 1994-12-27 14:59:08 guy Exp $ +// $Id: relapp.cpp,v 1.42 1995-01-02 09:32:49 guy Exp $ #include #include #include @@ -794,7 +794,10 @@ bool TRelation_application::main_loop() if (relation_remove()) query_mode(); if (_autoins_caller.not_empty()) + { + if (_lnflag) _recins = 0; k = K_QUIT; + } break; case K_F9: if (save(TRUE)) diff --git a/include/sheet.cpp b/include/sheet.cpp index 58855ddfa..b5243b897 100755 --- a/include/sheet.cpp +++ b/include/sheet.cpp @@ -699,15 +699,15 @@ TBrowse_sheet::TBrowse_sheet(TCursor* cursor, const char* fields, : TCursor_sheet(cursor, fields, title, head, buttons), _field(f) { - if (field().browse()->inputs() == 1) - { -#if XVT_OS == XVT_OS_WIN - xvt_create_control(WC_EDIT, 1, -3, f->size()+1, 1, f->get(), win(), - CTL_FLAG_DISABLED, 0L, 100); -#else - xvt_create_control(WC_EDIT, 1, -3, f->size()+2, 1, f->get(), win(), - CTL_FLAG_DISABLED, 0L, 100); + if (field().browse()->inputs() == 1 && cursor->items() > 0) + { +#if XVT_OS == XVT_OS_SCOUNIX + const int s = f->size()+2; +#else + const int s = f->size()+1; #endif + xvt_create_control(WC_EDIT, 1, -3, s, 1, f->get(), win(), + CTL_FLAG_DISABLED, 0L, 100); } if (s && s->items() > 2) @@ -844,7 +844,7 @@ KEY TBrowse_sheet::run() const KEY key = TCursor_sheet::run(); - if (key == K_ESC || key == K_F9 || key == K_INS) + if (key == K_ESC || key == K_INS || key >= K_CTRL) { field().set(old); // Restore field status field().set_dirty(spork); diff --git a/include/validate.cpp b/include/validate.cpp index 6da567cfa..132a26233 100755 --- a/include/validate.cpp +++ b/include/validate.cpp @@ -593,7 +593,20 @@ HIDDEN bool _zerofill_val(TEdit_field& f, KEY k) return TRUE; } -#define MAX_FUNC 20 +HIDDEN bool _alpha_val(TEdit_field& f, KEY k) +{ + if (f.to_check(k)) + { + const TString& s = f.get(); + for (int i = 0; s[i]; i++) + if (!isalpha(s[i])) + return error_box("Sono ammessi solo caratteri alfabetici"); + } + return TRUE; +} + + +#define MAX_FUNC 21 HIDDEN VAL_FUNC _global_val_func[MAX_FUNC] = { @@ -616,7 +629,8 @@ HIDDEN VAL_FUNC _global_val_func[MAX_FUNC] = _onereq_val, _chkfld_val, _filename_val, - _zerofill_val + _zerofill_val, + _alpha_val }; bool validate(int fn, TEdit_field& f, KEY k, const TArray& parms) diff --git a/include/window.cpp b/include/window.cpp index 2886e5caa..d1c7f307e 100755 --- a/include/window.cpp +++ b/include/window.cpp @@ -196,7 +196,8 @@ long TWindow::window_handler(WINDOW win, EVENT* ep) WINDOW TWindow::create(short x, short y, short dx, short dy, - const char* title, long flags, WIN_TYPE wt, WINDOW parent) + const char* title, long flags, WIN_TYPE wt, + WINDOW parent, int menu) { flags |= WSF_NO_MENUBAR; @@ -206,8 +207,9 @@ WINDOW TWindow::create(short x, short y, short dx, short dy, _win = xvt_create_window( wt, x, y, dx, dy, - title, parent, - flags, + title, + menu, parent, + flags, window_handler, PTR_LONG(this) ); @@ -623,11 +625,11 @@ TScroll_window::TScroll_window() } WINDOW TScroll_window::create(short x, short y, short dx, short dy, - const char* title, long flags, WIN_TYPE wt, WINDOW parent) + const char* title, long flags, WIN_TYPE wt, WINDOW parent, int menu) { _has_hscroll = (flags & WSF_HSCROLL) != 0; _has_vscroll = (flags & WSF_VSCROLL) != 0 ; - return TWindow::create(x, y, dx, dy, title, flags, wt, parent); + return TWindow::create(x, y, dx, dy, title, flags, wt, parent, menu); } PNT TScroll_window::log2dev(long x, long y) const diff --git a/include/window.h b/include/window.h index 0da0c02e8..bcfc421a0 100755 --- a/include/window.h +++ b/include/window.h @@ -68,7 +68,7 @@ protected: static long window_handler(WINDOW win, EVENT* ep); virtual WINDOW create(short x, short y, short dx, short dy, const char* title = "", long flags = WSF_NONE, - WIN_TYPE rt = W_DOC, WINDOW parent = NULL_WIN) ; + WIN_TYPE rt = W_DOC, WINDOW parent = NULL_WIN, int menu = 0) ; void set_win(WINDOW w) { _win = w; } // Usare con cautela @@ -187,7 +187,8 @@ protected: // @FPROT virtual WINDOW create(short x, short y, short dx, short dy, const char* title = "", long flags = WSF_NONE, - WIN_TYPE rt = W_DOC, WINDOW parent = NULL_WIN) ; // Crea la finestra + WIN_TYPE rt = W_DOC, WINDOW parent = NULL_WIN, + int menu = 0) ; // Crea la finestra virtual PNT log2dev(long x, long y) const; virtual bool on_key(KEY key); diff --git a/include/xvtility.cpp b/include/xvtility.cpp index 63992c7bc..5b609de78 100755 --- a/include/xvtility.cpp +++ b/include/xvtility.cpp @@ -29,7 +29,7 @@ COLOR MASK_BACK_COLOR = COLOR_WHITE; COLOR NORMAL_COLOR = COLOR_BLACK; COLOR NORMAL_BACK_COLOR = COLOR_WHITE; COLOR DISABLED_COLOR = COLOR_GRAY; -COLOR DISABLED_BACK_COLOR = COLOR_WHITE; +COLOR DISABLED_BACK_COLOR = MASK_BACK_COLOR; COLOR FOCUS_COLOR = COLOR_BLACK; COLOR FOCUS_BACK_COLOR = COLOR_WHITE; @@ -74,30 +74,24 @@ HIDDEN HFONT NormalFont = NULL; HIDDEN LOGFONT LogFont; HIDDEN int FontWeight; -#ifdef __CTL3D__ -COLOR MASK_BACK_COLOR = COLOR_LTGRAY; -#else -COLOR MASK_BACK_COLOR = MAKE_COLOR(0,128,128); -#endif +COLOR MASK_COLOR = COLOR_CYAN; +COLOR MASK_BACK_COLOR = COLOR_DKCYAN; COLOR NORMAL_COLOR = COLOR_BLACK; COLOR NORMAL_BACK_COLOR = COLOR_LTGRAY; COLOR DISABLED_COLOR = COLOR_GRAY; COLOR DISABLED_BACK_COLOR = MASK_BACK_COLOR; +COLOR FOCUS_COLOR = NORMAL_COLOR; +COLOR FOCUS_BACK_COLOR = COLOR_CYAN; HIDDEN COLORREF MaskColor = COLOR2RGB(MASK_BACK_COLOR); -HIDDEN HBRUSH MaskBrush = CreateSolidBrush(MaskColor); - -HIDDEN COLORREF FocusForeColor = COLOR2RGB(COLOR_BLACK); -HIDDEN COLORREF FocusBackColor = COLOR2RGB(COLOR_CYAN); -HIDDEN HBRUSH FocusBrush = CreateSolidBrush(FocusBackColor); - -COLOR FOCUS_COLOR = RGB2COLOR(FocusForeColor); -COLOR FOCUS_BACK_COLOR = RGB2COLOR(FocusBackColor); - +HIDDEN HBRUSH MaskBrush = 0 ; HIDDEN COLORREF NormalForeColor = COLOR2RGB(NORMAL_COLOR); HIDDEN COLORREF NormalBackColor = COLOR2RGB(NORMAL_BACK_COLOR); -HIDDEN HBRUSH NormalBrush = CreateSolidBrush(NormalBackColor); +HIDDEN HBRUSH NormalBrush = 0; +HIDDEN COLORREF FocusForeColor = COLOR2RGB(FOCUS_COLOR); +HIDDEN COLORREF FocusBackColor = COLOR2RGB(FOCUS_BACK_COLOR); +HIDDEN HBRUSH FocusBrush = 0; const word WM_WAKEUP = RegisterWindowMessage("WAKEUP"); @@ -493,7 +487,18 @@ void dispatch_e_scroll(WINDOW win, KEY key) } void customize_controls(bool on) -{ +{ + TConfig colors(CONFIG_GENERAL, "Colors"); + + MASK_COLOR = colors.get_color("Mask", NULL, -1, MASK_COLOR); + MASK_BACK_COLOR = colors.get_color("MaskBack", NULL, -1, MASK_BACK_COLOR); + NORMAL_COLOR = colors.get_color("Normal", NULL, -1, NORMAL_COLOR); + NORMAL_BACK_COLOR = colors.get_color("NormalBack", NULL, -1, NORMAL_BACK_COLOR); + DISABLED_COLOR = colors.get_color("Disabled", NULL, -1, DISABLED_COLOR); + DISABLED_BACK_COLOR = colors.get_color("DisabledBack", NULL, -1, DISABLED_BACK_COLOR); + FOCUS_COLOR = colors.get_color("Focus", NULL, -1, FOCUS_COLOR); + FOCUS_BACK_COLOR = colors.get_color("FocusBack", NULL, -1, FOCUS_BACK_COLOR); + #if XVTWS == WMWS if (on) { @@ -512,6 +517,17 @@ void customize_controls(bool on) HINSTANCE _hInstance = (HINSTANCE)get_value(NULL_WIN, ATTR_WIN_INSTANCE); Ctl3dRegister(_hInstance); Ctl3dAutoSubclass(_hInstance); +#else + MaskColor = COLOR2RGB(MASK_BACK_COLOR); + MaskBrush = CreateSolidBrush(MaskColor); + + NormalForeColor = COLOR2RGB(NORMAL_COLOR); + NormalBackColor = COLOR2RGB(NORMAL_BACK_COLOR); + NormalBrush = CreateSolidBrush(NormalBackColor); + + FocusForeColor = COLOR2RGB(FOCUS_COLOR); + FocusBackColor = COLOR2RGB(FOCUS_BACK_COLOR); + FocusBrush = CreateSolidBrush(FocusBackColor); #endif } else @@ -519,11 +535,12 @@ void customize_controls(bool on) #ifdef __CTL3D__ HINSTANCE _hInstance = (HINSTANCE)get_value(NULL_WIN, ATTR_WIN_INSTANCE); Ctl3dUnregister(_hInstance); -#endif +#else DeleteObject(NormalFont); DeleteObject(MaskBrush); DeleteObject(NormalBrush); DeleteObject(FocusBrush); +#endif free_controls_bmp(); } #endif @@ -547,9 +564,6 @@ void xvt_init_font() LogFont.lfWidth = (int)font.get_long("Width"); LogFont.lfWeight = FontWeight = (int)font.get_long("Weight"); LogFont.lfCharSet = (int)font.get_long("CharSet"); - // LogFont.lfClipPrecision = (int)font.get_long("Clip"); - // LogFont.lfOutPrecision = (int)font.get_long("Precision"); - // LogFont.lfQuality = (int)font.get_long("Quality");; LogFont.lfPitchAndFamily = (int)font.get_long("Pitch"); strcpy(LogFont.lfFaceName, font.get("Name")); } @@ -603,8 +617,11 @@ void xvt_set_font(WINDOW win, int family, int style, int dim) WINDOW xvt_create_window(WIN_TYPE wt, short x, short y, short dx, short dy, - const char* caption, WINDOW parent, - long flags, EVENT_HANDLER eh, long app_data + const char* caption, + int menu, + WINDOW parent, + long flags, + EVENT_HANDLER eh, long app_data ) { RCT& rect = resize_rect(x, y, dx, dy, wt, parent); @@ -613,7 +630,7 @@ WINDOW xvt_create_window(WIN_TYPE wt, WINDOW win = create_window(wt, &rect, (char*)caption, - 0, parent, + menu, parent, flags, EM_ALL, eh, app_data); @@ -930,14 +947,19 @@ PAT_STYLE trans_brush(char p) } PEN_STYLE trans_pen(char p) -{ +{ + PEN_STYLE ps = P_SOLID; switch (p) { - case 'n' : return P_SOLID; break; - case '.' : return P_DOT; break; - case '-' : return P_DASH; break; - default: CHECK(0,"trans_pen: Undefined pattern"); break; - } - return P_SOLID; + case 'n' : + ps = P_SOLID; break; + case '.' : + ps = P_DOT; break; + case '-' : + ps = P_DASH; break; + default: + CHECK(0, "trans_pen: Undefined pattern"); break; + } + return ps; } diff --git a/include/xvtility.h b/include/xvtility.h index 7f5030f27..6aa49cd1b 100755 --- a/include/xvtility.h +++ b/include/xvtility.h @@ -23,7 +23,8 @@ WINDOW xvt_create_window ( WIN_TYPE wt, short x, short y, short dx, short dy, - const char* caption, WINDOW parent, + const char* caption, + int menu, WINDOW parent, long flags, EVENT_HANDLER eh, long app_data @@ -61,6 +62,7 @@ WINDOW xvt_create_window void xvt_check_radio_button(WINDOW win, const WINDOW* ctls, int count); int xvt_get_checked_radio(const WINDOW* ctls, int count); void xvt_change_page_tags(WINDOW pag, bool on, WINDOW tag, byte p); + PICTURE xvt_picture_load(short id, bool convert_colors = FALSE); bool xvt_test_menu_tag(MENU_TAG tag);