Fix scrollbars

pull/1/head
Timothy Pearson 12 years ago
parent ec156de973
commit b358b8dfae

@ -60,6 +60,10 @@
p.setBrush(TQt::NoBrush); p.setBrush(TQt::NoBrush);
extern int m_scrollBarSubLineWidth; extern int m_scrollBarSubLineWidth;
extern bool m_scrollbarBack1;
extern bool m_scrollbarForward1;
extern bool m_scrollbarBack2;
extern bool m_scrollbarForward2;
WidgetLookup m_widgetLookup; WidgetLookup m_widgetLookup;
Animations m_animations; Animations m_animations;
@ -410,11 +414,18 @@ void gtkScrollbarToScrollbarCeData(GtkScrollbar* scrollbarWidget, TQStyleControl
ceData.pageStep = gtk_adjustment_get_page_increment(adjustment); ceData.pageStep = gtk_adjustment_get_page_increment(adjustment);
// Convert the GTK slider length into a correct pagestep that TQt3 can use to obtain the same slider length value // Convert the GTK slider length into a correct pagestep that TQt3 can use to obtain the same slider length value
bool threeButtonScrollBar = false;
if (m_scrollbarBack2 | m_scrollbarForward2) threeButtonScrollBar = true;
TQStyle::ControlElementFlags elementFlags = TQStyle::CEF_None; TQStyle::ControlElementFlags elementFlags = TQStyle::CEF_None;
int gtkSliderLength = slider_end_pos - slider_start_pos; int gtkSliderLength = slider_end_pos - slider_start_pos;
uint range = ceData.maxSteps - ceData.minSteps; uint range = ceData.maxSteps - ceData.minSteps;
// HACK
// GTK3 does not handle odd-sized steppers correctly
if ((m_scrollBarSubLineWidth % 2) != 0) {
gtkSliderLength = gtkSliderLength + 4;
}
int sbextent = tqApp->style().pixelMetric(TQStyle::PM_ScrollBarExtent, ceData, elementFlags, NULL); int sbextent = tqApp->style().pixelMetric(TQStyle::PM_ScrollBarExtent, ceData, elementFlags, NULL);
int maxlen = ((ceData.orientation == TQt::Horizontal) ? ceData.rect.width() : ceData.rect.height()) - (sbextent * 2); int maxlen = ((ceData.orientation == TQt::Horizontal) ? ceData.rect.width() : ceData.rect.height()) - (sbextent * (threeButtonScrollBar ? 3.0 : 2.0));
int gtkPageStep=ceil((-1.0)*(range*gtkSliderLength)/(gtkSliderLength-maxlen)); int gtkPageStep=ceil((-1.0)*(range*gtkSliderLength)/(gtkSliderLength-maxlen));
ceData.pageStep = gtkPageStep; ceData.pageStep = gtkPageStep;
} }
@ -600,6 +611,8 @@ draw_slider_frame(DRAW_ARGS, const GtkWidgetPath* path, GtkStateFlags state, Gtk
cairo_restore(cr); cairo_restore(cr);
} }
TQStyle::SubControl lastSliderActiveSubControl = TQStyle::SC_None;
static void static void
draw_scrollbar_frame(DRAW_ARGS, const GtkWidgetPath* path, GtkStateFlags state, GtkWidget* widget) { draw_scrollbar_frame(DRAW_ARGS, const GtkWidgetPath* path, GtkStateFlags state, GtkWidget* widget) {
cairo_save(cr); cairo_save(cr);
@ -658,6 +671,10 @@ draw_scrollbar_frame(DRAW_ARGS, const GtkWidgetPath* path, GtkStateFlags state,
state = (GtkStateFlags)(state | GTK_STATE_FLAG_INSENSITIVE); state = (GtkStateFlags)(state | GTK_STATE_FLAG_INSENSITIVE);
} }
sflags &= ~TQStyle::Style_On;
sflags &= ~TQStyle::Style_Down;
sflags &= ~TQStyle::Style_Active;
// Determine active subcontrols // Determine active subcontrols
gint cursor_x = -1; gint cursor_x = -1;
gint cursor_y = -1; gint cursor_y = -1;
@ -680,34 +697,64 @@ draw_scrollbar_frame(DRAW_ARGS, const GtkWidgetPath* path, GtkStateFlags state,
last = tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, ceData, elementFlags, TQStyle::SC_ScrollBarLast); last = tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, ceData, elementFlags, TQStyle::SC_ScrollBarLast);
// HACK // HACK
// This may not be 100% reliable, and it has the side effect of triggering the page step activity effect when the slider is dragged quickly and the mouse cursor momentarily pops out of the slider rectangle. // This may not be 100% reliable!
GdkModifierType mouseStateFlags; GdkModifierType mouseStateFlags;
gdk_device_get_state (device, gtk_widget_get_window(widget), NULL, &mouseStateFlags); gdk_device_get_state (device, gtk_widget_get_window(widget), NULL, &mouseStateFlags);
bool mousedown = (mouseStateFlags & GDK_BUTTON1_MASK); bool mousedown = (mouseStateFlags & GDK_BUTTON1_MASK);
if (mousedown) { if (mousedown) {
bool combine_addlineregion_drawing_areas = tqApp->style().styleHint(TQStyle::SH_ScrollBar_CombineAddLineRegionDrawingAreas);
if (lastSliderActiveSubControl != TQStyle::SC_None) {
activeSubControl = (TQStyle::SubControl)(activeSubControl | lastSliderActiveSubControl);
}
else {
if (subline.contains(cursor_pos)) { if (subline.contains(cursor_pos)) {
activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarSubLine); activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarSubLine);
lastSliderActiveSubControl = TQStyle::SC_ScrollBarSubLine;
}
else if (addline.contains(cursor_pos)) {
// Not so fast...the addline region may contain a subline control!
TQRect internalSubLine;
if (ceData.orientation == TQt::Horizontal) {
internalSubLine = TQRect(addline.x(), addline.y(), addline.width()/2, addline.height());
}
else {
internalSubLine = TQRect(addline.x(), addline.y(), addline.width(), addline.height()/2);
}
if (internalSubLine.contains(cursor_pos)) {
activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarSubLine);
lastSliderActiveSubControl = TQStyle::SC_ScrollBarSubLine;
} }
if (addline.contains(cursor_pos)) { else {
activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarAddLine); activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarAddLine);
lastSliderActiveSubControl = TQStyle::SC_ScrollBarAddLine;
} }
if (subpage.contains(cursor_pos)) { }
else if (subpage.contains(cursor_pos)) {
activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarSubPage); activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarSubPage);
lastSliderActiveSubControl = TQStyle::SC_ScrollBarSubPage;
} }
if (addpage.contains(cursor_pos)) { else if (addpage.contains(cursor_pos)) {
activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarAddPage); activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarAddPage);
lastSliderActiveSubControl = TQStyle::SC_ScrollBarAddPage;
} }
if (slider.contains(cursor_pos)) { else if (slider.contains(cursor_pos)) {
activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarSlider); activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarSlider);
lastSliderActiveSubControl = TQStyle::SC_ScrollBarSlider;
} }
if (first.contains(cursor_pos)) { else if (first.contains(cursor_pos)) {
activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarFirst); activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarFirst);
lastSliderActiveSubControl = TQStyle::SC_ScrollBarFirst;
} }
if (last.contains(cursor_pos)) { else if (last.contains(cursor_pos)) {
activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarLast); activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarLast);
lastSliderActiveSubControl = TQStyle::SC_ScrollBarLast;
}
} }
} }
else {
lastSliderActiveSubControl = TQStyle::SC_None;
}
} }
// Draw item // Draw item

@ -42,6 +42,10 @@ void initTDESettings();
void writeGtkThemeControlFile(int forceRecreate); void writeGtkThemeControlFile(int forceRecreate);
int m_scrollBarSubLineWidth = -1; int m_scrollBarSubLineWidth = -1;
bool m_scrollbarBack1 = false;
bool m_scrollbarForward1 = false;
bool m_scrollbarBack2 = false;
bool m_scrollbarForward2 = false;
extern "C" { extern "C" {
#include <gmodule.h> #include <gmodule.h>
@ -567,19 +571,14 @@ void writeGtkThemeControlFile(int forceRecreate) {
// and asking the style which subcontrol is at that location. // and asking the style which subcontrol is at that location.
TQRect rect = tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, &sbar, TQStyle::SC_ScrollBarGroove); TQRect rect = tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, &sbar, TQStyle::SC_ScrollBarGroove);
bool back1 = false;
bool forward1 = false;
bool back2 = false;
bool forward2 = false;
TQStyle::SubControl sc = TQStyle::SC_None; TQStyle::SubControl sc = TQStyle::SC_None;
for (TQPoint pos(0,7) ; pos.x()<rect.x() ; pos.setX(pos.x()+1)) for (TQPoint pos(0,7) ; pos.x()<rect.x() ; pos.setX(pos.x()+1))
{ {
TQStyle::SubControl sc2 = tqApp->style().querySubControl(TQStyle::CC_ScrollBar, &sbar, pos); TQStyle::SubControl sc2 = tqApp->style().querySubControl(TQStyle::CC_ScrollBar, &sbar, pos);
if (sc != sc2) if (sc != sc2)
{ {
if (sc2 == TQStyle::SC_ScrollBarAddLine) forward1 = true; if (sc2 == TQStyle::SC_ScrollBarAddLine) m_scrollbarForward1 = true;
if (sc2 == TQStyle::SC_ScrollBarSubLine) back1 = true; if (sc2 == TQStyle::SC_ScrollBarSubLine) m_scrollbarBack1 = true;
sc = sc2; sc = sc2;
} }
} }
@ -589,12 +588,15 @@ void writeGtkThemeControlFile(int forceRecreate) {
TQStyle::SubControl sc2 = tqApp->style().querySubControl(TQStyle::CC_ScrollBar, &sbar, pos); TQStyle::SubControl sc2 = tqApp->style().querySubControl(TQStyle::CC_ScrollBar, &sbar, pos);
if (sc != sc2) if (sc != sc2)
{ {
if (sc2 == TQStyle::SC_ScrollBarAddLine) forward2 = true; if (sc2 == TQStyle::SC_ScrollBarAddLine) m_scrollbarForward2 = true;
if (sc2 == TQStyle::SC_ScrollBarSubLine) back2 = true; if (sc2 == TQStyle::SC_ScrollBarSubLine) m_scrollbarBack2 = true;
sc = sc2; sc = sc2;
} }
} }
// FIXME
// The items in a GTK3 combobox cannot be styled, either to draw them in a custom manner or to change their height
// A bug report should be filed on this issue...
bool combobox_appears_as_list = (!(tqApp->style().styleHint(TQStyle::SH_ComboBox_Popup) || tqApp->style().styleHint(TQStyle::SH_GUIStyle) == TQt::MotifStyle)); bool combobox_appears_as_list = (!(tqApp->style().styleHint(TQStyle::SH_ComboBox_Popup) || tqApp->style().styleHint(TQStyle::SH_GUIStyle) == TQt::MotifStyle));
stream << parse_rc_string(TQString("-GtkComboBox-appears-as-list: %1px").arg(combobox_appears_as_list), "*"); stream << parse_rc_string(TQString("-GtkComboBox-appears-as-list: %1px").arg(combobox_appears_as_list), "*");
@ -605,10 +607,10 @@ void writeGtkThemeControlFile(int forceRecreate) {
stream << parse_rc_string("-GtkComboBox-arrow-size: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_ArrowSize)), "*"); stream << parse_rc_string("-GtkComboBox-arrow-size: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_ArrowSize)), "*");
stream << parse_rc_string("-GtkComboBox-arrow-scaling: 0", "*"); stream << parse_rc_string("-GtkComboBox-arrow-scaling: 0", "*");
stream << parse_rc_string(TQString("-GtkScrollbar-has-backward-stepper: ") + (back1 ? "1" : "0"), "*"); stream << parse_rc_string(TQString("-GtkScrollbar-has-backward-stepper: ") + (m_scrollbarBack1 ? "1" : "0"), "*");
stream << parse_rc_string(TQString("-GtkScrollbar-has-forward-stepper: ") + (forward2 ? "1" : "0"), "*"); stream << parse_rc_string(TQString("-GtkScrollbar-has-forward-stepper: ") + (m_scrollbarForward2 ? "1" : "0"), "*");
stream << parse_rc_string(TQString("-GtkScrollbar-has-secondary-forward-stepper: ") + (forward1 ? "1" : "0"), "*"); stream << parse_rc_string(TQString("-GtkScrollbar-has-secondary-forward-stepper: ") + (m_scrollbarForward1 ? "1" : "0"), "*");
stream << parse_rc_string(TQString("-GtkScrollbar-has-secondary-backward-stepper: ") + (back2 ? "1" : "0"), "*"); stream << parse_rc_string(TQString("-GtkScrollbar-has-secondary-backward-stepper: ") + (m_scrollbarBack2 ? "1" : "0"), "*");
m_scrollBarSubLineWidth = tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, &sbar, TQStyle::SC_ScrollBarSubLine).width(); m_scrollBarSubLineWidth = tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, &sbar, TQStyle::SC_ScrollBarSubLine).width();

Loading…
Cancel
Save