/* * ToolbarButtonPressed: Toolbar button with given Button structure was pressed. */ void ToolbarButtonPressed(Button *b) { int action; void *data; /* See if module wants to handle this event */ if (ModuleEvent(EVENT_TOOLBUTTON, b) == False) return; action = b->action; data = b->action_data; // If button is a toggle, set state to toggled if pressing in; perform up action if pushing out if (b->action2 != A_NOACTION) { // b->pressed = !b->pressed; if (b->pressed) Button_SetState(b->hwnd, TRUE); else { action = b->action2; data = b->action_data2; } } PerformAction(action, data); }
void TextureToolWindow::addTextureButton(const std::string& name, EventReceiver* eventReceiver, const std::string& bitmapFilename) { const UINT count = (UINT)m_items.size(); const UINT x = (count % m_textureButtonsPerRow) * (m_textureButtonSize + m_itemMargin) + m_itemMargin; const UINT y = m_itemMargin; const UINT id = m_itemIDStart + count; HWND hButton = CreateWindow("BUTTON", "", WS_CHILD | WS_VISIBLE | BS_BITMAP | BS_PUSHLIKE, x, y, m_textureButtonSize, m_textureButtonSize, m_hWnd, (HMENU)id, m_hInstance, NULL); HBITMAP hBitmap = (HBITMAP)LoadImage(m_hInstance, bitmapFilename.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); SendMessage(hButton, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap); m_items.push_back(EventElement(name, eventReceiver)); m_checkableButtonIDs.push_back(id); if (y >= m_clientHeight) { m_clientHeight = m_textureButtonSize + 2 * m_itemMargin; const POINT windowSize = getWindowSize(); const POINT windowPosition = getWindowPosition(); SetWindowPos(m_hWnd, HWND_TOP, windowPosition.x, windowPosition.y, windowSize.x, windowSize.y, NULL); } if (count <= 0) Button_SetState(GetDlgItem(m_hWnd, id), true); }
void OutputChatMessage(int partner, char *text) { int j, n = strlen(text); if(!chatHandle[partner]) return; text[n+1] = 0; text[n] = '\n'; text[n-1] = '\r'; // Needs CR to not lose line breaks on copy-paste InsertIntoMemo(chatHandle[partner], text); if(partner != onTop) for(j=0; j<MAX_CHAT; j++) if(j != partner && chatHandle[j]) Button_SetState(GetDlgItem(chatHandle[j], IDC_Focus1+partner-(j<partner)), TRUE); }
/* * ToolbarSetButtonState: Given an action, find the corresponding toolbar button * and set its state (True = pressed in, False = out). This is only useful * for toggle buttons. * Returns True iff button state set. */ Bool ToolbarSetButtonState(int action, void *action_data, Bool state) { Button *b = ToolbarFindButtonByAction(action, action_data); if (b == NULL) return False; Button_SetState(b->hwnd, state); // Redraw if necessary if (state != b->pressed) InvalidateRect(b->hwnd, NULL, TRUE); b->pressed = state; return TRUE; }
LRESULT TextureToolWindow::subWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { if (message == WM_COMMAND) { const UINT id = LOWORD(wParam); for (std::vector<UINT>::iterator it = m_checkableButtonIDs.begin(); it != m_checkableButtonIDs.end(); it++) { if ((*it) == id) { resetButtonHighlights(); Button_SetState(GetDlgItem(m_hWnd, (*it)), true); } } } return Subwindow::subWndProc(hWnd, message, wParam, lParam); }
// This seems pure front end LRESULT CALLBACK ChatProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { static SnapData sd; char buf[MSG_SIZ], mess[MSG_SIZ]; int partner = -1, i, x, y; static BOOL filterHasFocus[MAX_CHAT]; WORD wMask; HWND hMemo; for(i=0; i<MAX_CHAT; i++) if(hDlg == chatHandle[i]) { partner = i; break; } switch (message) { case WM_INITDIALOG: Translate(hDlg, DLG_Chat); if(partner<0) { for(i=0; i<MAX_CHAT; i++) if(chatHandle[i] == NULL) { partner = i; break; } chatHandle[partner] = hDlg; snprintf(buf, MSG_SIZ, T_("Chat Window %s"), ics_handle[0] ? ics_handle : first.tidy); SetWindowText(hDlg, buf); } for(i=0; i<MAX_CHAT; i++) if(chatHandle[i]) { if(i == partner) continue; // set our button in other open chats SetDlgItemText(chatHandle[i], IDC_Focus1+partner-(i<partner), chatPartner[partner]); EnableWindow( GetDlgItem(chatHandle[i], IDC_Focus1+partner-(i<partner)), 1 ); // and buttons for other chats in ours SetDlgItemText(hDlg, IDC_Focus1+i-(i>partner), chatPartner[i]); } else EnableWindow( GetDlgItem(hDlg, IDC_Focus1+i-(i>partner)), 0 ); for(i=0; i<MAX_CHAT-1; i++) { Button_SetStyle(GetDlgItem(hDlg, IDC_Focus1+i), BS_PUSHBUTTON|BS_LEFT, TRUE); } x = wpConsole.x; y = wpConsole.y; EnsureOnScreen(&x, &y, 0, 0); SetWindowPos(hDlg, NULL, x, y, 0, 0, SWP_NOZORDER|SWP_NOSIZE); SendMessage( GetDlgItem(hDlg, IDC_ChatPartner), // [HGM] clickbox: initialize with requested handle WM_SETTEXT, 0, (LPARAM) chatPartner[partner] ); filterHasFocus[partner] = TRUE; onTop = partner; // a newly opened box becomes top one if(chatPartner[partner][0]) { filterHasFocus[partner] = FALSE; SetFocus( GetDlgItem(hDlg, OPT_ChatInput) ); } hMemo = GetDlgItem(hDlg, IDC_ChatMemo); wMask = (WORD) SendMessage(hMemo, EM_GETEVENTMASK, 0, 0L); SendMessage(hMemo, EM_SETEVENTMASK, 0, wMask | ENM_LINK); SendMessage(hMemo, EM_AUTOURLDETECT, TRUE, 0L); chatInputWindowProc = (WNDPROC) // cloned from ConsoleWndProc(). Assume they all share same proc. SetWindowLongPtr(GetDlgItem(hDlg, OPT_ChatInput), GWLP_WNDPROC, (LONG_PTR) InterceptArrowKeys); return FALSE; case WM_NOTIFY: if (((NMHDR*)lParam)->code == EN_LINK) { ENLINK *pLink = (ENLINK*)lParam; if (pLink->msg == WM_LBUTTONUP) { TEXTRANGE tr; tr.chrg = pLink->chrg; tr.lpstrText = malloc(1+tr.chrg.cpMax-tr.chrg.cpMin); SendMessage( GetDlgItem(hDlg, IDC_ChatMemo), EM_GETTEXTRANGE, 0, (LPARAM)&tr); ShellExecute(NULL, "open", tr.lpstrText, NULL, NULL, SW_SHOW); free(tr.lpstrText); } } break; case WM_COMMAND: /* [AS] If <Enter> is pressed while editing the filter, it's better to apply the filter rather than selecting the current game. */ if( LOWORD(wParam) == IDC_ChatPartner ) { switch( HIWORD(wParam) ) { case EN_SETFOCUS: filterHasFocus[partner] = TRUE; break; case EN_KILLFOCUS: filterHasFocus[partner] = FALSE; break; } } if( filterHasFocus[partner] && (LOWORD(wParam) == IDC_Send) ) { SetFocus(GetDlgItem(hDlg, OPT_ChatInput)); wParam = IDC_Change; } /* [AS] End command replacement */ switch (LOWORD(wParam)) { case IDCANCEL: /* let Esc key switch focus back to console */ SetFocus(GetDlgItem(hwndConsole, OPT_ConsoleInput)); break; case IDC_Clear: SendMessage( GetDlgItem(hDlg, IDC_ChatMemo), WM_SETTEXT, 0, (LPARAM) "" ); break; case IDC_Change: GetDlgItemText(hDlg, IDC_ChatPartner, chatPartner[partner], MSG_SIZ); for(i=0; i<MAX_CHAT; i++) if(chatHandle[i] && i != partner) { // set our button in other open chats SetDlgItemText(chatHandle[i], IDC_Focus1+partner-(i<partner), chatPartner[partner]); } break; case IDC_Send: GetDlgItemText(hDlg, OPT_ChatInput, mess, MSG_SIZ); SetDlgItemText(hDlg, OPT_ChatInput, ""); // from here on it could be back-end SaveInHistory(mess); if(!strcmp("whispers", chatPartner[partner])) snprintf(buf, MSG_SIZ, "whisper %s\n", mess); // WHISPER box uses "whisper" to send else if(!strcmp("shouts", chatPartner[partner])) snprintf(buf, MSG_SIZ, "shout %s\n", mess); // SHOUT box uses "shout" to send else { if(!atoi(chatPartner[partner])) { snprintf(buf, MSG_SIZ, "> %s\r\n", mess); // echo only tells to handle, not channel InsertIntoMemo(hDlg, buf); snprintf(buf, MSG_SIZ, "xtell %s %s\n", chatPartner[partner], mess); } else snprintf(buf, MSG_SIZ, "tell %s %s\n", chatPartner[partner], mess); } SendToICS(buf); break; case IDC_Focus1: case IDC_Focus2: case IDC_Focus3: case IDC_Focus4: i = LOWORD(wParam) - IDC_Focus1; if(i >= partner) i++; onTop = i; SetFocus(GetDlgItem(hDlg, IDC_Send)); if(chatHandle[i]) { int j; for(j=0; j<MAX_CHAT; j++) if(i != j && chatHandle[j]) Button_SetState(GetDlgItem(chatHandle[j], IDC_Focus1+i-(j<i)), FALSE); SetFocus(GetDlgItem(chatHandle[i], OPT_ChatInput)); } break; default: break; } break; case WM_CLOSE: chatHandle[partner] = 0; chatPartner[partner][0] = 0; ChatPopDown(); for(i=0; i<MAX_CHAT; i++) if(chatHandle[i] && i != partner) { // set our button in other open chats SetDlgItemText(chatHandle[i], IDC_Focus1+partner-(i<partner), ""); EnableWindow( GetDlgItem(chatHandle[i], IDC_Focus1+partner-(i<partner)), 0 ); } EndDialog(hDlg, TRUE); break; case WM_SIZE: ResizeWindowControls( hDlg ); break; case WM_ENTERSIZEMOVE: return OnEnterSizeMove( &sd, hDlg, wParam, lParam ); case WM_SIZING: return OnSizing( &sd, hDlg, wParam, lParam ); case WM_MOVING: return OnMoving( &sd, hDlg, wParam, lParam ); case WM_EXITSIZEMOVE: return OnExitSizeMove( &sd, hDlg, wParam, lParam ); } return FALSE; }
void TextureToolWindow::resetButtonHighlights(void) { for (std::vector<UINT>::iterator it = m_checkableButtonIDs.begin(); it != m_checkableButtonIDs.end(); it++) Button_SetState(GetDlgItem(m_hWnd, (*it)), false); }