Ejemplo n.º 1
0
    // Decrement or increment the value of the current field (wrapping if
    // necessary).
    void ChangeCurrentFieldBy1(Direction dir)
    {
        switch ( m_currentField )
        {
            case Field_Hour:
                m_time.SetHour((m_time.GetHour() + 24 + dir) % 24);
                break;

            case Field_Min:
                m_time.SetMinute((m_time.GetMinute() + 60 + dir) % 60);
                break;

            case Field_Sec:
                m_time.SetSecond((m_time.GetSecond() + 60 + dir) % 60);
                break;

            case Field_AMPM:
                m_time.SetHour((m_time.GetHour() + 12) % 24);
                break;

            case Field_Max:
                wxFAIL_MSG( "Invalid field" );
                return;
        }

        UpdateText();
    }
Ejemplo n.º 2
0
    // Set the current field to its minimal or maximal value.
    void ResetCurrentField(Direction dir)
    {
        switch ( m_currentField )
        {
            case Field_Hour:
            case Field_AMPM:
                // In 12-hour mode setting the hour to the minimal value
                // also changes the suffix to AM and, correspondingly,
                // setting it to the maximal one changes the suffix to PM.
                // And, for consistency with the native MSW behaviour, we
                // also do the same thing when changing AM/PM field itself,
                // so change hours in any case.
                m_time.SetHour(dir == Dir_Down ? 0 : 23);
                break;

            case Field_Min:
                m_time.SetMinute(dir == Dir_Down ? 0 : 59);
                break;

            case Field_Sec:
                m_time.SetSecond(dir == Dir_Down ? 0 : 59);
                break;

            case Field_Max:
                wxFAIL_MSG( "Invalid field" );
                return;
        }

        UpdateText();
    }
Ejemplo n.º 3
0
bool DateChooserWidget::GetDate(wxDateTime &date)
{
	int ret = wxID_OK;
	
	date_control->SetDate(date);
	hour_control->SetValue(date.GetHour());
	minute_control->SetValue(date.GetMinute());

	current_minute = date.GetMinute();
	current_second = date.GetSecond();
	
	while( (ret = ShowModal()) == wxID_OK){ 

		date = date_control->GetDate();
		
		// ustawiamy godzine
		date.SetHour(hour_control->GetValue());
		date.SetMinute(minute_control->GetValue());
		if (second_control)
			date.SetSecond(second_control->GetValue());

		wxDateTime tmin(time_t(0));
		wxDateTime tmax(MAX_TIME_T_FOR_WX_DATE_TIME);
		
		if (date <= tmin || date >= tmax) {
			wxMessageBox(_("Invalid (too large/small) date"), _("Error!"), wxOK);
			return false;
		}

		if (min_date == -1 && max_date == -1)
			return true;

		if(date.GetTicks() >= min_date && date.GetTicks() <= max_date)
			return true;
		else {
      			wxString buf;
			buf = _("Please choose the date from between: ");
			buf += wxDateTime(min_date).Format(_T("%Y-%m-%d %H:%M "));
			buf += _("and");
			buf += wxDateTime(max_date).Format(_T(" %Y-%m-%d %H:%M\n"));
			wxMessageDialog *mesg = new wxMessageDialog(this, buf, _("Incorrect date range"), wxOK);
			mesg->ShowModal();
			delete mesg;
		}
	} 
	return false;
}
Ejemplo n.º 4
0
    // Append the given digit (from 0 to 9) to the current value of the current
    // field.
    void AppendDigitToCurrentField(int n)
    {
        bool moveToNextField = false;

        if ( !m_isFirstDigit )
        {
            // The first digit simply replaces the existing field contents,
            // but the second one should be combined with the previous one,
            // otherwise entering 2-digit numbers would be impossible.
            int currentValue = 0,
                maxValue  = 0;

            switch ( m_currentField )
            {
                case Field_Hour:
                    currentValue = m_time.GetHour();
                    maxValue = 23;
                    break;

                case Field_Min:
                    currentValue = m_time.GetMinute();
                    maxValue = 59;
                    break;

                case Field_Sec:
                    currentValue = m_time.GetSecond();
                    maxValue = 59;
                    break;

                case Field_AMPM:
                case Field_Max:
                    wxFAIL_MSG( "Invalid field" );
                    return;
            }

            // Check if the new value is acceptable. If not, we just handle
            // this digit as if it were the first one.
            int newValue = currentValue*10 + n;
            if ( newValue < maxValue )
            {
                n = newValue;

                // If we're not on the seconds field, advance to the next one.
                // This makes it more convenient to enter times as you can just
                // press all digits one after one without touching the cursor
                // arrow keys at all.
                //
                // Notice that MSW native control doesn't do this but it seems
                // so useful that we intentionally diverge from it here.
                moveToNextField = true;

                // We entered both digits so the next one will be "first" again.
                m_isFirstDigit = true;
            }
        }
        else // First digit entered.
        {
            // The next one won't be first any more.
            m_isFirstDigit = false;
        }

        switch ( m_currentField )
        {
            case Field_Hour:
                m_time.SetHour(n);
                break;

            case Field_Min:
                m_time.SetMinute(n);
                break;

            case Field_Sec:
                m_time.SetSecond(n);
                break;

            case Field_AMPM:
            case Field_Max:
                wxFAIL_MSG( "Invalid field" );
                return;
        }

        if ( moveToNextField && m_currentField < Field_Sec )
            CycleCurrentField(Dir_Up);

        UpdateText();
    }
Ejemplo n.º 5
0
    // Keyboard interface here is modelled over MSW native control and may need
    // adjustments for other platforms.
    void OnTextKeyDown(wxKeyEvent& event)
    {
        const int key = event.GetKeyCode();

        switch ( key )
        {
            case WXK_DOWN:
                ChangeCurrentFieldBy1(Dir_Down);
                break;

            case WXK_UP:
                ChangeCurrentFieldBy1(Dir_Up);
                break;

            case WXK_LEFT:
                CycleCurrentField(Dir_Down);
                break;

            case WXK_RIGHT:
                CycleCurrentField(Dir_Up);
                break;

            case WXK_HOME:
                ResetCurrentField(Dir_Down);
                break;

            case WXK_END:
                ResetCurrentField(Dir_Up);
                break;

            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                // The digits work in all keys except AM/PM.
                if ( m_currentField != Field_AMPM )
                {
                    AppendDigitToCurrentField(key - '0');
                }
                break;

            case 'A':
            case 'P':
                // These keys only work to toggle AM/PM field.
                if ( m_currentField == Field_AMPM )
                {
                    unsigned hour = m_time.GetHour();
                    if ( key == 'A' )
                    {
                        if ( hour >= 12 )
                            hour -= 12;
                    }
                    else // PM
                    {
                        if ( hour < 12 )
                            hour += 12;
                    }

                    if ( hour != m_time.GetHour() )
                    {
                        m_time.SetHour(hour);
                        UpdateText();
                    }
                }
                break;

            // Do not skip the other events, just consume them to prevent the
            // user from editing the text directly.
        }
    }