#include "cBroadcastingTextEditView.h" // =========================================================================== // cBroadcastingTextEditView.cpp Version 1.1 ©1998 Joakim Braun All rights reserved. // =========================================================================== // // A subclass of LTextEditView() whose UserChangedText() function broadcasts a message // whenever called, and passes up a command to the super commander. Each of these functions // may be enabled/disabled and have its parameters set in Constructor or programmatically. // The ioParam passed when sending the message and the command may be set to either NULL, // the pane ID of the view, the "this" pointer, the view's TEHandle, // or the value of the text in the LTextEditView. // cBroadcastingTextEditView is free for any and all use. // Do not distribute modified source code under my name. // No support promised, no liability accepted. Provided "as is". // That said, I can be reached at braun@swipnet.se. // Change history: // 1.0 May 1, 1998 First release // 1.1 August 30, 1998 We call LTextEditView::UserChangedText() in our own version, after having done our stuff. // Check whether we're really broadcasting in DoSendMessage(). // =========================================================================== // Ä Constructor // =========================================================================== // cBroadcastingTextEditView::cBroadcastingTextEditView(){ DefaultInit(); } // =========================================================================== // Ä Stream constructor // =========================================================================== // cBroadcastingTextEditView::cBroadcastingTextEditView(LStream *inStream ) : LTextEditView(inStream){ *inStream >> mUserChangedTextMsg; *inStream >> mMsgIoParamType; *inStream >> mUserChangedTextCmd; *inStream >> mCmdIoParamType; } // =========================================================================== // Ä UserChangedText() // (Overridden virtual from LTextEditView()) // Calls DoSendMessage() and DoSendCommand(). // =========================================================================== // void cBroadcastingTextEditView::UserChangedText(){ LTextEditView::UserChangedText(); DoSendMessage(); DoSendCommand(); } // =========================================================================== // Ä DefaultInit() // Disables subclass functionality (nothing will be broadcast or sent to superCommander) // =========================================================================== // void cBroadcastingTextEditView::DefaultInit(void){ mUserChangedTextMsg = msg_Nothing, mUserChangedTextCmd = cmd_Nothing, mMsgIoParamType = eNULLIoParam, mCmdIoParamType = eNULLIoParam; } // =========================================================================== // Ä SetMessage() // Set the message and ioParam to be broadcast when UserChangedText() is called. // A message of msg_Nothing means nothing is broadcast. // ioParamEnum is an enumerated value: either eNULLIoParam, ePaneIDIoParam, // eThisPtrIoParam, eTEHandleIoParam, or eValueIoParam. // =========================================================================== // void cBroadcastingTextEditView::SetMessage(MessageT newMsg, ioParamEnum ioParamEnum){ mUserChangedTextMsg = newMsg, mMsgIoParamType = ioParamEnum; } // =========================================================================== // Ä GetMessage() // Get message sent when UserChangedText() is called, as well as the ioParam type. // =========================================================================== // void cBroadcastingTextEditView::GetMessage(MessageT& outMsg, Int16& outIoParamEnum){ outMsg = mUserChangedTextMsg, outIoParamEnum = mMsgIoParamType; } // =========================================================================== // Ä SetCommand() // Set the command and ioParam to be sent to superCommander when UserChangedText() is called. // A command of cmd_Nothing means nothing is sent to superCommander. // ioParamEnum is an enumerated value: either eNULLIoParam, ePaneIDIoParam, // eThisPtrIoParam, eTEHandleIoParam, or eValueIoParam. // =========================================================================== // void cBroadcastingTextEditView::SetCommand(CommandT newCmd, ioParamEnum ioParamEnum){ mUserChangedTextCmd = newCmd, mCmdIoParamType = ioParamEnum; } // =========================================================================== // Ä GetCommand() // Get command sent to superCommander when UserChangedText() is called, as well as the ioParam type. // =========================================================================== // void cBroadcastingTextEditView::GetCommand(CommandT& outCmd, Int16& outIoParamEnum){ outCmd = mUserChangedTextCmd, outIoParamEnum = mCmdIoParamType; } // =========================================================================== // Ä DoSendMessage() // If mUserChangedTextMsg isn't msg_Nothing, broadcast it with appropriate ioParam. // =========================================================================== // void cBroadcastingTextEditView::DoSendMessage(void){ if (mUserChangedTextMsg != msg_Nothing && mIsBroadcasting){ switch(mMsgIoParamType){ case eNULLIoParam: BroadcastMessage(mUserChangedTextMsg, NULL); break; case ePaneIDIoParam: BroadcastMessage(mUserChangedTextMsg, &mPaneID); break; case eThisPtrIoParam: BroadcastMessage(mUserChangedTextMsg, this); break; case eTEHandleIoParam: BroadcastMessage(mUserChangedTextMsg, GetMacTEH()); break; case eValueIoParam: Handle theText = GetTextHandle(); if(theText){ StHandleLocker theLock(theText); LStr255 theString(theText); long theLong = 0; StringToNum(&theString[0], &theLong); BroadcastMessage(mUserChangedTextMsg, &theLong); } break; } } } // =========================================================================== // Ä DoSendMessage() // If mUserChangedTextCmd isn't cmd_Nothing, // and if mSuperCommander isn't NULL, send command to superCommander with appropriate ioParam. // =========================================================================== // void cBroadcastingTextEditView::DoSendCommand(void){ if (mUserChangedTextCmd != cmd_Nothing && mSuperCommander != NULL){ switch(mCmdIoParamType){ case eNULLIoParam: mSuperCommander->ObeyCommand(mUserChangedTextCmd, NULL); break; case ePaneIDIoParam: mSuperCommander->ObeyCommand(mUserChangedTextCmd, &mPaneID); break; case eThisPtrIoParam: mSuperCommander->ObeyCommand(mUserChangedTextCmd, this); break; case eTEHandleIoParam: mSuperCommander->ObeyCommand(mUserChangedTextCmd, GetMacTEH()); break; case eValueIoParam: Handle theText = GetTextHandle(); if(theText){ StHandleLocker theLock(theText); LStr255 theString(theText); long theLong = 0; StringToNum(&theString[0], &theLong); mSuperCommander->ObeyCommand(mUserChangedTextCmd, &theLong); } break; } } }