home *** CD-ROM | disk | FTP | other *** search
- /* Project RichCtrl
- DHB Software
- Copyright ⌐ 1996. All Rights Reserved.
-
- SUBSYSTEM: richctrl.exe Application
- FILE: rchctrla.cpp
- AUTHOR: David H. Borg
-
-
- OVERVIEW
- ========
- Source file for implementation of RichCtrlApp (TApplication).
- */
-
-
- #include <owl\owlpch.h>
- #pragma hdrstop
-
-
- #include "rchctrla.h"
- #include "rchedtcn.h" // Definition of client class.
- #include "rchctrad.h" // Definition of about dialog.
- #include "toolbar.h" // Windows 95 toolbar
- #include "formatbr.h" // Windows 95 toolbar
-
-
- //{{RichCtrlApp Implementation}}
-
-
- //
- // Build a response table for all messages/commands handled
- // by the application.
- //
- DEFINE_RESPONSE_TABLE1(RichCtrlApp, TApplication)
- //{{RichCtrlAppRSP_TBL_BEGIN}}
- EV_COMMAND(CM_FILEPRINT, CmFilePrint),
- EV_COMMAND(CM_FILEPRINTERSETUP, CmFilePrintSetup),
- EV_COMMAND_ENABLE(CM_FILEPRINT, CmPrintEnable),
- EV_COMMAND_ENABLE(CM_FILEPRINTERSETUP, CmPrintEnable),
- EV_COMMAND(CM_HELPABOUT, CmHelpAbout),
- EV_WM_WININICHANGE,
- EV_COMMAND(CM_EXIT, CmExit),
- //{{RichCtrlAppRSP_TBL_END}}
- END_RESPONSE_TABLE;
-
-
- //////////////////////////////////////////////////////////
- // RichCtrlApp
- // =====
- //
- RichCtrlApp::RichCtrlApp () : TApplication("RichCtrl"), rtfModule(0), rtfClient(0)
- {
- Printer = 0;
- Printing = 0;
-
- // INSERT>> Your constructor code here.
- }
-
-
- RichCtrlApp::~RichCtrlApp ()
- {
- if (Printer)
- delete Printer;
-
- // INSERT>> Your destructor code here.
-
- // delete the rich edit control module
- if( rtfModule){
- delete rtfModule;
- rtfModule = 0;
- }
- }
-
-
- //////////////////////////////////////////////////////////
- // RichCtrlApp
- // =====
- // Application intialization.
- //
- void RichCtrlApp::InitMainWindow ()
- {
- if (nCmdShow != SW_HIDE)
- nCmdShow = (nCmdShow != SW_SHOWMINNOACTIVE) ? SW_SHOWNORMAL : nCmdShow;
-
-
- // Ensure that common control DLL is loaded
- InitCommonControls();
-
- // Load the rich edit DLL
- rtfModule = new TModule( "riched32.dll");
-
- // create a RichCtrlWindow based on the Windows 95 Rich Edit DLL
- rtfClient = new RichEditControl( 0, 0, 0, 0, 0, 0, 0, 0, 0, rtfModule);
- SDIDecFrame *frame = new SDIDecFrame(0, GetName(), rtfClient, false);
-
- //
- // Assign ICON w/ this application.
- //
- frame->SetIcon(this, IDI_SDIAPPLICATION);
-
- //
- // Menu associated with window and accelerator table associated with table.
- //
- frame->AssignMenu(SDI_MENU);
-
- //
- // Associate with the accelerator table.
- //
- frame->Attr.AccelTable = SDI_MENU;
-
- // Insert toolbar at the top of the TDecoratedFrame window
- // w=0 & h=0 if using autosize and standard windows bitmaps
- ToolBar *tbar = new ToolBar( frame, IDW_TOOLBAR, 0, 0);
- frame->Insert(*tbar, TDecoratedFrame::Top);
-
- // Insert formatbar at the top of the TDecoratedFrame window
- // w=0 & h=0 if using autosize and some custom windows bitmaps
- FormatBar *fbar = new FormatBar( frame, IDW_TOOLBAR+1, 0, 0);
- frame->Insert(*fbar, TDecoratedFrame::Top);
-
- SetMainWindow(frame);
-
- frame->SetMenuDescr(TMenuDescr(SDI_MENU));
- }
-
-
- //{{SDIDecFrame Implementation}}
-
-
- SDIDecFrame::SDIDecFrame (TWindow *parent, const char far *title, TWindow *clientWnd, bool trackMenuSelection, TModule *module)
- : TDecoratedFrame(parent, title, clientWnd, trackMenuSelection, module)
- {
- // INSERT>> Your constructor code here.
-
- }
-
-
- SDIDecFrame::~SDIDecFrame ()
- {
- // INSERT>> Your destructor code here.
-
- }
-
-
- //////////////////////////////////////////////////////////
- // RichCtrlApp
- // ==========
- // Menu File Print command
- void RichCtrlApp::CmFilePrint ()
- {
- //
- // Create Printer object if not already created.
- //
- if (!Printer)
- Printer = new TPrinter(this);
-
- //
- // Create Printout window and set characteristics.
- //
- // Set scaling to false (default is true), rich edit control expects
- // units in TWiPS and scales itself.
- APXPrintOut printout(Printer, "Title", GetMainWindow()->GetClientWindow(), false);
- printout.SetBanding(true);
-
- Printing++;
-
- //
- // Bring up the Print dialog and print the document.
- //
- Printer->Print(GetWindowPtr(GetActiveWindow()), printout, true);
-
- Printing--;
- }
-
-
- //////////////////////////////////////////////////////////
- // RichCtrlApp
- // ==========
- // Menu File Print Setup command
- void RichCtrlApp::CmFilePrintSetup ()
- {
- if (!Printer)
- Printer = new TPrinter(this);
-
- //
- // Bring up the Print Setup dialog.
- //
- Printer->Setup(GetMainWindow());
- }
-
-
- //////////////////////////////////////////////////////////
- // RichCtrlApp
- // ==========
- // Menu enabler used by Print, Print Setup and Print Preview.
- void RichCtrlApp::CmPrintEnable (TCommandEnabler &tce)
- {
- // If we have a Printer already created just test if all is okay.
- // Otherwise create a Printer object and make sure the printer
- // really exists and then delete the Printer object.
- if (!Printer) {
- Printer = new TPrinter(this);
-
- tce.Enable(Printer->GetSetup().Error == 0);
- } else
- tce.Enable(Printer->GetSetup().Error == 0);
- }
-
-
- void RichCtrlApp::EvWinIniChange (char far* section)
- {
- if (strcmp(section, "windows") == 0) {
- // If the device changed in the WIN.INI file then the printer
- // might have changed. If we have a TPrinter (Printer) then
- // check and make sure it's identical to the current device
- // entry in WIN.INI.
- if (Printer) {
- char printDBuffer[255];
- LPSTR printDevice = printDBuffer;
- LPSTR devName;
- LPSTR driverName = 0;
- LPSTR outputName = 0;
-
- if (::GetProfileString("windows", "device", "", printDevice, sizeof(printDevice))) {
- // The string which should come back is something like:
- //
- // HP LaserJet III,hppcl5a,LPT1:
- //
- // Where the format is:
- //
- // devName,driverName,outputName
- //
- devName = printDevice;
- while (*printDevice) {
- if (*printDevice == ',') {
- *printDevice++ = 0;
- if (!driverName)
- driverName = printDevice;
- else
- outputName = printDevice;
- } else
- printDevice = ::AnsiNext(printDevice);
- }
-
- if ((Printer->GetSetup().Error != 0) ||
- (strcmp(devName, Printer->GetSetup().GetDeviceName()) != 0) ||
- (strcmp(driverName, Printer->GetSetup().GetDriverName()) != 0) ||
- (strcmp(outputName, Printer->GetSetup().GetOutputName()) != 0)) {
-
- // New printer installed so get the new printer device now.
- delete Printer;
- Printer = new TPrinter(this);
- }
- } else {
- // No printer installed (GetProfileString failed).
- delete Printer;
- Printer = new TPrinter(this);
- }
- }
- }
- }
-
-
- //////////////////////////////////////////////////////////
- // RichCtrlApp
- // ===========
- // Menu Help About richctrl.exe command
- void RichCtrlApp::CmHelpAbout ()
- {
- //
- // Show the modal dialog.
- //
- RichCtrlAboutDlg(MainWindow).Execute();
- }
-
-
- int OwlMain (int , char* [])
- {
- try {
- RichCtrlApp app;
- return app.Run();
- }
- catch (xmsg& x) {
- ::MessageBox(0, x.why().c_str(), "Exception", MB_OK);
- }
-
- return -1;
- }
-
- void RichCtrlApp::CmExit ()
- {
- // INSERT>> Your code here.
-
- }
-
-