📄 cityadditiondialog.cpp
字号:
//
// CityAdditionDialog.cpp
//
// Copyright (C) 2006 Sophia Cradle Incorporated
#include "CityAdditionDialog.hpp"
#include "SGRSoftkeyWindow.hpp"
#include "SGRSoftkeyToolbox.hpp"
#define CITYADDITIONDIALOG_LABEL_SOFTKEY1 "搊榐"
#define CITYADDITIONDIALOG_LABEL_SOFTKEY2 "庢徚"
#define CITYADDITIONDIALOG_LABEL_SOFTKEY3 "慖戰"
CityAdditionDialog::CityAdditionDialog(SFXWideStringConstRef name, SFXWideStringConstRef timeDifference, SFXWideStringConstRef longitude, SFXWideStringConstRef latitude, SFXWideStringConstRef height) static_throws : SFRTitleWindow(SFRApplication::GetInstance(), SGRSoftkeyToolbox::GetWindowPosition(), "搒巗偺捛壛"), _nameControl(null), _timeDifferenceControl(null), _latitudeControl(null), _longitudeControl(null), _heightControl(null)
{
SFXRectangle world(GetContentWorld());
SGRSoftkeyWindowPtr softkey;
SGRSoftkeyWindow::Initialize(this);
// 嵗昗寁嶼
world.Deflate(10, 10, 10, 10);
_nameLabelRect.Set(world);
_nameLabelRect.DivHeight(10);
_nameControlRect.Set(_nameLabelRect);
_nameControlRect.Offset(0, _nameLabelRect.GetHeight());
_timeDifferenceLabelRect.Set(_nameControlRect);
_timeDifferenceLabelRect.Offset(0, _nameControlRect.GetHeight());
_timeDifferenceControlRect.Set(_timeDifferenceLabelRect);
_timeDifferenceControlRect.Offset(0, _timeDifferenceLabelRect.GetHeight());
_latitudeLabelRect.Set(_timeDifferenceControlRect);
_latitudeLabelRect.Offset(0, _timeDifferenceControlRect.GetHeight());
_latitudeControlRect.Set(_latitudeLabelRect);
_latitudeControlRect.Offset(0, _latitudeLabelRect.GetHeight());
_longitudeLabelRect.Set(_latitudeControlRect);
_longitudeLabelRect.Offset(0, _latitudeControlRect.GetHeight());
_longitudeControlRect.Set(_longitudeLabelRect);
_longitudeControlRect.Offset(0, _longitudeLabelRect.GetHeight());
_heightLabelRect.Set(_longitudeControlRect);
_heightLabelRect.Offset(0, _longitudeControlRect.GetHeight());
_heightControlRect.Set(_heightLabelRect);
_heightControlRect.Offset(0, _heightLabelRect.GetHeight());
_nameControlRect.Deflate(10, 0, 30, 0);
_timeDifferenceControlRect.Deflate(10, 0, 30, 0);
_latitudeControlRect.Deflate(10, 0, 30, 0);
_longitudeControlRect.Deflate(10, 0, 30, 0);
_heightControlRect.Deflate(10, 0, 30, 0);
// 儗僗億儞僟偺惗惉
if (static_try()) {
_nameControl = ::new SFRBrewTextControl(this, _nameControlRect, name);
if (!_nameControl) {
static_throw(SFERR_NO_MEMORY);
}
else {
static_throw(*_nameControl);
}
if (!static_try()) {
::delete _nameControl;
_nameControl = null;
}
else {
_nameControl->SetMaxSize(20);
}
}
if (static_try()) {
_timeDifferenceControl = ::new SFRBrewTextControl(this, _timeDifferenceControlRect, timeDifference);
if (!_timeDifferenceControl) {
static_throw(SFERR_NO_MEMORY);
}
else {
static_throw(*_timeDifferenceControl);
}
if (!static_try()) {
::delete _timeDifferenceControl;
_timeDifferenceControl = null;
}
else {
_timeDifferenceControl->SetMaxSize(5);
}
}
if (static_try()) {
_latitudeControl = ::new SFRBrewTextControl(this, _latitudeControlRect, latitude);
if (!_latitudeControl) {
static_throw(SFERR_NO_MEMORY);
}
else {
static_throw(*_latitudeControl);
}
if (!static_try()) {
::delete _latitudeControl;
_latitudeControl = null;
}
else {
_latitudeControl->SetMaxSize(10);
}
}
if (static_try()) {
_longitudeControl = ::new SFRBrewTextControl(this, _longitudeControlRect, longitude);
if (!_longitudeControl) {
static_throw(SFERR_NO_MEMORY);
}
else {
static_throw(*_longitudeControl);
}
if (!static_try()) {
::delete _longitudeControl;
_longitudeControl = null;
}
else {
_longitudeControl->SetMaxSize(10);
}
}
if (static_try()) {
_heightControl = ::new SFRBrewTextControl(this, _heightControlRect, height);
if (!_heightControl) {
static_throw(SFERR_NO_MEMORY);
}
else {
static_throw(*_heightControl);
}
if (!static_try()) {
::delete _heightControl;
_heightControl = null;
}
else {
_heightControl->SetMaxSize(10);
}
}
// 僴儞僪儔偺搊榐
if (static_try()) {
static_throw(RegisterHandler(SREVT_RESPONDER_RENDER, SRP16_RENDER_CONTENT, HANDLER_BEFORE, HANDLER_FUNCTION(OnContent)));
}
if (static_try()) {
static_throw(RegisterHandler(SFEVT_KEY, HANDLER_BEFORE, HANDLER_FUNCTION(OnKey)));
}
if (static_try()) {
static_throw(SFRToolbox::RegisterManipulateHandler(this));
}
if (static_try()) {
static_throw(RegisterHandler(SFEVT_KEY, AVK_SELECT, HANDLER_AFTER, HANDLER_FUNCTION(OnSelect)));
}
if (static_try()) {
#if TARGET_VERSION_GE(3, 1, 0)
static_throw(RegisterHandler(SFEVT_CTL_TEXT_MODECHANGED, 0x8001, HANDLER_AFTER, HANDLER_FUNCTION(OnDone)));
#else
static_throw(RegisterHandler(SFEVT_CTL_TEXT_MODECHANGED, HANDLER_AFTER, HANDLER_FUNCTION(OnDone)));
#endif
}
// 僜僼僩 僉乕偺搊榐
if ((softkey = SGRSoftkeyWindow::GetInstance()) != null) {
static_throw(softkey->Register(this, SGRSoftkeyWindow::SOFTKEY_1, CITYADDITIONDIALOG_LABEL_SOFTKEY1));
if (static_try()) {
static_throw(softkey->Register(this, SGRSoftkeyWindow::SOFTKEY_2, CITYADDITIONDIALOG_LABEL_SOFTKEY2));
}
if (static_try()) {
static_throw(softkey->Register(this, SGRSoftkeyWindow::SOFTKEY_3, CITYADDITIONDIALOG_LABEL_SOFTKEY3));
}
if (static_try()) {
SetReference(softkey->Bind(this));
}
}
if (_nameControl) {
_nameControl->SetStatusFocus(true);
}
}
CityAdditionDialog::~CityAdditionDialog(Void)
{
SGRSoftkeyWindow::Terminate(this);
}
HANDLER_IMPLEMENT_VOIDRENDER(CityAdditionDialog, OnContent, graphics)
{
graphics->ClearRectangle(GetContentWorld());
graphics->DrawText("搒巗柤", _nameLabelRect, SFXRGBColor(0, 0, 0, 0), IDF_ALIGN_LEFT | IDF_ALIGN_MIDDLE);
graphics->DrawText("帪嵎 (椺 : +09:30 仺 +0930)", _timeDifferenceLabelRect, SFXRGBColor(0, 0, 0, 0), IDF_ALIGN_LEFT | IDF_ALIGN_MIDDLE);
graphics->DrawText("堒搙 (杒偼 +丄撿偼 -)", _latitudeLabelRect, SFXRGBColor(0, 0, 0, 0), IDF_ALIGN_LEFT | IDF_ALIGN_MIDDLE);
graphics->DrawText("宱搙 (搶偼 +丄惣偼 -)", _longitudeLabelRect, SFXRGBColor(0, 0, 0, 0), IDF_ALIGN_LEFT | IDF_ALIGN_MIDDLE);
graphics->DrawText("崅搙 (m) (捠忢偼 0 傪愝掕)", _heightLabelRect, SFXRGBColor(0, 0, 0, 0), IDF_ALIGN_LEFT | IDF_ALIGN_MIDDLE);
}
HANDLER_IMPLEMENT_BOOLEVENT(CityAdditionDialog, OnKey, event)
{
Bool result(false);
// 僼僅乕僇僗偺堏摦
switch (event.GetP16()) {
case AVK_UP:
FocusUp();
result = true;
break;
case AVK_LEFT:
FocusUp();
result = true;
break;
case AVK_DOWN:
FocusDown();
result = true;
break;
case AVK_RIGHT:
FocusDown();
result = true;
break;
case AVK_CLR:
// 僋儕傾 僉乕偼僜僼僩 僉乕 2 (庢徚) 偲摨偠埖偄
result = Invoke(SFXEvent(static_cast<SFCEventEnum>(SGRSoftkeyWindow::USEREVT_SOFTKEY), SGRSoftkeyWindow::SOFTKEY_2, 0));
break;
}
return result;
}
// 僙儗僋僩 僉乕 僴儞僪儔
HANDLER_IMPLEMENT_BOOLVOID(CityAdditionDialog, OnSelect)
{
SFRControlPtr control;
Bool result(false);
if ((control = static_cast<SFRControlPtr>(GetFocus())) != null) {
if (control->GetAttribute() == ATTRIBUTE_BREWTEXTCONTROL) {
control->SetStatusTarget(true);
#if defined TARGET_ENVIRONMENT_PHYSICAL
result = control->Invoke(SFXEvent(SFEVT_KEY, AVK_SELECT, 0));
#else
result = true;
#endif
}
}
return result;
}
// 僥僉僗僩 僐儞僩儘乕儖擖椡廔椆僴儞僪儔
HANDLER_IMPLEMENT_VOIDVOID(CityAdditionDialog, OnDone)
{
#if defined TARGET_ENVIRONMENT_PHYSICAL
SFRControlPtr control;
if ((control = static_cast<SFRControlPtr>(GetFocus())) != null) {
if (control->GetAttribute() == ATTRIBUTE_BREWTEXTCONTROL) {
control->SetStatusTarget(false);
}
}
#endif
}
// 僟僀傾儘僌偺忣曬傪庢摼偡傞 (僨乕僞僠僃僢僋婡擻晅偒)
CityAdditionDialog::NewCityInformation CityAdditionDialog::GetNewCityInformation(Void) const
{
NewCityInformation info;
SInt32 d(0), hour(0), minute(0);
Float64 f(0.0);
Bool valid(true), minus(false);
// 僐儞僩儘乕儖偐傜暥帤楍傪庢摼
if (_nameControl) {
info._name.Set(_nameControl->GetText().Trim());
}
if (_timeDifferenceControl) {
info._timeDifference.Set(_timeDifferenceControl->GetText().Trim());
}
if (_longitudeControl) {
info._longitude.Set(_longitudeControl->GetText().Trim());
}
if (_latitudeControl) {
info._latitude.Set(_latitudeControl->GetText().Trim());
}
if (_heightControl) {
info._height.Set(_heightControl->GetText().Trim());
}
// 僨乕僞偺懨摉惈傪僠僃僢僋
info._errorMessage.Clear();
info._invalidControl = null;
if (info._name.IsEmptyCString()) {
info._errorMessage.Set("搒巗柤偑擖椡偝傟傑偣傫丅");
info._invalidControl = _nameControl;
valid = false;
}
if (valid) {
d = info._timeDifference.ToSInt32();
if (d < 0) {
d = - d;
}
hour = d / 100;
minute = d % 100;
if (hour >= 12 || minute >= 60) {
info._errorMessage.Set("帪嵎偺抣偑晄惓偱偡丅");
info._invalidControl = _timeDifferenceControl;
valid = false;
}
}
if (valid) {
f = SFXHelper::wstrtofloat(info._longitude.GetCString());
if (f < 0.0) {
f = - f;
minus = true;
}
else {
minus = false;
}
if (f >= 180.0) {
info._errorMessage.Set("宱搙偺抣偑晄惓偱偡丅");
info._invalidControl = _longitudeControl;
valid = false;
}
else {
d = static_cast<SInt32>(floor(f * 1000.0 + 0.5));
if (minus) {
info._height.Set(SFXWideString::Format("-%d.%d", d / 1000, d % 1000));
}
else {
info._height.Set(SFXWideString::Format("%d.%d", d / 1000, d % 1000));
}
}
}
if (valid) {
f = SFXHelper::wstrtofloat(info._latitude.GetCString());
if (f < 0.0) {
f = - f;
minus = true;
}
else {
minus = false;
}
if (f >= 90.0) {
info._errorMessage.Set("堒搙偺抣偑晄惓偱偡丅");
info._invalidControl = _latitudeControl;
valid = false;
}
else {
d = static_cast<SInt32>(floor(f * 1000.0 + 0.5));
if (minus) {
info._height.Set(SFXWideString::Format("-%d.%d", d / 1000, d % 1000));
}
else {
info._height.Set(SFXWideString::Format("%d.%d", d / 1000, d % 1000));
}
}
}
if (valid) {
f = SFXHelper::wstrtofloat(info._height.GetCString());
if (f < 0.0) {
f = - f;
minus = true;
}
else {
minus = false;
}
d = static_cast<SInt32>(floor(f * 1000.0 + 0.5));
if (minus) {
info._height.Set(SFXWideString::Format("-%d.%d", d / 1000, d % 1000));
}
else {
info._height.Set(SFXWideString::Format("%d.%d", d / 1000, d % 1000));
}
}
return info;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -