Fix style crashes when used with third party toolkits

pull/1/head
Timothy Pearson 12 years ago
parent f16f8eb6bf
commit 06d51bc1ec

@ -114,17 +114,17 @@ void dotNETstyle::polish(TQStyleControlElementData ceData, ControlElementFlags e
if (ceData.widgetObjectTypes.contains(TQWIDGET_OBJECT_NAME_STRING)) {
TQWidget *widget = reinterpret_cast<TQWidget*>(ptr);
if (!qstrcmp(tqApp->argv()[0], "kicker") || widget->inherits("Kicker"))
if (!qstrcmp(tqApp->argv()[0], "kicker") || ceData.widgetObjectTypes.contains("Kicker"))
kickerMode = true;
if (widget->isTopLevel())
if (elementFlags & CEF_IsTopLevel)
return;
// we can't simply set a palette -- upon color-theme changes, we have
// to update the palette again.
// bool extraPalette = false;
if (widget->inherits(TQCOMBOBOX_OBJECT_NAME_STRING) && !inheritsKHTML(widget)) {
if (ceData.widgetObjectTypes.contains(TQCOMBOBOX_OBJECT_NAME_STRING) && !inheritsKHTML(widget)) {
installObjectEventHandler(ceData, elementFlags, ptr, this);
updatePalette( (TQComboBox*) widget );
// extraPalette = true;
@ -137,10 +137,10 @@ void dotNETstyle::polish(TQStyleControlElementData ceData, ControlElementFlags e
// other bad things (see bug #54569)
/*
if (!widget->ownPalette()) {
if (widget->inherits(TQTOOLBAR_OBJECT_NAME_STRING)) {
if (ceData.widgetObjectTypes.contains(TQTOOLBAR_OBJECT_NAME_STRING)) {
updatePalette( (TQToolBar*) widget );
extraPalette = true;
} else if (widget->inherits(TQMENUBAR_OBJECT_NAME_STRING)) {
} else if (ceData.widgetObjectTypes.contains(TQMENUBAR_OBJECT_NAME_STRING)) {
updatePalette( (TQMenuBar*) widget );
extraPalette = true;
}
@ -156,7 +156,7 @@ void dotNETstyle::unPolish(TQStyleControlElementData ceData, ControlElementFlags
if (ceData.widgetObjectTypes.contains(TQWIDGET_OBJECT_NAME_STRING)) {
TQWidget *widget = reinterpret_cast<TQWidget*>(ptr);
if (widget->inherits(TQCOMBOBOX_OBJECT_NAME_STRING) && !inheritsKHTML(widget)) {
if (ceData.widgetObjectTypes.contains(TQCOMBOBOX_OBJECT_NAME_STRING) && !inheritsKHTML(widget)) {
removeObjectEventHandler(ceData, elementFlags, ptr, this);
}
}
@ -390,10 +390,9 @@ void dotNETstyle::drawKStylePrimitive(KStylePrimitive kpe,
// ------
switch( kpe ) {
case KPE_SliderGroove: {
const TQSlider* slider = (const TQSlider*)widget;
int x, y, w, h;
r.rect(&x, &y, &w, &h);
bool horizontal = slider->orientation() ==Qt::Horizontal;
bool horizontal = ceData.orientation == TQt::Horizontal;
int gcenter = (horizontal ? h : w) / 2;
if (horizontal) {
@ -828,11 +827,9 @@ void dotNETstyle::drawControl(TQ_ControlElement element,
}
case CE_ProgressBarContents: {
const TQProgressBar *pb = (const TQProgressBar *)widget;
if (pb->totalSteps()) {
if (ceData.totalSteps) {
int x, y, w, h;
double percent = (double)pb->progress() / (double)pb->totalSteps();
double percent = (double)ceData.currentStep / (double)ceData.totalSteps;
r.rect(&x, &y, &w, &h);
@ -849,7 +846,7 @@ void dotNETstyle::drawControl(TQ_ControlElement element,
p->fillRect(x, y, w, h, cg.highlight());
if (pb->progress() < pb->totalSteps()) {
if (ceData.currentStep < ceData.totalSteps) {
p->setPen(cg.background().dark(115));
if (TQApplication::reverseLayout()) {
p->drawLine(x - 1, y, x - 1, h);
@ -1107,7 +1104,6 @@ void dotNETstyle::drawControl(TQ_ControlElement element,
}
case CE_PushButtonLabel: {
const TQPushButton *pb = (const TQPushButton *)widget;
const bool enabled = flags & Style_Enabled;
const int text_flags = AlignVCenter | AlignHCenter | ShowPrefix |
DontClip | SingleLine;
@ -1118,19 +1114,19 @@ void dotNETstyle::drawControl(TQ_ControlElement element,
pixelMetric(PM_ButtonShiftVertical, ceData, elementFlags));
}
if (!pb->text().isEmpty() && (flags & Style_ButtonDefault)) {
if (!ceData.text.isEmpty() && (flags & Style_ButtonDefault)) {
p->setFont(TQFont(p->font().family(), p->font().pointSize(), 75));
}
if (pb->iconSet() && !pb->iconSet()->isNull()) {
if (!ceData.iconSet.isNull()) {
TQIconSet::Mode mode = enabled ? TQIconSet::Normal : TQIconSet::Disabled;
TQPixmap pixmap = pb->iconSet()->pixmap(TQIconSet::Small, mode);
TQPixmap pixmap = ceData.iconSet.pixmap(TQIconSet::Small, mode);
if (!pb->text().isEmpty())
if (!ceData.text.isEmpty())
{
const int TextToIconMargin = 3;
int length = pixmap.width() + TextToIconMargin
+ p->fontMetrics().size(ShowPrefix, pb->text()).width();
+ p->fontMetrics().size(ShowPrefix, ceData.text).width();
int offset = (r.width() - length)/2;
p->drawPixmap( r.x() + offset, r.y() + r.height() / 2 - pixmap.height() / 2, pixmap );
@ -1138,28 +1134,28 @@ void dotNETstyle::drawControl(TQ_ControlElement element,
}
else
{
if (!pb->pixmap())
if (ceData.fgPixmap.isNull())
p->drawPixmap(r.x() + r.width()/2 - pixmap.width()/2, r.y() + r.height() / 2 - pixmap.height() / 2,
pixmap);
else //icon + pixmap. Ugh.
p->drawPixmap(r.x() + pb->isDefault() ? 8 : 4 , r.y() + r.height() / 2 - pixmap.height() / 2, pixmap);
p->drawPixmap(r.x() + (elementFlags & CEF_IsDefault) ? 8 : 4 , r.y() + r.height() / 2 - pixmap.height() / 2, pixmap);
}
}
if (pb->pixmap() && !pb->text()) {
TQRect pr(0, 0, pb->pixmap()->width(), pb->pixmap()->height());
if ((!ceData.fgPixmap.isNull()) && !ceData.text) {
TQRect pr(0, 0, ceData.fgPixmap.width(), ceData.fgPixmap.height());
pr.moveCenter(r.center());
p->drawPixmap(pr.topLeft(), *pb->pixmap());
p->drawPixmap(pr.topLeft(), (ceData.fgPixmap.isNull())?NULL:ceData.fgPixmap);
}
if (useTextShadows && !pb->text().isEmpty() && enabled) {
if (useTextShadows && !ceData.text.isEmpty() && enabled) {
p->setPen((flags & Style_Down ? cg.highlight().dark(135) : cg.background().dark(115)));
p->drawText(ur.x()+1, ur.y()+1, ur.width(), ur.height(), text_flags, pb->text());
p->drawText(ur.x()+1, ur.y()+1, ur.width(), ur.height(), text_flags, ceData.text);
}
if (!pb->text().isEmpty()) {
p->setPen(enabled ? cg.foreground() : pb->palette().disabled().buttonText());
p->drawText(ur, text_flags, pb->text());
if (!ceData.text.isEmpty()) {
p->setPen(enabled ? cg.foreground() : ceData.palette.disabled().buttonText());
p->drawText(ur, text_flags, ceData.text);
}
if ( flags & Style_HasFocus )
@ -1484,7 +1480,6 @@ void dotNETstyle::drawComplexControl(ComplexControl control,
// --------
case CC_ComboBox: {
int x, y, w, h;
const TQComboBox *cb = (const TQComboBox *)widget;
r.rect(&x, &y, &w, &h);
if (active & Style_Sunken)
@ -1501,13 +1496,13 @@ void dotNETstyle::drawComplexControl(ComplexControl control,
TQBitmap downArrow = TQBitmap(7, 4, downarrow_bits, true);
downArrow.setMask(downArrow);
cb->editable() ? p->fillRect(x + 1, y + 1, w - 2, h - 2, cg.base()) : p->fillRect(x + 1, y + 1, w - 2, h - 2, cg.light());
(elementFlags & CEF_IsEditable) ? p->fillRect(x + 1, y + 1, w - 2, h - 2, cg.base()) : p->fillRect(x + 1, y + 1, w - 2, h - 2, cg.light());
renderPanel(p, r, cg, true, true);
p->save();
// Draw the box on the right.
if (cb->listBox() && cb->listBox()->isVisible()) {
if (ceData.comboBoxListBoxFlags & CEF_IsVisible) {
p->setPen(cg.highlight());
p->setBrush(cg.highlight().light());
} else if (flags & Style_HasFocus) {
@ -1528,12 +1523,12 @@ void dotNETstyle::drawComplexControl(ComplexControl control,
if (TQApplication::reverseLayout()) { rr = visualRect( rr, r ); }
if (flags & Style_HasFocus || cg.highlight() == cg.midlight() ||
(cb->listBox() && cb->listBox()->isVisible())) {
(ceData.comboBoxListBoxFlags & CEF_IsVisible)) {
p->drawRect(rr);
}
if (pseudo3D && !((active & Style_Sunken) ||
(cb->listBox() && cb->listBox()->isVisible()))) {
(ceData.comboBoxListBoxFlags & CEF_IsVisible))) {
p->save();
p->setBrush(NoBrush);
TQColor test = ((flags & Style_HasFocus) ? cg.highlight() : cg.midlight());
@ -1564,7 +1559,7 @@ void dotNETstyle::drawComplexControl(ComplexControl control,
p->drawPoint(hr.bottomLeft());
}
if ((active && cb->hasFocus()) || (cb->listBox() && cb->listBox()->isVisible())) {
if ((active && (elementFlags & CEF_HasFocus)) || (ceData.comboBoxListBoxFlags & CEF_IsVisible)) {
p->setPen(cg.highlightedText());
} else {
p->setPen(cg.text());
@ -1737,7 +1732,7 @@ TQRect dotNETstyle::subRect(SubRect r, const TQStyleControlElementData ceData, c
}
case SR_PushButtonFocusRect: {
TQRect rect = widget->rect();
TQRect rect = ceData.rect;
int margin = pixelMetric(PM_ButtonDefaultIndicator, ceData, elementFlags, widget) + pixelMetric(PM_DefaultFrameWidth, ceData, elementFlags, widget) + 2;
rect.addCoords(margin, margin, -margin, -margin);
@ -1762,11 +1757,7 @@ TQRect dotNETstyle::querySubControlMetrics(ComplexControl control,
const TQStyleOption &opt,
const TQWidget *widget) const
{
if (!widget) {
return TQRect();
}
TQRect r(widget->rect());
TQRect r(ceData.rect);
switch (control) {
case CC_ComboBox: {
switch (subcontrol) {
@ -1783,12 +1774,12 @@ TQRect dotNETstyle::querySubControlMetrics(ComplexControl control,
case CC_SpinWidget: {
int fw = pixelMetric(PM_SpinBoxFrameWidth, ceData, elementFlags, widget);
TQSize bs;
bs.setHeight(TQMAX(8, widget->height()/2));
bs.setWidth(TQMIN(bs.height() * 8 / 5, widget->width() / 4));
bs.setHeight(TQMAX(8, ceData.rect.height()/2));
bs.setWidth(TQMIN(bs.height() * 8 / 5, ceData.rect.width() / 4));
int y = fw;
int x, lx;
x = widget->width() - y - bs.width();
x = ceData.rect.width() - y - bs.width();
lx = fw;
switch (subcontrol) {
@ -1799,13 +1790,13 @@ TQRect dotNETstyle::querySubControlMetrics(ComplexControl control,
return TQRect(x, y + bs.height()-1, bs.width(), bs.height());
}
case SC_SpinWidgetFrame: {
return TQRect(0, 0, widget->width() - (bs.width() + 2), widget->height());
return TQRect(0, 0, ceData.rect.width() - (bs.width() + 2), ceData.rect.height());
}
case SC_SpinWidgetEditField: {
return TQRect(lx, fw, widget->width() - (bs.width() + 4), widget->height() - 2 * fw);
return TQRect(lx, fw, ceData.rect.width() - (bs.width() + 4), ceData.rect.height() - 2 * fw);
}
case SC_SpinWidgetButtonField: {
return TQRect(x, y, bs.width(), widget->height() - 2 * fw);
return TQRect(x, y, bs.width(), ceData.rect.height() - 2 * fw);
}
default: {
}
@ -1885,11 +1876,10 @@ int dotNETstyle::pixelMetric(PixelMetric m, TQStyleControlElementData ceData, Co
if (!pseudo3D) {
return 1;
} else {
if (widget &&
(widget->inherits(TQPOPUPMENU_OBJECT_NAME_STRING) ||
widget->inherits(TQMENUBAR_OBJECT_NAME_STRING) ||
widget->inherits(TQRANGECONTROL_OBJECT_NAME_STRING) ||
widget->inherits(TQSCROLLVIEW_OBJECT_NAME_STRING))) {
if (ceData.widgetObjectTypes.contains(TQPOPUPMENU_OBJECT_NAME_STRING) ||
ceData.widgetObjectTypes.contains(TQMENUBAR_OBJECT_NAME_STRING) ||
ceData.widgetObjectTypes.contains(TQRANGECONTROL_OBJECT_NAME_STRING) ||
ceData.widgetObjectTypes.contains(TQSCROLLVIEW_OBJECT_NAME_STRING)) {
return 1;
} else {
return 2;
@ -1953,7 +1943,7 @@ TQSize dotNETstyle::sizeFromContents(ContentsType t,
h = TQMAX(h, mi->pixmap()->height() + 8);
}
h = TQMAX(h, widget->fontMetrics().height() + 10);
h = TQMAX(h, TQFontMetrics(ceData.font).height() + 10);
if (mi->iconSet()) {
h = TQMAX(h, mi->iconSet()->pixmap(TQIconSet::Small, TQIconSet::Normal).height() + 8);
@ -2128,7 +2118,7 @@ int dotNETstyle::styleHint(StyleHint sh, TQStyleControlElementData ceData, Contr
}
break;
default:
ret = TQCommonStyle::styleHint(sh, ceData, elementFlags, opt, returnData, w);
ret = KStyle::styleHint(sh, ceData, elementFlags, opt, returnData, w);
break;
}

@ -638,8 +638,8 @@ void PhaseStyle::drawPrimitive(TQ_PrimitiveElement element,
horiz = true;
}
if ((widget) && ((widget->inherits(TQPOPUPMENU_OBJECT_NAME_STRING)) ||
(widget->inherits("KPopupTitle")))) {
if ((ceData.widgetObjectTypes.contains(TQPOPUPMENU_OBJECT_NAME_STRING)) ||
(ceData.widgetObjectTypes.contains("KPopupTitle"))) {
// kicker/kdesktop menu titles
drawPhaseBevel(painter, x,y,w,h,
group, group.background(), depress, !horiz);
@ -894,12 +894,11 @@ void PhaseStyle::drawPrimitive(TQ_PrimitiveElement element,
widget = dynamic_cast<TQWidget*>(painter->device());
bool flat = true;
if (widget && widget->parent() &&
widget->parent()->inherits(TQTOOLBAR_OBJECT_NAME_STRING)) {
if (ceData.parentWidgetData.widgetObjectTypes.contains(TQTOOLBAR_OBJECT_NAME_STRING)) {
TQToolBar *toolbar = ::tqqt_cast<TQToolBar*>(widget->parent());
if (toolbar) {
// toolbar not floating or in a TQMainWindow
flat = flatToolbar(toolbar);
flat = flatToolbar(ceData, elementFlags, toolbar);
}
}
@ -1113,28 +1112,23 @@ void PhaseStyle::drawKStylePrimitive(KStylePrimitive element,
break;
case KPE_SliderGroove: {
const TQSlider* slider = ::tqqt_cast<const TQSlider*>(widget);
if (slider) {
if (slider->orientation() ==Qt::Horizontal) {
if (ceData.orientation == TQt::Horizontal) {
y = cy - 3;
h = 7;
} else {
x = cx - 3;
w = 7;
}
}
drawPhasePanel(painter, x, y, w, h, group, true,
&group.brush(TQColorGroup::Mid));
break;
}
case KPE_SliderHandle: {
const TQSlider* slider = ::tqqt_cast<const TQSlider*>(widget);
if (slider) {
TQColor color = (flags & Style_MouseOver)
? TQColor(group.button().light(contrast))
: group.button();
if (slider->orientation() ==Qt::Horizontal) {
if (ceData.orientation == TQt::Horizontal) {
drawPhaseBevel(painter, cx-5, y, 6, h, group, color,
false, false, false);
drawPhaseBevel(painter, cx, y, 6, h, group, color,
@ -1145,7 +1139,6 @@ void PhaseStyle::drawKStylePrimitive(KStylePrimitive element,
drawPhaseBevel(painter, x, cy, w, 6, group, color,
false, true, false);
}
}
break;
}
@ -1308,7 +1301,7 @@ void PhaseStyle::drawControl(TQ_ControlElement element,
const TQToolBar *tb = ::tqqt_cast<const TQToolBar*>(widget);
if (tb) {
// toolbar not floating or in a TQMainWindow
if (flatToolbar(tb)) {
if (flatToolbar(ceData, elementFlags, tb)) {
if (tb->backgroundMode() == PaletteButton)
// force default button color to background color
painter->fillRect(rect, group.background());
@ -1381,9 +1374,8 @@ void PhaseStyle::drawControl(TQ_ControlElement element,
// draw background
if (active && enabled) {
painter->fillRect(x, y, w, h, group.highlight());
} else if (widget->erasePixmap() &&
!widget->erasePixmap()->isNull()) {
painter->drawPixmap(x, y, *widget->erasePixmap(), x, y, w, h);
} else if (!ceData.bgPixmap.isNull()) {
painter->drawPixmap(x, y, ceData.bgPixmap, x, y, w, h);
} else {
painter->fillRect(x, y, w, h, group.background());
}
@ -1879,7 +1871,7 @@ void PhaseStyle::drawComplexControl(TQ_ComplexControl control,
if (toolbar) {
horiz = (toolbar->orientation() == Qt::Horizontal);
if (normal) { // draw background
if (flatToolbar(toolbar)) {
if (flatToolbar(ceData, elementFlags, toolbar)) {
// toolbar not floating or in a TQMainWindow
painter->fillRect(rect, group.background());
} else {
@ -2071,7 +2063,7 @@ TQRect PhaseStyle::querySubControlMetrics(TQ_ComplexControl control,
TQRect rect;
const int fw = pixelMetric(PM_DefaultFrameWidth, ceData, elementFlags, widget);
int w = widget->width(), h = widget->height();
int w = ceData.rect.width(), h = ceData.rect.height();
int xc;
switch (control) {
@ -2081,7 +2073,7 @@ TQRect PhaseStyle::querySubControlMetrics(TQ_ComplexControl control,
switch (subcontrol) {
case SC_ComboBoxFrame: // total combobox area
rect = widget->rect();
rect = ceData.rect;
break;
case SC_ComboBoxArrow: // the right side
@ -2103,10 +2095,7 @@ TQRect PhaseStyle::querySubControlMetrics(TQ_ComplexControl control,
}
case CC_ScrollBar: {
const TQScrollBar *sb = ::tqqt_cast<const TQScrollBar*>(widget);
if (!sb) break;
bool horizontal = (sb->orientation() == Qt::Horizontal);
bool horizontal = (ceData.orientation == TQt::Horizontal);
rect = KStyle::querySubControlMetrics(control, ceData, elementFlags,
subcontrol, option, widget);
@ -2119,7 +2108,7 @@ TQRect PhaseStyle::querySubControlMetrics(TQ_ComplexControl control,
}
case CC_SpinWidget: {
bool odd = widget->height() % 2;
bool odd = ceData.rect.height() % 2;
xc = (h * 3 / 4) + odd; // position between edit and arrows
switch (subcontrol) {
@ -2132,7 +2121,7 @@ TQRect PhaseStyle::querySubControlMetrics(TQ_ComplexControl control,
break;
case SC_SpinWidgetFrame:
rect = widget->rect();
rect = ceData.rect;
break;
case SC_SpinWidgetUp:
@ -2254,7 +2243,7 @@ TQSize PhaseStyle::sizeFromContents(ContentsType contents,
// -------------
// Is the toolbar "flat"
bool PhaseStyle::flatToolbar(const TQToolBar *toolbar) const
bool PhaseStyle::flatToolbar(const TQStyleControlElementData ceData, const ControlElementFlags elementFlags, const TQToolBar *toolbar) const
{
if (!toolbar) return true; // not on a toolbar
if (!toolbar->isMovingEnabled()) return true; // immobile toolbars are flat
@ -2280,7 +2269,7 @@ int PhaseStyle::styleHint(StyleHint sh, TQStyleControlElementData ceData, Contro
}
break;
default:
ret = TQCommonStyle::styleHint(sh, ceData, elementFlags, opt, returnData, w);
ret = KStyle::styleHint(sh, ceData, elementFlags, opt, returnData, w);
break;
}
@ -2316,7 +2305,7 @@ bool PhaseStyle::objectEventHandler( TQStyleControlElementData ceData, ControlEl
if (object->parent() && !qstrcmp(object->name(), KTOOLBARWIDGET)) {
if (0 == (widget = ::tqqt_cast<TQWidget*>(object))) return false;
TQWidget *parent = ::tqqt_cast<TQWidget*>(object->parent());
int px = widget->x(), py = widget->y();
int px = ceData.rect.x(), py = ceData.rect.y();
// find the toolbar
while (parent && parent->parent()
&& !::tqqt_cast<TQToolBar*>(parent)) {
@ -2325,18 +2314,18 @@ bool PhaseStyle::objectEventHandler( TQStyleControlElementData ceData, ControlEl
parent = ::tqqt_cast<TQWidget*>(parent->parent());
}
if (!parent) return false;
TQT_TQRECT_OBJECT(widget->rect()).rect(&x, &y, &w, &h);
TQT_TQRECT_OBJECT(ceData.rect).rect(&x, &y, &w, &h);
TQRect prect = parent->rect();
toolbar = ::tqqt_cast<TQToolBar*>(parent);
horiz = (toolbar) ? (toolbar->orientation() == Qt::Horizontal)
: (prect.height() < prect.width());
TQPainter painter(widget);
if (flatToolbar(toolbar)) {
painter.fillRect(widget->rect(),
if (flatToolbar(ceData, elementFlags, toolbar)) {
painter.fillRect(ceData.rect,
parent->colorGroup().background());
} else {
drawPhaseGradient(&painter, widget->rect(),
drawPhaseGradient(&painter, ceData.rect,
parent->colorGroup().background(),
!horiz, px, py,
prect.width(), prect.height(), true);
@ -2356,9 +2345,9 @@ bool PhaseStyle::objectEventHandler( TQStyleControlElementData ceData, ControlEl
if (0 == (widget = ::tqqt_cast<TQWidget*>(object))) return false;
horiz = (toolbar->orientation() == Qt::Horizontal);
TQPainter painter(widget);
TQT_TQRECT_OBJECT(widget->rect()).rect(&x, &y, &w, &h);
TQT_TQRECT_OBJECT(ceData.rect).rect(&x, &y, &w, &h);
// draw the extension
drawPhaseGradient(&painter, widget->rect(),
drawPhaseGradient(&painter, ceData.rect,
toolbar->colorGroup().background(),
!horiz, x, y, w-1, h-1, true);
if (horiz) {

@ -187,7 +187,7 @@ class PhaseStyle : public KStyle
int pw=-1, int ph=-1,
bool reverse=false) const;
bool flatToolbar(const TQToolBar *toolbar) const;
bool flatToolbar(const TQStyleControlElementData ceData, const ControlElementFlags elementFlags, const TQToolBar *toolbar) const;
bool objectEventHandler( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQEvent *e );

Loading…
Cancel
Save