#include <string>
#include <stdlib.h>
#include <objgfx40.h>
#include <vContext.h>
#include <sStyle.h>
#include <sTypes.h>
vContext::vContext(vContext * parent) {
pContext = parent;
realView = new ogSurface();
curX = curY = width = height = 0;
attached = false;
return;
} // vContext::vContext
vContext *
vContext::vAttach(vContext * context) {
/*
* vContext::vAttach()
* Accepts a vContext as a parameter and attaches it to the
* current child context list.
* Returns the child context pointer
*/
cContexts.push_back(context);
return context;
} // vContext::vAttach
bool
vContext::vDeleteStyle(const std::string styleKey) {
/*
* vContext::vDeleteStyle()
* returns true if style existed and was deleted
* returns false if style didn't exist (or wasn't deleted)
*/
sStyle * tmpStyle = styles[styleKey];
styles.erase(styleKey);
delete tmpStyle;
return (tmpStyle != NULL);
} // vContext::vDeleteStyle
vContext *
vContext::vDetach(vContext * context) {
cContexts.remove(context);
return context;
} // vContext::vDetach
/*
* void
* vContext::Draw(void) {
* return;
* } // vContext::Draw
*/
sStyle *
vContext::vGetStyle(const std::string styleKey) {
/*
* GetStyle()
* retreives a style out of the style map using the styleKey string
* If no style is present in this node, check the parent
*/
sStyle * tmpStyle = styles[styleKey];
if ((tmpStyle == NULL) && (pContext != NULL)) {
return pContext->vGetStyle(styleKey);
} // if
return tmpStyle;
} // vContext::vGetStyle
void
vContext::vSetPos(int32 newX, int32 newY) {
/*
* vContext::SetPos()
* Sets new position relative to parent's upper left corner
*/
// I really should detach from the parent here
if (pContext != NULL) pContext->vDetach(this);
curX = newX;
curY = newY;
// and reattach to parent here
if (pContext != NULL) pContext->vAttach(this);
return;
} // vContext::vSetPos
void
vContext::vSetSize(uInt32 newWidth, uInt32 newHeight) {
width = newWidth;
height = newHeight;
} // vContext::vSetSize
void
vContext::vSetStyle(const std::string styleKey, sStyle * style) {
// I probably should check to see if a style exists before setting it
// if the style is null, then just exit out without setting it
if (style == NULL) return;
// set the new style
styles[styleKey] = style;
} // vContext::vSetStyle
vContext::~vContext(void) {
delete realView;
pContext = NULL;
curX = curY = width = height = 0;
return;
} // vContext::~vContext