home *** CD-ROM | disk | FTP | other *** search
- /* Project emedit
- Early Morning Software
- Copyright ⌐ 1993. All Rights Reserved.
-
- SUBSYSTEM: emedit.exe Application
- FILE: mdtchldc.cpp
- AUTHOR: Ted Stockwell
-
-
- OVERVIEW
- ========
- Source file for implementation of emeditChildClient (TDialog).
- */
-
- #include <owl\owlpch.h>
- #pragma hdrstop
-
- #include "mdtchldc.h"
- #include "mdtmssgb.h" // editpad message bar
- #include "emedtapp.h" // editpad application
- #include "replace.h"
- #include "confirm.h"
- #include "mdtfnddl.h"
-
- emeditReplaceDialogXfer SearchData;
-
- //
- // Build a response table for all messages/commands handled
- // by the application.
- //
- DEFINE_RESPONSE_TABLE2(emeditChildClient, TDialog, TVbxEventHandler)
- //{{emeditChildClientRSP_TBL_BEGIN}}
- EV_WM_SIZE,
- EV_COMMAND_ENABLE(CM_EDITCOPY, CmEditSelectEnable),
- EV_COMMAND_ENABLE(CM_EDITCUT, CmEditSelectEnable),
- EV_COMMAND_ENABLE(CM_EDITDELETE, CmEditSelectEnable),
- EV_COMMAND_ENABLE(CM_EDITWRAP, CmEditSelectEnable),
- EV_COMMAND(CM_EDITCLEAR, CmEditClear),
- EV_COMMAND(CM_EDITCOPY, CmEditCopy),
- EV_COMMAND(CM_EDITCUT, CmEditCut),
- EV_COMMAND(CM_EDITDELETE, CmEditDelete),
- EV_COMMAND(CM_EDITWRAP, CmEditWrap),
- EV_COMMAND_ENABLE(CM_EDITPASTE, CmEditPasteEnable),
- EV_COMMAND(CM_EDITPASTE, CmEditPaste),
- EV_COMMAND(CM_EDITSELECT_ALL, CmEditSelectAll),
- EV_VBXEVENTNAME(IDC_CHILDCLIENTEDITOR, "CaretChange", CaretChange),
- EV_VBXEVENTNAME(IDC_CHILDCLIENTEDITOR, "Change", Change),
- EV_COMMAND_ENABLE(CM_EDITUNDO, CmEditUndoEnable),
- EV_COMMAND_ENABLE(CM_EDITREDO, CmEditRedoEnable),
- EV_COMMAND(CM_EDITREDO, CmEditRedo),
- EV_COMMAND(CM_EDITUNDO, CmEditUndo),
- EV_COMMAND_ENABLE(CM_EDITFIND, CmEditFindEnable),
- EV_COMMAND(CM_EDITFIND, CmEditFind),
- EV_COMMAND(CM_EDITFINDNEXT, CmEditFindNext),
- EV_COMMAND_ENABLE(CM_EDITFINDNEXT, CmEditFindNextEnable),
- EV_COMMAND(CM_EDITREPLACE, CmEditReplace),
- EV_COMMAND_ENABLE(CM_EDITREPLACE, CmEditReplaceEnable),
- EV_VBXEVENTNAME(IDC_CHILDCLIENTEDITOR, "SearchReplaceConfirm", SearchReplaceConfirm),
- //{{emeditChildClientRSP_TBL_END}}
- END_RESPONSE_TABLE;
-
-
- //{{emeditChildClient Implementation}}
-
-
- emeditChildClient::emeditChildClient (TWindow* parent, TResId resId, TModule* module):
- TDialog(parent, resId, module), TWindow( parent )
- {
- editor= new emeditEditor( this, IDC_CHILDCLIENTEDITOR );
- }
-
-
- emeditChildClient::~emeditChildClient ()
- {
- Destroy();
- }
-
-
-
-
-
- void emeditChildClient::EvSize (UINT sizeType, TSize& size)
- {
- TDialog::EvSize(sizeType, size);
-
- // Size the editor control to fit the client window.
- editor->SetPropTop( 0 );
- editor->SetPropLeft( 0 );
- editor->SetPropWidth( size.cx );
- editor->SetPropHeight( size.cy );
- }
-
-
-
- void emeditChildClient::CmEditSelectEnable (TCommandEnabler &tce)
- {
- ENUM SelType;
- editor->GetPropSelMark( SelType );
- tce.Enable( SelType != TVbxEditor::SelMark_0_None );
- }
-
-
- void emeditChildClient::CmEditClear ()
- {
- editor->SetPropRedraw( FALSE );
- CmEditSelectAll();
- CmEditDelete();
- editor->SetPropRedraw( TRUE );
- }
-
-
- void emeditChildClient::CmEditCopy ()
- {
- editor->SetPropAction( TVbxEditor::Action_1_Copy );
- }
-
-
- void emeditChildClient::CmEditCut ()
- {
- editor->SetPropAction( TVbxEditor::Action_3_Cut );
- }
-
-
- void emeditChildClient::CmEditDelete ()
- {
- editor->SetPropAction( TVbxEditor::Action_4_Clear );
- }
-
-
- void emeditChildClient::CmEditWrap ()
- {
- long width= 0;
-
- editor->GetPropWidth( width ); // get the width of the window, in pixels
- editor->SetPropWrapY( (int)width ); // get the wrap column to the width of window
- editor->SetPropWrapWholeWords( TRUE ); // wrap whole words
- editor->SetPropAction( TVbxEditor::Action_5_Wrap ); // wrap the text
- }
-
-
- void emeditChildClient::CmEditPasteEnable (TCommandEnabler &tce)
- {
- TClipboard& clipboard = OpenClipboard();
- tce.Enable(clipboard.IsClipboardFormatAvailable(CF_TEXT));
- clipboard.CloseClipboard();
- }
-
-
- void emeditChildClient::CmEditPaste ()
- {
- editor->SetPropAction( TVbxEditor::Action_2_Paste );
- }
-
-
- void emeditChildClient::CmEditSelectAll ()
- {
- // Implement code equivalent to the following VB code :
- // Editor1.Redraw= False
- // SendKeys( "^{HOME}", TRUE ); 'move caret to top of file
- // SendKeys( "+^{END}", TRUE ); ' mark entire file
- // Editor1.Redraw= True
- BYTE pbOrigKeyState[256], pbNewKeyState[256];
-
- editor->SetPropRedraw( FALSE );
-
- GetKeyboardState((LPBYTE) &pbOrigKeyState); // save keyboard state
- memcpy( pbNewKeyState, pbOrigKeyState, sizeof( pbNewKeyState ) );
-
- // Trick receiving window into thinking the Ctrl key is down.
- // For some receiving windows other than EMEDIT it might also be necessary
- // to properly set the lparam of the message that we send but it's not
- // necessary for EMEDIT.
- pbNewKeyState[VK_CONTROL] |= 0x80;
- SetKeyboardState((LPBYTE) &pbNewKeyState);
- ::SendMessage( editor->HWindow, WM_KEYDOWN, VK_HOME, 0 );
-
- pbNewKeyState[VK_SHIFT] |= 0x80;
- SetKeyboardState((LPBYTE) &pbNewKeyState);
- ::SendMessage( editor->HWindow, WM_KEYDOWN, VK_END, 0 );
-
- SetKeyboardState((LPBYTE) &pbOrigKeyState); // restore keyboard state
-
- editor->SetPropRedraw( TRUE );
-
- // NOTE : I didn't have to implement this the way I did above, I just thought
- // it would be cool to reproduce the way I originally did it in Visual Basic
- // (using SendKeys, a routine not available with C++). I could have
- // implemented this more straightforwardlly as shown below. The method
- // above of simulating SendKey could be usful if I wanted to do something like
- // move to the beginning of the next word, then I would "send" Ctrl-Right
- // Arrow.
- /*
- editor->SetPropRedraw( FALSE ); // don't redraw window til done
- editor->SetPropCaretY(1); // move to the first line
- editor->SetPropCaretX(1); // move to the 1st column in the 1st line
- editor->SetPropSelMark( emeditEditor::SelMark_2_Line ); // start a line block
-
- long count;
- string lastline;
- editor->GetPropCount( count ); // get # of lines in the file
- editor->SetPropTextIndex( count ); // get the last
- editor->GetPropText( lastline ); // line in the file
- editor->SetPropCaretY( count ); // move caret to last line in file
- editor->SetPropCaretX( lastline.length() ); // move caret to end of last line
- editor->SetPropRedraw( TRUE ); // now redraw window
- */
- }
-
-
-
- void emeditChildClient::CaretChange (VBXEVENT FAR */*event*/) { UpdateStatusBar(); }
-
-
- void emeditChildClient::Change (VBXEVENT FAR */*event*/) { UpdateStatusBar(); }
-
-
- void emeditChildClient::UpdateStatusBar() {
- // INSERT>> Your code here.
- BOOL D;
- long X, Y, C;
- editor->GetPropCaretY( Y );
- editor->GetPropCaretX( X );
- editor->GetPropCount( C );
- editor->GetPropIsDirty( D );
- emeditMessageBar* StatusBar= ((emeditApp*)GetApplication())->StatusBar();
- StatusBar->SetPositionIndicator( X, Y, C );
- StatusBar->SetModifyIndicator( D );
- }
-
-
- void emeditChildClient::CmEditUndoEnable (TCommandEnabler &tce)
- {
- BOOL canundo;
- editor->GetPropCanUndo( canundo );
- tce.Enable( canundo );
- }
-
-
- void emeditChildClient::CmEditRedoEnable (TCommandEnabler &tce)
- {
- BOOL canundo;
- editor->GetPropCanRedo( canundo );
- tce.Enable( canundo );
- }
-
-
- void emeditChildClient::CmEditRedo ()
- {
- editor->SetPropAction( TVbxEditor::Action_7_Redo );
- }
-
-
-
- void emeditChildClient::CmEditUndo ()
- {
- editor->SetPropAction( TVbxEditor::Action_6_Undo );
- }
-
-
-
-
- // Overiding this method as shown below enables the dialog to process
- // accelerator keys.
- BOOL emeditChildClient::PreProcessMsg (MSG& msg)
- {
- BOOL result= GetApplication()->GetMainWindow()->PreProcessMsg( msg );
- if (!result)
- result = TDialog::PreProcessMsg(msg);
- return result;
- }
-
-
- void emeditChildClient::CmEditFindEnable (TCommandEnabler &tce) { tce.Enable(TRUE); }
-
-
- void emeditChildClient::CmEditFind ()
- {
- emeditFindDialog FindDialog( this );
-
- FindDialog.SetTransferBuffer( &SearchData );
-
- // if there's highlighted text that spans one and only one line then stuff
- // the text into the combo box.
- const char* target= GetHilitedString();
- if (target)
- SearchData.SearchText.SelectString( target );
-
- if (FindDialog.Execute() == IDOK) {
-
- // if a target was entered then
- // add the target to the string list in the transfer buffer
- string& target= SearchData.SearchText.GetSelection();
- if (target.length())
- SearchData.SearchText.AddString( target.c_str() );
-
- // do the search...
- SetSearchProperties( SearchData ); // set control search properties
- editor->SetPropAction( TVbxEditor::Action_9_Search ); // find the string
-
- // if the test was not found then display a message...
- ENUM SearchResult;
- editor->GetPropSearchResult( SearchResult );
- if (SearchResult == TVbxEditor::SearchResult_0_Failure) { // if text was not found
- string Msg= "Cannot find ";
- ((Msg+= "\"")+= target)+= "\"";
- MessageBox( Msg.c_str(), GetApplication()->GetName(), MB_ICONEXCLAMATION | MB_OK );
- }
- }
- }
-
-
-
- void emeditChildClient::SetSearchProperties(emeditReplaceDialogXfer& SearchData) {
- editor->SetPropSearchTarget( SearchData.SearchText.GetSelection() );
- editor->SetPropSearchReplacement( SearchData.ReplaceText.GetSelection() );
- editor->SetPropSearchCaseSensitive( SearchData.MatchCase );
- editor->SetPropSearchWholeWordsOnly( SearchData.WholeWordsOnly );
- editor->SetPropSearchTo( SearchData.DirectionUp ?
- TVbxEditor::SearchTo_0_Top_of_text :
- TVbxEditor::SearchTo_1_Bottom_of_text );
- editor->SetPropSearchOrigin( SearchData.SearchFromCursor ?
- TVbxEditor::SearchOrigin_0_From_Cursor :
- TVbxEditor::SearchOrigin_1_Entire_Scope );
- }
-
-
-
- const char* emeditChildClient::GetHilitedString() {
- const char* histring= NULL;
-
- ENUM selmark= 0;
- editor->GetPropSelMark( selmark );
- if (selmark != 0 ) { // if there is selected text
- long starty, endy;
- editor->GetPropSelStartY( starty );
- editor->GetPropSelEndY( endy );
- if (starty == endy ) { // if the text selection only spans one line
- long startx, endx;
- editor->GetPropSelStartX( startx );
- editor->GetPropSelEndX( endx );
- if (startx < endx) {
- static string search;
- editor->SetPropTextIndex( starty );
- editor->GetPropText( search );
-
- search= search.substr( (unsigned)startx-1, (unsigned)(endx-startx) ).strip();
- histring= search.c_str();
- }
- }
- }
-
- return histring;
- }
-
-
- void emeditChildClient::CmEditFindNext ()
- {
- string SearchTarget;
- editor->GetPropSearchTarget( SearchTarget );
- if (SearchTarget.length() <= 0) {
- CmEditFind();
- } else {
- editor->SetPropAction( TVbxEditor::Action_11_Search_Again ); // find the string
-
- // if the test was not found then display a message...
- ENUM SearchResult;
- editor->GetPropSearchResult( SearchResult );
- if (SearchResult == TVbxEditor::SearchResult_0_Failure) { // if text was not found
- string Msg= "Cannot find ";
- string target;
- editor->GetPropSearchTarget( target );
- ((Msg+= "\"")+= target)+= "\"";
- MessageBox( Msg.c_str(), GetApplication()->GetName(), MB_ICONEXCLAMATION | MB_OK );
- }
- }
- }
-
-
- void emeditChildClient::CmEditFindNextEnable (TCommandEnabler &tce) { tce.Enable(TRUE); }
-
-
- void emeditChildClient::CmEditReplace ()
- {
- emeditReplaceDialog ReplaceDialog( this );
- ReplaceDialog.SetTransferBuffer( &SearchData );
-
- // if there's highlighted text that spans one and only one line then stuff
- // the text into the combo box.
- const char* target= GetHilitedString();
- if (target)
- SearchData.SearchText.SelectString( target );
-
- if (ReplaceDialog.Execute() == IDOK) {
-
- // if a target was entered then
- // add the target to the string list in the transfer buffer
- string& target= SearchData.SearchText.GetSelection();
- if (target.length())
- SearchData.SearchText.AddString( target.c_str() );
-
- // if a replacement was entered then
- // add the replacement to the string list in the transfer buffer
- string& replacement= SearchData.ReplaceText.GetSelection();
- if (replacement.length())
- SearchData.ReplaceText.AddString( replacement.c_str() );
-
-
- // do the search...
- SetSearchProperties( SearchData ); // set control search properties
- editor->SetPropAction( TVbxEditor::Action_10_Replace ); // find the string
-
- // if the test was not found then display a message...
- ENUM SearchResult;
- editor->GetPropSearchResult( SearchResult );
- if (SearchResult == TVbxEditor::SearchResult_0_Failure) { // if text was not found
- string Msg= "Cannot find ";
- ((Msg+= "\"")+= target)+= "\"";
- MessageBox( Msg.c_str(), GetApplication()->GetName(), MB_ICONEXCLAMATION | MB_OK );
- }
- }
- }
-
-
- void emeditChildClient::CmEditReplaceEnable (TCommandEnabler &tce) { tce.Enable(TRUE); }
-
-
- void emeditChildClient::SearchReplaceConfirm (VBXEVENT FAR *event)
- {
- // Confirmation as Integer
- int far * confirmation= *( int far * far *)(event->ParamList);
- emeditConfirmDialog ConfirmDialog( this );
- switch (ConfirmDialog.Execute()) {
- case IDC_YESBUTTON: *confirmation= 1; break;
- case IDC_NOBUTTON: *confirmation= 2; break;
- case IDC_ONEBUTTON: *confirmation= 3; break;
- case IDC_ALLBUTTON: *confirmation= 4; break;
- default: *confirmation= 0; break;
- }
- }
-
-