home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / tvision / colord / tdemo1.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-05  |  49.1 KB  |  1,465 lines

  1. /*-----------------------------------------------------------------------*/
  2. /* filename -       tdemo1.cpp                                           */
  3. /*                                                                       */
  4. /* function(s)                                                           */
  5. /*                  definitions for the TDemoApp class                   */
  6. /*                                                                       */
  7. /* Author -         Michael "Mick" Newton                                */
  8. /*                                                                       */
  9. /*-----------------------------------------------------------------------*/
  10.  
  11. /*-----------------------------------------------------------------------*/
  12. /*                                                                       */
  13. /*    TDEMO1.CPP                                                         */
  14. /*                                                                       */
  15. /*    TVColorDialog shareware version 2.0                                */
  16. /*    Copyright (C) 1992,1993 Comsoft Software                           */
  17. /*    All Rights Reserved.                                               */
  18. /*                                                                       */
  19. /*                                                                       */
  20. /*-----------------------------------------------------------------------*/
  21.  
  22. // Define Turbo Vision classes used ***************************************
  23.  
  24. #define Uses_TApplication
  25. #define Uses_TBackground
  26. #define Uses_TButton
  27. #define Uses_TCheckBoxes
  28. #define Uses_TCluster
  29. #define Uses_TCollection
  30. #define Uses_TColorGroup
  31. #define Uses_TColorItem
  32. #define Uses_TDeskTop
  33. #define Uses_TDialog
  34. #define Uses_TDisplay
  35. #define Uses_TEvent
  36. #define Uses_TFrame
  37. #define Uses_TGroup
  38. #define Uses_THistory
  39. #define Uses_TInputLine
  40. #define Uses_TKeys
  41. #define Uses_TLabel
  42. #define Uses_TListBox
  43. #define Uses_TListViewer
  44. #define Uses_TMenu
  45. #define Uses_TMenuBar
  46. #define Uses_TMenuItem
  47. #define Uses_TMenuView
  48. #define Uses_TObject
  49. #define Uses_TPalette
  50. #define Uses_TPoint
  51. #define Uses_TProgram
  52. #define Uses_TRadioButtons
  53. #define Uses_TRect
  54. #define Uses_TScreen
  55. #define Uses_TScrollBar
  56. #define Uses_TStaticText
  57. #define Uses_TStatusDef
  58. #define Uses_TStatusItem
  59. #define Uses_TStatusLine
  60. #define Uses_TSItem
  61. #define Uses_TStringCollection
  62. #define Uses_TSubMenu
  63. #define Uses_TView
  64. #define Uses_TWindow
  65. #define Uses_MsgBox
  66. #define Uses_fpstream
  67.  
  68. #include <tv.h>
  69.  
  70.  
  71.  
  72.  
  73.  
  74. // CRTL header files ******************************************************
  75.  
  76. #if !defined __STDLIB_H
  77. #include <stdlib.h>
  78. #endif
  79.  
  80. #if !defined __STDIO_H
  81. #include <stdio.h>
  82. #endif
  83.  
  84. #if !defined __CONIO_H
  85. #include <conio.h>
  86. #endif
  87.  
  88. #if !defined __STRSTREAM_H
  89. #include <strstrea.h>
  90. #endif
  91.  
  92. #if !defined __STRING_H
  93. #include <string.h>
  94. #endif
  95.  
  96.  
  97.  
  98.  
  99.  
  100. // Non-CRTL header files **************************************************
  101.  
  102. #if !defined __TDEMO1_HPP         // TDemoApp
  103. #include "tdemo1.hpp"
  104. #endif
  105.  
  106. #if !defined __TDEMO2_HPP         // xdialogs, statusline, etc
  107. #include "tdemo2.hpp"
  108. #endif
  109.  
  110. #if !defined __COLORDLG_HPP       // TVColorDialog
  111. #include "colordlg.hpp"
  112. #endif
  113.  
  114.  
  115.  
  116.  
  117.  
  118. // Constants **************************************************************
  119.  
  120. // Menubar commands
  121. const cmNone     = 0,
  122.       cmAbout    = 100,
  123.       cmWritePal = 101,
  124.       cmColors   = 102,
  125.       cmOptions  = 103,
  126.       cmXDialog1 = 104,
  127.       cmXDialog2 = 105,
  128.       cmXDialog3 = 106;
  129.  
  130.  
  131.  
  132.  
  133.  
  134. // External global variable references ************************************
  135.  
  136. extern TPoint shadowSize;
  137. extern unsigned _stklen = 8192;        // 8K stack
  138.  
  139. #if defined __OVERLAY__
  140. extern unsigned _ovrbuffer = 0x2000;
  141. #endif
  142.  
  143.  
  144.  
  145.  
  146.  
  147. // TMenuItem **************************************************************
  148.  
  149. TMenuItem& operator +(TMenuItem& item1, TMenuItem& item2)
  150. {
  151.    // For building the application menubar
  152.  
  153.    TMenuItem *p = &item1;
  154.  
  155.    while(p->next != NULL)
  156.       p = p->next;
  157.  
  158.    p->next = &item2;
  159.  
  160.    return item1;
  161. }
  162.  
  163.  
  164.  
  165.  
  166.  
  167. // TDemoApp ***************************************************************
  168.  
  169. /* ┌───────────────────────────────────────────────────────────────────┐ */
  170. /* │ TDemoApp palette layout                                           │ */
  171. /* ╞═══════════════════════════════════════════════════════════════════╡ */
  172. /* │                                                                   │ */
  173. /* │ NOTE:                                                             │ */
  174. /* │ Since elements of a palette are of type char, the maximum number  │ */
  175. /* │ of elements for a palette is 255. Since the char data type has a  │ */
  176. /* │ range of -128 to 127, TVColorDialog treats palette entries as     │ */
  177. /* │ unsigned chars, which range from 0 to 255.                        │ */
  178. /* │                                                                   │ */
  179. /* │ This demo's palette contains 240 elements, not all of which are   │ */
  180. /* │ used. The unused elements are for future expansion.               │ */
  181. /* │                                                                   │ */
  182. /* ╞═══════╤═══════╤═══════════════════════════════════════════════════╡ */
  183. /* │ Start │ End   │                                                   │ */
  184. /* │ index │ index │ Items     (* non-standard palette)                │ */
  185. /* ├───────┼───────┼───────────────────────────────────────────────────┤ */
  186. /* │       │   1   │ Desktop background                                │ */
  187. /* │     2 │   7   │ Menus                                             │ */
  188. /* │     8 │  15   │ Windows (blue)                                    │ */
  189. /* │    16 │  23   │ Windows (cyan)                                    │ */
  190. /* │    24 │  31   │ Windows (gray)                                    │ */
  191. /* │    32 │  63   │ TDialog                                           │ */
  192. /* │ *  64 │ 113   │ TXDialog1                                         │ */
  193. /* │ * 114 │ 163   │ TXDialog2                                         │ */
  194. /* │ * 164 │ 213   │ TXDialog3                                         │ */
  195. /* │ * 214 │ 219   │ TAppStatusLine                                    │ */
  196. /* │ * 220 │ 240   │ Unused                                            │ */
  197. /* └───────┴───────┴───────────────────────────────────────────────────┘ */
  198.  
  199. // Application color palette
  200. #define cpAppColor                            \
  201.    "\x08\x17\x18\x1F\x0E\x08\x0A\x48\x4E\x4E" \
  202.    "\x09\x1F\x4F\x4D\x4A\x4B\x70\x7F\x7E\x78" \
  203.    "\x71\x40\x00\x70\x7F\x7A\x13\x13\x70\x7F" \
  204.    "\x00\x78\x70\x7F\x0C\x0E\x70\x70\x7F\x7E" \
  205.    "\x17\x1E\x1F\x18\x1A\x78\x03\x4F\x0F\x03" \
  206.    "\x0C\x0A\x70\x78\x0C\x0E\x03\x4F\x0E\x70" \
  207.    "\x0A\x00\x00\x18\x1F\x0E\x0D\x4F\x17\x1F" \
  208.    "\x1E\x1A\x70\x7E\x4F\x78\x7B\x10\x03\x4F" \
  209.    "\x0E\x03\x0C\x0A\x1E\x17\x0C\x0E\x03\x4F" \
  210.    "\x0E\x1F\x0A\x2E\x0C\x7E\x5B\x4F\x58\x7F" \
  211.    "\x57\x4A\x00\x18\x1F\x70\x7F\x31\x13\x00" \
  212.    "\x00\x18\x1E\x58\x5F\x0E\x0A\x4F\x57\x5F" \
  213.    "\x5E\x5B\x70\x7F\x4F\x78\x7E\x50\x03\x4F" \
  214.    "\x0E\x03\x0C\x0A\x5E\x57\x0C\x4E\x03\x4F" \
  215.    "\x0E\x5F\x0A\x31\x30\x3E\x3E\x4F\x37\x3F" \
  216.    "\x3D\x4D\x60\x58\x5F\x70\x30\x3A\x6F\x6E" \
  217.    "\x17\x1B\x1F\x28\x2F\x0E\x09\x4E\x20\x2F" \
  218.    "\x2E\x24\x70\x7F\x4F\x78\x7E\x20\x03\x4F" \
  219.    "\x0E\x03\x0C\x0A\x2E\x20\x0C\x0E\x03\x4F" \
  220.    "\x0E\x2F\x0A\x1F\x4F\x5E\x7A\x7F\x78\x5F" \
  221.    "\x7D\x70\x0C\x28\x2F\x5F\x5E\x3E\x17\x1B" \
  222.    "\x1F\x18\x1E\x17\x18\x1F\x4F\x4E\x48\x18" \
  223.    "\x17\x0E\x0C\x4E\x17\x1E\x4F\x47\x4E\x70" \
  224.    "\x7E\x30\x3F\x1B\x0A\x31\x13\x00\x00\x00"
  225.  
  226. // Application black and white palette
  227. #define cpAppBlackWhite                       \
  228.    "\x07\x70\x78\x7F\x0F\x08\x07\x07\x0F\x07" \
  229.    "\x70\x70\x07\x70\x00\x07\x0F\x07\x70\x70" \
  230.    "\x07\x70\x00\x70\x7F\x7F\x70\x07\x70\x07" \
  231.    "\x00\x70\x7F\x7F\x70\x07\x70\x70\x7F\x7F" \
  232.    "\x07\x0F\x0F\x78\x0F\x78\x07\x0F\x0F\x0F" \
  233.    "\x70\x0F\x07\x70\x70\x70\x07\x70\x0F\x07" \
  234.    "\x07\x00\x00\x07\x70\x0F\x70\x0F\x70\x70" \
  235.    "\x7F\x78\x07\x0F\x7F\x08\x07\x78\x7F\x0F" \
  236.    "\x78\x07\x0F\x78\x0F\x78\x07\x0F\x07\x0F" \
  237.    "\x70\x07\x0F\x70\x70\x7F\x70\x0F\x78\x78" \
  238.    "\x07\x08\x00\x70\x7F\x70\x0F\x07\x07\x00" \
  239.    "\x00\x70\x7F\x7F\x70\x07\x70\x70\x7F\x7F" \
  240.    "\x07\x0F\x0F\x78\x0F\x78\x07\x0F\x0F\x0F" \
  241.    "\x70\x0F\x07\x70\x70\x70\x07\x70\x0F\x07" \
  242.    "\x07\x07\x00\x70\x07\x70\x0F\x07\x07\x00" \
  243.    "\x00\x70\x7F\x7F\x70\x07\x70\x70\x7F\x7F" \
  244.    "\x07\x0F\x0F\x78\x0F\x78\x07\x0F\x0F\x0F" \
  245.    "\x70\x0F\x07\x70\x70\x70\x07\x70\x0F\x07" \
  246.    "\x07\x07\x0F\x7F\x07\x70\x0F\x07\x07\x0F" \
  247.    "\x7F\x07\x0F\x07\x70\x70\x70\x07\x70\x70" \
  248.    "\x7F\x7F\x70\x07\x70\x70\x7F\x7F\x07\x0F" \
  249.    "\x0F\x78\x0F\x70\x78\x7F\x0F\x07\x08\x0F" \
  250.    "\x07\x70\x70\x70\x07\x70\x0F\x07\x07\x00" \
  251.    "\x00\x70\x07\x70\x0F\x07\x07\x00\x00\x00"
  252.  
  253. // Application monochrome palette
  254. #define cpAppMonochrome                       \
  255.    "\x07\x07\x01\x0F\x70\x70\x01\x07\x0F\x07" \
  256.    "\x70\x70\x07\x70\x00\x07\x0F\x07\x70\x70" \
  257.    "\x07\x70\x00\x70\x70\x70\x07\x07\x70\x07" \
  258.    "\x00\x07\x70\x0F\x07\x0F\x70\x70\x0F\x01" \
  259.    "\x07\x01\x0F\x70\x01\x70\x07\x0F\x01\x07" \
  260.    "\x0F\x0F\x07\x07\x07\x0F\x07\x70\x0F\x07" \
  261.    "\x07\x00\x00\x07\x0F\x07\x70\x70\x07\x0F" \
  262.    "\x70\x70\x70\x70\x07\x07\x70\x70\x70\x0F" \
  263.    "\x07\x07\x0F\x70\x0F\x70\x07\x0F\x0F\x07" \
  264.    "\x70\x07\x07\x70\x07\x07\x07\x70\x0F\x07" \
  265.    "\x07\x00\x00\x07\x07\x70\x0F\x07\x07\x00" \
  266.    "\x00\x70\x70\x70\x07\x07\x70\x70\x70\x0F" \
  267.    "\x07\x07\x0F\x70\x0F\x70\x07\x0F\x0F\x07" \
  268.    "\x70\x07\x07\x70\x07\x07\x07\x70\x0F\x07" \
  269.    "\x07\x00\x00\x07\x07\x70\x0F\x07\x07\x00" \
  270.    "\x00\x70\x70\x70\x07\x07\x70\x70\x70\x0F" \
  271.    "\x07\x07\x0F\x70\x0F\x70\x07\x0F\x0F\x07" \
  272.    "\x70\x07\x07\x70\x07\x07\x07\x70\x0F\x07" \
  273.    "\x07\x00\x00\x07\x07\x70\x0F\x07\x07\x00" \
  274.    "\x00\x07\x0F\x07\x70\x70\x70\x07\x0F\x70" \
  275.    "\x70\x70\x07\x07\x70\x70\x70\x0F\x07\x07" \
  276.    "\x0F\x70\x0F\x07\x70\x0F\x01\x07\x70\x07" \
  277.    "\x07\x70\x07\x07\x07\x70\x0F\x07\x07\x00" \
  278.    "\x00\x07\x07\x70\x0F\x07\x07\x00\x00\x00"
  279.  
  280.  
  281. TDemoApp::TDemoApp() :
  282.           TProgInit(initStatusLine, initMenuBar, initDeskTop),
  283.           patternIndex(4)
  284. {
  285.    // Set default options in optrec data structure
  286.    optrec.addHelp = 1;
  287.    optrec.patternCount = 2;
  288.    optrec.videoMode = 0;
  289.  
  290.    // Set default desktop pattern and redraw
  291.    deskTop->background->setPattern(patterns[patternIndex]);
  292.    setState(sfExposed, True);
  293.    redraw();
  294.  
  295.    // Display the "about" box
  296.    TEvent event;
  297.    event.what = evCommand;
  298.    event.message.command = cmAbout;
  299.    putEvent(event);
  300.    clearEvent(event);
  301. }
  302.  
  303.  
  304. void TDemoApp::shutDown()
  305. {
  306.    TApplication::shutDown();
  307. }
  308.  
  309.  
  310. TDeskTop *TDemoApp::initDeskTop(TRect r)
  311. {
  312.    r.a.y++;
  313.    r.b.y--;
  314.  
  315.    // Stop the application from drawing in default colors
  316.    TProgram::application->setState(sfExposed, False);
  317.  
  318.    TDeskTop *desktop = new TDeskTop(r);
  319.  
  320.    return desktop;
  321. }
  322.  
  323.  
  324. TMenuBar *TDemoApp::initMenuBar(TRect r)
  325. {
  326.    // Builds the program's menubar
  327.  
  328.    r.b.y = r.a.y + 1;
  329.  
  330.    TMenuItem *sys;
  331.    sys = new TMenuItem("~\360~", kbAltSpace, new TMenu(
  332.       *new TMenuItem("~A~bout", cmAbout, kbNoKey, hcAbout) +
  333.       *new TMenuItem("~W~rite palette to file", cmWritePal, kbNoKey,
  334.                      hcWritePal)), hcSystem);
  335.  
  336.    TMenuItem *exit;
  337.    exit = new TMenuItem("E~x~it", cmQuit, kbAltX, hcExit, 0);
  338.  
  339.    TMenuItem *colors;
  340.    colors = new TMenuItem("~T~VColorDialog", cmColors, kbAltT,
  341.                           hcColors, 0);
  342.  
  343.    TMenuItem *opts;
  344.    opts = new TMenuItem("~O~ptions", cmOptions, kbAltO, hcOptions, 0);
  345.  
  346.    TMenuItem *xdlg;
  347.    xdlg = new TMenuItem("~D~ialogs", kbAltD, new TMenu(
  348.       *new TMenuItem("TXDialog~1~", cmXDialog1, kbNoKey, hcXDialogs) +
  349.       *new TMenuItem("TXDialog~2~", cmXDialog2, kbNoKey, hcXDialogs) +
  350.       *new TMenuItem("TXDialog~3~", cmXDialog3, kbNoKey, hcXDialogs)),
  351.       hcXDialogs);
  352.  
  353.    TMenu *menu = new TMenu(*sys + *exit + *colors + *opts + *xdlg);
  354.    TMenuBar *menubar = new TMenuBar(r, menu);
  355.  
  356.    return menubar;
  357. }
  358.  
  359.  
  360. TStatusLine *TDemoApp::initStatusLine(TRect r)
  361. {
  362.    // Builds the program's status line.
  363.    //
  364.    // NOTE: Actually returns a pointer to a TAppStatusLine object.
  365.    //       See tdemo2.cpp for definition of TAppStatusLine class.
  366.  
  367.    r.a.y = r.b.y - 1;
  368.  
  369.    return new TAppStatusLine(r,
  370.       *new TStatusDef(0, 0xFFFF) +
  371.       *new TStatusItem("~Alt-X~ Exit", kbAltX, cmQuit) +
  372.       *new TStatusItem("~F10~ Menu", kbF10, cmMenu));
  373. }
  374.  
  375.  
  376. TPalette& TDemoApp::getPalette() const
  377. {
  378.    // Returns a reference to either the color, monochrome, or
  379.    // black and white palette, depending on value of 'appPalette'.
  380.  
  381.    static TPalette pal1(cpAppColor, sizeof(cpAppColor) - 1);
  382.    static TPalette pal2(cpAppBlackWhite, sizeof(cpAppBlackWhite) - 1);
  383.    static TPalette pal3(cpAppMonochrome, sizeof(cpAppMonochrome) - 1);
  384.    static TPalette *palettes[] = {&pal1, &pal2, &pal3};
  385.    return *(palettes[appPalette]);
  386. }
  387.  
  388.  
  389. void TDemoApp::getEvent(TEvent& event)
  390. {
  391.    static Boolean helpInUse = False;
  392.  
  393.    TApplication::getEvent(event);
  394.  
  395.    switch(event.what)
  396.       {
  397.       case evCommand:
  398.          if(event.message.command == cmHelp && !helpInUse)
  399.             {
  400.             helpInUse = True;
  401.             helpDialog();
  402.             helpCtx = hcNoContext;
  403.             helpInUse = False;
  404.             clearEvent(event);
  405.             }
  406.          break;
  407.       case evMouseDown:
  408.          if(event.mouse.buttons != mbLeftButton)
  409.             event.what = evNothing;
  410.          break;
  411.       }
  412.  
  413.    // getEvent
  414. }
  415.  
  416.  
  417. void TDemoApp::handleEvent(TEvent& event)
  418. {
  419.    TApplication::handleEvent(event);
  420.  
  421.    if(event.what == evCommand)
  422.       {
  423.       switch(event.message.command)
  424.          {
  425.          case cmAbout:
  426.             about();
  427.             break;
  428.          case cmWritePal:
  429.             writePalette();
  430.             break;
  431.          case cmColors:
  432.             colors();
  433.             break;
  434.          case cmOptions:
  435.             options();
  436.             break;
  437.          case cmXDialog1:
  438.             xdialog1();
  439.             break;
  440.          case cmXDialog2:
  441.             xdialog2();
  442.             break;
  443.          case cmXDialog3:
  444.             xdialog3();
  445.             break;
  446.          }
  447.       }
  448.  
  449.    clearEvent(event);
  450. }
  451.  
  452.  
  453. void TDemoApp::about()
  454. {
  455.    // Displays information about this demo application
  456.  
  457.    TDialog *dialog = new TDialog(TRect(10, 1, 70, 21), "About");
  458.  
  459.    if(dialog == NULL)
  460.       return;
  461.  
  462.    dialog->options |= ofCentered;
  463.    dialog->helpCtx = hcAbout;
  464.  
  465.    TView *box;
  466.    box = new TView(TRect(1, 12, 59, 15));
  467.    box->options |= ofFramed | ofCenterX;
  468.    dialog->insert(box);
  469.  
  470.    TStaticText *t;
  471.    t = new TStaticText(TRect(25, 2, 34, 3), "TDEMO.EXE");
  472.    t->options |= ofCenterX;
  473.    dialog->insert(t);
  474.  
  475.    t = new TStaticText(TRect(11, 3, 49, 4),
  476.                        "Demonstrates the TVColorDialog library");
  477.    t->options |= ofCenterX;
  478.    dialog->insert(t);
  479.  
  480.    char ver[36];
  481.    strcpy(ver, "TVColorDialog shareware version ");
  482.    strcat(ver, colorDlgVerStr);
  483.  
  484.    t = new TStaticText(TRect(12, 5, 47, 6), ver);
  485.    t->options |= ofCenterX;
  486.    dialog->insert(t);
  487.  
  488.    t = new TStaticText(TRect(10, 6, 50, 7),
  489.                        "(C) Copyright 1992,1993 Comsoft Software");
  490.    t->options |= ofCenterX;
  491.    dialog->insert(t);
  492.  
  493.    t = new TStaticText(TRect(20, 7, 40, 8), "All rights reserved.");
  494.    t->options |= ofCenterX;
  495.    dialog->insert(t);
  496.  
  497.    t = new TStaticText(TRect(7, 9, 53, 10),
  498.                        "Created by Michael Newton for Comsoft Software");
  499.    t->options |= ofCenterX;
  500.    dialog->insert(t);
  501.  
  502.    t = new TStaticText(TRect(3, 12, 57, 13),
  503.                        "See the file COLORDLG.DOC for information"
  504.                        " on obtaining");
  505.    t->options |= ofCenterX;
  506.    dialog->insert(t);
  507.  
  508.    t = new TStaticText(TRect(4, 13, 56, 14),
  509.                        "a registered version of TVColorDialog"
  510.                        " complete with");
  511.    t->options |= ofCenterX;
  512.    dialog->insert(t);
  513.  
  514.    t = new TStaticText(TRect(16, 14, 44, 15),
  515.                        "fully commented source code!");
  516.    t->options |= ofCenterX;
  517.    dialog->insert(t);
  518.  
  519.    TButton *b;
  520.    b = new TButton(TRect(14, 17, 46, 19), "~O~k", cmOK, bfDefault);
  521.    b->options |= ofCenterX;
  522.    dialog->insert(b);
  523.  
  524.    if(validView(dialog))
  525.       {
  526.       deskTop->execView(dialog);
  527.       TObject::destroy((TDialog *) dialog);
  528.       }
  529. }
  530.  
  531.  
  532. void TDemoApp::writePalette()
  533. {
  534.    // Writes the applications palettes to a text file formatted as they
  535.    // appear in the TDemoApp palette #defines above.
  536.    //
  537.    // NOTE: The resulting text file can be pasted into this code to
  538.    //       replace the current application palettes
  539.    //
  540.  
  541.    char filename[256];
  542.    memset(filename, '\0', 256);
  543.  
  544.    ushort result = inputBox("Path and/or filename for palette file",
  545.                             "Path/Filename", filename, 255);
  546.  
  547.    if(result == cmCancel)
  548.       return;
  549.  
  550.    char buff[512];
  551.    ostrstream os(buff, sizeof buff);
  552.  
  553.    fpstream *f = new fpstream(filename, ios::out | ios::trunc);
  554.  
  555.    if(!f->good())
  556.       {
  557.       os << "\003Could not create palette file:\n\003"
  558.          << filename
  559.          << ends;
  560.       messageBox(buff, mfError | mfOKButton);
  561.       return;
  562.       }
  563.  
  564.    char *commentLine[] =
  565.       {
  566.       "// Application color palette",
  567.       "// Application black and white palette",
  568.       "// Application monochrome palette"
  569.       };
  570.    char *paletteName[] =
  571.       {
  572.       "#define cpAppColor                            ",
  573.       "#define cpAppBlackWhite                       ",
  574.       "#define cpAppMonochrome                       "
  575.       };
  576.    char reverseSlant[] = "\\";
  577.    char quotationMark[] = "\"";
  578.    opstream& strm = *f;
  579.    int curpal = appPalette;
  580.  
  581.    // Write all three application palettes to stream
  582.    for(int paletteCtr = 0; paletteCtr < 3; paletteCtr++)
  583.       {
  584.       char oldFill;
  585.       os.seekp(0);
  586.       os << commentLine[paletteCtr]
  587.          << endl
  588.          << paletteName[paletteCtr]
  589.          << reverseSlant
  590.          << endl
  591.          << "   "
  592.          << quotationMark
  593.          << ends;
  594.       strm.writeBytes(buff, strlen(buff));
  595.       os.setf(ios::uppercase);
  596.       os.setf(ios::hex, ios::basefield);
  597.       oldFill = os.fill('0');
  598.       appPalette = paletteCtr;
  599.       TPalette &palette = getPalette();
  600.       int length = palette[0] & 0x00FF;
  601.       for(int ctr = 1; ctr <= length; ctr++)
  602.          {
  603.          os.seekp(0);
  604.          os << reverseSlant
  605.             << "x";
  606.          os.width(2);
  607.          os << (unsigned int) palette[ctr];
  608.          if(ctr == length)
  609.             os << quotationMark;
  610.          else if(ctr % 10 == 0)
  611.             os << quotationMark
  612.                << " "
  613.                << reverseSlant
  614.                << endl
  615.                << "   "
  616.                << quotationMark;
  617.          os << ends;
  618.          strm.writeBytes(buff, strlen(buff));
  619.          }
  620.       os.fill(oldFill);
  621.       os.seekp(0);
  622.       os << endl
  623.          << endl
  624.          << ends;
  625.       strm.writeBytes(buff, strlen(buff));
  626.       }
  627.  
  628.    appPalette = curpal;
  629.    f->close();
  630.    delete((fpstream *) f);
  631.    helpCtx = hcNoContext;
  632. }
  633.  
  634.  
  635. void TDemoApp::options()
  636. {
  637.    // Displays a dialog which lets the user select TVColorDialog options
  638.  
  639.    TDialog *dialog;
  640.    dialog = new TDialog(TRect(21, 1, 59, 21), "TVColorDialog options");
  641.  
  642.    if(dialog == NULL)
  643.       return;
  644.  
  645.    dialog->options |= ofCentered;
  646.    dialog->helpCtx = hcOptions;
  647.  
  648.    TCheckBoxes *helpCheckbox;
  649.    helpCheckbox = new TCheckBoxes(TRect(3, 3, 35, 4),
  650.                       new TSItem("Include help button", 0));
  651.    helpCheckbox->options |= ofFramed;
  652.    dialog->insert(helpCheckbox);
  653.  
  654.    TLabel *l;
  655.    l = new TLabel(TRect(4, 2, 17, 3), "~H~elp button ", helpCheckbox);
  656.    dialog->insert(l);
  657.  
  658.    TRadioButtons *patbutton;
  659.    patbutton = new TRadioButtons(TRect(3, 6, 35, 9),
  660.                    new TSItem("~4~ characters",
  661.                    new TSItem("~8~ characters",
  662.                    new TSItem("~1~6 characters", 0))));
  663.    patbutton->options |= ofFramed;
  664.    dialog->insert(patbutton);
  665.  
  666.    l = new TLabel(TRect(4, 5, 34, 6),
  667.                   "~N~umber of pattern characters ", patbutton);
  668.    dialog->insert(l);
  669.  
  670.    TRadioButtons *modebutton;
  671.    modebutton = new TRadioButtons(TRect(3, 11, 35, 15),
  672.                     new TSItem("~2~5 lines color",
  673.                     new TSItem("~4~3/50 lines color",
  674.                     new TSItem("~M~onochrome",
  675.                     new TSItem("~B~lack and white", 0)))));
  676.    modebutton->options |= ofFramed;
  677.    dialog->insert(modebutton);
  678.  
  679.    l = new TLabel(TRect(4, 10, 16, 11), "~V~ideo mode ", modebutton);
  680.    dialog->insert(l);
  681.  
  682.    TButton *b;
  683.    b = new TButton(TRect(4, 17, 18, 19), "~C~ancel", cmCancel, bfNormal);
  684.    dialog->insert(b);
  685.  
  686.    b = new TButton(TRect(20, 17, 34, 19), "~O~k", cmOK, bfDefault);
  687.    dialog->insert(b);
  688.  
  689.    dialog->selectNext(False);
  690.    dialog->helpCtx = hcOptions;
  691.  
  692.    if(validView(dialog))
  693.       {
  694.       ushort curmode = optrec.videoMode;
  695.       dialog->setData(&optrec);
  696.       if(deskTop->execView(dialog) != cmCancel)
  697.          {
  698.          dialog->getData(&optrec);
  699.          if(curmode != optrec.videoMode)
  700.             setVideoMode();
  701.          }
  702.       TObject::destroy((TDialog *) dialog);
  703.       }
  704. }
  705.  
  706.  
  707. void TDemoApp::setVideoMode()
  708. {
  709.    // Sets the video mode to the mode stored in optrec
  710.  
  711.    ushort mode;
  712.  
  713.    switch(optrec.videoMode)
  714.       {
  715.       case 0:
  716.          mode = TDisplay::smCO80;
  717.          break;
  718.       case 1:
  719.          mode = TDisplay::smFont8x8;
  720.          break;
  721.       case 2:
  722.          mode = TDisplay::smBW80;
  723.          break;
  724.       default:
  725.          mode = TDisplay::smMono;
  726.          break;
  727.       }
  728.  
  729.    if((mode & TDisplay::smFont8x8) != 0)
  730.       shadowSize.x = 1;
  731.    else
  732.       shadowSize.x = 2;
  733.  
  734.    // Set the selected mode
  735.    setScreenMode(mode);
  736.  
  737.    // Force a redraw of the application
  738.    setState(sfExposed, False);
  739.    setState(sfExposed, True);
  740.    redraw();
  741. }
  742.  
  743.  
  744. TColorGroup &TDemoApp::buildGroup1()
  745. {
  746.    // Builds color group 1 for the TVColorDialog
  747.  
  748.    // Maximum visible length of a string in either the "groups" list
  749.    // of "items" list is 37 characters
  750.    // "1---------------to-----------------37"
  751.  
  752.    TColorGroup &g1 =
  753.       *new TColorGroup("Desktop")                                      +
  754.          *new TColorItem("Background Color",                        1);
  755.  
  756.    TColorGroup &g2 =
  757.       *new TColorGroup("Menus")                                        +
  758.          *new TColorItem("Normal Text",                             2) +
  759.          *new TColorItem("Disabled Entry Text",                     3) +
  760.          *new TColorItem("Shortcut Letter",                         4) +
  761.          *new TColorItem("Selection Bar Normal Text",               5) +
  762.          *new TColorItem("Selection Bar Disabled Text",             6) +
  763.          *new TColorItem("Selection Bar Shortcut Letter",           7);
  764.  
  765.    TColorGroup &g3 =
  766.       *new TColorGroup("Status Line")                                  +
  767.          *new TColorItem("Normal Text",                           214) +
  768.          *new TColorItem("Disabled Entry Text",                   215) +
  769.          *new TColorItem("Shortcut Letter",                       216) +
  770.          *new TColorItem("Selected Text",                         217) +
  771.          *new TColorItem("Selected Letter",                       218) +
  772.          *new TColorItem("Selected Disabled Text",                219);
  773.  
  774.    TColorGroup &group1 = g1 + g2 + g3;
  775.  
  776.    return group1;
  777. }
  778.  
  779.  
  780. TColorGroup &TDemoApp::buildGroup2()
  781. {
  782.    // Builds color group 2 for the TVColorDialog
  783.  
  784.    // Maximum visible length of a string in either the "groups" list
  785.    // of "items" list is 37 characters
  786.    // "1---------------to-----------------37"
  787.  
  788.    TColorGroup &group2 =
  789.       *new TColorGroup("Standard Dialogs")                             +
  790.          *new TColorItem("Frame Passive",                          32) +
  791.          *new TColorItem("Frame Active",                           33) +
  792.          *new TColorItem("Frame Icons",                            34) +
  793.          *new TColorItem("Scrollbar Page Area",                    35) +
  794.          *new TColorItem("Scrollbar Icons",                        36) +
  795.          *new TColorItem("Static Text",                            37) +
  796.          *new TColorItem("Label Normal Text",                      38) +
  797.          *new TColorItem("Label Highlight Text",                   39) +
  798.          *new TColorItem("Label Shortcut Letter",                  40) +
  799.          *new TColorItem("Button Normal",                          41) +
  800.          *new TColorItem("Button Default",                         42) +
  801.          *new TColorItem("Button Selected",                        43) +
  802.          *new TColorItem("Button Disabled",                        44) +
  803.          *new TColorItem("Button Shortcut",                        45) +
  804.          *new TColorItem("Button Shadow",                          46) +
  805.          *new TColorItem("Cluster Normal",                         47) +
  806.          *new TColorItem("Cluster Selected",                       48) +
  807.          *new TColorItem("Cluster Shortcut",                       49) +
  808.          *new TColorItem("Input Line Normal Text",                 50) +
  809.          *new TColorItem("Input Line Selected Text",               51) +
  810.          *new TColorItem("Input Line Arrows",                      52) +
  811.          *new TColorItem("History List Arrow",                     53) +
  812.          *new TColorItem("History List Arrow Sides",               54) +
  813.          *new TColorItem("History List Scrollbar Page Area",       55) +
  814.          *new TColorItem("History List Scrollbar Icons",           56) +
  815.          *new TColorItem("List Viewer Normal Text",                57) +
  816.          *new TColorItem("List Viewer Focused Text",               58) +
  817.          *new TColorItem("List Viewer Selected Text",              59) +
  818.          *new TColorItem("List Viewer Divider",                    60);
  819.  
  820.    return group2;
  821. }
  822.  
  823.  
  824. TColorGroup &TDemoApp::buildGroup3()
  825. {
  826.    // Builds color group 3 for the TVColorDialog
  827.  
  828.    // Maximum visible length of a string in either the "groups" list
  829.    // of "items" list is 37 characters
  830.    // "1---------------to-----------------37"
  831.  
  832.    TColorGroup &group3 =
  833.       *new TColorGroup("Extended Palette Dialogs #1")                  +
  834.          *new TColorItem("Title Passive",                         104) +
  835.          *new TColorItem("Title Active",                          105) +
  836.          *new TColorItem("Frame Passive",                          64) +
  837.          *new TColorItem("Frame Active",                           65) +
  838.          *new TColorItem("Frame Icons",                            66) +
  839.          *new TColorItem("Scrollbar Page Area",                    67) +
  840.          *new TColorItem("Scrollbar Icons",                        68) +
  841.          *new TColorItem("Static Text",                            69) +
  842.          *new TColorItem("Label Normal Text",                      70) +
  843.          *new TColorItem("Label Highlight Text",                   71) +
  844.          *new TColorItem("Label Shortcut Letter",                  72) +
  845.          *new TColorItem("Button Normal",                          73) +
  846.          *new TColorItem("Button Default",                         74) +
  847.          *new TColorItem("Button Selected",                        75) +
  848.          *new TColorItem("Button Disabled",                        76) +
  849.          *new TColorItem("Button Shortcut",                        77) +
  850.          *new TColorItem("Button Shadow",                          78) +
  851.          *new TColorItem("Cluster Normal",                         79) +
  852.          *new TColorItem("Cluster Selected",                       80) +
  853.          *new TColorItem("Cluster Shortcut",                       81) +
  854.          *new TColorItem("Input Line Normal Text",                 82) +
  855.          *new TColorItem("Input Line Selected Text",               83) +
  856.          *new TColorItem("Input Line Arrows",                      84) +
  857.          *new TColorItem("History List Arrow",                     85) +
  858.          *new TColorItem("History List Arrow Sides",               86) +
  859.          *new TColorItem("History List Scrollbar Page Area",       87) +
  860.          *new TColorItem("History List Scrollbar Icons",           88) +
  861.          *new TColorItem("List Viewer Normal Text",                89) +
  862.          *new TColorItem("List Viewer Focused Text",               90) +
  863.          *new TColorItem("List Viewer Selected Text",              91) +
  864.          *new TColorItem("List Viewer Divider",                    92) +
  865.          *new TColorItem("Unused",                                 93) +
  866.          *new TColorItem("Unused",                                 96) +
  867.          *new TColorItem("Unused",                                 97) +
  868.          *new TColorItem("Unused",                                 98) +
  869.          *new TColorItem("Unused",                                 99) +
  870.          *new TColorItem("Unused",                                100) +
  871.          *new TColorItem("Unused",                                101) +
  872.          *new TColorItem("Unused",                                102) +
  873.          *new TColorItem("Unused",                                106) +
  874.          *new TColorItem("Unused",                                107);
  875.  
  876.    return group3;
  877. }
  878.  
  879.  
  880. TColorGroup &TDemoApp::buildGroup4()
  881. {
  882.    // Builds color group for the TVColorDialog
  883.  
  884.    // Maximum visible length of a string in either the "groups" list
  885.    // of "items" list is 37 characters
  886.    // "1---------------to-----------------37"
  887.  
  888.    TColorGroup &group4 =
  889.       *new TColorGroup("Extended Palette Dialogs #2")                  +
  890.          *new TColorItem("Title Passive",                         154) +
  891.          *new TColorItem("Title Active",                          155) +
  892.          *new TColorItem("Frame Passive",                         114) +
  893.          *new TColorItem("Frame Active",                          115) +
  894.          *new TColorItem("Frame Icons",                           116) +
  895.          *new TColorItem("Scrollbar Page Area",                   117) +
  896.          *new TColorItem("Scrollbar Icons",                       118) +
  897.          *new TColorItem("Static Text",                           119) +
  898.          *new TColorItem("Label Normal Text",                     120) +
  899.          *new TColorItem("Label Highlight Text",                  121) +
  900.          *new TColorItem("Label Shortcut Letter",                 122) +
  901.          *new TColorItem("Button Normal",                         123) +
  902.          *new TColorItem("Button Default",                        124) +
  903.          *new TColorItem("Button Selected",                       125) +
  904.          *new TColorItem("Button Disabled",                       126) +
  905.          *new TColorItem("Button Shortcut",                       127) +
  906.          *new TColorItem("Button Shadow",                         128) +
  907.          *new TColorItem("Cluster Normal",                        129) +
  908.          *new TColorItem("Cluster Selected",                      130) +
  909.          *new TColorItem("Cluster Shortcut",                      131) +
  910.          *new TColorItem("Input Line Normal Text",                132) +
  911.          *new TColorItem("Input Line Selected Text",              133) +
  912.          *new TColorItem("Input Line Arrows",                     134) +
  913.          *new TColorItem("History List Arrow",                    135) +
  914.          *new TColorItem("History List Arrow Sides",              136) +
  915.          *new TColorItem("History List Scrollbar Page Area",      137) +
  916.          *new TColorItem("History List Scrollbar Icons",          138) +
  917.          *new TColorItem("List Viewer Normal Text",               139) +
  918.          *new TColorItem("List Viewer Focused Text",              140) +
  919.          *new TColorItem("List Viewer Selected Text",             141) +
  920.          *new TColorItem("List Viewer Divider",                   142) +
  921.          *new TColorItem("Unused",                                143) +
  922.          *new TColorItem("Unused",                                146) +
  923.          *new TColorItem("Unused",                                147) +
  924.          *new TColorItem("Unused",                                148) +
  925.          *new TColorItem("Unused",                                149) +
  926.          *new TColorItem("Unused",                                150) +
  927.          *new TColorItem("Unused",                                151) +
  928.          *new TColorItem("Unused",                                152) +
  929.          *new TColorItem("Unused",                                156) +
  930.          *new TColorItem("Unused",                                157);
  931.  
  932.    return group4;
  933. }
  934.  
  935.  
  936. TColorGroup &TDemoApp::buildGroup5()
  937. {
  938.    // Builds color group 5 for the TVColorDialog
  939.  
  940.    // Maximum visible length of a string in either the "groups" list
  941.    // of "items" list is 37 characters
  942.    // "1---------------to-----------------37"
  943.  
  944.    TColorGroup &group5 =
  945.       *new TColorGroup("Extended Palette Dialogs #3")                  +
  946.          *new TColorItem("Title Passive",                         204) +
  947.          *new TColorItem("Title Active",                          205) +
  948.          *new TColorItem("Frame Passive",                         164) +
  949.          *new TColorItem("Frame Active",                          165) +
  950.          *new TColorItem("Frame Icons",                           166) +
  951.          *new TColorItem("Scrollbar Page Area",                   167) +
  952.          *new TColorItem("Scrollbar Icons",                       168) +
  953.          *new TColorItem("Static Text",                           169) +
  954.          *new TColorItem("Label Normal Text",                     170) +
  955.          *new TColorItem("Label Highlight Text",                  171) +
  956.          *new TColorItem("Label Shortcut Letter",                 172) +
  957.          *new TColorItem("Button Normal",                         173) +
  958.          *new TColorItem("Button Default",                        174) +
  959.          *new TColorItem("Button Selected",                       175) +
  960.          *new TColorItem("Button Disabled",                       176) +
  961.          *new TColorItem("Button Shortcut",                       177) +
  962.          *new TColorItem("Button Shadow",                         178) +
  963.          *new TColorItem("Cluster Normal",                        179) +
  964.          *new TColorItem("Cluster Selected",                      180) +
  965.          *new TColorItem("Cluster Shortcut",                      181) +
  966.          *new TColorItem("Input Line Normal Text",                182) +
  967.          *new TColorItem("Input Line Selected Text",              183) +
  968.          *new TColorItem("Input Line Arrows",                     184) +
  969.          *new TColorItem("History List Arrow",                    185) +
  970.          *new TColorItem("History List Arrow Sides",              186) +
  971.          *new TColorItem("History List Scrollbar Page Area",      187) +
  972.          *new TColorItem("History List Scrollbar Icons",          188) +
  973.          *new TColorItem("List Viewer Normal Text",               189) +
  974.          *new TColorItem("List Viewer Focused Text",              190) +
  975.          *new TColorItem("List Viewer Selected Text",             191) +
  976.          *new TColorItem("List Viewer Divider",                   192) +
  977.          *new TColorItem("Unused",                                193) +
  978.          *new TColorItem("Unused",                                196) +
  979.          *new TColorItem("Unused",                                197) +
  980.          *new TColorItem("Unused",                                198) +
  981.          *new TColorItem("Unused",                                199) +
  982.          *new TColorItem("Unused",                                200) +
  983.          *new TColorItem("Unused",                                201) +
  984.          *new TColorItem("Unused",                                202) +
  985.          *new TColorItem("Unused",                                206) +
  986.          *new TColorItem("Unused",                                207);
  987.  
  988.    return group5;
  989. }
  990.  
  991.  
  992. void TDemoApp::colors()
  993. {
  994.    // Displays the TVColorDialog dialog
  995.  
  996.    // Build the color groups
  997.    TColorGroup &g1 = buildGroup1();
  998.    TColorGroup &g2 = buildGroup2();
  999.    TColorGroup &g3 = buildGroup3();
  1000.    TColorGroup &g4 = buildGroup4();
  1001.    TColorGroup &g5 = buildGroup5();
  1002.    TColorGroup &groups = g1 + g2 + g3 + g4 + g5;
  1003.  
  1004.    // Copy patterns string into a temp buffer
  1005.    char buff[MAXPATTERNS + 1];
  1006.    strcpy(buff, patterns);
  1007.  
  1008.    // Check optrec to see how many patterns to display (4, 8, or 16).
  1009.    // Set patternIndex to zero if out of range.
  1010.    if(optrec.patternCount == 0)
  1011.       {
  1012.       buff[4] = 0;
  1013.       if(patternIndex > 3)
  1014.          patternIndex = 0;
  1015.       }
  1016.    else if(optrec.patternCount == 1)
  1017.       {
  1018.       buff[8] = 0;
  1019.       if(patternIndex > 7)
  1020.          patternIndex = 0;
  1021.       }
  1022.  
  1023.    // Check optrec to see if we want a help button in the dialog
  1024.    Boolean addHelp = False;
  1025.    if(optrec.addHelp)
  1026.       addHelp = True;
  1027.  
  1028.    // Create the TVColorDialog
  1029.    TVColorDialog *dialog;
  1030.    dialog = new TVColorDialog(&getPalette(), &groups, buff, addHelp);
  1031.  
  1032.    if(validView(dialog))
  1033.       {
  1034.       dialog->helpCtx = hcColors;      // Set dialog's help context
  1035.       TVColorDialogRec rec;            // Struct for setData
  1036.       TPalette *p = &getPalette();     // Point to app's palette
  1037.       rec.pal = p;                     // Init struct with palette...
  1038.       rec.pattern = patternIndex;      // and pattern index
  1039.       dialog->setData(&rec);           // Set dialog's data
  1040.       ushort choice = deskTop->execView(dialog);
  1041.       if(choice != cmCancel)
  1042.          {
  1043.          dialog->getData(&rec);
  1044.          patternIndex = rec.pattern;              // Store pattern index
  1045.          // Set the desktop pattern index
  1046.          deskTop->background->setPattern(buff[patternIndex]);
  1047.          // Force a redraw of the application
  1048.          setState(sfExposed, False);
  1049.          setState(sfExposed, True);
  1050.          redraw();
  1051.          }
  1052.       TObject::destroy((TVColorDialog *) dialog);
  1053.       }
  1054. }
  1055.  
  1056.  
  1057. void TDemoApp::xdialog1()
  1058. {
  1059.    // Inserts a TXDialog1 dialog (see TDEMO2.CPP) into the desktop
  1060.    // to demonstrate the colors selected in TVColorDialog
  1061.  
  1062.    TXDialog1 *dialog;
  1063.    dialog = new TXDialog1(TRect(6, 2, 73, 21),
  1064.                           "Extended Palette TXDialog1");
  1065.  
  1066.    if(dialog == NULL)
  1067.       return;
  1068.  
  1069.    dialog->options |= ofCentered;
  1070.    dialog->helpCtx = hcXDialogs;
  1071.  
  1072.    TView *v;
  1073.    v = new TView(TRect(1, 2, 33, 6));
  1074.    v->options |= ofFramed;
  1075.    dialog->insert(v);
  1076.  
  1077.    v = new TView(TRect(1, 7, 33, 11));
  1078.    v->options |= ofFramed;
  1079.    dialog->insert(v);
  1080.  
  1081.    v = new TView(TRect(1, 12, 33, 14));
  1082.    v->options |= ofFramed;
  1083.    dialog->insert(v);
  1084.  
  1085.    v = new TView(TRect(34, 2, 66, 11));
  1086.    v->options |= ofFramed;
  1087.    dialog->insert(v);
  1088.  
  1089.    v = new TView(TRect(34, 12, 66, 14));
  1090.    v->options |= ofFramed;
  1091.    dialog->insert(v);
  1092.  
  1093.    TCheckBoxes *cb = new TCheckBoxes(TRect(2, 3, 31, 6),
  1094.                          new TSItem("~W~indows",
  1095.                          new TSItem("~U~nix",
  1096.                          new TSItem("~O~S/2", 0))));
  1097.    dialog->insert(cb);
  1098.  
  1099.    dialog->insert(new TLabel(TRect(2, 2, 14, 3), "~C~heckboxes", cb));
  1100.  
  1101.    TRadioButtons *rb = new TRadioButtons(TRect(2, 8, 31, 11),
  1102.                            new TSItem("~A~pples",
  1103.                            new TSItem("~O~ranges",
  1104.                            new TSItem("~B~anannas", 0))));
  1105.    dialog->insert(rb);
  1106.  
  1107.    dialog->insert(new TLabel(TRect(2, 7, 17, 8), "~R~adio buttons", rb));
  1108.  
  1109.    TStaticText *t;
  1110.    t = new TStaticText(TRect(2, 12, 31, 14), "\003This is a sample\n"
  1111.                                              "\003TStaticText view.");
  1112.    dialog->insert(t);
  1113.  
  1114.    TScrollBar *sb = new TScrollBar(TRect(64, 3, 65, 10));
  1115.    dialog->insert(sb);
  1116.  
  1117.    dialog->listbox = new TListBox(TRect(36, 3, 64, 10), 2, sb);
  1118.    dialog->insert(dialog->listbox);
  1119.  
  1120.    TStringCollection *strings;
  1121.    strings = new TStringCollection(20, 10);
  1122.  
  1123.    for(short ctr = 0; ctr < 20; ctr++)
  1124.       {
  1125.       short num = ctr + 1;
  1126.       char str[16];
  1127.       ostrstream os(str, sizeof str);
  1128.       os << "List item #" << num << ends;
  1129.       strings->atInsert(ctr, newStr(str));
  1130.       }
  1131.  
  1132.    dialog->listbox->newList(strings);
  1133.  
  1134.    dialog->insert(new TLabel(TRect(36, 2, 45, 3), "~L~istbox ",
  1135.                   dialog->listbox));
  1136.  
  1137.    TInputLine *i = new TInputLine(TRect(35, 13, 62, 14), 129);
  1138.    dialog->insert(i);
  1139.  
  1140.    THistory *h;
  1141.    h = new THistory(TRect(62, 13, 65, 14), i, 1);
  1142.    dialog->insert(h);
  1143.  
  1144.    dialog->insert(new TLabel(TRect(35, 12, 46, 13), "~T~InputLine", i));
  1145.  
  1146.    TButton *b;
  1147.    b = new TButton(TRect(4, 16, 22, 18), "Button ~1~", cmNone, bfNormal);
  1148.    dialog->insert(b);
  1149.  
  1150.    b = new TButton(TRect(24, 16, 43, 18), "Button ~2~", cmNone, bfNormal);
  1151.    dialog->insert(b);
  1152.  
  1153.    b = new TButton(TRect(45, 16, 63, 18), "~C~lose", cmCloseX, bfDefault);
  1154.    dialog->insert(b);
  1155.  
  1156.    dialog->selectNext(False);
  1157.  
  1158.    if(validView(dialog))
  1159.       deskTop->insert(dialog);
  1160. }
  1161.  
  1162.  
  1163. void TDemoApp::xdialog2()
  1164. {
  1165.    // Inserts a TXDialog2 dialog (see TDEMO2.CPP) into the desktop
  1166.    // to demonstrate the colors selected in TVColorDialog
  1167.  
  1168.    TXDialog2 *dialog;
  1169.    dialog = new TXDialog2(TRect(6, 2, 73, 21),
  1170.                           "Extended Palette TXDialog2");
  1171.  
  1172.    if(dialog == NULL)
  1173.       return;
  1174.  
  1175.    dialog->options |= ofCentered;
  1176.    dialog->helpCtx = hcXDialogs;
  1177.  
  1178.    TView *v;
  1179.    v = new TView(TRect(1, 2, 33, 6));
  1180.    v->options |= ofFramed;
  1181.    dialog->insert(v);
  1182.  
  1183.    v = new TView(TRect(1, 7, 33, 11));
  1184.    v->options |= ofFramed;
  1185.    dialog->insert(v);
  1186.  
  1187.    v = new TView(TRect(1, 12, 33, 14));
  1188.    v->options |= ofFramed;
  1189.    dialog->insert(v);
  1190.  
  1191.    v = new TView(TRect(34, 2, 66, 11));
  1192.    v->options |= ofFramed;
  1193.    dialog->insert(v);
  1194.  
  1195.    v = new TView(TRect(34, 12, 66, 14));
  1196.    v->options |= ofFramed;
  1197.    dialog->insert(v);
  1198.  
  1199.    TCheckBoxes *cb = new TCheckBoxes(TRect(2, 3, 31, 6),
  1200.                          new TSItem("~W~indows",
  1201.                          new TSItem("~U~nix",
  1202.                          new TSItem("~O~S/2", 0))));
  1203.    dialog->insert(cb);
  1204.  
  1205.    dialog->insert(new TLabel(TRect(2, 2, 14, 3), "~C~heckboxes", cb));
  1206.  
  1207.    TRadioButtons *rb = new TRadioButtons(TRect(2, 8, 31, 11),
  1208.                            new TSItem("~A~pples",
  1209.                            new TSItem("~O~ranges",
  1210.                            new TSItem("~B~anannas", 0))));
  1211.    dialog->insert(rb);
  1212.  
  1213.    dialog->insert(new TLabel(TRect(2, 7, 17, 8), "~R~adio buttons", rb));
  1214.  
  1215.    TStaticText *t;
  1216.    t = new TStaticText(TRect(2, 12, 31, 14), "\003This is a sample\n"
  1217.                                              "\003TStaticText view.");
  1218.    dialog->insert(t);
  1219.  
  1220.    TScrollBar *sb = new TScrollBar(TRect(64, 3, 65, 10));
  1221.    dialog->insert(sb);
  1222.  
  1223.    dialog->listbox = new TListBox(TRect(36, 3, 64, 10), 2, sb);
  1224.    dialog->insert(dialog->listbox);
  1225.  
  1226.    TStringCollection *strings;
  1227.    strings = new TStringCollection(20, 10);
  1228.  
  1229.    for(short ctr = 0; ctr < 20; ctr++)
  1230.       {
  1231.       short num = ctr + 1;
  1232.       char str[16];
  1233.       ostrstream os(str, sizeof str);
  1234.       os << "List item #" << num << ends;
  1235.       strings->atInsert(ctr, newStr(str));
  1236.       }
  1237.  
  1238.    dialog->listbox->newList(strings);
  1239.  
  1240.    dialog->insert(new TLabel(TRect(36, 2, 45, 3), "~L~istbox ",
  1241.                   dialog->listbox));
  1242.  
  1243.    TInputLine *i = new TInputLine(TRect(35, 13, 62, 14), 129);
  1244.    dialog->insert(i);
  1245.  
  1246.    THistory *h;
  1247.    h = new THistory(TRect(62, 13, 65, 14), i, 1);
  1248.    dialog->insert(h);
  1249.  
  1250.    dialog->insert(new TLabel(TRect(35, 12, 46, 13), "~T~InputLine", i));
  1251.  
  1252.    TButton *b;
  1253.    b = new TButton(TRect(4, 16, 22, 18), "Button ~1~", cmNone, bfNormal);
  1254.    dialog->insert(b);
  1255.  
  1256.    b = new TButton(TRect(24, 16, 43, 18), "Button ~2~", cmNone, bfNormal);
  1257.    dialog->insert(b);
  1258.  
  1259.    b = new TButton(TRect(45, 16, 63, 18), "~C~lose", cmCloseX, bfDefault);
  1260.    dialog->insert(b);
  1261.  
  1262.    dialog->selectNext(False);
  1263.  
  1264.    if(validView(dialog))
  1265.       deskTop->insert(dialog);
  1266. }
  1267.  
  1268.  
  1269. void TDemoApp::xdialog3()
  1270. {
  1271.    // Inserts a TXDialog3 dialog (see TDEMO2.CPP) into the desktop
  1272.    // to demonstrate the colors selected in TVColorDialog
  1273.  
  1274.    TXDialog3 *dialog;
  1275.    dialog = new TXDialog3(TRect(6, 2, 73, 21),
  1276.                           "Extended Palette TXDialog3");
  1277.  
  1278.    if(dialog == NULL)
  1279.       return;
  1280.  
  1281.    dialog->options |= ofCentered;
  1282.    dialog->helpCtx = hcXDialogs;
  1283.  
  1284.    TView *v;
  1285.    v = new TView(TRect(1, 2, 33, 6));
  1286.    v->options |= ofFramed;
  1287.    dialog->insert(v);
  1288.  
  1289.    v = new TView(TRect(1, 7, 33, 11));
  1290.    v->options |= ofFramed;
  1291.    dialog->insert(v);
  1292.  
  1293.    v = new TView(TRect(1, 12, 33, 14));
  1294.    v->options |= ofFramed;
  1295.    dialog->insert(v);
  1296.  
  1297.    v = new TView(TRect(34, 2, 66, 11));
  1298.    v->options |= ofFramed;
  1299.    dialog->insert(v);
  1300.  
  1301.    v = new TView(TRect(34, 12, 66, 14));
  1302.    v->options |= ofFramed;
  1303.    dialog->insert(v);
  1304.  
  1305.    TCheckBoxes *cb = new TCheckBoxes(TRect(2, 3, 31, 6),
  1306.                          new TSItem("~W~indows",
  1307.                          new TSItem("~U~nix",
  1308.                          new TSItem("~O~S/2", 0))));
  1309.    dialog->insert(cb);
  1310.  
  1311.    dialog->insert(new TLabel(TRect(2, 2, 14, 3), "~C~heckboxes", cb));
  1312.  
  1313.    TRadioButtons *rb = new TRadioButtons(TRect(2, 8, 31, 11),
  1314.                            new TSItem("~A~pples",
  1315.                            new TSItem("~O~ranges",
  1316.                            new TSItem("~B~anannas", 0))));
  1317.    dialog->insert(rb);
  1318.  
  1319.    dialog->insert(new TLabel(TRect(2, 7, 17, 8), "~R~adio buttons", rb));
  1320.  
  1321.    TStaticText *t;
  1322.    t = new TStaticText(TRect(2, 12, 31, 14), "\003This is a sample\n"
  1323.                                              "\003TStaticText view.");
  1324.    dialog->insert(t);
  1325.  
  1326.    TScrollBar *sb = new TScrollBar(TRect(64, 3, 65, 10));
  1327.    dialog->insert(sb);
  1328.  
  1329.    dialog->listbox = new TListBox(TRect(36, 3, 64, 10), 2, sb);
  1330.    dialog->insert(dialog->listbox);
  1331.  
  1332.    TStringCollection *strings;
  1333.    strings = new TStringCollection(20, 10);
  1334.  
  1335.    for(short ctr = 0; ctr < 20; ctr++)
  1336.       {
  1337.       short num = ctr + 1;
  1338.       char str[16];
  1339.       ostrstream os(str, sizeof str);
  1340.       os << "List item #" << num << ends;
  1341.       strings->atInsert(ctr, newStr(str));
  1342.       }
  1343.  
  1344.    dialog->listbox->newList(strings);
  1345.  
  1346.    dialog->insert(new TLabel(TRect(36, 2, 45, 3), "~L~istbox ",
  1347.                   dialog->listbox));
  1348.  
  1349.    TInputLine *i = new TInputLine(TRect(35, 13, 62, 14), 129);
  1350.    dialog->insert(i);
  1351.  
  1352.    THistory *h;
  1353.    h = new THistory(TRect(62, 13, 65, 14), i, 1);
  1354.    dialog->insert(h);
  1355.  
  1356.    dialog->insert(new TLabel(TRect(35, 12, 46, 13), "~T~InputLine", i));
  1357.  
  1358.    TButton *b;
  1359.    b = new TButton(TRect(4, 16, 22, 18), "Button ~1~", cmNone, bfNormal);
  1360.    dialog->insert(b);
  1361.  
  1362.    b = new TButton(TRect(24, 16, 43, 18), "Button ~2~", cmNone, bfNormal);
  1363.    dialog->insert(b);
  1364.  
  1365.    b = new TButton(TRect(45, 16, 63, 18), "~C~lose", cmCloseX, bfDefault);
  1366.    dialog->insert(b);
  1367.  
  1368.    dialog->selectNext(False);
  1369.  
  1370.    if(validView(dialog))
  1371.       deskTop->insert(dialog);
  1372. }
  1373.  
  1374.  
  1375. void TDemoApp::helpDialog()
  1376. {
  1377.    // Displays a dialog to demonstrate that the help button in
  1378.    // TVColorDialog was pressed. There is currently no help file
  1379.    // in the demonstration program. Soon, we hope! <G>
  1380.  
  1381.    TDialog *dialog;
  1382.    dialog = new TDialog(TRect(13, 6, 66, 17),
  1383.                         "TVColorDialog help button information");
  1384.  
  1385.    if(dialog == NULL)
  1386.       return;
  1387.  
  1388.    dialog->options |= ofCentered;
  1389.  
  1390.    TStaticText *t;
  1391.    t = new TStaticText(TRect(3, 2, 50, 3),
  1392.                        "The help button in TVColorDialog sends a cmHelp");
  1393.    dialog->insert(t);
  1394.  
  1395.    t = new TStaticText(TRect(3, 3, 50, 4),
  1396.                        "command to the application. Unfortunately there");
  1397.    dialog->insert(t);
  1398.  
  1399.    t = new TStaticText(TRect(3, 4, 50, 5),
  1400.                        "is no help file available in this demonstration");
  1401.    dialog->insert(t);
  1402.  
  1403.    t = new TStaticText(TRect(3, 5, 15, 6), "application.");
  1404.    dialog->insert(t);
  1405.  
  1406.    TButton *b;
  1407.    b = new TButton(TRect(11, 8, 41, 10), "~O~k", cmOK, bfDefault);
  1408.    b->options |= ofCenterX;
  1409.    dialog->insert(b);
  1410.  
  1411.    if(validView(dialog))
  1412.       {
  1413.       deskTop->execView(dialog);
  1414.       TObject::destroy((TDialog *) dialog);
  1415.       }
  1416. }
  1417.  
  1418.  
  1419.  
  1420.  
  1421.  
  1422. // Non-member function definitions ****************************************
  1423.  
  1424. void exitfunc(void)
  1425. {
  1426.    // Prints an exit message
  1427.  
  1428.    cout << endl
  1429.         << endl
  1430.         << "┌────────────────────────────────────────────┐" << endl
  1431.         << "│  Thank you for testing TVColorDialog!      │" << endl
  1432.         << "├────────────────────────────────────────────┤" << endl
  1433.         << "│  TVColorDialog shareware version "
  1434.         << colorDlgVerStr
  1435.         << "       │" << endl
  1436.         << "│  Copyright (C) 1992,1993 Comsoft Software  │" << endl
  1437.         << "│  All rights reserved.                      │" << endl
  1438.         << "└────────────────────────────────────────────┘" << endl
  1439.         << ends;
  1440. }
  1441.  
  1442.  
  1443. #pragma exit exitfunc 31          // Register exitfunc
  1444.  
  1445.  
  1446. int main()
  1447. {
  1448.    TDemoApp *program = new TDemoApp();
  1449.  
  1450.    if(!program->valid(cmValid))
  1451.       {
  1452.       TObject::destroy((TDemoApp *) program);
  1453.       return 2;
  1454.       }
  1455.  
  1456.    program->run();
  1457.    TObject::destroy((TDemoApp *) program);
  1458.  
  1459.    return 0;
  1460. }
  1461.  
  1462.  
  1463. //                                End of TDEMO.CPP
  1464.  
  1465.