home *** CD-ROM | disk | FTP | other *** search
- /*
- Please excuse my "ignorance" in all of this, but this thing
- is based on the CALC.CPP code in the TVision demos directory.
-
- I don't know what everything does (yet) so if some things are
- inefficient, or not required, don't blame me - I'm still learning
-
- If you have questions that I might be able to answer,
- leave a message to Ernest W Johnson in Borland progB under
- DOS Frameworks - my CIS ID is: 70751,2567
- */
-
-
- //
- // Not sure if I need all of these, but what the heck <grin>
- //
- #define Uses_TBackground
- #define Uses_TListBox
- #define Uses_TMenu
- #define Uses_TMenuBar
- #define Uses_TMenuItem
- #define Uses_TScrollBar
- #define Uses_TStaticText
- #define Uses_TStatusDef
- #define Uses_TStatusItem
- #define Uses_TStatusLine
- #define Uses_TStringCollection
- #define Uses_MsgBox
- #define Uses_TEventQueue
- #define Uses_TApplication
- #define Uses_TRect
- #define Uses_TDeskTop
- #define Uses_TView
- #define Uses_TWindow
- #define Uses_TDialog
- #define Uses_TButton
- #define Uses_StaticText
- #define Uses_TSItem
- #define Uses_TLabel
- #define Uses_TInputLine
- #define Uses_TEvent
- #define Uses_TKeys
- #define Uses_TDrawBuffer
- #define Uses_TStreamableClass
- #define Uses_TStreamable
-
- #include <tv.h>
- __link( RView )
- __link( RDialog )
- __link( RButton )
-
- #include <dos.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <strstrea.h>
- #include <iomanip.h>
- #include <conio.h>
-
- #include "calc.h"
-
- const cmAboutCmd = 100; // User selected menu item 'About'
- const cmStatusCmd = 101; // User selected menu item 'List'
-
-
- TCalcDisplay::TCalcDisplay(TRect& r) : TView ( r )
- {
- options |= ofSelectable;
- eventMask = (evKeyboard | evBroadcast);
- dnfile= new char[DISPLAYLEN];
- strcpy(dnfile,"0");
- }
-
- TCalcDisplay::~TCalcDisplay()
- {
- delete dnfile;
- }
-
- void TCalcDisplay::handleEvent(TEvent& event)
- {
- TView::handleEvent(event);
-
- switch(event.what)
- {
- case evKeyboard:
- calcKey(event.keyDown.charScan.charCode);
- clearEvent(event);
- break;
- case evBroadcast:
- if(event.message.command == cmOK)
- {
- calcKey( ((TButton *) event.message.infoPtr)->title[0]);
- clearEvent(event);
- }
- break;
- }
- }
-
- void TCalcDisplay::draw()
- {
- char color = getColor(1);
- int i;
- TDrawBuffer nbuf;
- char Buf[DISPLAYLEN+1];
-
- nbuf.moveChar(0,' ',color,size.x);
-
- sprintf(Buf," %s",dnfile);
- nbuf.moveStr(0,Buf,color);
-
- writeLine(0, 0, size.x, 1, nbuf);
- }
-
- void TCalcDisplay::calcKey(unsigned char key)
- {
- ShowFiles("C:\\");
- strcpy(dnfile,"Press any key.");
- drawView();
- getch();
- message(owner,evCommand,cmOK,this); // close dialog box
- }
-
- TCalculator::TCalculator() :
- TDialog( TRect(5, 3, 69, 18), "Add Files" ),
- TWindowInit( &TCalculator::initFrame )
- {
- TView *tv;
- TRect r;
-
- options |= ofFirstClick;
- options |= ofCentered;
-
- r = TRect( 5, 9, 16, 11 );
- tv = new TButton( r, "~G~o 4 It", cmOK, bfNormal | bfBroadcast );
- tv->options &= ~ofSelectable;
- insert( tv );
- insert(
- new TButton( TRect( 26, 9, 37, 11 ), "~A~bort", cmCancel, bfNormal ) );
-
- insert(
- new TStaticText(TRect(2,3,15,6),"Directory:"));
-
- insert(new TCalcDisplay(TRect(14,3,61,4)));
- }
-
- //
- // The ShowFiles() function does its thing with the data "members" (?)
- // and calls drawView() whenever the display needs updating
- //
- void TCalcDisplay::ShowFiles(char *directory)
- {
- for(int x=0;x<=10;x++)
- {
- sprintf(dnfile,"Count %d",x);
- drawView();
- delay(500);
- }
- delay(1000);
- strcpy(dnfile,"All done!");
- drawView();
- }
-
- class TMyApplication : public TApplication
- {
- public:
- TMyApplication();
- static TMenuBar *initMenuBar(TRect);
- void handleEvent(TEvent &);
- private:
- void aboutDlg();
- void statusDlg();
- };
-
- TMyApplication::TMyApplication() :
- TProgInit(&TApplication::initStatusLine,&TMyApplication::initMenuBar,
- &TApplication::initDeskTop)
- {
- }
-
- TMenuBar *TMyApplication::initMenuBar(TRect bounds)
- {
- bounds.b.y = bounds.a.y + 1;
- return(new TMenuBar(bounds,
- new TMenu(
- *new TMenuItem("~A~bout",cmAboutCmd,kbAltA,hcNoContext,0,
- new TMenuItem("~S~tatus Box",cmStatusCmd,kbAltL,hcNoContext,0)))));
- }
-
- void TMyApplication::handleEvent(TEvent &event)
- {
- TApplication::handleEvent(event);
-
- if (event.what == evCommand)
- {
- switch (event.message.command)
- {
- case cmAboutCmd:
- {
- aboutDlg();
- clearEvent(event);
- break;
- }
- case cmStatusCmd:
- {
- statusDlg();
- clearEvent(event);
- break;
- }
- }
- }
- }
-
- void TMyApplication::aboutDlg()
- {
- TDialog *pd = new TDialog(TRect(0,0,35,12),"About");
- if (pd)
- {
- pd->options |= ofCentered;
- pd->insert(new TStaticText(TRect(1,2,34,7),
- "\003Turbo Vision Example\n\003\n"
- "\003Creating a StatusBox\n\003\n"));
- pd->insert(new TButton(TRect(3,9,32,11),"~O~k",cmOK,bfDefault));
-
- if (validView(pd) != 0)
- {
- deskTop->execView(pd);
-
- destroy(pd);
- }
- }
- }
-
- void TMyApplication::statusDlg()
- {
- TCalculator *calc = (TCalculator *) validView(new TCalculator);
- if(calc != 0) {
- message(this,evBroadcast,cmOK,this);
- deskTop->execView(calc);
- }
- }
-
- int main(void)
- {
- TMyApplication myApplication;
-
- myApplication.run();
-
- return 0;
- }
-
-