//-------------------------------------------------------------- // get cursor X coordinate int mgSimpleField::getCursorX( const mgString& displayStr) { int cursorX = 0; int posn = m_cursorPosn - m_scrollPosn; // if cursor position within displayed text if (posn <= displayStr.length()) { // measure string from scroll position up to cursor cursorX = m_font->stringWidth(displayStr, posn); } else { // measure string from scroll position, plus blanks to cursor position cursorX = m_font->stringWidth(displayStr, displayStr.length()); cursorX += m_font->stringWidth(" ", 1) * (posn - displayStr.length()); } return cursorX; }
//-------------------------------------------------------------- // resolve possibly relative file name. void mgOSResolveRelativeName( const char* sourceFile, const char* relName, mgString& absName) { mgString name(relName); mgOSFixFileName(name); // if relative name starts with /, we're done if (name.startsWith("/")) { absName = name; return; } // assume it's really relative. strip last directory in source file absName = sourceFile; int lastSlash = absName.reverseFind(absName.length(), "/"); if (lastSlash != -1) absName.deleteAt(lastSlash+1, absName.length()-(lastSlash+1)); else absName.empty(); // source file has no dir absName += name; }
//-------------------------------------------------------------- // set slashes appropriately for OS void mgOSFixFileName( mgString& name) { name.trim(); // convert any backslashes to forward slashes mgString bs("/"); char letter[MG_MAX_LETTER]; int posn = 0; while (posn < name.length()) { int next = name.nextLetter(posn, letter); if (strcmp(letter, "\\") == 0) next = name.setLetter(posn, bs); posn = next; } }