Skip to content

Commit

Permalink
Pages (#26)
Browse files Browse the repository at this point in the history
* newdel0

* newdel1

* keyhelp
  • Loading branch information
freakout42 authored Sep 6, 2024
1 parent 17e3c4d commit 045edbc
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 37 deletions.
7 changes: 3 additions & 4 deletions generate/makeform
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ cat <<EOF
INSERT INTO forms (id, name, title) VALUES (1, '$FORM', '$TITLE');
INSERT INTO blocks (form_id, name) VALUES (1, '$TABLE');
INSERT INTO blocks (id, form_id, name) VALUES (0, 1, 'dual');
INSERT INTO pages (form_id, name) VALUES (1, '$TABLE-0');
INSERT INTO pages (id, form_id, name, ysiz, vwpy0, border) VALUES (0, 1, 'formax', 1, 0, 0);
INSERT INTO maps (page_id, line, mtext) VALUES (1, 1, ' ');
INSERT INTO pages (form_id, seq, name) VALUES (0, 1, 'formax');
INSERT INTO maps (page_id, line, mtext) VALUES (3, 1, ' ');
EOF
LINE=0
FLDN=0
Expand All @@ -29,6 +28,6 @@ for COLUMN; do
FLDN=`expr $FLDN + 10`
if [ $LINE = 1 ]; then KEY=1; else KEY=0; fi
echo "INSERT INTO fields (seq, name, line, key) VALUES ($FLDN, '$COLUMN', $LINE+1, $KEY);"
printf "INSERT INTO maps (page_id, line, mtext) VALUES (1, $LINE+1, ' [$LINE]%-14s \$${LINE}__________________');\\n" $COLUMN
printf "INSERT INTO maps (page_id, line, mtext) VALUES (3, $LINE+1, ' [$LINE]%-14s \$${LINE}__________________');\\n" $COLUMN
done
exit
4 changes: 2 additions & 2 deletions generate/testform
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/sh
helpmap() {
LINE=`expr $LINE + 1`
echo "INSERT INTO maps (page_id, line, mtext) VALUES (1, $LINE, ' $1');"
echo "INSERT INTO maps (page_id, line, mtext) VALUES (3, $LINE, ' $1');"
}
guidmap() {
LINE=`expr $LINE + 1`
echo "UPDATE maps set mtext = mtext || ' $1' where line = $LINE;"
echo "UPDATE maps set mtext = mtext || ' $1' where page_id = 3 and line = $LINE;"
}
ARX=`pwd`/.. sh ./makeform scotty formax1 emps id ename job mgr hiredate sal comm dept_id
cat <<EOF
Expand Down
13 changes: 6 additions & 7 deletions runform/field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ switch(CM) {
default: color = COL_FIELD;
}
if (cur && CM != MOD_DELETE) color = COL_CURRENT;
F(p[1].writef)(line, col, color, displaylen, "%.*s", displaylen, CM==MOD_QUERY ? queryhuman : *valuep());
if (cur) F(p[1].wmov)(line, col);
F(p[1]).writef(line, col, color, displaylen, "%.*s", displaylen, CM==MOD_QUERY ? queryhuman : *valuep());
if (cur) F(p[1]).wmov(line, col);
}

void Field::clear() {
Expand Down Expand Up @@ -94,7 +94,7 @@ if (CM == MOD_UPDATE && fldtype() == FTY_BOOL) {
}
}
}
return 0;
return KEF_CANCEL;
}

int Field::increment(int ival) {
Expand Down Expand Up @@ -165,7 +165,6 @@ int Field::edit(int pos) {
int pressed;
char buf[SMLSIZE];
char **c;
int s;
pressed = 0;
switch(CM) {
case MOD_UPDATE:
Expand All @@ -175,13 +174,13 @@ switch(CM) {
if (F(b[blockindex].q->rows)) {
c = valuep();
if (*c) let(buf, *c); else *buf = '\0';
pressed = F(p[0].sedit)(buf, pos, fldtype(), fieldlen);
pressed = F(p[PGE_STATUS].sedit)(buf, pos, fldtype(), fieldlen);
if (pressed != KEF_CANCEL && validate(c, buf) == KEF_CANCEL) pressed = KEF_CANCEL;
}
break;
case MOD_QUERY:
pressed = F(p[0].sedit)(queryhuman, pos, FTY_ALL, SMLSIZE);
s = colquery(queryhuman, querywhere, name, querycharm, 0);
pressed = F(p[PGE_STATUS].sedit)(queryhuman, pos, FTY_ALL, SMLSIZE);
colquery(queryhuman, querywhere, name, querycharm, 0);
break;
case MOD_DELETE:
break;
Expand Down
23 changes: 13 additions & 10 deletions runform/form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* and provide control over the flow of execution.
* should be a pointer and not static
*/
#include <assert.h>
#include "runform.h"

Form::Form() {
Expand Down Expand Up @@ -38,6 +37,7 @@ if (q->rows != 1) return 7;
let(id, q->v(1, 1));
let(name, q->v(1, 2));
let(title, q->v(1, 3));
needredraw = 0;
rclose();

// triggers
Expand All @@ -50,17 +50,21 @@ for (i=0; i<numtrigger; i++) {
}
rtrigger.rclose();

// pages - page 0 is status/edit/message window
// pages - page [0]/1.0 is status/edit/message window
// [1]/3.1 is working window
// [2]/2.2 is key help popup
if (rpage.init(fid)) return 9;
if ((s = rpage.query())) return s;
numpage = rpage.q->rows;
if (numpage > NBLOCKS) return 7;
for (i=0; i<numpage; i++) if (p[i].init(rpage.q, i+1)) return 9;
for (i=0; i<numpage; i++) {
if (p[i].init(rpage.q, i+1)) return 9;
if (rmap.init(p[i].page_id)) return 9;
if ((s = rmap.query())) return s;
if (p[i].maps(rmap.q)) return 9;
rmap.rclose();
}
rpage.rclose();
if (rmap.init(1)) return 9;
if ((s = rmap.query())) return s;
if (p[1].maps(rmap.q)) return 9;
rmap.rclose();

// error messages
if (rerror.init()) return 9;
Expand Down Expand Up @@ -107,7 +111,7 @@ if (y.init()) return 6;
for (i=0; i<numpage; i++) p[i].create();
lastkey = -1;
while (!(s = u.dispatch())) {
lastkey = F(p[0]).wait();
lastkey = F(p[PGE_STATUS]).wait();
}
y.closedisplay();
return s==-1 ? 0 : s;
Expand All @@ -117,7 +121,6 @@ int Form::mapkey(int ckey) {
int ck;
ck = ispunctation(ckey);
switch(ck) { /* C */
case KEY_F(0): return KEF_REFRESH; /* l frefresh */
case KEY_F(1): return KEF_HELP; /* @ fhelp */
case KEY_F(2): return KEF_COPY; /* c fcopy */
case KEY_F(3): return KEF_PASTE; /* v fpaste */
Expand All @@ -129,6 +132,7 @@ switch(ck) { /* C */
case KEY_F(9): return KEF_QUIT; /* y cancel/quit */
case KEY_F(10): return KEF_QUERY; /* x enter_query */
case KEY_F(11): return KEF_KEYHELP; /* k keys_help */
case KEY_F(12): return KEF_REFRESH; /* l frefresh */
case KEY_ESC: return KEF_CANCEL; /* esc cancel/quit */
case KEY_CANCEL: return KEF_CANCEL; /* cancel cancel/quit */
case KEY_IC: return KEF_INSERT; /* j create_record */
Expand All @@ -148,4 +152,3 @@ switch(ck) { /* C */
default: return ck;
}
}

1 change: 1 addition & 0 deletions runform/form.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Form: public Record {
char title[SMLSIZE];
Qdata *e;
Screen y;
int needredraw;
Block b[NBLOCKS];
Field l[NFIELDS];
Page p[NBLOCKS];
Expand Down
12 changes: 8 additions & 4 deletions runform/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ int Function::dispatch() {
F(lastcmd) = F(mapkey)(LK);
switch(F(lastcmd)) {
#ifdef NOTYETIMPLEMENTED
case KEF_COPY: /* fhelp() */
case KEF_COPY: /* fcopy() */
case KEF_PASTE: /* fpaste() */
case KEF_LIST: /* flist() */
case KEF_COPYREC: /* fcopyrec() */
case KEF_HOME: /* fhome() */
case KEF_END: /* fend() */
case KEF_PRESETR: /* fpresetr() */
case KEF_NXTSETR: /* fnxtsetr() */
case KEF_REFRESH: /* frefresh() */
case KEF_NAVI0: /* fmenu() */
#endif
case -1: LK = enter_the_form(); break;
case KEF_REFRESH: LK = refresh_screen(); break;
case KEF_NAVI1: LK = fmove(0, NFIELD1+1); break;
case KEF_NAVI2: LK = fmove(0, NFIELD1+2); break;
case KEF_NAVI3: LK = fmove(0, NFIELD1+3); break;
Expand Down Expand Up @@ -99,14 +99,18 @@ notrunning = trigger(TRT_ENTERFORM); //"enter_the_form");
return 0;
}

int Function::refresh_screen() {
F(needredraw) = 1;
return 0;
}

int Function::help_item() {
MSG1(MSG_HELP,CF.helptext);
return 0;
}

int Function::keys_help() {
MSG(MSG_NOTYET);
return 0;
return F(p[PGE_KEYHELP]).showpopup();
}

/* NAVIGATION */
Expand Down
1 change: 1 addition & 0 deletions runform/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Function {
int changed;
int trigger(int tid);
int enter_the_form();
int refresh_screen();
int help_item();
int keys_help();
int switch_mode(fmode mod);
Expand Down
22 changes: 19 additions & 3 deletions runform/page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ ysiz = pag->n(rix, 3);
xsiz = pag->n(rix, 4);
vwpy0 = pag->n(rix, 5);
vwpx0 = pag->n(rix, 6);
border = pag->n(rix, 7);
popup = pag->n(rix, 7);
border = pag->n(rix, 8);
return 0;
}

// must be rewritten for multiple pages
int Page::maps(Qdata *qma) {
int i, r, y;
char *t, *p;
Expand Down Expand Up @@ -52,6 +52,18 @@ for (i=0; i<NLINES; i++) free(map[i]);
deletewindow();
}

void Page::repaint() { if (!popup) redraw(); }
void Page::refrnopop() { if (!popup) refr(); }

int Page::showpopup() {
int i;
redraw();
refr();
i = getkb();
F(needredraw) = 1;
return i==KEY_ENTER ? 0 : i;
}

static const char *rmodes[] = RMODENAMES;

int Page::wait() {
Expand All @@ -78,7 +90,11 @@ writef(0, 61, COL_HEADER,3,"%s", (char*)(insertmode ? "Ins" : "Rep"));
writef(0, 65, COL_COMMIT,15,"%s", commit);
refr();
for (i=0; i<F(numfield); i++) F(l[i]).show(i == F(curfield));
for (i=1; i<F(numpage); i++) F(p[i]).refr();
for (i=PGE_MAIN; i<F(numpage); i++) {
if (F(needredraw)) F(p[i]).repaint();
F(p[i]).refrnopop();
}
F(needredraw) = 0;
return LK ? LK : getkb();
}

Expand Down
6 changes: 5 additions & 1 deletion runform/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
#define LINE0SIZE 80
class Page: public Screen {
public:
int page_id;
int init(Qdata *pag, int rix);
void create();
void repaint();
int showpopup();
void destroy();
char name[SMLSIZE];
int maps(Qdata *rmap);
Expand All @@ -14,8 +17,9 @@ class Page: public Screen {
protected:
int vwpy0;
int vwpx0;
int popup;
int border;
private:
int page_id;
char *map[NLINES];
void refrnopop();
};
1 change: 0 additions & 1 deletion runform/record.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* record.cpp calls ODBC and
* provides an interface in an ORM style like rails active-record.
*/
#include <assert.h>
#include <stdlib.h>
#include <sql.h>
#include <sqlext.h>
Expand Down
14 changes: 14 additions & 0 deletions runform/rmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,18 @@ CREATE TABLE maps
line INTEGER NOT NULL DEFAULT 1,
mtext TEXT NOT NULL DEFAULT ''
);
INSERT INTO maps (page_id, line, mtext) VALUES (2, 1, 'KEY C FUNCTION KEY C FUNCTION');
INSERT INTO maps (page_id, line, mtext) VALUES (2, 2, 'Tab i NextField ^Tab g PrevField');
INSERT INTO maps (page_id, line, mtext) VALUES (2, 3, 'F1 @ Field Help Esc y Cancel');
INSERT INTO maps (page_id, line, mtext) VALUES (2, 4, 'F2 c Copy > f Right');
INSERT INTO maps (page_id, line, mtext) VALUES (2, 5, 'F3 v Paste < b Left');
INSERT INTO maps (page_id, line, mtext) VALUES (2, 6, 'F4 t Duplicate Up p PreviousRec');
INSERT INTO maps (page_id, line, mtext) VALUES (2, 7, 'F5 u ListOfVal Down n NextRecord');
INSERT INTO maps (page_id, line, mtext) VALUES (2, 8, 'F6 o Insert Ins j Insert');
INSERT INTO maps (page_id, line, mtext) VALUES (2, 9, 'F7 d Delete Del d Delete');
INSERT INTO maps (page_id, line, mtext) VALUES (2, 10, 'F8 z Exit <-- h DeleteLast');
INSERT INTO maps (page_id, line, mtext) VALUES (2, 11, 'F9 y Cancel PgUp r PrevSetRec');
INSERT INTO maps (page_id, line, mtext) VALUES (2, 12, 'F10 x Query PgDn w NextSetRec');
INSERT INTO maps (page_id, line, mtext) VALUES (2, 13, 'F11 k Key Help Home a PrevBlock');
INSERT INTO maps (page_id, line, mtext) VALUES (2, 14, 'F12 l Refresh End e NextBlock');
#endif
6 changes: 3 additions & 3 deletions runform/rpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ stmt = NULL;
if ((s = ropen())) return s;
let(table, "pages");
let(prikey, "id");
let(attrs, "id,name,ysiz,xsiz,vwpy0,vwpx0,border");
letf(t(where), "form_id = %d", form_id);
let(attrs, "id,name,ysiz,xsiz,vwpy0,vwpx0,popup,border");
letf(t(where), "form_id in (0, %d)", form_id);
let(order, "seq");
columni = 7;
columni = 8;
return 0;
}
2 changes: 2 additions & 0 deletions runform/rpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ CREATE TABLE pages
border INTEGER NOT NULL DEFAULT 1, /* if the view has a border */
dislv INTEGER NOT NULL DEFAULT 0 /* if the page dissolves when exited */
);
INSERT INTO pages (form_id, seq, name, ysiz, vwpy0, border) VALUES (1, 0, 'status', 1, 0, 0);
INSERT INTO pages (form_id, seq, name, ysiz, xsiz, vwpy0, vwpx0, popup, border) VALUES (0, 2, 'keyhelp', 16, 41, 2, 30, 1, 1);
#endif
3 changes: 3 additions & 0 deletions runform/runform.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
enum odrvr { ODR_SQLITE, ODR_ORACLE, ODR_PG, ODR_MYSQL, ODR_SQLSRVR, ODR_ADS, ODR_UNKNOWN };
enum fmode { MOD_INSERT, MOD_QUERY, MOD_UPDATE, MOD_DELETE };
enum ftype { FTY_ALL, FTY_CHAR, FTY_INT, FTY_FLOAT, FTY_DATE, FTY_BOOL };
enum upage { PGE_STATUS, PGE_MAIN, PGE_KEYHELP, PGE_EXTRA };
#define RMODENAMES { "Insert", "Query ", "Update", "Delete" }
#include "../version.h"

Expand All @@ -18,6 +19,7 @@ enum ftype { FTY_ALL, FTY_CHAR, FTY_INT, FTY_FLOAT, FTY_DATE, FTY_BOOL }
#define NPRIKEY 4
#define NBINDPA NFIELD1

#include <assert.h>
#include <string.h>
#include "regex/re.h"
#include "elk/elk.h"
Expand All @@ -42,6 +44,7 @@ enum ftype { FTY_ALL, FTY_CHAR, FTY_INT, FTY_FLOAT, FTY_DATE, FTY_BOOL }
#define min(x, y) (((x) < (y)) ? (x) : (y))
#define let(target,source) strncpy(target, source, sizeof(target)-1)
#define t(target) target, sizeof(target)
#define debugs(string) fprintf(stderr, ":%s:\n", string);

#define F(method) f.method
#define CM F(rmode)
Expand Down
5 changes: 3 additions & 2 deletions runform/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ wattrset(wndw, A_NORMAL);
wattron(wndw, COLOR_PAIR(0));
}

void Screen::deletewindow() { delwin(wndw); }
void Screen::deletewindow() { wera(); delwin(wndw); }
void Screen::wera() { werase(wndw); }
void Screen::wbox() { box(wndw, 0, 0); }
void Screen::wmov(int y, int x) { wmove(wndw, y, x); }
void Screen::refr() { wrefresh(wndw); }
void Screen::noutrefr() { wnoutrefresh(wndw); }
void Screen::redraw() { redrawwin(wndw); }
void Screen::closedisplay() { endwin(); tcsetattr (0, TCSANOW, &otermio); }

Expand Down Expand Up @@ -160,7 +161,7 @@ switch(ch) {
/* KEF_NXTFLD */ case KEY_CTRL('I'): return KEY_TAB; /* Next field NextField */
/* KEF_INSERT */ case KEY_CTRL('J'): return KEY_IC; /* Insert toggle (record) InsertReplace InsertRecord */
/* KEF_KEYHELP */ case KEY_CTRL('K'): return KEY_F(11); /* Keyboard help KeyHelp */
/* KEF_REFRESH */ case KEY_CTRL('L'): return KEY_F(0); /* Refresh Refresh */
/* KEF_REFRESH */ case KEY_CTRL('L'): return KEY_F(12); /* Refresh Refresh */
/* KEF_COMMIT */ case KEY_CTRL('M'): return KEY_ENTER; /* Commit Accept Commit Select Execute */
/* KEF_NXTREC */ case KEY_CTRL('N'): return KEY_DOWN; /* Next record Down NextRecord */
/* KEF_INSERT */ case KEY_CTRL('O'): return KEY_F(6); /* Insert record InsertRecord */
Expand Down
1 change: 1 addition & 0 deletions runform/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Screen {
int xsiz;
protected:
WINDOW *wndw;
void noutrefr();
private:
void setcolor(int pairi);
void uncolor(int pairi);
Expand Down

0 comments on commit 045edbc

Please sign in to comment.