예제 #1
0
	void TextField::positionCaret( int position, bool surpressNegChange)
	{
		bool negChange = false;
		if(position > getTextLength())
		{
			position = getTextLength();
		}
		if(position < 0)
		{
			position = 0;
		}
		if(position < caretPosition && !surpressNegChange)
		{
			negChange = true;
		}
		caretPosition = position;

		scrollToCaret(negChange,true);
		relocateCaret();

		//because circular dependencies
		//are the new recursion!
		scrollToCaret(negChange,true);
		relocateCaret();
	}
예제 #2
0
static void drawText(float x, float y, const char *text, int align, unsigned int col)
{
	if (!g_ftex) return;
	if (!text) return;

	if (align == IMGUI_ALIGN_CENTER)
		x -= getTextLength(g_cdata, text)/2;
	else if (align == IMGUI_ALIGN_RIGHT)
		x -= getTextLength(g_cdata, text);

	glColor4ub(col&0xff, (col>>8)&0xff, (col>>16)&0xff, (col>>24)&0xff);

	glEnable(GL_TEXTURE_2D);

	// assume orthographic projection with units = screen pixels, origin at top left
	glBindTexture(GL_TEXTURE_2D, g_ftex);

	glBegin(GL_TRIANGLES);

	const float ox = x;

	while (*text)
	{
		int c = (unsigned char)*text;
		if (c == '\t')
		{
			for (int i = 0; i < 4; ++i)
			{
				if (x < g_tabStops[i]+ox)
				{
					x = g_tabStops[i]+ox;
					break;
				}
			}
		}
		else if (c >= 32 && c < 128)
		{
			stbtt_aligned_quad q;
			getBakedQuad(g_cdata, 512,512, c-32, &x,&y,&q);

			glTexCoord2f(q.s0, q.t0);
			glVertex2f(q.x0, q.y0);
			glTexCoord2f(q.s1, q.t1);
			glVertex2f(q.x1, q.y1);
			glTexCoord2f(q.s1, q.t0);
			glVertex2f(q.x1, q.y0);

			glTexCoord2f(q.s0, q.t0);
			glVertex2f(q.x0, q.y0);
			glTexCoord2f(q.s0, q.t1);
			glVertex2f(q.x0, q.y1);
			glTexCoord2f(q.s1, q.t1);
			glVertex2f(q.x1, q.y1);
		}
		++text;
	}

	glEnd();
	glDisable(GL_TEXTURE_2D);
}
예제 #3
0
void Entry::onSetText()
{
  Widget::onSetText();

  if (m_caret >= 0 && (size_t)m_caret > getTextLength())
    m_caret = (int)getTextLength();
}
예제 #4
0
void Numkey::append(char* c){
	byte cSize = getTextLength(c);
	byte txtSize = getTextLength(text);//getTextSize();
	byte space = DISPLAY_SIZE - txtSize;
	
	//Check that there space available to append
	if(txtSize < DISPLAY_SIZE){
		//Serial.print("Space available: ");Serial.println(space);
		for(int i=0; i<space; i++)
		{
			text[i+txtSize] = c[i];
		}
	}
	update();
}
예제 #5
0
	void TextField::addToNextCharacter( int unichar )
	{
		if(getTextLength() + 1 > getMaxLength())
		{
			return;
		}

		char buffer[8];
		for(int i = 0; i < 8; ++i)
		{
			buffer[i] = 0;
		}

		unicodeFunctions.encodeUtf8(buffer,unichar);
		std::string appendStr = buffer;
		
		std::string text;
		if(!isPassword())
			text = getText();
		else
			text = getPassword();

		unicodeFunctions.insert(text,getCaretPosition(),buffer);

		setThisText(text);
		positionCaret(getCaretPosition() + 1);

	}
예제 #6
0
파일: brltty.c 프로젝트: MarkMielke/brltty
int
writeBrailleText (const char *mode, const char *text) {
  size_t count = getTextLength(text) + 1;
  wchar_t characters[count];
  size_t length = convertTextToWchars(characters, text, count);
  return writeBrailleCharacters(mode, characters, length);
}
예제 #7
0
	void TextField::selectAll()
	{
		
		setSelection(-1,-1);
		caretPosition = getTextLength();
		relocateCaret();
	}
예제 #8
0
파일: editor.cpp 프로젝트: Soulflare3/ilua
void Editor::addLogMessage(char const* text, uint64 timestamp, uint32 type)
{
  int len = getTextLength();
  POINT ptCaret = toPoint(caret);
  POINT ptSelStart = toPoint(selStart);
  if (lines.length() == 1 && lines[0].timestamp == 0)
    lines.pop();
  else if (lines.length() > 1024)
  {
    lines.remove(0, 1);
    ptCaret.y--;
    ptSelStart.y--;
  }
  int pos = 0;
  while (true)
  {
    if (text[pos] == '\r' || text[pos] == '\n' || text[pos] == 0)
    {
      Line& ln = lines.push();
      ln.text = WideString(text, pos);
      for (int i = 0; i < ln.text.length(); i++)
        if (ln.text[i] == '\t')
          ln.text.replace(i, 1, WideString(" ") * (settings->tabSize - (i % settings->tabSize)));
      ln.ctx = type;
      ln.timestamp = timestamp;
      if (text[pos] == 0)
        break;
      pos++;
      if ((text[pos] == '\r' || text[pos] == '\n') && text[pos - 1] != text[pos])
        pos++;
      text += pos;
      pos = 0;
    }
    else
      pos++;
  }
  if (selStart == caret && caret == len)
    selStart = caret = getTextLength();
  else
  {
    caret = fromPoint(ptCaret);
    selStart = fromPoint(ptSelStart);
  }
  updateExtent();
  updateCaret();
}
예제 #9
0
	void TextField::paste()
	{
		if(isReadOnly())
		{
			return;
		}


		std::string pasteResult = Clipboard::paste();

		if(pasteResult.length() == 0 || getTextLength() - getSelectionLength() == getMaxLength())
		{
			return;
		}

		deleteSelection();
		int start = getCaretPosition();
		
		std::string noNewLine;

		for(size_t i = 0; i < pasteResult.size(); ++i)
		{
			if(pasteResult[i] != '\n')
			{
				noNewLine += pasteResult[i];
			}
		}

		int length = int(unicodeFunctions.length(noNewLine));
		int numRemainingChar = getMaxLength() - getTextLength();
		if(numRemainingChar < length)
		{
			noNewLine = unicodeFunctions.subStr(noNewLine,0,numRemainingChar);
			length = numRemainingChar;
		}
		if(length > 0)
		{
			std::string* cText = (std::string*)&getText();
			unicodeFunctions.insert(*cText,start,noNewLine);
			setThisText(*cText);
			positionCaret(caretPosition + length);
		}
	}
예제 #10
0
	void TextField::setText( const std::string &text )
	{
		//truncate string if it is too long
		if(isPassword())
		{
			
			int len = int(unicodeFunctions.length(text));
			int subLen = len;
			if( len > getMaxLength())
			{
				subLen = maxLength;
			}
			passText = "";
			for(int i = 0; i < subLen ; ++i)
			{
				passText += passwordChar;
			}
		

			if(getMaxLength() < len)
			{
				passwordText = unicodeFunctions.subStr(text,0,getMaxLength());
			}
			else
			{
				passwordText = text;
			}

				Widget::setText(passText);
		}
		else
		{
			if(getMaxLength() < (int) unicodeFunctions.length(text))
			{
				Widget::setText(unicodeFunctions.subStr(text,0,getMaxLength()));
			}
			else
			{
				Widget::setText(text);
			}
		}
	
		

		
		if(!selfSetText)
		{
			positionCaret(getTextLength());
			
		}

		setSelection(0,0);
	}
예제 #11
0
	void TextField::appendText( const std::string& text, bool atCurrentPosition /*= true*/ )
	{
		if(text.length() == 0 || getTextLength() - getSelectionLength() == getMaxLength())
		{
			return;
		}

		deleteSelection();
		if(!atCurrentPosition)
		{
			positionCaret(getTextLength());
		}
		int start = getCaretPosition();

		std::string noNewLine;

		for(size_t i = 0; i < text.size(); ++i)
		{
			if(text[i] != '\n')
			{
				noNewLine += text[i];
			}
		}

		int length = int(unicodeFunctions.length(noNewLine));
		int numRemainingChar = getMaxLength() - getTextLength();
		if(numRemainingChar < length)
		{
			noNewLine = unicodeFunctions.subStr(noNewLine,0,numRemainingChar);
			length = numRemainingChar;
		}
		if(length > 0)
		{
			std::string* cText = (std::string*)&getText();
			unicodeFunctions.insert(*cText,start,noNewLine);
			setThisText(*cText);
			positionCaret(caretPosition + length);
		}
	}
예제 #12
0
void Numkey::appendNum(unsigned char c){
	//Serial.print("Append num ");Serial.println((byte)c);

	if(c > 9){ 
		//Serial.print("Not a number");Serial.write(c);
		return; //Exit if c is not a number 0 - 9
	}
	byte txtSize = getTextLength(text);//getTextSize();
	byte space = DISPLAY_SIZE - txtSize;
	//Check that there space available to append
	if(txtSize < DISPLAY_SIZE){
		text[txtSize] = c + 48;
		text[txtSize + 1] = 0;
		update();
	}
}
예제 #13
0
파일: font.cpp 프로젝트: Backson/3dgamecpp
void Font::writeLine(float x, float y, float z, const char *text, int count, Alignment alignment) {
	if (count <= 0)
		count = getTextLength(text);

	if (alignment == Alignment::CENTER) {
		float w = getTextWidth(text, count);
		x -= w / 2;
	} else if (alignment == Alignment::RIGHT) {
		float w = getTextWidth(text, count);
		x -= w;
	}

	beginRender();
	writeInternal(x, y, z, text, count);
	endRender();
}
예제 #14
0
	void TextField::removeNextCharacter()
	{
		//don't try to remove past the end
		if(getCaretPosition() + 1 > getTextLength())
		{
			return;
		}
		std::string text;
		if(!isPassword())
			text = getText();
		else
			text = getPassword();

		unicodeFunctions.erase(text,getCaretPosition(),1);

		setThisText(text);
		positionCaret(getCaretPosition());
	}
예제 #15
0
파일: font.cpp 프로젝트: Backson/3dgamecpp
void Font::write(float x, float y, float z, const char *text, int count, Alignment alignment) {
	if (count <= 0)
		count = getTextLength(text);

	// Get first line
	int pos = 0;
	int len = findTextChar(text, pos, count, '\n');
	if (len == -1) len = count;
	beginRender();
	while (pos < count) {
		float cx = x;
		if (alignment == Alignment::CENTER) {
			float w = getTextWidth(&text[pos], len);
			cx -= w / 2;
		} else if (alignment == Alignment::RIGHT) {
			float w = getTextWidth(&text[pos], len);
			cx -= w;
		}

		writeInternal(cx, y, z, &text[pos], len);

		y -= getLineHeight();

		// Get next line
		pos += len;
		int ch = getTextChar(text, pos, &pos);
		if (ch == '\n') {
			len = findTextChar(text, pos, count, '\n');
			if (len == -1)
				len = count - pos;
			else
				len = len - pos;
		}
	}
	endRender();
}
예제 #16
0
파일: RenderGL3.cpp 프로젝트: kdridi/box2d
void sRenderString(float x, float y, const char *text, TextAlign align, unsigned int col)
{
	if (!g_ftex) return;
	if (!text) return;

	if (align == TEXT_ALIGN_CENTER)
		x -= getTextLength(g_cdata, text) / 2;
	else if (align == TEXT_ALIGN_RIGHT)
		x -= getTextLength(g_cdata, text);

	float r = (float)(col & 0xff) / 255.f;
	float g = (float)((col >> 8) & 0xff) / 255.f;
	float b = (float)((col >> 16) & 0xff) / 255.f;
	float a = (float)((col >> 24) & 0xff) / 255.f;

	// assume orthographic projection with units = screen pixels, origin at top left
	glBindTexture(GL_TEXTURE_2D, g_ftex);

	const float ox = x;

	while (*text)
	{
		int c = (unsigned char)*text;
		if (c == '\t')
		{
			for (int i = 0; i < 4; ++i)
			{
				if (x < g_tabStops[i] + ox)
				{
					x = g_tabStops[i] + ox;
					break;
				}
			}
		}
		else if (c >= 32 && c < 128)
		{
			stbtt_aligned_quad q;
			getBakedQuad(g_cdata, 512, 512, c - 32, &x, &y, &q);

			float v[12] = {
				q.x0, q.y0,
				q.x1, q.y1,
				q.x1, q.y0,
				q.x0, q.y0,
				q.x0, q.y1,
				q.x1, q.y1,
			};
			float uv[12] = {
				q.s0, q.t0,
				q.s1, q.t1,
				q.s1, q.t0,
				q.s0, q.t0,
				q.s0, q.t1,
				q.s1, q.t1,
			};
			float c[24] = {
				r, g, b, a,
				r, g, b, a,
				r, g, b, a,
				r, g, b, a,
				r, g, b, a,
				r, g, b, a,
			};
			glBindVertexArray(g_vao);
			glBindBuffer(GL_ARRAY_BUFFER, g_vbos[0]);
			glBufferData(GL_ARRAY_BUFFER, 12 * sizeof(float), v, GL_STATIC_DRAW);
			glBindBuffer(GL_ARRAY_BUFFER, g_vbos[1]);
			glBufferData(GL_ARRAY_BUFFER, 12 * sizeof(float), uv, GL_STATIC_DRAW);
			glBindBuffer(GL_ARRAY_BUFFER, g_vbos[2]);
			glBufferData(GL_ARRAY_BUFFER, 24 * sizeof(float), c, GL_STATIC_DRAW);
			glDrawArrays(GL_TRIANGLES, 0, 6);

		}
		++text;
	}

	//glEnd();        
	//glDisable(GL_TEXTURE_2D);
}
// -----------------------------------------------------------------------
// getSelectTextLength:
// -----------------------------------------------------------------------
const Lng32 
CatApiRequest::getSelectTextLength( void ) const
{
  return getTextLength() + selectTextWrapperLength;
}
예제 #18
0
byte Numkey::getTextSize(){
  return getTextLength(text);
}
예제 #19
0
	void TextField::scrollToCaret(bool negetiveChange, bool reposition)
	{
		int retOffset = getLeftPadding();
		
		int textWidth = getFont()->getTextWidth(getText());
		if(textWidth < getAdjustedWidth())
		{
			switch(getTextAlignment())
			{
			case ALIGN_LEFT:
				alignOffset = 0;
				break;
			case ALIGN_CENTER:
				alignOffset = (getAdjustedWidth() - textWidth) / 2;
				break;
			case ALIGN_RIGHT:
				alignOffset = getAdjustedWidth() - textWidth;
				break;
			default:
				break;
			}
			
		}
		else
		{
			alignOffset = 0;
		}

		if(getTextLength() == 0 || getCaretPosition() == 0)
		{
			tOffset = retOffset;
			setTextOffset(retOffset + alignOffset);
			return;
		}

		if(reposition)
		{
			//do we need to move?
			if(getFont()->getTextWidth(unicodeFunctions.subStr(getText(),
				0,getCaretPosition())) > -tOffset + getAdjustedWidth() + getLeftPadding()
				
				)
			{

				//scroll to end
				if(getTextLength() < getCaretPosition() + getMaxCharacterSkip())
				{

					retOffset -= solveCaretRetPos(getFont()->getTextWidth(getText())
						- getAdjustedWidth(),
						retOffset);
				}
				else
				{
					int initialPlace = getFont()->getTextWidth(unicodeFunctions.subStr(getText(),
						0, getCaretPosition() + getMaxCharacterSkip() )) - getAdjustedWidth();
					retOffset -= solveCaretRetPos(initialPlace,retOffset);
					
				}



				tOffset = retOffset;
				setTextOffset(retOffset + alignOffset);
				return;

			}
			else if(tOffset + getFont()->getTextWidth(unicodeFunctions.subStr(getText(),
				0,getCaretPosition())) <= leftPadding)
			{

				if(getCaretPosition() - getMaxCharacterSkip() > 0)
				{
					int initialPlace = getFont()->getTextWidth(unicodeFunctions.subStr(getText(),
						0, getCaretPosition() - getMaxCharacterSkip() ));
					retOffset -= solveCaretRetPos(initialPlace,retOffset);

				}

				tOffset = retOffset;
				setTextOffset(retOffset + alignOffset);
				return;
			}
			else if(negetiveChange )
			{

				int change = getCaretLocation() - getFont()->getTextWidth(unicodeFunctions.subStr(getText(),
					0, getCaretPosition() )) ;
				if(change <= getLeftPadding())
				{
					
					tOffset = change;
					setTextOffset(change);
				}
				else
				{
					tOffset = leftPadding;
					setTextOffset(leftPadding + alignOffset);
				}
				return;
			}
		}

		//if there is more text than width
		//but theres not enough to fill the width
		//then fill the width


			int a = getAdjustedWidth() + getLeftPadding();
			int b = getTextOffset() + textWidth;

			if(a > b && getTextOffset() < getLeftPadding())
			{
				retOffset = -textWidth + getInnerSize().getWidth() - getRightPadding(); 

				tOffset = retOffset;

			}
			else if(getTextOffset() >= getLeftPadding() )
			{

				tOffset = leftPadding;
				setTextOffset(leftPadding + alignOffset);
				return;
			}

		setTextOffset(tOffset + alignOffset);

	}
예제 #20
0
파일: font.cpp 프로젝트: Backson/3dgamecpp
void Font::writeBox(float x, float y, float z, float width, const char *text, int count, Alignment alignment) {
	if (count <= 0)
		count = getTextLength(text);

	float currWidth = 0, wordWidth;
	int lineS = 0, lineE = 0, wordS = 0, wordE = 0;
	int wordCount = 0;

	const char *s = " ";
	float spaceWidth = getTextWidth(s, 1);
	bool softBreak = false;

	beginRender();
	for (; lineS < count;) {
		// Determine the extent of the line
		for (;;) {
			// Determine the number of characters in the word
			while (wordE < count &&
				getTextChar(text, wordE) != ' ' &&
				getTextChar(text, wordE) != '\n')
				// Advance the cursor to the next character
				getTextChar(text, wordE, &wordE);

			// Determine the width of the word
			if (wordE > wordS) {
				wordCount++;
				wordWidth = getTextWidth(&text[wordS], wordE - wordS);
			} else
				wordWidth = 0;

			// Does the word fit on the line? The first word is always accepted.
			if (wordCount == 1 || currWidth + (wordCount > 1 ? spaceWidth : 0) + wordWidth <= width) {
				// Increase the line extent to the end of the word
				lineE = wordE;
				currWidth += (wordCount > 1 ? spaceWidth : 0) + wordWidth;

				// Did we reach the end of the line?
				if (wordE == count || getTextChar(text, wordE) == '\n') {
					softBreak = false;

					// Skip the newline character
					if (wordE < count)
						// Advance the cursor to the next character
						getTextChar(text, wordE, &wordE);

					break;
				}

				// Skip the trailing space
				if (wordE < count && getTextChar(text, wordE) == ' ')
					// Advance the cursor to the next character
					getTextChar(text, wordE, &wordE);

				// Move to next word
				wordS = wordE;
			} else {
				softBreak = true;

				// Skip the trailing space
				if (wordE < count && getTextChar(text, wordE) == ' ')
					// Advance the cursor to the next character
					getTextChar(text, wordE, &wordE);

				break;
			}
		}

		// Write the line
		if (alignment == Alignment::JUSTIFY) {
			float spacing = 0;
			if (softBreak) {
				if (wordCount > 2)
					spacing = (width - currWidth) / (wordCount - 2);
				else
					spacing = (width - currWidth);
			}

			writeInternal(x, y, z, &text[lineS], lineE - lineS, spacing);
		} else {
			float cx = x;
			if (alignment == Alignment::RIGHT)
				cx = x + width - currWidth;
			else if (alignment == Alignment::CENTER)
				cx = x + 0.5f*(width - currWidth);

			writeInternal(cx, y, z, &text[lineS], lineE - lineS);
		}

		if (softBreak) {
			// Skip the trailing space
			if (lineE < count && getTextChar(text, lineE) == ' ')
				// Advance the cursor to the next character
				getTextChar(text, lineE, &lineE);

			// We've already counted the first word on the next line
			currWidth = wordWidth;
			wordCount = 1;
		} else {
			// Skip the line break
			if (lineE < count && getTextChar(text, lineE) == '\n')
				// Advance the cursor to the next character
				getTextChar(text, lineE, &lineE);

			currWidth = 0;
			wordCount = 0;
		}

		// Move to next line
		lineS = lineE;
		wordS = wordE;
		y -= getLineHeight();
	}
	endRender();
}
예제 #21
0
파일: editor.cpp 프로젝트: Soulflare3/ilua
uint32 Editor::onMessage(uint32 message, uint32 wParam, uint32 lParam)
{
  switch (message)
  {
  case WM_DESTROY:
    delete target;
    target = NULL;
    break;
  case WM_SETCURSOR:
    if (LOWORD(lParam) == HTCLIENT)
    {
      POINT pt;
      GetCursorPos(&pt);
      ScreenToClient(hWnd, &pt);
      if (pt.x < LeftMargin())
        SetCursor(cursors[cArrow]);
      else if (selStart != caret)
      {
        pt.x = (pt.x - LeftMargin()) / chSize.cx + scrollPos.x;
        pt.y = pt.y / chSize.cy + scrollPos.y;
        if (pt.y < 0 || pt.y >= lines.length() || pt.x < 0 || pt.x >= lines[pt.y].text.length())
          SetCursor(cursors[cBeam]);
        else
        {
          int offset = fromPoint(pt);
          int sela = (selStart < caret ? selStart : caret);
          int selb = (selStart < caret ? caret : selStart);
          if (offset >= sela && offset < selb)
            SetCursor(cursors[cArrow]);
          else
            SetCursor(cursors[cBeam]);
        }
      }
      else
        SetCursor(cursors[cBeam]);
    }
    else
      SetCursor(cursors[cArrow]);
    return TRUE;
  case WM_ERASEBKGND:
    return TRUE;
  case WM_PAINT:
    paint();
    return 0;
  case WM_SIZE:
    if (hBitmap)
    {
      int wd = LOWORD(lParam);
      int ht = HIWORD(lParam);
      if (wd < 10) wd = 10;
      if (ht < 10) ht = 10;
      hBitmap = CreateCompatibleBitmap(hDC, wd, ht);
      SelectObject(hDC, hBitmap);
    }
    updateExtent();
    return 0;
  case WM_SETFOCUS:
    placeCaret();
    invalidate();
    getParent()->notify(EN_FOCUSED, (uint32) this, 0);
    return 0;
  case WM_KILLFOCUS:
    DestroyCaret();
    updateCaret();
    invalidate();
    return 0;
  case WM_LBUTTONDBLCLK:
    {
      POINT pt = paramToPoint(lParam);
      fixPoint(pt);
      int ptStart = wordEnd(lines[pt.y].text.c_str(), pt.x, -1);
      int ptEnd = wordEnd(lines[pt.y].text.c_str(), pt.x, 1);
      int offset = fromPoint(pt);
      selStart = offset - (pt.x - ptStart);
      caret = offset + (ptEnd - pt.x);
      updateCaret();
    }
    return 0;
  case WM_LBUTTONDOWN:
    if (int(GET_X_LPARAM(lParam)) < int(settings->bpOffset - scrollPos.x * chSize.cx))
    {
      POINT pt = paramToPoint(lParam);
      toggleBreakpoint(pt.y);
    }
    else
    {
      POINT pt = paramToPoint(lParam);
      int offset = fromPoint(pt);
      int sela = (selStart < caret ? selStart : caret);
      int selb = (selStart > caret ? selStart : caret);
      if (offset >= sela && offset < selb)
      {
        dragop = 1;
        uint32 fx = DoDragDropEx(CF_UNICODETEXT, CreateGlobalText(getSelection()),
            DROPEFFECT_MOVE | DROPEFFECT_COPY, hWnd);
        if (fx == DROPEFFECT_NONE)
          dragop = 0;
        //else if (fx != DROPEFFECT_COPY && dragop != 2)
        //  replace(sela, selb, "");
      }
      else
        SetCapture(hWnd);
      if (dragop == 0)
      {
        caret = offset;
        if (!(wParam & MK_SHIFT))
          selStart = caret;
      }
      dragop = 0;
      if (GetFocus() != hWnd)
        SetFocus(hWnd);
      updateCaret();
    }
    return 0;
  case WM_RBUTTONDOWN:
    if (int(GET_X_LPARAM(lParam)) >= int(settings->bpOffset - scrollPos.x * chSize.cx))
    {
      POINT pt = paramToPoint(lParam);
      int offset = fromPoint(pt);
      int sela = (selStart < caret ? selStart : caret);
      int selb = (selStart > caret ? selStart : caret);
      if (offset < sela || offset >= selb)
        caret = selStart = offset;
      if (GetFocus() != hWnd)
        SetFocus(hWnd);
      updateCaret();
    }
    return 0;
  case WM_MOUSEMOVE:
    if (GetCapture() == hWnd && (wParam & MK_LBUTTON))
    {
      POINT pt = paramToPoint(lParam);
      caret = fromPoint(pt);
      updateCaret();
    }
    return 0;
  case WM_LBUTTONUP:
    ReleaseCapture();
    return 0;
  case WM_CHAR:
    if (iswprint(wParam) && (GetAsyncKeyState(VK_CONTROL) & 0x8000) == 0)
    {
      if (caret == selStart && !insertMode && caret < getTextLength())
        replace(caret, caret + 1, WideString((wchar_t) wParam));
      else
        replace(selStart, caret, WideString((wchar_t) wParam));
    }
    return 0;
  case WM_VSCROLL:
    {
      SCROLLINFO si;
      memset(&si, 0, sizeof si);
      si.cbSize = sizeof si;
      si.fMask = SIF_ALL;
      GetScrollInfo(hWnd, SB_VERT, &si);
      switch (LOWORD(wParam))
      {
      case SB_TOP:
        si.nPos = si.nMin;
        break;
      case SB_BOTTOM:
        si.nPos = si.nMax;
        break;
      case SB_LINEUP:
        si.nPos--;
        break;
      case SB_LINEDOWN:
        si.nPos++;
        break;
      case SB_PAGEUP:
        si.nPos -= si.nPage;
        break;
      case SB_PAGEDOWN:
        si.nPos += si.nPage;
        break;
      case SB_THUMBTRACK:
        si.nPos = si.nTrackPos;
        break;
      }
      doScroll(scrollPos.x, si.nPos);
    }
    return 0;
  case WM_HSCROLL:
    {
      SCROLLINFO si;
      memset(&si, 0, sizeof si);
      si.cbSize = sizeof si;
      si.fMask = SIF_ALL;
      GetScrollInfo(hWnd, SB_HORZ, &si);
      switch (LOWORD(wParam))
      {
      case SB_LEFT:
        si.nPos = si.nMin;
        break;
      case SB_RIGHT:
        si.nPos = si.nMax;
        break;
      case SB_LINELEFT:
        si.nPos--;
        break;
      case SB_LINERIGHT:
        si.nPos++;
        break;
      case SB_PAGELEFT:
        si.nPos -= si.nPage;
        break;
      case SB_PAGERIGHT:
        si.nPos += si.nPage;
        break;
      case SB_THUMBTRACK:
        si.nPos = si.nTrackPos;
        break;
      }
      doScroll(si.nPos, scrollPos.y);
    }
    return 0;
  case WM_MOUSEWHEEL:
    {
      int step;
      SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &step, 0);
      if (step < 0)
        step = 3;
      scrollAccum.y += GET_WHEEL_DELTA_WPARAM(wParam) * step;
      doScroll(scrollPos.x, scrollPos.y - scrollAccum.y / WHEEL_DELTA);
      scrollAccum.y %= WHEEL_DELTA;
    }
    return 0;
  case WM_MOUSEHWHEEL:
    {
      scrollAccum.x += GET_WHEEL_DELTA_WPARAM(wParam) * 4;
      doScroll(scrollPos.x + scrollAccum.x / WHEEL_DELTA, scrollPos.y);
      scrollAccum.x %= WHEEL_DELTA;
    }
    return 0;
  case WM_DRAGOVER:
    {
      if (running || settings->mode)
        return TRUE;
      POINT pt = paramToPoint(lParam);
      dropPos = fromPoint(pt);

      RECT rc;
      GetClientRect(hWnd, &rc);
      int xto = scrollPos.x;
      if (pt.x < 10)
        xto--;
      else if (pt.x > rc.right - 10)
        xto++;
      int yto = scrollPos.y;
      if (pt.y < 10)
        yto--;
      else if (pt.y > rc.bottom - 10)
        yto++;
      doScroll(xto, yto);

      int sela = (selStart < caret ? selStart : caret);
      int selb = (selStart > caret ? selStart : caret);
      if (dropPos > sela && dropPos < selb)
        return TRUE;
      else
      {
        fixPoint(pt);
        CreateCaret(hWnd, NULL, 2, chSize.cy);
        SetCaretPos((pt.x - scrollPos.x) * chSize.cx + LeftMargin(), (pt.y - scrollPos.y) * chSize.cy);
        ShowCaret(hWnd);
      }
    }
    return 0;
  case WM_DRAGLEAVE:
    dropPos = 0;
    updateCaret();
    return 0;
  case WM_DRAGDROP:
    if (running || settings->mode)
      return DROPEFFECT_NONE;
    if (dragop)
    {
      dragop = 2;
      int sela = (selStart < caret ? selStart : caret);
      int selb = (selStart > caret ? selStart : caret);
      if (dropPos < sela || dropPos > selb)
      {
        WideString text = getSelection();
        if (lParam != DROPEFFECT_COPY)
        {
          replace(sela, selb, L"");
          if (dropPos > selb)
            dropPos -= (selb - sela);
          caret = replace(dropPos, dropPos, text, NULL, true);
        }
        else
          caret = replace(dropPos, dropPos, text);
        selStart = dropPos;
      }
    }
    else
    {
      caret = replace(dropPos, dropPos, GetGlobalTextWide((HGLOBAL) wParam));
      selStart = dropPos;
      return DROPEFFECT_COPY;
    }
    return lParam;
  case WM_SYSKEYDOWN:
  case WM_KEYDOWN:
    onKey(wParam);
    return 0;
  case WM_COMMAND:
    switch (LOWORD(wParam))
    {
    case ID_EDIT_UNDO:
      {
        bool glue = true;
        bool first = true;
        while (glue && historyPos > 0)
        {
          HistoryItem& h = history[--historyPos];
          replace(h.begin, h.end, h.text, &h);
          glue = h.glue;
          h.glue = !first;
          first = false;
        }
      }
      break;
    case ID_EDIT_REDO:
      {
        bool glue = true;
        bool first = true;
        while (glue && historyPos < history.length())
        {
          HistoryItem& h = history[historyPos++];
          replace(h.begin, h.end, h.text, &h);
          glue = h.glue;
          h.glue = !first;
          first = false;
        }
      }
      break;
    case ID_EDIT_SELECTALL:
      selStart = 0;
      caret = getTextLength();
      updateCaret();
      break;
    case ID_EDIT_COPY:
      if (caret != selStart)
        SetClipboard(CF_UNICODETEXT, CreateGlobalText(getSelection()));
      else
      {
        POINT pt = toPoint(caret);
        pt.x = 0;
        int start = fromPoint(pt);
        if (pt.y < lines.length() - 1)
          pt.y++;
        else
          pt.x = lines[pt.y].text.length();
        int end = fromPoint(pt);
        if (pCopyLine)
          pCopyLine->Release();
        pCopyLine = SetClipboard(CF_UNICODETEXT, CreateGlobalText(substring(start, end)));
        if (pCopyLine)
          pCopyLine->AddRef();
      }
      break;
    case ID_EDIT_CUT:
      if (caret != selStart)
      {
        SetClipboard(CF_UNICODETEXT, CreateGlobalText(getSelection()));
        replace(selStart, caret, L"");
      }
      else
      {
        POINT pt = toPoint(caret);
        POINT save = pt;
        pt.x = 0;
        int start = fromPoint(pt);
        if (pt.y < lines.length() - 1)
          pt.y++;
        else
          pt.x = lines[pt.y].text.length();
        int end = fromPoint(pt);
        if (pCopyLine)
          pCopyLine->Release();
        pCopyLine = SetClipboard(CF_UNICODETEXT, CreateGlobalText(substring(start, end)));
        if (pCopyLine)
          pCopyLine->AddRef();
        replace(start, end, L"");
        caret = selStart = fromPoint(save);
        updateCaret();
      }
      break;
    case ID_EDIT_PASTE:
      {
        ClipboardReader reader(CF_UNICODETEXT);
        if (reader.getData())
        {
          if (OleIsCurrentClipboard(pCopyLine) == S_OK)
          {
            POINT pt = toPoint(caret);
            pt.x = 0;
            caret = selStart = fromPoint(pt);
          }
          selStart = caret = replace(selStart, caret, GetGlobalTextWide(reader.getData()));
          updateCaret();
        }
      }
      break;
    case ID_DEBUG_BREAKPOINT:
      {
        POINT pt = toPoint(caret);
        toggleBreakpoint(pt.y);
      }
      break;
    default:
      return M_UNHANDLED;
    }
    return 0;
  }
  return M_UNHANDLED;
}
예제 #22
0
	void TextField::handleKeyboard( KeyEvent &keyEvent )
	{
		if(handleHotkeys(keyEvent))
		{
			return;
		}

		//delete the next character
		if(keyEvent.getKey() == KEY_DELETE)
		{
			if(getCaretPosition() == getTextLength()
				&& getSelectionStart() == getSelectionEnd())
			{
				return;
			}

			if(isReadOnly())
			{
				return;
			}

			if(getSelectionStart() == getSelectionEnd())
			{
				removeNextCharacter();
			}
			else
			{
				deleteSelection();
			}
			setBlinking(true);
			invalidateBlink();
			return;
		}

		//delete the previous character
		if(keyEvent.getKey() == KEY_BACKSPACE)
		{
			if(getCaretPosition() == 0 && getSelectionStart() == getSelectionEnd())
			{
				return;
			}

			if(isReadOnly())
			{
				return;
			}

			if(getSelectionStart() == getSelectionEnd())
			{
				removeLastCharacter();
			}
			else
			{
				deleteSelection();
			}
			setBlinking(true);
			invalidateBlink();
			return;
		}

		if(keyEvent.getUnichar() >= ' ')
		{
			if(isReadOnly())
			{
				setBlinking(true);
				invalidateBlink();
				return;
			}

			if( isNumeric())
			{
				if(keyEvent.getUnichar() >= 0x30  && keyEvent.getUnichar() <= 0x39 )
				{
					deleteSelection();
					addToNextCharacter(keyEvent.getUnichar());
					setBlinking(true);
					invalidateBlink();
				}
				else if(wantedDecimal() && keyEvent.getUnichar() == 0x2e )
				{
					//check if there is already a decimal
					const char *text = getText().c_str();
					for (int i = 0; i < getTextLength(); ++i)
					{
						if(text[i] == 0x2e)
						{
							return;
						}
					}

					deleteSelection();
					addToNextCharacter(keyEvent.getUnichar());
					setBlinking(true);
					invalidateBlink();
				}
				else if(wantedMinus() && keyEvent.getUnichar() == 0x2d )
				{
					//check if we are in the first position
					if(getCaretPosition() != 0)
					{
						return;
					}

					//check if there is already a minus
					const char *text = getText().c_str();
					for (int i = 0; i < getTextLength(); ++i)
					{
						if(text[i] == 0x2d)
						{
							return;
						}
					}

					deleteSelection();
					addToNextCharacter(keyEvent.getUnichar());
					setBlinking(true);
					invalidateBlink();
				}
				

				return;
			}
			deleteSelection();
			addToNextCharacter(keyEvent.getUnichar());

			setBlinking(true);
			invalidateBlink();
			return;
		}

		switch (keyEvent.getExtendedKey())
		{
		case EXT_KEY_RIGHT:

			if(getCaretPosition() == getTextLength() 
				&& getSelectionStart() != getSelectionEnd() &&
				keyEvent.shift())
			{
				return;
			}
			else if(getCaretPosition() == getTextLength() 
				&& getSelectionStart() == getSelectionEnd())
			{
				return;
			}

			positionCaret(getCaretPosition() + 1);

			if(keyEvent.shift())
			{
				if(getSelectionStart() == getSelectionEnd())
				{
					setSelection(getCaretPosition() - 1, getCaretPosition());
				}
				else
				{
					if(getCaretPosition() - 1 < getSelectionEnd())
						setSelection(getSelectionEnd(), getCaretPosition());
					else
						setSelection(getSelectionStart(), getCaretPosition());
				}
			}
			else if(getSelectionStart() != getSelectionEnd())
			{
				int caretPos = getSelectionEnd();
				setSelection(0,0);
				positionCaret(caretPos);
			}

			setBlinking(true);
			invalidateBlink();
			break;
		case EXT_KEY_LEFT:

			if(getCaretPosition() == 0 
				&& getSelectionStart() != getSelectionEnd() &&
				keyEvent.shift())
			{
				return;
			}
			else if(getCaretPosition() == 0
				&& getSelectionStart() == getSelectionEnd())
			{
				return;
			}

			positionCaret(getCaretPosition() - 1);

			if(keyEvent.shift())
			{
				if(getSelectionStart() == getSelectionEnd())
				{
					setSelection(getCaretPosition() + 1, getCaretPosition());
				}
				else
				{
					if(getCaretPosition() + 1 < getSelectionEnd())
						setSelection(getSelectionEnd(), getCaretPosition());
					else
						setSelection(getSelectionStart(), getCaretPosition());
				}
			}

			else if(getSelectionStart() != getSelectionEnd())
			{
				int caretPos = getSelectionStart();
				setSelection(0,0);
				positionCaret(caretPos);
			}

			setBlinking(true);
			invalidateBlink();
			break;
		}

	}
예제 #23
0
void StatusBar::onPaint(ui::PaintEvent& ev)
{
  SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
  ui::Color textColor = theme->getColorById(kStatusBarText);
  Rect rc = getClientBounds();
  Graphics* g = ev.getGraphics();

  g->fillRect(getBgColor(), rc);

  rc.shrink(Border(2, 1, 2, 2)*jguiscale());

  int x = rc.x + 4*jguiscale();

  // Color
  if (m_state == SHOW_COLOR) {
    // Draw eyedropper icon
    BITMAP* icon = theme->get_toolicon("eyedropper");
    if (icon) {
      g->drawAlphaBitmap(icon, x, rc.y + rc.h/2 - icon->h/2);
      x += icon->w + 4*jguiscale();
    }

    // Draw color
    draw_color_button(g, gfx::Rect(x, rc.y, 32*jguiscale(), rc.h),
      true, true, true, true,
      true, true, true, true,
      app_get_current_pixel_format(), m_color,
      false, false);

    x += (32+4)*jguiscale();

    // Draw color description
    std::string str = m_color.toHumanReadableString(app_get_current_pixel_format(),
      app::Color::LongHumanReadableString);
    if (m_alpha < 255) {
      char buf[512];
      usprintf(buf, ", Alpha %d", m_alpha);
      str += buf;
    }

    g->drawString(str, textColor, ColorNone, false,
      gfx::Point(x, rc.y + rc.h/2 - text_height(getFont())/2));

    x += ji_font_text_len(getFont(), str.c_str()) + 4*jguiscale();
  }

  // Show tool
  if (m_state == SHOW_TOOL) {
    // Draw eyedropper icon
    BITMAP* icon = theme->get_toolicon(m_tool->getId().c_str());
    if (icon) {
      g->drawAlphaBitmap(icon, x, rc.y + rc.h/2 - icon->h/2);
      x += icon->w + 4*jguiscale();
    }
  }

  // Status bar text
  if (getTextLength() > 0) {
    g->drawString(getText(), textColor, ColorNone, false,
      gfx::Point(x, rc.y + rc.h/2 - text_height(getFont())/2));

    x += ji_font_text_len(getFont(), getText().c_str()) + 4*jguiscale();
  }

  // Draw progress bar
  if (!m_progress.empty()) {
    int width = 64;
    int x = rc.x2() - (width+4);

    for (ProgressList::iterator it = m_progress.begin(); it != m_progress.end(); ++it) {
      Progress* progress = *it;

      theme->paintProgressBar(g,
        gfx::Rect(x, rc.y, width, rc.h),
        progress->getPos());

      x -= width+4;
    }
  }

  updateSubwidgetsVisibility();
}
예제 #24
0
파일: main.c 프로젝트: krikelin/QML
qml_document *parseQML(QML_TEXT text,int unicode) {
    int insideString = 0;
    int row = 0;
    int col = 0;
    int mode = QML_PARSER_MODE_ENTITY;
    int level = 0;
    qml_node *currentNode = NULL;
    qml_document *qmlDoc = (qml_document *)malloc(1 * sizeof(qml_document));

    int textPos = 0;
    int length = getTextLength(text);
    for(int i = 0; i < length; i++) {
        
        QML_CHAR token = text[i];
        switch(token) {
          
            case '\n':
                row++;
                col = 0;
                break;
            case '#':

            case '$':
            case '^':
                textPos = 0;
                level--;
                mode = QML_PARSER_MODE_ENTITY;
                qml_node *child = createQMLElement();
                
                // add current_node to children
                if(currentNode != NULL) {
                    //currentNode->children[currentNode->iCountChildren] = child; // Add children to collection
                    //currentNode->iCountChildren++; // Increase it
                    child->parent = currentNode;
                    qml_push_child(currentNode, child);
                } else {
                    qmlDoc->documentElement = child;
                }   
                currentNode = child;
                child->type = token;
                
                break;
       
            default:
                if(level == 0) {
                    break;
                }
                if(text[i - 1] != '\\' && (token == '"' || token =='\'')) {
                    insideString = !insideString;
                    break;
                }
                if((token == '.' || token == ',') && !insideString) {
                   
                    mode = QML_PARSER_MODE_ENTITY;
                    currentNode = currentNode->parent;
                    level++;
                    
                    // Reset text buffer
                    textPos = 0;
                    break;
                } else {
                    switch(mode) {
                        case QML_PARSER_MODE_ENTITY:
                            if(token == ' ' || token == '\t' && !insideString) {
                                mode = QML_PARSER_MODE_CONTENT;
                                textPos = 0;
                                break;
                            }
                            else {      
                                    currentNode->tag[textPos] = token;
                                    
                            }
                            textPos++;
                            break;
                        case QML_PARSER_MODE_CONTENT:
                            currentNode->content[textPos] = token;
                            char *content = currentNode->content;
                            textPos++;
                            break;
                    
                    }
                }
            break;
                
        }
        if(level != 0) {
//            cerr("Error in leveling");
        }
        
        // insert code here
    }
    return qmlDoc;
}
예제 #25
0
	void TextField::setSelection( int start, int end )
	{
		if(!isSelectable())
		{
			if(getSelectionStart() != getSelectionEnd())
			{
				start = 0;
				end = 0;
			}
			else
			{
				return;
			}
		}
		if(start == end)
		{
			selStart = 0;
			selEnd = 0;
			selWidth = 0;
		}

		if(start == -1 && end == -1)
		{
			start = 0;
			end = getTextLength();
		}
		else if( end == -1)
		{
			end = getTextLength();
		}
		if( start > end)
		{
			int temp = start;
			start = end;
			end = temp;
		}

		if(start < 0)
		{
			start = 0;
		}
		if( end > getTextLength() )
		{
			end = getTextLength();
		}

		for(std::vector<TextFieldListener*>::iterator it = tFieldListeners.begin();
			it != tFieldListeners.end(); ++it)
		{
			(*it)->selectionChanged(this,start,end);
		}

		selStart = start;
		selEnd = end;
		selLength = end - start;
		selPos = getFont()->getTextWidth(unicodeFunctions.subStr(getText(),
			0,start)) + getTextOffset();

		selWidth = getFont()->getTextWidth(unicodeFunctions.subStr(getText(),
			start,selLength));

	}