Fix crashes when used with third party toolkits

pull/1/head
Timothy Pearson 12 years ago
parent 7e54430051
commit cb48b1e673

@ -2686,9 +2686,9 @@ void LipstikStyle::drawControl(ControlElement element,
case CE_PushButton: { case CE_PushButton: {
TQPushButton *button = (TQPushButton *)widget; TQPushButton *button = (TQPushButton *)widget;
const bool isDefault = enabled && button->isDefault(); const bool isDefault = enabled && (elementFlags & CEF_IsDefault);
if (button->isFlat() ) if (elementFlags & CEF_IsFlat)
flatMode = true; flatMode = true;
TQColorGroup g2 = cg; TQColorGroup g2 = cg;
@ -2710,8 +2710,7 @@ void LipstikStyle::drawControl(ControlElement element,
int x, y, w, h; int x, y, w, h;
r.rect( &x, &y, &w, &h ); r.rect( &x, &y, &w, &h );
const TQPushButton* button = static_cast<const TQPushButton *>( widget ); bool active = (elementFlags & CEF_IsOn) || (elementFlags & CEF_IsDown);
bool active = button->isOn() || button->isDown();
bool cornArrow = false; bool cornArrow = false;
// Shift button contents if pushed. // Shift button contents if pushed.
@ -2723,11 +2722,11 @@ void LipstikStyle::drawControl(ControlElement element,
} }
// Does the button have a popup menu? // Does the button have a popup menu?
if ( button->isMenuButton() ) if (elementFlags & CEF_IsMenuWidget)
{ {
int dx = pixelMetric( PM_MenuButtonIndicator, ceData, elementFlags, widget ); int dx = pixelMetric( PM_MenuButtonIndicator, ceData, elementFlags, widget );
if ( button->iconSet() && !button->iconSet()->isNull() && if ( !ceData.iconSet.isNull() &&
(dx + button->iconSet()->pixmap (TQIconSet::Small, TQIconSet::Normal, TQIconSet::Off ).width()) >= w ) (dx + ceData.iconSet.pixmap (TQIconSet::Small, TQIconSet::Normal, TQIconSet::Off ).width()) >= w )
{ {
cornArrow = true; //To little room. Draw the arrow in the corner, don't adjust the widget cornArrow = true; //To little room. Draw the arrow in the corner, don't adjust the widget
} }
@ -2741,19 +2740,19 @@ void LipstikStyle::drawControl(ControlElement element,
} }
// Draw the icon if there is one // Draw the icon if there is one
if ( button->iconSet() && !button->iconSet()->isNull() ) if ( !ceData.iconSet.isNull() )
{ {
TQIconSet::Mode mode = TQIconSet::Disabled; TQIconSet::Mode mode = TQIconSet::Disabled;
TQIconSet::State state = TQIconSet::Off; TQIconSet::State state = TQIconSet::Off;
if (button->isEnabled()) if (elementFlags & CEF_IsEnabled)
mode = button->hasFocus() ? TQIconSet::Active : TQIconSet::Normal; mode = (elementFlags & CEF_HasFocus) ? TQIconSet::Active : TQIconSet::Normal;
if (button->isToggleButton() && button->isOn()) if ((elementFlags & CEF_BiState) && (elementFlags & CEF_IsOn))
state = TQIconSet::On; state = TQIconSet::On;
TQPixmap pixmap = button->iconSet()->pixmap( TQIconSet::Small, mode, state ); TQPixmap pixmap = ceData.iconSet.pixmap( TQIconSet::Small, mode, state );
if (button->text().isEmpty() && !button->pixmap()) if (ceData.text.isEmpty() && ceData.fgPixmap.isNull())
p->drawPixmap( x + w/2 - pixmap.width()/2, y + h / 2 - pixmap.height() / 2, p->drawPixmap( x + w/2 - pixmap.width()/2, y + h / 2 - pixmap.height() / 2,
pixmap ); pixmap );
else else
@ -2770,9 +2769,9 @@ void LipstikStyle::drawControl(ControlElement element,
} }
// Make the label indicate if the button is a default button or not // Make the label indicate if the button is a default button or not
drawItem( p, TQRect(x, y, w, h), AlignCenter|ShowPrefix, button->colorGroup(), drawItem( p, TQRect(x, y, w, h), AlignCenter|ShowPrefix, ceData.colorGroup,
button->isEnabled(), button->pixmap(), button->text(), -1, (elementFlags & CEF_IsEnabled), (ceData.fgPixmap.isNull())?NULL:&ceData.fgPixmap, ceData.text, -1,
&button->colorGroup().buttonText() ); &ceData.colorGroup.buttonText() );
if ( flags & Style_HasFocus ) if ( flags & Style_HasFocus )
@ -3234,14 +3233,10 @@ void LipstikStyle::drawComplexControl(ComplexControl control,
static const unsigned int handleWidth = 15; static const unsigned int handleWidth = 15;
const TQComboBox *cb = dynamic_cast<const TQComboBox *>(widget); const TQComboBox *cb = dynamic_cast<const TQComboBox *>(widget);
// at the moment cb is only needed to check if the combo box is editable or not.
// if cb doesn't exist, just assume false and the app (gideon! ;) ) at least doesn't crash.
bool editable = false; bool editable = false;
bool hasFocus = false; bool hasFocus = false;
if (cb) { editable = (elementFlags & CEF_IsEditable);
editable = cb->editable(); hasFocus = (elementFlags & CEF_HasFocus);
hasFocus = cb->hasFocus();
}
const TQColor buttonColor = enabled?cg.button():cg.background(); const TQColor buttonColor = enabled?cg.button():cg.background();
const TQColor inputColor = enabled?(editable?cg.base():cg.button()) const TQColor inputColor = enabled?(editable?cg.base():cg.button())
@ -3397,8 +3392,6 @@ void LipstikStyle::drawComplexControl(ComplexControl control,
// TOOLBUTTON // TOOLBUTTON
// ---------- // ----------
case CC_ToolButton: { case CC_ToolButton: {
const TQToolButton *tb = (const TQToolButton *) widget;
TQRect button, menuarea; TQRect button, menuarea;
button = querySubControlMetrics(control, ceData, elementFlags, SC_ToolButton, opt, widget); button = querySubControlMetrics(control, ceData, elementFlags, SC_ToolButton, opt, widget);
menuarea = querySubControlMetrics(control, ceData, elementFlags, SC_ToolButtonMenu, opt, widget); menuarea = querySubControlMetrics(control, ceData, elementFlags, SC_ToolButtonMenu, opt, widget);
@ -3444,16 +3437,14 @@ void LipstikStyle::drawComplexControl(ComplexControl control,
if (controls & SC_ToolButton) { if (controls & SC_ToolButton) {
// If we're pressed, on, or raised... // If we're pressed, on, or raised...
if (bflags & (Style_Down | Style_On | Style_Raised) || (flags & Style_MouseOver)) { if (bflags & (Style_Down | Style_On | Style_Raised) || (flags & Style_MouseOver)) {
if ( (flags & Style_MouseOver) && tb->parentWidget()->inherits( "KTabWidget" )) { if ( (flags & Style_MouseOver) && ceData.parentWidgetData.widgetObjectTypes.contains( "KTabWidget" )) {
renderButton(p, r, cg, false, true, false, true, false ); renderButton(p, r, cg, false, true, false, true, false );
} else { } else {
drawPrimitive(PE_ButtonTool, p, ceData, elementFlags, button, cg, bflags, opt); drawPrimitive(PE_ButtonTool, p, ceData, elementFlags, button, cg, bflags, opt);
} }
} else if (tb->parentWidget() && } else if (!ceData.parentWidgetData.bgPixmap.isNull()) {
tb->parentWidget()->backgroundPixmap() && TQPixmap pixmap = ceData.parentWidgetData.bgPixmap;
!tb->parentWidget()->backgroundPixmap()->isNull()) { p->drawTiledPixmap( r, pixmap, ceData.pos );
TQPixmap pixmap = *(tb->parentWidget()->backgroundPixmap());
p->drawTiledPixmap( r, pixmap, tb->pos() );
} }
} }
@ -3465,8 +3456,8 @@ void LipstikStyle::drawComplexControl(ComplexControl control,
drawPrimitive(PE_ArrowDown, p, ceData, elementFlags, menuarea, cg, mflags, opt); drawPrimitive(PE_ArrowDown, p, ceData, elementFlags, menuarea, cg, mflags, opt);
} }
if (tb->hasFocus() && !tb->focusProxy()) { if ((elementFlags & CEF_HasFocus) && !(elementFlags & CEF_HasFocusProxy)) {
TQRect fr = tb->rect(); TQRect fr = ceData.rect;
fr.addCoords(2, 2, -2, -2); fr.addCoords(2, 2, -2, -2);
drawPrimitive(PE_FocusRect, p, ceData, elementFlags, fr, cg); drawPrimitive(PE_FocusRect, p, ceData, elementFlags, fr, cg);
} }
@ -3483,13 +3474,11 @@ void LipstikStyle::drawComplexControl(ComplexControl control,
case CC_SpinWidget: { case CC_SpinWidget: {
static const unsigned int handleWidth = 15; static const unsigned int handleWidth = 15;
const TQSpinWidget *sw = dynamic_cast<const TQSpinWidget *>(widget);
SFlags sflags = flags; SFlags sflags = flags;
PrimitiveElement pe; PrimitiveElement pe;
bool hasFocus = false; bool hasFocus = false;
if (sw) hasFocus = (elementFlags & CEF_HasFocus);
hasFocus = sw->hasFocus();
const TQColor buttonColor = enabled?cg.button():cg.background(); const TQColor buttonColor = enabled?cg.button():cg.background();
const TQColor inputColor = enabled?cg.base():cg.background(); const TQColor inputColor = enabled?cg.base():cg.background();
@ -3588,7 +3577,7 @@ void LipstikStyle::drawComplexControl(ComplexControl control,
sflags |= Style_Sunken; sflags |= Style_Sunken;
} else } else
sflags |= Style_Raised; sflags |= Style_Raised;
if (sw->buttonSymbols() == TQSpinWidget::PlusMinus) if (ceData.spinWidgetData.buttonSymbols == TQSpinWidget::PlusMinus)
pe = PE_SpinWidgetPlus; pe = PE_SpinWidgetPlus;
else else
pe = PE_SpinWidgetUp; pe = PE_SpinWidgetUp;
@ -3601,7 +3590,7 @@ void LipstikStyle::drawComplexControl(ComplexControl control,
sflags |= Style_Sunken; sflags |= Style_Sunken;
} else } else
sflags |= Style_Raised; sflags |= Style_Raised;
if (sw->buttonSymbols() == TQSpinWidget::PlusMinus) if (ceData.spinWidgetData.buttonSymbols == TQSpinWidget::PlusMinus)
pe = PE_SpinWidgetMinus; pe = PE_SpinWidgetMinus;
else else
pe = PE_SpinWidgetDown; pe = PE_SpinWidgetDown;
@ -3873,14 +3862,13 @@ TQSize LipstikStyle::sizeFromContents(ContentsType t,
{ {
switch (t) { switch (t) {
case CT_PopupMenuItem: { case CT_PopupMenuItem: {
if (!widget || opt.isDefault()) if (opt.isDefault())
return s; return s;
const TQPopupMenu *popup = dynamic_cast<const TQPopupMenu *>(widget);
TQMenuItem *mi = opt.menuItem(); TQMenuItem *mi = opt.menuItem();
int maxpmw = opt.maxIconWidth(); int maxpmw = opt.maxIconWidth();
int w = s.width(), h = s.height() + _menuSpacing; int w = s.width(), h = s.height() + _menuSpacing;
bool checkable = popup->isCheckable(); bool checkable = (elementFlags & CEF_IsCheckable);
if (mi->custom()) { if (mi->custom()) {
w = mi->custom()->sizeHint().width(); w = mi->custom()->sizeHint().width();
@ -3897,7 +3885,7 @@ TQSize LipstikStyle::sizeFromContents(ContentsType t,
h = TQMAX(h, mi->pixmap()->height() + 2); h = TQMAX(h, mi->pixmap()->height() + 2);
} else { } else {
h = TQMAX(h, 16 + 2); h = TQMAX(h, 16 + 2);
h = TQMAX(h, popup->fontMetrics().height() + 4 ); h = TQMAX(h, TQFontMetrics(ceData.font).height() + 4 );
} }
if (mi->iconSet()) { if (mi->iconSet()) {
@ -3928,11 +3916,9 @@ TQSize LipstikStyle::sizeFromContents(ContentsType t,
case CT_PushButton: case CT_PushButton:
{ {
const TQPushButton* btn = static_cast<const TQPushButton*>(widget);
int w = s.width() + 2 * pixelMetric(PM_ButtonMargin, ceData, elementFlags, widget); int w = s.width() + 2 * pixelMetric(PM_ButtonMargin, ceData, elementFlags, widget);
int h = s.height() + 2 * pixelMetric(PM_ButtonMargin, ceData, elementFlags, widget); int h = s.height() + 2 * pixelMetric(PM_ButtonMargin, ceData, elementFlags, widget);
if ( btn->text().isEmpty() && s.width() < 32 ) return TQSize(w, h); if ( ceData.text.isEmpty() && s.width() < 32 ) return TQSize(w, h);
return TQSize( w+25, h+5 ); return TQSize( w+25, h+5 );
} }

Loading…
Cancel
Save