home *** CD-ROM | disk | FTP | other *** search
- /* Project clsxprt2
-
- Copyright ⌐ 1993. All Rights Reserved.
-
- SUBSYSTEM: clsxprt2.exe Application
- FILE: clsxpr2a.cpp
- AUTHOR:
-
-
- OVERVIEW
- ========
- Source file for implementation of clsxprt2App (TApplication).
- */
-
-
- #include <owl\owlpch.h>
- #pragma hdrstop
-
-
- #include "clsxpr2a.h"
- #include "clsxp2ad.h" // Definition of about dialog.
-
- #include "tfrmtdlg.h"
- #include <stdio.h>
- #include <string.h>
- #include <dos.h>
-
- //{{clsxprt2App Implementation}}
-
-
- //
- // Build a response table for all messages/commands handled
- // by the application.
- //
- DEFINE_RESPONSE_TABLE1(clsxprt2App, TApplication)
- //{{clsxprt2AppRSP_TBL_BEGIN}}
- EV_COMMAND(CM_FILENEW, CmFileNew),
- EV_COMMAND(CM_FILEOPEN, CmFileOpen),
- EV_COMMAND(CM_FILECLOSE, CmFileClose),
- EV_COMMAND(CM_HELPABOUT, CmHelpAbout),
- EV_COMMAND(CM_INSDATETIME, CmInsertDateTime),
- EV_COMMAND(CM_INSTIME, CmInsertTime),
- EV_COMMAND(CM_LOWERCASE, CmLowercase),
- EV_COMMAND(CM_REVERSE, CmReverse),
- EV_COMMAND(CM_UPPERCASE, CmUppercase),
- EV_COMMAND(CM_DATETIMEFORMAT, CmPreferences),
- EV_COMMAND(CM_UPPERCASE, CmUppercase),
- EV_COMMAND(CM_REVERSE, CmReverse),
- EV_COMMAND(CM_LOWERCASE, CmLowercase),
- EV_COMMAND(CM_INSTIME, CmInsertTime),
- EV_COMMAND(CM_INSDATE, CmInsertDate),
- EV_COMMAND(CM_INSDATETIME, CmInsertDateTime),
- //{{clsxprt2AppRSP_TBL_END}}
- END_RESPONSE_TABLE;
-
-
- //
- // FrameWindow must be derived to override Paint for Preview and Print.
- //
- class SDIDecFrame : public TDecoratedFrame {
- public:
- SDIDecFrame (TWindow *parent, const char far *title, TWindow *clientWnd, BOOL trackMenuSelection = FALSE, TModule *module = 0) :
- TDecoratedFrame(parent, title, clientWnd, trackMenuSelection, module)
- { }
- ~SDIDecFrame ()
- { }
- };
-
-
- //////////////////////////////////////////////////////////
- // clsxprt2App
- // =====
- //
- clsxprt2App::clsxprt2App () : TApplication("clsxprt2")
- {
-
- // Common file file flags and filters for Open/Save As dialogs. Filename and directory are
- // computed in the member functions CmFileOpen, and CmFileSaveAs.
- FileData.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
- FileData.SetFilter("All Files (*.*)|*.*|");
-
- // INSERT>> Your constructor code here.
- IsAmPm = FALSE;
- df = mmddyy;
- }
-
-
- clsxprt2App::~clsxprt2App ()
- {
- // INSERT>> Your destructor code here.
-
- }
-
-
- //////////////////////////////////////////////////////////
- // clsxprt2App
- // =====
- // Application intialization.
- //
- void clsxprt2App::InitMainWindow ()
- {
- Client = new TEditFile(0, 0, 0);
- SDIDecFrame *frame = new SDIDecFrame(0, GetName(), Client, FALSE);
-
- nCmdShow = nCmdShow != SW_SHOWMINIMIZED ? SW_SHOWNORMAL : nCmdShow;
-
- //
- // 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;
-
-
- MainWindow = frame;
-
- }
-
-
- //////////////////////////////////////////////////////////
- // clsxprt2App
- // ===========
- // Menu File New command
- void clsxprt2App::CmFileNew ()
- {
- Client->NewFile();
- }
-
-
- //////////////////////////////////////////////////////////
- // clsxprt2App
- // ===========
- // Menu File Open command
- void clsxprt2App::CmFileOpen ()
- {
- //
- // Display standard Open dialog box to select a file name.
- //
- *FileData.FileName = 0;
- if (Client->CanClose())
- if (TFileOpenDialog(MainWindow, FileData).Execute() == IDOK)
- OpenFile();
- }
-
-
- void clsxprt2App::OpenFile (const char *fileName)
- {
- if (fileName)
- lstrcpy(FileData.FileName, fileName);
-
- Client->ReplaceWith(FileData.FileName);
- }
-
-
- //////////////////////////////////////////////////////////
- // clsxprt2App
- // =====
- // Menu File Close command
- void clsxprt2App::CmFileClose ()
- {
- if (Client->CanClose())
- Client->DeleteSubText(0, UINT(-1));
- }
-
-
- //////////////////////////////////////////////////////////
- // clsxprt2App
- // ===========
- // Menu Help About clsxprt2.exe command
- void clsxprt2App::CmHelpAbout ()
- {
- //
- // Show the modal dialog.
- //
- clsxprt2AboutDlg(MainWindow).Execute();
- }
-
-
- int OwlMain (int , char* [])
- {
- clsxprt2App App;
- int result;
-
- result = App.Run();
-
- return result;
- }
-
- void clsxprt2App::CmInsertTime ()
- {
- struct time tm;
- char szStr[41];
-
- gettime(&tm);
- if (IsAmPm) {
- if (tm.ti_hour == 12)
- sprintf(szStr, "12:%02d:%02d p.m.",
- tm.ti_min, tm.ti_sec);
- else if (tm.ti_hour > 12)
- sprintf(szStr, "%2d:%02d:%02d p.m.",
- tm.ti_hour - 12, tm.ti_min, tm.ti_sec);
- else
- sprintf(szStr, "%2d:%02d:%02d a.m.",
- tm.ti_hour, tm.ti_min, tm.ti_sec);
- }
- else
- sprintf(szStr, "%2d:%02d:%02d",
- tm.ti_hour, tm.ti_min, tm.ti_sec);
- Client->Insert(szStr);
-
- }
-
-
- void clsxprt2App::CmLowercase ()
- {
- UINT startPos, endPos;
- int numChars;
- char* pszStr;
-
- Client->GetSelection(startPos, endPos);
- // is there selected text
- if (startPos < endPos) {
- numChars = endPos - startPos + 1;
- pszStr = new char[numChars+1];
- Client->GetSubText(pszStr, startPos, endPos);
- strlwr(pszStr);
- Client->Insert(pszStr);
- Client->SetSelection(startPos, endPos);
- delete [] pszStr;
- }
- else {
- numChars = Client->GetWindowTextLength();
- pszStr = new char[numChars+1];
- Client->GetSubText(pszStr, 0, (UINT)numChars);
- strlwr(pszStr);
- Client->DeleteSubText(0, (UINT)numChars);
- Client->SetSelection(0, 0);
- Client->Insert(pszStr);
- delete [] pszStr;
- }
- }
-
-
- void clsxprt2App::CmReverse ()
- {
- UINT startPos, endPos;
- int numChars;
- char* pszStr;
- char swapChar;
-
- Client->GetSelection(startPos, endPos);
- // is there selected text
- if (startPos < endPos) {
- numChars = endPos - startPos + 1;
- pszStr = new char[numChars+1];
- Client->GetSubText(pszStr, startPos, endPos);
- for (int i = 0, j = strlen(pszStr)-1; i < j ; i++, j--) {
- swapChar = pszStr[i];
- pszStr[i] = pszStr[j];
- pszStr[j] = swapChar;
- }
- Client->Insert(pszStr);
- Client->SetSelection(startPos, endPos);
- delete [] pszStr;
- }
- else {
- numChars = Client->GetWindowTextLength();
- pszStr = new char[numChars+1];
- Client->GetSubText(pszStr, 0, (UINT)numChars);
- for (int i = 0, j = strlen(pszStr)-1; i < j ; i++, j--) {
- swapChar = pszStr[i];
- pszStr[i] = pszStr[j];
- pszStr[j] = swapChar;
- }
- Client->DeleteSubText(0, (UINT)numChars);
- Client->SetSelection(0, 0);
- Client->Insert(pszStr);
- delete [] pszStr;
- }
- }
-
-
- void clsxprt2App::CmUppercase ()
- {
- UINT startPos, endPos;
- int numChars;
- char* pszStr;
-
- Client->GetSelection(startPos, endPos);
- // is there selected text
- if (startPos < endPos) {
- numChars = endPos - startPos + 1;
- pszStr = new char[numChars+1];
- Client->GetSubText(pszStr, startPos, endPos);
- strupr(pszStr);
- Client->Insert(pszStr);
- Client->SetSelection(startPos, endPos);
- delete [] pszStr;
- }
- else {
- numChars = Client->GetWindowTextLength();
- pszStr = new char[numChars+1];
- Client->GetSubText(pszStr, 0, (UINT)numChars);
- strupr(pszStr);
- Client->DeleteSubText(0, (UINT)numChars);
- Client->SetSelection(0, 0);
- Client->Insert(pszStr);
- delete [] pszStr;
- }
- }
-
- void clsxprt2App::CmPreferences ()
- {
- TFrmtDialog* pDlg = new TFrmtDialog(Client,
- TResId(IDD_DATETIME_DLG));
- if (pDlg->Execute() == IDOK) {
- // save time format
- IsAmPm = pDlg->IsAmPm;
- // save date format
- df = pDlg->df;
- }
- }
-
-
- void clsxprt2App::CmInsertDateTime ()
- {
- struct date dt;
- struct time tm;
- char szStr[41];
-
- getdate(&dt);
- switch (df) {
- case mmddyy:
- sprintf(szStr, "%2d/%02d/%4d ",
- dt.da_mon, dt.da_day, dt.da_year);
- break;
- case ddmmyy:
- sprintf(szStr, "%2d/%02d/%4d ",
- dt.da_day, dt.da_mon, dt.da_year);
- break;
- default:
- sprintf(szStr, "%4d/%02d/%02d ",
- dt.da_year, dt.da_day, dt.da_mon);
- break;
- }
- Client->Insert(szStr);
-
- gettime(&tm);
- if (IsAmPm) {
- if (tm.ti_hour == 12)
- sprintf(szStr, "12:%02d:%02d p.m.",
- tm.ti_min, tm.ti_sec);
- else if (tm.ti_hour > 12)
- sprintf(szStr, "%2d:%02d:%02d p.m.",
- tm.ti_hour - 12, tm.ti_min, tm.ti_sec);
- else
- sprintf(szStr, "%2d:%02d:%02d a.m.",
- tm.ti_hour, tm.ti_min, tm.ti_sec);
- }
- else
- sprintf(szStr, "%2d:%02d:%02d",
- tm.ti_hour, tm.ti_min, tm.ti_sec);
- Client->Insert(szStr);
-
- }
-
- void clsxprt2App::CmInsertDate ()
- {
- struct date dt;
- char szStr[41];
-
- getdate(&dt);
- switch (df) {
- case mmddyy:
- sprintf(szStr, "%2d/%02d/%4d",
- dt.da_mon, dt.da_day, dt.da_year);
- break;
- case ddmmyy:
- sprintf(szStr, "%2d/%02d/%4d",
- dt.da_day, dt.da_mon, dt.da_year);
- break;
- default:
- sprintf(szStr, "%4d/%02d/%02d",
- dt.da_year, dt.da_day, dt.da_mon);
- break;
- }
- Client->Insert(szStr);
-
- }
-
-