home *** CD-ROM | disk | FTP | other *** search
/ Prima Shareware 3 / DuCom_Prima-Shareware-3_cd1.bin / PROGRAMO / C / RICHCT / RCHCTRLA.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-05  |  7.2 KB  |  296 lines

  1. /*  Project RichCtrl
  2.     DHB Software
  3.     Copyright ⌐ 1996. All Rights Reserved.
  4.  
  5.     SUBSYSTEM:    richctrl.exe Application
  6.     FILE:         rchctrla.cpp
  7.     AUTHOR:       David H. Borg
  8.  
  9.  
  10.     OVERVIEW
  11.     ========
  12.     Source file for implementation of RichCtrlApp (TApplication).      
  13. */
  14.  
  15.  
  16. #include <owl\owlpch.h>
  17. #pragma hdrstop
  18.  
  19.  
  20. #include "rchctrla.h"
  21. #include "rchedtcn.h"                        // Definition of client class.
  22. #include "rchctrad.h"                        // Definition of about dialog.       
  23. #include "toolbar.h"                        // Windows 95 toolbar
  24. #include "formatbr.h"                        // Windows 95 toolbar
  25.  
  26.  
  27. //{{RichCtrlApp Implementation}}
  28.  
  29.  
  30. //
  31. // Build a response table for all messages/commands handled
  32. // by the application.
  33. //
  34. DEFINE_RESPONSE_TABLE1(RichCtrlApp, TApplication)
  35. //{{RichCtrlAppRSP_TBL_BEGIN}}
  36.     EV_COMMAND(CM_FILEPRINT, CmFilePrint),
  37.     EV_COMMAND(CM_FILEPRINTERSETUP, CmFilePrintSetup),
  38.     EV_COMMAND_ENABLE(CM_FILEPRINT, CmPrintEnable),
  39.     EV_COMMAND_ENABLE(CM_FILEPRINTERSETUP, CmPrintEnable),
  40.     EV_COMMAND(CM_HELPABOUT, CmHelpAbout),
  41.     EV_WM_WININICHANGE,
  42.     EV_COMMAND(CM_EXIT, CmExit),
  43. //{{RichCtrlAppRSP_TBL_END}}
  44. END_RESPONSE_TABLE;
  45.  
  46.  
  47. //////////////////////////////////////////////////////////
  48. // RichCtrlApp
  49. // =====
  50. //
  51. RichCtrlApp::RichCtrlApp () : TApplication("RichCtrl"), rtfModule(0), rtfClient(0)
  52. {
  53.     Printer = 0;
  54.     Printing = 0;
  55.  
  56.     // INSERT>> Your constructor code here.
  57. }
  58.  
  59.  
  60. RichCtrlApp::~RichCtrlApp ()
  61. {
  62.     if (Printer)
  63.         delete Printer;
  64.  
  65.     // INSERT>> Your destructor code here.
  66.  
  67.     // delete the rich edit control module
  68.     if( rtfModule){
  69.         delete rtfModule;
  70.         rtfModule = 0;
  71.     }
  72. }
  73.  
  74.  
  75. //////////////////////////////////////////////////////////
  76. // RichCtrlApp
  77. // =====
  78. // Application intialization.
  79. //
  80. void RichCtrlApp::InitMainWindow ()
  81. {
  82.     if (nCmdShow != SW_HIDE)
  83.         nCmdShow = (nCmdShow != SW_SHOWMINNOACTIVE) ? SW_SHOWNORMAL : nCmdShow;
  84.  
  85.  
  86.     // Ensure that common control DLL is loaded
  87.     InitCommonControls();
  88.  
  89.     // Load the rich edit DLL
  90.     rtfModule = new TModule( "riched32.dll");
  91.  
  92.     // create a RichCtrlWindow based on the Windows 95 Rich Edit DLL
  93.     rtfClient = new RichEditControl( 0, 0, 0, 0, 0, 0, 0, 0, 0, rtfModule);
  94.     SDIDecFrame *frame = new SDIDecFrame(0, GetName(), rtfClient, false);
  95.  
  96.     //
  97.     // Assign ICON w/ this application.
  98.     //
  99.     frame->SetIcon(this, IDI_SDIAPPLICATION);
  100.  
  101.     //
  102.     // Menu associated with window and accelerator table associated with table.
  103.     //
  104.     frame->AssignMenu(SDI_MENU);
  105.  
  106.     //
  107.     // Associate with the accelerator table.
  108.     //
  109.     frame->Attr.AccelTable = SDI_MENU;
  110.  
  111.     // Insert toolbar at the top of the TDecoratedFrame window
  112.     // w=0 & h=0 if using autosize and standard windows bitmaps
  113.     ToolBar *tbar = new ToolBar( frame, IDW_TOOLBAR, 0, 0);
  114.     frame->Insert(*tbar, TDecoratedFrame::Top);
  115.  
  116.     // Insert formatbar at the top of the TDecoratedFrame window
  117.     // w=0 & h=0 if using autosize and some custom windows bitmaps
  118.     FormatBar *fbar = new FormatBar( frame, IDW_TOOLBAR+1, 0, 0);
  119.     frame->Insert(*fbar, TDecoratedFrame::Top);
  120.  
  121.     SetMainWindow(frame);
  122.  
  123.     frame->SetMenuDescr(TMenuDescr(SDI_MENU));
  124. }
  125.  
  126.  
  127. //{{SDIDecFrame Implementation}}
  128.  
  129.  
  130. SDIDecFrame::SDIDecFrame (TWindow *parent, const char far *title, TWindow *clientWnd, bool trackMenuSelection, TModule *module)
  131.     : TDecoratedFrame(parent, title, clientWnd, trackMenuSelection, module)
  132. {
  133.     // INSERT>> Your constructor code here.
  134.  
  135. }
  136.  
  137.  
  138. SDIDecFrame::~SDIDecFrame ()
  139. {
  140.     // INSERT>> Your destructor code here.
  141.  
  142. }
  143.  
  144.  
  145. //////////////////////////////////////////////////////////
  146. // RichCtrlApp
  147. // ==========
  148. // Menu File Print command
  149. void RichCtrlApp::CmFilePrint ()
  150. {
  151.     //
  152.     // Create Printer object if not already created.
  153.     //
  154.     if (!Printer)
  155.         Printer = new TPrinter(this);
  156.  
  157.     //
  158.     // Create Printout window and set characteristics.
  159.     //
  160.     // Set scaling to false (default is true), rich edit control expects
  161.     // units in TWiPS and scales itself.
  162.     APXPrintOut printout(Printer, "Title", GetMainWindow()->GetClientWindow(), false);
  163.     printout.SetBanding(true);
  164.  
  165.     Printing++;
  166.  
  167.     //
  168.     // Bring up the Print dialog and print the document.
  169.     //
  170.     Printer->Print(GetWindowPtr(GetActiveWindow()), printout, true);
  171.  
  172.     Printing--;
  173. }
  174.  
  175.  
  176. //////////////////////////////////////////////////////////
  177. // RichCtrlApp
  178. // ==========
  179. // Menu File Print Setup command
  180. void RichCtrlApp::CmFilePrintSetup ()
  181. {
  182.     if (!Printer)
  183.         Printer = new TPrinter(this);
  184.  
  185.     //
  186.     // Bring up the Print Setup dialog.
  187.     //
  188.     Printer->Setup(GetMainWindow());
  189. }
  190.  
  191.  
  192. //////////////////////////////////////////////////////////
  193. // RichCtrlApp
  194. // ==========
  195. // Menu enabler used by Print, Print Setup and Print Preview.
  196. void RichCtrlApp::CmPrintEnable (TCommandEnabler &tce)
  197. {
  198.     // If we have a Printer already created just test if all is okay.
  199.     // Otherwise create a Printer object and make sure the printer
  200.     // really exists and then delete the Printer object.
  201.     if (!Printer) {
  202.         Printer = new TPrinter(this);
  203.  
  204.         tce.Enable(Printer->GetSetup().Error == 0);
  205.     } else
  206.         tce.Enable(Printer->GetSetup().Error == 0);
  207. }
  208.  
  209.  
  210. void RichCtrlApp::EvWinIniChange (char far* section)
  211. {
  212.     if (strcmp(section, "windows") == 0) {
  213.         // If the device changed in the WIN.INI file then the printer
  214.         // might have changed.  If we have a TPrinter (Printer) then
  215.         // check and make sure it's identical to the current device
  216.         // entry in WIN.INI.
  217.         if (Printer) {
  218.             char printDBuffer[255];
  219.             LPSTR printDevice = printDBuffer;
  220.             LPSTR devName;
  221.             LPSTR driverName = 0;
  222.             LPSTR outputName = 0;
  223.  
  224.             if (::GetProfileString("windows", "device", "", printDevice, sizeof(printDevice))) {
  225.                 // The string which should come back is something like:
  226.                 //
  227.                 //      HP LaserJet III,hppcl5a,LPT1:
  228.                 //
  229.                 // Where the format is:
  230.                 //
  231.                 //      devName,driverName,outputName
  232.                 //
  233.                 devName = printDevice;
  234.                 while (*printDevice) {
  235.                     if (*printDevice == ',') {
  236.                         *printDevice++ = 0;
  237.                         if (!driverName)
  238.                             driverName = printDevice;
  239.                         else
  240.                             outputName = printDevice;
  241.                     } else
  242.                         printDevice = ::AnsiNext(printDevice);
  243.                 }
  244.  
  245.                 if ((Printer->GetSetup().Error != 0)                                ||
  246.                     (strcmp(devName, Printer->GetSetup().GetDeviceName()) != 0)    ||
  247.                     (strcmp(driverName, Printer->GetSetup().GetDriverName()) != 0) ||
  248.                     (strcmp(outputName, Printer->GetSetup().GetOutputName()) != 0)) {
  249.  
  250.                     // New printer installed so get the new printer device now.
  251.                     delete Printer;
  252.                     Printer = new TPrinter(this);
  253.                 }
  254.             } else {
  255.                 // No printer installed (GetProfileString failed).
  256.                 delete Printer;
  257.                 Printer = new TPrinter(this);
  258.             }
  259.         }
  260.     }
  261. }
  262.  
  263.  
  264. //////////////////////////////////////////////////////////
  265. // RichCtrlApp
  266. // ===========
  267. // Menu Help About richctrl.exe command
  268. void RichCtrlApp::CmHelpAbout ()
  269. {
  270.     //
  271.     // Show the modal dialog.
  272.     //
  273.     RichCtrlAboutDlg(MainWindow).Execute();
  274. }
  275.  
  276.  
  277. int OwlMain (int , char* [])
  278. {
  279.     try {
  280.         RichCtrlApp    app;
  281.         return app.Run();
  282.     }
  283.     catch (xmsg& x) {
  284.         ::MessageBox(0, x.why().c_str(), "Exception", MB_OK);
  285.     }
  286.  
  287.     return -1;
  288. }
  289.  
  290. void RichCtrlApp::CmExit ()
  291. {
  292.     // INSERT>> Your code here.
  293.  
  294. }
  295.  
  296.