Skip to content

Commit 4340e87

Browse files
author
Fraser J. Gordon
committed
Plumb things in enough to get list field colours correct
1 parent 7842074 commit 4340e87

File tree

11 files changed

+437
-25
lines changed

11 files changed

+437
-25
lines changed

engine/src/block.cpp

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,8 +1099,7 @@ void MCBlock::draw(MCDC *dc, coord_t x, coord_t cx, int2 y, uint2 si, uint2 ei,
10991099
if (flags & F_HAS_BACK_COLOR)
11001100
dc->setbackground(*atts->backcolor);
11011101

1102-
if (t_foreground_color != NULL)
1103-
dc -> setforeground(*t_foreground_color);
1102+
setcolorfornormaltext(dc, t_foreground_color);
11041103

11051104
uint32_t t_style;
11061105
t_style = 0;
@@ -1188,11 +1187,13 @@ void MCBlock::draw(MCDC *dc, coord_t x, coord_t cx, int2 y, uint2 si, uint2 ei,
11881187
f->getforecolor(DI_HILITE, False, True, hc, t_pattern, x, y, dc, f);
11891188
if (hc.pixel == fc.pixel)
11901189
f->setforeground(dc, DI_BACK, False, True);
1190+
else
1191+
setcolorforselectedtext(dc, nil);
11911192
}
11921193
else
1193-
f->setforeground(dc, DI_BACK, False, True);
1194+
setcolorforselectedtext(dc, t_foreground_color);
11941195
}
1195-
1196+
11961197
// Draw the selected text.
11971198
drawstring(dc, x, cx, y, index, size, (flags & F_HAS_BACK_COLOR) != 0, t_style);
11981199

@@ -2356,3 +2357,35 @@ bool MCBlock::imagechanged(MCImage *p_image, bool p_deleting)
23562357
return false;
23572358
}
23582359

2360+
void MCBlock::setcolorfornormaltext(MCDC* dc, MCColor* p_color)
2361+
{
2362+
MCField* f = parent->getparent();
2363+
2364+
if (p_color != nil)
2365+
dc->setforeground(*p_color);
2366+
else if (flags & F_HAS_COLOR)
2367+
dc->setforeground(*atts -> color);
2368+
else
2369+
f->setforeground(dc, DI_FORE, False, True);
2370+
}
2371+
2372+
void MCBlock::setcolorforhilite(MCDC* dc)
2373+
{
2374+
MCField* f = parent->getparent();
2375+
2376+
f->setforeground(dc, DI_HILITE, False, True);
2377+
}
2378+
2379+
void MCBlock::setcolorforselectedtext(MCDC* dc, MCColor* p_color)
2380+
{
2381+
MCField* f = parent->getparent();
2382+
2383+
if (p_color != nil)
2384+
dc->setforeground(*p_color);
2385+
else if (flags & F_HAS_COLOR)
2386+
dc->setforeground(*atts -> color);
2387+
else if (!IsMacLF()) // TODO: if platform reverses selected text
2388+
f->setforeground(dc, DI_BACK, False, True, true);
2389+
else
2390+
f->setforeground(dc, DI_FORE, False, True, true);
2391+
}

engine/src/block.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,5 +295,11 @@ class MCBlock : public MCDLlist
295295
MCBlock *advanceindex(uint2& p_index);
296296

297297
bool imagechanged(MCImage *p_image, bool p_deleting);
298+
299+
// FG-2014-11-11: [[ Better theming ]]
300+
// Sets up the colours on the DC for the given type of drawing
301+
void setcolorfornormaltext(MCDC*, MCColor*);
302+
void setcolorforhilite(MCDC*);
303+
void setcolorforselectedtext(MCDC*, MCColor*);
298304
};
299305
#endif

engine/src/button.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4733,3 +4733,58 @@ IO_stat MCButton::load(IO_handle stream, const char *version)
47334733
}
47344734
return IO_NORMAL;
47354735
}
4736+
4737+
////////////////////////////////////////////////////////////////////////////////
4738+
4739+
MCPlatformControlType MCButton::getcontroltype()
4740+
{
4741+
MCPlatformControlType t_type;
4742+
t_type = kMCPlatformControlTypeButton;
4743+
if (getstyleint(flags) == F_MENU)
4744+
{
4745+
t_type = kMCPlatformControlTypeMenu;
4746+
switch (menumode)
4747+
{
4748+
case WM_POPUP:
4749+
t_type = kMCPlatformControlTypePopupMenu;
4750+
break;
4751+
4752+
case WM_OPTION:
4753+
t_type = kMCPlatformControlTypeOptionMenu;
4754+
break;
4755+
4756+
case WM_COMBO:
4757+
t_type = kMCPlatformControlTypeComboBox;
4758+
break;
4759+
4760+
case WM_PULLDOWN:
4761+
t_type = kMCPlatformControlTypePulldownMenu;
4762+
break;
4763+
4764+
default:
4765+
break;
4766+
}
4767+
}
4768+
4769+
return t_type;
4770+
}
4771+
4772+
MCPlatformControlPart MCButton::getcontrolsubpart()
4773+
{
4774+
return kMCPlatformControlPartNone;
4775+
}
4776+
4777+
MCPlatformControlState MCButton::getcontrolstate()
4778+
{
4779+
int t_state;
4780+
t_state = MCControl::getcontrolstate();
4781+
4782+
if (flags & F_DEFAULT)
4783+
t_state |= kMCPlatformControlStateDefault;
4784+
4785+
if (t_state & kMCPlatformControlStateMouseFocus
4786+
&& MCbuttonstate & 1)
4787+
t_state |= kMCPlatformControlStatePressed;
4788+
4789+
return MCPlatformControlState(t_state);
4790+
}

engine/src/button.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,5 +362,12 @@ class MCButton : public MCControl
362362
void trytochangetonative(void);
363363

364364
friend class ButtonMenuCallback;
365+
366+
protected:
367+
368+
// FG-2014-11-11: [[ Better theming ]] Fetch the control type/state for theming purposes
369+
virtual MCPlatformControlType getcontroltype();
370+
virtual MCPlatformControlPart getcontrolsubpart();
371+
virtual MCPlatformControlState getcontrolstate();
365372
};
366373
#endif

engine/src/dispatch.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,31 +137,31 @@ Exec_stat MCDispatch::getprop(uint4 parid, Properties which, MCExecPoint &ep, Bo
137137
{
138138
#ifdef /* MCDispatch::getprop */ LEGACY_EXEC
139139
case P_BACK_PIXEL:
140-
ep.setint(MCscreen->background_pixel.pixel & 0xFFFFFF);
141-
return ES_NORMAL;
140+
//ep.setint(MCscreen->background_pixel.pixel & 0xFFFFFF);
141+
return ES_NOT_HANDLED;
142142
case P_TOP_PIXEL:
143-
ep.setint(MCscreen->white_pixel.pixel & 0xFFFFFF);
144-
return ES_NORMAL;
143+
//ep.setint(MCscreen->white_pixel.pixel & 0xFFFFFF);
144+
return ES_NOT_HANDLED;
145145
case P_HILITE_PIXEL:
146146
case P_FORE_PIXEL:
147147
case P_BORDER_PIXEL:
148148
case P_BOTTOM_PIXEL:
149149
case P_SHADOW_PIXEL:
150150
case P_FOCUS_PIXEL:
151-
ep.setint(MCscreen->black_pixel.pixel & 0xFFFFFF);
152-
return ES_NORMAL;
151+
//ep.setint(MCscreen->black_pixel.pixel & 0xFFFFFF);
152+
return ES_NOT_HANDLED;
153153
case P_BACK_COLOR:
154154
case P_HILITE_COLOR:
155-
ep.setstaticcstring("white");
156-
return ES_NORMAL;
155+
//ep.setstaticcstring("white");
156+
return ES_NOT_HANDLED;
157157
case P_FORE_COLOR:
158158
case P_BORDER_COLOR:
159159
case P_TOP_COLOR:
160160
case P_BOTTOM_COLOR:
161161
case P_SHADOW_COLOR:
162162
case P_FOCUS_COLOR:
163-
ep.setstaticcstring("black");
164-
return ES_NORMAL;
163+
//ep.setstaticcstring("black");
164+
return ES_NOT_HANDLED;
165165
case P_FORE_PATTERN:
166166
case P_BACK_PATTERN:
167167
case P_HILITE_PATTERN:

engine/src/field.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3233,4 +3233,30 @@ bool MCField::imagechanged(MCImage *p_image, bool p_deleting)
32333233
}
32343234

32353235
return t_used;
3236-
}
3236+
}
3237+
3238+
////////////////////////////////////////////////////////////////////////////////
3239+
3240+
MCPlatformControlType MCField::getcontroltype()
3241+
{
3242+
MCPlatformControlType t_type;
3243+
t_type = kMCPlatformControlTypeInputField;
3244+
3245+
if (flags & F_LIST_BEHAVIOR)
3246+
t_type = kMCPlatformControlTypeList;
3247+
3248+
return t_type;
3249+
}
3250+
3251+
MCPlatformControlPart MCField::getcontrolsubpart()
3252+
{
3253+
return kMCPlatformControlPartNone;
3254+
}
3255+
3256+
MCPlatformControlState MCField::getcontrolstate()
3257+
{
3258+
int t_state;
3259+
t_state = MCControl::getcontrolstate();
3260+
3261+
return MCPlatformControlState(t_state);
3262+
}

engine/src/field.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,5 +549,12 @@ class MCField : public MCControl
549549
bool imagechanged(MCImage *p_image, bool p_deleting);
550550

551551
MCRectangle firstRectForCharacterRange(int32_t& si, int32_t& ei);
552+
553+
protected:
554+
555+
// FG-2014-11-11: [[ Better theming ]] Fetch the control type/state for theming purposes
556+
virtual MCPlatformControlType getcontroltype();
557+
virtual MCPlatformControlPart getcontrolsubpart();
558+
virtual MCPlatformControlState getcontrolstate();
552559
};
553560
#endif

engine/src/object.cpp

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ Boolean MCObject::resizeparent()
12201220

12211221
Boolean MCObject::getforecolor(uint2 di, Boolean rev, Boolean hilite,
12221222
MCColor &c, MCPatternRef &r_pattern,
1223-
int2 &x, int2 &y, MCDC *dc, MCObject *o)
1223+
int2 &x, int2 &y, MCDC *dc, MCObject *o, bool selected)
12241224
{
12251225
uint2 i;
12261226
if (dc->getdepth() > 1)
@@ -1259,14 +1259,65 @@ Boolean MCObject::getforecolor(uint2 di, Boolean rev, Boolean hilite,
12591259
if (di == DI_BACK)
12601260
c = dc->getwhite();
12611261
else
1262-
parent->getforecolor(di, rev, False, c, r_pattern, x, y, dc, o);
1262+
parent->getforecolor(di, rev, hilite, c, r_pattern, x, y, dc, o, selected);
12631263
return True;
12641264
}
12651265
if (parent && parent != MCdispatcher)
1266-
return parent->getforecolor(di, rev, False, c, r_pattern, x, y, dc, o);
1266+
return parent->getforecolor(di, rev, hilite, c, r_pattern, x, y, dc, o, selected);
12671267
}
12681268
}
12691269

1270+
// Try to get the colour from the system theme rather than these hard-coded values
1271+
MCPlatformControlType t_control_type;
1272+
MCPlatformControlPart t_control_part;
1273+
MCPlatformControlState t_control_state;
1274+
MCPlatformThemeProperty t_theme_prop;
1275+
MCPlatformThemePropertyType t_theme_prop_type;
1276+
Properties which;
1277+
switch (di)
1278+
{
1279+
case DI_TOP:
1280+
which = P_TOP_COLOR;
1281+
break;
1282+
1283+
case DI_BOTTOM:
1284+
which = P_BOTTOM_COLOR;
1285+
break;
1286+
1287+
case DI_FORE:
1288+
which = P_FORE_COLOR;
1289+
break;
1290+
1291+
case DI_BACK:
1292+
which = P_BACK_COLOR;
1293+
break;
1294+
1295+
case DI_HILITE:
1296+
which = P_HILITE_COLOR;
1297+
break;
1298+
1299+
case DI_FOCUS:
1300+
which = P_FOCUS_COLOR;
1301+
break;
1302+
1303+
case DI_BORDER:
1304+
which = P_BORDER_COLOR;
1305+
break;
1306+
1307+
case DI_SHADOW:
1308+
which = P_SHADOW_COLOR;
1309+
break;
1310+
1311+
}
1312+
if (o->getthemeselectorsforprop(which, t_control_type, t_control_part, t_control_state, t_theme_prop, t_theme_prop_type))
1313+
{
1314+
if (selected)
1315+
t_control_state |= kMCPlatformControlStateSelected;
1316+
1317+
if (MCPlatformGetControlThemePropColor(t_control_type, t_control_part, t_control_state, t_theme_prop, c))
1318+
return True;
1319+
}
1320+
12701321
switch (di)
12711322
{
12721323

@@ -1312,7 +1363,7 @@ Boolean MCObject::getforecolor(uint2 di, Boolean rev, Boolean hilite,
13121363
return True;
13131364
}
13141365

1315-
void MCObject::setforeground(MCDC *dc, uint2 di, Boolean rev, Boolean hilite)
1366+
void MCObject::setforeground(MCDC *dc, uint2 di, Boolean rev, Boolean hilite, bool selected)
13161367
{
13171368
uint2 idi = di;
13181369
if (rev)
@@ -1337,7 +1388,7 @@ void MCObject::setforeground(MCDC *dc, uint2 di, Boolean rev, Boolean hilite)
13371388
MCColor color;
13381389
MCPatternRef t_pattern = nil;
13391390
int2 x, y;
1340-
if (getforecolor(idi, rev, hilite, color, t_pattern, x, y, dc, this))
1391+
if (getforecolor(idi, rev, hilite, color, t_pattern, x, y, dc, this, selected))
13411392
{
13421393
MCColor fcolor;
13431394
if (dc->getdepth() == 1 && di != DI_BACK
@@ -4306,6 +4357,8 @@ void MCObject::mapfont(void)
43064357
// This should never happen as the only object with nil parent when
43074358
// opened should be MCdispatcher, which always has font attrs.
43084359
assert(false);
4360+
4361+
// TODO: font theming
43094362
}
43104363

43114364
// MW-2012-03-02: [[ Bug 10044 ]] If we had to temporarily map the parent's font

engine/src/object.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
2929
#endif
3030

3131
#include "globals.h"
32+
#include "platform.h"
3233

3334
enum {
3435
MAC_SHADOW,
@@ -486,8 +487,8 @@ class MCObject : public MCDLlist
486487
Boolean isvisible();
487488
Boolean resizeparent();
488489
Boolean getforecolor(uint2 di, Boolean reversed, Boolean hilite, MCColor &c,
489-
MCPatternRef &r_pattern, int2 &x, int2 &y, MCDC *dc, MCObject *o);
490-
void setforeground(MCDC *dc, uint2 di, Boolean rev, Boolean hilite = False);
490+
MCPatternRef &r_pattern, int2 &x, int2 &y, MCDC *dc, MCObject *o, bool selected = false);
491+
void setforeground(MCDC *dc, uint2 di, Boolean rev, Boolean hilite = False, bool selected = false);
491492
Boolean setcolor(uint2 index, const MCString &eptr);
492493
Boolean setcolors(const MCString &data);
493494
Boolean setpattern(uint2 newpixmap, const MCString &);
@@ -725,6 +726,12 @@ class MCObject : public MCDLlist
725726
// MW-2014-09-30: [[ ScriptStack ]] Used by MCStack::setasscriptonly.
726727
Exec_stat setscriptprop(MCExecPoint& ep);
727728

729+
// FG-2014-11-11: [[ Better theming ]] Fetch the control type/state for theming purposes
730+
virtual MCPlatformControlType getcontroltype();
731+
virtual MCPlatformControlPart getcontrolsubpart();
732+
virtual MCPlatformControlState getcontrolstate();
733+
bool getthemeselectorsforprop(Properties, MCPlatformControlType&, MCPlatformControlPart&, MCPlatformControlState&, MCPlatformThemeProperty&, MCPlatformThemePropertyType&);
734+
728735
private:
729736
Exec_stat getrectprop(Properties which, MCExecPoint& ep, Boolean effective);
730737

0 commit comments

Comments
 (0)