Skip to content

Commit

Permalink
Added script function SetScroll
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Sep 4, 2010
1 parent fdf2772 commit 5bb6c97
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 14 deletions.
1 change: 1 addition & 0 deletions doc.cpp
Expand Up @@ -605,6 +605,7 @@ BEGIN_DISPATCH_MAP(CMUSHclientDoc, CDocument)
DISP_FUNCTION(CMUSHclientDoc, "WindowResize", WindowResize, VT_I4, VTS_BSTR VTS_I4 VTS_I4 VTS_I4)
DISP_FUNCTION(CMUSHclientDoc, "WindowMoveHotspot", WindowMoveHotspot, VT_I4, VTS_BSTR VTS_BSTR VTS_I4 VTS_I4 VTS_I4 VTS_I4)
DISP_FUNCTION(CMUSHclientDoc, "WindowTransformImage", WindowTransformImage, VT_I4, VTS_BSTR VTS_BSTR VTS_R4 VTS_R4 VTS_I2 VTS_R4 VTS_R4 VTS_R4 VTS_R4)
DISP_FUNCTION(CMUSHclientDoc, "SetScroll", SetScroll, VT_I4, VTS_I4 VTS_BOOL)
DISP_PROPERTY_PARAM(CMUSHclientDoc, "NormalColour", GetNormalColour, SetNormalColour, VT_I4, VTS_I2)
DISP_PROPERTY_PARAM(CMUSHclientDoc, "BoldColour", GetBoldColour, SetBoldColour, VT_I4, VTS_I2)
DISP_PROPERTY_PARAM(CMUSHclientDoc, "CustomColourText", GetCustomColourText, SetCustomColourText, VT_I4, VTS_I2)
Expand Down
2 changes: 2 additions & 0 deletions doc.h
Expand Up @@ -1288,6 +1288,7 @@ class CMUSHclientDoc : public CDocument
map<COLORREF, COLORREF> m_ColourTranslationMap;

list<CPaneStyle> m_OutstandingLines;
BOOL m_bScrollBarWanted; // true if we want to see scroll bars

long m_nCount_IAC_DO; // count of IAC DO we got
long m_nCount_IAC_DONT; // count of IAC DONT we got
Expand Down Expand Up @@ -2672,6 +2673,7 @@ class CMUSHclientDoc : public CDocument
afx_msg long WindowResize(LPCTSTR Name, long Width, long Height, long BackgroundColour);
afx_msg long WindowMoveHotspot(LPCTSTR Name, LPCTSTR HotspotId, long Left, long Top, long Right, long Bottom);
afx_msg long WindowTransformImage(LPCTSTR Name, LPCTSTR ImageId, float Left, float Top, short Mode, float Mxx, float Mxy, float Myx, float Myy);
afx_msg long SetScroll(long Position, BOOL Visible);
afx_msg long GetNormalColour(short WhichColour);
afx_msg void SetNormalColour(short WhichColour, long nNewValue);
afx_msg long GetBoldColour(short WhichColour);
Expand Down
1 change: 1 addition & 0 deletions doc_construct.cpp
Expand Up @@ -122,6 +122,7 @@ int i;
m_strSpamMessage = "look";
m_iSpamLineCount = 20;
m_iLastOutgoingChatPort = DEFAULT_CHAT_PORT;
m_bScrollBarWanted = TRUE;

m_iSocksProcessing = 0; // no socks processing wanted
m_iProxyServerPort = 1080; // default socks port
Expand Down
1 change: 1 addition & 0 deletions mushclient.cnt
Expand Up @@ -488,6 +488,7 @@
3 SetOption=FNC_SetOption
3 SetOutputFont=FNC_SetOutputFont
3 SetStatus=FNC_SetStatus
3 SetScroll=FNC_SetScroll
3 SetTimerOption=FNC_SetTimerOption
3 SetToolBarPosition=FNC_SetToolBarPosition
3 SetTriggerOption=FNC_SetTriggerOption
Expand Down
17 changes: 9 additions & 8 deletions mushclient.odl
Expand Up @@ -70,14 +70,14 @@ library MUSHclient
[id(44)] long SetCommand(BSTR Message);
[id(45)] BSTR GetNotes();
[id(46)] void SetNotes(BSTR Message);
[id(403), propget] long NormalColour(short WhichColour);
[id(403), propput] void NormalColour(short WhichColour, long nNewValue);
[id(404), propget] long BoldColour(short WhichColour);
[id(404), propput] void BoldColour(short WhichColour, long nNewValue);
[id(405), propget] long CustomColourText(short WhichColour);
[id(405), propput] void CustomColourText(short WhichColour, long nNewValue);
[id(406), propget] long CustomColourBackground(short WhichColour);
[id(406), propput] void CustomColourBackground(short WhichColour, long nNewValue);
[id(404), propget] long NormalColour(short WhichColour);
[id(404), propput] void NormalColour(short WhichColour, long nNewValue);
[id(405), propget] long BoldColour(short WhichColour);
[id(405), propput] void BoldColour(short WhichColour, long nNewValue);
[id(406), propget] long CustomColourText(short WhichColour);
[id(406), propput] void CustomColourText(short WhichColour, long nNewValue);
[id(407), propget] long CustomColourBackground(short WhichColour);
[id(407), propput] void CustomColourBackground(short WhichColour, long nNewValue);
[id(47)] void Redraw();
[id(48)] long ResetTimer(BSTR TimerName);
[id(49)] void SetOutputFont(BSTR FontName, short PointSize);
Expand Down Expand Up @@ -434,6 +434,7 @@ library MUSHclient
[id(400)] long WindowResize(BSTR Name, long Width, long Height, long BackgroundColour);
[id(401)] long WindowMoveHotspot(BSTR Name, BSTR HotspotId, long Left, long Top, long Right, long Bottom);
[id(402)] long WindowTransformImage(BSTR Name, BSTR ImageId, float Left, float Top, short Mode, float Mxx, float Mxy, float Myx, float Myy);
[id(403)] long SetScroll(long Position, BOOL Visible);
//}}AFX_ODL_METHOD

};
Expand Down
16 changes: 10 additions & 6 deletions mushview.cpp
Expand Up @@ -3053,6 +3053,8 @@ if (wp.showCmd != SW_MINIMIZE &&

} // end of auto-wrap wanted
pDoc->SendWindowSizes (pDoc->m_nWrapColumn);
EnableScrollBarCtrl (SB_VERT, pDoc->m_bScrollBarWanted);

}

void CMUSHView::OnDisplayFreezeoutput()
Expand Down Expand Up @@ -4401,7 +4403,7 @@ int iDeltaY = m_scroll_position.y - pt.y;
// update scroll bar
GetScrollInfo (SB_VERT, &ScrollInfo, SIF_POS);
ScrollInfo.nPos = m_scroll_position.y;
SetScrollInfo (SB_VERT, &ScrollInfo, SIF_POS);
SetScrollInfo (SB_VERT, &ScrollInfo, pDoc->m_bScrollBarWanted);
ScrollWindow (0, iSmoothDelta);
UpdateWindow ();
}
Expand Down Expand Up @@ -4436,11 +4438,11 @@ int iDeltaY = m_scroll_position.y - pt.y;
// update scroll bar
GetScrollInfo (SB_VERT, &ScrollInfo, SIF_POS);
ScrollInfo.nPos = pt.y;
SetScrollInfo (SB_VERT, &ScrollInfo, SIF_POS);
SetScrollInfo (SB_VERT, &ScrollInfo, pDoc->m_bScrollBarWanted);

// GetScrollInfo (SB_HORZ, &ScrollInfo, SIF_POS);
// ScrollInfo.nPos = pt.x;
// SetScrollInfo (SB_HORZ, &ScrollInfo, SIF_POS);
// SetScrollInfo (SB_HORZ, &ScrollInfo, pDoc->m_bScrollBarWanted);

if (pDoc->m_bAutoFreeze)
m_freeze = GetScrollPos (SB_VERT) < GetScrollLimit(SB_VERT);
Expand All @@ -4451,22 +4453,24 @@ void CMUSHView::SetScrollSizes (SIZE sizeTotal,
const SIZE& sizePage,
const SIZE& sizeLine)
{
SCROLLINFO ScrollInfo;
CMUSHclientDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
SCROLLINFO ScrollInfo;

m_scroll_limit = sizeTotal;

GetScrollInfo (SB_VERT, &ScrollInfo, SIF_ALL);
ScrollInfo.nMin = 0;
ScrollInfo.nMax = sizeTotal.cy - 1;
ScrollInfo.nPage = sizePage.cy;
SetScrollInfo (SB_VERT, &ScrollInfo, SIF_ALL);
SetScrollInfo (SB_VERT, &ScrollInfo, pDoc->m_bScrollBarWanted);

/*
GetScrollInfo (SB_HORZ, &ScrollInfo, SIF_ALL);
ScrollInfo.nMin = 0;
ScrollInfo.nMax = sizeTotal.cx - 1;
ScrollInfo.nPage = sizePage.cx;
SetScrollInfo (SB_HORZ, &ScrollInfo, SIF_ALL);
SetScrollInfo (SB_HORZ, &ScrollInfo, pDoc->m_bScrollBarWanted);
*/

} // end of CMUSHView::SetScrollSizes
Expand Down
1 change: 1 addition & 0 deletions scripting/functionlist.cpp
Expand Up @@ -346,6 +346,7 @@ tInternalFunctionsTable InternalFunctionsTable [] = {
{ "SetNotes" , "( Message )" } ,
{ "SetOption" , "( OptionName , Value )" } ,
{ "SetOutputFont" , "( FontName , PointSize )" } ,
{ "SetScroll", "( Position , Visible )" },
{ "SetStatus" , "( Message )" } ,
{ "SetTimerOption" , "( TimerName , OptionName , Value )" } ,
{ "SetToolBarPosition" , "( Which , Float , Side , Top , Left )" } ,
Expand Down
13 changes: 13 additions & 0 deletions scripting/lua_methods.cpp
Expand Up @@ -5195,6 +5195,18 @@ static int L_SetOutputFont (lua_State *L)
return 0; // number of result fields
} // end of L_SetOutputFont

//----------------------------------------
// world.SetScroll
//----------------------------------------
static int L_SetScroll (lua_State *L)
{
CMUSHclientDoc *pDoc = doc (L);
lua_pushnumber (L, pDoc->SetScroll (
my_checknumber (L, 1), // position
optboolean (L, 2, 1) // enabled flag, defaults to true
));
return 1; // number of result fields
} // end of L_SetScroll

//----------------------------------------
// world.SetStatus
Expand Down Expand Up @@ -6738,6 +6750,7 @@ static const struct luaL_reg worldlib [] =
{"SetNotes", L_SetNotes},
{"SetOption", L_SetOption},
{"SetOutputFont", L_SetOutputFont},
{"SetScroll", L_SetScroll},
{"SetStatus", L_SetStatus},
{"SetTimerOption", L_SetTimerOption},
{"SetToolBarPosition", L_SetToolBarPosition},
Expand Down
56 changes: 56 additions & 0 deletions scripting/methods.cpp
Expand Up @@ -4203,6 +4203,7 @@ tInfoTypeMapping InfoTypes [] =
{ 115, "Localization active" },
{ 118, "Variables have changed" },
{ 119, "Script engine active" },
{ 120, "Scroll bar visible" },


// (numbers (longs) - calculated at runtime)
Expand Down Expand Up @@ -4302,6 +4303,7 @@ tInfoTypeMapping InfoTypes [] =
{ 293, "Actual text rectangle - bottom" },
{ 294, "State of keyboard modifiers" },
{ 295, "Times output window redrawn" },
{ 296, "Output window scroll bar position" },


// (dates - calculated at runtime)
Expand Down Expand Up @@ -4553,6 +4555,7 @@ VARIANT CMUSHclientDoc::GetInfo(long InfoType)
case 115: SetUpVariantBool (vaResult, App.m_Translator_Lua != NULL); break;
case 118: SetUpVariantBool (vaResult, m_bVariablesChanged); break;
case 119: SetUpVariantBool (vaResult, m_ScriptEngine != NULL); break;
case 120: SetUpVariantBool (vaResult, m_bScrollBarWanted); break;


case 201: SetUpVariantLong (vaResult, m_total_lines); break;
Expand Down Expand Up @@ -5023,6 +5026,18 @@ VARIANT CMUSHclientDoc::GetInfo(long InfoType)
SetUpVariantLong (vaResult, m_iOutputWindowRedrawCount);
break; // state of virtual keys

case 296:
{
CMUSHView* pmyView = GetFirstOutputWindow ();
if (pmyView)
{
CPoint pt = pmyView->GetScrollPosition ();
SetUpVariantLong (vaResult, pt.y);
break;
}
}
break;

case 301:
if (m_tConnectTime.GetTime ()) // only if non-zero, otherwise return empty
SetUpVariantDate (vaResult, COleDateTime (m_tConnectTime.GetTime ()));
Expand Down Expand Up @@ -14903,6 +14918,47 @@ long CMUSHclientDoc::WindowTransformImage(LPCTSTR Name, LPCTSTR ImageId, float L



long CMUSHclientDoc::SetScroll(long Position, BOOL Visible)
{

CPoint pt (0, 0);
int lastline = GetLastLine ();
m_bScrollBarWanted = Visible;

for(POSITION pos = GetFirstViewPosition(); pos != NULL; )
{
CView* pView = GetNextView(pos);

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

int highest = (lastline * m_FontHeight) - pmyView->GetOutputWindowHeight ();

// -1 goes to the end
if (Position == -1)
pt.y = highest;
else
pt.y = Position;

if (pt.y < 0)
pt.y = 0;
if (pt.y > highest)
pt.y = highest;

pmyView->EnableScrollBarCtrl (SB_VERT, Visible);
if (Position != -2) // if -2, do not change position
pmyView->ScrollToPosition (pt, false);
pmyView->Invalidate ();

} // end of being a CMUSHView
} // end of loop through views


return eOK;
}


/*

======================================================================
Expand Down

0 comments on commit 5bb6c97

Please sign in to comment.