📄 inputwindow.cpp
字号:
#include "InputWindow.hpp"
#include "SGXAWSParser.hpp"
#include "InformationWindow.hpp"
#include "pself.hpp"
#include "SGRSoftkeyWindow.hpp"
#include "SGRSoftkeyToolbox.hpp"
#define FILE_RETRY_TIMES 64
InputWindow::InputWindow(Void) : SFRTitleWindow(SFRApplication::GetInstance(),
SGRSoftkeyToolbox::GetWindowPosition(), "ISBN 擖椡") static_throws
{
if (static_try()) {
// 昤夋僴儞僪儔傪搊榐
static_throw(RegisterHandler(SREVT_RESPONDER_RENDER, SRP16_RENDER_CONTENT,HANDLER_BEFORE, HANDLER_FUNCTION(OnRenderContent)));
if (static_try()) {
// 僉乕 僴儞僪儔傪搊榐
static_throw(RegisterHandler(SFEVT_KEY, HANDLER_AFTER, HANDLER_FUNCTION(OnKey)));
if (static_try()) {
SFXRectangle rectangle(GetContentWorld());
SInt16Const height = SFXGraphics::GetFontHeight(AEE_FONT_NORMAL);
SInt16Const top = rectangle.GetHeight() / 2 - 2 * height;
SInt16Const margin = 10;
// 儔儀儖
::new SFRLabelControl(this, rectangle.Deflate(20, 0).SetHeight(height).AddY(top), "ISBN:");
// 僥僉僗僩僐儞僩儘乕儖
_textcontrol = ::new SFRBrewTextControl(this, rectangle.AddY(height + margin).AddHeight(5), "");
if (_textcontrol != null) {
// 嵟戝暥帤悢傪愝掕
_textcontrol->SetMaxSize(255);
if (static_try()) {
// 僥僉僗僩僐儞僩儘乕儖忋偱僙儗僋僩僉乕傪墴偟偨偲偒偵
// 擖椡儌乕僪偵堏傞傛偆偵僙僢僩
// 乮SelectHandler 偼SophiaFramework 偑梡堄偟偰偄傞僙儗僋僩僉乕梡偺僴儞僪儔乯
static_throw(RegisterHandler(SFEVT_KEY, AVK_SELECT, HANDLER_BEFORE,HANDLER_FUNCTION(SelectHandler)));
if (static_try()) {
SFXAnsiStringConst buttonString("愙懕");
rectangle.AddY(height + margin + 5).SetWidth(
SFXGraphics::MeasureText(AEE_FONT_NORMAL, buttonString) + 10);
// 儃僞儞
_button = ::new SFRButtonControl(this, rectangle, buttonString);
if (_button != null) {
if (static_try()) {
// _button傪墴偟偨偲偒偺僴儞僪儔傪搊榐
static_throw(_button->RegisterHandler(SREVT_CONTROL, HANDLER_BEFORE,HANDLER_FUNCTION(OnButtonControl)));
if (static_try()) {
// 僥僉僗僩僐儞僩儘乕儖偵僼僅乕僇僗傪摉偰傞
_textcontrol->SetStatusFocus(true);
// 僜僼僩僉乕偺搊榐
SGRSoftkeyWindowPtr softkey;
SGRSoftkeyWindow::Initialize(this);
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, ""));
//if (static_try()) {
static_throw(softkey->Register(this, SGRSoftkeyWindow::SOFTKEY_2, "栠傞"));
if (static_try()) {
static_throw(softkey->Register(this, SGRSoftkeyWindow::SOFTKEY_3, "擖椡"));
if (static_try()) {
SetReference(softkey->Bind(this));
}
}
//}
}
}
}
}
}
}
}
}
}
}
}
return;
}
// 僨僗僩儔僋僞乮僂傿儞僪僂攋婞帪偵幚峴乯
InputWindow::~InputWindow(Void)
{
SGRSoftkeyWindow::Terminate(this);
return;
}
// 昤夋僴儞僪儔乮僂傿儞僪僂撪偵昤夋乯
HANDLER_IMPLEMENT_VOIDRENDER(InputWindow, OnRenderContent, graphics)
{
// 夋柺傪昤夋
// 敀偔揾傝偮傇偡
// GetContentWorld() 偼僂傿儞僪僂偺拞偺昤夋椞堟傪昞偡巐妏宍乮SFXRectangle乯傪曉偡
// SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00) 偼怓傪昞偡乮嵍偐傜R,G,B,傾儖僼傽抣乯丅
graphics->FillRectangle(GetContentWorld(), SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00));
return;
}
// 僉乕 僴儞僪儔乮僂傿儞僪僂偑慜柺偵偁傞偲偒偵僉乕偑墴偝傟傞偲幚峴偝傟傞乯
HANDLER_IMPLEMENT_BOOLEVENT(InputWindow, OnKey, event)
{
Bool ret(false);
switch (event.GetP16()) {
case AVK_UP:
FocusUp();
ret = true;
break;
case AVK_DOWN:
FocusDown();
ret = true;
break;
case AVK_CLR:
// 僂傿儞僪僂偺攋婞 (暵偠傞)
ret = Invoke(SFXEvent(SREVT_RESPONDER_TERMINATE, SRP16_TERMINATE_INVOKE, true));
break;
/*default:
break;*/
}
// 僜僼僩 僉乕偺暥帤傪曄峏
SGRSoftkeyWindowPtr softkey;
if ((softkey = SGRSoftkeyWindow::GetInstance()) != null) {
SFRResponderPtr responder;
if ((responder = GetFocus()) != null) {
if (responder->GetAttribute()== ATTRIBUTE_BREWTEXTCONTROL) {
softkey->Register(this, SGRSoftkeyWindow::SOFTKEY_3, "擖椡");
}
else if (responder->GetAttribute() == ATTRIBUTE_BUTTONCONTROL) {
softkey->Register(this, SGRSoftkeyWindow::SOFTKEY_3, "愙懕");
}
}
}
return ret;
}
HANDLER_IMPLEMENT_VOIDCONTROL(InputWindow, OnButtonControl, result, control) {
unused(control);
unused(result);
// 僱僢僩儚乕僋愙懕
_networkDialog.Open(SGXAWSParser::GetUrl(_textcontrol->GetText()), true, OnNetworkEntry, this);
}
// 僱僢僩儚乕僋僟僀傾儘僌偐傜偺捠抦乮static 斉乯
Void InputWindow::OnNetworkEntry(SGRNetworkDialogSet::NotifyEnum notify, SFCError error, VoidPtr reference)
{
InputWindowPtr(reference)->OnNetwork(notify, error);
}
// 僱僢僩儚乕僋僟僀傾儘僌偐傜偺捠抦
Void InputWindow::OnNetwork(SGRNetworkDialogSet::NotifyEnum notify, SFCError error)
{
unused(error);
switch(notify) {
case SGRNetworkDialogSet::NOTIFY_CONNECT_START:
break;
case SGRNetworkDialogSet::NOTIFY_CONNECT_END:
ParseXML();
break;
}
}
SFCError InputWindow::ParseXML(Void)
{
SFCError error;
SFXAnsiString str;
// 僼傽僀儖柤偺惗惉
SFXMTRandom rand;
SFUFileStream fstream;
SFBFileMgrSmp fileManager(SFBFileMgr::NewInstance());
SFXAnsiString filename;
SInt16 i;
for (i = 0; i < FILE_RETRY_TIMES; ++i) {
filename = DIR_NAME;
filename << SFXAnsiString::Format("data%d", rand.GetUInt16())
<< "_sjis" << EXTENSION_NAME;
if (fileManager->Test(filename) != SFERR_NO_ERROR) {
break;
}
}
if (i < FILE_RETRY_TIMES) {
// sjis 偵曄姺
error = Utf8toAnsiString(_networkDialog.GetText(), &str);
if (error == SFERR_NO_ERROR) {
_networkDialog.ClearText();
fileManager->Remove(filename);
error = fstream.Open(filename, _OFM_CREATE);
if (error == SFERR_NO_ERROR) {
fstream << str;
fstream.Close();
// XML 傪夝愅偡傞
_parser.SetParseImageUrl(true);
_parser.SetParseCustomerReviews(true);
_parser.SetParseSimilarProducts(true);
error = _parser.Parse(filename);
if (error == SFERR_NO_ERROR) {
error = pself::GetInstance()->AddItem(_textcontrol->GetText(), _parser.GetTitle(), filename);
if (error == SFERR_NO_ERROR) {
// 寢壥昞帵僂僀儞僪僂傪奐偔
if ((::new InformationWindow(&_parser, null)) == null) {
error = SFERR_NO_MEMORY;
}
}
} else {
fileManager->Remove(filename);
}
} else {
SFXHelper::dbgprintf("[RecogWindow] fopen err [%d]", error);
}
}
}
else {
error = SFERR_FAILED;
}
return error;
}
// 僜僼僩 僉乕偑墴偝傟偨
HANDLER_IMPLEMENT_VOIDEVENT(InputWindow, OnSoftkey, event)
{
switch (event.GetP16()) {
case SGRSoftkeyWindow::SOFTKEY_1:
break;
case SGRSoftkeyWindow::SOFTKEY_2:
// 僂傿儞僪僂傪攋婞
Invoke(SFXEvent(SREVT_RESPONDER_TERMINATE, SRP16_TERMINATE_INVOKE, true));
break;
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -