TDE core libraries
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

3367 lines
93KB

  1. /*
  2. Copyright (c) 2000 KDE Project
  3. Permission is hereby granted, free of charge, to any person obtaining a
  4. copy of this software and associated documentation files (the "Software"),
  5. to deal in the Software without restriction, including without limitation
  6. the rights to use, copy, modify, merge, publish, distribute, sublicense,
  7. and/or sell copies of the Software, and to permit persons to whom the
  8. Software is furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  14. THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  16. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. DEALINGS IN THE SOFTWARE.
  18. */
  19. #include "klegacystyle.h"
  20. #include "klegacystyle.moc"
  21. #include <tdelocale.h>
  22. #include <kiconloader.h>
  23. #define INCLUDE_MENUITEM_DEF
  24. #include <tqapplication.h>
  25. #include <tqbitmap.h>
  26. #include <tqbuttongroup.h>
  27. #include <tqcanvas.h>
  28. #include <tqcheckbox.h>
  29. #include <tqcolor.h>
  30. #include <tqcolordialog.h>
  31. #include <tqcombobox.h>
  32. #include <tqdial.h>
  33. #include <tqdialog.h>
  34. #include <tqdict.h>
  35. #include <tqfile.h>
  36. #include <tqfiledialog.h>
  37. #include <tqfileinfo.h>
  38. #include <tqfont.h>
  39. #include <tqfontdialog.h>
  40. #include <tqframe.h>
  41. #include <tqguardedptr.h>
  42. #include <tqgrid.h>
  43. #include <tqgroupbox.h>
  44. #include <tqhbox.h>
  45. #include <tqhbuttongroup.h>
  46. #include <tqheader.h>
  47. #include <tqhgroupbox.h>
  48. #include <tqiconview.h>
  49. #include <tqimage.h>
  50. #include <tqinputdialog.h>
  51. #include <tqintdict.h>
  52. #include <tqlabel.h>
  53. #include <tqlayout.h>
  54. #include <tqlcdnumber.h>
  55. #include <tqlineedit.h>
  56. #include <tqptrlist.h>
  57. #include <tqlistbox.h>
  58. #include <tqlistview.h>
  59. #include <tqmainwindow.h>
  60. #include <tqmenubar.h>
  61. #include <tqmenudata.h>
  62. #include <tqmessagebox.h>
  63. #include <tqmultilineedit.h>
  64. #include <tqobjectlist.h>
  65. #include <tqpainter.h>
  66. #include <tqpixmap.h>
  67. #include <tqpixmapcache.h>
  68. #include <tqpopupmenu.h>
  69. #include <tqprintdialog.h>
  70. #include <tqprogressbar.h>
  71. #include <tqprogressdialog.h>
  72. #include <tqpushbutton.h>
  73. #include <tqradiobutton.h>
  74. #include <tqregexp.h>
  75. #include <tqscrollbar.h>
  76. #include <tqscrollview.h>
  77. #include <tqsemimodal.h>
  78. #include <tqsizegrip.h>
  79. #include <tqslider.h>
  80. #include <tqspinbox.h>
  81. #include <tqsplitter.h>
  82. #include <tqstatusbar.h>
  83. #include <tqstring.h>
  84. #include <tqtabbar.h>
  85. #include <tqtabdialog.h>
  86. #include <qtableview.h>
  87. #include <tqtabwidget.h>
  88. #include <tqtextbrowser.h>
  89. #include <tqtextstream.h>
  90. #include <tqtextview.h>
  91. #include <tqtoolbar.h>
  92. #include <tqtoolbutton.h>
  93. #include <tqtooltip.h>
  94. #include <tqvbox.h>
  95. #include <tqvbuttongroup.h>
  96. #include <tqvgroupbox.h>
  97. #include <tqwidget.h>
  98. #include <tqwidgetstack.h>
  99. #include <tqwizard.h>
  100. #include <tqworkspace.h>
  101. #include <stdlib.h>
  102. #include <unistd.h>
  103. #include <limits.h>
  104. #include <sys/types.h>
  105. // forward declaration of classes
  106. class KLegacyBorder;
  107. class KLegacyStyleData;
  108. class KLegacyImageData;
  109. class GtkObject;
  110. // declaration of hidden functions
  111. typedef void (TQStyle::*QDrawMenuBarItemImpl) (TQPainter *, int, int, int, int,
  112. TQMenuItem *, TQColorGroup &, bool, bool);
  113. extern QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl impl);
  114. // the addresses of the integers are used to place things in the
  115. // style data dict
  116. static int listviewitem_ptr = 0;
  117. static int listboxitem_ptr = 1;
  118. static int menuitem_ptr = 2;
  119. static int separator_ptr = 3;
  120. static int arrow_ptr = 4;
  121. static int whatsthis_ptr = 5;
  122. static int checkmenuitem_ptr = 6;
  123. static int radiomenuitem_ptr = 7;
  124. static int eventbox_ptr = 8;
  125. // a TQImage cache, since we need to resize some images to different sizes, we
  126. // will cache them, to save the overhead of loading the image from disk each
  127. // time it's needed
  128. static const int imageCacheSize = 61;
  129. static TQDict<TQImage> *imageCache = 0;
  130. class KLegacy {
  131. public:
  132. enum Function { Box = 1, FlatBox, Extension, Check, Option,
  133. HLine, VLine, BoxGap, Slider, Tab, Arrow, Handle, FShadow, Focus };
  134. enum State { Normal = 1, Prelight, Active, Insensitive, Selected };
  135. enum Shadow { NoShadow = 0, In, Out, EtchedIn, EtchedOut };
  136. enum GapSide { Left = 1, Right, Top, Bottom };
  137. };
  138. class KLegacyBorder : public KLegacy {
  139. private:
  140. int l, r, t, b;
  141. public:
  142. KLegacyBorder(int ll = 0, int rr = 0, int tt = 0, int bb = 0)
  143. : l(ll), r(rr), t(tt), b(bb)
  144. { }
  145. KLegacyBorder(const KLegacyBorder &br)
  146. : l(br.l), r(br.r), t(br.t), b(br.b)
  147. { }
  148. inline int left(void) const
  149. { return l; }
  150. inline int right(void) const
  151. { return r; }
  152. inline int top(void) const
  153. { return t; }
  154. inline int bottom(void) const
  155. { return b; }
  156. inline void setLeft(int ll)
  157. { l = ll; }
  158. inline void setRight(int rr)
  159. { r = rr; }
  160. inline void setTop(int tt)
  161. { t = tt; }
  162. inline void setBottom(int bb)
  163. { b = bb; }
  164. };
  165. struct KLegacyImageDataKeyField {
  166. TQ_INT8 function : 8;
  167. TQ_INT8 state : 8;
  168. TQ_INT8 shadow : 4;
  169. TQ_INT8 orientation : 4;
  170. TQ_INT8 arrowDirection : 4;
  171. TQ_INT8 gapSide : 4;
  172. };
  173. union KLegacyImageDataKey {
  174. KLegacyImageDataKeyField data;
  175. long cachekey;
  176. };
  177. class KLegacyImageData : public KLegacy {
  178. public:
  179. KLegacyImageDataKey key;
  180. TQString file;
  181. TQString detail;
  182. TQString overlayFile;
  183. TQString gapFile;
  184. TQString gapStartFile;
  185. TQString gapEndFile;
  186. KLegacyBorder border;
  187. KLegacyBorder overlayBorder;
  188. KLegacyBorder gapBorder;
  189. KLegacyBorder gapStartBorder;
  190. KLegacyBorder gapEndBorder;
  191. bool recolorable;
  192. bool stretch;
  193. bool overlayStretch;
  194. KLegacyImageData()
  195. : recolorable(false),
  196. stretch(false),
  197. overlayStretch(false)
  198. { key.cachekey = 0; }
  199. };
  200. class KLegacyStyleData : public KLegacy {
  201. public:
  202. // name of this style
  203. TQString name;
  204. // font to use
  205. TQFont *fn;
  206. // list of image datas (which tell us how to draw things)
  207. QList<KLegacyImageData> imageList;
  208. // background, foreground and base colors for the 5 widget
  209. //states that Gtk defines
  210. TQColor back[5], fore[5], base[5];
  211. // reference count
  212. int ref;
  213. KLegacyStyleData()
  214. : fn(0), ref(0)
  215. {
  216. // have the imageList delete the items it holds when it's deleted
  217. imageList.setAutoDelete(true);
  218. }
  219. };
  220. class GtkObject : public TQObject {
  221. private:
  222. KLegacyStyleData *d;
  223. friend class KLegacyStylePrivate;
  224. public:
  225. GtkObject(GtkObject *parent, const char *name)
  226. : TQObject(parent, name)
  227. { d = 0; }
  228. GtkObject *find(TQRegExp &) const;
  229. TQColor backColor(KLegacy::State);
  230. TQColor baseColor(KLegacy::State);
  231. TQColor foreColor(KLegacy::State);
  232. TQFont *font();
  233. inline TQString styleName()
  234. { return styleData()->name; }
  235. KLegacyStyleData *styleData();
  236. KLegacyImageData *getImageData(KLegacyImageDataKey,
  237. const TQString & = TQString::null);
  238. TQPixmap *draw(KLegacyImageDataKey, int, int, const TQString & = TQString::null);
  239. TQPixmap *draw(KLegacyImageData *, int, int);
  240. };
  241. static TQPixmap *drawImage(TQImage *image, int width, int height,
  242. KLegacyBorder border, bool scale)
  243. {
  244. if ((! image) || (image->isNull()) || (width < 1) || (height < 1)) {
  245. return (TQPixmap *) 0;
  246. }
  247. TQPixmap *pixmap = new TQPixmap(width, height);
  248. if (scale) {
  249. if (width < 2) width = 2;
  250. if (height < 2) height = 2;
  251. int x[3], y[3], w[3], h[3], x2[3], y2[3], w2[3], h2[3];
  252. // left
  253. x[0] = x2[0] = 0;
  254. w[0] = (border.left() < 1) ? 1 : border.left();
  255. // middle
  256. x[1] = border.left();
  257. w[1] = image->width() - border.left() - border.right();
  258. if (w[1] < 1) w[1] = 1;
  259. // right
  260. x[2] = image->width() - border.right();
  261. w[2] = (border.right() < 1) ? 1 : border.right();
  262. if (x[2] < 0) x[2] = 0;
  263. if ((border.left() + border.right()) > width) {
  264. // left
  265. x2[0] = 0;
  266. w2[0] = (width / 2) + 1;
  267. // middle
  268. x2[1] = w2[0] - 1;
  269. w2[1] = 1;
  270. // right
  271. x2[2] = x2[1];
  272. w2[2] = w2[0];
  273. } else {
  274. // left
  275. x2[0] = 0;
  276. w2[0] = border.left();
  277. // middle
  278. x2[1] = w2[0];
  279. w2[1] = width - border.left() - border.right() + 1;
  280. // right
  281. x2[2] = width - border.right();
  282. w2[2] = border.right();
  283. }
  284. // top
  285. y[0] = 0;
  286. h[0] = (border.top() < 1) ? 1 : border.top();
  287. // middle
  288. y[1] = border.top();
  289. h[1] = image->height() - border.top() - border.bottom();
  290. if (h[1] < 1) h[1] = 1;
  291. // bottom
  292. y[2] = image->height() - border.bottom();
  293. h[2] = (border.bottom() < 1) ? 1 : border.bottom();
  294. if (y[2] < 0) y[2] = 0;
  295. if ((border.top() + border.bottom()) > height) {
  296. // left
  297. y2[0] = 0;
  298. h2[0] = height / 2;
  299. // middle
  300. y2[1] = h2[0];
  301. h2[1] = 1;
  302. // right
  303. y2[2] = y2[1];
  304. h2[2] = h2[0];
  305. } else {
  306. // left
  307. y2[0] = 0;
  308. h2[0] = border.top();
  309. // middle
  310. y2[1] = h2[0];
  311. h2[1] = height - border.top() - border.bottom() + 1;
  312. // bottom
  313. y2[2] = height - border.bottom();
  314. h2[2] = border.bottom();
  315. }
  316. // draw the image
  317. bool mask = image->hasAlphaBuffer();
  318. TQBitmap bm(width, height);
  319. bm.fill(Qt::color1);
  320. TQImage nimage[3][3];
  321. int xx = -1, yy = -1;
  322. while (++yy < 3) {
  323. xx = -1;
  324. while (++xx < 3) {
  325. nimage[yy][xx] = image->copy(x[xx], y[yy], w[xx], h[yy]);
  326. if (nimage[yy][xx].isNull()) continue;
  327. if ((w[xx] != w2[xx]) || (h[yy] != h2[yy]))
  328. nimage[yy][xx] = nimage[yy][xx].smoothScale(w2[xx], h2[yy]);
  329. if (nimage[yy][xx].isNull()) continue;
  330. bitBlt(pixmap, x2[xx], y2[yy], &nimage[yy][xx],
  331. 0, 0, w2[xx], h2[yy], Qt::CopyROP);
  332. if (mask) {
  333. TQImage am = nimage[yy][xx].createAlphaMask();
  334. bitBlt(&bm, x2[xx], y2[yy], &am,
  335. 0, 0, w2[xx], h2[yy], Qt::CopyROP);
  336. }
  337. }
  338. }
  339. if (mask)
  340. pixmap->setMask(bm);
  341. } else {
  342. for (int y = 0; y < height; y += image->height())
  343. for (int x = 0; x < width; x += image->width())
  344. bitBlt(pixmap, x, y, image, 0, 0, -1, -1, Qt::CopyROP);
  345. if (image->hasAlphaBuffer()) {
  346. TQImage mask = image->createAlphaMask();
  347. if (! mask.isNull() && mask.depth() == 1) {
  348. TQBitmap bm(width, height);
  349. bm.fill(Qt::color1);
  350. bm = mask;
  351. pixmap->setMask(bm);
  352. }
  353. }
  354. }
  355. return pixmap;
  356. }
  357. // Generate an object tree for all the known Gtk widgets...
  358. // returns a pointer to the bottom of the tree
  359. static GtkObject *initialize(TQPtrDict<GtkObject> &dict) {
  360. //
  361. // auto generated stuff from :
  362. // --
  363. // #!/usr/bin/perl -w
  364. //
  365. // foreach $line ( <STDIN> ) {
  366. // chomp $line;
  367. // $line =~ s/[^\sa-zA-Z0-9]/ /g;
  368. // $line =~ /^(\s*)(\S*)/;
  369. // $prefixlength = length $1;
  370. // $classname = $2;
  371. // $class{$prefixlength} = $classname;
  372. // $prefixlength--;
  373. // while( $prefixlength >= 0 && !defined($class{$prefixlength}) ) {
  374. // $prefixlength--;
  375. // }
  376. // $parent = $class{$prefixlength};
  377. // $parent = "0" if ( $parent eq $classname );
  378. //
  379. // # for GtkBin:
  380. // # myGtkBin = new GtkObject( myGtkWidget, "GtkBin" );
  381. //
  382. // print "GtkObject * my$classname =
  383. // new GtkObject( my$parent, \"$classname\" );\n";
  384. // }
  385. // --
  386. GtkObject * myGtkObject =
  387. new GtkObject( 0, "GtkObject" );
  388. GtkObject * myGtkWidget =
  389. new GtkObject( myGtkObject, "GtkWidget" );
  390. GtkObject * myGtkMisc =
  391. new GtkObject( myGtkWidget, "GtkMisc" );
  392. GtkObject * myGtkLabel =
  393. new GtkObject( myGtkMisc, "GtkLabel" );
  394. // GtkObject * myGtkAccelLabel =
  395. // new GtkObject( myGtkLabel, "GtkAccelLabel" );
  396. GtkObject * myGtkTipsQuery =
  397. new GtkObject( myGtkLabel, "GtkTipsQuery" );
  398. GtkObject * myGtkArrow =
  399. new GtkObject( myGtkMisc, "GtkArrow" );
  400. // GtkObject * myGtkImage =
  401. // new GtkObject( myGtkMisc, "GtkImage" );
  402. // GtkObject * myGtkPixmap =
  403. // new GtkObject( myGtkMisc, "GtkPixmap" );
  404. GtkObject * myGtkContainer =
  405. new GtkObject( myGtkWidget, "GtkContainer" );
  406. GtkObject * myGtkBin =
  407. new GtkObject( myGtkContainer, "GtkBin" );
  408. // GtkObject * myGtkAlignment =
  409. // new GtkObject( myGtkBin, "GtkAlignment" );
  410. GtkObject * myGtkFrame =
  411. new GtkObject( myGtkBin, "GtkFrame" );
  412. // GtkObject * myGtkAspectFrame =
  413. // new GtkObject( myGtkFrame, "GtkAspectFrame" );
  414. GtkObject * myGtkButton =
  415. new GtkObject( myGtkBin, "GtkButton" );
  416. GtkObject * myGtkToggleButton =
  417. new GtkObject( myGtkButton, "GtkToggleButton" );
  418. GtkObject * myGtkCheckButton =
  419. new GtkObject( myGtkToggleButton, "GtkCheckButton" );
  420. GtkObject * myGtkRadioButton =
  421. new GtkObject( myGtkCheckButton, "GtkRadioButton" );
  422. GtkObject * myGtkOptionMenu =
  423. new GtkObject( myGtkButton, "GtkOptionMenu" );
  424. GtkObject * myGtkItem =
  425. new GtkObject( myGtkBin, "GtkItem" );
  426. GtkObject * myGtkMenuItem =
  427. new GtkObject( myGtkItem, "GtkMenuItem" );
  428. GtkObject * myGtkCheckMenuItem =
  429. new GtkObject( myGtkMenuItem, "GtkCheckMenuItem" );
  430. GtkObject * myGtkRadioMenuItem =
  431. new GtkObject( myGtkCheckMenuItem, "GtkRadioMenuItem" );
  432. // GtkObject * myGtkTearoffMenuItem =
  433. // new GtkObject( myGtkMenuItem, "GtkTearoffMenuItem" );
  434. GtkObject * myGtkListItem =
  435. new GtkObject( myGtkItem, "GtkListItem" );
  436. GtkObject * myGtkTreeItem =
  437. new GtkObject( myGtkItem, "GtkTreeItem" );
  438. GtkObject * myGtkWindow =
  439. new GtkObject( myGtkBin, "GtkWindow" );
  440. GtkObject * myGtkColorSelectionDialog =
  441. new GtkObject( myGtkWindow, "GtkColorSelectionDialog" );
  442. GtkObject * myGtkDialog =
  443. new GtkObject( myGtkWindow, "GtkDialog" );
  444. GtkObject * myGtkInputDialog =
  445. new GtkObject( myGtkDialog, "GtkInputDialog" );
  446. // GtkObject * myGtkDrawWindow =
  447. // new GtkObject( myGtkWindow, "GtkDrawWindow" );
  448. GtkObject * myGtkFileSelection =
  449. new GtkObject( myGtkWindow, "GtkFileSelection" );
  450. GtkObject * myGtkFontSelectionDialog =
  451. new GtkObject( myGtkWindow, "GtkFontSelectionDialog" );
  452. // GtkObject * myGtkPlug =
  453. // new GtkObject( myGtkWindow, "GtkPlug" );
  454. GtkObject * myGtkEventBox =
  455. new GtkObject( myGtkBin, "GtkEventBox" );
  456. // GtkObject * myGtkHandleBox =
  457. // new GtkObject( myGtkBin, "GtkHandleBox" );
  458. // GtkObject * myGtkScrolledWindow =
  459. // new GtkObject( myGtkBin, "GtkScrolledWindow" );
  460. GtkObject * myGtkViewport =
  461. new GtkObject( myGtkBin, "GtkViewport" );
  462. GtkObject * myGtkBox =
  463. new GtkObject( myGtkContainer, "GtkBox" );
  464. GtkObject * myGtkButtonBox =
  465. new GtkObject( myGtkBox, "GtkButtonBox" );
  466. GtkObject * myGtkHButtonBox =
  467. new GtkObject( myGtkButtonBox, "GtkHButtonBox" );
  468. GtkObject * myGtkVButtonBox =
  469. new GtkObject( myGtkButtonBox, "GtkVButtonBox" );
  470. GtkObject * myGtkVBox =
  471. new GtkObject( myGtkBox, "GtkVBox" );
  472. // GtkObject * myGtkColorSelection =
  473. // new GtkObject( myGtkVBox, "GtkColorSelection" );
  474. // GtkObject * myGtkGammaCurve =
  475. // new GtkObject( myGtkVBox, "GtkGammaCurve" );
  476. GtkObject * myGtkHBox =
  477. new GtkObject( myGtkBox, "GtkHBox" );
  478. // CHANGED! It seems that the gtk optionmenu and gtk combobox aren't related,
  479. // but in Qt they are the same class... so we have changed gth GtkCombo to inherit
  480. // from GtkOptionMenu (so that Qt comboboxes look like the optionmenus by default)
  481. GtkObject * myGtkCombo =
  482. new GtkObject( myGtkOptionMenu, "GtkCombo" );
  483. GtkObject * myGtkStatusbar =
  484. new GtkObject( myGtkHBox, "GtkStatusbar" );
  485. GtkObject * myGtkCList =
  486. new GtkObject( myGtkContainer, "GtkCList" );
  487. GtkObject * myGtkCTree =
  488. new GtkObject( myGtkCList, "GtkCTree" );
  489. // GtkObject * myGtkFixed =
  490. // new GtkObject( myGtkContainer, "GtkFixed" );
  491. GtkObject * myGtkNotebook =
  492. new GtkObject( myGtkContainer, "GtkNotebook" );
  493. // GtkObject * myGtkFontSelection =
  494. // new GtkObject( myGtkNotebook, "GtkFontSelection" );
  495. GtkObject * myGtkPaned =
  496. new GtkObject( myGtkContainer, "GtkPaned" );
  497. // GtkObject * myGtkHPaned =
  498. // new GtkObject( myGtkPaned, "GtkHPaned" );
  499. // GtkObject * myGtkVPaned =
  500. // new GtkObject( myGtkPaned, "GtkVPaned" );
  501. // GtkObject * myGtkLayout =
  502. // new GtkObject( myGtkContainer, "GtkLayout" );
  503. // GtkObject * myGtkList =
  504. // new GtkObject( myGtkContainer, "GtkList" );
  505. GtkObject * myGtkMenuShell =
  506. new GtkObject( myGtkContainer, "GtkMenuShell" );
  507. GtkObject * myGtkMenuBar =
  508. new GtkObject( myGtkMenuShell, "GtkMenuBar" );
  509. GtkObject * myGtkMenu =
  510. new GtkObject( myGtkMenuShell, "GtkMenu" );
  511. // GtkObject * myGtkPacker =
  512. // new GtkObject( myGtkContainer, "GtkPacker" );
  513. // GtkObject * myGtkSocket =
  514. // new GtkObject( myGtkContainer, "GtkSocket" );
  515. GtkObject * myGtkTable =
  516. new GtkObject( myGtkContainer, "GtkTable" );
  517. GtkObject * myGtkToolbar =
  518. new GtkObject( myGtkContainer, "GtkToolbar" );
  519. // GtkObject * myGtkTree =
  520. // new GtkObject( myGtkContainer, "GtkTree" );
  521. // GtkObject * myGtkCalendar =
  522. // new GtkObject( myGtkWidget, "GtkCalendar" );
  523. GtkObject * myGtkDrawingArea =
  524. new GtkObject( myGtkWidget, "GtkDrawingArea");
  525. // GtkObject * myGtkCurve =
  526. // new GtkObject( myGtkDrawingArea, "GtkCurve" );
  527. GtkObject * myGtkEditable =
  528. new GtkObject( myGtkWidget, "GtkEditable" );
  529. GtkObject * myGtkEntry =
  530. new GtkObject( myGtkEditable, "GtkEntry" );
  531. GtkObject * myGtkSpinButton =
  532. new GtkObject( myGtkEntry, "GtkSpinButton" );
  533. GtkObject * myGtkText =
  534. new GtkObject( myGtkEditable, "GtkText" );
  535. GtkObject * myGtkRuler =
  536. new GtkObject( myGtkWidget, "GtkRuler" );
  537. // GtkObject * myGtkHRuler =
  538. // new GtkObject( myGtkRuler, "GtkHRuler" );
  539. // GtkObject * myGtkVRuler =
  540. // new GtkObject( myGtkRuler, "GtkVRuler" );
  541. GtkObject * myGtkRange =
  542. new GtkObject( myGtkWidget, "GtkRange" );
  543. GtkObject * myGtkScale =
  544. new GtkObject( myGtkRange, "GtkScale" );
  545. // GtkObject * myGtkHScale =
  546. // new GtkObject( myGtkScale, "GtkHScale" );
  547. // GtkObject * myGtkVScale =
  548. // new GtkObject( myGtkScale, "GtkVScale" );
  549. GtkObject * myGtkScrollbar =
  550. new GtkObject( myGtkRange, "GtkScrollbar" );
  551. // GtkObject * myGtkHScrollbar =
  552. // new GtkObject( myGtkScrollbar, "GtkHScrollbar" );
  553. // GtkObject * myGtkVScrollbar =
  554. // new GtkObject( myGtkScrollbar, "GtkVScrollbar" );
  555. GtkObject * myGtkSeparator =
  556. new GtkObject( myGtkWidget, "GtkSeparator" );
  557. // GtkObject * myGtkHSeparator =
  558. // new GtkObject( myGtkSeparator, "GtkHSeparator" );
  559. // GtkObject * myGtkVSeparator =
  560. // new GtkObject( myGtkSeparator, "GtkVSeparator" );
  561. // GtkObject * myGtkPreview =
  562. // new GtkObject( myGtkWidget, "GtkPreview" );
  563. GtkObject * myGtkProgress =
  564. new GtkObject( myGtkWidget, "GtkProgress" );
  565. GtkObject * myGtkProgressBar =
  566. new GtkObject( myGtkProgress, "GtkProgressBar" );
  567. //GtkObject * myGtkData =
  568. // new GtkObject( myGtkObject, "GtkData" );
  569. // GtkObject * myGtkAdjustment =
  570. // new GtkObject( myGtkData, "GtkAdjustment" );
  571. // GtkObject * myGtkTooltips =
  572. // new GtkObject( myGtkData, "GtkTooltips" );
  573. // GtkObject * myGtkItemFactory =
  574. // new GtkObject( myGtkObject, "GtkItemFactory" );
  575. // Insert the above Gtk widgets into a dict, using meta data pointers for
  576. // the different widgets in Qt
  577. //
  578. // verify with:
  579. // --
  580. // egrep "::staticMetaObject\(\)$" **/*.cpp | fmt -1 | grep :: |
  581. // sort | uniq > meta
  582. //--
  583. dict.insert(TQButton::staticMetaObject(), myGtkButton);
  584. dict.insert(TQButtonGroup::staticMetaObject(), myGtkButtonBox);
  585. dict.insert(TQCanvas::staticMetaObject(), myGtkDrawingArea);
  586. dict.insert(TQCanvasView::staticMetaObject(), myGtkDrawingArea);
  587. dict.insert(TQCheckBox::staticMetaObject(), myGtkCheckButton);
  588. dict.insert(QColorDialog::staticMetaObject(), myGtkColorSelectionDialog);
  589. dict.insert(TQComboBox::staticMetaObject(), myGtkCombo);
  590. dict.insert(TQDial::staticMetaObject(), myGtkWidget);
  591. dict.insert(TQDialog::staticMetaObject(), myGtkDialog);
  592. dict.insert(TQFileDialog::staticMetaObject(), myGtkFileSelection);
  593. dict.insert(QFontDialog::staticMetaObject(), myGtkFontSelectionDialog);
  594. dict.insert(TQFrame::staticMetaObject(), myGtkFrame);
  595. dict.insert(TQGrid::staticMetaObject(), myGtkFrame);
  596. dict.insert(TQGroupBox::staticMetaObject(), myGtkBox);
  597. dict.insert(TQHBox::staticMetaObject(), myGtkHBox);
  598. dict.insert(TQHButtonGroup::staticMetaObject(), myGtkHButtonBox);
  599. dict.insert(TQHGroupBox::staticMetaObject(), myGtkHBox);
  600. dict.insert(TQHeader::staticMetaObject(), myGtkRuler);
  601. dict.insert(TQIconView::staticMetaObject(), myGtkCTree);
  602. dict.insert(QInputDialog::staticMetaObject(), myGtkInputDialog);
  603. dict.insert(TQLCDNumber::staticMetaObject(), myGtkFrame);
  604. dict.insert(TQLabel::staticMetaObject(), myGtkLabel);
  605. dict.insert(TQLineEdit::staticMetaObject(), myGtkEntry);
  606. dict.insert(TQListBox::staticMetaObject(), myGtkCList);
  607. dict.insert(TQListView::staticMetaObject(), myGtkCTree);
  608. dict.insert(TQMainWindow::staticMetaObject(), myGtkWindow);
  609. dict.insert(TQMenuBar::staticMetaObject(), myGtkMenuBar);
  610. dict.insert(TQMessageBox::staticMetaObject(), myGtkDialog);
  611. dict.insert(TQMultiLineEdit::staticMetaObject(), myGtkText);
  612. dict.insert(TQPopupMenu::staticMetaObject(), myGtkMenu);
  613. dict.insert(TQPrintDialog::staticMetaObject(), myGtkDialog);
  614. dict.insert(TQProgressBar::staticMetaObject(), myGtkProgressBar);
  615. dict.insert(TQProgressDialog::staticMetaObject(), myGtkDialog);
  616. dict.insert(TQPushButton::staticMetaObject(), myGtkButton);
  617. dict.insert(TQRadioButton::staticMetaObject(), myGtkRadioButton);
  618. dict.insert(TQScrollBar::staticMetaObject(), myGtkScrollbar);
  619. dict.insert(TQScrollView::staticMetaObject(), myGtkViewport);
  620. dict.insert(TQSemiModal::staticMetaObject(), myGtkDialog);
  621. dict.insert(TQSizeGrip::staticMetaObject(), myGtkWidget);
  622. dict.insert(TQSlider::staticMetaObject(), myGtkScale);
  623. dict.insert(TQSpinBox::staticMetaObject(), myGtkSpinButton);
  624. dict.insert(TQSplitter::staticMetaObject(), myGtkPaned);
  625. dict.insert(TQStatusBar::staticMetaObject(), myGtkStatusbar);
  626. dict.insert(TQTabBar::staticMetaObject(), myGtkNotebook);
  627. dict.insert(TQTabDialog::staticMetaObject(), myGtkNotebook);
  628. dict.insert(TQTabWidget::staticMetaObject(), myGtkNotebook);
  629. dict.insert(QTableView::staticMetaObject(), myGtkTable);
  630. dict.insert(TQTextBrowser::staticMetaObject(), myGtkText);
  631. dict.insert(TQTextView::staticMetaObject(), myGtkText);
  632. dict.insert(TQToolBar::staticMetaObject(), myGtkToolbar);
  633. dict.insert(TQToolButton::staticMetaObject(), myGtkButton);
  634. dict.insert(TQVBox::staticMetaObject(), myGtkVBox);
  635. dict.insert(TQVButtonGroup::staticMetaObject(), myGtkVButtonBox);
  636. dict.insert(TQVGroupBox::staticMetaObject(), myGtkVBox);
  637. dict.insert(TQWidget::staticMetaObject(), myGtkWidget);
  638. dict.insert(TQWidgetStack::staticMetaObject(), myGtkWidget);
  639. dict.insert(TQWizard::staticMetaObject(), myGtkWindow);
  640. dict.insert(TQWorkspace::staticMetaObject(), myGtkWindow);
  641. // stuff that we don't have meta data for, but want to know about
  642. dict.insert(&listboxitem_ptr, myGtkListItem);
  643. dict.insert(&listviewitem_ptr, myGtkTreeItem);
  644. dict.insert(&menuitem_ptr, myGtkMenuItem);
  645. dict.insert(&separator_ptr, myGtkSeparator);
  646. dict.insert(&arrow_ptr, myGtkArrow);
  647. dict.insert(&whatsthis_ptr, myGtkTipsQuery);
  648. dict.insert(&checkmenuitem_ptr, myGtkCheckMenuItem);
  649. dict.insert(&radiomenuitem_ptr, myGtkRadioMenuItem);
  650. dict.insert(&eventbox_ptr, myGtkEventBox);
  651. return myGtkObject;
  652. }
  653. KLegacyImageData *GtkObject::getImageData(KLegacyImageDataKey key, const TQString &detail) {
  654. KLegacyImageData *imagedata = 0;
  655. if (styleData()) {
  656. QListIterator<KLegacyImageData> it(styleData()->imageList);
  657. while ((imagedata = it.current()) != 0) {
  658. ++it;
  659. if ((((imagedata->key.data.function != 0) &&
  660. (imagedata->key.data.function == key.data.function)) ||
  661. (imagedata->key.data.function == 0)) &&
  662. (((imagedata->key.data.state != 0) &&
  663. (imagedata->key.data.state == key.data.state)) ||
  664. (imagedata->key.data.state == 0)) &&
  665. (((imagedata->key.data.shadow != 0) &&
  666. (imagedata->key.data.shadow == key.data.shadow)) ||
  667. (imagedata->key.data.shadow == 0)) &&
  668. (((imagedata->key.data.orientation != 0) &&
  669. (imagedata->key.data.orientation == key.data.orientation)) ||
  670. (imagedata->key.data.orientation == 0)) &&
  671. (((imagedata->key.data.arrowDirection != 0) &&
  672. (imagedata->key.data.arrowDirection == key.data.arrowDirection)) ||
  673. (imagedata->key.data.arrowDirection == 0)) &&
  674. (((imagedata->key.data.gapSide != 0) &&
  675. (imagedata->key.data.gapSide == key.data.gapSide)) ||
  676. (imagedata->key.data.gapSide == 0)) &&
  677. (((!imagedata->detail.isNull()) &&
  678. (detail == imagedata->detail)) ||
  679. (imagedata->detail.isNull()))) {
  680. // we have a winner
  681. break;
  682. }
  683. }
  684. }
  685. if ((! imagedata) && (parent())) {
  686. imagedata = ((GtkObject *) parent())->getImageData(key, detail);
  687. }
  688. return imagedata;
  689. }
  690. KLegacyStyleData *GtkObject::styleData() {
  691. if ((! d) && parent()) {
  692. d = ((GtkObject *) parent())->styleData();
  693. }
  694. return d;
  695. }
  696. TQColor GtkObject::backColor(KLegacy::State s) {
  697. if ((! styleData()->back[s].isValid()) && parent()) {
  698. return ((GtkObject *) parent())->backColor(s);
  699. }
  700. if (styleData()->back[s].isValid())
  701. return styleData()->back[s];
  702. return white;
  703. }
  704. TQColor GtkObject::baseColor(KLegacy::State s) {
  705. if ((! styleData()->base[s].isValid()) && parent()) {
  706. return ((GtkObject *) parent())->baseColor(s);
  707. }
  708. if (styleData()->base[s].isValid())
  709. return styleData()->base[s];
  710. return white;
  711. }
  712. TQColor GtkObject::foreColor(KLegacy::State s) {
  713. if ((! styleData()->fore[s].isValid()) && parent()) {
  714. return ((GtkObject *) parent())->foreColor(s);
  715. }
  716. if (styleData()->fore[s].isValid())
  717. return styleData()->fore[s];
  718. return black;
  719. }
  720. TQFont *GtkObject::font() {
  721. if ((! styleData()->fn) && parent()) {
  722. return ((GtkObject *) parent())->font();
  723. }
  724. return styleData()->fn;
  725. }
  726. GtkObject *GtkObject::find(TQRegExp &r) const {
  727. // if the regular expression matches the name of this widget, return
  728. if (r.match(name()) != -1) {
  729. return (GtkObject *) this;
  730. }
  731. // regex doesn't match us, and we have no children, return 0
  732. if (! children()) return 0;
  733. TQObject *o;
  734. GtkObject *obj, *gobj;
  735. TQObjectListIt ot(*children());
  736. // search our children to see if any match the regex
  737. while ((o = ot.current()) != 0) {
  738. ++ot;
  739. // this would be nice if moc could parse this file :/
  740. //
  741. // if (o->className() != "GtkObject") {
  742. // tqDebug("object is not a GtkObject (className = '%s')",
  743. // o->className());
  744. // continue;
  745. // }
  746. obj = (GtkObject *) o;
  747. // use obj->find(r) instead of r.match(obj->name()) so that this child's
  748. // children will be searched as well... this allows us to search the entire
  749. // object tree
  750. if ((gobj = obj->find(r)) != 0) {
  751. // found something!
  752. return (GtkObject *) gobj;
  753. }
  754. }
  755. // found nothing
  756. return 0;
  757. }
  758. TQPixmap *GtkObject::draw(KLegacyImageDataKey key, int width, int height,
  759. const TQString &detail)
  760. {
  761. KLegacyImageData *imagedata = getImageData(key, detail);
  762. if (! imagedata) {
  763. return 0;
  764. }
  765. return draw(imagedata, width, height);
  766. }
  767. TQPixmap *GtkObject::draw(KLegacyImageData *imagedata, int width, int height) {
  768. TQString pixmapKey;
  769. TQTextOStream(&pixmapKey) << "$KLegacy_Image_" << styleData()->name << "_" <<
  770. className() << "_" << width << "x" << height << "_" <<
  771. imagedata->key.cachekey << "_" << (uint) imagedata->recolorable <<
  772. (uint) imagedata->stretch << (uint) imagedata->overlayStretch;
  773. TQPixmap *pixmap = TQPixmapCache::find(pixmapKey);
  774. if (pixmap) {
  775. return pixmap;
  776. }
  777. TQPixmap *main = 0, *overlay = 0;
  778. if (! imagedata->file.isNull()) {
  779. TQImage *image = imageCache->find(imagedata->file);
  780. bool found = true;
  781. if (! image) {
  782. image = new TQImage(imagedata->file);
  783. if (! image || image->isNull()) {
  784. found = false;
  785. } else {
  786. imageCache->insert(imagedata->file, image);
  787. }
  788. }
  789. if (found) {
  790. int w = ((imagedata->stretch) ? width : image->width()),
  791. h = ((imagedata->stretch) ? height : image->height());
  792. main = drawImage(image, w, h, imagedata->border, imagedata->stretch);
  793. }
  794. }
  795. if (! imagedata->overlayFile.isNull()) {
  796. TQImage *image = imageCache->find(imagedata->overlayFile);
  797. bool found = true;
  798. if (! image) {
  799. image = new TQImage(imagedata->overlayFile);
  800. if (! image || image->isNull()) {
  801. found = false;
  802. } else {
  803. imageCache->insert(imagedata->overlayFile, image);
  804. }
  805. }
  806. if (found) {
  807. int w = ((imagedata->overlayStretch) ? width : image->width()),
  808. h = ((imagedata->overlayStretch) ? height : image->height());
  809. overlay = drawImage(image, w, h, imagedata->overlayBorder,
  810. imagedata->overlayStretch);
  811. }
  812. }
  813. TQSize sz;
  814. if (main) {
  815. sz = sz.expandedTo(main->size());
  816. }
  817. if (overlay) {
  818. sz = sz.expandedTo(overlay->size());
  819. }
  820. if (sz.isEmpty()) {
  821. return (TQPixmap *) 0;
  822. }
  823. pixmap = new TQPixmap(sz);
  824. pixmap->fill(TQColor(192,192,176));
  825. TQPainter p(pixmap);
  826. if (main && (! main->isNull())) {
  827. p.drawTiledPixmap(0, 0, sz.width(), sz.height(), *main);
  828. }
  829. if (overlay && (! overlay->isNull())) {
  830. TQPoint pt((sz.width() - overlay->width()) / 2,
  831. (sz.height() - overlay->height()) / 2);
  832. p.drawPixmap(pt, *overlay);
  833. }
  834. p.end();
  835. if (main) {
  836. if (main->mask() && (! main->mask()->isNull())) {
  837. TQBitmap bm(sz);
  838. TQPainter m(&bm);
  839. TQRect r(0, 0, width, height);
  840. m.drawTiledPixmap(r, *(main->mask()));
  841. m.end();
  842. pixmap->setMask(bm);
  843. }
  844. } else if (overlay) {
  845. if (overlay->mask() && (! overlay->mask()->isNull())) {
  846. TQBitmap bm(sz);
  847. TQPainter m(&bm);
  848. TQRect r((sz.width() - overlay->width()) / 2,
  849. (sz.height() - overlay->height()) / 2,
  850. sz.width(), sz.height());
  851. m.drawTiledPixmap(r, *(overlay->mask()));
  852. m.end();
  853. pixmap->setMask(bm);
  854. }
  855. }
  856. if (! TQPixmapCache::insert(pixmapKey, pixmap)) {
  857. delete pixmap;
  858. pixmap = (TQPixmap *) 0;
  859. }
  860. return pixmap;
  861. }
  862. class KLegacyStylePrivate : public KLegacy {
  863. private:
  864. TQDict<KLegacyStyleData> styleDict;
  865. TQStringList pixmapPath;
  866. TQTextStream filestream;
  867. TQFont oldfont;
  868. TQPalette oldpalette;
  869. // pointer to the widget under the pointer
  870. TQGuardedPtr<TQWidget> lastWidget;
  871. // current position of the mouse
  872. TQPoint mousePos;
  873. bool hovering;
  874. TQPtrDict<GtkObject> gtkDict;
  875. GtkObject *gtktree;
  876. friend class KLegacyStyle;
  877. public:
  878. KLegacyStylePrivate();
  879. ~KLegacyStylePrivate();
  880. // parse the filename passed
  881. bool parse(const TQString &filename);
  882. bool parseClass();
  883. bool parseEngine(KLegacyStyleData *);
  884. bool parseImage(KLegacyStyleData *);
  885. bool parsePixmapPath();
  886. bool parseStyle();
  887. };
  888. KLegacyStylePrivate::KLegacyStylePrivate()
  889. : lastWidget(0), mousePos(-1, -1), hovering(false), gtktree(0)
  890. {
  891. TQPixmapCache::setCacheLimit(8192);
  892. if (! imageCache) {
  893. imageCache = new TQDict<TQImage>(imageCacheSize);
  894. CHECK_PTR(imageCache);
  895. imageCache->setAutoDelete(true);
  896. }
  897. styleDict.setAutoDelete(true);
  898. gtktree = initialize(gtkDict);
  899. CHECK_PTR(gtktree);
  900. if (! gtktree->d) {
  901. gtktree->d = new KLegacyStyleData;
  902. gtktree->d->name = "Default";
  903. }
  904. // get the path to this users .gtkrc
  905. TQString gtkrcFilename = getenv("HOME");
  906. gtkrcFilename += "/.gtkrc";
  907. TQFile gtkrc(gtkrcFilename);
  908. if (gtkrc.open(IO_ReadOnly)) {
  909. filestream.setDevice(&gtkrc);
  910. while (! filestream.atEnd()) {
  911. TQString next;
  912. filestream >> next;
  913. if (next.isNull()) continue;
  914. // skip comments
  915. if (next[0] == '#') { filestream.readLine(); continue; }
  916. if (next == "class" || next == "widget" || next == "widget_class") {
  917. if (! parseClass())
  918. tqWarning("\"class\" parse error");
  919. } else if (next == "pixmap_path") {
  920. if (! parsePixmapPath())
  921. tqWarning("\"pixmap_path\" parse error");
  922. } else if (next == "style") {
  923. if (! parseStyle())
  924. tqWarning("\"style\" parse error");
  925. }
  926. }
  927. gtkrc.close();
  928. } else
  929. tqWarning("%s: failed to open", gtkrcFilename.latin1());
  930. }
  931. KLegacyStylePrivate::~KLegacyStylePrivate() {
  932. if (imageCache) {
  933. delete imageCache;
  934. imageCache = 0;
  935. }
  936. if (gtktree) {
  937. delete gtktree;
  938. gtktree = 0;
  939. }
  940. }
  941. bool KLegacyStylePrivate::parseClass() {
  942. if (filestream.atEnd()) return false;
  943. TQString classname, keyword, stylename;
  944. filestream >> classname;
  945. filestream >> keyword;
  946. filestream >> stylename;
  947. if (classname.isNull() || keyword.isNull() || stylename.isNull() ||
  948. keyword != "style" ||
  949. classname[0] != '\"' || classname[classname.length() - 1] != '\"' ||
  950. stylename[0] != '\"' || stylename[stylename.length() - 1] != '\"')
  951. return false;
  952. classname = classname.mid(1, classname.length() - 2);
  953. stylename = stylename.mid(1, stylename.length() - 2);
  954. TQRegExp r(classname);
  955. r.setWildcard(true);
  956. GtkObject *obj = gtktree->find(r);
  957. if (! obj) {
  958. tqWarning("unknown object '%s'", classname.latin1());
  959. return false;
  960. }
  961. KLegacyStyleData *styledata = styleDict.find(stylename);
  962. if (! styledata) {
  963. tqWarning("no such style '%s' for class '%s' (%p)", stylename.latin1(),
  964. classname.latin1(), styledata);
  965. return false;
  966. }
  967. obj->d = styledata;
  968. styledata->ref++;
  969. return true;
  970. }
  971. bool KLegacyStylePrivate::parseImage(KLegacyStyleData *styledata) {
  972. if (filestream.atEnd()) {
  973. tqWarning("parseImage: premature end of stream");
  974. return false;
  975. }
  976. TQString next, equals, parameter;
  977. filestream >> next;
  978. // skip comments
  979. while (next[0] == '#') {
  980. filestream.readLine();
  981. filestream >> next;
  982. }
  983. if (next.isNull() || next != "{") {
  984. tqWarning("parseImage: expected '{' after 'image'\n"
  985. " in style '%s', after processing %d previous images\n",
  986. styledata->name.latin1(), styledata->imageList.count());
  987. return false;
  988. }
  989. KLegacyImageData *imagedata = new KLegacyImageData;
  990. int paren_count = 1;
  991. while (paren_count) {
  992. filestream >> next;
  993. if (next.isNull()) continue;
  994. // skip comments
  995. if (next[0] == '#') {filestream.readLine(); continue; }
  996. if (next == "arrow_direction") {
  997. filestream >> equals;
  998. filestream >> parameter;
  999. if (equals.isNull() || parameter.isNull() || equals != "=") continue;
  1000. if (parameter == "UP")
  1001. imagedata->key.data.arrowDirection = Qt::UpArrow + 1;
  1002. else if (parameter == "DOWN")
  1003. imagedata->key.data.arrowDirection = Qt::DownArrow + 1;
  1004. else if (parameter == "LEFT")
  1005. imagedata->key.data.arrowDirection = Qt::LeftArrow + 1;
  1006. else if (parameter == "RIGHT")
  1007. imagedata->key.data.arrowDirection = Qt::RightArrow + 1;
  1008. } else if (next == "border") {
  1009. filestream >> equals;
  1010. filestream >> parameter;
  1011. if (equals.isNull() || parameter.isNull() || equals != "=" ||
  1012. parameter != "{")
  1013. continue;
  1014. TQString border =filestream.readLine();
  1015. int lp, rp, tp, bp, l, r, t, b;
  1016. lp = border.find(',');
  1017. rp = border.find(',', lp + 1);
  1018. tp = border.find(',', rp + 1);
  1019. bp = border.find('}', tp + 1);
  1020. l = border.left(lp).toUInt();
  1021. r = border.mid(lp + 1, rp - lp - 1).toUInt();
  1022. t = border.mid(rp + 1, tp - rp - 1).toUInt();
  1023. b = border.mid(tp + 1, bp - tp - 1).toUInt();
  1024. imagedata->border.setLeft(l);
  1025. imagedata->border.setRight(r);
  1026. imagedata->border.setTop(t);
  1027. imagedata->border.setBottom(b);
  1028. } else if (next == "detail") {
  1029. filestream >> equals;
  1030. filestream >> parameter;
  1031. if (equals.isNull() || parameter.isNull() || equals != "=" ||
  1032. parameter[0] != '\"' || parameter[parameter.length() - 1] != '\"')
  1033. continue;
  1034. parameter = parameter.mid(1, parameter.length() - 2);
  1035. imagedata->detail = parameter;
  1036. } else if (next == "file") {
  1037. filestream >> equals;
  1038. filestream >> parameter;
  1039. if (equals.isNull() || parameter.isNull() || equals != "=" ||
  1040. parameter[0] != '\"' || parameter[parameter.length() - 1] != '\"') {
  1041. tqWarning("image: file parameter malformed");
  1042. continue;
  1043. }
  1044. parameter = parameter.mid(1, parameter.length() - 2);
  1045. TQStringList::Iterator it;
  1046. for (it = pixmapPath.begin(); it != pixmapPath.end(); ++it) {
  1047. TQFileInfo fileinfo((*it) + parameter);
  1048. if (fileinfo.exists()) {
  1049. imagedata->file = fileinfo.filePath();
  1050. break;
  1051. }
  1052. }
  1053. } else if (next == "function") {
  1054. filestream >> equals;
  1055. filestream >> parameter;
  1056. if (equals.isNull() || parameter.isNull() || equals != "=") continue;
  1057. if (parameter == "BOX")
  1058. imagedata->key.data.function = Box;
  1059. else if (parameter == "FLAT_BOX")
  1060. imagedata->key.data.function = FlatBox;
  1061. else if (parameter == "EXTENSION")
  1062. imagedata->key.data.function = Extension;
  1063. else if (parameter == "CHECK")
  1064. imagedata->key.data.function = Check;
  1065. else if (parameter == "OPTION")
  1066. imagedata->key.data.function = Option;
  1067. else if (parameter == "HLINE")
  1068. imagedata->key.data.function = HLine;
  1069. else if (parameter == "VLINE")
  1070. imagedata->key.data.function = VLine;
  1071. else if (parameter == "BOX_GAP")
  1072. imagedata->key.data.function = BoxGap;
  1073. else if (parameter == "SLIDER")
  1074. imagedata->key.data.function = Slider;
  1075. else if (parameter == "TAB")
  1076. imagedata->key.data.function = Tab;
  1077. else if (parameter == "ARROW")
  1078. imagedata->key.data.function = Arrow;
  1079. else if (parameter == "HANDLE")
  1080. imagedata->key.data.function = Handle;
  1081. else if (parameter == "SHADOW")
  1082. imagedata->key.data.function = FShadow;
  1083. else if (parameter == "FOCUS")
  1084. imagedata->key.data.function = Focus;
  1085. } else if (next == "gap_side" ) {
  1086. filestream >> equals;
  1087. filestream >> parameter;
  1088. if (equals.isNull() || parameter.isNull() || equals != "=") continue;
  1089. if (parameter == "TOP")
  1090. imagedata->key.data.gapSide = KLegacy::Top;
  1091. else if (parameter == "BOTTOM")
  1092. imagedata->key.data.gapSide = KLegacy::Bottom;
  1093. } else if (next == "orientation") {
  1094. filestream >> equals;
  1095. filestream >> parameter;
  1096. if (equals.isNull() || parameter.isNull() || equals != "=") continue;
  1097. if (parameter == "VERTICAL")
  1098. imagedata->key.data.orientation = Qt::Vertical + 1;
  1099. else if (parameter == "HORIZONTAL")
  1100. imagedata->key.data.orientation = Qt::Horizontal + 1;
  1101. } else if (next == "overlay_border") {
  1102. filestream >> equals;
  1103. filestream >> parameter;
  1104. if (equals.isNull() || parameter.isNull() || equals != "=" ||
  1105. parameter != "{")
  1106. continue;
  1107. TQString border = filestream.readLine();
  1108. int lp, rp, tp, bp, l, r, t, b;
  1109. lp = border.find(',');
  1110. rp = border.find(',', lp + 1);
  1111. tp = border.find(',', rp + 1);
  1112. bp = border.find('}', tp + 1);
  1113. l = border.left(lp).toUInt();
  1114. r = border.mid(lp + 1, rp - lp - 1).toUInt();
  1115. t = border.mid(rp + 1, tp - rp - 1).toUInt();
  1116. b = border.mid(tp + 1, bp - tp - 1).toUInt();
  1117. imagedata->overlayBorder.setLeft(l);
  1118. imagedata->overlayBorder.setRight(r);
  1119. imagedata->overlayBorder.setTop(t);
  1120. imagedata->overlayBorder.setBottom(b);
  1121. } else if (next == "overlay_file") {
  1122. filestream >> equals;
  1123. filestream >> parameter;
  1124. if (equals.isNull() || parameter.isNull() || equals != "=" ||
  1125. parameter[0] != '\"' || parameter[parameter.length() - 1] != '\"') {
  1126. tqWarning("image: overlay_file parameter malformed");
  1127. continue;
  1128. }
  1129. parameter = parameter.mid(1, parameter.length() - 2);
  1130. TQStringList::Iterator it;
  1131. for (it = pixmapPath.begin(); it != pixmapPath.end(); ++it) {
  1132. TQFileInfo fileinfo((*it) + parameter);
  1133. if (fileinfo.exists()) {
  1134. imagedata->overlayFile = fileinfo.filePath();
  1135. break;
  1136. }
  1137. }
  1138. } else if (next == "overlay_stretch") {
  1139. filestream >> equals;
  1140. filestream >> parameter;
  1141. if (equals.isNull() || parameter.isNull() || equals != "=") continue;
  1142. if (parameter == "TRUE")
  1143. imagedata->overlayStretch = true;
  1144. else
  1145. imagedata->overlayStretch = false;
  1146. } else if (next == "stretch") {
  1147. filestream >> equals;
  1148. filestream >> parameter;
  1149. if (equals.isNull() || parameter.isNull() || equals != "=") continue;
  1150. if (parameter == "TRUE")
  1151. imagedata->stretch = true;
  1152. else
  1153. imagedata->stretch = false;
  1154. } else if (next == "shadow") {
  1155. filestream >> equals;
  1156. filestream >> parameter;
  1157. if (equals.isNull() || parameter.isNull() || equals != "=") continue;
  1158. if (parameter == "NONE")
  1159. imagedata->key.data.shadow = NoShadow;
  1160. else if (parameter == "IN")
  1161. imagedata->key.data.shadow = In;
  1162. else if (parameter == "OUT")
  1163. imagedata->key.data.shadow = Out;
  1164. else if (parameter == "ETCHED_IN")
  1165. imagedata->key.data.shadow = EtchedIn;
  1166. else if (parameter == "ETCHED_OUT")
  1167. imagedata->key.data.shadow = EtchedOut;
  1168. } else if (next == "state") {
  1169. filestream >> equals;
  1170. filestream >> parameter;
  1171. if (equals.isNull() || parameter.isNull() || equals != "=") continue;
  1172. if (parameter == "NORMAL")
  1173. imagedata->key.data.state = Normal;
  1174. else if (parameter == "PRELIGHT")
  1175. imagedata->key.data.state = Prelight;
  1176. else if (parameter == "ACTIVE")
  1177. imagedata->key.data.state = Active;
  1178. else if (parameter == "INSENSITIVE")
  1179. imagedata->key.data.state = Insensitive;
  1180. else if (parameter == "SELECTED")
  1181. imagedata->key.data.state = Selected;
  1182. } else if (next == "{") paren_count++;
  1183. else if (next == "}") paren_count--;
  1184. }
  1185. styledata->imageList.append(imagedata);
  1186. return true;
  1187. }
  1188. bool KLegacyStylePrivate::parseEngine(KLegacyStyleData *styledata) {
  1189. if (filestream.atEnd()) return false;
  1190. TQString enginename, paren;
  1191. filestream >> enginename;
  1192. filestream >> paren;
  1193. if (enginename.isNull() || paren.isNull() ||
  1194. enginename[0] != '\"' || enginename[enginename.length() - 1] != '\"' ||
  1195. paren != "{") {
  1196. return false;
  1197. }
  1198. TQString next;
  1199. int paren_count = 1;
  1200. while (paren_count) {
  1201. filestream >> next;
  1202. // skip comments
  1203. if (next[0] == '#') {
  1204. filestream.readLine();
  1205. continue;
  1206. }
  1207. if (next == "image") {
  1208. if (! parseImage(styledata)) {
  1209. tqWarning("image parse error");
  1210. }
  1211. } else if (next == "{") {
  1212. paren_count++;
  1213. } else if (next == "}") {
  1214. paren_count--;
  1215. }
  1216. }
  1217. return true;
  1218. }
  1219. bool KLegacyStylePrivate::parsePixmapPath() {
  1220. if (filestream.atEnd()) {
  1221. return false;
  1222. }
  1223. TQString next;
  1224. filestream >> next;
  1225. if (next.isNull() || next[0] != '\"' || next[next.length() - 1] != '\"') {
  1226. return false;
  1227. }
  1228. next = next.mid(1, next.length() - 2);
  1229. int start = 0, end = next.find(":");
  1230. while (end != -1) {
  1231. TQString path(next.mid(start, end - start));
  1232. if (path[path.length() - 1] != '/') {
  1233. path += '/';
  1234. }
  1235. TQFileInfo fileinfo(path);
  1236. if (fileinfo.exists() && fileinfo.isDir()) {
  1237. pixmapPath.append(path);
  1238. }
  1239. start = end + 1;
  1240. end = next.find(":", start);
  1241. }
  1242. // get the straggler
  1243. end = next.length();
  1244. TQString path(next.mid(start, end - start));
  1245. if (path[path.length() - 1] != '/') {
  1246. path += '/';
  1247. }
  1248. TQFileInfo fileinfo(path);
  1249. if (fileinfo.exists() && fileinfo.isDir()) {
  1250. pixmapPath.append(path);
  1251. }
  1252. return true;
  1253. }
  1254. bool KLegacyStylePrivate::parseStyle() {
  1255. if (filestream.atEnd()) return false;
  1256. TQString stylename, paren;
  1257. filestream >> stylename;
  1258. filestream >> paren;
  1259. if (stylename.isNull() || paren.isNull() ||
  1260. stylename[0] != '\"' || stylename[stylename.length() - 1] != '\"')
  1261. return false;
  1262. stylename = stylename.mid(1, stylename.length() - 2);
  1263. if (paren == "=") {
  1264. TQString newstylename;
  1265. filestream >> newstylename;
  1266. if (newstylename.isNull() ||
  1267. newstylename[0] != '\"' || newstylename[newstylename.length() - 1] != '\"')
  1268. return false;
  1269. newstylename = newstylename.mid(1, newstylename.length() - 2);
  1270. KLegacyStyleData *styledata = styleDict.find(stylename);
  1271. if (! styledata) return false;
  1272. KLegacyStyleData *newstyledata = new KLegacyStyleData(*styledata);
  1273. newstyledata->name = newstylename;
  1274. styleDict.insert(newstylename, newstyledata);
  1275. return true;
  1276. } else if (paren != "{") {
  1277. tqWarning("parseStyle: expected '{' while parsing style %s",
  1278. stylename.latin1());
  1279. return false;
  1280. }
  1281. KLegacyStyleData *styledata = new KLegacyStyleData;
  1282. styledata->name = stylename;
  1283. TQString next, parameter;
  1284. int paren_count = 1;
  1285. while (paren_count) {
  1286. filestream >> next;
  1287. // skip comments
  1288. if (next[0] == '#') {
  1289. filestream.readLine();
  1290. continue;
  1291. }
  1292. if (next.left(5) == "base[") {
  1293. int l = next.find('['), r = next.find(']'), state;
  1294. if (l < 1 || r < 1 || r < l) continue;
  1295. TQString mode = next.mid(l + 1, r - l - 1);
  1296. if (mode == "ACTIVE")
  1297. state = Active;
  1298. else if (mode == "NORMAL")
  1299. state = Normal;
  1300. else if (mode == "INSENSITIVE")
  1301. state = Insensitive;
  1302. else if (mode == "PRELIGHT")
  1303. state = Prelight;
  1304. else if (mode == "SELECTED")
  1305. state = Selected;
  1306. filestream >> next;
  1307. filestream >> parameter;
  1308. if (next.isNull() || parameter.isNull() || next != "=") continue;
  1309. if (parameter[0] == '\"') { // assume color of the form "#rrggbb"
  1310. TQString colorname = parameter.mid(1, parameter.length() - 2);
  1311. if (colorname.isNull()) continue;
  1312. styledata->base[state].setNamedColor(colorname);
  1313. } else if (parameter == "{") { // assume color of the form { ri, gi, bi }
  1314. TQString color =filestream.readLine();
  1315. int rp, gp, bp;
  1316. float ri, gi, bi;
  1317. rp = color.find(',');
  1318. gp = color.find(',', rp + 1);
  1319. bp = color.find('}', gp + 1);
  1320. ri = color.left(rp).toFloat();
  1321. gi = color.mid(rp + 1, gp - rp - 1).toFloat();
  1322. bi = color.mid(gp + 1, bp - gp - 1).toFloat();
  1323. int red = (int) (255 * ri);
  1324. int green = (int) (255 * gi);
  1325. int blue = (int) (255 * bi);
  1326. styledata->base[state].setRgb(red, green, blue);
  1327. }
  1328. } else if (next.left(3) == "bg[") {
  1329. int l = next.find('['), r = next.find(']'), state;
  1330. if (l < 1 || r < 1 || r < l) continue;
  1331. TQString mode = next.mid(l + 1, r - l - 1);
  1332. if (mode == "ACTIVE")
  1333. state = Active;
  1334. else if (mode == "NORMAL")
  1335. state = Normal;
  1336. else if (mode == "INSENSITIVE")
  1337. state = Insensitive;
  1338. else if (mode == "PRELIGHT")
  1339. state = Prelight;
  1340. else if (mode == "SELECTED")
  1341. state = Selected;
  1342. filestream >> next;
  1343. filestream >> parameter;
  1344. if (next.isNull() || parameter.isNull() || next != "=") continue;
  1345. if (parameter[0] == '\"') { // assume color of the form "#rrggbb"
  1346. TQString colorname = parameter.mid(1, parameter.length() - 2);
  1347. if (colorname.isNull()) continue;
  1348. styledata->back[state].setNamedColor(colorname);
  1349. } else if (parameter == "{") { // assume color of the form { ri, gi, bi }
  1350. TQString color =filestream.readLine();
  1351. int rp, gp, bp;
  1352. float ri, gi, bi;
  1353. rp = color.find(',');
  1354. gp = color.find(',', rp + 1);
  1355. bp = color.find('}', gp + 1);
  1356. ri = color.left(rp).toFloat();
  1357. gi = color.mid(rp + 1, gp - rp - 1).toFloat();
  1358. bi = color.mid(gp + 1, bp - gp - 1).toFloat();
  1359. int red = (int) (255 * ri);
  1360. int green = (int) (255 * gi);
  1361. int blue = (int) (255 * bi);
  1362. styledata->back[state].setRgb(red, green, blue);
  1363. }
  1364. } else if (next == "engine") {
  1365. if (! parseEngine(styledata))
  1366. fprintf(stderr, "engine parse error\n");
  1367. } else if (next.left(3) == "fg[") {
  1368. int l = next.find('['), r = next.find(']'), state;
  1369. if (l < 1 || r < 1 || r < l) continue;
  1370. TQString mode = next.mid(l + 1, r - l - 1);
  1371. if (mode == "ACTIVE")
  1372. state = Active;
  1373. else if (mode == "NORMAL")
  1374. state = Normal;
  1375. else if (mode == "INSENSITIVE")
  1376. state = Insensitive;
  1377. else if (mode == "PRELIGHT")
  1378. state = Prelight;
  1379. else if (mode == "SELECTED")
  1380. state = Selected;
  1381. filestream >> next;
  1382. filestream >> parameter;
  1383. if (next.isNull() || parameter.isNull() || next != "=") continue;
  1384. if (parameter[0] == '\"') { // assume color of the form "#rrggbb"
  1385. TQString colorname = parameter.mid(1, parameter.length() - 2);
  1386. if (colorname.isNull()) continue;
  1387. styledata->fore[state].setNamedColor(colorname);
  1388. } else if (parameter == "{") { // assume color of the form { ri, gi, bi }
  1389. TQString color = filestream.readLine();
  1390. int rp, gp, bp;
  1391. float ri, gi, bi;
  1392. rp = color.find(',');
  1393. gp = color.find(',', rp + 1);
  1394. bp = color.find('}', gp + 1);
  1395. ri = color.left(rp).toFloat();
  1396. gi = color.mid(rp + 1, gp - rp - 1).toFloat();
  1397. bi = color.mid(gp + 1, bp - gp - 1).toFloat();
  1398. int red = (int) (255 * ri);
  1399. int green = (int) (255 * gi);
  1400. int blue = (int) (255 * bi);
  1401. styledata->fore[state].setRgb(red, green, blue);
  1402. }
  1403. } else if (next == "font") {
  1404. filestream >> next;
  1405. filestream >> parameter;
  1406. if (next.isNull() || parameter.isNull() || next != "=" ||
  1407. parameter[0] != '\"' || parameter[parameter.length() - 1] != '\"') {
  1408. tqWarning("font parameter malformed '%s'", parameter.latin1());
  1409. continue;
  1410. }
  1411. parameter = parameter.mid(1, parameter.length() - 2);
  1412. if (! styledata->fn) {
  1413. styledata->fn = new TQFont;
  1414. }
  1415. styledata->fn->setRawName(parameter);
  1416. } else if (next == "{") {
  1417. paren_count++;
  1418. } else if (next == "}") {
  1419. paren_count--;
  1420. }
  1421. }
  1422. styleDict.insert(styledata->name, styledata);
  1423. return true;
  1424. }
  1425. KLegacyStyle::KLegacyStyle(void) : TDEStyle() {
  1426. setButtonDefaultIndicatorWidth(6);
  1427. setScrollBarExtent(15, 15);
  1428. setButtonMargin(3);
  1429. setSliderThickness(15);
  1430. priv = new KLegacyStylePrivate;
  1431. }
  1432. KLegacyStyle::~KLegacyStyle(void) {
  1433. delete priv;
  1434. }
  1435. int KLegacyStyle::defaultFrameWidth() const {
  1436. return 2;
  1437. }
  1438. void KLegacyStyle::polish(TQApplication *app) {
  1439. priv->oldfont = app->font();
  1440. priv->oldpalette = app->palette();
  1441. GtkObject *gobj = priv->gtkDict.find(TQMainWindow::staticMetaObject());
  1442. if (gobj) {
  1443. if (gobj->font()) {
  1444. app->setFont(*gobj->font(), true);
  1445. }
  1446. TQPalette pal = app->palette();
  1447. TQBrush brush;
  1448. // background
  1449. brush = pal.brush(TQPalette::Active, TQColorGroup::Background);
  1450. brush.setColor(gobj->backColor(KLegacy::Active));
  1451. pal.setBrush(TQPalette::Active, TQColorGroup::Background, brush);
  1452. brush = pal.brush(TQPalette::Inactive, TQColorGroup::Background);
  1453. brush.setColor(gobj->backColor(KLegacy::Normal));
  1454. pal.setBrush(TQPalette::Inactive, TQColorGroup::Background, brush);
  1455. brush = pal.brush(TQPalette::Disabled, TQColorGroup::Background);
  1456. brush.setColor(gobj->backColor(KLegacy::Insensitive));
  1457. pal.setBrush(TQPalette::Disabled, TQColorGroup::Background, brush);
  1458. // foreground
  1459. brush = pal.brush(TQPalette::Active, TQColorGroup::Foreground);
  1460. brush.setColor(gobj->foreColor(KLegacy::Active));
  1461. pal.setBrush(TQPalette::Active, TQColorGroup::Foreground, brush);
  1462. brush = pal.brush(TQPalette::Inactive, TQColorGroup::Foreground);
  1463. brush.setColor(gobj->foreColor(KLegacy::Normal));
  1464. pal.setBrush(TQPalette::Inactive, TQColorGroup::Foreground, brush);
  1465. brush = pal.brush(TQPalette::Disabled, TQColorGroup::Foreground);
  1466. brush.setColor(gobj->foreColor(KLegacy::Insensitive));
  1467. pal.setBrush(TQPalette::Disabled, TQColorGroup::Foreground, brush);
  1468. // base
  1469. brush = pal.brush(TQPalette::Active, TQColorGroup::Base);
  1470. brush.setColor(gobj->baseColor(KLegacy::Normal));
  1471. pal.setBrush(TQPalette::Active, TQColorGroup::Base, brush);
  1472. brush = pal.brush(TQPalette::Inactive, TQColorGroup::Base);
  1473. brush.setColor(gobj->baseColor(KLegacy::Normal));
  1474. pal.setBrush(TQPalette::Inactive, TQColorGroup::Base, brush);
  1475. brush = pal.brush(TQPalette::Disabled, TQColorGroup::Base);
  1476. brush.setColor(gobj->baseColor(KLegacy::Normal));
  1477. pal.setBrush(TQPalette::Disabled, TQColorGroup::Base, brush);
  1478. // button
  1479. brush = pal.brush(TQPalette::Active, TQColorGroup::Button);
  1480. brush.setColor(gobj->backColor(KLegacy::Active));
  1481. pal.setBrush(TQPalette::Active, TQColorGroup::Button, brush);
  1482. brush = pal.brush(TQPalette::Normal, TQColorGroup::Button);
  1483. brush.setColor(gobj->backColor(KLegacy::Normal));
  1484. pal.setBrush(TQPalette::Normal, TQColorGroup::Button, brush);
  1485. brush = pal.brush(TQPalette::Disabled, TQColorGroup::Button);
  1486. brush.setColor(gobj->backColor(KLegacy::Insensitive));
  1487. pal.setBrush(TQPalette::Disabled, TQColorGroup::Button, brush);
  1488. // text
  1489. brush = pal.brush(TQPalette::Active, TQColorGroup::Text);
  1490. brush.setColor(gobj->foreColor(KLegacy::Active));
  1491. pal.setBrush(TQPalette::Active, TQColorGroup::Text, brush);
  1492. brush = pal.brush(TQPalette::Inactive, TQColorGroup::Text);
  1493. brush.setColor(gobj->foreColor(KLegacy::Normal));
  1494. pal.setBrush(TQPalette::Inactive, TQColorGroup::Text, brush);
  1495. brush = pal.brush(TQPalette::Disabled, TQColorGroup::Text);
  1496. brush.setColor(gobj->foreColor(KLegacy::Insensitive));
  1497. pal.setBrush(TQPalette::Disabled, TQColorGroup::Text, brush);
  1498. // highlight
  1499. brush = pal.brush(TQPalette::Active, TQColorGroup::Highlight);
  1500. brush.setColor(gobj->backColor(KLegacy::Selected));
  1501. pal.setBrush(TQPalette::Active, TQColorGroup::Highlight, brush);
  1502. brush = pal.brush(TQPalette::Active, TQColorGroup::Highlight);
  1503. brush.setColor(gobj->backColor(KLegacy::Selected));
  1504. pal.setBrush(TQPalette::Active, TQColorGroup::Highlight, brush);
  1505. brush = pal.brush(TQPalette::Active, TQColorGroup::Highlight);
  1506. brush.setColor(gobj->backColor(KLegacy::Selected));
  1507. pal.setBrush(TQPalette::Active, TQColorGroup::Highlight, brush);
  1508. // highlight text
  1509. brush = pal.brush(TQPalette::Active, TQColorGroup::HighlightedText);
  1510. brush.setColor(gobj->foreColor(KLegacy::Selected));
  1511. pal.setBrush(TQPalette::Active, TQColorGroup::HighlightedText, brush);
  1512. brush = pal.brush(TQPalette::Active, TQColorGroup::HighlightedText);
  1513. brush.setColor(gobj->foreColor(KLegacy::Active));
  1514. pal.setBrush(TQPalette::Active, TQColorGroup::HighlightedText, brush);
  1515. brush = pal.brush(TQPalette::Active, TQColorGroup::HighlightedText);
  1516. brush.setColor(gobj->foreColor(KLegacy::Active));
  1517. pal.setBrush(TQPalette::Active, TQColorGroup::HighlightedText, brush);
  1518. app->setPalette(pal, true);
  1519. }
  1520. qt_set_draw_menu_bar_impl((QDrawMenuBarItemImpl) &KLegacyStyle::drawMenuBarItem);
  1521. TDEStyle::polish(app);
  1522. }
  1523. void KLegacyStyle::polish(TQWidget *widget) {
  1524. if (qstrcmp(widget->name(), "qt_viewport") == 0 ||
  1525. widget->testWFlags(WType_Popup) ||
  1526. widget->inherits("KDesktop"))
  1527. return;
  1528. if (widget->backgroundMode() == TQWidget::PaletteBackground ||
  1529. widget->backgroundMode() == TQWidget::PaletteButton &&
  1530. (! widget->ownPalette()))
  1531. widget->setBackgroundMode(TQWidget::X11ParentRelative);
  1532. TQMetaObject *metaobject = 0;
  1533. TQString detail;
  1534. KLegacyImageDataKey key;
  1535. key.cachekey = 0;
  1536. bool eventFilter = false;
  1537. bool mouseTrack = false;
  1538. bool immediateRender = false;
  1539. bool bgPixmap = false;
  1540. if (widget->inherits(TQBUTTON_OBJECT_NAME_STRING)) {
  1541. metaobject = TQButton::staticMetaObject();
  1542. eventFilter = true;
  1543. }
  1544. if (widget->inherits(TQCOMBOBOX_OBJECT_NAME_STRING)) {
  1545. metaobject = TQComboBox::staticMetaObject();
  1546. eventFilter = true;
  1547. }
  1548. if (widget->inherits(TQSCROLLBAR_OBJECT_NAME_STRING)) {
  1549. metaobject = TQScrollBar::staticMetaObject();
  1550. eventFilter = true;
  1551. mouseTrack = true;
  1552. }
  1553. if (widget->inherits(TQMENUBAR_OBJECT_NAME_STRING)) {
  1554. eventFilter = true;
  1555. immediateRender = true;
  1556. metaobject = TQMenuBar::staticMetaObject();
  1557. detail = "menubar";
  1558. key.data.function = KLegacy::Box;
  1559. key.data.shadow = KLegacy::Out;
  1560. key.data.state = KLegacy::Normal;
  1561. ((TQMenuBar *) widget)->setFrameShape(TQFrame::StyledPanel);
  1562. ((TQMenuBar *) widget)->setLineWidth(0);
  1563. widget->setBackgroundMode(TQWidget::PaletteBackground);
  1564. }
  1565. if (widget->inherits(TQTOOLBAR_OBJECT_NAME_STRING)) {
  1566. metaobject = TQToolBar::staticMetaObject();
  1567. eventFilter = true;
  1568. immediateRender = true;
  1569. detail = "menubar";
  1570. key.data.function = KLegacy::Box;
  1571. key.data.shadow = KLegacy::Out;
  1572. key.data.state = KLegacy::Normal;
  1573. widget->setBackgroundMode(TQWidget::PaletteBackground);
  1574. }
  1575. if (widget->inherits(TQLINEEDIT_OBJECT_NAME_STRING)) {
  1576. metaobject = TQLineEdit::staticMetaObject();
  1577. eventFilter = true;
  1578. immediateRender = true;
  1579. detail = "entry_bg";
  1580. key.data.function = KLegacy::FlatBox;
  1581. key.data.shadow = KLegacy::NoShadow;
  1582. key.data.state = (widget->isEnabled()) ? KLegacy::Normal : KLegacy::Insensitive;
  1583. widget->setBackgroundMode(TQWidget::PaletteBase);
  1584. }
  1585. if (widget->isTopLevel() || widget->inherits("QWorkspaceChild")) {
  1586. immediateRender = true;
  1587. bgPixmap = true;
  1588. metaobject = TQMainWindow::staticMetaObject();
  1589. key.cachekey = 0;
  1590. key.data.function = KLegacy::FlatBox;
  1591. detail = "base";
  1592. }
  1593. if (widget->inherits(TQPOPUPMENU_OBJECT_NAME_STRING)) {
  1594. tqDebug("polishing popup '%s'", widget->className());
  1595. metaobject = TQPopupMenu::staticMetaObject();
  1596. widget->setBackgroundMode(TQWidget::PaletteBackground);
  1597. }
  1598. GtkObject *gobj = gobj = priv->gtkDict.find(((metaobject) ? metaobject :
  1599. widget->metaObject()));
  1600. if (gobj) {
  1601. if (gobj->font() && (*gobj->font() != TQApplication::font()))
  1602. widget->setFont(*gobj->font());
  1603. if (immediateRender) {
  1604. TQPixmap *pix = gobj->draw(key, widget->width(), widget->height(), detail);
  1605. if (pix && ! pix->isNull()) {
  1606. if (! bgPixmap) {
  1607. TQPalette pal = widget->palette();
  1608. TQBrush brush;
  1609. // base
  1610. // active
  1611. brush = pal.brush(TQPalette::Active,
  1612. TQColorGroup::Base);
  1613. brush.setPixmap(*pix);
  1614. pal.setBrush(TQPalette::Active,
  1615. TQColorGroup::Base, brush);
  1616. // inactive
  1617. brush = pal.brush(TQPalette::Inactive,
  1618. TQColorGroup::Base);
  1619. brush.setPixmap(*pix);
  1620. pal.setBrush(TQPalette::Inactive,
  1621. TQColorGroup::Base, brush);
  1622. // disabled
  1623. brush = pal.brush(TQPalette::Disabled,
  1624. TQColorGroup::Base);
  1625. brush.setPixmap(*pix);
  1626. pal.setBrush(TQPalette::Disabled,
  1627. TQColorGroup::Base, brush);
  1628. // background - button
  1629. // active
  1630. brush = pal.brush(TQPalette::Active,
  1631. TQColorGroup::Background);
  1632. brush.setPixmap(*pix);
  1633. pal.setBrush(TQPalette::Active,
  1634. TQColorGroup::Background, brush);
  1635. brush = pal.brush(TQPalette::Active,
  1636. TQColorGroup::Button);
  1637. brush.setPixmap(*pix);
  1638. pal.setBrush(TQPalette::Active,
  1639. TQColorGroup::Button, brush);
  1640. // inactive
  1641. brush = pal.brush(TQPalette::Inactive,
  1642. TQColorGroup::Background);
  1643. brush.setPixmap(*pix);
  1644. pal.setBrush(TQPalette::Inactive,
  1645. TQColorGroup::Background, brush);
  1646. brush = pal.brush(TQPalette::Inactive,
  1647. TQColorGroup::Button);
  1648. brush.setPixmap(*pix);
  1649. pal.setBrush(TQPalette::Inactive,
  1650. TQColorGroup::Button, brush);
  1651. // disabled
  1652. brush = pal.brush(TQPalette::Disabled,
  1653. TQColorGroup::Background);
  1654. brush.setPixmap(*pix);
  1655. pal.setBrush(TQPalette::Disabled,
  1656. TQColorGroup::Background, brush);
  1657. brush = pal.brush(TQPalette::Disabled,
  1658. TQColorGroup::Button);
  1659. brush.setPixmap(*pix);
  1660. pal.setBrush(TQPalette::Disabled,
  1661. TQColorGroup::Button, brush);
  1662. widget->setPalette(pal);
  1663. } else
  1664. widget->setBackgroundPixmap(*pix);
  1665. }
  1666. }
  1667. }
  1668. if (eventFilter) {
  1669. widget->installEventFilter(this);
  1670. }
  1671. if (mouseTrack) {
  1672. widget->setMouseTracking(mouseTrack);
  1673. }
  1674. TDEStyle::polish(widget);
  1675. }
  1676. void KLegacyStyle::polishPopupMenu(TQPopupMenu *popup) {
  1677. TDEStyle::polishPopupMenu(popup);
  1678. popup->setMouseTracking(true);
  1679. popup->setCheckable(true);
  1680. popup->installEventFilter(this);
  1681. }
  1682. void KLegacyStyle::unPolish(TQWidget *widget) {
  1683. if (widget->inherits("KDesktop"))
  1684. return;
  1685. widget->setBackgroundOrigin(TQWidget::WidgetOrigin);
  1686. widget->setBackgroundPixmap(TQPixmap());
  1687. widget->removeEventFilter(this);
  1688. widget->unsetPalette();
  1689. widget->setAutoMask(false);
  1690. TDEStyle::unPolish(widget);
  1691. }
  1692. void KLegacyStyle::unPolish(TQApplication *app) {
  1693. app->setFont(priv->oldfont, true);
  1694. app->setPalette(priv->oldpalette, true);
  1695. qt_set_draw_menu_bar_impl(0);
  1696. TDEStyle::unPolish(app);
  1697. }
  1698. void KLegacyStyle::drawKMenuItem(TQPainter *p, int x, int y, int w, int h, const TQColorGroup &g,
  1699. bool active, TQMenuItem *mi, TQBrush *)
  1700. {
  1701. drawMenuBarItem(p, x, y, w, h, mi, (TQColorGroup &) g,
  1702. (mi) ? mi->isEnabled() : false, active);
  1703. }
  1704. void KLegacyStyle::drawMenuBarItem(TQPainter *p, int x, int y, int w, int h, TQMenuItem *mi,
  1705. TQColorGroup &g, bool enabled, bool active)
  1706. {
  1707. if (enabled && active) {
  1708. GtkObject *gobj = priv->gtkDict.find(&menuitem_ptr);
  1709. if (gobj) {
  1710. KLegacyImageDataKey key;
  1711. key.cachekey = 0;
  1712. key.data.function = KLegacy::Box;
  1713. key.data.state = KLegacy::Prelight;
  1714. key.data.shadow = KLegacy::Out;
  1715. TQPixmap *pix = gobj->draw(key, w, h, "menuitem");
  1716. if (pix && ! pix->isNull())
  1717. p->drawPixmap(x, y, *pix);
  1718. }
  1719. }
  1720. drawItem(p, x, y, w, h, AlignCenter|ShowPrefix|DontClip|SingleLine,
  1721. g, enabled, mi->pixmap(), mi->text(), -1, &g.buttonText());
  1722. }
  1723. void KLegacyStyle::drawButton(TQPainter *p, int x, int y , int w, int h,
  1724. const TQColorGroup &g, bool sunken, const TQBrush *fill)
  1725. {
  1726. drawBevelButton(p, x, y, w, h, g, sunken, fill);
  1727. }
  1728. void KLegacyStyle::drawBevelButton(TQPainter *p, int x, int y, int w, int h,
  1729. const TQColorGroup & g, bool sunken,
  1730. const TQBrush *fill)
  1731. {
  1732. GtkObject *gobj = priv->gtkDict.find(TQButton::staticMetaObject());
  1733. if (! gobj) {
  1734. TDEStyle::drawBevelButton(p, x, y, w, h, g, sunken, fill);
  1735. return;
  1736. }
  1737. KLegacyImageDataKey key;
  1738. key.cachekey = 0;
  1739. key.data.function = KLegacy::Box;
  1740. key.data.shadow = (sunken) ? KLegacy::In : KLegacy::Out;
  1741. key.data.state = (sunken) ? KLegacy::Active : KLegacy::Normal;
  1742. TQPixmap *pix = gobj->draw(key, w, h, "button");
  1743. if (pix && (! pix->isNull()))
  1744. p->drawPixmap(x, y, *pix);
  1745. else
  1746. TDEStyle::drawBevelButton(p, x, y, w, h, g, sunken, fill);
  1747. }
  1748. void KLegacyStyle::drawPushButton(TQPushButton *btn, TQPainter *p) {
  1749. GtkObject *gobj = priv->gtkDict.find(TQPushButton::staticMetaObject());
  1750. if (! gobj) {
  1751. TDEStyle::drawPushButton(btn, p);
  1752. return;
  1753. }
  1754. KLegacyImageDataKey key;
  1755. key.cachekey = 0;
  1756. key.data.function = KLegacy::Box;
  1757. TQColorGroup g = btn->colorGroup();
  1758. TQBrush fill = g.brush(TQColorGroup::Button);
  1759. int x1, y1, x2, y2;
  1760. btn->rect().coords(&x1, &y1, &x2, &y2);
  1761. if (btn->isDefault()) {
  1762. // draw default button
  1763. key.data.state = (btn->isEnabled()) ? KLegacy::Normal : KLegacy::Insensitive;
  1764. key.data.shadow = KLegacy::In;
  1765. TQPixmap *pix = gobj->draw(key, x2 -x1 + 1, y2 - y1 + 1, "buttondefault");
  1766. if (! pix)
  1767. pix = gobj->draw(key, x2 - x1 + 1, y2 - y1 + 1, "button");
  1768. if (pix)
  1769. p->drawPixmap(x1, y1, *pix);
  1770. else
  1771. TDEStyle::drawBevelButton(p, x1, y1, x2 - x1 + 1, y2 - y1 + 1,
  1772. g, true, &fill);
  1773. }
  1774. int diw = buttonDefaultIndicatorWidth();
  1775. if (btn->isDefault() || btn->autoDefault()) {
  1776. x1 += diw;
  1777. y1 += diw;
  1778. x2 -= diw;
  1779. y2 -= diw;
  1780. }
  1781. if (btn->isOn() || btn->isDown()) {
  1782. key.data.state = KLegacy::Active;
  1783. key.data.shadow = KLegacy::In;
  1784. } else {
  1785. key.data.state = ((btn->isEnabled()) ?
  1786. ((static_cast<TQWidget *>( btn ) == priv->lastWidget) ? KLegacy::Prelight : KLegacy::Normal) :
  1787. KLegacy::Insensitive);
  1788. key.data.shadow = ((btn->isOn() || btn->isDown()) ?
  1789. KLegacy::In : KLegacy::Out);
  1790. }
  1791. TQPixmap *pix = gobj->draw(key, x2 - x1 + 1, y2 - y1 + 1, "button");
  1792. if (pix && ! pix->isNull())
  1793. p->drawPixmap(x1, y1, *pix);
  1794. else {
  1795. TDEStyle::drawBevelButton(p, x1, y1, x2 - x1 + 1, y2 - y1 + 1,
  1796. g, btn->isOn() || btn->isDown(), &fill);
  1797. }
  1798. }
  1799. void KLegacyStyle::drawIndicator(TQPainter *p, int x, int y, int w, int h,
  1800. const TQColorGroup &g, int state,
  1801. bool down, bool enabled)
  1802. {
  1803. GtkObject *gobj = priv->gtkDict.find(TQCheckBox::staticMetaObject());
  1804. if (! gobj) {
  1805. TDEStyle::drawIndicator(p, x, y, w, h, g, state, down, enabled);
  1806. return;
  1807. }
  1808. KLegacyImageDataKey key;
  1809. key.cachekey = 0;
  1810. key.data.function = KLegacy::Check;
  1811. key.data.state = KLegacy::Normal;
  1812. key.data.shadow = ((state != TQButton::Off) || down) ? KLegacy::In : KLegacy::Out;
  1813. TQPixmap *pix = gobj->draw(key, w, h, "checkbutton");
  1814. if (pix && (! pix->isNull()))
  1815. p->drawPixmap(x, y, *pix);
  1816. else
  1817. TDEStyle::drawIndicator(p, x, y, w, h, g, state, down, enabled);
  1818. }
  1819. void KLegacyStyle::drawIndicatorMask(TQPainter *p, int x, int y, int w, int h, int state) {
  1820. GtkObject *gobj = priv->gtkDict.find(TQCheckBox::staticMetaObject());
  1821. if (! gobj) {
  1822. TDEStyle::drawIndicatorMask(p, x, y, w, h, state);
  1823. return;
  1824. }
  1825. KLegacyImageDataKey key;
  1826. key.cachekey = 0;
  1827. key.data.function = KLegacy::Check;
  1828. key.data.state = KLegacy::Normal;
  1829. key.data.shadow = (state != TQButton::Off) ? KLegacy::In : KLegacy::Out;
  1830. TQPixmap *pix = gobj->draw(key, w, h, "checkbutton");
  1831. if (pix && pix->mask() && ! pix->mask()->isNull())
  1832. p->drawPixmap(x, y, *(pix->mask()));
  1833. else
  1834. TDEStyle::drawIndicatorMask(p, x, y, w, h, state);
  1835. }
  1836. TQSize KLegacyStyle::indicatorSize(void) const {
  1837. GtkObject *gobj = priv->gtkDict.find(TQCheckBox::staticMetaObject());
  1838. if (! gobj) return TDEStyle::indicatorSize();
  1839. KLegacyImageDataKey key;
  1840. key.cachekey = 0;
  1841. key.data.function = KLegacy::Check;
  1842. key.data.shadow = KLegacy::Out;
  1843. KLegacyImageData *id = gobj->getImageData(key, "checkbutton");
  1844. if (! id) return TDEStyle::indicatorSize();
  1845. TQString filename;
  1846. if (! id->file.isNull())
  1847. filename = id->file;
  1848. else if (! id->overlayFile.isNull())
  1849. filename = id->overlayFile;
  1850. else
  1851. return TDEStyle::indicatorSize();
  1852. TQImage *image = imageCache->find(filename);
  1853. if (! image) {
  1854. image = new TQImage(filename);
  1855. if (! image) return TDEStyle::indicatorSize();
  1856. imageCache->insert(filename, image);
  1857. }
  1858. return TQSize(image->width(), image->height());
  1859. }
  1860. void KLegacyStyle::drawExclusiveIndicator(TQPainter *p, int x, int y, int w, int h,
  1861. const TQColorGroup &g, bool on,
  1862. bool down, bool enabled)
  1863. {
  1864. GtkObject *gobj = priv->gtkDict.find(TQRadioButton::staticMetaObject());
  1865. if (! gobj) {
  1866. drawExclusiveIndicator(p, x, y, w, h, g, on, down, enabled);
  1867. return;
  1868. }
  1869. KLegacyImageDataKey key;
  1870. key.cachekey = 0;
  1871. key.data.function = KLegacy::Option;
  1872. key.data.state = KLegacy::Normal;
  1873. key.data.shadow = (on || down) ? KLegacy::In : KLegacy::Out;
  1874. TQPixmap *pix = gobj->draw(key, w, h, "radiobutton");
  1875. if (pix && (! pix->isNull()))
  1876. p->drawPixmap(x, y, *pix);
  1877. else
  1878. TDEStyle::drawExclusiveIndicator(p, x, y, w, h, g, down, enabled);
  1879. }
  1880. void KLegacyStyle::drawExclusiveIndicatorMask(TQPainter *p, int x, int y, int w, int h,
  1881. bool on)
  1882. {
  1883. GtkObject *gobj = priv->gtkDict.find(TQRadioButton::staticMetaObject());
  1884. if (! gobj) {
  1885. TDEStyle::drawExclusiveIndicatorMask(p, x, y, w, h, on);
  1886. return;
  1887. }
  1888. KLegacyImageDataKey key;
  1889. key.cachekey = 0;
  1890. key.data.function = KLegacy::Option;
  1891. key.data.state = KLegacy::Normal;
  1892. key.data.shadow = (on) ? KLegacy::In : KLegacy::Out;
  1893. TQPixmap *pix = gobj->draw(key, w, h, "radiobutton");
  1894. if (pix && pix->mask() && ! pix->mask()->isNull())
  1895. p->drawPixmap(x, y, *(pix->mask()));
  1896. else
  1897. TDEStyle::drawExclusiveIndicatorMask(p, x, y, w, h, on);
  1898. }
  1899. TQSize KLegacyStyle::exclusiveIndicatorSize(void) const {
  1900. GtkObject *gobj = priv->gtkDict.find(TQRadioButton::staticMetaObject());
  1901. if (! gobj) {
  1902. return TDEStyle::indicatorSize();
  1903. }
  1904. KLegacyImageDataKey key;
  1905. key.cachekey = 0;
  1906. key.data.function = KLegacy::Option;
  1907. key.data.shadow = KLegacy::Out;
  1908. KLegacyImageData *id = gobj->getImageData(key, "radiobutton");
  1909. if (! id) return TDEStyle::indicatorSize();
  1910. TQString filename;
  1911. if (! id->file.isNull()) {
  1912. filename = id->file;
  1913. } else if (! id->overlayFile.isNull()) {
  1914. filename = id->overlayFile;
  1915. } else {
  1916. return TDEStyle::indicatorSize();
  1917. }
  1918. TQImage *image = imageCache->find(filename);
  1919. if (! image) {
  1920. image = new TQImage(filename);
  1921. if (! image) {
  1922. return TDEStyle::indicatorSize();
  1923. }
  1924. imageCache->insert(filename, image);
  1925. }
  1926. return TQSize(image->width(), image->height());
  1927. }
  1928. void KLegacyStyle::drawPopupMenuItem(TQPainter *p, bool checkable, int maxpmw, int tab,
  1929. TQMenuItem *mi, const TQPalette &pal, bool act,
  1930. bool enabled, int x, int y, int w, int h)
  1931. {
  1932. const TQColorGroup & g = pal.active();
  1933. TQColorGroup itemg = (! enabled) ? pal.disabled() : pal.active();
  1934. if (checkable)
  1935. maxpmw = QMAX(maxpmw, 15);
  1936. int checkcol = maxpmw;
  1937. if (mi && mi->isSeparator()) {
  1938. p->setPen( g.dark() );
  1939. p->drawLine( x, y, x+w, y );
  1940. p->setPen( g.light() );
  1941. p->drawLine( x, y+1, x+w, y+1 );
  1942. return;
  1943. }
  1944. if ( act && enabled ) {
  1945. GtkObject *gobj = priv->gtkDict.find(&menuitem_ptr);
  1946. if (gobj) {
  1947. KLegacyImageDataKey key;
  1948. key.cachekey = 0;
  1949. key.data.function = KLegacy::Box;
  1950. key.data.state = KLegacy::Prelight;
  1951. key.data.shadow = KLegacy::Out;
  1952. TQPixmap *pix = gobj->draw(key, w, h, "menuitem");
  1953. if (pix && ! pix->isNull())
  1954. p->drawPixmap(x, y, *pix);
  1955. }
  1956. } else
  1957. p->fillRect(x, y, w, h, g.brush( TQColorGroup::Button ));
  1958. if ( !mi )
  1959. return;
  1960. if ( mi->isChecked() ) {
  1961. if ( mi->iconSet() ) {
  1962. qDrawShadePanel( p, x+2, y+2, checkcol, h-2*2,
  1963. g, true, 1, &g.brush( TQColorGroup::Midlight ) );
  1964. }
  1965. } else if ( !act ) {
  1966. p->fillRect(x+2, y+2, checkcol, h-2*2,
  1967. g.brush( TQColorGroup::Button ));
  1968. }
  1969. if ( mi->iconSet() ) { // draw iconset
  1970. TQIconSet::Mode mode = (enabled) ? TQIconSet::Normal : TQIconSet::Disabled;
  1971. if (act && enabled)
  1972. mode = TQIconSet::Active;
  1973. TQPixmap pixmap = mi->iconSet()->pixmap(TQIconSet::Small, mode);
  1974. int pixw = pixmap.width();
  1975. int pixh = pixmap.height();
  1976. TQRect cr( x + 2, y+2, checkcol, h-2*2 );
  1977. TQRect pmr( 0, 0, pixw, pixh );
  1978. pmr.moveCenter(cr.center());
  1979. p->setPen( itemg.text() );
  1980. p->drawPixmap( pmr.topLeft(), pixmap );
  1981. } else if (checkable) {
  1982. int mw = checkcol;
  1983. int mh = h - 4;
  1984. if (mi->isChecked())
  1985. drawCheckMark(p, x+2, y+2, mw, mh, itemg, act, ! enabled);
  1986. }
  1987. p->setPen( g.buttonText() );
  1988. TQColor discol;
  1989. if (! enabled) {
  1990. discol = itemg.text();
  1991. p->setPen( discol );
  1992. }
  1993. if (mi->custom()) {
  1994. p->save();
  1995. mi->custom()->paint(p, itemg, act, enabled, x + checkcol + 4, y + 2,
  1996. w - checkcol - tab - 3, h - 4);
  1997. p->restore();
  1998. }
  1999. TQString s = mi->text();
  2000. if ( !s.isNull() ) { // draw text
  2001. int t = s.find( '\t' );
  2002. int m = 2;
  2003. const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
  2004. if ( t >= 0 ) { // draw tab text
  2005. p->drawText( x+w-tab-2-2,
  2006. y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
  2007. }
  2008. p->drawText(x + checkcol + 4, y + 2, w - checkcol -tab - 3, h - 4,
  2009. text_flags, s, t);
  2010. } else if (mi->pixmap()) {
  2011. TQPixmap *pixmap = mi->pixmap();
  2012. if (pixmap->depth() == 1) p->setBackgroundMode(OpaqueMode);
  2013. p->drawPixmap(x + checkcol + 2, y + 2, *pixmap);
  2014. if (pixmap->depth() == 1) p->setBackgroundMode(TransparentMode);
  2015. }
  2016. if (mi->popup()) {
  2017. int hh = h / 2;
  2018. drawMenuArrow(p, RightArrow, (act) ? mi->isEnabled() : false,
  2019. x + w - hh - 6, y + (hh / 2), hh, hh, g, mi->isEnabled());
  2020. }
  2021. }
  2022. void KLegacyStyle::drawComboButton(TQPainter *p, int x, int y, int w, int h,
  2023. const TQColorGroup &g, bool sunken, bool editable,
  2024. bool enabled, const TQBrush *b)
  2025. {
  2026. GtkObject *gobj = priv->gtkDict.find(TQComboBox::staticMetaObject());
  2027. if (! gobj) {
  2028. TDEStyle::drawComboButton(p, x, y, w, h, g, sunken, editable, enabled, b);
  2029. return;
  2030. }
  2031. KLegacyImageDataKey key;
  2032. key.cachekey = 0;
  2033. key.data.function = KLegacy::Box;
  2034. key.data.state = KLegacy::Normal;
  2035. key.data.shadow = KLegacy::Out;
  2036. if (priv->lastWidget && priv->lastWidget->inherits(TQCOMBOBOX_OBJECT_NAME_STRING))
  2037. key.data.state = KLegacy::Prelight;
  2038. TQPixmap *pix = gobj->draw(key, w, h, "optionmenu");
  2039. if (pix && ! pix->isNull()) {
  2040. p->drawPixmap(x, y, *pix);
  2041. } else {
  2042. TDEStyle::drawComboButton(p, x, y, w, h, g, sunken, editable, enabled, b);
  2043. return;
  2044. }
  2045. TQRect rect = comboButtonRect(x, y, w, h);
  2046. int tw = w - rect.width() - rect.right() - rect.left();
  2047. int th = rect.height();
  2048. key.data.function = KLegacy::Tab;
  2049. key.data.state = KLegacy::Normal;
  2050. pix = gobj->draw(key, tw, th, "optionmenutab");
  2051. if (pix && ! pix->isNull())
  2052. p->drawPixmap(x + rect.width() + rect.left() + ((18 - pix->width()) / 2),
  2053. y + rect.y() + ((rect.height() - pix->height()) / 2), *pix);
  2054. }
  2055. TQRect KLegacyStyle::comboButtonRect(int x, int y, int w, int h) {
  2056. GtkObject *gobj = priv->gtkDict.find(TQComboBox::staticMetaObject());
  2057. if (! gobj) {
  2058. return TDEStyle::comboButtonRect(x, y, w, h);
  2059. }
  2060. KLegacyImageDataKey key;
  2061. key.cachekey = 0;
  2062. key.data.function = KLegacy::Box;
  2063. KLegacyImageData *id = gobj->getImageData(key, "optionmenu");
  2064. if (! id) {
  2065. return TDEStyle::comboButtonRect(x, y, w, h);
  2066. }
  2067. return TQRect(x + id->border.left() + 1, y + id->border.top() + 1,
  2068. w - id->border.left() - id->border.right() - 18,
  2069. h - id->border.top() - id->border.bottom() - 2);
  2070. }
  2071. TQRect KLegacyStyle::comboButtonFocusRect(int x, int y, int w, int h) {
  2072. return comboButtonRect(x, y, w, h);
  2073. }
  2074. TQStyle::ScrollControl KLegacyStyle::scrollBarPointOver(const TQScrollBar *scrollbar,
  2075. int sliderStart, const TQPoint &p)
  2076. {
  2077. return TQCommonStyle::scrollBarPointOver(scrollbar, sliderStart, p);
  2078. }
  2079. void KLegacyStyle::scrollBarMetrics(const TQScrollBar *scrollbar, int &sliderMin,
  2080. int &sliderMax, int &sliderLength, int &buttonDim)
  2081. {
  2082. int maxLength;
  2083. int b = defaultFrameWidth();
  2084. int length = ((scrollbar->orientation() == TQScrollBar::Horizontal) ?
  2085. scrollbar->width() : scrollbar->height());
  2086. int extent = ((scrollbar->orientation() == TQScrollBar::Horizontal) ?
  2087. scrollbar->height() : scrollbar->width());
  2088. if (length > ((extent - (b * 2) - 1) * 2) + (b * 2))
  2089. buttonDim = extent - (b * 2);
  2090. else
  2091. buttonDim = ((length - (b * 2)) / 2) - 1;
  2092. sliderMin = b + buttonDim;
  2093. maxLength = length - (b * 2) - (buttonDim * 2);
  2094. if (scrollbar->maxValue() == scrollbar->minValue()) {
  2095. sliderLength = maxLength - 2;
  2096. } else {
  2097. uint range = scrollbar->maxValue() - scrollbar->minValue();
  2098. sliderLength = (scrollbar->pageStep() * maxLength) /
  2099. (range + scrollbar->pageStep());
  2100. if (sliderLength < buttonDim || range > (INT_MAX / 2))
  2101. sliderLength = buttonDim;
  2102. if (sliderLength >= maxLength)
  2103. sliderLength = maxLength - 2;
  2104. }
  2105. sliderMax = sliderMin + maxLength - sliderLength;
  2106. sliderMin += 1;
  2107. sliderMax -= 1;
  2108. }
  2109. void KLegacyStyle::drawScrollBarControls(TQPainter *p, const TQScrollBar *scrollbar,
  2110. int start, uint controls, uint active)
  2111. {
  2112. if (! scrollbar->isVisible()) return;
  2113. GtkObject *gobj = priv->gtkDict.find(TQScrollBar::staticMetaObject());
  2114. if (! gobj) {
  2115. TDEStyle::drawScrollBarControls(p, scrollbar, start, controls, active);
  2116. return;
  2117. }
  2118. KLegacyImageDataKey gkey;
  2119. gkey.cachekey = 0;
  2120. gkey.data.function = KLegacy::Box;
  2121. gkey.data.orientation = scrollbar->orientation() + 1;
  2122. KLegacyImageData *groove_id = gobj->getImageData(gkey, "trough");
  2123. if (! groove_id) {
  2124. TDEStyle::drawScrollBarControls(p, scrollbar, start, controls, active);
  2125. return;
  2126. }
  2127. int sliderMin;
  2128. int sliderMax;
  2129. int sliderLen;
  2130. int buttonDim;
  2131. scrollBarMetrics(scrollbar, sliderMin, sliderMax, sliderLen, buttonDim);
  2132. // the rectangle for the slider
  2133. TQRect slider(
  2134. // x
  2135. ((scrollbar->orientation() == Vertical) ?
  2136. defaultFrameWidth() : start),
  2137. // y
  2138. ((scrollbar->orientation() == Vertical) ?
  2139. start : defaultFrameWidth()),
  2140. // w
  2141. ((scrollbar->orientation() == Vertical) ?
  2142. buttonDim : sliderLen),
  2143. // h
  2144. ((scrollbar->orientation() == Vertical) ?
  2145. sliderLen : buttonDim));
  2146. KLegacyImageDataKey skey;
  2147. skey.cachekey = 0;
  2148. skey.data.function = KLegacy::Box;
  2149. skey.data.orientation = scrollbar->orientation() + 1;
  2150. if ((active & Slider) || (priv->hovering && slider.contains(priv->mousePos)))
  2151. skey.data.state = KLegacy::Prelight;
  2152. else
  2153. skey.data.state = KLegacy::Normal;
  2154. KLegacyImageData *slider_id = gobj->getImageData(skey, "slider");
  2155. if (! slider_id) {
  2156. TDEStyle::drawScrollBarControls(p, scrollbar, start, controls, active);
  2157. return;
  2158. }
  2159. TQPixmap *groove_pm = gobj->draw(groove_id, scrollbar->width(), scrollbar->height());
  2160. if ((! groove_pm) || (groove_pm->isNull())) {
  2161. groove_pm = 0;
  2162. }
  2163. TQPixmap *slider_pm = gobj->draw(slider_id, slider.width(), slider.height());
  2164. if ((! slider_pm) || (slider_pm->isNull())) {
  2165. slider_pm = 0;
  2166. }
  2167. TQPixmap buf(scrollbar->size());
  2168. {
  2169. TQPainter p2(&buf);
  2170. if (groove_pm) {
  2171. p2.drawTiledPixmap(scrollbar->rect(), *groove_pm);
  2172. }
  2173. if (slider_pm) {
  2174. p2.drawTiledPixmap(slider, *slider_pm);
  2175. }
  2176. // arrows
  2177. int x, y;
  2178. x = y = defaultFrameWidth();
  2179. drawArrow(&p2, ((scrollbar->orientation() == Vertical) ?
  2180. UpArrow : LeftArrow),
  2181. (active & SubLine), x, y,
  2182. buttonDim,
  2183. buttonDim,
  2184. scrollbar->colorGroup(), true);
  2185. if (scrollbar->orientation() == Vertical)
  2186. y = scrollbar->height() - buttonDim - defaultFrameWidth();
  2187. else
  2188. x = scrollbar->width() - buttonDim - defaultFrameWidth();
  2189. drawArrow(&p2, ((scrollbar->orientation() == Vertical) ?
  2190. DownArrow : RightArrow),
  2191. (active & AddLine), x, y,
  2192. buttonDim,
  2193. buttonDim,
  2194. scrollbar->colorGroup(), true);
  2195. }
  2196. p->drawPixmap(0, 0, buf);
  2197. }
  2198. void KLegacyStyle::drawSlider(TQPainter *p, int x, int y, int w, int h, const TQColorGroup &g,
  2199. Orientation orientation, bool tickAbove, bool tickBelow)
  2200. {
  2201. GtkObject *gobj = priv->gtkDict.find(TQSlider::staticMetaObject());
  2202. if (! gobj) {
  2203. TDEStyle::drawSlider(p, x, y, w, h, g, orientation, tickAbove, tickBelow);
  2204. return;
  2205. }
  2206. KLegacyImageDataKey key;
  2207. key.cachekey = 0;
  2208. key.data.function = KLegacy::Box;
  2209. key.data.shadow = KLegacy::Out;
  2210. key.data.state = KLegacy::Normal;
  2211. key.data.orientation = orientation + 1;
  2212. TQPixmap *pix = gobj->draw(key, w, h, "slider");
  2213. if (pix && ! pix->isNull())
  2214. p->drawPixmap(x, y, *pix);
  2215. else
  2216. TDEStyle::drawSlider(p, x, y, w, h, g, orientation, tickAbove, tickBelow);
  2217. }
  2218. void KLegacyStyle::drawSliderGroove(TQPainter *p, int x, int y, int w, int h,
  2219. const TQColorGroup &g, QCOORD c, Orientation o)
  2220. {
  2221. GtkObject *gobj = priv->gtkDict.find(TQSlider::staticMetaObject());
  2222. if (! gobj) {
  2223. TDEStyle::drawSliderGroove(p, x, y, w, h, g, c, o);
  2224. return;
  2225. }
  2226. KLegacyImageDataKey key;
  2227. key.cachekey = 0;
  2228. key.data.function = KLegacy::Box;
  2229. key.data.shadow = KLegacy::In;
  2230. key.data.state = KLegacy::Active;
  2231. key.data.orientation = o + 1;
  2232. TQPixmap *pix = gobj->draw(key, w, h, "trough");
  2233. if (pix && ! pix->isNull())
  2234. p->drawPixmap(x, y, *pix);
  2235. else
  2236. TDEStyle::drawSliderGroove(p, x, y, w, h, g, c, o);
  2237. }
  2238. void KLegacyStyle::drawArrow(TQPainter *p, ArrowType type, bool down,
  2239. int x, int y, int w, int h,
  2240. const TQColorGroup &g, bool enabled, const TQBrush *b)
  2241. {
  2242. GtkObject *gobj = priv->gtkDict.find(&arrow_ptr);
  2243. if (! gobj) {
  2244. TDEStyle::drawArrow(p, type, down, x, y, w, h, g, enabled, b);
  2245. return;
  2246. }
  2247. KLegacyImageDataKey key;
  2248. key.cachekey = 0;
  2249. key.data.function = KLegacy::Arrow;
  2250. key.data.state = (down) ? KLegacy::Active : KLegacy::Normal;
  2251. key.data.shadow = (down) ? KLegacy::In : KLegacy::NoShadow;
  2252. key.data.arrowDirection = type + 1;
  2253. if ((! down) && priv->hovering &&
  2254. TQRect(x, y, w, h).contains(priv->mousePos)) {
  2255. key.data.state = KLegacy::Prelight;
  2256. }
  2257. TQPixmap *pix = gobj->draw(key, w, h, "arrow");
  2258. if (pix && ! pix->isNull())
  2259. p->drawPixmap(x, y, *pix);
  2260. else
  2261. TDEStyle::drawArrow(p, type, down, x, y, w, h, g, enabled, b);
  2262. }
  2263. void KLegacyStyle::drawMenuArrow(TQPainter *p, ArrowType type, bool down,
  2264. int x, int y, int w, int h,
  2265. const TQColorGroup &g, bool enabled, const TQBrush *b)
  2266. {
  2267. GtkObject *gobj = priv->gtkDict.find(&menuitem_ptr);
  2268. if (! gobj) {
  2269. TDEStyle::drawArrow(p, type, down, x, y, w, h, g, enabled, b);
  2270. return;
  2271. }
  2272. KLegacyImageDataKey key;
  2273. key.cachekey = 0;
  2274. key.data.function = KLegacy::Arrow;
  2275. key.data.state = (down) ? KLegacy::Active : KLegacy::Normal;
  2276. key.data.shadow = (down) ? KLegacy::In : KLegacy::NoShadow;
  2277. key.data.arrowDirection = type + 1;
  2278. TQPixmap *pix = gobj->draw(key, w, h, "arrow");
  2279. if (pix && ! pix->isNull())
  2280. p->drawPixmap(x + ((w - pix->width()) / 2),
  2281. y + ((h - pix->height()) / 2), *pix);
  2282. else
  2283. TDEStyle::drawArrow(p, type, down, x, y, w, h, g, enabled, b);
  2284. }
  2285. void KLegacyStyle::drawPanel(TQPainter *p, int x, int y, int w, int h,
  2286. const TQColorGroup &g, bool sunken, int, const TQBrush *brush)
  2287. {
  2288. TDEStyle::drawPanel(p, x, y, w, h, g, sunken, 1, brush);
  2289. }
  2290. void KLegacyStyle::drawPopupPanel(TQPainter *p, int x, int y, int w, int h,
  2291. const TQColorGroup &g, int, const TQBrush *fill)
  2292. {
  2293. TQBrush brush = (fill) ? *fill : g.brush(TQColorGroup::Background);
  2294. p->fillRect(x, y, w, h, brush);
  2295. }
  2296. void KLegacyStyle::drawCheckMark(TQPainter *p, int x, int y, int w, int h,
  2297. const TQColorGroup &g, bool activated, bool disabled)
  2298. {
  2299. GtkObject *gobj = priv->gtkDict.find(&checkmenuitem_ptr);
  2300. if (! gobj) {
  2301. TDEStyle::drawCheckMark(p, x, y, w, h, g, activated, disabled);
  2302. return;
  2303. }
  2304. KLegacyImageDataKey key;
  2305. key.cachekey = 0;
  2306. key.data.function = KLegacy::Check;
  2307. key.data.shadow = (disabled) ? KLegacy::Out : KLegacy::In;
  2308. TQPixmap *pix = gobj->draw(key, w, h);
  2309. if (pix && (! pix->isNull())) {
  2310. x += (w - pix->width()) / 2;
  2311. y += (h - pix->height()) / 2;
  2312. p->drawPixmap(x, y, *pix);
  2313. } else {
  2314. TDEStyle::drawCheckMark(p, x, y, w, h, g, activated, disabled);
  2315. }
  2316. }
  2317. void KLegacyStyle::drawSplitter(TQPainter *p, int x, int y, int w, int h,
  2318. const TQColorGroup &g, Orientation orientation)
  2319. {
  2320. if (orientation == Horizontal) {
  2321. int xpos = x + (w / 2);
  2322. int kpos = 10;
  2323. int ksize = splitterWidth() - 2;
  2324. qDrawShadeLine(p, xpos, kpos + ksize - 1, xpos, h, g);
  2325. drawBevelButton(p, xpos - (splitterWidth() / 2) + 1, kpos, ksize, ksize,
  2326. g, false, &g.brush(TQColorGroup::Button));
  2327. qDrawShadeLine(p, xpos, 0, xpos, kpos, g);
  2328. } else {
  2329. int ypos = y + (h / 2);
  2330. int kpos = w - 10 - splitterWidth();
  2331. int ksize = splitterWidth() - 2;
  2332. qDrawShadeLine(p, 0, ypos, kpos, ypos, g);
  2333. drawBevelButton(p, kpos, ypos - (splitterWidth() / 2) + 1, ksize, ksize,
  2334. g, false, &g.brush(TQColorGroup::Button));
  2335. qDrawShadeLine(p, kpos + ksize - 1, ypos, w, ypos, g);
  2336. }
  2337. }
  2338. void KLegacyStyle::drawTab(TQPainter *p, const TQTabBar *tabbar, TQTab *tab, bool selected)
  2339. {
  2340. GtkObject *gobj = priv->gtkDict.find(TQTabBar::staticMetaObject());
  2341. if (! gobj) {
  2342. TDEStyle::drawTab(p, tabbar, tab, selected);
  2343. return;
  2344. }
  2345. KLegacyImageDataKey key;
  2346. key.cachekey = 0;
  2347. key.data.function = KLegacy::Extension;
  2348. key.data.state = (! selected) ? KLegacy::Active : KLegacy::Normal;
  2349. key.data.shadow = KLegacy::Out;
  2350. key.data.gapSide = (tabbar->shape() == TQTabBar::RoundedAbove ||
  2351. tabbar->shape() == TQTabBar::TriangularAbove) ?
  2352. KLegacy::Bottom : KLegacy::Top;
  2353. int ry = tab->r.top(), rh = tab->r.height();
  2354. if (! selected) {
  2355. rh -= 2;
  2356. if (tabbar->shape() == TQTabBar::RoundedAbove ||
  2357. tabbar->shape() == TQTabBar::TriangularAbove)
  2358. ry += 2;
  2359. }
  2360. TQPixmap *pix = gobj->draw(key, tab->r.width(), rh, "tab");
  2361. if (pix && ! pix->isNull())
  2362. p->drawPixmap(tab->r.left(), ry, *pix);
  2363. else
  2364. TDEStyle::drawTab(p, tabbar, tab, selected);
  2365. }
  2366. void KLegacyStyle::drawKBarHandle(TQPainter *p, int x, int y, int w, int h,
  2367. const TQColorGroup &g, TDEToolBarPos type, TQBrush *fill)
  2368. {
  2369. GtkObject *gobj = priv->gtkDict.find(TQToolBar::staticMetaObject());
  2370. if (! gobj) {
  2371. TDEStyle::drawKBarHandle(p, x, y, w, h, g, type, fill);
  2372. return;
  2373. }
  2374. KLegacyImageDataKey key;
  2375. key.cachekey = 0;
  2376. key.data.function = KLegacy::Handle;
  2377. key.data.state = KLegacy::Normal;
  2378. key.data.shadow = KLegacy::Out;
  2379. key.data.orientation = (type == Left || type == Right) ?
  2380. Vertical + 1: Horizontal + 1;
  2381. TQPixmap *pix = gobj->draw(key, w, h, "handle");
  2382. if (pix && ! pix->isNull())
  2383. p->drawPixmap(x, y, *pix);
  2384. }
  2385. void KLegacyStyle::drawKickerHandle(TQPainter *p, int x, int y, int w, int h,
  2386. const TQColorGroup &g, TQBrush *fill)
  2387. {
  2388. drawKBarHandle(p, x, y, w, h, g, Left, fill);
  2389. }
  2390. void KLegacyStyle::drawKickerAppletHandle(TQPainter *p, int x, int y, int w, int h,
  2391. const TQColorGroup &g, TQBrush *fill)
  2392. {
  2393. drawKBarHandle(p, x, y, w, h, g, Left, fill);
  2394. }
  2395. void KLegacyStyle::drawKickerTaskButton(TQPainter *p, int x, int y, int w, int h,
  2396. const TQColorGroup &g, const TQString &title,
  2397. bool active, TQPixmap *icon, TQBrush *fill)
  2398. {
  2399. drawBevelButton(p, x, y, w, h, g, active, fill);
  2400. const int pxWidth = 20;
  2401. int textPos = pxWidth;
  2402. TQRect br(buttonRect(x, y, w, h));
  2403. if (active)
  2404. p->translate(1,1);
  2405. if (icon && ! icon->isNull()) {
  2406. int dx = (pxWidth - icon->width()) / 2;
  2407. int dy = (h - icon->height()) / 2;
  2408. p->drawPixmap(br.x() + dx, dy, *icon);
  2409. }
  2410. TQString s(title);
  2411. static const TQString &modStr = TDEGlobal::staticQString(
  2412. TQString::fromUtf8("[") + i18n("modified") + TQString::fromUtf8("]"));
  2413. int modStrPos = s.find(modStr);
  2414. if (modStrPos != -1) {
  2415. s.remove(modStrPos, modStr.length()+1);
  2416. TQPixmap modPixmap = SmallIcon("modified");
  2417. int dx = (pxWidth - modPixmap.width()) / 2;
  2418. int dy = (h - modPixmap.height()) / 2;
  2419. p->drawPixmap(br.x() + textPos + dx, dy, modPixmap);
  2420. textPos += pxWidth;
  2421. }
  2422. if (! s.isEmpty()) {
  2423. if (p->fontMetrics().width(s) > br.width() - textPos) {
  2424. int maxLen = br.width() - textPos - p->fontMetrics().width("...");
  2425. while ( (! s.isEmpty()) && (p->fontMetrics().width(s) > maxLen))
  2426. s.truncate(s.length() - 1);
  2427. s.append("...");
  2428. }
  2429. p->setPen((active) ? g.foreground() : g.buttonText());
  2430. p->drawText(br.x() + textPos, -1, w - textPos, h, AlignVCenter | AlignLeft, s);
  2431. }
  2432. }
  2433. bool KLegacyStyle::eventFilter(TQObject *obj, TQEvent *e) {
  2434. switch (e->type()) {
  2435. case TQEvent::Resize:
  2436. {
  2437. TQWidget *w = (TQWidget *) obj;
  2438. if (w->inherits(TQPOPUPMENU_OBJECT_NAME_STRING) && w->width() < 700) {
  2439. GtkObject *gobj = priv->gtkDict.find(TQPopupMenu::staticMetaObject());
  2440. if (gobj) {
  2441. KLegacyImageDataKey key;
  2442. key.cachekey = 0;
  2443. key.data.function = KLegacy::Box;
  2444. key.data.state = KLegacy::Normal;
  2445. key.data.shadow = KLegacy::Out;
  2446. TQPixmap *pix = gobj->draw(key, w->width(), w->height(), "menu");
  2447. if (pix && ! pix->isNull()) {
  2448. TQPalette pal = w->palette();
  2449. // active
  2450. TQBrush brush = pal.brush(TQPalette::Active,
  2451. TQColorGroup::Background);
  2452. brush.setPixmap(*pix);
  2453. pal.setBrush(TQPalette::Active,
  2454. TQColorGroup::Background, brush);
  2455. brush = pal.brush(TQPalette::Active,
  2456. TQColorGroup::Button);
  2457. brush.setPixmap(*pix);
  2458. pal.setBrush(TQPalette::Active,
  2459. TQColorGroup::Button, brush);
  2460. // inactive
  2461. brush = pal.brush(TQPalette::Inactive,
  2462. TQColorGroup::Background);
  2463. brush.setPixmap(*pix);
  2464. pal.setBrush(TQPalette::Inactive,
  2465. TQColorGroup::Background, brush);
  2466. brush = pal.brush(TQPalette::Inactive,
  2467. TQColorGroup::Button);
  2468. brush.setPixmap(*pix);
  2469. pal.setBrush(TQPalette::Inactive,
  2470. TQColorGroup::Button, brush);
  2471. // disabled
  2472. brush = pal.brush(TQPalette::Disabled,
  2473. TQColorGroup::Background);
  2474. brush.setPixmap(*pix);
  2475. pal.setBrush(TQPalette::Disabled,
  2476. TQColorGroup::Background, brush);
  2477. brush = pal.brush(TQPalette::Disabled,
  2478. TQColorGroup::Button);
  2479. brush.setPixmap(*pix);
  2480. pal.setBrush(TQPalette::Disabled,
  2481. TQColorGroup::Button, brush);
  2482. w->setPalette(pal);
  2483. }
  2484. }
  2485. } else if (w->isTopLevel() || w->inherits("QWorkspaceChild")) {
  2486. GtkObject *gobj = priv->gtkDict.find(TQMainWindow::staticMetaObject());
  2487. if (gobj) {
  2488. KLegacyImageDataKey key;
  2489. key.cachekey = 0;
  2490. key.data.function = KLegacy::FlatBox;
  2491. TQPixmap *p = gobj->draw(key, w->width(), w->height(), "base");
  2492. if (p && (! p->isNull()))
  2493. w->setBackgroundPixmap(*p);
  2494. }
  2495. } else if (w->inherits(TQLINEEDIT_OBJECT_NAME_STRING)) {
  2496. GtkObject *gobj = priv->gtkDict.find(TQLineEdit::staticMetaObject());
  2497. if (gobj) {
  2498. KLegacyImageDataKey key;
  2499. key.cachekey = 0;
  2500. key.data.function = KLegacy::FlatBox;
  2501. key.data.shadow = KLegacy::NoShadow;
  2502. key.data.state = (w->isEnabled()) ? KLegacy::Normal : KLegacy::Insensitive;
  2503. TQPixmap *pix = gobj->draw(key, w->width(), w->height(),
  2504. "entry_bg");
  2505. if (pix && (! pix->isNull())) {
  2506. TQPalette pal = w->palette();
  2507. // active
  2508. TQBrush brush = pal.brush(TQPalette::Active,
  2509. TQColorGroup::Base);
  2510. brush.setPixmap(*pix);
  2511. pal.setBrush(TQPalette::Active,
  2512. TQColorGroup::Base, brush);
  2513. // inactive
  2514. brush = pal.brush(TQPalette::Inactive,
  2515. TQColorGroup::Base);
  2516. brush.setPixmap(*pix);
  2517. pal.setBrush(TQPalette::Inactive,
  2518. TQColorGroup::Base, brush);
  2519. // disabled
  2520. brush = pal.brush(TQPalette::Disabled,
  2521. TQColorGroup::Base);
  2522. brush.setPixmap(*pix);
  2523. pal.setBrush(TQPalette::Disabled,
  2524. TQColorGroup::Base, brush);
  2525. w->setPalette(pal);
  2526. }
  2527. }
  2528. } else if (w->inherits(TQMENUBAR_OBJECT_NAME_STRING) ||
  2529. w->inherits(TQTOOLBAR_OBJECT_NAME_STRING)) {
  2530. GtkObject *gobj = priv->gtkDict.find(TQMenuBar::staticMetaObject());
  2531. if (gobj) {
  2532. KLegacyImageDataKey key;
  2533. key.cachekey = 0;
  2534. key.data.function = KLegacy::Box;
  2535. key.data.state = KLegacy::Normal;
  2536. key.data.shadow = KLegacy::Out;
  2537. TQPixmap *pix = gobj->draw(key, w->width(), w->height(),
  2538. "menubar");
  2539. if (pix && (! pix->isNull())) {
  2540. TQPalette pal = w->palette();
  2541. // active
  2542. TQBrush brush = pal.brush(TQPalette::Active,
  2543. TQColorGroup::Background);
  2544. brush.setPixmap(*pix);
  2545. pal.setBrush(TQPalette::Active,
  2546. TQColorGroup::Background, brush);
  2547. brush = pal.brush(TQPalette::Active,
  2548. TQColorGroup::Button);
  2549. brush.setPixmap(*pix);
  2550. pal.setBrush(TQPalette::Active,
  2551. TQColorGroup::Button, brush);
  2552. // inactive
  2553. brush = pal.brush(TQPalette::Inactive,
  2554. TQColorGroup::Background);
  2555. brush.setPixmap(*pix);
  2556. pal.setBrush(TQPalette::Inactive,
  2557. TQColorGroup::Background, brush);
  2558. brush = pal.brush(TQPalette::Inactive,
  2559. TQColorGroup::Button);
  2560. brush.setPixmap(*pix);
  2561. pal.setBrush(TQPalette::Inactive,
  2562. TQColorGroup::Button, brush);
  2563. // disabled
  2564. brush = pal.brush(TQPalette::Disabled,
  2565. TQColorGroup::Background);
  2566. brush.setPixmap(*pix);
  2567. pal.setBrush(TQPalette::Disabled,
  2568. TQColorGroup::Background, brush);
  2569. brush = pal.brush(TQPalette::Disabled,
  2570. TQColorGroup::Button);
  2571. brush.setPixmap(*pix);
  2572. pal.setBrush(TQPalette::Disabled,
  2573. TQColorGroup::Button, brush);
  2574. w->setPalette(pal);
  2575. }
  2576. }
  2577. }
  2578. break;
  2579. }
  2580. case TQEvent::Enter:
  2581. {
  2582. if (obj->inherits(TQPUSHBUTTON_OBJECT_NAME_STRING) ||
  2583. obj->inherits(TQCOMBOBOX_OBJECT_NAME_STRING) ||
  2584. obj->inherits(TQSLIDER_OBJECT_NAME_STRING) ||
  2585. obj->inherits(TQSCROLLBAR_OBJECT_NAME_STRING)) {
  2586. priv->lastWidget = (TQWidget *) obj;
  2587. priv->lastWidget->repaint(false);
  2588. } else if (obj->inherits(TQRADIOBUTTON_OBJECT_NAME_STRING)) {
  2589. TQWidget *w = (TQWidget *) obj;
  2590. if (! w->isTopLevel() && w->isEnabled()) {
  2591. GtkObject *gobj = priv->gtkDict.find(TQRadioButton::staticMetaObject());
  2592. if (gobj) {
  2593. KLegacyImageDataKey key;
  2594. key.cachekey = 0;
  2595. key.data.function = KLegacy::FlatBox;
  2596. TQPixmap *pix = gobj->draw(key, w->width(), w->height());
  2597. if (pix && (! pix->isNull())) {
  2598. TQPalette pal = w->palette();
  2599. TQBrush brush = pal.brush(TQPalette::Normal,
  2600. TQColorGroup::Background);
  2601. brush.setPixmap(*pix);
  2602. pal.setBrush(TQPalette::Normal,
  2603. TQColorGroup::Background, brush);
  2604. w->setPalette(pal);
  2605. w->setBackgroundMode(TQWidget::PaletteBackground);
  2606. w->setBackgroundOrigin(TQWidget::WidgetOrigin);
  2607. }
  2608. }
  2609. }
  2610. } else if (obj->inherits(TQCHECKBOX_OBJECT_NAME_STRING)) {
  2611. TQWidget *w = (TQWidget *) obj;
  2612. if (! w->isTopLevel() && w->isEnabled()) {
  2613. GtkObject *gobj = priv->gtkDict.find(TQCheckBox::staticMetaObject());
  2614. if (gobj) {
  2615. KLegacyImageDataKey key;
  2616. key.cachekey = 0;
  2617. key.data.function = KLegacy::FlatBox;
  2618. TQPixmap *pix = gobj->draw(key, w->width(), w->height());
  2619. if (pix && (! pix->isNull())) {
  2620. TQPalette pal = w->palette();
  2621. TQBrush brush = pal.brush(TQPalette::Normal,
  2622. TQColorGroup::Background);
  2623. brush.setPixmap(*pix);
  2624. pal.setBrush(TQPalette::Normal,
  2625. TQColorGroup::Background, brush);
  2626. w->setPalette(pal);
  2627. w->setBackgroundMode(TQWidget::PaletteBackground);
  2628. w->setBackgroundOrigin(TQWidget::WidgetOrigin);
  2629. }
  2630. }
  2631. }
  2632. }
  2633. break;
  2634. }
  2635. case TQEvent::Leave:
  2636. {
  2637. if (obj == priv->lastWidget) {
  2638. priv->lastWidget = 0;
  2639. ((TQWidget *) obj)->repaint(false);
  2640. } else if (obj->inherits(TQRADIOBUTTON_OBJECT_NAME_STRING) ||
  2641. obj->inherits(TQCHECKBOX_OBJECT_NAME_STRING)) {
  2642. TQWidget *w = (TQWidget *) obj;
  2643. if (! w->isTopLevel()) {
  2644. w->setBackgroundMode(TQWidget::X11ParentRelative);
  2645. w->setBackgroundOrigin(TQWidget::WidgetOrigin);
  2646. w->repaint(true);
  2647. }
  2648. }
  2649. break;
  2650. }
  2651. case TQEvent::MouseMove:
  2652. {
  2653. TQMouseEvent *me = (TQMouseEvent *) e;
  2654. priv->mousePos = me->pos();
  2655. if (obj->inherits(TQSCROLLBAR_OBJECT_NAME_STRING) &&
  2656. (! (me->state() & (LeftButton | MidButton | RightButton)))) {
  2657. priv->hovering = true;
  2658. ((TQWidget *) obj)->repaint(false);
  2659. priv->hovering = false;
  2660. }
  2661. break;
  2662. }
  2663. default:
  2664. {
  2665. break;
  2666. }
  2667. }
  2668. return TDEStyle::eventFilter(obj, e);
  2669. }