dateselectiondialog.cpp
来自「一个基于BREW上的电子时钟程序,通过太阳历计算当前时间,并有闹铃和日志功能.」· C++ 代码 · 共 170 行
CPP
170 行
//
// DateSelectionDialog.cpp
//
// Copyright (C) 2006 Sophia Cradle Incorporated
#include "DateSelectionDialog.hpp"
#include "SGRSoftkeyWindow.hpp"
#include "SGRSoftkeyToolbox.hpp"
#define DATESELECTIONDIALOG_HEIGHT 160
#define DATESELECTIONDIALOG_LABEL_SOFTKEY1 "仼"
#define DATESELECTIONDIALOG_LABEL_SOFTKEY2 "仺"
#define DATESELECTIONDIALOG_LABEL_SOFTKEY3 "慖戰"
DateSelectionDialog::DateSelectionDialog(SFXDateConstRef date, SFXDateDurationConstRef timeDifference, SGRCalendarControl::YearFormatEnum yearFormat, SGRCalendarControl::MonthFormatEnum monthFormat, SGRCalendarControl::DayFormatEnum dayFormat, Bool beginMonday) static_throws : SFRTitleWindow(SFRApplication::GetInstance(), ComputeWindowRectangle(), "擔晅偺慖戰"), _calendar(null)
{
SGRSoftkeyWindowPtr softkey;
SGRSoftkeyWindow::Initialize(this);
if (static_try()) {
_calendar = ::new SGRCalendarControl(this, GetContentWorld(), yearFormat, monthFormat, dayFormat, beginMonday);
if (!_calendar) {
static_throw(SFERR_NO_MEMORY);
}
else {
static_throw(*_calendar);
}
}
if (!static_try()) {
::delete _calendar;
_calendar = null;
}
else {
_calendar->SetCursor(date);
_calendar->SetTimeDifference(timeDifference);
}
if (static_try()) {
static_throw(RegisterHandler(SFEVT_KEY, HANDLER_BEFORE, HANDLER_FUNCTION(OnKey)));
}
if (static_try()) {
static_throw(RegisterHandler(static_cast<SFCEventEnum>(SGRSoftkeyWindow::USEREVT_SOFTKEY), HANDLER_AFTER, HANDLER_FUNCTION(OnSoftkey)));
}
if (static_try()) {
if ((softkey = SGRSoftkeyWindow::GetInstance()) != null) {
static_throw(softkey->Register(this, SGRSoftkeyWindow::SOFTKEY_1, DATESELECTIONDIALOG_LABEL_SOFTKEY1));
if (static_try()) {
static_throw(softkey->Register(this, SGRSoftkeyWindow::SOFTKEY_2, DATESELECTIONDIALOG_LABEL_SOFTKEY2));
}
if (static_try()) {
static_throw(softkey->Register(this, SGRSoftkeyWindow::SOFTKEY_3, DATESELECTIONDIALOG_LABEL_SOFTKEY3));
}
if (static_try()) {
SetReference(softkey->Bind(this));
}
}
}
if (_calendar) {
_calendar->SetStatusTarget(true);
}
}
DateSelectionDialog::~DateSelectionDialog(Void)
{
SGRSoftkeyWindow::Terminate(this);
}
// 僟僀傾儘僌 (僂傿儞僪僂) 偺昞帵埵抲傪寁嶼
SFXRectangle DateSelectionDialog::ComputeWindowRectangle(Void)
{
SFXRectangleConst display(SGRSoftkeyToolbox::GetWindowPosition());
SFXRectangle rect;
rect.SetOrigin(display.GetOrigin());
rect.SetSize(display.GetWidth(), DATESELECTIONDIALOG_HEIGHT);
rect.Offset((display.GetWidth() - rect.GetWidth()) / 2, (display.GetHeight() - rect.GetHeight()) / 2);
return rect;
}
HANDLER_IMPLEMENT_BOOLEVENT(DateSelectionDialog, OnKey, event)
{
SFXDate cursor;
SFXDate maxDate(0x7FFFFFFF);
Bool result(false);
switch (event.GetP16()) {
case AVK_SELECT:
Invoke(SFXEvent(SREVT_WINDOW, SRP16_OK, reinterpret_cast<UInt32>(this)));
result = true;
break;
case AVK_SOFT3:
// 僜僼僩 僉乕偺 3 偼丄1 擭慜傊堏摦
cursor = _calendar->GetCursor();
if (cursor >= SFXDate(1982, 1, 1, 0, 0, 0)) {
cursor.SubYear(1);
}
_calendar->SetCursor(cursor);
_calendar->InvalidateContent();
result = true;
break;
case AVK_SOFT4:
// 僜僼僩 僉乕偺 4 偼丄1 擭屻傊堏摦
cursor = _calendar->GetCursor();
maxDate.Set(maxDate.GetYear(), 1, 1, 0, 0, 0);
maxDate.SubYear(1);
if (cursor < maxDate) {
cursor.AddYear(1);
}
_calendar->SetCursor(cursor);
_calendar->InvalidateContent();
result = true;
break;
case AVK_0:
case AVK_1:
case AVK_2:
case AVK_3:
case AVK_4:
case AVK_5:
case AVK_6:
case AVK_7:
case AVK_8:
case AVK_9:
case AVK_STAR:
case AVK_POUND:
case AVK_CLR:
// 僥儞僉乕偲僋儕傾 僉乕偼乽崱擔傊堏摦乿
_calendar->SetCursor(SFXDate::CurrentUTCDate() + _calendar->GetTimeDifference());
_calendar->InvalidateContent();
result = true;
break;
}
return result;
}
HANDLER_IMPLEMENT_VOIDEVENT(DateSelectionDialog, OnSoftkey, event)
{
SFXDate cursor;
SFXDate maxDate(0x7FFFFFFF);
switch (event.GetP16()) {
case SGRSoftkeyWindow::SOFTKEY_1:
// 僜僼僩 僉乕偺 1 偼丄慜偺寧傊堏摦
cursor = _calendar->GetCursor();
if (cursor >= SFXDate(1981, 2, 1, 0, 0, 0)) {
cursor.SubMonth(1);
}
_calendar->SetCursor(cursor);
_calendar->InvalidateContent();
break;
case SGRSoftkeyWindow::SOFTKEY_2:
// 僜僼僩 僉乕偺 4 偼丄師偺寧傊堏摦
cursor = _calendar->GetCursor();
maxDate.Set(maxDate.GetYear(), 1, 1, 0, 0, 0);
maxDate.SubMonth(1);
if (cursor < maxDate) {
cursor.AddMonth(1);
}
_calendar->SetCursor(cursor);
_calendar->InvalidateContent();
break;
case SGRSoftkeyWindow::SOFTKEY_3:
_calendar->Invoke(SFXEvent(SFEVT_KEY, AVK_SOFT3, 0));
break;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?