BREW Scheduler Supporting vCalendar - 6 / 7 -
Key Handlers
MainWindow
Within the MainWindow that draws the calendar, the current cursor position is saved in the SFXDate variable _cursor. |
class MainWindow : public SFRPlainWindow { private: SFXDate _currentDay; // current day ... };
Key Handler
HANDLER_IMPLEMENT_BOOLEVENT(MainWindow, OnKey, event) { Bool result(false); switch (event.GetP16()) { case AVK_SELECT: // If SELECT key is pressed ::new OneDayWindow(_currentDay); result = true; break; case AVK_LEFT: _currentDay.SubDay(1); // Move day left InvalidateContent(); // A new area is registered result = true; break; case AVK_RIGHT: _currentDay.AddDay(1); // Move day right InvalidateContent(); // A new area is registered result = true; break; case AVK_UP: _currentDay.SubDay(7); // Move day up InvalidateContent(); // A new area is registered result = true; break; case AVK_DOWN: _currentDay.AddDay(7); // Move day down InvalidateContent(); // A new area is registered result = true; break; } return result; }
OneDayWindow
SFMTYPEDEFCLASS(OneDayWindow) class OneDayWindow : public SFRPlainWindow { SFMSEALCOPY(OneDayWindow) private: SInt16 _displine; // Head of displayed line SInt16 _cursor; // Cursor position SInt16 _maxline; // Number of lines displayed SFXDateConst _date; // Date of the current day SInt32 _index; // Index of VCalendar at date of _date SInt32 _number; // The number of VCalendar public: OneDayWindow(SFXDateConstRef date) static_throws; virtual ~OneDayWindow(Void); HANDLER_DECLARE_VOIDRENDER(OnRenderContent) // drawing handler HANDLER_DECLARE_BOOLEVENT(OnKey) // key handler };
* _cursor :create new window if is at 0, or diaplay the calendar data of the day if it is bigger than 0
Key Handler
HANDLER_IMPLEMENT_BOOLEVENT(OneDayWindow, OnKey, event) { Bool result(false); switch (event.GetP16()) { case AVK_CLR: // Clear key pressed // Close window result = Invoke(SFXEvent(SREVT_RESPONDER_TERMINATE, SRP16_TERMINATE_INVOKE, true)); break; case AVK_SELECT: if (_cursor <= 0) { // If cursor is at 0 ::new CreateWindow(_date); // Create new window } else { // Data that current cursor points to VCalendarFilePtr vcal = SyncScheduler::GetVCalCollection()->Get( _index + _displine + _cursor - 1); ::new ModifyWindow(_date, vcal); // create window } result = true; break; case AVK_DOWN: // If cursor is not at the bottom of data if (_cursor + _displine < _number) { // If cursor is not at the bottom of screen if (_cursor >= _maxline - 1) { ++_displine; // Move displayed line down } else { ++_cursor; // Move cursor down } } else { // If cursor is at the bottom of screen // move cursor at the top of screen _displine = 0; _cursor = 0; } InvalidateContent(); // A new area is registered result = true; break; case AVK_UP: if (_cursor == 0) { // If cursor is at the top of screen if (_displine > 0) { // If line displayed can be moved up --_displine; // Move the line up } else { // if line displayed cannot be moved up // move cursor at the bottom of screen _cursor = (_number < _maxline - 1) ? _number : _maxline - 1; _displine = (_number > _maxline - 1) ? (_number - _maxline + 1) : 0; } } else { --_cursor; // Move cursor up } InvalidateContent(); // A new area is registered result = true; break; } return result; }
DataInputWindow
Both CreateWindow for inputting new data and ModifyWindow for modifying data inherit from DataInputWindow and their logic is shared with it. |
SFMTYPEDEFCLASS(DataInputWindow) class DataInputWindow : public SFRPlainWindow { SFMSEALCOPY(DataInputWindow) protected: SFREditboxControlPtr _textHour; // Text control to input hours SFREditboxControlPtr _textMinute; // Text control to input minutes SFREditboxControlPtr _textContent; // Text control to input content SFRButtonControlPtr _buttonOk; // For OK button SFRButtonControlPtr _buttonCancel; // For Cancel button SFRLabelControlPtr _labelDate; // Date label SFRLabelControlPtr _labelHour; // Hour label SFRLabelControlPtr _labelMinute; // Minute label SInt16 _fontHeight; // Height of font SFXDateConst _date; // Date of today public: DataInputWindow(SFXDateConstRef date) static_throws; virtual ~DataInputWindow(Void); virtual Void MakeData(SFXDateConstRef start, SFXAnsiStringConstRef summary) = 0; HANDLER_DECLARE_VOIDRENDER(OnRenderContent) // Drawing handler HANDLER_DECLARE_BOOLEVENT(OnKey) // Key handler HANDLER_DECLARE_VOIDCONTROL(OnOkButtonControl) // Button handlers HANDLER_DECLARE_VOIDCONTROL(OnCancelButtonControl) }; SFMTYPEDEFCLASS(CreateWindow) class CreateWindow : public DataInputWindow { SFMSEALCOPY(CreateWindow) public: CreateWindow(SFXDateConstRef date); virtual Void MakeData(SFXDateConstRef start, SFXAnsiStringConstRef summary); }; SFMTYPEDEFCLASS(ModifyWindow) class ModifyWindow : public DataInputWindow { SFMSEALCOPY(ModifyWindow) private: VCalendarFilePtr _vcal; // Save data for modifying public: ModifyWindow(SFXDateConstRef date, VCalendarFilePtr vcal); virtual Void MakeData(SFXDateConstRef start, SFXAnsiStringConstRef summary); };
Constructor
DataInputWindow::DataInputWindow(SFXDateConstRef date) : SFRPlainWindow(SFRApplication::GetInstance(), SyncScheduler::CalculateWindowPosition()), _date(date) static_throws { // Registration of soft key SoftkeyWindowPtr softkey; SoftkeyWindow::Initialize(this); if (static_try()) { // Registration of drawing handler static_throw(RegisterHandler(SREVT_RESPONDER_RENDER, SRP16_RENDER_CONTENT,HANDLER_BEFORE, HANDLER_FUNCTION(OnRenderContent))); if (static_try()) { // Registration of key handler static_throw(RegisterHandler(SFEVT_KEY, HANDLER_AFTER, HANDLER_FUNCTION(OnKey))); if (static_try()) { //static_throw(RegisterHandler(static_cast <SFCEventEnum>(SoftkeyWindow::USEREVT_SOFTKEY), HANDLER_AFTER, HANDLER_FUNCTION(OnSoftkey))); if (static_try()) { if ((softkey = SoftkeyWindow::GetInstance()) != null) { static_throw(softkey->Register(this, SoftkeyWindow::SOFTKEY_1, LABEL_SOFTKEY1)); if (static_try()) { static_throw(softkey->Register(this, SoftkeyWindow::SOFTKEY_2, LABEL_SOFTKEY2)); if (static_try()) { static_throw(softkey->Register(this, SoftkeyWindow::SOFTKEY_3, LABEL_SOFTKEY3)); if (static_try()) { SetReference(softkey->Bind(this)); _fontHeight = SFXGraphics:: GetFontHeight(AEE_FONT_NORMAL); SFXRectangleConst screenRect (GetContentWorld()); SFXRectangle rect (MENU_SIDE_MARGIN, MENU_TOP_MARGIN, screenRect.GetRight() - MENU_SIDE_MARGIN, _fontHeight); // Make label _labelDate = ::new SFRLabelControl (this, rect, date.Format ("YYYY/MM/DD")); rect.AddY(_fontHeight + MENU_SPACE); rect.SetSize(MENU_BOX_WIDTH, _fontHeight + TEXTBOX_REVISING); // Make text control for hour input _textHour = ::new SFREditboxControl (this, rect, SFXWideString:: EmptyInstance()); rect.AddX(MENU_BOX_WIDTH); // Make label _labelHour = ::new SFRLabelControl (this, rect, "H"); rect.AddX(rect.GetWidth()); // Make Text control for // minutes input _textMinute=::new SFREditboxControl (this, rect, SFXWideString:: EmptyInstance()); rect.AddX(MENU_BOX_WIDTH); // Make label _labelMinute=::new SFRLabelControl (this, rect, "M"); rect.SetX(MENU_SIDE_MARGIN); rect.AddY(_fontHeight + MENU_SPACE + TEXTBOX_REVISING); rect.SetSize(screenRect.GetRight() - 2 * MENU_SIDE_MARGIN, screenRect. GetBottom() - 4 * MENU_SPACE - 3 * _fontHeight - MENU_TOP_MARGIN); // Make Text control for // inputting content _textContent = ::new SFREditboxControl(this, rect, SFXWideString::EmptyInstance()); rect.Set(MENU_SIDE_MARGIN, screenRect.GetBottom() -MENU_SPACE - _fontHeight, MENU_BUTTON_WIDTH, _fontHeight); // Make OK button _buttonOk =::new SFRButtonControl (this, rect, "OK"); rect.AddX(MENU_SPACE + MENU_BUTTON_WIDTH); // Make cancel button _buttonCancel=::new SFRButtonControl (this, rect, "CANCEL"); if (static_try()) { // The select key is processed // by the default handler.(For // the text control) static_throw(RegisterHandler (SFEVT_KEY, AVK_SELECT, HANDLER_AFTER,HANDLER_FUNCTION (SelectHandler))); if (static_try()) { if (_textHour != null && _textMinute != null && _textContent != null) { // Setting the maximum // character number _textHour-> SetMaxSize(2); _textMinute-> SetMaxSize(2); _textContent-> SetMaxSize(255); // Focus is set. _textHour-> SetStatusFocus(true); if (static_try()) { if (_buttonOk != null) { // Register // button hand static_throw(_buttonOk-> RegisterHandler( SREVT_CONTROL, HANDLER_BEFORE, HANDLER_FUNCTION (OnOkButtonControl))); if (static_try()) { if (_buttonCancel != null) { // Registration of // button handler static_throw( _buttonCancel-> RegisterHandler( SREVT_CONTROL, HANDLER_BEFORE, HANDLER_FUNCTION( OnCancelButtonControl))); } else { static_throw( SFERR_NO_MEMORY); } } } else { static_throw (SFERR_NO_MEMORY); } } } else { static_throw (SFERR_NO_MEMORY); } } } } } } } } } } } return; }
Additional Processing on ModifyWindow
ModifyWindow::ModifyWindow(SFXDateConstRef date, VCalendarFilePtr vcal) : DataInputWindow(date), // Call parent constructor _vcal(vcal) // Data for modifying { SFXDate start = _vcal->GetStartDate(); // Set initial value of the hour text control _textHour->SetText(SFXWideString::Format("%d", start.GetHour())); // Set initial value of the minute text control _textMinute->SetText(SFXWideString::Format("%02d", start.GetMinute())); // Set initial value of the content text control _textContent->SetText(_vcal->GetSummary()); return; }
Handler for OK Button
HANDLER_IMPLEMENT_VOIDCONTROL(DataInputWindow, OnOkButtonControl, result, control) { unused(control); unused(result); SFXDate start(_date); // Convert the string Hour to integer value SInt16 hour = static_cast<SInt16>(_textHour->GetText().AsSInt32()); if (hour < 0 || hour >= 24) { // Check Hour hour = 0; } start.SetHour(hour); // Convert the string Minute to integer value SInt16 minute = static_cast<SInt16>(_textMinute->GetText().AsSInt32()); if (minute < 0 || minute >= 60) { // Check Minute minute = 0; } start.SetMinute(minute); start.SetSecond(0); // Seconds is assumed to be 0 // Get Content string SFXAnsiString summary(static_cast<SFXAnsiString>( _textContent->GetText())); // Make data MakeData(start, summary); // Get OneDayWindow SFRResponderPtr oneDayWindow = GetNext(); // Close this window and the background window Invoke(SFXEvent(SREVT_RESPONDER_TERMINATE, SRP16_TERMINATE_INVOKE, true)); oneDayWindow->Invoke(SFXEvent(SREVT_RESPONDER_TERMINATE, SRP16_TERMINATE_INVOKE, true)); return; }
MakeData() of CreateWindow
Void CreateWindow::MakeData(SFXDateConstRef start, SFXAnsiStringConstRef summary) { VCalendarFilePtr vcal = ::new VCalendarFile("1.0", start, start, summary); if (vcal != null) { SyncScheduler::GetVCalCollection()->Append(vcal); } return; }
MakeData() of ModifyWindow
Void ModifyWindow::MakeData(SFXDateConstRef start, SFXAnsiStringConstRef summary) { if (_vcal != null) { _vcal->Set(start, start, start ,summary); // modify SyncScheduler::GetVCalCollection()->Update(_vcal); } return; }
Update() of VCalCollection
Void VCalCollection::Update(VCalendarFilePtr vcalendar) { _list.Remove(_list.IndexOf(vcalendar)); Append(vcalendar); vcalendar->SetFlag("m"); return; }