1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016
|
/****************************************************************************
** $Id: qwidget_x11.cpp,v 2.235.2.8 1999/09/09 08:56:42 eiriken Exp $
**
** Implementation of QWidget and QWindow classes for X11
**
** Created : 931031
**
** Copyright (C) 1992-1999 Troll Tech AS. All rights reserved.
**
** This file is part of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Troll Tech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** Licensees holding valid Qt Professional Edition licenses may use this
** file in accordance with the Qt Professional Edition License Agreement
** provided with the Qt Professional Edition.
**
** See http://www.troll.no/pricing.html or email sales@troll.no for
** information about the Professional Edition licensing, or see
** http://www.troll.no/qpl/ for QPL licensing information.
**
*****************************************************************************/
#include "qapplication.h"
#include "qpaintdevicemetrics.h"
#include "qpainter.h"
#include "qbitmap.h"
#include "qwidgetlist.h"
#include "qwidgetintdict.h"
#include "qobjectlist.h"
#include "qobjectdict.h"
#include "qaccel.h"
#include "qdragobject.h"
#include "qfocusdata.h"
#include "qabstractlayout.h"
#include "qtextcodec.h"
#include "qt_x11.h"
void qt_enter_modal( QWidget * ); // defined in qapplication_x11.cpp
void qt_leave_modal( QWidget * ); // --- "" ---
bool qt_modal_state(); // --- "" ---
void qt_insert_sip( QWidget*, int, int ); // --- "" ---
int qt_sip_count( QWidget* ); // --- "" ---
bool qt_wstate_iconified( WId ); // --- "" ---
void qt_updated_rootinfo();
#ifndef NO_XIM
extern XIM qt_xim;
extern XIMStyle qt_xim_style;
#endif
// Paint event clipping magic
extern void qt_set_paintevent_clipping( QPaintDevice* dev, const QRegion& region);
extern void qt_clear_paintevent_clipping();
extern bool qt_xdnd_enable( QWidget* w, bool on );
extern bool qt_nograb();
extern void qt_deferred_map_add( QWidget* ); // defined in qapplication_x11.const
extern void qt_deferred_map_take( QWidget* );// defined in qapplication_x11.const
static QWidget *mouseGrb = 0;
static QWidget *keyboardGrb = 0;
/*****************************************************************************
QWidget member functions
*****************************************************************************/
extern Atom qt_wm_delete_window; // defined in qapplication_x11.cpp
extern Atom qt_wm_client_leader; // defined in qapplication_x11.cpp
extern Atom qt_window_role; // defined in qapplication_x11.cpp
extern Atom qt_sm_client_id; // defined in qapplication_x11.cpp
const uint stdWidgetEventMask = // X event mask
(uint)(
KeyPressMask | KeyReleaseMask |
ButtonPressMask | ButtonReleaseMask |
KeymapStateMask |
ButtonMotionMask |
EnterWindowMask | LeaveWindowMask |
FocusChangeMask |
ExposureMask |
PropertyChangeMask |
StructureNotifyMask | SubstructureRedirectMask
);
const uint stdDesktopEventMask = // X event mask
(uint)(
KeyPressMask | KeyReleaseMask |
KeymapStateMask |
EnterWindowMask | LeaveWindowMask |
FocusChangeMask | PropertyChangeMask
);
/*
The qt_ functions below are implemented in qwidgetcreate_x11.cpp.
*/
Window qt_XCreateWindow( const QWidget *creator,
Display *display, Window parent,
int x, int y, uint w, uint h,
int borderwidth, int depth,
uint windowclass, Visual *visual,
ulong valuemask, XSetWindowAttributes *attributes );
Window qt_XCreateSimpleWindow( const QWidget *creator,
Display *display, Window parent,
int x, int y, uint w, uint h, int borderwidth,
ulong border, ulong background );
void qt_XDestroyWindow( const QWidget *destroyer,
Display *display, Window window );
/*!
Creates a new widget window if \a window is null, otherwise sets the
widget's window to \a window.
Initializes the window (sets the geometry etc.) if \a initializeWindow
is TRUE. If \a initializeWindow is FALSE, no initialization is
performed. This parameter makes only sense if \a window is a valid
window.
Destroys the old window if \a destroyOldWindow is TRUE. If \a
destroyOldWindow is FALSE, you are responsible for destroying
the window yourself (using platform native code).
The QWidget constructor calls create(0,TRUE,TRUE) to create a window for
this widget.
*/
void QWidget::create( WId window, bool initializeWindow, bool destroyOldWindow)
{
if ( testWState(WState_Created) && window == 0 )
return;
setWState( WState_Created ); // set created flag
clearWState( WState_USPositionX );
setX11Data( 0 );
if ( !parentWidget() )
setWFlags( WType_TopLevel ); // top-level widget
static int sw = -1, sh = -1; // screen size
Display *dpy = x11Display();
int scr = x11Screen();
bool topLevel = testWFlags(WType_TopLevel);
bool popup = testWFlags(WType_Popup);
bool modal = testWFlags(WType_Modal);
if ( modal )
setWFlags(WStyle_Dialog);
bool desktop = testWFlags(WType_Desktop);
Window root_win = RootWindow(dpy,scr);
Window parentw, destroyw = 0;
WId id;
if ( !window ) // always initialize
initializeWindow = TRUE;
if ( popup ) {
setWFlags(WStyle_Tool); // a popup is a tool window
setWFlags(WStyle_StaysOnTop); // a popup stays on top
}
if ( sw < 0 ) { // get the screen size
sw = DisplayWidth(dpy,scr);
sh = DisplayHeight(dpy,scr);
}
if ( modal || popup || desktop ) { // these are top-level, too
topLevel = TRUE;
setWFlags( WType_TopLevel );
}
if ( desktop ) { // desktop widget
modal = popup = FALSE; // force these flags off
crect.setRect( 0, 0, sw, sh );
} else if ( topLevel ) { // calc pos/size from screen
crect.setRect( sw/4, 3*sh/10, sw/2, 4*sh/10 );
} else { // child widget
crect.setRect( 0, 0, 100, 30 );
}
fpos = crect.topLeft(); // default frame rect
parentw = topLevel ? root_win : parentWidget()->winId();
XSetWindowAttributes wsa;
if ( window ) { // override the old window
if ( destroyOldWindow )
destroyw = winid;
id = window;
setWinId( window );
} else if ( desktop ) { // desktop widget
id = (WId)parentw; // id = root window
QWidget *otherDesktop = find( id ); // is there another desktop?
if ( otherDesktop && otherDesktop->testWFlags(WPaintDesktop) ) {
otherDesktop->setWinId( 0 ); // remove id from widget mapper
setWinId( id ); // make sure otherDesktop is
otherDesktop->setWinId( id ); // found first
} else {
setWinId( id );
}
} else {
if ( x11DefaultVisual() && x11DefaultColormap() ) {
id = (WId)qt_XCreateSimpleWindow( this, dpy, parentw,
crect.left(), crect.top(),
crect.width(), crect.height(),
0,
black.pixel(),
bg_col.pixel() );
} else {
wsa.background_pixel = bg_col.pixel();
wsa.border_pixel = black.pixel();
wsa.colormap = (Colormap)x11Colormap();
id = (WId)qt_XCreateWindow( this, dpy, parentw,
crect.left(), crect.top(),
crect.width(), crect.height(),
0, x11Depth(), InputOutput,
(Visual*)x11Visual(),
CWBackPixel|CWBorderPixel|CWColormap,
&wsa );
}
setWinId( id ); // set widget id/handle + hd
if ( parentw == root_win )
qt_xdnd_enable( this, TRUE );
}
if ( topLevel && !(desktop || popup) ) {
if ( testWFlags(WStyle_Customize) ) { // customize top-level widget
ulong wsa_mask = 0;
if ( testWFlags(WStyle_NormalBorder) ) {
; // ok, we already have it
} else {
if ( !testWFlags(WStyle_DialogBorder) ) {
wsa.override_redirect = TRUE;
wsa_mask |= CWOverrideRedirect;
}
}
if ( testWFlags(WStyle_Tool) ) {
wsa.save_under = TRUE;
wsa_mask |= CWSaveUnder;
}
if ( wsa_mask && initializeWindow )
XChangeWindowAttributes( dpy, id, wsa_mask, &wsa );
} else { // normal top-level widget
setWFlags( WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu |
WStyle_MinMax );
}
}
if ( !initializeWindow ) {
// do no initialization
} else if ( popup ) { // popup widget
XSetTransientForHint( dpy, id, parentw ); //?!?! this looks pointless
wsa.override_redirect = TRUE;
wsa.save_under = TRUE;
XChangeWindowAttributes( dpy, id, CWOverrideRedirect | CWSaveUnder,
&wsa );
} else if ( topLevel && !desktop ) { // top-level widget
QWidget *p = parentWidget(); // real parent
if (p)
p = p->topLevelWidget();
if ( testWFlags(WStyle_DialogBorder)
|| testWFlags(WStyle_StaysOnTop)
|| testWFlags(WStyle_Dialog)
|| testWFlags(WStyle_Tool) ) {
if ( p )
XSetTransientForHint( dpy, id, p->winId() );
else // application-modal
XSetTransientForHint( dpy, id, root_win );
}
// find the real client leader, i.e. a toplevel without parent
while ( p && p->parentWidget()) {
p = p->parentWidget()->topLevelWidget();
}
XSizeHints size_hints;
size_hints.flags = USSize | PSize | PWinGravity;
size_hints.x = crect.left();
size_hints.y = crect.top();
size_hints.width = crect.width();
size_hints.height = crect.height();
size_hints.win_gravity = 1; // NorthWest
char *title = qAppName();
XWMHints wm_hints; // window manager hints
wm_hints.input = True;
wm_hints.initial_state = NormalState;
wm_hints.flags = InputHint | StateHint;
if (p) { // the real client leader (head of the group)
wm_hints.window_group = p->winId();
wm_hints.flags |= WindowGroupHint;
}
XClassHint class_hint;
class_hint.res_name = title; // app name and widget name
class_hint.res_class = name() ? (char *)name() : title;
XSetWMProperties( dpy, id, 0, 0, 0, 0, &size_hints, &wm_hints,
&class_hint );
XResizeWindow( dpy, id, crect.width(), crect.height() );
XStoreName( dpy, id, title );
Atom protocols[1];
protocols[0] = qt_wm_delete_window; // support del window protocol
XSetWMProtocols( dpy, id, protocols, 1 );
}
if ( initializeWindow ) {
// if ( testWFlags(WResizeNoErase) && initializeWindow ) { //}
wsa.bit_gravity = NorthWestGravity; // don't erase when resizing
XChangeWindowAttributes( dpy, id, CWBitGravity, &wsa );
}
setWState( WState_MouseTracking );
setMouseTracking( FALSE ); // also sets event mask
if ( desktop ) {
setWState( WState_Visible );
} else if ( topLevel ) { // set X cursor
QCursor *oc = QApplication::overrideCursor();
if ( initializeWindow )
XDefineCursor( dpy, winid, oc ? oc->handle() : cursor().handle() );
setWState( WState_OwnCursor );
}
if ( window ) { // got window from outside
XWindowAttributes a;
XGetWindowAttributes( dpy, window, &a );
crect.setRect( a.x, a.y, a.width, a.height );
fpos = crect.topLeft();
if ( a.map_state == IsUnmapped )
clearWState( WState_Visible );
else
setWState( WState_Visible );
if ( a.depth != x11AppDepth() ) { // multi-depth system
// #Handling of various X11 factors can be added here
QPaintDeviceX11Data* xd = getX11Data( TRUE );
xd->x_depth = a.depth;
//### also set visual!
setX11Data( xd );
delete xd;
}
}
if ( topLevel ) {
// declare the widget's object name as window role
XChangeProperty( dpy, id,
qt_window_role, XA_STRING, 8, PropModeReplace,
(unsigned char *)name(), qstrlen( name() ) );
// If we are session managed, inform the window manager about it
QCString session = qApp->sessionId().latin1();
if ( !session.isEmpty() ) {
XChangeProperty( dpy, id,
qt_sm_client_id, XA_STRING, 8, PropModeReplace,
(unsigned char *)session.data(), session.length() );
}
}
if ( destroyw )
qt_XDestroyWindow( this, dpy, destroyw );
}
/*!
Frees up window system resources.
Destroys the widget window if \a destroyWindow is TRUE.
destroy() calls itself recursively for all the child widgets,
passing \a destroySubWindows for the \a destroyWindow parameter.
To have more control over destruction of subwidgets,
destroy subwidgets selectively first.
This function is usually called from the QWidget destructor.
*/
void QWidget::destroy( bool destroyWindow, bool destroySubWindows )
{
deactivateWidgetCleanup();
if ( testWState(WState_Created) ) {
clearWState( WState_Created );
if ( children() ) {
QObjectListIt it(*children());
register QObject *obj;
while ( (obj=it.current()) ) { // destroy all widget children
++it;
if ( obj->isWidgetType() )
((QWidget*)obj)->destroy(destroySubWindows,
destroySubWindows);
}
}
if ( mouseGrb == this )
releaseMouse();
if ( keyboardGrb == this )
releaseKeyboard();
if ( testWState( WType_TopLevel ) )
qt_deferred_map_take( this );
if ( testWFlags(WType_Modal) ) // just be sure we leave modal
qt_leave_modal( this );
else if ( testWFlags(WType_Popup) )
qApp->closePopup( this );
if ( testWFlags(WType_Desktop) ) {
if ( acceptDrops() )
qt_xdnd_enable( this, FALSE );
} else {
if ( destroyWindow )
qt_XDestroyWindow( this, x11Display(), winid );
}
setWinId( 0 );
}
}
/*!
Reparents the widget. The widget gets a new \a parent, new widget
flags (\a f, but as usual, use 0) at a new position in its new
parent (\a p).
If \a showIt is TRUE, show() is called once the widget has been
reparented.
If the new parent widget is in a different top-level widget, the
reparented widget and its children are appended to the end of the
\link setFocusPolicy() TAB chain \endlink of the new parent widget,
in the same internal order as before. If one of the moved widgets
had keyboard focus, reparent() calls clearFocus() for that widget.
If the new parent widget is in the same top-level widget as the old
parent, reparent doesn't change the TAB order or keyboard focus.
\warning Reparenting widgets should be a real exception. In normal
applications, you will almost never need it. Dynamic masks can be
achieved much easier and cleaner with classes like QWidgetStack or
on a higher abstraction level, QWizard.
\sa getWFlags()
*/
void QWidget::reparent( QWidget *parent, WFlags f, const QPoint &p,
bool showIt )
{
extern void qPRCreate( const QWidget *, Window );
Display *dpy = x11Display();
QCursor oldcurs;
bool setcurs=testWState(WState_OwnCursor);
if ( setcurs ) {
oldcurs = cursor();
unsetCursor();
}
WId old_winid = winid;
if ( testWFlags(WType_Desktop) )
old_winid = 0;
setWinId( 0 );
reparentFocusWidgets( parent ); // fix focus chains
if ( parentObj ) { // remove from parent
parentObj->removeChild( this );
}
if ( parent ) { // insert into new parent
parentObj = parent; // avoid insertChild warning
parent->insertChild( this );
} else {
qApp->noteTopLevel(this);
}
bool enable = isEnabled(); // remember status
FocusPolicy fp = focusPolicy();
QSize s = size();
QPixmap *bgp = (QPixmap *)backgroundPixmap();
QColor bgc = bg_col; // save colors
QString capt= caption();
widget_flags = f;
clearWState( WState_Created | WState_Visible );
create();
const QObjectList *chlist = children();
if ( chlist ) { // reparent children
QObjectListIt it( *chlist );
QObject *obj;
while ( (obj=it.current()) ) {
if ( obj->isWidgetType() && !((QWidget*)obj)->isTopLevel() ) {
QWidget *w = (QWidget *)obj;
XReparentWindow( x11Display(), w->winId(), winId(),
w->geometry().x(), w->geometry().y() );
}
++it;
}
}
qPRCreate( this, old_winid );
if ( bgp )
XSetWindowBackgroundPixmap( dpy, winid, bgp->handle() );
else
XSetWindowBackground( dpy, winid, bgc.pixel() );
setGeometry( p.x(), p.y(), s.width(), s.height() );
setEnabled( enable );
setFocusPolicy( fp );
if ( !capt.isNull() ) {
extra->topextra->caption = QString::null;
setCaption( capt );
}
if ( showIt )
show();
if ( old_winid )
qt_XDestroyWindow( this, dpy, old_winid );
if ( setcurs ) {
setCursor(oldcurs);
}
QObjectList *accelerators = queryList( "QAccel" );
QObjectListIt it( *accelerators );
QObject *obj;
while ( (obj=it.current()) != 0 ) {
++it;
((QAccel*)obj)->repairEventFilter();
}
delete accelerators;
if ( !parent ) {
QFocusData *fd = focusData( TRUE );
if ( fd->focusWidgets.findRef(this) < 0 )
fd->focusWidgets.append( this );
}
}
/*!
Translates the widget coordinate \e pos to global screen coordinates.
For example, \code mapToGlobal(QPoint(0,0))\endcode would give the
global coordinates of the top-left pixel of the widget.
\sa mapFromGlobal()
*/
QPoint QWidget::mapToGlobal( const QPoint &pos ) const
{
int x, y;
Window child;
XTranslateCoordinates( x11Display(), winId(),
QApplication::desktop()->winId(),
pos.x(), pos.y(), &x, &y, &child );
return QPoint( x, y );
}
/*!
Translates the global screen coordinate \e pos to widget coordinates.
\sa mapToGlobal()
*/
QPoint QWidget::mapFromGlobal( const QPoint &pos ) const
{
int x, y;
Window child;
XTranslateCoordinates( x11Display(), QApplication::desktop()->winId(),
winId(), pos.x(), pos.y(), &x, &y, &child );
return QPoint( x, y );
}
/*!
When a widget gets focus, it should call setMicroFocusHint for some
appropriate position and size - \a x, \a y and \a w by \a h. This
has no \e visual effect, it just provides hints to any
system-specific input handling tools.
The \a text argument should be TRUE if this is a position for text
input.
In the Windows version of Qt, this method sets the system caret, which is
used for user Accessibility focus handling. If \a text is TRUE, it also
sets the IME composition window in Far East Asian language input systems.
In the X11 version of Qt, if \a text is TRUE,
this method sets the XIM "spot" point for
complex language input handling.
*/
void QWidget::setMicroFocusHint(int x, int y, int /*width*/, int height, bool text)
{
#ifndef NO_XIM
if ( text ) {
QWidget* tlw = topLevelWidget();
if ( tlw->extra && tlw->extra->topextra && tlw->extra->topextra->xic ) {
QPoint p = tlw->mapFromGlobal(mapToGlobal(QPoint(x,y)));
XPoint spot;
spot.x = p.x();
spot.y = p.y()+height;
XIC xic = (XIC)tlw->extra->topextra->xic;
XVaNestedList preedit_attr;
preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, 0);
XSetICValues(xic, XNPreeditAttributes, preedit_attr, 0);
XFree(preedit_attr);
}
}
#endif
}
#ifndef NO_XIM
static XFontSet fixed_fontset = 0; // leaked once
static
void cleanup_ffs()
{
if ( fixed_fontset )
XFreeFontSet(QPaintDevice::x11AppDisplay(), fixed_fontset);
fixed_fontset = 0;
}
static
XFontSet xic_fontset(void* qfs, int pt)
{
XFontSet fontset = (XFontSet)qfs;
if ( fontset )
return fontset;
// ##### TODO: this case cannot happen if we ensure that
// the default font etc. are for this locale.
char** missing=0;
int nmissing;
if ( !fixed_fontset ) {
QCString n;
n.sprintf( "-*-Helvetica-*-*-normal-*-*-%d-*-*-*-*-*-*,"
"-*-*-*-*-normal-*-*-%d-*-*-*-*-*-*,"
"-*-*-*-*-*-*-*-%d-*-*-*-*-*-*",
pt*10,
pt*10,
pt*10 );
fixed_fontset = XCreateFontSet( QPaintDevice::x11AppDisplay(), n,
&missing, &nmissing, 0 );
qAddPostRoutine(cleanup_ffs);
}
return fixed_fontset;
}
#endif
void QWidget::setFontSys()
{
#ifndef NO_XIM
QWidget* tlw = topLevelWidget();
if ( tlw->extra && tlw->extra->topextra && tlw->extra->topextra->xic ) {
XIC xic = (XIC)tlw->extra->topextra->xic;
XFontSet fontset = xic_fontset( fontMetrics().fontSet(),
font().pointSize());
XVaNestedList preedit_att = XVaCreateNestedList( 0, XNFontSet, fontset,
NULL );
XVaNestedList status_att = XVaCreateNestedList( 0, XNFontSet, fontset,
NULL );
XSetICValues( xic,
XNPreeditAttributes, preedit_att,
XNStatusAttributes, status_att,
0 );
XFree(preedit_att);
XFree(status_att);
}
#endif
}
void QWidget::setBackgroundColorDirect( const QColor &color )
{
QColor old = bg_col;
bg_col = color;
if ( extra && extra->bg_pix ) { // kill the background pixmap
delete extra->bg_pix;
extra->bg_pix = 0;
}
XSetWindowBackground( x11Display(), winId(), bg_col.pixel() );
backgroundColorChange( old );
}
static int allow_null_pixmaps = 0;
void QWidget::setBackgroundPixmapDirect( const QPixmap &pixmap )
{
QPixmap old;
if ( extra && extra->bg_pix )
old = *extra->bg_pix;
if ( !allow_null_pixmaps && pixmap.isNull() ) {
XSetWindowBackground( x11Display(), winId(), bg_col.pixel() );
if ( extra && extra->bg_pix ) {
delete extra->bg_pix;
extra->bg_pix = 0;
}
} else {
QPixmap pm = pixmap;
if (!pm.isNull()) {
if ( pm.depth() == 1 && QPixmap::defaultDepth() > 1 ) {
pm = QPixmap( pixmap.size() );
bitBlt( &pm, 0, 0, &pixmap, 0, 0, pm.width(), pm.height() );
}
}
if ( extra && extra->bg_pix )
delete extra->bg_pix;
else
createExtra();
extra->bg_pix = new QPixmap( pm );
XSetWindowBackgroundPixmap( x11Display(), winId(), pm.handle() );
if ( testWFlags(WType_Desktop) ) // save rootinfo later
qt_updated_rootinfo();
}
if ( !allow_null_pixmaps ) {
backgroundPixmapChange( old );
}
}
/*!
Sets the window-system background of the widget to nothing.
Note that `nothing' is actually a pixmap that isNull(), thus you
can check for an empty background by checking backgroundPixmap().
\sa setBackgroundPixmap(), setBackgroundColor()
This class should \e NOT be made virtual - it is an alternate usage
of setBackgroundPixmap().
*/
void QWidget::setBackgroundEmpty()
{
allow_null_pixmaps++;
setBackgroundPixmap(QPixmap());
allow_null_pixmaps--;
}
/*!
Sets the widget cursor shape to \e cursor.
The mouse cursor will assume this shape when it's over this widget.
See a list of predefined cursor objects with a range of useful
shapes in the QCursor documentation.
An editor widget would for example use an I-beam cursor:
\code
setCursor( ibeamCursor );
\endcode
\sa cursor(), unsetCursor(), QApplication::setOverrideCursor()
*/
void QWidget::setCursor( const QCursor &cursor )
{
if ( cursor.handle() != arrowCursor.handle()
|| (extra && extra->curs) ) {
createExtra();
delete extra->curs;
extra->curs = new QCursor(cursor);
}
setWState( WState_OwnCursor );
QCursor *oc = QApplication::overrideCursor();
XDefineCursor( x11Display(), winId(),
oc ? oc->handle() : cursor.handle() );
XFlush( x11Display() );
}
/*!
Unset the cursor for this widget. The widget will use the cursor of
its parent from now on.
This functions does nothing for toplevel windows.
\sa cursor(), setCursor(), QApplication::setOverrideCursor()
*/
void QWidget::unsetCursor()
{
if ( !isTopLevel() ) {
if (extra ) {
delete extra->curs;
extra->curs = 0;
}
clearWState( WState_OwnCursor );
XDefineCursor( x11Display(), winId(), None );
XFlush( x11Display() );
}
}
static XTextProperty*
qstring_to_xtp( const QString& s )
{
static XTextProperty tp;
static const QTextCodec* mapper = QTextCodec::codecForLocale();
if ( mapper ) {
QCString mapped = mapper->fromUnicode(s);
char* tl[2];
tl[0] = mapped.data();
tl[1] = 0;
XmbTextListToTextProperty( QPaintDevice::x11AppDisplay(),
tl, 1, XStdICCTextStyle, &tp );
} else {
static QCString qcs = s.ascii();
tp.value = (uchar*)qcs.data();
tp.encoding = XA_STRING;
tp.format = 8;
tp.nitems = qcs.length();
}
// ### If we knew WM could understand unicode, we could use
// ### a much simpler, cheaper encoding...
/*
tp.value = (XChar2b*)s.unicode();
tp.encoding = XA_UNICODE; // wish
tp.format = 16;
tp.nitems = s.length();
*/
return &tp;
}
/*!
Sets the window caption (title).
\sa caption(), setIcon(), setIconText()
*/
void QWidget::setCaption( const QString &caption )
{
if ( extra && extra->topextra && extra->topextra->caption == caption )
return; // for less flicker
createTLExtra();
extra->topextra->caption = caption;
XSetWMName( x11Display(), winId(), qstring_to_xtp(caption) );
}
/*!
Sets the window icon pixmap.
\sa icon(), setIconText(), setCaption()
*/
void QWidget::setIcon( const QPixmap &pixmap )
{
if ( extra && extra->topextra ) {
delete extra->topextra->icon;
extra->topextra->icon = 0;
} else {
createTLExtra();
}
::Pixmap icon_pixmap;
::Pixmap mask_pixmap;
QBitmap mask;
if ( pixmap.isNull() ) {
icon_pixmap = 0;
mask_pixmap = 0;
} else {
extra->topextra->icon = new QPixmap( pixmap );
icon_pixmap = pixmap.handle();
mask = pixmap.mask() ? *pixmap.mask() : pixmap.createHeuristicMask();
mask_pixmap = mask.handle();
}
XWMHints *h = XGetWMHints( x11Display(), winId() );
XWMHints wm_hints;
bool got_hints = h != 0;
if ( !got_hints ) {
h = &wm_hints;
h->flags = 0;
}
h->icon_pixmap = icon_pixmap;
h->icon_mask = mask_pixmap;
h->flags |= IconPixmapHint | IconMaskHint;
XSetWMHints( x11Display(), winId(), h );
if ( got_hints )
XFree( (char *)h );
}
/*!
Sets the text of the window's icon to \e iconText.
\sa iconText(), setIcon(), setCaption()
*/
void QWidget::setIconText( const QString &iconText )
{
createTLExtra();
extra->topextra->iconText = iconText;
XSetIconName( x11Display(), winId(), iconText.utf8() );
XSetWMIconName( x11Display(), winId(), qstring_to_xtp(iconText) );
}
void QWidget::setMouseTracking( bool enable )
{
bool gmt = QApplication::hasGlobalMouseTracking();
if ( enable == testWState(WState_MouseTracking) && !gmt )
return;
uint m = (enable || gmt) ? (uint)PointerMotionMask : 0;
if ( enable )
setWState( WState_MouseTracking );
else
clearWState( WState_MouseTracking );
if ( testWFlags(WType_Desktop) ) { // desktop widget?
QWidget* main_desktop = find( winId() );
if ( main_desktop->testWFlags(WPaintDesktop) ) // get desktop paint events
XSelectInput( x11Display(), winId(),
stdDesktopEventMask|ExposureMask );
else
XSelectInput( x11Display(), winId(), stdDesktopEventMask );
} else {
XSelectInput( x11Display(), winId(), // specify events
m | stdWidgetEventMask );
}
}
/*!
Grabs the mouse input.
This widget will be the only one to receive mouse events until
releaseMouse() is called.
\warning Grabbing the mouse might lock the terminal.
It is almost never necessary to grab the mouse when using Qt since
Qt grabs and releases it sensibly. In particular, Qt grabs the
mouse when a button is pressed and keeps it until the last button is
released.
\sa releaseMouse(), grabKeyboard(), releaseKeyboard()
*/
void QWidget::grabMouse()
{
if ( !qt_nograb() ) {
if ( mouseGrb )
mouseGrb->releaseMouse();
XGrabPointer( x11Display(), winId(), TRUE,
(uint)(ButtonPressMask | ButtonReleaseMask |
PointerMotionMask | EnterWindowMask | LeaveWindowMask),
GrabModeAsync, GrabModeAsync,
None, None, CurrentTime );
mouseGrb = this;
}
}
/*!
Grabs the mouse input and changes the cursor shape.
The cursor will assume shape \e cursor (for as long as the mouse focus is
grabbed) and this widget will be the only one to receive mouse events
until releaseMouse() is called().
\warning Grabbing the mouse might lock the terminal.
\sa releaseMouse(), grabKeyboard(), releaseKeyboard(), setCursor()
*/
void QWidget::grabMouse( const QCursor &cursor )
{
if ( !qt_nograb() ) {
if ( mouseGrb )
mouseGrb->releaseMouse();
XGrabPointer( x11Display(), winId(), TRUE,
(uint)(ButtonPressMask | ButtonReleaseMask |
PointerMotionMask | EnterWindowMask | LeaveWindowMask),
GrabModeAsync, GrabModeAsync,
None, cursor.handle(), CurrentTime );
mouseGrb = this;
}
}
/*!
Releases the mouse grab.
\sa grabMouse(), grabKeyboard(), releaseKeyboard()
*/
void QWidget::releaseMouse()
{
if ( !qt_nograb() && mouseGrb == this ) {
XUngrabPointer( x11Display(), CurrentTime );
XFlush( x11Display() );
mouseGrb = 0;
}
}
/*!
Grabs all keyboard input.
This widget will receive all keyboard events, independent of the active
window.
\warning Grabbing the keyboard might lock the terminal.
\sa releaseKeyboard(), grabMouse(), releaseMouse()
*/
void QWidget::grabKeyboard()
{
if ( !qt_nograb() ) {
if ( keyboardGrb )
keyboardGrb->releaseKeyboard();
XGrabKeyboard( x11Display(), winid, TRUE, GrabModeAsync, GrabModeAsync,
CurrentTime );
keyboardGrb = this;
}
}
/*!
Releases the keyboard grab.
\sa grabKeyboard(), grabMouse(), releaseMouse()
*/
void QWidget::releaseKeyboard()
{
if ( !qt_nograb() && keyboardGrb == this ) {
XUngrabKeyboard( x11Display(), CurrentTime );
keyboardGrb = 0;
}
}
/*!
Returns a pointer to the widget that is currently grabbing the
mouse input.
If no widget in this application is currently grabbing the mouse, 0 is
returned.
\sa grabMouse(), keyboardGrabber()
*/
QWidget *QWidget::mouseGrabber()
{
return mouseGrb;
}
/*!
Returns a pointer to the widget that is currently grabbing the
keyboard input.
If no widget in this application is currently grabbing the keyboard, 0
is returned.
\sa grabMouse(), mouseGrabber()
*/
QWidget *QWidget::keyboardGrabber()
{
return keyboardGrb;
}
/*!
Sets the top-level widget containing this widget to be the active
window.
An active window is a visible top-level window that has the keyboard input
focus.
This function performs the same operation as clicking the mouse on
the title bar of a top-level window, at least on Windows. On X11,
the result depends on the Window Manager. If you want to ensure that
the window is stacked on top as well, call raise() in addition. Note
that the window has be to visible, otherwise setActiveWindow() has
no effect.
\sa isActiveWindow(), topLevelWidget(), show()
*/
void QWidget::setActiveWindow()
{
QWidget *tlw = topLevelWidget();
if ( tlw->isVisible() )
XSetInputFocus( x11Display(), tlw->winId(), RevertToNone, CurrentTime);
}
/*!
Updates the widget unless updates are disabled or the widget is hidden.
Updating the widget will erase the widget contents and generate a paint
event from the window system. The paint event is processed after the
program has returned to the main event loop.
\sa repaint(), paintEvent(), setUpdatesEnabled(), erase()
*/
void QWidget::update()
{
if ( (widget_state & (WState_Visible|WState_BlockUpdates)) == WState_Visible )
XClearArea( x11Display(), winId(), 0, 0, 0, 0, TRUE );
}
/*!
Updates a rectangle (\e x, \e y, \e w, \e h) inside the widget
unless updates are disabled or the widget is hidden.
Updating the widget erases the widget area \e (x,y,w,h), which in turn
generates a paint event from the window system. The paint event is
processed after the program has returned to the main event loop.
If \e w is negative, it is replaced with <code>width() - x</code>.
If \e h is negative, it is replaced width <code>height() - y</code>.
\sa repaint(), paintEvent(), setUpdatesEnabled(), erase()
*/
void QWidget::update( int x, int y, int w, int h )
{
if ( w && h &&
(widget_state & (WState_Visible|WState_BlockUpdates)) == WState_Visible ) {
if ( w < 0 )
w = crect.width() - x;
if ( h < 0 )
h = crect.height() - y;
if ( w != 0 && h != 0 )
XClearArea( x11Display(), winId(), x, y, w, h, TRUE );
}
}
/*!
\overload void QWidget::update( const QRect &r )
*/
/*!
\overload void QWidget::repaint( bool erase )
This version repaints the entire widget.
*/
/*!
\overload void QWidget::repaint()
This version erases and repaints the entire widget.
*/
/*!
Repaints the widget directly by calling paintEvent() directly,
unless updates are disabled or the widget is hidden.
Erases the widget area \e (x,y,w,h) if \e erase is TRUE.
If \e w is negative, it is replaced with <code>width() - x</code>.
If \e h is negative, it is replaced width <code>height() - y</code>.
Doing a repaint() is usually faster than doing an update(), but
calling update() many times in a row will generate a single paint
event.
\warning If you call repaint() in a function which may itself be called
from paintEvent(), you may see infinite recursion. The update() function
never generates recursion.
\sa update(), paintEvent(), setUpdatesEnabled(), erase()
*/
void QWidget::repaint( int x, int y, int w, int h, bool erase )
{
if ( (widget_state & (WState_Visible|WState_BlockUpdates)) == WState_Visible ) {
if ( w < 0 )
w = crect.width() - x;
if ( h < 0 )
h = crect.height() - y;
QRect r(x,y,w,h);
if ( r.isEmpty() )
return; // nothing to do
QPaintEvent e( r, erase );
qt_set_paintevent_clipping( this, r );
if ( erase && w != 0 && h != 0 )
XClearArea( x11Display(), winId(), x, y, w, h, FALSE );
QApplication::sendEvent( this, &e );
qt_clear_paintevent_clipping();
}
}
/*!
Repaints the widget directly by calling paintEvent() directly,
unless updates are disabled or the widget is hidden.
Erases the widget region \a reg if \a erase is TRUE.
Calling repaint() is usually faster than doing an update(), but
calling update() many times in a row will generate a single paint
event.
\warning If you call repaint() in a function which may itself be called
from paintEvent(), you may see infinite recursion. The update() function
never generates recursion.
\sa update(), paintEvent(), setUpdatesEnabled(), erase()
*/
void QWidget::repaint( const QRegion& reg, bool erase )
{
if ( (widget_state & (WState_Visible|WState_BlockUpdates)) == WState_Visible ) {
QPaintEvent e( reg );
qt_set_paintevent_clipping( this, reg );
if ( erase )
this->erase(reg);
QApplication::sendEvent( this, &e );
qt_clear_paintevent_clipping();
}
}
/*!
\overload void QWidget::repaint( const QRect &r, bool erase )
*/
/*!
\internal
Platform-specific part of QWidget::show().
*/
void QWidget::showWindow()
{
setWState( WState_Visible );
clearWState( WState_ForceHide );
clearWState( WState_Withdrawn );
QShowEvent e(FALSE);
QApplication::sendEvent( this, &e );
if ( testWFlags(WType_TopLevel) &&
extra &&
extra->topextra &&
extra->topextra->wmstate == 2)
qt_deferred_map_add( this );
else
XMapWindow( x11Display(), winId() );
}
/*!
\internal
Platform-specific part of QWidget::hide().
*/
void QWidget::hideWindow()
{
deactivateWidgetCleanup();
if ( testWFlags(WType_TopLevel) ) {
qt_deferred_map_take( this );
XWithdrawWindow( x11Display(), winId(), x11Screen() );
if ( extra && extra->topextra && extra->topextra->wmstate ) // wm_state supported
extra->topextra->wmstate = 2; // waiting for wm_state change before next showWindow
}
else
XUnmapWindow( x11Display(), winId() );
if ( isPopup() )
XFlush( x11Display() );
}
/*!
Shows the widget minimized, as an icon.
Calling this function has no effect for other than \link isTopLevel()
top-level widgets\endlink.
\sa showNormal(), showMaximized(), show(), hide(), isVisible(), isMinimized()
*/
void QWidget::showMinimized()
{
if ( testWFlags(WType_TopLevel) )
XIconifyWindow( x11Display(), winId(), x11Screen() );
//### if the window is mapped (i.e. not WState_Withdrawn) we have
// to show it with initial state Iconic! Right now the function only
// works for widgets that are already visible.
}
/*!
Returns TRUE if this widget is a top-level widget that is minimized
(iconified), or else FALSE.
\sa showMinimized(), isVisible(), show(), hide(), showNormal()
*/
bool QWidget::isMinimized() const
{
return qt_wstate_iconified( winId() );
}
/*!
Shows the widget maximized.
Calling this function has no effect for other than \link isTopLevel()
top-level widgets\endlink.
\sa showNormal(), showMinimized(), show(), hide(), isVisible()
*/
void QWidget::showMaximized()
{
if ( testWFlags(WType_TopLevel) ) {
Display *dpy = x11Display();
int scr = x11Screen();
int sw = DisplayWidth(dpy,scr);
int sh = DisplayHeight(dpy,scr);
createTLExtra();
if ( extra->topextra->normalGeometry.width() < 0 )
extra->topextra->normalGeometry = geometry();
if ( !extra->topextra->parentWinId ) {
setGeometry(0, 0, sw, sh );
show();
XEvent ev;
while (!XCheckTypedWindowEvent( qt_xdisplay(), winId(), ReparentNotify, &ev ))
;
qApp->x11ProcessEvent( &ev );
}
sw -= frameGeometry().width() - width();
sh -= frameGeometry().height() - height();
setGeometry( 0, 0, sw, sh );
show();
}
}
/*!
Restores the widget after it has been maximized or minimized.
Calling this function has no effect for other than \link isTopLevel()
top-level widgets\endlink.
\sa showMinimized(), showMaximized(), show(), hide(), isVisible()
*/
void QWidget::showNormal()
{
if ( testWFlags(WType_TopLevel) ) {
if ( extra && extra->topextra ) {
QRect r = extra->topextra->normalGeometry;
if ( r.width() >= 0 ) {
// the widget has been maximized
extra->topextra->normalGeometry = QRect(0,0,-1,-1);
setGeometry( r );
}
}
show();
}
}
/*!
Raises this widget to the top of the parent widget's stack.
If there are any siblings of this widget that overlap it on the screen,
this widget will be visually in front of its siblings afterwards.
\sa lower()
*/
void QWidget::raise()
{
QWidget *p = parentWidget();
if ( p && p->childObjects && p->childObjects->findRef(this) >= 0 )
p->childObjects->append( p->childObjects->take() );
XRaiseWindow( x11Display(), winId() );
}
/*!
Lowers the widget to the bottom of the parent widget's stack.
If there are siblings of this widget that overlap it on the screen, this
widget will be obscured by its siblings afterwards.
\sa raise()
*/
void QWidget::lower()
{
QWidget *p = parentWidget();
if ( p && p->childObjects && p->childObjects->findRef(this) >= 0 )
p->childObjects->insert( 0, p->childObjects->take() );
XLowerWindow( x11Display(), winId() );
}
/*
The global variable qwidget_tlw_gravity defines the window gravity of
the next top level window to be created. We do this when setting the
main widget's geometry and the "-geometry" command line option contains
a negative position.
*/
int qwidget_tlw_gravity = 1;
static void do_size_hints( Display *dpy, WId winid, QWExtra *x, XSizeHints *s )
{
if ( x ) {
if ( x->minw > 0 || x->minh > 0 ) { // add minimum size hints
s->flags |= PMinSize;
s->min_width = x->minw;
s->min_height = x->minh;
}
if ( x->maxw < QWIDGETSIZE_MAX || x->maxh < QWIDGETSIZE_MAX ) {
s->flags |= PMaxSize; // add maximum size hints
s->max_width = x->maxw;
s->max_height = x->maxh;
}
if ( x->topextra &&
(x->topextra->incw > 0 || x->topextra->inch > 0) )
{ // add resize increment hints
s->flags |= PResizeInc | PBaseSize;
s->width_inc = x->topextra->incw;
s->height_inc = x->topextra->inch;
s->base_width = x->topextra->basew;
s->base_height = x->topextra->baseh;
}
}
s->flags |= PWinGravity;
s->win_gravity = qwidget_tlw_gravity; // usually NorthWest (1)
qwidget_tlw_gravity = 1; // reset in case it was set
XSetWMNormalHints( dpy, winid, s );
}
void QWidget::internalSetGeometry( int x, int y, int w, int h, bool isMove )
{
Display *dpy = x11Display();
if ( testWFlags(WType_Desktop) )
return;
if ( extra ) { // any size restrictions?
w = QMIN(w,extra->maxw);
h = QMIN(h,extra->maxh);
w = QMAX(w,extra->minw);
h = QMAX(h,extra->minh);
}
if ( w < 1 ) // invalid size
w = 1;
if ( h < 1 )
h = 1;
QPoint oldp = pos();
QSize olds = size();
QRect r( x, y, w, h );
// We only care about stuff that changes the geometry, or may
// cause the window manager to change its state
if ( r.size() == olds && oldp == r.topLeft() &&
(isTopLevel() == FALSE
|| !isMove || testWState(WState_USPositionX)) )
return;
setCRect( r );
if ( isTopLevel() ) {
setWState( WState_ConfigPending );
XSizeHints size_hints;
size_hints.flags = USSize | PSize;
if ( isMove )
setWState(WState_USPositionX);
if ( testWState(WState_USPositionX) )
// also restore the usposition, otherwise it would be cleared
size_hints.flags |= USPosition;
size_hints.x = x;
size_hints.y = y;
size_hints.width = w;
size_hints.height = h;
do_size_hints( dpy, winId(), extra, &size_hints );
}
if ( isMove )
XMoveResizeWindow( dpy, winid, x, y, w, h );
else
XResizeWindow( dpy, winid, w, h );
bool isResize = olds != r.size();
if ( isVisible() ) {
if ( isMove ) {
QMoveEvent e( r.topLeft(), oldp );
QApplication::sendEvent( this, &e );
}
if ( isResize ) {
QResizeEvent e( r.size(), olds );
QApplication::sendEvent( this, &e );
if ( !testWFlags( WNorthWestGravity ) )
repaint( visibleRect(), !testWFlags(WResizeNoErase) );
}
} else {
if ( isMove )
QApplication::postEvent( this,
new QMoveEvent( r.topLeft(), oldp ) );
if ( isResize )
QApplication::postEvent( this,
new QResizeEvent( r.size(), olds ) );
}
}
/*!
\overload void QWidget::setMinimumSize( const QSize &size )
*/
/*!
Sets the minimum size of the widget to \e w by \e h pixels.
The widget cannot be resized to a smaller size than the minimum widget
size. The widget's size is forced to the minimum size if the current
size is smaller.
\sa minimumSize(), setMaximumSize(), setSizeIncrement(), resize(), size()
*/
void QWidget::setMinimumSize( int minw, int minh )
{
#if defined(CHECK_RANGE)
if ( minw < 0 || minh < 0 )
qWarning("QWidget::setMinimumSize: The smallest allowed size is (0,0)");
#endif
createExtra();
if ( extra->minw == minw && extra->minh == minh )
return;
extra->minw = minw;
extra->minh = minh;
if ( minw > width() || minh > height() )
resize( QMAX(minw,width()), QMAX(minh,height()) );
if ( testWFlags(WType_TopLevel) ) {
XSizeHints size_hints;
size_hints.flags = 0;
do_size_hints( x11Display(), winId(), extra, &size_hints );
}
updateGeometry();
}
/*!
\overload void QWidget::setMaximumSize( const QSize &size )
*/
/*!
Sets the maximum size of the widget to \e w by \e h pixels.
The widget cannot be resized to a larger size than the maximum widget
size. The widget's size is forced to the maximum size if the current
size is greater.
\sa maximumSize(), setMinimumSize(), setSizeIncrement(), resize(), size()
*/
void QWidget::setMaximumSize( int maxw, int maxh )
{
#if defined(CHECK_RANGE)
if ( maxw > QWIDGETSIZE_MAX || maxh > QWIDGETSIZE_MAX ) {
qWarning("QWidget::setMaximumSize: (%s/%s) "
"The largest allowed size is (%d,%d)",
name( "unnamed" ), className(), QWIDGETSIZE_MAX,
QWIDGETSIZE_MAX );
maxw = QMIN( maxw, QWIDGETSIZE_MAX );
maxh = QMIN( maxh, QWIDGETSIZE_MAX );
}
if ( maxw < 0 || maxh < 0 ) {
qWarning("QWidget::setMaximumSize: (%s/%s) Negative sizes (%d,%d) "
"are not possible",
name( "unnamed" ), className(), maxw, maxh );
maxw = QMAX( maxw, 0 );
maxh = QMAX( maxh, 0 );
}
#endif
createExtra();
if ( extra->maxw == maxw && extra->maxh == maxh )
return;
extra->maxw = maxw;
extra->maxh = maxh;
if ( maxw < width() || maxh < height() )
resize( QMIN(maxw,width()), QMIN(maxh,height()) );
if ( testWFlags(WType_TopLevel) ) {
XSizeHints size_hints;
size_hints.flags = 0;
do_size_hints( x11Display(), winId(), extra, &size_hints );
}
updateGeometry();
}
/*!
Sets the size increment of the widget. When the user resizes the
window, the size will move in steps of \e w pixels horizontally and
\e h pixels vertically, with baseSize() as basis. Preferred widget sizes are therefore for
non-negative integers \e i and \e j:
\code
width = baseSize().width() + i * sizeIncrement().width();
height = baseSize().height() + j * sizeIncrement().height();
\endcode
Note that while you can set the size increment for all widgets, it
has no effect except for top-level widgets.
\warning The size increment has no effect under Windows, and may be
disregarded by the window manager on X.
\sa sizeIncrement(), setMinimumSize(), setMaximumSize(), resize(), size()
*/
void QWidget::setSizeIncrement( int w, int h )
{
createTLExtra();
QTLWExtra* x = extra->topextra;
if ( x->incw == w && x->inch == h )
return;
x->incw = w;
x->inch = h;
if ( testWFlags(WType_TopLevel) ) {
XSizeHints size_hints;
size_hints.flags = 0;
do_size_hints( x11Display(), winId(), extra, &size_hints );
}
}
/*!
\overload void QWidget::setSizeIncrement( const QSize& )
*/
/*!
Sets the base size of the widget. The base size is important only
in combination with size increments. See setSizeIncrement() for details.
\sa baseSize()
*/
void QWidget::setBaseSize( int basew, int baseh )
{
createTLExtra();
QTLWExtra* x = extra->topextra;
if ( x->basew == basew && x->baseh == baseh )
return;
x->basew = basew;
x->baseh = baseh;
if ( testWFlags(WType_TopLevel) ) {
XSizeHints size_hints;
size_hints.flags = 0;
do_size_hints( x11Display(), winId(), extra, &size_hints );
}
}
/*!
\overload void QWidget::setBaseSize( const QSize& )
*/
/*!
\overload void QWidget::erase()
This version erases the entire widget.
*/
/*!
\overload void QWidget::erase( const QRect &r )
*/
/*!
Erases the specified area \e (x,y,w,h) in the widget without generating
a \link paintEvent() paint event\endlink.
If \e w is negative, it is replaced with <code>width() - x</code>.
If \e h is negative, it is replaced width <code>height() - y</code>.
Child widgets are not affected.
\sa repaint()
*/
void QWidget::erase( int x, int y, int w, int h )
{
if ( w < 0 )
w = crect.width() - x;
if ( h < 0 )
h = crect.height() - y;
if ( w != 0 && h != 0 )
XClearArea( x11Display(), winId(), x, y, w, h, FALSE );
}
/*!
Erases the area defined by \a reg, without generating a
\link paintEvent() paint event\endlink.
Child widgets are not affected.
*/
void QWidget::erase( const QRegion& reg )
{
QArray<QRect> r = reg.rects();
for (uint i=0; i<r.size(); i++) {
const QRect& rr = r[(int)i];
XClearArea( x11Display(), winId(),
rr.x(), rr.y(), rr.width(), rr.height(), FALSE );
}
}
/*!
Scrolls the contents of the widget \e dx pixels rightwards and \e dy
pixels downwards. If \e dx/dy is negative, the scroll direction is
leftwards/upwards. Child widgets are moved accordingly.
\warning You might find that QScrollView offers a higher-level of
functionality than using this function.
The areas of the widget that are exposed will be erased and
\link paintEvent() paint events\endlink may be generated immediately,
or after some further event processing.
\warning If you call scroll() in a function which may itself be
called from the moveEvent() or paintEvent() of a direct child of the
widget being scrolled, you may see infinite recursion.
\sa erase(), bitBlt()
*/
void QWidget::scroll( int dx, int dy )
{
scroll( dx, dy, QRect() );
}
/*!
Scrolls the area \a r of this widget \a dx pixels rightwards and \a dy
pixels downwards. If \e dx/dy is negative, the scroll direction is
leftwards/upwards. Child widgets are not moved.
\warning You might find that QScrollView offers a higher-level of
functionality than using this function.
The areas of the widget that are exposed will be erased and
\link paintEvent() paint events\endlink may be generated immediately,
or after some further event processing.
\warning If you call scroll() in a function which may itself be
called from the moveEvent() or paintEvent() of a direct child of the
widget being scrolled, you may see infinite recursion.
\sa erase(), bitBlt()
*/
void QWidget::scroll( int dx, int dy, const QRect& r )
{
if ( testWState( WState_BlockUpdates ) )
return;
bool valid_rect = r.isValid();
QRect sr = valid_rect?r:rect();
int x1, y1, x2, y2, w=sr.width(), h=sr.height();
if ( dx > 0 ) {
x1 = sr.x();
x2 = x1+dx;
w -= dx;
} else {
x2 = sr.x();
x1 = x2-dx;
w += dx;
}
if ( dy > 0 ) {
y1 = sr.y();
y2 = y1+dy;
h -= dy;
} else {
y2 = sr.y();
y1 = y2-dy;
h += dy;
}
if ( dx == 0 && dy == 0 )
return;
Display *dpy = x11Display();
GC gc = qt_xget_readonly_gc();
// Want expose events
XSetGraphicsExposures( dpy, gc, TRUE );
XCopyArea( dpy, winId(), winId(), gc, x1, y1, w, h, x2, y2);
XSetGraphicsExposures( dpy, gc, FALSE );
if ( !valid_rect && children() ) { // scroll children
QPoint pd( dx, dy );
QObjectListIt it(*children());
register QObject *object;
while ( it ) { // move all children
object = it.current();
if ( object->isWidgetType() ) {
QWidget *w = (QWidget *)object;
w->move( w->pos() + pd );
}
++it;
}
}
// Don't let the server be bogged-down with repaint events
bool repaint_immediately = qt_sip_count( this ) < 3;
if ( dx ) {
int x = x2 == sr.x() ? sr.x()+w : sr.x();
if ( repaint_immediately )
repaint( x, sr.y(), QABS(dx), sr.height(), TRUE );
else
XClearArea( dpy, winid, x, sr.y(), QABS(dx), sr.height(), TRUE );
}
if ( dy ) {
int y = y2 == sr.y() ? sr.y()+h : sr.y();
if ( repaint_immediately )
repaint( sr.x(), y, sr.width(), QABS(dy), TRUE );
else
XClearArea( dpy, winid, sr.x(), y, sr.width(), QABS(dy), TRUE );
}
qt_insert_sip( this, dx, dy ); // #### ignores r
}
/*!
\overload void QWidget::drawText( const QPoint &pos, const QString& str )
*/
/*!
Writes \e str at position \e x,y.
The \e y position is the base line position of the text. The text is
drawn using the default font and the default foreground color.
This function is provided for convenience. You will generally get
more flexible results and often higher speed by using a a \link
QPainter painter\endlink instead.
\sa setFont(), foregroundColor(), QPainter::drawText()
*/
void QWidget::drawText( int x, int y, const QString &str )
{
if ( testWState(WState_Visible) ) {
QPainter paint;
paint.begin( this );
paint.drawText( x, y, str );
paint.end();
}
}
/*!
Internal implementation of the virtual QPaintDevice::metric() function.
Use the QPaintDeviceMetrics class instead.
*/
int QWidget::metric( int m ) const
{
int val;
if ( m == QPaintDeviceMetrics::PdmWidth ) {
val = crect.width();
} else if ( m == QPaintDeviceMetrics::PdmHeight ) {
val = crect.height();
} else {
Display *dpy = x11Display();
int scr = x11Screen();
switch ( m ) {
case QPaintDeviceMetrics::PdmDpiX:
val = QPaintDevice::x11AppDpiX();
break;
case QPaintDeviceMetrics::PdmDpiY:
val = QPaintDevice::x11AppDpiY();
break;
case QPaintDeviceMetrics::PdmWidthMM:
val = (DisplayWidthMM(dpy,scr)*crect.width())/
DisplayWidth(dpy,scr);
break;
case QPaintDeviceMetrics::PdmHeightMM:
val = (DisplayHeightMM(dpy,scr)*crect.height())/
DisplayHeight(dpy,scr);
break;
case QPaintDeviceMetrics::PdmNumColors:
val = DisplayCells(dpy,scr);
break;
case QPaintDeviceMetrics::PdmDepth:
val = DisplayPlanes(dpy,scr);
break;
default:
val = 0;
#if defined(CHECK_RANGE)
qWarning( "QWidget::metric: Invalid metric command" );
#endif
}
}
return val;
}
void QWidget::createSysExtra()
{
extra->xDndProxy = 0;
}
void QWidget::deleteSysExtra()
{
}
void QWidget::createTLSysExtra()
{
#ifndef NO_XIM
if ( qt_xim ) {
XPoint spot; spot.x = 1; spot.y = 1; // dummmy
XFontSet fontset = xic_fontset(fontMetrics().fontSet(), font().pointSize());
XVaNestedList preedit_att = XVaCreateNestedList(0,
XNSpotLocation, &spot,
XNFontSet, fontset,
NULL);
XVaNestedList status_att = XVaCreateNestedList(0,
XNFontSet, fontset,
NULL);
extra->topextra->xic = (void*)XCreateIC( qt_xim,
XNInputStyle, qt_xim_style,
XNClientWindow, winId(),
XNFocusWindow, winId(),
XNPreeditAttributes, preedit_att,
XNStatusAttributes, status_att,
0 );
XFree(preedit_att);
XFree(status_att);
} else {
extra->topextra->xic = 0;
}
#endif
}
void QWidget::deleteTLSysExtra()
{
#ifndef NO_XIM
if (extra->topextra->xic) {
XUnsetICFocus( (XIC) extra->topextra->xic );
XDestroyIC( (XIC) extra->topextra->xic );
extra->topextra->xic = 0;
}
#endif
}
/*!
Returns TRUE if drop events are enabled for this widget.
\sa setAcceptDrops()
*/
bool QWidget::acceptDrops() const
{
return testWState(WState_DND);
}
/*!
Announces to the system that this widget \e may be able to
accept drop events.
If the widgets is \link QWidget::isDesktop() the desktop\endlink,
this may fail if another application is using the desktop - you
can call acceptDrops() to test if this occurs.
\sa acceptDrops()
*/
void QWidget::setAcceptDrops( bool on )
{
if ( testWState(WState_DND) != on ) {
if ( qt_xdnd_enable( this, on ) ) {
if ( on )
setWState(WState_DND);
else
clearWState(WState_DND);
}
}
}
/*!
Causes only the parts of the widget which overlap \a region
to be visible. If the region includes pixels outside the
rect() of the widget, window system controls in that area
may or may not be visible, depending on the platform.
Note that this effect can be slow if the region is particularly
complex.
\sa setMask(QBitmap), clearMask()
*/
void QWidget::setMask( const QRegion& region )
{
XShapeCombineRegion( x11Display(), winId(), ShapeBounding, 0, 0,
region.handle(), ShapeSet );
}
/*!
Causes only the pixels of the widget for which \a bitmap
has a corresponding 1 bit
to be visible. If the region includes pixels outside the
rect() of the widget, window system controls in that area
may or may not be visible, depending on the platform.
Note that this effect can be slow if the region is particularly
complex.
\sa setMask(const QRegion&), clearMask()
*/
void QWidget::setMask( const QBitmap &bitmap )
{
XShapeCombineMask( x11Display(), winId(), ShapeBounding, 0, 0,
bitmap.handle(), ShapeSet );
}
/*!
Removes any mask set by setMask().
\sa setMask()
*/
void QWidget::clearMask()
{
XShapeCombineMask( x11Display(), winId(), ShapeBounding, 0, 0,
None, ShapeSet );
}
/*!\reimp
*/
void QWidget::setName( const char *name )
{
QObject::setName( name );
if ( isTopLevel() ) {
XChangeProperty(qt_xdisplay(), winId(),
qt_window_role, XA_STRING, 8, PropModeReplace,
(unsigned char *)name, qstrlen( name ) );
}
}
|