From 6d79069eb68d7fe8fc0f76b85acd2afa326250db Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 23 Aug 1994 13:52:36 +0000 Subject: [PATCH] Gestione tasti rapidi. git-svn-id: svn://10.65.10.50/trunk@52 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- ba/ba1.url | 2 +- ba/ba1100d.uml | 2 +- ba/ba1200.cpp | 18 +- ba/ba4300a.uml | 1486 ++++++++++++------------ ba/ba6.cpp | 22 +- ba/ba6200a.uml | 252 ++--- cg/cg2102.cpp | 4 +- cg/cg4.cpp | 3 +- cg/cg4400.cpp | 9 +- cg/cg4400.h | 234 ++-- cg/cg4500.cpp | 1170 ++++++++++--------- cg/cglib02.cpp | 6 +- include/applicat.cpp | 1074 +++++++++--------- include/controls.cpp | 2049 +++++++++++++++++---------------- include/default.url | 167 ++- include/files.h | 20 +- include/keys.h | 53 +- include/mask.cpp | 151 ++- include/mask.h | 374 +++--- include/maskfld.cpp | 46 +- include/maskfld.h | 576 +++++----- include/msksheet.cpp | 8 + include/relapp.cpp | 4 +- include/sheet.cpp | 1468 ++++++++++++------------ include/toolbar.h | 67 +- include/validate.cpp | 1120 +++++++++--------- include/viswin.cpp | 2568 +++++++++++++++++++++--------------------- include/window.cpp | 1462 ++++++++++++------------ include/window.h | 431 +++---- include/xvtility.cpp | 128 ++- 30 files changed, 7556 insertions(+), 7418 deletions(-) diff --git a/ba/ba1.url b/ba/ba1.url index aa91b9993..6878f85d9 100755 --- a/ba/ba1.url +++ b/ba/ba1.url @@ -12,7 +12,7 @@ MENUBAR MENU_BAR(1) MENU MENU_BAR(1) SUBMENU MENU_FILE "~File" - ITEM BAR_ITEM(1) "~Selezione" + ITEM BAR_ITEM(1) "~Test" /* ba1 -2 */ diff --git a/ba/ba1100d.uml b/ba/ba1100d.uml index 9dfc84f95..7c4655799 100755 --- a/ba/ba1100d.uml +++ b/ba/ba1100d.uml @@ -47,7 +47,7 @@ BEGIN FLAGS "D" END -SPREADSHEET F_FIELDS 34 7 +SPREADSHEET F_FIELDS 44 7 BEGIN PROMPT 15 4 "" ITEM "Nome@10" diff --git a/ba/ba1200.cpp b/ba/ba1200.cpp index 1d82d4e2d..2e5b0311f 100755 --- a/ba/ba1200.cpp +++ b/ba/ba1200.cpp @@ -21,28 +21,28 @@ public: bool TTest_application::menu(MENU_TAG) { - TLocalisamfile tab(LF_TABCOM); + TLocalisamfile tab(LF_COMUNI); const TRecnotype n = tab.items(); - time_t start; + clock_t start; TRecnotype r = 1; TString80 msg; { - TProgind p(n, "Lettura file tabelle comuni", TRUE, TRUE, 32); - start = time(NULL); + TProgind p(n, "Lettura file comuni", TRUE, TRUE, 32); + start = clock(); for (tab.first(); tab.good(); tab.next(), r++) { - if ((r % 50) == 0) + if ((r % 100) == 0) { - msg.format("%ld records %ld sec", r, time(NULL) - start); + msg.format("%ld records %ld msec", r, clock() - start); p.setstatus(r); p.set_text(msg); + if (p.iscancelled()) break; } - if (p.iscancelled()) break; } } -const time_t t = time(NULL) - start; -msg.format("%ld records in %ld sec\n%lg records per sec", r, t, (double)r/t); +const clock_t t = clock() - start; +msg.format("%ld records in %ld msec\n%lg records per sec", r, t, 1000.0*r/t); message_box(msg); return TRUE; diff --git a/ba/ba4300a.uml b/ba/ba4300a.uml index 117fc4e57..c9d20036c 100755 --- a/ba/ba4300a.uml +++ b/ba/ba4300a.uml @@ -1,743 +1,743 @@ -#include "ba4300.h" - -TOOLBAR "" 0 19 0 3 - -BUTTON DLG_ATT 8 1 -BEGIN - PROMPT -16 -3 "Attivita'" - MESSAGE K_F6 -END - -BUTTON DLG_ULC 8 1 -BEGIN - PROMPT -26 -3 "U.Locali" - MESSAGE K_F5 -END - -BUTTON DLG_SOC 8 1 -BEGIN - PROMPT -36 -3 "Soci" - MESSAGE K_F7 -END - -BUTTON DLG_REG 8 1 -BEGIN - PROMPT -46 -3 "Registri" - MESSAGE K_F8 -END - -#include -ENDPAGE - -PAGE "Ditte 1/4" -1 -1 77 18 - -GROUPBOX DLG_NULL 76 4 -BEGIN - PROMPT 0 0 "" - FLAGS "R" -END - -NUMBER FLD_GD1_CODDITTA 5 -BEGIN - PROMPT 1 1 "Codice " - FIELD LF_NDITTE->CODDITTA - FLAGS "RG" - KEY 1 - USE LF_NDITTE KEY 1 - INPUT CODDITTA FLD_GD1_CODDITTA - DISPLAY "Codice" CODDITTA - DISPLAY "Ragione sociale@50" RAGSOC - OUTPUT FLD_GD1_CODDITTA CODDITTA - OUTPUT FLD_GD1_CODDITTAH CODDITTA - OUTPUT FLD_GD1_RAGSOC RAGSOC - HELP "Codice della ditta" - CHECKTYPE REQUIRED - MESSAGE COPY,1@ - MESSAGE COPY,FLD_GD1_CODDITTAH -END - -NUMBER FLD_GD1_CODDITTAH 5 -BEGIN - PROMPT 1 1 "Codice " - FIELD LF_NDITTE->CODDITTA - FLAGS "RG" - USE LF_NDITTE KEY 3 - INPUT TIPOA FLD_GD1_TIPOA - INPUT CODANAGR FLD_GD1_CODANAGR - INPUT CODDITTA FLD_GD1_CODDITTAH - DISPLAY "Codice" CODDITTA - DISPLAY "Ragione sociale@50" RAGSOC - OUTPUT FLD_GD1_CODDITTAH CODDITTA - OUTPUT FLD_GD1_CODDITTA CODDITTA - OUTPUT FLD_GD1_RAGSOC RAGSOC - CHECKTYPE REQUIRED - MESSAGE COPY,1@ - MESSAGE COPY,FLD_GD1_CODDITTA - KEY 1 -END - -STRING FLD_GD1_RAGSOC 50 -BEGIN - PROMPT 1 2 "Ragione sociale " - FIELD LF_NDITTE->RAGSOC - KEY 2 - USE LF_NDITTE KEY 2 - INPUT RAGSOC FLD_GD1_RAGSOC - INPUT CODDITTA FLD_GD1_CODDITTA - DISPLAY "Codice" CODDITTA - DISPLAY "Ragione sociale@50" RAGSOC - OUTPUT FLD_GD1_CODDITTA CODDITTA - OUTPUT FLD_GD1_RAGSOC RAGSOC - HELP "Inserire la ragione sociale della ditta" - CHECKTYPE REQUIRED - FLAGS "G" - MESSAGE COPY,2@ -END - -GROUPBOX DLG_NULL 76 4 -BEGIN - PROMPT 0 4 "Anagrafica" -END - -LIST FLD_GD1_TIPOA 11 -BEGIN - PROMPT 1 5 "Tipo " - FIELD LF_NDITTE->TIPOA - ITEM "F|Fisica" - ITEM "G|Giuridica" -END - -STRING FLD_GD1_CODANAGR 5 -BEGIN - PROMPT 46 5 "Codice " - FIELD LF_NDITTE->CODANAGR - FLAGS "R" - USE LF_ANAG KEY 1 - INPUT TIPOA FLD_GD1_TIPOA - INPUT CODANAGR FLD_GD1_CODANAGR - DISPLAY "Tipo" TIPOA - DISPLAY "Codice" CODANAGR - DISPLAY "Ragione sociale@50" RAGSOC - OUTPUT FLD_GD1_CODANAGR CODANAGR - OUTPUT FLD_GD1_TIPOA TIPOA - OUTPUT FLD_GD1_CODANAGR_ANAGR_RAGSOC RAGSOC - HELP "Inserire il codice della anagrafica" - CHECKTYPE REQUIRED - WARNING "Anagrafica assente" - ADD RUN ba4 -1 -END - -STRING FLD_GD1_CODANAGR_ANAGR_RAGSOC 50 -BEGIN - PROMPT 1 6 "Denominazione " - USE LF_ANAG KEY 2 - INPUT TIPOA FLD_GD1_TIPOA - INPUT RAGSOC FLD_GD1_CODANAGR_ANAGR_RAGSOC - DISPLAY "Ragione Sociale@50" RAGSOC - DISPLAY "Tipo" TIPOA - DISPLAY "Codice" CODANAGR - OUTPUT FLD_GD1_TIPOA TIPOA - OUTPUT FLD_GD1_CODANAGR CODANAGR - OUTPUT FLD_GD1_CODANAGR_ANAGR_RAGSOC RAGSOC - ADD RUN ba4 -1 -END - -GROUPBOX DLG_NULL 76 4 -BEGIN - PROMPT 0 8 "Attivita' principale" -END - -STRING FLD_GD1_CODATTPREV 5 -BEGIN - PROMPT 1 9 "Codice " - FIELD LF_NDITTE->CODATTPREV - FLAGS "URZ" - USE %AIS - INPUT CODTAB FLD_GD1_CODATTPREV - DISPLAY "Codice" CODTAB - DISPLAY "Attivita' " S0 - OUTPUT FLD_GD1_CODATTPREV CODTAB - OUTPUT FLD_GD1_CODATTPREV_TABATT_DESCR S0 - HELP "Inserire il codice dell'attivita' prevalente della ditta" - CHECKTYPE REQUIRED - WARNING "Codice attivita' assente" -END - -STRING FLD_GD1_CODATTPREV_TABATT_DESCR 50 -BEGIN - PROMPT 1 10 "Nome " - FLAGS "D" - HELP "" -END - -GROUPBOX DLG_NULL 76 4 -BEGIN - PROMPT 0 12 "Telefoni" -END - -STRING FLD_GD1_PTEL 10 -BEGIN - PROMPT 1 13 "Telefono : Prefisso " - FIELD LF_NDITTE->PTEL - HELP "Inserire il prefisso telefonico della ditta" -END - -STRING FLD_GD1_TEL 30 -BEGIN - PROMPT 34 13 "Numero " - FIELD LF_NDITTE->TEL - HELP "Inserire il numero di telefono della ditta" -END - -STRING FLD_GD1_PFAX 10 -BEGIN - PROMPT 1 14 "FAX : Prefisso " - FIELD LF_NDITTE->PFAX - HELP "Inserire il prefisso telefonico del fax della ditta" -END - -STRING FLD_GD1_FAX 30 -BEGIN - PROMPT 34 14 "Numero " - FIELD LF_NDITTE->FAX - HELP "Inserire il numero di telefono del fax della ditta" -END - -ENDPAGE - -PAGE "Ditte 2/4" -1 -1 77 18 - -GROUPBOX DLG_NULL 76 4 -BEGIN - PROMPT 0 0 "" - FLAGS "R" -END - -NUMBER DLG_NULL 5 -BEGIN - PROMPT 1 1 "Codice " - FLAGS "RD" - GROUP 1 -END - -STRING DLG_NULL 50 -BEGIN - PROMPT 1 2 "Ragione sociale " - FLAGS "D" - GROUP 2 -END - -RADIOBUTTON RDB_GD1_FREQVIVA 20 -BEGIN - PROMPT 1 4 "Frequenza IVA" - FIELD LF_NDITTE->FREQVIVA - HELP "Inserire la frequenza di liquidazione dell'IVA" - ITEM "M|Mensile" - ITEM "T|Trimestrale" -END - -STRING FLD_GD1_PERRIF 20 -BEGIN - PROMPT 24 5 "Persona di riferimento " - FIELD LF_NDITTE->PERRIF - HELP "Inserire il nominativo della persona a cui fare rfierimento" -END - -BOOLEAN CHK_GD1_ARTIG -BEGIN - PROMPT 1 8 "Artigiano" - FIELD LF_NDITTE->ARTIG - HELP "Dire se si tratta di una ditta artigiana" - MESSAGE FALSE DISABLE,3@|RESET,3@ - MESSAGE TRUE ENABLE,3@ -END - -GROUPBOX DLG_NULL 76 5 -BEGIN - PROMPT 0 9 "" -END - -STRING FLD_GD1_NISCRAA 10 -BEGIN - PROMPT 1 10 "Iscriz. Albo N." - FIELD LF_NDITTE->NISCRAA - FLAGS "R" - HELP "Inserire il numero di iscrizione all'albo" - GROUP 3 -END - -DATE FLD_GD1_DATAISCRAA -BEGIN - PROMPT 52 10 "Data " - FIELD LF_NDITTE->DATAISCRAA - FLAGS "R" - HELP "Inserire la data di iscrizione all'albo" - WARNING "Data non coerente" - VALIDATE DATE_CMP_FUNC >= FLD_GD2_DINIZIOATT - GROUP 3 -END - -STRING FLD_GD1_COMAA 4 -BEGIN - PROMPT 1 11 "Comune : Codice " - FIELD LF_NDITTE->COMAA - FLAGS "U" - USE LF_COMUNI KEY 1 - INPUT STATO "" - INPUT COM FLD_GD1_COMAA -#include - OUTPUT FLD_GD1_COMAA COM - OUTPUT FLD_GD1_COMAA_COMUNI_DESCR DENCOM - OUTPUT FLD_GD1_CAPAA CAPCOM - HELP "Inserire il codice del comune a cui si e' iscritti all'albo" - CHECKTYPE NORMAL - WARNING "Comune assente" - ADD MASK ba4100a - GROUP 3 -END - -STRING FLD_GD1_CAPAA 5 -BEGIN - PROMPT 52 11 "CAP " - FIELD LF_NDITTE->CAPAA - FLAGS "RZ" - HELP "Inserire il CAP del comune a cui si e' iscritti all'albo" - GROUP 3 -END - -STRING FLD_GD1_COMAA_COMUNI_DESCR 50 -BEGIN - PROMPT 8 12 ": Nome " - USE LF_COMUNI KEY 2 SELECT STATO="" - INPUT COM FLD_GD1_COMAA_COMUNI_DESCR -#include - OUTPUT FLD_GD1_COMAA COM - OUTPUT FLD_GD1_COMAA_COMUNI_DESCR DENCOM - OUTPUT FLD_GD1_CAPAA CAPCOM - ADD MASK ba4100a - GROUP 3 -END - -BOOLEAN CHK_GD1_CONTORD -BEGIN - PROMPT 1 14 "Contabilit… ordinaria" - FIELD LF_NDITTE->CONTORD - HELP "Indicare se la ditta tiene una contabilita' ordinaria" -END - -BOOLEAN CHK_GD1_REGMAG -BEGIN - PROMPT 52 14 "Regime Magazzino" - FIELD LF_NDITTE->REGMAG - HELP "Indicare se si utilizza un regime di magazzino" -END - -BOOLEAN CHK_GD1_IMPRFAM -BEGIN - PROMPT 1 15 "Impresa familiare" - FIELD LF_NDITTE->IMPRFAM - HELP "Dire se si tratta di una impresa familiare" -END - -BOOLEAN CHK_GD1_FLIVA11Q -BEGIN - PROMPT 52 15 "IVA 11 Quater" - FIELD LF_NDITTE->FLIVA11Q - HELP "Dire se soggetta all'articolo IVA 11 Quater" -END - -ENDPAGE - -PAGE "Ditte 3/4" -1 -1 77 18 - -GROUPBOX DLG_NULL 76 4 -BEGIN - PROMPT 0 0 "" - FLAGS "R" -END - -NUMBER DLG_NULL 5 -BEGIN - PROMPT 1 1 "Codice " - FLAGS "RD" - GROUP 1 -END - -STRING DLG_NULL 50 -BEGIN - PROMPT 1 2 "Ragione sociale " - FLAGS "D" - GROUP 2 -END - -LIST LST_GD2_DATLAV 20 -BEGIN - PROMPT 1 4 "Datore lavoro " - FIELD LF_NDITTE->DATLAV - HELP "Inserire il tipo di datore di lavoro" - ITEM "1|Datore di lavoro" - ITEM "2|Non datore di lavoro" - ITEM "3|Datore Agricolo" -END - -NUMBER FLD_GD2_NAPP 3 -BEGIN - PROMPT 45 4 "Numero apprendisti " - FIELD LF_NDITTE->NAPP - FLAGS "R" - HELP "Inserire il numero di apprendisti presenti in ditta" -END - -DATE FLD_GD2_DINIZIOATT -BEGIN - PROMPT 1 5 "Inizio Attivit… " - FIELD LF_NDITTE->DINIZIOATT - HELP "Inserire la data di inizio attivita'" -END - -NUMBER FLD_GD2_NULC 3 -BEGIN - PROMPT 45 5 "Numero Unit… Locali " - FIELD LF_NDITTE->NULC - FLAGS "RZ" - HELP "Inserire il numero dell'unit' locale di appartenenza" -END - -STRING FLD_GD2_NENASARCO 12 -BEGIN - PROMPT 1 6 "Enasarco " - FIELD LF_NDITTE->NENASARCO - HELP "Inserire il numero di iscrizione all'ENASARCO" -END - -NUMBER FLD_GD2_MESIREDD 3 -BEGIN - PROMPT 45 6 "Mesi produzione reddito " - FIELD LF_NDITTE->MESIREDD - NUM_EXPR {(#THIS_FIELD>=0) && (#THIS_FIELD<=12)} - FLAGS "R" - HELP "Inserire il numero di mesi di produzione reddito" - WARNING "Numero di mesi non corretto" -END - -STRING FLD_GD2_ABIBAN 5 -BEGIN - PROMPT 1 7 "Banca : Cod.ABI " - FIELD LF_NDITTE->ABIBAN - FLAGS "RZ" - USE %BAN - INPUT CODTAB[1,5] FLD_GD2_ABIBAN - INPUT CODTAB[6,10] FLD_GD2_CABBAN - DISPLAY "ABI " CODTAB[1,5] - DISPLAY "CAB " CODTAB[6,10] - DISPLAY "Denominazione@50" S0 - OUTPUT FLD_GD2_ABIBAN CODTAB[1,5] - OUTPUT FLD_GD2_CABBAN CODTAB[6,10] - OUTPUT FLD_GD2_ABIBAN_TABBANCHE_DESCR S0 - HELP "Inserire il ABI della banca della ditta" - CHECKTYPE NORMAL - WARNING "Banca assente" -END - -STRING FLD_GD2_CABBAN 5 -BEGIN - PROMPT 7 8 ": Cod.CAB " - FIELD LF_NDITTE->CABBAN - FLAGS "RZ" - COPY ALL FLD_GD2_ABIBAN - HELP "Inserire il codice CAB della banca" - CHECKTYPE NORMAL - WARNING "Banca assente" -END - -STRING FLD_GD2_ABIBAN_TABBANCHE_DESCR 47 -BEGIN - PROMPT 25 8 "" - FLAGS "D" -END - -NUMBER LST_GD2_SITSOC 1 -BEGIN - PROMPT 45 9 "Situazione societ… " - FIELD LF_NDITTE->SITSOC - SHEET "Codice|Situazione@70" - INPUT LST_GD2_SITSOC - OUTPUT LST_GD2_SITSOC - HELP "Inserire il codice della situazione della societ…" - ITEM " |Sconosciuta" - ITEM "1|Periodo d'imposta in cui ha avuto inizio la liquidazione" - ITEM "2|Periodi d'imposta successivi a quello in cui ha avuto inizio la liquidazione" - ITEM "3|Periodo d'imposta in cui ha avuto termine la liquidazione" - ITEM "4|Periodo d'imposta in cui si e' verificata l' estinzione del soggetto" - ITEM "5|Periodo d'imposta in cui si e' variato l' assoggettamento IRPEG del soggetto" - ITEM "6|Periodo d'imposta normale" -END - -NUMBER LST_GD2_STATOSOC 1 -BEGIN - PROMPT 1 9 "Stato societ… " - FIELD LF_NDITTE->STATOSOC - SHEET "Codice|Stato@70" - INPUT LST_GD2_STATOSOC - OUTPUT LST_GD2_STATOSOC - HELP "Inserire il codice dello stato della societ…" - ITEM " |Sconosciuto" - ITEM "1|Soggetto in normale attivita'" - ITEM "2|Soggetto in liquidazione per cessazione di attivita'" - ITEM "3|Soggetto in fallimento o in liquidazione coatta amministrativa" - ITEM "4|Soggetto estinto" -END - -GROUPBOX DLG_NULL 76 5 -BEGIN - PROMPT 0 10 "Codici statistici" -END - -STRING FLD_GD2_CODSTAT1 7 -BEGIN - PROMPT 1 11 "1 " - FIELD LF_NDITTE->CODSTAT1 - USE %STT - INPUT CODTAB FLD_GD2_CODSTAT1 - DISPLAY "Codice" CODTAB - DISPLAY "Descrizione@50" S0 - OUTPUT FLD_GD2_CODSTAT1 CODTAB - OUTPUT FLD_GD2_CODSTAT1_TABSTT_S0 S0 - HELP "Inserire il primo codice statistico" - CHECKTYPE NORMAL - WARNING "Codice assente" -END - -STRING FLD_GD2_CODSTAT1_TABSTT_S0 55 -BEGIN - PROMPT 17 11 "" - FLAGS "D" - HELP "" -END - -STRING FLD_GD2_CODSTAT2 7 -BEGIN - PROMPT 1 12 "2 " - FIELD LF_NDITTE->CODSTAT2 - COPY USE FLD_GD2_CODSTAT1 - INPUT CODTAB FLD_GD2_CODSTAT2 - COPY DISPLAY FLD_GD2_CODSTAT1 - OUTPUT FLD_GD2_CODSTAT2 CODTAB - OUTPUT FLD_GD2_CODSTAT2_TABSTT_S0 S0 - HELP "Inserire il secondo codice statistico" - WARNING "Codice assente" -END - -STRING FLD_GD2_CODSTAT2_TABSTT_S0 55 -BEGIN - PROMPT 17 12 "" - FLAGS "D" - HELP "" -END - -STRING FLD_GD2_CODSTAT3 7 -BEGIN - PROMPT 1 13 "3 " - FIELD LF_NDITTE->CODSTAT3 - COPY USE FLD_GD2_CODSTAT1 - INPUT CODTAB FLD_GD2_CODSTAT3 - COPY DISPLAY FLD_GD2_CODSTAT1 - OUTPUT FLD_GD2_CODSTAT3 CODTAB - OUTPUT FLD_GD2_CODSTAT3_TABSTT_S0 S0 - HELP "Inserire il terzo codice statistico" - CHECKTYPE NORMAL - WARNING "Codice assente" -END - -STRING FLD_GD2_CODSTAT3_TABSTT_S0 55 -BEGIN - PROMPT 17 13 "" - FLAGS "D" - HELP "" -END - -ENDPAGE - -PAGE "Ditte 4/4" -1 -1 77 18 - -GROUPBOX DLG_NULL 76 4 -BEGIN - PROMPT 0 0 "" - FLAGS "R" -END - -NUMBER DLG_NULL 5 -BEGIN - PROMPT 1 1 "Codice " - FLAGS "RD" - GROUP 1 -END - -STRING DLG_NULL 50 -BEGIN - PROMPT 1 2 "Ragione sociale " - FLAGS "D" - GROUP 2 -END - -STRING FLD_GD3_FIRMAT 5 -BEGIN - PROMPT 1 4 "Firmatario " - FIELD LF_NDITTE->FIRMAT - FLAGS "R" - USE LF_ANAG KEY 1 - INPUT TIPOA "F" - INPUT CODANAGR FLD_GD3_FIRMAT - DISPLAY "Tipo" TIPOA - DISPLAY "Codice" CODANAGR - DISPLAY "Nome@50" RAGSOC - OUTPUT FLD_GD3_FIRMAT CODANAGR - OUTPUT FLD_GD3_FIRMAT_ANAGR_RAGSOC RAGSOC - HELP "Inserire il codice anagrafico del firmatario" - CHECKTYPE NORMAL - WARNING "Anagrafica assente" - ADD RUN ba4 -1 -END - -STRING FLD_GD3_FIRMAT_ANAGR_RAGSOC 50 -BEGIN - PROMPT 17 5 "" - USE LF_ANAG KEY 2 - INPUT TIPOA "F" - INPUT RAGSOC FLD_GD3_FIRMAT_ANAGR_RAGSOC - DISPLAY "Nome@50" RAGSOC - DISPLAY "Tipo" TIPOA - DISPLAY "Codice" CODANAGR - OUTPUT FLD_GD3_FIRMAT CODANAGR - OUTPUT FLD_GD3_FIRMAT_ANAGR_RAGSOC RAGSOC - ADD RUN ba4 -1 -END - -BOOLEAN CHK_GD3_ESILOR -BEGIN - PROMPT 1 6 "Esenzione ILOR" - FIELD LF_NDITTE->ESILOR - HELP "Indicare l'eventuale esenzione ILOR della ditta" -END - -BOOLEAN CHK_GD3_REGSTATSP -BEGIN - PROMPT 27 6 "Statuto speciale" - FIELD LF_NDITTE->REGSTATSP - HELP "Indicare se la regione di residenza e' ha statuto speciale" -END - -BOOLEAN CHK_GD3_AZCONIUG -BEGIN - PROMPT 54 6 "Azienda coniugale" - FIELD LF_NDITTE->AZCONIUG - HELP "Indicare se si tratta di impresa coniugale" -END - -BOOLEAN CHK_GD3_CONDFAM -BEGIN - PROMPT 1 7 "Conduzione familiare" - FIELD LF_NDITTE->CONDFAM - HELP "Indicare se la ditta e' a conduzione familiare" -END - -BOOLEAN CHK_GD3_DEDART13 -BEGIN - PROMPT 27 7 "Deduzioni art.13" - FIELD LF_NDITTE->DEDART13 - HELP "Indicare se la ditta ha diritto a deduzioni secondo l'articolo 13" -END - -BOOLEAN CHK_GD3_RICSUP20 -BEGIN - PROMPT 54 7 "Ricavi > 20%" - FIELD LF_NDITTE->RICSUP20% - HELP "Indicare se i ricavi sono superiore al 20%" -END - -LIST FLD_GD3_CARRAPP 21 -BEGIN - PROMPT 1 8 "Carica " - FIELD LF_NDITTE->CARRAPP - HELP "Inserire il codice della carica del rappresentante" - ITEMS " |Nessun rappresentante" - MESSAGE RESET,4@|DISABLE,4@ - ITEMS "1|Rappresentante legale" - MESSAGE ENABLE,4@ - ITEMS "2|Curatore fallimentare" - MESSAGE ENABLE,4@ - ITEMS "3|Liquidatore" - MESSAGE ENABLE,4@ - ITEMS "4|Socio amministratore" - MESSAGE ENABLE,4@ -END - -DATE FLD_GD3_DECCARRAPP -BEGIN - PROMPT 50 8 "Decorrenza " - FIELD LF_NDITTE->DECCARRAPP - GROUP 4 - HELP "Inserire la data di decorrenza della rappresentanza" - WARNING "Data non coerente" - VALIDATE DATE_CMP_FUNC >= FLD_GD2_DINIZIOATT -END - -STRING FLD_GD3_RAPPR 5 -BEGIN - PROMPT 1 9 "Rappresentante " - FIELD LF_NDITTE->RAPPR - FLAGS "R" - GROUP 4 - COPY USE FLD_GD3_FIRMAT - INPUT TIPOA "F" - INPUT CODANAGR FLD_GD3_RAPPR - COPY DISPLAY FLD_GD3_FIRMAT - OUTPUT FLD_GD3_RAPPR CODANAGR - OUTPUT FLD_GD3_RAPPR_ANAGR_RAGSOC RAGSOC - HELP "Inserire il codice del rapppresentante legale" - CHECKTYPE NORMAL - WARNING "Anagrafica assente" - ADD RUN ba4 -1 -END - -STRING FLD_GD3_RAPPR_ANAGR_RAGSOC 50 -BEGIN - PROMPT 17 10 "" - COPY USE FLD_GD3_FIRMAT_ANAGR_RAGSOC - INPUT RAGSOC FLD_GD3_RAPPR_ANAGR_RAGSOC - COPY DISPLAY FLD_GD3_FIRMAT_ANAGR_RAGSOC - OUTPUT FLD_GD3_RAPPR CODANAGR - OUTPUT FLD_GD3_RAPPR_ANAGR_RAGSOC RAGSOC - ADD RUN ba4 -1 - GROUP 4 -END - -TEXT DLG_NULL -BEGIN - PROMPT 1 11 "Denominazione Estesa" -END - -STRING FLD_DE_DENEST1 70 -BEGIN - PROMPT 3 12 "" - FIELD LF_NDITTE->DENEST1 - HELP "Inserire la prima riga della denominazione estesa" -END - -STRING FLD_DE_DENEST2 70 -BEGIN - PROMPT 3 13 "" - FIELD LF_NDITTE->DENEST2 - HELP "Inserire la seconda riga della denominazione estesa" -END - -STRING FLD_DE_DENEST3 70 -BEGIN - PROMPT 3 14 "" - FIELD LF_NDITTE->DENEST3 - HELP "Inserire la terza riga della denominazione estesa" -END - -ENDPAGE - -ENDMASK +#include "ba4300.h" + +TOOLBAR "" 0 19 0 3 + +BUTTON DLG_ATT 8 1 +BEGIN + PROMPT -16 -3 "Attivita'" + MESSAGE K_F6 +END + +BUTTON DLG_ULC 8 1 +BEGIN + PROMPT -26 -3 "U.Locali" + MESSAGE K_F5 +END + +BUTTON DLG_SOC 8 1 +BEGIN + PROMPT -36 -3 "Soci" + MESSAGE K_F7 +END + +BUTTON DLG_REG 8 1 +BEGIN + PROMPT -46 -3 "Registri" + MESSAGE K_F8 +END + +#include +ENDPAGE + +PAGE "Ditte 1/4" -1 -1 77 18 + +GROUPBOX DLG_NULL 76 4 +BEGIN + PROMPT 0 0 "" + FLAGS "R" +END + +NUMBER FLD_GD1_CODDITTA 5 +BEGIN + PROMPT 1 1 "Codice " + FIELD LF_NDITTE->CODDITTA + FLAGS "RG" + KEY 1 + USE LF_NDITTE KEY 1 + INPUT CODDITTA FLD_GD1_CODDITTA + DISPLAY "Codice" CODDITTA + DISPLAY "Ragione sociale@50" RAGSOC + OUTPUT FLD_GD1_CODDITTA CODDITTA + OUTPUT FLD_GD1_CODDITTAH CODDITTA + OUTPUT FLD_GD1_RAGSOC RAGSOC + HELP "Codice della ditta" + CHECKTYPE REQUIRED + MESSAGE COPY,1@ + MESSAGE COPY,FLD_GD1_CODDITTAH +END + +NUMBER FLD_GD1_CODDITTAH 5 +BEGIN + PROMPT 1 1 "Codice " + FIELD LF_NDITTE->CODDITTA + FLAGS "RG" + USE LF_NDITTE KEY 3 + INPUT TIPOA FLD_GD1_TIPOA + INPUT CODANAGR FLD_GD1_CODANAGR + INPUT CODDITTA FLD_GD1_CODDITTAH + DISPLAY "Codice" CODDITTA + DISPLAY "Ragione sociale@50" RAGSOC + OUTPUT FLD_GD1_CODDITTAH CODDITTA + OUTPUT FLD_GD1_CODDITTA CODDITTA + OUTPUT FLD_GD1_RAGSOC RAGSOC + CHECKTYPE REQUIRED + MESSAGE COPY,1@ + MESSAGE COPY,FLD_GD1_CODDITTA + KEY 1 +END + +STRING FLD_GD1_RAGSOC 50 +BEGIN + PROMPT 1 2 "Ragione sociale " + FIELD LF_NDITTE->RAGSOC + KEY 2 + USE LF_NDITTE KEY 2 + INPUT RAGSOC FLD_GD1_RAGSOC + INPUT CODDITTA FLD_GD1_CODDITTA + DISPLAY "Codice" CODDITTA + DISPLAY "Ragione sociale@50" RAGSOC + OUTPUT FLD_GD1_CODDITTA CODDITTA + OUTPUT FLD_GD1_RAGSOC RAGSOC + HELP "Inserire la ragione sociale della ditta" + CHECKTYPE REQUIRED + FLAGS "G" + MESSAGE COPY,2@ +END + +GROUPBOX DLG_NULL 76 4 +BEGIN + PROMPT 0 4 "Anagrafica" +END + +LIST FLD_GD1_TIPOA 11 +BEGIN + PROMPT 1 5 "Tipo " + FIELD LF_NDITTE->TIPOA + ITEM "F|Fisica" + ITEM "G|Giuridica" +END + +STRING FLD_GD1_CODANAGR 5 +BEGIN + PROMPT 46 5 "Codice " + FIELD LF_NDITTE->CODANAGR + FLAGS "R" + USE LF_ANAG KEY 1 + INPUT TIPOA FLD_GD1_TIPOA + INPUT CODANAGR FLD_GD1_CODANAGR + DISPLAY "Tipo" TIPOA + DISPLAY "Codice" CODANAGR + DISPLAY "Ragione sociale@50" RAGSOC + OUTPUT FLD_GD1_CODANAGR CODANAGR + OUTPUT FLD_GD1_TIPOA TIPOA + OUTPUT FLD_GD1_CODANAGR_ANAGR_RAGSOC RAGSOC + HELP "Inserire il codice della anagrafica" + CHECKTYPE REQUIRED + WARNING "Anagrafica assente" + ADD RUN ba4 -1 +END + +STRING FLD_GD1_CODANAGR_ANAGR_RAGSOC 50 +BEGIN + PROMPT 1 6 "Denominazione " + USE LF_ANAG KEY 2 + INPUT TIPOA FLD_GD1_TIPOA + INPUT RAGSOC FLD_GD1_CODANAGR_ANAGR_RAGSOC + DISPLAY "Ragione Sociale@50" RAGSOC + DISPLAY "Tipo" TIPOA + DISPLAY "Codice" CODANAGR + OUTPUT FLD_GD1_TIPOA TIPOA + OUTPUT FLD_GD1_CODANAGR CODANAGR + OUTPUT FLD_GD1_CODANAGR_ANAGR_RAGSOC RAGSOC + ADD RUN ba4 -1 +END + +GROUPBOX DLG_NULL 76 4 +BEGIN + PROMPT 0 8 "Attivita' principale" +END + +STRING FLD_GD1_CODATTPREV 5 +BEGIN + PROMPT 1 9 "Codice " + FIELD LF_NDITTE->CODATTPREV + FLAGS "URZ" + USE %AIS + INPUT CODTAB FLD_GD1_CODATTPREV + DISPLAY "Codice" CODTAB + DISPLAY "Attivita' " S0 + OUTPUT FLD_GD1_CODATTPREV CODTAB + OUTPUT FLD_GD1_CODATTPREV_TABATT_DESCR S0 + HELP "Inserire il codice dell'attivita' prevalente della ditta" + CHECKTYPE REQUIRED + WARNING "Codice attivita' assente" +END + +STRING FLD_GD1_CODATTPREV_TABATT_DESCR 50 +BEGIN + PROMPT 1 10 "Nome " + FLAGS "D" + HELP "" +END + +GROUPBOX DLG_NULL 76 4 +BEGIN + PROMPT 0 12 "Telefoni" +END + +STRING FLD_GD1_PTEL 10 +BEGIN + PROMPT 1 13 "Telefono : Prefisso " + FIELD LF_NDITTE->PTEL + HELP "Inserire il prefisso telefonico della ditta" +END + +STRING FLD_GD1_TEL 30 +BEGIN + PROMPT 34 13 "Numero " + FIELD LF_NDITTE->TEL + HELP "Inserire il numero di telefono della ditta" +END + +STRING FLD_GD1_PFAX 10 +BEGIN + PROMPT 1 14 "FAX : Prefisso " + FIELD LF_NDITTE->PFAX + HELP "Inserire il prefisso telefonico del fax della ditta" +END + +STRING FLD_GD1_FAX 30 +BEGIN + PROMPT 34 14 "Numero " + FIELD LF_NDITTE->FAX + HELP "Inserire il numero di telefono del fax della ditta" +END + +ENDPAGE + +PAGE "Ditte 2/4" -1 -1 77 18 + +GROUPBOX DLG_NULL 76 4 +BEGIN + PROMPT 0 0 "" + FLAGS "R" +END + +NUMBER DLG_NULL 5 +BEGIN + PROMPT 1 1 "Codice " + FLAGS "RD" + GROUP 1 +END + +STRING DLG_NULL 50 +BEGIN + PROMPT 1 2 "Ragione sociale " + FLAGS "D" + GROUP 2 +END + +RADIOBUTTON RDB_GD1_FREQVIVA 20 +BEGIN + PROMPT 1 4 "Frequenza IVA" + FIELD LF_NDITTE->FREQVIVA + HELP "Inserire la frequenza di liquidazione dell'IVA" + ITEM "M|Mensile" + ITEM "T|Trimestrale" +END + +STRING FLD_GD1_PERRIF 20 +BEGIN + PROMPT 24 5 "Persona di riferimento " + FIELD LF_NDITTE->PERRIF + HELP "Inserire il nominativo della persona a cui fare rfierimento" +END + +BOOLEAN CHK_GD1_ARTIG +BEGIN + PROMPT 1 8 "Artigiano" + FIELD LF_NDITTE->ARTIG + HELP "Dire se si tratta di una ditta artigiana" + MESSAGE FALSE DISABLE,3@|RESET,3@ + MESSAGE TRUE ENABLE,3@ +END + +GROUPBOX DLG_NULL 76 5 +BEGIN + PROMPT 0 9 "" +END + +STRING FLD_GD1_NISCRAA 10 +BEGIN + PROMPT 1 10 "Iscriz. Albo N." + FIELD LF_NDITTE->NISCRAA + FLAGS "R" + HELP "Inserire il numero di iscrizione all'albo" + GROUP 3 +END + +DATE FLD_GD1_DATAISCRAA +BEGIN + PROMPT 52 10 "Data " + FIELD LF_NDITTE->DATAISCRAA + FLAGS "R" + HELP "Inserire la data di iscrizione all'albo" + WARNING "Data non coerente" + VALIDATE DATE_CMP_FUNC >= FLD_GD2_DINIZIOATT + GROUP 3 +END + +STRING FLD_GD1_COMAA 4 +BEGIN + PROMPT 1 11 "Comune : Codice " + FIELD LF_NDITTE->COMAA + FLAGS "U" + USE LF_COMUNI KEY 1 + INPUT STATO "" + INPUT COM FLD_GD1_COMAA +#include + OUTPUT FLD_GD1_COMAA COM + OUTPUT FLD_GD1_COMAA_COMUNI_DESCR DENCOM + OUTPUT FLD_GD1_CAPAA CAPCOM + HELP "Inserire il codice del comune a cui si e' iscritti all'albo" + CHECKTYPE NORMAL + WARNING "Comune assente" + ADD MASK ba4100a + GROUP 3 +END + +STRING FLD_GD1_CAPAA 5 +BEGIN + PROMPT 52 11 "CAP " + FIELD LF_NDITTE->CAPAA + FLAGS "RZ" + HELP "Inserire il CAP del comune a cui si e' iscritti all'albo" + GROUP 3 +END + +STRING FLD_GD1_COMAA_COMUNI_DESCR 50 +BEGIN + PROMPT 8 12 ": Nome " + USE LF_COMUNI KEY 2 SELECT STATO="" + INPUT COM FLD_GD1_COMAA_COMUNI_DESCR +#include + OUTPUT FLD_GD1_COMAA COM + OUTPUT FLD_GD1_COMAA_COMUNI_DESCR DENCOM + OUTPUT FLD_GD1_CAPAA CAPCOM + ADD MASK ba4100a + GROUP 3 +END + +BOOLEAN CHK_GD1_CONTORD +BEGIN + PROMPT 1 14 "Contabilit… ordinaria" + FIELD LF_NDITTE->CONTORD + HELP "Indicare se la ditta tiene una contabilita' ordinaria" +END + +BOOLEAN CHK_GD1_REGMAG +BEGIN + PROMPT 52 14 "Regime Magazzino" + FIELD LF_NDITTE->REGMAG + HELP "Indicare se si utilizza un regime di magazzino" +END + +BOOLEAN CHK_GD1_IMPRFAM +BEGIN + PROMPT 1 15 "Impresa familiare" + FIELD LF_NDITTE->IMPRFAM + HELP "Dire se si tratta di una impresa familiare" +END + +BOOLEAN CHK_GD1_FLIVA11Q +BEGIN + PROMPT 52 15 "IVA 11 Quater" + FIELD LF_NDITTE->FLIVA11Q + HELP "Dire se soggetta all'articolo IVA 11 Quater" +END + +ENDPAGE + +PAGE "Ditte 3/4" -1 -1 77 18 + +GROUPBOX DLG_NULL 76 4 +BEGIN + PROMPT 0 0 "" + FLAGS "R" +END + +NUMBER DLG_NULL 5 +BEGIN + PROMPT 1 1 "Codice " + FLAGS "RD" + GROUP 1 +END + +STRING DLG_NULL 50 +BEGIN + PROMPT 1 2 "Ragione sociale " + FLAGS "D" + GROUP 2 +END + +LIST LST_GD2_DATLAV 20 +BEGIN + PROMPT 1 4 "Datore lavoro " + FIELD LF_NDITTE->DATLAV + HELP "Inserire il tipo di datore di lavoro" + ITEM "1|Datore di lavoro" + ITEM "2|Non datore di lavoro" + ITEM "3|Datore Agricolo" +END + +NUMBER FLD_GD2_NAPP 3 +BEGIN + PROMPT 45 4 "Numero apprendisti " + FIELD LF_NDITTE->NAPP + FLAGS "R" + HELP "Inserire il numero di apprendisti presenti in ditta" +END + +DATE FLD_GD2_DINIZIOATT +BEGIN + PROMPT 1 5 "Inizio Attivit… " + FIELD LF_NDITTE->DINIZIOATT + HELP "Inserire la data di inizio attivita'" +END + +NUMBER FLD_GD2_NULC 3 +BEGIN + PROMPT 45 5 "Numero Unit… Locali " + FIELD LF_NDITTE->NULC + FLAGS "RZ" + HELP "Inserire il numero dell'unit' locale di appartenenza" +END + +STRING FLD_GD2_NENASARCO 12 +BEGIN + PROMPT 1 6 "Enasarco " + FIELD LF_NDITTE->NENASARCO + HELP "Inserire il numero di iscrizione all'ENASARCO" +END + +NUMBER FLD_GD2_MESIREDD 3 +BEGIN + PROMPT 45 6 "Mesi produzione reddito " + FIELD LF_NDITTE->MESIREDD + NUM_EXPR {(#THIS_FIELD>=0) && (#THIS_FIELD<=12)} + FLAGS "R" + HELP "Inserire il numero di mesi di produzione reddito" + WARNING "Numero di mesi non corretto" +END + +STRING FLD_GD2_ABIBAN 5 +BEGIN + PROMPT 1 7 "Banca : Cod.ABI " + FIELD LF_NDITTE->ABIBAN + FLAGS "RZ" + USE %BAN + INPUT CODTAB[1,5] FLD_GD2_ABIBAN + INPUT CODTAB[6,10] FLD_GD2_CABBAN + DISPLAY "ABI " CODTAB[1,5] + DISPLAY "CAB " CODTAB[6,10] + DISPLAY "Denominazione@50" S0 + OUTPUT FLD_GD2_ABIBAN CODTAB[1,5] + OUTPUT FLD_GD2_CABBAN CODTAB[6,10] + OUTPUT FLD_GD2_ABIBAN_TABBANCHE_DESCR S0 + HELP "Inserire il ABI della banca della ditta" + CHECKTYPE NORMAL + WARNING "Banca assente" +END + +STRING FLD_GD2_CABBAN 5 +BEGIN + PROMPT 7 8 ": Cod.CAB " + FIELD LF_NDITTE->CABBAN + FLAGS "RZ" + COPY ALL FLD_GD2_ABIBAN + HELP "Inserire il codice CAB della banca" + CHECKTYPE NORMAL + WARNING "Banca assente" +END + +STRING FLD_GD2_ABIBAN_TABBANCHE_DESCR 47 +BEGIN + PROMPT 25 8 "" + FLAGS "D" +END + +NUMBER LST_GD2_SITSOC 1 +BEGIN + PROMPT 45 9 "Situazione societ… " + FIELD LF_NDITTE->SITSOC + SHEET "Codice|Situazione@70" + INPUT LST_GD2_SITSOC + OUTPUT LST_GD2_SITSOC + HELP "Inserire il codice della situazione della societ…" + ITEM " |Sconosciuta" + ITEM "1|Periodo d'imposta in cui ha avuto inizio la liquidazione" + ITEM "2|Periodi d'imposta successivi a quello in cui ha avuto inizio la liquidazione" + ITEM "3|Periodo d'imposta in cui ha avuto termine la liquidazione" + ITEM "4|Periodo d'imposta in cui si e' verificata l' estinzione del soggetto" + ITEM "5|Periodo d'imposta in cui si e' variato l' assoggettamento IRPEG del soggetto" + ITEM "6|Periodo d'imposta normale" +END + +NUMBER LST_GD2_STATOSOC 1 +BEGIN + PROMPT 1 9 "Stato societ… " + FIELD LF_NDITTE->STATOSOC + SHEET "Codice|Stato@70" + INPUT LST_GD2_STATOSOC + OUTPUT LST_GD2_STATOSOC + HELP "Inserire il codice dello stato della societ…" + ITEM " |Sconosciuto" + ITEM "1|Soggetto in normale attivita'" + ITEM "2|Soggetto in liquidazione per cessazione di attivita'" + ITEM "3|Soggetto in fallimento o in liquidazione coatta amministrativa" + ITEM "4|Soggetto estinto" +END + +GROUPBOX DLG_NULL 76 5 +BEGIN + PROMPT 0 10 "Codici statistici" +END + +STRING FLD_GD2_CODSTAT1 7 +BEGIN + PROMPT 1 11 "1 " + FIELD LF_NDITTE->CODSTAT1 + USE %STT + INPUT CODTAB FLD_GD2_CODSTAT1 + DISPLAY "Codice" CODTAB + DISPLAY "Descrizione@50" S0 + OUTPUT FLD_GD2_CODSTAT1 CODTAB + OUTPUT FLD_GD2_CODSTAT1_TABSTT_S0 S0 + HELP "Inserire il primo codice statistico" + CHECKTYPE NORMAL + WARNING "Codice assente" +END + +STRING FLD_GD2_CODSTAT1_TABSTT_S0 55 +BEGIN + PROMPT 17 11 "" + FLAGS "D" + HELP "" +END + +STRING FLD_GD2_CODSTAT2 7 +BEGIN + PROMPT 1 12 "2 " + FIELD LF_NDITTE->CODSTAT2 + COPY USE FLD_GD2_CODSTAT1 + INPUT CODTAB FLD_GD2_CODSTAT2 + COPY DISPLAY FLD_GD2_CODSTAT1 + OUTPUT FLD_GD2_CODSTAT2 CODTAB + OUTPUT FLD_GD2_CODSTAT2_TABSTT_S0 S0 + HELP "Inserire il secondo codice statistico" + WARNING "Codice assente" +END + +STRING FLD_GD2_CODSTAT2_TABSTT_S0 55 +BEGIN + PROMPT 17 12 "" + FLAGS "D" + HELP "" +END + +STRING FLD_GD2_CODSTAT3 7 +BEGIN + PROMPT 1 13 "3 " + FIELD LF_NDITTE->CODSTAT3 + COPY USE FLD_GD2_CODSTAT1 + INPUT CODTAB FLD_GD2_CODSTAT3 + COPY DISPLAY FLD_GD2_CODSTAT1 + OUTPUT FLD_GD2_CODSTAT3 CODTAB + OUTPUT FLD_GD2_CODSTAT3_TABSTT_S0 S0 + HELP "Inserire il terzo codice statistico" + CHECKTYPE NORMAL + WARNING "Codice assente" +END + +STRING FLD_GD2_CODSTAT3_TABSTT_S0 55 +BEGIN + PROMPT 17 13 "" + FLAGS "D" + HELP "" +END + +ENDPAGE + +PAGE "Ditte 4/4" -1 -1 77 18 + +GROUPBOX DLG_NULL 76 4 +BEGIN + PROMPT 0 0 "" + FLAGS "R" +END + +NUMBER DLG_NULL 5 +BEGIN + PROMPT 1 1 "Codice " + FLAGS "RD" + GROUP 1 +END + +STRING DLG_NULL 50 +BEGIN + PROMPT 1 2 "Ragione sociale " + FLAGS "D" + GROUP 2 +END + +STRING FLD_GD3_FIRMAT 5 +BEGIN + PROMPT 1 4 "Firmatario " + FIELD LF_NDITTE->FIRMAT + FLAGS "R" + USE LF_ANAG KEY 1 + INPUT TIPOA "F" + INPUT CODANAGR FLD_GD3_FIRMAT + DISPLAY "Tipo" TIPOA + DISPLAY "Codice" CODANAGR + DISPLAY "Nome@50" RAGSOC + OUTPUT FLD_GD3_FIRMAT CODANAGR + OUTPUT FLD_GD3_FIRMAT_ANAGR_RAGSOC RAGSOC + HELP "Inserire il codice anagrafico del firmatario" + CHECKTYPE NORMAL + WARNING "Anagrafica assente" + ADD RUN ba4 -1 +END + +STRING FLD_GD3_FIRMAT_ANAGR_RAGSOC 50 +BEGIN + PROMPT 17 5 "" + USE LF_ANAG KEY 2 + INPUT TIPOA "F" + INPUT RAGSOC FLD_GD3_FIRMAT_ANAGR_RAGSOC + DISPLAY "Nome@50" RAGSOC + DISPLAY "Tipo" TIPOA + DISPLAY "Codice" CODANAGR + OUTPUT FLD_GD3_FIRMAT CODANAGR + OUTPUT FLD_GD3_FIRMAT_ANAGR_RAGSOC RAGSOC + ADD RUN ba4 -1 +END + +BOOLEAN CHK_GD3_ESILOR +BEGIN + PROMPT 1 6 "Esenzione ILOR" + FIELD LF_NDITTE->ESILOR + HELP "Indicare l'eventuale esenzione ILOR della ditta" +END + +BOOLEAN CHK_GD3_REGSTATSP +BEGIN + PROMPT 27 6 "Statuto speciale" + FIELD LF_NDITTE->REGSTATSP + HELP "Indicare se la regione di residenza e' ha statuto speciale" +END + +BOOLEAN CHK_GD3_AZCONIUG +BEGIN + PROMPT 54 6 "Azienda coniugale" + FIELD LF_NDITTE->AZCONIUG + HELP "Indicare se si tratta di impresa coniugale" +END + +BOOLEAN CHK_GD3_CONDFAM +BEGIN + PROMPT 1 7 "Conduzione familiare" + FIELD LF_NDITTE->CONDFAM + HELP "Indicare se la ditta e' a conduzione familiare" +END + +BOOLEAN CHK_GD3_DEDART13 +BEGIN + PROMPT 27 7 "Deduzioni art.13" + FIELD LF_NDITTE->DEDART13 + HELP "Indicare se la ditta ha diritto a deduzioni secondo l'articolo 13" +END + +BOOLEAN CHK_GD3_RICSUP20 +BEGIN + PROMPT 54 7 "Ricavi > 20%" + FIELD LF_NDITTE->RICSUP20% + HELP "Indicare se i ricavi sono superiore al 20%" +END + +LIST FLD_GD3_CARRAPP 21 +BEGIN + PROMPT 1 8 "Carica " + FIELD LF_NDITTE->CARRAPP + HELP "Inserire il codice della carica del rappresentante" + ITEMS " |Nessun rappresentante" + MESSAGE RESET,4@|DISABLE,4@ + ITEMS "1|Rappresentante legale" + MESSAGE ENABLE,4@ + ITEMS "2|Curatore fallimentare" + MESSAGE ENABLE,4@ + ITEMS "3|Liquidatore" + MESSAGE ENABLE,4@ + ITEMS "4|Socio amministratore" + MESSAGE ENABLE,4@ +END + +DATE FLD_GD3_DECCARRAPP +BEGIN + PROMPT 50 8 "Decorrenza " + FIELD LF_NDITTE->DECCARRAPP + GROUP 4 + HELP "Inserire la data di decorrenza della rappresentanza" + WARNING "Data non coerente" + VALIDATE DATE_CMP_FUNC >= FLD_GD2_DINIZIOATT +END + +STRING FLD_GD3_RAPPR 5 +BEGIN + PROMPT 1 9 "Rappresentante " + FIELD LF_NDITTE->RAPPR + FLAGS "R" + GROUP 4 + COPY USE FLD_GD3_FIRMAT + INPUT TIPOA "F" + INPUT CODANAGR FLD_GD3_RAPPR + COPY DISPLAY FLD_GD3_FIRMAT + OUTPUT FLD_GD3_RAPPR CODANAGR + OUTPUT FLD_GD3_RAPPR_ANAGR_RAGSOC RAGSOC + HELP "Inserire il codice del rapppresentante legale" + CHECKTYPE NORMAL + WARNING "Anagrafica assente" + ADD RUN ba4 -1 +END + +STRING FLD_GD3_RAPPR_ANAGR_RAGSOC 50 +BEGIN + PROMPT 17 10 "" + COPY USE FLD_GD3_FIRMAT_ANAGR_RAGSOC + INPUT RAGSOC FLD_GD3_RAPPR_ANAGR_RAGSOC + COPY DISPLAY FLD_GD3_FIRMAT_ANAGR_RAGSOC + OUTPUT FLD_GD3_RAPPR CODANAGR + OUTPUT FLD_GD3_RAPPR_ANAGR_RAGSOC RAGSOC + ADD RUN ba4 -1 + GROUP 4 +END + +TEXT DLG_NULL +BEGIN + PROMPT 1 11 "Denominazione Estesa" +END + +STRING FLD_DE_DENEST1 70 +BEGIN + PROMPT 3 12 "" + FIELD LF_NDITTE->DENEST1 + HELP "Inserire la prima riga della denominazione estesa" +END + +STRING FLD_DE_DENEST2 70 +BEGIN + PROMPT 3 13 "" + FIELD LF_NDITTE->DENEST2 + HELP "Inserire la seconda riga della denominazione estesa" +END + +STRING FLD_DE_DENEST3 70 +BEGIN + PROMPT 3 14 "" + FIELD LF_NDITTE->DENEST3 + HELP "Inserire la terza riga della denominazione estesa" +END + +ENDPAGE + +ENDMASK diff --git a/ba/ba6.cpp b/ba/ba6.cpp index a35d07e74..867622fe2 100755 --- a/ba/ba6.cpp +++ b/ba/ba6.cpp @@ -1,23 +1,21 @@ #include -#include #include #include "ba6.h" -#define usage "Error - usage : %s -0" +#define usage "Errore - uso : %s -{0,1}" int main(int argc,char** argv) - { - int rt = 0 ; - TString p = argv[0], s = argv[1] ; - - if (argc!=2) fatal_box(usage, (const char*) p) ; - else - if (s == "-0") rt = ba6100(argc,argv) ; - if (s == "-1") rt = ba6200(argc,argv) ; - else fatal_box(usage, (const char*) p) ; - return rt; + const int r = (argc > 1) ? atoi(argv[1]) : -1; + + switch (r) + { + case 0:ba6100(argc,argv) ; break; + case 1:ba6200(argc,argv) ; break; + default:error_box(usage, argv[0]) ; break; + } + return r < 0; } diff --git a/ba/ba6200a.uml b/ba/ba6200a.uml index dbe1c54e1..d07069f39 100755 --- a/ba/ba6200a.uml +++ b/ba/ba6200a.uml @@ -1,126 +1,126 @@ -#include "ba6200.h" - -PAGE "" -1 -1 65 14 - -RADIOBUTTON F_SCELTA 25 -BEGIN - PROMPT 1 1 "Stampa per: " - ITEM "1|Codice comune " - MESSAGE HIDE,F_NOMEINI|HIDE,F_NOMEFINE|HIDE,F_NOME - MESSAGE RESET,F_NOMEINI|RESET,F_NOMEFINE|RESET,F_NOME - MESSAGE SHOW,F_CODICEINI|SHOW,F_CODICEFINE|SHOW,F_CODICE - MESSAGE SHOW,F_STATOINI|SHOW,F_STATOFINE - ITEM "2|Denominazione comune" - MESSAGE HIDE,F_CODICEINI|HIDE,F_CODICEFINE|HIDE,F_CODICE - MESSAGE HIDE,F_STATOINI|HIDE,F_STATOFINE - MESSAGE RESET,F_CODICEINI|RESET,F_CODICEFINE|RESET,F_CODICE - MESSAGE RESET,F_STATOINI|RESET,F_STATOFINE - MESSAGE SHOW,F_NOMEINI|SHOW,F_NOMEFINE|SHOW,F_NOME -END - -DATE F_DATA -BEGIN - PROMPT 37 2 "Data di stampa " - FLAGS "A" -END - -GROUPBOX F_CODICE 63 3 -BEGIN - PROMPT 1 5 "" -END - -STRING F_STATOINI 3 -BEGIN - PROMPT 2 6 "Da codice " - USE LF_COMUNI KEY 1 - INPUT STATO F_STATOINI - INPUT COM F_CODICEINI - DISPLAY "Stato" STATO - DISPLAY "Comune" COM - DISPLAY "Denominazione@50" DENCOM - OUTPUT F_STATOINI STATO - OUTPUT F_CODICEINI COM - CHECKTYPE NORMAL -END - -STRING F_CODICEINI 4 -BEGIN - PROMPT 20 6 "" - COPY USE F_STATOINI - INPUT STATO F_STATOINI - INPUT COM F_CODICEINI - COPY DISPLAY F_STATOINI - OUTPUT F_STATOINI STATO - OUTPUT F_CODICEINI COM - CHECKTYPE NORMAL -END - -STRING F_STATOFINE 3 -BEGIN - PROMPT 37 6 "A codice " - COPY USE F_STATOINI - INPUT STATO F_STATOFINE - INPUT COM F_CODICEFINE - COPY DISPLAY F_STATOINI - OUTPUT F_STATOFINE STATO - OUTPUT F_CODICEFINE COM - CHECKTYPE NORMAL -END - -STRING F_CODICEFINE 4 -BEGIN - PROMPT 54 6 "" - COPY USE F_STATOINI - INPUT STATO F_STATOFINE - INPUT COM F_CODICEFINE - COPY DISPLAY F_STATOINI - OUTPUT F_STATOFINE STATO - OUTPUT F_CODICEFINE COM - CHECKTYPE NORMAL -END - -GROUPBOX F_NOME 63 4 -BEGIN - PROMPT 1 5 "" -END - -STRING F_NOMEINI 50 -BEGIN - PROMPT 2 6 "Da nome " - USE LF_COMUNI KEY 2 - INPUT DENCOM F_NOMEINI - DISPLAY "Denominazione@50" DENCOM - OUTPUT F_NOMEINI DENCOM - CHECKTYPE NORMAL -END - -STRING F_NOMEFINE 50 -BEGIN - PROMPT 2 7 "A nome " - COPY USE F_NOMEINI - INPUT DENCOM F_NOMEFINE - COPY DISPLAY F_NOMEINI - OUTPUT F_NOMEFINE DENCOM - CHECKTYPE NORMAL -END - -STRING F_PROVCOM 5 -BEGIN - PROMPT 1 9 "Stampa solo la provincia di " - FLAGS "U" -END - -BUTTON DLG_OK 9 0 -BEGIN - PROMPT 10 12 "" -END - -BUTTON DLG_CANCEL 9 0 -BEGIN - PROMPT 43 12 "" -END - -ENDPAGE - -ENDMASK - +#include "ba6200.h" + +PAGE "" -1 -1 65 14 + +RADIOBUTTON F_SCELTA 25 +BEGIN + PROMPT 1 1 "Stampa per: " + ITEM "1|Codice comune " + MESSAGE HIDE,F_NOMEINI|HIDE,F_NOMEFINE|HIDE,F_NOME + MESSAGE RESET,F_NOMEINI|RESET,F_NOMEFINE|RESET,F_NOME + MESSAGE SHOW,F_CODICEINI|SHOW,F_CODICEFINE|SHOW,F_CODICE + MESSAGE SHOW,F_STATOINI|SHOW,F_STATOFINE + ITEM "2|Denominazione comune" + MESSAGE HIDE,F_CODICEINI|HIDE,F_CODICEFINE|HIDE,F_CODICE + MESSAGE HIDE,F_STATOINI|HIDE,F_STATOFINE + MESSAGE RESET,F_CODICEINI|RESET,F_CODICEFINE|RESET,F_CODICE + MESSAGE RESET,F_STATOINI|RESET,F_STATOFINE + MESSAGE SHOW,F_NOMEINI|SHOW,F_NOMEFINE|SHOW,F_NOME +END + +DATE F_DATA +BEGIN + PROMPT 37 2 "Data di stampa " + FLAGS "A" +END + +GROUPBOX F_CODICE 63 3 +BEGIN + PROMPT 1 5 "" +END + +STRING F_STATOINI 3 +BEGIN + PROMPT 2 6 "Da codice " + USE LF_COMUNI KEY 1 + INPUT STATO F_STATOINI + INPUT COM F_CODICEINI + DISPLAY "Stato" STATO + DISPLAY "Comune" COM + DISPLAY "Denominazione@50" DENCOM + OUTPUT F_STATOINI STATO + OUTPUT F_CODICEINI COM + CHECKTYPE NORMAL +END + +STRING F_CODICEINI 4 +BEGIN + PROMPT 20 6 "" + COPY USE F_STATOINI + INPUT STATO F_STATOINI + INPUT COM F_CODICEINI + COPY DISPLAY F_STATOINI + OUTPUT F_STATOINI STATO + OUTPUT F_CODICEINI COM + CHECKTYPE NORMAL +END + +STRING F_STATOFINE 3 +BEGIN + PROMPT 37 6 "A codice " + COPY USE F_STATOINI + INPUT STATO F_STATOFINE + INPUT COM F_CODICEFINE + COPY DISPLAY F_STATOINI + OUTPUT F_STATOFINE STATO + OUTPUT F_CODICEFINE COM + CHECKTYPE NORMAL +END + +STRING F_CODICEFINE 4 +BEGIN + PROMPT 54 6 "" + COPY USE F_STATOINI + INPUT STATO F_STATOFINE + INPUT COM F_CODICEFINE + COPY DISPLAY F_STATOINI + OUTPUT F_STATOFINE STATO + OUTPUT F_CODICEFINE COM + CHECKTYPE NORMAL +END + +GROUPBOX F_NOME 63 4 +BEGIN + PROMPT 1 5 "" +END + +STRING F_NOMEINI 50 +BEGIN + PROMPT 2 6 "Da nome " + USE LF_COMUNI KEY 2 + INPUT DENCOM F_NOMEINI + DISPLAY "Denominazione@50" DENCOM + OUTPUT F_NOMEINI DENCOM + CHECKTYPE NORMAL +END + +STRING F_NOMEFINE 50 +BEGIN + PROMPT 2 7 "A nome " + COPY USE F_NOMEINI + INPUT DENCOM F_NOMEFINE + COPY DISPLAY F_NOMEINI + OUTPUT F_NOMEFINE DENCOM + CHECKTYPE NORMAL +END + +STRING F_PROVCOM 5 +BEGIN + PROMPT 1 9 "Stampa solo la provincia di " + FLAGS "U" +END + +BUTTON DLG_OK 9 2 +BEGIN + PROMPT -12 -2 "" +END + +BUTTON DLG_CANCEL 9 2 +BEGIN + PROMPT -22 -2 "" +END + +ENDPAGE + +ENDMASK + diff --git a/cg/cg2102.cpp b/cg/cg2102.cpp index bef736716..39f59b84d 100755 --- a/cg/cg2102.cpp +++ b/cg/cg2102.cpp @@ -637,7 +637,7 @@ bool TPrimanota_application::num_handler(TMask_field& f, KEY key) if (key == K_TAB && f.get().not_empty()) { if (app().find(1)) - dispatch_e_char(f.parent(), K_SHIFT_ENTER); + dispatch_e_char(f.parent(), K_AUTO_ENTER); } return TRUE; } @@ -659,7 +659,7 @@ bool TPrimanota_application::caus_query_handler(TMask_field& f, KEY key) { const bool ok = suspended_handler(f, key); // Controlla sospensione if (ok) - dispatch_e_char(f.parent(), K_INS); // Entra in modo inserimento + f.mask().stop_run(K_INS); // Entra in modo inserimento } } diff --git a/cg/cg4.cpp b/cg/cg4.cpp index bbcbf8379..45a7092bb 100755 --- a/cg/cg4.cpp +++ b/cg/cg4.cpp @@ -3,7 +3,7 @@ #include "cg4.h" -#define usage "Error - usage : %s -{0,2,3,4,5}" +const char* const usage = "Errore - uso : %s -{0,2,3,4,5}"; int main(int argc,char** argv) { @@ -24,6 +24,7 @@ int main(int argc,char** argv) default: error_box(usage, argv[0]); } + return n < 0; } diff --git a/cg/cg4400.cpp b/cg/cg4400.cpp index c6f27213a..652093232 100755 --- a/cg/cg4400.cpp +++ b/cg/cg4400.cpp @@ -36,12 +36,9 @@ HIDDEN int compare(const TObject** o1, const TObject** o2) { TRigaiva* r1 = (TRigaiva*)*o1; TRigaiva* r2 = (TRigaiva*)*o2; - TString campo1; - TString campo2; - - campo1.format("%d%4s", r1->_tipodet, (const char*)r1->_codiva); - campo2.format("%d%4s", r2->_tipodet, (const char*)r2->_codiva); - return (strcmp((const char*)campo1, (const char*)campo2)); + TString16 campo1; campo1.format("%d%4s", r1->_tipodet, (const char*)r1->_codiva); + TString16 campo2; campo2.format("%d%4s", r2->_tipodet, (const char*)r2->_codiva); + return (strcmp(campo1, campo2)); } /* diff --git a/cg/cg4400.h b/cg/cg4400.h index 2ee185ae7..70aa3e783 100755 --- a/cg/cg4400.h +++ b/cg/cg4400.h @@ -1,121 +1,121 @@ -// -// cg4400.h -// -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -const int MAXSTR = 128; -static char __tmp[MAXSTR]; - -//enum STAMPA { bollati=1, unici=2 }; -const int TABREG = (int)TTable::name2log("REG"); - -bool filter_func (const TRelation*); -bool my_handler (TMask_field&, KEY); -bool mask_cod (TMask_field&, KEY); +// +// cg4400.h +// +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cglib03.h" + +#include +#include +#include +#include +#include +#include +#include +#include + + +const int MAXSTR = 128; +static char __tmp[MAXSTR]; + +//enum STAMPA { bollati=1, unici=2 }; +const int TABREG = (int)TTable::name2log("REG"); + +bool filter_func (const TRelation*); +bool my_handler (TMask_field&, KEY); +bool mask_cod (TMask_field&, KEY); bool mask_mese (TMask_field&, KEY); bool mask_fino_a_mese (TMask_field&, KEY); -bool mask_select (TMask_field&, KEY); -bool mask_verifica (TMask_field&, KEY); -bool mask_annulla (TMask_field&, KEY); - -class TDati_ditta : public TObject -{ - TLocalisamfile * _nditte, * _anag, *_comuni; - TString _ragsoc, _cofi, _paiva; - TString _comunefis, _viafis, _provfis, _cap; - long _codditta; - int _stampa_width; -protected: - void get_dati_ditta(); - TRectype& look_com (const char * codice); -public: - const char* prima_riga (); - const char* seconda_riga (); - TDati_ditta (long cod_ditta, int stampa_width); - virtual ~TDati_ditta(); -}; - -class CG4400_application : public TPrintapp -{ - friend bool filter_func (const TRelation *r); - friend bool mask_cod (TMask_field&, KEY); - friend bool mask_mese (TMask_field&, KEY); - friend bool mask_fino_a_mese (TMask_field&, KEY); - friend bool my_handler (TMask_field&, KEY); - friend bool mask_select (TMask_field&, KEY); - friend bool mask_verifica (TMask_field&, KEY); - friend bool mask_annulla (TMask_field&, KEY); - - TCursor * _cur; - TRelation *_rel; +bool mask_select (TMask_field&, KEY); +bool mask_verifica (TMask_field&, KEY); +bool mask_annulla (TMask_field&, KEY); + +class TDati_ditta : public TObject +{ + TLocalisamfile * _nditte, * _anag, *_comuni; + TString _ragsoc, _cofi, _paiva; + TString _comunefis, _viafis, _provfis, _cap; + long _codditta; + int _stampa_width; +protected: + void get_dati_ditta(); + TRectype& look_com (const char * codice); +public: + const char* prima_riga (); + const char* seconda_riga (); + TDati_ditta (long cod_ditta, int stampa_width); + virtual ~TDati_ditta(); +}; + +class CG4400_application : public TPrintapp +{ + friend bool filter_func (const TRelation *r); + friend bool mask_cod (TMask_field&, KEY); + friend bool mask_mese (TMask_field&, KEY); + friend bool mask_fino_a_mese (TMask_field&, KEY); + friend bool my_handler (TMask_field&, KEY); + friend bool mask_select (TMask_field&, KEY); + friend bool mask_verifica (TMask_field&, KEY); + friend bool mask_annulla (TMask_field&, KEY); + + TCursor * _cur; + TRelation *_rel; TLocalisamfile *_clifo, *_nditte, *_occas, *_tab, *_tabcom; TTable *_tabreg; - TRigaiva_array _iva_array, _riga_rmi; - TTipodoc_array _doc_array; - TRiga_array _tot_iva_array; - TArray_sheet *_ditte; - TBit_array _selected; - TArray _nomiditte; //array descrizioni ditte per sheet - bool _riferim, _mov_empty; - char _frequiva; - TDate _data_da, _data_a, _data_stampa, _dataregp, _datareg; - long _annoes, _n_ditte; - int _riepil, _tipo_reg, _fino_a_mese, _tipo_stampa; - int _r, _stampa_width; // riga corrente di stampa - real _totale_doc; - TString _codreg, _desc_lib, _codatt, _attivita; - TString _codtab, _tipodoc, _descr_doc; - bool _stampa_tutti_i_registri; - -public: - const char* desc_attivita (const char * codatt); - const char* descr_doc (const char * tipo); - const char* descr_iva (const char * cod); - const char* ricerca_cf (char tipocf, long codcf); - const char* ricerca_occ(const char * occ); - int setta_riga (int, const TRigaiva&, real&, real&, real&, real&); - int riga_rmoviva(); - bool set_print(int); - bool set_ditte(TMask&); - bool compila_reg(); - bool controlla_liquidazione(); - bool controlla_mov(); - void stampa_registri_IVA(); - void set_page_tot_reg(); - void calcola_progressivi(real&, real&, const char*, const int); - void user_create(); - void user_destroy(); - bool preprocess_page(int, int); - int stampa_intestazione_ditta(); - bool preprocess_print(int, int); - print_action postprocess_print(int, int); - void preprocess_header(); - - CG4400_application() : TPrintapp(),_ditte(NULL),_selected(10000), - _nomiditte(100) {} - - virtual ~CG4400_application() {} -}; - - - - + TRigaiva_array _iva_array, _riga_rmi; + TTipodoc_array _doc_array; + TRiga_array _tot_iva_array; + TArray_sheet *_ditte; + TBit_array _selected; + TArray _nomiditte; //array descrizioni ditte per sheet + bool _riferim, _mov_empty; + char _frequiva; + TDate _data_da, _data_a, _data_stampa, _dataregp, _datareg; + long _annoes, _n_ditte; + int _riepil, _tipo_reg, _fino_a_mese, _tipo_stampa; + int _r, _stampa_width; // riga corrente di stampa + real _totale_doc; + TString _codreg, _desc_lib, _codatt, _attivita; + TString _codtab, _tipodoc, _descr_doc; + bool _stampa_tutti_i_registri; + +public: + const char* desc_attivita (const char * codatt); + const char* descr_doc (const char * tipo); + const char* descr_iva (const char * cod); + const char* ricerca_cf (char tipocf, long codcf); + const char* ricerca_occ(const char * occ); + int setta_riga (int, const TRigaiva&, real&, real&, real&, real&); + int riga_rmoviva(); + bool set_print(int); + bool set_ditte(TMask&); + bool compila_reg(); + bool controlla_liquidazione(); + bool controlla_mov(); + void stampa_registri_IVA(); + void set_page_tot_reg(); + void calcola_progressivi(real&, real&, const char*, const int); + void user_create(); + void user_destroy(); + bool preprocess_page(int, int); + int stampa_intestazione_ditta(); + bool preprocess_print(int, int); + print_action postprocess_print(int, int); + void preprocess_header(); + + CG4400_application() : TPrintapp(),_ditte(NULL),_selected(10000), + _nomiditte(100) {} + + virtual ~CG4400_application() {} +}; + + + + diff --git a/cg/cg4500.cpp b/cg/cg4500.cpp index 34bc74899..bb21b7175 100755 --- a/cg/cg4500.cpp +++ b/cg/cg4500.cpp @@ -1,587 +1,583 @@ -// Apertura nuovo esercizio/nuovo esercizio IVA - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -bool mask_dataini (TMask_field&, KEY); -bool mask_newanno (TMask_field&, KEY); -bool mask_annoiva (TMask_field&, KEY); -bool mask_frequenza (TMask_field&, KEY); - -class CG4500_application : public TApplication -{ - friend bool mask_dataini (TMask_field&, KEY); - friend bool mask_newanno (TMask_field&, KEY); - friend bool mask_annoiva (TMask_field&, KEY); - friend bool mask_frequenza (TMask_field&); - - TTable* _esc, * _reg, * _lia, * _lbu; - TLocalisamfile* _nditte; - int _anno, _newanno, _annoiva; - TDate _dataini, _datafin, _datainp, _datafip; - TString _annop; - long _ditta; - char _frequenza; - -public: - virtual bool create(); - virtual bool destroy(); - virtual bool menu(MENU_TAG m); - - void create_files(); - void destroy_files(); - bool set(); - bool setta(); - bool apertura_es(); - bool apertura_iva(); - - CG4500_application() {} -}; - -TDate InizioEsercizio(int anno) -{ - TTable TabEs ("ESC"); - TString codtab; - TDate inizio_es; - - TabEs.zero(); - codtab.format ("%04d", anno); - TabEs.put ("CODTAB", codtab); - TabEs.read(); - if (TabEs.good()) - inizio_es= TabEs.get_date ("D0"); - - return inizio_es; -} - -TDate FineEsercizio(int anno) -{ - TTable TabEs ("ESC"); - TString codtab; - TDate fine_es; - - TabEs.zero(); - codtab.format ("%04d", anno); - TabEs.put ("CODTAB", codtab); - TabEs.read(); - if (TabEs.good()) - fine_es= TabEs.get_date ("D1"); - - return fine_es; -} - -bool mask_newanno (TMask_field& f, KEY k) -{ - TTable TabEs ("ESC"); - TString codtab; - -// if ( (k == K_TAB) && f.mask().is_running() ) - if ( (k == K_ENTER) && f.to_check(k) ) - { - int newanno = f.mask().get_int(F_NUOVOANNO); - int anno = f.mask().get_int(F_ANNO); - TabEs.zero(); - codtab.format ("%04d", newanno); - TabEs.put ("CODTAB", codtab); - TabEs.read(); - if ( TabEs.good() ) - { - f.warning_box ("L'anno inserito e' gia' presente nella tabella degli esercizi!"); - return FALSE; - } - - if (newanno != anno + 1) - { - f.warning_box ("L'anno del nuovo esercizio deve essere successivo all'anno esercizio precedente"); - return FALSE; - } - } - return TRUE; -} - -bool mask_annoiva (TMask_field& f, KEY k) -{ - if ( (k == K_ENTER) && f.to_check(k) ) -//if ( (k == K_TAB) && f.mask().is_running() ) - { - int annoiva = f.mask().get_int(F_ANNOIVA); - TConfig conf(CONFIG_DITTA); - int annoivap = atoi(conf.get("AnLiIv")); - if (annoiva != annoivap + 1) - { - f.warning_box("Il nuovo anno esercizio IVA deve essere successivo all'anno esercizio IVA precedente"); - return FALSE; - } - } - return TRUE; -} - -bool mask_dataini (TMask_field& f, KEY k) -{ - if ( (k == K_ENTER) && f.to_check(k) ) - { - TDate data(f.mask().get(F_DATAINI)); - TDate fine(f.mask().get(F_DATAFINC)); - /* - if ( data.year() != FineEsercizio(anno).year() + 1 ) - { - warning_box ("L'anno del nuovo esercizio deve essere successivo a quello della fine dell'esercizio precedente"); - return FALSE; - } - */ - if ( data <= fine ) - { - f.warning_box ("La data di inizio del nuovo esercizio deve essere superiore alla data di fine esercizio precedente"); - return FALSE; - } - } - return TRUE; -} - -void CG4500_application::create_files() -{ - _nditte = new TLocalisamfile(LF_NDITTE); - _esc = new TTable("ESC"); - _reg = new TTable("REG"); - _lia = new TTable("LIA"); - _lbu = new TTable("%LBU"); -} - -void CG4500_application::destroy_files() -{ - delete _nditte; - delete _esc; - delete _reg; - delete _lia; - delete _lbu; -} - -bool CG4500_application::create() -{ - TApplication::create(); - create_files(); - dispatch_e_menu (BAR_ITEM(1)); - - return TRUE; -} - -bool CG4500_application::destroy() -{ - destroy_files(); - - return TApplication::destroy(); -} - -bool CG4500_application::set() -{ - TTable TabEs ("ESC"); - TMask m ("cg4500a"); - - KEY tasto; - - /* - if (TabEs.last() == NOERR) - { - int anno = TabEs.get_int ("CODTAB"); - TDate inizio = TabEs.get_date("D0"); //data inizio es. in corso - TDate fine = TabEs.get_date("D1"); //data fine es. in corso - - m.show (F_ANNO); - m.show (F_DATAINIC); - m.show (F_DATAFINC); - - m.set(F_ANNO, (long) anno); - m.set(F_DATAINIC, inizio.string()); - m.set(F_DATAFINC, fine.string()); - } - else - { - m.hide(F_ANNO); - m.hide(F_DATAINIC); - m.hide(F_DATAFINC); - } - */ - - if (TabEs.last() != NOERR) - { - error_box("Non e' ancora stato aperto alcun esercizio!"); - return FALSE; - } - - int anno = TabEs.get_int ("CODTAB"); - TDate inizio = TabEs.get_date("D0"); //data inizio es. in corso - TDate fine = TabEs.get_date("D1"); //data fine es. in corso - - m.set(F_ANNO, anno); - m.set(F_DATAINIC, inizio.string()); - m.set(F_DATAFINC, fine.string()); - m.set(F_NUOVOANNO, anno+1); - - m.set_handler (F_NUOVOANNO, mask_newanno); - m.set_handler (F_DATAINI, mask_dataini); - - tasto = m.run(); - - if (tasto == K_ENTER) - { - _anno = m.get_int(F_ANNO); - _datainp = m.get(F_DATAINIC); - _datafip = m.get(F_DATAFINC); - _newanno = m.get_int(F_NUOVOANNO); //nuovo anno esercizio - _dataini = m.get(F_DATAINI); - _datafin = m.get(F_DATAFIN); - - return TRUE; - } - return FALSE; -} - -bool CG4500_application::setta() -{ - TTable TabLia ("LIA"); - TLocalisamfile nditte (LF_NDITTE); - TMask m ("cg4500b"); - KEY tasto; - - TConfig conf(CONFIG_DITTA); - _annop = conf.get("AnLiIv"); - int aivap = atoi(conf.get("AnLiIv")); - TString anno ( format("%04d", aivap+1) ); - - TabLia.zero(); - TabLia.put("CODTAB", anno); - if (TabLia.read() == NOERR) - m.set(F_FREQUENZA, TabLia.get("S7")); - else - { - TabLia.zero(); - TabLia.put("CODTAB", _annop); - if (TabLia.read() == NOERR) - m.set(F_FREQUENZA, TabLia.get("S7")); - else - { - nditte.zero(); - nditte.put("CODDITTA", MainApp()->get_firm()); - if (nditte.read() == NOERR) - m.set(F_FREQUENZA, nditte.get(NDT_FREQVIVA)); - } - } - - m.set(F_ANNOIVA, aivap+1); - - m.set_handler (F_ANNOIVA, mask_annoiva); - - tasto = m.run(); - - if (tasto == K_ENTER) - { - _ditta = m.get_long(F_CODDITTA); - _annoiva = m.get_int(F_ANNOIVA); - _frequenza = m.get(F_FREQUENZA)[0]; - - return TRUE; - } - return FALSE; -} - -bool CG4500_application::menu(MENU_TAG m) -{ - switch (m) - { - case BAR_ITEM(1): - apertura_es(); - break; - case BAR_ITEM(2): - apertura_iva(); - break; - } - //return TApplication::menu(m); - return TRUE; -} - -bool CG4500_application::apertura_es() -{ - TTable TabReg ("REG"); - TTable TabEs ("ESC"); - TString anno (4); - TString annonew(4); - TDate data; - bool ok = FALSE; - - if (!set()) - return FALSE; - - //viene aggiornata la tabella dei registri. Se esisteva gia' un record relativo al nuovo esercizio, viene cancellato. - //In ogni caso ne viene creato uno nuovo relativo al nuovo esercizio. - - TabReg.zero(); - annonew = format ("%04d", _newanno); - TabReg.put ("CODTAB", annonew); - - TRectype r (TabReg.curr()); - - TabReg.read(_isgteq); - - for (; !TabReg.eof(); TabReg.next()) - { - if (TabReg.curr() != r) break; - - int tiporeg = TabReg.get_int("I0"); - if (tiporeg == 5) - TabReg.remove(); - } - - TabReg.zero(); - TRectype nuovo (TabReg.curr()); - anno = format ("%04d", _anno); - TabReg.put ("CODTAB", anno); - - TRectype rec (TabReg.curr()); - - TabReg.read(_isgteq); - - for (; !TabReg.eof(); TabReg.next()) - { - if (TabReg.curr() != rec) break; - - int tiporeg = TabReg.get_int("I0"); - TString cod_reg = TabReg.get("CODTAB"); - cod_reg = cod_reg.mid(4,3); - if (tiporeg == 5) - { - ok = TRUE; - nuovo = TabReg.curr(); - TString16 cod; - cod << _newanno << cod_reg; - nuovo.put("CODTAB", cod); - nuovo.put("D2", data); - nuovo.put("D3", data); - nuovo.put("I6", 0L); - nuovo.put("R1", real(0.0)); - nuovo.put("R2", real(0.0)); - - TabReg.write(nuovo); - } - } - if (!ok) - { - error_box("Non esiste il registro libro giornale relativo all'es. precedente"); - return FALSE; - } - - //viene aggiornata la tabella degli esercizi - TabEs.zero(); - annonew = format ("%04d", _newanno); - TabEs.put ("CODTAB", annonew); - TabEs.put ("D0", _dataini); - TabEs.put ("D1", _datafin); - TabEs.write(); - - message_box("Apertura nuovo esercizio completata"); - return TRUE; -} - -bool CG4500_application::apertura_iva() -{ - TTable TabReg ("REG"); - TTable TabLia ("LIA"); - TTable TabLbu ("%LBU"); - TLocalisamfile nditte (LF_NDITTE); - TDate data; - TString annoiva (4); - bool ok = FALSE; - - if (!setta()) - return FALSE; - - //viene aggiornata la tabella del libro unico. Se esisteva gia' un record relativo al nuovo esercizio IVA, viene cancellato. - //In ogni caso ne viene creato uno nuovo relativo al nuovo esercizio. - - annoiva = format ("%04d", _annoiva); - - TabLbu.zero(); - TabLbu.put ("CODTAB", annoiva); - - TRectype r (TabLbu.curr()); - - TabLbu.read(_isgteq); - - for (; !TabLbu.eof(); TabLbu.next()) - { - if (TabLbu.curr() != r) break; - - TabLbu.remove(); - } - - TabLbu.zero(); - TRectype nrec (TabLbu.curr()); - TabLbu.put ("CODTAB", _annop); - - TRectype rec (TabLbu.curr()); - - TabLbu.read(_isgteq); - - for (; !TabLbu.eof(); TabLbu.next()) - { - if (TabLbu.curr() != rec) break; - - TString cod_lib = TabLbu.get("CODTAB"); - cod_lib = cod_lib.mid(4,3); - - ok = TRUE; - nrec = TabLbu.curr(); - TString16 cod; - cod << _annoiva << cod_lib; - nrec.put("CODTAB", cod); - nrec.put("I0", 0L); - - TabLbu.write(nrec); - } - if (!ok) - { - error_box("Non esistono i registri del libro unico relativi all'anno iva precedente"); - return FALSE; - } - - //viene aggiornata la tabella dei registri. Se esisteva gia' un record relativo al nuovo esercizio, viene cancellato. - //In ogni caso ne viene creato uno nuovo relativo al nuovo esercizio. - - TabReg.zero(); - TabReg.put ("CODTAB", annoiva); - - TRectype rr (TabReg.curr()); - - TabReg.read(_isgteq); - - for (; !TabReg.eof(); TabReg.next()) - { - if (TabReg.curr() != rr) break; - - int tiporeg = TabReg.get_int("I0"); - if ( (tiporeg == 1)||(tiporeg == 2)||(tiporeg == 3) ) - TabReg.remove(); - } - - ok = FALSE; - TabReg.zero(); - TRectype nuovo (TabReg.curr()); - TabReg.put ("CODTAB", _annop); - - TRectype recc (TabReg.curr()); - - TabReg.read(_isgteq); - - for (; !TabReg.eof(); TabReg.next()) - { - if (TabReg.curr() != recc) break; - - int tiporeg = TabReg.get_int("I0"); - TString cod_reg = TabReg.get("CODTAB"); - TDate data_vid = TabReg.get_date("D0"); - data_vid.addyear(); - cod_reg = cod_reg.mid(4,3); - if ( (tiporeg == 1)||(tiporeg == 2)||(tiporeg==3) ) - { - ok = TRUE; - nuovo = TabReg.curr(); - TString16 cod; - cod << _annoiva << cod_reg; - nuovo.put("CODTAB", cod); - nuovo.put("I1", 0L); - nuovo.put("I2", 0L); - nuovo.put("I4", 0L); - nuovo.put("I5", 0L); - nuovo.put("I6", 0L); - nuovo.put("S1", ""); - nuovo.put("D0", data_vid); - nuovo.put("D2", data); - nuovo.put("D3", data); - nuovo.put("R1", real(0.0)); - nuovo.put("R2", real(0.0)); - - TabReg.write(nuovo); - } - } - if (!ok) - { - error_box("Non esistono i registri iva relativi all'anno iva precedente"); - return FALSE; - } - - //viene aggiornata la tabella LIA (liquidazione iva annuale) - TabLia.zero(); - TabLia.put ("CODTAB", annoiva); - if (TabLia.read() == NOERR) - TabLia.remove(); - - ok = FALSE; - TabLia.zero(); - TRectype newrec (TabLia.curr()); - TabLia.put ("CODTAB", _annop); - - if (TabLia.read() == NOERR) - { - ok = TRUE; - newrec = TabLia.curr(); - newrec.put("CODTAB", annoiva); - newrec.put("S7", _frequenza); - - TabLia.write(newrec); - } - if (!ok) - { - error_box("Non esiste il record relativo all'anno iva precedente sulla tabella liquidazione annuale iva"); - return FALSE; - } - - //viene aggiornato l'anno iva sui parametri ditta - TConfig conf(CONFIG_DITTA); - conf.set("AnLiIv", _annoiva); - - //sull'anagrafica ditte viene aggiornata la frequenza versamento - nditte.zero(); - nditte.put("CODDITTA", _ditta); - if (nditte.read() == NOERR) - { - nditte.put(NDT_FREQVIVA, _frequenza); - nditte.rewrite(); - } - - message_box("Apertura nuovo esercizio IVA completata"); - return TRUE; -} - -int cg4500 (int argc, char* argv[]) -{ - CG4500_application main_app; - main_app.run(argc, argv, ""); - return TRUE; -} - - - - - - - - - +// Apertura nuovo esercizio/nuovo esercizio IVA + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "cg4500a.h" +#include "cg4500b.h" + +bool mask_dataini (TMask_field&, KEY); +bool mask_newanno (TMask_field&, KEY); +bool mask_annoiva (TMask_field&, KEY); +bool mask_frequenza (TMask_field&, KEY); + +class CG4500_application : public TApplication +{ + friend bool mask_dataini (TMask_field&, KEY); + friend bool mask_newanno (TMask_field&, KEY); + friend bool mask_annoiva (TMask_field&, KEY); + friend bool mask_frequenza (TMask_field&); + + TTable* _esc, * _reg, * _lia, * _lbu; + TLocalisamfile* _nditte; + int _anno, _newanno, _annoiva; + TDate _dataini, _datafin, _datainp, _datafip; + TString _annop; + long _ditta; + char _frequenza; + +public: + virtual bool create(); + virtual bool destroy(); + virtual bool menu(MENU_TAG m); + + void create_files(); + void destroy_files(); + bool set(); + bool setta(); + bool apertura_es(); + bool apertura_iva(); + + CG4500_application() {} +}; + +TDate InizioEsercizio(int anno) +{ + TTable TabEs ("ESC"); + TString codtab; + TDate inizio_es; + + TabEs.zero(); + codtab.format ("%04d", anno); + TabEs.put ("CODTAB", codtab); + TabEs.read(); + if (TabEs.good()) + inizio_es= TabEs.get_date ("D0"); + + return inizio_es; +} + +TDate FineEsercizio(int anno) +{ + TTable TabEs ("ESC"); + TString codtab; + TDate fine_es; + + TabEs.zero(); + codtab.format ("%04d", anno); + TabEs.put ("CODTAB", codtab); + TabEs.read(); + if (TabEs.good()) + fine_es= TabEs.get_date ("D1"); + + return fine_es; +} + +bool mask_newanno (TMask_field& f, KEY k) +{ + TTable TabEs ("ESC"); + TString codtab; + + // if ( (k == K_TAB) && f.mask().is_running() ) + if ( (k == K_ENTER) && f.to_check(k) ) + { + int newanno = f.mask().get_int(F_NUOVOANNO); + int anno = f.mask().get_int(F_ANNO); + TabEs.zero(); + codtab.format ("%04d", newanno); + TabEs.put ("CODTAB", codtab); + TabEs.read(); + if ( TabEs.good() ) + { + f.warning_box ("L'anno inserito e' gia' presente nella tabella degli esercizi!"); + return FALSE; + } + + if (newanno != anno + 1) + { + f.warning_box ("L'anno del nuovo esercizio deve essere successivo all'anno esercizio precedente"); + return FALSE; + } + } + return TRUE; +} + +bool mask_annoiva (TMask_field& f, KEY k) +{ + if ( (k == K_ENTER) && f.to_check(k) ) + //if ( (k == K_TAB) && f.mask().is_running() ) + { + int annoiva = f.mask().get_int(F_ANNOIVA); + TConfig conf(CONFIG_DITTA); + int annoivap = atoi(conf.get("AnLiIv")); + if (annoiva != annoivap + 1) + { + f.warning_box("Il nuovo anno esercizio IVA deve essere successivo all'anno esercizio IVA precedente"); + return FALSE; + } + } + return TRUE; +} + +bool mask_dataini (TMask_field& f, KEY k) +{ + if ( (k == K_ENTER) && f.to_check(k) ) + { + TDate data(f.mask().get(F_DATAINI)); + TDate fine(f.mask().get(F_DATAFINC)); + /* + if ( data.year() != FineEsercizio(anno).year() + 1 ) + { + warning_box ("L'anno del nuovo esercizio deve essere successivo a quello della fine dell'esercizio precedente"); + return FALSE; + } + */ + if ( data <= fine ) + { + f.warning_box ("La data di inizio del nuovo esercizio deve essere superiore alla data di fine esercizio precedente"); + return FALSE; + } + } + return TRUE; +} + +void CG4500_application::create_files() +{ + _nditte = new TLocalisamfile(LF_NDITTE); + _esc = new TTable("ESC"); + _reg = new TTable("REG"); + _lia = new TTable("LIA"); + _lbu = new TTable("%LBU"); +} + +void CG4500_application::destroy_files() +{ + delete _nditte; + delete _esc; + delete _reg; + delete _lia; + delete _lbu; +} + +bool CG4500_application::create() +{ + TApplication::create(); + create_files(); + dispatch_e_menu (BAR_ITEM(1)); + + return TRUE; +} + +bool CG4500_application::destroy() +{ + destroy_files(); + + return TApplication::destroy(); +} + +bool CG4500_application::set() +{ + TTable TabEs ("ESC"); + TMask m ("cg4500a"); + + KEY tasto; + + /* + if (TabEs.last() == NOERR) + { + int anno = TabEs.get_int ("CODTAB"); + TDate inizio = TabEs.get_date("D0"); //data inizio es. in corso + TDate fine = TabEs.get_date("D1"); //data fine es. in corso + + m.show (F_ANNO); + m.show (F_DATAINIC); + m.show (F_DATAFINC); + + m.set(F_ANNO, (long) anno); + m.set(F_DATAINIC, inizio.string()); + m.set(F_DATAFINC, fine.string()); + } + else + { + m.hide(F_ANNO); + m.hide(F_DATAINIC); + m.hide(F_DATAFINC); + } + */ + + if (TabEs.last() != NOERR) + { + error_box("Non e' ancora stato aperto alcun esercizio!"); + return FALSE; + } + + int anno = TabEs.get_int ("CODTAB"); + TDate inizio = TabEs.get_date("D0"); //data inizio es. in corso + TDate fine = TabEs.get_date("D1"); //data fine es. in corso + + m.set(F_ANNO, anno); + m.set(F_DATAINIC, inizio.string()); + m.set(F_DATAFINC, fine.string()); + m.set(F_NUOVOANNO, anno+1); + + m.set_handler (F_NUOVOANNO, mask_newanno); + m.set_handler (F_DATAINI, mask_dataini); + + tasto = m.run(); + + if (tasto == K_ENTER) + { + _anno = m.get_int(F_ANNO); + _datainp = m.get(F_DATAINIC); + _datafip = m.get(F_DATAFINC); + _newanno = m.get_int(F_NUOVOANNO); //nuovo anno esercizio + _dataini = m.get(F_DATAINI); + _datafin = m.get(F_DATAFIN); + + return TRUE; + } + return FALSE; +} + +bool CG4500_application::setta() +{ + TTable TabLia ("LIA"); + TLocalisamfile nditte (LF_NDITTE); + TMask m ("cg4500b"); + KEY tasto; + + TConfig conf(CONFIG_DITTA); + _annop = conf.get("AnLiIv"); + int aivap = atoi(conf.get("AnLiIv")); + TString anno ( format("%04d", aivap+1) ); + + TabLia.zero(); + TabLia.put("CODTAB", anno); + if (TabLia.read() == NOERR) + m.set(F_FREQUENZA, TabLia.get("S7")); + else + { + TabLia.zero(); + TabLia.put("CODTAB", _annop); + if (TabLia.read() == NOERR) + m.set(F_FREQUENZA, TabLia.get("S7")); + else + { + nditte.zero(); + nditte.put("CODDITTA", MainApp()->get_firm()); + if (nditte.read() == NOERR) + m.set(F_FREQUENZA, nditte.get(NDT_FREQVIVA)); + } + } + + m.set(F_ANNOIVA, aivap+1); + + m.set_handler (F_ANNOIVA, mask_annoiva); + + tasto = m.run(); + + if (tasto == K_ENTER) + { + _ditta = m.get_long(F_CODDITTA); + _annoiva = m.get_int(F_ANNOIVA); + _frequenza = m.get(F_FREQUENZA)[0]; + + return TRUE; + } + return FALSE; +} + +bool CG4500_application::menu(MENU_TAG m) +{ + switch (m) + { + case BAR_ITEM(1): + apertura_es(); + break; + case BAR_ITEM(2): + apertura_iva(); + break; + } + //return TApplication::menu(m); + return TRUE; +} + +bool CG4500_application::apertura_es() +{ + TTable TabReg ("REG"); + TTable TabEs ("ESC"); + TString anno (4); + TString annonew(4); + TDate data; + bool ok = FALSE; + + if (!set()) + return FALSE; + + //viene aggiornata la tabella dei registri. Se esisteva gia' un record relativo al nuovo esercizio, viene cancellato. + //In ogni caso ne viene creato uno nuovo relativo al nuovo esercizio. + + TabReg.zero(); + annonew = format ("%04d", _newanno); + TabReg.put ("CODTAB", annonew); + + TRectype r (TabReg.curr()); + + TabReg.read(_isgteq); + + for (; !TabReg.eof(); TabReg.next()) + { + if (TabReg.curr() != r) break; + + int tiporeg = TabReg.get_int("I0"); + if (tiporeg == 5) + TabReg.remove(); + } + + TabReg.zero(); + TRectype nuovo (TabReg.curr()); + anno = format ("%04d", _anno); + TabReg.put ("CODTAB", anno); + + TRectype rec (TabReg.curr()); + + TabReg.read(_isgteq); + + for (; !TabReg.eof(); TabReg.next()) + { + if (TabReg.curr() != rec) break; + + int tiporeg = TabReg.get_int("I0"); + TString cod_reg = TabReg.get("CODTAB"); + cod_reg = cod_reg.mid(4,3); + if (tiporeg == 5) + { + ok = TRUE; + nuovo = TabReg.curr(); + TString16 cod; + cod << _newanno << cod_reg; + nuovo.put("CODTAB", cod); + nuovo.put("D2", data); + nuovo.put("D3", data); + nuovo.put("I6", 0L); + nuovo.put("R1", real(0.0)); + nuovo.put("R2", real(0.0)); + + TabReg.write(nuovo); + } + } + if (!ok) + { + error_box("Non esiste il registro libro giornale relativo all'es. precedente"); + return FALSE; + } + + //viene aggiornata la tabella degli esercizi + TabEs.zero(); + annonew = format ("%04d", _newanno); + TabEs.put ("CODTAB", annonew); + TabEs.put ("D0", _dataini); + TabEs.put ("D1", _datafin); + TabEs.write(); + + message_box("Apertura nuovo esercizio completata"); + return TRUE; +} + +bool CG4500_application::apertura_iva() +{ + TTable TabReg ("REG"); + TTable TabLia ("LIA"); + TTable TabLbu ("%LBU"); + TLocalisamfile nditte (LF_NDITTE); + TDate data; + TString annoiva (4); + bool ok = FALSE; + + if (!setta()) + return FALSE; + + //viene aggiornata la tabella del libro unico. Se esisteva gia' un record relativo al nuovo esercizio IVA, viene cancellato. + //In ogni caso ne viene creato uno nuovo relativo al nuovo esercizio. + + annoiva = format ("%04d", _annoiva); + + TabLbu.zero(); + TabLbu.put ("CODTAB", annoiva); + + TRectype r (TabLbu.curr()); + + TabLbu.read(_isgteq); + + for (; !TabLbu.eof(); TabLbu.next()) + { + if (TabLbu.curr() != r) break; + + TabLbu.remove(); + } + + TabLbu.zero(); + TRectype nrec (TabLbu.curr()); + TabLbu.put ("CODTAB", _annop); + + TRectype rec (TabLbu.curr()); + + TabLbu.read(_isgteq); + + for (; !TabLbu.eof(); TabLbu.next()) + { + if (TabLbu.curr() != rec) break; + + TString cod_lib = TabLbu.get("CODTAB"); + cod_lib = cod_lib.mid(4,3); + + ok = TRUE; + nrec = TabLbu.curr(); + TString16 cod; + cod << _annoiva << cod_lib; + nrec.put("CODTAB", cod); + nrec.put("I0", 0L); + + TabLbu.write(nrec); + } + if (!ok) + { + error_box("Non esistono i registri del libro unico relativi all'anno iva precedente"); + return FALSE; + } + + //viene aggiornata la tabella dei registri. Se esisteva gia' un record relativo al nuovo esercizio, viene cancellato. + //In ogni caso ne viene creato uno nuovo relativo al nuovo esercizio. + + TabReg.zero(); + TabReg.put ("CODTAB", annoiva); + + TRectype rr (TabReg.curr()); + + TabReg.read(_isgteq); + + for (; !TabReg.eof(); TabReg.next()) + { + if (TabReg.curr() != rr) break; + + int tiporeg = TabReg.get_int("I0"); + if ( (tiporeg == 1)||(tiporeg == 2)||(tiporeg == 3) ) + TabReg.remove(); + } + + ok = FALSE; + TabReg.zero(); + TRectype nuovo (TabReg.curr()); + TabReg.put ("CODTAB", _annop); + + TRectype recc (TabReg.curr()); + + TabReg.read(_isgteq); + + for (; !TabReg.eof(); TabReg.next()) + { + if (TabReg.curr() != recc) break; + + int tiporeg = TabReg.get_int("I0"); + TString cod_reg = TabReg.get("CODTAB"); + TDate data_vid = TabReg.get_date("D0"); + data_vid.addyear(); + cod_reg = cod_reg.mid(4,3); + if ( (tiporeg == 1)||(tiporeg == 2)||(tiporeg==3) ) + { + ok = TRUE; + nuovo = TabReg.curr(); + TString16 cod; + cod << _annoiva << cod_reg; + nuovo.put("CODTAB", cod); + nuovo.put("I1", 0L); + nuovo.put("I2", 0L); + nuovo.put("I4", 0L); + nuovo.put("I5", 0L); + nuovo.put("I6", 0L); + nuovo.put("S1", ""); + nuovo.put("D0", data_vid); + nuovo.put("D2", data); + nuovo.put("D3", data); + nuovo.put("R1", real(0.0)); + nuovo.put("R2", real(0.0)); + + TabReg.write(nuovo); + } + } + if (!ok) + { + error_box("Non esistono i registri iva relativi all'anno iva precedente"); + return FALSE; + } + + //viene aggiornata la tabella LIA (liquidazione iva annuale) + TabLia.zero(); + TabLia.put ("CODTAB", annoiva); + if (TabLia.read() == NOERR) + TabLia.remove(); + + ok = FALSE; + TabLia.zero(); + TRectype newrec (TabLia.curr()); + TabLia.put ("CODTAB", _annop); + + if (TabLia.read() == NOERR) + { + ok = TRUE; + newrec = TabLia.curr(); + newrec.put("CODTAB", annoiva); + newrec.put("S7", _frequenza); + + TabLia.write(newrec); + } + if (!ok) + { + error_box("Non esiste il record relativo all'anno iva precedente sulla tabella liquidazione annuale iva"); + return FALSE; + } + + //viene aggiornato l'anno iva sui parametri ditta + TConfig conf(CONFIG_DITTA); + conf.set("AnLiIv", _annoiva); + + //sull'anagrafica ditte viene aggiornata la frequenza versamento + nditte.zero(); + nditte.put("CODDITTA", _ditta); + if (nditte.read() == NOERR) + { + nditte.put(NDT_FREQVIVA, _frequenza); + nditte.rewrite(); + } + + message_box("Apertura nuovo esercizio IVA completata"); + return TRUE; +} + +int cg4500 (int argc, char* argv[]) +{ + CG4500_application main_app; + main_app.run(argc, argv, ""); + return TRUE; +} + + + + + + + + + diff --git a/cg/cglib02.cpp b/cg/cglib02.cpp index 7448e95c7..c96862e10 100755 --- a/cg/cglib02.cpp +++ b/cg/cglib02.cpp @@ -42,9 +42,9 @@ void TTab_conti::do_agg(TConto* tc, int anno_es, const real& importo, } -void TTab_conti::aggiorna_conto(const TConto& tcon, const int anno_es, const real& importo, char sezione, bool movap, bool provv, bool somma) +void TTab_conti::aggiorna_conto(const TConto& tcon, int anno_es, const real& importo, char sezione, bool movap, bool provv, bool somma) { - TString key; + TString80 key; key << format("%4d", anno_es); key << format("%3d", tcon.gruppo()); key << format("%3d", tcon.conto()); @@ -68,7 +68,7 @@ void TTab_conti::aggiorna_conto(int gruppo, int conto, long sottoconto, int anno_es, const real& importo, char sezione, bool movap, bool provv, bool somma) { - TString key; + TString80 key; key << format("%4d", anno_es); key << format("%3d", gruppo); key << format("%3d", conto); diff --git a/include/applicat.cpp b/include/applicat.cpp index 9b6632adc..28b6dba2f 100755 --- a/include/applicat.cpp +++ b/include/applicat.cpp @@ -1,532 +1,542 @@ -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -HIDDEN XVT_CONFIG cfg; -HIDDEN TApplication* application = NULL; -HIDDEN long savefirm = 0; - -TApplication* MainApp() -{ - CHECK(application, "NULL application!"); - return application; -} - -bool xvt_running() { return application != NULL; } - -HIDDEN long backdrop_eh( WINDOW win, EVENT* ep) -{ -#if XVTWS == WMWS - clear_window( win, COLOR_BLUE ); -#else - clear_window( win, COLOR_GRAY ); -/* - const RCT& rct = ep->v.update.rct; - bool even = FALSE; - for (int y = 0; y < rct.bottom; y += 96) - { - const int sx = even ? 96 : 0; - for (int x = sx; x < rct.right; x += 192) - if ( - (y+64) > rct.top && y < rct.bottom && - (x+64) > rct.left && x < rct.right - ) win_draw_icon(win, x, y, ICON_RSRC); - even = !even; - } -*/ -#endif - - return 0L; -} - -HIDDEN void create_backdrop( void ) -{ -#if XVTWS == WMWS - xvt_escape(XVT_ESC_CH_COLOR, XVT_CH_CLR_MENU, COLOR_BLACK, COLOR_WHITE); - xvt_escape(XVT_ESC_CH_COLOR, XVT_CH_CLR_DIALOG, COLOR_BLUE, COLOR_WHITE); - xvt_escape(XVT_ESC_CH_COLOR, XVT_CH_CLR_WINDOW, COLOR_RED, COLOR_WHITE); - xvt_escape(XVT_ESC_CH_COLOR, XVT_CH_CLR_CONTROL, COLOR_BLACK, COLOR_WHITE); - xvt_escape(XVT_ESC_CH_COLOR, XVT_CH_CLR_DISABLED, COLOR_GRAY, COLOR_WHITE); - xvt_escape(XVT_ESC_CH_COLOR, XVT_CH_CLR_MNEMONIC, COLOR_RED, COLOR_WHITE); - - RCT rct; - get_client_rect( SCREEN_WIN, &rct ); - create_window(W_PLAIN, &rct, (char*) "BACKDROP", 0, TASK_WIN, - WSF_NO_MENUBAR | WSF_CH_BACKDROP , EM_UPDATE, - backdrop_eh, 0L ); -#else - xvt_create_statbar(); - xvt_statbar_set(""); -#endif -} - -#if XVT_OS == XVT_OS_WIN - -#include - -const word WM_WAKEUP = RegisterWindowMessage("WAKEUP"); -DWORD waiting_for = 0; - -BOOLEAN event_hook(HWND, WORD msg, WORD, - DWORD lparam, long far* ret) -{ - if (msg == WM_WAKEUP) - { - if( lparam == waiting_for || lparam == 0) - { - waiting_for = 0L; - TTemp_window tw(TASK_WIN); - tw.maximize(); - } - *ret = 0; - return TRUE; - } - - return FALSE; -} - - -HIDDEN DWORD name2id(const char* name) -{ - waiting_for = 0L; - for (int i = 0; i < 5 && name[i] > ' '; i++) - { - waiting_for <<= 6; - waiting_for |= toupper(name[i]) - '0'; - } - return waiting_for; -} - - -void TApplication::wait_for(const char* command) -{ - TTemp_window tw(TASK_WIN); - tw.iconize(); - name2id(cmd2name(command)); - set_value(TASK_WIN, ATTR_EVENT_HOOK, (long)event_hook); - while (waiting_for) do_events(); - -/////////////////////////////////////////////////////////// -// It seems necessary to restore these things -/////////////////////////////////////////////////////////// - customize_controls(TRUE); - xvt_statbar_refresh(); -} - -void TApplication::wake_up_caller() const -{ - name2id(name()); - SendMessage(-1, WM_WAKEUP, 0, waiting_for); -} - -#endif - - -void TApplication::print() -{ -#ifdef DBG - error_box("Non saprei bene cosa stampare!"); -#endif -} - - -long TApplication::task_eh(WINDOW win, EVENT *ep) -{ - switch (ep->type) - { - case E_CREATE: - create_backdrop(); -#if defined(DBG) && XVT_OS == XVT_OS_SCOUNIX - message_box("attach to process %d ...", getpid()); -#endif - do_events(); - break; -#if XVT_OS == XVT_OS_WIN - case E_UPDATE: - backdrop_eh(win, ep); - break; -#endif - default: - break; - } - - return application->handler(win, ep); -} - -void TApplication::about() const -{ - #include - message_box("PRASSI Version %g\nLibreria del %s", VERSION, __DATE__); -} - - -long TApplication::handler(WINDOW, EVENT* ep) -{ - switch (ep->type) - { - case E_CREATE: - if (create() == FALSE) - stop_run(); - break; - case E_COMMAND: - { - MENU_TAG mt = ep->v.cmd.tag; - switch(mt) - { - case M_FILE_QUIT: - stop_run(); - break; - case M_FILE_PG_SETUP: - printer().set(); - break; - case M_FILE_PRINT: - print(); - break; - case M_FILE_NEW: - set_firm(); - break; - case M_FILE_REVERT: - config(); - break; - case (M_FILE+11) : - about(); - break; - default: - if (!menu(mt)) - stop_run(); - break; - } - } - break; - case E_CLOSE: - if (can_close()) - stop_run(); - break; - case E_QUIT: - if (ep->v.query) - { - if (can_close()) - quit_OK(); - else - error_box("Chiudere la finestra attiva prima di chiudere il programma"); - } - else stop_run(); - break; - default: - break; - } - return 0L; -} - - -void TApplication::stop_run() -{ - if (savefirm) prefhndl->set_codditta(savefirm); - terminate(); -//#if XVT_OS == XVT_OS_WIN -// xvt_escape(XVT_ESC_WIN_TERMINATE); -//#else - xvt_terminate(); -//#endif -} - - -TApplication::TApplication() : _printer(NULL) -{ - init_global_vars(); - _bar = TASK_MENUBAR; -} - - -TApplication::~TApplication() -{} - - -TPrinter* TApplication::set_printer(TPrinter* p) -{ - TPrinter* printer = _printer; - _printer = p; - return printer; -} - - -TPrinter& TApplication::printer() -{ - if (_printer == NULL) _printer = new TPrinter; - return *_printer; -} - - -bool TApplication::create() -{ -// include_progind(); // TBC da eliminare quando il linker diventa furbo - return TRUE; -} - - -bool TApplication::destroy() -{ - return TRUE; -} - - -void TApplication::terminate() -{ -#if XVT_OS == XVT_OS_WIN - wake_up_caller(); // Manda il segnale di risveglio al chiamante -#endif - - close_all_dialogs(); - application->destroy(); // Distruzione files e maschere - do_events(); - - if (_printer) // Distruzione dell'eventuale stampante - { - if (printer().isopen()) - printer().close(); - delete _printer; - _printer = NULL; - } - - free_global_vars(); // Distruzione variabili globali - - customize_controls(FALSE); // Rilascio eventuali DLL -} - - -const char* TApplication::get_module_name() const -{ - TScanner scanner("prassi.aut"); - - bool ok = FALSE; - for (int aut = 0; scanner.line() != ""; aut++) - if (strncmp(scanner.token(), _name, 2) == 0) { ok = TRUE; break; } - - const char* module = scanner.token().mid(3); - if (ok) ok = has_module(aut); - - if (!ok) - fatal_box("Il modulo '%s' non e' autorizzato", module); - - return module; -} - -void TApplication::set_title(const char* t) -{ cfg.appl_name = (char*)t; } - -const char* TApplication::title() const -{ return cfg.appl_name; } - -void TApplication::run(int argc, char* argv[], const char* title) -{ - TFilename base(argv[0]); - base.ext(""); base.lower(); - - __argc = argc; - __argv = (const char**)argv; - - int addbar; - if (argc > 1) - { - addbar = atoi(argv[1]+1); - _name = cmd2name(argv[0], argv[1]); - } - else - { - addbar = 0; - _name = cmd2name(argv[0]); - } - - TString80 caption; - caption << "PRASSI S.P.A. - " << get_module_name(); - - cfg.base_appl_name = (char*) base.name(); - cfg.appl_name = (char*) title; - cfg.taskwin_title = (char*)(const char*)caption; - cfg.menu_bar_ID = TASK_MENUBAR+addbar; - cfg.about_box_ID = 0; - - customize_controls(TRUE); - - application = this; - xvt_system(argc, argv, 0L, task_eh, &cfg); -} - -void TApplication::check_menu_item(MENU_TAG item) -{ - win_menu_check(TASK_WIN, item, TRUE); - win_update_menu_bar(TASK_WIN); -} - - -void TApplication::uncheck_menu_item(MENU_TAG item) -{ - win_menu_check(TASK_WIN, item, FALSE); - win_update_menu_bar(TASK_WIN); -} - - -void TApplication::enable_menu_item(MENU_TAG item, bool on) -{ - win_menu_enable(TASK_WIN, item, on); - win_update_menu_bar(TASK_WIN); -} - - -void TApplication::dispatch_e_menu(MENU_TAG item) - -{ -#if XVT_OS == XVT_OS_WIN - HWND w = (HWND)get_value(TASK_WIN, ATTR_NATIVE_WINDOW); - PostMessage(w, WM_COMMAND, item, 0L); -#else - EVENT e; - e.type = E_COMMAND; - e.v.cmd.tag = item; - e.v.cmd.shift = e.v.cmd.control = 0; - dispatch_event(TASK_WIN, &e); -#endif -} - - -bool TApplication::has_module(int module) const -{ - return (bool)CGetAut(module); -} - - -long TApplication::get_firm() const -{ - return prefhndl->get_codditta(); -} - -const char* TApplication::get_firm_dir() const -{ -// return prefhndl->name(); - return format("%s%s", __ptprf, prefhndl->name()); -} - - -bool TApplication::set_firm(long newfirm) -{ - disable_menu_item(M_FILE_NEW); - const long oldfirm = get_firm(); - - if (newfirm < 1) - { - TMask mask("bagn002"); - - mask.send_key(K_CTRL+K_SHIFT+(extended_firm() ? 's' : 'h'), -2); - const KEY k = mask.run(); - - enable_menu_item(M_FILE_NEW); - if (k == K_ENTER) - { - newfirm = atol(mask.get(F_CODDITTA)); - const int tipodir = atoi(mask.get(F_TIPO)); - - if (tipodir > 0) - { - if (savefirm == 0) savefirm = oldfirm; - prefhndl->set(tipodir == 1 ? "com" : ""); - return TRUE; - } - } - } - - if (newfirm == oldfirm || newfirm < 1) - return FALSE; - - if (prefhndl->test(newfirm)) - { - prefhndl->set_codditta(newfirm); - savefirm = 0; - } - - return TRUE; -} - -bool TApplication::config() - // gestisce le voci di configurazione - // le si passa il file in cui cercare il proprio - // paragrafo (comunque relativo alla ditta) - // se non c'e', viene creato copiando il default - // la variabile EdMask di quel paragrafo specifica - // la maschera da usare -{ - TConfig cnf(CONFIG_DITTA); - bool ok = FALSE; - - TString80 maskname(cnf.get("EdMask")); - if (!maskname.empty()) - { - TMask m(maskname); - - // carica campi - for (int i = 0; i < m.fields(); i++) - { - TMask_field& f = m.fld(i); - const TFieldref* fref = f.field(); - if (fref != NULL) - { - const char* fname = fref->name(); - if (fname != NULL) - { - TString& oldvl = cnf.get(fname); - if (!oldvl.empty()) - f.set(oldvl); - } - } - } - - - // run mask - disable_menu_item(M_FILE_NEW); - disable_menu_item(M_FILE_REVERT); - - if (m.run() == K_ENTER) - { - // aggiusta campi - for (i = 0; i < m.fields(); i++) - { - TMask_field& f = m.fld(i); - if (f.dirty()) - { - const TFieldref* fref = f.field(); - if (fref != NULL) - { - const char* fname = fref->name(); - const char* value = f.get(); - const char* oldvl = cnf.get(fname); - if (change_config(fname,oldvl,value)) - cnf.set(fname, value, NULL, TRUE); - } - } - } - ok = TRUE; - } - else ok = FALSE; - enable_menu_item(M_FILE_NEW); - enable_menu_item(M_FILE_REVERT); - return ok; - } - return warning_box("Nessun parametro da configurare"); -} - -bool TApplication::change_config(const char* var, const char* oldv, - const char* newv) - -{ return TRUE; } +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +HIDDEN XVT_CONFIG cfg; +HIDDEN TApplication* application = NULL; +HIDDEN long savefirm = 0; + +TApplication* MainApp() +{ + CHECK(application, "NULL application!"); + return application; +} + +bool xvt_running() { return application != NULL; } + +HIDDEN long backdrop_eh( WINDOW win, EVENT* ep) +{ +#if XVTWS == WMWS + clear_window( win, COLOR_BLUE ); +#else + clear_window( win, COLOR_GRAY ); + /* + const RCT& rct = ep->v.update.rct; + bool even = FALSE; + for (int y = 0; y < rct.bottom; y += 96) + { + const int sx = even ? 96 : 0; + for (int x = sx; x < rct.right; x += 192) + if ( + (y+64) > rct.top && y < rct.bottom && + (x+64) > rct.left && x < rct.right + ) win_draw_icon(win, x, y, ICON_RSRC); + even = !even; + } + */ +#endif + + return 0L; +} + +HIDDEN void create_backdrop( void ) +{ +#if XVTWS == WMWS + xvt_escape(XVT_ESC_CH_COLOR, XVT_CH_CLR_MENU, COLOR_BLACK, COLOR_WHITE); + xvt_escape(XVT_ESC_CH_COLOR, XVT_CH_CLR_DIALOG, COLOR_BLUE, COLOR_WHITE); + xvt_escape(XVT_ESC_CH_COLOR, XVT_CH_CLR_WINDOW, COLOR_RED, COLOR_WHITE); + xvt_escape(XVT_ESC_CH_COLOR, XVT_CH_CLR_CONTROL, COLOR_BLACK, COLOR_WHITE); + xvt_escape(XVT_ESC_CH_COLOR, XVT_CH_CLR_DISABLED, COLOR_GRAY, COLOR_WHITE); + xvt_escape(XVT_ESC_CH_COLOR, XVT_CH_CLR_MNEMONIC, COLOR_RED, COLOR_WHITE); + + RCT rct; + get_client_rect( SCREEN_WIN, &rct ); + create_window(W_PLAIN, &rct, (char*) "BACKDROP", 0, TASK_WIN, + WSF_NO_MENUBAR | WSF_CH_BACKDROP , EM_UPDATE, + backdrop_eh, 0L ); +#else + xvt_create_statbar(); + xvt_statbar_set(""); +#endif +} + +#if XVT_OS == XVT_OS_WIN + +#include + +const word WM_WAKEUP = RegisterWindowMessage("WAKEUP"); +DWORD waiting_for = 0; + +BOOLEAN waiting_event_hook(HWND, WORD msg, WORD, + DWORD lparam, long far* ret) +{ + if (msg == WM_WAKEUP) + { + if( lparam == waiting_for || lparam == 0) + { + waiting_for = 0L; + TTemp_window tw(TASK_WIN); + tw.maximize(); + } + *ret = 0; + return TRUE; + } + + return FALSE; +} + + +HIDDEN DWORD name2id(const char* name) +{ + waiting_for = 0L; + for (int i = 0; i < 5 && name[i] > ' '; i++) + { + waiting_for <<= 6; + waiting_for |= toupper(name[i]) - '0'; + } + return waiting_for; +} + + +void TApplication::wait_for(const char* command) +{ + TTemp_window tw(TASK_WIN); + tw.iconize(); + name2id(cmd2name(command)); + set_value(TASK_WIN, ATTR_EVENT_HOOK, (long)waiting_event_hook); + while (waiting_for) do_events(); + + /////////////////////////////////////////////////////////// + // It seems necessary to restore these things + /////////////////////////////////////////////////////////// + customize_controls(TRUE); + xvt_statbar_refresh(); +} + +void TApplication::wake_up_caller() const +{ + name2id(name()); + SendMessage(-1, WM_WAKEUP, 0, waiting_for); +} + +#endif + + +void TApplication::print() +{ +#ifdef DBG + error_box("Non saprei bene cosa stampare!"); +#endif +} + + +long TApplication::task_eh(WINDOW win, EVENT *ep) +{ + switch (ep->type) + { + case E_CREATE: + create_backdrop(); +#if defined(DBG) && XVT_OS == XVT_OS_SCOUNIX + message_box("Attach to process %d ...", getpid()); +#endif + do_events(); + break; +#if XVT_OS == XVT_OS_WIN + case E_UPDATE: + backdrop_eh(win, ep); + break; +#endif + default: + break; + } + + return application->handler(win, ep); +} + +void TApplication::about() const +{ +#include + message_box("PRASSI Versione %g\nProgramma %s\nLibreria del %s", + VERSION, (const char*)name(), __DATE__); +} + + +long TApplication::handler(WINDOW, EVENT* ep) +{ + switch (ep->type) + { + case E_CREATE: + if (create() == FALSE) + stop_run(); + break; + case E_CHAR: + { +#ifdef DBG + KEY k = e_char_to_key(ep); +#endif + } + break; + case E_COMMAND: + { + MENU_TAG mt = ep->v.cmd.tag; + switch(mt) + { + case M_FILE_QUIT: + stop_run(); + break; + case M_FILE_PG_SETUP: + printer().set(); + break; + case M_FILE_PRINT: + print(); + break; + case M_FILE_NEW: + set_firm(); + break; + case M_FILE_REVERT: + config(); + break; + case (M_FILE+11) : + about(); + break; + default: + if (mt >= BAR_ITEM(1)) + { + if(!menu(mt)) + stop_run(); + } + break; + } + } + break; + case E_CLOSE: + if (can_close()) + stop_run(); + break; + case E_QUIT: + if (ep->v.query) + { + if (can_close()) + quit_OK(); + else + error_box("Chiudere la finestra attiva prima di chiudere il programma"); + } + else stop_run(); + break; + default: + break; + } + return 0L; +} + + +void TApplication::stop_run() +{ + if (savefirm) prefhndl->set_codditta(savefirm); + terminate(); + //#if XVT_OS == XVT_OS_WIN + // xvt_escape(XVT_ESC_WIN_TERMINATE); + //#else + xvt_terminate(); + //#endif +} + + +TApplication::TApplication() : _printer(NULL) +{ + init_global_vars(); + _bar = TASK_MENUBAR; +} + + +TApplication::~TApplication() +{} + + +TPrinter* TApplication::set_printer(TPrinter* p) +{ + TPrinter* printer = _printer; + _printer = p; + return printer; +} + + +TPrinter& TApplication::printer() +{ + if (_printer == NULL) _printer = new TPrinter; + return *_printer; +} + + +bool TApplication::create() +{ + // include_progind(); // TBC da eliminare quando il linker diventa furbo + return TRUE; +} + + +bool TApplication::destroy() +{ + return TRUE; +} + + +void TApplication::terminate() +{ +#if XVT_OS == XVT_OS_WIN + wake_up_caller(); // Manda il segnale di risveglio al chiamante +#endif + + close_all_dialogs(); + application->destroy(); // Distruzione files e maschere + do_events(); + + if (_printer) // Distruzione dell'eventuale stampante + { + if (printer().isopen()) + printer().close(); + delete _printer; + _printer = NULL; + } + + free_global_vars(); // Distruzione variabili globali + + customize_controls(FALSE); // Rilascio eventuali DLL +} + + +const char* TApplication::get_module_name() const +{ + TScanner scanner("prassi.aut"); + + bool ok = FALSE; + for (int aut = 0; scanner.line() != ""; aut++) + if (strncmp(scanner.token(), _name, 2) == 0) { ok = TRUE; break; } + + const char* module = scanner.token().mid(3); + if (ok) ok = has_module(aut); + + if (!ok) + fatal_box("Il modulo '%s' non e' autorizzato", module); + + return module; +} + +void TApplication::set_title(const char* t) +{ cfg.appl_name = (char*)t; } + +const char* TApplication::title() const +{ return cfg.appl_name; } + +void TApplication::run(int argc, char* argv[], const char* title) +{ + TFilename base(argv[0]); + base.ext(""); base.lower(); + + __argc = argc; + __argv = (const char**)argv; + + int addbar; + if (argc > 1) + { + addbar = atoi(argv[1]+1); + _name = cmd2name(argv[0], argv[1]); + } + else + { + addbar = 0; + _name = cmd2name(argv[0]); + } + + TString80 caption; + caption << "PRASSI S.P.A. - " << get_module_name(); + + cfg.base_appl_name = (char*) base.name(); + cfg.appl_name = (char*) title; + cfg.taskwin_title = (char*)(const char*)caption; + cfg.menu_bar_ID = TASK_MENUBAR+addbar; + cfg.about_box_ID = 0; + + customize_controls(TRUE); + + application = this; + xvt_system(argc, argv, 0L, task_eh, &cfg); +} + +void TApplication::check_menu_item(MENU_TAG item) +{ + win_menu_check(TASK_WIN, item, TRUE); + win_update_menu_bar(TASK_WIN); +} + + +void TApplication::uncheck_menu_item(MENU_TAG item) +{ + win_menu_check(TASK_WIN, item, FALSE); + win_update_menu_bar(TASK_WIN); +} + + +void TApplication::enable_menu_item(MENU_TAG item, bool on) +{ + win_menu_enable(TASK_WIN, item, on); + win_update_menu_bar(TASK_WIN); +} + + +void TApplication::dispatch_e_menu(MENU_TAG item) + +{ +#if XVT_OS == XVT_OS_WIN + HWND w = (HWND)get_value(TASK_WIN, ATTR_NATIVE_WINDOW); + PostMessage(w, WM_COMMAND, item, 0L); +#else + EVENT e; + e.type = E_COMMAND; + e.v.cmd.tag = item; + e.v.cmd.shift = e.v.cmd.control = 0; + dispatch_event(TASK_WIN, &e); +#endif +} + + +bool TApplication::has_module(int module) const +{ + return (bool)CGetAut(module); +} + + +long TApplication::get_firm() const +{ + return prefhndl->get_codditta(); +} + +const char* TApplication::get_firm_dir() const +{ + return format("%s%s", __ptprf, prefhndl->name()); +} + + +bool TApplication::set_firm(long newfirm) +{ + disable_menu_item(M_FILE_NEW); + const long oldfirm = get_firm(); + + if (newfirm < 1) + { + TMask mask("bagn002"); + + mask.send_key(K_CTRL+K_SHIFT+(extended_firm() ? 's' : 'h'), -2); + const KEY k = mask.run(); + + enable_menu_item(M_FILE_NEW); + if (k == K_ENTER) + { + newfirm = atol(mask.get(F_CODDITTA)); + const int tipodir = atoi(mask.get(F_TIPO)); + + if (tipodir > 0) + { + if (savefirm == 0) savefirm = oldfirm; + prefhndl->set(tipodir == 1 ? "com" : ""); + return TRUE; + } + } + } + + if (newfirm == oldfirm || newfirm < 1) + return FALSE; + + if (prefhndl->test(newfirm)) + { + prefhndl->set_codditta(newfirm); + savefirm = 0; + } + + return TRUE; +} + +bool TApplication::config() + // gestisce le voci di configurazione + // le si passa il file in cui cercare il proprio + // paragrafo (comunque relativo alla ditta) + // se non c'e', viene creato copiando il default + // la variabile EdMask di quel paragrafo specifica + // la maschera da usare +{ + TConfig cnf(CONFIG_DITTA); + bool ok = FALSE; + + TString80 maskname(cnf.get("EdMask")); + if (!maskname.empty()) + { + TMask m(maskname); + + // carica campi + for (int i = 0; i < m.fields(); i++) + { + TMask_field& f = m.fld(i); + const TFieldref* fref = f.field(); + if (fref != NULL) + { + const char* fname = fref->name(); + if (fname != NULL) + { + TString& oldvl = cnf.get(fname); + if (!oldvl.empty()) + f.set(oldvl); + } + } + } + + + // run mask + disable_menu_item(M_FILE_NEW); + disable_menu_item(M_FILE_REVERT); + + if (m.run() == K_ENTER) + { + // aggiusta campi + for (i = 0; i < m.fields(); i++) + { + TMask_field& f = m.fld(i); + if (f.dirty()) + { + const TFieldref* fref = f.field(); + if (fref != NULL) + { + const char* fname = fref->name(); + const char* value = f.get(); + const char* oldvl = cnf.get(fname); + if (change_config(fname,oldvl,value)) + cnf.set(fname, value, NULL, TRUE); + } + } + } + ok = TRUE; + } + else ok = FALSE; + enable_menu_item(M_FILE_NEW); + enable_menu_item(M_FILE_REVERT); + return ok; + } + return warning_box("Nessun parametro da configurare"); +} + +bool TApplication::change_config(const char* var, const char* oldv, + const char* newv) + +{ return TRUE; } diff --git a/include/controls.cpp b/include/controls.cpp index 09d197a13..85ad85859 100755 --- a/include/controls.cpp +++ b/include/controls.cpp @@ -1,1025 +1,1024 @@ -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]; - HBITMAP _graybmp; - HBRUSH _graybrush; - -public: - PICTURE getbmp(short id); - PICTURE operator[](short id) { return _picture[id-BMP_OK]; } - HBRUSH graybrush() const { return _graybrush; } - - void reset(); - - TPicture_array(); - ~TPicture_array() { reset(); } // Shouldn't do anything -}; - - -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)); - - const byte even = 1+4+16+64; - const byte odd = 2+8+32+128; - const byte grid[8] = { odd, even, odd, even, odd, even, odd, even }; - _graybmp = CreateBitmap(8, 8, 1, 1, grid); - _graybrush = CreatePatternBrush(_graybmp); -} - -void TPicture_array::reset() -{ - for (int i = 0; i < MAXPIC; i++) - if (_picture[i] != NULL) - { - picture_free(_picture[i]); - _picture[i] = NULL; - } - - if (_graybrush) - { - DeleteObject(_graybrush); - DeleteObject(_graybmp); - _graybrush = _graybmp = 0; - } -} - - -/////////////////////////////////////////////////////////// -// 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; - _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); - CHECKS(_win, "Can't create control ", title); - - 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 active! -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: - { - KEY key = e_char_to_key(ep); - switch(key) - { - case K_SPACE: - cc->mouse_up(); - break; - default: - { - WINDOW parent = get_parent(win); - dispatch_event(parent, ep); - } - 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, right, bottom, caption, parent, flags, app_data, id); -} - -void TText::update() const -{ - TControl::update(); - win_draw_text(_hdc, _client.left, _client.top+CHARY-3, (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, 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; - -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* caption, WINDOW parent, - long flags, long app_data, short id) - : TButton(left-(id == DLG_F9), top, right, bottom, - caption, parent, flags, app_data, id), - _picup(0L), _picdn(0L) -{ - const int height = bottom-top; - - switch(id) - { - case DLG_OK: - if (height > ROWY && strcmp("Conferma", caption) == 0) - caption = format("#%d", BMP_OK); - break; - case DLG_CANCEL: - if (height > ROWY && strcmp("Annulla", caption) == 0) - caption = format("#%d", BMP_CANCEL); - break; - case DLG_QUIT: - caption = format("#%d#%d", BMP_QUIT, BMP_QUITDN); - break; - case DLG_SELECT: - caption = format("#%d", BMP_SELECT); - break; - case DLG_DELREC: - caption = format("#%d#%d", BMP_DELREC, BMP_DELRECDN); - break; - case DLG_NEWREC: - if (strcmp("Nuovo", caption) == 0) - caption = format("#%d#%d", BMP_NEWREC, BMP_NEWRECDN); - break; - case DLG_FIRSTREC: - caption = format("#%d", BMP_FIRSTREC); - break; - case DLG_PREVREC: - caption = format("#%d", BMP_PREVREC); - break; - case DLG_STOPREC: - caption = format("#%d", BMP_STOPREC); - break; - case DLG_NEXTREC: - caption = format("#%d", BMP_NEXTREC); - break; - case DLG_LASTREC: - caption = format("#%d", BMP_LASTREC); - break; - case DLG_SAVEREC: - caption = format("#%d#%d", BMP_SAVEREC, BMP_SAVERECDN); - break; - case DLG_FINDREC: - caption = format("#%d", BMP_FINDREC); - break; - case DLG_F9: - caption = format("#%d", BMP_SEARCH); - break; - case DLG_LINK: - caption = format("#%d", BMP_LINK); - break; - case DLG_EDIT: - caption = format("#%d", BMP_EDIT); - break; - case DLG_PRINT: - caption = format("#%d", BMP_PRINT); - break; - default: - break; - } - - if (*caption == '#') - { - int pid = atoi(caption+1); - _picup = cpb.getbmp(pid); - const char* d = strrchr(caption, '#'); - if (d > caption) - { - pid = atoi(d+1); - _picdn = cpb.getbmp(pid); - } - - RCT r; - cpb_get_picture_size(_picup, &r); - _dx = byte((right-left-r.right+1) >> 1); - _dy = byte((height-r.bottom) >> 1); - } - else - { - _dx = (right-left-strlen(caption)*CHARX) >> 1; - _dy = ((height-CHARY) >> 1) + CHARY-3; - } -} - -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); - - 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); - } -} - -void TPush_button::update() const -{ - draw_pressed(FALSE); - if (focused() && id() != DLG_F9) - { - HWND hwnd = (HWND)get_value(_hdc, ATTR_NATIVE_WINDOW); - HDC hdc = GetDC(hwnd); - RECT r; - r.left = _client.left+DEPTH+1; - r.top = _client.top+DEPTH; - r.right = _client.right-DEPTH-1; - r.bottom = _client.bottom-DEPTH; - DrawFocusRect(hdc, &r); - ReleaseDC(hwnd, hdc); - } 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); - } -/* - HWND hwnd = (HWND)get_value(_hdc, ATTR_NATIVE_WINDOW); - HDC hdc = GetDC(hwnd); - RECT r; - r.left = _client.left+DEPTH+1; - r.top = _client.top+DEPTH+1; - r.right = _client.right-DEPTH-1; - r.bottom = _client.bottom-DEPTH-1; - HBRUSH oldBrush = SelectObject(hdc, cpb.graybrush()); - PatBlt(hdc, r.left, r.top, r.right-r.left, r.bottom-r.top, 0xFA0089); // Real magic number - SelectObject(hdc, oldBrush); - ReleaseDC(hwnd, hdc); -*/ - } -} - -/////////////////////////////////////////////////////////// -// 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); -}; - -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(); - cpb_win_picture_draw_at(_hdc, cpb[BMP_BOOK1 + _flag -1], 0, 0); -} - -/////////////////////////////////////////////////////////// -// 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); -}; - -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, COLOR_CYAN, COLOR_GRAY); - - char n[4]; sprintf(n, "%d", i+1); - win_draw_text(_hdc, (width-CHARX)/2 + i*width, CHARY-3, n, -1); - } - - CPEN pen; - pen.width = 1; - pen.pat = PAT_SOLID; - pen.style = P_SOLID; - pen.color = COLOR_CYAN; - 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; -} - -void TTag_button::mouse_up() -{ - if (_curr != _page) - dispatch_e_char(_parent, K_CTRL + K_F1 + _curr); -} - -/////////////////////////////////////////////////////////// -// Checkbox -/////////////////////////////////////////////////////////// - -class TCheckbox : public TButton -{ - static bool _bmploaded; - -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(); -}; - -bool TCheckbox::_bmploaded = FALSE; - -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 (!_bmploaded) - { - cpb.getbmp(BMP_CHECK_ON); - cpb.getbmp(BMP_CHECK_OFF); - cpb.getbmp(BMP_RADIO_ON); - cpb.getbmp(BMP_RADIO_OFF); - _bmploaded = TRUE; - } -} - - -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); -} - - -void TCheckbox::update() const -{ - TButton::update(); - - const int x = _client.left+20; - const int y = _client.top + CHARY-1; - - if (focused()) - { -#if XVT_OS == XVT_OS_WIN - RECT r; - r.left = x-2; r.top = _client.top; - r.right = _client.right; r.bottom = _client.bottom; - - 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 > ROWY) - { - top += 6; - bottom -= ROWY/2 -4; - } - 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; -} +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]; + HBITMAP _graybmp; + HBRUSH _graybrush; + +public: + PICTURE getbmp(short id); + PICTURE operator[](short id) { return _picture[id-BMP_OK]; } + HBRUSH graybrush() const { return _graybrush; } + + void reset(); + + TPicture_array(); + ~TPicture_array() { reset(); } // Shouldn't do anything +}; + + +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)); + + const byte even = 1+4+16+64; + const byte odd = 2+8+32+128; + const byte grid[8] = { odd, even, odd, even, odd, even, odd, even }; + _graybmp = CreateBitmap(8, 8, 1, 1, grid); + _graybrush = CreatePatternBrush(_graybmp); +} + +void TPicture_array::reset() +{ + for (int i = 0; i < MAXPIC; i++) + if (_picture[i] != NULL) + { + picture_free(_picture[i]); + _picture[i] = NULL; + } + + if (_graybrush) + { + DeleteObject(_graybrush); + DeleteObject(_graybmp); + _graybrush = _graybmp = 0; + } +} + + +/////////////////////////////////////////////////////////// +// 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; + _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); + CHECKS(_win, "Can't create control ", title); + + 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 active! +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: + { + KEY key = e_char_to_key(ep); + switch(key) + { + case K_SPACE: + cc->mouse_up(); + break; + default: + { + WINDOW parent = get_parent(win); + dispatch_event(parent, ep); + } + 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, right, bottom, caption, parent, flags, app_data, id); +} + +void TText::update() const +{ + TControl::update(); + win_draw_text(_hdc, _client.left, _client.top+CHARY-3, (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, 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; + +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* caption, WINDOW parent, + long flags, long app_data, short id) +: TButton(left-(id == DLG_F9), top, right, bottom, + caption, parent, flags, app_data, id), + _picup(0L), _picdn(0L) +{ + const int height = bottom-top; + + switch(id) + { + case DLG_OK: + if (height > ROWY && strcmp("Conferma", caption) == 0) + caption = format("#%d", BMP_OK); + break; + case DLG_CANCEL: + if (height > ROWY && strcmp("Annulla", caption) == 0) + caption = format("#%d", BMP_CANCEL); + break; + case DLG_QUIT: + caption = format("#%d#%d", BMP_QUIT, BMP_QUITDN); + break; + case DLG_SELECT: + caption = format("#%d", BMP_SELECT); + break; + case DLG_DELREC: + caption = format("#%d#%d", BMP_DELREC, BMP_DELRECDN); + break; + case DLG_NEWREC: + caption = format("#%d#%d", BMP_NEWREC, BMP_NEWRECDN); + break; + case DLG_FIRSTREC: + caption = format("#%d", BMP_FIRSTREC); + break; + case DLG_PREVREC: + caption = format("#%d", BMP_PREVREC); + break; + case DLG_STOPREC: + caption = format("#%d", BMP_STOPREC); + break; + case DLG_NEXTREC: + caption = format("#%d", BMP_NEXTREC); + break; + case DLG_LASTREC: + caption = format("#%d", BMP_LASTREC); + break; + case DLG_SAVEREC: + caption = format("#%d#%d", BMP_SAVEREC, BMP_SAVERECDN); + break; + case DLG_FINDREC: + caption = format("#%d", BMP_FINDREC); + break; + case DLG_F9: + caption = format("#%d", BMP_SEARCH); + break; + case DLG_LINK: + caption = format("#%d", BMP_LINK); + break; + case DLG_EDIT: + caption = format("#%d", BMP_EDIT); + break; + case DLG_PRINT: + caption = format("#%d", BMP_PRINT); + break; + default: + break; + } + + if (*caption == '#') + { + int pid = atoi(caption+1); + _picup = cpb.getbmp(pid); + const char* d = strrchr(caption, '#'); + if (d > caption) + { + pid = atoi(d+1); + _picdn = cpb.getbmp(pid); + } + + RCT r; + cpb_get_picture_size(_picup, &r); + _dx = byte((right-left-r.right+1) >> 1); + _dy = byte((height-r.bottom) >> 1); + } + else + { + _dx = (right-left-strlen(caption)*CHARX) >> 1; + _dy = ((height-CHARY) >> 1) + CHARY-3; + } +} + +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); + + 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); + } +} + +void TPush_button::update() const +{ + draw_pressed(FALSE); + if (focused() && id() != DLG_F9) + { + HWND hwnd = (HWND)get_value(_hdc, ATTR_NATIVE_WINDOW); + HDC hdc = GetDC(hwnd); + RECT r; + r.left = _client.left+DEPTH+1; + r.top = _client.top+DEPTH; + r.right = _client.right-DEPTH-1; + r.bottom = _client.bottom-DEPTH; + DrawFocusRect(hdc, &r); + ReleaseDC(hwnd, hdc); + } 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); + } + /* + HWND hwnd = (HWND)get_value(_hdc, ATTR_NATIVE_WINDOW); + HDC hdc = GetDC(hwnd); + RECT r; + r.left = _client.left+DEPTH+1; + r.top = _client.top+DEPTH+1; + r.right = _client.right-DEPTH-1; + r.bottom = _client.bottom-DEPTH-1; + HBRUSH oldBrush = SelectObject(hdc, cpb.graybrush()); + PatBlt(hdc, r.left, r.top, r.right-r.left, r.bottom-r.top, 0xFA0089); // Real magic number + SelectObject(hdc, oldBrush); + ReleaseDC(hwnd, hdc); + */ + } +} + +/////////////////////////////////////////////////////////// +// 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); +}; + +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(); + cpb_win_picture_draw_at(_hdc, cpb[BMP_BOOK1 + _flag -1], 0, 0); +} + +/////////////////////////////////////////////////////////// +// 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); +}; + +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, COLOR_CYAN, COLOR_GRAY); + + char n[4]; sprintf(n, "%d", i+1); + win_draw_text(_hdc, (width-CHARX)/2 + i*width, CHARY-3, n, -1); + } + + CPEN pen; + pen.width = 1; + pen.pat = PAT_SOLID; + pen.style = P_SOLID; + pen.color = COLOR_CYAN; + 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; +} + +void TTag_button::mouse_up() +{ + if (_curr != _page) + dispatch_e_char(_parent, K_CTRL + K_F1 + _curr); +} + +/////////////////////////////////////////////////////////// +// Checkbox +/////////////////////////////////////////////////////////// + +class TCheckbox : public TButton +{ + static bool _bmploaded; + +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(); +}; + +bool TCheckbox::_bmploaded = FALSE; + +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 (!_bmploaded) + { + cpb.getbmp(BMP_CHECK_ON); + cpb.getbmp(BMP_CHECK_OFF); + cpb.getbmp(BMP_RADIO_ON); + cpb.getbmp(BMP_RADIO_OFF); + _bmploaded = TRUE; + } +} + + +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); +} + + +void TCheckbox::update() const +{ + TButton::update(); + + const int x = _client.left+20; + const int y = _client.top + CHARY-1; + + if (focused()) + { +#if XVT_OS == XVT_OS_WIN + RECT r; + r.left = x-2; r.top = _client.top; + r.right = _client.right; r.bottom = _client.bottom; + + 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 > ROWY) + { + top += 6; + bottom -= ROWY/2 -4; + } + 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; +} diff --git a/include/default.url b/include/default.url index a02345182..8be4b7fa7 100755 --- a/include/default.url +++ b/include/default.url @@ -1,84 +1,83 @@ -#ifndef APPNAME -#define APPNAME CAMPO -#define QAPPNAME "CAMPO" -#define LIBDIR c:\xvt.322\xvtwin\lib -#endif - -#define NO_STD_EDIT_MENU -#define NO_STD_FILE_MENU -#define NO_STD_FONT_MENU -#define NO_STD_HELP_MENU -#define NO_STD_ABOUT_BOX -#include - -#include - -MENUBAR TASK_MENUBAR - -MENU MENU_FILE - ITEM M_FILE_NEW "Scelta ~Ditta..." - ITEM M_FILE_REVERT "Impostazione ~Parametri..." - SEPARATOR - ITEM M_FILE_PG_SETUP "~Impostazione Stampante..." - ITEM M_FILE_PRINT "~Stampa" DISABLED - SEPARATOR - ITEM (M_FILE+11) "I~nformazioni" - ITEM M_FILE_QUIT "~Fine" - -MENU MENU_EDIT - ITEM M_EDIT_INSERT "~Inserisci" - ITEM M_EDIT_MODIFY "~Aggiorna" - ITEM M_EDIT_DELETE "~Cancella" - ITEM M_EDIT_SHOW "~Visualizza" - ITEM M_EDIT_SEARCH "C~erca" DISABLED - -MENU MENU_ALT_EDIT - ITEM M_EDIT_EDIT "~Aggiorna" - ITEM M_EDIT_SEARCH "C~erca" DISABLED - -ACCEL MENU_FILE "f" ALT -ACCEL MENU_EDIT "g" ALT - -#if XVTWS == WINWS -#scan -#transparent $$$ - XI_CURSOR_RESIZE cursor DISCARDABLE f:\p.due\bmp\resize.cur - XI_CURSOR_HAND cursor DISCARDABLE f:\p.due\bmp\hand.cur - XI_CURSOR_VRESIZE cursor DISCARDABLE f:\p.due\bmp\vresize.cur - COMBO_ICON icon DISCARDABLE f:\p.due\bmp\combo.ico - BMP_OK bitmap DISCARDABLE f:\p.due\bmp\ok.bmp - BMP_CANCEL bitmap DISCARDABLE f:\p.due\bmp\cancel.bmp - BMP_QUIT bitmap DISCARDABLE f:\p.due\bmp\quit.bmp - BMP_QUITDN bitmap DISCARDABLE f:\p.due\bmp\quitdn.bmp - BMP_SELECT bitmap DISCARDABLE f:\p.due\bmp\select.bmp - BMP_FIRSTREC bitmap DISCARDABLE f:\p.due\bmp\firstrec.bmp - BMP_PREVREC bitmap DISCARDABLE f:\p.due\bmp\prevrec.bmp - BMP_STOPREC bitmap DISCARDABLE f:\p.due\bmp\stoprec.bmp - BMP_NEXTREC bitmap DISCARDABLE f:\p.due\bmp\nextrec.bmp - BMP_LASTREC bitmap DISCARDABLE f:\p.due\bmp\lastrec.bmp - BMP_SAVEREC bitmap DISCARDABLE f:\p.due\bmp\saverec.bmp - BMP_SAVERECDN bitmap DISCARDABLE f:\p.due\bmp\saverecd.bmp - BMP_NEWREC bitmap DISCARDABLE f:\p.due\bmp\newrec.bmp - BMP_NEWRECDN bitmap DISCARDABLE f:\p.due\bmp\newrecdn.bmp - BMP_DELREC bitmap DISCARDABLE f:\p.due\bmp\delrec.bmp - BMP_DELRECDN bitmap DISCARDABLE f:\p.due\bmp\delrecdn.bmp - BMP_FINDREC bitmap DISCARDABLE f:\p.due\bmp\findrec.bmp - BMP_SEARCH bitmap DISCARDABLE f:\p.due\bmp\search.bmp - BMP_CHECK_ON bitmap DISCARDABLE f:\p.due\bmp\checkon.bmp - BMP_CHECK_OFF bitmap DISCARDABLE f:\p.due\bmp\checkoff.bmp - BMP_RADIO_ON bitmap DISCARDABLE f:\p.due\bmp\radioon.bmp - BMP_RADIO_OFF bitmap DISCARDABLE f:\p.due\bmp\radiooff.bmp - BMP_MODULE1 bitmap DISCARDABLE f:\p.due\bmp\module1.bmp - BMP_MODULE2 bitmap DISCARDABLE f:\p.due\bmp\module2.bmp - BMP_MODULE3 bitmap DISCARDABLE f:\p.due\bmp\module3.bmp - BMP_MODULE4 bitmap DISCARDABLE f:\p.due\bmp\module4.bmp - BMP_BOOK1 bitmap DISCARDABLE f:\p.due\bmp\book1.bmp - BMP_BOOK2 bitmap DISCARDABLE f:\p.due\bmp\book2.bmp - BMP_BOOK3 bitmap DISCARDABLE f:\p.due\bmp\book3.bmp - BMP_MODULE bitmap DISCARDABLE f:\p.due\bmp\module.bmp - BMP_EDIT bitmap DISCARDABLE f:\p.due\bmp\edit.bmp - BMP_LINK bitmap DISCARDABLE f:\p.due\bmp\link.bmp - BMP_PRINT bitmap DISCARDABLE f:\p.due\bmp\print.bmp - -$$$ -#endif +#ifndef APPNAME +#define APPNAME CAMPO +#define QAPPNAME "CAMPO" +#define LIBDIR c:\xvt.322\xvtwin\lib +#endif + +#define NO_STD_EDIT_MENU +#define NO_STD_FILE_MENU +#define NO_STD_FONT_MENU +#define NO_STD_HELP_MENU +#define NO_STD_ABOUT_BOX +#include + +#include + +MENUBAR TASK_MENUBAR + +MENU MENU_FILE + ITEM M_FILE_NEW "Scelta ~Ditta..." + ITEM M_FILE_REVERT "Impostazione ~Parametri..." + SEPARATOR + ITEM M_FILE_PG_SETUP "~Impostazione Stampante..." + ITEM M_FILE_PRINT "~Stampa" DISABLED + SEPARATOR + ITEM (M_FILE+11) "I~nformazioni" + ITEM M_FILE_QUIT "~Fine" + +MENU MENU_EDIT + ITEM M_EDIT_INSERT "~Inserisci" + ITEM M_EDIT_MODIFY "~Aggiorna" + ITEM M_EDIT_DELETE "~Cancella" + ITEM M_EDIT_SHOW "~Visualizza" + ITEM M_EDIT_SEARCH "C~erca" DISABLED + +MENU MENU_ALT_EDIT + ITEM M_EDIT_EDIT "~Aggiorna" + ITEM M_EDIT_SEARCH "C~erca" DISABLED + +ACCEL MENU_FILE "f" ALT + +#if XVTWS == WINWS +#scan +#transparent $$$ + XI_CURSOR_RESIZE cursor DISCARDABLE f:\p.due\bmp\resize.cur + XI_CURSOR_HAND cursor DISCARDABLE f:\p.due\bmp\hand.cur + XI_CURSOR_VRESIZE cursor DISCARDABLE f:\p.due\bmp\vresize.cur + COMBO_ICON icon DISCARDABLE f:\p.due\bmp\combo.ico + BMP_OK bitmap DISCARDABLE f:\p.due\bmp\ok.bmp + BMP_CANCEL bitmap DISCARDABLE f:\p.due\bmp\cancel.bmp + BMP_QUIT bitmap DISCARDABLE f:\p.due\bmp\quit.bmp + BMP_QUITDN bitmap DISCARDABLE f:\p.due\bmp\quitdn.bmp + BMP_SELECT bitmap DISCARDABLE f:\p.due\bmp\select.bmp + BMP_FIRSTREC bitmap DISCARDABLE f:\p.due\bmp\firstrec.bmp + BMP_PREVREC bitmap DISCARDABLE f:\p.due\bmp\prevrec.bmp + BMP_STOPREC bitmap DISCARDABLE f:\p.due\bmp\stoprec.bmp + BMP_NEXTREC bitmap DISCARDABLE f:\p.due\bmp\nextrec.bmp + BMP_LASTREC bitmap DISCARDABLE f:\p.due\bmp\lastrec.bmp + BMP_SAVEREC bitmap DISCARDABLE f:\p.due\bmp\saverec.bmp + BMP_SAVERECDN bitmap DISCARDABLE f:\p.due\bmp\saverecd.bmp + BMP_NEWREC bitmap DISCARDABLE f:\p.due\bmp\newrec.bmp + BMP_NEWRECDN bitmap DISCARDABLE f:\p.due\bmp\newrecdn.bmp + BMP_DELREC bitmap DISCARDABLE f:\p.due\bmp\delrec.bmp + BMP_DELRECDN bitmap DISCARDABLE f:\p.due\bmp\delrecdn.bmp + BMP_FINDREC bitmap DISCARDABLE f:\p.due\bmp\findrec.bmp + BMP_SEARCH bitmap DISCARDABLE f:\p.due\bmp\search.bmp + BMP_CHECK_ON bitmap DISCARDABLE f:\p.due\bmp\checkon.bmp + BMP_CHECK_OFF bitmap DISCARDABLE f:\p.due\bmp\checkoff.bmp + BMP_RADIO_ON bitmap DISCARDABLE f:\p.due\bmp\radioon.bmp + BMP_RADIO_OFF bitmap DISCARDABLE f:\p.due\bmp\radiooff.bmp + BMP_MODULE1 bitmap DISCARDABLE f:\p.due\bmp\module1.bmp + BMP_MODULE2 bitmap DISCARDABLE f:\p.due\bmp\module2.bmp + BMP_MODULE3 bitmap DISCARDABLE f:\p.due\bmp\module3.bmp + BMP_MODULE4 bitmap DISCARDABLE f:\p.due\bmp\module4.bmp + BMP_BOOK1 bitmap DISCARDABLE f:\p.due\bmp\book1.bmp + BMP_BOOK2 bitmap DISCARDABLE f:\p.due\bmp\book2.bmp + BMP_BOOK3 bitmap DISCARDABLE f:\p.due\bmp\book3.bmp + BMP_MODULE bitmap DISCARDABLE f:\p.due\bmp\module.bmp + BMP_EDIT bitmap DISCARDABLE f:\p.due\bmp\edit.bmp + BMP_LINK bitmap DISCARDABLE f:\p.due\bmp\link.bmp + BMP_PRINT bitmap DISCARDABLE f:\p.due\bmp\print.bmp + +$$$ +#endif diff --git a/include/files.h b/include/files.h index d55a2ebca..ec562992b 100755 --- a/include/files.h +++ b/include/files.h @@ -23,12 +23,12 @@ class TFile : public TObject { -// @DPRIV + // @DPRIV SecDef* _file; int _len; int _base; public: -// @FPUB + // @FPUB void open(const char* name, TFilelock lockmode = _manulock); bool verify(const char* name); void create(const char* name, TRecnotype nrecord = 10); @@ -54,12 +54,12 @@ public: class TDir : public TObject { -// @DPRIV + // @DPRIV FileDes* _dir; int _num; public: -// @FPUB + // @FPUB void get(int nfile, TReclock lock = _nolock, TDirtype dirtype = _nordir, TDirop op = _nordirop); void put(int nfile, TDirtype dirtype = _nordir, TDirop op = _nordirop); void zero(); @@ -91,14 +91,14 @@ public: class TTrec : public TSortable { -// @DPRIV + // @DPRIV RecDes* _rec; int _num; protected: int compare(const TSortable& a) const; public: -// @FPUB + // @FPUB void get(int nfile, TDirtype dirtype = _nordir); void put(int nfile, TDirtype dirtype = _nordir); void zero(); @@ -114,13 +114,15 @@ public: void set_keys(int nkeys) { _rec->NKeys = nkeys;} const char* fielddef(int fld) const; // ritorna una token string const char* keydef(int key) const; + int len() const { return _rec->Fd[fields() - 1].RecOff + + _rec->Fd[fields() - 1].Len; } + +#ifndef FOXPRO void update_keydef(int key, const char* desc); //desc e' una token string void update_fielddef(int nfld, const char* desc); //desc e' una token string - int len() const { return _rec->Fd[fields() - 1].RecOff + - _rec->Fd[fields() - 1].Len; } virtual void print_on(ostream& out) const; virtual void read_from(istream& in); - +#endif TTrec(); virtual ~TTrec(); diff --git a/include/keys.h b/include/keys.h index f017f232f..2b4532787 100755 --- a/include/keys.h +++ b/include/keys.h @@ -1,26 +1,27 @@ -#ifndef __KEYS_H -#define __KEYS_H - -#ifndef XVT_INCL_CONST -#include -#endif - -/* @M */ -#define K_BACKSPACE 8 -#define K_TAB 9 -#define K_ENTER 13 -#define K_ESC 27 -#define K_SPACE 32 -#define K_SHIFT 1000 -#define K_CTRL 10000 -#define K_SHIFT_ENTER K_ENTER+K_SHIFT -#define K_SHIFT_TAB K_TAB+K_SHIFT -#define K_SHIFT_F2 K_SHIFT+K_F2 -#define K_SHIFT_F3 K_SHIFT+K_F3 -#define K_NO 'N' -#define K_SAVE 'S' -#define K_QUIT 'Q' -#define K_YES 'Y' - -/* @END */ -#endif +#ifndef __KEYS_H +#define __KEYS_H + +#ifndef XVT_INCL_CONST +#include +#endif + +/* @M */ +#define K_BACKSPACE 8 +#define K_TAB 9 +#define K_ENTER 13 +#define K_ESC 27 +#define K_SPACE 32 +#define K_SHIFT 1000 +#define K_CTRL 10000 +#define K_CTRL_ENTER K_CTRL+K_ENTER +#define K_AUTO_ENTER K_SHIFT+K_ENTER +#define K_QUIT 10334 +#define K_SAVE 10082 +#define K_SHIFT_TAB K_SHIFT+K_TAB +#define K_SHIFT_F2 K_SHIFT+K_F2 +#define K_SHIFT_F3 K_SHIFT+K_F3 +#define K_NO 'N' +#define K_YES 'Y' + +/* @END */ +#endif diff --git a/include/mask.cpp b/include/mask.cpp index 0be4cb98d..5d009ccd1 100755 --- a/include/mask.cpp +++ b/include/mask.cpp @@ -97,30 +97,46 @@ void TMask::handler(WINDOW win, EVENT* ep) case E_CONTROL: switch(ep->v.ctl.id) { - case DLG_OK :on_key(K_SHIFT_ENTER); break; - case DLG_BAR : - case DLG_CANCEL :on_key(K_ESC); break; - case DLG_PGDN :on_key(K_NEXT); break; - case DLG_PGUP :on_key(K_PREV); break; - case DLG_FIRSTREC:stop_run(K_HOME); break; - case DLG_PREVREC :stop_run(K_PREV); break; - case DLG_NEXTREC :stop_run(K_NEXT); break; - case DLG_FINDREC :stop_run(K_F9); break; - case DLG_LASTREC :stop_run(K_END); break; - case DLG_NEWREC :stop_run(K_INS); break; - case DLG_DELREC :stop_run(K_DEL); break; - case DLG_SAVEREC :stop_run(K_SAVE); break; - case DLG_QUIT :stop_run(K_QUIT); break; - case DLG_F9: - { - TMask_field* f = (TMask_field*)get_app_data(ep->v.ctl.ci.win); - f->on_key(K_F9); - } - break; - default: - control_handler(ep); - break; - } + case DLG_OK : + on_key(K_AUTO_ENTER); break; + case DLG_BAR : + case DLG_CANCEL : + on_key(K_ESC); break; + /* + case DLG_PGDN : + on_key(K_NEXT); break; + case DLG_PGUP : + on_key(K_PREV); break; + case DLG_FIRSTREC: + stop_run(K_HOME); break; + case DLG_PREVREC : + stop_run(K_PREV); break; + case DLG_NEXTREC : + stop_run(K_NEXT); break; + case DLG_FINDREC : + stop_run(K_F9); break; + case DLG_LASTREC : + stop_run(K_END); break; + case DLG_NEWREC : + stop_run(K_INS); break; + case DLG_DELREC : + stop_run(K_DEL); break; + case DLG_SAVEREC : + stop_run(K_SAVE); break; + case DLG_QUIT : + stop_run(K_QUIT); break; + */ + case DLG_F9: + { + // Attiva ricerca sul campo associato al bottone + TMask_field* f = (TMask_field*)get_app_data(ep->v.ctl.ci.win); + f->on_key(K_F9); + } + break; + default: + control_handler(ep); + break; + } break; default: break; @@ -130,15 +146,16 @@ void TMask::handler(WINDOW win, EVENT* ep) void TMask::init_mask(int mode) { - _sheets = _pages = 0; - _enabled = 0xffff; - _focus = _first_focus = 0; - _page = -1; - _handler = NULL; _mode = mode; - _exchange = 1.0; + _sheets = _pages = 0; // Azzera numero pagine e sheets + _enabled = 0xffff; // Abilita tutte le pagine + _focus = _first_focus = 0; // Nessuna ha il focus + _page = -1; // Nessuan pagina corrente + _handler = NULL; // Nessun handler utente + _mode = mode; // Inizializza modo + _exchange = 1.0; // Il cambio per la valuta e' la lira for (int i = 0; i <= MAX_PAGES; i++) - _pagewin[i] = NULL_WIN; + _pagewin[i] = NULL_WIN; // Azzera le finestre delle varie pagine } @@ -584,13 +601,42 @@ void TMask::move_focus_field(int d) bool TMask::stop_run(KEY key) { - if (key == K_SHIFT_ENTER) key = K_ENTER; - + if (key == K_CTRL_ENTER) key = K_ENTER; + + if (key != K_AUTO_ENTER) + { + const int last = fields(); + bool found = FALSE; + for (int i = 0; i < last; i++) + { + const TMask_field& f = fld(i); + if (f.class_id() != CLASS_BUTTON_FIELD) continue; + const TButton_field& b = (const TButton_field&)f; + if (b.exit_key() == key) + { + if (b.active()) + { + found = TRUE; + break; + } + } + } + if (!found) + { +#ifdef DBG + return error_box("Non e' attivo il bottone associato a %d", key); +#else + beep(); + return FALSE; +#endif + } + } else key = K_ENTER; + if (key != K_ESC && key != K_QUIT && key != K_DEL) { const bool ok = check_fields(); if (!ok) return FALSE; - if (is_running()) // Gestisce meglio le maschere chiuse + if (is_running()) // Gestisce correttamenete le maschere chiuse get_mask_fields(); } @@ -606,12 +652,11 @@ bool TMask::on_key(KEY key) } switch(key) - { - case K_SHIFT_ENTER: + { + case K_AUTO_ENTER: + case K_CTRL_ENTER: case K_QUIT: case K_ESC: - case K_INS: - case K_DEL: stop_run(key); break; case K_UP: @@ -639,18 +684,34 @@ bool TMask::on_key(KEY key) #ifdef DBG case K_F11: message_box("Siete fortunati utenti del campo %d della maschera '%s'\n" - "caricata nell'incredibile tempo di %ld cicli\n" - "ed inizializzata mostruosamente in %ld cicli\n" - "Grazie per la comprensione", + "caricata nell'incredibile tempo di %ld millisecondi\n" + "ed inizializzata mostruosamente in %ld millisecondi\n" + "Grazie per la comprensione", fld(_focus).dlg(), (const char*)source_file(), clock1, clock2); break; #endif default: - if (key >= K_CTRL+K_F1 && key <= K_CTRL+K_F12) + if (key > K_CTRL) { - const int page = key - (K_CTRL+K_F1); - next_page(1000+page); - } + key -= K_CTRL; + if (key >= K_F1 && key <= K_F10) + next_page(1000 + key - K_F1); + else + { + const int last = fields(); + for (int i = 0; i < last; i++) + { + TMask_field& f = fld(i); + if (f.class_id() != CLASS_BUTTON_FIELD || !f.active()) continue; + TButton_field& b = (TButton_field&)f; + if (b.virtual_key() == key && fld(_focus).on_key(K_TAB) == TRUE) + { + f.on_key(K_SPACE); + break; + } + } + } + } else return fld(_focus).on_key(key); } diff --git a/include/mask.h b/include/mask.h index 59ce466d4..f2456ab43 100755 --- a/include/mask.h +++ b/include/mask.h @@ -1,187 +1,187 @@ -#ifndef __MASK_H -#define __MASK_H - -#ifndef __WINDOW_H -#include -#endif - -#ifndef __MASKFLD_H -#include -#endif - -#ifndef __REAL_H -#include -#endif - - -// @T -typedef bool (*MASK_HANDLER)(TMask& mask, KEY key); -enum TMaskmode { NO_MODE, MODE_INS , MODE_MOD , MODE_DEL , - MODE_VIS , MODE_QUERY, MODE_QUERYINS, - MODE_SEARCH }; -// @END - -// @C -// Classe TMask : public TWindow -// @END - -class TMask : public TWindow -{ -// @DPRIV - enum { MAX_PAGES = 12 }; // Massimo numero di pagine nella maschera - WINDOW _pagewin[MAX_PAGES+1]; // Windows of the pages - - int _pages; // Number of pages of the mask - int _page; // Current page - - word _enabled; // Are pages enabled (bit field) - int _mode; // Mode of the mask - TArray _field; // Fields in the mask - - int _first_focus; // First control to have focus - int _focus; // Control with focus - int _sheets; // Number of sheets - - MASK_HANDLER _handler; // User defined key handler - - TFilename _source_file; // Source file of the mask - TFilename _workfile; // Name of savefile - long _lastpos; // last read offset on savefile - - real _exchange; // Current value exhange - -protected: - // Ritorna la finestra della pagina corrente (Usare con attenzione) - WINDOW win() const { return _page == -1 ? NULL_WIN : _pagewin[_page]; } - WINDOW toolwin() const { return _pagewin[MAX_PAGES]; } - - int find_field_win(WINDOW win) const; // number of field with window win - - void set_mask_fields() const; // update screen - - void load_checks() const; // load checks related fields - virtual void start_run(); // called when the mask starts to run - virtual TMask_field* parse_field(TScanner& scanner); - - void init_mask(int mode); - WINDOW read_page(TScanner& scanner, bool toolbar = FALSE); - void read_mask(const char* name, int mode, int num); - void add_buttons(); - - int find_parent_page(const TMask_field&) const; - int find_first_field(WINDOW w, int dir) const; - int find_active_field(int first, int dir) const; - bool check_current_page(); // Check all the fields on the current page - void next_page(int p); // Show next/previous page - int curr_page() const { return _page; } // Current page number - void control_handler(EVENT* ep); - void handler(WINDOW win, EVENT* ep); - -public: -// @FPUB - // crea leggendo descrizione da file .msk - TMask(const char* name, int mode = NO_MODE, int num = 0); - - // crea mask vuota con parametri dati - TMask(const char* title, int pages, int cols, int rows, int xpos = -1, - int ypos = -1, int mode = NO_MODE); - - virtual ~TMask(); - - const TFilename& source_file() const { return _source_file; } - - // aggiunta campi a runtime - void add_static (short id, int page, const char* prompt, int x, int y, - const char* flags = ""); - void add_string (short id, int page, const char* prompt, int x, int y, - int dim, const char* flags = "", int width = 0); - void add_number (short id, int page, const char* prompt, int x, int y, - int dim, const char* flags = "", int ndec = 0); - void add_date (short id, int page, const char* prompt, int x, int y, - const char* flags = ""); - void add_button (short id, int page, const char* prompt, int x, int y, - int dx = 9, int dy = 1, const char* flags = ""); - - void add_radio(short id, int page, const char* prompt, int x, int y, - int dx, const char* codes, const char* items, const char* flags = ""); - - int fields() const { return _field.items(); } - int sheets() const { return _sheets; } - - void set_mode(int m) { _mode = m; } - int mode() const { return _mode; } - - void set_exchange(const real& e); - const real& exchange() const { return _exchange; } - - bool check_fields(); - void get_mask_fields(); // read screen contents - virtual bool stop_run(KEY key); // called to close the mask - - - virtual void open(); - virtual void close(); - virtual void enable(bool on) const; - - int id2pos(short id) const; - TMask_field& fld(int i) const { return (TMask_field&)_field[i]; } // Ritorna il campo i-esimo della maschera - TMask_field& field(short id) const; // field with given id - - void set(short fld_id, const char* str, bool hit=FALSE); - void set(short fld_id, long num, bool hit=FALSE); - const TString& get(short fld_id) const; - long get_long(short fld_id) const; - int get_int(short fld_id) const { return (int)get_long(fld_id); } - bool get_bool(short fld_id) const; - - int first_focus(short id); - void set_focus(); - void move_focus_field(int num); - void set_focus_win(WINDOW win, bool force); - int focus_field() const { return _focus;} - - virtual bool on_key(KEY key); - - void enable(short fld_id, bool on = TRUE); // Abilita un campo - void disable(short fld_id) { enable(fld_id, FALSE); } - void enable_default(short fld_id = -1); - - void enable_page(int p, bool on = TRUE); - void disable_page(int p) { enable_page(p, FALSE); } - bool page_enabled(int p) const; - - byte num_keys() const; - void enable_key(byte key, bool on = TRUE); - void disable_key(byte key) { enable_key(key, FALSE); } - short get_key_field(byte key, bool first) const; - bool key_valid(int key) const; - - void show(short fld_id = -1, bool on = TRUE); - void hide(short fld_id = -1) { show(fld_id, FALSE); } - void show_default(short fld_id = -1); - - void reset(short fld_id = -1); - void undo(short fld_id = -1); - - void autoload(const TRelation* = NULL); - void autosave(TRelation* = NULL) const; - - void send_key(KEY key, short id) const; - void set_handler(short fld_id, CONTROL_HANDLER handler); - void set_handler(MASK_HANDLER handler); - void set_workfile(const char* workfile) { _workfile = workfile; _lastpos = 0L;} - bool save(bool append = FALSE) const; - bool load(bool reset = FALSE); - - short dirty() const; // Ritorna il primo campo dirty - - bool no_mode() const { return _mode == NO_MODE; } - bool query_mode() const { return _mode == MODE_QUERY || _mode == MODE_QUERYINS; } - bool edit_mode() const { return _mode == MODE_MOD || _mode == MODE_VIS || _mode == MODE_DEL; } - bool insert_mode() const { return _mode == MODE_QUERYINS || _mode == MODE_INS; } - - virtual const char* get_caption() const; - virtual void set_caption(const char* c); -}; - -#endif // __MASK_H +#ifndef __MASK_H +#define __MASK_H + +#ifndef __WINDOW_H +#include +#endif + +#ifndef __MASKFLD_H +#include +#endif + +#ifndef __REAL_H +#include +#endif + + +// @T +typedef bool (*MASK_HANDLER)(TMask& mask, KEY key); +enum TMaskmode { NO_MODE, MODE_INS , MODE_MOD , MODE_DEL , + MODE_VIS , MODE_QUERY, MODE_QUERYINS, + MODE_SEARCH }; +// @END + +// @C +// Classe TMask : public TWindow +// @END + +class TMask : public TWindow +{ + // @DPRIV + enum { MAX_PAGES = 12 }; // Massimo numero di pagine nella maschera + WINDOW _pagewin[MAX_PAGES+1]; // Windows of the pages + + int _pages; // Number of pages of the mask + int _page; // Current page + + word _enabled; // Are pages enabled (bit field) + int _mode; // Mode of the mask + TArray _field; // Fields in the mask + + int _first_focus; // First control to have focus + int _focus; // Control with focus + int _sheets; // Number of sheets + + MASK_HANDLER _handler; // User defined key handler + + TFilename _source_file; // Source file of the mask + TFilename _workfile; // Name of savefile + long _lastpos; // last read offset on savefile + + real _exchange; // Current value exhange + +protected: + // Ritorna la finestra della pagina corrente (Usare con attenzione) + WINDOW win() const { return _page == -1 ? NULL_WIN : _pagewin[_page]; } + WINDOW toolwin() const { return _pagewin[MAX_PAGES]; } + + int find_field_win(WINDOW win) const; // number of field with window win + + void set_mask_fields() const; // update screen + + void load_checks() const; // load checks related fields + virtual void start_run(); // called when the mask starts to run + virtual TMask_field* parse_field(TScanner& scanner); + + void init_mask(int mode); + WINDOW read_page(TScanner& scanner, bool toolbar = FALSE); + void read_mask(const char* name, int mode, int num); + void add_buttons(); + + int find_parent_page(const TMask_field&) const; + int find_first_field(WINDOW w, int dir) const; + int find_active_field(int first, int dir) const; + bool check_current_page(); // Check all the fields on the current page + void next_page(int p); // Show next/previous page + int curr_page() const { return _page; } // Current page number + void control_handler(EVENT* ep); + void handler(WINDOW win, EVENT* ep); + +public: + // @FPUB + // crea leggendo descrizione da file .msk + TMask(const char* name, int mode = NO_MODE, int num = 0); + + // crea mask vuota con parametri dati + TMask(const char* title, int pages, int cols, int rows, int xpos = -1, + int ypos = -1, int mode = NO_MODE); + + virtual ~TMask(); + + const TFilename& source_file() const { return _source_file; } + + // aggiunta campi a runtime + void add_static (short id, int page, const char* prompt, int x, int y, + const char* flags = ""); + void add_string (short id, int page, const char* prompt, int x, int y, + int dim, const char* flags = "", int width = 0); + void add_number (short id, int page, const char* prompt, int x, int y, + int dim, const char* flags = "", int ndec = 0); + void add_date (short id, int page, const char* prompt, int x, int y, + const char* flags = ""); + void add_button (short id, int page, const char* prompt, int x, int y, + int dx = 9, int dy = 1, const char* flags = ""); + + void add_radio(short id, int page, const char* prompt, int x, int y, + int dx, const char* codes, const char* items, const char* flags = ""); + + int fields() const { return _field.items(); } + int sheets() const { return _sheets; } + + void set_mode(int m) { _mode = m; } + int mode() const { return _mode; } + + void set_exchange(const real& e); + const real& exchange() const { return _exchange; } + + bool check_fields(); + void get_mask_fields(); // read screen contents + virtual bool stop_run(KEY key); // called to close the mask + + + virtual void open(); + virtual void close(); + virtual void enable(bool on) const; + + int id2pos(short id) const; + TMask_field& fld(int i) const { return (TMask_field&)_field[i]; } // Ritorna il campo i-esimo della maschera + TMask_field& field(short id) const; // field with given id + + void set(short fld_id, const char* str, bool hit=FALSE); + void set(short fld_id, long num, bool hit=FALSE); + const TString& get(short fld_id) const; + long get_long(short fld_id) const; + int get_int(short fld_id) const { return (int)get_long(fld_id); } + bool get_bool(short fld_id) const; + + int first_focus(short id); + void set_focus(); + void move_focus_field(int num); + void set_focus_win(WINDOW win, bool force); + int focus_field() const { return _focus;} + + virtual bool on_key(KEY key); + + void enable(short fld_id, bool on = TRUE); // Abilita un campo + void disable(short fld_id) { enable(fld_id, FALSE); } + void enable_default(short fld_id = -1); + + void enable_page(int p, bool on = TRUE); + void disable_page(int p) { enable_page(p, FALSE); } + bool page_enabled(int p) const; + + byte num_keys() const; + void enable_key(byte key, bool on = TRUE); + void disable_key(byte key) { enable_key(key, FALSE); } + short get_key_field(byte key, bool first) const; + bool key_valid(int key) const; + + void show(short fld_id = -1, bool on = TRUE); + void hide(short fld_id = -1) { show(fld_id, FALSE); } + void show_default(short fld_id = -1); + + void reset(short fld_id = -1); + void undo(short fld_id = -1); + + void autoload(const TRelation* = NULL); + void autosave(TRelation* = NULL) const; + + void send_key(KEY key, short id) const; + void set_handler(short fld_id, CONTROL_HANDLER handler); + void set_handler(MASK_HANDLER handler); + void set_workfile(const char* workfile) { _workfile = workfile; _lastpos = 0L;} + bool save(bool append = FALSE) const; + bool load(bool reset = FALSE); + + short dirty() const; // Ritorna il primo campo dirty + + bool no_mode() const { return _mode == NO_MODE; } + bool query_mode() const { return _mode == MODE_QUERY || _mode == MODE_QUERYINS; } + bool edit_mode() const { return _mode == MODE_MOD || _mode == MODE_VIS || _mode == MODE_DEL; } + bool insert_mode() const { return _mode == MODE_QUERYINS || _mode == MODE_INS; } + + virtual const char* get_caption() const; + virtual void set_caption(const char* c); +}; + +#endif // __MASK_H diff --git a/include/maskfld.cpp b/include/maskfld.cpp index f2bb746cb..ac5a92c75 100755 --- a/include/maskfld.cpp +++ b/include/maskfld.cpp @@ -1,4 +1,4 @@ -// $Id: maskfld.cpp,v 1.2 1994-08-17 14:05:45 guy Exp $ +// $Id: maskfld.cpp,v 1.3 1994-08-23 13:52:21 guy Exp $ #include #include @@ -1823,7 +1823,7 @@ bool TEdit_field::on_key(KEY key) { for (int fld = m.get_key_field(i, TRUE); fld != -1; fld = m.get_key_field(i, FALSE)) m.field(fld).set_dirty(FALSE); - dispatch_e_char(get_parent(win()), K_SHIFT_ENTER); + dispatch_e_char(get_parent(win()), K_AUTO_ENTER); break; } } @@ -2053,29 +2053,49 @@ void TButton_field::create(WINDOW parent) { long flags = CTL_FLAG_CENTER_JUST; - if (_prompt.empty()) switch (dlg()) + switch (dlg()) { case DLG_OK: - _prompt = "Conferma"; + if (_prompt.empty()) + _prompt = "Conferma"; + _virtual_key = _exit_key = K_ENTER; flags |= CTL_FLAG_DEFAULT; break; case DLG_CANCEL: - _prompt = "Annulla"; + if (_prompt.empty()) + _prompt = "Annulla"; + _virtual_key = _exit_key = K_ESC; break; - case DLG_PGUP: - _prompt = "Pag <<"; break; - case DLG_PGDN: - _prompt = "Pag >>"; break; - case DLG_SAVEREC: - _prompt = "Registra"; break; case DLG_QUIT: - _prompt = "Fine"; break; + if (_prompt.empty()) + _prompt = "Fine"; + _virtual_key = K_F4; + _exit_key = K_QUIT; + break; default: + { + _exit_key = 0; + TToken_string* message = (TToken_string*)_message.objptr(0); + if (message != NULL) + { + TToken_string msg(message->get(0), ','); + const TFixed_string m(msg.get(0)); + if (m == "EXIT") + _exit_key = msg.get_int(); + else + if (msg.get_int() == 0) _exit_key = atoi(m); + } + const int n = _prompt.find('~'); + _virtual_key = (n >= 0) ? toupper(_prompt[n+1]) : _exit_key; + } break; } + + #if XWTWS == WMWS _prompt.center_just(_width); -#endif +#endif + wincreate(WC_PUSHBUTTON, _width + 2, _size, _prompt, parent, flags); } diff --git a/include/maskfld.h b/include/maskfld.h index b16458e2b..310a12151 100755 --- a/include/maskfld.h +++ b/include/maskfld.h @@ -1,4 +1,4 @@ -/* $Id: maskfld.h,v 1.1.1.1 1994-08-12 10:51:57 alex Exp $ */ +/* $Id: maskfld.h,v 1.2 1994-08-23 13:52:23 guy Exp $ */ #ifndef __MASKFLD_H #define __MASKFLD_H @@ -17,8 +17,8 @@ class TMask_field; class TRelation; // __RELATION_H -class TCursor; -class TFieldref; +class TCursor; +class TFieldref; // @T typedef bool (*CONTROL_HANDLER)(TMask_field& field, KEY key); @@ -33,167 +33,167 @@ enum CheckTime { RUNNING_CHECK, STARTING_CHECK, FINAL_CHECK }; class TMask_field : public TObject { -// @DPRIV -friend class TMask; + // @DPRIV + friend class TMask; - TMask* _mask; // The mask the control belongs to + TMask* _mask; // The mask the control belongs to - TString _help; // Help message - TFieldref* _field; // Corresponding field on the file - TBit_array _keys; // The keys the field belongs to - TBit_array _groups; // The groups the field belongs to + TString _help; // Help message + TFieldref* _field; // Corresponding field on the file + TBit_array _keys; // The keys the field belongs to + TBit_array _groups; // The groups the field belongs to protected: -// @DPROT - static int _x, _y; // Coordinate of the control - static int _width; // Size of the control - static TFixed_string _prompt;// Prompt of the field - CONTROL_HANDLER _handler; + // @DPROT + static int _x, _y; // Coordinate of the control + static int _width; // Size of the control + static TFixed_string _prompt;// Prompt of the field + CONTROL_HANDLER _handler; - int _size; // Max length of the string + int _size; // Max length of the string - WINDOW _win; // Window of the control (not its parent!) - WINDOW _promptwin; // Prompt of the control - short _dlg; // Identifier of the control + WINDOW _win; // Window of the control (not its parent!) + WINDOW _promptwin; // Prompt of the control + short _dlg; // Identifier of the control - int _validate_func; // Number of validation function - TArray _validate_parms; // Parameters for validation function - TArray _message; // Messages to send on modify + int _validate_func; // Number of validation function + TArray _validate_parms; // Parameters for validation function + TArray _message; // Messages to send on modify - struct TField_Flags - { - bool automagic : 1; - bool dirty : 1; // Modified during run ? - bool enabled : 1; // Is editable - bool enable_default : 1; - bool firm : 1; // Is the current firm ? - bool focusdirty : 1; // Modified during focus ? - bool ghost : 1; - bool persistent : 1; - bool rightjust : 1; - bool roman : 1; // Is a Roman number ? - bool showed : 1; // Is visible - bool show_default : 1; - bool uppercase : 1; - bool exchange : 1; // Value exchange - bool zerofilled : 1; + struct TField_Flags + { + bool automagic : 1; + bool dirty : 1; // Modified during run ? + bool enabled : 1; // Is editable + bool enable_default : 1; + bool firm : 1; // Is the current firm ? + bool focusdirty : 1; // Modified during focus ? + bool ghost : 1; + bool persistent : 1; + bool rightjust : 1; + bool roman : 1; // Is a Roman number ? + bool showed : 1; // Is visible + bool show_default : 1; + bool uppercase : 1; + bool exchange : 1; // Value exchange + bool zerofilled : 1; - TField_Flags(); - char update(const char*); - } _flags; + TField_Flags(); + char update(const char*); + } _flags; - void construct(TScanner& scanner, WINDOW parent); - void construct(short id, const char* prompt, int x, int y, int len, - WINDOW parent, const char* flags = "", int width = 0); + void construct(TScanner& scanner, WINDOW parent); + void construct(short id, const char* prompt, int x, int y, int len, + WINDOW parent, const char* flags = "", int width = 0); - virtual WINDOW win() const { return _win; } + virtual WINDOW win() const { return _win; } - WINDOW wincreate(WIN_TYPE ct, short dx, short dy, - const char* title, WINDOW parent, long flags); - int create_prompt(WINDOW parent, int width = 0, int heigth = 1); + WINDOW wincreate(WIN_TYPE ct, short dx, short dy, + const char* title, WINDOW parent, long flags); + int create_prompt(WINDOW parent, int width = 0, int heigth = 1); - long default_flags() const; + long default_flags() const; - virtual void parse_head(TScanner& scanner); - virtual bool parse_item(TScanner& scanner); + virtual void parse_head(TScanner& scanner); + virtual bool parse_item(TScanner& scanner); - virtual void create(WINDOW parent); - virtual void destroy(); + virtual void create(WINDOW parent); + virtual void destroy(); - virtual const char* get_window_data() const; - virtual void set_window_data(const char* data); + virtual const char* get_window_data() const; + virtual void set_window_data(const char* data); virtual void set_field_data(const char* data); - virtual const char* get_field_data() const; + virtual const char* get_field_data() const; - bool do_message(int n); + bool do_message(int n); public: -// @FPUB - short atodlg(const char* s) const; + // @FPUB + short atodlg(const char* s) const; - WINDOW parent() const; - short dlg() const { return _dlg; } - - virtual bool ok() const; - - bool dirty() const { return _flags.dirty; } - bool focusdirty() const { return _flags.focusdirty; } - void set_focusdirty(bool d = TRUE) { _flags.focusdirty = d; } - void set_dirty(bool d = TRUE) { _flags.dirty = d; set_focusdirty(d); } + WINDOW parent() const; + short dlg() const { return _dlg; } + + virtual bool ok() const; + + bool dirty() const { return _flags.dirty; } + bool focusdirty() const { return _flags.focusdirty; } + void set_focusdirty(bool d = TRUE) { _flags.focusdirty = d; } + void set_dirty(bool d = TRUE) { _flags.dirty = d; set_focusdirty(d); } - virtual const char* class_name() const; - virtual word class_id() const; - - int size() const { return _size; } + virtual const char* class_name() const; + virtual word class_id() const; + + int size() const { return _size; } - bool roman() const { return _flags.roman; } - bool automagic() const { return _flags.automagic; } - bool ghost() const { return _flags.ghost; } + bool roman() const { return _flags.roman; } + bool automagic() const { return _flags.automagic; } + bool ghost() const { return _flags.ghost; } - virtual bool has_check() const { return FALSE;} - virtual bool has_query() const { return FALSE;} - virtual bool has_message() const { return _message.items() > 0; } + virtual bool has_check() const { return FALSE;} + virtual bool has_query() const { return FALSE;} + virtual bool has_message() const { return _message.items() > 0; } - virtual CheckType check_type() const { return CHECK_NONE; } - bool required() const { return check_type() == CHECK_REQUIRED; } - virtual bool check(CheckTime = RUNNING_CHECK) { return TRUE;} + virtual CheckType check_type() const { return CHECK_NONE; } + bool required() const { return check_type() == CHECK_REQUIRED; } + virtual bool check(CheckTime = RUNNING_CHECK) { return TRUE;} - virtual void reset(); + virtual void reset(); - virtual void enable(bool on = TRUE); - void disable() { enable(FALSE); } - bool enabled() const { return _flags.enabled; } - void enable_default(); + virtual void enable(bool on = TRUE); + void disable() { enable(FALSE); } + bool enabled() const { return _flags.enabled; } + void enable_default(); - virtual void show(bool on = TRUE); - void hide() { show(FALSE); } - bool showed() const { return _flags.showed; } - void show_default(); + virtual void show(bool on = TRUE); + void hide() { show(FALSE); } + bool showed() const { return _flags.showed; } + void show_default(); - bool active() const; // Is visible and enabled? + bool active() const; // Is visible and enabled? - void set_handler(CONTROL_HANDLER handler) { _handler = handler; } + void set_handler(CONTROL_HANDLER handler) { _handler = handler; } - bool is_edit() const; - bool to_check(KEY k, bool checkrun = FALSE) const; + bool is_edit() const; + bool to_check(KEY k, bool checkrun = FALSE) const; - virtual bool on_hit(); - virtual bool on_key(KEY key); + virtual bool on_hit(); + virtual bool on_key(KEY key); - void set(const char* s); - TString& get() const; - - virtual const char* picture_data(const char* data, bool video); + void set(const char* s); + TString& get() const; + + virtual const char* picture_data(const char* data, bool video); - bool autoload(const TRelation* r = NULL); - bool autosave(TRelation* r = NULL) const; + bool autoload(const TRelation* r = NULL); + bool autosave(TRelation* r = NULL) const; - void undo(); + void undo(); - const char* prompt() const; - void set_prompt(const char* p); + const char* prompt() const; + void set_prompt(const char* p); - bool in_key(byte key) const { return _keys[key]; } - void set_key(byte key) { _keys.set(long(key)); _keys.set(0L);} - word last_key() const; + bool in_key(byte key) const { return _keys[key]; } + void set_key(byte key) { _keys.set(long(key)); _keys.set(0L);} + word last_key() const; - bool in_group(byte group) const { return _groups[group]; } - void set_group(byte group) { _groups.set(long(group)); _groups.set(0L);} + bool in_group(byte group) const { return _groups[group]; } + void set_group(byte group) { _groups.set(long(group)); _groups.set(0L);} - const TFieldref* field() const { return _field; } - - void set_focus() const; + const TFieldref* field() const { return _field; } + + void set_focus() const; -// set focus, message-box, set focus - bool message_box(const char* fmt, ...) const; - bool warning_box(const char* fmt, ...) const; - bool error_box(const char* fmt, ...) const; - bool yesno_box(const char* fmt, ...) const; - KEY yesnocancel_box(const char* fmt, ...) const; + // set focus, message-box, set focus + bool message_box(const char* fmt, ...) const; + bool warning_box(const char* fmt, ...) const; + bool error_box(const char* fmt, ...) const; + bool yesno_box(const char* fmt, ...) const; + KEY yesnocancel_box(const char* fmt, ...) const; - TMask& mask() const { return *_mask; } - TMask_field(TMask* mask); - virtual ~TMask_field(); + TMask& mask() const { return *_mask; } + TMask_field(TMask* mask); + virtual ~TMask_field(); }; @@ -208,57 +208,57 @@ class TEdit_field : public TMask_field friend class TList_sheet; protected: -// @DPROT - TString _str; - TString _picture; - TString _warning; - CheckType _check; // Accettabilita' di valori nulli - bool _forced; - bool _check_enabled; // Abilitato + // @DPROT + TString _str; + TString _picture; + TString _warning; + CheckType _check; // Accettabilita' di valori nulli + bool _forced; + bool _check_enabled; // Abilitato - TBrowse* _browse; - TList_sheet* _sheet; - WINDOW _buttonwin; + TBrowse* _browse; + TList_sheet* _sheet; + WINDOW _buttonwin; - const TBrowse* get_browse(TScanner& scanner) const; + const TBrowse* get_browse(TScanner& scanner) const; - virtual word class_id() const; - virtual void parse_head(TScanner& scanner); - virtual bool parse_item(TScanner& scanner); - virtual void show(bool on); - virtual void enable(bool on); + virtual word class_id() const; + virtual void parse_head(TScanner& scanner); + virtual bool parse_item(TScanner& scanner); + virtual void show(bool on); + virtual void enable(bool on); - virtual void create(WINDOW parent); - virtual void destroy(); + virtual void create(WINDOW parent); + virtual void destroy(); - bool validate(KEY k); + bool validate(KEY k); - virtual void set_window_data(const char* data); - virtual void set_field_data(const char* data); - virtual const char* get_field_data() const; + virtual void set_window_data(const char* data); + virtual void set_field_data(const char* data); + virtual const char* get_field_data() const; public: -// @FPUB - virtual bool on_hit(); - virtual bool on_key(KEY key); - virtual bool has_check() const; - virtual bool has_query() const { return _browse || _sheet;} - virtual const char* picture_data(const char* data, bool video); - virtual CheckType check_type() const { return _check; } - void check_type(CheckType c) { _check = c; } + // @FPUB + virtual bool on_hit(); + virtual bool on_key(KEY key); + virtual bool has_check() const; + virtual bool has_query() const { return _browse || _sheet;} + virtual const char* picture_data(const char* data, bool video); + virtual CheckType check_type() const { return _check; } + void check_type(CheckType c) { _check = c; } - bool forced() const { return _forced;} - virtual bool check(CheckTime = RUNNING_CHECK); - TBrowse* browse() const { return _browse;} - void enable_check(bool on = TRUE) ; - bool check_enabled() const { return _check_enabled;} + bool forced() const { return _forced;} + virtual bool check(CheckTime = RUNNING_CHECK); + TBrowse* browse() const { return _browse;} + void enable_check(bool on = TRUE) ; + bool check_enabled() const { return _check_enabled;} - const char* format(const char* data); - const char* picture() const { return _picture; } + const char* format(const char* data); + const char* picture() const { return _picture; } - TEdit_field(TMask* mask); - virtual ~TEdit_field(); + TEdit_field(TMask* mask); + virtual ~TEdit_field(); }; @@ -268,56 +268,56 @@ public: class TBrowse { - TEdit_field* _fld; // The field owning the sheet - TRelation* _relation; // Main relation - TCursor* _cursor; // Cursor on the relation - TString _insert; - TString _filter; - long _rec; - bool _secondary; - bool _checked; + TEdit_field* _fld; // The field owning the sheet + TRelation* _relation; // Main relation + TCursor* _cursor; // Cursor on the relation + TString _insert; + TString _filter; + long _rec; + bool _secondary; + bool _checked; - TToken_string _head, _items; - TToken_string _inp_id, _inp_fn; - TToken_string _out_id, _out_fn; + TToken_string _head, _items; + TToken_string _inp_id, _inp_fn; + TToken_string _out_id, _out_fn; protected: - void do_output(CheckTime = RUNNING_CHECK); - void do_clear(); - bool do_insert(); + void do_output(CheckTime = RUNNING_CHECK); + void do_clear(); + bool do_insert(); - TMask_field& field(short n) const; + TMask_field& field(short n) const; TToken_string& create_siblings(TToken_string& siblings); public: - int do_input(bool filter = FALSE); // Serve ai TCursor_sheet + int do_input(bool filter = FALSE); // Serve ai TCursor_sheet - TBrowse(TEdit_field* f, TRelation* r, int key = 1, const char* filter = ""); - TBrowse(TEdit_field* f, TCursor* c); - ~TBrowse(); + TBrowse(TEdit_field* f, TRelation* r, int key = 1, const char* filter = ""); + TBrowse(TEdit_field* f, TCursor* c); + ~TBrowse(); - void parse_join(TScanner& scanner); - void parse_input(TScanner& scanner); - void parse_display(TScanner& scanner); - void parse_output(TScanner& scanner); - void parse_insert(TScanner& scanner); - bool parse_copy(const TString& what, const TBrowse* b); + void parse_join(TScanner& scanner); + void parse_input(TScanner& scanner); + void parse_display(TScanner& scanner); + void parse_output(TScanner& scanner); + void parse_insert(TScanner& scanner); + bool parse_copy(const TString& what, const TBrowse* b); - void set_insert(const char* s) { _insert = s;} - const TString& get_insert() const { return _insert;} - const TString& get_filter() const { return _filter;} + void set_insert(const char* s) { _insert = s;} + const TString& get_insert() const { return _insert;} + const TString& get_filter() const { return _filter;} - TEdit_field& field() {return *_fld;} + TEdit_field& field() {return *_fld;} - bool check(CheckTime = RUNNING_CHECK); - bool empty_check(); - const TToken_string& head() const { return _head;} - const TToken_string& items() const { return _items;} - TCursor* cursor() const { return _cursor;} - bool checked() const { return _checked;} - bool secondary() const { return _secondary;} + bool check(CheckTime = RUNNING_CHECK); + bool empty_check(); + const TToken_string& head() const { return _head;} + const TToken_string& items() const { return _items;} + TCursor* cursor() const { return _cursor;} + bool checked() const { return _checked;} + bool secondary() const { return _secondary;} - KEY run(); + KEY run(); }; @@ -330,23 +330,23 @@ class TReal_field : public TEdit_field int _decimals; protected: -// @FPROT - virtual word class_id() const; + // @FPROT + virtual word class_id() const; - virtual const char* get_window_data() const; - virtual void set_window_data(const char* data); + virtual const char* get_window_data() const; + virtual void set_window_data(const char* data); - virtual void create(WINDOW parent); - virtual void parse_head(TScanner& scanner); - virtual bool on_key(KEY key); + virtual void create(WINDOW parent); + virtual void parse_head(TScanner& scanner); + virtual bool on_key(KEY key); public: -// @FPUB - void set_decimals(int d); // Set precision & picture - int decimals() const { return _decimals; } // Get precision - void exchange(const real& o, const real& n); // Change value / o * n + // @FPUB + void set_decimals(int d); // Set precision & picture + int decimals() const { return _decimals; } // Get precision + void exchange(const real& o, const real& n); // Change value / o * n - TReal_field(TMask* mask); + TReal_field(TMask* mask); }; @@ -357,15 +357,15 @@ public: class TDate_field : public TEdit_field { protected: -// @FPROT - virtual word class_id() const; - virtual void create(WINDOW parent); - virtual bool on_key(KEY key); + // @FPROT + virtual word class_id() const; + virtual void create(WINDOW parent); + virtual bool on_key(KEY key); public: -// @FPUB - void parse_head(TScanner& scanner); - TDate_field(TMask* mask); + // @FPUB + void parse_head(TScanner& scanner); + TDate_field(TMask* mask); }; @@ -376,24 +376,24 @@ public: class TBoolean_field : public TMask_field { protected: -// @DPROT - bool _on; + // @DPROT + bool _on; - virtual word class_id() const; + virtual word class_id() const; - virtual void create(WINDOW parent); - virtual const char* get_window_data() const; - virtual void set_window_data(const char* data); - virtual void set_field_data(const char* data = NULL); - virtual const char* get_field_data() const; - virtual bool parse_item(TScanner& scanner); - virtual void enable(bool on); - virtual bool on_hit(); - virtual bool on_key(KEY key); + virtual void create(WINDOW parent); + virtual const char* get_window_data() const; + virtual void set_window_data(const char* data); + virtual void set_field_data(const char* data = NULL); + virtual const char* get_field_data() const; + virtual bool parse_item(TScanner& scanner); + virtual void enable(bool on); + virtual bool on_hit(); + virtual bool on_key(KEY key); public: -// @FPUB - TBoolean_field(TMask* mask); + // @FPUB + TBoolean_field(TMask* mask); }; @@ -403,43 +403,43 @@ public: class TList_field : public TMask_field { -// @FPRIV - void add_list(); + // @FPRIV + void add_list(); protected: -// @FPROT - TToken_string _values; - TToken_string _codes; - TString _str; + // @FPROT + TToken_string _values; + TToken_string _codes; + TString _str; - virtual word class_id() const; + virtual word class_id() const; - virtual void set_window_data(const char* data); - virtual const char* get_window_data() const; - virtual void set_field_data(const char* data = NULL); - virtual const char* get_field_data() const; -// virtual const char* picture_data(const char* data, bool video); - - virtual void create(WINDOW parent); + virtual void set_window_data(const char* data); + virtual const char* get_window_data() const; + virtual void set_field_data(const char* data = NULL); + virtual const char* get_field_data() const; + // virtual const char* picture_data(const char* data, bool video); + + virtual void create(WINDOW parent); - virtual void current(int n); - virtual int current() const; + virtual void current(int n); + virtual int current() const; - int str2curr(const char* data); - virtual bool on_hit(); - virtual bool on_key(KEY key); - virtual void read_item(TScanner& scanner); + int str2curr(const char* data); + virtual bool on_hit(); + virtual bool on_key(KEY key); + virtual void read_item(TScanner& scanner); - virtual void parse_head(TScanner& scanner); - virtual bool parse_item(TScanner& scanner); + virtual void parse_head(TScanner& scanner); + virtual bool parse_item(TScanner& scanner); public: -// @FPUB - TList_field(TMask* mask); - virtual void replace_items(const char* codes, const char* values); - virtual void add_item(const char* code_value); + // @FPUB + TList_field(TMask* mask); + virtual void replace_items(const char* codes, const char* values); + virtual void add_item(const char* code_value); virtual void delete_item(const char* code); - int items() const; + int items() const; }; @@ -451,29 +451,29 @@ class TRadio_field : public TList_field { enum { MAX_RADIO = 8 }; -// @FPRIV - int _nitems; + // @FPRIV + int _nitems; int _active_item; WINDOW _radio_ctl_win[MAX_RADIO]; protected: -// @FPROT - virtual word class_id() const; - virtual void create(WINDOW parent); - virtual void destroy(); - virtual void enable(bool on); - virtual void show(bool on); + // @FPROT + virtual word class_id() const; + virtual void create(WINDOW parent); + virtual void destroy(); + virtual void enable(bool on); + virtual void show(bool on); - virtual void current(int n); - virtual int current() const; - WINDOW win() const { return _radio_ctl_win[_active_item]; } + virtual void current(int n); + virtual int current() const; + WINDOW win() const { return _radio_ctl_win[_active_item]; } public: -// @FPUB - TRadio_field(TMask* mask); + // @FPUB + TRadio_field(TMask* mask); - void check_radiobutton(WINDOW checked); - bool move_focus(int d); + void check_radiobutton(WINDOW checked); + bool move_focus(int d); }; @@ -483,21 +483,25 @@ public: // @END class TButton_field : public TMask_field -{ +{ + KEY _virtual_key, _exit_key; + protected: -// @FPROT - virtual word class_id() const; - virtual void create(WINDOW parent); + // @FPROT + virtual word class_id() const; + virtual void create(WINDOW parent); - void parse_head(TScanner& scanner); - bool parse_item(TScanner& scanner); - virtual void enable(bool); - virtual void show(bool); - virtual bool on_key(KEY key); + void parse_head(TScanner& scanner); + bool parse_item(TScanner& scanner); + virtual void enable(bool); + virtual void show(bool); + virtual bool on_key(KEY key); public: -// @FPUB + // @FPUB TButton_field(TMask* mask); + KEY virtual_key() const { return _virtual_key; } + KEY exit_key() const { return _exit_key; } }; @@ -508,12 +512,12 @@ public: class TGroup_field : public TMask_field { protected: -// @DPROT + // @DPROT virtual void parse_head(TScanner& scanner); virtual void create(WINDOW parent); public: -// @FPUB + // @FPUB TGroup_field(TMask* mask); }; diff --git a/include/msksheet.cpp b/include/msksheet.cpp index 6c246776c..124e38b53 100755 --- a/include/msksheet.cpp +++ b/include/msksheet.cpp @@ -609,6 +609,14 @@ break; } set_focus_cell(cur_row, cur_col); check_enabled = TRUE; // Enable checks + } + break; + case K_PREV: + case K_NEXT: + { + XI_OBJ* itf = xi_get_itf(win()); + const bool ok = (bool)xi_move_focus(itf); + if (ok) dispatch_e_char(parent(), k); } break; /* diff --git a/include/relapp.cpp b/include/relapp.cpp index 6a9d34303..3fa610f24 100755 --- a/include/relapp.cpp +++ b/include/relapp.cpp @@ -1,4 +1,4 @@ -// $Id: relapp.cpp,v 1.2 1994-08-17 14:08:21 guy Exp $ +// $Id: relapp.cpp,v 1.3 1994-08-23 13:52:26 guy Exp $ #include #include #include @@ -676,7 +676,7 @@ bool TRelation_application::main_loop() KEY k; // Provoca l'autopremimento per il messaggio di LINK - if (_lnflag) _mask->send_key(K_SHIFT_ENTER, 0); + if (_lnflag) _mask->send_key(K_CTRL_ENTER, 0); do { diff --git a/include/sheet.cpp b/include/sheet.cpp index 724daff01..570c9a8c6 100755 --- a/include/sheet.cpp +++ b/include/sheet.cpp @@ -1,735 +1,733 @@ -#include -#include -#include -#include -#include -#include -#include - -TSheet::TSheet(short x, short y, short dx, short dy, - const char* title, const char* head, byte buttons, - long first, WINDOW parent) - : _curr(first), _last_update(-1), _checkable(FALSE), - _check_enabled(TRUE), _buttonmask(buttons) -{ - const char* g; - - TToken_string new_head(512); - TToken_string h(head); - TString item(80); - - for(_columns = 0; (g = h.get()) != NULL; _columns++) - { - CHECK(_columns < MAX_COL, "To many columns in sheet "); - item = g; - - const int et = item.find('@'); - if (et >= 0) - { - _size[_columns] = atoi(item.mid(et+1)); - item.cut(et); - if (_columns == 0 && et == 0) - _checkable = _size[0] == 1; - } else _size[_columns] = item.len(); - - item.trim(); - new_head.add(item); - } - set_row(new_head, -1); - - for (int i = 0; i < MAX_BUT; i++) _button[i] = NULL_WIN; - - if (parent == NULL_WIN) parent = TASK_WIN; - - long flags = WSF_CLOSE | WSF_SIZE | WSF_VSCROLL | WSF_HSCROLL ; - WIN_TYPE wt = W_DOC; - - if (parent != TASK_WIN) - { - wt = W_PLAIN; - flags = WSF_VSCROLL; - } - - if (dx == 0) // Calculates window width - { - RCT r; get_client_rect(parent, &r); - dx = r.right/CHARX -6; - - const int larg = width(); - if (dx > larg) dx = larg; - } - if (dy == 0) dy = 20; // Calculates window height - - create(x, y, dx, dy, title, flags, wt, parent); - if (wt != W_PLAIN) // If normal sheet add buttons - { - _visible_rows = rows()- head_on() - 3; - - add_button(DLG_SELECT, "Selezione" ); - if (buttons & 0x1) add_button(DLG_NEWREC, "Gestione"); - if (buttons & 0x2) add_button(DLG_NEWREC, "Nuovo"); - if (buttons & 0x4) add_button(DLG_DELREC, "Elimina"); - if (buttons & 0x8) add_button(DLG_QUIT, "Fine"); - else add_button(DLG_CANCEL, "Annulla"); - } -} - -void TSheet::add_button(short id, const char* caption, KEY key) -{ -const int BUT_HEIGHT = -#if XVT_OS == XVT_OS_WIN - 2 -#else - 1 -#endif -; - WINDOW b = xvt_create_control(WC_PUSHBUTTON, 0, 0, 11, BUT_HEIGHT, caption, win(), 0, 0, id); - for (int i = 0; i < MAX_BUT; i++) - if (_button[i] == NULL_WIN) - { - _button[i] = b; - _key[i] = key; - break; - } -} - -void TSheet::repos_buttons() const -{ - for (int buttons = 0; _button[buttons] != NULL_WIN; buttons++) - if (buttons == MAX_BUT-1) { buttons++; break; } - if (buttons == 0) return; - - RCT wr; get_client_rect(win(), &wr); - RCT br; get_client_rect(_button[0], &br); - - int space = (wr.right - buttons * br.right) / (buttons+1); - if (space < 0) space = 0; - - int x = space; - const int y = wr.bottom - br.bottom-4; - for (int b = 0; b < buttons; b++, x += br.right+space) - { - RCT r; set_rect(&r, x, y, x+br.right, y+br.bottom); - move_window(_button[b], &r); - } -} - -void TSheet::open() -{ - set_scroll_max(width(), items()); - _last_update = -1; - - if (!is_visible(_curr)) set_first(_curr); - - if (buttons_on()) - { - // Abilita selezione se c'e' almeno un elemento - xvt_enable_control(_button[0], items() > 0); - repos_buttons(); - } - TScroll_window::open(); - force_update(); -} - - -void TSheet::set_first(long n) -{ - update_thumb(-1, n); -} - - -void TSheet::set_row(const TToken_string& row, byte i) -{ - if (i > 64) i = 0; else i++; - if (_page.objptr(i) == NULL) - _page.add(row, i); - else - ((TToken_string&)_page[i]) = row; -} - - -void TSheet::build_page(long from) -{ - const long f = (from < 0) ? first() : from; - - if (_last_update != f) - { - int r = visible_rows(); - if (f+r > items()) - r = int(items()-f); - if (r > 0) - page_build(f, r); - _last_update = f; - } -} - - -short TSheet::reserved_rows() const -{ - return buttons_on() ? 3 : 0; -} - - -void TSheet::handler(WINDOW win, EVENT* ep) -{ - switch(ep->type) - { - case E_FOCUS: - invert_row(selected()); - break; - case E_MOUSE_DOWN: - if (ep->v.mouse.button) - { - dispatch_e_char(win, K_ESC); - return; - } - case E_MOUSE_DBL: - { - const short y = ep->v.mouse.where.v / CHARY; - const short f = head_on() ? 1 : 0; - if (y >= f) - { - long vec = selected(); - long nuo = first()+y-f; - select(nuo); - if (ep->type == E_MOUSE_DBL) - dispatch_e_char(win, K_SHIFT_ENTER); - else if (_checkable && _check_enabled && vec == nuo) - { - _checked.not(nuo); - force_update(); - } - } - else - dispatch_e_char(win, y ? K_UP : K_PREV); - } - break; - case E_CONTROL: - switch(ep->v.ctl.id) - { - case DLG_OK : - case DLG_SELECT:dispatch_e_char(win, K_SHIFT_ENTER); break; - case DLG_CANCEL: - case DLG_QUIT :dispatch_e_char(win, K_ESC); break; - case DLG_NEWREC:dispatch_e_char(win, K_INS); break; - case DLG_DELREC:dispatch_e_char(win, K_DEL); break; - default: - { - const WINDOW b = ep->v.ctl.ci.win; - - for (int i = 0; i < MAX_BUT; i++) - if (_button[i] == b) - { - stop_run(_key[i]); - break; - } - break; - } - } - break; - case E_SIZE: - { - _last_update = -1; - _visible_rows = ep->v.size.height/CHARY - (head_on() ? 1 : 0); - if (buttons_on()) - { - _visible_rows -= reserved_rows(); - repos_buttons(); - } - force_update(); - } - break; - default: - break; - } - - TScroll_window::handler(win, ep); -} - - -PNT TSheet::log2dev(long x, long y) const -{ - if (autoscrolling()) x -= origin().x; - return TWindow::log2dev(x, y); -} - -bool TSheet::on_key(KEY key) -{ - switch(key) - { - case K_SHIFT_ENTER: - key = K_ENTER; - case K_ENTER: - if (items() < 1) key = K_ESC; - case K_ESC: - stop_run(key); - case K_DEL: - if ((_buttonmask & 0x4) && items()) - stop_run(key); - break; - case K_INS: - if (_buttonmask & 0x3) - stop_run(K_INS); - break; - case K_LHOME: - select(0); - return TRUE; - case K_LEND: - select(items()-1); - return TRUE; - case K_PREV: - select(selected()-visible_rows()); - return TRUE; - case K_UP: - select(selected()-1); - return TRUE; - case K_NEXT: - select(selected()+visible_rows()); - return TRUE; - case K_DOWN: - select(selected()+1); - return TRUE; - case K_CTRL+'P': - print(); - break; - default: - for (int i = 0; i < MAX_BUT; i++) - if (_key[i] == key) - { - stop_run(key); - break; - } - break; - } - - if (_checkable && _check_enabled && items() > 0) - { - bool ok = TRUE; - switch(key) - { - case K_SPACE: _checked.not(selected()); break; - case K_F2 : uncheck(-1); break; - case K_F3 : check(-1); break; - default : ok = FALSE; break; - } - if (ok) force_update(); - } - return TScroll_window::on_key(key); -} - - -void TSheet::select(long n) -{ - if (n < 0) n = 0; else - if (n >= items()) n = items()-1; - - invert_row(_curr); - _curr = n; - - if (is_visible(_curr)) - invert_row(_curr); - else - { - const long s = (_curr < first()) ? _curr : _curr-visible_rows()+1; - set_first(s); - force_update(); - } -} - - -void TSheet::check(long n, bool on) -{ - if (n < 0) - { - if (on) - { - _checked.set(items()-1); // Force the size of Bit_array - _checked.set(); - } - else - _checked.reset(); - } - else - _checked.set(n, on); -} - - -// Converte il numero di riga assoluto nell'indice dell'array _page -int TSheet::row_to_page(long n) const -{ - long i = (n < 0) ? 0L : n-first()+1; - - if (i < 0 || i > visible_rows()) - { - error_box("Line out of screen"); - i = 0L; - } - - return (int)i; -} - - -// Converte il numero di riga assoluto nella coordinata y sulla finestra -int TSheet::row_to_win(long n) const -{ - int y = row_to_page(n); - - if (y < 1) y = 0; else - if (!head_on()) y--; - - return y; -} - - -// Calcola la larghezza totale dello sheet virtuale -int TSheet::width() const -{ - int width = 0; - for (int c = 0; c < _columns; c++) - width += _size[c]+(c > 0); - return width; -} - -void TSheet::invert_row(long n) -{ - if (win() != NULL_WIN && is_visible(n)) - { - const short y = row_to_win(n); - autoscroll(FALSE); - invert_bar(0,y,columns(),y+1); - autoscroll(TRUE); - } -} - - -bool TSheet::update_row(long n) -{ - const int i = row_to_page(n); - if (i >= _page.items()) return FALSE; - - TToken_string& t = (TToken_string&)(_page[i]); - t.restart(); - - const short y = row_to_win(n); - const char* s; - - int x = 0; - for (int j = 0; (s = t.get()) != NULL; x += _size[j++]+1) - { - int x1 = x; - if (n < 0) // Centra le testate - x1 += (_size[j]-strlen(s)) / 2; - else - if (_checkable && j == 0) - s = _checked[n] ? "X" : " "; - stringat(x1, y, s); - } - - return TRUE; -} - - -TToken_string& TSheet::row(long n) -{ - if (n < 0) n = selected(); - if (!is_visible(n)) - { - build_page(n); - set_first(n); - } - short idx = row_to_page(n); - return (TToken_string&)_page[idx]; -} - - -void TSheet::update() -{ - if (_last_update < 0) - { - set_color(COLOR_BLACK, COLOR_WHITE); - set_brush(COLOR_WHITE); - set_pen(COLOR_BLACK); - set_font(FF_FIXED); - _visible_rows = rows() - reserved_rows() - head_on(); - } - - if (head_on()) - { - const int height = visible_rows()+1; - const int width = columns()+1; - short x = -1; - for (int c = 0; c < _columns; c++) - { - x += _size[c] + 1; - line(x,0,x,height); - } - autoscroll(FALSE); - set_brush(MASK_BACK_COLOR); - bar(0,0,width,1); - if (buttons_on()) - bar(0, height, width, height+reserved_rows()+1); - autoscroll(TRUE); - } - - build_page(); - if (head_on()) update_row(-1); - - long last = first() + visible_rows(); - if (last > items()) last = items(); - for (long n = first(); n < last; n++) update_row(n); - - if (get_front_window() == win()) - invert_row(selected()); -} - -void TSheet::print() -{ - TPrinter& pr = MainApp()->printer(); - TPrintrow row; - bool ok = pr.open(); - - set_cursor(TASK_WIN, CURSOR_WAIT); - int step = visible_rows(); - for (long n = 0L; ok && n < items(); n += step) - { - set_first(n); - build_page(); - - if ((n+step) > items()) step = int(items()-n); - for (int i = 1; ok && i <= step; i++) - { - const char* s; - - TToken_string& t = (TToken_string&)_page[i]; - t.restart(); - - row.reset(); - for (int j = 0, x = 0; (s = t.get()) != NULL; x += _size[j++]+1) - row.put(s, x); - - ok = pr.print(row); - } - } - set_cursor(TASK_WIN, CURSOR_ARROW); - - if (ok) - { - pr.formfeed(); - pr.close(); - } - set_focus(); -} - -/////////////////////////////////////////////////////////// -// TArray_sheet -/////////////////////////////////////////////////////////// - -TArray_sheet::TArray_sheet(short x, short y, short dx, short dy, - const char* caption, const char* head, byte buttons, WINDOW parent) - : TSheet(x, y, dx, dy, caption, head, buttons, 0L, parent) -{} - -void TArray_sheet::page_build(long first, byte num) -{ - for (byte i = 0; i < num; i++) - set_row(data(first+i), i); -} - -long TArray_sheet::add(const TToken_string& s) -{ - const long n = _data.add(s, -1); - set_scroll_max(-1, n); - return n; -} - -long TArray_sheet::insert(const TToken_string& s, long n) -{ - _data.insert(s, (int)n); - set_scroll_max(-1, items()); - return n; -} - - -/////////////////////////////////////////////////////////// -// TCursor_sheet -/////////////////////////////////////////////////////////// - -TCursor_sheet::TCursor_sheet(TCursor* cursor, const char* fields, - const char* title, const char* head, byte buttons) - : TSheet(-1,-1, 0, 0, title,head,buttons,cursor->pos()), - _cursor(cursor), _records(cursor->items()) -{ - TToken_string fldlst(fields); - int campi = 0; - for (const char* t = fldlst.get(); t; t = fldlst.get(), campi++) - if (*t > ' ' && *t != '\"') - { - TFieldref fr(t, 0); - TRecfield* rf = new TRecfield(_cursor->curr(fr.file()), - fr.name(), fr.from(), fr.to() - 1); - _fields.add(rf, campi); - } -} - - -KEY TCursor_sheet::run() -{ - _records = _cursor->items(); - _cursor->freeze(TRUE); - const KEY k = TSheet::run(); - _cursor->freeze(FALSE); - return k; -} - - -void TCursor_sheet::page_build(long first, byte rows) -{ - TToken_string l(256); - - *_cursor = (TRecnotype)first; - for (byte r = 0; r < rows; r++, ++(*_cursor)) - { - l.cut(0); - const int last = _fields.last(); - for (int i = 0; i <= last; i++) - { - TRecfield* rf = (TRecfield*)_fields.objptr(i); - TFixed_string s(rf ? (const char*)*rf : ""); - l.add(s); - } - set_row(l, r); - } -} - -/////////////////////////////////////////////////////////// -// TBrowse_sheet -/////////////////////////////////////////////////////////// - -TBrowse_sheet::TBrowse_sheet(TCursor* cursor, const char* fields, - const char* title, const char* head, byte buttons, - TEdit_field* f, TToken_string* s) - : TCursor_sheet(cursor, fields, title, head, buttons), _field(f) - -{ - xvt_create_control(WC_EDIT, 1, -3, f->size()+1, 1, f->get(), win(), - CTL_FLAG_DISABLED, 0L, 100); - if (s) - { - WINDOW listbox = xvt_create_control(WC_LISTBUTTON, f->size()+3, -3, 18, 3, - "", win(), 0, 0L, 99); - - SLIST lst = slist_new(); - for (const char* item = s->get(0); item; item = s->get()) - { - item = s->get(); - slist_add(lst, (SLIST_ELT)NULL, (char*)item, 0L); - } - win_list_add(listbox, -1, (char*)lst); - slist_dispose(lst); - - TString id(3); id << f->dlg(); - const int sel = s->get_pos(id) >> 1; - win_list_set_sel(listbox, sel, TRUE); - } -} - - -short TBrowse_sheet::reserved_rows() const -{ - return TSheet::reserved_rows() + 1; -} - - -void TBrowse_sheet::repos_buttons() const -{ - TSheet::repos_buttons(); - - RCT wr; get_client_rect(win(), &wr); - for (int id = 99; id <= 100; id++) - { - WINDOW w = get_ctl_window(win(), id); - if (w != NULL_WIN) - { - RCT r; get_client_rect(w, &r); - r.left = CHARX*(id == 99 ? 1 : 21); - r.top = wr.bottom - 4*CHARY + 4; - r.right += r.left; - r.bottom += r.top; - move_window(w, &r); - } - } -} - - -bool TBrowse_sheet::on_key(KEY k) -{ - WINDOW ctl = get_ctl_window(win(), 100); - - const bool alnum = (k >= '0' && k <= '9') || - (k >= 'A' && k <= 'Z') || - (k >= 'a' && k <= 'z') || - k == ' '; - if (alnum || k == K_BACKSPACE || k == K_DEL) - { - const long oldsel = selected(); - const TString old(_field->get()); - - TString val(old.size()+1); val = old; - if (alnum) val << char(k); - else val.rtrim(1); - field().set(val); - - ((TBrowse*)field().browse())->do_input(FALSE); - _cursor->read(); - if (_cursor->file()->bad()) - { - beep(); - field().set(val = old); - *_cursor = oldsel; - } - else - select(_cursor->pos()); - - if (ctl != NULL_WIN) set_title(ctl, (char*)(const char*)field().get()); - return TRUE; - } - else - { - field().reset(); - if (ctl != NULL_WIN) set_title(ctl, ""); - } - - return TSheet::on_key(k); -} - - -void TBrowse_sheet::handler(WINDOW win, EVENT* ep) -{ - if (ep->type == E_CONTROL && ep->v.ctl.id == 99) - { - const int what = win_list_get_sel_index(ep->v.ctl.ci.win); - if (what >= 0) - stop_run(K_CTRL + what); - else - set_front_window(win); - return; - } - TCursor_sheet::handler(win, ep); -} - - -KEY TBrowse_sheet::run() -{ - const bool spork = field().dirty(); // Store field status - const TString old(field().get()); - - const KEY key = TCursor_sheet::run(); - - if (key == K_ESC || key == K_F9 || key == K_INS) - { - field().set(old); // Restore field status - field().set_dirty(spork); - } - - return key; -} \ No newline at end of file +#include +#include +#include +#include +#include +#include +#include + +TSheet::TSheet(short x, short y, short dx, short dy, + const char* title, const char* head, byte buttons, + long first, WINDOW parent) +: _curr(first), _last_update(-1), _checkable(FALSE), + _check_enabled(TRUE), _buttonmask(buttons) +{ + const char* g; + + TToken_string new_head(512); + TToken_string h(head); + TString item(80); + + for(_columns = 0; (g = h.get()) != NULL; _columns++) + { + CHECK(_columns < MAX_COL, "To many columns in sheet "); + item = g; + + const int et = item.find('@'); + if (et >= 0) + { + _size[_columns] = atoi(item.mid(et+1)); + item.cut(et); + if (_columns == 0 && et == 0) + _checkable = _size[0] == 1; + } else _size[_columns] = item.len(); + + item.trim(); + new_head.add(item); + } + set_row(new_head, -1); + + for (int i = 0; i < MAX_BUT; i++) _button[i] = NULL_WIN; + + if (parent == NULL_WIN) parent = TASK_WIN; + + long flags = WSF_CLOSE | WSF_SIZE | WSF_VSCROLL | WSF_HSCROLL ; + WIN_TYPE wt = W_DOC; + + if (parent != TASK_WIN) + { + wt = W_PLAIN; + flags = WSF_VSCROLL; + } + + if (dx == 0) // Calculates window width + { + RCT r; get_client_rect(parent, &r); + dx = r.right/CHARX -6; + + const int larg = width(); + if (dx > larg) dx = larg; + } + if (dy == 0) dy = 20; // Calculates window height + + create(x, y, dx, dy, title, flags, wt, parent); + if (wt != W_PLAIN) // If normal sheet add buttons + { + _visible_rows = rows()- head_on() - 3; + + add_button(DLG_SELECT, "Selezione" ); + if (buttons & 0x1) add_button(DLG_NEWREC, "Gestione"); + if (buttons & 0x2) add_button(DLG_NEWREC, "Nuovo"); + if (buttons & 0x4) add_button(DLG_DELREC, "Elimina"); + if (buttons & 0x8) add_button(DLG_QUIT, "Fine"); + else add_button(DLG_CANCEL, "Annulla"); + } +} + +void TSheet::add_button(short id, const char* caption, KEY key) +{ + const int BUT_HEIGHT = +#if XVT_OS == XVT_OS_WIN + 2 +#else + 1 +#endif + ; + WINDOW b = xvt_create_control(WC_PUSHBUTTON, 0, 0, 11, BUT_HEIGHT, caption, win(), 0, 0, id); + for (int i = 0; i < MAX_BUT; i++) + if (_button[i] == NULL_WIN) + { + _button[i] = b; + _key[i] = key; + break; + } +} + +void TSheet::repos_buttons() const +{ + for (int buttons = 0; _button[buttons] != NULL_WIN; buttons++) + if (buttons == MAX_BUT-1) { buttons++; break; } + if (buttons == 0) return; + + RCT wr; get_client_rect(win(), &wr); + RCT br; get_client_rect(_button[0], &br); + + int space = (wr.right - buttons * br.right) / (buttons+1); + if (space < 0) space = 0; + + int x = space; + const int y = wr.bottom - br.bottom-4; + for (int b = 0; b < buttons; b++, x += br.right+space) + { + RCT r; set_rect(&r, x, y, x+br.right, y+br.bottom); + move_window(_button[b], &r); + } +} + +void TSheet::open() +{ + set_scroll_max(width(), items()); + _last_update = -1; + + if (!is_visible(_curr)) set_first(_curr); + + if (buttons_on()) + { + // Abilita selezione se c'e' almeno un elemento + xvt_enable_control(_button[0], items() > 0); + repos_buttons(); + } + TScroll_window::open(); + force_update(); +} + + +void TSheet::set_first(long n) +{ + update_thumb(-1, n); +} + + +void TSheet::set_row(const TToken_string& row, byte i) +{ + if (i > 64) i = 0; else i++; + if (_page.objptr(i) == NULL) + _page.add(row, i); + else + ((TToken_string&)_page[i]) = row; +} + + +void TSheet::build_page(long from) +{ + const long f = (from < 0) ? first() : from; + + if (_last_update != f) + { + int r = visible_rows(); + if (f+r > items()) + r = int(items()-f); + if (r > 0) + page_build(f, r); + _last_update = f; + } +} + + +short TSheet::reserved_rows() const +{ + return buttons_on() ? 3 : 0; +} + + +void TSheet::handler(WINDOW win, EVENT* ep) +{ + switch(ep->type) + { + case E_FOCUS: + invert_row(selected()); + break; + case E_MOUSE_DOWN: + if (ep->v.mouse.button) + { + dispatch_e_char(win, K_ESC); + return; + } + case E_MOUSE_DBL: + { + const short y = ep->v.mouse.where.v / CHARY; + const short f = head_on() ? 1 : 0; + if (y >= f) + { + long vec = selected(); + long nuo = first()+y-f; + select(nuo); + if (ep->type == E_MOUSE_DBL) + dispatch_e_char(win, K_ENTER); + else if (_checkable && _check_enabled && vec == nuo) + { + _checked.not(nuo); + force_update(); + } + } + else + dispatch_e_char(win, y ? K_UP : K_PREV); + } + break; + case E_CONTROL: + switch(ep->v.ctl.id) + { + case DLG_OK : + case DLG_SELECT:dispatch_e_char(win, K_ENTER); break; + case DLG_CANCEL: + case DLG_QUIT :dispatch_e_char(win, K_ESC); break; + case DLG_NEWREC:dispatch_e_char(win, K_INS); break; + case DLG_DELREC:dispatch_e_char(win, K_DEL); break; + default: + { + const WINDOW b = ep->v.ctl.ci.win; + + for (int i = 0; i < MAX_BUT; i++) + if (_button[i] == b) + { + stop_run(_key[i]); + break; + } + break; + } + } + break; + case E_SIZE: + { + _last_update = -1; + _visible_rows = ep->v.size.height/CHARY - (head_on() ? 1 : 0); + if (buttons_on()) + { + _visible_rows -= reserved_rows(); + repos_buttons(); + } + force_update(); + } + break; + default: + break; + } + + TScroll_window::handler(win, ep); +} + + +PNT TSheet::log2dev(long x, long y) const +{ + if (autoscrolling()) x -= origin().x; + return TWindow::log2dev(x, y); +} + +bool TSheet::on_key(KEY key) +{ + switch(key) + { + case K_ENTER: + if (items() < 1) key = K_ESC; + case K_ESC: + stop_run(key); + case K_DEL: + if ((_buttonmask & 0x4) && items()) + stop_run(key); + break; + case K_INS: + if (_buttonmask & 0x3) + stop_run(K_INS); + break; + case K_LHOME: + select(0); + return TRUE; + case K_LEND: + select(items()-1); + return TRUE; + case K_PREV: + select(selected()-visible_rows()); + return TRUE; + case K_UP: + select(selected()-1); + return TRUE; + case K_NEXT: + select(selected()+visible_rows()); + return TRUE; + case K_DOWN: + select(selected()+1); + return TRUE; + case K_CTRL+'P': + print(); + break; + default: + for (int i = 0; i < MAX_BUT; i++) + if (_key[i] == key) + { + stop_run(key); + break; + } + break; + } + + if (_checkable && _check_enabled && items() > 0) + { + bool ok = TRUE; + switch(key) + { + case K_SPACE: _checked.not(selected()); break; + case K_F2 : uncheck(-1); break; + case K_F3 : check(-1); break; + default : ok = FALSE; break; + } + if (ok) force_update(); + } + return TScroll_window::on_key(key); +} + + +void TSheet::select(long n) +{ + if (n < 0) n = 0; else + if (n >= items()) n = items()-1; + + invert_row(_curr); + _curr = n; + + if (is_visible(_curr)) + invert_row(_curr); + else + { + const long s = (_curr < first()) ? _curr : _curr-visible_rows()+1; + set_first(s); + force_update(); + } +} + + +void TSheet::check(long n, bool on) +{ + if (n < 0) + { + if (on) + { + _checked.set(items()-1); // Force the size of Bit_array + _checked.set(); + } + else + _checked.reset(); + } + else + _checked.set(n, on); +} + + +// Converte il numero di riga assoluto nell'indice dell'array _page +int TSheet::row_to_page(long n) const +{ + long i = (n < 0) ? 0L : n-first()+1; + + if (i < 0 || i > visible_rows()) + { + error_box("Line out of screen"); + i = 0L; + } + + return (int)i; +} + + +// Converte il numero di riga assoluto nella coordinata y sulla finestra +int TSheet::row_to_win(long n) const +{ + int y = row_to_page(n); + + if (y < 1) y = 0; else + if (!head_on()) y--; + + return y; +} + + +// Calcola la larghezza totale dello sheet virtuale +int TSheet::width() const +{ + int width = 0; + for (int c = 0; c < _columns; c++) + width += _size[c]+(c > 0); + return width; +} + +void TSheet::invert_row(long n) +{ + if (win() != NULL_WIN && is_visible(n)) + { + const short y = row_to_win(n); + autoscroll(FALSE); + invert_bar(0,y,columns(),y+1); + autoscroll(TRUE); + } +} + + +bool TSheet::update_row(long n) +{ + const int i = row_to_page(n); + if (i >= _page.items()) return FALSE; + + TToken_string& t = (TToken_string&)(_page[i]); + t.restart(); + + const short y = row_to_win(n); + const char* s; + + int x = 0; + for (int j = 0; (s = t.get()) != NULL; x += _size[j++]+1) + { + int x1 = x; + if (n < 0) // Centra le testate + x1 += (_size[j]-strlen(s)) / 2; + else + if (_checkable && j == 0) + s = _checked[n] ? "X" : " "; + stringat(x1, y, s); + } + + return TRUE; +} + + +TToken_string& TSheet::row(long n) +{ + if (n < 0) n = selected(); + if (!is_visible(n)) + { + build_page(n); + set_first(n); + } + short idx = row_to_page(n); + return (TToken_string&)_page[idx]; +} + + +void TSheet::update() +{ + if (_last_update < 0) + { + set_color(COLOR_BLACK, COLOR_WHITE); + set_brush(COLOR_WHITE); + set_pen(COLOR_BLACK); + set_font(FF_FIXED); + _visible_rows = rows() - reserved_rows() - head_on(); + } + + if (head_on()) + { + const int height = visible_rows()+1; + const int width = columns()+1; + short x = -1; + for (int c = 0; c < _columns; c++) + { + x += _size[c] + 1; + line(x,0,x,height); + } + autoscroll(FALSE); + set_brush(MASK_BACK_COLOR); + bar(0,0,width,1); + if (buttons_on()) + bar(0, height, width, height+reserved_rows()+1); + autoscroll(TRUE); + } + + build_page(); + if (head_on()) update_row(-1); + + long last = first() + visible_rows(); + if (last > items()) last = items(); + for (long n = first(); n < last; n++) update_row(n); + + if (get_front_window() == win()) + invert_row(selected()); +} + +void TSheet::print() +{ + TPrinter& pr = MainApp()->printer(); + TPrintrow row; + bool ok = pr.open(); + + set_cursor(TASK_WIN, CURSOR_WAIT); + int step = visible_rows(); + for (long n = 0L; ok && n < items(); n += step) + { + set_first(n); + build_page(); + + if ((n+step) > items()) step = int(items()-n); + for (int i = 1; ok && i <= step; i++) + { + const char* s; + + TToken_string& t = (TToken_string&)_page[i]; + t.restart(); + + row.reset(); + for (int j = 0, x = 0; (s = t.get()) != NULL; x += _size[j++]+1) + row.put(s, x); + + ok = pr.print(row); + } + } + set_cursor(TASK_WIN, CURSOR_ARROW); + + if (ok) + { + pr.formfeed(); + pr.close(); + } + set_focus(); +} + +/////////////////////////////////////////////////////////// +// TArray_sheet +/////////////////////////////////////////////////////////// + +TArray_sheet::TArray_sheet(short x, short y, short dx, short dy, + const char* caption, const char* head, byte buttons, WINDOW parent) +: TSheet(x, y, dx, dy, caption, head, buttons, 0L, parent) +{} + +void TArray_sheet::page_build(long first, byte num) +{ + for (byte i = 0; i < num; i++) + set_row(data(first+i), i); +} + +long TArray_sheet::add(const TToken_string& s) +{ + const long n = _data.add(s, -1); + set_scroll_max(-1, n); + return n; +} + +long TArray_sheet::insert(const TToken_string& s, long n) +{ + _data.insert(s, (int)n); + set_scroll_max(-1, items()); + return n; +} + + +/////////////////////////////////////////////////////////// +// TCursor_sheet +/////////////////////////////////////////////////////////// + +TCursor_sheet::TCursor_sheet(TCursor* cursor, const char* fields, + const char* title, const char* head, byte buttons) +: TSheet(-1,-1, 0, 0, title,head,buttons,cursor->pos()), + _cursor(cursor), _records(cursor->items()) +{ + TToken_string fldlst(fields); + int campi = 0; + for (const char* t = fldlst.get(); t; t = fldlst.get(), campi++) + if (*t > ' ' && *t != '\"') + { + TFieldref fr(t, 0); + TRecfield* rf = new TRecfield(_cursor->curr(fr.file()), + fr.name(), fr.from(), fr.to() - 1); + _fields.add(rf, campi); + } +} + + +KEY TCursor_sheet::run() +{ + _records = _cursor->items(); + _cursor->freeze(TRUE); + const KEY k = TSheet::run(); + _cursor->freeze(FALSE); + return k; +} + + +void TCursor_sheet::page_build(long first, byte rows) +{ + TToken_string l(256); + + *_cursor = (TRecnotype)first; + for (byte r = 0; r < rows; r++, ++(*_cursor)) + { + l.cut(0); + const int last = _fields.last(); + for (int i = 0; i <= last; i++) + { + TRecfield* rf = (TRecfield*)_fields.objptr(i); + TFixed_string s(rf ? (const char*)*rf : ""); + l.add(s); + } + set_row(l, r); + } +} + +/////////////////////////////////////////////////////////// +// TBrowse_sheet +/////////////////////////////////////////////////////////// + +TBrowse_sheet::TBrowse_sheet(TCursor* cursor, const char* fields, + const char* title, const char* head, byte buttons, + TEdit_field* f, TToken_string* s) +: TCursor_sheet(cursor, fields, title, head, buttons), _field(f) + +{ + xvt_create_control(WC_EDIT, 1, -3, f->size()+1, 1, f->get(), win(), + CTL_FLAG_DISABLED, 0L, 100); + if (s) + { + WINDOW listbox = xvt_create_control(WC_LISTBUTTON, f->size()+3, -3, 18, 3, + "", win(), 0, 0L, 99); + + SLIST lst = slist_new(); + for (const char* item = s->get(0); item; item = s->get()) + { + item = s->get(); + slist_add(lst, (SLIST_ELT)NULL, (char*)item, 0L); + } + win_list_add(listbox, -1, (char*)lst); + slist_dispose(lst); + + TString id(3); id << f->dlg(); + const int sel = s->get_pos(id) >> 1; + win_list_set_sel(listbox, sel, TRUE); + } +} + + +short TBrowse_sheet::reserved_rows() const +{ + return TSheet::reserved_rows() + 1; +} + + +void TBrowse_sheet::repos_buttons() const +{ + TSheet::repos_buttons(); + + RCT wr; get_client_rect(win(), &wr); + for (int id = 99; id <= 100; id++) + { + WINDOW w = get_ctl_window(win(), id); + if (w != NULL_WIN) + { + RCT r; get_client_rect(w, &r); + r.left = CHARX*(id == 99 ? 1 : 21); + r.top = wr.bottom - 4*CHARY + 4; + r.right += r.left; + r.bottom += r.top; + move_window(w, &r); + } + } +} + + +bool TBrowse_sheet::on_key(KEY k) +{ + WINDOW ctl = get_ctl_window(win(), 100); + + const bool alnum = (k >= '0' && k <= '9') || + (k >= 'A' && k <= 'Z') || + (k >= 'a' && k <= 'z') || + k == ' '; + if (alnum || k == K_BACKSPACE || k == K_DEL) + { + const long oldsel = selected(); + const TString old(_field->get()); + + TString val(old.size()+1); val = old; + if (alnum) val << char(k); + else val.rtrim(1); + field().set(val); + + ((TBrowse*)field().browse())->do_input(FALSE); + _cursor->read(); + if (_cursor->file()->bad()) + { + beep(); + field().set(val = old); + *_cursor = oldsel; + } + else + select(_cursor->pos()); + + if (ctl != NULL_WIN) set_title(ctl, (char*)(const char*)field().get()); + return TRUE; + } + else + { + field().reset(); + if (ctl != NULL_WIN) set_title(ctl, ""); + } + + return TSheet::on_key(k); +} + + +void TBrowse_sheet::handler(WINDOW win, EVENT* ep) +{ + if (ep->type == E_CONTROL && ep->v.ctl.id == 99) + { + const int what = win_list_get_sel_index(ep->v.ctl.ci.win); + if (what >= 0) + stop_run(K_CTRL + what); + else + set_front_window(win); + return; + } + TCursor_sheet::handler(win, ep); +} + + +KEY TBrowse_sheet::run() +{ + const bool spork = field().dirty(); // Store field status + const TString old(field().get()); + + const KEY key = TCursor_sheet::run(); + + if (key == K_ESC || key == K_F9 || key == K_INS) + { + field().set(old); // Restore field status + field().set_dirty(spork); + } + + return key; +} diff --git a/include/toolbar.h b/include/toolbar.h index df81c6b44..6853429ab 100755 --- a/include/toolbar.h +++ b/include/toolbar.h @@ -1,31 +1,36 @@ - -BUTTON DLG_SAVEREC 8 2 -BEGIN - PROMPT -16 -1 "" -END - -BUTTON DLG_NEWREC 8 2 -BEGIN - PROMPT -26 -1 "Nuovo" -END - -BUTTON DLG_DELREC 8 2 -BEGIN - PROMPT -36 -1 "Elimina" -END - -BUTTON DLG_FINDREC 8 2 -BEGIN - PROMPT -46 -1 "Ricerca" -END - -BUTTON DLG_CANCEL 8 2 -BEGIN - PROMPT -56 -1 "" -END - -BUTTON DLG_QUIT 8 2 -BEGIN - PROMPT -66 -1 "" -END - +BUTTON DLG_SAVEREC 8 2 +BEGIN +PROMPT -16 -1 "~Registra" +MESSAGE EXIT,K_SAVE +END + +BUTTON DLG_NEWREC 8 2 +BEGIN +PROMPT -26 -1 "~Nuovo" +MESSAGE EXIT,K_INS +END + +BUTTON DLG_DELREC 8 2 +BEGIN +PROMPT -36 -1 "~Elimina" +MESSAGE EXIT,K_DEL +END + +BUTTON DLG_FINDREC 8 2 +BEGIN +PROMPT -46 -1 "Ricerca" +MESSAGE EXIT,K_F9 +END + +BUTTON DLG_CANCEL 8 2 +BEGIN +PROMPT -56 -1 "" +MESSAGE EXIT,K_ESC +END + +BUTTON DLG_QUIT 8 2 +BEGIN +PROMPT -66 -1 "" +MESSAGE EXIT,K_QUIT +END + diff --git a/include/validate.cpp b/include/validate.cpp index 0137a581f..78f13c02e 100755 --- a/include/validate.cpp +++ b/include/validate.cpp @@ -1,560 +1,560 @@ -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -typedef bool (*VAL_FUNC)(TEdit_field&, KEY k); -HIDDEN const TArray* _parms; - -HIDDEN int get_val_param_num() { return _parms->items();} -HIDDEN const char* get_val_param(int i) - { return i < _parms->items() ? (const char*)((const TString&) (*_parms)[i]):"" ;} - - -HIDDEN bool _expr_val(TEdit_field& f, KEY) -{ - TTypeexp type = atoi(get_val_param(0)) == 0 ? _numexpr :_strexpr; - TExpression e(get_val_param(1), type); - - for (int i = 0 ; i < e.numvar(); i++) - { - const char* s = e.varname(i); - if (s[0] != '#') - { - TString err(64); err << "Cannot load variable " << s << " in " << e; - return f.error_box((const char*)err); - } - s++; - const int fldid = atoi(s); - if (type == _numexpr) - { - const real r(fldid == 0 ? f.get() : f.mask().get(fldid)); - e.setvar(i, r); - } - else - { - const char* v = fldid == 0 ? f.get() : f.mask().get(fldid); - e.setvar(i, v); - } - } - return bool(e); -} - - -HIDDEN bool _emptycopy_val(TEdit_field& f, KEY) -{ - if (f.get().empty()) - { - const short id = atoi(get_val_param(0)); - const TFixed_string val(f.mask().get(id)); - if (val.not_empty()) - { - f.set(val); - f.on_hit(); - } - } - return TRUE; -} - - -bool pi_check(const char * st, const char * paiva) -{ - int tot = 0, y; - TFixed_string stato (st); - TFixed_string pi (paiva); - - if ((stato.not_empty()) && (stato != "IT")) return TRUE; - if (pi.empty()) return TRUE; - if (pi.len() != 11) - return FALSE; - - for (int i = 0; i <= 9; i++) - { - if ((i + 1) & 0x0001) tot += (pi[i] - '0'); - else - { - y = (pi[i] - '0') * 2; - if (y >= 10) - { - tot += (y / 10); - y = y % 10; - } - tot += y; - } - } - y = 10 - (tot % 10); - if (y == 10) y = 0; - bool ok = (pi[10] == (y + '0')); - - return ok; -} - - -// Controlla la partita iva se e' non vuota ed italiana -HIDDEN bool _pi_val(TEdit_field& f, KEY) -{ - TString stato(f.mask().get(atoi(get_val_param(0)))), pi(f.get()); - - if (stato.not_empty() && stato != "IT") return TRUE; - if (pi.empty()) return TRUE; - if (pi.len() != 11) - { - f.error_box("Lunghezza partita IVA diversa da 11"); - return FALSE; - } - - bool ok = pi_check (stato, pi); - if (!ok) - { - if(f.dirty()) - { - ok = f.yesno_box("Partita IVA errata, la accetto ugualmente?"); - if (ok) f.set_dirty(FALSE); - } - else ok = TRUE; // Era gia' errata e la ho accettata - } - return ok; -} - - -HIDDEN bool __cf_check (const char * codcf) -{ - const TFixed_string cf (codcf); - const TFixed_string tab("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); - - int tot = 0, y; - - byte val[36][2]; - - val[0][0] = 0; val[0][1] = 1; - val[1][0] = 1; val[1][1] = 0; - val[2][0] = 2; val[2][1] = 5; - val[3][0] = 3; val[3][1] = 7; - val[4][0] = 4; val[4][1] = 9; - val[5][0] = 5; val[5][1] = 13; - val[6][0] = 6; val[6][1] = 15; - val[7][0] = 7; val[7][1] = 17; - val[8][0] = 8; val[8][1] = 19; - val[9][0] = 9; val[9][1] = 21; - val[10][0] = 10; val[10][1] = 2; - val[11][0] = 11; val[11][1] = 4; - val[12][0] = 12; val[12][1] = 18; - val[13][0] = 13; val[13][1] = 20; - val[14][0] = 14; val[14][1] = 11; - val[15][0] = 15; val[15][1] = 3; - val[16][0] = 16; val[16][1] = 6; - val[17][0] = 17; val[17][1] = 8; - val[18][0] = 18; val[18][1] = 12; - val[19][0] = 19; val[19][1] = 14; - val[20][0] = 20; val[20][1] = 16; - val[21][0] = 21; val[21][1] = 10; - val[22][0] = 22; val[22][1] = 22; - val[23][0] = 23; val[23][1] = 25; - val[24][0] = 24; val[24][1] = 24; - val[25][0] = 25; val[25][1] = 23; - val[26][0] = 0; val[26][1] = 1; - val[27][0] = 1; val[27][1] = 0; - val[28][0] = 2; val[28][1] = 5; - val[29][0] = 3; val[29][1] = 7; - val[30][0] = 4; val[30][1] = 9; - val[31][0] = 5; val[31][1] = 13; - val[32][0] = 6; val[32][1] = 15; - val[33][0] = 7; val[33][1] = 17; - val[34][0] = 8; val[34][1] = 19; - val[35][0] = 9; val[35][1] = 21; - - for (int i = 0; i <= 14; i++) - { - y = tab.find(cf[i]); - if (y >= 0) tot += val[y][(i + 1) & 0x1]; - } - const bool ok = (cf[15] == (tot % 26) + 'A'); - - return ok; -} - - -bool cf_check (const char * stato, const char * codcf) -{ - TFixed_string cf (codcf); - if (cf.empty()) - return TRUE; - const bool ok = (cf.len() == 11) ? pi_check(stato, cf) : __cf_check(cf); - return ok; -} - - -HIDDEN bool _cf_val(TEdit_field& f, KEY key) -{ - if (f.mask().query_mode()) return TRUE; - - const TFixed_string cf(f.get()); - if (cf.empty()) return TRUE; - if (cf.len() == 11) - return _pi_val(f, key); - - bool ok = __cf_check(cf); - if (!ok) - { - if(f.dirty()) - { - ok = f.yesno_box("Codice fiscale errato: lo accetto ugualmente?"); - if (ok) f.set_dirty(FALSE); - } - else ok = TRUE; // Era gia' errato al caricamento quindi lo accetto - } - return ok; -} - - -HIDDEN bool _xt_pi_val(TEdit_field& f, KEY key) - -{ - TMask& m = f.mask(); - if (m.query_mode()) return TRUE; - - TString value(f.get()); - if (value.empty()) return f.error_box("Partita IVA obbligatoria"); - - const TString stato(m.get(atoi(get_val_param(0)))); - if (stato.not_empty() && stato != "IT") return TRUE; - - if (!_pi_val(f, key)) return FALSE; - - TLocalisamfile c(LF_COMUNI); - - const int pi = atoi(value.mid(7,3)); - - for (int i = 1 ; i < 3; i++) - { - const int comune = atoi(get_val_param(i)); - if (comune) - { - const TString com(m.get(comune)); // Comune residenza fiscale e residenza - if (com.not_empty()) - { - c.zero(); - c.put("COM", com); - if (c.read() == NOERR) - { - const int s1 = c.get_int("UFFIVA1"); - const int s2 = c.get_int("UFFIVA2"); - const int s3 = c.get_int("UFFIVA3"); - if (pi != s1 && pi != s2 && pi != s3) - { - const char* ui = format("%03d", s1); - if (f.yesno_box("Ufficio IVA della partita IVA non congruente: correggere in %s?", ui)) - { - value.overwrite(ui, 7); - f.set(value); - } - } - break; - } - } - } - } - return TRUE; -} - - -HIDDEN bool _xtz_pi_val(TEdit_field& f, KEY key) - -{ - if (f.mask().query_mode()) return TRUE; - TString pi(f.get()); - if (pi.empty()) return TRUE; - return _xt_pi_val(f, key); -} - - -HIDDEN bool _xt_cf_val(TEdit_field& f, KEY key) - -{ - if (f.mask().query_mode()) return TRUE; - - const TString cf(f.get()); - if (cf.empty()) return f.error_box("Codice fiscale obbligatorio"); - - if (!_cf_val(f, key)) return FALSE; - - if (cf.len() == 11) - { - if (!_xt_pi_val(f, key)) return FALSE; - TString stato(f.mask().get(atoi(get_val_param(0)))); - if ((stato.not_empty()) && (stato != "IT")) return TRUE; - } - - bool passed = __cf_check(cf); - if (!passed) return TRUE; - - TMask& m = f.mask(); - - TMask_field& fld_sex = m.field(atoi(get_val_param(1))); - TMask_field& fld_dat = m.field(atoi(get_val_param(2))); - TMask_field& fld_com = m.field(atoi(get_val_param(3))); - - char sesso = fld_sex.get()[0]; - TString data(fld_dat.get()); - TString com(fld_com.get()); - - TString wm("LMNPQRSTUV"); - int p; - if ((p = wm.find(cf[6])) != -1) cf[6] = '0' + p; - if ((p = wm.find(cf[7])) != -1) cf[7] = '0' + p; - if ((p = wm.find(cf[9])) != -1) cf[9] = '0' + p; - if ((p = wm.find(cf[10])) != -1) cf[10] = '0' + p; - if ((p = wm.find(cf[12])) != -1) cf[12] = '0' + p; - if ((p = wm.find(cf[13])) != -1) cf[13] = '0' + p; - if ((p = wm.find(cf[14])) != -1) cf[14] = '0' + p; - int gn = atoi(cf.mid(9,2)); - - if ((sesso == 'F' && gn <= 40) || (sesso == 'M' && gn >= 40)) - { - passed = fld_sex.yesno_box("Sesso non congruente al codice fiscale: correzione automatica?"); - if (passed) fld_sex.set(sesso == 'M' ? "F" : "M"); - else return TRUE; - } - - if (gn > 40) gn -= 40; - - // Controllo data di nascita - wm = "ABCDEHLMPRST"; - if (data.not_empty()) - { - const TDate d(data); - int err = 0; - if ((d.year() % 100) != atoi(cf.mid(6, 2))) - err = 1; - if (wm[d.month() - 1] != cf[8]) - err = 2; - if (d.day() != gn) - err = 3; - if (err != 0) - { - const char* const what = err==1 ? "Anno" : (err==2 ? "Mese" : "Giorno"); - passed = fld_dat.yesno_box("%s di nascita non congruente al codice fiscale: correzione automatica?", what); - if (passed) data = ""; - else return TRUE; - } - } - - if (data.empty()) - { - const int mn = wm.find(cf[8]) + 1; - if (mn > 0) - { - const TDate d(gn, mn, 1900 + atoi(cf.mid(6, 2))); - fld_dat.set(d.string()); - } - } - - // Controllo del comune di nascita - const char* const codcom = cf.mid(11, 4); - if (com.not_empty() && com != codcom) - { - passed = fld_com.yesno_box("Comune non congruente al codice fiscale: correzione automatica?"); - if (passed) com = ""; - else return TRUE; - } - if (com.empty()) - { - fld_com.set(codcom); - fld_com.on_key(K_TAB); - } - - return TRUE; -} - - -HIDDEN bool _xtz_cf_val(TEdit_field& f, KEY key) - -{ - if (f.mask().query_mode()) return TRUE; - const char* cf = f.get(); - return (*cf == '\0') ? TRUE : _xt_cf_val(f, key); -} - - -HIDDEN bool _notempty_val(TEdit_field& f, KEY) - -{ - return f.mask().query_mode() || f.get().not_empty(); -} - - -HIDDEN bool _date_cmp(TEdit_field& f, KEY) - -{ - TFixed_string s(f.get()); - if (s.empty()) return TRUE; - - TDate d0(s), d1(f.mask().get(atoi(get_val_param(1)))); - TFixed_string op(get_val_param(0)); - - if (op == "==") return d0 == d1; - if (op == "!=") return d0 != d1; - if (op == ">") return d0 > d1; - if (op == "<") return d0 < d1; - if (op == ">=") return d0 >= d1; - if (op == "<=") return d0 <= d1; - -#ifdef DBG - f.error_box("Bad date operator '%s' in field %d", (const char*) op, f.dlg()); -#endif - - return FALSE; -} - - -HIDDEN bool _fixlen_val(TEdit_field& f, KEY) -{ - const TFixed_string s(f.get()); - - if (s.empty()) return TRUE; - - const int length = atoi(get_val_param(0)); - const bool ok = s.len() == length; - if (!ok) f.error_box("Lunghezza errata: deve essere %d", length); - return ok; -} - - -HIDDEN bool _mtcheck_val(TEdit_field& f, KEY) -{ - const int month = atoi(f.get()); - if (month < 1 || month > 13) return FALSE; - - TLocalisamfile d(LF_NDITTE); - d.zero(); - d.put(NDT_CODDITTA, MainApp()->get_firm()); - d.read(); - if (d.bad()) return TRUE; - if (d.get_char(NDT_FREQVIVA) == 'M') return TRUE; - return month == 13 || (month % 3) == 0; -} - - -HIDDEN bool _reqif_val(TEdit_field& f, KEY) -{ - if (f.get().not_empty()) return TRUE; - const int nparms = get_val_param_num(); - for (int i = 0 ; i < nparms; i++) - { - const char* s = get_val_param(i); - if (*s == '\0') break; - if (f.mask().get(atoi(s)).not_empty()) return FALSE; - } - return TRUE; -} - - -HIDDEN bool _autoexit_val(TEdit_field& f, KEY key) -{ - const int nparms = get_val_param_num(); - bool one_not_empty = FALSE; - for (int i = nparms; i-- > 0;) - { - const short id = f.atodlg(get_val_param(i)); - const TMask_field& c = f.mask().field(id); - const bool empty = c.get().empty(); - if (empty) - { - if (c.check_type() != CHECK_NONE || one_not_empty) - return key == K_TAB; - } - else - one_not_empty = TRUE; - } - - bool ok = TRUE; - if (key == K_TAB) - f.mask().send_key(K_SHIFT_ENTER, 0); - else - ok = one_not_empty; - - return ok; -} - - -HIDDEN bool _numcalc_val(TEdit_field& f, KEY k) -{ - if (k != K_TAB) return TRUE; - TExpression e(get_val_param(0), _numexpr); - - for (int i = 0 ; i < e.numvar(); i++) - { - const char* s = e.varname(i); - if (s[0] != '#') - { - TString err(64); err << "Cannot load variable " << s << " in " << e; - return f.error_box((const char*)err); - } - s++; - const int fldid = atoi(s); - e.setvar(i, fldid == 0 ? f.get() : f.mask().get(fldid)); - } - TFixed_string s((const char*) e); - f.set(s); - return TRUE; -} - - -HIDDEN bool _strcalc_val(TEdit_field& f, KEY k) -{ - if (k != K_TAB) return TRUE; - TExpression e(get_val_param(0), _strexpr); - - for (int i = 0 ; i < e.numvar(); i++) - { - const char* s = e.varname(i); - if (s[0] != '#') - { - TString err(64); err << "Cannot load variable " << s << " in " << e; - return f.error_box((const char*)err); - } - s++; - const int fldid = atoi(s); - e.setvar(i, fldid == 0 ? f.get() : f.mask().get(fldid)); - } - TFixed_string s((const char*) e); - f.set(s); - return TRUE; -} - - -#define MAX_FUNC 16 - -HIDDEN VAL_FUNC _global_val_func[MAX_FUNC] = - { - _expr_val, - _emptycopy_val, - _pi_val, - _cf_val, - _notempty_val, - _date_cmp, - _xt_pi_val, - _xt_cf_val, - _xtz_pi_val, - _xtz_cf_val, - _fixlen_val, - _mtcheck_val, - _reqif_val, - _autoexit_val, - _numcalc_val, - _strcalc_val - }; - -bool validate(int fn, TEdit_field& f, KEY k, const TArray& parms) -{ - _parms = &parms; - return (fn >= 0 && fn < MAX_FUNC) ? _global_val_func[fn](f, k) : TRUE; -} - +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +typedef bool (*VAL_FUNC)(TEdit_field&, KEY k); +HIDDEN const TArray* _parms; + +HIDDEN int get_val_param_num() { return _parms->items();} +HIDDEN const char* get_val_param(int i) +{ return i < _parms->items() ? (const char*)((const TString&) (*_parms)[i]):"" ;} + + +HIDDEN bool _expr_val(TEdit_field& f, KEY) +{ + TTypeexp type = atoi(get_val_param(0)) == 0 ? _numexpr :_strexpr; + TExpression e(get_val_param(1), type); + + for (int i = 0 ; i < e.numvar(); i++) + { + const char* s = e.varname(i); + if (s[0] != '#') + { + TString err(64); err << "Cannot load variable " << s << " in " << e; + return f.error_box((const char*)err); + } + s++; + const int fldid = atoi(s); + if (type == _numexpr) + { + const real r(fldid == 0 ? f.get() : f.mask().get(fldid)); + e.setvar(i, r); + } + else + { + const char* v = fldid == 0 ? f.get() : f.mask().get(fldid); + e.setvar(i, v); + } + } + return bool(e); +} + + +HIDDEN bool _emptycopy_val(TEdit_field& f, KEY) +{ + if (f.get().empty()) + { + const short id = atoi(get_val_param(0)); + const TFixed_string val(f.mask().get(id)); + if (val.not_empty()) + { + f.set(val); + f.on_hit(); + } + } + return TRUE; +} + + +bool pi_check(const char * st, const char * paiva) +{ + int tot = 0, y; + TFixed_string stato (st); + TFixed_string pi (paiva); + + if ((stato.not_empty()) && (stato != "IT")) return TRUE; + if (pi.empty()) return TRUE; + if (pi.len() != 11) + return FALSE; + + for (int i = 0; i <= 9; i++) + { + if ((i + 1) & 0x0001) tot += (pi[i] - '0'); + else + { + y = (pi[i] - '0') * 2; + if (y >= 10) + { + tot += (y / 10); + y = y % 10; + } + tot += y; + } + } + y = 10 - (tot % 10); + if (y == 10) y = 0; + bool ok = (pi[10] == (y + '0')); + + return ok; +} + + +// Controlla la partita iva se e' non vuota ed italiana +HIDDEN bool _pi_val(TEdit_field& f, KEY) +{ + TString stato(f.mask().get(atoi(get_val_param(0)))), pi(f.get()); + + if (stato.not_empty() && stato != "IT") return TRUE; + if (pi.empty()) return TRUE; + if (pi.len() != 11) + { + f.error_box("Lunghezza partita IVA diversa da 11"); + return FALSE; + } + + bool ok = pi_check (stato, pi); + if (!ok) + { + if(f.dirty()) + { + ok = f.yesno_box("Partita IVA errata, la accetto ugualmente?"); + if (ok) f.set_dirty(FALSE); + } + else ok = TRUE; // Era gia' errata e la ho accettata + } + return ok; +} + + +HIDDEN bool __cf_check (const char * codcf) +{ + const TFixed_string cf (codcf); + const TFixed_string tab("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); + + int tot = 0, y; + + byte val[36][2]; + + val[0][0] = 0; val[0][1] = 1; + val[1][0] = 1; val[1][1] = 0; + val[2][0] = 2; val[2][1] = 5; + val[3][0] = 3; val[3][1] = 7; + val[4][0] = 4; val[4][1] = 9; + val[5][0] = 5; val[5][1] = 13; + val[6][0] = 6; val[6][1] = 15; + val[7][0] = 7; val[7][1] = 17; + val[8][0] = 8; val[8][1] = 19; + val[9][0] = 9; val[9][1] = 21; + val[10][0] = 10; val[10][1] = 2; + val[11][0] = 11; val[11][1] = 4; + val[12][0] = 12; val[12][1] = 18; + val[13][0] = 13; val[13][1] = 20; + val[14][0] = 14; val[14][1] = 11; + val[15][0] = 15; val[15][1] = 3; + val[16][0] = 16; val[16][1] = 6; + val[17][0] = 17; val[17][1] = 8; + val[18][0] = 18; val[18][1] = 12; + val[19][0] = 19; val[19][1] = 14; + val[20][0] = 20; val[20][1] = 16; + val[21][0] = 21; val[21][1] = 10; + val[22][0] = 22; val[22][1] = 22; + val[23][0] = 23; val[23][1] = 25; + val[24][0] = 24; val[24][1] = 24; + val[25][0] = 25; val[25][1] = 23; + val[26][0] = 0; val[26][1] = 1; + val[27][0] = 1; val[27][1] = 0; + val[28][0] = 2; val[28][1] = 5; + val[29][0] = 3; val[29][1] = 7; + val[30][0] = 4; val[30][1] = 9; + val[31][0] = 5; val[31][1] = 13; + val[32][0] = 6; val[32][1] = 15; + val[33][0] = 7; val[33][1] = 17; + val[34][0] = 8; val[34][1] = 19; + val[35][0] = 9; val[35][1] = 21; + + for (int i = 0; i <= 14; i++) + { + y = tab.find(cf[i]); + if (y >= 0) tot += val[y][(i + 1) & 0x1]; + } + const bool ok = (cf[15] == (tot % 26) + 'A'); + + return ok; +} + + +bool cf_check (const char * stato, const char * codcf) +{ + TFixed_string cf (codcf); + if (cf.empty()) + return TRUE; + const bool ok = (cf.len() == 11) ? pi_check(stato, cf) : __cf_check(cf); + return ok; +} + + +HIDDEN bool _cf_val(TEdit_field& f, KEY key) +{ + if (f.mask().query_mode()) return TRUE; + + const TFixed_string cf(f.get()); + if (cf.empty()) return TRUE; + if (cf.len() == 11) + return _pi_val(f, key); + + bool ok = __cf_check(cf); + if (!ok) + { + if(f.dirty()) + { + ok = f.yesno_box("Codice fiscale errato: lo accetto ugualmente?"); + if (ok) f.set_dirty(FALSE); + } + else ok = TRUE; // Era gia' errato al caricamento quindi lo accetto + } + return ok; +} + + +HIDDEN bool _xt_pi_val(TEdit_field& f, KEY key) + +{ + TMask& m = f.mask(); + if (m.query_mode()) return TRUE; + + TString value(f.get()); + if (value.empty()) return f.error_box("Partita IVA obbligatoria"); + + const TString stato(m.get(atoi(get_val_param(0)))); + if (stato.not_empty() && stato != "IT") return TRUE; + + if (!_pi_val(f, key)) return FALSE; + + TLocalisamfile c(LF_COMUNI); + + const int pi = atoi(value.mid(7,3)); + + for (int i = 1 ; i < 3; i++) + { + const int comune = atoi(get_val_param(i)); + if (comune) + { + const TString com(m.get(comune)); // Comune residenza fiscale e residenza + if (com.not_empty()) + { + c.zero(); + c.put("COM", com); + if (c.read() == NOERR) + { + const int s1 = c.get_int("UFFIVA1"); + const int s2 = c.get_int("UFFIVA2"); + const int s3 = c.get_int("UFFIVA3"); + if (pi != s1 && pi != s2 && pi != s3) + { + const char* ui = format("%03d", s1); + if (f.yesno_box("Ufficio IVA della partita IVA non congruente: correggere in %s?", ui)) + { + value.overwrite(ui, 7); + f.set(value); + } + } + break; + } + } + } + } + return TRUE; +} + + +HIDDEN bool _xtz_pi_val(TEdit_field& f, KEY key) + +{ + if (f.mask().query_mode()) return TRUE; + TString pi(f.get()); + if (pi.empty()) return TRUE; + return _xt_pi_val(f, key); +} + + +HIDDEN bool _xt_cf_val(TEdit_field& f, KEY key) + +{ + if (f.mask().query_mode()) return TRUE; + + const TString cf(f.get()); + if (cf.empty()) return f.error_box("Codice fiscale obbligatorio"); + + if (!_cf_val(f, key)) return FALSE; + + if (cf.len() == 11) + { + if (!_xt_pi_val(f, key)) return FALSE; + TString stato(f.mask().get(atoi(get_val_param(0)))); + if ((stato.not_empty()) && (stato != "IT")) return TRUE; + } + + bool passed = __cf_check(cf); + if (!passed) return TRUE; + + TMask& m = f.mask(); + + TMask_field& fld_sex = m.field(atoi(get_val_param(1))); + TMask_field& fld_dat = m.field(atoi(get_val_param(2))); + TMask_field& fld_com = m.field(atoi(get_val_param(3))); + + char sesso = fld_sex.get()[0]; + TString data(fld_dat.get()); + TString com(fld_com.get()); + + TString wm("LMNPQRSTUV"); + int p; + if ((p = wm.find(cf[6])) != -1) cf[6] = '0' + p; + if ((p = wm.find(cf[7])) != -1) cf[7] = '0' + p; + if ((p = wm.find(cf[9])) != -1) cf[9] = '0' + p; + if ((p = wm.find(cf[10])) != -1) cf[10] = '0' + p; + if ((p = wm.find(cf[12])) != -1) cf[12] = '0' + p; + if ((p = wm.find(cf[13])) != -1) cf[13] = '0' + p; + if ((p = wm.find(cf[14])) != -1) cf[14] = '0' + p; + int gn = atoi(cf.mid(9,2)); + + if ((sesso == 'F' && gn <= 40) || (sesso == 'M' && gn >= 40)) + { + passed = fld_sex.yesno_box("Sesso non congruente al codice fiscale: correzione automatica?"); + if (passed) fld_sex.set(sesso == 'M' ? "F" : "M"); + else return TRUE; + } + + if (gn > 40) gn -= 40; + + // Controllo data di nascita + wm = "ABCDEHLMPRST"; + if (data.not_empty()) + { + const TDate d(data); + int err = 0; + if ((d.year() % 100) != atoi(cf.mid(6, 2))) + err = 1; + if (wm[d.month() - 1] != cf[8]) + err = 2; + if (d.day() != gn) + err = 3; + if (err != 0) + { + const char* const what = err==1 ? "Anno" : (err==2 ? "Mese" : "Giorno"); + passed = fld_dat.yesno_box("%s di nascita non congruente al codice fiscale: correzione automatica?", what); + if (passed) data = ""; + else return TRUE; + } + } + + if (data.empty()) + { + const int mn = wm.find(cf[8]) + 1; + if (mn > 0) + { + const TDate d(gn, mn, 1900 + atoi(cf.mid(6, 2))); + fld_dat.set(d.string()); + } + } + + // Controllo del comune di nascita + const char* const codcom = cf.mid(11, 4); + if (com.not_empty() && com != codcom) + { + passed = fld_com.yesno_box("Comune non congruente al codice fiscale: correzione automatica?"); + if (passed) com = ""; + else return TRUE; + } + if (com.empty()) + { + fld_com.set(codcom); + fld_com.on_key(K_TAB); + } + + return TRUE; +} + + +HIDDEN bool _xtz_cf_val(TEdit_field& f, KEY key) + +{ + if (f.mask().query_mode()) return TRUE; + const char* cf = f.get(); + return (*cf == '\0') ? TRUE : _xt_cf_val(f, key); +} + + +HIDDEN bool _notempty_val(TEdit_field& f, KEY) + +{ + return f.mask().query_mode() || f.get().not_empty(); +} + + +HIDDEN bool _date_cmp(TEdit_field& f, KEY) + +{ + TFixed_string s(f.get()); + if (s.empty()) return TRUE; + + TDate d0(s), d1(f.mask().get(atoi(get_val_param(1)))); + TFixed_string op(get_val_param(0)); + + if (op == "==") return d0 == d1; + if (op == "!=") return d0 != d1; + if (op == ">") return d0 > d1; + if (op == "<") return d0 < d1; + if (op == ">=") return d0 >= d1; + if (op == "<=") return d0 <= d1; + +#ifdef DBG + f.error_box("Bad date operator '%s' in field %d", (const char*) op, f.dlg()); +#endif + + return FALSE; +} + + +HIDDEN bool _fixlen_val(TEdit_field& f, KEY) +{ + const TFixed_string s(f.get()); + + if (s.empty()) return TRUE; + + const int length = atoi(get_val_param(0)); + const bool ok = s.len() == length; + if (!ok) f.error_box("Lunghezza errata: deve essere %d", length); + return ok; +} + + +HIDDEN bool _mtcheck_val(TEdit_field& f, KEY) +{ + const int month = atoi(f.get()); + if (month < 1 || month > 13) return FALSE; + + TLocalisamfile d(LF_NDITTE); + d.zero(); + d.put(NDT_CODDITTA, MainApp()->get_firm()); + d.read(); + if (d.bad()) return TRUE; + if (d.get_char(NDT_FREQVIVA) == 'M') return TRUE; + return month == 13 || (month % 3) == 0; +} + + +HIDDEN bool _reqif_val(TEdit_field& f, KEY) +{ + if (f.get().not_empty()) return TRUE; + const int nparms = get_val_param_num(); + for (int i = 0 ; i < nparms; i++) + { + const char* s = get_val_param(i); + if (*s == '\0') break; + if (f.mask().get(atoi(s)).not_empty()) return FALSE; + } + return TRUE; +} + + +HIDDEN bool _autoexit_val(TEdit_field& f, KEY key) +{ + const int nparms = get_val_param_num(); + bool one_not_empty = FALSE; + for (int i = nparms; i-- > 0;) + { + const short id = f.atodlg(get_val_param(i)); + const TMask_field& c = f.mask().field(id); + const bool empty = c.get().empty(); + if (empty) + { + if (c.check_type() != CHECK_NONE || one_not_empty) + return key == K_TAB; + } + else + one_not_empty = TRUE; + } + + bool ok = TRUE; + if (key == K_TAB) + f.mask().send_key(K_AUTO_ENTER, 0); + else + ok = one_not_empty; + + return ok; +} + + +HIDDEN bool _numcalc_val(TEdit_field& f, KEY k) +{ + if (k != K_TAB) return TRUE; + TExpression e(get_val_param(0), _numexpr); + + for (int i = 0 ; i < e.numvar(); i++) + { + const char* s = e.varname(i); + if (s[0] != '#') + { + TString err(64); err << "Cannot load variable " << s << " in " << e; + return f.error_box((const char*)err); + } + s++; + const int fldid = atoi(s); + e.setvar(i, fldid == 0 ? f.get() : f.mask().get(fldid)); + } + TFixed_string s((const char*) e); + f.set(s); + return TRUE; +} + + +HIDDEN bool _strcalc_val(TEdit_field& f, KEY k) +{ + if (k != K_TAB) return TRUE; + TExpression e(get_val_param(0), _strexpr); + + for (int i = 0 ; i < e.numvar(); i++) + { + const char* s = e.varname(i); + if (s[0] != '#') + { + TString err(64); err << "Cannot load variable " << s << " in " << e; + return f.error_box((const char*)err); + } + s++; + const int fldid = atoi(s); + e.setvar(i, fldid == 0 ? f.get() : f.mask().get(fldid)); + } + TFixed_string s((const char*) e); + f.set(s); + return TRUE; +} + + +#define MAX_FUNC 16 + +HIDDEN VAL_FUNC _global_val_func[MAX_FUNC] = +{ + _expr_val, + _emptycopy_val, + _pi_val, + _cf_val, + _notempty_val, + _date_cmp, + _xt_pi_val, + _xt_cf_val, + _xtz_pi_val, + _xtz_cf_val, + _fixlen_val, + _mtcheck_val, + _reqif_val, + _autoexit_val, + _numcalc_val, + _strcalc_val + }; + +bool validate(int fn, TEdit_field& f, KEY k, const TArray& parms) +{ + _parms = &parms; + return (fn >= 0 && fn < MAX_FUNC) ? _global_val_func[fn](f, k) : TRUE; +} + diff --git a/include/viswin.cpp b/include/viswin.cpp index a725936d7..30e6102f0 100755 --- a/include/viswin.cpp +++ b/include/viswin.cpp @@ -62,30 +62,30 @@ void TViswin :: display_link (long y, long x1, long x2, const char *d) { if (!_link_displayed) - { - paint_link (y, x1, x2); - _link_displayed = TRUE; + { + paint_link (y, x1, x2); + _link_displayed = TRUE; #if XVT_OS == XVT_OS_WIN - xvt_statbar_set (d); - xvt_statbar_refresh (); + xvt_statbar_set (d); + xvt_statbar_refresh (); #endif - xvt_enable_control (_link_button, TRUE); - } + xvt_enable_control (_link_button, TRUE); + } } void TViswin :: erase_link (long y, long x1, long x2) { if (_link_displayed) - { - paint_link (y, x1, x2); - _link_displayed = FALSE; + { + paint_link (y, x1, x2); + _link_displayed = FALSE; #if XVT_OS == XVT_OS_WIN - xvt_statbar_set (""); - xvt_statbar_refresh (); + xvt_statbar_set (""); + xvt_statbar_refresh (); #endif - xvt_enable_control (_link_button, FALSE); - } + xvt_enable_control (_link_button, FALSE); + } } void TViswin :: @@ -117,107 +117,107 @@ check_link (TPoint * p) if (p == NULL) // erase and go + { + if (old_id != -1) { - if (old_id != -1) - { - erase_link (y, x1, x2); - old_id = _linkID = plinkID = -1; - py = px1 = px2 = x1 = y = x2 = 0l; - } - return FALSE; + erase_link (y, x1, x2); + old_id = _linkID = plinkID = -1; + py = px1 = px2 = x1 = y = x2 = 0l; } + return FALSE; + } // poi se e' il caso lo si risistema if (p == &_point) plinkID = -1; for (int i = 0; i < _hotspots->items (); i++) + { + TToken_string & t = (TToken_string &) (*_hotspots)[i]; + t.restart (); + long ty = t.get_long (); + long tx1 = t.get_long (); + long tx2 = t.get_long (); + if (p->y == ty && p->x < tx2 && p->x >= tx1) { - TToken_string & t = (TToken_string &) (*_hotspots)[i]; - t.restart (); - long ty = t.get_long (); - long tx1 = t.get_long (); - long tx2 = t.get_long (); - if (p->y == ty && p->x < tx2 && p->x >= tx1) - { - // ci siamo - int id = (int) t.get_long (4); + // ci siamo + int id = (int) t.get_long (4); - if (ty != y || tx1 != x1 || tx2 != x2) - { - if (old_id != -1) - erase_link (y, x1, x2); - TToken_string & ttt = (TToken_string &) (*_links)[id]; - ttt.restart (); - strcpy (descr, ttt.get ()); - strcat (descr, t.get (3)); - strcpy (_linktxt, t.get (3)); - if (_multiple) - { - // get all parts of the same color - const char *cp; - _txt.read_line (y); - _multiple_link = ""; + if (ty != y || tx1 != x1 || tx2 != x2) + { + if (old_id != -1) + erase_link (y, x1, x2); + TToken_string & ttt = (TToken_string &) (*_links)[id]; + ttt.restart (); + strcpy (descr, ttt.get ()); + strcat (descr, t.get (3)); + strcpy (_linktxt, t.get (3)); + if (_multiple) + { + // get all parts of the same color + const char *cp; + _txt.read_line (y); + _multiple_link = ""; - while (cp = _txt.piece ()) - { - if (_txt.get_foreground () == *(ttt.get (1)) && - _txt.get_background () == *(ttt.get (2))) - _multiple_link.add (cp); - } - } - old_id = _linkID = id; - y = ty; - x1 = tx1; - x2 = tx2; - display_link (y, x1, x2, descr); - } - if (p == &_point) - { - strcpy (pdescr, descr); - plinkID = id; - px1 = x1; - px2 = x2; - py = y; - } - return TRUE; - } - } - // non sono su un bottone: puo' esserci il point - if (old_id != -1 && plinkID == -1) - { - old_id = _linkID = -1; - erase_link (y, x1, x2); - x1 = x2 = y = 0l; - } - // se point e' su un bottone, evidenzia quello - else if (plinkID != -1 && (x1 != px1 || x2 != px2 || y != py)) - { - // erase old one - erase_link (y, x1, x2); - old_id = _linkID = plinkID; - x1 = px1; - x2 = px2; - y = py; - strcpy (descr, pdescr); - display_link (y, x1, x2, descr); + while (cp = _txt.piece ()) + { + if (_txt.get_foreground () == *(ttt.get (1)) && + _txt.get_background () == *(ttt.get (2))) + _multiple_link.add (cp); + } + } + old_id = _linkID = id; + y = ty; + x1 = tx1; + x2 = tx2; + display_link (y, x1, x2, descr); + } + if (p == &_point) + { + strcpy (pdescr, descr); + plinkID = id; + px1 = x1; + px2 = x2; + py = y; + } return TRUE; } + } + // non sono su un bottone: puo' esserci il point + if (old_id != -1 && plinkID == -1) + { + old_id = _linkID = -1; + erase_link (y, x1, x2); + x1 = x2 = y = 0l; + } + // se point e' su un bottone, evidenzia quello + else if (plinkID != -1 && (x1 != px1 || x2 != px2 || y != py)) + { + // erase old one + erase_link (y, x1, x2); + old_id = _linkID = plinkID; + x1 = px1; + x2 = px2; + y = py; + strcpy (descr, pdescr); + display_link (y, x1, x2, descr); + return TRUE; + } return FALSE; } bool TViswin :: in_text (const TPoint & p) - const - { - if (p.x > 5 && p.x < columns () && p.y > 0 && p.y < (rows () - 3)) - return TRUE; - return FALSE; - } + const +{ + if (p.x > 5 && p.x < columns () && p.y > 0 && p.y < (rows () - 3)) + return TRUE; + return FALSE; +} // general use, will probably move elsewhere - bool TViswin ::need_paint_sel (bool smart) +bool TViswin ::need_paint_sel (bool smart) { TPoint p1, p2; adjust_selection (p1, p2); @@ -225,8 +225,8 @@ in_text (const TPoint & p) bool r = _isselection; if (smart) r = r && ( - (origin ().y >= p1.y - 1 && origin ().y <= p2.y + 1) || - (end >= p1.y - 1 && end <= p2.y + 1)); + (origin ().y >= p1.y - 1 && origin ().y <= p2.y + 1) || + (end >= p1.y - 1 && end <= p2.y + 1)); return r; } @@ -250,15 +250,15 @@ void TViswin :: adjust_selection (TPoint & p1, TPoint & p2) { if (_sel_start.y < _sel_end.y) - { - p1 = _sel_start; - p2 = _sel_end; - } + { + p1 = _sel_start; + p2 = _sel_end; + } else - { - p1 = _sel_end; - p2 = _sel_start; - } + { + p1 = _sel_end; + p2 = _sel_start; + } } void TViswin :: @@ -271,23 +271,23 @@ shift_screen (scroll dir) _scrolling = TRUE; // origin() e' gia' stata modificata switch (dir) - { - case up: - case down: - set_rect (&r, 0, CHARY + 2, (int) (CHARX * (_textcolumns + 6)), (int) (CHARY * (_textrows + 1))); - win_scroll_rect (win (), &r, 0, dir == down ? CHARY : -CHARY); - paint_row (dir == up ? origin ().y + _textrows - 1 : origin ().y); - break; - case left: - case right: - set_rect (&r, CHARX * 6, 0, (int) (CHARX * (_textcolumns + 6) + 2), (int) (CHARY * (_textrows + 1) - 2)); - win_scroll_rect (win (), &r, dir == right ? CHARX : -CHARX, 0); - paint_column (dir == left ? origin ().x + _textcolumns - 1 : origin ().x, - dir == left); - break; - default: - break; - } + { + case up: + case down: + set_rect (&r, 0, CHARY + 2, (int) (CHARX * (_textcolumns + 6)), (int) (CHARY * (_textrows + 1))); + win_scroll_rect (win (), &r, 0, dir == down ? CHARY : -CHARY); + paint_row (dir == up ? origin ().y + _textrows - 1 : origin ().y); + break; + case left: + case right: + set_rect (&r, CHARX * 6, 0, (int) (CHARX * (_textcolumns + 6) + 2), (int) (CHARY * (_textrows + 1) - 2)); + win_scroll_rect (win (), &r, dir == right ? CHARX : -CHARX, 0); + paint_column (dir == left ? origin ().x + _textcolumns - 1 : origin ().x, + dir == left); + break; + default: + break; + } _scrolling = FALSE; } @@ -296,20 +296,20 @@ add_button (short id, const char *caption) { const int BUT_HEIGHT = #if XVT_OS == XVT_OS_WIN - 2 + 2 #else - 1 + 1 #endif - ; + ; WINDOW b = xvt_create_control (WC_PUSHBUTTON, 0, 0, 11, - BUT_HEIGHT, caption, win (), 0, 0, id); + BUT_HEIGHT, caption, win (), 0, 0, id); for (int i = 0; i < MAXBUT; i++) if (_button[i] == NULL_WIN) - { - _button[i] = b; - break; - } + { + _button[i] = b; + break; + } return b; } @@ -318,10 +318,10 @@ repos_buttons () { for (int buttons = 0; _button[buttons] != NULL_WIN; buttons++) if (buttons == MAXBUT - 1) - { - buttons++; - break; - } + { + buttons++; + break; + } if (buttons == 0) return; @@ -344,11 +344,11 @@ repos_buttons () int x = space; const int y = wr.bottom - br.bottom - 4; for (int b = 0; b < buttons; b++, x += br.right + space) - { - RCT r; - set_rect (&r, x, y, x + br.right, y + br.bottom); - move_window (_button[b], &r); - } + { + RCT r; + set_rect (&r, x, y, x + br.right, y + br.bottom); + move_window (_button[b], &r); + } } void TViswin :: @@ -356,7 +356,7 @@ open () { set_scroll_max (MAXLEN, _txt.lines () <= _textrows ? _txt.lines () : _txt.lines () - _textrows); repos_buttons (); -TScroll_window ::open (); + TScroll_window ::open (); _need_update = TRUE; force_update (); } @@ -367,36 +367,36 @@ paint_screen () { bool first = TRUE; for (long j = 0; j < _textrows; j++) + { + long rw = origin ().y + j; + if (rw < _txt.lines ()) + paint_row (rw); + else if (!_isopen) { - long rw = origin ().y + j; - if (rw < _txt.lines ()) - paint_row (rw); - else if (!_isopen) - { #if XVT_OS == XVT_OS_WIN - autoscroll (FALSE); - set_mode (M_COPY); - set_pen (COLOR_BLACK); + autoscroll (FALSE); + set_mode (M_COPY); + set_pen (COLOR_BLACK); - PNT b, e; - b.h = CHARX * 5; - b.v = (CHARY * (int) (j + 1l - origin ().y)) - 2; - e.h = CHARX * columns (); - e.v = b.v; - win_move_to (win (), b); - win_draw_line (win (), e); - set_pen (COLOR_LTGRAY); - e.v++; - b.v++; - win_move_to (win (), b); - win_draw_line (win (), e); - set_brush (COLOR_DKGRAY); - bar (5, (int) (j + 1l - origin ().y), (int) columns (), (int) (rows () - 3l)); - autoscroll (TRUE); - break; + PNT b, e; + b.h = CHARX * 5; + b.v = (CHARY * (int) (j + 1l - origin ().y)) - 2; + e.h = CHARX * columns (); + e.v = b.v; + win_move_to (win (), b); + win_draw_line (win (), e); + set_pen (COLOR_LTGRAY); + e.v++; + b.v++; + win_move_to (win (), b); + win_draw_line (win (), e); + set_brush (COLOR_DKGRAY); + bar (5, (int) (j + 1l - origin ().y), (int) columns (), (int) (rows () - 3l)); + autoscroll (TRUE); + break; #endif - } } + } } void TViswin :: @@ -417,80 +417,80 @@ paint_background (long j, int row) unsigned int x1, x2; PNT b, e; while (ch = rwd[cnt++]) + { + switch (ch) { - switch (ch) - { - case 'v': // verticale intera + case 'v': // verticale intera - x1 = (unsigned char) rwd[cnt++] + 5; - b.h = e.h = x1 * CHARX + CHARX / 2; - b.v = row * CHARY; - e.v = (row + 1) * CHARY; - win_move_to (win (), b); - win_draw_line (win (), e); - break; - case 'o': // verticale pezzo sopra + x1 = (unsigned char) rwd[cnt++] + 5; + b.h = e.h = x1 * CHARX + CHARX / 2; + b.v = row * CHARY; + e.v = (row + 1) * CHARY; + win_move_to (win (), b); + win_draw_line (win (), e); + break; + case 'o': // verticale pezzo sopra - x1 = (unsigned char) rwd[cnt++] + 5; - b.h = e.h = x1 * CHARX + CHARX / 2; - b.v = row * CHARY; - e.v = (row + 1) * CHARY - CHARY / 2; - win_move_to (win (), b); - win_draw_line (win (), e); - break; - case 'u': // verticale pezzo sotto + x1 = (unsigned char) rwd[cnt++] + 5; + b.h = e.h = x1 * CHARX + CHARX / 2; + b.v = row * CHARY; + e.v = (row + 1) * CHARY - CHARY / 2; + win_move_to (win (), b); + win_draw_line (win (), e); + break; + case 'u': // verticale pezzo sotto - x1 = (unsigned char) rwd[cnt++] + 5; - b.h = e.h = x1 * CHARX + CHARX / 2; - b.v = row * CHARY + CHARY / 2; - e.v = (row + 1) * CHARY; - win_move_to (win (), b); - win_draw_line (win (), e); - break; - case 'h': // orizzontale intera + x1 = (unsigned char) rwd[cnt++] + 5; + b.h = e.h = x1 * CHARX + CHARX / 2; + b.v = row * CHARY + CHARY / 2; + e.v = (row + 1) * CHARY; + win_move_to (win (), b); + win_draw_line (win (), e); + break; + case 'h': // orizzontale intera - x1 = (unsigned char) rwd[cnt++] + 5; - x2 = (unsigned char) rwd[cnt++] + 5; - b.v = e.v = row * CHARY + CHARY / 2; - b.h = x1 * CHARX; - e.h = (x2 + 1) * CHARX; - win_move_to (win (), b); - win_draw_line (win (), e); - break; - case 'r': // orizzontale scorciata agli estremi + x1 = (unsigned char) rwd[cnt++] + 5; + x2 = (unsigned char) rwd[cnt++] + 5; + b.v = e.v = row * CHARY + CHARY / 2; + b.h = x1 * CHARX; + e.h = (x2 + 1) * CHARX; + win_move_to (win (), b); + win_draw_line (win (), e); + break; + case 'r': // orizzontale scorciata agli estremi - x1 = (unsigned char) rwd[cnt++] + 5; - x2 = (unsigned char) rwd[cnt++] + 5; - b.v = e.v = row * CHARY + CHARY / 2; - b.h = x1 * CHARX + CHARX / 2; - e.h = x2 * CHARX + CHARX / 2; - win_move_to (win (), b); - win_draw_line (win (), e); - break; - case 'W': - curwid = rwd[cnt++]; - set_pen (trans_color (curcol), curwid - '0', trans_brush (curpat), - trans_pen (curpen)); - break; - case 'P': - curpen = rwd[cnt++]; - set_pen (trans_color (curcol), curwid - '0', trans_brush (curpat), - trans_pen (curpen)); - break; - case 'B': - curpat = rwd[cnt++]; - set_pen (trans_color (curcol), curwid - '0', trans_brush (curpat), - trans_pen (curpen)); - break; - case 'C': - curcol = rwd[cnt++]; - set_pen (trans_color (curcol), curwid - '0', trans_brush (curpat), - trans_pen (curpen)); - break; - default: - break; - } + x1 = (unsigned char) rwd[cnt++] + 5; + x2 = (unsigned char) rwd[cnt++] + 5; + b.v = e.v = row * CHARY + CHARY / 2; + b.h = x1 * CHARX + CHARX / 2; + e.h = x2 * CHARX + CHARX / 2; + win_move_to (win (), b); + win_draw_line (win (), e); + break; + case 'W': + curwid = rwd[cnt++]; + set_pen (trans_color (curcol), curwid - '0', trans_brush (curpat), + trans_pen (curpen)); + break; + case 'P': + curpen = rwd[cnt++]; + set_pen (trans_color (curcol), curwid - '0', trans_brush (curpat), + trans_pen (curpen)); + break; + case 'B': + curpat = rwd[cnt++]; + set_pen (trans_color (curcol), curwid - '0', trans_brush (curpat), + trans_pen (curpen)); + break; + case 'C': + curcol = rwd[cnt++]; + set_pen (trans_color (curcol), curwid - '0', trans_brush (curpat), + trans_pen (curpen)); + break; + default: + break; } + } // restore default pen set_pen (COLOR_BLACK); } @@ -498,14 +498,14 @@ paint_background (long j, int row) void TViswin :: paint_row (long j) { -// int or = (int)origin().x; + // int or = (int)origin().x; long y = origin ().y; TPoint p1, p2; if (need_paint_sel (FALSE)) adjust_selection (p1, p2); int row = (int) (j + 1l - y); static char fill[] = " " - " "; + " "; autoscroll (FALSE); set_font (FF_FIXED, 0); set_mode (M_COPY); @@ -513,66 +513,66 @@ paint_row (long j) set_color (FOREGROUND, BACKGROUND); printat (0, row, "%05ld", j + 1); if (_scrolling) - { - hide_pen (); - set_brush (COLOR_WHITE); - RCT r; - r.top = row * CHARY; - r.left = CHARX * 5, - r.bottom = r.top + CHARY + 2; - r.right = CHARX * 255; - win_draw_rect (win (), &r); - } + { + hide_pen (); + set_brush (COLOR_WHITE); + RCT r; + r.top = row * CHARY; + r.left = CHARX * 5, + r.bottom = r.top + CHARY + 2; + r.right = CHARX * 255; + win_draw_rect (win (), &r); + } const char *cp; int pos = 0; _txt.read_line (j, origin ().x); while (cp = _txt.piece ()) - { + { #if XVT_OS != XVT_OS_SCOUNIX - int st = _txt.get_style (); - long bg = trans_color (_txt.get_background ()); - long fg = trans_color (_txt.get_foreground ()); - set_font (FF_FIXED, st & 0x000f); - set_color (fg, bg); + int st = _txt.get_style (); + long bg = trans_color (_txt.get_background ()); + long fg = trans_color (_txt.get_foreground ()); + set_font (FF_FIXED, st & 0x000f); + set_color (fg, bg); #else - set_color (COLOR_BLACK, COLOR_WHITE); + set_color (COLOR_BLACK, COLOR_WHITE); #endif - printat (6 + pos, row, "%s", cp); + printat (6 + pos, row, "%s", cp); #if XVT_OS == XVT_OS_WIN - if (st & underlined) - { - PNT b, e; - - set_pen (COLOR_BLACK); - b.h = CHARX * (6 + pos); - b.v = (row + 1) * CHARY; - e.h = CHARX * (6 + pos + strlen (cp)); - e.v = (row + 1) * CHARY; - win_move_to (win (), b); - win_draw_line (win (), e); - } -#endif - pos += strlen (cp); - } - if (_scrolling && (pos < _textcolumns)) - { - set_color (COLOR_BLACK, COLOR_WHITE); - printat (6 + pos, row, "%s", fill); - } -#if XVT_OS == XVT_OS_WIN // paint page limits - if ((j % _formlen) == (_formlen - 1)) // last row - + if (st & underlined) { PNT b, e; - b.h = CHARX * 5; - b.v = (row + 1) * CHARY - 1; - e.h = CHARX * 132; - e.v = (row + 1) * CHARY - 1; - set_pen (COLOR_LTGRAY, 2, PAT_SOLID, P_DASH); + set_pen (COLOR_BLACK); + b.h = CHARX * (6 + pos); + b.v = (row + 1) * CHARY; + e.h = CHARX * (6 + pos + strlen (cp)); + e.v = (row + 1) * CHARY; win_move_to (win (), b); win_draw_line (win (), e); } +#endif + pos += strlen (cp); + } + if (_scrolling && (pos < _textcolumns)) + { + set_color (COLOR_BLACK, COLOR_WHITE); + printat (6 + pos, row, "%s", fill); + } +#if XVT_OS == XVT_OS_WIN // paint page limits + if ((j % _formlen) == (_formlen - 1)) // last row + + { + PNT b, e; + + b.h = CHARX * 5; + b.v = (row + 1) * CHARY - 1; + e.h = CHARX * 132; + e.v = (row + 1) * CHARY - 1; + set_pen (COLOR_LTGRAY, 2, PAT_SOLID, P_DASH); + win_move_to (win (), b); + win_draw_line (win (), e); + } #endif paint_background (j, row); autoscroll (TRUE); @@ -591,66 +591,66 @@ paint_column (long j, bool end) autoscroll (FALSE); for (long l = 0l; l < _textrows && l < (_txt.lines () - origin ().y); l++) - { - const char *c = (const char *) _txt.line (origin ().y + l); + { + const char *c = (const char *) _txt.line (origin ().y + l); #if XVT_OS != XVT_OS_SCOUNIX - int st = _txt.get_style ((int) j); - set_font (FF_FIXED, st & 0x000f); - long bg = trans_color (_txt.get_background ((int) j)); - long fg = trans_color (_txt.get_foreground ((int) j)); - set_color (fg, bg); + int st = _txt.get_style ((int) j); + set_font (FF_FIXED, st & 0x000f); + long bg = trans_color (_txt.get_background ((int) j)); + long fg = trans_color (_txt.get_foreground ((int) j)); + set_color (fg, bg); #endif - int col = end ? (int) (_textcolumns + 5) : 6; - printat (col, (int) l + 1, "%c", - (unsigned int) j < strlen (c) ? c[(int) j] : ' '); + int col = end ? (int) (_textcolumns + 5) : 6; + printat (col, (int) l + 1, "%c", + (unsigned int) j < strlen (c) ? c[(int) j] : ' '); #if XVT_OS == XVT_OS_WIN - if ((st & underlined) && strlen (c) > (word) j) - { - PNT b, e; + if ((st & underlined) && strlen (c) > (word) j) + { + PNT b, e; - set_pen (COLOR_BLACK); - b.h = CHARX * col; - b.v = (int) (l + 2l) * CHARY; - e.h = CHARX * (col + 1); - e.v = (int) (l + 2l) * CHARY; - win_move_to (win (), b); - win_draw_line (win (), e); - } -#endif - paint_background ((int) l, (int) l + 1); + set_pen (COLOR_BLACK); + b.h = CHARX * col; + b.v = (int) (l + 2l) * CHARY; + e.h = CHARX * (col + 1); + e.v = (int) (l + 2l) * CHARY; + win_move_to (win (), b); + win_draw_line (win (), e); } +#endif + paint_background ((int) l, (int) l + 1); + } autoscroll (TRUE); } void TViswin :: draw_crossbars () - // prints reference crossbars + // prints reference crossbars { #if XVT_OS == XVT_OS_WIN if (_cross.v > CHARY && _cross.v < (rows () - 3) * CHARY && _cross.h > CHARX * 5 && _cross.h < columns () * CHARX) - { - set_pen (COLOR_BLACK); - set_mode (M_XOR); + { + set_pen (COLOR_BLACK); + set_mode (M_XOR); - PNT b1, e1, b2, e2; + PNT b1, e1, b2, e2; - autoscroll (FALSE); - b1.h = _cross.h; - b1.v = CHARY; - e1.h = _cross.h; - e1.v = ((rows () - 3) * CHARY); - b2.h = CHARX * 5; - b2.v = _cross.v; - e2.h = CHARX * columns (); - e2.v = _cross.v; - win_move_to (win (), b1); - win_draw_line (win (), e1); - win_move_to (win (), b2); - win_draw_line (win (), e2); - autoscroll (TRUE); - } + autoscroll (FALSE); + b1.h = _cross.h; + b1.v = CHARY; + e1.h = _cross.h; + e1.v = ((rows () - 3) * CHARY); + b2.h = CHARX * 5; + b2.v = _cross.v; + e2.h = CHARX * columns (); + e2.v = _cross.v; + win_move_to (win (), b1); + win_draw_line (win (), e1); + win_move_to (win (), b2); + win_draw_line (win (), e2); + autoscroll (TRUE); + } #endif } @@ -694,21 +694,21 @@ paint_point (bool erase) static bool wasbar; if (_isbar) - { - invert_bar (6, (int) (_point.y - origin ().y + 1l), - (int) columns (), (int) (_point.y - origin ().y + 2l)); - invert_bar ((int) (_point.x - origin ().x + 6l), 1, - (int) (_point.x - origin ().x + 7l), (int) (rows () - 3l)); - } + { + invert_bar (6, (int) (_point.y - origin ().y + 1l), + (int) columns (), (int) (_point.y - origin ().y + 2l)); + invert_bar ((int) (_point.x - origin ().x + 6l), 1, + (int) (_point.x - origin ().x + 7l), (int) (rows () - 3l)); + } else - { - invert_bar ((int) (_point.x - origin ().x + 6l), (int) (_point.y - origin ().y + 1l), - (int) (_point.x - origin ().x + 7l), (int) (_point.y - origin ().y + 2l)); - invert_bar (0, (int) (_point.y - origin ().y + 1l), 5, - (int) (_point.y - origin ().y + 2l)); - invert_bar ((int) (_point.x - origin ().x + 6l), 0, - (int) (_point.x - origin ().x + 7l), 1); - } + { + invert_bar ((int) (_point.x - origin ().x + 6l), (int) (_point.y - origin ().y + 1l), + (int) (_point.x - origin ().x + 7l), (int) (_point.y - origin ().y + 2l)); + invert_bar (0, (int) (_point.y - origin ().y + 1l), 5, + (int) (_point.y - origin ().y + 2l)); + invert_bar ((int) (_point.x - origin ().x + 6l), 0, + (int) (_point.x - origin ().x + 7l), 1); + } autoscroll (TRUE); wasbar = _isbar; } @@ -723,11 +723,11 @@ paint_header () set_font (FF_FIXED, 0); TString htmpst (10); for (int i = 1; i < 26; i++) - { - htmpst.format ("%d", i); - htmpst.right_just (10, '.'); - printat (i * 10 - 4, (int) origin ().y, "%s", (const char *) htmpst); - } + { + htmpst.format ("%d", i); + htmpst.right_just (10, '.'); + printat (i * 10 - 4, (int) origin ().y, "%s", (const char *) htmpst); + } autoscroll (FALSE); set_color (COLOR_WHITE, BACKGROUND); printat (0, 0, "P.%3ld ", ((origin ().y) / _formlen) + 1l); @@ -742,19 +742,19 @@ paint_selection () // paint rows for (long l = p1.y; l <= p2.y; l++) + { + int top, left, right; + top = (int) (l - origin ().y + 1); + if (top > 0 && top <= _textrows) { - int top, left, right; - top = (int) (l - origin ().y + 1); - if (top > 0 && top <= _textrows) - { - left = p1.y == l ? (int) (p1.x - origin ().x + 6l) : 6; - right = p2.y == l ? (int) (p2.x - origin ().x + 6l) : - (int) (_textcolumns + 6l); - autoscroll (FALSE); - invert_bar (left, top, right, top + 1); - autoscroll (TRUE); - } + left = p1.y == l ? (int) (p1.x - origin ().x + 6l) : 6; + right = p2.y == l ? (int) (p2.x - origin ().x + 6l) : + (int) (_textcolumns + 6l); + autoscroll (FALSE); + invert_bar (left, top, right, top + 1); + autoscroll (TRUE); } + } } void TViswin :: @@ -765,30 +765,30 @@ paint_waitbar (bool xor) #endif autoscroll (FALSE); if (xor) - { + { #if XVT_OS == XVT_OS_WIN - cpb_win_picture_draw_at (win (), _picture[pic], 4, 4 + (int) (rows () - 3l) * CHARY); - if (pic == 3) - pic = 0; - else - pic++; + cpb_win_picture_draw_at (win (), _picture[pic], 4, 4 + (int) (rows () - 3l) * CHARY); + if (pic == 3) + pic = 0; + else + pic++; #else - invert_bar (3, rows () - 2, 4, rows () - 1); + invert_bar (3, rows () - 2, 4, rows () - 1); #endif - } + } else - { + { #if XVT_OS == XVT_OS_WIN - cpb_win_picture_draw_at (win (), _picture[pic], 4, - 4 + (int) (rows () - 3l) * CHARY); - if (pic == 3) - pic = 0; - else - pic++; + cpb_win_picture_draw_at (win (), _picture[pic], 4, + 4 + (int) (rows () - 3l) * CHARY); + if (pic == 3) + pic = 0; + else + pic++; #else - printat (3, rows () - 2, "%c", '*'); + printat (3, rows () - 2, "%c", '*'); #endif - } + } autoscroll (TRUE); } @@ -805,29 +805,29 @@ update () bar (5, rows () - 3, columns () + 1, rows () + 1); if (_need_update) - { - if (_isselection) - erase_selection (); - clear (COLOR_WHITE); - set_mode (M_COPY); - set_brush (MASK_BACK_COLOR); - autoscroll (FALSE); - bar (0, 0, columns () + 1, 1); - bar (0, 0, 5, rows () + 1); - bar (5, rows () - 3, columns () + 1, rows () + 1); - if (_isopen) - paint_waitbar (FALSE); + { + if (_isselection) + erase_selection (); + clear (COLOR_WHITE); + set_mode (M_COPY); + set_brush (MASK_BACK_COLOR); + autoscroll (FALSE); + bar (0, 0, columns () + 1, 1); + bar (0, 0, 5, rows () + 1); + bar (5, rows () - 3, columns () + 1, rows () + 1); + if (_isopen) + paint_waitbar (FALSE); #if XVT_OS == XVT_OS_WIN - else - cpb_win_picture_draw_at (win (), _modpic, 4, - 4 + (int) (rows () - 3l) * CHARY); +else + cpb_win_picture_draw_at (win (), _modpic, 4, + 4 + (int) (rows () - 3l) * CHARY); #endif - autoscroll (TRUE); - paint_header (); - paint_screen (); - if (_isselection) - display_selection (); - } + autoscroll (TRUE); + paint_header (); + paint_screen (); + if (_isselection) + display_selection (); + } display_point (); autoscroll (TRUE); _need_update = TRUE; @@ -838,12 +838,12 @@ void TViswin :: abort_print () { if (yesno_box ("Interruzione della stampa su video?")) - { - _txt.freeze (); - freeze (); - set_focus (); - close_print (); - } + { + _txt.freeze (); + freeze (); + set_focus (); + close_print (); + } } void TViswin :: @@ -857,531 +857,531 @@ handler (WINDOW win, EVENT * ep) int kdiff; long new_origin; switch (ep->type) + { + case E_USER: + if (ep->v.user.id == E_ADDLINE) { - case E_USER: - if (ep->v.user.id == E_ADDLINE) - { - set_scroll_max (MAXLEN - 1, _txt.lines () <= _textrows ? - _txt.lines () : _txt.lines () - _textrows); - } - else if (ep->v.user.id == E_ADDLINE_ONSCREEN) - { - set_scroll_max (MAXLEN - 1, _txt.lines () <= _textrows ? _txt.lines () : _txt.lines () - _textrows); - erase_point (); - if (need_paint_sel (FALSE)) - erase_selection (); - paint_row (_txt.lines () - 1l); - if (need_paint_sel (FALSE)) - display_selection (); - display_point (); - if (_txt.lines () > 1l) - _need_update = FALSE; - else - force_update (); - } + set_scroll_max (MAXLEN - 1, _txt.lines () <= _textrows ? + _txt.lines () : _txt.lines () - _textrows); + } + else if (ep->v.user.id == E_ADDLINE_ONSCREEN) + { + set_scroll_max (MAXLEN - 1, _txt.lines () <= _textrows ? _txt.lines () : _txt.lines () - _textrows); + erase_point (); + if (need_paint_sel (FALSE)) + erase_selection (); + paint_row (_txt.lines () - 1l); + if (need_paint_sel (FALSE)) + display_selection (); + display_point (); + if (_txt.lines () > 1l) + _need_update = FALSE; + else + force_update (); + } + autoscroll (FALSE); + _textrows = TEXTROWS; + _textcolumns = TEXTCOLUMNS; + autoscroll (TRUE); + break; + case E_CONTROL: + if (ep->v.ctl.ci.type == WC_PUSHBUTTON) + switch (ep->v.ctl.id) + { + case DLG_QUIT: + if (_isopen) + abort_print (); + else + { +#if XVT_OS == XVT_OS_WIN + xvt_statbar_set (""); + xvt_statbar_refresh (); +#endif + stop_run (K_ENTER); + } + break; + case DLG_PRINT: + _txt.print (); + break; + case DLG_EDIT: + check_link (); + call_editor (); + _need_update = TRUE; + update (); + check_link (&_point); + break; + case DLG_LINK: + if (_linkID != -1) + { + LINKHANDLER pl = MainApp ()->printer ().getlinkhandler (); + if (pl) + (*pl) (_linkID, _multiple ? (const char *) _multiple_link : + _linktxt); + set_focus (); + check_link (); + _need_update = TRUE; + force_update (); + do_events (); + check_link (&_point); + } + else + beep (); + break; + } + break; + case E_TIMER: + if (ep->v.timer.id == _timer) + { + kill_timer (_timer); + _istimer = FALSE; + } + else if (ep->v.timer.id == _wtimer) + { + paint_waitbar (); + kill_timer (_wtimer); + if (_isopen) + _wtimer = set_timer (win, 150l); + } + break; + case E_MOUSE_DBL: + break; + case E_MOUSE_DOWN: + p = ep->v.mouse.where; + trap_mouse (win); + + if (ep->v.mouse.button == 0) // left button: text selection + + { + if (need_paint_sel (FALSE)) + { + erase_selection (); + _isselection = FALSE; + } + if (!in_text (p) || (p.y + origin ().y) >= _txt.lines ()) + { + ignore = TRUE; + break; + } + + erase_point (); + _sel_start = ep->v.mouse.where; + _sel_start.x += (origin ().x - 6); + _sel_start.y += (origin ().y - 1); + _sel_end = _sel_start; + _selecting = TRUE; + } + else + { + // show crossbars + _cross = ep->v.mouse.where; + display_crossbar (); + _iscross = TRUE; + } + break; + case E_MOUSE_UP: + release_mouse (); + + if (ep->v.mouse.button == 0) // left button: text selection/move + // point + + { + p = ep->v.mouse.where; + + if (_isopen && (p.x >= 4 && p.x) <= 6 && + (p.y >= (int) rows () - 3 && p.y <= (int) rows () - 1)) + { + abort_print (); + ignore = TRUE; + } + if (ignore) + { + ignore = FALSE; + _selecting = FALSE; + break; + } + // confirm selection & store + p.x += (origin ().x - 6); + p.y += (origin ().y - 1); + + if (_sel_start == p) + { + if (_isselection) + { + _isselection = FALSE; + erase_selection (); + } + if (_sel_start == _point && !_selecting) + { + dispatch_e_char (win, K_F5); + } + else + { + TPoint xx; + _point.x = p.x; + _point.y = p.y; + if (_point.y > _txt.lines ()) + _point.y = _txt.lines () - 1l; + if (_point.y < 0) + _point.y = 0; + if (_point.x < 0) + _point.x = 0; + if (_point.x > 255) + _point.x = 255; + + check_link (&_point); + display_point (); + } + } + else + { + _sel_end.x = p.x; + _sel_end.y = p.y; + if (_sel_end.y >= _txt.lines ()) + _sel_end.y = _txt.lines () - 1l; + if (_sel_end.y < 0) + _sel_end.y = 0; + if (_sel_end.x < 0) + _sel_end.x = 0; + if (_sel_end.x > 255) + _sel_end.x = 255; + _point = _sel_end; + _isselection = TRUE; + check_link (&_point); + display_point (); + } + _selecting = FALSE; + } + else + { + erase_crossbar (); + _iscross = FALSE; + } + break; + case E_MOUSE_MOVE: + { + if (!_selecting && !_iscross) // no buttons pressed + + { + p = ep->v.mouse.where; + if (in_text (p)) + { + p.x += (origin ().x - 6); + p.y += (origin ().y - 1); + check_link (&p); + } + } + if (_selecting || _iscross) + { + p = ep->v.mouse.where; + if (_selecting) + _isselection = TRUE;; + { + _isselection = TRUE; + } + // scroll if necessary + if (p.y >= _textrows + 1l) + { + if (_isselection) + erase_selection (); + if (_iscross) + erase_crossbar (); + dispatch_e_scroll (win, K_DOWN); + if (_isselection) + display_selection (); + if (_iscross) + display_crossbar (); + } + else if (p.y <= 0l) + { + if (_isselection) + erase_selection (); + if (_iscross) + erase_crossbar (); + dispatch_e_scroll (win, K_UP); + if (_isselection) + display_selection (); + if (_iscross) + display_crossbar (); + } + else if (p.x <= 5l) + { + if (_isselection) + erase_selection (); + if (_iscross) + erase_crossbar (); + dispatch_e_scroll (win, K_LEFT); + if (_isselection) + display_selection (); + if (_iscross) + display_crossbar (); + } + else if (p.x >= _textcolumns + 6) + { + if (_isselection) + erase_selection (); + if (_iscross) + erase_crossbar (); + dispatch_e_scroll (win, K_RIGHT); + if (_isselection) + display_selection (); + if (_iscross) + display_crossbar (); + } + if (_selecting) + { + if (in_text (p)) + { + p.x += (origin ().x - 6); + p.y += (origin ().y - 1); + _point = p; + if (_point.y >= _txt.lines ()) + _point.y = _txt.lines () - 1l; + } + if (_point != _sel_end) + { + erase_selection (); + _sel_end = _point; + display_selection (); + } + } + } + if (_iscross) + { + newcross = ep->v.mouse.where; + if (_cross.h != newcross.h || _cross.v != newcross.v) + { + erase_crossbar (); + _cross = newcross; + display_crossbar (); + } + } + } + break; + case E_SIZE: + if (is_open ()) + { + check_link (); + erase_point (); + if (_isselection) + erase_selection (); autoscroll (FALSE); _textrows = TEXTROWS; _textcolumns = TEXTCOLUMNS; autoscroll (TRUE); - break; - case E_CONTROL: - if (ep->v.ctl.ci.type == WC_PUSHBUTTON) - switch (ep->v.ctl.id) - { - case DLG_QUIT: - if (_isopen) - abort_print (); - else - { -#if XVT_OS == XVT_OS_WIN - xvt_statbar_set (""); - xvt_statbar_refresh (); -#endif - stop_run (K_ENTER); - } - break; - case DLG_PRINT: - _txt.print (); - break; - case DLG_EDIT: - check_link (); - call_editor (); - _need_update = TRUE; - update (); - check_link (&_point); - break; - case DLG_LINK: - if (_linkID != -1) - { - LINKHANDLER pl = MainApp ()->printer ().getlinkhandler (); - if (pl) - (*pl) (_linkID, _multiple ? (const char *) _multiple_link : - _linktxt); - set_focus (); - check_link (); - _need_update = TRUE; - force_update (); - do_events (); - check_link (&_point); - } - else - beep (); - break; - } - break; - case E_TIMER: - if (ep->v.timer.id == _timer) - { - kill_timer (_timer); - _istimer = FALSE; - } - else if (ep->v.timer.id == _wtimer) - { - paint_waitbar (); - kill_timer (_wtimer); - if (_isopen) - _wtimer = set_timer (win, 150l); - } - break; - case E_MOUSE_DBL: - break; - case E_MOUSE_DOWN: - p = ep->v.mouse.where; - trap_mouse (win); - - if (ep->v.mouse.button == 0) // left button: text selection - - { - if (need_paint_sel (FALSE)) - { - erase_selection (); - _isselection = FALSE; - } - if (!in_text (p) || (p.y + origin ().y) >= _txt.lines ()) - { - ignore = TRUE; - break; - } - - erase_point (); - _sel_start = ep->v.mouse.where; - _sel_start.x += (origin ().x - 6); - _sel_start.y += (origin ().y - 1); - _sel_end = _sel_start; - _selecting = TRUE; - } - else - { - // show crossbars - _cross = ep->v.mouse.where; - display_crossbar (); - _iscross = TRUE; - } - break; - case E_MOUSE_UP: - release_mouse (); - - if (ep->v.mouse.button == 0) // left button: text selection/move - // point - - { - p = ep->v.mouse.where; - - if (_isopen && (p.x >= 4 && p.x) <= 6 && - (p.y >= (int) rows () - 3 && p.y <= (int) rows () - 1)) - { - abort_print (); - ignore = TRUE; - } - if (ignore) - { - ignore = FALSE; - _selecting = FALSE; - break; - } - // confirm selection & store - p.x += (origin ().x - 6); - p.y += (origin ().y - 1); - - if (_sel_start == p) - { - if (_isselection) - { - _isselection = FALSE; - erase_selection (); - } - if (_sel_start == _point && !_selecting) - { - dispatch_e_char (win, K_F5); - } - else - { - TPoint xx; - _point.x = p.x; - _point.y = p.y; - if (_point.y > _txt.lines ()) - _point.y = _txt.lines () - 1l; - if (_point.y < 0) - _point.y = 0; - if (_point.x < 0) - _point.x = 0; - if (_point.x > 255) - _point.x = 255; - - check_link (&_point); - display_point (); - } - } - else - { - _sel_end.x = p.x; - _sel_end.y = p.y; - if (_sel_end.y >= _txt.lines ()) - _sel_end.y = _txt.lines () - 1l; - if (_sel_end.y < 0) - _sel_end.y = 0; - if (_sel_end.x < 0) - _sel_end.x = 0; - if (_sel_end.x > 255) - _sel_end.x = 255; - _point = _sel_end; - _isselection = TRUE; - check_link (&_point); - display_point (); - } - _selecting = FALSE; - } - else - { - erase_crossbar (); - _iscross = FALSE; - } - break; - case E_MOUSE_MOVE: + repos_buttons (); + display_point (); + force_update (); + do_events (); + check_link (&_point); + } + break; + case E_HSCROLL: + case E_VSCROLL: + { + erase_point (); + tlnk = TRUE; + switch (ep->v.scroll.what) + { + case SC_PAGE_UP: + if (ep->type == E_VSCROLL) { - if (!_selecting && !_iscross) // no buttons pressed + if (origin ().y > 0) + { + kdiff = (int) (_point.y - origin ().y); + new_origin = origin ().y > _textrows ? + origin ().y - _textrows + 1l : 0; + _point.y = new_origin + kdiff; + check_link (); + update_thumb (origin ().x, new_origin); + _need_update = TRUE; + update (); // ORRIIIBILE! - { - p = ep->v.mouse.where; - if (in_text (p)) - { - p.x += (origin ().x - 6); - p.y += (origin ().y - 1); - check_link (&p); - } - } - if (_selecting || _iscross) - { - p = ep->v.mouse.where; - if (_selecting) - _isselection = TRUE;; - { - _isselection = TRUE; - } - // scroll if necessary - if (p.y >= _textrows + 1l) - { - if (_isselection) - erase_selection (); - if (_iscross) - erase_crossbar (); - dispatch_e_scroll (win, K_DOWN); - if (_isselection) - display_selection (); - if (_iscross) - display_crossbar (); - } - else if (p.y <= 0l) - { - if (_isselection) - erase_selection (); - if (_iscross) - erase_crossbar (); - dispatch_e_scroll (win, K_UP); - if (_isselection) - display_selection (); - if (_iscross) - display_crossbar (); - } - else if (p.x <= 5l) - { - if (_isselection) - erase_selection (); - if (_iscross) - erase_crossbar (); - dispatch_e_scroll (win, K_LEFT); - if (_isselection) - display_selection (); - if (_iscross) - display_crossbar (); - } - else if (p.x >= _textcolumns + 6) - { - if (_isselection) - erase_selection (); - if (_iscross) - erase_crossbar (); - dispatch_e_scroll (win, K_RIGHT); - if (_isselection) - display_selection (); - if (_iscross) - display_crossbar (); - } - if (_selecting) - { - if (in_text (p)) - { - p.x += (origin ().x - 6); - p.y += (origin ().y - 1); - _point = p; - if (_point.y >= _txt.lines ()) - _point.y = _txt.lines () - 1l; - } - if (_point != _sel_end) - { - erase_selection (); - _sel_end = _point; - display_selection (); - } - } - } - if (_iscross) - { - newcross = ep->v.mouse.where; - if (_cross.h != newcross.h || _cross.v != newcross.v) - { - erase_crossbar (); - _cross = newcross; - display_crossbar (); - } - } + check_link (&_point); + _need_update = FALSE; + } + else + beep (); + } + else + { + if (origin ().x > 0) + { + kdiff = (int) (_point.x - origin ().x); + new_origin = origin ().x > _textcolumns ? + origin ().x - _textcolumns + 1 : 0; + _point.x = new_origin + kdiff; + check_link (); + update_thumb (new_origin, _point.x); + _need_update = TRUE; + update (); // AAAARGH! + + check_link (&_point); + _need_update = FALSE; + } + else + beep (); } break; - case E_SIZE: - if (is_open ()) - { - check_link (); - erase_point (); - if (_isselection) - erase_selection (); - autoscroll (FALSE); - _textrows = TEXTROWS; - _textcolumns = TEXTCOLUMNS; - autoscroll (TRUE); - repos_buttons (); - display_point (); - force_update (); - do_events (); - check_link (&_point); - } - break; - case E_HSCROLL: - case E_VSCROLL: + case SC_LINE_UP: + if (ep->type == E_VSCROLL) { - erase_point (); - tlnk = TRUE; - switch (ep->v.scroll.what) - { - case SC_PAGE_UP: - if (ep->type == E_VSCROLL) - { - if (origin ().y > 0) - { - kdiff = (int) (_point.y - origin ().y); - new_origin = origin ().y > _textrows ? - origin ().y - _textrows + 1l : 0; - _point.y = new_origin + kdiff; - check_link (); - update_thumb (origin ().x, new_origin); - _need_update = TRUE; - update (); // ORRIIIBILE! - - check_link (&_point); - _need_update = FALSE; - } - else - beep (); - } - else - { - if (origin ().x > 0) - { - kdiff = (int) (_point.x - origin ().x); - new_origin = origin ().x > _textcolumns ? - origin ().x - _textcolumns + 1 : 0; - _point.x = new_origin + kdiff; - check_link (); - update_thumb (new_origin, _point.x); - _need_update = TRUE; - update (); // AAAARGH! - - check_link (&_point); - _need_update = FALSE; - } - else - beep (); - } - break; - case SC_LINE_UP: - if (ep->type == E_VSCROLL) - { - _need_update = FALSE; - if (origin ().y > 0l) - { - _point.y--; - if (need_paint_sel ()) - erase_selection (); - check_link (); - update_thumb (origin ().x, origin ().y - 1l); - _need_scroll = down; - } - else - beep (); - } - else - { - _need_update = FALSE; - if (origin ().x > 0l) - { - if (need_paint_sel (FALSE)) - erase_selection (); - check_link (); - update_thumb (origin ().x - 1l, origin ().y); - _point.x--; - _need_scroll = right; - } - else - beep (); - } - break; - case SC_PAGE_DOWN: - if (ep->type == E_VSCROLL) - { - if ((origin ().y + _textrows) < _txt.lines ()) - { - kdiff = (int) (_point.y - origin ().y); - new_origin = (_txt.lines () - origin ().y) > - (_textrows * 2l) ? - origin ().y + _textrows - 1 : _txt.lines () - _textrows; - _point.y = new_origin + kdiff; - check_link (); - update_thumb (origin ().x, new_origin); - _need_update = TRUE; - update (); // AAAARGH! - - check_link (&_point); - _need_update = FALSE; - } - else - beep (); - } - else - { - if ((origin ().x + _textcolumns) < 256) - { - kdiff = (int) (_point.x - origin ().x); - new_origin = (256 - origin ().x) > _textcolumns ? - origin ().x + _textcolumns - 1 : 256 - _textcolumns; - _point.x = new_origin + kdiff; - check_link (); - update_thumb (new_origin, origin ().y); - _need_update = TRUE; - update (); // AAAARGH! - - check_link (&_point); - _need_update = FALSE; - } - else - beep (); - } - break; - case SC_LINE_DOWN: - if (ep->type == E_VSCROLL) - { - _need_update = FALSE; - if ((origin ().y + _textrows) < _txt.lines ()) - { - if (need_paint_sel ()) - erase_selection (); - check_link (); - update_thumb (origin ().x, origin ().y + 1l); - _point.y++; - _need_scroll = up; - } - else - beep (); - } - else - { - _need_update = FALSE; - if ((origin ().x + _textcolumns) < 255) - { - if (need_paint_sel (FALSE)) - erase_selection (); - check_link (); - update_thumb (origin ().x + 1l, origin ().y); - _need_scroll = left; - _point.x++; - } - else - beep (); - } - break; - case SC_THUMB: - - check_link (); - kdiff_x = (int) (_point.x - origin ().x); - kdiff_y = (int) (_point.y - origin ().y); - - p.x = ep->type == E_VSCROLL ? origin ().x : ep->v.scroll.pos; - p.y = ep->type == E_HSCROLL ? origin ().y : ep->v.scroll.pos; - - if ((p.y + _textrows) >= _txt.lines ()) - p.y = _txt.lines () - _textrows; - if ((p.x + _textcolumns) >= 255) - p.x = 255 - _textcolumns; - - update_thumb (p.x, p.y); - - _point.x = ep->type == E_VSCROLL ? origin ().x : - origin ().x + kdiff_x; - _point.y = ep->type == E_HSCROLL ? origin ().y : - origin ().y + kdiff_y; - _need_update = TRUE; - update (); - check_link (&_point); - break; - - default: - break; - } - // for failed scrollings - if (!_selecting && _need_scroll == none) - { - check_link (&_point); - display_point (); - } + _need_update = FALSE; + if (origin ().y > 0l) + { + _point.y--; + if (need_paint_sel ()) + erase_selection (); + check_link (); + update_thumb (origin ().x, origin ().y - 1l); + _need_scroll = down; + } + else + beep (); + } + else + { + _need_update = FALSE; + if (origin ().x > 0l) + { + if (need_paint_sel (FALSE)) + erase_selection (); + check_link (); + update_thumb (origin ().x - 1l, origin ().y); + _point.x--; + _need_scroll = right; + } + else + beep (); } break; + case SC_PAGE_DOWN: + if (ep->type == E_VSCROLL) + { + if ((origin ().y + _textrows) < _txt.lines ()) + { + kdiff = (int) (_point.y - origin ().y); + new_origin = (_txt.lines () - origin ().y) > + (_textrows * 2l) ? + origin ().y + _textrows - 1 : _txt.lines () - _textrows; + _point.y = new_origin + kdiff; + check_link (); + update_thumb (origin ().x, new_origin); + _need_update = TRUE; + update (); // AAAARGH! + + check_link (&_point); + _need_update = FALSE; + } + else + beep (); + } + else + { + if ((origin ().x + _textcolumns) < 256) + { + kdiff = (int) (_point.x - origin ().x); + new_origin = (256 - origin ().x) > _textcolumns ? + origin ().x + _textcolumns - 1 : 256 - _textcolumns; + _point.x = new_origin + kdiff; + check_link (); + update_thumb (new_origin, origin ().y); + _need_update = TRUE; + update (); // AAAARGH! + + check_link (&_point); + _need_update = FALSE; + } + else + beep (); + } + break; + case SC_LINE_DOWN: + if (ep->type == E_VSCROLL) + { + _need_update = FALSE; + if ((origin ().y + _textrows) < _txt.lines ()) + { + if (need_paint_sel ()) + erase_selection (); + check_link (); + update_thumb (origin ().x, origin ().y + 1l); + _point.y++; + _need_scroll = up; + } + else + beep (); + } + else + { + _need_update = FALSE; + if ((origin ().x + _textcolumns) < 255) + { + if (need_paint_sel (FALSE)) + erase_selection (); + check_link (); + update_thumb (origin ().x + 1l, origin ().y); + _need_scroll = left; + _point.x++; + } + else + beep (); + } + break; + case SC_THUMB: + + check_link (); + kdiff_x = (int) (_point.x - origin ().x); + kdiff_y = (int) (_point.y - origin ().y); + + p.x = ep->type == E_VSCROLL ? origin ().x : ep->v.scroll.pos; + p.y = ep->type == E_HSCROLL ? origin ().y : ep->v.scroll.pos; + + if ((p.y + _textrows) >= _txt.lines ()) + p.y = _txt.lines () - _textrows; + if ((p.x + _textcolumns) >= 255) + p.x = 255 - _textcolumns; + + update_thumb (p.x, p.y); + + _point.x = ep->type == E_VSCROLL ? origin ().x : + origin ().x + kdiff_x; + _point.y = ep->type == E_HSCROLL ? origin ().y : + origin ().y + kdiff_y; + _need_update = TRUE; + update (); + check_link (&_point); + break; + default: break; } - if (_need_scroll != none) + // for failed scrollings + if (!_selecting && _need_scroll == none) { - _need_update = FALSE; - scroll tmp = _need_scroll; - _need_scroll = none; - shift_screen (tmp); - if (!_selecting) - { - check_link (&_point); - display_point (); - } - if (_isselection) - display_selection (); + check_link (&_point); + display_point (); } + } + break; + default: + break; + } + if (_need_scroll != none) + { + _need_update = FALSE; + scroll tmp = _need_scroll; + _need_scroll = none; + shift_screen (tmp); + if (!_selecting) + { + check_link (&_point); + display_point (); + } + if (_isselection) + display_selection (); + } if (ep->type != E_UPDATE || _need_update) - TWindow ::handler (win, ep); + TWindow ::handler (win, ep); else if (ep->type == E_UPDATE) update (); } @@ -1405,335 +1405,335 @@ on_key (KEY key) _selecting = FALSE; switch (key) + { + case CTRL_E: + if (_isedit) { - case CTRL_E: - if (_isedit) - { - check_link (); - call_editor (); - set_focus (); - _need_update = TRUE; - update (); - check_link (&_point); - } - break; - case CTRL_C: - if (_linkID != -1) - { - LINKHANDLER pl = MainApp ()->printer ().getlinkhandler (); - if (pl) - (*pl) (_linkID, _multiple ? (const char *) _multiple_link : - _linktxt); - set_focus (); - check_link (); - _need_update = TRUE; - force_update (); - do_events (); - check_link (&_point); - } - else - beep (); - break; - case CTRL_S: - if (_isprint) - _txt.print (); - break; - case CTRL_R: - _need_update = TRUE; check_link (); + call_editor (); + set_focus (); + _need_update = TRUE; + update (); + check_link (&_point); + } + break; + case CTRL_C: + if (_linkID != -1) + { + LINKHANDLER pl = MainApp ()->printer ().getlinkhandler (); + if (pl) + (*pl) (_linkID, _multiple ? (const char *) _multiple_link : + _linktxt); + set_focus (); + check_link (); + _need_update = TRUE; force_update (); do_events (); check_link (&_point); - break; - case K_ESC: - if (_isopen) - abort_print (); - else - { + } + else + beep (); + break; + case CTRL_S: + if (_isprint) + _txt.print (); + break; + case CTRL_R: + _need_update = TRUE; + check_link (); + force_update (); + do_events (); + check_link (&_point); + break; + case K_ESC: + if (_isopen) + abort_print (); + else + { #if XVT_OS == XVT_OS_WIN - xvt_statbar_set (""); - xvt_statbar_refresh (); + xvt_statbar_set (""); + xvt_statbar_refresh (); #endif - stop_run (K_ESC); - } - break; - case K_ENTER: - if (_isselection) - { - erase_selection (); - _isselection = FALSE; - } - break; - case K_TAB: - if (_curbut == (_buttons - 1)) - _curbut = 0; - else - _curbut++; - break; - case K_BTAB: - if (_curbut == 0) - _curbut = _buttons - 1; - else - _curbut--; - break; - case K_SPACE: - case K_SHIFT_ENTER: - if (_linkID != -1) - { - LINKHANDLER pl = MainApp ()->printer ().getlinkhandler (); - if (pl) - (*pl) (_linkID, _multiple ? (const char *) _multiple_link : - _linktxt); - _need_update = TRUE; - set_focus (); - check_link (); - _need_update = TRUE; - force_update (); - do_events (); - check_link (&_point); - } - else - dispatch_e_char (_button[_curbut], K_SPACE); - break; - case K_LHOME: + stop_run (K_ESC); + } + break; + case K_ENTER: + if (_isselection) + { + erase_selection (); + _isselection = FALSE; + } + break; + case K_TAB: + if (_curbut == (_buttons - 1)) + _curbut = 0; + else + _curbut++; + break; + case K_BTAB: + if (_curbut == 0) + _curbut = _buttons - 1; + else + _curbut--; + break; + case K_SPACE: + case K_CTRL_ENTER: + if (_linkID != -1) + { + LINKHANDLER pl = MainApp ()->printer ().getlinkhandler (); + if (pl) + (*pl) (_linkID, _multiple ? (const char *) _multiple_link : + _linktxt); _need_update = TRUE; - update_thumb (0, 0); - _point.set (0, 0); - check_link (&_point); - force_update (); - break; - case K_LEND: - _need_update = TRUE; - update_thumb (0, _txt.lines () - _textrows); - _point.set (0, _txt.lines () - 1); - check_link (&_point); - force_update (); - break; - case K_RIGHT: - case K_LEFT: - case K_WRIGHT: - case K_WLEFT: - case K_ALT_RIGHT: - case K_ALT_LEFT: - case K_SHIFT_RIGHT: - case K_SHIFT_LEFT: - type = E_HSCROLL; - break; - case K_UP: - case K_DOWN: - case K_NEXT: - case K_PREV: - case K_CTRL_UP: - case K_CTRL_DOWN: - case K_SHIFT_UP: - case K_SHIFT_DOWN: - type = E_VSCROLL; - break; - case K_F5: + set_focus (); check_link (); - erase_point (); - _isbar = !_isbar; _need_update = TRUE; force_update (); do_events (); check_link (&_point); - break; - case K_F6: - _selflag = !_selflag; - break; - default: - break; } + else + dispatch_e_char (_button[_curbut], K_SPACE); + break; + case K_LHOME: + _need_update = TRUE; + update_thumb (0, 0); + _point.set (0, 0); + check_link (&_point); + force_update (); + break; + case K_LEND: + _need_update = TRUE; + update_thumb (0, _txt.lines () - _textrows); + _point.set (0, _txt.lines () - 1); + check_link (&_point); + force_update (); + break; + case K_RIGHT: + case K_LEFT: + case K_WRIGHT: + case K_WLEFT: + case K_ALT_RIGHT: + case K_ALT_LEFT: + case K_SHIFT_RIGHT: + case K_SHIFT_LEFT: + type = E_HSCROLL; + break; + case K_UP: + case K_DOWN: + case K_NEXT: + case K_PREV: + case K_CTRL_UP: + case K_CTRL_DOWN: + case K_SHIFT_UP: + case K_SHIFT_DOWN: + type = E_VSCROLL; + break; + case K_F5: + check_link (); + erase_point (); + _isbar = !_isbar; + _need_update = TRUE; + force_update (); + do_events (); + check_link (&_point); + break; + case K_F6: + _selflag = !_selflag; + break; + default: + break; + } switch (type) + { + case E_HSCROLL: + case E_VSCROLL: + { + erase_point (); + check_link (); + switch (key) { - case E_HSCROLL: - case E_VSCROLL: + case K_PREV: + dispatch_e_scroll (win (), K_PREV); + break; + case K_NEXT: + dispatch_e_scroll (win (), K_NEXT); + break; + case K_WRIGHT: + dispatch_e_scroll (win (), K_BTAB); + break; + case K_WLEFT: + dispatch_e_scroll (win (), K_TAB); + break; + case K_CTRL_UP: + dispatch_e_scroll (win (), K_UP); + break; + case K_CTRL_DOWN: + dispatch_e_scroll (win (), K_DOWN); + break; + case K_ALT_LEFT: + dispatch_e_scroll (win (), K_LEFT); + break; + case K_ALT_RIGHT: + dispatch_e_scroll (win (), K_RIGHT); + break; + case K_UP: + case K_SHIFT_UP: + _need_update = FALSE; + if (key == K_SHIFT_UP) { - erase_point (); - check_link (); - switch (key) - { - case K_PREV: - dispatch_e_scroll (win (), K_PREV); - break; - case K_NEXT: - dispatch_e_scroll (win (), K_NEXT); - break; - case K_WRIGHT: - dispatch_e_scroll (win (), K_BTAB); - break; - case K_WLEFT: - dispatch_e_scroll (win (), K_TAB); - break; - case K_CTRL_UP: - dispatch_e_scroll (win (), K_UP); - break; - case K_CTRL_DOWN: - dispatch_e_scroll (win (), K_DOWN); - break; - case K_ALT_LEFT: - dispatch_e_scroll (win (), K_LEFT); - break; - case K_ALT_RIGHT: - dispatch_e_scroll (win (), K_RIGHT); - break; - case K_UP: - case K_SHIFT_UP: - _need_update = FALSE; - if (key == K_SHIFT_UP) - { - if (need_paint_sel (FALSE)) - erase_selection (); - if (!_selecting) - { - _sel_start = _point; - _selecting = TRUE; - } - } - if (_point.y > 0l) - { - if (_point.y == origin ().y) - { - if (need_paint_sel ()) - erase_selection (); - update_thumb (origin ().x, --_point.y); - _need_scroll = down; - } - else - _point.y--; - if (key == K_SHIFT_UP) - { - _sel_end = _point; - _isselection = TRUE; - } - } - else - beep (); - break; - case K_LEFT: - case K_SHIFT_LEFT: - _need_update = FALSE; - if (_point.x > 0l) - { - if (key == K_SHIFT_LEFT) - { - if (need_paint_sel (FALSE)) - erase_selection (); - if (!_selecting) - { - _sel_start = _point; - _selecting = TRUE; - } - } - if (_point.x == origin ().x) - { - _need_update = FALSE; - if (need_paint_sel (FALSE)) - erase_selection (); - update_thumb (--_point.x, origin ().y); - _need_scroll = right; - } - else - _point.x--; - if (key == K_SHIFT_LEFT) - { - _sel_end = _point; - _isselection = TRUE; - } - } - else - beep (); - break; - case K_DOWN: - case K_SHIFT_DOWN: - _need_update = FALSE; - if (_point.y < (_txt.lines () - 1)) - { - if (key == K_SHIFT_DOWN) - { - if (need_paint_sel (FALSE)) - erase_selection (); - if (!_selecting) - { - _sel_start = _point; - _selecting = TRUE; - } - } - if (_point.y == origin ().y + _textrows - 1) - { - if (need_paint_sel ()) - erase_selection (); -// check_link(); - update_thumb (origin ().x, (++_point.y) - _textrows + 1); - _need_scroll = up; - } - else - _point.y++; - if (key == K_SHIFT_DOWN) - { - _sel_end = _point; - _isselection = TRUE; - } - } - else - beep (); - break; - case K_RIGHT: - case K_SHIFT_RIGHT: - _need_update = FALSE; - if (_point.x < 256) - { - if (key == K_SHIFT_RIGHT) - { - if (need_paint_sel (FALSE)) - erase_selection (); - if (!_selecting) - { - _sel_start = _point; - _selecting = TRUE; - } - } - if (_point.x == (origin ().x + _textcolumns - 1)) - { - if (need_paint_sel (FALSE)) - erase_selection (); -// check_link(); - update_thumb ((++_point.x) - _textcolumns + 1l, origin ().y); - _need_scroll = left; - } - else - _point.x++; - if (key == K_SHIFT_RIGHT) - { - _sel_end = _point; - _isselection = TRUE; - } - } - else - beep (); - break; - default: - break; - } - if (_need_scroll != none) - { - _need_update = FALSE; - scroll tmp = _need_scroll; - _need_scroll = none; - shift_screen (tmp); - } - if (_isselection) - display_selection (); - check_link (&_point); - force_update (); + if (need_paint_sel (FALSE)) + erase_selection (); + if (!_selecting) + { + _sel_start = _point; + _selecting = TRUE; + } } + if (_point.y > 0l) + { + if (_point.y == origin ().y) + { + if (need_paint_sel ()) + erase_selection (); + update_thumb (origin ().x, --_point.y); + _need_scroll = down; + } + else + _point.y--; + if (key == K_SHIFT_UP) + { + _sel_end = _point; + _isselection = TRUE; + } + } + else + beep (); + break; + case K_LEFT: + case K_SHIFT_LEFT: + _need_update = FALSE; + if (_point.x > 0l) + { + if (key == K_SHIFT_LEFT) + { + if (need_paint_sel (FALSE)) + erase_selection (); + if (!_selecting) + { + _sel_start = _point; + _selecting = TRUE; + } + } + if (_point.x == origin ().x) + { + _need_update = FALSE; + if (need_paint_sel (FALSE)) + erase_selection (); + update_thumb (--_point.x, origin ().y); + _need_scroll = right; + } + else + _point.x--; + if (key == K_SHIFT_LEFT) + { + _sel_end = _point; + _isselection = TRUE; + } + } + else + beep (); + break; + case K_DOWN: + case K_SHIFT_DOWN: + _need_update = FALSE; + if (_point.y < (_txt.lines () - 1)) + { + if (key == K_SHIFT_DOWN) + { + if (need_paint_sel (FALSE)) + erase_selection (); + if (!_selecting) + { + _sel_start = _point; + _selecting = TRUE; + } + } + if (_point.y == origin ().y + _textrows - 1) + { + if (need_paint_sel ()) + erase_selection (); + // check_link(); + update_thumb (origin ().x, (++_point.y) - _textrows + 1); + _need_scroll = up; + } + else + _point.y++; + if (key == K_SHIFT_DOWN) + { + _sel_end = _point; + _isselection = TRUE; + } + } + else + beep (); + break; + case K_RIGHT: + case K_SHIFT_RIGHT: + _need_update = FALSE; + if (_point.x < 256) + { + if (key == K_SHIFT_RIGHT) + { + if (need_paint_sel (FALSE)) + erase_selection (); + if (!_selecting) + { + _sel_start = _point; + _selecting = TRUE; + } + } + if (_point.x == (origin ().x + _textcolumns - 1)) + { + if (need_paint_sel (FALSE)) + erase_selection (); + // check_link(); + update_thumb ((++_point.x) - _textcolumns + 1l, origin ().y); + _need_scroll = left; + } + else + _point.x++; + if (key == K_SHIFT_RIGHT) + { + _sel_end = _point; + _isselection = TRUE; + } + } + else + beep (); break; default: break; } -return TWindow ::on_key (key); + if (_need_scroll != none) + { + _need_update = FALSE; + scroll tmp = _need_scroll; + _need_scroll = none; + shift_screen (tmp); + } + if (_isselection) + display_selection (); + check_link (&_point); + force_update (); + } + break; +default: + break; +} + return TWindow ::on_key (key); } bool TViswin :: @@ -1745,39 +1745,39 @@ call_editor () bool ok = FALSE; if (!editor.empty ()) + { + TString newfilename; + + static FILE_SPEC fs; + get_default_dir (&fs.dir); + strcpy (fs.type, "txt"); + save_dir (); + if (save_file_dlg (&fs, "Salva il file con il nome:") == FL_OK) { - TString newfilename; + restore_dir (); + char path[256]; + dir_to_str (&fs.dir, path, sizeof (path)); + newfilename << path << '/' << fs.name; - static FILE_SPEC fs; - get_default_dir (&fs.dir); - strcpy (fs.type, "txt"); - save_dir (); - if (save_file_dlg (&fs, "Salva il file con il nome:") == FL_OK) - { - restore_dir (); - char path[256]; - dir_to_str (&fs.dir, path, sizeof (path)); - newfilename << path << '/' << fs.name; + TPoint p1, p2; + if (_isselection) + adjust_selection (p1, p2); - TPoint p1, p2; - if (_isselection) - adjust_selection (p1, p2); - - if (_txt.write (newfilename, _isselection ? &p1 : NULL, - _isselection ? &p2 : NULL)) - { - newfilename.insert (" ", 0); - newfilename.insert (editor, 0); - TExternal_app edit (newfilename); - if (edit.run (TRUE)) - beep (); - else - ok = TRUE; - } - } - else - restore_dir (); + if (_txt.write (newfilename, _isselection ? &p1 : NULL, + _isselection ? &p2 : NULL)) + { + newfilename.insert (" ", 0); + newfilename.insert (editor, 0); + TExternal_app edit (newfilename); + if (edit.run (TRUE)) + beep (); + else + ok = TRUE; + } } + else + restore_dir (); + } else warning_box ("Nessun editor specificato nei parametri studio"); return ok; @@ -1787,21 +1787,21 @@ void TViswin :: add_line (const char *l) { if (_isopen && !_frozen) - { - if (_txt.frozen ()) // error writing files + { + if (_txt.frozen ()) // error writing files - { - close_print (); - return; - } - _txt.append (l); - EVENT ev; - ev.type = E_USER; - ev.v.user.id = (_txt.lines () - origin ().y) <= _textrows ? - E_ADDLINE_ONSCREEN : E_ADDLINE; - dispatch_event (win (), &ev); - do_events (); + { + close_print (); + return; } + _txt.append (l); + EVENT ev; + ev.type = E_USER; + ev.v.user.id = (_txt.lines () - origin ().y) <= _textrows ? + E_ADDLINE_ONSCREEN : E_ADDLINE; + dispatch_event (win (), &ev); + do_events (); + } } void TViswin :: @@ -1814,17 +1814,17 @@ close_print () } TViswin ::TViswin (const char *fname, - const char *title, - bool editbutton, - bool printbutton, - bool linkbutton): - _filename (fname), _txt (fname, BUFFERSIZE), _islink (linkbutton), _isedit (editbutton), - _isprint (printbutton), _isbar (FALSE), _istimer (FALSE), _iscross (FALSE), - _isselection (FALSE), _sel_displayed (FALSE), _cross_displayed (FALSE), - _link_displayed (FALSE), _point_displayed (FALSE), _selecting (FALSE), - _scrolling (FALSE), _selflag (FALSE), _need_update (TRUE), _need_scroll (none), - _multiple (FALSE), -_frozen (FALSE) + const char *title, + bool editbutton, + bool printbutton, + bool linkbutton): + _filename (fname), _txt (fname, BUFFERSIZE), _islink (linkbutton), _isedit (editbutton), + _isprint (printbutton), _isbar (FALSE), _istimer (FALSE), _iscross (FALSE), + _isselection (FALSE), _sel_displayed (FALSE), _cross_displayed (FALSE), + _link_displayed (FALSE), _point_displayed (FALSE), _selecting (FALSE), + _scrolling (FALSE), _selflag (FALSE), _need_update (TRUE), _need_scroll (none), + _multiple (FALSE), + _frozen (FALSE) { if (title == NULL) title = (fname ? fname : "Anteprima di stampa"); @@ -1840,7 +1840,7 @@ _frozen (FALSE) const int alt = 20; RCT r; get_client_rect (TASK_WIN, &r); - int maxlarg = r.right / CHARX - 6; // Calculates max window width + int maxlarg = r.right / CHARX - 6; // Calculates max window width int maxalt = r.bottom / CHARY - 6; if (larg > maxlarg) @@ -1855,7 +1855,7 @@ _frozen (FALSE) #endif create (-1, -1, maxlarg, maxalt, title, - WSF_CLOSE | WSF_HSCROLL | WSF_VSCROLL | WSF_SIZE); + WSF_CLOSE | WSF_HSCROLL | WSF_VSCROLL | WSF_SIZE); set_opaque_text (TRUE); set_font (FF_FIXED); @@ -1864,23 +1864,23 @@ _frozen (FALSE) _buttons = 1; if (_isedit) - { - add_button (DLG_EDIT, DLG_EDIT_TITLE); - _buttons++; - } + { + add_button (DLG_EDIT, DLG_EDIT_TITLE); + _buttons++; + } if (_islink) - { - _link_button = add_button (DLG_LINK, DLG_LINK_TITLE); - _buttons++; - xvt_enable_control (_link_button, FALSE); - } + { + _link_button = add_button (DLG_LINK, DLG_LINK_TITLE); + _buttons++; + xvt_enable_control (_link_button, FALSE); + } if (_isprint) - { - add_button (DLG_PRINT, DLG_PRINT_TITLE); - _buttons++; - } + { + add_button (DLG_PRINT, DLG_PRINT_TITLE); + _buttons++; + } -//#if XVT_OS == XVT_OS_SCOUNIX + //#if XVT_OS == XVT_OS_SCOUNIX // maximize(); // #endif @@ -1902,13 +1902,13 @@ _frozen (FALSE) _formlen = MainApp ()->printer ().formlen (); for (i = 0; i < _links->items (); i++) - { - TToken_string & t = (TToken_string &) (*_links)[i]; - char f = *(t.get (1)); - char b = *(t.get (2)); - t.restart (); - _txt.set_hotspots (f, b); - } + { + TToken_string & t = (TToken_string &) (*_links)[i]; + char f = *(t.get (1)); + char b = *(t.get (2)); + t.restart (); + _txt.set_hotspots (f, b); + } _hotspots = &(_txt.hotspots ()); } diff --git a/include/window.cpp b/include/window.cpp index 028769b9b..5b6d5e0fa 100755 --- a/include/window.cpp +++ b/include/window.cpp @@ -1,728 +1,734 @@ -#include -#include -#include - -#define __WINDOW_CPP -#include -#include - - -#if XVT_OS == XVT_OS_WIN -#include -#endif - -/////////////////////////////////////////////////////////// -// TWindow_manager -/////////////////////////////////////////////////////////// -// @C -// Classe TWindow_manager -// -// @END - -class TWindow_manager -{ -// @DPRIV - enum { MAX_WIN = 4 }; // Max number of modal windows - - TWindow* _window[MAX_WIN]; // Stack of active windows - char _current; // Stack pointer - void menu_enable(bool) const; // Abilita o disabilita il menu della task window - -public: -// @FPUB - TWindow_manager(); // Costruttore - ~TWindow_manager() { destroy(); } - - void reg(TWindow* m); - // Registra la finestra corrente - void unreg(const TWindow* m); - // De-registra la finestra corrente - - TWindow* cur_win() const { return (_current < 0) ? NULL : _window[_current]; } // Ritorna il puntatore alla finestra corrente - void destroy(); - bool can_close() const { return _current < 1; } -} WinManager; - - -TWindow_manager::TWindow_manager() : _current(-1) -{} - - -void TWindow_manager::destroy() -{ - while (_current >= 0) - { - TWindow* w = cur_win(); - w->stop_run(K_QUIT); - w->close_modal(); - } -} - -// Dis/abilitazione del menu principale -HIDDEN void xvt_menu_enable(MENU_ITEM* m, bool on) -{ - while (m->tag) - { - switch(m->tag) - { - case M_FILE: - case MENU_FILE: - case MENU_EDIT: - case MENU_ALT_EDIT: - if (m->child) - xvt_menu_enable(m->child, on); - break; - case 65535: // Separator - case M_FILE_NEW: - case M_FILE_REVERT: - case M_FILE_QUIT: - case M_FILE_ABOUT: - case M_FILE_PRINT: - case M_FILE_PG_SETUP: - case (M_FILE+11): - case M_EDIT_SEARCH: - break; // Leave them as they are - default: - win_menu_enable(TASK_WIN, m->tag, on); - break; - } - m++; - } -} - - -void TWindow_manager::menu_enable(bool on) const -{ - MENU_ITEM *mi = win_menu_fetch(TASK_WIN); - xvt_menu_enable(mi, on); - win_update_menu_bar(TASK_WIN); - menu_free(mi); -} - - -void TWindow_manager::reg(TWindow* m) -{ - _current++; - CHECK(_current < MAX_WIN, "Too many windows"); - - switch (_current) - { - case 0 : menu_enable(FALSE); break; - case 1 : win_menu_enable(TASK_WIN, M_FILE_QUIT, FALSE); - default: _window[_current-1]->disable(); break; - } - - _window[_current] = m; -} - - -void TWindow_manager::unreg(const TWindow* m) -{ -#ifdef DBG - if (m != cur_win()) - { - error_box("You can unregister the current window only"); - return; - } -#endif - - _current--; - - if (_current < 0) - menu_enable(TRUE); - else - { - if (_current == 0) - win_menu_enable(TASK_WIN, M_FILE_QUIT, TRUE); - cur_win()->enable(); - } -} - - -void close_all_dialogs() -{ - WinManager.destroy(); -} - -bool can_close() -{ - return WinManager.can_close(); -} - - -/////////////////////////////////////////////////////////// -// TWindow -/////////////////////////////////////////////////////////// - -DRAW_CTOOLS TWindow::_ct; -bool TWindow::_ctools_saved; - - -TWindow::TWindow() - : _win(NULL_WIN), _open(FALSE), _modal(FALSE), - _running(FALSE), _lastkey(0) -{} - - -long TWindow::window_handler(WINDOW win, EVENT* ep) -{ - TWindow* w = (TWindow*)get_app_data(win); - CHECK(w != NULL, "Invalid window"); - w->handler(win, ep); - - return 0L; -} - - -WINDOW TWindow::create(short x, short y, short dx, short dy, - const char* title, long flags, WIN_TYPE wt, WINDOW parent) -{ - flags |= WSF_NO_MENUBAR; - - if (parent == NULL_WIN) parent = TASK_WIN; - if (parent == TASK_WIN) flags |= WSF_INVISIBLE; - - _win = xvt_create_window( - wt, - x, y, dx, dy, - title, parent, - flags, - window_handler, - PTR_LONG(this) - ); - - CHECK(_win, "Can't create a window"); - - return _win; -} - - -TWindow::~TWindow() -{ - if (_win != NULL_WIN) - { - close_window(_win); - _win = NULL_WIN; - } -} - - -void TWindow::open() -{ - CHECK(win() != NULL_WIN, "Can't open a NULL window"); - show_window(win(), _open = TRUE); - set_front_window(win()); -} - - -void TWindow::open_modal() -{ - set_modal(TRUE); - _open = TRUE; - open(); - - WinManager.reg(this); -} - - -void TWindow::close() -{ - CHECK(_win != NULL_WIN, "Can't close a NULL window"); - show_window(_win, _open = FALSE); -} - - -void TWindow::close_modal() -{ - WinManager.unreg(this); - - close(); - _open = FALSE; -} - -bool TWindow::stop_run(KEY key) -{ - _running = FALSE; - _lastkey = key; - return TRUE; -} - - -KEY TWindow::run() -{ - const bool was_open = is_open(); - - start_run(); - _running = TRUE; - - if (!was_open) open_modal(); - else open(); - - while (_running) - do_events(); - - if (!was_open) close_modal(); - - return last_key(); -} - -void TWindow::handler(WINDOW win, EVENT* ep) -{ - switch(ep->type) - { - case E_CLOSE: - stop_run(K_ESC); - break; - case E_UPDATE: - { - clear_window(win, NORMAL_BACK_COLOR); - update(); - } - break; - case E_CHAR: - on_key(e_char_to_key(ep)); - break; - case E_DESTROY: - _win = NULL_WIN; - break; - default: - break; - } -} - - -TPoint TWindow::size() const -{ - RCT r; - get_client_rect(_win ? _win : TASK_WIN, &r); - return TPoint(r.right / CHARX, r.bottom / CHARY); -} - -WINDOW TWindow::parent() const -{ - return get_parent(win()); -} - - -void TWindow::set_focus() -{ - if (_win) - set_front_window(_win); -} - - -void TWindow::iconize() const -{ -#if XVTWS != WMWS - HWND hwnd = (HWND)get_value(win(), ATTR_NATIVE_WINDOW); - ShowWindow(hwnd, SW_MINIMIZE); -#endif -} - -void TWindow::maximize() const -{ -#if XVTWS != WMWS - HWND hwnd = (HWND)get_value(win(), ATTR_NATIVE_WINDOW); - ShowWindow(hwnd, SW_SHOWMAXIMIZED); -#else - RCT r; set_rect(&r, 1,1,79,23); - move_window(win(),&r); -#endif -} - -void TWindow::enable(bool on) const -{ - enable_window(win(), on); -} - - -void TWindow::set_caption(const char* title) -{ - set_title(win(), (char*)title); -} - - -const char* TWindow::get_caption() const -{ - char* title = &__tmp_string[512]; - get_title(win(), title, 80); - return title; -} - - -void TWindow::force_update() -{ - if (win() != NULL_WIN) - invalidate_rect(win(), NULL); -} - - -bool TWindow::save_ctools() -{ - if (_ctools_saved == FALSE) - { - win_get_draw_ctools(win(), &_ct); - return _ctools_saved = TRUE; - } - return FALSE; -} - - -bool TWindow::restore_ctools() -{ - if (_ctools_saved) - { - win_set_draw_ctools(win(), &_ct); - _ctools_saved = FALSE; - return TRUE; - } - return FALSE; -} - - -void TWindow::set_color(COLOR fore, COLOR back) -{ - win_set_fore_color(win(), fore); - win_set_back_color(win(), back); -} - - -void TWindow::set_pen(COLOR color, int width, PAT_STYLE pat, PEN_STYLE style) -{ - CPEN pen; - - pen.width = width; - pen.pat = pat; - pen.style = style; - pen.color = color; - - win_set_cpen(win(), &pen); -} - - -void TWindow::hide_pen() -{ - win_set_std_cpen(win(), TL_PEN_HOLLOW); -} - - -void TWindow::set_brush(COLOR color, PAT_STYLE pat) -{ - CBRUSH brush = { pat, color }; - win_set_cbrush(win(), &brush); -} - - -void TWindow::hide_brush() -{ - CBRUSH brush = { PAT_HOLLOW, COLOR_WHITE }; - win_set_cbrush(win(), &brush); -} - - -HIDDEN void swap(short& a, short& b) -{ - short tmp = a; - a = b; - b = tmp; -} - - -void TWindow::frame(short left, short top, short right, short bottom, - int flag) -{ - if (left > right) swap(left, right); - if (top > bottom) swap(top, bottom); - - const bool saved = flag && save_ctools(); - - if (flag & 1) hide_pen(); - if (flag & 2) hide_brush(); - if (flag & 4) - { - set_mode(M_XOR); - set_brush(COLOR_BLACK); // Needed for Windows - } - - - const PNT f = log2dev(left,top); - const PNT t = log2dev(right,bottom); - RCT r; - r.top = f.v; r.left = f.h; - r.bottom = t.v; r.right = t.h; - -#if XVTWS != WMWS - if (flag & 2) - { - r.left += CHARX>>1; r.top += CHARY>>1; - r.right-= CHARX>>1; r.bottom -= CHARY>>1; - } -#endif - - win_draw_rect(win(), &r); - - if (saved) restore_ctools(); -} - - -void TWindow::rect(short left, short top, short right, short bottom) -{ - frame(left, top, right, bottom, 2); -} - - -void TWindow::bar(short left, short top, short right, short bottom) -{ - frame(left, top, right, bottom, 1); -} - - -void TWindow::invert_bar(short left, short top, short right, short bottom) -{ - frame(left, top, right, bottom, 5); -} - -void TWindow::set_opaque_text(bool o) -{ - DRAW_CTOOLS ct; - win_get_draw_ctools(win(), &ct); - ct.opaque_text = o; - win_set_draw_ctools(win(), &ct); -} - -void TWindow::set_font(int family, int style, int dim) -{ - xvt_set_font(win(), family, style, dim); -} - -PNT TWindow::log2dev(long x, long y) const -{ - PNT pnt; - pnt.h = (int)x*CHARX; - pnt.v = (int)y*CHARY; - - return pnt; -} - -TPoint TWindow::dev2log(const PNT& p) const -{ - TPoint pnt(p.h / CHARX, p.v / CHARY); - return pnt; -} - - -void TWindow::stringat(short x, short y, const char* str) -{ - PNT pnt = log2dev(x,y); -#if XVTWS != WMVS - pnt.v += CHARY-3; -#endif - - win_draw_text(win(), pnt.h, pnt.v, (char *)str, -1); -} - -void TWindow::printat(short x, short y, const char* fmt, ...) -{ - va_list argptr; - va_start(argptr, fmt); - vsprintf(__tmp_string, fmt, argptr); - va_end(argptr); - stringat(x, y, __tmp_string); -} - - -void TWindow::line(short x0, short y0, short x1, short y1) -{ - PNT f = log2dev(x0,y0); - PNT t = log2dev(x1,y1); - - if (f.h == 0) f.h = -CHARX; else f.h += CHARX>>1; - if (f.v == 0) f.v = -CHARY; else f.v += CHARY>>1; - if (t.h == 0) t.h = -CHARX; else t.h += CHARX>>1; - if (t.v == 0) t.v = -CHARY; else t.v += CHARY>>1; - - win_move_to(_win, f); - win_draw_line(_win, t); -} - -void TWindow::icon(short x0, short y0, int iconid) -{ -#if XVTWS == WMWS - bar(x0, y0, x0+1, y0+1); -#else - PNT f = log2dev(x0,y0); - if (iconid < 0) iconid = ICON_RSRC; - win_draw_icon(win(), f.h, f.v, iconid); -#endif -} - -/////////////////////////////////////////////////////////// -// TTemp_window -/////////////////////////////////////////////////////////// - -TTemp_window::TTemp_window(WINDOW w) -{ - set_win(w); -} - -TTemp_window::~TTemp_window() -{ - set_win(NULL_WIN); // I don't want to be closed! -} - -/////////////////////////////////////////////////////////// -// TScroll_window -/////////////////////////////////////////////////////////// - -TScroll_window::TScroll_window() - : _origin(0, 0), _max(0, 0), _shift(0), _autoscroll(TRUE), - _has_hscroll(TRUE), _has_vscroll(TRUE) -{ -} - -WINDOW TScroll_window::create(short x, short y, short dx, short dy, - const char* title, long flags, WIN_TYPE wt, WINDOW parent) -{ - _has_hscroll = (flags & WSF_HSCROLL) != 0; - _has_vscroll = (flags & WSF_VSCROLL) != 0 ; - return TWindow::create(x, y, dx, dy, title, flags, wt, parent); -} - -PNT TScroll_window::log2dev(long x, long y) const -{ - if (_autoscroll) - { - x -= _origin.x; - y -= _origin.y >> _shift; - } - return TWindow::log2dev(x,y); -} - - -void TScroll_window::set_scroll_max(long maxx, long maxy) -{ - if (_has_hscroll && maxx >= 0) - { - _max.x = maxx; - set_scroll_range(win(), HSCROLL, 0, int(maxx)); - } - if (_has_vscroll && maxy >= 0) - { - _shift = 0; - while ((maxy >> _shift) > 0x7FFF) _shift++; - _max.y = maxy; - set_scroll_range(win(), VSCROLL, 0, int(maxy >> _shift)); - } -} - -void TScroll_window::update_thumb(long x, long y) -{ - if (x >= 0 && x <= _max.x) _origin.x = x; - if (y >= 0 && y <= _max.y) _origin.y = y; - - if (_has_hscroll) - set_scroll_pos(win(), HSCROLL, int(_origin.x)); - if (_has_vscroll) - set_scroll_pos(win(), VSCROLL, int(_origin.y >> _shift)); -} - -void TScroll_window::handler(WINDOW win, EVENT* ep) -{ - bool up = FALSE; - - switch (ep->type) - { - case E_HSCROLL: - case E_VSCROLL: - { - long& pos = (ep->type == E_HSCROLL) ? _origin.x : _origin.y; - long& max = (ep->type == E_HSCROLL) ? _max.x : _max.y; - short pag = (ep->type == E_HSCROLL) ? columns()/2+1 : rows()/2+1; - switch(ep->v.scroll.what) - { - case SC_PAGE_UP: - pos -= pag; - up = TRUE; - break; - case SC_LINE_UP: - pos--; - up = TRUE; - break; - case SC_PAGE_DOWN: - pos += pag; - up = TRUE; - break; - case SC_LINE_DOWN: - pos++; - up = TRUE; - break; - case SC_THUMB: - pos = ep->v.scroll.pos; - up = TRUE; - break; - default: - break; - } - if (pos < 0) pos = 0; - if (pos > max) pos = max; - } - break; - default: - break; - } - - if (up) - { - update_thumb(); - force_update(); - } - - TWindow::handler(win, ep); -} - -bool TScroll_window::on_key(KEY key) -{ - switch(key) - { - case K_LHOME: - update_thumb(0,0); - force_update(); - break; - case K_LEND: - update_thumb(0,range().y); - force_update(); - break; - case K_TAB: - update_thumb(origin().x+8); - force_update(); - break; - case K_BTAB: - { - long x = origin().x-8; - if (x < 0) x = 0; - update_thumb(x); - force_update(); - } - break; - case K_UP: - case K_DOWN: - case K_PREV: - case K_NEXT: - case K_LEFT: - case K_RIGHT: - dispatch_e_scroll(win(), key); - break; - default: - break; - } - - return TWindow::on_key(key); -} - -void TWindow::clear(COLOR color) - -{ clear_window(win(), color); } - -void TWindow::set_mode(DRAW_MODE mode) - -{ win_set_draw_mode(win(), mode); } +#include +#include +#include + +#define __WINDOW_CPP +#include +#include + + +#if XVT_OS == XVT_OS_WIN +#include +#endif + +/////////////////////////////////////////////////////////// +// TWindow_manager +/////////////////////////////////////////////////////////// +// @C +// Classe TWindow_manager +// +// @END + +class TWindow_manager +{ + // @DPRIV + enum { MAX_WIN = 4 }; // Max number of modal windows + + TWindow* _window[MAX_WIN]; // Stack of active windows + char _current; // Stack pointer + void menu_enable(bool) const; // Abilita o disabilita il menu della task window + +public: + // @FPUB + TWindow_manager(); // Costruttore + ~TWindow_manager() { destroy(); } + + void reg(TWindow* m); + // Registra la finestra corrente + void unreg(const TWindow* m); + // De-registra la finestra corrente + + TWindow* cur_win() const { return (_current < 0) ? NULL : _window[_current]; } // Ritorna il puntatore alla finestra corrente + void destroy(); + bool can_close() const { return _current < 1; } +} WinManager; + + +TWindow_manager::TWindow_manager() : _current(-1) +{} + + +void TWindow_manager::destroy() +{ + while (_current >= 0) + { + TWindow* w = cur_win(); + w->stop_run(K_QUIT); + w->close_modal(); + } +} + +// Dis/abilitazione del menu principale +HIDDEN void xvt_menu_enable(MENU_ITEM* m, bool on) +{ + while (m->tag) + { + switch(m->tag) + { + case M_FILE: + case MENU_FILE: + case MENU_EDIT: + case MENU_ALT_EDIT: + if (m->child) + xvt_menu_enable(m->child, on); + break; + case 65535: // Separator + case M_FILE_NEW: + case M_FILE_REVERT: + case M_FILE_QUIT: + case M_FILE_ABOUT: + case M_FILE_PRINT: + case M_FILE_PG_SETUP: + case (M_FILE+11): + case M_EDIT_SEARCH: + break; // Leave them as they are + default: + win_menu_enable(TASK_WIN, m->tag, on); + break; + } + m++; + } +} + + +void TWindow_manager::menu_enable(bool on) const +{ + MENU_ITEM *mi = win_menu_fetch(TASK_WIN); + xvt_menu_enable(mi, on); + win_update_menu_bar(TASK_WIN); + menu_free(mi); +} + + +void TWindow_manager::reg(TWindow* m) +{ + _current++; + CHECK(_current < MAX_WIN, "Too many windows"); + + switch (_current) + { + case 0 : menu_enable(FALSE); break; + case 1 : win_menu_enable(TASK_WIN, M_FILE_QUIT, FALSE); + default: _window[_current-1]->disable(); break; + } + + _window[_current] = m; +} + + +void TWindow_manager::unreg(const TWindow* m) +{ +#ifdef DBG + if (m != cur_win()) + { + error_box("You can unregister the current window only"); + return; + } +#endif + + _current--; + + if (_current < 0) + menu_enable(TRUE); + else + { + if (_current == 0) + win_menu_enable(TASK_WIN, M_FILE_QUIT, TRUE); + cur_win()->enable(); + } +} + + +void close_all_dialogs() +{ + WinManager.destroy(); +} + +bool can_close() +{ + return WinManager.can_close(); +} + +WINDOW cur_win() +{ + const TWindow* w = WinManager.cur_win(); + return w ? w->win() : NULL_WIN; +} + + +/////////////////////////////////////////////////////////// +// TWindow +/////////////////////////////////////////////////////////// + +DRAW_CTOOLS TWindow::_ct; +bool TWindow::_ctools_saved; + + +TWindow::TWindow() +: _win(NULL_WIN), _open(FALSE), _modal(FALSE), + _running(FALSE), _lastkey(0) +{} + + +long TWindow::window_handler(WINDOW win, EVENT* ep) +{ + TWindow* w = (TWindow*)get_app_data(win); + CHECK(w != NULL, "Invalid window"); + w->handler(win, ep); + + return 0L; +} + + +WINDOW TWindow::create(short x, short y, short dx, short dy, + const char* title, long flags, WIN_TYPE wt, WINDOW parent) +{ + flags |= WSF_NO_MENUBAR; + + if (parent == NULL_WIN) parent = TASK_WIN; + if (parent == TASK_WIN) flags |= WSF_INVISIBLE; + + _win = xvt_create_window( + wt, + x, y, dx, dy, + title, parent, + flags, + window_handler, + PTR_LONG(this) + ); + + CHECK(_win, "Can't create a window"); + + return _win; +} + + +TWindow::~TWindow() +{ + if (_win != NULL_WIN) + { + close_window(_win); + _win = NULL_WIN; + } +} + + +void TWindow::open() +{ + CHECK(win() != NULL_WIN, "Can't open a NULL window"); + show_window(win(), _open = TRUE); + set_front_window(win()); +} + + +void TWindow::open_modal() +{ + set_modal(TRUE); + _open = TRUE; + open(); + + WinManager.reg(this); +} + + +void TWindow::close() +{ + CHECK(_win != NULL_WIN, "Can't close a NULL window"); + show_window(_win, _open = FALSE); +} + + +void TWindow::close_modal() +{ + WinManager.unreg(this); + + close(); + _open = FALSE; +} + +bool TWindow::stop_run(KEY key) +{ + _running = FALSE; + _lastkey = key; + return TRUE; +} + + +KEY TWindow::run() +{ + const bool was_open = is_open(); + + start_run(); + _running = TRUE; + + if (!was_open) open_modal(); + else open(); + + while (_running) + do_events(); + + if (!was_open) close_modal(); + + return last_key(); +} + +void TWindow::handler(WINDOW win, EVENT* ep) +{ + switch(ep->type) + { + case E_CLOSE: + stop_run(K_ESC); + break; + case E_UPDATE: + { + clear_window(win, NORMAL_BACK_COLOR); + update(); + } + break; + case E_CHAR: + on_key(e_char_to_key(ep)); + break; + case E_DESTROY: + _win = NULL_WIN; + break; + default: + break; + } +} + + +TPoint TWindow::size() const +{ + RCT r; + get_client_rect(_win ? _win : TASK_WIN, &r); + return TPoint(r.right / CHARX, r.bottom / CHARY); +} + +WINDOW TWindow::parent() const +{ + return get_parent(win()); +} + + +void TWindow::set_focus() +{ + if (_win) + set_front_window(_win); +} + + +void TWindow::iconize() const +{ +#if XVTWS != WMWS + HWND hwnd = (HWND)get_value(win(), ATTR_NATIVE_WINDOW); + ShowWindow(hwnd, SW_MINIMIZE); +#endif +} + +void TWindow::maximize() const +{ +#if XVTWS != WMWS + HWND hwnd = (HWND)get_value(win(), ATTR_NATIVE_WINDOW); + ShowWindow(hwnd, SW_SHOWMAXIMIZED); +#else + RCT r; set_rect(&r, 1,1,79,23); + move_window(win(),&r); +#endif +} + +void TWindow::enable(bool on) const +{ + enable_window(win(), on); +} + + +void TWindow::set_caption(const char* title) +{ + set_title(win(), (char*)title); +} + + +const char* TWindow::get_caption() const +{ + char* title = &__tmp_string[512]; + get_title(win(), title, 80); + return title; +} + + +void TWindow::force_update() +{ + if (win() != NULL_WIN) + invalidate_rect(win(), NULL); +} + + +bool TWindow::save_ctools() +{ + if (_ctools_saved == FALSE) + { + win_get_draw_ctools(win(), &_ct); + return _ctools_saved = TRUE; + } + return FALSE; +} + + +bool TWindow::restore_ctools() +{ + if (_ctools_saved) + { + win_set_draw_ctools(win(), &_ct); + _ctools_saved = FALSE; + return TRUE; + } + return FALSE; +} + + +void TWindow::set_color(COLOR fore, COLOR back) +{ + win_set_fore_color(win(), fore); + win_set_back_color(win(), back); +} + + +void TWindow::set_pen(COLOR color, int width, PAT_STYLE pat, PEN_STYLE style) +{ + CPEN pen; + + pen.width = width; + pen.pat = pat; + pen.style = style; + pen.color = color; + + win_set_cpen(win(), &pen); +} + + +void TWindow::hide_pen() +{ + win_set_std_cpen(win(), TL_PEN_HOLLOW); +} + + +void TWindow::set_brush(COLOR color, PAT_STYLE pat) +{ + CBRUSH brush = { pat, color }; + win_set_cbrush(win(), &brush); +} + + +void TWindow::hide_brush() +{ + CBRUSH brush = { PAT_HOLLOW, COLOR_WHITE }; + win_set_cbrush(win(), &brush); +} + + +HIDDEN void swap(short& a, short& b) +{ + short tmp = a; + a = b; + b = tmp; +} + + +void TWindow::frame(short left, short top, short right, short bottom, + int flag) +{ + if (left > right) swap(left, right); + if (top > bottom) swap(top, bottom); + + const bool saved = flag && save_ctools(); + + if (flag & 1) hide_pen(); + if (flag & 2) hide_brush(); + if (flag & 4) + { + set_mode(M_XOR); + set_brush(COLOR_BLACK); // Needed for Windows + } + + + const PNT f = log2dev(left,top); + const PNT t = log2dev(right,bottom); + RCT r; + r.top = f.v; r.left = f.h; + r.bottom = t.v; r.right = t.h; + +#if XVTWS != WMWS + if (flag & 2) + { + r.left += CHARX>>1; r.top += CHARY>>1; + r.right-= CHARX>>1; r.bottom -= CHARY>>1; + } +#endif + + win_draw_rect(win(), &r); + + if (saved) restore_ctools(); +} + + +void TWindow::rect(short left, short top, short right, short bottom) +{ + frame(left, top, right, bottom, 2); +} + + +void TWindow::bar(short left, short top, short right, short bottom) +{ + frame(left, top, right, bottom, 1); +} + + +void TWindow::invert_bar(short left, short top, short right, short bottom) +{ + frame(left, top, right, bottom, 5); +} + +void TWindow::set_opaque_text(bool o) +{ + DRAW_CTOOLS ct; + win_get_draw_ctools(win(), &ct); + ct.opaque_text = o; + win_set_draw_ctools(win(), &ct); +} + +void TWindow::set_font(int family, int style, int dim) +{ + xvt_set_font(win(), family, style, dim); +} + +PNT TWindow::log2dev(long x, long y) const +{ + PNT pnt; + pnt.h = (int)x*CHARX; + pnt.v = (int)y*CHARY; + + return pnt; +} + +TPoint TWindow::dev2log(const PNT& p) const +{ + TPoint pnt(p.h / CHARX, p.v / CHARY); + return pnt; +} + + +void TWindow::stringat(short x, short y, const char* str) +{ + PNT pnt = log2dev(x,y); +#if XVTWS != WMVS + pnt.v += CHARY-3; +#endif + + win_draw_text(win(), pnt.h, pnt.v, (char *)str, -1); +} + +void TWindow::printat(short x, short y, const char* fmt, ...) +{ + va_list argptr; + va_start(argptr, fmt); + vsprintf(__tmp_string, fmt, argptr); + va_end(argptr); + stringat(x, y, __tmp_string); +} + + +void TWindow::line(short x0, short y0, short x1, short y1) +{ + PNT f = log2dev(x0,y0); + PNT t = log2dev(x1,y1); + + if (f.h == 0) f.h = -CHARX; else f.h += CHARX>>1; + if (f.v == 0) f.v = -CHARY; else f.v += CHARY>>1; + if (t.h == 0) t.h = -CHARX; else t.h += CHARX>>1; + if (t.v == 0) t.v = -CHARY; else t.v += CHARY>>1; + + win_move_to(_win, f); + win_draw_line(_win, t); +} + +void TWindow::icon(short x0, short y0, int iconid) +{ +#if XVTWS == WMWS + bar(x0, y0, x0+1, y0+1); +#else + PNT f = log2dev(x0,y0); + if (iconid < 0) iconid = ICON_RSRC; + win_draw_icon(win(), f.h, f.v, iconid); +#endif +} + +/////////////////////////////////////////////////////////// +// TTemp_window +/////////////////////////////////////////////////////////// + +TTemp_window::TTemp_window(WINDOW w) +{ + set_win(w); +} + +TTemp_window::~TTemp_window() +{ + set_win(NULL_WIN); // I don't want to be closed! +} + +/////////////////////////////////////////////////////////// +// TScroll_window +/////////////////////////////////////////////////////////// + +TScroll_window::TScroll_window() +: _origin(0, 0), _max(0, 0), _shift(0), _autoscroll(TRUE), + _has_hscroll(TRUE), _has_vscroll(TRUE) +{ +} + +WINDOW TScroll_window::create(short x, short y, short dx, short dy, + const char* title, long flags, WIN_TYPE wt, WINDOW parent) +{ + _has_hscroll = (flags & WSF_HSCROLL) != 0; + _has_vscroll = (flags & WSF_VSCROLL) != 0 ; + return TWindow::create(x, y, dx, dy, title, flags, wt, parent); +} + +PNT TScroll_window::log2dev(long x, long y) const +{ + if (_autoscroll) + { + x -= _origin.x; + y -= _origin.y >> _shift; + } + return TWindow::log2dev(x,y); +} + + +void TScroll_window::set_scroll_max(long maxx, long maxy) +{ + if (_has_hscroll && maxx >= 0) + { + _max.x = maxx; + set_scroll_range(win(), HSCROLL, 0, int(maxx)); + } + if (_has_vscroll && maxy >= 0) + { + _shift = 0; + while ((maxy >> _shift) > 0x7FFF) _shift++; + _max.y = maxy; + set_scroll_range(win(), VSCROLL, 0, int(maxy >> _shift)); + } +} + +void TScroll_window::update_thumb(long x, long y) +{ + if (x >= 0 && x <= _max.x) _origin.x = x; + if (y >= 0 && y <= _max.y) _origin.y = y; + + if (_has_hscroll) + set_scroll_pos(win(), HSCROLL, int(_origin.x)); + if (_has_vscroll) + set_scroll_pos(win(), VSCROLL, int(_origin.y >> _shift)); +} + +void TScroll_window::handler(WINDOW win, EVENT* ep) +{ + bool up = FALSE; + + switch (ep->type) + { + case E_HSCROLL: + case E_VSCROLL: + { + long& pos = (ep->type == E_HSCROLL) ? _origin.x : _origin.y; + long& max = (ep->type == E_HSCROLL) ? _max.x : _max.y; + short pag = (ep->type == E_HSCROLL) ? columns()/2+1 : rows()/2+1; + switch(ep->v.scroll.what) + { + case SC_PAGE_UP: + pos -= pag; + up = TRUE; + break; + case SC_LINE_UP: + pos--; + up = TRUE; + break; + case SC_PAGE_DOWN: + pos += pag; + up = TRUE; + break; + case SC_LINE_DOWN: + pos++; + up = TRUE; + break; + case SC_THUMB: + pos = ep->v.scroll.pos; + up = TRUE; + break; + default: + break; + } + if (pos < 0) pos = 0; + if (pos > max) pos = max; + } + break; +default: + break; +} + + if (up) + { + update_thumb(); + force_update(); + } + + TWindow::handler(win, ep); +} + +bool TScroll_window::on_key(KEY key) +{ + switch(key) + { + case K_LHOME: + update_thumb(0,0); + force_update(); + break; + case K_LEND: + update_thumb(0,range().y); + force_update(); + break; + case K_TAB: + update_thumb(origin().x+8); + force_update(); + break; + case K_BTAB: + { + long x = origin().x-8; + if (x < 0) x = 0; + update_thumb(x); + force_update(); + } + break; + case K_UP: + case K_DOWN: + case K_PREV: + case K_NEXT: + case K_LEFT: + case K_RIGHT: + dispatch_e_scroll(win(), key); + break; + default: + break; + } + + return TWindow::on_key(key); +} + +void TWindow::clear(COLOR color) + +{ clear_window(win(), color); } + +void TWindow::set_mode(DRAW_MODE mode) + +{ win_set_draw_mode(win(), mode); } diff --git a/include/window.h b/include/window.h index 4447c8351..431fe86f4 100755 --- a/include/window.h +++ b/include/window.h @@ -1,215 +1,216 @@ -#ifndef __WINDOW_H -#define __WINDOW_H - -#ifndef __XVTILITY_H -#include -#endif - -void close_all_dialogs(); -bool can_close(); - -// @C -// Classe TPoint -// @END - -// @N -// Punto dello schermo -// @END - -struct TPoint -{ -// @DPUB - long x, y; - // Coordinate - -// @FPUB - TPoint(long sx = 0, long sy = 0) : x(sx), y(sy) {} -// Costruttore - TPoint(PNT pnt) : x(pnt.h/CHARX), y(pnt.v/CHARY) {} - void set(long sx, long sy) { x = sx; y = sy; } - void set(PNT pnt) { x = pnt.h/CHARX; y = pnt.v/CHARY; } - TPoint& operator= (PNT pnt) { set(pnt); return *this; } - TPoint& operator= (TPoint pnt) { set(pnt.x,pnt.y); return *this; } - bool operator ==(const TPoint& p) { return p.x == x && p.y == y; } - bool operator !=(const TPoint& p) { return p.x != x || p.y != y; } -}; - - -// @C -// Classe TWindow -// -// @END - -class TWindow -{ - -friend class TWindow_manager; - -// @DPRIV -static DRAW_CTOOLS _ct; // Set di drawing tools (xvttype.h) -static bool _ctools_saved; // E' stata salvata _ct ? - - WINDOW _win; // Descrittore finestra - KEY _lastkey; // Tasto di uscita - -// @FPRIV - bool save_ctools(); // Compila la struct _ct con i valori correnti - bool restore_ctools(); // Ripristina i valori DA _ct - -protected: -// @DPROT - bool _open : 1; // Se la finestra e' aperta - bool _modal : 1; // Se la finestra e' modale - bool _running : 1; // Se la finestra e' in esecuzione - -// @FPROT - 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) ; - - void set_win(WINDOW w) { _win = w; } // Usare con cautela - - void set_modal(bool m) { _modal = m; } // Modifica il flag _modal - - WINDOW parent() const; - - virtual void update() {} // E_UPDATE - virtual bool on_key(KEY) { return TRUE; } // E_CHAR - - virtual PNT log2dev(long x, long y) const; - virtual TPoint dev2log(const PNT& p) const; - -public: -// @FPUB - TWindow(); // Costruttore - virtual ~TWindow(); - - virtual void handler(WINDOW win, EVENT* ep); // Handler finestra - virtual void set_focus(); // Mette la finestra in primo piano - virtual WINDOW win() const { return _win; } // Ritorna il descrittore della finestra - - bool is_open() const { return _open; } // Ritorna _open - bool is_modal() const { return _modal; } // Ritorna _modal - bool is_running() const { return _running; } // Ritorna _running - - TPoint size() const; // Determina numero di righe e colonne nella finestra - short rows() const { return (short)size().y; }// Ritorna numero di righe - short columns() const { return (short)size().x; } // Ritorna numero di colonne - - virtual void start_run() {} - virtual bool stop_run(KEY key); - void force_update(); // Forza ridisegno della finestra - - virtual void open(); // Mostra la finestra - virtual void close(); // Nasconde la finestra - - void iconize() const; - void maximize() const; - virtual void enable(bool = TRUE) const; - void disable() const { enable(FALSE); } - - void open_modal(); // Mostra la finestra modale - void close_modal(); // Nasconde la finestra modale - - KEY run(); // Esegue la finestra - KEY last_key() const { return _lastkey; } // Ritorna l'ultimo tasto - - virtual void set_caption(const char* title); - virtual const char* get_caption() const; - - // Riempie la finestra con il colore in color - void clear(COLOR color); - - // Setta il draw mode - void set_mode(DRAW_MODE mode); - - // Setta il colore - void set_color(COLOR fore, COLOR back); - - // Setta opaque_text. Quando e' FALSE il testo viene scritto in modo trasparente - void set_opaque_text(bool o); - - // Sceglie penna con colore color eccetera - void set_pen(COLOR color, int width = 1, PAT_STYLE pat = PAT_SOLID, PEN_STYLE st = P_SOLID); - void hide_pen(); // Nasconde la penna - void hide_brush(); // Nasconde il pennello - void set_brush(COLOR color, PAT_STYLE = PAT_SOLID); // Sceglie pennello con colore color - void set_font(int family = FF_SYSTEM, int style = 0, int dim = 0); // Sceglie il font - -// Disegna un rettangolo con la possibilita' di settare la penna e il draw_mode - void frame(short left, short top, short right, short bottom, int flag); - -// Queste funzioni chiamano tutte frame con diversi flag - void rect(short left, short top, short right, short bottom); - void bar(short left, short top, short right, short bottom); - void invert_bar(short left, short top, short right, short bottom); - - void stringat(short x, short y, const char* str); - void printat(short x, short y, const char* fmt, ...); // Scrive un testo nella finestra alla posizione indicata - - void line(short x0, short y0, short x1, short y1); // Disegna una linea nella finestra - void icon(short x0, short y0, int iconid = -1); -}; - -class TTemp_window : public TWindow -{ -public: - TTemp_window(WINDOW w); - virtual ~TTemp_window(); -}; - -// @C -// Classe TScroll_window : public TWindow -// -// Finestra con scrollbar -// -// @END - -class TScroll_window : public TWindow -{ - -// @DPRIV - TPoint _origin; - TPoint _max; - short _shift; - - bool _autoscroll : 1; - bool _has_hscroll : 1; - bool _has_vscroll : 1; - -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 - - virtual PNT log2dev(long x, long y) const; - virtual bool on_key(KEY key); - -public: -// @FPUB - - TScroll_window(); - // Costruttore - - virtual void handler(WINDOW win, EVENT* ep); - - void set_scroll_max(long maxx, long maxy); - // Setta punto di massimo scroll - void update_thumb(long x = -1, long y = -1); - // Aggiorna la scrollbar - - void autoscroll(bool on) { _autoscroll = on; } - // Setta autoscroll - - bool autoscrolling() const { return _autoscroll; } - - const TPoint& origin() const { return _origin; } - // Ritorna punto origine - const TPoint& range() const { return _max; } - // Ritorna punto massimo -}; - -#endif // __WINDOW_H +#ifndef __WINDOW_H +#define __WINDOW_H + +#ifndef __XVTILITY_H +#include +#endif + +void close_all_dialogs(); +bool can_close(); +WINDOW cur_win(); + +// @C +// Classe TPoint +// @END + +// @N +// Punto dello schermo +// @END + +struct TPoint +{ + // @DPUB + long x, y; + // Coordinate + + // @FPUB + TPoint(long sx = 0, long sy = 0) : x(sx), y(sy) {} + // Costruttore + TPoint(PNT pnt) : x(pnt.h/CHARX), y(pnt.v/CHARY) {} + void set(long sx, long sy) { x = sx; y = sy; } + void set(PNT pnt) { x = pnt.h/CHARX; y = pnt.v/CHARY; } + TPoint& operator= (PNT pnt) { set(pnt); return *this; } + TPoint& operator= (TPoint pnt) { set(pnt.x,pnt.y); return *this; } + bool operator ==(const TPoint& p) { return p.x == x && p.y == y; } + bool operator !=(const TPoint& p) { return p.x != x || p.y != y; } +}; + + +// @C +// Classe TWindow +// +// @END + +class TWindow +{ + + friend class TWindow_manager; + + // @DPRIV + static DRAW_CTOOLS _ct; // Set di drawing tools (xvttype.h) + static bool _ctools_saved; // E' stata salvata _ct ? + + WINDOW _win; // Descrittore finestra + KEY _lastkey; // Tasto di uscita + + // @FPRIV + bool save_ctools(); // Compila la struct _ct con i valori correnti + bool restore_ctools(); // Ripristina i valori DA _ct + +protected: + // @DPROT + bool _open : 1; // Se la finestra e' aperta + bool _modal : 1; // Se la finestra e' modale + bool _running : 1; // Se la finestra e' in esecuzione + + // @FPROT + 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) ; + + void set_win(WINDOW w) { _win = w; } // Usare con cautela + + void set_modal(bool m) { _modal = m; } // Modifica il flag _modal + + WINDOW parent() const; + + virtual void update() {} // E_UPDATE + virtual bool on_key(KEY) { return TRUE; } // E_CHAR + + virtual PNT log2dev(long x, long y) const; + virtual TPoint dev2log(const PNT& p) const; + +public: + // @FPUB + TWindow(); // Costruttore + virtual ~TWindow(); + + virtual void handler(WINDOW win, EVENT* ep); // Handler finestra + virtual void set_focus(); // Mette la finestra in primo piano + virtual WINDOW win() const { return _win; } // Ritorna il descrittore della finestra + + bool is_open() const { return _open; } // Ritorna _open + bool is_modal() const { return _modal; } // Ritorna _modal + bool is_running() const { return _running; } // Ritorna _running + + TPoint size() const; // Determina numero di righe e colonne nella finestra + short rows() const { return (short)size().y; }// Ritorna numero di righe + short columns() const { return (short)size().x; } // Ritorna numero di colonne + + virtual void start_run() {} + virtual bool stop_run(KEY key); + void force_update(); // Forza ridisegno della finestra + + virtual void open(); // Mostra la finestra + virtual void close(); // Nasconde la finestra + + void iconize() const; + void maximize() const; + virtual void enable(bool = TRUE) const; + void disable() const { enable(FALSE); } + + void open_modal(); // Mostra la finestra modale + void close_modal(); // Nasconde la finestra modale + + KEY run(); // Esegue la finestra + KEY last_key() const { return _lastkey; } // Ritorna l'ultimo tasto + + virtual void set_caption(const char* title); + virtual const char* get_caption() const; + + // Riempie la finestra con il colore in color + void clear(COLOR color); + + // Setta il draw mode + void set_mode(DRAW_MODE mode); + + // Setta il colore + void set_color(COLOR fore, COLOR back); + + // Setta opaque_text. Quando e' FALSE il testo viene scritto in modo trasparente + void set_opaque_text(bool o); + + // Sceglie penna con colore color eccetera + void set_pen(COLOR color, int width = 1, PAT_STYLE pat = PAT_SOLID, PEN_STYLE st = P_SOLID); + void hide_pen(); // Nasconde la penna + void hide_brush(); // Nasconde il pennello + void set_brush(COLOR color, PAT_STYLE = PAT_SOLID); // Sceglie pennello con colore color + void set_font(int family = FF_SYSTEM, int style = 0, int dim = 0); // Sceglie il font + + // Disegna un rettangolo con la possibilita' di settare la penna e il draw_mode + void frame(short left, short top, short right, short bottom, int flag); + + // Queste funzioni chiamano tutte frame con diversi flag + void rect(short left, short top, short right, short bottom); + void bar(short left, short top, short right, short bottom); + void invert_bar(short left, short top, short right, short bottom); + + void stringat(short x, short y, const char* str); + void printat(short x, short y, const char* fmt, ...); // Scrive un testo nella finestra alla posizione indicata + + void line(short x0, short y0, short x1, short y1); // Disegna una linea nella finestra + void icon(short x0, short y0, int iconid = -1); +}; + +class TTemp_window : public TWindow +{ +public: + TTemp_window(WINDOW w); + virtual ~TTemp_window(); +}; + +// @C +// Classe TScroll_window : public TWindow +// +// Finestra con scrollbar +// +// @END + +class TScroll_window : public TWindow +{ + + // @DPRIV + TPoint _origin; + TPoint _max; + short _shift; + + bool _autoscroll : 1; + bool _has_hscroll : 1; + bool _has_vscroll : 1; + +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 + + virtual PNT log2dev(long x, long y) const; + virtual bool on_key(KEY key); + +public: + // @FPUB + + TScroll_window(); + // Costruttore + + virtual void handler(WINDOW win, EVENT* ep); + + void set_scroll_max(long maxx, long maxy); + // Setta punto di massimo scroll + void update_thumb(long x = -1, long y = -1); + // Aggiorna la scrollbar + + void autoscroll(bool on) { _autoscroll = on; } + // Setta autoscroll + + bool autoscrolling() const { return _autoscroll; } + + const TPoint& origin() const { return _origin; } + // Ritorna punto origine + const TPoint& range() const { return _max; } + // Ritorna punto massimo +}; + +#endif // __WINDOW_H diff --git a/include/xvtility.cpp b/include/xvtility.cpp index 3ecf03629..4039d49d0 100755 --- a/include/xvtility.cpp +++ b/include/xvtility.cpp @@ -107,11 +107,13 @@ HIDDEN BOOLEAN event_hook(HWND hwnd, ULONG lparam, long* ret) { - if (msg == WM_CTLCOLOR) + switch(msg) + { + case WM_CTLCOLOR: { const word type = HIWORD(lparam); - if (type == CTLCOLOR_LISTBOX || type == CTLCOLOR_EDIT || + if (type == CTLCOLOR_LISTBOX || type == CTLCOLOR_EDIT || type == CTLCOLOR_MSGBOX) { HWND hwnd = LOWORD(lparam); @@ -137,44 +139,64 @@ HIDDEN BOOLEAN event_hook(HWND hwnd, *ret = focus ? FocusBrush : NormalBrush; return TRUE; } - } else - if (msg == WM_COMMAND) + } + 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 ) +{ + char name[16]; + GetClassName(hwnd, name, 5); + if (stricmp(name, "Edit") == 0) + { + KEY key; + switch(wparam) { - word notify = HIWORD(lparam); - if (notify == EN_KILLFOCUS || notify == EN_SETFOCUS) - { - HWND hwnd = LOWORD(lparam); - InvalidateRect(hwnd, NULL, TRUE); - } - } else - if (msg == WM_KEYUP) - { - if (wparam == VK_PRIOR || wparam == VK_NEXT || - wparam == VK_UP || wparam == VK_DOWN ) - { - char name[16]; - GetClassName(hwnd, name, 15); - if (stricmp(name, "Edit") == 0) - { - switch(wparam) - { - case VK_PRIOR:wparam = K_PREV; break; - case VK_NEXT :wparam = K_NEXT; break; - case VK_UP :wparam = K_UP; break; - case VK_DOWN :wparam = K_DOWN; break; - default:wparam = 0; break; - } - if (wparam) - { - WINDOW w = xvtwi_hwnd_to_window(GetParent(hwnd)); - dispatch_e_char(w, wparam); - } - } - } - } + case VK_PRIOR: + wparam = 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 (key > 0) + { + WINDOW w = cur_win(); + if (w != NULL_WIN) + dispatch_e_char(w, key); + } + } +} +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: +break; +} - - return FALSE; +return FALSE; } #endif @@ -671,6 +693,7 @@ int xvt_get_checked_radio(const WINDOW* ctls, int count) /////////////////////////////////////////////////////////// HIDDEN WINDOW statbar = NULL_WIN; +HIDDEN TString80 stattext; WINDOW xvt_create_statbar() { @@ -701,18 +724,23 @@ WINDOW xvt_create_statbar() } void xvt_statbar_set(const char* text) -{ - TString t(text); t.cut(60); - const TDate oggi(TODAY); - t << '\t' << oggi.string() << " - " << MainApp()->title(); +{ #if XVT_OS == XVT_OS_WIN - statbar_set_title(statbar, (char*)(const char*)t); + if (text != NULL) + { + stattext.strncpy(text, 56); + const TDate oggi(TODAY); + stattext << '\t' << oggi.string() << " - " << MainApp()->title(); + } + statbar_set_title(statbar, (char*)(const char*)stattext); #endif } void xvt_statbar_refresh() { - invalidate_rect(statbar, NULL); +#if XVT_OS == XVT_OS_WIN + statbar_set_title(statbar, (char*)(const char*)stattext); +#endif } /////////////////////////////////////////////////////////// @@ -742,7 +770,8 @@ bool xvt_test_menu_tag(MENU_TAG tag) COLOR trans_color(char c) { - switch (c) { + switch (c) + { case 'n': return COLOR_BLACK; break; case 'r': return COLOR_RED; break; case 'g': return COLOR_GREEN; break; @@ -755,8 +784,9 @@ COLOR trans_color(char c) case 'd': return COLOR_DKGRAY; break; case 'l': return COLOR_LTGRAY; break; case 'k': return COLOR_GRAY; break; - default: CHECK(0,"trans_color: Undefined color"); return -1; break; + default: CHECK(0,"trans_color: Undefined color"); break; } + return -1; } PAT_STYLE trans_brush(char p) @@ -772,8 +802,9 @@ PAT_STYLE trans_brush(char p) case '\\': return PAT_BDIAG; break; case 'X' : return PAT_DIAGCROSS; break; case '+' : return PAT_CROSS; break; - default: CHECK(0,"trans_brush: Undefined pattern"); return PAT_NONE; break; + default : CHECK(0,"trans_brush: Undefined pattern"); break; } + return PAT_NONE; } PEN_STYLE trans_pen(char p) @@ -783,7 +814,8 @@ PEN_STYLE trans_pen(char p) case 'n' : return P_SOLID; break; case '.' : return P_DOT; break; case '-' : return P_DASH; break; - default: CHECK(0,"trans_pen: Undefined pattern"); return P_SOLID; break; + default: CHECK(0,"trans_pen: Undefined pattern"); break; } + return P_SOLID; }