void Stack::Clear() { DeleteAllChildren(); while (!m_widgets.empty()) m_widgets.pop(); ResizeRequest(); }
void BrowserClient::OnData() { if (socket->bytesAvailable() == 0) return; QByteArray data = socket->readAll(); QDataStream s(&data, QIODevice::ReadOnly); while (!s.atEnd()) { quint8 typeInt = 0; s >> typeInt; BrowserProtocol::MessageType type = (BrowserProtocol::MessageType)typeInt; switch(type) { case BrowserProtocol::Url: { emit UrlRequest(BrowserProtocol::UrlMessage(s)); break; } case BrowserProtocol::Resize: { emit ResizeRequest(BrowserProtocol::ResizeMessage(s)); break; } case BrowserProtocol::MouseMoveEvent: { emit MouseMoveRequest(BrowserProtocol::MouseMoveMessage(s)); break; } case BrowserProtocol::MouseButtonEvent: { emit MouseButtonRequest(BrowserProtocol::MouseButtonMessage(s)); break; } case BrowserProtocol::KeyboardEvent: { emit KeyboardRequest(BrowserProtocol::KeyboardMessage(s)); break; } case BrowserProtocol::FocusIn: case BrowserProtocol::FocusOut: case BrowserProtocol::Invalidate: case BrowserProtocol::Close: { emit TypedRequest(BrowserProtocol::TypedMessage(type)); break; } case BrowserProtocol::Invalid: return; default: return; } } }
void Stack::Push(Widget *w) { if (!m_widgets.empty()) m_widgets.top()->Hide(); m_widgets.push(w); AppendChild(w,0,0); ResizeRequest(); }
void Stack::Pop() { if (m_widgets.empty()) return; Widget *w = m_widgets.top(); m_widgets.pop(); RemoveChild(w); delete w; ResizeRequest(); }
void TextEntry::SetText(const std::string &text) { m_text = text; SetCursorPos(m_text.size()); int count = 0; for (int i = 0; i < int(text.size()); ++i) { if (text[i] == '\n') ++count; } m_newlineCount = count; ResizeRequest(); }
void OnAxisPick(SDL_JoyAxisEvent *e) { if (e->value > -32767/3 && e->value < 32767/3) return; m_keyUpConnection.disconnect(); Gui::Screen::RemoveBaseWidget(m_infoTooltip); delete m_infoTooltip; m_infoTooltip = 0; m_axisBinding.joystick = e->which; m_axisBinding.axis = e->axis; m_axisBinding.direction = (e->value < 0 ? KeyBindings::NEGATIVE : KeyBindings::POSITIVE); onChange.emit(m_axisBinding); m_keyLabel->SetText(m_axisBinding.Description()); ResizeRequest(); }
void LuaConsole::OnKeyPressed(const SDL_keysym *sym) { // XXX totally horrible doing this on every key press ResizeRequest(); if ((sym->sym == SDLK_UP) || (sym->sym == SDLK_DOWN)) { if (m_historyPosition == -1) { if (sym->sym == SDLK_UP) { m_historyPosition = (m_statementHistory.size() - 1); if (m_historyPosition != -1) { m_stashedStatement = m_entryField->GetText(); m_entryField->SetText(m_statementHistory[m_historyPosition]); ResizeRequest(); } } } else { if (sym->sym == SDLK_DOWN) { ++m_historyPosition; if (m_historyPosition >= int(m_statementHistory.size())) { m_historyPosition = -1; m_entryField->SetText(m_stashedStatement); m_stashedStatement.clear(); ResizeRequest(); } else { m_entryField->SetText(m_statementHistory[m_historyPosition]); ResizeRequest(); } } else { if (m_historyPosition > 0) { --m_historyPosition; m_entryField->SetText(m_statementHistory[m_historyPosition]); ResizeRequest(); } } } } // CTRL+U clears the current command if ((sym->sym == SDLK_u) && (sym->mod & KMOD_CTRL)) { m_stashedStatement.clear(); m_entryField->SetText(""); m_historyPosition = -1; ResizeRequest(); } if (((sym->unicode == '\n') || (sym->unicode == '\r')) && ((sym->mod & KMOD_CTRL) == 0)) { ExecOrContinue(); } }
void Label::RecalcSize() { ResizeRequest(); }
bool TextEntry::OnKeyDown(const SDL_Keysym *sym) { bool accepted = false; bool changed = false; int oldNewlineCount = m_newlineCount; // XXX moving the cursor is not UTF-8 safe if (sym->sym == SDLK_LEFT || sym->sym == SDLK_RIGHT) { bool forward = (sym->sym == SDLK_RIGHT); int direction = (forward) ? 1 : -1; if (!(sym->mod & KMOD_CTRL)) { SetCursorPos(m_cursPos + direction); } else { int inspect_offset = (forward) ? 0 : -1; // When going back, we need the character before the cursor. int ending = (forward) ? m_text.size() : 0; int current = m_cursPos+inspect_offset; bool found_word = false; while(current != ending) { bool alphanum; alphanum = Text::is_alphanumunderscore(m_text[current]); if (found_word && !alphanum) { // Word boundary. current -= inspect_offset; // Make up for the initial offset. break; } current += direction; found_word = found_word || alphanum; // You need to be in a word before finding its boudaries. } SetCursorPos(current); } accepted = true; } // XXX deleting characters is not UTF-8 safe if (sym->sym == SDLK_BACKSPACE) { if (m_cursPos > 0) { if (m_text[m_cursPos-1] == '\n') --m_newlineCount; m_text = m_text.substr(0, m_cursPos-1) + m_text.substr(m_cursPos); SetCursorPos(m_cursPos-1); changed = true; } accepted = true; } if (sym->sym == SDLK_DELETE) { if (m_cursPos < signed(m_text.size())) { if (m_text[m_cursPos] == '\n') --m_newlineCount; m_text = m_text.substr(0, m_cursPos) + m_text.substr(m_cursPos+1); changed = true; } accepted = true; } if (sym->sym == SDLK_HOME) { size_t pos = m_text.rfind('\n', std::max(m_cursPos-1, 0)); if (pos == std::string::npos) pos = 0; else ++pos; m_cursPos = int(pos); accepted = true; } if (sym->sym == SDLK_END) { size_t pos = m_text.find('\n', m_cursPos); if (pos == std::string::npos) pos = m_text.size(); m_cursPos = int(pos); accepted = true; } if (sym->sym == SDLK_RETURN) { switch (m_newlineMode) { case IgnoreNewline: accepted = false; break; case AcceptNewline: accepted = true; break; case AcceptCtrlNewline: accepted = sym->mod & KMOD_CTRL; break; } if (accepted) { ++m_newlineCount; OnTextInput('\n'); } } if (oldNewlineCount != m_newlineCount) ResizeRequest(); onKeyPress.emit(sym); if (changed) onValueChanged.emit(); return accepted; }
void Box::PackEnd(Widget *child) { AppendChild(child, 0, 0); ResizeRequest(); }
void Box::PackStart(Widget *child) { PrependChild(child, 0, 0); ResizeRequest(); }
void Box::Remove(Widget *child) { Container::RemoveChild(child); ResizeRequest(); }
bool TextEntry::OnKeyPress(const SDL_keysym *sym) { bool accepted = onFilterKeys.empty() ? true : onFilterKeys.emit(sym); if (! accepted) return false; accepted = false; bool changed = false; Uint16 unicode = sym->unicode; int oldNewlineCount = m_newlineCount; // XXX moving the cursor is not UTF-8 safe if (sym->sym == SDLK_LEFT) { SetCursorPos(m_cursPos-1); accepted = true; } if (sym->sym == SDLK_RIGHT) { SetCursorPos(m_cursPos+1); accepted = true; } // XXX deleting characters is not UTF-8 safe if (sym->sym == SDLK_BACKSPACE) { if (m_cursPos > 0) { if (m_text[m_cursPos-1] == '\n') --m_newlineCount; m_text = m_text.substr(0, m_cursPos-1) + m_text.substr(m_cursPos); SetCursorPos(m_cursPos-1); changed = true; } accepted = true; } if (sym->sym == SDLK_DELETE) { if (m_cursPos < signed(m_text.size())) { if (m_text[m_cursPos] == '\n') --m_newlineCount; m_text = m_text.substr(0, m_cursPos) + m_text.substr(m_cursPos+1); changed = true; } accepted = true; } if (sym->sym == SDLK_HOME) { size_t pos = m_text.rfind('\n', std::max(m_cursPos-1, 0)); if (pos == std::string::npos) pos = 0; else ++pos; m_cursPos = int(pos); accepted = true; } if (sym->sym == SDLK_END) { size_t pos = m_text.find('\n', m_cursPos); if (pos == std::string::npos) pos = m_text.size(); m_cursPos = int(pos); accepted = true; } if ((unicode == '\n') || (unicode == '\r')) { switch (m_newlineMode) { case IgnoreNewline: unicode = '\0'; break; case AcceptNewline: unicode = '\n'; break; case AcceptCtrlNewline: unicode = (sym->mod & KMOD_CTRL) ? '\n' : '\0'; break; } } if (isgraph(unicode) || (unicode == ' ') || (unicode == '\n')) { if (unicode == '\n') ++m_newlineCount; char buf[4]; int len = conv_wc_to_mb(unicode, buf); m_text.insert(m_cursPos, buf, len); SetCursorPos(m_cursPos+len); changed = true; accepted = true; } if (oldNewlineCount != m_newlineCount) ResizeRequest(); onKeyPress.emit(sym); if (changed) onValueChanged.emit(); return accepted; }
void LuaConsole::ExecOrContinue() { const std::string stmt = m_entryField->GetText(); int result; lua_State *L = Pi::luaManager->GetLuaState(); result = luaL_loadbuffer(L, stmt.c_str(), stmt.size(), "console"); // check for an incomplete statement // (follows logic from the official Lua interpreter lua.c:incomplete()) if (result == LUA_ERRSYNTAX) { const char eofstring[] = LUA_QL("<eof>"); size_t msglen; const char *msg = lua_tolstring(L, -1, &msglen); if (msglen >= (sizeof(eofstring) - 1)) { const char *tail = msg + msglen - (sizeof(eofstring) - 1); if (strcmp(tail, eofstring) == 0) { // statement is incomplete -- allow the user to continue on the next line m_entryField->SetText(stmt + "\n"); m_entryField->ResizeRequest(); ResizeRequest(); lua_pop(L, 1); return; } } } if (result == LUA_ERRSYNTAX) { size_t msglen; const char *msg = lua_tolstring(L, -1, &msglen); AddOutput(std::string(msg, msglen)); lua_pop(L, 1); return; } if (result == LUA_ERRMEM) { // this will probably fail too, since we've apparently // just had a memory allocation failure... AddOutput("memory allocation failure"); return; } // perform a protected call int top = lua_gettop(L) - 1; // -1 for the chunk itself result = lua_pcall(L, 0, LUA_MULTRET, 0); if (result == LUA_ERRRUN) { size_t len; const char *s = lua_tolstring(L, -1, &len); AddOutput(std::string(s, len)); } else if (result == LUA_ERRERR) { size_t len; const char *s = lua_tolstring(L, -1, &len); AddOutput("error in error handler: " + std::string(s, len)); } else if (result == LUA_ERRMEM) { AddOutput("memory allocation failure"); } else { int nresults = lua_gettop(L) - top; if (nresults) { std::ostringstream ss; // call tostring() on each value and display it lua_getglobal(L, "tostring"); // i starts at 1 because Lua stack uses 1-based indexing for (int i = 1; i <= nresults; ++i) { ss.str(std::string()); if (nresults > 1) ss << "[" << i << "] "; // duplicate the tostring function for the call lua_pushvalue(L, -1); lua_pushvalue(L, top+i); result = lua_pcall(L, 1, 1, 0); size_t len = 0; const char *s = 0; if (result == 0) s = lua_tolstring(L, -1, &len); ss << s ? std::string(s, len) : "<internal error when converting result to string>"; // pop the result lua_pop(L, 1); AddOutput(ss.str()); } } } // pop all return values lua_settop(L, top); // update the history list if (! result) { // command succeeded... add it to the history unless it's just // an exact repeat of the immediate last command if (m_statementHistory.empty() || (stmt != m_statementHistory.back())) m_statementHistory.push_back(stmt); // clear the entry box m_entryField->SetText(""); ResizeRequest(); } // always forget the history position and clear the stashed command m_historyPosition = -1; m_stashedStatement.clear(); }
void Label::RecalcSize() { // float size[2]; // Screen::MeasureLayout(m_text, FLT_MAX, size); ResizeRequest(); }
void LuaConsole::OnKeyPressed(const SDL_keysym *sym) { // XXX totally horrible doing this on every key press ResizeRequest(); if ((sym->sym == SDLK_UP) || (sym->sym == SDLK_DOWN)) { if (m_historyPosition == -1) { if (sym->sym == SDLK_UP) { m_historyPosition = (m_statementHistory.size() - 1); if (m_historyPosition != -1) { m_stashedStatement = m_entryField->GetText(); m_entryField->SetText(m_statementHistory[m_historyPosition]); ResizeRequest(); } } } else { if (sym->sym == SDLK_DOWN) { ++m_historyPosition; if (m_historyPosition >= int(m_statementHistory.size())) { m_historyPosition = -1; m_entryField->SetText(m_stashedStatement); m_stashedStatement.clear(); ResizeRequest(); } else { m_entryField->SetText(m_statementHistory[m_historyPosition]); ResizeRequest(); } } else { if (m_historyPosition > 0) { --m_historyPosition; m_entryField->SetText(m_statementHistory[m_historyPosition]); ResizeRequest(); } } } } // CTRL+U clears the current command if ((sym->sym == SDLK_u) && (sym->mod & KMOD_CTRL)) { m_stashedStatement.clear(); m_entryField->SetText(""); m_historyPosition = -1; ResizeRequest(); } if (sym->sym == SDLK_TAB) { if (m_completionList.empty()) { UpdateCompletion(m_entryField->GetText()); } if (!m_completionList.empty()) { // We still need to test whether it failed or not. if (sym->mod & KMOD_SHIFT) { if (m_currentCompletion == 0) m_currentCompletion = m_completionList.size(); m_currentCompletion--; } else { m_currentCompletion++; if (m_currentCompletion == m_completionList.size()) m_currentCompletion = 0; } m_entryField->SetText(m_precompletionStatement + m_completionList[m_currentCompletion]); ResizeRequest(); } } else if (!m_completionList.empty() && (sym->sym < SDLK_NUMLOCK || sym->sym > SDLK_COMPOSE)) { m_completionList.clear(); } if (((sym->unicode == '\n') || (sym->unicode == '\r')) && ((sym->mod & KMOD_CTRL) == 0)) { ExecOrContinue(); } }
void Close() { onChange.emit(m_binding); m_keyLabel->SetText(m_binding.Description()); ResizeRequest(); }