home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
drdobbs
/
1991
/
09
/
dflat.991
< prev
next >
Wrap
Text File
|
1991-08-21
|
34KB
|
898 lines
_C PROGRAMMING COLUMN_
by Al Stevens
[LISTING ONE]
/* ------------ menu.h ------------- */
#ifndef MENU_H
#define MENU_H
/* ----------- popdown menu selection structure
one for each selection on a popdown menu --------- */
struct PopDown {
char *SelectionTitle; /* title of the selection */
int ActionId; /* the command executed */
int Accelerator; /* the accelerator key */
int Attrib; /* INACTIVE | CHECKED | TOGGLE */
char *help; /* Help mnemonic */
};
/* ----------- popdown menu structure
one for each popdown menu on the menu bar -------- */
typedef struct Menu {
char *Title; /* title on the menu bar */
void (*PrepMenu)(void *, struct Menu *); /* function */
struct PopDown Selections[23]; /* up to 23 selections */
int Selection; /* most recent selection */
} MENU;
/* --------- macros to define a menu bar with
popdowns and selections ------------- */
#define SEPCHAR "\xc4"
#define DEFMENU(m) MENU m[]= {
#define POPDOWN(ttl,func) {ttl,func,{
#define SELECTION(stxt,acc,id,attr) {stxt,acc,id,attr,#acc},
#define SEPARATOR {SEPCHAR},
#define ENDPOPDOWN {NULL},0}},
#define ENDMENU {NULL} };
/* -------- menu selection attributes -------- */
#define INACTIVE 1
#define CHECKED 2
#define TOGGLE 4
/* --------- the standard menus ---------- */
extern MENU MainMenu[];
extern MENU SystemMenu[];
extern MENU *ActiveMenu;
int MenuHeight(struct PopDown *);
int MenuWidth(struct PopDown *);
#endif
[LISTING TWO]
/* -------------- menus.c ------------- */
#include <stdio.h>
#include "dflat.h"
/* --------------------- the main menu --------------------- */
DEFMENU(MainMenu)
/* --------------- the File popdown menu ----------------*/
POPDOWN( "~File", PrepFileMenu )
SELECTION( "~New", ID_NEW, 0, 0 )
#ifdef INCLUDE_DIALOG_BOXES
SELECTION( "~Open...", ID_OPEN, 0, 0 )
SEPARATOR
#endif
SELECTION( "~Save", ID_SAVE, ALT_S, INACTIVE)
#ifdef INCLUDE_DIALOG_BOXES
SELECTION( "Save ~as...", ID_SAVEAS, 0, INACTIVE)
#endif
SEPARATOR
SELECTION( "~Print", ID_PRINT, 0, INACTIVE)
SEPARATOR
SELECTION( "~DOS", ID_DOS, 0, 0 )
SELECTION( "E~xit", ID_EXIT, ALT_X, 0 )
ENDPOPDOWN
/* --------------- the Edit popdown menu ----------------*/
POPDOWN( "~Edit", PrepEditMenu )
SELECTION( "~Undo", ID_UNDO, ALT_BS, INACTIVE)
#ifdef INCLUDE_CLIPBOARD
SEPARATOR
SELECTION( "Cu~t", ID_CUT, SHIFT_DEL, INACTIVE)
SELECTION( "~Copy", ID_COPY, CTRL_INS, INACTIVE)
SELECTION( "~Paste", ID_PASTE, SHIFT_INS, INACTIVE)
SEPARATOR
SELECTION( "Cl~ear", ID_CLEAR, 0, INACTIVE)
#endif
SELECTION( "~Delete", ID_DELETETEXT, DEL, INACTIVE)
SEPARATOR
SELECTION( "Pa~ragraph", ID_PARAGRAPH, ALT_P,INACTIVE)
ENDPOPDOWN
/* ------------- the Options popdown menu ---------------*/
POPDOWN( "~Options", NULL )
SELECTION( "~Insert", ID_INSERT, INS, TOGGLE)
SELECTION( "~Word wrap", ID_WRAP, 0, TOGGLE)
#ifdef INCLUDE_DIALOG_BOXES
SELECTION( "~Tabs...", ID_TABS, 0, 0 )
SEPARATOR
SELECTION( "~Display...", ID_DISPLAY, 0, 0 )
#ifdef INCLUDE_LOGGING
SEPARATOR
SELECTION( "~Log Messages ",ID_LOG, 0, 0 )
#endif
#endif
SEPARATOR
SELECTION( "~Save Options", ID_SAVEOPTIONS, 0, 0 )
ENDPOPDOWN
#ifdef INCLUDE_MULTIDOCS
/* --------------- the Window popdown menu --------------*/
POPDOWN( "~Window", PrepWindowMenu )
SELECTION( NULL, ID_CLOSEALL, 0, 0)
SEPARATOR
SELECTION( NULL, ID_WINDOW, 0, 0 )
SELECTION( NULL, ID_WINDOW, 0, 0 )
SELECTION( NULL, ID_WINDOW, 0, 0 )
SELECTION( NULL, ID_WINDOW, 0, 0 )
SELECTION( NULL, ID_WINDOW, 0, 0 )
SELECTION( NULL, ID_WINDOW, 0, 0 )
SELECTION( NULL, ID_WINDOW, 0, 0 )
SELECTION( NULL, ID_WINDOW, 0, 0 )
SELECTION( NULL, ID_WINDOW, 0, 0 )
SELECTION( NULL, ID_WINDOW, 0, 0 )
SELECTION( NULL, ID_WINDOW, 0, 0 )
SELECTION( "~More Windows...", ID_WINDOW, 0, 0)
SELECTION( NULL, ID_WINDOW, 0, 0 )
ENDPOPDOWN
#endif
#ifdef INCLUDE_HELP
/* --------------- the Help popdown menu ----------------*/
POPDOWN( "~Help", NULL )
SELECTION( "~Help for help...", ID_HELPHELP, 0, 0 )
SELECTION( "~Extended help...", ID_EXTHELP, 0, 0 )
SELECTION( "~Keys help...", ID_KEYSHELP, 0, 0 )
SELECTION( "Help ~index...", ID_HELPINDEX, 0, 0 )
SEPARATOR
SELECTION( "~About...", ID_ABOUT, 0, 0 )
#ifdef INCLUDE_RELOADHELP
SEPARATOR
SELECTION( "~Reload Help Database",ID_LOADHELP,0, 0 )
#endif
ENDPOPDOWN
#endif
ENDMENU
#ifdef INCLUDE_SYSTEM_MENUS
/* ------------- the System Menu --------------------- */
DEFMENU(SystemMenu)
POPDOWN("System Menu", NULL)
SELECTION("~Restore", ID_SYSRESTORE, 0, 0 )
SELECTION("~Move", ID_SYSMOVE, 0, 0 )
SELECTION("~Size", ID_SYSSIZE, 0, 0 )
SELECTION("Mi~nimize", ID_SYSMINIMIZE, 0, 0 )
SELECTION("Ma~ximize", ID_SYSMAXIMIZE, 0, 0 )
SEPARATOR
SELECTION("~Close", ID_SYSCLOSE, CTRL_F4, 0 )
ENDPOPDOWN
ENDMENU
#endif
[LISTING THREE]
/* ----------------- dialbox.h ---------------- */
#ifndef DIALOG_H
#define DIALOG_H
#include <stdio.h>
#define MAXCONTROLS 25
#define OFF FALSE
#define ON TRUE
/* -------- dialog box and control window structure ------- */
typedef struct {
char *title; /* window title */
int x, y; /* relative coordinates */
int h, w; /* size */
} DIALOGWINDOW;
/* ------ one of these for each control window ------- */
typedef struct {
DIALOGWINDOW dwnd;
int class; /* LISTBOX, BUTTON, etc */
char *itext; /* initialized text */
char *vtext; /* variable text */
int command; /* command code */
char *help; /* help mnemonic */
int isetting; /* initially ON or OFF */
int setting; /* ON or OFF */
void *wnd; /* window handle */
} CTLWINDOW;
/* --------- one of these for each dialog box ------- */
typedef struct {
char *HelpName;
DIALOGWINDOW dwnd;
CTLWINDOW ctl[MAXCONTROLS+1];
} DBOX;
/* -------- macros for dialog box resource compile -------- */
#define DIALOGBOX(db) DBOX db={ #db,
#define DB_TITLE(ttl,x,y,h,w) {ttl,x,y,h,w},{
#define CONTROL(ty,tx,x,y,h,w,c) \
{{NULL,x,y,h,w},ty,tx,NULL,c,#c,(ty==BUTTON?ON:OFF),OFF,NULL},
#define ENDDB }};
#define Cancel " Cancel "
#define Ok " OK "
#define Yes " Yes "
#define No " No "
#endif
[LISTING FOUR]
/* ----------- dialogs.c --------------- */
#include "dflat.h"
#ifdef INCLUDE_DIALOG_BOXES
/* -------------- the File Open dialog box --------------- */
DIALOGBOX( FileOpen )
DB_TITLE( "Open File", -1,-1,19,48)
CONTROL(TEXT, "~Filename", 2, 1, 1, 8, ID_FILENAME)
CONTROL(EDITBOX, NULL, 13, 1, 1,29, ID_FILENAME)
CONTROL(TEXT, "Directory:", 2, 3, 1,10, 0 )
CONTROL(TEXT, NULL, 13, 3, 1,28, ID_PATH )
CONTROL(TEXT, "F~iles", 2, 5, 1, 5, ID_FILES )
CONTROL(LISTBOX, NULL, 2, 6,11,16, ID_FILES )
CONTROL(TEXT, "~Directories", 19, 5, 1,11, ID_DRIVE )
CONTROL(LISTBOX, NULL, 19, 6,11,16, ID_DRIVE )
CONTROL(BUTTON, " ~OK ", 36, 7, 1, 8, ID_OK)
CONTROL(BUTTON, " ~Cancel ", 36,10, 1, 8, ID_CANCEL)
CONTROL(BUTTON, " ~Help ", 36,13, 1, 8, ID_HELP)
ENDDB
/* -------------- the Save As dialog box --------------- */
DIALOGBOX( SaveAs )
DB_TITLE( "Save As", -1,-1,19,48)
CONTROL(TEXT, "~Filename", 2, 1, 1, 8, ID_FILENAME)
CONTROL(EDITBOX, NULL, 13, 1, 1,29, ID_FILENAME)
CONTROL(TEXT, "Directory:", 2, 3, 1,10, 0 )
CONTROL(TEXT, NULL, 13, 3, 1,28, ID_PATH )
CONTROL(TEXT, "~Directories",2, 5, 1,11, ID_DRIVE )
CONTROL(LISTBOX, NULL, 2, 6,11,16, ID_DRIVE )
CONTROL(BUTTON, " ~OK ", 36, 7, 1, 8, ID_OK)
CONTROL(BUTTON, " ~Cancel ", 36,10, 1, 8, ID_CANCEL)
CONTROL(BUTTON, " ~Help ", 36,13, 1, 8, ID_HELP)
ENDDB
/* -------------- generic message dialog box --------------- */
DIALOGBOX( MsgBox )
DB_TITLE( NULL, -1,-1, 0, 0)
CONTROL(TEXT, NULL, 1, 1, 0, 0, 0)
CONTROL(BUTTON, NULL, 0, 0, 1, 8, ID_OK)
CONTROL(0, NULL, 0, 0, 1, 8, ID_CANCEL)
ENDDB
#ifdef INCLUDE_MULTIDOCS
#define offset 4
#else
#define offset 0
#endif
/* ------------ VGA Display dialog box -------------- */
DIALOGBOX( DisplayVGA )
DB_TITLE( "Display", -1, -1, 13+offset, 34)
#ifdef INCLUDE_MULTIDOCS
CONTROL(CHECKBOX, OFF, 9, 1, 1, 3, ID_TITLE)
CONTROL(TEXT, "~Title", 15, 1, 1, 5, ID_TITLE)
CONTROL(CHECKBOX, OFF, 9, 2, 1, 3, ID_BORDER)
CONTROL(TEXT, "~Border", 15, 2, 1, 6, ID_BORDER)
CONTROL(CHECKBOX, OFF, 9, 3, 1, 3, ID_TEXTURE)
CONTROL(TEXT, "Te~xture",15, 3, 1, 7, ID_TEXTURE)
#endif
CONTROL(RADIOBUTTON, OFF, 9,1+offset,1,3,ID_COLOR)
CONTROL(TEXT, "Co~lor", 15,1+offset,1,5,ID_COLOR)
CONTROL(RADIOBUTTON, OFF, 9,2+offset,1,3,ID_MONO)
CONTROL(TEXT, "~Mono", 15,2+offset,1,4,ID_MONO)
CONTROL(RADIOBUTTON, OFF, 9,3+offset,1,3,ID_REVERSE)
CONTROL(TEXT, "~Reverse", 15,3+offset,1,7,ID_REVERSE)
CONTROL(RADIOBUTTON, OFF, 9,5+offset,1,3,ID_25LINES)
CONTROL(TEXT, "~25 Lines",15,5+offset,1,8,ID_25LINES)
CONTROL(RADIOBUTTON, OFF, 9,6+offset,1,3,ID_43LINES)
CONTROL(TEXT, "~43 Lines",15,6+offset,1,8,ID_43LINES)
CONTROL(RADIOBUTTON, OFF, 9,7+offset,1,3,ID_50LINES)
CONTROL(TEXT, "~50 Lines",15,7+offset,1,8,ID_50LINES)
CONTROL(BUTTON, " ~OK ", 2,9+offset,1,8,ID_OK)
CONTROL(BUTTON, " ~Cancel ", 12,9+offset,1,8,ID_CANCEL)
CONTROL(BUTTON, " ~Help ", 22,9+offset,1,8,ID_HELP)
ENDDB
/* ------------ EGA Display dialog box -------------- */
DIALOGBOX( DisplayEGA )
DB_TITLE( "Display", -1, -1, 12+offset, 34)
#ifdef INCLUDE_MULTIDOCS
CONTROL(CHECKBOX, OFF, 9, 1, 1, 3, ID_TITLE)
CONTROL(TEXT, "~Title", 15, 1, 1, 5, ID_TITLE)
CONTROL(CHECKBOX, OFF, 9, 2, 1, 3, ID_BORDER)
CONTROL(TEXT, "~Border", 15, 2, 1, 6, ID_BORDER)
CONTROL(CHECKBOX, OFF, 9, 3, 1, 3, ID_TEXTURE)
CONTROL(TEXT, "Te~xture",15, 3, 1, 7, ID_TEXTURE)
#endif
CONTROL(RADIOBUTTON, OFF, 9, 1+offset,1,3,ID_COLOR)
CONTROL(TEXT, "Co~lor", 15, 1+offset,1,5,ID_COLOR)
CONTROL(RADIOBUTTON, OFF, 9, 2+offset,1,3,ID_MONO)
CONTROL(TEXT, "~Mono", 15, 2+offset,1,4,ID_MONO)
CONTROL(RADIOBUTTON, OFF, 9, 3+offset,1,3,ID_REVERSE)
CONTROL(TEXT, "~Reverse", 15, 3+offset,1,7,ID_REVERSE)
CONTROL(RADIOBUTTON, OFF, 9, 5+offset,1,3,ID_25LINES)
CONTROL(TEXT, "~25 Lines",15, 5+offset,1,8,ID_25LINES)
CONTROL(RADIOBUTTON, OFF, 9, 6+offset,1,3,ID_43LINES)
CONTROL(TEXT, "~43 Lines",15, 6+offset,1,8,ID_43LINES)
CONTROL(BUTTON, " ~OK ", 2, 8+offset,1,8,ID_OK)
CONTROL(BUTTON, " ~Cancel ", 12, 8+offset,1,8,ID_CANCEL)
CONTROL(BUTTON, " ~Help ", 22, 8+offset,1,8,ID_HELP)
ENDDB
/* ------------ CGA/MDA Display dialog box -------------- */
DIALOGBOX( DisplayCGA )
DB_TITLE( "Display", -1, -1, 9+offset, 34)
#ifdef INCLUDE_MULTIDOCS
CONTROL(CHECKBOX, OFF, 9, 1, 1, 3, ID_TITLE)
CONTROL(TEXT, "~Title", 15, 1, 1, 5, ID_TITLE)
CONTROL(CHECKBOX, OFF, 9, 2, 1, 3, ID_BORDER)
CONTROL(TEXT, "~Border", 15, 2, 1, 6, ID_BORDER)
CONTROL(CHECKBOX, OFF, 9, 3, 1, 3, ID_TEXTURE)
CONTROL(TEXT, "Te~xture",15, 3, 1, 7, ID_TEXTURE)
#endif
CONTROL(RADIOBUTTON, OFF, 9, 1+offset,1,3,ID_COLOR)
CONTROL(TEXT, "Co~lor", 15, 1+offset,1,5,ID_COLOR)
CONTROL(RADIOBUTTON, OFF, 9, 2+offset,1,3,ID_MONO)
CONTROL(TEXT, "~Mono", 15, 2+offset,1,4,ID_MONO)
CONTROL(RADIOBUTTON, OFF, 9, 3+offset,1,3,ID_REVERSE)
CONTROL(TEXT, "~Reverse", 15, 3+offset,1,7,ID_REVERSE)
CONTROL(BUTTON, " ~OK ", 2, 5+offset,1,8,ID_OK)
CONTROL(BUTTON, " ~Cancel ", 12, 5+offset,1,8,ID_CANCEL)
CONTROL(BUTTON, " ~Help ", 22, 5+offset,1,8,ID_HELP)
ENDDB
#define TS2 "~2 ─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴"
#define TS4 "~4 ───┴───┴───┴───┴───┴"
#define TS6 "~6 ─────┴─────┴─────┴──"
#define TS8 "~8 ───────┴───────┴────"
/* ------------ Tab Stops dialog box -------------- */
DIALOGBOX( TabStops )
DB_TITLE( "Editor Tab Stops", -1,-1, 10, 35)
CONTROL(RADIOBUTTON, OFF, 2, 1, 1, 3, ID_TAB2)
CONTROL(TEXT, TS2, 7, 1, 1, 23, ID_TAB2)
CONTROL(RADIOBUTTON, OFF, 2, 2, 1, 11, ID_TAB4)
CONTROL(TEXT, TS4, 7, 2, 1, 23, ID_TAB4)
CONTROL(RADIOBUTTON, OFF, 2, 3, 1, 11, ID_TAB6)
CONTROL(TEXT, TS6, 7, 3, 1, 23, ID_TAB6)
CONTROL(RADIOBUTTON, OFF, 2, 4, 1, 11, ID_TAB8)
CONTROL(TEXT, TS8, 7, 4, 1, 23, ID_TAB8)
CONTROL(BUTTON, " ~OK ", 1, 6, 1, 8, ID_OK)
CONTROL(BUTTON, " ~Cancel ", 12, 6, 1, 8, ID_CANCEL)
CONTROL(BUTTON, " ~Help ", 23, 6, 1, 8, ID_HELP)
ENDDB
/* ------------ Windows dialog box -------------- */
#ifdef INCLUDE_MULTIDOCS
DIALOGBOX( Windows )
DB_TITLE( "Windows", -1, -1, 19, 24)
CONTROL(LISTBOX, NULL, 1, 1,11, 20, ID_WINDOWLIST)
CONTROL(BUTTON, " ~OK ", 2, 13, 1, 8, ID_OK)
CONTROL(BUTTON, " ~Cancel ", 12, 13, 1, 8, ID_CANCEL)
CONTROL(BUTTON, " ~Help ", 7, 15, 1, 8, ID_HELP)
ENDDB
#endif
#ifdef INCLUDE_LOGGING
/* ------------ Message Log dialog box -------------- */
DIALOGBOX( Log )
DB_TITLE( "D-Flat Message Log", -1, -1, 18, 41)
CONTROL(TEXT, "~Messages", 10, 1, 1, 8, ID_LOGLIST)
CONTROL(LISTBOX, NULL, 1, 2, 14, 26, ID_LOGLIST)
CONTROL(TEXT, "~Logging:", 29, 4, 1, 10, ID_LOGGING)
CONTROL(CHECKBOX, OFF, 31, 5, 1, 3, ID_LOGGING)
CONTROL(BUTTON, " ~OK ", 29, 7, 1, 8, ID_OK)
CONTROL(BUTTON, " ~Cancel ", 29, 10, 1, 8, ID_CANCEL)
CONTROL(BUTTON, " ~Help ", 29, 13, 1, 8, ID_HELP)
ENDDB
#endif
#ifdef INCLUDE_HELP
/* ------------ the Help window dialog box -------------- */
DIALOGBOX( HelpBox )
DB_TITLE( NULL, -1, -1, 0, 45)
CONTROL(TEXTBOX, NULL, 1, 1, 0, 40, ID_HELPTEXT)
CONTROL(BUTTON, " ~Close ", 0, 0, 1, 8, ID_CANCEL)
CONTROL(BUTTON, " ~Back ", 10, 0, 1, 8, ID_BACK)
CONTROL(BUTTON, "<< ~Prev ", 20, 0, 1, 8, ID_PREV)
CONTROL(BUTTON, " ~Next >>", 30, 0, 1, 8, ID_NEXT)
ENDDB
#endif
#endif
[LISTING FIVE]
/* ----------- classes.h ------------ */
/* Class definition source file
* Make class changes to this source file
* Other source files will adapt
* You must add entries to the color tables in
* CONFIG.C for new classes.
* Class Name Base Class Processor Attribute
* ------------ --------- --------------- -----------
*/
ClassDef( NORMAL, -1, NormalProc, 0 )
ClassDef( APPLICATION, NORMAL, ApplicationProc, VISIBLE |
SAVESELF |
CONTROLBOX )
ClassDef( TEXTBOX, NORMAL, TextBoxProc, 0 )
ClassDef( LISTBOX, TEXTBOX, ListBoxProc, 0 )
ClassDef( EDITBOX, TEXTBOX, EditBoxProc, 0 )
ClassDef( MENUBAR, NORMAL, MenuBarProc, NOCLIP )
ClassDef( POPDOWNMENU, LISTBOX, PopDownProc, SAVESELF |
NOCLIP |
HASBORDER )
#ifdef INCLUDE_DIALOG_BOXES
ClassDef( BUTTON, TEXTBOX, ButtonProc, SHADOW |
NOCLIP )
ClassDef( DIALOG, NORMAL, DialogProc, SHADOW |
MOVEABLE |
CONTROLBOX|
HASBORDER |
NOCLIP )
ClassDef( ERRORBOX, DIALOG, DialogProc, SHADOW |
HASBORDER )
ClassDef( MESSAGEBOX, DIALOG, DialogProc, SHADOW |
HASBORDER )
#else
ClassDef( ERRORBOX, TEXTBOX, NULL, SHADOW |
HASBORDER )
ClassDef( MESSAGEBOX, TEXTBOX, NULL, SHADOW |
HASBORDER )
#endif
#ifdef INCLUDE_HELP
ClassDef( HELPBOX, DIALOG, HelpBoxProc, SHADOW |
MOVEABLE |
SAVESELF |
HASBORDER |
NOCLIP |
CONTROLBOX )
#endif
/* ========> Add new classes here <======== */
/* ---------- pseudo classes to create enums, etc. ---------- */
ClassDef( TITLEBAR, -1, NULL, 0 )
ClassDef( DUMMY, -1, NULL, HASBORDER )
ClassDef( TEXT, -1, NULL, 0 )
ClassDef( RADIOBUTTON, -1, NULL, 0 )
ClassDef( CHECKBOX, -1, NULL, 0 )
[LISTING SIX]
/* ------------- config.c ------------- */
#include <conio.h>
#include <string.h>
#include "dflat.h"
/* ----- default colors for color video system ----- */
unsigned char color[CLASSCOUNT] [4] [2] = {
/* ------------ NORMAL ------------ */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}},/* HILITE_COLOR */
/* ---------- APPLICATION --------- */
{{LIGHTGRAY, BLUE}, /* STD_COLOR */
{LIGHTGRAY, BLUE}, /* SELECT_COLOR */
{LIGHTGRAY, BLUE}, /* FRAME_COLOR */
{LIGHTGRAY, BLUE}}, /* HILITE_COLOR */
/* ------------ TEXTBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ------------ LISTBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLUE}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ----------- EDITBOX ------------ */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLUE}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ---------- MENUBAR ------------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, CYAN}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{DARKGRAY, RED}}, /* HILITE_COLOR Inactive, Shortcut (both FG) */
/* ---------- POPDOWNMENU --------- */
{{BLACK, CYAN}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, CYAN}, /* FRAME_COLOR */
{DARKGRAY, RED}}, /* HILITE_COLOR Inactive ,Shortcut (both FG) */
#ifdef INCLUDE_DIALOG_BOXES
/* ------------ BUTTON ------------ */
{{BLACK, CYAN}, /* STD_COLOR */
{WHITE, CYAN}, /* SELECT_COLOR */
{BLACK, CYAN}, /* FRAME_COLOR */
{DARKGRAY, RED}}, /* HILITE_COLOR Inactive ,Shortcut (both FG) */
/* ------------- DIALOG ----------- */
{{LIGHTGRAY, BLUE}, /* STD_COLOR */
{LIGHTGRAY, BLUE}, /* SELECT_COLOR */
{LIGHTGRAY, BLUE}, /* FRAME_COLOR */
{LIGHTGRAY, BLUE}}, /* HILITE_COLOR */
#endif
/* ----------- ERRORBOX ----------- */
{{YELLOW, RED}, /* STD_COLOR */
{YELLOW, RED}, /* SELECT_COLOR */
{YELLOW, RED}, /* FRAME_COLOR */
{YELLOW, RED}}, /* HILITE_COLOR */
/* ----------- MESSAGEBOX --------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
#ifdef INCLUDE_HELP
/* ----------- HELPBOX ------------ */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLUE}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{WHITE, LIGHTGRAY}},/* HILITE_COLOR */
#endif
/* ---------- TITLEBAR ------------ */
{{BLACK, CYAN}, /* STD_COLOR */
{BLACK, CYAN}, /* SELECT_COLOR */
{BLACK, CYAN}, /* FRAME_COLOR */
{WHITE, CYAN}}, /* HILITE_COLOR */
/* ------------ DUMMY ------------- */
{{GREEN, LIGHTGRAY}, /* STD_COLOR */
{GREEN, LIGHTGRAY}, /* SELECT_COLOR */
{GREEN, LIGHTGRAY}, /* FRAME_COLOR */
{GREEN, LIGHTGRAY}} /* HILITE_COLOR */
};
/* ----- default colors for mono video system ----- */
unsigned char bw[CLASSCOUNT] [4] [2] = {
/* ------------ NORMAL ------------ */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}},/* HILITE_COLOR */
/* ---------- APPLICATION --------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}},/* HILITE_COLOR */
/* ------------ TEXTBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ------------ LISTBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ----------- EDITBOX ------------ */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ---------- MENUBAR ------------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{DARKGRAY, WHITE}}, /* HILITE_COLOR Inactive, Shortcut (both FG) */
/* ---------- POPDOWNMENU --------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{DARKGRAY, WHITE}}, /* HILITE_COLOR Inactive ,Shortcut (both FG) */
#ifdef INCLUDE_DIALOG_BOXES
/* ------------ BUTTON ------------ */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{WHITE, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{DARKGRAY, WHITE}}, /* HILITE_COLOR Inactive ,Shortcut (both FG) */
/* ------------- DIALOG ----------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}}, /* HILITE_COLOR */
#endif
/* ----------- ERRORBOX ----------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}},/* HILITE_COLOR */
/* ----------- MESSAGEBOX --------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}},/* HILITE_COLOR */
#ifdef INCLUDE_HELP
/* ----------- HELPBOX ------------ */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{WHITE, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{WHITE, LIGHTGRAY}},/* HILITE_COLOR */
#endif
/* ---------- TITLEBAR ------------ */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{WHITE, LIGHTGRAY}},/* HILITE_COLOR */
/* ------------ DUMMY ------------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}} /* HILITE_COLOR */
};
/* ----- default colors for reverse mono video ----- */
unsigned char reverse[CLASSCOUNT] [4] [2] = {
/* ------------ NORMAL ------------ */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ---------- APPLICATION --------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ------------ TEXTBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ------------ LISTBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ----------- EDITBOX ------------ */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ---------- MENUBAR ------------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{DARKGRAY, WHITE}}, /* HILITE_COLOR Inactive, Shortcut (both FG) */
/* ---------- POPDOWNMENU --------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{DARKGRAY, WHITE}}, /* HILITE_COLOR Inactive ,Shortcut (both FG) */
#ifdef INCLUDE_DIALOG_BOXES
/* ------------ BUTTON ------------ */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{WHITE, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{DARKGRAY, WHITE}}, /* HILITE_COLOR Inactive ,Shortcut (both FG) */
/* ------------- DIALOG ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}}, /* HILITE_COLOR */
#endif
/* ----------- ERRORBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}}, /* HILITE_COLOR */
/* ----------- MESSAGEBOX --------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
#ifdef INCLUDE_HELP
/* ----------- HELPBOX ------------ */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{WHITE, LIGHTGRAY}},/* HILITE_COLOR */
#endif
/* ---------- TITLEBAR ------------ */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}}, /* HILITE_COLOR */
/* ------------ DUMMY ------------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}} /* HILITE_COLOR */
};
#define SIGNATURE DFLAT_APPLICATION " " VERSION
/* ------ default configuration values ------- */
CONFIG cfg = {
SIGNATURE,
0, /* Color */
TRUE, /* Editor Insert Mode */
4, /* Editor tab stops */
TRUE, /* Editor word wrap */
TRUE, /* Application Border */
TRUE, /* Application Title */
TRUE, /* Textured application window */
25 /* Number of screen lines */
};
/* ------ load a configuration file from disk ------- */
int LoadConfig(void)
{
FILE *fp = fopen(DFLAT_APPLICATION ".cfg", "rb");
if (fp != NULL) {
fread(cfg.version, sizeof cfg.version+1, 1, fp);
if (strcmp(cfg.version, SIGNATURE) == 0) {
fseek(fp, 0L, SEEK_SET);
fread(&cfg, sizeof(CONFIG), 1, fp);
}
else
strcpy(cfg.version, SIGNATURE);
fclose(fp);
}
return fp != NULL;
}
/* ------ save a configuration file to disk ------- */
void SaveConfig(void)
{
FILE *fp = fopen(DFLAT_APPLICATION ".cfg", "wb");
if (fp != NULL) {
cfg.InsertMode = GetCommandToggle(MainMenu, ID_INSERT);
cfg.WordWrap = GetCommandToggle(MainMenu, ID_WRAP);
fwrite(&cfg, sizeof(CONFIG), 1, fp);
fclose(fp);
}
}
[LISTING SEVEN]
/* ------------- keys.c ----------- */
#include <stdio.h>
#include "keys.h"
struct keys keys[] = {
{F1, "F1"},
{F2, "F2"},
{F3, "F3"},
{F4, "F4"},
{F5, "F5"},
{F6, "F6"},
{F7, "F7"},
{F8, "F8"},
{F9, "F9"},
{F10, "F10"},
{CTRL_F1, "Ctrl+F1"},
{CTRL_F2, "Ctrl+F2"},
{CTRL_F3, "Ctrl+F3"},
{CTRL_F4, "Ctrl+F4"},
{CTRL_F5, "Ctrl+F5"},
{CTRL_F6, "Ctrl+F6"},
{CTRL_F7, "Ctrl+F7"},
{CTRL_F8, "Ctrl+F8"},
{CTRL_F9, "Ctrl+F9"},
{CTRL_F10, "Ctrl+F10"},
{ALT_F1, "Alt+F1"},
{ALT_F2, "Alt+F2"},
{ALT_F3, "Alt+F3"},
{ALT_F4, "Alt+F4"},
{ALT_F5, "Alt+F5"},
{ALT_F6, "Alt+F6"},
{ALT_F7, "Alt+F7"},
{ALT_F8, "Alt+F8"},
{ALT_F9, "Alt+F9"},
{ALT_F10, "Alt+F10"},
{HOME, "Home"},
{UP, "Up"},
{PGUP, "PgUp"},
{BS, "BS"},
{END, "End"},
{DN, "Dn"},
{PGDN, "PgDn"},
{INS, "Ins"},
{DEL, "Del"},
{CTRL_HOME, "Ctrl+Home"},
{CTRL_PGUP, "Ctrl+PgUp"},
{CTRL_BS, "Ctrl+BS"},
{CTRL_END, "Ctrl+End"},
{CTRL_PGDN, "Ctrl+PgDn"},
{SHIFT_HT, "Shift+Tab"},
{ALT_BS, "Alt+BS"},
{SHIFT_DEL, "Shift+Del"},
{SHIFT_INS, "Shift+Ins"},
{CTRL_INS, "Ctrl+Ins"},
{ALT_A, "Alt+A"},
{ALT_B, "Alt+B"},
{ALT_C, "Alt+C"},
{ALT_D, "Alt+D"},
{ALT_E, "Alt+E"},
{ALT_F, "Alt+F"},
{ALT_G, "Alt+G"},
{ALT_H, "Alt+H"},
{ALT_I, "Alt+I"},
{ALT_J, "Alt+J"},
{ALT_K, "Alt+K"},
{ALT_L, "Alt+L"},
{ALT_M, "Alt+M"},
{ALT_N, "Alt+N"},
{ALT_O, "Alt+O"},
{ALT_P, "Alt+P"},
{ALT_Q, "Alt+Q"},
{ALT_R, "Alt+R"},
{ALT_S, "Alt+S"},
{ALT_T, "Alt+T"},
{ALT_U, "Alt+U"},
{ALT_V, "Alt+V"},
{ALT_W, "Alt+W"},
{ALT_X, "Alt+X"},
{ALT_Y, "Alt+Y"},
{ALT_Z, "Alt+Z"},
{-1, NULL}
};
Examplσ 1:
(a)
typedef enum window_class {
#define ClassDef(c,b,p,a) c,
#include "classes.h"
CLASSCOUNT
} CLASS;
(b)
char *ClassNames[] = {
#undef ClassDef
#define ClassDef(c,b,p,a) #c,
#include "classes.h"
NULL
};
(c)
CLASSDEFS classdefs[] = {
#undef ClassDef
#define ClassDef(c,b,p,a) {b,p,a},
{0,0,0}
#include "classes.h"
};
Examplσ 2:
(a)
KeyDef(ALT_S, 159+OFFSET, "Alt+S")
(b)
struct keys keys[] = {
#undef KeyDef
#define KeyDef(k,v,s) {v,s},
#include "keycaps.h"
{-1,NULL}
};
(c)
#undef KeyDef
è #define KeyDef(k,v,s) #define k v
#include "keycaps.h"
(d)
#undef KeyDef
#define KeyDef(k,v,s) extern const int k;
#include "keycaps.h"
(e)
#undef KeyDef
#define KeyDef(k,v,s) const int k = v;
#include "keycaps.h"