From: Andy D. <kha...@us...> - 2004-01-10 23:47:46
|
Update of /cvsroot/planeshift/planeshift/src/client/gui In directory sc8-pr-cvs1:/tmp/cvs-serv14701/src/client/gui Added Files: pawshelp.cpp pawshelp.h Log Message: Implemented help system, read from data/help.xml and displayed with F1. --- NEW FILE: pawshelp.cpp --- /* * pawsSplashWindow.cpp - Author: Andrew Craig * * Copyright (C) 2003 PlaneShift Team (in...@pl..., * http://www.planeshift.it) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 of the License) * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include <config.h> #include "pawshelp.h" #include "paws/pawsmanager.h" pawsHelp::pawsHelp( PawsManager* manager ) :pawsWidget( manager ) { vfs = CS_QUERY_REGISTRY( windowManager->GetObjectRegistry(), iVFS ); xml = csPtr<iDocumentSystem>(new csTinyDocumentSystem); helpDoc = xml->CreateDocument(); csRef<iDataBuffer> buf (vfs->ReadFile ("/this/data/help.xml")); if (!buf || !buf->GetSize ()) { printf("ERROR: Loading 'data/help.xml'"); return; } const char* error = helpDoc->Parse( buf ); if ( error ) { printf("ERROR: Invalid 'data/help.xml': %s\n", error); return ; } } bool pawsHelp::PostSetup(void) { helpText = dynamic_cast<pawsMessageTextBox*>(FindWidget("HelpText")); if (!helpText) return false; // creates tree: helpTree = (pawsSimpleTree*) (windowManager->CreateWidget("pawsSimpleTree")); if (helpTree == NULL) { Error1("Could not create widget pawsSimpleTree"); return false; } AddChild(helpTree); helpTree->SetRelativeFrame(0,0,170,245); helpTree->SetNotify(this); helpTree->SetScrollBars(false, true); helpTree->UseBorder("line"); helpTree->InsertChildL("", "RootTopic", "", ""); helpTree->SetAttachFlags(ATTACH_TOP | ATTACH_BOTTOM); LoadHelps(helpDoc->GetRoot()->GetNode("help"), "RootTopic"); pawsTreeNode * child = helpTree->GetRoot()->GetFirstChild(); while (child != NULL) { child->CollapseAll(); child = child->GetNextSibling(); } return true; } void pawsHelp::LoadHelps(iDocumentNode *node, csString parent) { csRef<iDocumentNodeIterator> helpIter = node->GetNodes(); while(helpIter->HasNext()) { csRef<iDocumentNode> topicName = helpIter->Next(); if (!strcmp(topicName->GetValue(), "branch")) helpTree->InsertChildL(parent, topicName->GetAttributeValue("name"), topicName->GetAttributeValue("name"), ""); else if (!strcmp(topicName->GetValue(), "topic")) { helpTree->InsertChildL(parent, topicName->GetAttributeValue("name"), topicName->GetAttributeValue("name"), ""); continue; } else continue; // Load children LoadHelps(topicName, topicName->GetAttributeValue("name")); } } bool pawsHelp::OnSelected(pawsWidget *widget) { helpText->Clear(); pawsTreeNode* node = dynamic_cast<pawsTreeNode*> (widget); csRef<iDocumentNode> root = helpDoc->GetRoot()->GetNode("help"); // xmlnode contains the root root->IncRef(); csRef<iDocumentNode> xmlnode = RetrieveHelp(node,root); if (!xmlnode) return false; csRef<iDocumentNodeIterator> iter = xmlnode->GetNodes(); while(iter->HasNext()) { csRef<iDocumentNode> text = iter->Next(); if (strcmp(text->GetValue(),"P") && strcmp(text->GetValue(),"topic")) helpText->AddMessage(text->GetValue()); } return true; } iDocumentNode* pawsHelp::RetrieveHelp(pawsTreeNode* node, iDocumentNode* helpRoot) { if(node->GetName().Compare("RootTopic")) return helpRoot; csRef<iDocumentNode> parentnode = RetrieveHelp(node->GetParent(),helpRoot); parentnode->DecRef(); csRef<iDocumentNodeIterator> iter = parentnode->GetNodes(); while (iter->HasNext()) { csRef<iDocumentNode> xmlnode = iter->Next(); if (node->GetName().Compare(xmlnode->GetAttributeValue("name"))) { xmlnode->IncRef(); return xmlnode; } } return NULL; } pawsHelp::~pawsHelp() { } --- NEW FILE: pawshelp.h --- /* * pawshelp.h - Author: Andrew Dai * * Copyright (C) 2003 PlaneShift Team (in...@pl..., * http://www.planeshift.it) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 of the License) * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef PAWS_HELP_WINDOW_HEADER #define PAWS_HELP_WINDOW_HEADER #include <csutil/xmltiny.h> #include <csutil/csstring.h> #include <csutil/refcount.h> #include "paws/pawswidget.h" #include "paws/pawstree.h" #include "util/binarytree.h" class pawsProgressBar; class pawsHelp : public pawsWidget { public: pawsHelp( PawsManager* manager ); ~pawsHelp(); bool PostSetup(); bool OnSelected(pawsWidget* widget); protected: void LoadHelps(iDocumentNode* node, csString parent); iDocumentNode* RetrieveHelp(pawsTreeNode* node, iDocumentNode* helpRoot); csRef<iVFS> vfs; csRef<iDocumentSystem> xml; csRef<iDocument> helpDoc; //BinaryTree<csString> helpIndex; pawsSimpleTree* helpTree; pawsMessageTextBox* helpText; }; CREATE_PAWS_FACTORY( pawsHelp ); #endif |