• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdefx
 

tdefx

  • tdefx
tdestyle.cpp
1 /*
2  *
3  * TDEStyle
4  * Copyright (C) 2001-2002 Karol Szwed <gallium@kde.org>
5  *
6  * TQWindowsStyle CC_ListView and style images were kindly donated by TrollTech,
7  * Copyright (C) 1998-2000 TrollTech AS.
8  *
9  * Many thanks to Bradley T. Hughes for the 3 button scrollbar code.
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License version 2 as published by the Free Software Foundation.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public License
21  * along with this library; see the file COPYING.LIB. If not, write to
22  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23  * Boston, MA 02110-1301, USA.
24  */
25 
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29 
30 #include "tdestyle.h"
31 
32 #include <tqapplication.h>
33 #include <tqbitmap.h>
34 #include <tqmetaobject.h>
35 #include <tqcleanuphandler.h>
36 #include <tqmap.h>
37 #include <tqimage.h>
38 #include <tqlistview.h>
39 #include <tqmenubar.h>
40 #include <tqpainter.h>
41 #include <tqpixmap.h>
42 #include <tqpopupmenu.h>
43 #include <tqprogressbar.h>
44 #include <tqscrollbar.h>
45 #include <tqsettings.h>
46 #include <tqslider.h>
47 #include <tqstylefactory.h>
48 #include <tqtabbar.h>
49 #include <tqtoolbar.h>
50 #include <tqframe.h>
51 
52 #include <kpixmap.h>
53 #include <kpixmapeffect.h>
54 #include <kimageeffect.h>
55 
56 #ifdef Q_WS_X11
57 # include <X11/Xlib.h>
58 # ifdef HAVE_XRENDER
59 # include <X11/extensions/Xrender.h> // schroder
60  extern bool tqt_use_xrender;
61 # endif
62 #else
63 #undef HAVE_XRENDER
64 #endif
65 
66 #ifdef HAVE_XCOMPOSITE
67 #include <X11/extensions/Xrender.h>
68 #include <X11/extensions/Xcomposite.h>
69 #include <dlfcn.h>
70 #endif
71 
72 #include <limits.h>
73 
74 namespace
75 {
76  // INTERNAL
77  enum TransparencyEngine {
78  Disabled = 0,
79  SoftwareTint,
80  SoftwareBlend,
81  XRender
82  };
83 
84  // Drop Shadow
85  struct ShadowElements {
86  TQWidget* w1;
87  TQWidget* w2;
88  };
89  typedef TQMap<const TQWidget*,ShadowElements> ShadowMap;
90  static ShadowMap *_shadowMap = 0;
91  TQSingleCleanupHandler<ShadowMap> cleanupShadowMap;
92  ShadowMap &shadowMap() {
93  if ( !_shadowMap ) {
94  _shadowMap = new ShadowMap;
95  cleanupShadowMap.set( &_shadowMap );
96  }
97  return *_shadowMap;
98  }
99 
100 
101  // DO NOT ASK ME HOW I MADE THESE TABLES!
102  // (I probably won't remember anyway ;)
103  const double top_right_corner[16] =
104  { 0.949, 0.965, 0.980, 0.992,
105  0.851, 0.890, 0.945, 0.980,
106  0.706, 0.780, 0.890, 0.960,
107  0.608, 0.706, 0.851, 0.949 };
108 
109  const double bottom_right_corner[16] =
110  { 0.608, 0.706, 0.851, 0.949,
111  0.706, 0.780, 0.890, 0.960,
112  0.851, 0.890, 0.945, 0.980,
113  0.949, 0.965, 0.980, 0.992 };
114 
115  const double bottom_left_corner[16] =
116  { 0.949, 0.851, 0.706, 0.608,
117  0.965, 0.890, 0.780, 0.706,
118  0.980, 0.945, 0.890, 0.851,
119  0.992, 0.980, 0.960, 0.949 };
120 
121  const double shadow_strip[4] =
122  { 0.565, 0.675, 0.835, 0.945 };
123 
124  static bool useDropShadow(TQWidget* w)
125  {
126  return w && w->metaObject() &&
127  w->metaObject()->findProperty("TDEStyleMenuDropShadow") != -1;
128  }
129 }
130 
131 namespace
132 {
133 class TransparencyHandler : public TQObject
134 {
135  public:
136  TransparencyHandler(TDEStyle* style, TransparencyEngine tEngine,
137  float menuOpacity, bool useDropShadow);
138  ~TransparencyHandler();
139  bool eventFilter(TQObject* object, TQEvent* event);
140 
141  protected:
142  void blendToColor(const TQColor &col);
143  void blendToPixmap(const TQColorGroup &cg, const TQWidget* p);
144 #ifdef HAVE_XRENDER
145  void XRenderBlendToPixmap(const TQWidget* p);
146 #endif
147  bool haveX11RGBASupport();
148  TQImage handleRealAlpha(TQImage);
149  void createShadowWindows(const TQWidget* p);
150  void removeShadowWindows(const TQWidget* p);
151  void rightShadow(TQImage& dst);
152  void bottomShadow(TQImage& dst);
153  private:
154  bool dropShadow;
155  float opacity;
156  TQPixmap pix;
157  TDEStyle* tdestyle;
158  TransparencyEngine te;
159 };
160 } // namespace
161 
162 struct TDEStylePrivate
163 {
164  bool highcolor : 1;
165  bool useFilledFrameWorkaround : 1;
166  bool etchDisabledText : 1;
167  bool scrollablePopupmenus : 1;
168  bool autoHideAccelerators : 1;
169  bool menuAltKeyNavigation : 1;
170  bool menuDropShadow : 1;
171  bool sloppySubMenus : 1;
172  bool semiTransparentRubberband : 1;
173  int popupMenuDelay;
174  float menuOpacity;
175 
176  TransparencyEngine transparencyEngine;
177  TDEStyle::TDEStyleScrollBarType scrollbarType;
178  TransparencyHandler* menuHandler;
179  TDEStyle::TDEStyleFlags flags;
180 
181  //For KPE_ListViewBranch
182  TQBitmap *verticalLine;
183  TQBitmap *horizontalLine;
184 };
185 
186 // -----------------------------------------------------------------------------
187 
188 
189 TDEStyle::TDEStyle( TDEStyleFlags flags, TDEStyleScrollBarType sbtype )
190  : TQCommonStyle(), d(new TDEStylePrivate)
191 {
192  d->flags = flags;
193  bool useMenuTransparency = (flags & AllowMenuTransparency);
194  d->useFilledFrameWorkaround = (flags & FilledFrameWorkaround);
195  d->scrollbarType = sbtype;
196  d->highcolor = TQPixmap::defaultDepth() > 8;
197 
198  // Read style settings
199  TQSettings settings;
200  d->popupMenuDelay = settings.readNumEntry ("/TDEStyle/Settings/PopupMenuDelay", 250);
201  d->sloppySubMenus = settings.readBoolEntry("/TDEStyle/Settings/SloppySubMenus", false);
202  d->etchDisabledText = settings.readBoolEntry("/TDEStyle/Settings/EtchDisabledText", true);
203  d->menuAltKeyNavigation = settings.readBoolEntry("/TDEStyle/Settings/MenuAltKeyNavigation", true);
204  d->scrollablePopupmenus = settings.readBoolEntry("/TDEStyle/Settings/ScrollablePopupMenus", false);
205  d->autoHideAccelerators = settings.readBoolEntry("/TDEStyle/Settings/AutoHideAccelerators", false);
206  d->menuDropShadow = settings.readBoolEntry("/TDEStyle/Settings/MenuDropShadow", false);
207  d->semiTransparentRubberband = settings.readBoolEntry("/TDEStyle/Settings/SemiTransparentRubberband", false);
208  d->menuHandler = NULL;
209 
210  if (useMenuTransparency) {
211  TQString effectEngine = settings.readEntry("/TDEStyle/Settings/MenuTransparencyEngine", "Disabled");
212 
213 #ifdef HAVE_XRENDER
214  if (effectEngine == "XRender")
215  d->transparencyEngine = XRender;
216 #else
217  if (effectEngine == "XRender")
218  d->transparencyEngine = SoftwareBlend;
219 #endif
220  else if (effectEngine == "SoftwareBlend")
221  d->transparencyEngine = SoftwareBlend;
222  else if (effectEngine == "SoftwareTint")
223  d->transparencyEngine = SoftwareTint;
224  else
225  d->transparencyEngine = Disabled;
226 
227  if (d->transparencyEngine != Disabled) {
228  // Create an instance of the menu transparency handler
229  d->menuOpacity = settings.readDoubleEntry("/TDEStyle/Settings/MenuOpacity", 0.90);
230  d->menuHandler = new TransparencyHandler(this, d->transparencyEngine,
231  d->menuOpacity, d->menuDropShadow);
232  }
233  }
234 
235  d->verticalLine = 0;
236  d->horizontalLine = 0;
237 
238  // Create a transparency handler if only drop shadows are enabled.
239  if (!d->menuHandler && d->menuDropShadow)
240  d->menuHandler = new TransparencyHandler(this, Disabled, 1.0, d->menuDropShadow);
241 }
242 
243 
244 TDEStyle::~TDEStyle()
245 {
246  delete d->verticalLine;
247  delete d->horizontalLine;
248 
249  delete d->menuHandler;
250 
251  d->menuHandler = NULL;
252  delete d;
253 }
254 
255 
256 TQString TDEStyle::defaultStyle()
257 {
258  if (TQPixmap::defaultDepth() > 8)
259  return TQString("plastik");
260  else
261  return TQString("light, 3rd revision");
262 }
263 
264 void TDEStyle::polish( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void *ptr )
265 {
266  if (ceData.widgetObjectTypes.contains(TQWIDGET_OBJECT_NAME_STRING)) {
267  TQWidget* widget = reinterpret_cast<TQWidget*>(ptr);
268  if ( d->useFilledFrameWorkaround )
269  {
270  if ( TQFrame *frame = ::tqqt_cast< TQFrame* >( widget ) ) {
271  TQFrame::Shape shape = frame->frameShape();
272  if (shape == TQFrame::ToolBarPanel || shape == TQFrame::MenuBarPanel)
273  widget->installEventFilter(this);
274  }
275  }
276  if (widget->isTopLevel())
277  {
278  if (!d->menuHandler && useDropShadow(widget))
279  d->menuHandler = new TransparencyHandler(this, Disabled, 1.0, false);
280 
281  if (d->menuHandler && useDropShadow(widget))
282  widget->installEventFilter(d->menuHandler);
283  }
284  }
285 }
286 
287 
288 void TDEStyle::unPolish( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void *ptr )
289 {
290  if (ceData.widgetObjectTypes.contains(TQWIDGET_OBJECT_NAME_STRING)) {
291  TQWidget* widget = reinterpret_cast<TQWidget*>(ptr);
292  if ( d->useFilledFrameWorkaround )
293  {
294  if ( TQFrame *frame = ::tqqt_cast< TQFrame* >( widget ) ) {
295  TQFrame::Shape shape = frame->frameShape();
296  if (shape == TQFrame::ToolBarPanel || shape == TQFrame::MenuBarPanel)
297  widget->removeEventFilter(this);
298  }
299  }
300  if (widget->isTopLevel() && d->menuHandler && useDropShadow(widget))
301  widget->removeEventFilter(d->menuHandler);
302  }
303 }
304 
305 
306 // Style changes (should) always re-polish popups.
307 void TDEStyle::polishPopupMenu( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void *ptr )
308 {
309  if ( !(ceData.windowState & WState_Polished ) ) {
310  widgetActionRequest(ceData, elementFlags, ptr, WAR_SetCheckable);
311  }
312 
313  if (ceData.widgetObjectTypes.contains(TQWIDGET_OBJECT_NAME_STRING)) {
314  TQWidget* widget = reinterpret_cast<TQWidget*>(ptr);
315  TQPopupMenu *p = dynamic_cast<TQPopupMenu*>(widget);
316  if (p) {
317  // Install transparency handler if the effect is enabled.
318  if ( d->menuHandler && (strcmp(p->name(), "tear off menu") != 0)) {
319  p->installEventFilter(d->menuHandler);
320  }
321  }
322  }
323 }
324 
325 
326 // -----------------------------------------------------------------------------
327 // TDEStyle extensions
328 // -----------------------------------------------------------------------------
329 
330 void TDEStyle::setScrollBarType(TDEStyleScrollBarType sbtype)
331 {
332  d->scrollbarType = sbtype;
333 }
334 
335 TDEStyle::TDEStyleFlags TDEStyle::styleFlags() const
336 {
337  return d->flags;
338 }
339 
340 void TDEStyle::renderMenuBlendPixmap( KPixmap &pix, const TQColorGroup &cg,
341  const TQPopupMenu* /* popup */ ) const
342 {
343  pix.fill(cg.button()); // Just tint as the default behavior
344 }
345 
346 void TDEStyle::drawTDEStylePrimitive( TDEStylePrimitive kpe,
347  TQPainter* p,
348  const TQWidget* widget,
349  const TQRect &r,
350  const TQColorGroup &cg,
351  SFlags flags,
352  const TQStyleOption &opt ) const
353 {
354  const TQStyleControlElementData &ceData = populateControlElementDataFromWidget(widget, TQStyleOption());
355  drawTDEStylePrimitive(kpe, p, ceData, getControlElementFlagsForObject(widget, TQStyleOption()), r, cg, flags, opt);
356 }
357 
358 void TDEStyle::drawTDEStylePrimitive( TDEStylePrimitive kpe,
359  TQPainter* p,
360  const TQStyleControlElementData &ceData,
361  ControlElementFlags elementFlags,
362  const TQRect &r,
363  const TQColorGroup &cg,
364  SFlags flags,
365  const TQStyleOption&, /* opt */
366  const TQWidget* widget ) const
367 {
368  switch( kpe )
369  {
370  // Dock / Toolbar / General handles.
371  // ---------------------------------
372 
373  case KPE_DockWindowHandle: {
374 
375  // Draws a nice DockWindow handle including the dock title.
376  TQWidget* wid = const_cast<TQWidget*>(widget);
377  bool horizontal = flags & Style_Horizontal;
378  int x,y,w,h,x2,y2;
379 
380  r.rect( &x, &y, &w, &h );
381  if ((w <= 2) || (h <= 2)) {
382  p->fillRect(r, cg.highlight());
383  return;
384  }
385 
386 
387  x2 = x + w - 1;
388  y2 = y + h - 1;
389 
390  TQFont fnt;
391  fnt = TQApplication::font(wid);
392  fnt.setPointSize( fnt.pointSize()-2 );
393 
394  // Draw the item on an off-screen pixmap
395  // to preserve Xft antialiasing for
396  // vertically oriented handles.
397  TQPixmap pix;
398  if (horizontal)
399  pix.resize( h-2, w-2 );
400  else
401  pix.resize( w-2, h-2 );
402 
403  TQString title = wid->parentWidget()->caption();
404  TQPainter p2;
405  p2.begin(&pix);
406  p2.fillRect(pix.rect(), cg.brush(TQColorGroup::Highlight));
407  p2.setPen(cg.highlightedText());
408  p2.setFont(fnt);
409  p2.drawText(pix.rect(), AlignCenter, title);
410  p2.end();
411 
412  // Draw a sunken bevel
413  p->setPen(cg.dark());
414  p->drawLine(x, y, x2, y);
415  p->drawLine(x, y, x, y2);
416  p->setPen(cg.light());
417  p->drawLine(x+1, y2, x2, y2);
418  p->drawLine(x2, y+1, x2, y2);
419 
420  if (horizontal) {
421  TQWMatrix m;
422  m.rotate(-90.0);
423  TQPixmap vpix = pix.xForm(m);
424  bitBlt(wid, r.x()+1, r.y()+1, &vpix);
425  } else
426  bitBlt(wid, r.x()+1, r.y()+1, &pix);
427 
428  break;
429  }
430 
431 
432  /*
433  * KPE_ListViewExpander and KPE_ListViewBranch are based on code from
434  * QWindowStyle's CC_ListView, kindly donated by TrollTech.
435  * CC_ListView code is Copyright (C) 1998-2000 TrollTech AS.
436  */
437 
438  case KPE_ListViewExpander: {
439  // Typical Windows style expand/collapse element.
440  int radius = (r.width() - 4) / 2;
441  int centerx = r.x() + r.width()/2;
442  int centery = r.y() + r.height()/2;
443 
444  // Outer box
445  p->setPen( cg.mid() );
446  p->drawRect( r );
447 
448  // plus or minus
449  p->setPen( cg.text() );
450  p->drawLine( centerx - radius, centery, centerx + radius, centery );
451  if ( flags & Style_On ) // Collapsed = On
452  p->drawLine( centerx, centery - radius, centerx, centery + radius );
453  break;
454  }
455 
456  case KPE_ListViewBranch: {
457  // Typical Windows style listview branch element (dotted line).
458 
459  // Create the dotline pixmaps if not already created
460  if ( !d->verticalLine )
461  {
462  // make 128*1 and 1*128 bitmaps that can be used for
463  // drawing the right sort of lines.
464  d->verticalLine = new TQBitmap( 1, 129, true );
465  d->horizontalLine = new TQBitmap( 128, 1, true );
466  TQPointArray a( 64 );
467  TQPainter p2;
468  p2.begin( d->verticalLine );
469 
470  int i;
471  for( i=0; i < 64; i++ )
472  a.setPoint( i, 0, i*2+1 );
473  p2.setPen( color1 );
474  p2.drawPoints( a );
475  p2.end();
476  TQApplication::flushX();
477  d->verticalLine->setMask( *d->verticalLine );
478 
479  p2.begin( d->horizontalLine );
480  for( i=0; i < 64; i++ )
481  a.setPoint( i, i*2+1, 0 );
482  p2.setPen( color1 );
483  p2.drawPoints( a );
484  p2.end();
485  TQApplication::flushX();
486  d->horizontalLine->setMask( *d->horizontalLine );
487  }
488 
489  p->setPen( cg.text() ); // cg.dark() is bad for dark color schemes.
490 
491  if (flags & Style_Horizontal)
492  {
493  int point = r.x();
494  int other = r.y();
495  int end = r.x()+r.width();
496  int thickness = r.height();
497 
498  while( point < end )
499  {
500  int i = 128;
501  if ( i+point > end )
502  i = end-point;
503  p->drawPixmap( point, other, *d->horizontalLine, 0, 0, i, thickness );
504  point += i;
505  }
506 
507  } else {
508  int point = r.y();
509  int other = r.x();
510  int end = r.y()+r.height();
511  int thickness = r.width();
512  int pixmapoffset = (flags & Style_NoChange) ? 0 : 1; // ### Hackish
513 
514  while( point < end )
515  {
516  int i = 128;
517  if ( i+point > end )
518  i = end-point;
519  p->drawPixmap( other, point, *d->verticalLine, 0, pixmapoffset, thickness, i );
520  point += i;
521  }
522  }
523 
524  break;
525  }
526 
527  // Reimplement the other primitives in your styles.
528  // The current implementation just paints something visibly different.
529  case KPE_ToolBarHandle:
530  case KPE_GeneralHandle:
531  case KPE_SliderHandle:
532  p->fillRect(r, cg.light());
533  break;
534 
535  case KPE_SliderGroove:
536  p->fillRect(r, cg.dark());
537  break;
538 
539  default:
540  p->fillRect(r, Qt::yellow); // Something really bad happened - highlight.
541  break;
542  }
543 }
544 
545 
546 int TDEStyle::kPixelMetric( TDEStylePixelMetric kpm, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, const TQWidget* /* widget */) const
547 {
548  int value;
549  switch(kpm)
550  {
551  case KPM_ListViewBranchThickness:
552  value = 1;
553  break;
554 
555  case KPM_MenuItemSeparatorHeight:
556  case KPM_MenuItemHMargin:
557  case KPM_MenuItemVMargin:
558  case KPM_MenuItemHFrame:
559  case KPM_MenuItemVFrame:
560  case KPM_MenuItemCheckMarkHMargin:
561  case KPM_MenuItemArrowHMargin:
562  case KPM_MenuItemTabSpacing:
563  default:
564  value = 0;
565  }
566 
567  return value;
568 }
569 
570 // -----------------------------------------------------------------------------
571 
572 // #ifdef USE_QT4 // tdebindings / smoke needs this function declaration available at all times. Furthermore I don't think it would hurt to have the declaration available at all times...so leave these commented out for now
573 
574 //void TDEStyle::drawPrimitive( TQ_ControlElement pe,
575 // TQPainter* p,
576 // const TQStyleControlElementData &ceData,
577 // ControlElementFlags elementFlags,
578 // const TQRect &r,
579 // const TQColorGroup &cg,
580 // SFlags flags,
581 // const TQStyleOption& opt ) const
582 //{
583 // // FIXME:
584 // // What should "widget" be in actuality? How should I get it? From where?
585 // // Almost certainly it should not be null!
586 // TQWidget *widget = 0;
587 // drawControl(pe, p, ceData, elementFlags, r, cg, flags, opt, widget);
588 //}
589 
590 // #endif // USE_QT4
591 
592 // -----------------------------------------------------------------------------
593 
594 void TDEStyle::drawPrimitive( TQ_PrimitiveElement pe,
595  TQPainter* p,
596  const TQStyleControlElementData &ceData,
597  ControlElementFlags elementFlags,
598  const TQRect &r,
599  const TQColorGroup &cg,
600  SFlags flags,
601  const TQStyleOption& opt ) const
602 {
603  // TOOLBAR/DOCK WINDOW HANDLE
604  // ------------------------------------------------------------------------
605  if (pe == PE_DockWindowHandle)
606  {
607  // Wild workarounds are here. Beware.
608  TQWidget *widget, *parent;
609 
610  if (p && p->device()->devType() == TQInternal::Widget) {
611  widget = static_cast<TQWidget*>(p->device());
612  parent = widget->parentWidget();
613  } else
614  return; // Don't paint on non-widgets
615 
616  // Check if we are a normal toolbar or a hidden dockwidget.
617  if ( parent &&
618  (parent->inherits(TQTOOLBAR_OBJECT_NAME_STRING) || // Normal toolbar
619  (parent->inherits(TQMAINWINDOW_OBJECT_NAME_STRING)) )) // Collapsed dock
620 
621  // Draw a toolbar handle
622  drawTDEStylePrimitive( KPE_ToolBarHandle, p, ceData, elementFlags, r, cg, flags, opt, widget );
623 
624  else if (ceData.widgetObjectTypes.contains(TQDOCKWINDOWHANDLE_OBJECT_NAME_STRING))
625 
626  // Draw a dock window handle
627  drawTDEStylePrimitive( KPE_DockWindowHandle, p, ceData, elementFlags, r, cg, flags, opt, widget );
628 
629  else
630  // General handle, probably a kicker applet handle.
631  drawTDEStylePrimitive( KPE_GeneralHandle, p, ceData, elementFlags, r, cg, flags, opt, widget );
632 #if TQT_VERSION >= 0x030300
633 #ifdef HAVE_XRENDER
634  } else if ( d->semiTransparentRubberband && pe == TQStyle::PE_RubberBand ) {
635  TQRect rect = r.normalize();
636  TQPoint point;
637  point = p->xForm( point );
638 
639  static XRenderColor clr = { 0, 0, 0, 0 };
640  static unsigned long fillColor = 0;
641  if ( fillColor != cg.highlight().rgb() ) {
642  fillColor = cg.highlight().rgb();
643 
644  unsigned long color = fillColor << 8 | 0x40;
645 
646  int red = (color >> 24) & 0xff;
647  int green = (color >> 16) & 0xff;
648  int blue = (color >> 8) & 0xff;
649  int alpha = (color >> 0) & 0xff;
650 
651  red = red * alpha / 255;
652  green = green * alpha / 255;
653  blue = blue * alpha / 255;
654 
655  clr.red = (red << 8) + red;
656  clr.green = (green << 8) + green;
657  clr.blue = (blue << 8) + blue;
658  clr.alpha = (alpha << 8) + alpha;
659  }
660 
661  XRenderFillRectangle(
662  p->device()->x11Display(),
663  PictOpOver,
664  p->device()->x11RenderHandle(),
665  &clr,
666  rect.x() + point.x(),
667  rect.y() + point.y(),
668  rect.width(),
669  rect.height() );
670 
671  p->save();
672  p->setRasterOp( TQt::CopyROP );
673  p->setPen( TQPen( cg.highlight().dark( 160 ), 1 ) );
674  p->setBrush( NoBrush );
675  p->drawRect(
676  rect.x() + point.x(),
677  rect.y() + point.y(),
678  rect.width(),
679  rect.height() );
680  p->restore();
681 #endif
682 #endif
683  } else
684  TQCommonStyle::drawPrimitive( pe, p, ceData, elementFlags, r, cg, flags, opt );
685 }
686 
687 
688 
689 void TDEStyle::drawControl( TQ_ControlElement element,
690  TQPainter* p,
691  const TQStyleControlElementData &ceData,
692  ControlElementFlags elementFlags,
693  const TQRect &r,
694  const TQColorGroup &cg,
695  SFlags flags,
696  const TQStyleOption &opt,
697  const TQWidget* widget ) const
698 {
699  switch (element)
700  {
701  // TABS
702  // ------------------------------------------------------------------------
703  case CE_TabBarTab: {
704  TQTabBar::Shape tbs = ceData.tabBarData.shape;
705  bool selected = flags & Style_Selected;
706  int x = r.x(), y=r.y(), bottom=r.bottom(), right=r.right();
707 
708  switch (tbs) {
709 
710  case TQTabBar::RoundedAbove: {
711  if (!selected)
712  p->translate(0,1);
713  p->setPen(selected ? cg.light() : cg.shadow());
714  p->drawLine(x, y+4, x, bottom);
715  p->drawLine(x, y+4, x+4, y);
716  p->drawLine(x+4, y, right-1, y);
717  if (selected)
718  p->setPen(cg.shadow());
719  p->drawLine(right, y+1, right, bottom);
720 
721  p->setPen(cg.midlight());
722  p->drawLine(x+1, y+4, x+1, bottom);
723  p->drawLine(x+1, y+4, x+4, y+1);
724  p->drawLine(x+5, y+1, right-2, y+1);
725 
726  if (selected) {
727  p->setPen(cg.mid());
728  p->drawLine(right-1, y+1, right-1, bottom);
729  } else {
730  p->setPen(cg.mid());
731  p->drawPoint(right-1, y+1);
732  p->drawLine(x+4, y+2, right-1, y+2);
733  p->drawLine(x+3, y+3, right-1, y+3);
734  p->fillRect(x+2, y+4, r.width()-3, r.height()-6, cg.mid());
735 
736  p->setPen(cg.light());
737  p->drawLine(x, bottom-1, right, bottom-1);
738  p->translate(0,-1);
739  }
740  break;
741  }
742 
743  case TQTabBar::RoundedBelow: {
744  if (!selected)
745  p->translate(0,-1);
746  p->setPen(selected ? cg.light() : cg.shadow());
747  p->drawLine(x, bottom-4, x, y);
748  if (selected)
749  p->setPen(cg.mid());
750  p->drawLine(x, bottom-4, x+4, bottom);
751  if (selected)
752  p->setPen(cg.shadow());
753  p->drawLine(x+4, bottom, right-1, bottom);
754  p->drawLine(right, bottom-1, right, y);
755 
756  p->setPen(cg.midlight());
757  p->drawLine(x+1, bottom-4, x+1, y);
758  p->drawLine(x+1, bottom-4, x+4, bottom-1);
759  p->drawLine(x+5, bottom-1, right-2, bottom-1);
760 
761  if (selected) {
762  p->setPen(cg.mid());
763  p->drawLine(right-1, y, right-1, bottom-1);
764  } else {
765  p->setPen(cg.mid());
766  p->drawPoint(right-1, bottom-1);
767  p->drawLine(x+4, bottom-2, right-1, bottom-2);
768  p->drawLine(x+3, bottom-3, right-1, bottom-3);
769  p->fillRect(x+2, y+2, r.width()-3, r.height()-6, cg.mid());
770  p->translate(0,1);
771  p->setPen(cg.dark());
772  p->drawLine(x, y, right, y);
773  }
774  break;
775  }
776 
777  case TQTabBar::TriangularAbove: {
778  if (!selected)
779  p->translate(0,1);
780  p->setPen(selected ? cg.light() : cg.shadow());
781  p->drawLine(x, bottom, x, y+6);
782  p->drawLine(x, y+6, x+6, y);
783  p->drawLine(x+6, y, right-6, y);
784  if (selected)
785  p->setPen(cg.mid());
786  p->drawLine(right-5, y+1, right-1, y+5);
787  p->setPen(cg.shadow());
788  p->drawLine(right, y+6, right, bottom);
789 
790  p->setPen(cg.midlight());
791  p->drawLine(x+1, bottom, x+1, y+6);
792  p->drawLine(x+1, y+6, x+6, y+1);
793  p->drawLine(x+6, y+1, right-6, y+1);
794  p->drawLine(right-5, y+2, right-2, y+5);
795  p->setPen(cg.mid());
796  p->drawLine(right-1, y+6, right-1, bottom);
797 
798  TQPointArray a(6);
799  a.setPoint(0, x+2, bottom);
800  a.setPoint(1, x+2, y+7);
801  a.setPoint(2, x+7, y+2);
802  a.setPoint(3, right-7, y+2);
803  a.setPoint(4, right-2, y+7);
804  a.setPoint(5, right-2, bottom);
805  p->setPen (selected ? cg.background() : cg.mid());
806  p->setBrush(selected ? cg.background() : cg.mid());
807  p->drawPolygon(a);
808  p->setBrush(NoBrush);
809  if (!selected) {
810  p->translate(0,-1);
811  p->setPen(cg.light());
812  p->drawLine(x, bottom, right, bottom);
813  }
814  break;
815  }
816 
817  default: { // TQTabBar::TriangularBelow
818  if (!selected)
819  p->translate(0,-1);
820  p->setPen(selected ? cg.light() : cg.shadow());
821  p->drawLine(x, y, x, bottom-6);
822  if (selected)
823  p->setPen(cg.mid());
824  p->drawLine(x, bottom-6, x+6, bottom);
825  if (selected)
826  p->setPen(cg.shadow());
827  p->drawLine(x+6, bottom, right-6, bottom);
828  p->drawLine(right-5, bottom-1, right-1, bottom-5);
829  if (!selected)
830  p->setPen(cg.shadow());
831  p->drawLine(right, bottom-6, right, y);
832 
833  p->setPen(cg.midlight());
834  p->drawLine(x+1, y, x+1, bottom-6);
835  p->drawLine(x+1, bottom-6, x+6, bottom-1);
836  p->drawLine(x+6, bottom-1, right-6, bottom-1);
837  p->drawLine(right-5, bottom-2, right-2, bottom-5);
838  p->setPen(cg.mid());
839  p->drawLine(right-1, bottom-6, right-1, y);
840 
841  TQPointArray a(6);
842  a.setPoint(0, x+2, y);
843  a.setPoint(1, x+2, bottom-7);
844  a.setPoint(2, x+7, bottom-2);
845  a.setPoint(3, right-7, bottom-2);
846  a.setPoint(4, right-2, bottom-7);
847  a.setPoint(5, right-2, y);
848  p->setPen (selected ? cg.background() : cg.mid());
849  p->setBrush(selected ? cg.background() : cg.mid());
850  p->drawPolygon(a);
851  p->setBrush(NoBrush);
852  if (!selected) {
853  p->translate(0,1);
854  p->setPen(cg.dark());
855  p->drawLine(x, y, right, y);
856  }
857  break;
858  }
859  };
860 
861  break;
862  }
863 
864  // Popup menu scroller
865  // ------------------------------------------------------------------------
866  case CE_PopupMenuScroller: {
867  p->fillRect(r, cg.background());
868  drawPrimitive(PE_ButtonTool, p, ceData, elementFlags, r, cg, Style_Enabled);
869  drawPrimitive((flags & Style_Up) ? PE_ArrowUp : PE_ArrowDown, p, ceData, elementFlags, r, cg, Style_Enabled);
870  break;
871  }
872 
873 
874  // PROGRESSBAR
875  // ------------------------------------------------------------------------
876  case CE_ProgressBarGroove: {
877  TQRect fr = subRect(SR_ProgressBarGroove, ceData, elementFlags, widget);
878  drawPrimitive(PE_Panel, p, ceData, elementFlags, fr, cg, Style_Sunken, TQStyleOption::SO_Default);
879  break;
880  }
881 
882  case CE_ProgressBarContents: {
883  // ### Take into account totalSteps() for busy indicator
884  TQRect cr = subRect(SR_ProgressBarContents, ceData, elementFlags, widget);
885  double progress = ceData.currentStep;
886  bool reverse = TQApplication::reverseLayout();
887  int steps = ceData.totalSteps;
888 
889  if (!cr.isValid())
890  return;
891 
892  // Draw progress bar
893  if (progress > 0 || steps == 0) {
894  double pg = (steps == 0) ? 0.1 : progress / steps;
895  int width = TQMIN(cr.width(), (int)(pg * cr.width()));
896  if (steps == 0) { //Busy indicator
897 
898  if (width < 1) width = 1; //A busy indicator with width 0 is kind of useless
899 
900  int remWidth = cr.width() - width; //Never disappear completely
901  if (remWidth <= 0) remWidth = 1; //Do something non-crashy when too small...
902 
903  int pstep = int(progress) % ( 2 * remWidth );
904 
905  if ( pstep > remWidth ) {
906  //Bounce about.. We're remWidth + some delta, we want to be remWidth - delta...
907  // - ( (remWidth + some delta) - 2* remWidth ) = - (some deleta - remWidth) = remWidth - some delta..
908  pstep = - (pstep - 2 * remWidth );
909  }
910 
911  if (reverse)
912  p->fillRect(cr.x() + cr.width() - width - pstep, cr.y(), width, cr.height(),
913  cg.brush(TQColorGroup::Highlight));
914  else
915  p->fillRect(cr.x() + pstep, cr.y(), width, cr.height(),
916  cg.brush(TQColorGroup::Highlight));
917 
918  return;
919  }
920 
921 
922  // Do fancy gradient for highcolor displays
923  if (d->highcolor) {
924  TQColor c(cg.highlight());
925  KPixmap pix;
926  pix.resize(cr.width(), cr.height());
927  KPixmapEffect::gradient(pix, reverse ? c.light(150) : c.dark(150),
928  reverse ? c.dark(150) : c.light(150),
929  KPixmapEffect::HorizontalGradient);
930  if (reverse)
931  p->drawPixmap(cr.x()+(cr.width()-width), cr.y(), pix,
932  cr.width()-width, 0, width, cr.height());
933  else
934  p->drawPixmap(cr.x(), cr.y(), pix, 0, 0, width, cr.height());
935  } else
936  if (reverse)
937  p->fillRect(cr.x()+(cr.width()-width), cr.y(), width, cr.height(),
938  cg.brush(TQColorGroup::Highlight));
939  else
940  p->fillRect(cr.x(), cr.y(), width, cr.height(),
941  cg.brush(TQColorGroup::Highlight));
942  }
943  break;
944  }
945 
946  case CE_ProgressBarLabel: {
947  TQRect cr = subRect(SR_ProgressBarContents, ceData, elementFlags, widget);
948  double progress = ceData.currentStep;
949  bool reverse = TQApplication::reverseLayout();
950  int steps = ceData.totalSteps;
951 
952  if (!cr.isValid())
953  return;
954 
955  TQFont font = p->font();
956  font.setBold(true);
957  p->setFont(font);
958 
959  // Draw label
960  if (progress > 0 || steps == 0) {
961  double pg = (steps == 0) ? 1.0 : progress / steps;
962  int width = TQMIN(cr.width(), (int)(pg * cr.width()));
963  TQRect crect;
964  if (reverse)
965  crect.setRect(cr.x()+(cr.width()-width), cr.y(), cr.width(), cr.height());
966  else
967  crect.setRect(cr.x()+width, cr.y(), cr.width(), cr.height());
968 
969  p->save();
970  p->setPen((elementFlags & CEF_IsEnabled) ? (reverse ? cg.text() : cg.highlightedText()) : cg.text());
971  p->drawText(r, AlignCenter, ceData.progressText);
972  p->setClipRect(crect);
973  p->setPen(reverse ? cg.highlightedText() : cg.text());
974  p->drawText(r, AlignCenter, ceData.progressText);
975  p->restore();
976 
977  } else {
978  p->setPen(cg.text());
979  p->drawText(r, AlignCenter, ceData.progressText);
980  }
981 
982  break;
983  }
984 
985  default:
986  TQCommonStyle::drawControl(element, p, ceData, elementFlags, r, cg, flags, opt, widget);
987  }
988 }
989 
990 
991 TQRect TDEStyle::subRect(SubRect r, const TQStyleControlElementData &ceData, const ControlElementFlags elementFlags, const TQWidget* widget) const
992 {
993  switch(r)
994  {
995  // KDE2 look smooth progress bar
996  // ------------------------------------------------------------------------
997  case SR_ProgressBarGroove:
998  return ceData.rect;
999 
1000  case SR_ProgressBarContents:
1001  case SR_ProgressBarLabel: {
1002  // ### take into account indicatorFollowsStyle()
1003  TQRect rt = ceData.rect;
1004  return TQRect(rt.x()+2, rt.y()+2, rt.width()-4, rt.height()-4);
1005  }
1006 
1007  default:
1008  return TQCommonStyle::subRect(r, ceData, elementFlags, widget);
1009  }
1010 }
1011 
1012 
1013 int TDEStyle::pixelMetric(PixelMetric m, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, const TQWidget* widget) const
1014 {
1015  switch(m)
1016  {
1017  // BUTTONS
1018  // ------------------------------------------------------------------------
1019  case PM_ButtonShiftHorizontal: // Offset by 1
1020  case PM_ButtonShiftVertical: // ### Make configurable
1021  return 1;
1022 
1023  case PM_DockWindowHandleExtent:
1024  {
1025  // Check that we are not a normal toolbar or a hidden dockwidget,
1026  // in which case we need to adjust the height for font size
1027  if (widget
1028  && !(ceData.parentWidgetData.widgetObjectTypes.contains(TQTOOLBAR_OBJECT_NAME_STRING))
1029  && !(ceData.parentWidgetData.widgetObjectTypes.contains(TQMAINWINDOW_OBJECT_NAME_STRING))
1030  && (ceData.widgetObjectTypes.contains(TQDOCKWINDOWHANDLE_OBJECT_NAME_STRING)) )
1031  return widget->fontMetrics().lineSpacing();
1032  else
1033  return TQCommonStyle::pixelMetric(m, ceData, elementFlags, widget);
1034  }
1035 
1036  // TABS
1037  // ------------------------------------------------------------------------
1038  case PM_TabBarTabHSpace:
1039  return 24;
1040 
1041  case PM_TabBarTabVSpace: {
1042  if ( ceData.tabBarData.shape == TQTabBar::RoundedAbove ||
1043  ceData.tabBarData.shape == TQTabBar::RoundedBelow )
1044  return 10;
1045  else
1046  return 4;
1047  }
1048 
1049  case PM_TabBarTabOverlap: {
1050  TQTabBar::Shape tbs = ceData.tabBarData.shape;
1051 
1052  if ( (tbs == TQTabBar::RoundedAbove) ||
1053  (tbs == TQTabBar::RoundedBelow) )
1054  return 0;
1055  else
1056  return 2;
1057  }
1058 
1059  // SLIDER
1060  // ------------------------------------------------------------------------
1061  case PM_SliderLength:
1062  return 18;
1063 
1064  case PM_SliderThickness:
1065  return 24;
1066 
1067  // Determines how much space to leave for the actual non-tickmark
1068  // portion of the slider.
1069  case PM_SliderControlThickness: {
1070  TQSlider::TickSetting ts = (TQSlider::TickSetting)ceData.tickMarkSetting;
1071  int thickness = (ceData.orientation == TQt::Horizontal) ?
1072  ceData.rect.height() : ceData.rect.width();
1073  switch (ts) {
1074  case TQSlider::NoMarks: // Use total area.
1075  break;
1076  case TQSlider::Both:
1077  thickness = (thickness/2) + 3; // Use approx. 1/2 of area.
1078  break;
1079  default: // Use approx. 2/3 of area
1080  thickness = ((thickness*2)/3) + 3;
1081  break;
1082  };
1083  return thickness;
1084  }
1085 
1086  // SPLITTER
1087  // ------------------------------------------------------------------------
1088  case PM_SplitterWidth:
1089  if (ceData.widgetObjectTypes.contains(TQDOCKWINDOWRESIZEHANDLE_OBJECT_NAME_STRING))
1090  return 8; // ### why do we need 2pix extra?
1091  else
1092  return 6;
1093 
1094  // FRAMES
1095  // ------------------------------------------------------------------------
1096  case PM_MenuBarFrameWidth:
1097  return 1;
1098 
1099  case PM_DockWindowFrameWidth:
1100  return 1;
1101 
1102  // GENERAL
1103  // ------------------------------------------------------------------------
1104  case PM_MaximumDragDistance:
1105  return -1;
1106 
1107  case PM_MenuBarItemSpacing:
1108  return 5;
1109 
1110  case PM_ToolBarItemSpacing:
1111  return 0;
1112 
1113  case PM_PopupMenuScrollerHeight:
1114  return pixelMetric( PM_ScrollBarExtent, ceData, elementFlags, 0);
1115 
1116  default:
1117  return TQCommonStyle::pixelMetric( m, ceData, elementFlags, widget );
1118  }
1119 }
1120 
1121 //Helper to find the next sibling that's not hidden
1122 static TQListViewItem* nextVisibleSibling(TQListViewItem* item)
1123 {
1124  TQListViewItem* sibling = item;
1125  do
1126  {
1127  sibling = sibling->nextSibling();
1128  }
1129  while (sibling && !sibling->isVisible());
1130 
1131  return sibling;
1132 }
1133 
1134 void TDEStyle::drawComplexControl( TQ_ComplexControl control,
1135  TQPainter* p,
1136  const TQStyleControlElementData &ceData,
1137  ControlElementFlags elementFlags,
1138  const TQRect &r,
1139  const TQColorGroup &cg,
1140  SFlags flags,
1141  SCFlags controls,
1142  SCFlags active,
1143  const TQStyleOption &opt,
1144  const TQWidget* widget ) const
1145 {
1146  switch(control)
1147  {
1148  // 3 BUTTON SCROLLBAR
1149  // ------------------------------------------------------------------------
1150  case CC_ScrollBar: {
1151  // Many thanks to Brad Hughes for contributing this code.
1152  bool useThreeButtonScrollBar = (d->scrollbarType & ThreeButtonScrollBar);
1153 
1154  bool maxedOut = (ceData.minSteps == ceData.maxSteps);
1155  bool horizontal = (ceData.orientation == TQt::Horizontal);
1156  SFlags sflags = ((horizontal ? Style_Horizontal : Style_Default) |
1157  (maxedOut ? Style_Default : Style_Enabled));
1158 
1159  TQRect addline, subline, subline2, addpage, subpage, slider, first, last;
1160  subline = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarSubLine, opt, widget);
1161  addline = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarAddLine, opt, widget);
1162  subpage = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarSubPage, opt, widget);
1163  addpage = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarAddPage, opt, widget);
1164  slider = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarSlider, opt, widget);
1165  first = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarFirst, opt, widget);
1166  last = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarLast, opt, widget);
1167  subline2 = addline;
1168 
1169  if ( useThreeButtonScrollBar ) {
1170  if (horizontal) {
1171  subline2.moveBy(-addline.width(), 0);
1172  }
1173  else {
1174  subline2.moveBy(0, -addline.height());
1175  }
1176  }
1177 
1178  // Draw the up/left button set
1179  if ((controls & SC_ScrollBarSubLine) && subline.isValid()) {
1180  drawPrimitive(PE_ScrollBarSubLine, p, ceData, elementFlags, subline, cg,
1181  sflags | (active == SC_ScrollBarSubLine ?
1182  Style_Down : Style_Default));
1183 
1184  if (useThreeButtonScrollBar && subline2.isValid())
1185  drawPrimitive(PE_ScrollBarSubLine, p, ceData, elementFlags, subline2, cg,
1186  sflags | (active == SC_ScrollBarSubLine ?
1187  Style_Down : Style_Default));
1188  }
1189 
1190  if ((controls & SC_ScrollBarAddLine) && addline.isValid())
1191  drawPrimitive(PE_ScrollBarAddLine, p, ceData, elementFlags, addline, cg,
1192  sflags | ((active == SC_ScrollBarAddLine) ?
1193  Style_Down : Style_Default));
1194 
1195  if ((controls & SC_ScrollBarSubPage) && subpage.isValid())
1196  drawPrimitive(PE_ScrollBarSubPage, p, ceData, elementFlags, subpage, cg,
1197  sflags | ((active == SC_ScrollBarSubPage) ?
1198  Style_Down : Style_Default));
1199 
1200  if ((controls & SC_ScrollBarAddPage) && addpage.isValid())
1201  drawPrimitive(PE_ScrollBarAddPage, p, ceData, elementFlags, addpage, cg,
1202  sflags | ((active == SC_ScrollBarAddPage) ?
1203  Style_Down : Style_Default));
1204 
1205  if ((controls & SC_ScrollBarFirst) && first.isValid())
1206  drawPrimitive(PE_ScrollBarFirst, p, ceData, elementFlags, first, cg,
1207  sflags | ((active == SC_ScrollBarFirst) ?
1208  Style_Down : Style_Default));
1209 
1210  if ((controls & SC_ScrollBarLast) && last.isValid())
1211  drawPrimitive(PE_ScrollBarLast, p, ceData, elementFlags, last, cg,
1212  sflags | ((active == SC_ScrollBarLast) ?
1213  Style_Down : Style_Default));
1214 
1215  if ((controls & SC_ScrollBarSlider) && slider.isValid()) {
1216  drawPrimitive(PE_ScrollBarSlider, p, ceData, elementFlags, slider, cg,
1217  sflags | ((active == SC_ScrollBarSlider) ?
1218  Style_Down : Style_Default));
1219  // Draw focus rect
1220  if (elementFlags & CEF_HasFocus) {
1221  TQRect fr(slider.x() + 2, slider.y() + 2,
1222  slider.width() - 5, slider.height() - 5);
1223  drawPrimitive(PE_FocusRect, p, ceData, elementFlags, fr, cg, Style_Default);
1224  }
1225  }
1226  break;
1227  }
1228 
1229 
1230  // SLIDER
1231  // -------------------------------------------------------------------
1232  case CC_Slider: {
1233  TQRect groove = querySubControlMetrics(CC_Slider, ceData, elementFlags, SC_SliderGroove, opt, widget);
1234  TQRect handle = querySubControlMetrics(CC_Slider, ceData, elementFlags, SC_SliderHandle, opt, widget);
1235 
1236  // Double-buffer slider for no flicker
1237  TQPixmap pix(ceData.rect.size());
1238  TQPainter p2;
1239  p2.begin(&pix);
1240 
1241  if ( (elementFlags & CEF_HasParentWidget) &&
1242  !ceData.parentWidgetData.bgPixmap.isNull() ) {
1243  TQPixmap pixmap = ceData.parentWidgetData.bgPixmap;
1244  p2.drawTiledPixmap(r, pixmap, ceData.pos);
1245  } else
1246  pix.fill(cg.background());
1247 
1248  // Draw slider groove
1249  if ((controls & SC_SliderGroove) && groove.isValid()) {
1250  drawTDEStylePrimitive( KPE_SliderGroove, &p2, ceData, elementFlags, groove, cg, flags, opt, widget );
1251 
1252  // Draw the focus rect around the groove
1253  if (elementFlags & CEF_HasFocus) {
1254  drawPrimitive(PE_FocusRect, &p2, ceData, elementFlags, groove, cg);
1255  }
1256  }
1257 
1258  // Draw the tickmarks
1259  if (controls & SC_SliderTickmarks)
1260  TQCommonStyle::drawComplexControl(control, &p2, ceData, elementFlags,
1261  r, cg, flags, SC_SliderTickmarks, active, opt, widget);
1262 
1263  // Draw the slider handle
1264  if ((controls & SC_SliderHandle) && handle.isValid()) {
1265  if (active == SC_SliderHandle)
1266  flags |= Style_Active;
1267  drawTDEStylePrimitive( KPE_SliderHandle, &p2, ceData, elementFlags, handle, cg, flags, opt, widget );
1268  }
1269 
1270  p2.end();
1271 
1272  TQPaintDevice* ppd = p->device();
1273  if (ppd->isExtDev()) {
1274  p->drawPixmap(0, 0, pix);
1275  }
1276  else {
1277  bitBlt((TQWidget*)widget, r.x(), r.y(), &pix);
1278  }
1279  break;
1280  }
1281 
1282  // LISTVIEW
1283  // -------------------------------------------------------------------
1284  case CC_ListView: {
1285 
1286  /*
1287  * Many thanks to TrollTech AS for donating CC_ListView from TQWindowsStyle.
1288  * CC_ListView code is Copyright (C) 1998-2000 TrollTech AS.
1289  */
1290 
1291  // Paint the icon and text.
1292  if ( controls & SC_ListView )
1293  TQCommonStyle::drawComplexControl( control, p, ceData, elementFlags, r, cg, flags, controls, active, opt, widget );
1294 
1295  // If we're have a branch or are expanded...
1296  if ( controls & (SC_ListViewBranch | SC_ListViewExpand) )
1297  {
1298  // If no list view item was supplied, break
1299  if (opt.isDefault())
1300  break;
1301 
1302  TQListViewItem *item = opt.listViewItem();
1303  TQListViewItem *child = item->firstChild();
1304 
1305  int y = r.y();
1306  int c; // dotline vertice count
1307  int dotoffset = 0;
1308  TQPointArray dotlines;
1309 
1310  if ( active == SC_All && controls == SC_ListViewExpand ) {
1311  // We only need to draw a vertical line
1312  c = 2;
1313  dotlines.resize(2);
1314  dotlines[0] = TQPoint( r.right(), r.top() );
1315  dotlines[1] = TQPoint( r.right(), r.bottom() );
1316 
1317  } else {
1318 
1319  int linetop = 0, linebot = 0;
1320  // each branch needs at most two lines, ie. four end points
1321  dotoffset = (item->itemPos() + item->height() - y) % 2;
1322  dotlines.resize( item->childCount() * 4 );
1323  c = 0;
1324 
1325  // skip the stuff above the exposed rectangle
1326  while ( child && y + child->height() <= 0 )
1327  {
1328  y += child->totalHeight();
1329  child = nextVisibleSibling(child);
1330  }
1331 
1332  int bx = r.width() / 2;
1333 
1334  // paint stuff in the magical area
1335  TQListView* v = item->listView();
1336  int lh = TQMAX( p->fontMetrics().height() + 2 * v->itemMargin(),
1337  TQApplication::globalStrut().height() );
1338  if ( lh % 2 > 0 )
1339  lh++;
1340 
1341  // Draw all the expand/close boxes...
1342  TQRect boxrect;
1343  TQStyle::StyleFlags boxflags;
1344  while ( child && y < r.height() )
1345  {
1346  linebot = y + lh/2;
1347  if ( (child->isExpandable() || child->childCount()) &&
1348  (child->height() > 0) )
1349  {
1350  // The primitive requires a rect.
1351  boxrect = TQRect( bx-4, linebot-4, 9, 9 );
1352  boxflags = child->isOpen() ? TQStyle::Style_Off : TQStyle::Style_On;
1353 
1354  // TDEStyle extension: Draw the box and expand/collapse indicator
1355  drawTDEStylePrimitive( KPE_ListViewExpander, p, ceData, elementFlags, boxrect, cg, boxflags, opt, NULL );
1356 
1357  // dotlinery
1358  p->setPen( cg.mid() );
1359  dotlines[c++] = TQPoint( bx, linetop );
1360  dotlines[c++] = TQPoint( bx, linebot - 5 );
1361  dotlines[c++] = TQPoint( bx + 5, linebot );
1362  dotlines[c++] = TQPoint( r.width(), linebot );
1363  linetop = linebot + 5;
1364  } else {
1365  // just dotlinery
1366  dotlines[c++] = TQPoint( bx+1, linebot );
1367  dotlines[c++] = TQPoint( r.width(), linebot );
1368  }
1369 
1370  y += child->totalHeight();
1371  child = nextVisibleSibling(child);
1372  }
1373 
1374  if ( child ) // there's a child to draw, so move linebot to edge of rectangle
1375  linebot = r.height();
1376 
1377  if ( linetop < linebot )
1378  {
1379  dotlines[c++] = TQPoint( bx, linetop );
1380  dotlines[c++] = TQPoint( bx, linebot );
1381  }
1382  }
1383 
1384  // Draw all the branches...
1385  static int thickness = kPixelMetric( KPM_ListViewBranchThickness, ceData, elementFlags );
1386  int line; // index into dotlines
1387  TQRect branchrect;
1388  TQStyle::StyleFlags branchflags;
1389  for( line = 0; line < c; line += 2 )
1390  {
1391  // assumptions here: lines are horizontal or vertical.
1392  // lines always start with the numerically lowest
1393  // coordinate.
1394 
1395  // point ... relevant coordinate of current point
1396  // end ..... same coordinate of the end of the current line
1397  // other ... the other coordinate of the current point/line
1398  if ( dotlines[line].y() == dotlines[line+1].y() )
1399  {
1400  // Horizontal branch
1401  int end = dotlines[line+1].x();
1402  int point = dotlines[line].x();
1403  int other = dotlines[line].y();
1404 
1405  branchrect = TQRect( point, other-(thickness/2), end-point, thickness );
1406  branchflags = TQStyle::Style_Horizontal;
1407 
1408  // TDEStyle extension: Draw the horizontal branch
1409  drawTDEStylePrimitive( KPE_ListViewBranch, p, ceData, elementFlags, branchrect, cg, branchflags, opt, NULL );
1410 
1411  } else {
1412  // Vertical branch
1413  int end = dotlines[line+1].y();
1414  int point = dotlines[line].y();
1415  int other = dotlines[line].x();
1416  int pixmapoffset = ((point & 1) != dotoffset ) ? 1 : 0;
1417 
1418  branchrect = TQRect( other-(thickness/2), point, thickness, end-point );
1419  if (!pixmapoffset) // ### Hackish - used to hint the offset
1420  branchflags = TQStyle::Style_NoChange;
1421  else
1422  branchflags = TQStyle::Style_Default;
1423 
1424  // TDEStyle extension: Draw the vertical branch
1425  drawTDEStylePrimitive( KPE_ListViewBranch, p, ceData, elementFlags, branchrect, cg, branchflags, opt, NULL );
1426  }
1427  }
1428  }
1429  break;
1430  }
1431 
1432  default:
1433  TQCommonStyle::drawComplexControl( control, p, ceData, elementFlags, r, cg,
1434  flags, controls, active, opt, widget );
1435  break;
1436  }
1437 }
1438 
1439 
1440 TQStyle::SubControl TDEStyle::querySubControl( TQ_ComplexControl control,
1441  const TQStyleControlElementData &ceData,
1442  ControlElementFlags elementFlags,
1443  const TQPoint &pos,
1444  const TQStyleOption &opt,
1445  const TQWidget* widget ) const
1446 {
1447  TQStyle::SubControl ret = TQCommonStyle::querySubControl(control, ceData, elementFlags, pos, opt, widget);
1448 
1449  if (d->scrollbarType == ThreeButtonScrollBar) {
1450  // Enable third button
1451  if (control == CC_ScrollBar && ret == SC_None)
1452  ret = SC_ScrollBarSubLine;
1453  }
1454  return ret;
1455 }
1456 
1457 
1458 TQRect TDEStyle::querySubControlMetrics( TQ_ComplexControl control,
1459  const TQStyleControlElementData &ceData,
1460  ControlElementFlags elementFlags,
1461  SubControl sc,
1462  const TQStyleOption &opt,
1463  const TQWidget* widget ) const
1464 {
1465  TQRect ret;
1466 
1467  if (control == CC_ScrollBar)
1468  {
1469  bool threeButtonScrollBar = d->scrollbarType & ThreeButtonScrollBar;
1470  bool platinumScrollBar = d->scrollbarType & PlatinumStyleScrollBar;
1471  bool nextScrollBar = d->scrollbarType & NextStyleScrollBar;
1472 
1473  bool horizontal = ceData.orientation == TQt::Horizontal;
1474  int sliderstart = ceData.startStep;
1475  int sbextent = pixelMetric(PM_ScrollBarExtent, ceData, elementFlags, widget);
1476  int maxlen = (horizontal ? ceData.rect.width() : ceData.rect.height())
1477  - (sbextent * (threeButtonScrollBar ? 3 : 2));
1478  int sliderlen;
1479 
1480  // calculate slider length
1481  if (ceData.maxSteps != ceData.minSteps)
1482  {
1483  uint range = ceData.maxSteps - ceData.minSteps;
1484  sliderlen = (ceData.pageStep * maxlen) / (range + ceData.pageStep);
1485 
1486  int slidermin = pixelMetric( PM_ScrollBarSliderMin, ceData, elementFlags, widget );
1487  if ( sliderlen < slidermin || range > INT_MAX / 2 )
1488  sliderlen = slidermin;
1489  if ( sliderlen > maxlen )
1490  sliderlen = maxlen;
1491  } else
1492  sliderlen = maxlen;
1493 
1494  // Subcontrols
1495  switch (sc)
1496  {
1497  case SC_ScrollBarSubLine: {
1498  // top/left button
1499  if (platinumScrollBar) {
1500  if (horizontal)
1501  ret.setRect(ceData.rect.width() - 2 * sbextent, 0, sbextent, sbextent);
1502  else
1503  ret.setRect(0, ceData.rect.height() - 2 * sbextent, sbextent, sbextent);
1504  } else
1505  ret.setRect(0, 0, sbextent, sbextent);
1506  break;
1507  }
1508 
1509  case SC_ScrollBarAddLine: {
1510  // bottom/right button
1511  if (nextScrollBar) {
1512  if (horizontal)
1513  ret.setRect(sbextent, 0, sbextent, sbextent);
1514  else
1515  ret.setRect(0, sbextent, sbextent, sbextent);
1516  } else {
1517  if (horizontal)
1518  ret.setRect(ceData.rect.width() - sbextent, 0, sbextent, sbextent);
1519  else
1520  ret.setRect(0, ceData.rect.height() - sbextent, sbextent, sbextent);
1521  }
1522  break;
1523  }
1524 
1525  case SC_ScrollBarSubPage: {
1526  // between top/left button and slider
1527  if (platinumScrollBar) {
1528  if (horizontal)
1529  ret.setRect(0, 0, sliderstart, sbextent);
1530  else
1531  ret.setRect(0, 0, sbextent, sliderstart);
1532  } else if (nextScrollBar) {
1533  if (horizontal)
1534  ret.setRect(sbextent*2, 0, sliderstart-2*sbextent, sbextent);
1535  else
1536  ret.setRect(0, sbextent*2, sbextent, sliderstart-2*sbextent);
1537  } else {
1538  if (horizontal)
1539  ret.setRect(sbextent, 0, sliderstart - sbextent, sbextent);
1540  else
1541  ret.setRect(0, sbextent, sbextent, sliderstart - sbextent);
1542  }
1543  break;
1544  }
1545 
1546  case SC_ScrollBarAddPage: {
1547  // between bottom/right button and slider
1548  int fudge;
1549 
1550  if (platinumScrollBar)
1551  fudge = 0;
1552  else if (nextScrollBar)
1553  fudge = 2*sbextent;
1554  else
1555  fudge = sbextent;
1556 
1557  if (horizontal)
1558  ret.setRect(sliderstart + sliderlen, 0,
1559  maxlen - sliderstart - sliderlen + fudge, sbextent);
1560  else
1561  ret.setRect(0, sliderstart + sliderlen, sbextent,
1562  maxlen - sliderstart - sliderlen + fudge);
1563  break;
1564  }
1565 
1566  case SC_ScrollBarGroove: {
1567  int multi = threeButtonScrollBar ? 3 : 2;
1568  int fudge;
1569 
1570  if (platinumScrollBar)
1571  fudge = 0;
1572  else if (nextScrollBar)
1573  fudge = 2*sbextent;
1574  else
1575  fudge = sbextent;
1576 
1577  if (horizontal)
1578  ret.setRect(fudge, 0, ceData.rect.width() - sbextent * multi, ceData.rect.height());
1579  else
1580  ret.setRect(0, fudge, ceData.rect.width(), ceData.rect.height() - sbextent * multi);
1581  break;
1582  }
1583 
1584  case SC_ScrollBarSlider: {
1585  if (horizontal)
1586  ret.setRect(sliderstart, 0, sliderlen, sbextent);
1587  else
1588  ret.setRect(0, sliderstart, sbextent, sliderlen);
1589  break;
1590  }
1591 
1592  default:
1593  ret = TQCommonStyle::querySubControlMetrics(control, ceData, elementFlags, sc, opt, widget);
1594  break;
1595  }
1596  } else
1597  ret = TQCommonStyle::querySubControlMetrics(control, ceData, elementFlags, sc, opt, widget);
1598 
1599  return ret;
1600 }
1601 
1602 static const char * const tdestyle_close_xpm[] = {
1603 "12 12 2 1",
1604 "# c #000000",
1605 ". c None",
1606 "............",
1607 "............",
1608 "..##....##..",
1609 "...##..##...",
1610 "....####....",
1611 ".....##.....",
1612 "....####....",
1613 "...##..##...",
1614 "..##....##..",
1615 "............",
1616 "............",
1617 "............"};
1618 
1619 static const char * const tdestyle_maximize_xpm[]={
1620 "12 12 2 1",
1621 "# c #000000",
1622 ". c None",
1623 "............",
1624 "............",
1625 ".##########.",
1626 ".##########.",
1627 ".#........#.",
1628 ".#........#.",
1629 ".#........#.",
1630 ".#........#.",
1631 ".#........#.",
1632 ".#........#.",
1633 ".##########.",
1634 "............"};
1635 
1636 
1637 static const char * const tdestyle_minimize_xpm[] = {
1638 "12 12 2 1",
1639 "# c #000000",
1640 ". c None",
1641 "............",
1642 "............",
1643 "............",
1644 "............",
1645 "............",
1646 "............",
1647 "............",
1648 "...######...",
1649 "...######...",
1650 "............",
1651 "............",
1652 "............"};
1653 
1654 static const char * const tdestyle_normalizeup_xpm[] = {
1655 "12 12 2 1",
1656 "# c #000000",
1657 ". c None",
1658 "............",
1659 "...#######..",
1660 "...#######..",
1661 "...#.....#..",
1662 ".#######.#..",
1663 ".#######.#..",
1664 ".#.....#.#..",
1665 ".#.....###..",
1666 ".#.....#....",
1667 ".#.....#....",
1668 ".#######....",
1669 "............"};
1670 
1671 
1672 static const char * const tdestyle_shade_xpm[] = {
1673 "12 12 2 1",
1674 "# c #000000",
1675 ". c None",
1676 "............",
1677 "............",
1678 "............",
1679 "............",
1680 "............",
1681 ".....#......",
1682 "....###.....",
1683 "...#####....",
1684 "..#######...",
1685 "............",
1686 "............",
1687 "............"};
1688 
1689 static const char * const tdestyle_unshade_xpm[] = {
1690 "12 12 2 1",
1691 "# c #000000",
1692 ". c None",
1693 "............",
1694 "............",
1695 "............",
1696 "............",
1697 "..#######...",
1698 "...#####....",
1699 "....###.....",
1700 ".....#......",
1701 "............",
1702 "............",
1703 "............",
1704 "............"};
1705 
1706 static const char * const dock_window_close_xpm[] = {
1707 "8 8 2 1",
1708 "# c #000000",
1709 ". c None",
1710 "##....##",
1711 ".##..##.",
1712 "..####..",
1713 "...##...",
1714 "..####..",
1715 ".##..##.",
1716 "##....##",
1717 "........"};
1718 
1719 // Message box icons, from page 210 of the Windows style guide.
1720 
1721 // Hand-drawn to resemble Microsoft's icons, but in the Mac/Netscape
1722 // palette. The "question mark" icon, which Microsoft recommends not
1723 // using but a lot of people still use, is left out.
1724 
1725 /* XPM */
1726 static const char * const information_xpm[]={
1727 "32 32 5 1",
1728 ". c None",
1729 "c c #000000",
1730 "* c #999999",
1731 "a c #ffffff",
1732 "b c #0000ff",
1733 "...........********.............",
1734 "........***aaaaaaaa***..........",
1735 "......**aaaaaaaaaaaaaa**........",
1736 ".....*aaaaaaaaaaaaaaaaaa*.......",
1737 "....*aaaaaaaabbbbaaaaaaaac......",
1738 "...*aaaaaaaabbbbbbaaaaaaaac.....",
1739 "..*aaaaaaaaabbbbbbaaaaaaaaac....",
1740 ".*aaaaaaaaaaabbbbaaaaaaaaaaac...",
1741 ".*aaaaaaaaaaaaaaaaaaaaaaaaaac*..",
1742 "*aaaaaaaaaaaaaaaaaaaaaaaaaaaac*.",
1743 "*aaaaaaaaaabbbbbbbaaaaaaaaaaac*.",
1744 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
1745 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
1746 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
1747 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
1748 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
1749 ".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
1750 ".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
1751 "..*aaaaaaaaaabbbbbaaaaaaaaac***.",
1752 "...caaaaaaabbbbbbbbbaaaaaac****.",
1753 "....caaaaaaaaaaaaaaaaaaaac****..",
1754 ".....caaaaaaaaaaaaaaaaaac****...",
1755 "......ccaaaaaaaaaaaaaacc****....",
1756 ".......*cccaaaaaaaaccc*****.....",
1757 "........***cccaaaac*******......",
1758 "..........****caaac*****........",
1759 ".............*caaac**...........",
1760 "...............caac**...........",
1761 "................cac**...........",
1762 ".................cc**...........",
1763 "..................***...........",
1764 "...................**..........."};
1765 /* XPM */
1766 static const char* const warning_xpm[]={
1767 "32 32 4 1",
1768 ". c None",
1769 "a c #ffff00",
1770 "* c #000000",
1771 "b c #999999",
1772 ".............***................",
1773 "............*aaa*...............",
1774 "...........*aaaaa*b.............",
1775 "...........*aaaaa*bb............",
1776 "..........*aaaaaaa*bb...........",
1777 "..........*aaaaaaa*bb...........",
1778 ".........*aaaaaaaaa*bb..........",
1779 ".........*aaaaaaaaa*bb..........",
1780 "........*aaaaaaaaaaa*bb.........",
1781 "........*aaaa***aaaa*bb.........",
1782 ".......*aaaa*****aaaa*bb........",
1783 ".......*aaaa*****aaaa*bb........",
1784 "......*aaaaa*****aaaaa*bb.......",
1785 "......*aaaaa*****aaaaa*bb.......",
1786 ".....*aaaaaa*****aaaaaa*bb......",
1787 ".....*aaaaaa*****aaaaaa*bb......",
1788 "....*aaaaaaaa***aaaaaaaa*bb.....",
1789 "....*aaaaaaaa***aaaaaaaa*bb.....",
1790 "...*aaaaaaaaa***aaaaaaaaa*bb....",
1791 "...*aaaaaaaaaa*aaaaaaaaaa*bb....",
1792 "..*aaaaaaaaaaa*aaaaaaaaaaa*bb...",
1793 "..*aaaaaaaaaaaaaaaaaaaaaaa*bb...",
1794 ".*aaaaaaaaaaaa**aaaaaaaaaaa*bb..",
1795 ".*aaaaaaaaaaa****aaaaaaaaaa*bb..",
1796 "*aaaaaaaaaaaa****aaaaaaaaaaa*bb.",
1797 "*aaaaaaaaaaaaa**aaaaaaaaaaaa*bb.",
1798 "*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
1799 "*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
1800 ".*aaaaaaaaaaaaaaaaaaaaaaaaa*bbbb",
1801 "..*************************bbbbb",
1802 "....bbbbbbbbbbbbbbbbbbbbbbbbbbb.",
1803 ".....bbbbbbbbbbbbbbbbbbbbbbbbb.."};
1804 /* XPM */
1805 static const char* const critical_xpm[]={
1806 "32 32 4 1",
1807 ". c None",
1808 "a c #999999",
1809 "* c #ff0000",
1810 "b c #ffffff",
1811 "...........********.............",
1812 ".........************...........",
1813 ".......****************.........",
1814 "......******************........",
1815 ".....********************a......",
1816 "....**********************a.....",
1817 "...************************a....",
1818 "..*******b**********b*******a...",
1819 "..******bbb********bbb******a...",
1820 ".******bbbbb******bbbbb******a..",
1821 ".*******bbbbb****bbbbb*******a..",
1822 "*********bbbbb**bbbbb*********a.",
1823 "**********bbbbbbbbbb**********a.",
1824 "***********bbbbbbbb***********aa",
1825 "************bbbbbb************aa",
1826 "************bbbbbb************aa",
1827 "***********bbbbbbbb***********aa",
1828 "**********bbbbbbbbbb**********aa",
1829 "*********bbbbb**bbbbb*********aa",
1830 ".*******bbbbb****bbbbb*******aa.",
1831 ".******bbbbb******bbbbb******aa.",
1832 "..******bbb********bbb******aaa.",
1833 "..*******b**********b*******aa..",
1834 "...************************aaa..",
1835 "....**********************aaa...",
1836 "....a********************aaa....",
1837 ".....a******************aaa.....",
1838 "......a****************aaa......",
1839 ".......aa************aaaa.......",
1840 ".........aa********aaaaa........",
1841 "...........aaaaaaaaaaa..........",
1842 ".............aaaaaaa............"};
1843 
1844 TQPixmap TDEStyle::stylePixmap( StylePixmap stylepixmap,
1845  const TQStyleControlElementData &ceData,
1846  ControlElementFlags elementFlags,
1847  const TQStyleOption& opt,
1848  const TQWidget* widget) const
1849 {
1850  switch (stylepixmap) {
1851  case SP_TitleBarShadeButton:
1852  return TQPixmap(const_cast<const char**>(tdestyle_shade_xpm));
1853  case SP_TitleBarUnshadeButton:
1854  return TQPixmap(const_cast<const char**>(tdestyle_unshade_xpm));
1855  case SP_TitleBarNormalButton:
1856  return TQPixmap(const_cast<const char**>(tdestyle_normalizeup_xpm));
1857  case SP_TitleBarMinButton:
1858  return TQPixmap(const_cast<const char**>(tdestyle_minimize_xpm));
1859  case SP_TitleBarMaxButton:
1860  return TQPixmap(const_cast<const char**>(tdestyle_maximize_xpm));
1861  case SP_TitleBarCloseButton:
1862  return TQPixmap(const_cast<const char**>(tdestyle_close_xpm));
1863  case SP_DockWindowCloseButton:
1864  return TQPixmap(const_cast<const char**>(dock_window_close_xpm ));
1865  case SP_MessageBoxInformation:
1866  return TQPixmap(const_cast<const char**>(information_xpm));
1867  case SP_MessageBoxWarning:
1868  return TQPixmap(const_cast<const char**>(warning_xpm));
1869  case SP_MessageBoxCritical:
1870  return TQPixmap(const_cast<const char**>(critical_xpm));
1871  default:
1872  break;
1873  }
1874  return TQCommonStyle::stylePixmap(stylepixmap, ceData, elementFlags, opt, widget);
1875 }
1876 
1877 
1878 int TDEStyle::styleHint( TQ_StyleHint sh, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags,
1879  const TQStyleOption &opt, TQStyleHintReturn* shr, const TQWidget* w) const
1880 {
1881  switch (sh)
1882  {
1883  case SH_EtchDisabledText:
1884  return d->etchDisabledText ? 1 : 0;
1885 
1886  case SH_PopupMenu_Scrollable:
1887  return d->scrollablePopupmenus ? 1 : 0;
1888 
1889  case SH_HideUnderlineAcceleratorWhenAltUp:
1890  return d->autoHideAccelerators ? 1 : 0;
1891 
1892  case SH_MenuBar_AltKeyNavigation:
1893  return d->menuAltKeyNavigation ? 1 : 0;
1894 
1895  case SH_PopupMenu_SubMenuPopupDelay:
1896  if ( styleHint( SH_PopupMenu_SloppySubMenus, ceData, elementFlags, TQStyleOption::Default, 0, w ) )
1897  return TQMIN( 100, d->popupMenuDelay );
1898  else
1899  return d->popupMenuDelay;
1900 
1901  case SH_PopupMenu_SloppySubMenus:
1902  return d->sloppySubMenus;
1903 
1904  case SH_ItemView_ChangeHighlightOnFocus:
1905  case SH_Slider_SloppyKeyEvents:
1906  case SH_MainWindow_SpaceBelowMenuBar:
1907  case SH_PopupMenu_AllowActiveAndDisabled:
1908  return 0;
1909 
1910  case SH_Slider_SnapToValue:
1911  case SH_PrintDialog_RightAlignButtons:
1912  case SH_FontDialog_SelectAssociatedText:
1913  case SH_MenuBar_MouseTracking:
1914  case SH_PopupMenu_MouseTracking:
1915  case SH_ComboBox_ListMouseTracking:
1916  case SH_ScrollBar_MiddleClickAbsolutePosition:
1917  return 1;
1918  case SH_LineEdit_PasswordCharacter:
1919  {
1920  if (w) {
1921  const TQFontMetrics &fm = w->fontMetrics();
1922  if (fm.inFont(TQChar(0x25CF))) {
1923  return 0x25CF;
1924  } else if (fm.inFont(TQChar(0x2022))) {
1925  return 0x2022;
1926  }
1927  }
1928  return '*';
1929  }
1930 
1931  default:
1932  return TQCommonStyle::styleHint(sh, ceData, elementFlags, opt, shr, w);
1933  }
1934 }
1935 
1936 
1937 bool TDEStyle::objectEventHandler( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void* source, TQEvent *event )
1938 {
1939  if (ceData.widgetObjectTypes.contains(TQOBJECT_OBJECT_NAME_STRING)) {
1940  TQObject* object = reinterpret_cast<TQObject*>(source);
1941  if ( d->useFilledFrameWorkaround )
1942  {
1943  // Make the QMenuBar/TQToolBar paintEvent() cover a larger area to
1944  // ensure that the filled frame contents are properly painted.
1945  // We essentially modify the paintEvent's rect to include the
1946  // panel border, which also paints the widget's interior.
1947  // This is nasty, but I see no other way to properly repaint
1948  // filled frames in all QMenuBars and QToolBars.
1949  // -- Karol.
1950  TQFrame *frame = 0;
1951  if ( event->type() == TQEvent::Paint
1952  && (frame = ::tqqt_cast<TQFrame*>(object)) )
1953  {
1954  if (frame->frameShape() != TQFrame::ToolBarPanel && frame->frameShape() != TQFrame::MenuBarPanel)
1955  return false;
1956 
1957  bool horizontal = true;
1958  TQPaintEvent* pe = (TQPaintEvent*)event;
1959  TQToolBar *toolbar = ::tqqt_cast< TQToolBar *>( frame );
1960  TQRect r = pe->rect();
1961 
1962  if (toolbar && toolbar->orientation() == Qt::Vertical)
1963  horizontal = false;
1964 
1965  if (horizontal) {
1966  if ( r.height() == frame->height() )
1967  return false; // Let TQFrame handle the painting now.
1968 
1969  // Else, send a new paint event with an updated paint rect.
1970  TQPaintEvent dummyPE( TQRect( r.x(), 0, r.width(), frame->height()) );
1971  TQApplication::sendEvent( frame, &dummyPE );
1972  }
1973  else { // Vertical
1974  if ( r.width() == frame->width() )
1975  return false;
1976 
1977  TQPaintEvent dummyPE( TQRect( 0, r.y(), frame->width(), r.height()) );
1978  TQApplication::sendEvent( frame, &dummyPE );
1979  }
1980 
1981  // Discard this event as we sent a new paintEvent.
1982  return true;
1983  }
1984  }
1985  }
1986 
1987  return false;
1988 }
1989 
1990 
1991 // -----------------------------------------------------------------------------
1992 // I N T E R N A L - TDEStyle menu transparency handler
1993 // -----------------------------------------------------------------------------
1994 
1995 TransparencyHandler::TransparencyHandler( TDEStyle* style,
1996  TransparencyEngine tEngine, float menuOpacity, bool useDropShadow )
1997  : TQObject()
1998 {
1999  te = tEngine;
2000  tdestyle = style;
2001  opacity = menuOpacity;
2002  dropShadow = useDropShadow;
2003  pix.setOptimization(TQPixmap::BestOptim);
2004 }
2005 
2006 TransparencyHandler::~TransparencyHandler()
2007 {
2008 }
2009 
2010 bool TransparencyHandler::haveX11RGBASupport()
2011 {
2012  // Simple way to determine if we have ARGB support
2013  if (TQPaintDevice::x11AppDepth() == 32) {
2014  return true;
2015  }
2016  else {
2017  return false;
2018  }
2019 }
2020 
2021 #define REAL_ALPHA_STRENGTH 255.0
2022 
2023 // This is meant to be ugly but fast.
2024 void TransparencyHandler::rightShadow(TQImage& dst)
2025 {
2026  bool have_composite = haveX11RGBASupport();
2027 
2028  if (dst.depth() != 32)
2029  dst = dst.convertDepth(32);
2030 
2031  // blend top-right corner.
2032  int pixels = dst.width() * dst.height();
2033 #ifdef WORDS_BIGENDIAN
2034  unsigned char* data = dst.bits() + 1; // Skip alpha
2035 #else
2036  unsigned char* data = dst.bits(); // Skip alpha
2037 #endif
2038  for(int i = 0; i < 16; i++) {
2039  if (have_composite) {
2040  data++;
2041  data++;
2042  data++;
2043  *data = (unsigned char)(REAL_ALPHA_STRENGTH*(1.0-top_right_corner[i])); data++;
2044  }
2045  else {
2046  *data = (unsigned char)((*data)*top_right_corner[i]); data++;
2047  *data = (unsigned char)((*data)*top_right_corner[i]); data++;
2048  *data = (unsigned char)((*data)*top_right_corner[i]); data++;
2049  data++; // skip alpha
2050  }
2051  }
2052 
2053  pixels -= 32; // tint right strip without rounded edges.
2054  int c = 0;
2055  for(int i = 0; i < pixels; i++) {
2056  if (have_composite) {
2057  data++;
2058  data++;
2059  data++;;
2060  *data = (unsigned char)(REAL_ALPHA_STRENGTH*(1.0-shadow_strip[c])); data++;
2061  }
2062  else {
2063  *data = (unsigned char)((*data)*shadow_strip[c]); data++;
2064  *data = (unsigned char)((*data)*shadow_strip[c]); data++;
2065  *data = (unsigned char)((*data)*shadow_strip[c]); data++;
2066  data++; // skip alpha
2067  }
2068  ++c;
2069  c %= 4;
2070  }
2071 
2072  // tint bottom edge
2073  for(int i = 0; i < 16; i++) {
2074  if (have_composite) {
2075  data++;
2076  data++;
2077  data++;
2078  *data = (unsigned char)(REAL_ALPHA_STRENGTH*(1.0-bottom_right_corner[i])); data++;
2079  }
2080  else {
2081  *data = (unsigned char)((*data)*bottom_right_corner[i]); data++;
2082  *data = (unsigned char)((*data)*bottom_right_corner[i]); data++;
2083  *data = (unsigned char)((*data)*bottom_right_corner[i]); data++;
2084  data++; // skip alpha
2085  }
2086  }
2087 }
2088 
2089 void TransparencyHandler::bottomShadow(TQImage& dst)
2090 {
2091  bool have_composite = haveX11RGBASupport();
2092 
2093  if (dst.depth() != 32)
2094  dst = dst.convertDepth(32);
2095 
2096  int line = 0;
2097  int width = dst.width() - 4;
2098  double strip_data = shadow_strip[0];
2099  double* corner = const_cast<double*>(bottom_left_corner);
2100 
2101 #ifdef WORDS_BIGENDIAN
2102  unsigned char* data = dst.bits() + 1; // Skip alpha
2103 #else
2104  unsigned char* data = dst.bits(); // Skip alpha
2105 #endif
2106 
2107  for(int y = 0; y < 4; y++)
2108  {
2109  // Bottom-left Corner
2110  for(int x = 0; x < 4; x++) {
2111  if (have_composite) {
2112  data++;
2113  data++;
2114  data++;
2115  *data = (unsigned char)(REAL_ALPHA_STRENGTH*(1.0-(*corner))); data++;
2116  }
2117  else {
2118  *data = (unsigned char)((*data)*(*corner)); data++;
2119  *data = (unsigned char)((*data)*(*corner)); data++;
2120  *data = (unsigned char)((*data)*(*corner)); data++;
2121  data++; // skip alpha
2122  }
2123  corner++;
2124  }
2125 
2126  // Scanline
2127  for(int x = 0; x < width; x++) {
2128  if (have_composite) {
2129  data++;
2130  data++;
2131  data++;
2132  *data = (unsigned char)(REAL_ALPHA_STRENGTH*(1.0-strip_data)); data++;
2133  }
2134  else {
2135  *data = (unsigned char)((*data)*strip_data); data++;
2136  *data = (unsigned char)((*data)*strip_data); data++;
2137  *data = (unsigned char)((*data)*strip_data); data++;
2138  data++; // skip alpha
2139  }
2140  }
2141 
2142  strip_data = shadow_strip[line++];
2143  }
2144 }
2145 
2146 TQImage TransparencyHandler::handleRealAlpha(TQImage img) {
2147  TQImage clearImage = img.convertDepth(32);
2148  clearImage.setAlphaBuffer(true);
2149 
2150  int w = clearImage.width();
2151  int h = clearImage.height();
2152 
2153  for (int y = 0; y < h; ++y) {
2154  TQRgb *ls = (TQRgb *)clearImage.scanLine( y );
2155  for (int x = 0; x < w; ++x) {
2156  ls[x] = tqRgba( 0, 0, 0, 0 );
2157  }
2158  }
2159 
2160  return clearImage;
2161 }
2162 
2163 // Create a shadow of thickness 4.
2164 void TransparencyHandler::createShadowWindows(const TQWidget* p)
2165 {
2166 #ifdef Q_WS_X11
2167  int x2 = p->x()+p->width();
2168  int y2 = p->y()+p->height();
2169  TQRect shadow1(x2, p->y() + 4, 4, p->height());
2170  TQRect shadow2(p->x() + 4, y2, p->width() - 4, 4);
2171 
2172  bool have_composite = haveX11RGBASupport();
2173 
2174  // Create a fake drop-down shadow effect via blended Xwindows
2175  ShadowElements se;
2176  se.w1 = new TQWidget(0, 0, (WFlags)(WStyle_Customize | WType_Popup | WX11BypassWM) );
2177  se.w2 = new TQWidget(0, 0, (WFlags)(WStyle_Customize | WType_Popup | WX11BypassWM) );
2178  se.w1->setGeometry(shadow1);
2179  se.w2->setGeometry(shadow2);
2180  XSelectInput(tqt_xdisplay(), se.w1->winId(), StructureNotifyMask );
2181  XSelectInput(tqt_xdisplay(), se.w2->winId(), StructureNotifyMask );
2182 
2183  // Insert a new ShadowMap entry
2184  shadowMap()[p] = se;
2185 
2186  // Some hocus-pocus here to create the drop-shadow.
2187  TQPixmap pix_shadow1;
2188  TQPixmap pix_shadow2;
2189  if (have_composite) {
2190  pix_shadow1 = TQPixmap(shadow1.width(), shadow1.height());
2191  pix_shadow2 = TQPixmap(shadow2.width(), shadow2.height());
2192  }
2193  else {
2194  pix_shadow1 = TQPixmap::grabWindow(tqt_xrootwin(),
2195  shadow1.x(), shadow1.y(), shadow1.width(), shadow1.height());
2196  pix_shadow2 = TQPixmap::grabWindow(tqt_xrootwin(),
2197  shadow2.x(), shadow2.y(), shadow2.width(), shadow2.height());
2198  }
2199 
2200  TQImage img;
2201  img = pix_shadow1.convertToImage();
2202  if (have_composite) img = handleRealAlpha(img);
2203  rightShadow(img);
2204  pix_shadow1.convertFromImage(img);
2205  img = pix_shadow2.convertToImage();
2206  if (have_composite) img = handleRealAlpha(img);
2207  bottomShadow(img);
2208  pix_shadow2.convertFromImage(img);
2209 
2210  // Set the background pixmaps
2211  se.w1->setErasePixmap(pix_shadow1);
2212  se.w2->setErasePixmap(pix_shadow2);
2213 
2214  // Show the 'shadow' just before showing the popup menu window
2215  // Don't use TQWidget::show() so we don't confuse QEffects, thus causing broken focus.
2216  XMapWindow(tqt_xdisplay(), se.w1->winId());
2217  XMapWindow(tqt_xdisplay(), se.w2->winId());
2218 #else
2219  Q_UNUSED( p )
2220 #endif
2221 }
2222 
2223 void TransparencyHandler::removeShadowWindows(const TQWidget* p)
2224 {
2225 #ifdef Q_WS_X11
2226  ShadowMap::iterator it = shadowMap().find(p);
2227  if (it != shadowMap().end())
2228  {
2229  ShadowElements se = it.data();
2230  XUnmapWindow(tqt_xdisplay(), se.w1->winId()); // hide
2231  XUnmapWindow(tqt_xdisplay(), se.w2->winId());
2232  XFlush(tqt_xdisplay()); // try to hide faster
2233  delete se.w1;
2234  delete se.w2;
2235  shadowMap().erase(it);
2236  }
2237 #else
2238  Q_UNUSED( p )
2239 #endif
2240 }
2241 
2242 bool TransparencyHandler::eventFilter( TQObject* object, TQEvent* event )
2243 {
2244 #if !defined Q_WS_MAC && !defined Q_WS_WIN
2245  // Transparency idea was borrowed from KDE2's "MegaGradient" Style,
2246  // Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org>
2247 
2248  // Added 'fake' menu shadows <04-Jul-2002> -- Karol
2249  TQWidget* p = (TQWidget*)object;
2250  TQEvent::Type et = event->type();
2251 
2252  if (et == TQEvent::Show)
2253  {
2254  // Handle translucency
2255  if (te != Disabled)
2256  {
2257  pix = TQPixmap::grabWindow(tqt_xrootwin(),
2258  p->x(), p->y(), p->width(), p->height());
2259 
2260  switch (te) {
2261 #ifdef HAVE_XRENDER
2262  case XRender:
2263  if (tqt_use_xrender) {
2264  XRenderBlendToPixmap(p);
2265  break;
2266  }
2267  // Fall through intended
2268 #else
2269  case XRender:
2270 #endif
2271  case SoftwareBlend:
2272  blendToPixmap(p->colorGroup(), p);
2273  break;
2274 
2275  case SoftwareTint:
2276  default:
2277  blendToColor(p->colorGroup().button());
2278  };
2279 
2280  p->setErasePixmap(pix);
2281  }
2282 
2283  // Handle drop shadow
2284  // * FIXME : !shadowMap().contains(p) is a workaround for leftover
2285  // * shadows after duplicate show events.
2286  // * TODO : determine real cause for duplicate events
2287  // * till 20021005
2288  if ((dropShadow || useDropShadow(p))
2289  && p->width() > 16 && p->height() > 16 && !shadowMap().contains( p ))
2290  createShadowWindows(p);
2291  }
2292  else if (et == TQEvent::Resize && p->isShown() && p->isTopLevel())
2293  {
2294  // Handle drop shadow
2295  if (dropShadow || useDropShadow(p))
2296  {
2297  removeShadowWindows(p);
2298  createShadowWindows(p);
2299  }
2300  }
2301  else if (et == TQEvent::Hide)
2302  {
2303  // Handle drop shadow
2304  if (dropShadow || useDropShadow(p))
2305  removeShadowWindows(p);
2306 
2307  // Handle translucency
2308  if (te != Disabled)
2309  p->setErasePixmap(TQPixmap());
2310  }
2311 
2312 #endif
2313  return false;
2314 }
2315 
2316 
2317 // Blends a TQImage to a predefined color, with a given opacity.
2318 void TransparencyHandler::blendToColor(const TQColor &col)
2319 {
2320  if (opacity < 0.0 || opacity > 1.0)
2321  return;
2322 
2323  TQImage img = pix.convertToImage();
2324  KImageEffect::blend(col, img, opacity);
2325  pix.convertFromImage(img);
2326 }
2327 
2328 
2329 void TransparencyHandler::blendToPixmap(const TQColorGroup &cg, const TQWidget* p)
2330 {
2331  if (opacity < 0.0 || opacity > 1.0)
2332  return;
2333 
2334  KPixmap blendPix;
2335  blendPix.resize( pix.width(), pix.height() );
2336 
2337  if (blendPix.width() != pix.width() ||
2338  blendPix.height() != pix.height())
2339  return;
2340 
2341  // Allow styles to define the blend pixmap - allows for some interesting effects.
2342  if (::tqqt_cast<TQPopupMenu*>(p))
2343  tdestyle->renderMenuBlendPixmap( blendPix, cg, ::tqqt_cast<TQPopupMenu*>(p) );
2344  else
2345  blendPix.fill(cg.button()); // Just tint as the default behavior
2346 
2347  TQImage blendImg = blendPix.convertToImage();
2348  TQImage backImg = pix.convertToImage();
2349  KImageEffect::blend(blendImg, backImg, opacity);
2350  pix.convertFromImage(backImg);
2351 }
2352 
2353 
2354 #ifdef HAVE_XRENDER
2355 // Here we go, use XRender in all its glory.
2356 // NOTE: This is actually a bit slower than the above routines
2357 // on non-accelerated displays. -- Karol.
2358 void TransparencyHandler::XRenderBlendToPixmap(const TQWidget* p)
2359 {
2360  KPixmap renderPix;
2361  renderPix.resize( pix.width(), pix.height() );
2362 
2363  // Allow styles to define the blend pixmap - allows for some interesting effects.
2364  if (::tqqt_cast<TQPopupMenu*>(p))
2365  tdestyle->renderMenuBlendPixmap( renderPix, p->colorGroup(),
2366  ::tqqt_cast<TQPopupMenu*>(p) );
2367  else
2368  renderPix.fill(p->colorGroup().button()); // Just tint as the default behavior
2369 
2370  Display* dpy = tqt_xdisplay();
2371  Pixmap alphaPixmap;
2372  Picture alphaPicture;
2373  XRenderPictFormat Rpf;
2374  XRenderPictureAttributes Rpa;
2375  XRenderColor clr;
2376  clr.alpha = ((unsigned short)(255*opacity) << 8);
2377 
2378  Rpf.type = PictTypeDirect;
2379  Rpf.depth = 8;
2380  Rpf.direct.alphaMask = 0xff;
2381  Rpa.repeat = True; // Tile
2382 
2383  XRenderPictFormat* xformat = XRenderFindFormat(dpy,
2384  PictFormatType | PictFormatDepth | PictFormatAlphaMask, &Rpf, 0);
2385 
2386  alphaPixmap = XCreatePixmap(dpy, p->handle(), 1, 1, 8);
2387  alphaPicture = XRenderCreatePicture(dpy, alphaPixmap, xformat, CPRepeat, &Rpa);
2388 
2389  XRenderFillRectangle(dpy, PictOpSrc, alphaPicture, &clr, 0, 0, 1, 1);
2390 
2391  XRenderComposite(dpy, PictOpOver,
2392  renderPix.x11RenderHandle(), alphaPicture, pix.x11RenderHandle(), // src, mask, dst
2393  0, 0, // srcx, srcy
2394  0, 0, // maskx, masky
2395  0, 0, // dstx, dsty
2396  pix.width(), pix.height());
2397 
2398  XRenderFreePicture(dpy, alphaPicture);
2399  XFreePixmap(dpy, alphaPixmap);
2400 }
2401 #endif
2402 
2403 void TDEStyle::virtual_hook( int, void* )
2404 { /*BASE::virtual_hook( id, data );*/ }
2405 
2406 // HACK for gtk-qt-engine
2407 
2408 extern "C" KDE_EXPORT
2409 void kde_tdestyle_set_scrollbar_type_windows( void* style )
2410 {
2411  ((TDEStyle*)style)->setScrollBarType( TDEStyle::WindowsStyleScrollBar );
2412 }
2413 #include "tdestyle.moc"
TDEStyle::WindowsStyleScrollBar
two button, windows style
Definition: tdestyle.h:111
TDEStyle::~TDEStyle
~TDEStyle()
Destructs the TDEStyle object.
Definition: tdestyle.cpp:244
KPixmap
Off-screen paint device with extended features.
Definition: kpixmap.h:57
TDEStyle::FilledFrameWorkaround
Filled frames enabled.
Definition: tdestyle.h:84
TDEStyle::TDEStylePrimitive
TDEStylePrimitive
TDEStyle Primitive Elements:
Definition: tdestyle.h:228
TDEStyle::AllowMenuTransparency
Internal transparency enabled.
Definition: tdestyle.h:83
TDEStyle::ThreeButtonScrollBar
three buttons, KDE style
Definition: tdestyle.h:113
KPixmapEffect::gradient
static KPixmap & gradient(KPixmap &pixmap, const TQColor &ca, const TQColor &cb, GradientType type, int ncols=3)
Creates a gradient from color a to color b of the specified type.
Definition: kpixmapeffect.cpp:24
TDEStyle
Simplifies and extends the TQStyle API to make style coding easier.
Definition: tdestyle.h:57
TDEStdAccel::end
const TDEShortcut & end()
TDEStyle::PlatinumStyleScrollBar
two button, platinum style
Definition: tdestyle.h:112
TDEStyle::defaultStyle
static TQString defaultStyle()
Returns the default widget style depending on color depth.
Definition: tdestyle.cpp:256
TDEStyle::TDEStyleFlags
uint TDEStyleFlags
TDEStyle Flags:
Definition: tdestyle.h:80
TDEStyle::TDEStyle
TDEStyle(TDEStyleFlags flags=TDEStyle::Default, TDEStyleScrollBarType sbtype=TDEStyle::WindowsStyleScrollBar)
Constructs a TDEStyle object.
Definition: tdestyle.cpp:189
TDEStyle::renderMenuBlendPixmap
virtual void renderMenuBlendPixmap(KPixmap &pix, const TQColorGroup &cg, const TQPopupMenu *popup) const
This virtual function defines the pixmap used to blend between the popup menu and the background to c...
Definition: tdestyle.cpp:340
TDEStyle::NextStyleScrollBar
two button, NeXT style
Definition: tdestyle.h:114
TDEStyle::styleFlags
TDEStyleFlags styleFlags() const
Returns the TDEStyle flags used to initialize the style.
Definition: tdestyle.cpp:335
KImageEffect::blend
static TQImage & blend(const TQColor &clr, TQImage &dst, float opacity)
Blends a color into the destination image, using an opacity value for blending one into another...
Definition: kimageeffect.cpp:1067
TDEStyle::setScrollBarType
void setScrollBarType(TDEStyleScrollBarType sbtype)
Modifies the scrollbar type used by the style.
Definition: tdestyle.cpp:330
TDEStyle::TDEStyleScrollBarType
TDEStyleScrollBarType
TDEStyle ScrollBarType:
Definition: tdestyle.h:110

tdefx

Skip menu "tdefx"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdefx

Skip menu "tdefx"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdefx by doxygen 1.8.8
This website is maintained by Timothy Pearson.