home *** CD-ROM | disk | FTP | other *** search
- // Program : EXPDEMO.CPP
- // Author : Eric Woodruff, CIS ID: 72134,1150
- // Updated : Wed 08/25/93 10:02:42
- // Note : Copyright 1993, Eric Woodruff, All rights reserved
- // Compiler: Borland C++ 3.1
- //
- // This is a demonstration program that puts the TExplodeWindow
- // and TExplodeDialog classes through their paces. One demo lets you see
- // an exploding window while another lets you see an exploding dialog box.
- // The last two demonstrations are streamable variations on the first two
- // from a resource file.
- //
- // NOTE: Change the IDE Compiler Directories if necessary and turn on the
- // debugger options if needed when using the supplied EXPDEMO.PRJ.
- //
-
- #include <conio.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #define Uses_MsgBox
- #define Uses_TApplication
- #define Uses_TButton
- #define Uses_TDeskTop
- #define Uses_TCheckBoxes
- #define Uses_TDialog
- #define Uses_TEvent
- #define Uses_TInputLine
- #define Uses_TKeys
- #define Uses_TLabel
- #define Uses_TMenuBar
- #define Uses_TMenuItem
- #define Uses_TProgram
- #define Uses_TRadioButtons
- #define Uses_TRect
- #define Uses_TResourceFile
- #define Uses_TScreen
- #define Uses_TSItem
- #define Uses_TStaticText
- #define Uses_TStatusDef
- #define Uses_TStatusItem
- #define Uses_TStatusLine
- #define Uses_TSubMenu
- #define Uses_fpstream
- #include <tv.h>
-
- extern TPoint shadowSize; // Used for changing screen modes.
-
- __link(RButton)
- __link(RCheckBoxes)
- __link(RCluster )
- __link(RInputLine)
- __link(RLabel)
- __link(RMenuBar)
- __link(RRadioButtons)
- __link(RResourceCollection)
- __link(RStaticText)
- __link(RStatusLine)
-
- #define Uses_TExplodeWindow
- #define Uses_TExplodeDialog
- #include <texplode.h> // TExplodeWindow/TExplodeDialog header file.
- #include <expdemo.h> // Demo header file
-
- // NOTE: Always be sure to include these two lines somewhere in your
- // program if you are using streamed TExplodeWindow and/or
- // TExplodeDialog objects (i.e. loading them from a resource file)!
- __link(RExplodeWindow)
- __link(RExplodeDialog)
-
- // Function that returns True when there is a tileable window in the desktop.
- static Boolean isTileable(TView *p, void *);
-
- // ****************************************************************************
- // Demonstration declarations and variables.
-
- // Resource file pointers.
- fpstream *s;
- TResourceFile *rsc;
-
- // ****************************************************************************
- // Application declarations.
- //
- TMyApplication::TMyApplication(void) :
- TProgInit(&TMyApplication::initStatusLine, &TMyApplication::initMenuBar,
- &TMyApplication::initDeskTop)
- {
- TEvent event;
-
- // If you haven't got the Turbo Vision source code or don't want to
- // modify it, uncomment this line to speed up the screen updates.
- //
- // TScreen::checkSnow = False; // Turn off snow checking.
-
- event.what = evCommand;
- event.message.command = cmAboutCmd;
- putEvent(event);
- }
-
- #pragma argsused
- TMenuBar *TMyApplication::initMenuBar(TRect r)
- {
- return (TMenuBar *)rsc->get("MenuBar");
- }
-
- #pragma argsused
- TStatusLine *TMyApplication::initStatusLine(TRect r)
- {
- return (TStatusLine *)rsc->get("StatusLine");
- }
-
- void TMyApplication::handleEvent(TEvent &event)
- {
- TApplication::handleEvent(event);
-
- if(event.what == evCommand)
- {
- switch (event.message.command)
- {
- case cmAboutCmd:
- deskTop->execView((TDialog *)rsc->get("AboutBox"));
- break;
-
- case cmCloseTileable:
- while(deskTop->firstThat(isTileable, 0))
- message(deskTop, evCommand, cmClose, NULL);
- break;
-
- case cmScreenSize: // Change screen modes.
- ushort NewSize = TScreen::screenMode ^ TDisplay::smFont8x8;
-
- if(NewSize & TDisplay::smFont8x8)
- shadowSize.x = 1;
- else
- shadowSize.x = 2;
-
- setScreenMode(NewSize);
-
- // Adjust mouse limits if present.
- if(TMouse::present())
- TMouse::setRange(TScreen::screenWidth - 1,
- TScreen::screenHeight - 1);
- break;
-
- case cmTile: // Tile current windows
- deskTop->tile(deskTop->getExtent());
- break;
-
- case cmCascade: // Cascade current windows
- deskTop->cascade(deskTop->getExtent());
- break;
-
- case cmDemo1: // TExplodeWindow demo.
- Demo1();
- break;
-
- case cmDemo2: // TExplodeDialog demo.
- Demo2();
- break;
-
- case cmDemo3:
- // Get TExplodeWindow from stream. Does what Demo1() does
- // but restores objects from the resource file.
- TExplodeWindow *xw = (TExplodeWindow *)rsc->get("Demo3");
-
- if(validView(xw))
- deskTop->insert(xw);
- break;
-
- case cmDemo4:
- // Get TExplodeDialog from stream. Does what Demo2() does
- // but restores objects from the resource file.
- TExplodeDialog *xd = (TExplodeDialog *)rsc->get("Demo4");
-
- if(validView(xd))
- {
- deskTop->execView(xd);
- destroy(xd);
- }
- break;
-
- default:
- return;
- }
- clearEvent(event);
- }
- }
-
- void TMyApplication::Demo1(void)
- {
- randomize();
-
- // Randomly select an initial size and position.
- TRect r(0, 0, 20 + rand() % 53, 6 + rand() % 16);
-
- r.move(rand() % 30, rand() % 10);
-
- TExplodeWindow *xw = new TExplodeWindow(r, "Demo Exploding Window", 0);
- xw->MakeItExplode(rand() % 50); // Random delay.
-
- // Make it tileable and let it grow and shrink with the screen mode.
- xw->options |= ofTileable;
- xw->growMode = gfGrowAll | gfGrowRel;
-
- r = xw->getExtent();
- r.grow(-1, -1);
-
- TStaticText *s = new TStaticText(r, "This is a test.");
- s->growMode = gfGrowHiX | gfGrowHiY;
- xw->insert(s);
-
- if(validView(xw))
- deskTop->insert(xw);
- }
-
- void TMyApplication::Demo2(void)
- {
- TExplodeDialog *dlg = new TExplodeDialog(TRect(4,0,76,22),
- "General Information");
-
- if(!dlg)
- return;
-
- dlg->options = ofCentered;
-
- TButton *b = new TButton(TRect(30,19,42,21), "O~K~", cmOK, bfDefault);
- b->options = ofCenterX;
- dlg->insert(b);
-
- TStaticText *s = new TStaticText(TRect(15,2,56,4),
- "\003TExplodeWindow and TExplodeDialog Classes\n"
- "\003by Eric Woodruff");
- s->options = ofCenterX;
- dlg->insert(s);
-
- s = new TStaticText(TRect(3,5,69,11),
- "\003If you use these classes in your own programs, please send"
- " $10 to:\n\003\n\003Eric Woodruff\n"
- "\00316719 Lakeside Drive\n"
- "\003Medical Lake WA 99022");
- s->options = ofCenterX;
- dlg->insert(s);
-
- s = new TStaticText(TRect(3,11,69,15),
- "Feel free to distribute these files to anyone but please distribute"
- " all of them in UNMODIFIED form. If you find any bugs or make any"
- " interesting changes, please let me know so that I can maintain"
- " these classes and distribute updates.");
- s->options = ofCenterX;
- dlg->insert(s);
-
- s = new TStaticText(TRect(8,16,64,18),
- "\003I can also be reached on CompuServe at 72134,1150\n"
- "\003Thanks for trying them out!");
- s->options = ofCenterX;
- dlg->insert(s);
-
- dlg->selectNext(False);
- if(validView(dlg))
- {
- deskTop->execView(dlg);
- destroy(dlg);
- }
- }
-
- // ****************************************************************************
- void main(void)
- {
- s = new fpstream("EXPDEMO.RSC", ios::in | ios::nocreate | ios::binary);
- if(!s->good())
- {
- cerr << "Error opening resource file EXPDEMO.RSC! Press any key.";
- getch();
- exit(1);
- }
-
- rsc = (TResourceFile *)new TResourceFile(s);
- if(!rsc)
- {
- cerr << "Could not allocate resource file memory!";
- exit(1);
- }
-
- TMyApplication MyApp;
- MyApp.run();
- exit(0);
- }
-
- //
- // The isTileable() function checks for a tileable view on the desktop.
- //
- static Boolean isTileable(TView *p, void *)
- {
- return (p->options & ofTileable) ? True : False;
- }
-