Skip to content

Commit

Permalink
Fixed a couple of bugs regarding auto-wrap to window size
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Nov 28, 2010
1 parent abd36bd commit 0b8c3b6
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 76 deletions.
47 changes: 25 additions & 22 deletions dialogs/world_prefs/prefspropertypages.cpp
Expand Up @@ -5929,9 +5929,6 @@ void CPrefsP14::OnAdjustWidth()
// this is for the guy that wants to fit the max text he can in his window,
// after resizing it

if (m_doc->m_pActiveCommandView || m_doc->m_pActiveOutputView)
{

CDC dc;

dc.CreateCompatibleDC (NULL);
Expand All @@ -5954,33 +5951,39 @@ if (m_doc->m_pActiveCommandView || m_doc->m_pActiveOutputView)
MUSHCLIENT_FONT_FAMILY, // BYTE nPitchAndFamily, // was FF_DONTCARE
m_font_name);// LPCTSTR lpszFacename );

// Get the metrics of the font.
// Get the metrics of the font.

dc.SelectObject(font);
dc.SelectObject(font);

TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);

RECT rect;
// find the first output window, work out the correct width
for(POSITION pos = m_doc->GetFirstViewPosition(); pos != NULL; )
{
CView* pView = m_doc->GetNextView(pos);

if (pView->IsKindOf(RUNTIME_CLASS(CMUSHView)))
{
CMUSHView* pmyView = (CMUSHView*)pView;

if (m_doc->m_pActiveCommandView)
m_doc->m_pActiveCommandView->GetClientRect (&rect);
else
m_doc->m_pActiveOutputView->GetClientRect (&rect);
int iWidth = (pmyView->GetOutputWindowWidth () - m_doc->m_iPixelOffset) / tm.tmAveCharWidth;

int iWidth = (rect.right - rect.left - m_iPixelOffset) / tm.tmAveCharWidth;
// ensure in range that we allow
if (iWidth < 20)
iWidth = 20;
if (iWidth > MAX_LINE_WIDTH)
iWidth = MAX_LINE_WIDTH;

// ensure in range that we allow
if (iWidth < 20)
iWidth = 20;
if (iWidth > MAX_LINE_WIDTH)
iWidth = MAX_LINE_WIDTH;
// put in the new figure
m_ctlWrapColumn.SetWindowText (CFormat ("%i", iWidth));

break;
} // if CMUSHView
} // end for

// put in the new figure
m_ctlWrapColumn.SetWindowText (CFormat ("%i", iWidth));
} // end of CPrefsP14::OnAdjustWidth

}
}

LRESULT CPrefsP14::OnKickIdle(WPARAM, LPARAM)
{
Expand Down
110 changes: 59 additions & 51 deletions mushview.cpp
Expand Up @@ -3081,57 +3081,8 @@ void CMUSHView::OnKeysActivatecommandview()
}


void CMUSHView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);

CMUSHclientDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);


// find page size


// find last line

int lastline;

lastline = pDoc->GetLastLine ();

CSize sizeTotal (pDoc->m_nWrapColumn * pDoc->m_FontWidth, lastline * pDoc->m_FontHeight),
sizePage (GetOutputWindowWidth () - pDoc->m_iPixelOffset, GetOutputWindowHeight ()),
sizeLine (pDoc->m_FontWidth, pDoc->m_FontHeight);

SetScrollSizes (sizeTotal, sizePage, sizeLine);

// very bizarre bug - fixed in 4.39
// we seem to get size messages if we are maximized and in the background

bool bOldFreeze = m_freeze;
if (m_bAtBufferEnd)
OnTestEnd ();

m_freeze = bOldFreeze;

Frame.FixUpTitleBar (); // in case we need to add the mud name to the title bar

pDoc->SendToAllPluginCallbacks (ON_PLUGIN_WORLD_OUTPUT_RESIZED);


// this is for the guy that wants to fit the max text he can in his window,
// after resizing it

WINDOWPLACEMENT wp;
wp.length = sizeof (wp);
GetOwner()->GetOwner()->GetWindowPlacement (&wp);

// don't resize if not active, or minimized, or closed
if (wp.showCmd != SW_MINIMIZE &&
pDoc->m_iConnectPhase == eConnectConnectedToMud &&
(
pDoc->m_pActiveOutputView == this ||
pDoc->m_pActiveCommandView == m_bottomview
))
void CMUSHView::AutoWrapWindowWidth (CMUSHclientDoc* pDoc)
{

if (pDoc->m_bAutoWrapWindowWidth &&
!pDoc->m_font_name.IsEmpty () &&
Expand Down Expand Up @@ -3202,6 +3153,63 @@ if (wp.showCmd != SW_MINIMIZE &&


} // end of auto-wrap wanted


} // end of CMUSHView::AutoWrapWindowWidth

void CMUSHView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);

CMUSHclientDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);


// find page size


// find last line

int lastline;

lastline = pDoc->GetLastLine ();

CSize sizeTotal (pDoc->m_nWrapColumn * pDoc->m_FontWidth, lastline * pDoc->m_FontHeight),
sizePage (GetOutputWindowWidth () - pDoc->m_iPixelOffset, GetOutputWindowHeight ()),
sizeLine (pDoc->m_FontWidth, pDoc->m_FontHeight);

SetScrollSizes (sizeTotal, sizePage, sizeLine);

// very bizarre bug - fixed in 4.39
// we seem to get size messages if we are maximized and in the background

bool bOldFreeze = m_freeze;
if (m_bAtBufferEnd)
OnTestEnd ();

m_freeze = bOldFreeze;

Frame.FixUpTitleBar (); // in case we need to add the mud name to the title bar

pDoc->SendToAllPluginCallbacks (ON_PLUGIN_WORLD_OUTPUT_RESIZED);


// this is for the guy that wants to fit the max text he can in his window,
// after resizing it

WINDOWPLACEMENT wp;
wp.length = sizeof (wp);
GetOwner()->GetOwner()->GetWindowPlacement (&wp);

// don't resize if not active, or minimized, or closed
if (wp.showCmd != SW_MINIMIZE &&
pDoc->m_iConnectPhase == eConnectConnectedToMud &&
(
pDoc->m_pActiveOutputView == this ||
pDoc->m_pActiveCommandView == m_bottomview
))
AutoWrapWindowWidth (pDoc);

pDoc->SendWindowSizes (pDoc->m_nWrapColumn);
EnableScrollBarCtrl (SB_VERT, pDoc->m_bScrollBarWanted);

Expand Down
1 change: 1 addition & 0 deletions mushview.h
Expand Up @@ -157,6 +157,7 @@ bool GetSelection(CFile & f);
bool GetSelection(CString & s);
void SendMacro (int whichone);
void SelectionChanged (void);
void AutoWrapWindowWidth (CMUSHclientDoc* pDoc);

// Overrides
// ClassWizard generated virtual function overrides
Expand Down
14 changes: 11 additions & 3 deletions scripting/methods/methods_output.cpp
Expand Up @@ -668,7 +668,8 @@ long CMUSHclientDoc::TextRectangle(long Left, long Top, long Right, long Bottom,
m_TextRectangleBorderColour = BorderColour;
m_TextRectangleBorderWidth = BorderWidth;
m_TextRectangleOutsideFillColour = OutsideFillColour;
m_TextRectangleOutsideFillStyle = OutsideFillStyle;
m_TextRectangleOutsideFillStyle = OutsideFillStyle;
bool bFixedWindowWidth = false;

// refresh views - get scroll bars right

Expand All @@ -681,9 +682,16 @@ long CMUSHclientDoc::TextRectangle(long Left, long Top, long Right, long Bottom,
CMUSHView* pmyView = (CMUSHView*)pView;

pmyView->addedstuff();
}
}

// now fix up auto-wrapping column if required
if (!bFixedWindowWidth)
{
bFixedWindowWidth = true;
pmyView->AutoWrapWindowWidth(this);
} // if not already done
} // if CMUSHView
} // end for

SendWindowSizes (m_nWrapColumn); // notify of different window height
Redraw ();
return eOK;
Expand Down

0 comments on commit 0b8c3b6

Please sign in to comment.