示例#1
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);
  }
}
示例#2
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);
}
示例#3
0
void NyqTextCtrl::OnUpdate(wxUpdateUIEvent & e)
{
   int pos = GetInsertionPoint();

   if (pos != mLastCaretPos) {
      int lpos = wxMax(0, pos - 1);
   
      wxString text = GetRange(lpos, pos);
      if (text.Length() > 0) {
         if (text[0] == wxT('(')) {
            wxLongToLongHashMap::const_iterator left = mLeftParens.find(lpos);
            if (left != mLeftParens.end()) {
               Colorize(lpos, left->second);
            }
         }
         else if (text[0] == wxT(')')) {
            wxLongToLongHashMap::const_iterator right = mRightParens.find(lpos);
            if (right != mRightParens.end()) {
               Colorize(right->second, lpos);
            }
         }
      }

      mLastCaretPos = pos;
   }
}
示例#4
0
void wxTextEntry::GetSelection(long *from, long *to) const
{
    gint start, end;
    if ( gtk_editable_get_selection_bounds(GetEditable(), &start, &end) )
    {
        // the output must always be in order, although in GTK+ it isn't
        if ( start > end )
        {
            gint tmp = start;
            start = end;
            end = tmp;
        }
    }
    else // no selection
    {
        // for compatibility with MSW return the empty selection at cursor
        start =
        end = GetInsertionPoint();
    }

    if ( from )
        *from = start;

    if ( to )
        *to = end;
}
示例#5
0
// If the return values from and to are the same, there is no
// selection.
void wxTextCtrl::GetSelection(long* fromOut, long* toOut) const
{
    wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );

    gint from = -1;
    gint to = -1;
    bool haveSelection = false;

    if ( (GTK_EDITABLE(m_text)->has_selection) )
    {
        haveSelection = true;
        from = (long) GTK_EDITABLE(m_text)->selection_start_pos;
        to = (long) GTK_EDITABLE(m_text)->selection_end_pos;
    }

    if (! haveSelection )
        from = to = GetInsertionPoint();

    if ( from > to )
    {
        // exchange them to be compatible with wxMSW
        gint tmp = from;
        from = to;
        to = tmp;
    }

    if ( fromOut )
        *fromOut = from;
    if ( toOut )
        *toOut = to;
}
示例#6
0
void luLogEdit::OnLButtonDBClick(wxMouseEvent& event)
{
	long pos = GetInsertionPoint();
	long x = 0, y = 0;
	PositionToXY(pos, &x, &y);
	wxString line = GetLineText(y);

	//01:15:55: TestError.lua:49: attempt to index field 'object' (a nil value)
	size_t i = wxString(line).MakeLower().find(".lua:");
	if (i != wxString::npos)
	{
		size_t k = line.rfind(':', i);
		size_t p = i+4;
		size_t s = line.find(':', p+1);

		if (k != wxString::npos && p != wxString::npos && s != wxString::npos)
		{
			wxString luaFile = line.SubString(k+1, p-1).Trim().Trim(false);
			wxString lineNo = line.SubString(p+1, s-1).Trim().Trim(false);
			long line = 0;

			if (lineNo.ToLong(&line))
			{
				luMainFrame* frame = getLuMainFrame();
				if (frame) frame->gotoLuaSource(luaFile, line);
			}
		}
	}
	

	event.Skip();
}
int ctlComboBox::GuessSelection(wxCommandEvent &ev)
{
    if (ev.GetEventType() != wxEVT_COMMAND_TEXT_UPDATED)
        return GetGuessedSelection();

    wxString str=wxComboBox::GetValue();
    if (str.Length())
    {
        long pos=GetInsertionPoint();
    
        long sel, count=GetCount();
        int len=str.Length();
        for (sel = 0 ; sel < count ; sel++)
        {
            if (str == GetString(sel).Left(len))
            {
                SetSelection(sel);
                wxString current = GetString(sel);
                SetSelection(pos, current.Length());
                return sel;
            }
        }
    }
    return -1;
}
示例#8
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);
	}
}
示例#9
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())) );
}
示例#10
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);
        } 
   }
}
示例#11
0
void wxTextEntry::GetSelection(long *from, long *to) const
{
    // no unified get selection method in Qt (overriden in textctrl & combobox)
    // only called if no selection
    // If the return values from and to are the same, there is no
    // selection.
    {
        *from =
        *to = GetInsertionPoint();
    }
}
示例#12
0
int SearchWindow::GetCurrentLine() const
{

    long pos = GetInsertionPoint();

    long x, y;
    PositionToXY(pos, &x, &y);

    return y;

}
示例#13
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);
}
示例#14
0
void SourceView::OnUpdateUI(wxUpdateUIEvent& event)
{
	long col, line;
	const bool result = PositionToXY(GetInsertionPoint(), &col, &line);
	if(!result)
		line = -1;
	else
		line += 1;//convert to 1-based line numbering

	mainwin->setCurrent(currentfile, line);

	event.Skip();
}
示例#15
0
文件: textctrl.cpp 项目: EdgarTx/wx
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
示例#16
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);
   }
}
示例#17
0
void wxTextEntry::GetSelection(long* from, long* to) const
{
    XmTextPosition left, right;
    if ( !XmTextGetSelectionPosition(GetText(), &left, &right) )
    {
        // no selection, for compatibility with wxMSW return empty range at
        // cursor position
        left =
        right = GetInsertionPoint();
    }

    if ( from )
        *from = left;
    if ( to )
        *to = right;
}
示例#18
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);
         }
      }
   }
}
示例#19
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();
}
示例#20
0
void NyqTextCtrl::OnKeyUp(wxKeyEvent & e)
{
   e.Skip();

   int pos = GetInsertionPoint();
   int lpos = wxMax(0, pos - 1);

   wxString text = GetRange(lpos, pos);

   if (text[0] == wxT('(')) {
      wxLongToLongHashMap::const_iterator left = mLeftParens.find(lpos);
      if (left != mLeftParens.end()) {
         Colorize(lpos, left->second);
      }
   }
   else if (text[0] == wxT(')')) {
      wxLongToLongHashMap::const_iterator right = mRightParens.find(lpos);
      if (right != mRightParens.end()) {
         Colorize(right->second, lpos);
      }
   }
}
示例#21
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();
}
示例#22
0
void wxTextCtrl::SetInsertionPointEnd()
{
    if ( GetInsertionPoint() != GetLastPosition() )
        SetInsertionPoint(GetLastPosition());
}
示例#23
0
bool wxTextCtrlBase::EmulateKeyPress(const wxKeyEvent& event)
{
    // we have a native implementation for Win32 and so don't need this one
#ifndef __WIN32__
    wxChar ch = 0;
    int keycode = event.GetKeyCode();
    switch ( keycode )
    {
        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)(_T('0') + keycode - WXK_NUMPAD0);
            break;

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

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

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

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

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

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

        case WXK_BACK:
            // delete the character before the cursor
            {
                const long pos = GetInsertionPoint();
                if ( pos > 0 )
                    Remove(pos - 1, pos);
            }
            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 = _T('\0');
            }
    }

    if ( ch )
    {
        WriteText(ch);

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

    return false;
}
示例#24
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();
	}
}
示例#25
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;
}
示例#26
0
void luConsoleEdit::OnKeyDown(wxKeyEvent& event)
{
	int ch = event.GetKeyCode();
	wxString str;
	
	if (ch == WXK_UP) 
	{
		pasteCommand(-1);
		return;
	} 
	else if (ch == WXK_DOWN) 
	{
		pasteCommand(+1);
		return;
	} 
	else if (ch == WXK_ESCAPE) 
	{
		pasteCommand(0);
		replaceCommand("");
		return;
	} 
	else if (ch == WXK_LEFT || ch == WXK_BACK) 
	{
		long x = 0, y = 0;
		if (PositionToXY(GetInsertionPoint(), &x, &y))
		{
			if (x <= (int)m_prompt.Length()) 
				return;
		}		
	} 
	else if (ch == WXK_HOME) 
	{
		long x = 0, y = 0;
		if (PositionToXY(GetInsertionPoint(), &x, &y))
		{
			x = m_prompt.Length();
			long pos = XYToPosition(x, y);
			SetSelection(pos, pos);
		}

		return;
	} 
	
	
	if (ch == WXK_RETURN) 
	{
		str = GetLineText(GetNumberOfLines() - 1);
		str.Replace(m_prompt, "");
	}
	else
	{
		event.Skip();
	}

	if (ch == WXK_RETURN) 
	{
		writeLine("\n");

		str.Trim().Trim(false);

		if (!str.IsEmpty()) 
		{
			runCmd(str, false, false);
			addCommand(str);
		} 
				
		writeLine(m_prompt);
		pasteCommand(0);
	}
}
示例#27
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);
}
void BFTimeCtrl::TextCtrl::UpdatePosition()
{
	iPos_ = GetInsertionPoint();
}
示例#29
0
nsMenuFrame*
nsMenuBarFrame::FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent)
{
  uint32_t charCode;
  aKeyEvent->GetCharCode(&charCode);

  nsAutoTArray<uint32_t, 10> accessKeys;
  nsEvent* nativeEvent = nsContentUtils::GetNativeEvent(aKeyEvent);
  nsKeyEvent* nativeKeyEvent = static_cast<nsKeyEvent*>(nativeEvent);
  if (nativeKeyEvent)
    nsContentUtils::GetAccessKeyCandidates(nativeKeyEvent, accessKeys);
  if (accessKeys.IsEmpty() && charCode)
    accessKeys.AppendElement(charCode);

  if (accessKeys.IsEmpty())
    return nullptr; // no character was pressed so just return

  // Enumerate over our list of frames.
  nsIFrame* immediateParent = nullptr;
  GetInsertionPoint(PresContext()->PresShell(), this, nullptr, &immediateParent);
  if (!immediateParent)
    immediateParent = this;

  // Find a most preferred accesskey which should be returned.
  nsIFrame* foundMenu = nullptr;
  uint32_t foundIndex = accessKeys.NoIndex;
  nsIFrame* currFrame = immediateParent->GetFirstPrincipalChild();

  while (currFrame) {
    nsIContent* current = currFrame->GetContent();

    // See if it's a menu item.
    if (nsXULPopupManager::IsValidMenuItem(PresContext(), current, false)) {
      // Get the shortcut attribute.
      nsAutoString shortcutKey;
      current->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, shortcutKey);
      if (!shortcutKey.IsEmpty()) {
        ToLowerCase(shortcutKey);
        const PRUnichar* start = shortcutKey.BeginReading();
        const PRUnichar* end = shortcutKey.EndReading();
        uint32_t ch = UTF16CharEnumerator::NextChar(&start, end);
        uint32_t index = accessKeys.IndexOf(ch);
        if (index != accessKeys.NoIndex &&
            (foundIndex == accessKeys.NoIndex || index < foundIndex)) {
          foundMenu = currFrame;
          foundIndex = index;
        }
      }
    }
    currFrame = currFrame->GetNextSibling();
  }
  if (foundMenu) {
    return do_QueryFrame(foundMenu);
  }

  // didn't find a matching menu item
#ifdef XP_WIN
  // behavior on Windows - this item is on the menu bar, beep and deactivate the menu bar
  if (mIsActive) {
    nsCOMPtr<nsISound> soundInterface = do_CreateInstance("@mozilla.org/sound;1");
    if (soundInterface)
      soundInterface->Beep();
  }

  nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
  if (pm) {
    nsIFrame* popup = pm->GetTopPopup(ePopupTypeAny);
    if (popup)
      pm->HidePopup(popup->GetContent(), true, true, true);
  }

  SetCurrentMenuItem(nullptr);
  SetActive(false);

#endif  // #ifdef XP_WIN

  return nullptr;
}