home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
drdobbs
/
1990
/
12
/
entsming.asc
< prev
next >
Wrap
Text File
|
1990-11-15
|
8KB
|
320 lines
_EXAMINING THE ZINC INTERFACE LIBRARY_
by Gary Entsminger
[LISTING ONE]
//database/field window code
// Construct a window databaselike window.
+ new UIW_PROMPT(38, 0, "#", WOF_NO_FLAGS)
+ new UIW_NUMBER(40, 0, 6, &recordNumber, "",
NMF_NO_FLAGS, WOF_NO_ALLOCATE_DATA | WOF_NON_SELECTABLE)
+ new UIW_PROMPT(2, 1, "Name......", WOF_NO_FLAGS)
+ new UIW_STRING(15, 1, 27, tmpRecord.name, 26,
STF_NO_FLAGS, WOF_BORDER | WOF_NO_ALLOCATE_DATA)
+ new UIW_PROMPT(2, 2, "Address...", WOF_NO_FLAGS)
+ new UIW_STRING(15, 2, 27, tmpRecord.address1, 26,
STF_NO_FLAGS, WOF_BORDER | WOF_NO_ALLOCATE_DATA)
+ new UIW_STRING(15, 3, 27, tmpRecord.address2, 26,
STF_NO_FLAGS, WOF_BORDER | WOF_NO_ALLOCATE_DATA)
+ new UIW_PROMPT(2, 4, "Phone.....", WOF_NO_FLAGS)
+ new UIW_FORMATTED_STRING(15, 4, 27, tmpRecord.phone,
"LNNNLLNNNLCCCC", "(...) ...-....", WOF_BORDER
| WOF_NO_ALLOCATE_DATA);
[LISTING TWO]
// Line Editor example using Zinc Interface Library -- (c) Gary Entsminger
#include <ui_win.hpp>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// Derive a new class which adds File I/O to a window.
class Line_editor: public UIW_WINDOW
{
public :
Line_editor(); // Constructor
~Line_editor(); // Destructor
char * line_buffer[64];
}; // end class Line_editor declaration
// Define Line_editor's constructor
Line_editor :: Line_editor() : UIW_WINDOW(2,2,70,5,
WOF_NO_FLAGS, WOAF_NO_FLAGS)
{
FILE *textfile; // pointer to file
char ln[64]; // local char array to hold lines read from file
// Open file
if ((textfile = fopen("mk.bat", "r")) == NULL)
{
printf("Error opening text file\n Aborting.");
exit(0);
}
// Read first 64 characters of file
fseek(textfile,SEEK_SET,0);
fread(ln,64,1,textfile);
// Close file
fclose(textfile);
strcpy(*line_buffer,ln);
} // end Line_editor constructor
// Define Line_editor's destructor.
Line_editor:: ~Line_editor()
{
FILE *textfile; // pointer to file
char ln[64]; // char array to hold a line read from file
// Open Make file (MK.BAT)
if ((textfile = fopen("mk.bat", "w")) == NULL)
{
printf("Error opening text file. Aborting. \n");
exit(0);
}
// Write edited text to the file
strcpy(ln,*line_buffer);
fwrite(ln,64,1,textfile);
// Close file
fclose(textfile);
} // end destructor.
main()
{
// Construct the display, trying for graphics first.
UI_DISPLAY *display = new UI_DOS_BGI_DISPLAY;
if (!display->installed)
{
delete display;
display = new UI_DOS_TEXT_DISPLAY;
}
// Construct the event manager and add three devices to it.
UI_EVENT_MANAGER *eventManager =
new UI_EVENT_MANAGER(100, display);
*eventManager
+ new UI_BIOS_KEYBOARD
+ new UI_MS_MOUSE
+ new UI_CURSOR;
// Construct the window manager.
UI_WINDOW_MANAGER *windowManager =
new UI_WINDOW_MANAGER(display, eventManager);
// Construct a new Line_editor in window 1.
Line_editor *window1 = new Line_editor();
// Construct a new string field for the Line_editor in window1.
UIW_STRING *stringfield = new UIW_STRING(1,1,64,
*window1->line_buffer, 64,
STF_NO_FLAGS, WOF_NO_ALLOCATE_DATA);
// Add the window objects to the line_editor in window 1.
*window1
+ new UIW_BORDER
+ new UIW_MAXIMIZE_BUTTON
+ new UIW_MINIMIZE_BUTTON
+ new UIW_SYSTEM_BUTTON
+ new UIW_TITLE("MAKE .BAT editor", WOF_JUSTIFY_CENTER)
+ stringfield; // Add the string field we constructed to window1
// Add window1 to the window manager.
*windowManager + window1;
// Loop for user response.
int ccode;
UI_EVENT event;
do
{
// Get input from the user.
eventManager->Get(event, Q_NORMAL);
// Send event information to the window manager.
ccode = windowManager->Event(event);
}
while (ccode != L_EXIT && ccode != S_NO_OBJECT);
// Manually decouple stringfield from window1. Destruct all the objects we
// constructed in the opposite order in which we created them.
*window1 - stringfield;
delete stringfield;
delete window1;
delete windowManager;
delete eventManager;
delete display;
} // end main.
[LISTING THREE]
#include <ui_win.hpp>
#include "editor.hlh"
main()
{
// Initialize the display, try for graphics first.
UI_DISPLAY *display = new UI_DOS_BGI_DISPLAY;
if (!display->installed)
{
delete display;
display = new UI_DOS_TEXT_DISPLAY;
}
// Initialize the event manager.
UI_EVENT_MANAGER *eventManager = new UI_EVENT_MANAGER(100, display);
*eventManager + new UI_BIOS_KEYBOARD + new UI_MS_MOUSE + new
UI_CURSOR;
// Initialize the window manager.
UI_WINDOW_MANAGER *windowManager =
new UI_WINDOW_MANAGER(display, eventManager);
// Initialize the help window system.
_helpSystem = new UI_HELP_WINDOW_SYSTEM("notepad.hlp",
windowManager, HELP_GENERAL);
// Initialize the error window system.
_errorSystem = new UI_ERROR_WINDOW_SYSTEM;
// Create a field editor window.
UIW_WINDOW *editor = new UIW_WINDOW(4, 5, 66, 12,
WOF_NO_FLAGS, WOAF_NO_FLAGS);
// Add window objects to editor.
*editor
+ new UIW_BORDER
+ new UIW_MAXIMIZE_BUTTON
+ new UIW_MINIMIZE_BUTTON
+ new UIW_SYSTEM_BUTTON
+ new UIW_TITLE("FieldEditor", WOF_JUSTIFY_CENTER)
+ new UIW_PROMPT(2, 1, "To:", WOF_NO_FLAGS)
+ new UIW_STRING(6, 1, 15, "Dr. Dobbs folk", 40, STF_NO_FLAGS,
WOF_BORDER)
+ new UIW_PROMPT(28, 1, "Date:", WOF_NO_FLAGS)
+ new UIW_DATE(35, 1, 20, &UI_DATE(), "",
DTF_SYSTEM | DTF_ALPHA_MONTH, WOF_BORDER,
NO_HELP_CONTEXT)
+ new UIW_PROMPT(2, 2, "Message:", WOF_NO_FLAGS)
+ new UIW_TEXT(2, 3, 60, 4, "", 1028, TXF_NO_FLAGS, WOF_BORDER);
// Add field editor to the window manager.
*windowManager + editor;
// Wait for user response.
int ccode;
UI_EVENT event;
do
{
eventManager->Get(event, Q_NORMAL);
ccode = windowManager->Event(event);
} while (ccode != L_EXIT && ccode != S_NO_OBJECT);
// Clean up.
delete _helpSystem;
delete _errorSystem;
delete windowManager;
delete eventManager;
delete display;
}
// Contents of editor.hlh........
// This file was created by the GENHELP utility.
const int HELP_GENERAL = 1; // General Help
const int HELP_EDITOR = 2; // Editor Help
[Example 1]
class AnyType : public Node
{
AnyType; // constructor
~AnyType; // destructor
virtual void Action; { } // abstract inline
};
[Example 2]
// Construct a graphics display if possible.
UI_DISPLAY *display = new UI_DOS_BGI_DISPLAY;
if (!display ->installed)
// if this system can't handle graphics,
// delete the graphics
// display we just created with new.
{
delete display;
// then create a text display.
display = new UI_DOS_TEXT_DISPLAY;
}
// Construct an event manager.
UI_EVENT_MANAGER *eventManager =
new UI_EVENT_MANAGER(100, display);
// 100 = MaxNoEvents
*eventManager // add devices by constructing
// new instances of device class.
+ new UI_BIOS_KEYBOARD
+ new UI_MS_MOUSE
+ new UI_CURSOR;
// Construct a window manager.
UI_WINDOW_MANAGER *windowManager =
new UI_WINDOW_MANAGER(display, eventManager):
// Construct and add a window to the window manager.
UIW_WINDOW *window1 = new UIW_WINDOW(1,1,50,20,WOF_NO_FLAGS, WOAF_NO_FLAGS);
*window1 // add window objects by constructing instances
// of the window object class.
+ new UIW_BORDER
+ new UIW_TITLE("WIN1", WOF_JUSTIFY_CENTER);
[Example 3]
UI_WINDOW_MANAGER &operator+(void *object)
{ Add((UI_WINDOW_OBJECT *)object); return(*this); }
[Example 4]
+ new MY_OBJECT
[Example 5]
int ccode;
UI_EVENT event; // an event is an instance of class UI_EVENT
do // loop: do-while event not equal to ESCAPE
{
// Get input from a user.
eventManager.Get(event, Q_NORMAL);
// If ESC message, exit.
If (event.type == E_KEY && event.rawCode == ESCAPE)
event.type = L_EXIT;
// Send event information to the window manager
ccode = windowManager.Event(event);
} while (ccode != L_EXIT);