GCUI: Golded+ Character-oriented User Interface library.

This commit is contained in:
Stas Degteff 2011-02-18 19:46:02 +00:00
parent 0d2daff9c9
commit a809315916
33 changed files with 17757 additions and 0 deletions

37
goldlib/gcui/Makefile Normal file
View File

@ -0,0 +1,37 @@
## -------------------------------------------------------------------
## The Goldware Library. Copyright (C) Odinn Sorensen and Golded+ team
## -------------------------------------------------------------------
## GCUI: Golded+ Character-oriented User Interface library.
## -------------------------------------------------------------------
# -*- makefile -*-
# Build library using GNU make and CNU C++ compuler.
ifeq ($(TERM),cygwin)
MINGW=true
else
ifeq ($(OSTYPE),msys)
MINGW=true
endif
endif
TOP=../..
TARGET=gcui
INCS=-I$(TOP)/goldlib/gcui -I$(TOP)/goldlib/gall
ifeq ($(PLATFORM),emx) || ($(PLATFORM),MINGW)
INCS+=-I$(TOP)/goldlib/glibc
endif
include $(TOP)/Config.def
ifneq ($(findstring GCFG_NO_MYSPELL, $(CPPFLAGS)), GCFG_NO_MYSPELL)
INCS+=-I$(TOP)/goldlib/hunspell
endif
include $(TOP)/GNUmakef.inc
ifeq ($(PLATFORM),emx)
ifeq ($(AR),emxomfar)
AR += -p32
endif
endif
include $(TOP)/GNUmakef.lib

53
goldlib/gcui/gcui.all Normal file
View File

@ -0,0 +1,53 @@
## -------------------------------------------------------------------
## The Goldware Library. Copyright (C) Odinn Sorensen and Golded+ team
## -------------------------------------------------------------------
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
## -------------------------------------------------------------------
## $Id$
## -------------------------------------------------------------------
## GCUI: Golded+ Character-oriented User Interface.
## Master build file for GCUI.
## -------------------------------------------------------------------
## Keyboard.
gkbdbase cpp all nov bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
gkbdgetm cpp all nov bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
gkbdwait cpp all nov bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
## Text searching.
gsrchmgr cpp all ovl bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
## Mouse.
gmoubase cpp all nov bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
## Low-level text video
gvidbase cpp all nov bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
gvidinit cpp all ovl bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
## Text windowing.
gwinbase cpp all ovl bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
gwindow cpp all ovl bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
gwinhlp1 cpp all ovl bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
gwinhlp2 cpp all ovl bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
gwininit cpp all ovl bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
gwinline cpp all ovl bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
gwinmenu cpp all ovl bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
gwinmnub cpp all ovl bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
gwinpckf cpp all ovl bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
gwinpcks cpp all ovl bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
gwinpick cpp all ovl bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
gwinput2 cpp all ovl bcd bco bcx wcn wco wcx lnx emx djg rsx cyg be sun osx
## ------------------------------------------------------------------

253
goldlib/gcui/gcurses.h Normal file
View File

@ -0,0 +1,253 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1989 Free Software Foundation
// Copyright (C) 2000 Alexander S. Aganichev
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// This file is derived from the GNU C++ Library.
// Written by Eric Newton (newton@rocky.oswego.edu)
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Declarations for ncurses.
// ------------------------------------------------------------------
#ifndef __gcurses_h
#define __gcurses_h
// ------------------------------------------------------------------
// Even many system which mostly have C++-ready header files,
// do not have C++-ready curses.h.
extern "C" {
#if defined(__FreeBSD__) && (__FreeBSD__ < 4)
#include <ncurses/ncurses.h>
#elif defined(__sun__)
#include <ncurses/ncurses.h>
#else
#include <curses.h>
#endif
}
// ------------------------------------------------------------------
// "Convert" macros to inlines, if needed.
#ifdef addch
inline int (addch)(char ch) { return addch(ch); }
#undef addch
#endif
#ifdef addstr
// The (char*) cast is to hack around missing const's
inline int (addstr)(const char * str) { return addstr((char*)str); }
#undef addstr
#endif
#ifdef clear
inline int (clear)() { return clear(); }
#undef clear
#endif
#ifdef clearok
inline int (clearok)(WINDOW* win, bool bf) { return clearok(win, bf); }
#undef clearok
#else
extern "C" int clearok(WINDOW*, bool);
#endif
#ifdef clrtobot
inline int (clrtobot)() { return clrtobot(); }
#undef clrtobot
#endif
#ifdef clrtoeol
inline int (clrtoeol)() { return clrtoeol(); }
#undef clrtoeol
#endif
#ifdef delch
inline int (delch)() { return delch(); }
#undef delch
#endif
#ifdef deleteln
inline int (deleteln)() { return deleteln(); }
#undef deleteln
#endif
#ifdef erase
inline int (erase)() { return erase(); }
#undef erase
#endif
#ifdef flushok
inline int (flushok)(WINDOW* _win, int _bf) { return flushok(_win, _bf); }
#undef flushok
#else
#define _no_flushok
#endif
#ifdef getch
inline int (getch)() { return getch(); }
#undef getch
#endif
#ifdef getstr
inline int (getstr)(char *_str) { return getstr(_str); }
#undef getstr
#endif
#ifdef getyx
inline void (getyx)(WINDOW* win, int& y, int& x) { getyx(win, y, x); }
#undef getyx
#endif
#ifdef inch
inline chtype (inch)() { return inch(); }
#undef inch
#endif
#ifdef insch
inline int (insch)(char c) { return insch(c); }
#undef insch
#endif
#ifdef insertln
inline int (insertln)() { return insertln(); }
#undef insertln
#endif
#ifdef leaveok
inline int (leaveok)(WINDOW* win, bool bf) { return leaveok(win, bf); }
#undef leaveok
#else
extern "C" int leaveok(WINDOW* win, bool bf);
#endif
#ifdef move
inline int (move)(int x, int y) { return move(x, y); }
#undef move
#endif
#ifdef refresh
inline int (rfresh)() { return refresh(); }
#undef refresh
#endif
#ifdef scrollok
inline int (scrollok)(WINDOW* win, bool bf) { return scrollok(win, bf); }
#undef scrollok
#else
#ifndef hpux
extern "C" int scrollok(WINDOW*, bool);
#else
extern "C" int scrollok(WINDOW*, char);
#endif
#endif
#ifdef standend
inline int (standend)() { return standend(); }
#undef standend
#endif
#ifdef standout
inline int (standout)() { return standout(); }
#undef standout
#endif
#ifdef wstandend
inline int (wstandend)(WINDOW *win) { return wstandend(win); }
#undef wstandend
#endif
#ifdef wstandout
inline int (wstandout)(WINDOW *win) { return wstandout(win); }
#undef wstandout
#endif
#ifdef winch
inline chtype (winch)(WINDOW* win) { return winch(win); }
#undef winch
#endif
// deal with conflicting macros in ncurses.h which is SYSV based
#ifdef box
inline int _G_box(WINDOW* win, chtype v, chtype h) {return box(win, v, h); }
#undef box
inline int box(WINDOW* win, chtype v, chtype h) {return _G_box(win, v, h); }
#endif
#ifdef scroll
inline int (scroll)(WINDOW* win) { return scroll(win); }
#undef scroll
#endif
#ifdef touchwin
inline int (touchwin)(WINDOW* win) { return touchwin(win); }
#undef touchwin
#endif
#ifdef mvwaddch
inline int (mvwaddch)(WINDOW *win, int y, int x, char ch)
{ return mvwaddch(win, y, x, ch); }
#undef mvwaddch
#endif
#ifdef mvwaddstr
inline int (mvwaddstr)(WINDOW *win, int y, int x, const char * str)
{ return mvwaddstr(win, y, x, (char*)str); }
#undef mvwaddstr
#endif
#ifdef mvwdelch
inline int (mvwdelch)(WINDOW *win, int y, int x) { return mvwdelch(win, y, x);}
#undef mvwdelch
#endif
#ifdef mvwgetch
inline int (mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
#undef mvwgetch
#endif
#ifdef mvwgetstr
inline int (mvwgetstr)(WINDOW *win, int y, int x, char *str)
{return mvwgetstr(win,y,x, str);}
#undef mvwgetstr
#endif
#ifdef mvwinch
inline chtype (mvwinch)(WINDOW *win, int y, int x) { return mvwinch(win, y, x);}
#undef mvwinch
#endif
#ifdef mvwinsch
inline int (mvwinsch)(WINDOW *win, int y, int x, char c)
{ return mvwinsch(win, y, x, c); }
#undef mvwinsch
#endif
#ifdef mvaddch
inline int (mvaddch)(int y, int x, char ch)
{ return mvaddch(y, x, ch); }
#undef mvaddch
#endif
#ifdef mvaddstr
inline int (mvaddstr)(int y, int x, const char * str)
{ return mvaddstr(y, x, (char*)str); }
#undef mvaddstr
#endif
#ifdef mvdelch
inline int (mvdelch)(int y, int x) { return mvdelch(y, x);}
#undef mvdelch
#endif
#ifdef mvgetch
inline int (mvgetch)(int y, int x) { return mvgetch(y, x);}
#undef mvgetch
#endif
#ifdef mvgetstr
inline int (mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
#undef mvgetstr
#endif
#ifdef mvinch
inline chtype (mvinch)(int y, int x) { return mvinch(y, x);}
#undef mvinch
#endif
#ifdef mvinsch
inline int (mvinsch)(int y, int x, char c)
{ return mvinsch(y, x, c); }
#undef mvinsch
#endif
extern int curses_initialized;
// ------------------------------------------------------------------
#endif // __gcurses_h
// ------------------------------------------------------------------

1836
goldlib/gcui/gkbdbase.cpp Normal file

File diff suppressed because it is too large Load Diff

168
goldlib/gcui/gkbdbase.h Normal file
View File

@ -0,0 +1,168 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// Copyright (C) 1999-2000 Alexander S. Aganichev
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Keyboard functions (declarations).
// ------------------------------------------------------------------
#ifndef __gkbdbase_h
#define __gkbdbase_h
// ------------------------------------------------------------------
#include <gtimall.h>
// ------------------------------------------------------------------
// Simple types
typedef word gkey;
// ------------------------------------------------------------------
// Keycode object
inline gkey& KCodKey(gkey &key) { return key; }
inline byte& KCodAsc(gkey &key) { return *(((byte *)&key)+0); }
inline byte& KCodScn(gkey &key) { return *(((byte *)&key)+1); }
// ------------------------------------------------------------------
// Definition of kbuf record
struct KBuf {
KBuf* prev; // previous record
KBuf* next; // next record
gkey xch; // keypress
};
// ------------------------------------------------------------------
// Definition of onkey record
struct KBnd {
KBnd* prev; // pointer to previous record
KBnd* next; // pointer to next record
gkey keycode; // Scan/ASCII code of trap key
VfvCP func; // address of onkey function
gkey pass; // key to pass back, 0=don't pass
};
// ------------------------------------------------------------------
// Definition of keyboard info record
class GKbd {
public:
KBuf* kbuf; // Pointer to head record in key buffer
KBnd* onkey; // Pointer to head record in onkey list
KBnd* curronkey; // Pointer to current onkey record
int inmenu; // In-menu flag used by menuing functions
int source; // Source of keypress 0=kb, 1=kbuf, 2=mouse
int extkbd; // Extended keyboard 0=none, 1=yes
int polling; // Keyboard polling enabled
Clock tickinterval; // Minimum interval between ticks
Clock tickvalue; // Value from last tick
VfvCP tickfunc; // Function to call when a tick is generated
Clock tickpress; // Tick value at last keypress
bool inidle; // In-idle flag used by tickfunc
bool quitall; // Quit-all flag for menus etc.
void Init();
GKbd();
~GKbd();
};
extern GKbd gkbd;
// ------------------------------------------------------------------
// Keyboard status codes returned from kbstat()
#define RSHIFT 1 // right shift pressed
#define LSHIFT 2 // left shift pressed
#define GCTRL 4 // [Ctrl] pressed
#define ALT 8 // [Alt] pressed
#define SCRLOCK 16 // [Scroll Lock] toggled
#define NUMLOCK 32 // [Num Lock] toggled
#define CAPSLOCK 64 // [Caps Lock] toggled
#define INS 128 // [Ins] toggled
// ------------------------------------------------------------------
extern gkey scancode_table[];
extern bool right_alt_same_as_left;
// ------------------------------------------------------------------
// Function prototypes
KBnd* chgonkey (KBnd* kblist);
void clearkeys ();
void freonkey ();
int setonkey (gkey keycode, VfvCP func, gkey pass);
gkey getxch (int __tick=false);
void kbclear ();
gkey kbmhit ();
gkey kbxget (int mode=0);
gkey kbxhit ();
int kbput (gkey xch);
word kbput_ (gkey xch);
void kbputs_ (char* str);
byte scancode (gkey ch);
gkey waitkey ();
gkey waitkeyt (int duration);
gkey key_tolower(gkey __keycode);
gkey keyscanxlat(gkey k);
gkey __kbxget(int __mode=0, long __ticks=0, VfvCP __idlefunc=NULL);
void gkbdtickpressreset();
void gkbdtickvaluereset();
// ------------------------------------------------------------------
// Inline functions
inline gkey getxchtick() { return getxch(true); }
inline void kbdsettickfunc(VfvCP func) { gkbd.tickfunc = func; }
// ------------------------------------------------------------------
// Shorthand definitions of keyboard scancodes
#define KEY_BRK 0xFFFF // ^Break return from _KeyHit()/_KeyGet()
// ------------------------------------------------------------------
#endif
// ------------------------------------------------------------------

466
goldlib/gcui/gkbdcode.h Normal file
View File

@ -0,0 +1,466 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// Copyright (C) 1999-2000 Alexander S. Aganichev
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Define mnemonic symbols for full set of PC-Compatible non-display
// control and extended keycodes.
// ------------------------------------------------------------------
#ifndef __gkbdcode_h
#define __gkbdcode_h
// ------------------------------------------------------------------
// Notes and Caveats (from the original TCXL 6.0 TCXLCOD.H file)
//
// 1. The keycode symbols suffixed with 'G' and marked in the 'G'
// column are the "Grey" keys around the numeric keypad or in a
// separate cursor-key cluster on "enhanced" keyboards. Those
// marked in the 'N' column are on numeric keypad.
// 2. The keycodes marked in the 'E' column are only available on
// "enhanced" 101/102-key keyboards with extended keyboard BIOS
// support enabled. The extended BIOS returns keycodes containing
// 0xE0 to distinguish duplicated keys, which are marked in the
// 'T' column.
// 3. If an "enhanced" keyboard and extended BIOS is detected, the
// DEFAULT is to enable extended BIOS support and translation of
// any duplicate extended keycodes.
// 4. Keycodes are ordered by character-code, then scan-code.
// 5. Control-Break, which has an actual keycode of 0x000 is
// returned as 0xFFFF.
// 6. The ASCII control-code names are shown in square brackets.
// 7. The Key_M_??? mouse-return codes are those returned by
// _MouGet().
// ------------------------------------------------------------------
#include <gdefs.h>
// ------------------------------------------------------------------
#define Key_Lsr '<'
#define Key_Gtr '>'
#define Key_Multi '*'
#define Key_Plus '+'
#define Key_Minus '-'
// ------------------------------------------------------------------
//- Normal key -------- N G E T -
#define Key_0 '0' // <0> - - - -
#define Key_1 '1' // <1> - - - -
#define Key_2 '2' // <2> - - - -
#define Key_3 '3' // <3> - - - -
#define Key_4 '4' // <4> - - - -
#define Key_5 '5' // <5> - - - -
#define Key_6 '6' // <6> - - - -
#define Key_7 '7' // <7> - - - -
#define Key_8 '8' // <8> - - - -
#define Key_9 '9' // <9> - - - -
#define Key_A 0x1E61 // <a> - - - -
#define Key_B 0x3062 // <b> - - - -
#define Key_C 0x2E63 // <c> - - - -
#define Key_D 0x2064 // <d> - - - -
#define Key_E 0x1265 // <e> - - - -
#define Key_F 0x2166 // <f> - - - -
#define Key_G 0x2267 // <g> - - - -
#define Key_H 0x2368 // <h> - - - -
#define Key_I 0x1769 // <i> - - - -
#define Key_J 0x246a // <j> - - - -
#define Key_K 0x256b // <k> - - - -
#define Key_L 0x266c // <l> - - - -
#define Key_M 0x326d // <m> - - - -
#define Key_N 0x316e // <n> - - - -
#define Key_O 0x186f // <o> - - - -
#define Key_P 0x1970 // <p> - - - -
#define Key_Q 0x1071 // <q> - - - -
#define Key_R 0x1372 // <r> - - - -
#define Key_S 0x1F73 // <s> - - - -
#define Key_T 0x1474 // <t> - - - -
#define Key_U 0x1675 // <u> - - - -
#define Key_V 0x2F76 // <v> - - - -
#define Key_W 0x1177 // <w> - - - -
#define Key_X 0x2D78 // <x> - - - -
#define Key_Y 0x1579 // <y> - - - -
#define Key_Z 0x2C7A // <z> - - - -
#define Key_StrG 0x372A // <*> - G - -
#define Key_PlsG 0x4E2B // <+> - G - -
#define Key_Com 0x332C // <,> - - - -
#define Key_MinG 0x4A2D // <-> - G - -
#define Key_Dot 0x342E // <.> - - - -
#define Key_BS 0x0E08 // <BS> - - - -
#define Key_5Num 0x4C00 // <Cent> N - E -
#define Key_Del 0x5300 // <Del> N - - -
#define Key_DelG 0x53E0 // <Del> Grey - G E T
#define Key_Dwn 0x5000 // <Down> N - - -
#define Key_DwnG 0x50E0 // <Down> Grey - G E T
#define Key_End 0x4F00 // <End> N - - -
#define Key_EndG 0x4FE0 // <End> Grey - G E T
#define Key_Ent 0x1C0D // <Enter> - - - -
#define Key_EntG 0xE00D // <Enter> Grey - G E T
#define Key_Esc 0x011B // <Esc> - - - -
#define Key_F1 0x3B00 // <F1> - - - -
#define Key_F2 0x3C00 // <F2> - - - -
#define Key_F3 0x3D00 // <F3> - - - -
#define Key_F4 0x3E00 // <F4> - - - -
#define Key_F5 0x3F00 // <F5> - - - -
#define Key_F6 0x4000 // <F6> - - - -
#define Key_F7 0x4100 // <F7> - - - -
#define Key_F8 0x4200 // <F8> - - - -
#define Key_F9 0x4300 // <F9> - - - -
#define Key_F10 0x4400 // <F10> - - - -
#define Key_F11 0x8500 // <F11> - - E -
#define Key_F12 0x8600 // <F12> - - E -
#define Key_Home 0x4700 // <Home> N - - -
#define Key_HomeG 0x47E0 // <Home> Grey - G E T
#define Key_Ins 0x5200 // <Ins> N - - -
#define Key_InsG 0x52E0 // <Ins> Grey - G E T
#define Key_Lft 0x4B00 // <Left> N - - -
#define Key_LftG 0x4BE0 // <Left> Grey - G E T
#define Key_PgDn 0x5100 // <PgDn> N - - -
#define Key_PgDnG 0x51E0 // <PgDn> Grey - G E T
#define Key_PgUp 0x4900 // <PgUp> N - - -
#define Key_PgUpG 0x49E0 // <PgUp> Grey - G E T
#define Key_Rgt 0x4D00 // <Right> N - - -
#define Key_RgtG 0x4DE0 // <Right> Grey - G E T
#define Key_Space 0x3920 // <Space> - - - -
#define Key_Tab 0x0F09 // <Tab> - - - -
#define Key_Up 0x4800 // <Up> N - - -
#define Key_UpG 0x48E0 // <Up> Grey - G E T
#define Key_Quo 0x2827 // <'> - - - -
#define Key_Min 0x0C2D // <-> - - - -
#define Key_Sls 0x352F // </> - - - -
#define Key_Smi 0x273B // <;> - - - -
#define Key_Equ 0x0D3D // <=> - - - -
#define Key_Lbr 0x1A5B // <[> - - - -
#define Key_Bsl 0x2B5C // <\> - - - -
#define Key_Rbr 0x1B5D // <]> - - - -
#define Key_Grv 0x2960 // <`> - - - -
// ------------------------------------------------------------------
//- Shift key --------- N G E T -
#define Key_S_0 0x0B29 // <0 )> - - - -
#define Key_S_1 0x0221 // <1 !> - - - -
#define Key_S_2 0x0340 // <2 @> - - - -
#define Key_S_3 0x0423 // <3 #> - - - -
#define Key_S_4 0x0524 // <4 $> - - - -
#define Key_S_5 0x0625 // <5 %> - - - -
#define Key_S_6 0x075E // <6 ^> - - - -
#define Key_S_7 0x0826 // <7 &> - - - -
#define Key_S_8 0x092A // <8 *> - - - -
#define Key_S_9 0x0A28 // <9 (> - - - -
#define Key_S_A 0x1E41 // <A> - - - -
#define Key_S_B 0x3042 // <B> - - - -
#define Key_S_C 0x2E43 // <C> - - - -
#define Key_S_D 0x2044 // <D> - - - -
#define Key_S_E 0x1245 // <E> - - - -
#define Key_S_F 0x2146 // <F> - - - -
#define Key_S_G 0x2247 // <G> - - - -
#define Key_S_H 0x2348 // <H> - - - -
#define Key_S_I 0x1749 // <I> - - - -
#define Key_S_J 0x244a // <J> - - - -
#define Key_S_K 0x254b // <K> - - - -
#define Key_S_L 0x264c // <L> - - - -
#define Key_S_M 0x324d // <M> - - - -
#define Key_S_N 0x314e // <N> - - - -
#define Key_S_O 0x184f // <O> - - - -
#define Key_S_P 0x1950 // <P> - - - -
#define Key_S_Q 0x1051 // <Q> - - - -
#define Key_S_R 0x1352 // <R> - - - -
#define Key_S_S 0x1F53 // <S> - - - -
#define Key_S_T 0x1454 // <T> - - - -
#define Key_S_U 0x1655 // <U> - - - -
#define Key_S_V 0x2F56 // <V> - - - -
#define Key_S_W 0x1157 // <W> - - - -
#define Key_S_X 0x2D58 // <X> - - - -
#define Key_S_Y 0x1559 // <Y> - - - -
#define Key_S_Z 0x2C5a // <Z> - - - -
#define Key_S_Quo 0x2822 // <' "> - - - -
#define Key_S_Com 0x333C // <, >> - - - -
#define Key_S_Min 0x0C5F // <- _> - - - -
#define Key_S_Dot 0x343E // <. <> - - - -
#define Key_S_Sls 0x353F // </ ?> - - - -
#define Key_S_Smi 0x273A // <; :> - - - -
#define Key_S_Equ 0x0D2B // <= +> - - - -
#define Key_S_Lbr 0x1A7B // <[ {> - - - -
#define Key_S_Bsl 0x2B7C // <\ |> - - - -
#define Key_S_Rbr 0x1B7D // <] }> - - - -
#define Key_S_Grv 0x297E // <` ~> - - - -
#define Key_S_5Num 0x4C35 // S <Cent 5> N - - -
#define Key_S_F1 0x5400 // S <F1> - - - -
#define Key_S_F2 0x5500 // S <F2> - - - -
#define Key_S_F3 0x5600 // S <F3> - - - -
#define Key_S_F4 0x5700 // S <F4> - - - -
#define Key_S_F5 0x5800 // S <F5> - - - -
#define Key_S_F6 0x5900 // S <F6> - - - -
#define Key_S_F7 0x5A00 // S <F7> - - - -
#define Key_S_F8 0x5B00 // S <F8> - - - -
#define Key_S_F9 0x5C00 // S <F9> - - - -
#define Key_S_F10 0x5D00 // S <F10> - - - -
#define Key_S_F11 0x8700 // S <F11> - - E -
#define Key_S_F12 0x8800 // S <F12> - - E -
#define Key_S_Tab 0x0F00 // S <Tab> - - - -
#if !defined(__UNIX__) || defined(__USE_NCURSES__)
#define Key_S_Ins 0xD200 // S <Ins> Grey - G E T
#define Key_S_Lft 0xCB00 // S <Left> Grey - G E T
#define Key_S_PgDn 0xD100 // S <PgDn> Grey - G E T
#define Key_S_PgUp 0xC900 // S <PgUp> Grey - G E T
#define Key_S_Rgt 0xCD00 // S <Right> Grey - G E T
#define Key_S_Up 0xC800 // S <Up> Grey - G E T
#define Key_S_Dwn 0xD000 // S <Down> Grey - G E T
#define Key_S_End 0xCF00 // S <End> Grey - G E T
#define Key_S_Home 0xC700 // S <Home> Grey - G E T
#define Key_S_Del 0xD300 // S <Del .> N - - -
#else
#define Key_S_Home 0x4737 // S <Home 7> N - - -
#define Key_S_HomeG 0x47E0 // S <Home> Grey - G E T
#define Key_S_Ins 0x5230 // S <Ins 0> N - - -
#define Key_S_InsG 0x52E0 // S <Ins> Grey - G E T
#define Key_S_Lft 0x4B34 // S <Left 4> N - - -
#define Key_S_LftG 0x4BE0 // S <Left> Grey - G E T
#define Key_S_PgDn 0x5133 // S <PgDn 3> N - - -
#define Key_S_PgDnG 0x51E0 // S <PgDn> Grey - G E T
#define Key_S_PgUp 0x4939 // S <PgUp 9> N - - -
#define Key_S_PgUpG 0x49E0 // S <PgUp> Grey - G E T
#define Key_S_Rgt 0x4D36 // S <Right 6> N - - -
#define Key_S_RgtG 0x4DE0 // S <Right> Grey - G E T
#define Key_S_Up 0x4838 // S <Up 8> N - - -
#define Key_S_UpG 0x48E0 // S <Up> Grey - G E T
#define Key_S_Dwn 0x5032 // S <Down 2> N - - -
#define Key_S_DwnG 0x50E0 // S <Down> Grey - G E T
#define Key_S_End 0x4F31 // S <End 1> N - - -
#define Key_S_EndG 0x4FE0 // S <End> Grey - G E T
#define Key_S_Del 0x532E // S <Del .> N - - -
#define Key_S_DelG 0x53E0 // S <Del> Grey - G E T
#endif
// ------------------------------------------------------------------
//- Control key ------- N G E T -
#define Key_C_2 0x0300 // C <2 @> [NUL] - - - -
#define Key_C_A 0x1E01 // C <A> [SOH] - - - -
#define Key_C_B 0x3002 // C <B> [STX] - - - -
#define Key_C_C 0x2E03 // C <C> [ETX] - - - -
#define Key_C_D 0x2004 // C <D> [EOT] - - - -
#define Key_C_E 0x1205 // C <E> [ENQ] - - - -
#define Key_C_F 0x2106 // C <F> [ACK] - - - -
#define Key_C_G 0x2207 // C <G> [BEL] - - - -
#define Key_C_H 0x2308 // C <H> [BS] - - - -
#define Key_C_I 0x1709 // C <I> [HT] - - - -
#define Key_C_J 0x240A // C <J> [LF] - - - -
#define Key_C_K 0x250B // C <K> [VT] - - - -
#define Key_C_L 0x260C // C <L> [FF] - - - -
#define Key_C_M 0x320D // C <M> [CR] - - - -
#define Key_C_N 0x310E // C <N> [SO] - - - -
#define Key_C_O 0x180F // C <O> [SI] - - - -
#define Key_C_P 0x1910 // C <P> [DLE] - - - -
#define Key_C_Q 0x1011 // C <Q> [DC1] - - - -
#define Key_C_R 0x1312 // C <R> [DC2] - - - -
#define Key_C_S 0x1F13 // C <S> [DC3] - - - -
#define Key_C_T 0x1414 // C <T> [DC4] - - - -
#define Key_C_U 0x1615 // C <U> [NAK] - - - -
#define Key_C_V 0x2F16 // C <V> [SYN] - - - -
#define Key_C_W 0x1117 // C <W> [ETB] - - - -
#define Key_C_X 0x2D18 // C <X> [CAN] - - - -
#define Key_C_Y 0x1519 // C <Y> [EM] - - - -
#define Key_C_Z 0x2C1A // C <Z> [SUB] - - - -
#define Key_C_StrG 0x7200 // C <*> Grey - G E -
#define Key_C_PlsG 0x9000 // C <+> Grey - G E -
#define Key_C_Min 0x0C1F // C <- _> - - - -
#define Key_C_MinG 0x8E00 // C <-> Grey - G E -
#define Key_C_6 0x071E // C <7 &> [RS] - - - -
#define Key_C_Brk 0xFFFF // C <Break> Grey - - - -
#define Key_C_BS 0x0E7F // C <BS> [RUB] - - - -
#define Key_C_5Num 0x8F00 // C <Cent 5> N - E -
#define Key_C_Del 0x9300 // C <Del 2> - - E -
#define Key_C_DelG 0x93E0 // C <Del> Grey - G E T
#define Key_C_Dwn 0x9100 // C <Dwn 2> - - E -
#define Key_C_DwnG 0x91E0 // C <Dwn> Grey - G E T
#define Key_C_End 0x7500 // C <End 1> N - - -
#define Key_C_EndG 0x75E0 // C <End> Grey - G E T
#define Key_C_EntG 0xE00A // C <Enter> Grey - G E T
#define Key_C_Ent 0x1C0A // C <Enter> [LF] - - - -
#define Key_C_F1 0x5E00 // C <F1> - - - -
#define Key_C_F2 0x5F00 // C <F2> - - - -
#define Key_C_F3 0x6000 // C <F3> - - - -
#define Key_C_F4 0x6100 // C <F4> - - - -
#define Key_C_F5 0x6200 // C <F5> - - - -
#define Key_C_F6 0x6300 // C <F6> - - - -
#define Key_C_F7 0x6400 // C <F7> - - - -
#define Key_C_F8 0x6500 // C <F8> - - - -
#define Key_C_F9 0x6600 // C <F9> - - - -
#define Key_C_F10 0x6700 // C <F10> - - - -
#define Key_C_F11 0x8900 // C <F11> - - E -
#define Key_C_F12 0x8A00 // C <F12> - - E -
#define Key_C_Home 0x7700 // C <Home 7> N - - -
#define Key_C_HomeG 0x77E0 // C <Home> Grey - G E T
#define Key_C_Ins 0x9200 // C <Ins 0> - - E -
#define Key_C_InsG 0x92E0 // C <Ins> Grey - G E T
#define Key_C_Lft 0x7300 // C <Left 4> N - - -
#define Key_C_LftG 0x73E0 // C <Left> Grey - G E T
#define Key_C_PgDn 0x7600 // C <PgDn 3> N - - -
#define Key_C_PgDnG 0x76E0 // C <PgDn> Grey - G E T
#define Key_C_PgUp 0x8400 // C <PgUp 9> N - - -
#define Key_C_PgUpG 0x84E0 // C <PgUp> Grey - G E T
#define Key_C_Rgt 0x7400 // C <Right 6> N - - -
#define Key_C_RgtG 0x74E0 // C <Right> Grey - G E T
#define Key_C_Tab 0x9400 // C <Tab> - - E -
#define Key_C_Up 0x8D00 // C <Up 8> - - E -
#define Key_C_UpG 0x8DE0 // C <Up> Grey - G E T
#define Key_C_Lbr 0x1A1B // C <[ {> [ESC] - - - -
#define Key_C_Bsl 0x2B1C // C <\ |> [FS] - - - -
#define Key_C_Rbr 0x1B1D // C <] }> [GS] - - - -
// ------------------------------------------------------------------
//- Alt key ----------- N G E T -
#define Key_A_0 0x8100 // A <0 )> - - - -
#define Key_A_1 0x7800 // A <1 !> - - - -
#define Key_A_2 0x7900 // A <2 @> - - - -
#define Key_A_3 0x7A00 // A <3 #> - - - -
#define Key_A_4 0x7B00 // A <4 ^> - - - -
#define Key_A_5 0x7C00 // A <5 %> - - - -
#define Key_A_6 0x7D00 // A <6 %> - - - -
#define Key_A_7 0x7E00 // A <7 &> - - - -
#define Key_A_8 0x7F00 // A <8 *> - - - -
#define Key_A_9 0x8000 // A <9 (> - - - -
#define Key_A_A 0x1E00 // A <A> - - - -
#define Key_A_B 0x3000 // A <B> - - - -
#define Key_A_C 0x2E00 // A <C> - - - -
#define Key_A_D 0x2000 // A <D> - - - -
#define Key_A_E 0x1200 // A <E> - - - -
#define Key_A_F 0x2100 // A <F> - - - -
#define Key_A_G 0x2200 // A <G> - - - -
#define Key_A_H 0x2300 // A <H> - - - -
#define Key_A_I 0x1700 // A <I> - - - -
#define Key_A_J 0x2400 // A <J> - - - -
#define Key_A_K 0x2500 // A <K> - - - -
#define Key_A_L 0x2600 // A <L> - - - -
#define Key_A_M 0x3200 // A <M> - - - -
#define Key_A_N 0x3100 // A <N> - - - -
#define Key_A_O 0x1800 // A <O> - - - -
#define Key_A_P 0x1900 // A <P> - - - -
#define Key_A_Q 0x1000 // A <Q> - - - -
#define Key_A_R 0x1300 // A <R> - - - -
#define Key_A_S 0x1F00 // A <S> - - - -
#define Key_A_T 0x1400 // A <T> - - - -
#define Key_A_U 0x1600 // A <U> - - - -
#define Key_A_V 0x2F00 // A <V> - - - -
#define Key_A_W 0x1100 // A <W> - - - -
#define Key_A_X 0x2D00 // A <X> - - - -
#define Key_A_Y 0x1500 // A <Y> - - - -
#define Key_A_Z 0x2C00 // A <Z> - - - -
#define Key_A_Quo 0x2800 // A <' "> - - E -
#define Key_A_PlsG 0x4E00 // A <+> Grey - G E -
#define Key_A_Com 0x3300 // A <, <> - - E -
#define Key_A_Min 0x8200 // A <- _> - - - -
#define Key_A_MinG 0x4A00 // A <-> Grey - G E -
#define Key_A_Dot 0x3400 // A <. >> - - E -
#define Key_A_Sls 0x3500 // A </ ?> - - E -
#define Key_A_Smi 0x2700 // A <; :> - - E -
#define Key_A_Equ 0x8300 // A <= +> - - - -
#define Key_A_BS 0x0E00 // A <BS> - - E -
#define Key_A_5Num 0x4C00 // A <Cent 5> N - E -
#define Key_A_Del 0xA300 // A <Del> - - E -
#define Key_A_DelG 0xA300 // A <Del> Grey - G E -
#define Key_A_Dwn 0xA000 // A <Dwn> - - E -
#define Key_A_DwnG 0xA000 // A <Dwn> Grey - G E -
#define Key_A_End 0x9F00 // A <End> - - E -
#define Key_A_EndG 0x9F00 // A <End> Grey - G E -
#define Key_A_EntG 0xA600 // A <Enter Grey - G E -
#define Key_A_Ent 0x1C00 // A <Enter> - - E -
#define Key_A_Esc 0x0100 // A <Esc> - - E -
#define Key_A_F1 0x6800 // A <F1> - - - -
#define Key_A_F2 0x6900 // A <F2> - - - -
#define Key_A_F3 0x6A00 // A <F3> - - - -
#define Key_A_F4 0x6B00 // A <F4> - - - -
#define Key_A_F5 0x6C00 // A <F5> - - - -
#define Key_A_F6 0x6D00 // A <F6> - - - -
#define Key_A_F7 0x6E00 // A <F7> - - - -
#define Key_A_F8 0x6F00 // A <F8> - - - -
#define Key_A_F9 0x7000 // A <F9> - - - -
#define Key_A_F10 0x7100 // A <F10> - - - -
#define Key_A_F11 0x8B00 // A <F11> - - E -
#define Key_A_F12 0x8C00 // A <F12> - - E -
#define Key_A_Home 0x9700 // A <Home> - - E -
#define Key_A_HomeG 0x9700 // A <Home> Grey - G E -
#define Key_A_Ins 0xA200 // A <Ins> - - E -
#define Key_A_InsG 0xA200 // A <Ins> Grey - G E -
#define Key_A_Lft 0x9B00 // A <Left> - - E -
#define Key_A_LftG 0x9B00 // A <Left> Grey - G E -
#define Key_A_PgDn 0xA100 // A <PgDn> - - E -
#define Key_A_PgDnG 0xA100 // A <PgDn> Grey - G E -
#define Key_A_PgUp 0x9900 // A <PgUp> - - E -
#define Key_A_PgUpG 0x9900 // A <PgUp> Grey - G E -
#define Key_A_Rgt 0x9D00 // A <Right - - E -
#define Key_A_RgtG 0x9D00 // A <Right Grey - G E -
#define Key_A_Tab 0xA500 // A <Tab> - - E -
#define Key_A_Up 0x9800 // A <Up> - - E -
#define Key_A_UpG 0x9800 // A <Up> Grey - G E -
#define Key_A_Lbr 0x1A00 // A <[ {> - - E -
#define Key_A_Bsl 0x2B00 // A <\ |> - - E -
#define Key_A_Rbr 0x1B00 // A <] }> - - E -
#define Key_A_Grv 0x2900 // A <` ~> - - E -
// ------------------------------------------------------------------
//- Mouse KeyCode Returns -------
#define Key_M_Scn 0xD4 // Scan-code
#define Key_M_Clk 0x30 // Single-click keycodes
#define Key_M_ClkL 0xD431 // Left-button
#define Key_M_ClkR 0xD432 // Right-button
#define Key_M_ClkM 0xD434 // Middle-button
#define Key_M_DClk 0x20 // Double-click keycodes
#define Key_M_DClkL 0xD421 // Left-button
#define Key_M_DClkR 0xD422 // Right-button
#define Key_M_DClkM 0xD424 // Middle-button
#define Key_M_Prs 0x30 // Single-press keycodes
#define Key_M_PrsL 0xD431 // Left-button
#define Key_M_PrsR 0xD432 // Right-button
#define Key_M_PrsM 0xD434 // Middle-button
#define Key_M_Rel 0x40 // Single-release keycodes
#define Key_M_RelL 0xD441 // Left-button
#define Key_M_RelR 0xD442 // Right-button
#define Key_M_RelM 0xD444 // Middle-button
#define Key_M_Mov 0x50 // Mouse motion keycodes
#define Key_M_Up 0xD450 // Motion [Up]
#define Key_M_Dwn 0xD451 // Motion [Down]
#define Key_M_Lft 0xD452 // Motion [Left]
#define Key_M_Rgt 0xD453 // Motion [Right]
// ------------------------------------------------------------------
// Goldware internal keycodes
#define Key_Tick 0x0200 // Timer tick
#define Key_Auto 0xFD00 // Auto macro
#define Key_Macro 0xFE00 // Macro
// ------------------------------------------------------------------
#endif
// ------------------------------------------------------------------

330
goldlib/gcui/gkbdgetm.cpp Normal file
View File

@ -0,0 +1,330 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Keyboard functions.
// ------------------------------------------------------------------
#include <gkbdcode.h>
#include <gkbdbase.h>
#include <gmemdbg.h>
#include <gwinall.h>
#include <gutlmtsk.h>
#ifdef GOLD_MOUSE
#include <gmoubase.h>
#endif
// ------------------------------------------------------------------
// Event sources
const int GEVT_KEYBOARD = 0;
const int GEVT_BUFFER = 1;
const int GEVT_MOUSE = 2;
const int GEVT_TICK = 3;
// ------------------------------------------------------------------
void gkbdtickpressreset() {
gkbd.tickpress = gclock();
}
// ------------------------------------------------------------------
void gkbdtickvaluereset() {
gkbd.tickvalue = gclock();
}
// ------------------------------------------------------------------
gkey kbmhit() {
gkey k;
// Check for keypress in internal buffer or keyboard
if(gkbd.kbuf) {
gkbd.source = GEVT_BUFFER;
k = gkbd.kbuf->xch;
}
else {
gkbd.source = GEVT_KEYBOARD;
k = kbxhit();
}
return k;
}
// ------------------------------------------------------------------
static void kbd_call_func(VfvCP func) {
int row, col;
bool hidden = vcurhidden();
vposget(&row,&col);
_menu_t* menu = gwin.cmenu;
(*func)();
gwin.cmenu = menu;
vposset(row,col);
if(hidden)
vcurhide();
else
vcurshow();
}
// ------------------------------------------------------------------
static _item_t* find_hotkey(_menu_t* wmenu, gkey xch) {
_item_t* witem;
_item_t* item;
// do while more items in this menu
for(witem=wmenu->item; witem!=NULL; witem=witem->prev) {
// if hot key matches keypress, return its item address
if(witem->hotkey==xch and (!(witem->fmask&M_NOSEL)) and witem->select!=NULL)
return witem;
// if current item has a child menu, process it
if(witem->child!=NULL) {
item = find_hotkey((_menu_t*)witem->child, xch);
if(item!=NULL)
return item;
}
}
// return address of item found
return witem;
}
// ------------------------------------------------------------------
static void makeextkey(gkey xshift, gkey& xkey) {
switch(xkey) {
case Key_Home:
case Key_C_Home:
if(xshift & ALT)
xkey = Key_A_HomeG;
if(xshift & (LSHIFT | RSHIFT))
KCodScn(xkey) |= 0x80;
break;
case Key_End:
case Key_C_End:
if(xshift & ALT)
xkey = Key_A_EndG;
if(xshift & (LSHIFT | RSHIFT))
KCodScn(xkey) |= 0x80;
break;
case Key_Up:
if(xshift & ALT)
xkey = Key_A_UpG;
else if(xshift & GCTRL)
xkey = Key_C_Up;
if(xshift & (LSHIFT | RSHIFT))
KCodScn(xkey) |= 0x80;
break;
case Key_Dwn:
if(xshift & ALT)
xkey = Key_A_DwnG;
else if(xshift & GCTRL)
xkey = Key_C_Dwn;
if(xshift & (LSHIFT | RSHIFT))
KCodScn(xkey) |= 0x80;
break;
case Key_Lft:
if(xshift & ALT)
xkey = Key_A_LftG;
if(xshift & (LSHIFT | RSHIFT))
KCodScn(xkey) |= 0x80;
break;
case Key_Rgt:
if(xshift & ALT)
xkey = Key_A_RgtG;
if(xshift & (LSHIFT | RSHIFT))
KCodScn(xkey) |= 0x80;
break;
case Key_PgUp:
if(xshift & ALT)
xkey = Key_A_PgUpG;
if(xshift & (LSHIFT | RSHIFT))
KCodScn(xkey) |= 0x80;
break;
case Key_PgDn:
if(xshift & ALT)
xkey = Key_A_PgDnG;
if(xshift & (LSHIFT | RSHIFT))
KCodScn(xkey) |= 0x80;
break;
case Key_Ins:
if(xshift & ALT)
xkey = Key_A_InsG;
else if(xshift & GCTRL)
xkey = Key_C_Ins;
if(xshift & (LSHIFT | RSHIFT))
KCodScn(xkey) |= 0x80;
break;
case Key_Del:
if(xshift & ALT)
xkey = Key_A_DelG;
else if(xshift & GCTRL)
xkey = Key_C_Del;
if(xshift & (LSHIFT | RSHIFT))
KCodScn(xkey) |= 0x80;
break;
}
}
// ------------------------------------------------------------------
extern int blanked;
gkey getxch(int __tick) {
gkey k;
while(1) {
// Keyboard polling loop
if(gkbd.polling) {
while(not kbmhit()) {
Clock thistick = gclock();
long tickdiff = thistick - gkbd.tickvalue;
if(tickdiff < 0) {
gkbd.tickvalue = thistick;
tickdiff = gkbd.tickinterval + 1;
}
if(tickdiff >= gkbd.tickinterval) {
gkbd.tickvalue = thistick;
if(gkbd.tickfunc) {
gkbd.inidle = true;
(*gkbd.tickfunc)();
gkbd.inidle = false;
}
if(__tick)
kbput(Key_Tick);
}
if(gmtsk.detected)
gmtsk.timeslice();
}
}
// Get key from internal buffer or keyboard
if(gkbd.kbuf) {
gkbd.source = GEVT_BUFFER;
k = gkbd.kbuf->xch;
KBuf* _kbuf = gkbd.kbuf->next;
throw_free(gkbd.kbuf);
gkbd.kbuf = _kbuf;
if(gkbd.kbuf)
gkbd.kbuf->prev = NULL;
}
else {
gkbd.source = GEVT_KEYBOARD;
k = kbxget();
gkey s = kbxget(2); // Read shift status
if(not gkbd.extkbd) {
if(s & (LSHIFT|RSHIFT|GCTRL|ALT))
makeextkey(s,k);
}
}
// Note time of keypress unless it's a tick
if(k != Key_Tick)
gkbdtickpressreset();
// Search through onkey linked list for a
// matching defined onkey. If one is found,
// then save the current environment, call the
// onkey's function, and restore the environment.
if(not blanked) {
KBnd* _onkey = gkbd.onkey;
while(_onkey) {
if(_onkey->keycode == k) {
gkbd.curronkey = _onkey;
kbd_call_func(_onkey->func);
#ifdef GOLD_MOUSE
if(gkbd.inmenu and gmou.FreeCursor())
return 0;
#endif
break;
}
_onkey = _onkey->prev;
}
if(_onkey) {
if(not _onkey->pass or (_onkey->pass >= 0xFE00))
k = 0;
else
k = _onkey->pass;
}
else {
// Search for a menu hot key. If one is found,
// then save the current environment, call the
// hotkey's function, and restore the environment.
if(gwin.menu) {
_item_t* item = find_hotkey(gwin.menu,k);
if(item) {
gwin.menu->hotkey = true;
kbd_call_func(item->select);
#ifdef GOLD_MOUSE
if(gkbd.inmenu and gmou.FreeCursor())
return 0;
#endif
k = 0;
}
}
}
}
// If we still have a keycode, exit the loop
if(k)
break;
}
// Return keycode
return k;
}
// ------------------------------------------------------------------

68
goldlib/gcui/gkbdwait.cpp Normal file
View File

@ -0,0 +1,68 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Keyboard functions
// ------------------------------------------------------------------
#include <gkbdbase.h>
#include <gkbdcode.h>
#include <gtimall.h>
#include <gutlmtsk.h>
// ------------------------------------------------------------------
// Halts execution until a key is pressed
gkey waitkey() {
clearkeys();
return getxch();
}
// ------------------------------------------------------------------
// Halts execution until a key is pressed or the specified time
// period has expired
gkey waitkeyt(int duration) {
clearkeys();
Clock stop = gclock() + duration;
Clock sliced_time = gclock();
while(1) {
if(kbmhit())
return getxch();
if(gclock() >= stop)
return 0;
if(gclock() - sliced_time >= 10) {
if(gkbd.tickfunc)
(*gkbd.tickfunc)();
sliced_time = gclock();
}
gmtsk.timeslice();
}
}
// ------------------------------------------------------------------

137
goldlib/gcui/gmnubase.h Normal file
View File

@ -0,0 +1,137 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Menu class.
// ------------------------------------------------------------------
#ifndef __gmnubase_h
#define __gmnubase_h
// ------------------------------------------------------------------
#include <gwinall.h>
// ------------------------------------------------------------------
// Menu items
typedef struct _item_t GMnuItm;
// ------------------------------------------------------------------
// Menu class
class GMnu {
protected:
int bordertype;
vattr bordercolor;
vattr textcolor;
vattr quickcolor;
vattr noselcolor;
vattr barcolor;
vattr shadowcolor;
const char* title;
int titlepos;
vattr titlecolor;
int deschdl;
int descrow;
int desccolumn;
vattr desccolor;
int helpnumber;
int beginrow;
int begincolumn;
int beginwidth;
int beginheight;
VfvCP menuopen;
int itemmask;
int escape;
int overtag;
int finaltag;
int status;
int depth;
struct {
int tag;
int type;
int winrow;
int wincolumn;
int winwidth;
int winheight;
int itemrow;
int itemcolumn;
} stack[10];
public:
void Init();
void SetBorder(int type, vattr color);
void SetColor(vattr text, vattr quick, vattr nosel, vattr bar, vattr shadow = DEFATTR);
void SetTitle(const char* title, vattr color, int pos=TCENTER);
void SetTitle(const char* title);
void SetDesc(int hdl, int row, int col, vattr color);
void SetPos(int row, int col, int width=0, int height=0);
void SetEsc(int option);
void SetHelp(int help);
void SetMask(int mask);
void SetTag(int tag);
void Begin(int type=M_VERT);
void BeginPullDown(int type=0) { Begin(M_VERT|M_PD|type); }
void End();
void Start();
void Item(int tag, const char* text);
void Item(int tag, const char* text, int fmask);
void Item(int tag, const char* text, VfvCP select, int fmask=M_CLOSE);
void Item(int tag, const char* text, int fmask, VfvCP select, gkey hotkey=0);
void ItemDesc(const char* text);
void ItemSep();
void ItemFuncs(VfvCP before, VfvCP after);
void SetNextItem(int tag);
void DisableItem(int tag);
void EnableItem(int tag);
GMnuItm* FindItem(int tag);
int FinalTag() { return finaltag; }
};
// ------------------------------------------------------------------
#endif
// ------------------------------------------------------------------

456
goldlib/gcui/gmoubase.cpp Normal file
View File

@ -0,0 +1,456 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Mousing: class GMou member functions implementation.
// ------------------------------------------------------------------
#include <gmemall.h>
#include <gvidall.h>
#include <gmoubase.h>
// ------------------------------------------------------------------
#ifdef GOLD_MOUSE
// ------------------------------------------------------------------
GMou gmou;
// ------------------------------------------------------------------
GMou::GMou() {
detected = false;
Reset();
}
// ------------------------------------------------------------------
GMou::~GMou() {
Reset();
}
// ------------------------------------------------------------------
void GMou::SetLevel(int __level) {
if(detected) {
level = __level;
if(level < GMOU_LEVEL_NONE)
level = GMOU_LEVEL_NONE;
else if(level > GMOU_LEVEL_FULL)
level = GMOU_LEVEL_FULL;
}
else {
level = GMOU_LEVEL_NONE;
}
}
// ------------------------------------------------------------------
void GMou::Reset() {
level = GMOU_LEVEL_NONE;
hidden = 1;
hit.button = 0;
hit.count = 0;
hit.row = 0;
hit.column = 0;
if(detected)
Init();
}
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// DOS MOUSING - BEGIN
// ------------------------------------------------------------------
// ------------------------------------------------------------------
#if defined(__MSDOS__)
// ------------------------------------------------------------------
void GMou::Init() {
i86 cpu;
cpu.ax(MSMOUSE_RESET_DRIVER);
cpu.genint(MSMOUSE_INT);
if(cpu.ax())
detected = true;
}
// ------------------------------------------------------------------
void GMou::ClearEvents() {
if(level) {
i86 cpu;
cpu.ax(MSMOUSE_GET_BUTTON_PRESS);
cpu.bx(GMOU_LEFT_BUTTON);
cpu.genint(MSMOUSE_INT);
cpu.ax(MSMOUSE_GET_BUTTON_PRESS);
cpu.bx(GMOU_RIGHT_BUTTON);
cpu.genint(MSMOUSE_INT);
cpu.ax(MSMOUSE_GET_BUTTON_RELEASE);
cpu.bx(GMOU_LEFT_BUTTON);
cpu.genint(MSMOUSE_INT);
cpu.ax(MSMOUSE_GET_BUTTON_RELEASE);
cpu.bx(GMOU_RIGHT_BUTTON);
cpu.genint(MSMOUSE_INT);
}
}
// ------------------------------------------------------------------
void GMou::GetStatus() {
if(level) {
i86 cpu;
cpu.ax(MSMOUSE_GET_BUTTONS_AND_POSITION);
cpu.genint(MSMOUSE_INT);
hit.button = cpu.bx();
hit.count = 0;
hit.column = cpu.cx() / gvid->curr.screen.cwidth;
hit.row = cpu.dx() / gvid->curr.screen.cheight;
}
}
// ------------------------------------------------------------------
void GMou::GetPress(int __button) {
if(level) {
i86 cpu;
cpu.ax(MSMOUSE_GET_BUTTON_PRESS);
cpu.bx((word)__button);
cpu.genint(MSMOUSE_INT);
hit.button = cpu.ax();
hit.count = cpu.bx();
hit.column = cpu.cx() / gvid->curr.screen.cwidth;
hit.row = cpu.dx() / gvid->curr.screen.cheight;
}
}
// ------------------------------------------------------------------
void GMou::GetRelease(int __button) {
if(level) {
i86 cpu;
cpu.ax(MSMOUSE_GET_BUTTON_RELEASE);
cpu.bx((word)__button);
cpu.genint(MSMOUSE_INT);
hit.button = cpu.ax();
hit.count = cpu.bx();
hit.column = cpu.cx() / gvid->curr.screen.cwidth;
hit.row = cpu.dx() / gvid->curr.screen.cheight;
}
}
// ------------------------------------------------------------------
void GMou::SetCursor(int __curtype, int __smask, int __cmask) {
if(level) {
i86 cpu;
cpu.ax(MSMOUSE_SET_TEXT_CURSOR);
cpu.bx((word)__curtype);
cpu.cx((word)__smask);
cpu.dx((word)__cmask);
cpu.genint(MSMOUSE_INT);
}
}
// ------------------------------------------------------------------
void GMou::SetPosition(int __row, int __col) {
if(level) {
i86 cpu;
cpu.ax(MSMOUSE_SET_CURSOR_POSITION);
cpu.cx((word)(__col * gvid->curr.screen.cwidth));
cpu.dx((word)(__row * gvid->curr.screen.cheight));
cpu.genint(MSMOUSE_INT);
}
}
// ------------------------------------------------------------------
void GMou::HideCursor() {
if(level) {
if(not hidden) {
i86 cpu;
cpu.ax(MSMOUSE_HIDE_CURSOR);
cpu.genint(MSMOUSE_INT);
hidden = true;
}
}
}
// ------------------------------------------------------------------
void GMou::ShowCursor() {
if(level) {
i86 cpu;
cpu.ax(MSMOUSE_SHOW_CURSOR);
cpu.genint(MSMOUSE_INT);
hidden = false;
}
}
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// DOS MOUSING - END
// ------------------------------------------------------------------
// ------------------------------------------------------------------
#endif
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// OS/2 MOUSING - BEGIN
// ------------------------------------------------------------------
// ------------------------------------------------------------------
#if defined(__OS2__)
// ------------------------------------------------------------------
void GMou::Init() {
#if 0
if(MouOpen(NULL, &hmou) == 0) {
USHORT _mask = MOUSE_BN1_DOWN|MOUSE_BN2_DOWN|MOUSE_BN3_DOWN;
MouSetEventMask(&_mask, hmou);
detected = true;
}
#endif
}
// ------------------------------------------------------------------
void GMou::ClearEvents() {
if(level) {
MouFlushQue(hmou);
}
}
// ------------------------------------------------------------------
void GMou::GetStatus() {
if(level) {
PTRLOC _pos;
MouGetPtrPos(&_pos, hmou);
hit.button = 0;
hit.count = 0;
hit.column = _pos.col;
hit.row = _pos.row;
MOUEVENTINFO _event;
USHORT _wait = MOU_NOWAIT;
if(MouReadEventQue(&_event, &_wait, hmou) == 0) {
if(_event.fs & (MOUSE_BN1_DOWN|MOUSE_MOTION_WITH_BN1_DOWN))
hit.button |= GMOU_LEFT_PRESSED;
if(_event.fs & (MOUSE_BN2_DOWN|MOUSE_MOTION_WITH_BN2_DOWN))
hit.button |= GMOU_RIGHT_PRESSED;
if(_event.fs & (MOUSE_BN3_DOWN|MOUSE_MOTION_WITH_BN3_DOWN))
hit.button |= GMOU_MIDDLE_PRESSED;
}
}
}
// ------------------------------------------------------------------
void GMou::GetPress(int __button) {
NW(__button);
#if 0
if(level) {
hit.button = 0;
hit.count = 0;
hit.column = 0;
hit.row = 0;
MOUQUEINFO _que;
MouGetNumQueEl(&_que, hmou);
hit.count = _que.cEvents;
if(hit.count) {
MOUEVENTINFO _event;
USHORT _wait = MOU_WAIT;
if(MouReadEventQue(&_event, &_wait, hmou) == 0) {
if(_event.fs & (MOUSE_BN1_DOWN|MOUSE_MOTION_WITH_BN1_DOWN))
hit.button |= GMOU_LEFT_PRESSED;
if(_event.fs & (MOUSE_BN2_DOWN|MOUSE_MOTION_WITH_BN2_DOWN))
hit.button |= GMOU_RIGHT_PRESSED;
if(_event.fs & (MOUSE_BN3_DOWN|MOUSE_MOTION_WITH_BN3_DOWN))
hit.button |= GMOU_MIDDLE_PRESSED;
hit.column = _event.col;
hit.row = _event.row;
}
}
}
#endif
}
// ------------------------------------------------------------------
void GMou::GetRelease(int __button) {
NW(__button);
#if 0
if(level) {
hit.button = 0;
hit.count = 0;
hit.column = 0;
hit.row = 0;
MOUQUEINFO _que;
MouGetNumQueEl(&_que, hmou);
hit.count = _que.cEvents;
if(hit.count) {
MOUEVENTINFO _event;
USHORT _wait = MOU_WAIT;
if(MouReadEventQue(&_event, &_wait, hmou) == 0) {
if(_event.fs & (MOUSE_BN1_DOWN|MOUSE_MOTION_WITH_BN1_DOWN))
hit.button |= GMOU_LEFT_PRESSED;
if(_event.fs & (MOUSE_BN2_DOWN|MOUSE_MOTION_WITH_BN2_DOWN))
hit.button |= GMOU_RIGHT_PRESSED;
if(_event.fs & (MOUSE_BN3_DOWN|MOUSE_MOTION_WITH_BN3_DOWN))
hit.button |= GMOU_MIDDLE_PRESSED;
hit.column = _event.col;
hit.row = _event.row;
}
}
}
#endif
}
// ------------------------------------------------------------------
void GMou::SetCursor(int __curtype, int __smask, int __cmask) {
if(level) {
// Not implemented yet
NW(__curtype);
NW(__smask);
NW(__cmask);
}
}
// ------------------------------------------------------------------
void GMou::SetPosition(int __row, int __col) {
if(level) {
PTRLOC _pos;
_pos.row = (USHORT)__row;
_pos.col = (USHORT)__col;
MouSetPtrPos(&_pos, hmou);
}
}
// ------------------------------------------------------------------
void GMou::HideCursor() {
if(level) {
if(not hidden) {
NOPTRRECT _rect;
_rect.row = 0;
_rect.col = 0;
_rect.cRow = (USHORT)(gvid->curr.screen.rows-1);
_rect.cCol = (USHORT)(gvid->curr.screen.columns-1);
MouRemovePtr(&_rect, hmou);
hidden = true;
}
}
}
// ------------------------------------------------------------------
void GMou::ShowCursor() {
if(level) {
MouDrawPtr(hmou);
hidden = false;
}
}
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// OS/2 MOUSING - END
// ------------------------------------------------------------------
// ------------------------------------------------------------------
#endif
// ------------------------------------------------------------------
// Dummy definitions when mouse support is not defined
void GMou::Init() {}
void GMou::ClearEvents() {}
void GMou::GetStatus() {}
void GMou::GetPress(int) {}
void GMou::GetRelease(int) {}
void GMou::SetCursor(int, int, int) {}
void GMou::SetPosition(int, int) {}
void GMou::HideCursor() {}
void GMou::ShowCursor() {}
// ------------------------------------------------------------------
#endif // GOLD_MOUSE
// ------------------------------------------------------------------

174
goldlib/gcui/gmoubase.h Normal file
View File

@ -0,0 +1,174 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Mousing (declarations).
// ------------------------------------------------------------------
#ifndef __gmoubase_h
#define __gmoubase_h
// ------------------------------------------------------------------
#include <gdefs.h>
// ------------------------------------------------------------------
#ifdef GOLD_MOUSE
// ------------------------------------------------------------------
// Mouse constants
const int GMOU_LEVEL_NONE = 0; // No mouse support
const int GMOU_LEVEL_KEYS = 1; // Mouse movement emulates arrow keys
const int GMOU_LEVEL_CURS = 2; // Free-moving mouse cursor where supported
const int GMOU_LEVEL_FULL = 3; // Full mouse support (MS_KEYS | MS_CURS)
const int GMOU_EVENT_MAX = 10;
const int GMOU_LEFT_BUTTON = 0x00;
const int GMOU_RIGHT_BUTTON = 0x01;
const int GMOU_LEFT_PRESSED = 0x01;
const int GMOU_RIGHT_PRESSED = 0x02;
const int GMOU_MIDDLE_PRESSED = 0x04;
const int GMOU_MOVED = 0x01;
const int GMOU_PRESSED_LEFT = 0x02;
const int GMOU_RELEASED_LEFT = 0x04;
const int GMOU_PRESSED_RIGHT = 0x08;
const int GMOU_RELEASED_RIGHT = 0x10;
const int GMOU_PRESSED_MIDDLE = 0x20;
const int GMOU_RELEASED_MIDDLE = 0x40;
const int GMOU_EVENT_LEFT = GMOU_PRESSED_LEFT | GMOU_RELEASED_LEFT;
const int GMOU_EVENT_RIGHT = GMOU_PRESSED_RIGHT | GMOU_RELEASED_RIGHT;
const int GMOU_EVENT_MIDDLE = GMOU_PRESSED_MIDDLE | GMOU_RELEASED_MIDDLE;
// ------------------------------------------------------------------
// MS MOUSE interrupt
const word MSMOUSE_INT = 0x33;
// ------------------------------------------------------------------
// MS MOUSE functions
const word MSMOUSE_RESET_DRIVER = 0x00;
const word MSMOUSE_SHOW_CURSOR = 0x01;
const word MSMOUSE_HIDE_CURSOR = 0x02;
const word MSMOUSE_GET_BUTTONS_AND_POSITION = 0x03;
const word MSMOUSE_SET_CURSOR_POSITION = 0x04;
const word MSMOUSE_GET_BUTTON_PRESS = 0x05;
const word MSMOUSE_GET_BUTTON_RELEASE = 0x06;
const word MSMOUSE_SET_HORIZONTAL_RANGE = 0x07;
const word MSMOUSE_SET_VERTIAL_RANGE = 0x08;
const word MSMOUSE_SET_GRAPHICS_CURSOR = 0x09;
const word MSMOUSE_SET_TEXT_CURSOR = 0x0A;
// ------------------------------------------------------------------
// Mouse class
class GMou {
#if 0
#ifdef __OS2__
HMOU hmou;
#endif
#endif
public:
int detected; // true if a mouse driver was detected
int level; // Mouse support level (GMOU_LEVEL_xxxx)
int hidden; // Depth of cursor hides
struct {
int button;
int count;
int row;
int column;
} hit;
GMou();
~GMou();
void SetLevel(int __level);
void Reset();
void Init();
void ClearEvents();
void GetStatus();
void GetPress(int __button);
void GetRelease(int __button);
void SetCursor(int __curtype, int __smask, int __cmask);
void SetPosition(int __row, int __col);
void HideCursor();
void ShowCursor();
int Hidden() { return make_bool(hidden); }
int Enabled() { return level > GMOU_LEVEL_NONE; }
int FreeCursor() { return level & GMOU_LEVEL_CURS; }
int KeysEmulate() { return level & GMOU_LEVEL_KEYS; }
int Button() { return hit.button; }
int LeftButton() { return hit.button & GMOU_LEFT_PRESSED; }
int RightButton() { return hit.button & GMOU_RIGHT_PRESSED; }
int MiddleButton() { return hit.button & GMOU_MIDDLE_PRESSED; }
int Count() { return hit.count; }
int Row() { return hit.row; }
int Column() { return hit.column; }
void GetLeftPress() { GetPress(GMOU_LEFT_BUTTON); }
void GetRightPress() { GetPress(GMOU_RIGHT_BUTTON); }
void GetLeftRelease() { GetRelease(GMOU_LEFT_BUTTON); }
void GetRightRelease() { GetRelease(GMOU_RIGHT_BUTTON); }
};
extern GMou gmou;
// ------------------------------------------------------------------
#endif // GOLD_MOUSE
// ------------------------------------------------------------------
#endif
// ------------------------------------------------------------------

95
goldlib/gcui/gsrchmgr.cpp Normal file
View File

@ -0,0 +1,95 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Search manager.
// ------------------------------------------------------------------
#include <gsrchmgr.h>
// ------------------------------------------------------------------
search_item::search_item() {
logic = logic_or;
where.from = false;
where.to = false;
where.subject = false;
where.body = false;
where.tagline = false;
where.tearline = false;
where.origin = false;
where.signature = false;
where.kludges = false;
}
// ------------------------------------------------------------------
search_item::~search_item() {
}
// ------------------------------------------------------------------
search_item& search_item::operator=(const search_item& a) {
gsearch::operator=(a);
logic = a.logic;
where.from = a.where.from;
where.to = a.where.to;
where.subject = a.where.subject;
where.body = a.where.body;
where.tagline = a.where.tagline;
where.tearline = a.where.tearline;
where.origin = a.where.origin;
where.signature = a.where.signature;
where.kludges = a.where.kludges;
return *this;
}
// ------------------------------------------------------------------
search_manager::search_manager() : gwinput2(window) {
direction = direction_forward;
messages = messages_new;
action = action_read;
areas = areas_current;
}
// ------------------------------------------------------------------
search_manager::~search_manager() {
}
// ------------------------------------------------------------------

143
goldlib/gcui/gsrchmgr.h Normal file
View File

@ -0,0 +1,143 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// Copyright (C) 1999 Alexander S. Aganichev
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Search manager.
// ------------------------------------------------------------------
#ifndef __gsrchmgr_h
#define __gsrchmgr_h
// ------------------------------------------------------------------
#include <gdefs.h>
#include <vector>
#include <gsearch.h>
#include <gwinput.h>
// ------------------------------------------------------------------
class search_item : public gsearch {
public:
enum item_logic {
logic_and,
logic_or
};
struct item_where {
bool from;
bool to;
bool subject;
bool body;
bool tagline;
bool tearline;
bool origin;
bool signature;
bool kludges;
};
item_logic logic;
item_where where;
search_item();
virtual ~search_item();
search_item& operator=(const search_item& a);
};
// ------------------------------------------------------------------
class search_manager : public gwinput2 {
public:
enum {
if_nothing,
id_pattern1, id_logic1, id_options1,
id_pattern2, id_logic2, id_options2,
id_pattern3, id_logic3, id_options3,
id_pattern4, id_logic4, id_options4,
id_pattern5, id_logic5, id_options5,
id_pattern6, id_logic6, id_options6,
id_pattern7, id_logic7, id_options7,
id_pattern8, id_logic8, id_options8,
id_pattern9, id_logic9, id_options9,
id_direction,
id_messages,
id_action,
id_areas
};
enum search_direction {
direction_backward,
direction_forward
};
enum search_messages {
messages_new,
messages_unread,
messages_all
};
enum search_action {
action_read,
action_mark,
action_delete,
action_write,
action_copy,
action_move
};
enum search_areas {
areas_current,
areas_tagged,
areas_all
};
std::vector<search_item> items;
search_direction direction;
search_messages messages;
search_action action;
search_areas areas;
gwindow window;
search_manager();
virtual ~search_manager();
};
// ------------------------------------------------------------------
#endif
// ------------------------------------------------------------------

469
goldlib/gcui/gvidall.h Normal file
View File

@ -0,0 +1,469 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// Copyright (C) 1999-2000 Alexander S. Aganichev
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Screen/video functions.
// Based on CXL by Mike Smedley.
// ------------------------------------------------------------------
#ifndef __gvidall_h
#define __gvidall_h
// ------------------------------------------------------------------
#include <gdefs.h>
#if defined(__USE_NCURSES__)
#include <gcurses.h>
#endif
#if defined(__WIN32__)
#include <windows.h>
#endif
#if defined(_MSC_VER)
#pragma warning(disable: 4200)
#endif
// ------------------------------------------------------------------
#ifdef BLINK
#undef BLINK
#endif
#define BLINK 128
#ifdef INTENSE
#undef INTENSE
#endif
#define INTENSE 8
#if defined(__UNIX__) && !defined(__USE_NCURSES__)
#define ACSET BLINK
#else
#define ACSET 0
#endif
// ------------------------------------------------------------------
#if defined(__USE_NCURSES__)
typedef chtype vchar; // Type of characters on-screen
typedef int vattr; // Type of screen attributes
typedef chtype vatch; // Type of character-attribute groups
#elif defined(__WIN32__)
typedef char vchar; // Type of characters on-screen
typedef int vattr; // Type of screen attributes
typedef CHAR_INFO vatch; // Type of character-attribute groups
#else
typedef char vchar; // Type of characters on-screen
typedef int vattr; // Type of screen attributes
typedef word vatch; // Type of character-attribute groups
#endif
// ------------------------------------------------------------------
// Attribute codes for functions that use them
const vattr DEFATTR = -1;
const vattr BLACK_ = 0;
const vattr BLUE_ = 1;
const vattr GREEN_ = 2;
const vattr CYAN_ = 3;
const vattr RED_ = 4;
const vattr MAGENTA_ = 5;
const vattr BROWN_ = 6;
const vattr LGREY_ = 7;
const vattr DGREY_ = 8;
const vattr LBLUE_ = 9;
const vattr LGREEN_ = 10;
const vattr LCYAN_ = 11;
const vattr LRED_ = 12;
const vattr LMAGENTA_ = 13;
const vattr YELLOW_ = 14;
const vattr WHITE_ = 15;
const vattr _BLACK = (BLACK_ << 4);
const vattr _BLUE = (BLUE_ << 4);
const vattr _GREEN = (GREEN_ << 4);
const vattr _CYAN = (CYAN_ << 4);
const vattr _RED = (RED_ << 4);
const vattr _MAGENTA = (MAGENTA_ << 4);
const vattr _BROWN = (BROWN_ << 4);
const vattr _LGREY = (LGREY_ << 4);
const vattr _DGREY = (DGREY_ << 4);
const vattr _LBLUE = (LBLUE_ << 4);
const vattr _LGREEN = (LGREEN_ << 4);
const vattr _LCYAN = (LCYAN_ << 4);
const vattr _LRED = (LRED_ << 4);
const vattr _LMAGENTA = (LMAGENTA_<< 4);
const vattr _YELLOW = (YELLOW_ << 4);
const vattr _WHITE = (WHITE_ << 4);
// ------------------------------------------------------------------
// Additional monochrome color values
const vattr UNDERLINE = 1;
const vattr NORMAL = 7;
const vattr HIGHLIGHT = 15;
const vattr REVERSE = 112;
// ------------------------------------------------------------------
// Display adapter types returned from vidtype()
// If bit 0 is set, the adapter was detected in monochrome mode
#define GV_NONE 0x0000
#define V_MONO 0x0001
#define V_MDA 0x0011
#define V_HGC 0x0021
#define V_HGCPLUS 0x0041
#define V_INCOLOR 0x0080
#define V_CGA 0x0100
#define V_EGA 0x0200
#define V_EGAMONO 0x0201
#define V_MCGA 0x0400
#define V_MCGAMONO 0x0401
#define V_VGA 0x0800
#define V_VGAMONO 0x0801
// ------------------------------------------------------------------
// Video parameter settings
#define VP_DMA 0 // direct screen writes
#define VP_CGA 1 // direct screen writes, eliminate CGA snow
#define VP_BIOS 2 // BIOS screen writes
#define VP_MONO 3 // monochrome attribute translation on
#define VP_COLOR 4 // monochrome attribute translation off
#define VP_OS2VIO 6 // OS/2 vio screen writes
#define VP_W32CON 7 // WIN32 console screen writes
#define VP_CURSES 8 // Curses screen writes
// ------------------------------------------------------------------
// Video devices
#define GVID_DMA 0
#define GVID_CGA 1
#define GVID_BIO 2
#define GVID_OS2 4
#define GVID_W32 5
#define GVID_CUR 6
// ------------------------------------------------------------------
// Useful defines for video (0x10) interrupt function numbers
#if defined(__MSDOS__)
#define V_SET_MODE 0x00
#define V_SET_CURSOR_POS 0x02
#define V_GET_CURSOR_POS 0x03
#define V_SCROLL_UP 0x06
#define V_SCROLL_DOWN 0x07
#define V_RD_CHAR_ATTR 0x08
#define V_WR_CHAR_ATTR 0x09
#define V_WR_CHAR 0x0A
#define V_WR_TTY 0x0E
#define V_GET_MODE 0x0F
#define V_GET_FONT_INFO 0x1130
#endif
// ------------------------------------------------------------------
#if defined(__MSDOS__)
struct __int10_ah1b_statebuf {
// Offset Size Description
dword statfunctable; // 00h DWORD address of static funtionality table (see below)
byte videomode; // 04h BYTE video mode in effect
word columns; // 05h WORD number of columns
word regenbuflen; // 07h WORD length of regen buffer in bytes
word regenbufstart; // 09h WORD starting address of regen buffer
word cursorpos0; // 0Bh WORD cursor position for page 0
word cursorpos1; // 0Dh WORD cursor position for page 1
word cursorpos2; // 0Fh WORD cursor position for page 2
word cursorpos3; // 11h WORD cursor position for page 3
word cursorpos4; // 13h WORD cursor position for page 4
word cursorpos5; // 15h WORD cursor position for page 5
word cursorpos6; // 17h WORD cursor position for page 6
word cursorpos7; // 19h WORD cursor position for page 7
word cursortype; // 1Bh WORD cursor type
byte activepage; // 1Dh BYTE active display page
word crctportaddr; // 1Eh WORD CRTC port address
byte curr_reg_3x8; // 20h BYTE current setting of register (3?8)
byte curr_reg_3x9; // 21h BYTE current setting of register (3?9)
byte rows; // 22h BYTE number of rows
word bytesperchar; // 23h WORD bytes/character
byte dispcombcode; // 25h BYTE display combination code of active display
byte dcc; // 26h BYTE DCC of alternate display
word numcolors; // 27h WORD number of colors supported in current mode
byte numpages; // 29h BYTE number of pages supported in current mode
byte numscanlines; // 2Ah BYTE number of scan lines active (0,1,2,3) = (200,350,400,480) Tseng ET3000: (4,5,6 = 512,600,768)
byte primcharblock; // 2Bh BYTE primary character block
byte seccharblock; // 2Ch BYTE secondary character block
byte miscflags; // 2Dh BYTE miscellaneous flags (see below)
byte reserved1[3]; // 2Eh 3 BYTEs reserved (00h)
byte videomem; // 31h BYTE video memory available 00h = 64K, 01h = 128K, 02h = 192K, 03h = 256K
byte stateflags; // 32h BYTE save pointer state flags (see below)
byte reserved2[13]; // 33h 13 BYTEs reserved (00h)
};
#endif
// ------------------------------------------------------------------
// Border types
#define BT_SINGLE 0
#define BT_DOUBLE 1
#define BT_SINGLETOP 2
#define BT_DOUBLETOP 3
#define BT_BLANKS 4
#define BT_NONE 5
#define BT_BLOCKS 6
#define BT_ASCII 7
// ------------------------------------------------------------------
// Video information structure
struct GVidInfo {
// Screen info
struct _screen
{
int mode; // Video mode
int rows; // Number of rows
int columns; // Number of columns
int cheight; // Character height
int cwidth; // Character width
} screen;
// Cursor info
struct _cursor
{
int column; // Cursor column
int row; // Cursor row
int start; // Cursor start line
int end; // Cursor end line
word attr; // Cursor attribute. Hidden if attr == 0xFFFF
} cursor;
// Colors
struct _color
{
vattr textattr; // Text attribute
vattr overscan; // Overscan color
int intensity; // Background color state (intense or blinking)
int palette[16]; // Palette state
} color;
};
// ------------------------------------------------------------------
#ifdef __DJGPP__
typedef uint32_t gdma; // Video DMA linear address
#else
typedef word* gdma; // Video DMA pointer
#endif
// ------------------------------------------------------------------
// Video information record
class GVid {
public:
int adapter; // Video adapter type
GVidInfo orig; // Original video info
GVidInfo curr; // Current video info
int device; // Video device type
gdma dmadir; // Video DMA pointer (direct)
gdma dmaptr; // Video DMA pointer (direct or buffered)
vchar* bufchr; // Video line char buffer (char only)
vatch* bufwrd; // Video line word buffer (char+attr)
vchar* bufansi; // Video line ANSI buffer (11*numcols)
int currow; // Current cursor row
int curcol; // Current cursor column
size_t numrows; // number of displayed rows
size_t numcols; // number of displayed columns
word videoseg; // video buffer segment address
public:
GVid();
~GVid();
public:
void init();
int detectadapter ();
void detectinfo (GVidInfo* _info);
static
void setcolorpairs (bool enabletransparent=false);
void resetcurr ();
void setdevice (int _device);
void setmode (int _mode);
void setrows (int _rows);
void setoverscan (vattr _overscan);
void setintensity (int _intensity);
void getpalette (int* _palette);
void setpalette (int* _palette);
bool isdma() { return device == GVID_DMA; }
bool iscga() { return device == GVID_CGA; }
bool isbios() { return device == GVID_BIO; }
void restore_cursor();
void resize_screen(int columns, int rows);
};
extern GVid *gvid;
// ------------------------------------------------------------------
// Box characters table
#if !defined(__USE_NCURSES__)
extern char* __box_table[];
#define _box_table(i,j) (__box_table[i][j])
#else
chtype _box_table(int type, int c);
#endif
// ------------------------------------------------------------------
// Prototypes
int setvparam (int setting);
vattr mapattr (vattr attr);
vattr revsattr (vattr attr);
inline vattr attrib(int f, int b, int i, int bl) { return (int)((b<<4)|(f)|(i<<3)|(bl<<7)); }
void vputw (int row, int col, vatch chat);
void vputws (int row, int col, vatch* buf, uint len);
void vputc (int row, int col, vattr atr, vchar chr);
void vputvs (int row, int col, vattr atr, const vchar* str);
void vputs (int row, int col, vattr atr, const char* str);
void vputs_box (int row, int col, vattr atr, const char* str);
void vputns (int row, int col, vattr atr, const char* str, uint len);
void vputx (int row, int col, vattr atr, vchar chr, uint len);
void vputy (int row, int col, vattr atr, vchar chr, uint len);
vatch vgetw (int row, int col);
void vgetc (int row, int col, vattr* atr, vchar* chr);
void vscroll (int srow, int scol, int erow, int ecol, vattr atr, int lines);
void vposget (int* row, int* col);
void vposset (int row, int col);
void vclrscr ();
void vclrscr (vattr atr); // Overloaded
typedef struct _vsavebuf {
int top, left, right, bottom;
__extension__ vatch data[0];
} vsavebuf;
vsavebuf* vsave (int srow=-1, int scol=-1, int erow=-1, int ecol=-1);
void vrestore (vsavebuf* buf, int srow=-1, int scol=-1, int erow=-1, int ecol=-1);
void vcurget (int* sline, int* eline);
void vcurset (int sline, int eline);
void vcurhide ();
void vcurshow ();
bool vcurhidden ();
void vcurlarge ();
void vcursmall ();
void vbox (int srow, int scol, int erow, int ecol, int box, vattr hiattr, vattr loattr = DEFATTR);
void vfill (int srow, int scol, int erow, int ecol, vchar chr, vattr atr);
#if defined(__USE_NCURSES__)
int gvid_dosattrcalc (int ourattr);
int gvid_attrcalc (int dosattr);
inline vchar vgchar (vatch chat) { return chat & (A_CHARTEXT | A_ALTCHARSET); }
inline vattr vgattr (vatch chat) { return gvid_dosattrcalc(chat & ~(A_CHARTEXT | A_ALTCHARSET)); }
inline vatch vschar (vatch chat, vchar chr) { return (chr & (A_CHARTEXT | A_ALTCHARSET)) | (chat & ~(A_CHARTEXT | A_ALTCHARSET)); }
inline vatch vsattr (vatch chat, vattr atr) { return (chat & (A_CHARTEXT | A_ALTCHARSET)) | gvid_attrcalc(atr); }
inline vatch vcatch (vchar chr, vattr atr) { return chr | gvid_attrcalc(atr); }
#elif defined(__WIN32__)
inline vchar vgchar (vatch chat) { return chat.Char.AsciiChar; }
inline vattr vgattr (vatch chat) { return chat.Attributes; }
inline vatch vschar (vatch chat, vchar chr) { chat.Char.UnicodeChar = 0; chat.Char.AsciiChar = chr; return chat; }
inline vatch vsattr (vatch chat, vattr atr) { chat.Attributes = WORD(atr); return chat; }
inline vatch vcatch (vchar chr, vattr atr) { vatch chat; chat.Char.UnicodeChar = 0; chat.Char.AsciiChar = chr; chat.Attributes = WORD(atr); return chat; }
#else
inline vchar vgchar (vatch chat) { return chat & 0xff; }
inline vattr vgattr (vatch chat) { return (chat >> 8) & 0xff; }
inline vatch vschar (vatch chat, vchar chr) { return (chat & 0xff00) | chr; }
inline vatch vsattr (vatch chat, vattr atr) { return (chat & 0xff) | (atr << 8); }
inline vatch vcatch (vchar chr, vattr atr) { return (chr & 0xff) | ((atr << 8) & 0xff00); }
#endif
inline vchar vgetc (int row, int col) { return vgchar(vgetw(row, col)); }
typedef void (*VidPutStrCP)(int,int,int,const char*);
void gvid_boxcvt(char* s);
// ------------------------------------------------------------------
#endif
// ------------------------------------------------------------------

2189
goldlib/gcui/gvidbase.cpp Normal file

File diff suppressed because it is too large Load Diff

1061
goldlib/gcui/gvidinit.cpp Normal file

File diff suppressed because it is too large Load Diff

448
goldlib/gcui/gwinall.h Normal file
View File

@ -0,0 +1,448 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// Copyright (C) 1999-2000 Alexander S. Aganichev
// Copyright (C) 2000 Jacobo Tarrio
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Windowing functions.
// Based on CXL by Mike Smedley.
// ------------------------------------------------------------------
#ifndef __gwinall_h
#define __gwinall_h
// ------------------------------------------------------------------
#include <gdefs.h>
#include <gstrall.h>
#include <gkbdbase.h>
#include <gvidall.h>
// ------------------------------------------------------------------
// Error codes returned from windowing functions
#define W_NOERROR 0 // no error
#define W_ESCPRESS 1 // Escape key was pressed
#define W_ALLOCERR 2 // memory allocation error
#define W_NOTFOUND 3 // record not found
#define W_NOACTIVE 4 // no active window
#define W_INVCOORD 5 // invalid coordinates
#define W_INVFORMT 6 // invalid format string
#define W_NOINPDEF 7 // no input fields defined
#define W_STRLONG 8 // string too long for window
#define W_INVBTYPE 9 // invalid box type
#define W_NOBORDER 10 // no window border
#define W_NOHIDDEN 11 // no hidden windows
#define W_NOTHIDD 12 // window is not hidden
#define W_NOSELECT 13 // no selectable menu items
#define W_NOITMDEF 14 // no menu items defined
#define W_NOMNUEND 15 // no end of menu specified
#define W_NOMNUDEF 16 // no menu defined
#define W_NOMNUBEG 17 // no begin of menu specified
#define W_NOFRMDEF 18 // no form defined
#define W_NOFRMBEG 19 // no begin of form specified
#define W_NOHLPDEF 20 // no help record defined
#define W_HLPSTKOV 21 // help stack overflow
#define W_HLPSTKUN 22 // help stack underflow
#define W_DOSERROR 23 // DOS error
#define W_NOMATCH 24 // no files matched input filespec
#define W_INVTAGID 25 // invalid tag identifier
// ------------------------------------------------------------------
// Window border identifiers
#define TP_BORD 0 // top border
#define BT_BORD 1 // bottom border
#define LT_BORD 2 // left border
#define RT_BORD 3 // right border
// ------------------------------------------------------------------
// Direction codes
#define D_DOWN 0
#define D_UP 1
#define D_LEFT 2
#define D_RIGHT 3
#define SDOWN D_DOWN // scroll down
#define SUP D_UP // scroll up
// ------------------------------------------------------------------
// Scrollbar orientation
const int W_HORZ = 1;
const int W_VERT = 2;
// ------------------------------------------------------------------
// Menu item record definition
struct _item_t {
_item_t* prev; // pointer to previous record
_item_t* next; // pointer to next record
void* child; // pointer to submenu's record
const char* str; // address of selection string
const char* desc; // text description of menu option
VfvCP select; // address of selection function
VfvCP before; // address of "before" function
VfvCP after; // address of "after" function
gkey hotkey; // hot key to select function
int tagid; // tag identifier
int help; // help category number
int wrow; // start of text - window row
int wcol; // start of text - window column
char schar; // quick selection character
int fmask; // special feature mask
int dwhdl; // description window handle
int dwrow; // description window row
int dwcol; // description window column
vattr dattr; // description attribute
int redisp; // redisplay flag
};
// ------------------------------------------------------------------
// Window menu record definition
struct _menu_t {
_menu_t* prev; // pointer to prev menu structure
_menu_t* next; // pointer to next menu structure
_menu_t* parent; // pointer to parent menu
_item_t* item; // pointer to head menu item
_item_t* citem; // pointer to current menu item
VfvCP open; // address of post-opening function
int tagcurr; // tag ID of item selection bar on
int usecurr; // will menu use current window?
int srow; // starting row of menu window
int scol; // starting column of menu window
int erow; // ending row of menu window
int ecol; // ending column of menu window
int btype; // menu window border type
vattr battr; // menu window "hi" border attribute
vattr loattr; // menu window "lo" border attribute
vattr sbattr; // menu window scrollbar attribute
vattr wattr; // menu window attribute
int menutype; // menu type mask
int barwidth; // width of menu bar or zero
int textpos; // offset of text from start of bar
vattr textattr; // attribute of menu text
vattr scharattr; // attribute of selection character
vattr noselattr; // non-selectable text attribute
vattr barattr; // attribute of selection bar
const char* title; // menu title string or NULL if no title
int titlepos; // position of menu title (TLEFT,TCENTER,TRIGHT)
vattr titleattr; // attribute of menu title
vattr shadattr; // shadow attribute or -1 if no shadow
int items; // number of items in menu
bool hotkey;
};
// ------------------------------------------------------------------
// Window input field definition
struct _field_t {
_field_t* prev; // pointer to previous field
_field_t* next; // pointer to next field
char* str; // address of receiving string
char* buf; // address of temp receive string
const char* format; // input field format string
IfcpCP validate; // address of validation function
VfvCP before; // address of "before" function
VfvCP after; // address of "after" function
int help; // help category number
int lenbuf; // length of buffer
int lenfld; // length of screen input field
int lenfmt; // length of format string
int wrow; // start of input - window row
int wcol; // start of input - window column
int mode; // 0=init, 1=update, 2=cond update
int decpos; // decimal position (numeric)
int redisp; // redisplay flag
char fconv; // field conversion character
};
// ------------------------------------------------------------------
// Window data entry form definition
typedef gkey (*KfipCP)(int*);
struct _form_t {
KfipCP getkey; // pointer to alternate get func
_form_t* prev; // pointer to previous form record
_form_t* next; // pointer to next form record
_field_t* field; // pointer to head field record
_field_t* cfield; // pointer to current field record
gkey* termkey; // addr of int for terminating key
const char* pformat; // format string pointer
char* pbuf; // buffer string pointer
int cwrow; // current window row
int cwcol; // current window column
int decimal; // decimal field flag
int insert; // insert mode flag
int fieldattr; // field attribute
int textattr; // text attribute
};
// ------------------------------------------------------------------
// Structure of window records
struct _wrec_t {
_wrec_t* prev; // pointer to previous window record
_wrec_t* next; // pointer to next window record
_form_t* form; // pointer to head form record
vsavebuf* wbuf; // address of window's buffer
vatch* wsbuf; // address of window shadow's buffer
const char* title; // address of window's title string
int whandle; // window's handle
int help; // help category number
int srow; // start row of window
int scol; // start column of window
int erow; // end row of window
int ecol; // end column of window
int btype; // window's box type
vattr wattr; // window's initial text attribute
vattr battr; // attribute of window's border
vattr loattr; // attribute of window's border
vattr sbattr; // attribute of window's scrollbar
int border; // has border? 0 = no, 1 = yes
int row; // window's current cursor row
int column; // window's current cursor column
vattr attr; // window's current text attribute
int tpos; // position of window's title
vattr tattr; // attribute of window's title
vattr wsattr; // attribute of window's shadow
};
// ------------------------------------------------------------------
class _help_t;
// ------------------------------------------------------------------
// Window information record
class GWin {
public:
_wrec_t* active; // pointer to active window
_wrec_t* hidden; // pointer to head hidden window
_menu_t* menu; // pointer to head menu record
_menu_t* cmenu; // pointer to current menu record
_help_t* helptr; // pointer to help info record
int handle; // last handle given to a window
int help; // current help category
int werrno; // error num from last window func
int total; // total number of open windows
int mlevel; // system variable used in menus
int ilevel; // system variable used in menus
int esc; // check for Esc in input funcions?
int tabwidth; // window TTY output tab width
vchar fillch; // character to fill windows with
int style; // how to open the windows
public:
GWin();
~GWin();
};
extern GWin gwin;
// ------------------------------------------------------------------
// Window open styles
#define STYLE_NORMAL 0
#define STYLE_EXPLODE 1
#define STYLE_EXPLODENOISY 2
// ------------------------------------------------------------------
// Fmask definitions for wmenuitem()
#define M_HASPD 1 // has pull-down menu attached
#define M_NOSEL 2 // is not selectable
#define M_CLOSE 4 // close menu after select func
#define M_CLALL 8 // close all menus when selected
#define M_CLOSB 16 // close menu before select func
#define M_SEPAR (32 + M_NOSEL) // item is separator
// ------------------------------------------------------------------
// Menutype definitions for wmenuend()
#define M_HORZ 1 // horizontal menu
#define M_VERT 2 // vertical menu
#define M_OMNI 7 // omnidirectional menu
#define M_PD 8 // pull-down menu
#define M_NOQS 16 // disable quick selection
#define M_SAVE 32 // save last bar position
// ------------------------------------------------------------------
// Special return codes from wmenuget()
#define M_EXIT 32764 // exit menu
#define M_EXITALL 32765 // exit all menus
#define M_PREVPD 32766 // previous pull-down menu
#define M_NEXTPD 32767 // next pull-down menu
// ------------------------------------------------------------------
// Window title position definitions for wtitle()
#define TTOP 0 // Top border
#define TLEFT 1 // Left justified
#define TCENTER 2 // Centered
#define TRIGHT 3 // Right justified
#define TBOTTOM 4 // Bottom border
// ------------------------------------------------------------------
// Values for the Proportional Bar
#define PROP_PAGE 1
#define PROP_BARGRAPH 2
// ------------------------------------------------------------------
extern int wpickstr_tag;
// ------------------------------------------------------------------
// Function prototypes
int wactiv (int whandle);
int wactiv_ (int whandle);
int wborder (int btype);
int wbox (int wsrow, int wscol, int werow, int wecol, int btype, int attr);
int wcclear (vattr attr);
int wcenters (int wrow, vattr attr, const char* str);
int wchkbox (int wsrow, int wscol, int werow, int wecol);
int wchkcol (int wcol);
int wchkcoord (int wrow, int wcol);
int wchkrow (int wrow);
int wclose ();
int wcloseall ();
int wclreol ();
int wclreos ();
int wcopy (int nsrow, int nscol);
int wdelline (int wrow, int direc);
int wdrag (int direction);
int wdupc (char ch, int count);
int wfill (int wsrow, int wscol, int werow, int wecol, vchar ch, vattr attr);
_wrec_t* wfindrec (int whandle);
int wgotoxy (int wrow, int wcol);
int whandle ();
int whide ();
int whline (int wsrow, int wscol, int count, int btype, vattr attr);
int wmessage (const char* str, int border, int leftofs, vattr attr);
int wmove (int nsrow, int nscol);
int wopen (int srow, int scol, int erow, int ecol, int btype, vattr battr, vattr wattr, vattr sbattr = DEFATTR, vattr loattr = DEFATTR);
inline int wopen_ (int srow, int scol, int vlen, int hlen, int btype, vattr battr, vattr wattr, vattr sbattr = DEFATTR, vattr loattr = DEFATTR) { return wopen(srow, scol, srow+vlen-1, scol+hlen-1, btype, battr, wattr, sbattr, loattr); }
int wperror (const char* message);
bool wpickfile (int srow, int scol, int erow, int ecol, int btype, vattr bordattr, vattr winattr, vattr barattr, bool title, std::string &filespec, IfcpCP open, bool casesens=false);
int wpickstr (int srow, int scol, int erow, int ecol, int btype, vattr bordattr, vattr winattr, vattr barattr, gstrarray &strarr, int initelem, VfvCP open);
int wprintc (int wrow, int wcol, vattr attr, vchar ch);
int wprintf (const char* format, ...) __attribute__ ((format (printf, 1, 2)));
int wprintaf (int attr, const char* format, ...) __attribute__ ((format (printf, 2, 3)));
int wprintfs (int wrow, int wcol, vattr attr, const char* format, ...) __attribute__ ((format (printf, 4, 5)));
int wprints (int wrow, int wcol, vattr attr, const char* str);
int wprints_box (int wrow, int wcol, vattr attr, const char* str);
int wprintvs (int wrow, int wcol, vattr attr, const vchar* str);
int wprintns (int wrow, int wcol, vattr attr, const std::string &str, uint len, vchar fill=' ', vattr fill_attr = DEFATTR);
int wprintsf (int wrow, int wcol, vattr attr, const char* format, const char* str);
int wprintws (int wrow, int wcol, vatch* buf, uint len);
void wpropbar (int xx, int yy, long len, vattr attr, long pos, long size);
int wputc (vchar ch);
int wputs (const char* str);
int wputx (int wrow, int wcol, vattr attr, vchar chr, uint len);
int wputy (int wrow, int wcol, vattr attr, vchar chr, uint len);
int wreadcur (int* wrow, int* wcol);
int wscroll (int count, int direc);
void wscrollbar (int orientation, uint total, uint maxpos, uint pos, int sadd=0);
int wscrollbox (int wsrow, int wscol, int werow, int wecol, int count, int direction);
int wshadoff ();
int wshadow (vattr attr);
int wsize (int nerow, int necol);
int wslide (int nsrow, int nscol);
void wtextattr (vattr attr);
int wtitle (const char* str, int tpos, vattr tattr);
int wunhide (int whandle);
int wunlink (int w);
int wvline (int wsrow, int wscol, int count, int btype, vattr attr);
int wwprintc (int whandle, int wrow, int wcol, vattr attr, const vchar chr);
int wwprints (int whandle, int wrow, int wcol, vattr attr, const char* str);
int wwprintstr (int whandle, int wrow, int wcol, vattr attr, const char* str);
int wmenubeg (int srow, int scol, int erow, int ecol, int btype, vattr battr, vattr wattr, VfvCP open, int menutype=M_VERT);
inline int wmenubeg_ (int srow, int scol, int vlen, int hlen, int btype, vattr battr, vattr wattr, VfvCP open, int menutype=M_VERT) { return wmenubeg(srow, scol, srow+vlen-1, scol+hlen-1, btype, battr, wattr, open, menutype); }
int wmenubegc ();
int wmenuend (int taginit, int menutype, int barwidth, int textpos, vattr textattr, vattr scharattr, vattr noselattr, vattr barattr);
int wmenuget ();
int wmenuiba (VfvCP before, VfvCP after);
int wmenuidsab (int tagid);
int wmenuienab (int tagid);
_item_t* wmenuifind (int tagid);
int wmenuinext (int tagid);
int wmenuitem (int wrow, int wcol, const char* str, char schar, int tagid, int fmask, VfvCP select, gkey hotkey, int help);
int wmenuitxt (int whdl, int wrow, int wcol, vattr attr, const char* str);
// ------------------------------------------------------------------
// Inline functions
inline void wtextattr(vattr attr) { gwin.active->attr = attr; }
inline int wclear () { return wcclear(gwin.active->wattr); }
inline void wfillch (vchar a) { gwin.fillch=a; }
inline vchar wgetc (int wrow, int wcol) { return vgetc(gwin.active->srow+wrow+gwin.active->border,gwin.active->scol+wcol+gwin.active->border); }
inline int wisactiv (int a) { return a == gwin.active->whandle; }
inline int wsetesc (int a) { int t=gwin.esc; gwin.esc=a; return t; }
inline void wsetstyle (int a) { gwin.style = a; }
inline int wstyle () { return gwin.style; }
inline void wtabwidth (int a) { gwin.tabwidth = (a==0) ? 1 : a; }
inline _field_t* winpfcurr () { return gwin.active->form->cfield; }
inline _menu_t* wmenumcurr () { return gwin.cmenu; }
inline _item_t* wmenuicurr () { return wmenumcurr()->citem; }
inline int wmenutitshad(const char* title, int pos, vattr attr, vattr shadattr) { gwin.cmenu->title=title; gwin.cmenu->titlepos=pos; gwin.cmenu->titleattr=attr; gwin.cmenu->shadattr=shadattr; return W_NOERROR; }
// ------------------------------------------------------------------
#endif
// ------------------------------------------------------------------

2104
goldlib/gcui/gwinbase.cpp Normal file

File diff suppressed because it is too large Load Diff

92
goldlib/gcui/gwindow.cpp Normal file
View File

@ -0,0 +1,92 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Windowing wrapper class.
// ------------------------------------------------------------------
#include <cstdio>
#include <cstdarg>
#include <gwindow.h>
// ------------------------------------------------------------------
int gwindow::printf(const char* format, ...) {
char buf[255];
va_list argptr;
va_start(argptr,format);
int result = vsprintf(buf,format,argptr);
va_end(argptr);
puts(buf);
return result;
}
// ------------------------------------------------------------------
int gwindow::printf(vattr color, const char* format, ...) {
char buf[255];
va_list argptr;
va_start(argptr,format);
int result = vsprintf(buf,format,argptr);
va_end(argptr);
text_color(color);
puts(buf);
return result;
}
// ------------------------------------------------------------------
int gwindow::printf(int row, int col, const char* format, ...) {
va_list argptr;
char buf[256];
*buf = NUL;
va_start(argptr, format);
int result = vsprintf(buf, format, argptr);
va_end(argptr);
prints(row, col, window_color, buf);
return result;
}
// ------------------------------------------------------------------
int gwindow::printf(int row, int col, vattr color, const char* format, ...) {
va_list argptr;
char buf[256];
*buf = NUL;
va_start(argptr, format);
int result = vsprintf(buf, format, argptr);
va_end(argptr);
prints(row, col, color, buf);
return result;
}
// ------------------------------------------------------------------

687
goldlib/gcui/gwindow.h Normal file
View File

@ -0,0 +1,687 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// Copyright (C) 1999-2000 Alexander S. Aganichev
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Windowing class.
// ------------------------------------------------------------------
#ifndef __gwindow_h
#define __gwindow_h
// ------------------------------------------------------------------
#include <string>
#include <gwinall.h>
#undef getc
#undef putc
// ------------------------------------------------------------------
inline void wgetc(int wrow, int wcol, vattr* atr, vchar* chr) {
vgetc(wrow+gwin.active->srow+gwin.active->border, wcol+gwin.active->scol+gwin.active->border, atr, chr);
}
// ------------------------------------------------------------------
struct gscrollbar_data {
long minpos; // Minimum range position
long maxpos; // Maximum range position
long pos; // Position of the thumb button
long page; // Size of the visible part
};
// ------------------------------------------------------------------
class gwindow {
protected:
_wrec_t* wrec;
int owner;
int window_style;
vattr window_color;
vattr border_hi_color;
vattr border_lo_color;
vattr scrollbar_color;
vattr title_color;
int title_position;
vattr message_color;
vattr shadow_color;
public:
int start_row;
int start_column;
int end_row;
int end_column;
enum {
title_top = TTOP,
title_left = TLEFT,
title_center = TCENTER,
title_right = TRIGHT,
title_bottom = TBOTTOM,
border_top = TP_BORD,
border_bottom = BT_BORD,
border_left = LT_BORD,
border_right = RT_BORD,
scrollbar_horizontal = W_HORZ,
scrollbar_vertical = W_VERT,
direction_down = D_DOWN,
direction_up = D_UP,
direction_left = D_LEFT,
direction_right = D_RIGHT,
bordertype_single = BT_SINGLE,
bordertype_double = BT_DOUBLE,
bordertype_singletop = BT_SINGLETOP,
bordertype_doubletop = BT_DOUBLETOP,
bordertype_blanks = BT_BLANKS,
bordertype_none = BT_NONE,
bordertype_blocks = BT_BLOCKS,
bordertype_ascii = BT_ASCII,
bordertypes = 7
};
gwindow();
gwindow(int old_handle);
virtual ~gwindow();
void init();
int height() { return 1 + end_row - start_row; }
int width() { return 1 + end_column - start_column; }
int border_type() { return window_style & bordertypes; }
bool has_border() { return border_type() != BT_NONE; }
vchar boxchar_upper_left_corner() { return _box_table(border_type(), 0); }
vchar boxchar_upper_horizontal_line() { return _box_table(border_type(), 1); }
vchar boxchar_upper_right_corner() { return _box_table(border_type(), 2); }
vchar boxchar_left_vertical_line() { return _box_table(border_type(), 3); }
vchar boxchar_right_vertical_line() { return _box_table(border_type(), 4); }
vchar boxchar_lower_left_corner() { return _box_table(border_type(), 5); }
vchar boxchar_lower_horizontal_line() { return _box_table(border_type(), 6); }
vchar boxchar_lower_right_corner() { return _box_table(border_type(), 7); }
vchar boxchar_middle_junction() { return _box_table(border_type(), 8); }
vchar boxchar_left_vertical_junction() { return _box_table(border_type(), 9); }
vchar boxchar_right_vertical_junction() { return _box_table(border_type(), 10); }
vchar boxchar_upper_horizontal_junction() { return _box_table(border_type(), 11); }
vchar boxchar_lower_horizontal_junction() { return _box_table(border_type(), 12); }
void set_window_at(int srow, int scol);
void set_window_size(int vlen, int hlen);
void open(int srow, int scol, int erow, int ecol, int style, vattr bcolor, vattr wcolor, vattr sbcolor = DEFATTR, vattr locolor = DEFATTR);
void openxy(int srow, int scol, int vlen, int hlen, int style, vattr bcolor, vattr wcolor, vattr sbcolor = DEFATTR, vattr locolor = DEFATTR);
void open();
void close();
void unlink();
void hide();
void unhide();
int active();
void activate();
void activate_quick();
int cursor_row();
int cursor_column();
void text_color(vattr color);
void move_cursor(int row, int column);
void title(const char* title, vattr color = DEFATTR, int position=-1);
void no_title();
void message(const char* text, int border, int leftofs, vattr color = DEFATTR);
void shadow(vattr color = DEFATTR);
void no_shadow();
void set_vscrollbar_range(int minpos, int maxpos, int visible, int total, int redraw);
void set_hscrollbar_range(int minpos, int maxpos, int visible, int total, int redraw);
void set_vscrollbar_pos(int pos, int redraw);
void set_hscrollbar_pos(int pos, int redraw);
void set_scrollbar_color(vattr color);
void vscrollbar(uint total, uint maxpos, uint pos, int sadd=0);
void hscrollbar(uint total, uint maxpos, uint pos, int sadd=0);
void scroll_down(int count=1);
void scroll_up(int count=1);
void scroll_box_down(int scol, int srow, int ecol, int erow, int count=1);
void scroll_box_up(int scol, int srow, int ecol, int erow, int count=1);
void getc(int row, int col, vattr* atr, vchar* chr);
void putc(vchar ch);
void puts(const char* text);
void printc(int row, int col, vattr color, vchar ch);
void prints(int row, int col, vattr color, const char* text);
void printvs(int row, int col, vattr color, const vchar* text);
void prints(int row, int col, vattr color, const std::string& text);
void printns(int row, int col, vattr color, const char* text, int len, vchar fill=' ', vattr fill_color = DEFATTR);
int printf(const char* format, ...) __attribute__ ((format (printf, 2, 3)));
int printf(vattr color, const char* format, ...) __attribute__ ((format (printf, 3, 4)));
int printf(int row, int col, const char* format, ...) __attribute__ ((format (printf, 4, 5)));
int printf(int row, int col, vattr color, const char* format, ...) __attribute__ ((format (printf, 5, 6)));
void fill_char(vchar ch);
void fill(int wsrow, int wscol, int werow, int wecol, vchar ch, vattr color);
void vertical_line(int wsrow, int wscol, int count, int btype, vattr color);
void horizontal_line(int wsrow, int wscol, int count, int btype, vattr color);
void clear(vattr color = DEFATTR);
void clear_eol();
void drag(int direction, int howmuch=1);
void slide(int row, int col);
void putx(int wrow, int wcol, vattr color, char chr, uint len);
void print_center(int row, vattr color, const char* text);
};
// ------------------------------------------------------------------
inline void gwindow::init() {
wrec = NULL;
start_row = start_column = 0;
end_row = gvid->curr.screen.rows - 1;
end_column = gvid->curr.screen.columns - 1;
window_style = 0;
window_color = BLACK_|_LGREY;
border_hi_color = BLUE_|_LGREY;
border_lo_color = DEFATTR;
scrollbar_color = DEFATTR;
title_color = BLUE_|_LGREY;
title_position = title_center;
message_color = BLUE_|_LGREY;
shadow_color = DGREY_|_BLACK;
}
// ------------------------------------------------------------------
inline void gwindow::set_window_at(int srow, int scol) {
start_row = srow;
start_column = scol;
}
// ------------------------------------------------------------------
inline void gwindow::set_window_size(int vlen, int hlen) {
end_row = start_row + vlen - 1;
end_column = start_column + hlen - 1;
}
// ------------------------------------------------------------------
inline void gwindow::open(int srow, int scol, int erow, int ecol, int style, vattr bcolor, vattr wcolor, vattr sbcolor, vattr locolor) {
start_row = srow;
start_column = scol;
end_row = erow;
end_column = ecol;
window_color = wcolor;
window_style = style;
border_hi_color = bcolor;
border_lo_color = locolor;
scrollbar_color = sbcolor;
wopen(srow, scol, erow, ecol, style, bcolor, wcolor, sbcolor, locolor);
wrec = gwin.active;
}
// ------------------------------------------------------------------
inline void gwindow::openxy(int srow, int scol, int vlen, int hlen, int style, vattr bcolor, vattr wcolor, vattr sbcolor, vattr locolor) {
open(srow, scol, srow+vlen-1, scol+hlen-1, style, bcolor, wcolor, sbcolor, locolor);
}
// ------------------------------------------------------------------
inline void gwindow::open() {
open(start_row, start_column, end_row, end_column, window_style, border_hi_color, window_color, scrollbar_color, border_lo_color);
}
// ------------------------------------------------------------------
inline int gwindow::active() {
return wrec == gwin.active;
}
// ------------------------------------------------------------------
inline void gwindow::activate_quick() {
if(!active())
wactiv_(wrec->whandle);
}
// ------------------------------------------------------------------
inline void gwindow::close() {
if(wrec) {
activate_quick();
wclose();
wrec = NULL;
}
}
// ------------------------------------------------------------------
inline void gwindow::unlink() {
wunlink(wrec->whandle);
wrec = NULL;
}
// ------------------------------------------------------------------
inline void gwindow::hide() {
activate_quick();
whide();
}
// ------------------------------------------------------------------
inline void gwindow::unhide() {
wunhide(wrec->whandle);
}
// ------------------------------------------------------------------
inline void gwindow::activate() {
if(!active())
wactiv(wrec->whandle);
}
// ------------------------------------------------------------------
inline int gwindow::cursor_row() {
return wrec->row;
}
// ------------------------------------------------------------------
inline int gwindow::cursor_column() {
return wrec->column;
}
// ------------------------------------------------------------------
inline void gwindow::text_color(vattr color) {
window_color = color;
activate_quick();
wtextattr(color);
}
// ------------------------------------------------------------------
inline void gwindow::set_scrollbar_color(vattr color) {
wrec->sbattr = color;
scrollbar_color = color;
}
// ------------------------------------------------------------------
inline void gwindow::move_cursor(int row, int column) {
activate_quick();
wgotoxy(row, column);
}
// ------------------------------------------------------------------
inline void gwindow::title(const char* title, vattr color, int position) {
if(color != DEFATTR)
title_color = color;
if(position != -1)
title_position = position;
activate_quick();
wtitle(title, title_position, title_color);
}
// ------------------------------------------------------------------
inline void gwindow::no_title() {
title(NULL);
}
// ------------------------------------------------------------------
inline void gwindow::message(const char* text, int border, int leftofs, vattr color) {
if(color != DEFATTR)
message_color = color;
activate_quick();
wmessage(text, border, leftofs, message_color);
}
// ------------------------------------------------------------------
inline void gwindow::shadow(vattr color) {
if(color != DEFATTR)
shadow_color = color;
activate_quick();
wshadow(shadow_color);
}
// ------------------------------------------------------------------
inline void gwindow::no_shadow() {
activate_quick();
wshadoff();
}
// ------------------------------------------------------------------
inline void gwindow::vscrollbar(uint total, uint maxpos, uint pos, int sadd) {
activate_quick();
wscrollbar(scrollbar_vertical, total, maxpos, pos, sadd);
}
// ------------------------------------------------------------------
inline void gwindow::hscrollbar(uint total, uint maxpos, uint pos, int sadd) {
activate_quick();
wscrollbar(scrollbar_horizontal, total, maxpos, pos, sadd);
}
// ------------------------------------------------------------------
inline void gwindow::scroll_down(int count) {
activate_quick();
wscroll(count, direction_down);
}
// ------------------------------------------------------------------
inline void gwindow::scroll_up(int count) {
activate_quick();
wscroll(count, direction_up);
}
// ------------------------------------------------------------------
inline void gwindow::scroll_box_down(int scol, int srow, int ecol, int erow, int count) {
activate_quick();
wscrollbox(scol, srow, ecol, erow, count, direction_down);
}
// ------------------------------------------------------------------
inline void gwindow::scroll_box_up(int scol, int srow, int ecol, int erow, int count) {
activate_quick();
wscrollbox(scol, srow, ecol, erow, count, direction_up);
}
// ------------------------------------------------------------------
inline void gwindow::getc(int row, int col, vattr* atr, vchar* chr) {
activate_quick();
wgetc(row, col, atr, chr);
}
// ------------------------------------------------------------------
inline void gwindow::putc(vchar ch) {
activate_quick();
wputc(ch);
}
// ------------------------------------------------------------------
inline void gwindow::puts(const char* text) {
activate_quick();
wputs(text);
}
// ------------------------------------------------------------------
inline void gwindow::printc(int row, int col, vattr color, vchar ch) {
activate_quick();
wprintc(row, col, color, ch);
}
// ------------------------------------------------------------------
inline void gwindow::prints(int row, int col, vattr color, const char* text) {
activate_quick();
wprints(row, col, color == DEFATTR ? window_color : color, text);
}
// ------------------------------------------------------------------
inline void gwindow::printvs(int row, int col, vattr color, const vchar* text) {
activate_quick();
wprintvs(row, col, color == DEFATTR ? window_color : color, text);
}
// ------------------------------------------------------------------
inline void gwindow::prints(int row, int col, vattr color, const std::string& text) {
prints(row, col, color, text.c_str());
}
// ------------------------------------------------------------------
inline void gwindow::printns(int row, int col, vattr color, const char* text, int len, vchar fill, vattr fill_color) {
activate_quick();
wprintns(row, col, color, text, len, fill, fill_color);
}
// ------------------------------------------------------------------
inline void gwindow::fill_char(vchar ch) {
activate_quick();
wfillch(ch);
}
// ------------------------------------------------------------------
inline void gwindow::fill(int wsrow, int wscol, int werow, int wecol, vchar ch, vattr color) {
activate_quick();
wfill(wsrow, wscol, werow, wecol, ch, color);
}
// ------------------------------------------------------------------
inline void gwindow::vertical_line(int wsrow, int wscol, int count, int btype, vattr color) {
activate_quick();
wvline(wsrow, wscol, count, btype, color);
}
// ------------------------------------------------------------------
inline void gwindow::horizontal_line(int wsrow, int wscol, int count, int btype, vattr color) {
activate_quick();
whline(wsrow, wscol, count, btype, color);
}
// ------------------------------------------------------------------
inline void gwindow::clear(vattr color) {
activate_quick();
wcclear(color == DEFATTR ? window_color : color);
}
// ------------------------------------------------------------------
inline gwindow::gwindow() {
init();
owner = true;
}
// ------------------------------------------------------------------
inline gwindow::gwindow(int old_handle) {
init();
owner = false;
wrec = wfindrec(old_handle);
start_row = wrec->srow;
start_column = wrec->scol;
end_row = wrec->erow;
end_column = wrec->ecol;
window_color = wrec->wattr;
window_style = wrec->btype;
border_hi_color = wrec->battr;
border_lo_color = wrec->loattr;
scrollbar_color = wrec->sbattr;
}
// ------------------------------------------------------------------
inline gwindow::~gwindow() {
if(owner)
close();
}
// ------------------------------------------------------------------
inline void gwindow::slide(int row, int col) {
activate_quick();
wslide(row, col);
}
// ------------------------------------------------------------------
inline void gwindow::print_center(int row, vattr color, const char* text) {
activate_quick();
wcenters(row, color, text);
}
// ------------------------------------------------------------------
#endif
// ------------------------------------------------------------------

124
goldlib/gcui/gwinhelp.h Normal file
View File

@ -0,0 +1,124 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// Copyright (C) 1999-2000 Alexander S. Aganichev
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Help.
// ------------------------------------------------------------------
#ifndef __gwinhelp_h
#define __gwinhelp_h
// ------------------------------------------------------------------
#include <gfile.h>
#include <gwinall.h>
// ------------------------------------------------------------------
// Window help information record
class _help_t {
public:
int help[20]; // help stack
const char* file; // help file name
int helpptr; // help stack pointer
gkey key; // help hot key
vattr winattr; // help window attribute
vattr textattr; // help window text attribute
vattr selattr; // selection text attribute
vattr barattr; // selection bar attribute
int srow; // help window start row
int scol; // help window start column
int erow; // help window end row
int ecol; // help window end column
int btype; // help window box type
int title; // display "Help" title?
VfvCP open; // pointer to open function
gfile* fp; // help file
long offset; // help file offset
_help_t()
{
memset(help, 0, sizeof(help));
file = NULL;
helpptr = -1;
key = 0;
winattr = BLACK_|_BLACK;
textattr = BLACK_|_BLACK;
selattr = BLACK_|_BLACK;
barattr = BLACK_|_BLACK;
srow = 3;
scol = 8;
erow = 21;
ecol = 71;
btype = 0;
title = YES;
open = NULL;
fp = NULL;
offset = 0;
}
};
// ------------------------------------------------------------------
// Help index file record definition
#if defined(GOLD_CANPACK)
#pragma pack(1)
#endif
typedef struct _hlpidx_t {
word help;
char category[30];
long offset;
} Hlpr;
#if defined(GOLD_CANPACK)
#pragma pack()
#endif
// ------------------------------------------------------------------
int whelpcat(int cat);
int whelpclr();
int whelpdef(const char* file, gkey key, vattr winattr, vattr textattr, vattr selattr, vattr barattr, VfvCP open);
int whelpop();
int whelpopc();
int whelppcat(int cat);
int whelpush();
int whelpushc(int cat);
int whelpwin(int srow, int scol, int erow, int ecol, int btype, int title);
void whelpcompile(const char* helpfile, long& offset);
inline int whelpundef() { return whelpdef(NULL,0,BLACK_|_BLACK,BLACK_|_BLACK,BLACK_|_BLACK,BLACK_|_BLACK,NULL); }
// ------------------------------------------------------------------
#endif
// ------------------------------------------------------------------

763
goldlib/gcui/gwinhlp1.cpp Normal file
View File

@ -0,0 +1,763 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// Copyright (C) 1999-2000 Alexander S. Aganichev
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Help functions.
// Based on CXL by Mike Smedley.
// ------------------------------------------------------------------
// esc_esc() emulate two Esc key pressed
// esc_pgdn() emulate key sequence Esc & PgDn
// esc_pgup() emulate key sequence Esc & PgUp
// not_found() display alert window "Help category not found"
// find_cat_name() search index for help category entry by name
// find_cat_number() search index for help category entry by numbe.
// find_page() search a page in the help file
// disp_cat() display a help category
// help_handler() display a window with help
//
// whelpdef() defines the help key, file, and window colors
// whelpwin() defines the help window boundaries
// whelpcat() sets the help category
// whelppcat() sets the help category, but pushes current one first
// whelpopc() pops the last saved help category into the void
// whelpclr() clears the help buffer
// whelpush() pushes the current help category onto the stack
// whelpushc() pushes the given help category onto the stack
// whelpop() pops last saved help category, sets current
// ------------------------------------------------------------------
#include <cstdio>
#include <cstdlib>
#include <gfile.h>
#include <gmemdbg.h>
#include <gkbdcode.h>
#include <gkbdbase.h>
#include <gmoubase.h>
#include <gutlmisc.h>
#include <gstrall.h>
#include <gvidall.h>
#include <gwinall.h>
#include <gwinhelp.h>
// ------------------------------------------------------------------
// Constants
#define MAXXREF 50
#define BUFSIZE 80
#define BASETAGID 200
// ------------------------------------------------------------------
// Global variables
extern int gmnudropthrough;
// ------------------------------------------------------------------
// Local variables
static bool whelpclosefile = false;
static char* catarray[MAXXREF];
static int arraycnt = 0;
static char buf[BUFSIZE+1];
_help_t whelp;
// ------------------------------------------------------------------
// Help index file record definition
static Hlpr recd;
// ------------------------------------------------------------------
static void esc_esc() {
setonkey(Key_Esc,NULL,0);
kbput(Key_Esc);
kbput(Key_Esc);
}
// ------------------------------------------------------------------
static void esc_pgdn() {
setonkey(Key_Esc,NULL,0);
setonkey(Key_PgDn,NULL,0);
kbput(Key_Esc);
kbput(Key_PgDn);
}
// ------------------------------------------------------------------
static void esc_pgup() {
setonkey(Key_Esc,NULL,0);
setonkey(Key_PgUp,NULL,0);
kbput(Key_Esc);
kbput(Key_PgUp);
}
// ------------------------------------------------------------------
static void not_found(const char* cat) {
wtextattr(whelp.textattr);
wputs("\nHelp category not found: ");
wputs(cat);
wputs("\nPress a key to continue.");
waitkey();
}
// ------------------------------------------------------------------
static int find_cat_name(const char* cat) {
int found=NO;
// Reset file pointer.
whelp.fp->FseekSet(whelp.offset);
// Check for "*I" marker.
whelp.fp->Fgets(buf, BUFSIZE);
if (strnieql(buf,"*I",2))
{
// Search index for help category entry. If found,
// then advance file pointer to specified position.
for(;;)
{
whelp.fp->Fread(&recd,sizeof(Hlpr));
if(recd.offset==-1L)
break;
if (strieql(recd.category,cat))
{
whelp.fp->FseekSet(whelp.offset + recd.offset);
found=YES;
break;
}
}
}
// If help category was not found, display an error message.
if(not found)
not_found(cat);
return found;
}
// ------------------------------------------------------------------
static int find_cat_number(int cat) {
int found=NO;
// Reset file pointer.
whelp.fp->FseekSet(whelp.offset);
// Check for "*I" marker.
whelp.fp->Fgets(buf, BUFSIZE);
if (strnieql(buf,"*I",2))
{
// Search index for help category entry. If found,
// then advance file pointer to specified position.
for (;;)
{
whelp.fp->Fread(&recd,sizeof(Hlpr));
if (recd.offset==-1L)
break;
if (recd.help==cat)
{
whelp.fp->FseekSet(whelp.offset + recd.offset);
found=YES;
break;
}
}
}
// If help category was not found, display an error message.
if(!found) {
sprintf(buf, "%u", cat);
not_found(buf);
}
return found;
}
// ------------------------------------------------------------------
static int find_page(long startpos, int pageofs) {
long lastpagepos, currpos;
int currpage = 0;
int lines = whelp.srow;
lastpagepos = currpos = startpos;
whelp.fp->FseekSet(startpos);
while (currpage < pageofs)
{
whelp.fp->Fgets(buf, BUFSIZE);
if (not whelp.fp->okay())
{
whelp.fp->FseekSet(lastpagepos);
break;
}
lines++;
currpos=whelp.fp->Ftell();
if (strnieql(buf, "*E", 2))
{
whelp.fp->FseekSet(lastpagepos);
break;
}
if(strnieql(buf, "*P", 2)) {
if(lines != whelp.srow+1) {
lastpagepos=currpos;
currpage++;
}
lines = whelp.srow;
}
else if(lines == whelp.erow-1) {
lastpagepos=currpos;
currpage++;
lines = whelp.srow;
}
}
return currpage;
}
// ------------------------------------------------------------------
static void disp_cat() {
int page, wrow, wcol, end, menuopen, itemopen;
long startpos;
_menu_t *curr;
char* p;
char* q;
gkey i, kbch;
// initialize variables
page = wrow = wcol = end = menuopen = itemopen = 0;
// save current info
startpos = whelp.fp->Ftell();
curr = gwin.cmenu;
// set text attribute
wtextattr(whelp.textattr);
for(;;) {
// read next line from help file into buffer
whelp.fp->Fgets(buf,BUFSIZE);
strtrim(buf);
// if end-of-file or "*E" was found, assume end-of-category
end = strnieql(buf,"*E",2) ? YES : NO;
bool pagebreak = false;
if(strnieql(buf,"*P",2)) {
if(wrow != whelp.srow)
pagebreak = true;
else
continue;
}
// if end-of-category or new-page specified
if((wrow > whelp.erow-1) or pagebreak or end)
{
const char* _help = " Help ";
char _title[80];
sprintf(_title, " %s ", recd.category);
wtitle(NULL, TTOP, whelp.winattr);
wtitle(_title, TLEFT, whelp.winattr);
wtitle(NULL, TCENTER|TBOTTOM, whelp.winattr);
wmessage(_help, TP_BORD, whelp.ecol-whelp.scol-strlen(_help), whelp.winattr);
// update bottom border of window with PgUp/PgDn info
if(page and not end) p = " PgUp/PgDn ";
else if(not page and end) p = "";
else if(page and end) p = " PgUp ";
else p = " PgDn ";
wmessage(p,BT_BORD,whelp.ecol-whelp.scol-strlen(p),whelp.winattr);
wmessage(" ESC ",BT_BORD,1,whelp.winattr);
// if one or more cross reference menu items were specified
if (arraycnt)
{
// define the PgUp/PgDn/Esc keys
setonkey(Key_PgUp,esc_pgup,0);
setonkey(Key_PgDn,esc_pgdn,0);
setonkey(Key_Esc,esc_esc,0);
// end the menu and process it
wmenuend(BASETAGID,M_OMNI|M_NOQS,0,0,whelp.selattr,whelp.selattr,BLACK_|_BLACK,whelp.barattr);
gmnudropthrough = YES;
kbch = i = (gkey)wmenuget();
gmnudropthrough = NO;
// free the keys that were defined
setonkey(Key_PgUp,NULL,0);
setonkey(Key_PgDn,NULL,0);
setonkey(Key_Esc,NULL,0);
// turn off the menuopen flag and restore menu info
menuopen=NO;
gwin.cmenu=curr;
// if Esc, PgDn, or PgUp was not pressed
if(i != 0xFFFF) {
// convert tagid to array subscript
i -= (gkey)BASETAGID;
// try to find selected category, if found set
// file pointer to it, otherwise reset file
// pointer back to previous help category
if (find_cat_name(catarray[i]))
startpos = whelp.fp->Ftell();
else
whelp.fp->FseekSet(startpos);
// clear help window and set
// position to upper left corner
wclear();
wrow=page=0;
// free menu item strings
for(i=0;i<arraycnt;i++)
throw_release(catarray[i]);
arraycnt=0;
continue;
}
// free menu item strings
for(i=0;i<arraycnt;i++)
throw_release(catarray[i]);
arraycnt=0;
if(kbmhit()) {
gkbd.inmenu = true;
kbch = getxch();
gkbd.inmenu = false;
}
}
else {
gkbd.inmenu = true;
kbch = getxch();
gkbd.inmenu = false;
}
if ((kbch == word(-1)) || (kbch == Key_Esc))
{
// clear any PgUp or PgDn keystrokes that
// may be lurking in CXL's keystroke
// buffer, and return to caller.
kbclear();
return;
}
else
{
if (kbch == Key_PgUp)
page -= (page ? 1 : 0); // find previous page
else if (kbch == Key_PgDn)
page += (end ? 0 : 1); // find next page
// clear help window, and set position to upper left corner
page = find_page(startpos, page);
wrow=0;
wclear();
kbclear();
continue;
}
}
// search for cross reference categories on current line.
// if any are found, then define them as a menu item
q = buf;
do {
// search for 1st carat. if found, test for double carat.
// if double carat was found display literal carat. next,
// search for 2nd carat. if not found, then display the
// line as text. otherwise, if found, define everything
// in between the 2 carats as a menu item.
p = strchr(q,'^');
if(p) {
if(*(p+1)=='^') {
*(p+1) = NUL;
wprints(wrow, wcol, gwin.active->attr, q);
wcol += strlen(q);
q = p + 2;
}
else {
*p = NUL;
itemopen ^= 1;
wprints(wrow, wcol, gwin.active->attr, q);
if((not itemopen) and (arraycnt<MAXXREF)) {
if((catarray[arraycnt]=(char*)throw_malloc(strlen(q)+1))!=NULL) {
strcpy(catarray[arraycnt],q);
if(not menuopen) {
wmenubegc();
menuopen=YES;
}
wmenuitem(
wrow,
wcol,
catarray[arraycnt],
*catarray[arraycnt],
BASETAGID+arraycnt,
0,
NULL,
0,
0
);
arraycnt++;
}
}
wcol += strlen(q);
q = p + 1;
}
}
} while(p);
// display text line and increment current window row
wprints(wrow, wcol, gwin.active->attr, q);
wrow++;
wcol=0;
}
} /* disp_cat() */
// ------------------------------------------------------------------
static void help_handler() {
register int i;
int help,cat;
int found;
KBnd* savekb;
// save help category
help=gwin.help;
// temporarily un-define the onkey list to avoid collision
savekb=chgonkey(NULL);
// hide cursor
int cursorwashidden = vcurhidden();
vcurhide();
// hide mouse cursor
#ifdef GOLD_MOUSE
gmou.HideCursor();
#endif
// open help window
if(not wopen(whelp.srow, whelp.scol, whelp.erow, whelp.ecol, whelp.btype, whelp.winattr, whelp.winattr))
return;
// display window title if specified
if(whelp.title)
wtitle("[ Help ]",TCENTER,whelp.winattr);
// see if an open function was given. If so, then call it
if(whelp.open)
(*whelp.open)();
// determine help category to use. If the current help category
// is empty, check the stack for a help category there
cat=help;
if(not cat) {
if(whelp.helpptr>-1) {
for(i=whelp.helpptr;i>=0;i--) {
if(whelp.help[i]) {
cat=whelp.help[i];
break;
}
}
}
}
// check for no defined help category
if(not cat) {
wtextattr(whelp.textattr);
wputs("\nNo help category defined.\nPress a key to continue.");
waitkey();
}
else {
if (not whelp.fp)
{
whelpclosefile = true;
whelp.fp = new gfile; throw_new(whelp.fp);
whelp.fp->Fopen(whelp.file,"rb");
if (!whelp.fp->isopen())
{
wtextattr(whelp.textattr);
wputs("\nHelp file not found: ");
wputs(whelp.file);
wputs("\nPress a key to continue.");
waitkey();
}
}
if (whelp.fp->isopen())
{
whelp.fp->FseekSet(whelp.offset);
// find help category in help file
found=find_cat_number(cat);
// read and display help category text
if(found)
disp_cat();
}
if (whelpclosefile)
{
whelp.fp->Fclose();
delete whelp.fp;
whelp.fp = NULL;
}
}
// close help window
wclose();
// reset mouse info
#ifdef GOLD_MOUSE
if(gmou.FreeCursor())
gmou.ShowCursor();
#endif
// reset cursor
if(not cursorwashidden)
vcurshow();
// clear any onkeys defined in "open" function and relink the onkey list
freonkey();
chgonkey(savekb);
// restore help category
gwin.help=help;
}
// ------------------------------------------------------------------
int whelpdef(const char* file, gkey key, vattr winattr, vattr textattr, vattr selattr, vattr barattr, VfvCP open) {
// is help disengagement requested? If so, un-define the help key.
if(file==NULL) {
if(gwin.helptr==NULL)
return gwin.werrno=W_NOHLPDEF;
else {
gwin.helptr=NULL;
whelpclr();
setonkey(whelp.key,NULL,0);
}
}
else {
// attach help key to help handler
if(setonkey(key,help_handler,0))
return gwin.werrno=W_ALLOCERR;
// point global help info pointer to internal struct
gwin.helptr=&whelp;
}
// add information to window help information record
whelp.file = file;
whelp.key = key;
whelp.winattr = winattr;
whelp.textattr = textattr;
whelp.selattr = selattr;
whelp.barattr = barattr;
whelp.open = open;
// return with no error
return gwin.werrno=W_NOERROR;
}
// ------------------------------------------------------------------
int whelpwin(int srow, int scol, int erow, int ecol, int btype, int title) {
// make sure help has been defined
if(gwin.helptr==NULL)
return gwin.werrno=W_NOHLPDEF;
// load given coordinates into local static structure
whelp.srow =srow;
whelp.scol =scol;
whelp.erow =erow;
whelp.ecol =ecol;
whelp.btype=btype;
whelp.title=title;
// return normally
return gwin.werrno=W_NOERROR;
}
// ------------------------------------------------------------------
int whelpcat(int cat) {
// make sure help record has been defined
if(gwin.helptr==NULL)
return gwin.werrno=W_NOHLPDEF;
// determine if help is to be global or window
if(gwin.active)
gwin.active->help=cat;
gwin.help=cat;
// return normally
return gwin.werrno=W_NOERROR;
}
// ------------------------------------------------------------------
int whelppcat(int cat) {
// check for existance of help, and push
// current help category onto help stack
if(whelpush())
return gwin.werrno;
// set help category
return whelpcat(cat);
}
// ------------------------------------------------------------------
int whelpopc() {
// make sure help has been defined
if(gwin.helptr==NULL)
return gwin.werrno=W_NOHLPDEF;
// check for stack underflow
if(whelp.helpptr==-1)
return gwin.werrno=W_HLPSTKUN;
// decrement stack pointer
whelp.helpptr--;
// return normally
return gwin.werrno=W_NOERROR;
}
// ------------------------------------------------------------------
int whelpclr() {
// make sure help has been defined
if(gwin.helptr==NULL)
return gwin.werrno=W_NOHLPDEF;
// clear help category and reset help stack pointer
gwin.help=0;
whelp.helpptr=-1;
// return normally
return(gwin.werrno=W_NOERROR);
}
// ------------------------------------------------------------------
int whelpush() {
// make sure help has been defined
if(gwin.helptr==NULL)
return(gwin.werrno=W_NOHLPDEF);
// push the current help category onto the help stack
return(whelpushc(gwin.help));
}
// ------------------------------------------------------------------
int whelpushc(int cat) {
// make sure help has been defined
if(gwin.helptr==NULL)
return(gwin.werrno=W_NOHLPDEF);
// check for stack overflow
if(gwin.helptr->helpptr==19)
return(gwin.werrno=W_HLPSTKOV);
// add help category to stack and increment stack pointer
gwin.helptr->help[++gwin.helptr->helpptr]=cat;
// return normally
return(gwin.werrno=W_NOERROR);
}
// ------------------------------------------------------------------
int whelpop() {
// make sure help has been defined
if(gwin.helptr==NULL)
return(gwin.werrno=W_NOHLPDEF);
// check for stack underflow
if(gwin.helptr->helpptr==-1)
return(gwin.werrno=W_HLPSTKUN);
// restore help category and decrement stack pointer
gwin.help=gwin.helptr->help[gwin.helptr->helpptr--];
if(gwin.active)
gwin.active->help=gwin.help;
// return normally
return(gwin.werrno=W_NOERROR);
}
// ------------------------------------------------------------------

101
goldlib/gcui/gwinhlp2.cpp Normal file
View File

@ -0,0 +1,101 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// Copyright (C) 1999-2000 Alexander S. Aganichev
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Help file compiler.
// ------------------------------------------------------------------
#include <gmemdbg.h>
#include <gutlmisc.h>
#include <gstrall.h>
#include <gwinall.h>
#include <gwinhelp.h>
// ------------------------------------------------------------------
extern _help_t whelp;
// ------------------------------------------------------------------
void whelpcompile(const char* helpfile, long& offset) {
gfile ifp(helpfile, "rb");
if (ifp.isopen())
{
ifp.SetvBuf();
int count = 0;
char buf[1024];
while (ifp.Fgets(buf, sizeof(buf)))
{
if(strnieql(buf, "*B ", 3))
count++;
}
ifp.Rewind();
Hlpr* helpindex = (Hlpr*)throw_xcalloc(count+2, sizeof(Hlpr));
long relative_offset = 0;
whelp.fp->Fputs("*I\r\n");
whelp.fp->Fwrite(helpindex, count+1, sizeof(Hlpr));
whelp.fp->Fputs("\r\n\r\n");
relative_offset += 4 + ((count+1)*sizeof(Hlpr)) + 4;
int counter = 0;
bool comment = true;
while (ifp.Fgets(buf, sizeof(buf)))
{
if(strnieql(buf, "*B ", 3)) {
comment = false;
helpindex[counter].help = atow(buf+3);
char* ptr = strchr(buf, ',');
strbtrim(strcpy(helpindex[counter].category, ptr ? ptr+1 : ""));
helpindex[counter].offset = relative_offset + strlen(buf);
counter++;
}
if (not comment)
{
whelp.fp->Fputs(buf);
relative_offset += strlen(buf);
}
if(strnieql(buf, "*E", 2))
comment = true;
}
helpindex[counter].offset = -1L;
whelp.fp->FseekSet(offset);
whelp.fp->Fputs("*I\r\n");
whelp.fp->Fwrite(helpindex, count+1, sizeof(Hlpr));
offset += relative_offset;
whelp.fp->FseekSet(offset);
throw_xfree(helpindex);
ifp.Fclose();
}
} /* whelpcompile() */
// ------------------------------------------------------------------

328
goldlib/gcui/gwininit.cpp Normal file
View File

@ -0,0 +1,328 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// Copyright (C) 1999-2000 Alexander S. Aganichev
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Windowing kernel.
// Based on CXL by Mike Smedley.
// ------------------------------------------------------------------
#include <cstdio>
#include <cstdarg>
#include <cstdlib>
#include <cstring>
#include <gmemdbg.h>
#include <gutlmisc.h>
#include <gwinall.h>
#include <gkbdcode.h>
// ------------------------------------------------------------------
#define GOLD_INLINE inline
#define GOLD_WCHK
// ------------------------------------------------------------------
// Global window data
GWin gwin;
// ------------------------------------------------------------------
// Window Class constructor
GWin::GWin() {
active = NULL; // pointer to active window
hidden = NULL; // pointer to last hidden window
menu = NULL; // pointer to head menu record
cmenu = NULL; // pointer to current menu record
helptr = NULL; // pointer to help info record
handle = 0; // last handle given to a window
help = 0; // pointer to current help category
werrno = W_NOERROR; // error num from last window func
total = 0; // total number of open windows
mlevel = 0; // system variable used in menus
ilevel = 0; // system variable used in menus
esc = true; // check for Esc in input funcions?
tabwidth = 8; // window TTY output tab width
fillch = ' '; // character to fill windows with
style = STYLE_NORMAL; // window opening style
}
// ------------------------------------------------------------------
// Window Class destructor
GWin::~GWin() {
// No action defined yet
}
// ------------------------------------------------------------------
// Displays a string in centered in active window
int wcenters(int wrow, vattr attr, const char* str) {
register int window_width, string_length;
int start_column, border;
// check for active window
if(!gwin.total)
return gwin.werrno=W_NOACTIVE;
// check for valid row
if(wchkcoord(wrow,0))
return gwin.werrno=W_INVCOORD;
// check for window border
border=gwin.active->border;
// calculate start column & window width
start_column = gwin.active->scol+border;
window_width = (gwin.active->ecol-border)-start_column+1;
// check length of input string
string_length=strlen(str);
if(string_length>window_width)
return gwin.werrno=W_STRLONG;
// display the string
vputs(
gwin.active->srow+wrow+border,
((window_width/2)+start_column)-(string_length/2),
attr,
str
);
// return normally
return gwin.werrno=W_NOERROR;
}
// ------------------------------------------------------------------
// Smoothly drag a window 1 position in given direction
int wdrag(int direction) {
int srow, scol, erow, ecol, fill_row, fill_col, i;
int nsrow, nscol, nerow, necol;
vattr shad_attr = DEFATTR;
int chars_per_line, lines_per_win;
int vert_movement, horz_movement;
vsavebuf* win_image;
vsavebuf* wp;
vatch* p;
register vatch* src;
register vatch* dest;
// check for active window
if(!gwin.total)
return(gwin.werrno=W_NOACTIVE);
// get window coordinates
srow = gwin.active->srow;
scol = gwin.active->scol;
erow = gwin.active->erow;
ecol = gwin.active->ecol;
// calculate lines-per-window and characters-per-line
lines_per_win = erow - srow + 1;
chars_per_line = ecol - scol + 1;
// determine facts about direction of move
vert_movement=horz_movement=0;
switch(direction) {
case D_DOWN:
vert_movement=1;
lines_per_win--;
break;
case D_UP:
vert_movement=-1;
lines_per_win--;
break;
case D_LEFT:
horz_movement=-1;
chars_per_line--;
break;
case D_RIGHT:
default:
horz_movement=1;
chars_per_line--;
}
// calculate new window coordinates
nsrow = srow + vert_movement;
nscol = scol + horz_movement;
nerow = erow + vert_movement;
necol = ecol + horz_movement;
// if window has shadow, close it before the move
if(gwin.active->wsbuf!=NULL) {
shad_attr = gwin.active->wsattr;
wshadoff();
}
// save the current window image
win_image = vsave(srow,scol,erow,ecol);
if(win_image==NULL)
return(gwin.werrno=W_ALLOCERR);
// save the area where the window will relocate to
wp = vsave(nsrow,nscol,nerow,necol);
if(wp==NULL) {
throw_xfree(win_image);
return(gwin.werrno=W_ALLOCERR);
}
// restore window to new coordinates
vrestore(win_image, nsrow, nscol, nerow, necol);
throw_xfree(win_image);
// start buffer positions past coordinates
src = gwin.active->wbuf->data;
dest = wp->data;
if(direction==D_DOWN)
src += chars_per_line;
if(direction==D_UP)
dest += chars_per_line;
// do the transfer of buffer contents
for(i=0; i < lines_per_win; i++) {
if(direction==D_LEFT)
dest++;
if(direction==D_RIGHT)
src++;
// move 1 line
memmove(dest, src, chars_per_line*sizeof(vatch));
src += chars_per_line;
dest += chars_per_line;
if(direction==D_LEFT)
src++;
if(direction==D_RIGHT)
dest++;
}
// erase the trail that was left-over
p = gwin.active->wbuf->data;
if(vert_movement) {
if(direction==D_DOWN)
fill_row=srow;
else {
p += (lines_per_win * chars_per_line);
fill_row=erow;
}
vputx(fill_row, scol, vgattr(*p), vgchar(*p), ecol-scol+1);
}
else {
if(direction==D_RIGHT)
fill_col=scol;
else {
p += chars_per_line;
fill_col=ecol;
}
for(i=srow;i<=erow;i++,p+=chars_per_line+1)
vputc(i, fill_col, vgattr(*p), vgchar(*p));
}
// free old window buffer
throw_xfree(gwin.active->wbuf);
// update window record
gwin.active->wbuf = wp;
gwin.active->row = gwin.active->row - gwin.active->srow + nsrow;
gwin.active->column = gwin.active->column - gwin.active->scol + nscol;
gwin.active->srow = nsrow;
gwin.active->scol = nscol;
gwin.active->erow = nerow;
gwin.active->ecol = necol;
// if window has shadow, redraw it
if(shad_attr != DEFATTR)
wshadow(shad_attr);
// reset cursor position
vposset(gwin.active->row,gwin.active->column);
// return normally
return(gwin.werrno=W_NOERROR);
}
// ------------------------------------------------------------------
// Slides active window to a new location
int wslide(int nsrow, int nscol) {
vattr shattr = DEFATTR;
int err = 0;
// check for active windows
if(!gwin.total)
return gwin.werrno=W_NOACTIVE;
// check for valid coordinates
if(nsrow<0 or nscol<0)
return gwin.werrno=W_INVCOORD;
// if window has shadow, close it before the move
if(gwin.active->wsbuf!=NULL) {
shattr = gwin.active->wsattr;
wshadoff();
}
// slide it on over
while(gwin.active->scol>nscol and !err) err = wdrag(D_LEFT);
while(gwin.active->scol<nscol and !err) err = wdrag(D_RIGHT);
while(gwin.active->srow>nsrow and !err) err = wdrag(D_UP);
while(gwin.active->srow<nsrow and !err) err = wdrag(D_DOWN);
// test for error
if(gwin.werrno)
return gwin.werrno;
// if window has shadow, redraw it
if(shattr != DEFATTR)
wshadow(shattr);
// return normally
return gwin.werrno=W_NOERROR;
}
// ------------------------------------------------------------------

318
goldlib/gcui/gwinline.cpp Normal file
View File

@ -0,0 +1,318 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// Copyright (C) 1999-2000 Alexander S. Aganichev
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Functions for line drawing.
// Based on CXL by Mike Smedley.
// ------------------------------------------------------------------
// whline() draws a horizontal text line in active window
// wvline() draws a vertical text line in active window
// ------------------------------------------------------------------
#include <gwinall.h>
// ------------------------------------------------------------------
#define HORZ 0
#define VERT 1
// ------------------------------------------------------------------
#define ULC _box_table(bt, 0) // upper left corner
#define UHL _box_table(bt, 1) // upper horizontal line
#define URC _box_table(bt, 2) // upper right corner
#define LVL _box_table(bt, 3) // left vertical line
#define RVL _box_table(bt, 4) // right vertical line
#define LLC _box_table(bt, 5) // lower left corner
#define LHL _box_table(bt, 6) // lower horizontal line
#define LRC _box_table(bt, 7) // lower right corner
#define MJ _box_table(bt, 8) // middle junction
#define LVJ _box_table(bt, 9) // left vertical junction
#define RVJ _box_table(bt, 10) // right vertical junction
#define UHJ _box_table(bt, 11) // upper horizontal junction
#define LHJ _box_table(bt, 12) // lower horizontal junction
// ------------------------------------------------------------------
static int disp_char(int wrow,int wcol, vattr attr,int btype,vchar ch,int direc) {
attr = attr|ACSET;
// see if next to a border, if so, connect to it
if(gwin.active->border) {
// abbreviate pointer
const int bt = btype;
// calculate effective row and column
int row = gwin.active->srow+gwin.active->border+wrow;
int col = gwin.active->scol+gwin.active->border+wcol;
// see if this is a horizontal or vertical line
if(direc==HORZ) {
// make sure that the box type characters match
if(LVL==_box_table(gwin.active->btype, 3)) {
// check left border
if(col==(gwin.active->scol+1)) {
vputc(row,gwin.active->scol,attr,LVJ);
ch=UHL;
}
// check right border
if(col==(gwin.active->ecol-1)) {
vputc(row,gwin.active->ecol,attr,RVJ);
ch=UHL;
}
}
}
else {
// make sure that the box type characters match
if(UHL==_box_table(gwin.active->btype, 1)) {
// check top border
if(row==(gwin.active->srow+1)) {
vputc(gwin.active->srow,col,attr,UHJ);
ch=LVL;
}
// check bottom border
if(row==(gwin.active->erow-1)) {
vputc(gwin.active->erow,col,attr,LHJ);
ch=LVL;
}
}
}
}
// display character
if(wprintc(wrow,wcol,attr,ch))
return gwin.werrno;
// return normally
return 0;
} /* disp_char() */
// ------------------------------------------------------------------
static inline int isupvert(int btype, vchar ch) {
const int bt = btype;
return (ch==LVL or ch==UHJ or ch==ULC or ch==URC or ch==LVJ or ch==RVJ or ch==MJ) ? YES : NO;
}
// ------------------------------------------------------------------
static inline int isdownvert(int btype, vchar ch) {
const int bt = btype;
return (ch==LVL or ch==LHJ or ch==LLC or ch==LRC or ch==LVJ or ch==RVJ or ch==MJ) ? YES : NO;
}
// ------------------------------------------------------------------
static inline int islefthorz(int btype, vchar ch) {
const int bt = btype;
return (ch==UHL or ch==LVJ or ch==LLC or ch==ULC or ch==UHJ or ch==LHJ or ch==MJ) ? YES : NO;
}
// ------------------------------------------------------------------
static inline int isrighthorz(int btype, vchar ch) {
const int bt = btype;
return (ch==UHL or ch==RVJ or ch==LRC or ch==URC or ch==UHJ or ch==LHJ or ch==MJ) ? YES : NO;
}
// ------------------------------------------------------------------
int whline(int wsrow, int wscol, int count, int btype, vattr attr) {
register int bt;
int row,col,up,down;
vchar ch;
row=wsrow;
col=wscol;
// abbreviate pointer
bt = btype;
if(count) {
// see if a left junction or corner is needed
up = isupvert (btype,wgetc(row-1,col));
down = isdownvert(btype,wgetc(row+1,col));
if(up and down)
ch=LVJ;
else if(up)
ch=LLC;
else if(down)
ch=ULC;
else
ch=UHL;
// display leftmost character
if(disp_char(row,col,attr,btype,ch,HORZ))
return gwin.werrno;
col++;
count--;
}
// do while not last character
while(count>1) {
// see if a middle junction is needed
up = isupvert (btype,wgetc(row-1,col));
down = isdownvert(btype,wgetc(row+1,col));
if(up and down)
ch=MJ;
else if(up)
ch=LHJ;
else if(down)
ch=UHJ;
else
ch=UHL;
// display middle character
if(disp_char(row,col,attr,btype,ch,HORZ))
return gwin.werrno;
col++;
count--;
}
if(count) {
// see if a right junction or corner is needed
up = isupvert (btype,wgetc(row-1,col));
down = isdownvert(btype,wgetc(row+1,col));
if(up and down)
ch=RVJ;
else if(up)
ch=LRC;
else if(down)
ch=URC;
else
ch=UHL;
// display rightmost character
if(disp_char(row,col,attr,btype,ch,HORZ))
return gwin.werrno;
}
// return normally
return gwin.werrno=W_NOERROR;
} /* whline() */
// ------------------------------------------------------------------
int wvline(int wsrow, int wscol, int count, int btype, vattr attr) {
register int bt;
int row,col,left,right;
vchar ch;
row=wsrow;
col=wscol;
// abbreviate pointer
bt = btype;
if(count) {
// see if a top junction or corner is needed
left = islefthorz (btype,wgetc(row,col-1));
right = isrighthorz(btype,wgetc(row,col+1));
if(left and right)
ch=UHJ;
else if(left)
ch=URC;
else if(right)
ch=ULC;
else
ch=LVL;
// display uppermost character
if(disp_char(row,col,attr,btype,ch,VERT))
return gwin.werrno;
row++;
count--;
}
// do while not last character
while(count>1) {
left = islefthorz (btype,wgetc(row,col-1));
right = isrighthorz(btype,wgetc(row,col+1));
if(left and right)
ch=MJ;
else if(left)
ch=RVJ;
else if(right)
ch=LVJ;
else
ch=LVL;
// display middle character
if(disp_char(row,col,attr,btype,ch,VERT))
return gwin.werrno;
row++;
count--;
}
if(count) {
// see if a bottom junction or corner is needed
left = islefthorz (btype,wgetc(row,col-1));
right = isrighthorz(btype,wgetc(row,col+1));
if(left and right)
ch=LHJ;
else if(left)
ch=LRC;
else if(right)
ch=LLC;
else
ch=LVL;
// display bottommost character
if(disp_char(row,col,attr,btype,ch,VERT))
return gwin.werrno;
}
// return normally
return gwin.werrno=W_NOERROR;
} /* wvline() */
// ------------------------------------------------------------------

1460
goldlib/gcui/gwinmenu.cpp Normal file

File diff suppressed because it is too large Load Diff

323
goldlib/gcui/gwinmnub.cpp Normal file
View File

@ -0,0 +1,323 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Menu class.
// ------------------------------------------------------------------
#include <cstdlib>
#include <cstring>
#include <gmnubase.h>
// ------------------------------------------------------------------
void GMnu::Init() {
bordertype = 0;
bordercolor = BLACK_|_BLACK;
textcolor = BLACK_|_BLACK;
quickcolor = BLACK_|_BLACK;
noselcolor = BLACK_|_BLACK;
barcolor = BLACK_|_BLACK;
shadowcolor = DEFATTR;
title = NULL;
titlepos = TCENTER;
titlecolor = BLACK_|_BLACK;
deschdl = -1;
descrow = 0;
desccolumn = 0;
desccolor = BLACK_|_BLACK;
helpnumber = -1;
beginrow = 0;
begincolumn = 0;
menuopen = NULL;
itemmask = 0;
escape = YES;
finaltag = -1;
status = W_NOERROR;
depth = -1;
memset(stack, 0, sizeof(stack));
}
// ------------------------------------------------------------------
void GMnu::SetBorder(int type, vattr color) {
bordertype = type;
bordercolor = color;
}
// ------------------------------------------------------------------
void GMnu::SetColor(vattr text, vattr quick, vattr nosel, vattr bar, vattr shadow) {
textcolor = text;
quickcolor = quick;
noselcolor = nosel;
barcolor = bar;
shadowcolor = shadow;
}
// ------------------------------------------------------------------
void GMnu::SetTitle(const char* text, vattr color, int pos) {
title = text;
titlepos = pos;
titlecolor = color;
}
// ------------------------------------------------------------------
void GMnu::SetTitle(const char* text) {
title = text;
}
// ------------------------------------------------------------------
void GMnu::SetDesc(int hdl, int row, int col, vattr color) {
deschdl = hdl;
descrow = row;
desccolumn = col;
desccolor = color;
}
// ------------------------------------------------------------------
void GMnu::SetPos(int row, int col, int width, int height) {
beginrow = row;
begincolumn = col;
beginwidth = width;
beginheight = height;
}
// ------------------------------------------------------------------
void GMnu::SetEsc(int option) {
escape = option;
}
// ------------------------------------------------------------------
void GMnu::SetHelp(int help) {
helpnumber = help;
}
// ------------------------------------------------------------------
void GMnu::SetMask(int mask) {
itemmask = mask;
}
// ------------------------------------------------------------------
void GMnu::SetTag(int tag) {
stack[depth].tag = tag;
}
// ------------------------------------------------------------------
void GMnu::Begin(int type) {
bool was_horz = make_bool(stack[depth].type & M_HORZ);
depth++;
stack[depth].tag = -1;
stack[depth].type = type | M_SAVE;
stack[depth].winrow = (beginrow != -1) ? beginrow : (was_horz ? stack[depth-1].winrow+1 : stack[depth-1].winrow+stack[depth-1].itemrow);
stack[depth].wincolumn = (begincolumn != -1) ? begincolumn : (stack[depth-1].wincolumn+(was_horz?0:1));
stack[depth].itemrow = stack[depth].itemcolumn = 0;
status = wmenubeg_(
stack[depth].winrow,
stack[depth].wincolumn,
beginheight,
beginwidth,
bordertype,
bordercolor,
textcolor,
menuopen,
stack[depth].type
);
wmenutitshad(title, titlepos, titlecolor, shadowcolor);
beginwidth = beginheight = 0;
beginrow = begincolumn = -1;
}
// ------------------------------------------------------------------
void GMnu::End() {
status = wmenuend(stack[depth].tag, stack[depth].type, (stack[depth].type&M_VERT)?255:0, 0, textcolor, quickcolor, noselcolor, barcolor);
depth--;
if((depth >= 0) and (stack[depth].type & M_HORZ))
stack[depth].wincolumn += stack[depth].winwidth;
title = NULL;
}
// ------------------------------------------------------------------
extern int _overtagid;
extern int _finaltagid;
void GMnu::Start() {
int _prev_escape = wsetesc(escape);
wmenuget();
finaltag = _finaltagid;
overtag = _overtagid;
wsetesc(_prev_escape);
}
// ------------------------------------------------------------------
void GMnu::Item(int tag, const char* text) {
Item(tag, text, itemmask, NULL, 0);
}
// ------------------------------------------------------------------
void GMnu::Item(int tag, const char* text, int fmask) {
Item(tag, text, fmask, NULL, 0);
}
// ------------------------------------------------------------------
void GMnu::Item(int tag, const char* text, VfvCP select, int fmask) {
Item(tag, text, fmask, select, 0);
}
// ------------------------------------------------------------------
void GMnu::Item(int tag, const char* text, int fmask, VfvCP select, gkey hotkey) {
if(stack[depth].tag == -1)
stack[depth].tag = tag;
char shortcut = *text;
for(_item_t* p = gwin.cmenu->item; p; p = p->prev) {
if(p->schar == shortcut)
shortcut = NUL;
}
status = wmenuitem(stack[depth].itemrow, stack[depth].itemcolumn, text+1, shortcut, tag, fmask, select, hotkey, helpnumber);
stack[depth].winwidth = strlen(text+1);
if(stack[depth].type & M_HORZ)
stack[depth].itemcolumn += stack[depth].winwidth;
else
stack[depth].itemrow++;
}
// ------------------------------------------------------------------
void GMnu::ItemDesc(const char* text) {
status = wmenuitxt(deschdl, descrow, desccolumn, desccolor, text);
}
// ------------------------------------------------------------------
void GMnu::ItemSep()
{
Item(-1, " ", M_SEPAR, NULL, 0);
}
// ------------------------------------------------------------------
void GMnu::ItemFuncs(VfvCP before, VfvCP after) {
status = wmenuiba(before, after);
}
// ------------------------------------------------------------------
void GMnu::SetNextItem(int tag) {
status = wmenuinext(tag);
}
// ------------------------------------------------------------------
void GMnu::DisableItem(int tag) {
status = wmenuidsab(tag);
}
// ------------------------------------------------------------------
void GMnu::EnableItem(int tag) {
status = wmenuienab(tag);
}
// ------------------------------------------------------------------
GMnuItm* GMnu::FindItem(int tag) {
return wmenuifind(tag);
}
// ------------------------------------------------------------------

231
goldlib/gcui/gwinpckf.cpp Normal file
View File

@ -0,0 +1,231 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// Copyright (C) 1999-2000 Alexander S. Aganichev
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// wpickfile() - Allows user to select a file name.
// ------------------------------------------------------------------
#include <gctype.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <gmemdbg.h>
#include <gfilutil.h>
#include <gwildmat.h>
#include <gwinall.h>
#include <gfilutil.h>
#include <gdirposx.h>
#include <gstrall.h>
// ------------------------------------------------------------------
static bool path_in_title, case_sensitive;
static IfcpCP open_function = NULL;
static char* cwdp;
static char* tcwdp;
static char* namextp;
// ------------------------------------------------------------------
// this function is the compare function for std::sort()
static bool compare(const std::string str1, const std::string str2)
{
// Sort with directories first
bool dir1 = !!strchr(str1.c_str(), GOLD_SLASH_CHR);
bool dir2 = !!strchr(str2.c_str(), GOLD_SLASH_CHR);
if (dir1 && !dir2) return true;
if (!dir1 && dir2) return false;
std::string s1 = dir1 ? str1.substr(0, str1.length()-1) : str1;
std::string s2 = dir2 ? str2.substr(0, str2.length()-1) : str2;
int cmp;
if (case_sensitive)
cmp = strcmp(s1.c_str(), s2.c_str());
else
{
cmp = stricmp(s1.c_str(), s2.c_str());
if (cmp == 0)
cmp = strcmp(s1.c_str(), s2.c_str());
}
return (cmp < 0);
}
// ------------------------------------------------------------------
// this function displays the title on the pick window border
static void disp_title() {
char buf[sizeof(Path)+2];
if(path_in_title or open_function) {
strcpy(buf, " ");
PathCopy(buf+1, cwdp);
strcat(buf, namextp);
strcat(buf, " ");
}
if(path_in_title) {
wtitle(buf, TCENTER, gwin.active->battr);
}
if(open_function) {
(*open_function)(buf);
}
}
// ------------------------------------------------------------------
bool wpickfile(int srow, int scol, int erow, int ecol, int btype, vattr bordattr, vattr winattr, vattr barattr, bool title, std::string &filespec, IfcpCP open, bool casesens)
{
Path cwd, dir, namext, tcwd, path, spec;
cwdp = cwd;
tcwdp = tcwd;
namextp = namext;
// set static variables
open_function = open;
path_in_title = title;
case_sensitive = casesens;
// save current working directory
getcwd(tcwd, GMAXPATH);
// if drive was specified, change to it
char* q = strxcpy(spec, filespec.c_str(), sizeof(Path));
// split up input filespec into its current
// working directory and filename/extension
char* r = strrchr(q, GOLD_SLASH_CHR);
#if defined(__HAVE_DRIVES__)
if(r == NULL)
if(q[1] == ':')
r = q + 1;
#endif
if(r == NULL) {
*dir = NUL;
strcpy(namext, q);
}
else {
strins(" ", ++r, 0);
*r++ = NUL;
strcpy(dir, q);
strcpy(namext, r);
}
bool finished;
int picked;
do
{
// if directory was specified, change to it
if (*dir && gchdir(dir))
{
gchdir(tcwdp);
return false;
}
// get current working directory
getcwd(cwd, GMAXPATH);
strcpy(dir, cwd);
// find all directories plus all files matching input filespec in
// current directory, allocating an array element for each
picked = -1;
gposixdir d(dir);
gstrarray strarr;
const gdirentry *de;
if (d.ok)
{
while((de = d.nextentry()) != NULL)
{
const char* name = NULL;
if (de->is_directory())
{
if(de->name != ".") {
strxmerge(path, sizeof(Path), de->name.c_str(), GOLD_SLASH_STR, NULL);
name = path;
}
}
else if(de->is_file())
{
if(case_sensitive ? gwildmat(de->name.c_str(), namext) : gwildmati(de->name.c_str(), namext))
name = de->name.c_str();
}
if (name) strarr.push_back(name);
}
}
// sort files in array by swapping their pointers
std::sort(strarr.begin(), strarr.end(), compare);
// let user pick file
if (strarr.size())
{
picked = wpickstr(srow, scol, erow, ecol, btype, bordattr, winattr, barattr, strarr, 0, disp_title);
}
if (picked == -1 or !strarr.size())
{
gchdir(tcwdp);
return false;
}
// see if a directory was selected. if so save
// directory name, otherwise build whole path name
const char *slash = strchr(strarr[picked].c_str(), GOLD_SLASH_CHR);
if (slash)
{
finished = false;
strcpy(dir, strarr[picked].c_str());
r = strrchr(dir, GOLD_SLASH_CHR);
if (r) *r = NUL;
}
else {
finished = true;
PathCopy(filespec, cwd);
filespec += strarr[picked].c_str();
}
strarr.clear();
}
while(not finished); // if a directory was selected, go back and do again
gchdir(tcwd); // change back to current drive and directory
return true; // return normally
}
// ------------------------------------------------------------------

728
goldlib/gcui/gwinpcks.cpp Normal file
View File

@ -0,0 +1,728 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// Copyright (C) 1999-2000 Alexander S. Aganichev
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Based on CXL by Mike Smedley.
// ------------------------------------------------------------------
// wpickstr() - Lets user pick from an array of strings.
// ------------------------------------------------------------------
#include <gctype.h>
#include <cstdlib>
#include <cstring>
#include <gkbdcode.h>
#include <gmoubase.h>
#include <gtimall.h>
#include <gwinall.h>
extern char m_title[];
// ------------------------------------------------------------------
int wpickstr_tag = false;
// ------------------------------------------------------------------
// define record that will hold pick window info
struct r_t {
int numelems;
int lastelem;
int curr;
int first;
int last;
int strsperline;
int strsperwin;
int maxstrlen;
int wwidth;
int wheight;
int fillspaces;
int gapspaces;
int xtraspaces;
vattr winattr;
vattr barattr;
int scrollbar;
};
// ------------------------------------------------------------------
// this function will display the mouse
// cursor if mouse cursor mode is on
static void show_mouse_cursor_pck() {
#ifdef GOLD_MOUSE
if(gmou.FreeCursor()) {
gmou.ShowCursor();
gmou.SetCursor(0,0xFFFF,((LGREY_|_LGREY)<<8));
}
#endif
}
// ------------------------------------------------------------------
// this function will hide the mouse
// cursor if mouse cursor mode is on
static void hide_mouse_cursor_pck() {
#ifdef GOLD_MOUSE
if(gmou.FreeCursor())
gmou.HideCursor();
#endif
}
// ------------------------------------------------------------------
// this function updates the current item by either
// displaying or erasing the selection bar on it
static void update_curr( const gstrarray &strarr, r_t* r, int bar)
{
// calculate row and column string will be displayed
// at, then print out the string character-by-character
int crow = (r->curr-r->first)/r->strsperline;
int temp = r->curr-((crow*r->strsperline)+r->first);
int ccol = (temp*r->maxstrlen)+((temp+1)*(r->gapspaces))+r->xtraspaces;
wgotoxy(crow,ccol);
hide_mouse_cursor_pck();
wprintns(crow, ccol, bar ? r->barattr : r->winattr, strarr[r->curr], r->maxstrlen);
show_mouse_cursor_pck();
}
// ------------------------------------------------------------------
static void update_line(const gstrarray &strarr, r_t* r, int wrow, int upcurr)
{
int nomore = false;
int ccol = r->gapspaces + r->xtraspaces;
int celem = (wrow*r->strsperline) + r->first;
if(celem >= r->numelems)
nomore = true;
for(int j=0; j<r->strsperline; j++) {
int ccolbeg = ccol;
wprintns(wrow, ccolbeg, (upcurr and r->curr==celem) ? r->barattr : r->winattr, nomore ? "" : strarr[celem], r->maxstrlen);
ccol += r->maxstrlen;
if(++celem >= r->numelems)
nomore = true;
ccol += r->gapspaces;
}
}
// ------------------------------------------------------------------
// this function will update all items in the window
static void update_window(const gstrarray &strarr, r_t* r)
{
hide_mouse_cursor_pck();
for(int crow=0; crow<r->wheight; crow++)
update_line(strarr, r, crow, 1);
show_mouse_cursor_pck();
}
// ------------------------------------------------------------------
// this function will find the element number of the
// first element on the same line as the given element
static int e_begline(r_t* r, int elem) {
return (elem/r->strsperline) * r->strsperline;
}
// ------------------------------------------------------------------
// this function will find the first element in a
// window, using a given last element as input
static int e_begwin(r_t* r, int lelem) {
int beg = e_begline(r,lelem) + r->strsperline - r->strsperwin;
if(beg < 0)
beg = 0;
return beg;
}
// ------------------------------------------------------------------
// this function will find the element number of the
// last element on the same line as the given element
static int e_endline(r_t* r, int elem) {
int end = (((elem/r->strsperline)+1)*r->strsperline)-1;
if(end>=r->numelems)
end = r->lastelem;
return end;
}
// ------------------------------------------------------------------
// this function will find the last element in a
// window, using a given first element as input
static int e_endwin(r_t* r, int felem) {
int end = felem + r->strsperwin - 1;
if(end > (r->lastelem))
end = r->lastelem;
return end;
}
// ------------------------------------------------------------------
static void goto_item(r_t* r, const gstrarray &strarr, int elem)
{
if(elem<0 or elem>r->lastelem)
elem = 0;
int outside = (elem<r->first or elem>r->last) ? YES : NO;
if(outside == NO)
update_curr(strarr,r,0);
r->curr = elem;
if(outside) {
r->first = e_begwin(r,r->last = e_endwin(r,e_begline(r,r->curr)));
update_window(strarr,r);
}
else {
update_curr(strarr,r,1);
}
}
// ------------------------------------------------------------------
// this function determines if the mouse cursor is on a item
#ifdef GOLD_MOUSE
static int mouse_on_item(r_t* r, int mcrow, int mccol) {
int found = -1;
int srow = gwin.active->srow;
int scol = gwin.active->scol;
int border = gwin.active->border;
for(int i=r->first; i<=r->last; i++) {
if(mcrow==(srow+border+((i-r->first)/r->strsperline))) {
int start = scol+border+r->xtraspaces+r->gapspaces+((i%r->strsperline)*(r->maxstrlen+r->gapspaces));
int end = start+r->maxstrlen-1;
if(mccol>=start and mccol<=end) {
found = i;
break;
}
}
}
if(found==-1 and r->scrollbar and mccol==gwin.active->ecol) {
if(mcrow==srow+1)
found=-2;
else {
if(mcrow==gwin.active->erow-1)
found=-3;
}
}
return found;
}
#endif
// ------------------------------------------------------------------
static void page_down(const gstrarray &strarr, r_t* r)
{
if(r->curr != r->last) {
r->curr = r->last;
update_window(strarr, r);
}
else if(r->last != (r->lastelem)) {
int i = r->curr-r->first;
r->last = e_endwin(r,r->last+1);
r->first = e_begwin(r, r->last);
if((r->curr = r->first+i) > (r->lastelem))
r->curr -= r->strsperline;
update_window(strarr, r);
}
}
// ------------------------------------------------------------------
static void page_up(const gstrarray &strarr, r_t* r)
{
if(r->curr != r->first) {
r->curr = r->first;
update_window(strarr, r);
}
else if(r->first) {
int i = r->curr-r->first;
r->first = e_begwin(r,r->first-1);
r->last = e_endwin(r, r->first);
r->curr = r->first+i;
update_window(strarr,r);
}
}
// ------------------------------------------------------------------
static void scroll_down(const gstrarray &strarr, r_t* r, int upcurr)
{
if(r->first) {
hide_mouse_cursor_pck();
if(upcurr)
update_curr(strarr,r,0);
r->first -= r->strsperline;
r->last = e_endline(r,r->last-r->strsperline);
if(upcurr>1)
r->curr -= r->strsperline;
if(r->first != e_begline(r,r->last))
wscroll(1,SDOWN);
update_line(strarr, r, 0, (upcurr>2) ? 0 : upcurr);
show_mouse_cursor_pck();
}
}
// ------------------------------------------------------------------
static void scroll_up(const gstrarray &strarr, r_t* r, int upcurr)
{
if(r->last!=(r->lastelem)) {
hide_mouse_cursor_pck();
if(upcurr)
update_curr(strarr,r,0);
r->first+=r->strsperline;
r->last=e_endline(r,r->last+1);
if(upcurr>1)
if((r->curr+r->strsperline)<=r->last)
r->curr+=r->strsperline;
if(r->first!=e_begline(r,r->last))
wscroll(1,SUP);
update_line(strarr,r,r->wheight-1,(upcurr>2)?0:upcurr);
show_mouse_cursor_pck();
}
}
// ------------------------------------------------------------------
// this function reads the mouse for input
static gkey read_mouse(const gstrarray & /*strarr*/, r_t* /*r*/)
{
#ifdef GOLD_MOUSE
// if free-floating mouse cursor support is on
if(gmou.FreeCursor()) {
// clear mouse button queue
gmou.ClearEvents();
// loop until a key is pressed
while(!kbxhit() and gkbd.kbuf==NULL) {
// call the keyboard loop function, if defined
//if(gkbd.kbloop!=NULL)
//(*gkbd.kbloop)();
// see if the right button (Esc) was pressed
gmou.GetRightRelease();
if(gmou.Count())
return Key_Esc;
// see where mouse cursor is at - if it is on a scroll bar
// or menu item, and the left button is pressed, then scroll
// menu or select item
gmou.GetStatus();
int i = mouse_on_item(r,gmou.Row(),gmou.Column());
switch(i) {
case -1:
gmou.ClearEvents();
break;
case -2:
if(gmou.LeftButton()) {
scroll_down(strarr,r,3);
if(gvid->isbios())
usleep(50);
gmou.ClearEvents();
}
break;
case -3:
if(gmou.LeftButton()) {
scroll_up(strarr,r,3);
if(gvid->isbios())
usleep(50);
gmou.ClearEvents();
}
break;
default:
gmou.GetLeftRelease();
if(gmou.Count()) {
r->curr = i;
return Key_Ent;
}
}
}
}
#endif
// return zero - it means a key was pressed
return 0;
}
// ------------------------------------------------------------------
int wpickstr(int srow, int scol, int erow, int ecol, int btype, vattr bordattr, vattr winattr, vattr barattr, gstrarray &strarr, int initelem, VfvCP open)
{
int outside;
gkey xch;
char ch;
r_t r;
int quickpos = (strarr[0][0] == ' ') ? 1 : 0;
// go through input array and determine the longest
// string, and count the number of elements in the array
size_t maxlen = strlen(m_title);
gstrarray::const_iterator it = strarr.begin();
gstrarray::const_iterator end = strarr.end();
for (; it != end; it++)
{
size_t len;
if ((len = it->length()) > maxlen)
{
maxlen = len;
}
}
r.maxstrlen = maxlen;
r.numelems = strarr.size();
r.lastelem = r.numelems - 1;
r.winattr = winattr;
r.barattr = barattr;
// see if window is to have a border
int border = (btype==5) ? NO : YES;
// if ecol == -1 then adjust it to conform to length of longest string
if(ecol==-1)
ecol = scol+border+r.maxstrlen+border-1;
// calculate window area width and height
r.wwidth = (ecol-border)-(scol+border)+1;
r.wheight = (erow-border)-(srow+border)+1;
// make sure longest string can fit in window
if(r.maxstrlen > r.wwidth)
r.maxstrlen = r.wwidth;
// open window which strings will reside in
hide_mouse_cursor_pck();
if(!wopen(srow,scol,erow,ecol,btype,bordattr,winattr,bordattr))
return -1;
// if mouse cursor mode is on and window has a border,
// display scroll indicator arrows on right window border
#ifdef GOLD_MOUSE
if(gmou.FreeCursor() and (btype!=5) and ((srow+2) < erow)) {
vputc(srow+1,ecol,bordattr,(char) 24);
vputc(erow-1,ecol,bordattr,(char) 25);
r.scrollbar=true;
}
else {
#endif
r.scrollbar=false;
#ifdef GOLD_MOUSE
}
#endif
show_mouse_cursor_pck();
// if an open function has been specified, then call it
if(open!=NULL)
open();
// if mouse cursor mode is on, then turn on mouse cursor
show_mouse_cursor_pck();
// calculate how many strings can fit into 1 window line, number of
// filler spaces needed per window line, number of spaces per gap in
// between strings, number of extra spaces to add to first gap, and
// number of strings that can fit inside the window
r.strsperline = (r.wwidth-2)/(r.maxstrlen+2);
if(!r.strsperline)
r.strsperline++;
r.fillspaces = r.wwidth-(r.strsperline*r.maxstrlen);
r.gapspaces = r.fillspaces/(r.strsperline+1);
r.xtraspaces = (r.fillspaces%(r.strsperline+1))/2;
r.strsperwin = r.strsperline*r.wheight;
// initialize first, last, and current elements
r.curr = r.first = 0;
r.last = (r.numelems<r.strsperwin) ? (r.lastelem) : (r.strsperwin-1);
// move selection bar to specified initial element
goto_item(&r,strarr,initelem);
// fill window with as many strings as can fit and display bar
update_window(strarr,&r);
// loop until an element is selected or Escape is pressed
for(;;) {
// get keystroke/mouse movement
gkbd.inmenu = true;
xch = read_mouse(strarr,&r);
if(!xch) {
xch = getxch();
}
gkbd.inmenu=false;
// test keystroke for a special key
switch(xch) {
case Key_Space:
if (wpickstr_tag)
{
char p = strarr[r.curr][0];
switch (p)
{
case ' ':
strarr[r.curr][0] = (char)wpickstr_tag;
update_curr(strarr, &r, 1);
break;
default:
strarr[r.curr][0] = ' ';
update_curr(strarr, &r, 1);
}
kbput(Key_Dwn);
}
break;
case Key_Ins:
case Key_PlsG:
case Key_S_Equ:
if(wpickstr_tag) {
strarr[r.curr][0] = (char)wpickstr_tag;
update_curr(strarr,&r,1);
kbput(Key_Dwn);
}
break;
case Key_Del:
case Key_Min:
case Key_MinG:
if(wpickstr_tag) {
strarr[r.curr][0] = ' ';
update_curr(strarr,&r,1);
kbput(Key_Dwn);
}
break;
case Key_StrG:
case Key_S_8:
if (wpickstr_tag)
{
for (size_t i = 0; i < r.numelems; i++)
{
strarr[i][0] = (char)wpickstr_tag;
}
update_window(strarr, &r);
}
break;
case Key_Sls:
if (wpickstr_tag)
{
for (size_t i = 0; i < r.numelems; i++)
{
strarr[i][0] = ' ';
}
update_window(strarr, &r);
}
break;
case Key_Esc:
// close window and set error to Escape press code
if(gwin.esc) {
hide_mouse_cursor_pck();
wclose();
gwin.werrno=W_ESCPRESS;
return -1;
}
break;
case Key_Ent:
// close window and return subscript of selected string
hide_mouse_cursor_pck();
wclose();
gwin.werrno=W_NOERROR;
return(r.curr);
case Key_Lft:
// move to the item to the left, scrolling if necessary
if(r.curr) {
update_curr(strarr,&r,0);
if(r.curr==r.first)
scroll_down(strarr,&r,0);
r.curr--;
update_curr(strarr,&r,1);
}
break;
case Key_Rgt:
// move to the item to the right, scrolling if necessary
if(r.curr!=r.lastelem) {
update_curr(strarr,&r,0);
if(r.curr==r.last)
scroll_up(strarr,&r,0);
r.curr++;
update_curr(strarr,&r,1);
}
break;
case Key_Up:
// move to the item up, scrolling if necessary
if((r.curr-r.strsperline)<r.first)
scroll_down(strarr,&r,2);
else {
update_curr(strarr,&r,0);
r.curr-=r.strsperline;
update_curr(strarr,&r,1);
}
break;
case Key_Dwn:
// move to the item down, scrolling if necessary
if((r.curr+r.strsperline)>r.last)
scroll_up(strarr,&r,((r.curr+r.strsperline)>r.lastelem) ? 0 : 2);
else {
update_curr(strarr,&r,0);
r.curr+=r.strsperline;
update_curr(strarr,&r,1);
}
break;
case Key_PgUp:
// move up 1 page. adjust position if at 1st element
page_up(strarr,&r);
break;
case Key_PgDn:
// move down 1 page. adjust position if at last element
page_down(strarr,&r);
break;
case Key_Home:
// set position to 1st element
if(r.curr) {
if((outside=r.first)==NO)
update_curr(strarr,&r,0);
r.first=r.curr=0;
if(outside) {
r.last=e_endwin(&r,r.first);
update_window(strarr,&r);
}
else {
update_curr(strarr,&r,1);
}
}
break;
case Key_End:
// set position to last element
if(r.curr!=r.lastelem) {
if((outside=(r.last<(r.lastelem))?YES:NO)==NO)
update_curr(strarr,&r,0);
r.last=r.curr=r.lastelem;
if(outside) {
r.first=e_begwin(&r,r.last);
update_window(strarr,&r);
}
else {
update_curr(strarr,&r,1);
}
}
break;
default:
// if not an extended keypress, then search from current
// position for the item that begins with the same ASCII
// character as the keypress. If not found after current
// position, search from the beginning for a match
ch = (char)g_toupper(char(xch & 0xFF));
if (!ch) break;
size_t i;
for (i = r.curr + 1; i < r.numelems; i++)
{
if (ch == g_toupper(strarr[i][quickpos]))
break;
}
if (i == r.numelems)
{
for (i = 0; i < r.curr; i++)
{
if (ch == g_toupper(strarr[i][quickpos]))
break;
}
if (i == r.curr) continue;
}
// a matching ASCII character was found. set position
// to matching element, adjusting window if necessary
goto_item(&r, strarr, i);
}
}
} /* wpickstr() */
// ------------------------------------------------------------------

528
goldlib/gcui/gwinpick.cpp Normal file
View File

@ -0,0 +1,528 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// Copyright (C) 1999-2000 Alexander S. Aganichev
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Class gwinpick - Pick engine.
// ------------------------------------------------------------------
#include <gkbdcode.h>
#include <gmoubase.h>
#include <gtimall.h>
#include <gutlmisc.h>
#include <gwinall.h>
#include <gwinhelp.h>
#include <gwinpick.h>
// ------------------------------------------------------------------
gwinpick::gwinpick() {
// memset(this, 0, sizeof(gwinpick)); WHAT!?!?! ARE YOU NUTS?
key = 0;
keyok = false;
ypos = xpos = ylen = xlen = 0;
btype = 0;
battr = wattr = tattr = sattr = hattr = loattr = sbattr = BLACK_|_BLACK;
title = NULL;
helpcat = 0;
maximum_index = minimum_index = maximum_position = index = position = 0;
aborted = listwrap = false;
direction = 0;
replylinkfloat = 0;
}
// ------------------------------------------------------------------
void gwinpick::cursor_up() {
bool done;
do {
if(index > minimum_index) {
display_line();
if(position)
position--;
else
scroll(SDOWN);
index--;
if((done = is_selectable(index))==true)
update_cursor();
}
else {
if(listwrap)
cursor_last();
else if(not is_selectable(index))
cursor_down();
done = true;
}
} while(not done);
direction = -1;
}
// ------------------------------------------------------------------
void gwinpick::cursor_down() {
bool done;
do {
if(index < maximum_index) {
display_line();
index++;
if(position < maximum_position)
position++;
else
scroll(SUP);
if((done = is_selectable(index))!=false)
update_cursor();
}
else {
if(listwrap)
cursor_first();
else if(not is_selectable(index))
cursor_up();
done = true;
}
} while(not done);
direction = 1;
}
// ------------------------------------------------------------------
void gwinpick::cursor_pageup() {
uint i = index - position;
while(not is_selectable(i)) i++;
uint min = i + position - index;
if(position > min) {
display_line();
index = i;
position = min;
update_cursor();
}
else if(index > min) {
i = maximum_position - min + position;
index -= (index >= i) ? i : index;
position = 0;
display_page();
if(not is_selectable(index))
cursor_down();
}
direction = -1;
}
// ------------------------------------------------------------------
void gwinpick::cursor_pagedown() {
uint max_index = index + maximum_position - position;
if(max_index > maximum_index) max_index = maximum_index;
while(not is_selectable(max_index)) --max_index;
uint max_position = max_index - index + position;
if(position < max_position) {
if(index == max_index) {
if(maximum_position < maximum_index) {
position = maximum_position;
index = maximum_index;
display_page();
update_cursor();
}
}
else if(max_index >= max_position) {
display_line();
position = max_position;
index = max_index;
update_cursor();
}
else if(position != maximum_position) {
display_line();
index += maximum_position-position;
position = maximum_position;
update_cursor();
}
}
else if(index < maximum_index) {
if(index+maximum_position+(maximum_position - max_position)> maximum_index) {
position = maximum_index - index;
index = maximum_index;
}
else {
index += maximum_position + (maximum_position - max_position);
position = maximum_position;
}
display_page();
}
if(not is_selectable(index))
cursor_up();
direction = 1;
}
// ------------------------------------------------------------------
void gwinpick::cursor_first() {
uint min_select = minimum_index;
while(not is_selectable(min_select))
min_select++;
if(index > min_select) {
if(index <= position) {
display_line();
index = position = min_select;
update_cursor();
}
else {
index = position = min_select;
display_page();
}
}
direction = -1;
}
// ------------------------------------------------------------------
void gwinpick::cursor_last() {
uint max_select = maximum_index;
while(not is_selectable(max_select))
max_select--;
if(index < max_select) {
if(index + (maximum_position-position) >= maximum_index) {
display_line();
position += max_select - index;
index = max_select;
update_cursor();
}
else {
position = (maximum_index-index) < maximum_position ? maximum_index-index : maximum_position;
position -= maximum_index - max_select;
index = max_select;
display_page();
}
}
else if(position < maximum_position) {
if(maximum_position < maximum_index) {
position = maximum_position + max_select - maximum_index;
index = max_select;
display_page();
}
}
direction = 1;
}
// ------------------------------------------------------------------
void gwinpick::cursor_scroll_up() {
uint oldidx = index;
do {
if(index - position)
index--;
else
while((not is_selectable(index)) and (index < maximum_index))
index++;
} while(not is_selectable(index));
if(index != oldidx)
display_page();
direction = -1;
}
// ------------------------------------------------------------------
void gwinpick::cursor_scroll_down() {
uint oldidx = index;
if(index != maximum_index) {
do {
if(index < maximum_index)
index++;
else
while((not is_selectable(--index)) and (index > minimum_index))
;
} while(not is_selectable(index));
}
if(index!=oldidx)
display_page();
direction = 1;
}
// ------------------------------------------------------------------
void gwinpick::display_line(bool bar) {
print_line(index, position, bar);
}
// ------------------------------------------------------------------
void gwinpick::display_page() {
if(index > position)
index -= position;
else
index = 0;
register uint m = maximum_index-index;
uint n;
if (replylinkfloat)
{
if (h_offset == new_hoffset)
{
for (n=0; n<=maximum_position and n<=m; n++)
if (position == n)
print_line(index+n, n, true);
}
h_offset = new_hoffset;
}
for(n=0; n<=maximum_position and n<=m; n++)
print_line(index+n, n, (position == n));
if(n < ylen)
wputx(n, 0, battr|ACSET, _box_table(btype,1), xlen);
for(++n; n<ylen; n++)
wputx(n, 0, wattr, (vchar)' ', xlen);
index += position;
wgotoxy(position, 0);
}
// ------------------------------------------------------------------
void gwinpick::open() { update(); }
void gwinpick::close() {}
void gwinpick::precursor() {}
void gwinpick::do_delayed() {}
void gwinpick::scroll(int direction) { wscroll(1, direction); }
bool gwinpick::handle_key() { return false; }
bool gwinpick::is_selectable(uint) { return true; }
// ------------------------------------------------------------------
bool gwinpick::default_handle_key() {
keyok = true;
switch(key) {
case Key_Up: precursor(); cursor_up(); break;
case Key_Dwn: precursor(); cursor_down(); break;
case Key_PgUp: precursor(); cursor_pageup(); break;
case Key_PgDn: precursor(); cursor_pagedown(); break;
case Key_Home: precursor(); cursor_first(); break;
case Key_End: precursor(); cursor_last(); break;
case Key_C_Up: precursor(); cursor_scroll_up(); break;
case Key_C_Dwn: precursor(); cursor_scroll_down(); break;
default:
keyok = handle_key();
}
return keyok;
}
// ------------------------------------------------------------------
void gwinpick::update_cursor() {
wgotoxy(position, 0);
display_bar();
// do_delayed();
}
// ------------------------------------------------------------------
void gwinpick::center(int listmode) {
if(maximum_index <= maximum_position) {
position = index;
update();
return;
}
uint botroom = maximum_index - index;
switch(listmode) {
case LIST_TOP:
position = (botroom > maximum_position) ? 0 : (maximum_position - botroom);
break;
case LIST_NEARTOP:
{
uint room;
uint toproom = index;
if(toproom > (maximum_position/4)) {
if(botroom > (maximum_position/4))
room = maximum_position/4;
else if(botroom)
room = maximum_position - botroom;
else
room = maximum_position;
}
else
room = toproom;
position = room;
}
break;
case LIST_MIDDLE:
{
uint room;
uint toproom = index;
if(toproom > (maximum_position/2)) {
if(botroom > (maximum_position/2))
room = maximum_position/2;
else if(botroom)
room = maximum_position - botroom;
else
room = maximum_position;
}
else
room = toproom;
position = room;
}
break;
case LIST_NEARBOTTOM:
{
uint room;
uint toproom = index;
if(toproom > 3*(maximum_position/4)) {
if(botroom > 3*(maximum_position/4))
room = 3*(maximum_position/4);
else if(botroom)
room = maximum_position - botroom;
else
room = maximum_position;
}
else
room = toproom;
position = room;
}
break;
case LIST_BOTTOM:
position = maximum_position;
break;
}
update();
}
// ------------------------------------------------------------------
int gwinpick::run_picker() {
#ifdef GOLD_MOUSE
gmou.HideCursor();
#endif
// Open and initialize
open();
if(helpcat)
whelppcat(helpcat);
if(not is_selectable(index))
cursor_down();
do {
do_delayed();
#ifdef GOLD_MOUSE
gmou.ShowCursor();
#endif
keyok = true;
do {
key = getxchtick();
if(key == Key_Tick)
handle_key();
} while(key == Key_Tick);
#ifdef GOLD_MOUSE
gmou.HideCursor();
#endif
keyok = default_handle_key();
if (replylinkfloat && (h_offset != new_hoffset))
display_page();
} while(keyok);
#ifdef GOLD_MOUSE
gmou.HideCursor();
#endif
// Close and clean
if(helpcat)
whelpop();
close();
#ifdef GOLD_MOUSE
gmou.ShowCursor();
#endif
return 0;
}
// ------------------------------------------------------------------

130
goldlib/gcui/gwinpick.h Normal file
View File

@ -0,0 +1,130 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Pick engine (declarations).
// ------------------------------------------------------------------
#ifndef __gwinpick_h
#define __gwinpick_h
// ------------------------------------------------------------------
#include <gkbdbase.h>
// ------------------------------------------------------------------
// Constants
const int PICK_DISP = 0;
const int PICK_BAR = 1;
const int LIST_BOTTOM = -2;
const int LIST_NEARBOTTOM = -1;
const int LIST_MIDDLE = 0;
const int LIST_NEARTOP = 1;
const int LIST_TOP = 2;
// ------------------------------------------------------------------
class gwinpick {
private:
protected:
gkey key;
bool keyok;
uint new_hoffset;
uint h_offset;
bool replylinkfloat; // in derived classes set this with CFG->replylinkfloat
// before call display_page() and run_picker()
void cursor_up();
void cursor_down();
void cursor_pageup();
void cursor_pagedown();
void cursor_first();
void cursor_last();
void cursor_scroll_up();
void cursor_scroll_down();
void update_cursor();
void display_line(bool bar=false);
void display_page();
bool default_handle_key();
inline void update() { display_page(); };
public:
uint ypos; // Window Starting Row
uint xpos; // Window Starting Column
uint ylen; // Window Height
uint xlen; // Window Width
int btype; // Window Border Type
vattr battr; // Window Border Color
vattr wattr; // Window Color
vattr tattr; // Window Title Color
vattr sattr; // Window Selection Bar Color
vattr hattr; // Window Highlight Color
vattr loattr; // Window LoAttr Color
vattr sbattr; // Window Scrollbar Color
const char* title; // Window Title
int helpcat; // Window Help Category
uint maximum_index; // List Entries - 1
uint minimum_index; // Minimum index in the list
uint maximum_position; // Display Pos
uint index; // List Index
uint position; // Display Pos
bool aborted; // True if aborted
bool listwrap; // True if wrap-around is supported
int direction; // 1 if next, -1 if previous
virtual void open(); // Called after window is opened
virtual void close(); // Called after window is closed
virtual void precursor(); // Called before any cursor movement
virtual void do_delayed(); // Called after a delay
virtual void print_line(uint idx, uint pos, bool isbar) = 0;
virtual void scroll(int where); // Scroll page
virtual bool handle_key(); // Handles keypress
virtual bool is_selectable(uint idx); // returns true if selectable
void display_bar() { display_line(true); }
void center(int listmode);
int run_picker();
gwinpick();
virtual ~gwinpick() { };
};
// ------------------------------------------------------------------
#endif
// ------------------------------------------------------------------

236
goldlib/gcui/gwinput.h Normal file
View File

@ -0,0 +1,236 @@
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// Copyright (C) 1999-2000 Alexander S. Aganichev
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// GCUI: Golded+ Character-oriented User Interface.
// Class gwinput: Input form and field editing (declarations).
// ------------------------------------------------------------------
#ifndef __gwinput_h
#define __gwinput_h
// ------------------------------------------------------------------
#include <gwindow.h>
// ------------------------------------------------------------------
class gwinput {
public:
class field {
public:
gwinput* form;
int pos;
int max_pos;
vattr attr;
bool fill_acs;
vchar fill;
int entry;
char* buf;
int buf_left_pos;
int buf_end_pos;
int buf_pos;
int buf_len;
std::string& destination;
int id;
int row;
int column;
int max_column;
int conversion;
int entry_mode;
field* prev;
field* next;
field(gwinput* iform, int idnum, int wrow, int wcol, int field_width, std::string& dest, int dest_size, int cvt, int mode);
~field();
bool visible();
void move_left();
void move_right();
bool left();
bool right();
bool left_word();
bool right_word();
bool delete_left();
bool delete_char();
bool delete_word(bool left);
bool insert_char(char ch);
bool overwrite_char(char ch);
bool home();
bool end();
void update();
void activate();
void deactivate();
void restore();
void commit();
void convert();
bool adjust_mode();
void conditional();
void move_cursor();
void draw(int from_pos=0);
void clear_field();
void clipboard_paste();
void clipboard_copy();
};
field* first_field;
field* current;
enum {
entry_new,
entry_update,
entry_conditional,
entry_noedit
};
enum {
cvt_none,
cvt_lowercase,
cvt_uppercase,
cvt_mixedcase
};
vattr idle_attr;
vattr active_attr;
vattr edit_attr;
bool fill_acs;
vchar idle_fill;
vchar active_fill;
vchar edit_fill;
int insert_mode;
int done;
int dropped;
int start_id;
bool cursor_was_hidden;
gwindow &window;
gwinput(gwindow &w);
virtual ~gwinput();
void setup(vattr i_attr, vattr a_attr, vattr e_attr, vchar fill, bool fill_acs);
void add_field(int idnum, int wrow, int wcol, int field_width, std::string& dest, int dest_size, int cvt=gwinput::cvt_none, int mode=gwinput::entry_conditional);
bool first(int id=0);
bool next();
bool previous();
bool last();
bool first_visible();
bool next_visible();
bool previous_visible();
bool last_visible();
bool move_to(int wrow, int wcol);
field* field_at(int wrow, int wcol);
field* get_field(int id);
void draw_all();
void reload_all();
void show_cursor();
void drop_form();
void form_complete();
void field_complete();
void go_next_field();
void go_previous_field();
void go_up();
void go_down();
void go_left();
void go_right();
void delete_left();
void delete_char();
void go_field_begin();
void go_field_end();
void go_form_begin();
void go_form_end();
void toggle_insert();
void restore_field();
void delete_left_word();
void delete_right_word();
void go_left_word();
void go_right_word();
void enter_char(char ch);
void prepare_form();
void finish_form();
void clear_field();
void clipboard_cut();
void clipboard_paste();
void clipboard_copy();
bool handle_key(gkey key);
// These are supposed to be overridden by the inheriting class
virtual bool handle_other_keys(gkey& key);
virtual bool validate();
virtual void before();
virtual void after();
};
// ------------------------------------------------------------------
class gwinput2 : public gwinput {
public:
gwinput2(gwindow &w) : gwinput(w) { }
bool run(int helpcat);
};
// ------------------------------------------------------------------
#endif
// ------------------------------------------------------------------

1221
goldlib/gcui/gwinput2.cpp Normal file

File diff suppressed because it is too large Load Diff