📄 hubframe.cpp
字号:
if( r.PtInRect(p) || MDIGetActive() != m_hWnd)
noscroll = FALSE;
else {
ctrlClient.SetRedraw(FALSE); // Strange!! This disables the scrolling...????
}
if(BOOLSETTING(LOG_MAIN_CHAT)) {
StringMap params;
params["message"] = Text::fromT(aLine);
client->getHubIdentity().getParams(params, "hub", false);
params["hubURL"] = client->getHubUrl();
client->getMyIdentity().getParams(params, "my", true);
LOG(LogManager::CHAT, params);
}
if(timeStamps) {
ctrlClient.AppendText((Text::toT("\r\n[" + Util::getShortTimeString() + "] ") + aLine).c_str());
} else {
ctrlClient.AppendText((_T("\r\n") + aLine).c_str());
}
if(noscroll) {
ctrlClient.SetRedraw(TRUE);
}
if (BOOLSETTING(BOLD_HUB)) {
setDirty();
}
}
LRESULT HubFrame::onTabContextMenu(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/) {
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; // location of mouse click
tabMenuShown = true;
prepareMenu(tabMenu, ::UserCommand::CONTEXT_HUB, client->getHubUrl());
tabMenu.AppendMenu(MF_SEPARATOR);
tabMenu.AppendMenu(MF_STRING, IDC_CLOSE_WINDOW, CTSTRING(CLOSE));
tabMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, m_hWnd);
tabMenu.DeleteMenu(tabMenu.GetMenuItemCount()-1, MF_BYPOSITION);
tabMenu.DeleteMenu(tabMenu.GetMenuItemCount()-1, MF_BYPOSITION);
cleanMenu(tabMenu);
return TRUE;
}
LRESULT HubFrame::onCtlColor(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) {
HWND hWnd = (HWND)lParam;
HDC hDC = (HDC)wParam;
if(hWnd == ctrlClient.m_hWnd || hWnd == ctrlMessage.m_hWnd ||
hWnd == ctrlFilter.m_hWnd || hWnd == ctrlFilterSel.m_hWnd) {
::SetBkColor(hDC, WinUtil::bgColor);
::SetTextColor(hDC, WinUtil::textColor);
return (LRESULT)WinUtil::bgBrush;
} else {
return 0;
}
}
LRESULT HubFrame::onContextMenu(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
bool doMenu = false;
if(reinterpret_cast<HWND>(wParam) == ctrlClient) {
if(pt.x == -1 && pt.y == -1) {
WinUtil::getContextMenuPos(ctrlClient, pt);
}
tstring x;
ctrlClient.ScreenToClient(&pt);
tstring::size_type start = (tstring::size_type)WinUtil::textUnderCursor(pt, ctrlClient, x);
ctrlClient.ClientToScreen(&pt);
tstring::size_type end = x.find_first_of(_T(" >\t"), start+1);
if(end == string::npos) // get EOL as well
end = x.length();
else if(end == start + 1) {
bHandled = FALSE;
return FALSE;
}
// Nickname click, let's see if we can find one like it in the name list...
int pos = ctrlUsers.findItem(x.substr(start, end - start));
if(pos != -1) {
int items = ctrlUsers.GetItemCount();
ctrlUsers.SetRedraw(FALSE);
for(int i = 0; i < items; ++i) {
ctrlUsers.SetItemState(i, (i == pos) ? LVIS_SELECTED | LVIS_FOCUSED : 0, LVIS_SELECTED | LVIS_FOCUSED);
}
ctrlUsers.SetRedraw(TRUE);
ctrlUsers.EnsureVisible(pos, FALSE);
doMenu = true;
}
}
if((doMenu || (reinterpret_cast<HWND>(wParam) == ctrlUsers)) && ctrlUsers.GetSelectedCount() > 0) {
if(pt.x == -1 && pt.y == -1) {
WinUtil::getContextMenuPos(ctrlUsers, pt);
}
tabMenuShown = false;
prepareMenu(userMenu, ::UserCommand::CONTEXT_CHAT, client->getHubUrl());
checkAdcItems(userMenu);
userMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, m_hWnd);
cleanMenu(userMenu);
return TRUE;
} else {
bHandled = FALSE; //needed to popup context menu under userlist
}
return FALSE;
}
void HubFrame::runUserCommand(::UserCommand& uc) {
if(!WinUtil::getUCParams(m_hWnd, uc, ucLineParams))
return;
StringMap ucParams = ucLineParams;
client->getMyIdentity().getParams(ucParams, "my", true);
client->getHubIdentity().getParams(ucParams, "hub", false);
if(tabMenuShown) {
client->escapeParams(ucParams);
client->sendUserCmd(Util::formatParams(uc.getCommand(), ucParams, false));
} else {
int sel = -1;
while((sel = ctrlUsers.GetNextItem(sel, LVNI_SELECTED)) != -1) {
UserInfo* u = (UserInfo*) ctrlUsers.GetItemData(sel);
StringMap tmp = ucParams;
u->getIdentity().getParams(tmp, "user", true);
client->escapeParams(tmp);
client->sendUserCmd(Util::formatParams(uc.getCommand(), tmp, false));
}
}
}
void HubFrame::onTab() {
if(ctrlMessage.GetWindowTextLength() == 0) {
handleTab(WinUtil::isShift());
return;
}
HWND focus = GetFocus();
if( (focus == ctrlMessage.m_hWnd) && !WinUtil::isShift() )
{
int n = ctrlMessage.GetWindowTextLength();
AutoArray<TCHAR> buf(n+1);
ctrlMessage.GetWindowText(buf, n+1);
tstring text(buf, n);
string::size_type textStart = text.find_last_of(_T(" \n\t"));
if(complete.empty()) {
if(textStart != string::npos) {
complete = text.substr(textStart + 1);
} else {
complete = text;
}
if(complete.empty()) {
// Still empty, no text entered...
ctrlUsers.SetFocus();
return;
}
int y = ctrlUsers.GetItemCount();
for(int x = 0; x < y; ++x)
ctrlUsers.SetItemState(x, 0, LVNI_FOCUSED | LVNI_SELECTED);
}
if(textStart == string::npos)
textStart = 0;
else
textStart++;
int start = ctrlUsers.GetNextItem(-1, LVNI_FOCUSED) + 1;
int i = start;
int j = ctrlUsers.GetItemCount();
bool firstPass = i < j;
if(!firstPass)
i = 0;
while(firstPass || (!firstPass && i < start)) {
UserInfo* ui = ctrlUsers.getItemData(i);
const tstring& nick = ui->columns[COLUMN_NICK];
bool found = (Util::strnicmp(nick, complete, complete.length()) == 0);
tstring::size_type x = 0;
if(!found) {
// Check if there's one or more [ISP] tags to ignore...
tstring::size_type y = 0;
while(nick[y] == _T('[')) {
x = nick.find(_T(']'), y);
if(x != string::npos) {
if(Util::strnicmp(nick.c_str() + x + 1, complete.c_str(), complete.length()) == 0) {
found = true;
break;
}
} else {
break;
}
y = x + 1; // assuming that nick[y] == '\0' is legal
}
}
if(found) {
if((start - 1) != -1) {
ctrlUsers.SetItemState(start - 1, 0, LVNI_SELECTED | LVNI_FOCUSED);
}
ctrlUsers.SetItemState(i, LVNI_FOCUSED | LVNI_SELECTED, LVNI_FOCUSED | LVNI_SELECTED);
ctrlUsers.EnsureVisible(i, FALSE);
ctrlMessage.SetSel(textStart, ctrlMessage.GetWindowTextLength(), TRUE);
ctrlMessage.ReplaceSel(nick.c_str());
return;
}
i++;
if(i == j) {
firstPass = false;
i = 0;
}
}
}
}
LRESULT HubFrame::onFileReconnect(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
client->disconnect(false);
clearUserList();
clearTaskList();
client->connect();
return 0;
}
LRESULT HubFrame::onChar(UINT uMsg, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled) {
if(!complete.empty() && wParam != VK_TAB && uMsg == WM_KEYDOWN)
complete.clear();
if (uMsg != WM_KEYDOWN) {
switch(wParam) {
case VK_RETURN:
if( (GetKeyState(VK_CONTROL) & 0x8000) || (GetKeyState(VK_MENU) & 0x8000) ) {
bHandled = FALSE;
}
break;
case VK_TAB:
bHandled = TRUE;
break;
default:
bHandled = FALSE;
break;
}
return 0;
}
switch(wParam) {
case VK_TAB:
onTab();
break;
case VK_RETURN:
if( (GetKeyState(VK_CONTROL) & 0x8000) ||
(GetKeyState(VK_MENU) & 0x8000) ) {
bHandled = FALSE;
} else {
onEnter();
}
break;
case VK_UP:
if ( (GetKeyState(VK_MENU) & 0x8000) || ( ((GetKeyState(VK_CONTROL) & 0x8000) == 0) ^ (BOOLSETTING(USE_CTRL_FOR_LINE_HISTORY) == true) ) ) {
//scroll up in chat command history
//currently beyond the last command?
if (curCommandPosition > 0) {
//check whether current command needs to be saved
if (curCommandPosition == prevCommands.size()) {
auto_ptr<TCHAR> messageContents(new TCHAR[ctrlMessage.GetWindowTextLength()+2]);
ctrlMessage.GetWindowText(messageContents.get(), ctrlMessage.GetWindowTextLength()+1);
currentCommand = tstring(messageContents.get());
}
//replace current chat buffer with current command
ctrlMessage.SetWindowText(prevCommands[--curCommandPosition].c_str());
}
// move cursor to end of line
ctrlMessage.SetSel(ctrlMessage.GetWindowTextLength(), ctrlMessage.GetWindowTextLength());
} else {
bHandled = FALSE;
}
break;
case VK_DOWN:
if ( (GetKeyState(VK_MENU) & 0x8000) || ( ((GetKeyState(VK_CONTROL) & 0x8000) == 0) ^ (BOOLSETTING(USE_CTRL_FOR_LINE_HISTORY) == true) ) ) {
//scroll down in chat command history
//currently beyond the last command?
if (curCommandPosition + 1 < prevCommands.size()) {
//replace current chat buffer with current command
ctrlMessage.SetWindowText(prevCommands[++curCommandPosition].c_str());
} else if (curCommandPosition + 1 == prevCommands.size()) {
//revert to last saved, unfinished command
ctrlMessage.SetWindowText(currentCommand.c_str());
++curCommandPosition;
}
// move cursor to end of line
ctrlMessage.SetSel(ctrlMessage.GetWindowTextLength(), ctrlMessage.GetWindowTextLength());
} else {
bHandled = FALSE;
}
break;
case VK_PRIOR: // page up
ctrlClient.SendMessage(WM_VSCROLL, SB_PAGEUP);
break;
case VK_NEXT: // page down
ctrlClient.SendMessage(WM_VSCROLL, SB_PAGEDOWN);
break;
case VK_HOME:
if (!prevCommands.empty() && (GetKeyState(VK_CONTROL) & 0x8000) || (GetKeyState(VK_MENU) & 0x8000)) {
curCommandPosition = 0;
auto_ptr<TCHAR> messageContents(new TCHAR[ctrlMessage.GetWindowTextLength()+2]);
ctrlMessage.GetWindowText(messageContents.get(), ctrlMessage.GetWindowTextLength()+1);
currentCommand = tstring(messageContents.get());
ctrlMessage.SetWindowText(prevCommands[curCommandPosition].c_str());
} else {
bHandled = FALSE;
}
break;
case VK_END:
if ((GetKeyState(VK_CONTROL) & 0x8000) || (GetKeyState(VK_MENU) & 0x8000)) {
curCommandPosition = prevCommands.size();
ctrlMessage.SetWindowText(currentCommand.c_str());
} else {
bHandled = FALSE;
}
break;
default:
bHandled = FALSE;
}
return 0;
}
LRESULT HubFrame::onShowUsers(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled) {
bHandled = FALSE;
if((wParam == BST_CHECKED)) {
showUsers = true;
ctrlUsers.SetRedraw(FALSE);
ctrlUsers.DeleteAllItems();
for(UserMapIter i = userMap.begin(); i != userMap.end(); ++i) {
UserInfo* ui = i->second;
if(!ui->getIdentity().isHidden())
ctrlUsers.insertItem(ui, getImage(ui->getIdentity()));
}
ctrlUsers.SetRedraw(TRUE);
ctrlUsers.resort();
} else {
showUsers = false;
ctrlUsers.DeleteAllItems();
}
SettingsManager::getInstance()->set(SettingsManager::GET_USER_INFO, showUsers);
UpdateLayout(FALSE);
return 0;
}
LRESULT HubFrame::onFollow(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
if(!redirect.empty()) {
if(ClientManager::getInstance()->isConnected(Text::fromT(redirect))) {
addClientLine(TSTRING(REDIRECT_ALREADY_CONNECTED));
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -