Skip to content

Commit

Permalink
Added ability to detect word under mouse during alias menu operation
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Oct 23, 2010
1 parent 24b0db7 commit cf98abf
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,8 @@ class CMUSHclientDoc : public CDocument
long m_nCount_IAC_WONT; // count of IAC WONT we got
long m_nCount_IAC_SB; // count of IAC SB x IAC SE we got

CString m_strWordUnderMenu; // word under menu in output window

#ifdef PANE
// for pane windows

Expand Down
45 changes: 44 additions & 1 deletion mushview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1891,6 +1891,49 @@ void CMUSHView::AliasMenu (CPoint point)
CMUSHclientDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

if (!pDoc->m_FontHeight)
return;

CPoint wordPoint (point);

// CView changes the viewport origin and mapping mode.
// It's necessary to convert the point from device coordinates
// to logical coordinates, such as are stored in the document.
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&wordPoint);

int line, start_col, end_col, col;

// find which line and column the mouse position is at

calculate_line_and_column (wordPoint, dc, line, col, false);

POSITION pos = pDoc->GetLinePosition (line);

start_col = end_col = col;

// find word under mouse for GetInfo (86)

CLine * pLine = pDoc->m_LineList.GetAt (pos);
while (start_col >= 0 &&
!isspace ((unsigned char) pLine->text [start_col]) &&
strchr (App.m_strWordDelimitersDblClick, pLine->text [start_col]) == NULL)
start_col--;
start_col++; // now onto the start of that word

// a word will end on a space, or whatever
while (end_col < pLine->len &&
!isspace ((unsigned char) pLine->text [end_col]) &&
strchr (App.m_strWordDelimitersDblClick, pLine->text [end_col]) == NULL)
end_col++;

if (end_col > start_col)
pDoc->m_strWordUnderMenu = CString (&pLine->text [start_col],
end_col - start_col);
else
pDoc->m_strWordUnderMenu.Empty ();

CPoint menupoint = point;

CMenu menu;
Expand All @@ -1907,7 +1950,7 @@ CPoint menupoint = point;
CAlias * pAlias;
CString strAliasName;

for (POSITION pos = pDoc->m_AliasMap.GetStartPosition();
for (pos = pDoc->m_AliasMap.GetStartPosition();
pos && i < MXP_MENU_COUNT;
)
{
Expand Down
3 changes: 3 additions & 0 deletions scripting/methods/methods_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ tInfoTypeMapping InfoTypes [] =
{ 83, "SQLite3 version" },
{ 84, "File browsing directory" },
{ 85, "State files path (directory)" },
{ 86, "Word under mouse on mouse menu" },




Expand Down Expand Up @@ -538,6 +540,7 @@ VARIANT CMUSHclientDoc::GetInfo(long InfoType)
case 83: SetUpVariantString (vaResult, sqlite3_libversion ()); break;
case 84: SetUpVariantString (vaResult, file_browsing_dir); break;
case 85: SetUpVariantString (vaResult, App.m_strDefaultStateFilesDirectory); break;
case 86: SetUpVariantString (vaResult, m_strWordUnderMenu); break;


case 101: SetUpVariantBool (vaResult, m_bNoEcho); break;
Expand Down

0 comments on commit cf98abf

Please sign in to comment.