NAutoPtr<NDataReader> NParserImpl::FindStyleNode(Base::NAutoPtr<Data::NDataReader> dataReader, LPCTSTR styleName) { NAutoPtr<NDataReader> styleNode; for(int i=0;; ++i) { if(!dataReader->ReadNode(i, styleNode)) return NULL; Base::NString name; if(styleNode->ReadValue(_T("name"), name) && name == styleName) break; styleNode = NULL; } return styleNode; }
bool NStringBundleImpl::InitStringBundle(LPCTSTR stringLang) { // Load config NAutoPtr<NDataReader> reader = CreateDataReader(ReaderXml); if(!reader->ParseFile(_T("@root:package.xml"))) return false; NString bundleLang; for(int i=0; reader->ReadPath(i, _T("string\\bundle"), _T("lang"), bundleLang); ++ i) { if(bundleLang == stringLang) { if(reader->ReadPath(i, _T("string\\bundle"), _T("path"), basePath_)) break; } } if(basePath_.IsEmpty()) { if(!reader->ReadPath(0, _T("string\\bundle"), _T("path"), basePath_)) return false; } return !basePath_.IsEmpty(); }
const NString& NStringBundleImpl::GetString(const NString& name) { if(name.GetLength() < 1 || name[0] != _T('@')) return NString::EmptyString; // Find BundleName and stringId int pos = name.IndexOf(_T(':')); if(pos <= 1 || pos >= name.GetLength() - 1) return NString::EmptyString; NString bundleName = name.SubString(1, pos - 1); NString stringId = name.SubString(pos + 1); // Find if existed BundleMap::const_iterator iteBundle = bundleMap_.find(bundleName); if(iteBundle != bundleMap_.end()) { // existed const StringBundle& stringBundle = iteBundle->second; StringBundle::const_iterator iteString = stringBundle.find(stringId); if(iteString == stringBundle.end()) return NString::EmptyString; return iteString->second; } // Load Bundle Data NString bundlePath = nui::Util::File::CombinePath(basePath_, bundleName); bundlePath += _T(".xml"); NAutoPtr<NDataReader> reader = CreateDataReader(ReaderXml); if(!reader->ParseFile(bundlePath.GetData())) return NString::EmptyString; StringBundle tmpBundle; std::pair<BundleMap::iterator, bool> result = bundleMap_.insert(std::make_pair(bundleName, tmpBundle)); if(!result.second) return NString::EmptyString; StringBundle& bundleData = result.first->second; NString id; NString value; bool hasId = false; NAutoPtr<NDataReader> node; for(int i=0; reader->ReadNode(i, node); ++ i) { if(node->ReadValue(_T("id"), id) && node->ReadValue(_T("value"), value)) { if(id == stringId) hasId = true; bundleData.insert(std::make_pair(id, value)); } } if(hasId) return bundleData[stringId]; return NString::EmptyString; }
NAutoPtr<NBaseObj> NParserImpl::Parse(Ui::NFrame* parentFrame, LPCTSTR packFilePath) { NString filePath; NString styleName; if(!GetStyleParam(packFilePath, filePath, styleName)) return NULL; // Find Resource NInstPtr<NBuffer> buffer(MemToolParam); NInstPtr<NFileSystem> fs(MemToolParam); if(!fs->LoadFile(filePath.GetData(), buffer)) return NULL; // Load Xml NAutoPtr<NDataReader> reader = CreateDataReader(ReaderXml); if(!reader->ParseUtf8(static_cast<const char*>(buffer->GetBuffer()), buffer->GetSize())) return NULL; NAutoPtr<NDataReader> styleNode = FindStyleNode(reader, styleName); return ParserUtil::LoadObj(parentFrame, styleNode); }
void CControlTest::Test() { // create window window_.Create(MemToolParam); // window_->Create(NULL, WindowStyle::Layered); window_->Create(NULL, WindowStyle::Sizable); window_->SetSize(520, 420); window_->CenterWindow(NULL); window_->SetText(_T("Test Window")); window_->SetVisible(true); NInstPtr<NTimerSrv> timerSrv(MemToolParam); timerSrv->startTimer(100, MakeDelegate(this, &CControlTest::PaintTest)); // setup controls NResourceLoader* loader = NUiBus::Instance().GetResourceLoader(); NAutoPtr<NShapeDraw> pBkgDraw = loader->CreateShape(MemToolParam); pBkgDraw->SetStyle(NShapeDraw::Rect)->SetFillColor(MakeArgb(255, 255, 255, 0)); window_->GetRootFrame()->SetBkgDraw(pBkgDraw); //* // VertScroll NInstPtr<NScroll> pVertScroll(MemToolParam); pVertScroll->SetPos(100, 200); pVertScroll->SetSize(16, 200); pVertScroll->SetScrollRange(4); pVertScroll->SetScrollPos(3); window_->GetRootFrame()->AddChild(pVertScroll); // HorzScroll NInstPtr<NScroll> pHorzScroll(MemToolParam); pHorzScroll->SetPos(100, 180); pHorzScroll->SetSize(200, 16); pHorzScroll->SetScrollType(true); pHorzScroll->SetScrollRange(1); pHorzScroll->SetScrollPos(1); window_->GetRootFrame()->AddChild(pHorzScroll); // Button NInstPtr<NButton> pButton1(MemToolParam); pButton1->SetLayout(NFrame::LayoutHCenter | NFrame::LayoutTop); pButton1->SetMargin(10, 10, 20, 40); window_->GetRootFrame()->AddChild(pButton1); pButton1->SetClickCallback(MakeDelegate(this, &CControlTest::OnButtonClicked)); //*/ /* // Static Image NInstPtr<NImage> pImg1(MemToolParam); pImg1->LoadImage(_T("@skin:images\\514540469.png")); window_->GetRootFrame()->AddChild(pImg1); */ NInstPtr<NFrame> posLabel(MemToolParam); posLabel->SetPos(10, 100); posLabel->SetText(_T("Pos: ")); window_->GetRootFrame()->AddChild(posLabel); NInstPtr<NFrame> rangeLabel(MemToolParam); rangeLabel->SetPos(10, 130); rangeLabel->SetText(_T("Range: ")); window_->GetRootFrame()->AddChild(rangeLabel); NInstPtr<NEdit> pEdit1(MemToolParam); pEdit1->SetLayout(NFrame::LayoutLeft | NFrame::LayoutTop); pEdit1->SetMargin(60, 100, 0, 0); pEdit1->SetAutoSize(false); pEdit1->SetSize(100, 18); pEdit1->SetTextChangeCallback(MakeDelegate(this, &CControlTest::OnEditTextChanged)); window_->GetRootFrame()->AddChild(pEdit1); NInstPtr<NEdit> pEdit2(MemToolParam); pEdit2->SetLayout(NFrame::LayoutLeft | NFrame::LayoutTop); pEdit2->SetMargin(60, 130, 0, 0); pEdit2->SetAutoSize(false); pEdit2->SetSize(100, 18); pEdit2->SetTextChangeCallback(MakeDelegate(this, &CControlTest::OnEditTextChanged)); window_->GetRootFrame()->AddChild(pEdit2); // Gif Image for(int i=0; i<0; ++ i) { NInstPtr<NImage> pImg2(MemToolParam); pImg2->LoadImage(_T("@skin:images\\3.gif")); pImg2->SetPos(i * 10, i % 5 * 50); window_->GetRootFrame()->AddChild(pImg2); } // Label NInstPtr<NFrame> label(MemToolParam); label->SetText(_T("1111111111\r\n2222222222\r\n33333333333333\r\n444444444\r\n55555555555555555\r\n")); label->GetRichText()->SetSingleLine(false); window_->GetRootFrame()->AddChild(label); // loop nui::Ui::NMsgLoop loop; loop.Loop(window_->GetNative()); // destroy window_ = NULL; }