Skip to content

Commit cb84b2d

Browse files
author
Fraser J. Gordon
committed
Merge branch 'feature-better-text' of https://github.com/runrevfraser/livecode into widgets-plumbing
Conflicts: engine/Makefile.kernel engine/engine.xcodeproj/project.pbxproj engine/src/linux.stubs
2 parents 9d5884e + 69890f1 commit cb84b2d

File tree

105 files changed

+5740
-286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+5740
-286
lines changed

engine/Makefile.kernel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ SOURCES=\
7979
foundation-legacy.cpp legacy_spec.cpp \
8080
sysunxthreads.cpp, stacktile.cpp \
8181
native-layer.cpp native-layer-x11.cpp \
82-
widget.cpp widget-events.cpp
82+
widget.cpp widget-events.cpp \
83+
linux-theme.cpp
8384

8485
linuxstubs.cpp: src/linux.stubs ../util/weak_stub_maker.pl
8586
# ../prebuilt/bin/Revolution.lnx "../tools/weak_stub_maker.lc" <./src/linux.stubs >./src/linuxstubs.cpp

engine/engine.xcodeproj/project.pbxproj

Lines changed: 132 additions & 2 deletions
Large diffs are not rendered by default.

engine/kernel.vcproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3551,6 +3551,10 @@
35513551
RelativePath="src\w32transfer.h"
35523552
>
35533553
</File>
3554+
<File
3555+
RelativePath=".\src\windows-theme.cpp"
3556+
>
3557+
</File>
35543558
</Filter>
35553559
</Filter>
35563560
<Filter

engine/src/MCBlock.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ class MCBlock : public MCDLlist
171171
void reset();
172172
uint2 getascent(void);
173173
uint2 getdescent(void);
174+
coord_t GetAscent() const;
175+
coord_t GetDescent() const;
176+
coord_t GetLeading() const;
174177
void freeatts();
175178
void freerefs();
176179
void openimage();
@@ -412,5 +415,11 @@ class MCBlock : public MCDLlist
412415
void SetTextStyleElement(MCExecContext& ctxt, MCNameRef p_index, bool p_value);
413416

414417
//////////
418+
419+
// FG-2014-11-11: [[ Better theming ]]
420+
// Sets up the colours on the DC for the given type of drawing
421+
void setcolorfornormaltext(MCDC*, MCColor*);
422+
void setcolorforhilite(MCDC*);
423+
void setcolorforselectedtext(MCDC*, MCColor*);
415424
};
416425
#endif

engine/src/aclip.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,9 @@ void MCAudioClip::timer(MCNameRef mptr, MCParameter *params)
202202
delete this;
203203
}
204204
}
205-
#ifdef LEGACY_EXEC
206-
Exec_stat MCAudioClip::getprop_legacy(uint4 parid, Properties which, MCExecPoint &ep, Boolean effective)
205+
206+
#ifdef LEGACY_EXEC
207+
Exec_stat MCAudioClip::getprop_legacy(uint4 parid, Properties which, MCExecPoint &ep, Boolean effective, bool recursive)
207208
{
208209
switch (which)
209210
{
@@ -223,7 +224,7 @@ Exec_stat MCAudioClip::getprop_legacy(uint4 parid, Properties which, MCExecPoint
223224
break;
224225
#endif /* MCAudioClip::getprop */
225226
default:
226-
return MCObject::getprop_legacy(parid, which, ep, effective);
227+
return MCObject::getprop_legacy(parid, which, ep, effective, recursive);
227228
}
228229
return ES_NORMAL;
229230
}

engine/src/aclip.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@ class MCAudioClip : public MCObject
8080
virtual void timer(MCNameRef mptr, MCParameter *params);
8181

8282
#ifdef LEGACY_EXEC
83-
virtual Exec_stat getprop_legacy(uint4 parid, Properties which, MCExecPoint &, Boolean effective);
83+
virtual Exec_stat getprop_legacy(uint4 parid, Properties which, MCExecPoint &, Boolean effective, bool recursive = false);
8484
virtual Exec_stat setprop_legacy(uint4 parid, Properties which, MCExecPoint &, Boolean effective);
8585
#endif
8686

87-
8887
virtual Boolean del();
8988
virtual void paste(void);
9089

engine/src/block.cpp

Lines changed: 95 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -950,9 +950,15 @@ void MCBlock::split(findex_t p_index)
950950
void MCBlock::drawstring(MCDC *dc, coord_t x, coord_t p_cell_left, coord_t p_cell_right, int2 y, findex_t start, findex_t length, Boolean image, uint32_t style)
951951
{
952952
// MW-2012-02-16: [[ FontRefs ]] Fetch the font metrics we need to draw.
953-
int32_t t_ascent, t_descent;
953+
coord_t t_ascent, t_descent, t_leading, t_xheight;
954954
t_ascent = MCFontGetAscent(m_font);
955955
t_descent = MCFontGetDescent(m_font);
956+
t_leading = MCFontGetLeading(m_font);
957+
t_xheight = MCFontGetXHeight(m_font);
958+
959+
// Width for strike-through/underline lines. Factor is arbitrary...
960+
coord_t t_strikewidth;
961+
t_strikewidth = ceilf(MCFontGetAscent(m_font)/16);
956962

957963
// MW-2012-01-25: [[ ParaStyles ]] Fetch the vGrid setting from the owning paragraph.
958964
if (parent -> getvgrid())
@@ -1011,9 +1017,17 @@ void MCBlock::drawstring(MCDC *dc, coord_t x, coord_t p_cell_left, coord_t p_cel
10111017
if (t_next_index - t_index > 0)
10121018
{
10131019
if ((style & FA_UNDERLINE) != 0)
1014-
dc -> drawline(x, y + 1, x + t_width, y + 1);
1020+
{
1021+
MCRectangle t_underlinerect;
1022+
t_underlinerect = MCU_make_rect(x, y + t_strikewidth, t_width, t_strikewidth);
1023+
dc -> fillrect(t_underlinerect);
1024+
}
10151025
if ((style & FA_STRIKEOUT) != 0)
1016-
dc -> drawline(x, y - (t_ascent >> 1), x + t_width, y - (t_ascent >> 1));
1026+
{
1027+
MCRectangle t_strikerect;
1028+
t_strikerect = MCU_make_rect(x, y - (t_xheight / 2) - (t_strikewidth / 2), t_width, t_strikewidth);
1029+
dc -> fillrect(t_strikerect);
1030+
}
10171031
if ((style & FA_BOX) != 0)
10181032
{
10191033
// MW-2012-09-04: [[ Bug 9759 ]] Adjust any pattern origin to scroll with text.
@@ -1111,9 +1125,17 @@ void MCBlock::drawstring(MCDC *dc, coord_t x, coord_t p_cell_left, coord_t p_cel
11111125

11121126
// Apply strike/underline.
11131127
if ((style & FA_UNDERLINE) != 0)
1114-
dc -> drawline(t_line_x, y + 1, t_line_x + t_line_width, y + 1);
1128+
{
1129+
MCRectangle t_underlinerect;
1130+
t_underlinerect = MCU_make_rect(t_line_x, y + t_strikewidth, t_line_width, t_strikewidth);
1131+
dc -> fillrect(t_underlinerect);
1132+
}
11151133
if ((style & FA_STRIKEOUT) != 0)
1116-
dc -> drawline(t_line_x, y - (t_ascent >> 1), t_line_x + t_line_width, y - (t_ascent >> 1));
1134+
{
1135+
MCRectangle t_strikerect;
1136+
t_strikerect = MCU_make_rect(t_line_x, y - (t_xheight / 2) - (t_strikewidth / 2), t_line_width, t_strikewidth);
1137+
dc -> fillrect(t_strikerect);
1138+
}
11171139
}
11181140
}
11191141

@@ -1177,8 +1199,7 @@ void MCBlock::draw(MCDC *dc, coord_t x, coord_t lx, coord_t cx, int2 y, findex_t
11771199
if (flags & F_HAS_BACK_COLOR)
11781200
dc->setbackground(*atts->backcolor);
11791201

1180-
if (t_foreground_color != NULL)
1181-
dc -> setforeground(*t_foreground_color);
1202+
setcolorfornormaltext(dc, t_foreground_color);
11821203

11831204
uint32_t t_style;
11841205
t_style = 0;
@@ -1292,11 +1313,13 @@ void MCBlock::draw(MCDC *dc, coord_t x, coord_t lx, coord_t cx, int2 y, findex_t
12921313
f->getforecolor(DI_HILITE, False, True, hc, t_pattern, x, y, dc, f);
12931314
if (hc.pixel == fc.pixel)
12941315
f->setforeground(dc, DI_BACK, False, True);
1316+
else
1317+
setcolorforselectedtext(dc, nil);
12951318
}
12961319
else
1297-
f->setforeground(dc, DI_BACK, False, True);
1320+
setcolorforselectedtext(dc, t_foreground_color);
12981321
}
1299-
1322+
13001323
// Draw the selected text.
13011324
// SN-2014-08-13: [[ Bug 13016 ]] Added a parameter for the left of the cell
13021325
drawstring(dc, x, lx, cx, y, m_index, m_size, (flags & F_HAS_BACK_COLOR) != 0, t_style);
@@ -1888,7 +1911,7 @@ uint2 MCBlock::getascent(void)
18881911
if (flags & F_HAS_IMAGE && atts->image != NULL)
18891912
return MCU_max(0, atts->image->getrect().height - shift + 2);
18901913
else
1891-
return MCU_max(0, heightfromsize(MCFontGetAscent(m_font)) - MCFontGetDescent(m_font) - shift);
1914+
return MCU_max(0, heightfromsize(ceilf(MCFontGetAscent(m_font))) - uint2(ceilf(MCFontGetDescent(m_font))) - shift);
18921915
}
18931916

18941917
uint2 MCBlock::getdescent(void)
@@ -1897,7 +1920,35 @@ uint2 MCBlock::getdescent(void)
18971920
if (flags & F_HAS_IMAGE && atts->image != NULL)
18981921
return MCU_max(0, shift);
18991922
else
1900-
return MCU_max(0, MCFontGetDescent(m_font) + shift);
1923+
return MCU_max(0, uint2(ceilf(MCFontGetDescent(m_font))) + shift);
1924+
}
1925+
1926+
coord_t MCBlock::GetAscent() const
1927+
{
1928+
int2 shift = flags & F_HAS_SHIFT ? atts->shift : 0;
1929+
// MW-2007-07-05: [[ Bug 1943 ]] - Images do not have correct ascent height *MIGHT NEED REVERSION*
1930+
if (flags & F_HAS_IMAGE && atts->image != NULL)
1931+
return MCU_max(0, atts->image->getrect().height - shift + 2);
1932+
else
1933+
return MCU_max(0.0f, MCFontGetAscent(m_font) - shift);
1934+
}
1935+
1936+
coord_t MCBlock::GetDescent() const
1937+
{
1938+
int2 shift = flags & F_HAS_SHIFT ? atts->shift : 0;
1939+
if (flags & F_HAS_IMAGE && atts->image != NULL)
1940+
return MCU_max(0, shift);
1941+
else
1942+
return MCU_max(0.0f, MCFontGetDescent(m_font) + shift);
1943+
}
1944+
1945+
coord_t MCBlock::GetLeading() const
1946+
{
1947+
int2 shift = flags & F_HAS_SHIFT ? atts->shift : 0;
1948+
if (flags & F_HAS_IMAGE && atts->image != NULL)
1949+
return GetAscent()+GetDescent();
1950+
else
1951+
return MCFontGetLeading(m_font);
19011952
}
19021953

19031954
void MCBlock::freeatts()
@@ -2400,3 +2451,36 @@ MCBlock *MCBlock::GetPrevBlockVisualOrder()
24002451

24012452
return nil;
24022453
}
2454+
2455+
void MCBlock::setcolorfornormaltext(MCDC* dc, MCColor* p_color)
2456+
{
2457+
MCField* f = parent->getparent();
2458+
2459+
if (p_color != nil)
2460+
dc->setforeground(*p_color);
2461+
else if (flags & F_HAS_COLOR)
2462+
dc->setforeground(*atts -> color);
2463+
else
2464+
f->setforeground(dc, DI_PSEUDO_TEXT_COLOR, False, True);
2465+
}
2466+
2467+
void MCBlock::setcolorforhilite(MCDC* dc)
2468+
{
2469+
MCField* f = parent->getparent();
2470+
2471+
f->setforeground(dc, DI_PSEUDO_TEXT_BACKGROUND_SEL, False, True);
2472+
}
2473+
2474+
void MCBlock::setcolorforselectedtext(MCDC* dc, MCColor* p_color)
2475+
{
2476+
MCField* f = parent->getparent();
2477+
2478+
if (p_color != nil)
2479+
dc->setforeground(*p_color);
2480+
else if (flags & F_HAS_COLOR)
2481+
dc->setforeground(*atts -> color);
2482+
else if (!IsMacLF()) // TODO: if platform reverses selected text
2483+
f->setforeground(dc, DI_PSEUDO_TEXT_COLOR_SEL_BACK, False, True, true);
2484+
else
2485+
f->setforeground(dc, DI_PSEUDO_TEXT_COLOR_SEL_FORE, False, True, true);
2486+
}

engine/src/button.cpp

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ void MCButton::setrect(const MCRectangle &nrect)
16941694
}
16951695

16961696
#ifdef LEGACY_EXEC
1697-
Exec_stat MCButton::getprop_legacy(uint4 parid, Properties which, MCExecPoint& ep, Boolean effective)
1697+
Exec_stat MCButton::getprop_legacy(uint4 parid, Properties which, MCExecPoint& ep, Boolean effective, bool recursive)
16981698
{
16991699
uint2 fheight;
17001700
uint2 j = 0;
@@ -1972,7 +1972,7 @@ Exec_stat MCButton::getprop_legacy(uint4 parid, Properties which, MCExecPoint& e
19721972
break;
19731973
#endif /* MCButton::getprop */
19741974
default:
1975-
return MCControl::getprop_legacy(parid, which, ep, effective);
1975+
return MCControl::getprop_legacy(parid, which, ep, effective, recursive);
19761976
}
19771977
return ES_NORMAL;
19781978
}
@@ -4765,3 +4765,62 @@ IO_stat MCButton::load(IO_handle stream, uint32_t version)
47654765
}
47664766
return IO_NORMAL;
47674767
}
4768+
4769+
////////////////////////////////////////////////////////////////////////////////
4770+
4771+
MCPlatformControlType MCButton::getcontroltype()
4772+
{
4773+
MCPlatformControlType t_type;
4774+
t_type = kMCPlatformControlTypeButton;
4775+
if (getstyleint(flags) == F_MENU)
4776+
{
4777+
t_type = kMCPlatformControlTypeMenu;
4778+
switch (menumode)
4779+
{
4780+
case WM_POPUP:
4781+
t_type = kMCPlatformControlTypePopupMenu;
4782+
break;
4783+
4784+
case WM_OPTION:
4785+
t_type = kMCPlatformControlTypeOptionMenu;
4786+
break;
4787+
4788+
case WM_COMBO:
4789+
t_type = kMCPlatformControlTypeComboBox;
4790+
break;
4791+
4792+
case WM_PULLDOWN:
4793+
t_type = kMCPlatformControlTypePulldownMenu;
4794+
break;
4795+
4796+
default:
4797+
break;
4798+
}
4799+
}
4800+
else if (menucontrol != MENUCONTROL_NONE)
4801+
{
4802+
t_type = kMCPlatformControlTypeMenuItem;
4803+
}
4804+
4805+
return t_type;
4806+
}
4807+
4808+
MCPlatformControlPart MCButton::getcontrolsubpart()
4809+
{
4810+
return kMCPlatformControlPartNone;
4811+
}
4812+
4813+
MCPlatformControlState MCButton::getcontrolstate()
4814+
{
4815+
int t_state;
4816+
t_state = MCControl::getcontrolstate();
4817+
4818+
if (flags & F_DEFAULT)
4819+
t_state |= kMCPlatformControlStateDefault;
4820+
4821+
if (t_state & kMCPlatformControlStateMouseFocus
4822+
&& MCbuttonstate & 1)
4823+
t_state |= kMCPlatformControlStatePressed;
4824+
4825+
return MCPlatformControlState(t_state);
4826+
}

engine/src/button.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,12 @@ class MCButton : public MCControl
180180

181181
virtual uint2 gettransient() const;
182182
virtual void setrect(const MCRectangle &nrect);
183+
183184
#ifdef LEGACY_EXEC
184-
virtual Exec_stat getprop_legacy(uint4 parid, Properties which, MCExecPoint &, Boolean effective);
185+
virtual Exec_stat getprop_legacy(uint4 parid, Properties which, MCExecPoint &, Boolean effective, bool recursive = false);
185186
virtual Exec_stat setprop_legacy(uint4 parid, Properties which, MCExecPoint &, Boolean effective);
186187
#endif
188+
187189
virtual void closemenu(Boolean kfocus, Boolean disarm);
188190

189191
// MW-2011-09-20: [[ Collision ]] Compute shape of button - will use mask of icon if possible.
@@ -473,5 +475,12 @@ class MCButton : public MCControl
473475
void trytochangetonative(void);
474476

475477
friend class ButtonMenuCallback;
478+
479+
protected:
480+
481+
// FG-2014-11-11: [[ Better theming ]] Fetch the control type/state for theming purposes
482+
virtual MCPlatformControlType getcontroltype();
483+
virtual MCPlatformControlPart getcontrolsubpart();
484+
virtual MCPlatformControlState getcontrolstate();
476485
};
477486
#endif

0 commit comments

Comments
 (0)