Ignore:
Timestamp:
Jun 25, 2001, 9:06:00 PM (24 years ago)
Author:
umoeller
Message:

Updates to XCenter and help management.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/dialog.c

    r81 r82  
    15251525
    15261526/*
     1527 *@@ dlghCreateMessageBox:
     1528 *
     1529 *@@added V0.9.13 (2001-06-21) [umoeller]
     1530 */
     1531
     1532APIRET dlghCreateMessageBox(HWND *phwndDlg,
     1533                            HWND hwndOwner,
     1534                            HPOINTER hptrIcon,
     1535                            const char *pcszTitle,
     1536                            const char *pcszMessage,
     1537                            ULONG flFlags,
     1538                            const char *pcszFont,
     1539                            const MSGBOXSTRINGS *pStrings,
     1540                            PULONG pulAlarmFlag)      // out: alarm sound to be played
     1541{
     1542    CONTROLDEF
     1543        Icon = {
     1544                        WC_STATIC,
     1545                        NULL,           // text, set below
     1546                        WS_VISIBLE | SS_ICON,
     1547                        0,          // ID
     1548                        NULL,       // no font
     1549                        0,
     1550                        { SZL_AUTOSIZE, SZL_AUTOSIZE },
     1551                        5
     1552                    },
     1553        InfoText =
     1554                    {
     1555                        WC_STATIC,
     1556                        NULL,       // text, set below
     1557                        WS_VISIBLE | SS_TEXT | DT_WORDBREAK | DT_LEFT | DT_TOP,
     1558                        10,          // ID
     1559                        CTL_COMMON_FONT,
     1560                        0,
     1561                        { 400, SZL_AUTOSIZE },
     1562                        5
     1563                    },
     1564        Buttons[] = {
     1565                        {
     1566                            WC_BUTTON,
     1567                            NULL,       // text, set below
     1568                            WS_VISIBLE | BS_PUSHBUTTON,
     1569                            1,          // ID
     1570                            CTL_COMMON_FONT,  // no font
     1571                            0,
     1572                            { 100, 30 },
     1573                            5
     1574                        },
     1575                        {
     1576                            WC_BUTTON,
     1577                            NULL,       // text, set below
     1578                            WS_VISIBLE | BS_PUSHBUTTON,
     1579                            2,          // ID
     1580                            CTL_COMMON_FONT,  // no font
     1581                            0,
     1582                            { 100, 30 },
     1583                            5
     1584                        },
     1585                        {
     1586                            WC_BUTTON,
     1587                            NULL,       // text, set below
     1588                            WS_VISIBLE | BS_PUSHBUTTON,
     1589                            3,          // ID
     1590                            CTL_COMMON_FONT,  // no font
     1591                            0,
     1592                            { 100, 30 },
     1593                            5
     1594                        }
     1595                    };
     1596
     1597    DLGHITEM MessageBox[] =
     1598                 {
     1599                    START_TABLE,
     1600                        START_ROW(ROW_VALIGN_CENTER),
     1601                            CONTROL_DEF(&Icon),
     1602                        START_TABLE,
     1603                            START_ROW(ROW_VALIGN_CENTER),
     1604                                CONTROL_DEF(&InfoText),
     1605                            START_ROW(ROW_VALIGN_CENTER),
     1606                                CONTROL_DEF(&Buttons[0]),
     1607                                CONTROL_DEF(&Buttons[1]),
     1608                                CONTROL_DEF(&Buttons[2]),
     1609                        END_TABLE,
     1610                    END_TABLE
     1611                 };
     1612
     1613    ULONG flButtons = flFlags & 0xF;        // low nibble contains MB_YESNO etc.
     1614
     1615    const char  *p0 = "Error",
     1616                *p1 = NULL,
     1617                *p2 = NULL;
     1618
     1619    Icon.pcszText = (const char *)hptrIcon;
     1620    InfoText.pcszText = pcszMessage;
     1621
     1622    // now work on the three buttons of the dlg template:
     1623    // give them proper titles or hide them
     1624    if (flButtons == MB_OK)
     1625    {
     1626        p0 = pStrings->pcszOK;
     1627    }
     1628    else if (flButtons == MB_OKCANCEL)
     1629    {
     1630        p0 = pStrings->pcszOK;
     1631        p1 = pStrings->pcszCancel;
     1632    }
     1633    else if (flButtons == MB_RETRYCANCEL)
     1634    {
     1635        p0 = pStrings->pcszRetry;
     1636        p1 = pStrings->pcszCancel;
     1637    }
     1638    else if (flButtons == MB_ABORTRETRYIGNORE)
     1639    {
     1640        p0 = pStrings->pcszAbort;
     1641        p1 = pStrings->pcszRetry;
     1642        p2 = pStrings->pcszIgnore;
     1643    }
     1644    else if (flButtons == MB_YESNO)
     1645    {
     1646        p0 = pStrings->pcszYes;
     1647        p1 = pStrings->pcszNo;
     1648    }
     1649    else if (flButtons == MB_YESNOCANCEL)
     1650    {
     1651        p0 = pStrings->pcszYes;
     1652        p1 = pStrings->pcszNo;
     1653        p2 = pStrings->pcszCancel;
     1654    }
     1655    else if (flButtons == MB_CANCEL)
     1656    {
     1657        p0 = pStrings->pcszCancel;
     1658    }
     1659    else if (flButtons == MB_ENTER)
     1660    {
     1661        p0 = pStrings->pcszEnter;
     1662    }
     1663    else if (flButtons == MB_ENTERCANCEL)
     1664    {
     1665        p0 = pStrings->pcszEnter;
     1666        p1 = pStrings->pcszCancel;
     1667    }
     1668    else if (flButtons == MB_YES_YES2ALL_NO)
     1669    {
     1670        p0 = pStrings->pcszYes;
     1671        p1 = pStrings->pcszYesToAll;
     1672        p2 = pStrings->pcszNo;
     1673    }
     1674
     1675    // now set strings and hide empty buttons
     1676    Buttons[0].pcszText = p0;
     1677
     1678    if (p1)
     1679        Buttons[1].pcszText = p1;
     1680    else
     1681        Buttons[1].flStyle &= ~WS_VISIBLE;
     1682
     1683    if (p2)
     1684        Buttons[2].pcszText = p2;
     1685    else
     1686        Buttons[2].flStyle &= ~WS_VISIBLE;
     1687
     1688    // query default button IDs
     1689    if (flFlags & MB_DEFBUTTON2)
     1690        Buttons[1].flStyle |= BS_DEFAULT;
     1691    else if (flFlags & MB_DEFBUTTON3)
     1692        Buttons[2].flStyle |= BS_DEFAULT;
     1693    else
     1694        Buttons[0].flStyle |= BS_DEFAULT;
     1695
     1696    *pulAlarmFlag = WA_NOTE;
     1697    if (flFlags & (MB_ICONHAND | MB_ERROR))
     1698        *pulAlarmFlag = WA_ERROR;
     1699    else if (flFlags & (MB_ICONEXCLAMATION | MB_WARNING))
     1700        *pulAlarmFlag = WA_WARNING;
     1701
     1702    return (dlghCreateDlg(phwndDlg,
     1703                          hwndOwner,
     1704                          FCF_TITLEBAR | FCF_SYSMENU | FCF_DLGBORDER | FCF_NOBYTEALIGN,
     1705                          WinDefDlgProc,
     1706                          pcszTitle,
     1707                          MessageBox,
     1708                          ARRAYITEMCOUNT(MessageBox),
     1709                          NULL,
     1710                          pcszFont));
     1711}
     1712
     1713/*
     1714 *@@ dlghProcessMessageBox:
     1715 *
     1716 *@@added V0.9.13 (2001-06-21) [umoeller]
     1717 */
     1718
     1719ULONG dlghProcessMessageBox(HWND hwndDlg,
     1720                            ULONG ulAlarmFlag,
     1721                            ULONG flFlags)
     1722{
     1723    ULONG ulrcDlg;
     1724    ULONG flButtons = flFlags & 0xF;        // low nibble contains MB_YESNO etc.
     1725
     1726    winhCenterWindow(hwndDlg);
     1727
     1728    if (flFlags & MB_SYSTEMMODAL)
     1729        WinSetSysModalWindow(HWND_DESKTOP, hwndDlg);
     1730
     1731    if (ulAlarmFlag)
     1732        WinAlarm(HWND_DESKTOP, ulAlarmFlag);
     1733
     1734    ulrcDlg = WinProcessDlg(hwndDlg);
     1735
     1736    WinDestroyWindow(hwndDlg);
     1737
     1738    if (flButtons == MB_OK)
     1739        return MBID_OK;
     1740    else if (flButtons == MB_OKCANCEL)
     1741        switch (ulrcDlg)
     1742        {
     1743            case 1:     return MBID_OK;
     1744            default:    return MBID_CANCEL;
     1745        }
     1746    else if (flButtons == MB_RETRYCANCEL)
     1747        switch (ulrcDlg)
     1748        {
     1749            case 1:     return MBID_RETRY;
     1750            default:    return MBID_CANCEL;
     1751        }
     1752    else if (flButtons == MB_ABORTRETRYIGNORE)
     1753        switch (ulrcDlg)
     1754        {
     1755            case 2:     return MBID_RETRY;
     1756            case 3:     return MBID_IGNORE;
     1757            default:    return MBID_ABORT;
     1758        }
     1759    else if (flButtons == MB_YESNO)
     1760        switch (ulrcDlg)
     1761        {
     1762            case 1:     return MBID_YES;
     1763            default:    return MBID_NO;
     1764        }
     1765    else if (flButtons == MB_YESNOCANCEL)
     1766        switch (ulrcDlg)
     1767        {
     1768            case 1:     return MBID_YES;
     1769            case 2:     return MBID_NO;
     1770            default:    return MBID_CANCEL;
     1771        }
     1772    else if (flButtons == MB_CANCEL)
     1773        return MBID_CANCEL;
     1774    else if (flButtons == MB_ENTER)
     1775        return MBID_ENTER;
     1776    else if (flButtons == MB_ENTERCANCEL)
     1777        switch (ulrcDlg)
     1778        {
     1779            case 1:     return MBID_ENTER;
     1780            default:    return MBID_CANCEL;
     1781        }
     1782    else if (flButtons == MB_YES_YES2ALL_NO)
     1783        switch (ulrcDlg)
     1784        {
     1785            case 1:     return MBID_YES;
     1786            case 2:     return MBID_YES2ALL;
     1787            default:    return MBID_NO;
     1788        }
     1789
     1790    return (MBID_CANCEL);
     1791}
     1792
     1793/*
     1794 *@@ dlghMessageBox:
     1795 *      WinMessageBox replacement.
     1796 *
     1797 *      This has all the flags of the standard call,
     1798 *      but looks much prettier. Besides, it allows
     1799 *      you to specify any icon to be displayed.
     1800 *
     1801 *      Currently the following flStyle's are supported:
     1802 *
     1803 *      -- MB_OK                      0x0000
     1804 *      -- MB_OKCANCEL                0x0001
     1805 *      -- MB_RETRYCANCEL             0x0002
     1806 *      -- MB_ABORTRETRYIGNORE        0x0003
     1807 *      -- MB_YESNO                   0x0004
     1808 *      -- MB_YESNOCANCEL             0x0005
     1809 *      -- MB_CANCEL                  0x0006
     1810 *      -- MB_ENTER                   0x0007 (not implemented yet)
     1811 *      -- MB_ENTERCANCEL             0x0008 (not implemented yet)
     1812 *
     1813 *      -- MB_YES_YES2ALL_NO          0x0009
     1814 *          This is new: this has three buttons called "Yes"
     1815 *          (MBID_YES), "Yes to all" (MBID_YES2ALL), "No" (MBID_NO).
     1816 *
     1817 *      -- MB_DEFBUTTON2            (for two-button styles)
     1818 *      -- MB_DEFBUTTON3            (for three-button styles)
     1819 *
     1820 *      -- MB_ICONHAND
     1821 *      -- MB_ICONEXCLAMATION
     1822 *
     1823 *      Returns MBID_* codes like WinMessageBox.
     1824 *
     1825 *@@added V0.9.13 (2001-06-21) [umoeller]
     1826 */
     1827
     1828ULONG dlghMessageBox(HWND hwndOwner,            // in: owner for msg box
     1829                     HPOINTER hptrIcon,         // in: icon to display
     1830                     const char *pcszTitle,     // in: title
     1831                     const char *pcszMessage,   // in: message
     1832                     ULONG flFlags,             // in: standard message box flags
     1833                     const char *pcszFont,      // in: font (e.g. "9.WarpSans")
     1834                     const MSGBOXSTRINGS *pStrings) // in: strings array
     1835{
     1836    HWND hwndDlg;
     1837    ULONG ulAlarmFlag;
     1838    APIRET arc = dlghCreateMessageBox(&hwndDlg,
     1839                                      hwndOwner,
     1840                                      hptrIcon,
     1841                                      pcszTitle,
     1842                                      pcszMessage,
     1843                                      flFlags,
     1844                                      pcszFont,
     1845                                      pStrings,
     1846                                      &ulAlarmFlag);
     1847
     1848    if (!arc && hwndDlg)
     1849    {
     1850        // SHOW DIALOG
     1851        return (dlghProcessMessageBox(hwndDlg,
     1852                                      ulAlarmFlag,
     1853                                      flFlags));
     1854    }
     1855    else
     1856    {
     1857        CHAR szMsg[100];
     1858        sprintf(szMsg, "dlghCreateMessageBox reported error %u.", arc);
     1859        WinMessageBox(HWND_DESKTOP,
     1860                      NULLHANDLE,
     1861                      "Error",
     1862                      szMsg,
     1863                      0,
     1864                      MB_CANCEL | MB_MOVEABLE);
     1865    }
     1866
     1867    return (DID_CANCEL);
     1868}
     1869
     1870/*
    15271871 *@@ dlghSetPrevFocus:
    15281872 *      "backward" function for rotating the focus
Note: See TracChangeset for help on using the changeset viewer.