Permalink
Browse files

widget: Use QString internally.

Previously, some strings were stored in fixed length static arrays, and others were stored as pointers to the
original (uncopied) data.
  • Loading branch information...
1 parent 57b5b68 commit 84e3461ffcf4a2e2c5a64a3fb369ddfa330fa043 @Cyp committed Feb 11, 2013
View
@@ -58,7 +58,7 @@ W_BARGRAPH::W_BARGRAPH(W_BARINIT const *init)
, majorCol(init->sCol)
, minorCol(init->sMinorCol)
, textCol(WZCOL_BLACK)
- , pTip(init->pTip)
+ , pTip(QString::fromUtf8(init->pTip))
{
/* Set the display function */
if (display == NULL)
@@ -194,7 +194,7 @@ void widgSetMinorBarSize(W_SCREEN *psScreen, UDWORD id, UDWORD iValue)
/* Respond to a mouse moving over a barGraph */
void W_BARGRAPH::highlight(W_CONTEXT *psContext)
{
- if (pTip)
+ if (!pTip.isEmpty())
{
tipStart(this, pTip, psContext->psScreen->TipFontID,
psContext->psForm->aColours,
View
@@ -45,7 +45,7 @@ struct W_BARGRAPH : public WIDGET
PIELIGHT majorCol; // Colour for the major bar
PIELIGHT minorCol; // Colour for the minor bar
PIELIGHT textCol; // Colour for the text on the bar.
- const char *pTip; // The tool tip for the graph
+ QString pTip; // The tool tip for the graph
QString text; // Text on the bar.
};
View
@@ -46,8 +46,8 @@ W_BUTINIT::W_BUTINIT()
W_BUTTON::W_BUTTON(W_BUTINIT const *init)
: WIDGET(init, WIDG_BUTTON)
- , pText(init->pText)
- , pTip(init->pTip)
+ , pText(QString::fromUtf8(init->pText))
+ , pTip(QString::fromUtf8(init->pTip))
, HilightAudioID(WidgGetHilightAudioID())
, ClickedAudioID(WidgGetClickedAudioID())
, AudioCallback(WidgGetAudioCallback())
@@ -157,16 +157,15 @@ void W_BUTTON::setState(unsigned newState)
/* Run a button widget */
void W_BUTTON::run(W_CONTEXT *)
{
- W_BUTTON *psButton = this;
- if (psButton->state & WBUTS_FLASH)
+ if (state & WBUTS_FLASH)
{
if (((realTime / 250) % 2) == 0)
{
- psButton->state &= ~WBUTS_FLASHON;
+ state &= ~WBUTS_FLASHON;
}
else
{
- psButton->state |= WBUTS_FLASHON;
+ state |= WBUTS_FLASHON;
}
}
}
@@ -175,44 +174,42 @@ void W_BUTTON::run(W_CONTEXT *)
/* Respond to a mouse click */
void W_BUTTON::clicked(W_CONTEXT *, WIDGET_KEY key)
{
- W_BUTTON *psWidget = this;
/* Can't click a button if it is disabled or locked down */
- if (!(psWidget->state & (WBUTS_GREY | WBUTS_LOCKED)))
+ if (!(state & (WBUTS_GREY | WBUTS_LOCKED)))
{
// Check this is the correct key
- if ((!(psWidget->style & WBUT_NOPRIMARY) && key == WKEY_PRIMARY) ||
- ((psWidget->style & WBUT_SECONDARY) && key == WKEY_SECONDARY))
+ if ((!(style & WBUT_NOPRIMARY) && key == WKEY_PRIMARY) ||
+ ((style & WBUT_SECONDARY) && key == WKEY_SECONDARY))
{
- if (psWidget->AudioCallback)
+ if (AudioCallback)
{
- psWidget->AudioCallback(psWidget->ClickedAudioID);
+ AudioCallback(ClickedAudioID);
}
- psWidget->state &= ~WBUTS_FLASH; // Stop it flashing
- psWidget->state &= ~WBUTS_FLASHON;
- psWidget->state |= WBUTS_DOWN;
+ state &= ~WBUTS_FLASH; // Stop it flashing
+ state &= ~WBUTS_FLASHON;
+ state |= WBUTS_DOWN;
}
}
/* Kill the tip if there is one */
- if (psWidget->pTip)
+ if (!pTip.isEmpty())
{
- tipStop((WIDGET *)psWidget);
+ tipStop(this);
}
}
/* Respond to a mouse button up */
void W_BUTTON::released(W_CONTEXT *psContext, WIDGET_KEY key)
{
W_SCREEN *psScreen = psContext->psScreen;
- W_BUTTON *psWidget = this;
- if (psWidget->state & WBUTS_DOWN)
+ if (state & WBUTS_DOWN)
{
// Check this is the correct key
- if ((!(psWidget->style & WBUT_NOPRIMARY) && key == WKEY_PRIMARY) ||
- ((psWidget->style & WBUT_SECONDARY) && key == WKEY_SECONDARY))
+ if ((!(style & WBUT_NOPRIMARY) && key == WKEY_PRIMARY) ||
+ ((style & WBUT_SECONDARY) && key == WKEY_SECONDARY))
{
- widgSetReturn(psScreen, (WIDGET *)psWidget);
- psWidget->state &= ~WBUTS_DOWN;
+ widgSetReturn(psScreen, this);
+ state &= ~WBUTS_DOWN;
}
}
}
@@ -221,33 +218,31 @@ void W_BUTTON::released(W_CONTEXT *psContext, WIDGET_KEY key)
/* Respond to a mouse moving over a button */
void W_BUTTON::highlight(W_CONTEXT *psContext)
{
- W_BUTTON *psWidget = this;
- psWidget->state |= WBUTS_HILITE;
+ state |= WBUTS_HILITE;
- if (psWidget->AudioCallback)
+ if (AudioCallback)
{
- psWidget->AudioCallback(psWidget->HilightAudioID);
+ AudioCallback(HilightAudioID);
}
/* If there is a tip string start the tool tip */
- if (psWidget->pTip)
+ if (!pTip.isEmpty())
{
- tipStart((WIDGET *)psWidget, psWidget->pTip, psContext->psScreen->TipFontID,
- psContext->psForm->aColours,
- psWidget->x + psContext->xOffset, psWidget->y + psContext->yOffset,
- psWidget->width, psWidget->height);
+ tipStart(this, pTip, psContext->psScreen->TipFontID,
+ psContext->psForm->aColours,
+ x + psContext->xOffset, y + psContext->yOffset,
+ width, height);
}
}
/* Respond to the mouse moving off a button */
void W_BUTTON::highlightLost(W_CONTEXT *)
{
- W_BUTTON *psWidget = this;
- psWidget->state &= ~(WBUTS_DOWN | WBUTS_HILITE);
- if (psWidget->pTip)
+ state &= ~(WBUTS_DOWN | WBUTS_HILITE);
+ if (!pTip.isEmpty())
{
- tipStop((WIDGET *)psWidget);
+ tipStop(this);
}
}
@@ -271,16 +266,20 @@ void buttonDisplay(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *p
x1 = x0 + psButton->width;
y1 = y0 + psButton->height;
+ bool haveText = !psButton->pText.isEmpty();
+ QByteArray textBytes = psButton->pText.toUtf8();
+ char const *textData = textBytes.constData();
+
if (psButton->state & (WBUTS_DOWN | WBUTS_LOCKED | WBUTS_CLICKLOCK))
{
/* Display the button down */
iV_ShadowBox(x0, y0, x1, y1, 0, pColours[WCOL_LIGHT], pColours[WCOL_DARK], pColours[WCOL_BKGRND]);
- if (psButton->pText)
+ if (haveText)
{
iV_SetFont(psButton->FontID);
iV_SetTextColour(pColours[WCOL_TEXT]);
- fw = iV_GetTextWidth(psButton->pText);
+ fw = iV_GetTextWidth(textData);
if (psButton->style & WBUT_NOCLICKMOVE)
{
fx = x0 + (psButton->width - fw) / 2 + 1;
@@ -291,7 +290,7 @@ void buttonDisplay(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *p
fx = x0 + (psButton->width - fw) / 2;
fy = y0 + (psButton->height - iV_GetTextLineSize()) / 2 - iV_GetTextAboveBase();
}
- iV_DrawText(psButton->pText, fx, fy);
+ iV_DrawText(textData, fx, fy);
}
if (psButton->state & WBUTS_HILITE)
@@ -305,16 +304,16 @@ void buttonDisplay(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *p
/* Display the disabled button */
iV_ShadowBox(x0, y0, x1, y1, 0, pColours[WCOL_LIGHT], pColours[WCOL_LIGHT], pColours[WCOL_BKGRND]);
- if (psButton->pText)
+ if (haveText)
{
iV_SetFont(psButton->FontID);
- fw = iV_GetTextWidth(psButton->pText);
+ fw = iV_GetTextWidth(textData);
fx = x0 + (psButton->width - fw) / 2;
fy = y0 + (psButton->height - iV_GetTextLineSize()) / 2 - iV_GetTextAboveBase();
iV_SetTextColour(pColours[WCOL_LIGHT]);
- iV_DrawText(psButton->pText, fx + 1, fy + 1);
+ iV_DrawText(textData, fx + 1, fy + 1);
iV_SetTextColour(pColours[WCOL_DISABLE]);
- iV_DrawText(psButton->pText, fx, fy);
+ iV_DrawText(textData, fx, fy);
}
if (psButton->state & WBUTS_HILITE)
@@ -328,14 +327,14 @@ void buttonDisplay(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *p
/* Display the button up */
iV_ShadowBox(x0, y0, x1, y1, 0, pColours[WCOL_LIGHT], pColours[WCOL_DARK], pColours[WCOL_BKGRND]);
- if (psButton->pText)
+ if (haveText)
{
iV_SetFont(psButton->FontID);
iV_SetTextColour(pColours[WCOL_TEXT]);
- fw = iV_GetTextWidth(psButton->pText);
+ fw = iV_GetTextWidth(textData);
fx = x0 + (psButton->width - fw) / 2;
fy = y0 + (psButton->height - iV_GetTextLineSize()) / 2 - iV_GetTextAboveBase();
- iV_DrawText(psButton->pText, fx, fy);
+ iV_DrawText(textData, fx, fy);
}
if (psButton->state & WBUTS_HILITE)
View
@@ -54,8 +54,8 @@ struct W_BUTTON : public WIDGET
void setFlash(bool enable);
UDWORD state; // The current button state
- const char *pText; // The text for the button
- const char *pTip; // The tool tip for the button
+ QString pText; // The text for the button
+ QString pTip; // The tool tip for the button
SWORD HilightAudioID; // Audio ID for form clicked sound
SWORD ClickedAudioID; // Audio ID for form hilighted sound
WIDGET_AUDIOCALLBACK AudioCallback; // Pointer to audio callback function
View
@@ -129,7 +129,7 @@ static void formFreePlain(W_FORM *psWidget)
W_CLICKFORM::W_CLICKFORM(W_FORMINIT const *init)
: W_FORM(init)
, state(WCLICK_NORMAL)
- , pTip(init->pTip)
+ , pTip(QString::fromUtf8(init->pTip))
, HilightAudioID(WidgGetHilightAudioID())
, ClickedAudioID(WidgGetClickedAudioID())
, AudioCallback(WidgGetAudioCallback())
@@ -167,6 +167,17 @@ static void formFreeClickable(W_CLICKFORM *psWidget)
delete psWidget;
}
+W_MINORTAB::W_MINORTAB()
+ : psWidgets(NULL)
+{
+}
+
+
+W_MAJORTAB::W_MAJORTAB()
+ : lastMinor(0)
+ , numMinor(0)
+{
+}
W_TABFORM::W_TABFORM(W_FORMINIT const *init)
: W_FORM(init)
@@ -189,8 +200,6 @@ W_TABFORM::W_TABFORM(W_FORMINIT const *init)
, numButtons(init->numButtons)
, pTabDisplay(init->pTabDisplay)
{
- memset(asMajor, 0, sizeof(asMajor));
-
/* Allocate the memory for tool tips and copy them in */
/* Set up the tab data.
* All widget pointers have been zeroed by the memset above.
@@ -199,14 +208,14 @@ W_TABFORM::W_TABFORM(W_FORMINIT const *init)
for (unsigned major = 0; major < init->numMajor; ++major)
{
/* Check for a tip for the major tab */
- asMajor[major].pTip = init->apMajorTips[major];
+ asMajor[major].pTip = QString::fromUtf8(init->apMajorTips[major]);
asMajor[major].lastMinor = 0;
/* Check for tips for the minor tab */
asMajor[major].numMinor = init->aNumMinors[major];
for (unsigned minor = 0; minor < init->aNumMinors[major]; ++minor)
{
- asMajor[major].asMinor[minor].pTip = init->apMinorTips[major][minor];
+ asMajor[major].asMinor[minor].pTip = QString::fromUtf8(init->apMinorTips[major][minor]);
}
}
@@ -988,7 +997,7 @@ void W_TABFORM::run(W_CONTEXT *psContext)
{
// Got a new tab - start the tool tip if there is one.
tabHiLite = (UWORD)sTabPos.index;
- char *pTip;
+ QString pTip;
if (sTabPos.index >= numMajor)
{
pTip = asMajor[majorT].asMinor[sTabPos.index - numMajor].pTip;
@@ -997,7 +1006,7 @@ void W_TABFORM::run(W_CONTEXT *psContext)
{
pTip = asMajor[sTabPos.index].pTip;
}
- if (pTip)
+ if (!pTip.isEmpty())
{
// Got a tip - start it off.
tipStart(this, pTip, psContext->psScreen->TipFontID, aColours, sTabPos.x + psContext->xOffset, sTabPos.y + psContext->yOffset, sTabPos.width, sTabPos.height);
@@ -1123,7 +1132,7 @@ void W_CLICKFORM::highlight(W_CONTEXT *psContext)
state |= WCLICK_HILITE;
// If there is a tip string start the tool tip.
- if (pTip)
+ if (!pTip.isEmpty())
{
tipStart(this, pTip, psContext->psScreen->TipFontID, psContext->psForm->aColours, x + psContext->xOffset, y + psContext->yOffset, width, height);
}
View
@@ -47,19 +47,23 @@ struct W_FORM : public WIDGET
/* Information for a minor tab */
struct W_MINORTAB
{
+ W_MINORTAB();
+
/* Graphics data for the tab will go here */
WIDGET *psWidgets; // Widgets on the tab
- char *pTip; // Tool tip
+ QString pTip; // Tool tip
};
/* Information for a major tab */
struct W_MAJORTAB
{
+ W_MAJORTAB();
+
/* Graphics data for the tab will go here */
UWORD lastMinor; // Store which was the last selected minor tab
UWORD numMinor;
W_MINORTAB asMinor[WFORM_MAXMINOR]; // Minor tab information
- char *pTip;
+ QString pTip;
};
/* The tabbed form data structure */
@@ -124,7 +128,7 @@ struct W_CLICKFORM : public W_FORM
void setFlash(bool enable);
UDWORD state; // Button state of the form
- const char *pTip; // Tip for the form
+ QString pTip; // Tip for the form
SWORD HilightAudioID; // Audio ID for form clicked sound
SWORD ClickedAudioID; // Audio ID for form hilighted sound
WIDGET_AUDIOCALLBACK AudioCallback; // Pointer to audio callback function
Oops, something went wrong.

0 comments on commit 84e3461

Please sign in to comment.