//-------------------------------------------------------------- void ofxFileDialog::keyPressedText(int key) { switch(key) { case OF_KEY_UP: case OF_KEY_DOWN: return; case OF_KEY_RIGHT: if(!m_text.empty()) { m_position++; } if(m_position > m_text.size()) { m_position = m_text.size(); } break; case OF_KEY_LEFT: if(m_position > 0) { m_position--; } break; case OF_KEY_DEL: m_text.erase(m_position, 1); break; case OF_KEY_BACKSPACE: if(!m_text.empty() && m_position != 0) { if(m_selection != NONE) { m_text.erase(m_highlightStart, m_highlightEnd - m_highlightStart); m_position -= m_highlightEnd - m_highlightStart; m_selection = NONE; } else { m_text.erase(m_position-1, 1); m_position--; } } break; default: // build multibyte UTF-8 character if(key > 0x80) { if(m_UTF8Bytes == 0) { m_UTF8Bytes = wchar_width(key); } m_UTF8Char.push_back(key); if(m_UTF8Char.length() < m_UTF8Bytes) { return; } } else if(m_UTF8Bytes > 0) { ofLogWarning("ofxFileDialog") << "dropping bad UTF8 bytes"; m_UTF8Bytes = 0; m_UTF8Char = ""; } // ignore control chars if(key != '\n' && key < ' ') { return; } // multibyte UTF8 if(m_UTF8Bytes > 0) { m_UTF8Bytes = 0; } else { // single byte UTF8 & ASCII m_UTF8Char.push_back(key); } m_text.insert(m_position, string_to_wstring(m_UTF8Char)); m_UTF8Char = ""; m_position++; break; } }
void Fl_Device::transformed_draw(const char *str, int n, float x, float y) { SetTextColor(fl_gc, fl_colorref); SelectObject(fl_gc, current_font); #ifdef _WIN32_WCE RECT rect = { int(floor(x+.5f)), int(floor(y+.5f)), 0, 0 }; #else int X = int(floor(x+.5f)); int Y = int(floor(y+.5f)); #endif unsigned ucs; unsigned no_spc; WCHAR buf[128]; // drawing buffer int pos = 0; // position in buffer while(n > 0) { if(pos>120) { #ifdef _WIN32_WCE DrawText(fl_gc, buf, pos, &rect, DT_SINGLELINE | DT_TOP | DT_LEFT | DT_NOCLIP); rect.left += wchar_width(buf, pos); #else TextOutW(fl_gc, X, Y, buf, pos); X += wchar_width(buf, pos); #endif pos = 0; } int ulen = fl_fast_utf2ucs((unsigned char*)str, n, &ucs); if (ulen < 1) ulen = 1; no_spc = fl_nonspacing(ucs); if(no_spc) ucs = no_spc; buf[pos] = ucs; if(no_spc) { #ifdef _WIN32_WCE DrawText(fl_gc, buf, pos, &rect, DT_SINGLELINE | DT_TOP | DT_LEFT | DT_NOCLIP); rect.left += wchar_width(buf, pos); rect.left -= fl_width(buf[pos]); #else TextOutW(fl_gc, X, Y, buf, pos); X += wchar_width(buf, pos); X -= fl_width(buf[pos]); #endif buf[0] = ucs; pos = 0; } pos++; str += ulen; n-=ulen; } if(pos>0) #ifdef _WIN32_WCE DrawText(fl_gc, buf, pos, &rect, DT_SINGLELINE | DT_TOP | DT_LEFT | DT_NOCLIP); #else TextOutW(fl_gc, X, Y, buf, pos); #endif }