Esempio n. 1
0
void TimeEdit::OnChar(wxKeyEvent &event) {
    event.Skip();
    if (byFrame || insert) return;

    int key = event.GetUnicodeKey();
    if ((key < '0' || key > '9') && key != ';' && key != '.' && key != ',') return;

    event.Skip(false);

    long start = GetInsertionPoint();
    std::string text = from_wx(GetValue());
    // Cursor is at the end so do nothing
    if (start >= (long)text.size()) return;

    // If the cursor is at punctuation, move it forward to the next digit
    if (text[start] == ':' || text[start] == '.' || text[start] == ',')
        ++start;

    // : and . hop over punctuation but never insert anything
    if (key == ':' || key == ';' || key == '.' || key == ',') {
        SetInsertionPoint(start);
        return;
    }

    // Overwrite the digit
    text[start] = (char)key;
    time = text;
    SetValue(to_wx(time.GetAssFormated()));
    SetInsertionPoint(start + 1);
}
Esempio n. 2
0
// DateCtrl
void DateCtrl::OnChar(wxKeyEvent& event)
{
    size_t keycode = event.GetKeyCode();
    size_t point = GetInsertionPoint();
    wxString value = GetValue();
    long from, to;

    GetSelection(&from, &to);
    if ( from != to ) {
        value = DATE_PATTERN;
    }

    if ( WXK_BACK == keycode ) {
        size_t prevPoint = point - 1;
        if ( prevPoint >= 0 
             && prevPoint != 4 
             && prevPoint != 7 
             && value.Length() == 10 ) {
             value[prevPoint] = 32;
             SetValue(value);
             size_t prevPrev = prevPoint - 1;
             
             if ( prevPrev == 4 
                 || prevPrev == 7 ) {
                SetInsertionPoint(prevPrev);
            } else {
                SetInsertionPoint(prevPoint);
            }
        }   
    } else if ( WXK_DELETE == keycode ) {
        if ( point != 4 
             && point != 7 
             && value.Length() == 10 ) {
            value[point] = 32;
            SetValue(value);
            SetInsertionPoint(point);
        }    
    } else if ( !wxIsprint((int)keycode) ) {
        event.Skip();
    } else if ( point >= 10 ) {
        event.Skip();
    } else {
        if ( point  == 4 || point == 7 ) {
            point++;    
        }
        // compatibility with pattern must be here
        if ( value.Length() != 10 ) {
            value = DATE_PATTERN;
        }
        if ( wxIsdigit((int)keycode) ) {
            value[point] = event.GetKeyCode();
            SetValue(value);
            SetInsertionPoint(point+1);
        } 
   }
}
Esempio n. 3
0
void wxTextCtrl::DoSetValue( const wxString &value, int flags )
{
    wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );

    if ( !(flags & SetValue_SendEvent) )
    {
        // do not generate events
        IgnoreNextTextUpdate();
    }

    if (m_windowStyle & wxTE_MULTILINE)
    {
        gint len = gtk_text_get_length( GTK_TEXT(m_text) );
        gtk_editable_delete_text( GTK_EDITABLE(m_text), 0, len );
        len = 0;
        gtk_editable_insert_text( GTK_EDITABLE(m_text), value.mbc_str(), value.length(), &len );
    }
    else
    {
        gtk_entry_set_text( GTK_ENTRY(m_text), wxGTK_CONV( value ) );
    }

    // GRG, Jun/2000: Changed this after a lot of discussion in
    //   the lists. wxWidgets 2.2 will have a set of flags to
    //   customize this behaviour.
    SetInsertionPoint(0);

    m_modified = false;
}
Esempio n. 4
0
void NyqTextCtrl::MoveCursor(long first, long second)
{
   int pos = GetInsertionPoint();
   int lpos = wxMax(0, pos - 1);

   wxString text = GetRange(lpos, pos);

   if (text[0] == wxT('(')) {
      SetInsertionPoint(first + 1);
      Colorize(first, second);
   }
   else if (text[0] == wxT(')')) {
      SetInsertionPoint(second + 1);
      Colorize(first, second);
   }
}
Esempio n. 5
0
void wxTextCtrl::DoSetValue(const wxString& value, int flags)
{
    // if the text is long enough, it's faster to just set it instead of first
    // comparing it with the old one (chances are that it will be different
    // anyhow, this comparison is there to avoid flicker for small single-line
    // edit controls mostly)
    if ( (value.length() > 0x400) || (value != GetValue()) )
    {
        DoWriteText(value, flags);

        // for compatibility, don't move the cursor when doing SetValue()
        SetInsertionPoint(0);
    }
    else // same text
    {
        // still send an event for consistency
        if ( flags & SetValue_SendEvent )
            SendUpdateEvent();
    }

    // we should reset the modified flag even if the value didn't really change

    // mark the control as being not dirty - we changed its text, not the
    // user
    DiscardEdits();
}
Esempio n. 6
0
void wxTextEntry::Remove(long from, long to)
{
    const long insertionPoint = GetInsertionPoint();
    wxString string = GetValue();
    string.erase(from, to - from);
    SetValue(string);
    SetInsertionPoint( std::min(insertionPoint, static_cast<long>(string.length())) );
}
Esempio n. 7
0
void CMuleTextCtrl::OnSelAll( wxCommandEvent& WXUNUSED(evt) )
{
	// Move the pointer to the front
	SetInsertionPoint( 0 );

	// Selects everything
	SetSelection( -1, -1 );
}
Esempio n. 8
0
void wxComboBox::SetInsertionPointEnd()
{
    // setting insertion point doesn't make sense for read only comboboxes
    if ( !(GetWindowStyle() & wxCB_READONLY) )
    {
        wxTextPos pos = GetLastPosition();
        SetInsertionPoint(pos);
    }
}
Esempio n. 9
0
bool wxTextCtrl::SetStyle( long start, long end, const wxTextAttr& style )
{
    if ( m_windowStyle & wxTE_MULTILINE )
    {
        if ( style.IsDefault() )
        {
            // nothing to do
            return true;
        }

        // VERY dirty way to do that - removes the required text and re-adds it
        // with styling (FIXME)

        gint l = gtk_text_get_length( GTK_TEXT(m_text) );

        wxCHECK_MSG( start >= 0 && end <= l, false,
                     wxT("invalid range in wxTextCtrl::SetStyle") );

        gint old_pos = gtk_editable_get_position( GTK_EDITABLE(m_text) );
        char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), start, end );
        wxString tmp(text,*wxConvCurrent);
        g_free( text );

        gtk_editable_delete_text( GTK_EDITABLE(m_text), start, end );
        gtk_editable_set_position( GTK_EDITABLE(m_text), start );

#if wxUSE_UNICODE
        wxWX2MBbuf buf = tmp.mbc_str();
        const char *txt = buf;
        size_t txtlen = strlen(buf);
#else
        const char *txt = tmp;
        size_t txtlen = tmp.length();
#endif

        // use the attributes from style which are set in it and fall back
        // first to the default style and then to the text control default
        // colours for the others
        wxGtkTextInsert(m_text,
                        wxTextAttr::Combine(style, m_defaultStyle, this),
                        txt,
                        txtlen);

        /* does not seem to help under GTK+ 1.2 !!!
        gtk_editable_set_position( GTK_EDITABLE(m_text), old_pos ); */
        SetInsertionPoint( old_pos );

        return true;
    }

    // else single line
    // cannot do this for GTK+'s Entry widget
    return false;
}
Esempio n. 10
0
void wxTextEntry::WriteText(const wxString& text)
{
    long pos = GetInsertionPoint();

    XmTextInsert(GetText(), pos, text.char_str());

    pos += text.length();

    XtVaSetValues(GetText(), XmNcursorPosition, pos, NULL);
    SetInsertionPoint(pos);
    XmTextShowPosition(GetText(), pos);
}
Esempio n. 11
0
void BTextCtrl::CloseParenthesis(wxString open, wxString close, bool fromOpen)
{
  long from, to;
  GetSelection(&from, &to);

  if (from == to)  // nothing selected
  {
    wxString text = this->GetValue();
    wxString charHere = text.GetChar((size_t)GetInsertionPoint());

    if (!fromOpen)
    {
      if (charHere == close)
        SetInsertionPoint(GetInsertionPoint() + 1);
      else
        WriteText(close);
    }
    else
    {
      WriteText(open + close);
      SetInsertionPoint(GetInsertionPoint() - 1);
    }
  }
  else
  {
    SetInsertionPoint(to);
    WriteText(close);
    SetInsertionPoint(from);
    WriteText(open);
    if (fromOpen)
      SetInsertionPoint(from);
    else
      SetInsertionPoint(to+2);
  }
}
Esempio n. 12
0
void wxTextCtrl::SetInsertionPointEnd()
{
    wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );

    if (m_windowStyle & wxTE_MULTILINE)
    {
        SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text)));
    }
    else
    {
        gtk_entry_set_position( GTK_ENTRY(m_text), -1 );
    }
}
Esempio n. 13
0
void wxTextCtrl::SetInsertionPointEnd()
{
    wxTextPos                       lPos = GetLastPosition();

    //
    // We must not do anything if the caret is already there because calling
    // SetInsertionPoint() thaws the controls if Freeze() had been called even
    // if it doesn't actually move the caret anywhere and so the simple fact of
    // doing it results in horrible flicker when appending big amounts of text
    // to the control in a few chunks (see DoAddText() test in the text sample)
    //
    if (GetInsertionPoint() == GetLastPosition())
        return;
    SetInsertionPoint(lPos);
} // end of wxTextCtrl::SetInsertionPointEnd
Esempio n. 14
0
void NumberTextCtrl::OnEnterText(wxCommandEvent& evt)
{
	printf("%d\n", (int)GetInsertionPoint());
	wxString text = GetValue();
	wxString ntext;

	int p = GetInsertionPoint();
	if(text.size() && text[0] == wxT('-'))
		ntext.Append(wxT('-'));

	for(size_t s = 0; s < text.size(); ++s)
	{
		if(text[s] >= '0' && text[s] <= '9')
			ntext.Append(text[s]);
		else
			--p;
	}

	// Check that value is in range
	long v;
	if(ntext.ToLong(&v))
	{
		if(v < minval)
			v = minval;
		else if(v > maxval)
			v = maxval;

		ntext.clear();
		ntext << v;
	}
	else
	{
		// Invalid input, set to ""
		ntext = wxT("");
	}

	// Check if there was any change
	if(ntext != text)
	{
		// User input was invalid, change the text to the cleaned one.

		// ChangeValue doesn't generate events
		ChangeValue(ntext);
		SetInsertionPoint(p);
	}
}
Esempio n. 15
0
// This is hackage to correct a problem on Leopard where the
// caret jumps up two lines when the up arrow is pressed and
// the caret is at the beginning of the line.
void NyqTextCtrl::OnKeyDown(wxKeyEvent & e)
{
   e.Skip();
   if (UMAGetSystemVersion() >= 0x1050) {
      if (e.GetKeyCode() == WXK_UP && e.GetModifiers() == 0) {
         long x;
         long y;
   
         PositionToXY(GetInsertionPoint(), &x, &y);
         if (x == 0 && y > 1) {
            y--;
            SetInsertionPoint(XYToPosition(x, y) - 1);
            e.Skip(false);
         }
      }
   }
}
Esempio n. 16
0
void wxTextCtrl::DoSetValue(const wxString& text, int flags)
{
    m_inSetValue = true;

    XmTextSetString ((Widget) m_mainWidget, text.char_str());
    XtVaSetValues ((Widget) m_mainWidget,
                   XmNcursorPosition, text.length(),
                   NULL);

    SetInsertionPoint(text.length());
    XmTextShowPosition ((Widget) m_mainWidget, text.length());
    m_modified = true;

    m_inSetValue = false;

    if ( flags & SetValue_SendEvent )
        SendTextUpdatedEvent();
}
Esempio n. 17
0
void TimeEdit::OnKeyDown(wxKeyEvent &event) {
    int kc = event.GetKeyCode();

    // Needs to be done here to trump user-defined hotkeys
    int key = event.GetUnicodeKey();
    if (event.CmdDown()) {
        if (key == 'C' || key == 'X')
            CopyTime();
        else if (key == 'V')
            PasteTime();
        else
            event.Skip();
        return;
    }

    // Shift-Insert would paste the stuff anyway
    // but no one updates the private "time" variable.
    if (event.ShiftDown() && kc == WXK_INSERT) {
        PasteTime();
        return;
    }

    if (byFrame || insert) {
        event.Skip();
        return;
    }
    // Overwrite mode stuff

    // On OS X backspace is reported as delete
#ifdef __APPLE__
    if (kc == WXK_DELETE)
        kc = WXK_BACK;
#endif

    // Back just moves cursor back one without deleting
    if (kc == WXK_BACK) {
        long start = GetInsertionPoint();
        if (start > 0)
            SetInsertionPoint(start - 1);
    }
    // Delete just does nothing
    else if (kc != WXK_DELETE)
        event.Skip();
}
Esempio n. 18
0
void wxTextEntry::DoSetValue(const wxString& value, int flags)
{
    if (value != DoGetValue())
    {
        // Use Remove() rather than SelectAll() to avoid unnecessary clipboard
        // operations, and prevent triggering an apparent bug in GTK which
        // causes the subsequent WriteText() to append rather than overwrite.
        {
            EventsSuppressor noevents(this);
            Remove(0, -1);
        }
        EventsSuppressor noeventsIf(this, !(flags & SetValue_SendEvent));
        WriteText(value);
    }
    else if (flags & SetValue_SendEvent)
        SendTextUpdatedEvent(GetEditableWindow());

    SetInsertionPoint(0);
}
Esempio n. 19
0
/* NumberTextCtrl::onChanged
 * Called when the value is changed
 *******************************************************************/
void NumberTextCtrl::onChanged(wxCommandEvent& e)
{
	string new_value = GetValue();

	// Check if valid
	// Can begin with '+', '++', '-' or '--', rest has to be numeric
	bool num = false;
	bool valid = true;
	int plus = 0;
	int minus = 0;
	int decimal = 0;
	for (unsigned a = 0; a < new_value.size(); a++)
	{
		// Check for number
		if (new_value.at(a) >= '0' && new_value.at(a) <= '9')
		{
			num = true;
			continue;
		}

		// Check for +
		if (new_value.at(a) == '+')
		{
			if (num || plus == 2 || minus > 0)
			{
				// We've had a number, '-' or 2 '+' already, invalid
				valid = false;
				break;
			}
			else
				plus++;
		}

		// Check for -
		else if (new_value.at(a) == '-')
		{
			if (num || minus == 2 || plus > 0)
			{
				// We've had a number, '+' or 2 '-' already, invalid
				valid = false;
				break;
			}
			else
				minus++;
		}

		// Check for .
		else if (new_value.at(a) == '.')
		{
			if (!num || decimal > 0)
			{
				// We've already had a decimal, or no numbers yet, invalid
				valid = false;
				break;
			}
			else
				decimal++;
		}
	}

	// If invalid revert to previous value
	if (!valid)
	{
		ChangeValue(last_value);
		SetInsertionPoint(last_point);
	}
	else
	{
		last_value = new_value;
		last_point = GetInsertionPoint();
		e.Skip();
	}
}
Esempio n. 20
0
void wxComboBox::SetInsertionPointEnd()
{
    wxTextPos                       lPos = GetLastPosition();

    SetInsertionPoint(lPos);
} // end of wxComboBox::SetInsertionPointEnd
Esempio n. 21
0
bool wxTextCtrlBase::EmulateKeyPress(const wxKeyEvent& event)
{
    bool handled = false;
    // we have a native implementation for Win32 and so don't need this one
#ifndef __WIN32__
    wxChar ch = 0;
    int keycode = event.GetKeyCode();

    long from, to;
    GetSelection(&from,&to);
    long insert = GetInsertionPoint();
    long last = GetLastPosition();

    // catch arrow left and right

    switch ( keycode )
    {
        case WXK_LEFT:
            if ( event.ShiftDown() )
                SetSelection( (from > 0 ? from - 1 : 0) , to );
            else
            {
                if ( from != to )
                    insert = from;
                else if ( insert > 0 )
                    insert -= 1;
                SetInsertionPoint( insert );
            }
            handled = true;
            break;
        case WXK_RIGHT:
            if ( event.ShiftDown() )
                SetSelection( from, (to < last ? to + 1 : last) );
            else
            {
                if ( from != to )
                    insert = to;
                else if ( insert < last )
                    insert += 1;
                SetInsertionPoint( insert );
            }
            handled = true;
            break;
        case WXK_NUMPAD0:
        case WXK_NUMPAD1:
        case WXK_NUMPAD2:
        case WXK_NUMPAD3:
        case WXK_NUMPAD4:
        case WXK_NUMPAD5:
        case WXK_NUMPAD6:
        case WXK_NUMPAD7:
        case WXK_NUMPAD8:
        case WXK_NUMPAD9:
            ch = (wxChar)(wxT('0') + keycode - WXK_NUMPAD0);
            break;

        case WXK_MULTIPLY:
        case WXK_NUMPAD_MULTIPLY:
            ch = wxT('*');
            break;

        case WXK_ADD:
        case WXK_NUMPAD_ADD:
            ch = wxT('+');
            break;

        case WXK_SUBTRACT:
        case WXK_NUMPAD_SUBTRACT:
            ch = wxT('-');
            break;

        case WXK_DECIMAL:
        case WXK_NUMPAD_DECIMAL:
            ch = wxT('.');
            break;

        case WXK_DIVIDE:
        case WXK_NUMPAD_DIVIDE:
            ch = wxT('/');
            break;

        case WXK_DELETE:
        case WXK_NUMPAD_DELETE:
            // delete the character at cursor
            {
                const long pos = GetInsertionPoint();
                if ( pos < GetLastPosition() )
                    Remove(pos, pos + 1);
                handled = true;
            }
            break;

        case WXK_BACK:
            // delete the character before the cursor
            {
                const long pos = GetInsertionPoint();
                if ( pos > 0 )
                    Remove(pos - 1, pos);
                handled = true;
            }
            break;

        default:
#if wxUSE_UNICODE
            if ( event.GetUnicodeKey() )
            {
                ch = event.GetUnicodeKey();
            }
            else
#endif
            if ( keycode < 256 && keycode >= 0 && wxIsprint(keycode) )
            {
                // FIXME this is not going to work for non letters...
                if ( !event.ShiftDown() )
                {
                    keycode = wxTolower(keycode);
                }

                ch = (wxChar)keycode;
            }
            else
            {
                ch = wxT('\0');
            }
    }

    if ( ch )
    {
        WriteText(ch);

        handled = true;
    }
#else // __WIN32__
    wxUnusedVar(event);
#endif // !__WIN32__/__WIN32__

    return handled;
}
Esempio n. 22
0
void TimeEdit::OnKeyDown(wxKeyEvent &event) {
	int key = event.GetKeyCode();
	if (event.CmdDown()) {
		if (key == 'C' || key == 'X')
			CopyTime();
		else if (key == 'V')
			PasteTime();
		else
			event.Skip();
		return;
	}

	// Shift-Insert would paste the stuff anyway
	// but no one updates the private "time" variable.
	if (event.ShiftDown() && key == WXK_INSERT) {
		PasteTime();
		return;
	}

	// Translate numpad presses to normal numbers
	if (key >= WXK_NUMPAD0 && key <= WXK_NUMPAD9)
		key += '0' - WXK_NUMPAD0;

	// If overwriting is disabled, we're in frame mode, or it's a key we
	// don't care about just let the standard processing happen
	event.Skip();
	if (byFrame) return;
	if (insert) return;
	if ((key < '0' || key > '9') && key != WXK_BACK && key != WXK_DELETE && key != ';' && key != '.') return;

	event.Skip(false);

	long start = GetInsertionPoint();
	wxString text = GetValue();

	// Delete does nothing
	if (key == WXK_DELETE) return;
	// Back just moves cursor back one without deleting
	if (key == WXK_BACK) {
		if (start > 0)
			SetInsertionPoint(start - 1);
		return;
	}
	// Cursor is at the end so do nothing
	if (start >= (long)text.size()) return;

	// If the cursor is at punctuation, move it forward to the next digit
	if (text[start] == ':' || text[start] == '.')
		++start;

	// : and . hop over punctuation but never insert anything
	if (key == ';' || key == '.') {
		SetInsertionPoint(start);
		return;
	}

	// Overwrite the digit
	time = text.Left(start) + (char)key + text.Mid(start + 1);
	SetValue(time.GetASSFormated());
	SetInsertionPoint(start + 1);
}
Esempio n. 23
0
void wxTextCtrl::SetInsertionPointEnd()
{
    if ( GetInsertionPoint() != GetLastPosition() )
        SetInsertionPoint(GetLastPosition());
}
Esempio n. 24
0
void TextCtrl::OnChar(wxKeyEvent& event)
{
  long from, to;
  GetSelection(&from, &to);
  switch (event.GetKeyCode())
  {
  case WXK_RETURN:
    {
      long int c, l;
      PositionToXY(GetInsertionPoint(), &c, &l);
      wxString line = GetLineText(l);
      WriteText(wxT("\n"));
      for (int i = 0; i < (int)line.Length(); i++)
      {
        if (line.GetChar(i) != ' ')
          break;
        WriteText(wxT(" "));
      }
    }
    return ;
    break;
  case WXK_TAB:
    {
      long int c, l;
      PositionToXY(GetInsertionPoint(), &c, &l);
      do
      {
        WriteText(wxT(" "));
        c++;
      }
      while (c % 4 != 0);
      SetFocus();
    }
    return ;
    break;
  default:
    break;
  }
  if (m_matchParens)
  {
    switch (event.GetKeyCode())
    {
    case '(':
      if (from == to)
      {
        WriteText(wxT("()"));
        SetInsertionPoint(GetInsertionPoint() - 1);
      }
      else
      {
        SetInsertionPoint(to);
        WriteText(wxT(")"));
        SetInsertionPoint(from);
        WriteText(wxT("("));
        SetInsertionPoint(to + 1);
      }
      break;
    case '[':
      if (from == to)
      {
        WriteText(wxT("[]"));
        SetInsertionPoint(GetInsertionPoint() - 1);
      }
      else
      {
        SetInsertionPoint(to);
        WriteText(wxT("]"));
        SetInsertionPoint(from);
        WriteText(wxT("["));
        SetInsertionPoint(to + 1);
      }
      break;
    case '"':
      if (from == to)
      {
        WriteText(wxT("\"\""));
        SetInsertionPoint(GetInsertionPoint() - 1);
      }
      else
      {
        SetInsertionPoint(to);
        WriteText(wxT("\""));
        SetInsertionPoint(from);
        WriteText(wxT("\""));
        SetInsertionPoint(to + 1);
      }
      break;
    default:
      event.Skip();
    }
  }
  else
    event.Skip();
}
Esempio n. 25
0
void wxTextEntry::SetInsertionPointEnd()
{
    long pos = GetLastPosition();
    SetInsertionPoint( pos );
}