Category : Files from Magazines
Archive   : DDJ9210.ZIP
Filename : OOPAFX.ASC

 
Output of file : OOPAFX.ASC contained in archive : DDJ9210.ZIP
_SIZING UP APPLICATION FRAMEWORKS AND CLASS LIBRARIES_
by Ray Valdes

[LISTING ONE]

/******* BORLAND ******/

....standard #includes...

_CLASSDEF( TMainWindow )
_CLASSDEF( TMainApp )

//---------------------------- Constructor of Application's MainWindow.
TMainWindow::TMainWindow( PTWindowsObject AParent,LPSTR AName,PTModule AModule)
: TDialog( AParent, AName, AModule )
{
fDataLoaded= FALSE;
DrawData.cur_char = 'A';
DrawData.cur_inst = 0;
DrawData.rgbBackGroundColor = GetSysColor( COLOR_WINDOW );
DrawData.rgbLineColor = GetSysColor( COLOR_WINDOWTEXT );
DrawData.nLineThickness = 1;
DrawData.nScaleFactor = NORM_SCALE;
GridWindow = new TGridWindow( this, ID_GRIDWINDOW , &DrawData );
ViewWindow = new TViewWindow( this, ID_VIEWWINDOW , &DrawData );
Printer = new TPrinter;
ScaleScrollBar = new TScrollBar( this, ID_SCROLLSCALE );
ScaleText = new TStatic ( this, ID_SCALETEXT,-1);
}
//-------------------------------------- Destructor of App's MainWindow
TMainWindow::~TMainWindow()
{
if ( Printer ) delete Printer;
}
//------------------------------------- return Main Window's Class Name
LPSTR TMainWindow::GetClassName()
{
return "bordlg_MainDialog";
}
//---- Use the Borland Custom Dialog Class and indicate the Application's Icon
void TMainWindow::GetWindowClass( WNDCLASS& AWndClass )
{
TDialog::GetWindowClass( AWndClass );
AWndClass.lpfnWndProc = BWCCDefDlgProc;
AWndClass.hIcon = LoadIcon( GetApplication()->hInstance,"ApplicationIcon" );
}
//----- Function called as a result of WM_INITDIALOG. Center Dialog on Screen.
void TMainWindow::SetupWindow()
{
RECT rc;
TDialog::SetupWindow();
GetWindowRect( HWindow, &rc );
OffsetRect( &rc, -rc.left, -rc.top );
MoveWindow( HWindow, (( GetSystemMetrics( SM_CXSCREEN ) -
rc.right ) / 2 + 4 ) & ~7,
( GetSystemMetrics( SM_CYSCREEN ) - rc.bottom ) / 2,
rc.right, rc.bottom, 0 );
ScaleScrollBar->SetRange( 1, 10 );
ScaleScrollBar->SetPosition( 5 );
EnableScaleScrollBar( FALSE );
ScaleText->SetText( "&Scale: 50%" );
SetFocus( GridWindow->HWindow );
}
void TMainWindow::EnableScaleScrollBar( BOOL fFlag )
{
EnableWindow( ScaleScrollBar->HWindow, fFlag );
EnableWindow( ScaleText->HWindow, fFlag );
}
//---- Function responds to FILE|READ Menu Option...
// Prompts user for FileName and Read Data...
void TMainWindow::CMFileRead ( RTMessage )
{
strcpy( lpszFileName , "*.dat" );
GetApplication()->ExecDialog( new TFileDialog( this ,
SD_FILEOPEN , lpszFileName ));
SetWait();
if ( file_LoadHWXData( lpszFileName ))
{
fDataLoaded = TRUE;
GridWindow->UpdateView();
ViewWindow->UpdateView();
}
ReleaseWait();
}
//-------- Responds to the Print Request...
void TMainWindow::CMPrint(RTMessage)
{
PTPrintCharInst Printout = 0;

if ( Printer )
{
Printout = new TPrintCharInst( "Char Instance", DrawData.cur_char,
DrawData.cur_inst, DrawData.nLineThickness,
DrawData.nScaleFactor );
if ( Printout )
{
Printout->SetBanding( TRUE );
Printer->Print(this, Printout);
delete Printout;
}
}
}
//------- Allows user to Select/Configure Printer
void TMainWindow::CMPrinterSetup(RTMessage)
{
if ( Printer ) Printer->Setup(this);
}
//--------- Request to Exit Menu Choice - Terminates App...
void TMainWindow::CMExit( RTMessage )
{
PostMessage( HWindow, WM_SYSCOMMAND, SC_CLOSE, 0 );
}
//--------------------------------------Bring up AboutBox
void TMainWindow::CMAbout( RTMessage )
{
GetApplication()->ExecDialog( new TDialog( this , "ABOUTBOX" ));
}
void TMainWindow::UpdateSubViews( void )
{
GridWindow->UpdateView();
ViewWindow->UpdateView();
}
//----- Allows user to select Foreground/Line Color.
void TMainWindow::IDForColor( RTMessage )
{
PTColorDialog ColorDialog = new TColorDialog( this , DrawData.rgbLineColor );
if ( ColorDialog )
{
delete ColorDialog;
UpdateSubViews();
}
}
//--------------------------------------user selects Background Color
void TMainWindow::IDBackColor( RTMessage )
{
PTColorDialog ColorDialog = new TColorDialog( this ,
DrawData.rgbBackGroundColor , TRUE );
if ( ColorDialog )
{
delete ColorDialog;
UpdateSubViews();
}
}
//-------------------------------------- Responds to Line Thickness Selection
void TMainWindow::IDLineRad1( RTMessage )
{
DrawData.nLineThickness = 1;
UpdateSubViews();
}
//---------------------------------- user can specify scale for GridDisplay
void TMainWindow::IDScrollScale( RTMessage )
{
int nPos = ScaleScrollBar->GetPosition();
if ( nPos != DrawData.nScaleFactor )
{
char buff[80];
wsprintf( buff, "&Scale: %d%%", nPos*10 );
DrawData.nScaleFactor = MAX_SCALE + MIN_SCALE - nPos;
ScaleText->SetText( buff );
GridWindow->UpdateView();
}
}
//---- Sent by GridWindow to MainWindow which then informs ViewWindow of change
void TMainWindow::SetCurChar( int ch, int inst )
{
if ( DrawData.cur_char != ch || DrawData.cur_inst != inst )
{
DrawData.cur_char = ch;
DrawData.cur_inst = inst;
ViewWindow->UpdateView(); // Allows View to Refresh
}
}
//---------------------------------- Constructor of Main Application Class

TMainApp::TMainApp( LPSTR AName, HINSTANCE hInstance,
HINSTANCE hPrevInstance, LPSTR lpCmd, int nCmdShow )
: TApplication( AName, hInstance, hPrevInstance, lpCmd, nCmdShow )
{
}
//--------------------------------- Specifying the Application's Main Window
void TMainApp::InitMainWindow()
{
BWCCGetVersion(); // Force Implicit Loading of BWCC.DLL !
MainWindow = new TMainWindow( NULL, "MainDialog" );
}
//---------------------------------- Create Application Class and run !
int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmd, int nCmdShow )
{
TMainApp MyApp( "HWX Browser", hInstance, hPrevInstance, lpCmd, nCmdShow );
MyApp.Run();
return( MyApp.Status );
}



[LISTING TWO]

/******** INMARK *******/

#include "zapp.hpp"
#include "ddj.hpp"

typedef int (zEvH::*KeyProc)(zKeyEvt*);
Alphabet *alpha=0;
char *types[]={
"HWX Files (*.dat)","*.dat",
"All Files (*.*)","*.*",
0,0
};
void Browser::removeViews() {
if (grid!=0) {
grid->sizer()->remove();
has()->remove(grid);
delete grid;
grid=0;
}
if (curVis!=0) {
curVis->sizer()->remove();
has()->remove(curVis);
}
if (ilet!=0) {
ilet->sizer()->parent()->remove();
delete ilet->sizer()->parent();
has()->remove(ilet);
delete ilet;
ilet=0;
}
}
void Browser::changeLetInInstView() {
removeViews();
curInst = 0;
ilet=new VisLetter(this,center,new zPercentSizer(left,100,50,sizer()),curLet,1);
has()->append(ilet);
grid=new GridCompound(this,sizer());
select(grid->addLetter(alpha,curVis->letter()->ch()));
sizer()->update();
canvas()->setDirty();
updateStats(selVis);
}
void Browser::changeInstanceInAlphaView(int spos) {
removeViews();
curInst = spos;
grid=new GridCompound(this,sizer());
select(grid->addAlphabet(alpha,curInst));
updateStats(selVis);
sizer()->update();
canvas()->setDirty();
}
void Browser::changeLetterFromScrollPos(int spos) {
int cnt=0,let=0;
while (let if (alpha->instance(let++,curInst)!=0) cnt++;
changeChar(let-1,curInst);
}
void Browser::changeLetFromInstScr(int spos) {
int cnt=0,let=0;
while (let if (alpha->instance(let++,curInst)!=0) cnt++;
curLet = alpha->instance(let-1,curInst);
curVis->letter(curLet);
}
InfoPane::InfoPane(zWindow *w, zSizer *siz):VisualPane(w,siz) {
VisPanel *pan;
pan=new VisPanel(this,new zPercentSizer(left,100.0,33.3,siz));
add(pan);
zSizer *x2;
x2=new TextFrameSizer(middle,zDimension(0,0),sizer(),pan);

totalc=new InfoText(this,x2,"Total Chars",pan);
fsize=new InfoText(this,x2,"Size",pan);
totalseg=new InfoText(this,x2,"Total Segments",pan);

pan=new VisPanel(this,new zPercentSizer(left,100.0,33.3,siz));
add(pan);
x2=new TextFrameSizer(middle,zDimension(0,0),sizer(),pan);
wchar=new InfoText(this,x2,"Char",pan);
cinst=new InfoText(this,x2,"Instance",pan);
scalef=new InfoText(this,x2,"Scaling Factor",pan);

pan=new VisPanel(this,new zPercentSizer(left,100,33.3,siz));
add(pan);
x2=new TextFrameSizer(middle,zDimension(0,0),sizer(),pan);
nstrok=new InfoText(this,x2,"Strokes",pan);
npoints=new InfoText(this,x2,"Points",pan);
csize=new InfoText(this,x2,"Size",pan);
backgroundColor(zColor(192,192,192));
}
Browser::Browser(zWindow *w,zSizer *siz, InfoPane *inp):VisualPane(w,siz,zSCROLLV|zSCROLLH) {
ilet=selVis=0;
curLet=0;
curInst=curWidth=0;
curView=IDM_SVIEW;
ip=inp;
curVis=new VisLetter(this,center,sizer(),0,1);
add(curVis);
has()->alwaysHit();
}
BOOL Browser::getPreferredSize(zDimension& d) {
d.width() = 500;
d.height() = alpha->maxSize().height()*grid->vertKids();
return 1;
}
void Browser::updateStats(VisLetter *vl) {
char buf[50];
wsprintf(buf," %d - %c ",(int)vl->letter()->ch(),
(char)vl->letter()->ch());
ip->wchar->setVal(buf);
wsprintf(buf," %d of %d ",vl->letter()->instance()+1,
alpha->letterInstances(vl->letter()->ch()));
ip->cinst->setVal(buf);
wsprintf(buf," %d x %d ",
vl->maxSize().width(),vl->maxSize().height());
ip->csize->setVal(buf);
ip->nstrok->setVal(vl->letter()->strokes());
int tot=vl->letter()->strokes();
for (int i=0;iletter()->strokes();i++)
tot+=vl->letter()->path(i).length();
ip->npoints->setVal(tot);
ip->scalef->setVal(vl->scaling());
}
int Browser::ch(zKeyEvt* e) {
if (curView == IDM_SVIEW || curView == IDM_IVIEW) {
Letter *test=0;
if (alpha!=0) test=alpha->instance(e->ch(),0);
if (test!=0 && test!=curLet) {
if (curView == IDM_SVIEW) changeChar(e->ch(),0);
else {
curLet = test;
curVis->letter(curLet);
int mnum = 0;
for (int cnt = 0; cnt < curVis->letter()->ch();cnt++)
if (alpha->instance(cnt,curInst)!=0) mnum++;
scrollBarVert()->pos(mnum);
scrollBarVert()->oldpos(mnum);
changeLetInInstView();
}
}
}
return 0;
}
int Browser::printView(zCommandEvt* e) {
if (alpha==0) {
zMessage(app->rootWindow(),"No data file loaded","Error");
return 1;
}
zPrinterDisplay *pr=new zPrinterDisplay;
if (!pr->isValid()) {
zMessage mess(this,"No Printer drivers installed","Unable to print");
return 1;
}
if (pr->printerSetup()) {
zDefPrJobDlg *prDlg=new zDefPrJobDlg(parent(), zResId(PRINT));
zPrintJob *pj = new zPrintJob(this, pr, prDlg);
pj->setJobName("HWX Print Job");
pj->go();
}
return 1;
}
int Browser::print(zPrinterDisplay *pd, zRect *re) {
zRect r;
pushDisplay(pd);
canvas()->lock();
// Re-Lay out the display based on the printers display;
canvas()->getVisible(r);
zRect save(*sizer());
sizer()->update(&r);
draw(0);
// Restore the old display layout.
canvas()->unlock();
sizer()->update(&save);
popDisplay();
return 0;
}
int Browser::changeView(zCommandEvt* e) {
int which,cnt=0;
if (e==0) {
curView=0;
which=IDM_SVIEW;
} else which=e->cmd();

if (which==curView || alpha==0) return 1;
selVis=0;
curInst = 0;
app->rootWindow()->menu()->checkItem(curView,FALSE);
app->rootWindow()->menu()->checkItem(which,TRUE);
if (scroller()) delete scroller();
removeViews();
switch (which) {
case IDM_SVIEW:
sizer()->append(curVis->sizer());
has()->append(curVis);
scroller(new BroScroller(this));
scrollBarVert()->limits(zRange(0,alpha->totalChars()-1));
for (cnt = 0; alpha->instance(cnt,curInst)==0;cnt++);
changeChar(cnt,curInst,0);
scrollBarVert()->oldpos(scrollBarVert()->pos());
scrollBarHoriz()->pos(curInst);
scrollBarHoriz()->oldpos(curInst);
ip->totalc->setVal(alpha->totalChars());
ip->fsize->setVal(alpha->fileSize());
ip->totalseg->setVal(alpha->totalSegments());
break;
case IDM_IVIEW:{
ilet=new VisLetter(this,center,new zPercentSizer(left,100,50,sizer()),curLet,1);
has()->append(ilet);
grid=new GridCompound(this,sizer());
select(grid->addLetter(alpha,curLet->ch()));
updateStats(selVis);
scroller(new InstanceScroller(this));
scrollBarVert()->limits(zRange(0,alpha->totalChars()-1));
int mnum=0;
for (cnt = 0; cnt < curVis->letter()->ch();cnt++)
if (alpha->instance(cnt,curInst)!=0) mnum++;
scrollBarVert()->pos(mnum);
scrollBarVert()->oldpos(mnum);
break;}
case IDM_AVIEW:
grid=new GridCompound(this,sizer());
select(grid->addAlphabet(alpha,curInst));
updateStats(selVis);
scroller(new AlphabetScroller(this));
scroller()->respondToSize();
}
sizer()->update();
canvas()->setDirty();
curView=which;
return 1;
}
void Browser::changeChar(int wh,int ins,int updateNow) {
curInst=ins;
curLet=alpha->instance(wh,ins);
curVis->letter(curLet);
updateStats(curVis);
scrollBarHoriz()->limits(zRange(0,
(alpha->letterInstances(curVis->letter()->ch())-1)));
int mnum=0;
for (int cnt=0; cnt < curVis->letter()->ch();cnt++)
if (alpha->instance(cnt,curInst)!=0) mnum++;
scrollBarVert()->pos(mnum);
if (updateNow) {
canvas()->setDirty();
UpdateWindow(*this);
}
}
void Browser::select(VisLetter *vl) {
if (selVis!=vl) {
if (selVis!=0) selVis->select(FALSE);
selVis=vl;
selVis->select(TRUE);
if (ilet!=0) {
ilet->letter(selVis->letter());
updateStats(ilet);
} else
updateStats(selVis);
}
}
int Browser::changeLineWidth(zCommandEvt* e) {
AskNumForm *ask;
ask=new AskNumForm(new zFormDlg(((HwxApp *)parent()),
zResId("ASKNUMFORM")),curWidth);
if (ask->completed() && ask->width()!=curWidth) {
VisLetter::setPen(new zPen(def[IDM_LINEC-IDM_BACK],Solid,
curWidth=ask->width()));
canvas()->setDirty();
}
delete ask;
return 1;
}
int Browser::changeColor(zCommandEvt* e) {
zColorSelForm *tmp=new zColorSelForm(this,def[e->cmd()-IDM_BACK]);
if (tmp->completed()) {
def[e->cmd()-IDM_BACK]=tmp->color();
switch (e->cmd()) {
case IDM_BACK:
backgroundColor(tmp->color());
break;
case IDM_LINEC:
VisLetter::setPen(new zPen(tmp->color(),Solid,curWidth));
break;
case IDM_HILIGHTC:
VisLetter::setHighlightColor(tmp->color());
break;
case IDM_LINEB:
VisLetter::setBrush(new zBrush(tmp->color()));
}
canvas()->setDirty();
}
return 1;
}
HwxToolBar::HwxToolBar(zWindow *w,zSizer *s,DWORD d):ToolBar(w,s,d) {
backgroundColor(zColor(LTGRAY));
frame->append(new VisBmpButton(this,top,sizer(),IDM_OPEN,LINEI,LINEI+1));
frame->append(new VisBmpButton(this,top,sizer(),IDM_PRINT,PRI,PRI+1));
frame->append(new VisBmpButton(this,top,sizer(),IDM_SVIEW,SVI,SVI+1));
frame->append(new VisBmpButton(this,top,sizer(),IDM_IVIEW,IVI,IVI+1));
frame->append(new VisBmpButton(this,top,sizer(),IDM_AVIEW,AVI,AVI+1));
}
HwxApp::HwxApp(zWindow *w,zSizer *siz,DWORD d,const char *title)
: zAppFrame(w,siz,d,title) {
menu(new zMenu(this,zResId("TOPMENU")));
menu()->setCommand(this,(CommandProc)&HwxApp::fOpen,IDM_OPEN);
setIcon(new zIcon(zResId("DRAWICON")));
sline=new StatusLine(this,new zGravSizer(bottom,0));
sline->show();
sline->setupHilite();
toolbar=new HwxToolBar(this,new zGravSizer(left,32),WS_BORDER);
toolbar->show();
ip = new InfoPane(this, new zGravSizer(top,zPrPoint(0,590)));
ip->show();
image=new Browser(this,new zGravSizer(middle),ip);
menu()->setCommand(image,
(CommandProc)&Browser::changeColor,IDM_BACK,IDM_LINEB);
menu()->setCommand(image,
(CommandProc)&Browser::changeLineWidth,IDM_LINEW);
menu()->setCommand(image,
(CommandProc)&Browser::changeView,IDM_SVIEW,IDM_AVIEW);
menu()->setCommand(image,(CommandProc)&Browser::printView,IDM_PRINT);
image->show();
}
HwxApp::~HwxApp() {
delete sline;
delete toolbar;
delete image;
}
int HwxApp::fOpen(zCommandEvt*e) {
zFileOpenForm *tmp=new zFileOpenForm(this,"Select File",0,types);
if (tmp->completed()) {
sline->message()->printf("Loading File...");
setCursor(zCursor(Hourglass));
char buf[300];
wsprintf(buf,"zApp HWX Browser - %s",tmp->name());
caption(buf);
alpha=new Alphabet();
alpha->readFile(tmp->name());
if (alpha->isValid()) {
image->addVertScrollBar();
image->addHorzScrollBar();
image->changeView();
sline->message()->printf("File Loaded");
} else alpha=0;
setCursor(zCursor(Arrow));
}
return 1;
}
int HwxApp::focus(zFocusEvt* e) {
if (e->gainFocus() && image!=0) image->setFocus();
return 1;
}
int HwxApp::command(zCommandEvt*e) {
switch (e->cmd()) {
case IDM_EXIT:
app->quit();
break;
case IDM_HELP:
WinHelp(*this,"ddj.hlp",HELP_INDEX,0);
break;
case IDM_ABOUT:{
AboutBox *ab = new AboutBox(this,new zSizer,"About Box");
delete ab;}
}
return 1;
}
void zApp::main() {
HwxApp* p=new HwxApp(0,new zSizer,zSTDFRAME,"zApp HWX Browser");
p->show();
go();
delete p;
}


[LISTING THREE]

/***** ISLAND SYSTEMS IMPLEMENTATION USING OBJECT-MENU*****/

#include "omExt.h"

#include "h_config.h"
#include "h_stddef.h"
#include "h_list.h"
#include "h_grafic.h"

#include "h_om.h"


#include "omExt.h"

#include "h_config.h"
#include "h_stddef.h"
#include "h_list.h"
#include "h_grafic.h"

#include "h_om.h"

extern void LoadHWXData(LPSTR name);
extern void omDisplayInstance(lpRect R, int char_code, int instance_num,
int shift, int boxcolor, int drawcolor);

extern void RegisterCallback(
HDISPLAY display_entity,
void (*pf_move_to)(HDISPLAY,INT16,INT16),
void (*pf_line_to)(HDISPLAY,INT16,INT16));

extern void myMoveTo(HDISPLAY display_entity,INT16 h,INT16 v);
extern void myLineTo(HDISPLAY display_entity,INT16 h,INT16 v);

//----- globals
const char titlePredicate[] = "Sample File: ";
omDispHelpBlock *dispHelp;

...subordinate routines deleted...

//-----------------MAIN FUNCTION------------------

int omRunIt()
{
//------ initialize help and icon libraries: hw.dlb, hw.ilb

omLibMgr = new omLibMgrType("hw");
if (omLibMgr==NULL) {omBeep(); return 1;} // enough memory?
if (!omLibMgr) {omBeep(); return omLibMgr->lastErr;} // init ok?

RegisterCallback(0, myMoveTo, myLineTo); // DDJ callbacks

dispHelp = new omDispHelpBlock( 100, 4*omFontHeight, 0,0);
dispHelp->usedNew = TRUE;
dispHelp->pageBkColor = LIGHTGRAY;
dispHelp->theDress = RIDGE;

//------- FILE MENU: allocate and assign items to the "File" pulldown menu

hwFileMenu *fileMenu = new hwFileMenu(4);
if (fileMenu==NULL) return 1;
fileMenu->usedNew = omTRUE;
*fileMenu + "~Open" + "~About" + "_" + "E~xit";
fileMenu->assignId( ID_FILEMENU );
omIDTABLE.add(ID_FILEMENU, fileMenu);
fileMenu->setEventHelp( "file" ); // set help prefix
fileMenu->setDisplayHelp( dispHelp ); // attach help

//------- EDIT MENU: allocate and assign items to the "Edit" pulldown menu

omVertMenu *editMenu = new omVertMenu( 5 );
if (editMenu==NULL) return 1;
editMenu->usedNew = omTRUE;
*editMenu + "~Cut" + DISABLE + "~Copy" + "?copy" //+ DISABLE
+ "~Paste" + DISABLE + "_" + "Undo" + DISABLE + IS_TEAROFF;
editMenu->setEventHelp( "edit" ); // set help prefix
editMenu->setDisplayHelp( dispHelp ); // attach help

//------- OPTION MENU: allocate and assign items to the "Edit" pulldown menu

hwOptMenu *optMenu = new hwOptMenu( 2 );
if (optMenu==NULL) return 1;
optMenu->usedNew = omTRUE;
*optMenu + "~Open new browser !!"
+ "?open" + "~Single letter !!" + "?single";
optMenu->setEventHelp( "optmenu" ); // set help prefix
optMenu->setDisplayHelp( dispHelp ); // attach help

//------- TOP MENU: allocate and assign items to Horizontal menu bar

omHorizMenu *topMenu = new omHorizMenu( 6 );
if (topMenu==NULL) return 1;
topMenu->usedNew = omTRUE;
*topMenu + "~File" + "?file" + *fileMenu
+ "~Edit" + "?edit" + *editMenu
+ "~Browse" + "?browse" + *optMenu
+ "~Printer| setup" + "?printcfg" + psetup
+ "dela~yed|help" + omIconFcnRadioDiam + changeHelpTimeOut
+ "?delayedhelp" + IS_RADIO
+ "~immediate|help" + omIconFcnRadioDiam + changeHelpTimeOut
+ "?immedhelp";

if ( omPrefs.helpTimeout>0 ) topMenu->autoRadioToggle(4); // delayed help
else topMenu->autoRadioToggle(5); // immed help

topMenu->setEventHelp( "topmenu" ); // set help prefix
topMenu->setDisplayHelp( dispHelp ); // attach help
topMenu->assignId(ID_TOPMENU);

//------------ WINDOW: define the window

omBkWindow *w = new omBkWindow(); w->bkColor = CYAN;
if (w==NULL) return 1;
w->usedNew = omTRUE;

w->setTitle("Island Systems Handwriting Utility"
" Rev 1.1|Dr. Dobb's Journal, October 1992");
w->assignId(ID_BKWINDOW);
w->setDrawModeBk( omCOLOR );

*w + *topMenu + omTL + *dispHelp + omBL;
w->makeTask();

//------------- RUN: put the window on the event Queue and run.
*omMEQ + *w;
omMEQ->run();

return 0;
}




[LISTING FOUR]

/****** LIANT ******/

#include "about.h"
#include "brush.h"
#include "bttnrbbn.h"
#include "button.h"
#include "charview.h"
#include "file.h"
#include "fileslct.h"
#include "font.h"
#include "hwxappvw.h"
#include "notifier.h"
#include "objarray.h"
#include "pen.h"
#include "pointrry.h"
#include "popupmen.h"
#include "port.h"
#include "printer.h"
#include "printdlg.h"
#include "printab.h"
#include "statusbr.h"

#include // for sprintf()

#define BR_HT 40 // height of the Button Bar window
#define STAT_HT 24 // height of the Status Bar window

defineClass(HwxAppView, VAppView)

/* menu definition (could also come from a resource) */
char *file[] = { "&Open...", "",
"&Print...", "",
"&About...", "",
"E&xit", 0
};
method fmthds[] = { methodOf(HwxAppView, openFile),NIL_METHOD,
methodOf(HwxAppView, print),NIL_METHOD,
methodOf(HwxAppView, about),NIL_METHOD,
methodOf(HwxAppView, closeApp),NIL_METHOD
};
char *display[] = { "&Style...", "",
"&Instance",
"&Alphabet",
0
};
method dmthds[] = { methodOf(HwxAppView, setDisplayStyle),NIL_METHOD,
methodOf(HwxAppView, showByInstance),
methodOf(HwxAppView, showByAlphabet),NIL_METHOD
};
/* icon bar definition */
char *bttns[] = { "FILEBOX","PRINTER","PALETTE","ALPHA",0};
method bMthds[] = {
methodOf(HwxAppView, btnOpen),
methodOf(HwxAppView, btnPrint),
methodOf(HwxAppView, btnStyle),
methodOf(HwxAppView, btnAlpha),
NIL_METHOD
};
HwxAppView::HwxAppView()
{
/* set title and background brush for main window */
setTitle("Liant HWX: (no file loaded)");
setBackground(new VBrush(BLUE));
/* create the icon bar */
bttnRbbn = new ButtonRibbon(VFrame(0, 0, 1.0F, BR_HT),
this, this, bttns, bMthds);
/* create a status bar */
int x, y, w, h;
getArea(&x, &y, &w, &h);
statBar = new StatusBar(VFrame(0, h - STAT_HT, 1.0F, STAT_HT), this);
statBar->putText("HWX Browser");
statBar->setFont(new VFont("TMS RMN", 10));
/* create the pull down menu (using arrays defined above) */
VPopupMenu *pm = new VPopupMenu("&File");
addPopup(pm);
pm->addItems(file, fmthds, this);
displayMenu = new VPopupMenu("&Display");
addPopup(displayMenu);
displayMenu->addItems(display, dmthds, this);
displayMenu->enableAll(FALSE);
displayMenu->checkAt(TRUE, 2);
/* create the single character view sub-window */
charView = new CharacterView(VFrame(10, 50, 100, 100), this);
/* create the multi-instance view sub-window */
multiView = new MultiCellView(VFrame(130, 50, 7 * 60, 200), this);
multiView->setDims(6, 13, 30, 30);
multiView->uponClick(this, methodOf(HwxAppView, multiSelect));
/* create the character selection sub-window */
selectView = new AlphaCellView(VFrame(10, 300,
17 * 32 + 6, 17 * 3 + 6), this);
selectView->setDims(3, 32, 17, 17);
selectView->uponClick(this, methodOf(HwxAppView, charSelect));
/* create pen for drawing single character instance */
charPen = new VPen();
charData = 0;
byInstance = TRUE;
setCharacter(48, 0);
}
HwxAppView::~HwxAppView()
{
/* destroy status bar font */
VFont *f = statBar->getFont();
if (f) {
f->free();
}
/* destroy background brush */
if (getBackground()) {
delete getBackground();
}
/* destroy character pen */
if (charPen) {
delete charPen;
}
/* destroy associated character data */
if (charData) {
delete charData;
}
}
boolean HwxAppView::free()
{
delete this;
return(TRUE);
}
boolean HwxAppView::paint()
{
VPort port(this);
int x, y, w, h;
getArea(&x, &y, &w, &h);
port.open();
/* draw a separator above the staus bar */
port.moveTo(0, h - STAT_HT - 1);
port.lineTo(w, h - STAT_HT - 1);
port.close();
return(TRUE);
}
boolean HwxAppView::resized(int w,int h) // called when window changes size.
{
// resize the ButtonRibbon
bttnRbbn->resize(w, BR_HT);
// move the StatusBar up to bottom of MDI client
statBar->move(0, h - STAT_HT, w, STAT_HT);
return(TRUE);
}
boolean HwxAppView::openFile(VMenuItem *m) // Load a new data file
{
VString *temp;
VString filter("*.dat");
char str[100];
temp = VFileSelect::dialog(this, "Select Data File", NIL, &filter);
if (temp) {
notifier->beginWait();
statBar->putText("Loading File...");
VFile f(temp->gets());
if (f.open(ReadOnly)) {
if (charData != 0) {
delete charData;
charData = 0;
}
charData = new CharacterData(f);
f.close();
/* update window title */
sprintf(str, "Liant HWX: (%s)", temp->gets());
setTitle(str);
/* enable display menu */
displayMenu->enableAll(TRUE);
}
notifier->endWait();
setCharacter(48, 0);
}
return(TRUE);
}
boolean HwxAppView::closeApp(VMenuItem *m) // Close the application
{
return(VAppView::close());
}
boolean HwxAppView::print(VMenuItem *m) // Print the current character.
{
VPrinter *printer = 0;
/* get a printer object via the printer dialog */
boolean ret = VPrintDialog::print(NIL, &printer, this);
if (!ret) {
statBar->putText("Printer not ready.");
}
else {
/* display the print abort dialog */
VPrintAbort *pab = new VPrintAbort("HWX",
"Printing character.", printer, this);
/* open a port on the printer */
VPort port(printer);
VRectangle rect(CornerDim, 50, 50, 300, 300);
port.open();
/* draw the character on the printer */
charView->drawCharacter(&port, &rect, 5.0);
// printer->newPage();
port.close();
pab->free();
printer->free();
}
return(TRUE);
}
boolean HwxAppView::about(VMenuItem *m) // Display the About box
{
VAbout::dialog("Liant HWX Browser\n\n) 1992 by Liant Software Corp."
"\nWritten by Joe DeSantis\n"
"\nDeveloped with C++/Views 2.0", this);
return(TRUE);
}
boolean HwxAppView::setDisplayStyle(VMenuItem *m)
/* Put up a dialog, and set the width and color of the character display. */
{
int width;
rgbColor color;
width = charPen->width();
color = charPen->color();
DisplayDialog::dialog(this, &width, &color);
charPen->width(width);
charPen->color(color);
charView->update();
return(TRUE);
}
boolean HwxAppView::showByAlphabet(VMenuItem *m)
{
displayMenu->checkAt(FALSE, 2);
displayMenu->checkAt(TRUE, 3);
setByInstance(FALSE);
return(TRUE);
}
boolean HwxAppView::showByInstance(VMenuItem *m)
{
displayMenu->checkAt(TRUE, 2);
displayMenu->checkAt(FALSE, 3);
setByInstance(TRUE);
return(TRUE);
}
void HwxAppView::setCharacter(int cno, int ino)
{ // Set the current character/instance displayed.
char str[100];
currChar = cno;
currInst = ino;
int icount = (charData) ? charData->getInstanceCount(currChar) : 0;
/* update status bar */
sprintf(str, "Character %d, Instance %d out of %d",
currChar, currInst, icount);
statBar->putText(str);
/* update views */
charView->setCharData(charData, currChar, currInst);
multiView->setCharData(charData, currChar, currInst);
selectView->setCharData(currChar, currInst);
}
void HwxAppView::charSelect(long row, long col)
{ // AlphaCellView box clicked in cell row, col
if (byInstance) { /* view a new character */
setCharacter((int) ((row + 1) * 32 + col), currInst);
}
else { /* view a new instance */
setCharacter(currChar, (int) (row * 16 + col));
}
}
void HwxAppView::multiSelect(long row, long col)
{ // MultiCellView box clicked in cell row, col
if (byInstance) {
/* view a new instance */
setCharacter(currChar, (int) (row * 13 + col));
}
else {
/* view a new character */
setCharacter((int) (row * 13 + col + 48), currInst);
}
}
void HwxAppView::setByInstance(boolean tf)
/* Specifies whether to display all instances of a single character,
or an alphabet of a specific instance. */
{
if (byInstance != tf) {
byInstance = tf;
if (tf) {
selectView->setDims(3, 32, 17, 17);
}
else {
selectView->setDims(3, 16, 34, 17);
}
multiView->setByInstance(tf);
selectView->setByInstance(tf);
setCharacter(48, 0);
selectView->update();
}
}
boolean HwxAppView::btnOpen(VButton *b) // Callback for file icon
{
openFile(NIL);
return(TRUE);
}
boolean HwxAppView::btnPrint(VButton *b) // Callback for print icon
{
print(NIL);
return(TRUE);
}
boolean HwxAppView::btnStyle(VButton *b) // Callback for style icon
{
setDisplayStyle(NIL);
return(TRUE);
}
boolean HwxAppView::btnAlpha(VButton *b)// Callback for alpha/instance icon
{
if (byInstance) {
showByAlphabet(NIL);
}
else {
showByInstance(NIL);
}
return(TRUE);
}



[LISTING FIVE]

/****** MICROSOFT ******/

//------ CHwbDlg: The main user interface to this application is a dialog
class CHwbDlg : public CModalDialog
{
// Constructors
public:
CHwbDlg();
~CHwbDlg();
// Attributes
// global state of browser
COLORREF m_colorCur;
int m_nLineWidth;
// current state (based on selection in .DAT file)
BOOL m_bLoaded; // .DAT file loaded
char m_chCur; // current character
int m_nInstanceCount; // number of instance of this character
int m_iInstanceCur; // current instance of that character
// Operations
void RenderInstance(CDC* pDC, char ch, int iInstance,
CRect rect, int inflate, BOOL bAttrib);
// Implementation
CImageBox m_charBox; // all possible characters
protected:
// brushes for drawing
CBrush m_brBack, m_brGray;
CFont m_statusFont;
// special controls
CBitmapButton m_buttons[NUM_BITMAPBUTTONS];
CImageBox m_imageBox; // image selection
CStatic m_display; // display output control
CScrollBar m_scrollBar;
CRect GetOutputRect();
// message handlers
virtual BOOL OnInitDialog();
virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
afx_msg void OnPaint();
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*);
afx_msg void OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu);
// command handlers
afx_msg void OnOpen();
afx_msg void OnCopy();
afx_msg void OnPrint();
afx_msg void OnAbout();
afx_msg void OnPrevChar();
afx_msg void OnNextChar();
afx_msg void OnLineColor();
// control notification handlers
afx_msg void OnInstanceSelect();
afx_msg void OnCharSelect();
#ifdef _DEBUG
afx_msg void OnShowStrokes();
#endif
DECLARE_MESSAGE_MAP()
};
// Message map defines messages handled by our main window
BEGIN_MESSAGE_MAP(CHwbDlg, CModalDialog)
ON_WM_PAINT()
ON_WM_HSCROLL()
ON_WM_MENUSELECT()
ON_COMMAND(IDM_OPEN, OnOpen)
ON_COMMAND(IDM_COPY, OnCopy)
ON_COMMAND(IDM_PRINT, OnPrint)
ON_COMMAND(IDM_ABOUT, OnAbout)
ON_COMMAND(IDC_PREV, OnPrevChar)
ON_COMMAND(IDC_NEXT, OnNextChar)
ON_COMMAND(IDM_LINE_COLOR, OnLineColor)
#ifdef _DEBUG // debug commands
ON_COMMAND(IDM_DEBUG_SHOW_STROKES, OnShowStrokes)
#endif //_DEBUG
ON_CBN_SELCHANGE(IDC_INSTANCE_BOX, OnInstanceSelect)
ON_CBN_SELCHANGE(IDC_ALLCHARS_BOX, OnCharSelect)
END_MESSAGE_MAP()
//-----------------------------------------------------------------
CHwbDlg::CHwbDlg()
: CModalDialog("MAINDIALOG"),
m_brBack(::GetSysColor(COLOR_WINDOW)),
m_brGray(RGB(128, 128, 128))
{
m_bLoaded = FALSE;
m_colorCur = RGB(0, 0, 0); // black to start with
m_nLineWidth = 1;
}
//-----------------------------------------------------------------
CHwbDlg::~CHwbDlg()
{
if (m_bLoaded)
::UnloadHWXData(); // free old data file
}
//-----------------------------------------------------------------
BOOL CHwbDlg::OnInitDialog()
{
// initialize bitmap buttons
for (int i = 0; i < NUM_BITMAPBUTTONS; i++)
VERIFY(m_buttons[i].AutoLoad(IDC_BITMAPBUTTON_MIN + i, this));
// wire in the dialog controls
VERIFY(m_imageBox.SubclassDlgItem(IDC_INSTANCE_BOX, this));
m_imageBox.m_pParent = this;
VERIFY(m_charBox.SubclassDlgItem(IDC_ALLCHARS_BOX, this));
m_charBox.m_pParent = this;
VERIFY(m_scrollBar.SubclassDlgItem(IDC_SCROLLBAR, this));
// select a lighter font for the status bar
LOGFONT logfont;
GetFont()->GetObject(sizeof(logfont), &logfont);
logfont.lfWeight = FW_NORMAL;
VERIFY(m_statusFont.CreateFontIndirect(&logfont));
GetDlgItem(IDC_STATUS)->SetFont(&m_statusFont);
OnOpen(); // require an open data file
if (!m_bLoaded)
EndDialog(IDCANCEL); // abort
return TRUE;
}
//-----------------------------------------------------------------
void CHwbDlg::OnOpen()
{
CFileDialog dlg(TRUE, "dat", NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY,
"Data Files (*.dat)|*.dat|All Files (*.*)|*.*||");
// constructor for standard file open dialog
if (dlg.DoModal() != IDOK)
return; // stay with old data file
HCURSOR hCurs = ::SetCursor(::LoadCursor(NULL, IDC_WAIT));
// set the wait cursor
if (m_bLoaded)
::UnloadHWXData(); // free old data file
// open new data file
::LoadHWXData(dlg.GetPathName());
m_bLoaded = TRUE;
// fill listbox with all valid characters using exported Dr. Dobbs APIs
m_charBox.ResetContent();
for (char ch = 0; ch <= 126; ch++) // simple ASCII range
{
if (::GetInstanceCount(ch) == 0)
continue; // skip characters with no instances
int nIndex = m_charBox.AddString(MAKEINTRESOURCE(ch));
if (ch == 'A')
m_charBox.SetCurSel(nIndex); // initial selection
}
OnCharSelect(); // update instances
::SetCursor(hCurs); // change cursor back to standard
}
//-----------------------------------------------------------------
void CHwbDlg::OnCopy()
{
// copy current image to clipboard
if (!OpenClipboard())
return;
CMetaFileDC dc;
if (dc.Create())
{
RenderInstance(&dc, m_chCur, m_iInstanceCur, CRect(0,0,0,0), 0, TRUE);
HGLOBAL hData = ::GlobalAlloc(GPTR, sizeof(METAFILEPICT));
if (hData != NULL)
{
LPMETAFILEPICT lpMFP = (LPMETAFILEPICT)::GlobalLock(hData);
lpMFP->mm = MM_ANISOTROPIC;
lpMFP->hMF = dc.Close();
VERIFY(EmptyClipboard());
::GlobalUnlock(hData);
SetClipboardData(CF_METAFILEPICT, hData);
}
VERIFY(CloseClipboard());
}
}
//-----------------------------------------------------------------
void CHwbDlg::OnPrint()
{
// print the current image
CPrintDialog dlg(FALSE, PD_NOPAGENUMS | PD_NOSELECTION);
if (dlg.DoModal() != IDOK)
return;
HCURSOR hCurs = ::SetCursor(::LoadCursor(NULL, IDC_WAIT));
// set the wait cursor
CDC dc;
dc.Attach(dlg.GetPrinterDC());
CRect rect;
dc.GetClipBox(rect);
dc.StartDoc("HandWriting");
dc.StartPage();
RenderInstance(&dc, m_chCur, m_iInstanceCur, rect, 0, FALSE);
dc.EndPage();
dc.EndDoc();
::SetCursor(hCurs); // return to standard cursor
}
void CHwbDlg::OnAbout()
{
CModalDialog dlg("ABOUTDIALOG");
dlg.DoModal();
}
void CHwbDlg::OnNextChar()
{
m_charBox.SetCurSel(m_charBox.GetCurSel() + 1);
OnCharSelect();
}
void CHwbDlg::OnPrevChar()
{
m_charBox.SetCurSel(m_charBox.GetCurSel() - 1);
OnCharSelect();
}
void CHwbDlg::OnCharSelect()
{
ASSERT(m_bLoaded);
if (m_charBox.GetCurSel() == -1)
m_charBox.SetCurSel(0); // select first one
m_chCur = (char)m_charBox.GetItemData(m_charBox.GetCurSel());
// update the character indicator and box
SetDlgItemText(IDC_CHARACTER, CString(m_chCur));
m_nInstanceCount = ::GetInstanceCount(m_chCur);
m_scrollBar.SetScrollRange(0, m_nInstanceCount-1);
// update the list of possible instances
m_imageBox.ResetContent();
for (int i = 0; i < m_nInstanceCount; i++)
m_imageBox.InsertString(i, NULL); // data not used
m_imageBox.SetCurSel(m_iInstanceCur = 0); // start at first one
OnInstanceSelect(); // initial update
}
void CHwbDlg::OnInstanceSelect()
{
int iSel = m_imageBox.GetCurSel();
if (iSel != -1)
{
ASSERT(iSel >= 0 && iSel < m_nInstanceCount);
m_iInstanceCur = iSel;
}
// update output
ASSERT(m_bLoaded);
ASSERT(m_iInstanceCur >= 0 && m_iInstanceCur < m_nInstanceCount);
m_scrollBar.SetScrollPos(m_iInstanceCur);
InvalidateRect(GetOutputRect(), FALSE); // will redraw at paint time
}
//-------- Encapsulated drawing code
CRect CHwbDlg::GetOutputRect()
{
CRect rect;
GetDlgItem(IDC_OUTPUT)->GetWindowRect(rect);
ScreenToClient(rect);
rect.InflateRect(-2, -2); // leave border alone
return rect;
}
//----- functions to map Dr Dobbs API calls to CDC member functions
static void _MoveTo(CDC* pDC, int x, int y)
{ pDC->MoveTo(x, y); }
static void _LineTo(CDC* pDC, int x, int y)
{ pDC->LineTo(x, y); }
//------- Render a character in the DC passed in. All drawing takes place here
void CHwbDlg::RenderInstance(CDC* pDC, char ch, int iInstance,
CRect rect, int inflate, BOOL bAttrib)
{
// fill in background
if (inflate)
pDC->FillRect(rect, &m_brBack);
if (iInstance < 0)
return; // nothing more to do
rect.InflateRect(inflate, inflate);
if (inflate != 0 && bAttrib)
pDC->FrameRect(rect, &m_brGray);
pDC->SaveDC();
// draw scaled to fit with optional attributes
CPen pen(PS_INSIDEFRAME, m_nLineWidth*2+1, m_colorCur);
if (bAttrib)
pDC->SelectObject(&pen);
pDC->SetMapMode(MM_ANISOTROPIC);
if (!rect.IsRectEmpty())
{
pDC->SetViewportExt(rect.Size());
pDC->SetViewportOrg(rect.TopLeft());
}
CRect rect2 = ::CalcInstanceBoundingBox(ch, iInstance);
pDC->SetWindowExt(rect2.Size());
pDC->SetWindowOrg(rect2.TopLeft());
::RegisterCallback(pDC, _MoveTo, _LineTo);
::DisplayInstance(ch, iInstance);
pDC->RestoreDC(-1);
}
void CHwbDlg::OnPaint()
{
CPaintDC dc(this);
RenderInstance(&dc, m_chCur, m_iInstanceCur, GetOutputRect(), -10, TRUE);
}
void CHwbDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*)
{
static int deltas[] = { -1, 1, -1, 1, 0, 0, -1000, 1000, 0 };
int iSel = nPos;
if (nSBCode != SB_THUMBTRACK && nSBCode != SB_THUMBPOSITION)
iSel = m_iInstanceCur + deltas[nSBCode];
if (iSel < 0)
iSel = 0;
else if (iSel >= m_nInstanceCount)
iSel = m_nInstanceCount-1;
m_imageBox.SetCurSel(iSel);
OnInstanceSelect();
}
// menu prompt string tracking
void CHwbDlg::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU)
{
CString strPrompt;
if (nItemID != 0 &&
!(nFlags & (MF_SEPARATOR|MF_POPUP|MF_MENUBREAK|MF_MENUBARBREAK)))
strPrompt.LoadString(nItemID);
SetDlgItemText(IDC_STATUS, strPrompt);
}
// Line width: handle with one function for efficiency for a range of commands
BOOL CHwbDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
int nWidth = LOWORD(wParam) - IDM_LINE_WIDTH_BASE;
if (nWidth < 0 || nWidth >= MAX_LINE_WIDTH)
return CModalDialog::OnCommand(wParam, lParam); // not line width
m_nLineWidth = nWidth;
// update the menu
for (int i = 0; i < MAX_LINE_WIDTH; i++)
GetMenu()->CheckMenuItem(IDM_LINE_WIDTH_BASE + i,
(i == m_nLineWidth) ? MF_CHECKED : MF_UNCHECKED);
InvalidateRect(GetOutputRect(), FALSE); // redraw
return TRUE;
}
void CHwbDlg::OnLineColor()
{
CColorDialog dlg(m_colorCur);
if (dlg.DoModal() != IDOK)
return;
m_colorCur = dlg.GetColor();
InvalidateRect(GetOutputRect(), FALSE);
}





  3 Responses to “Category : Files from Magazines
Archive   : DDJ9210.ZIP
Filename : OOPAFX.ASC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/