campo-sirio/include/xvtility.cpp
guy 4e3cc536f6 Correzioni per ripresa del focus dopo il lancio una applicazione o la pressione
di un bottone di una maschera in uno sheet


git-svn-id: svn://10.65.10.50/trunk@2257 c028cbd2-c16b-5b4b-a496-9718f37d4682
1995-12-07 11:14:10 +00:00

1256 lines
33 KiB
C++
Executable File

#include <applicat.h>
#include <colors.h>
#include <config.h>
#include <date.h>
#include <urldefid.h>
#include <utility.h>
#include <mask.h>
#if XVT_OS == XVT_OS_SCOUNIX
extern "C" { long nap(long period); }
#endif
// @doc EXTERNAL
// ERROR HOOK che intercetta errori XVT
// put breakpoint here
BOOLEAN error_hook(XVT_ERRMSG err, DATA_PTR)
{
const XVT_ERRSEV sev = xvt_errmsg_get_sev_id(err);
#ifdef DBG
return FALSE;
#else
return sev < SEV_ERROR;
#endif
}
HIDDEN XVT_FNTID DEF_FONT = NULL;
HIDDEN XVT_FNTID FAT_FONT = NULL;
#if XVTWS == WMWS
short CHARX = 8;
short CHARY = 8;
short BASEY = 8;
short ROWY = 8;
COLOR MASK_BACK_COLOR = COLOR_WHITE;
COLOR MASK_LIGHT_COLOR = COLOR_WHITE;
COLOR MASK_DARK_COLOR = COLOR_BLUE;
COLOR NORMAL_COLOR = COLOR_BLACK;
COLOR NORMAL_BACK_COLOR = COLOR_WHITE;
COLOR DISABLED_COLOR = COLOR_GRAY;
COLOR DISABLED_BACK_COLOR = MASK_BACK_COLOR;
COLOR FOCUS_COLOR = COLOR_BLACK;
COLOR FOCUS_BACK_COLOR = COLOR_WHITE;
#else
#include <windows.h>
#include <ctl3d.h>
HIDDEN COLORREF COLOR2RGB(COLOR c)
{
const byte red = byte((c >> 16) & 0xFF);
const byte gre = byte((c >> 8) & 0xFF);
const byte blu = byte(c & 0xFF);
return RGB(red, gre, blu);
}
HIDDEN COLOR RGB2COLOR(COLORREF c)
{
const byte red = byte(c & 0xFF);
const byte gre = byte((c >> 8) & 0xFF);
const byte blu = byte((c >> 16) & 0xFF);
return XVT_MAKE_COLOR(red, gre, blu);
}
#ifndef XVT_CALLCONV1
#define XVT_CALLCONV1
#endif
extern "C" {
WINDOW XVT_CALLCONV1 xvtwi_hwnd_to_window(HWND);
#include <statbar.h>
}
#include <controls.h>
short CHARX = 8;
short ROWY = GetSystemMetrics(SM_CYSCREEN) / 25;
short CHARY = 14;
short BASEY = 12;
HIDDEN HFONT NormalFont = NULL;
HIDDEN LOGFONT LogFont;
HIDDEN int FontWeight;
COLOR MASK_BACK_COLOR = COLOR_DKCYAN;
COLOR MASK_LIGHT_COLOR = COLOR_CYAN;
COLOR MASK_DARK_COLOR = COLOR_GRAY;
COLOR TOOL_BACK_COLOR = COLOR_GRAY;
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 = 0 ;
HIDDEN COLORREF NormalForeColor = COLOR2RGB(NORMAL_COLOR);
HIDDEN COLORREF NormalBackColor = COLOR2RGB(NORMAL_BACK_COLOR);
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");
#if XVT_OS == XVT_OS_WIN
// By Matt Pietrek
bool allow_another_instance()
{
HINSTANCE hInstance = (HINSTANCE)xvt_vobj_get_attr(NULL_WIN, ATTR_WIN_INSTANCE);
HMODULE hModuleSel = SELECTOROF( // Convert the HINSTANCE to an HMODULE
GlobalLock(GetModuleHandle((const char*)MAKELP(0,hInstance))));
if ( hModuleSel == 0 ) // Make sure we succeeded.
return FALSE;
// Make pointers to the resident names table and the OFSTRUCT
LPSTR moduleName = (LPSTR)MAKELP( hModuleSel, *(WORD FAR *)MAKELP(hModuleSel, 0x26));
LPSTR fileName = (LPSTR)MAKELP( hModuleSel, *(WORD FAR *)MAKELP(hModuleSel, 0x0A));
// Get the module name length, and advance to the actual string
BYTE cbModuleName = *moduleName++; // First byte is a length byte
// Convert the first uppercase letter of the modulename to lowercase
while ( cbModuleName )
{
if ( isupper(*moduleName) )
{
*moduleName = tolower(*moduleName); break;
}
cbModuleName--; moduleName++;
}
if ( cbModuleName == 0 ) // Make sure we succeeded
return FALSE;
// Position to the end of the filename. First byte is a length byte
fileName += *fileName - 1;
// Find the first uppercase letter in the filename. Convert to lowercase
while ( TRUE )
{
// Stop when we come to a directory separator or colon
if ( (*fileName=='\\') || (*fileName=='/') || (*fileName==':') )
return FALSE;
if ( isupper(*fileName) )
{
*fileName = tolower(*fileName); break;
}
fileName--;
}
return TRUE;
}
#endif
static BOOLEAN event_hook(HWND hwnd,
UINT msg,
UINT wparam,
ULONG lparam,
long* ret)
{
switch(msg)
{
case WM_SYSCOLORCHANGE:
Ctl3dColorChange();
break;
case WM_CTLCOLOR:
{
const word type = HIWORD(lparam);
if (type == CTLCOLOR_LISTBOX || type == CTLCOLOR_EDIT ||
type == CTLCOLOR_MSGBOX)
{
HWND hwnd = LOWORD(lparam);
HDC hdc = wparam;
if (!IsWindowEnabled(hwnd)) // Campo disabilitato
{
if (type != CTLCOLOR_MSGBOX)
{
SetTextColor(hdc, NormalForeColor);
SetBkColor(hdc, MaskColor);
}
*ret = MaskBrush;
return FALSE; // Non fare altro
}
bool focus = GetFocus() == hwnd;
if (type != CTLCOLOR_MSGBOX)
{
SetTextColor(hdc, focus ? FocusForeColor : NormalForeColor);
SetBkColor(hdc, focus ? FocusBackColor : NormalBackColor);
}
*ret = focus ? FocusBrush : NormalBrush;
return FALSE; // Non fare altro
}
#ifdef __CTL3D__
else
{
*ret = Ctl3dCtlColorEx(msg, wparam, lparam);
return TRUE;
}
#else
#endif
}
break;
case WM_COMMAND:
{
const word notify = HIWORD(lparam);
if (notify == EN_KILLFOCUS || notify == EN_SETFOCUS)
{
HWND hwnd = LOWORD(lparam); // Ridisegna BENE il campo
InvalidateRect(hwnd, NULL, TRUE);
}
}
break;
case WM_KEYDOWN:
if (wparam == VK_PRIOR || wparam == VK_NEXT ||
wparam == VK_UP || wparam == VK_DOWN ||
wparam == VK_F1 )
{
KEY key = 0;
char name[16];
GetClassName(hwnd, name, 5);
if (stricmp(name, "Edit") == 0) switch(wparam)
{
case VK_PRIOR:
key = K_PREV; break;
case VK_NEXT:
key = K_NEXT; break;
case VK_UP:
key = K_UP; break;
case VK_DOWN:
key = K_DOWN; break;
default:
key = 0; break;
}
if (wparam == VK_F1)
key = K_F1;
if (key > 0)
{
WINDOW w = cur_win();
if (w != NULL_WIN)
{
dispatch_e_char(w, key);
return FALSE;
}
}
}
break;
case WM_MENUCHAR:
{
WINDOW w = cur_win();
if (w != NULL_WIN)
{
const KEY key = toupper(wparam)+K_CTRL;
dispatch_e_char(w, key);
}
}
break;
default:
if (msg == WM_WAKEUP && wparam == main_app().waiting())
main_app().wake_up();
break;
}
return TRUE; // Continua col processo normale
}
HIDDEN WIN_TYPE _wc_type = W_NONE;
HIDDEN long _bandiere = 0L;
static void createwindow_hook(DWORD* exstyle, LPCSTR* classname, LPCSTR* windowname, DWORD* styl,
int* x, int* y, int* width, int* height, HWND* parent, HMENU* menu,
HINSTANCE inst, void **)
{
if (_wc_type == WC_EDIT)
{
if (_bandiere & CTL_FLAG_MAC_MONACO9)
*exstyle |= ES_PASSWORD;
}
_wc_type = W_NONE;
}
#endif
// @func Calcola dimensioni e posizione di un controllo contenuto nella finestra
//
// @rdesc Ritorna il rettangolo
RCT& resize_rect(
short x, // @parm Coordinata x del controllo (espresso in caratteri)
short y, // @parm Coordinata y del controllo (espresso in caratteri)
short dx, // @parm Larghezza del controllo (espresso in caratteri)
short dy, // @parm Altezza del controllo (espresso in caratteri)
WIN_TYPE wt, // @parm Tipo di controllo da creare
WINDOW parent) // @parm Identificatore della finestra padre
{
static RCT r;
if (parent != TASK_WIN)
{
if (xvt_vobj_get_type(parent) == W_PLAIN) // Mask with Toolbar
{
if (y >= 0)
{
const TMask* m = (const TMask*)xvt_vobj_get_data(parent);
if (parent != m->toolwin())
y++;
}
if (x > 0 || (wt != WO_TE && x == 0))
{
RCT pc; xvt_vobj_get_client_rect(parent, &pc); // Get parent window size
const int width = pc.right;
const int tot = 80*CHARX;
if (width > tot) x += (width-tot) / (CHARX<<1);
}
}
wt = WC_EDIT;
}
#if XVT_OS == XVT_OS_WIN
switch (wt)
{
case WC_EDIT :
r.left = (x+1)*CHARX;
r.top = y*ROWY;
r.right = dx*CHARX;
r.bottom = (CHARY << 1) - BASEY;
if (dy > 1)
r.bottom += ROWY*(dy-1);
break;
case W_DOC:
r.left = x * CHARX;
r.top = y * ROWY;
r.right = dx * CHARX;
r.bottom = dy * CHARY;
break;
default:
r.left = x * CHARX;
r.top = y * ROWY;
r.right = (dx+2)*CHARX;
r.bottom = dy*ROWY-1;
break;
}
#else
r.left = x * CHARX;
r.top = y * CHARY;
r.right = dx * CHARX;
r.bottom = dy * CHARY;
#endif
if (x < 0 || y < 0 || dx <= 0 || dy <= 0)
{
RCT pc;
if (parent == NULL_WIN) parent = TASK_WIN;
xvt_vobj_get_client_rect(parent, &pc); // Get parent window size
const short MAXX = pc.right;
const short MAXY = pc.bottom;
if (x < 0)
{
x = -x;
if (wt != WC_EDIT && x == 1) x = 11;
if (x > 10)
{
const int num = x/10 -1;
const int tot = x%10;
const int spc = (MAXX - tot*r.right) / (tot+1);
r.left = spc + num*(spc+r.right);
}
else
r.left = MAXX - r.right - x*CHARX;
}
if (y < 0)
{
y = -y;
if (wt != WC_EDIT && y == 1) y = 11;
if (y > 10)
{
const int num = y/10 -1;
const int tot = y%10;
const int spc = (MAXY - tot*r.bottom) / (tot+1);
r.top = spc + num*(spc+r.bottom);
}
else
r.top = MAXY - r.bottom - (y-1)*ROWY;
}
if (dx <= 0) r.right = MAXX + dx*CHARX;
else r.right += r.left;
if (dy <= 0) r.bottom = MAXY + dy*ROWY;
else r.bottom += r.top;
}
else
{
r.right += r.left;
r.bottom += r.top;
}
return r;
}
// @func Emette un suono di default
void beep()
{ xvt_scr_beep(); }
///////////////////////////////////////////////////////////
// Event Handling
///////////////////////////////////////////////////////////
class TEvent_manager
{
enum { MAX = 2 };
WINDOW _w[MAX];
EVENT _e[MAX];
int _begin, _end;
public:
TEvent_manager() : _begin(0), _end(0) {}
void push(WINDOW win, const EVENT& event);
void pop();
};
HIDDEN TEvent_manager EM;
void TEvent_manager::push(WINDOW w, const EVENT& e)
{
CHECK(w, "You shouldn't send events to NULL_WIN!");
_w[_end] = w;
_e[_end] = e;
const int next = (_end+1) % MAX;
if (next == _begin)
warning_box("Hey, clicca piu' piano!");
else
_end = next;
}
void TEvent_manager::pop()
{
if (_begin != _end)
{
const int i = _begin;
_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();
}
}
// @func Processa tutti gli eventi rimasti in coda
void do_events()
{
xvt_app_process_pending_events();
EM.pop();
#if XVT_OS == XVT_OS_SCOUNIX
nap(20);
#endif
}
// @func Permette di convertire un evento carattere in un codice carattere premuto
//
// @rdesc Ritorna il codice del carattere corrispondente all'evento
KEY e_char_to_key(
const EVENT* ep) // @parm Evento da codificare
// @comm Viene controllato se l'evento e' un e_car e viene tradotto, in caso
// controrio viene emesso un segnale d'errore.
{
CHECK(ep->type == E_CHAR, "I can't convert a Non-E_CHAR event to a key");
KEY key = ep->v.chr.ch;
if (key < K_INS || key > K_HELP)
{
if (ep->v.chr.shift && (key < ' ' || key >= K_UP)) key += K_SHIFT;
if (ep->v.chr.control && key >= ' ') key += K_CTRL;
}
return key;
}
// @func Simula la scelta di una voce di menu
void dispatch_e_menu(
WINDOW win, // @parm Finestra che contiene il menu
MENU_TAG item) // @parm Voce del menu da selezionare
// @xref <f dispatch_e_char> <f dispatch_e_scroll>
{
EVENT e;
e.type = E_COMMAND;
e.v.cmd.tag = item;
e.v.cmd.shift = e.v.cmd.control = 0;
EM.push(win, e);
}
// @func Simula la scelta di una combinazione di caratteri
void dispatch_e_char(
WINDOW win, // @parm Finestra che contiene il menu
KEY key) // @parm Combinazione di caratteri da utilizzare
// @xref <f dispatch_e_menu> <f dispatch_e_scroll>
{
EVENT e;
e.type = E_CHAR;
if (key > 10000) { e.v.chr.control = TRUE; key -= K_CTRL; }
else e.v.chr.control = FALSE;
if (key > 1000) { e.v.chr.shift = TRUE; key -= K_SHIFT; }
else e.v.chr.shift = FALSE;
e.v.chr.ch = short(key);
EM.push(win, e);
}
// @func Simula uno scroll all'interno di una finestra
void dispatch_e_scroll(
WINDOW win, // @parm Finestra nella quale operare
KEY key) // @parm Tasto utilizzato per lo scroll nella finestra
// @xref <f dispatch_e_menu> <f dispatch_e_char>
{
EVENT e;
EVENT_TYPE& t = e.type;
SCROLL_CONTROL& w = e.v.scroll.what;
short& p = e.v.scroll.pos;
w = SC_NONE;
switch(key)
{
case K_HOME:
t = E_HSCROLL;
w = SC_THUMB;
p = 0;
break;
case K_LHOME:
t = E_VSCROLL;
w = SC_THUMB;
p = 0;
break;
case K_UP:
t = E_VSCROLL;
w = SC_LINE_UP;
break;
case K_DOWN:
t = E_VSCROLL;
w = SC_LINE_DOWN;
break;
case K_BTAB:
t = E_HSCROLL;
w = SC_PAGE_UP;
break;
case K_TAB:
t = E_HSCROLL;
w = SC_PAGE_DOWN;
break;
case K_PREV:
t = E_VSCROLL;
w = SC_PAGE_UP;
break;
case K_NEXT:
t = E_VSCROLL;
w = SC_PAGE_DOWN;
break;
case K_LEFT:
t = E_HSCROLL;
w = SC_LINE_UP;
break;
case K_RIGHT:
t = E_HSCROLL;
w = SC_LINE_DOWN;
break;
default:
break;
};
if (w != SC_NONE) xvt_win_dispatch_event(win, &e);
}
// @func Permette di cambiare i colori attivi del programma
void customize_colors()
// @comm Legge dal file di configurazione i colori scelti dall'utente e
// ne setta le variabili in modo da poter personalizzare i colori
//
// @xref <c TConfig>
{
TConfig colors(CONFIG_USER, "Colors");
MASK_BACK_COLOR = colors.get_color("MaskBack", NULL, -1, MASK_BACK_COLOR);
MASK_LIGHT_COLOR = colors.get_color("MaskLight", NULL, -1, MASK_LIGHT_COLOR);
MASK_DARK_COLOR = colors.get_color("MaskDark", NULL, -1, MASK_DARK_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);
TOOL_BACK_COLOR = colors.get_color("ToolBack", NULL, -1, MASK_DARK_COLOR);
}
// @func Stabilisce i parametri standard dei controlli
void customize_controls(
bool on) // @parm Permette di inizializzare (TRUE) o scaricare (FALSE) i parametri
{
customize_colors();
if (on)
{
#if XVTWS == WMWS
// xvt_vobj_set_attr(NULL_WIN,ATTR_CH_SHADOW,XVT_CH_SHADOW_WINDOW|XVT_CH_SHADOW_DIALOG);
xvt_vobj_set_attr(NULL_WIN, ATTR_CH_TOGGLE_COMBO, (long)K_F9);
#endif
#if XVT_OS == XVT_OS_WIN
xvt_vobj_set_attr(NULL_WIN,ATTR_WIN_PM_DRAWABLE_TWIN, TRUE);
xvt_vobj_set_attr(NULL_WIN,ATTR_EVENT_HOOK, (long)event_hook);
xvt_vobj_set_attr(NULL_WIN,ATTR_WIN_CREATEWINDOW_HOOK, (long)createwindow_hook);
allow_another_instance();
HINSTANCE _hInstance = (HINSTANCE)xvt_vobj_get_attr(NULL_WIN, ATTR_WIN_INSTANCE);
Ctl3dRegister(_hInstance);
Ctl3dAutoSubclass(_hInstance);
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
{
#if XVT_OS == XVT_OS_WIN
HINSTANCE _hInstance = (HINSTANCE)xvt_vobj_get_attr(NULL_WIN, ATTR_WIN_INSTANCE);
Ctl3dUnregister(_hInstance);
DeleteObject(NormalFont);
DeleteObject(MaskBrush);
DeleteObject(NormalBrush);
DeleteObject(FocusBrush);
free_controls_bmp();
#endif
xvt_font_destroy(DEF_FONT);
xvt_font_destroy(FAT_FONT);
}
if (on) xvt_vobj_set_attr(NULL_WIN,ATTR_ERRMSG_HANDLER, (long)error_hook);
}
XVT_FNTID xvt_default_font()
{
if (DEF_FONT == NULL)
{
DEF_FONT = xvt_dwin_get_font(TASK_WIN);
FAT_FONT = xvt_dwin_get_font(TASK_WIN);
#if XVT_OS == XVT_OS_WIN
NormalFont = GetStockObject(ANSI_FIXED_FONT);
GetObject(NormalFont, sizeof(LOGFONT), &LogFont);
TConfig font(CONFIG_USER, "Font");
CHARY = (int)font.get_long("Height");
if (CHARY > 0)
{
LogFont.lfHeight = CHARY;
LogFont.lfWeight = FontWeight = font.get_int("Weight");
LogFont.lfPitchAndFamily = font.get_int("Pitch");
strcpy(LogFont.lfFaceName, font.get("Name"));
}
else
{
LogFont.lfHeight = CHARY = 10;
FontWeight = 300; // Normal weight
}
NormalFont = CreateFontIndirect(&LogFont);
TToken_string desc(128, '/');
desc.add("WIN01"); // 0
desc.add(LogFont.lfHeight); // 1
desc.add(LogFont.lfWidth); // 2
desc.add(LogFont.lfEscapement); // 3
desc.add(LogFont.lfOrientation); // 4
desc.add(LogFont.lfWeight); // 5
desc.add(LogFont.lfItalic); // 6
desc.add(LogFont.lfUnderline);
desc.add(LogFont.lfStrikeOut);
desc.add(LogFont.lfCharSet);
desc.add(LogFont.lfOutPrecision);
desc.add(LogFont.lfClipPrecision);
desc.add(LogFont.lfQuality);
desc.add(LogFont.lfPitchAndFamily);
desc.add(LogFont.lfFaceName);
xvt_font_set_native_desc(DEF_FONT, (char*)(const char*)desc);
CHECK(xvt_font_has_valid_native_desc(DEF_FONT), "Bad font description");
xvt_font_map_using_default(DEF_FONT);
CHECK(xvt_font_is_mapped(DEF_FONT), "Can't map native font");
xvt_dwin_set_font(TASK_WIN, DEF_FONT);
desc.add(600, 5);
xvt_font_set_native_desc(FAT_FONT, (char*)(const char*)desc);
CHECK(xvt_font_has_valid_native_desc(FAT_FONT), "Bad font description");
xvt_font_map_using_default(FAT_FONT);
CHECK(xvt_font_is_mapped(FAT_FONT), "Can't map native font");
// Get true text size
TEXTMETRIC tm;
HDC hdc = (HDC)xvt_vobj_get_attr(TASK_WIN, ATTR_NATIVE_GRAPHIC_CONTEXT);
GetTextMetrics(hdc, &tm);
const int COLX = GetSystemMetrics(SM_CXSCREEN) / 80;
CHARX = tm.tmAveCharWidth+1;
if (CHARX > COLX) CHARX = COLX;
CHARY = tm.tmHeight;
BASEY = tm.tmAscent;
if (CHARY > ROWY-2) CHARY = ROWY-2;
#endif
}
return DEF_FONT;
}
// @func Permette di settare il font attivo nella finestra
void xvt_set_font(
WINDOW win, // @parm Finestra nella quale settare il font
const char* family, // @parm Nome del font da settare
int style, // @parm Stile da applicare al font
int dim) // @parm Dimensione del font
{
CHECK(win != NULL_WIN, "Can't set the font in a NULL window");
#if XVT_OS != XVT_OS_SCOUNIX
if ((family == NULL || *family == '\0') &&
(style == XVT_FS_NONE || style == XVT_FS_BOLD) &&
dim == 0)
{
xvt_dwin_set_font(win, (style == XVT_FS_NONE) ? DEF_FONT : FAT_FONT);
}
else
{
XVT_FNTID font = xvt_dwin_get_font(TASK_WIN);
if (family && *family) xvt_font_set_family(font, (char*)family);
if (dim != 0) xvt_font_set_size(font, dim);
if (style != XVT_FS_NONE) xvt_font_set_style(font, style);
if(!xvt_font_is_mapped(font))
xvt_font_map(font, win);
xvt_dwin_set_font(win, font);
xvt_font_destroy(font);
}
#endif
}
// @func Permette di creare una finestra
//
// @rdesc Ritorna l'identificatore della finestra creata
WINDOW xvt_create_window(
WIN_TYPE wt, // @parm Tipo di finestra da creare
short x, // @parm Coordinata x della finestra (espresso in caratteri)
short y, // @parm Coordinata y della finestra (espresso in caratteri)
short dx, // @parm Larghezza della finestra (espresso in caratteri)
short dy, // @parm Altezza della finestra (espresso in caratteri)
const char* caption, // @parm Titolo da assegnare alla finestra
int menu, // @parm Menu della finestra (definito nelle risorse, 0=senza)
WINDOW parent, // @parm Identificatore della finestra padre
long flags, // @parm Attributi della finestra
EVENT_HANDLER eh, // @parm Funzioni per la gestione degli eventi diretti alla finestra
long app_data) // @parm Puntatore alla classe C++ che gestisce la finestra
{
RCT& rect = resize_rect(x, y, dx, dy, wt, parent);
if (wt == WD_MODAL) wt = W_DOC;
WINDOW win = xvt_win_create(wt,
&rect,
(char*)caption,
menu, parent,
flags,
EM_ALL, eh,
app_data);
CHECK(win, "Can't create a window: XVT error");
#if XVT_OS == XVT_OS_WIN
static bool to_set = TRUE;
HWND hwnd = (HWND)xvt_vobj_get_attr(win, ATTR_NATIVE_WINDOW);
if (to_set)
{
word style = GetClassWord(hwnd, GCW_STYLE);
style |= CS_BYTEALIGNCLIENT;
SetClassWord(hwnd, GCW_STYLE, style);
to_set = FALSE;
}
#endif
return win;
}
// @func Permette di creare i controlli all'interno di una finestra
//
// @rdesc Ritorna la finestra del controllo
WINDOW xvt_create_control(
WIN_TYPE wt, // @parm Tipo di controllo da creare
short x, // @parm Coordinata x del control
short y, // @parm Coordinata y del control
short dx, // @parm Larghezza della control
short dy, // @parm Altezza della control
const char* caption, // @parm Titolo da assegnare alla control
WINDOW parent, // @parm Identificatore della finestra padre
long flags, // @parm Attributi della finestra
long app_data, // @parm Puntatore alla classe C++ che gestisce la finestra
int id) // @parm Indentificatore del controlllo
{
RCT r = resize_rect(x, y, dx, dy, wt, parent);
WINDOW win = NULL_WIN;
#if XVT_OS == XVT_OS_WIN
_wc_type = wt;
_bandiere = flags;
flags &= ~(CTL_FLAG_MAC_MONACO9 | CTL_FLAG_MAC_GENEVA9);
if (wt == WC_PUSHBUTTON)
win = xvt_create_pushbutton(r.left, r.top, r.right, r.bottom,
caption, parent, flags, app_data, id);
#ifndef __CTL3D__
if (wt == WC_CHECKBOX)
win = xvt_create_checkbox(r.left, r.top, r.right, r.bottom,
caption, parent, flags, app_data, id);
if (wt == WC_RADIOBUTTON)
win = xvt_create_radiobutton(r.left, r.top, r.right, r.bottom,
caption, parent, flags, app_data, id);
if (wt == WC_GROUPBOX)
{
win = xvt_create_groupbox(r.left, r.top, r.right, r.bottom,
caption, parent, flags, app_data, id);
}
if (wt == WC_TEXT)
{
win = xvt_create_text(r.left, r.top, r.right, r.bottom,
caption, parent, flags, app_data, id);
}
#else
if (wt == WC_GROUPBOX)
{
win = xvt_create_text(r.left, r.top, r.right, r.top+CHARY,
caption, parent, 0, app_data, id);
}
#endif
#endif
if (win == NULL_WIN)
{
#if XVT_OS == XVT_OS_SCOUNIX
if (wt == WC_PUSHBUTTON)
{
if (dy == 2) r.bottom -= ROWY;
if (id == DLG_F9)
{ wt = WC_TEXT; r.right = r.left+CHARX; caption = "*"; }
else if (*caption == '*') caption = "";
}
#endif
while (*caption == '@') caption += 2;
win = xvt_ctl_create(wt, &r, (char*)caption, parent,
flags, app_data, id);
if (win == NULL_WIN)
fatal_box("Can't create control %d", id);
}
#if XVT_OS == XVT_OS_WIN
#ifdef __CTL3D__
if (wt != WC_PUSHBUTTON)
#else
if (wt == WC_EDIT || wt == WC_LISTBUTTON)
#endif
{
HWND hwnd = (HWND)xvt_vobj_get_attr(win, ATTR_NATIVE_WINDOW);
SendMessage(hwnd, WM_SETFONT, NormalFont, FALSE);
if (_bandiere & CTL_FLAG_MAC_MONACO9)
SendMessage(hwnd, EM_SETPASSWORDCHAR, (WORD)'#', 0);
#ifdef __CTL3D__
Ctl3dSubclassCtl(hwnd);
#endif
}
#endif
return win;
}
// @func Restituisce il titolo della finestra
//
// @rdesc Stringa contenente il titolo della finestra
const char* xvt_get_title(
WINDOW win) // @parm Finestra della quale si vuole conoscere il titolo
// @xref <f xvt_set_title>
{
#if XVT_OS == XVT_OS_WIN && !defined(__CTL3D__)
const TControl* c = TControl::WINDOW2TControl(win);
return c->caption();
#else
xvt_vobj_get_title(win, __tmp_string, 80);
return __tmp_string;
#endif
}
// @func Permette di assegnare il titolo ad una finestra
void xvt_set_title(
WINDOW win, // @parm Finestra a cui assegnare il titolo
const char* cap) // @parm Titolo da assegnare
// @xref <f xvt_get_title>
{
#if XVT_OS == XVT_OS_WIN && !defined(__CTL3D__)
TControl* c = TControl::WINDOW2TControl(win);
c->set_caption(cap);
#else
xvt_vobj_set_title(win, (char*)cap);
#endif
}
// @func Permette di abilitare il focus su un controllo
void xvt_set_front_control(
WINDOW win) // @parm Finestra nella quale abilitare il focus
{
#if XVT_OS == XVT_OS_WIN && !defined(__CTL3D__)
TControl* c = TControl::WINDOW2TControl(win);
c->focus(TRUE);
#endif
xvt_scr_set_focus_vobj(win);
}
// @func Permette di abilitare o disabilitare un controllo
void xvt_enable_control(
WINDOW win, // @parm Finestra all'interno della quale abilitare il controllo
bool on) // @parm Abilita (TRUE) o disabilita (FALSE) il controllo
{
#if XVT_OS == XVT_OS_WIN && !defined(__CTL3D__)
TControl* c = TControl::WINDOW2TControl(win);
c->enable(on);
#else
xvt_vobj_set_enabled(win, on);
#endif
}
// @func Permette di gestire un check box all'interno di una finestra
void xvt_check_box(
WINDOW win, // @parm Finestra all'interno della quale abilitare il check box
bool on) // @parm Permette di inizializzare (TRUE) o scaricare (FALSE) i parametri
{
#if XVT_OS == XVT_OS_WIN && !defined(__CTL3D__)
TControl* c = (TControl*)TControl::WINDOW2TControl(win);
c->check(on);
#else
xvt_ctl_set_checked(win, on);
#endif
}
// @func Permette di controllare se un controllo e' stato selezionato
//
// @rdesc Ritorna i seguenti valori:
//
// @flag TRUE | Se il controllo e' stato selezionato
// @flag FALSE | Se il controllo non e' stato selezionato
bool xvt_get_checked_state(
WINDOW win) // @parm Finestra di cui si vuole conoscere lo stato
{
#if XVT_OS == XVT_OS_WIN && !defined(__CTL3D__)
TControl* c = TControl::WINDOW2TControl(win);
return c->checked();
#else
return xvt_ctl_is_checked(win) ? TRUE : FALSE;
#endif
}
// @func Permette di gestire un radio button all'interno di una finestra
void xvt_check_radio_button(
WINDOW win, // @parm Finestra all'interno della quale abilitare il radio button
const WINDOW* ctls, // @parm Array di stringhe contenenti le scelte del radiobutton
int count) // @parm Numero di elementi del radiobutton
{
#if XVT_OS == XVT_OS_WIN && !defined(__CTL3D__)
for (int i = 0; i < count; i++)
xvt_check_box(ctls[i], ctls[i] == win);
#else
xvt_ctl_check_radio_button(win, (WINDOW*)ctls, count);
#endif
}
// @func Permette di controllare lo stato di un radiobutton
//
// @rdesc Ritorna il numero dell'elemento del radiobutton selezionato
int xvt_get_checked_radio(
const WINDOW* ctls, // @parm Array di stringhe contenenti le scelte del radiobutton
int count) // @parm Numero di elemnti del radiobutton
{
for (int i = 0; i < count; i++)
if (xvt_get_checked_state(ctls[i])) return i;
#ifdef DBG
error_box("Accendi la tua radio per favore!");
#endif
return 0;
}
// @func Permette di cambiare il colore di sfondo di un controllo
void xvt_set_ctrl_back_color(
WINDOW win, // @parm Finestra di cui si vuole cambiare lo sfondo
COLOR col) // @parm Colore dello sfondo
{
#if XVT_OS == XVT_OS_WIN && !defined(__CTL3D__)
TControl* c = (TControl*)TControl::WINDOW2TControl(win);
c->set_back_color(col);
#endif
}
///////////////////////////////////////////////////////////
// Gestione Status bar
///////////////////////////////////////////////////////////
HIDDEN WINDOW _statbar = NULL_WIN;
// @func Permette di creare la barra di stato del programma
//
// @rdesc Ritorna l'identificatore della barra di stato creata
WINDOW xvt_create_statbar()
// @xref <f xvt_statbar_set> <f xvt_statbar_refresh>
{
CHECK(_statbar == NULL_WIN, "Onli uan stabar, plis");
#if XVT_OS == XVT_OS_WIN
const int prop_count = 4;
char* prop_list[prop_count+1] =
{
"Status bar",
"HEIGHT=24",
"TASK_WIN",
"FIELD_OFFSET=24",
NULL
};
_statbar = statbar_create(0, 0, 600, 1024, 800, prop_count, prop_list,
TASK_WIN, 0, 0, "");
CHECK(_statbar, "Can't create the status bar");
statbar_set_fontid(_statbar, xvt_default_font());
#endif
return _statbar;
}
// @func Permette di settare una finestra con la barra di stato
void xvt_statbar_set(
const char* text, // @parm Testo da inserire nella barra di stato
bool def) // @parm (default FALSE)
// @comm Nella barra di stato vi e' sempre presente la data del sistema
//
// @xref <f xvt_create_statbar> <f xvt_statbar_refresh>
{
#if XVT_OS == XVT_OS_WIN
const TDate oggi(TODAY);
TString256 t(text);
t << '\t' << oggi.string() << " - " << main_app().title();
if (def)
statbar_set_default_title(_statbar, (char*)(const char*)t);
statbar_set_title(_statbar, (char*)(const char*)t);
#endif
}
// @func Permette di cambiare il titolo alla barra di stato presente
void xvt_statbar_refresh()
// @xref <f xvt_create_statbar> <f xvt_statbar_set>
{
#if XVT_OS == XVT_OS_WIN
statbar_set_title(_statbar, NULL);
#endif
}
///////////////////////////////////////////////////////////
// Test menu
///////////////////////////////////////////////////////////
HIDDEN bool test_menu_tag(MENU_ITEM* mi, MENU_TAG tag)
{
while (mi->tag)
{
if (mi->tag == tag) return TRUE;
if (mi->child != NULL)
{
const bool ok = test_menu_tag(mi->child, tag);
if (ok) return TRUE;
}
mi++;
}
return FALSE;
}
// @func Controlla se e' esiste una voce del menu'
//
// @rdesc Ritorna i seguenti valori
//
// @flag TRUE | Se esiste la voce di menu'
// @flag FALSE | Se non esiste la voce di menu'
bool xvt_test_menu_tag(
MENU_TAG tag) // @parm Menu' nel quale cercare la voce
{
MENU_ITEM *mi = xvt_menu_get_tree(TASK_WIN);
const bool ok = test_menu_tag(mi, tag);
xvt_res_free_menu_tree(mi);
return ok;
}
// @func Permette di convertire in attributi grafici i codici caratteri usati
// dalle funzioni di stampa
//
// @rdesc Ritorna il codice del colore convertito in attributo grafico
COLOR trans_color(
char c) // @parm Codice carattere da convertire
{
COLOR col;
switch (c)
{
case 'b':
col = COLOR_BLUE; break;
case 'c':
col = COLOR_CYAN; break;
case 'd':
col = COLOR_DKGRAY; break;
case 'g':
col = COLOR_GREEN; break;
case 'k':
col = COLOR_GRAY; break;
case 'l':
col = COLOR_LTGRAY; break;
case 'm':
col = MASK_BACK_COLOR; break;
case 'n':
col = COLOR_BLACK; break;
case 'r':
col = COLOR_RED; break;
case 'v':
col = COLOR_MAGENTA; break;
case 'w':
col = COLOR_WHITE; break;
case 'y':
col = COLOR_YELLOW; break;
default:
CHECK(0,"trans_color: Undefined color"); break;
}
return col;
}
// @func Permette di converitire lo stile del pattern in attributi grafici da
// codici carattere.
//
// @rdesc Ritorna il pattern convertito
PAT_STYLE trans_brush(
char p) // @parm Codice carattere da convertire
{
switch (p)
{
case 'n' :
return PAT_NONE; break;
case 'h' :
return PAT_HOLLOW; break;
case 's' :
return PAT_SOLID; break;
case '-' :
return PAT_HORZ; break;
case '|' :
return PAT_VERT; break;
case '/' :
return PAT_FDIAG; break;
case '\\':
return PAT_BDIAG; break;
case 'X' :
return PAT_DIAGCROSS; break;
case '+' :
return PAT_CROSS; break;
default :
CHECK(0,"trans_brush: Undefined pattern"); break;
}
return PAT_NONE;
}
// @func Permette di convertire lo stile della penna da codice carattere
//
// @rdesc Ritorna lo stilo convertito
PEN_STYLE trans_pen(
char p) // @parm Codice carattere da convertire
{
PEN_STYLE ps = P_SOLID;
switch (p)
{
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;
}