Skip to content

Commit

Permalink
Added option 'wrap_input' to wrap command window at output wrap column
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Dec 12, 2011
1 parent e093abc commit b57100e
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 2 deletions.
2 changes: 2 additions & 0 deletions dialogs/world_prefs/configuration.cpp
Expand Up @@ -1616,6 +1616,8 @@ void CMUSHclientDoc:: SavePrefsP14 (CPrefsP14 &page14)

m_nWrapColumn = page14.m_nWrapColumn;

FixInputWrap();

} // end of CMUSHclientDoc::SavePrefsP14

void CMUSHclientDoc:: SavePrefsP15 (CPrefsP15 &page15)
Expand Down
16 changes: 16 additions & 0 deletions doc.cpp
Expand Up @@ -7823,3 +7823,19 @@ void CMUSHclientDoc::SortWindows (void)

} // end of CMUSHclientDoc::SortWindows


void CMUSHclientDoc::FixInputWrap()
{
for(POSITION pos=GetFirstViewPosition();pos!=NULL;)
{
CView* pView = GetNextView(pos);

if (pView->IsKindOf(RUNTIME_CLASS(CSendView)))
{
CSendView* pmyView = (CSendView*)pView;
pmyView->UpdateWrap();
} // end of if CSendView
} // end of for each view
} // end of CMUSHclientDoc::FixInputWrap()


5 changes: 5 additions & 0 deletions doc.h
Expand Up @@ -377,6 +377,7 @@ enum {
#define OPT_PLUGIN_CANNOT_RW 0x300000 // plugin may not read or write its value
#define OPT_CANNOT_WRITE 0x400000 // cannot be changed by any script
#define OPT_SERVER_CAN_WRITE 0x800000 // CAN be changed by <recommend_option> tag
#define OPT_FIX_INPUT_WRAP 0x1000000 // Added for input wrapping.

// for debug.options and MXP <option> tag
typedef struct
Expand Down Expand Up @@ -880,6 +881,9 @@ class CMUSHclientDoc : public CDocument
unsigned short m_bTreeviewAliases; // show aliases in tree view?
unsigned short m_bTreeviewTimers; // show timers in tree view?

// version 4.81
unsigned short m_bAutoWrapInput; // Match input wrap to output?

// end of stuff saved to disk **************************************************************

// stuff from pre version 11, read from disk but not saved
Expand Down Expand Up @@ -1423,6 +1427,7 @@ class CMUSHclientDoc : public CDocument
CArgumentList & ArgumentList);

void AddToCommandHistory (LPCTSTR Message);
void FixInputWrap();

// simple test to see if we are in secure mode right now
inline bool MXP_Secure (void)
Expand Down
5 changes: 5 additions & 0 deletions mushview.cpp
Expand Up @@ -282,6 +282,7 @@ CMUSHView::CMUSHView()
m_nLastToolTipColumn = 0;
m_scroll_position = 0;
m_mousedover = false;
m_bottomview = NULL;

m_iPauseStatus = ePauseUninitialised;

Expand Down Expand Up @@ -3213,6 +3214,10 @@ if (wp.showCmd != SW_MINIMIZE &&
pDoc->SendWindowSizes (pDoc->m_nWrapColumn);
EnableScrollBarCtrl (SB_VERT, pDoc->m_bScrollBarWanted);

// update wrap size
if (m_bottomview)
m_bottomview->UpdateWrap();

}

void CMUSHView::OnDisplayFreezeoutput()
Expand Down
1 change: 1 addition & 0 deletions plugins/Config_Option_Changer.xml
Expand Up @@ -68,6 +68,7 @@ boolean_options = {
do_not_translate_iac_to_iac_iac = { desc = 'Translate IAC to IAC IAC?' , invert = true },
play_sounds_in_background = { desc = 'Play sounds in background?' },
send_keep_alives = { desc = 'Send keep-alives?' },
wrap_input = { desc = 'Wrap command window at output wrap column' },
} -- end boolean_options
-- numeric options they can change
Expand Down
9 changes: 7 additions & 2 deletions scriptingoptions.cpp
Expand Up @@ -152,7 +152,7 @@ tConfigurationNumericOption OptionsTable [] = {
{"paste_delay_per_lines", 1, O(m_nPasteDelayPerLines), 1, 100000},
{"paste_echo", false, O(m_bPasteEcho)},
{"play_sounds_in_background", false, O(m_bPlaySoundsInBackground)},
{"pixel_offset", 1, O(m_iPixelOffset), 0, 20, OPT_UPDATE_VIEWS},
{"pixel_offset", 1, O(m_iPixelOffset), 0, 20, OPT_UPDATE_VIEWS | OPT_FIX_INPUT_WRAP},
{"port", 4000, O(m_port), 1, USHRT_MAX, OPT_PLUGIN_CANNOT_WRITE},
{"proxy_port", 1080, O(m_iProxyServerPort), 0, USHRT_MAX, OPT_PLUGIN_CANNOT_WRITE},
{"proxy_type", eProxyServerNone, O(m_iSocksProcessing), eProxyServerNone, eProxyServerLast - 1, OPT_PLUGIN_CANNOT_WRITE},
Expand Down Expand Up @@ -206,7 +206,9 @@ tConfigurationNumericOption OptionsTable [] = {
{"validate_incoming_chat_calls", false, O(m_bValidateIncomingCalls)},
{"warn_if_scripting_inactive", true, O(m_bWarnIfScriptingInactive)},
{"wrap", true, O(m_wrap)},
{"wrap_column", 80, O(m_nWrapColumn), 20, MAX_LINE_WIDTH, OPT_FIX_WRAP_COLUMN},
{"wrap_input", false, O(m_bAutoWrapInput), 0, 0, OPT_FIX_INPUT_WRAP}, // Added this, also fix wrap on column change.
{"wrap_column", 80, O(m_nWrapColumn), 20, MAX_LINE_WIDTH, OPT_FIX_WRAP_COLUMN | OPT_FIX_INPUT_WRAP},

{"write_world_name_to_log", true, O(m_bWriteWorldNameToLog)},

{NULL} // end of table marker
Expand Down Expand Up @@ -517,6 +519,9 @@ long iResult = SetBaseOptionItem (iItem,
if (m_pCurrentLine) // a new world might not have a line yet
FixUpOutputBuffer (Value);

if (OptionsTable [iItem].iFlags & OPT_FIX_INPUT_WRAP)
FixInputWrap();

if (OptionsTable [iItem].iFlags & OPT_FIX_WRAP_COLUMN)
{
if (m_pCurrentLine) // a new world might not have a line yet
Expand Down
54 changes: 54 additions & 0 deletions sendvw.cpp
Expand Up @@ -1174,6 +1174,7 @@ void CSendView::OnChange()

NotifyPluginCommandChanged ();

UpdateWrap();
} // end of CSendView::OnChange


Expand Down Expand Up @@ -1221,6 +1222,9 @@ void CSendView::OnInitialUpdate()

// if they want auto-command size, put back to 1
AdjustCommandWindowSize ();

UpdateWrap();

} // end of CSendView::OnInitialUpdate

void CSendView::OnContextMenu(CWnd*, CPoint point)
Expand Down Expand Up @@ -2961,3 +2965,53 @@ void CSendView::OnEditCopyashtml()
m_topview->OnEditCopyashtml ();
} // end of CSendView::OnEditCopyashtml()


void CSendView::UpdateWrap()
{

CMUSHclientDoc* pDoc = GetDocument();
CEdit& theEdit = GetEditCtrl();

int iOffset = pDoc->m_iPixelOffset; // Need this either way.

if (pDoc->m_bAutoWrapInput)
{

CRect r;
GetClientRect(r); // How big is the input window?

int iWidth = pDoc->m_nWrapColumn + 1; // Letter-width of the line.

if (iWidth < 20)
iWidth = 20;
if (iWidth > MAX_LINE_WIDTH)
iWidth = MAX_LINE_WIDTH; // Uses the minimums and maximums from elsewhere.

// Subtracts the pixel width of text and the left-side offset to determine what the right side should be.
int rMargin = r.Width() - (iWidth * pDoc->m_InputFontWidth) - iOffset;

// If the right side isn't at least as big as the offset, use the offset.
if (rMargin < iOffset)
rMargin = iOffset;

// If the margin needs to change, change it.
if (rMargin != HIWORD(theEdit.GetMargins()))
{
theEdit.SetMargins (iOffset, rMargin);
theEdit.Invalidate (FALSE);
} // end if changed

} // end if m_bAutoWrapInput
else
{
iOffset = 0; // prefer this, Neva
// not wrapping
if ( HIWORD(theEdit.GetMargins ()) != iOffset) // If the option is off, just using the offset.
{
theEdit.SetMargins (iOffset, iOffset);
theEdit.Invalidate (FALSE);
} // end if changed
} // end if

} // end of CSendView::UpdateWrap()

1 change: 1 addition & 0 deletions sendvw.h
Expand Up @@ -80,6 +80,7 @@ class CSendView : public CEditView
void AdjustCommandWindowSize (void);
void CheckForSelectionChange (void);
void CancelSelection (void);
void UpdateWrap();

// Overrides
// ClassWizard generated virtual function overrides
Expand Down

0 comments on commit b57100e

Please sign in to comment.