// // Copyright 2005 The Android Open Source Project // // Simulated device data. // // For compilers that support precompilation, include "wx/wx.h". #include "wx/wxprec.h" // Otherwise, include all standard headers #ifndef WX_PRECOMP # include "wx/wx.h" #endif #include "wx/image.h" // needed for Windows build #include "PhoneData.h" #include "PhoneButton.h" #include "PhoneCollection.h" #include "MyApp.h" #include #include #include #include "tinyxml.h" #include #include #include #include #include using namespace android; /* image relative path hack */ static const char* kRelPathMagic = "::/"; /* * =========================================================================== * PhoneKeyboard * =========================================================================== */ /* * Load a chunk. */ bool PhoneKeyboard::ProcessAndValidate(TiXmlNode* pNode) { //TiXmlNode* pChild; TiXmlElement* pElem; int qwerty = 0; assert(pNode->Type() == TiXmlNode::ELEMENT); pElem = pNode->ToElement(); pElem->Attribute("qwerty", &qwerty); const char *kmap = pElem->Attribute("keycharmap"); if (qwerty == 1) { printf("############## PhoneKeyboard::ProcessAndValidate: qwerty = true!\n"); mQwerty = true; } if (kmap != NULL) { printf("############## PhoneKeyboard::ProcessAndValidate: keycharmap = %s\n", kmap); mKeyMap = strdup(kmap); } return true; } /* * =========================================================================== * PhoneDisplay * =========================================================================== */ /* * Load a chunk. */ bool PhoneDisplay::ProcessAndValidate(TiXmlNode* pNode) { //TiXmlNode* pChild; TiXmlElement* pElem; const char* name; const char* format; assert(pNode->Type() == TiXmlNode::ELEMENT); /* * Process attributes. Right now they're all mandatory, but some of * them could be defaulted (e.g. "rotate"). * * [We should do some range-checking here.] */ pElem = pNode->ToElement(); name = pElem->Attribute("name"); if (name == NULL) goto missing; if (pElem->Attribute("width", &mWidth) == NULL) goto missing; if (pElem->Attribute("height", &mHeight) == NULL) goto missing; if (pElem->Attribute("refresh", &mRefresh) == NULL) goto missing; format = pElem->Attribute("format"); if (format == NULL) goto missing; delete[] mName; mName = strdupNew(name); if (strcasecmp(format, "rgb565") == 0) { mFormat = android::PIXEL_FORMAT_RGB_565; } else { fprintf(stderr, "SimCFG: unexpected value for display format\n"); return false; } return true; missing: fprintf(stderr, "SimCFG: requires name/width/height/format/refresh\n"); return false; } /* * Returns "true" if the two displays are compatible, "false" if not. * * Compatibility means they have the same resolution, format, refresh * rate, and so on. Anything transmitted to the runtime as part of the * initial configuration setup should be tested. */ /*static*/ bool PhoneDisplay::IsCompatible(PhoneDisplay* pDisplay1, PhoneDisplay* pDisplay2) { return (pDisplay1->mWidth == pDisplay2->mWidth && pDisplay1->mHeight == pDisplay2->mHeight && pDisplay1->mFormat == pDisplay2->mFormat && pDisplay1->mRefresh == pDisplay2->mRefresh); } /* * =========================================================================== * PhoneView * =========================================================================== */ /* * Load a chunk. */ bool PhoneView::ProcessAndValidate(TiXmlNode* pNode, const char* directory) { TiXmlNode* pChild; TiXmlElement* pElem; int rotate; const char* displayName; assert(pNode->Type() == TiXmlNode::ELEMENT); /* * Process attributes. Right now they're all mandatory, but some of * them could be defaulted (e.g. "rotate"). * * [We should do some range-checking here.] */ pElem = pNode->ToElement(); displayName = pElem->Attribute("display"); if (displayName == NULL) goto missing; if (pElem->Attribute("x", &mXOffset) == NULL) goto missing; if (pElem->Attribute("y", &mYOffset) == NULL) goto missing; if (pElem->Attribute("rotate", &rotate) == NULL) goto missing; switch (rotate) { case 0: mRotation = kRot0; break; case 90: mRotation = kRot90; break; case 180: mRotation = kRot180; break; case 270: mRotation = kRot270; break; default: fprintf(stderr, "SimCFG: unexpected value for rotation\n"); mRotation = kRotUnknown; return false; } delete[] mDisplayName; mDisplayName = android::strdupNew(displayName); /* * Process elements. */ for (pChild = pNode->FirstChild(); pChild != NULL; pChild = pChild->NextSibling()) { if (pChild->Type() == TiXmlNode::COMMENT) continue; if (pChild->Type() == TiXmlNode::ELEMENT) { if (strcasecmp(pChild->Value(), "image") == 0) { if (!ProcessImage(pChild, directory)) return false; } else if (strcasecmp(pChild->Value(), "button") == 0) { if (!ProcessButton(pChild, directory)) return false; } else { fprintf(stderr, "SimCFG: Warning: unexpected elements in \n"); } } else { fprintf(stderr, "SimCFG: Warning: unexpected stuff in \n"); } } return true; missing: fprintf(stderr, "SimCFG: requires display/x/y/rotate\n"); return false; } /* * Handle . */ bool PhoneView::ProcessImage(TiXmlNode* pNode, const char* directory) { TiXmlNode* pChild; TiXmlElement* pElem; int x, y; const char* src; LoadableImage tmpLimg; android::String8 fileName; pChild = pNode->FirstChild(); if (pChild != NULL) { fprintf(stderr, "SimCFG: is funky\n"); return false; } /* * All attributes are mandatory. */ pElem = pNode->ToElement(); src = pElem->Attribute("src"); if (src == NULL) goto missing; if (pElem->Attribute("x", &x) == NULL) goto missing; if (pElem->Attribute("y", &y) == NULL) goto missing; if (strncmp(src, kRelPathMagic, strlen(kRelPathMagic)) == 0) { fileName = src + strlen(kRelPathMagic); } else { fileName = directory; fileName += "/"; fileName += src; } tmpLimg.Create(fileName, x, y); mImageList.push_back(tmpLimg); return true; missing: fprintf(stderr, "SimCFG: requires src/x/y\n"); return false; } /* * Handle