home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / krcls012.zip / KrClass / source / krwc.cpp < prev   
Text File  |  1997-02-23  |  21KB  |  892 lines

  1. // Kroni's Classes: objects for  user communication using window
  2. // (c) 1997 Wolfgang Kronberg
  3. // file: krwc.cpp
  4.  
  5.  
  6. #include "krwc.hpp"
  7. #include "krprof.hpp"
  8.  
  9. #include <os2.h>                                 // WM_* messages
  10.  
  11. #include <limits.h>                              // To test for valid integer numbers
  12.  
  13. #include <istattxt.hpp>                          // IStaticText
  14. #include <ientryfd.hpp>                          // IEntryField
  15. #include <ipushbut.hpp>                          // IPushButton
  16. #include <icmdhdr.hpp>                           // ICommandHandler
  17. #include <iradiobt.hpp>                          // IRadioButton
  18. #include <icheckbx.hpp>                          // ICheckBox
  19.  
  20.  
  21.  
  22. int const & key (_KrChoiceDataEntry const & t)
  23. {
  24.   return t.id;
  25. };
  26.  
  27.  
  28. int const & key (_KrBitfieldDataEntry const & t)
  29. {
  30.   return t.id;
  31. };
  32.  
  33.  
  34. int const & key (_KrWinCommDataField const & t)
  35. {
  36.   return t.id;
  37. };
  38.  
  39.  
  40. #define _KrWcOk 0x1ffe                           // ID for OK button in the KrWinComm dialog
  41. #define _KrWcCancel 0x1ffd                       // ID for cancel button in the KrWinComm dialog
  42.  
  43.  
  44. class _KrWcHandler : public ICommandHandler
  45. {
  46.  
  47. public:
  48.  
  49.   _KrWcHandler (IWindow * win, KrWinComm * wc) : ICommandHandler () {window = win; winComm = wc;};
  50.                                                  // win: Dialog Window
  51.   virtual Boolean command (ICommandEvent & event);
  52.  
  53. private:
  54.  
  55.   IWindow * window;
  56.   KrWinComm * winComm;
  57.  
  58. };
  59.  
  60.  
  61. Boolean _KrWcHandler::command (ICommandEvent & event)
  62. {
  63.   KrWinCommData::Cursor cursor (winComm->data);
  64.   winComm -> errorOccurred = false;
  65.   winComm -> okPressed = false;
  66.  
  67.   switch (event.commandId ())
  68.      {
  69.      case _KrWcOk:
  70.         if (winComm->data.setToFirst(cursor))
  71.            {
  72.            do
  73.               {
  74.               if (winComm->data.elementAt(cursor).translator (
  75.                     true, winComm->data.elementAt(cursor).data, winComm->data.elementAt(cursor).window
  76.                   )
  77.                  )
  78.                  winComm -> errorOccurred = true;
  79.               }
  80.            while (winComm->data.setToNext(cursor));
  81.            };
  82.  
  83.         window -> postEvent(WM_CLOSE,0,0);
  84.         winComm -> okPressed = true;
  85.         window -> postEvent(WM_CLOSE,0,0);
  86.         return true;
  87.  
  88.      case _KrWcCancel:
  89.         window -> postEvent(WM_CLOSE,0,0);
  90.         return true;
  91.  
  92.      default:
  93.         return false;
  94.      }
  95. };
  96.  
  97.  
  98.  
  99. KrChoice::KrChoice ()
  100. {
  101.   active = 0;
  102. };
  103.  
  104.  
  105. KrChoice::KrChoice (const KrChoiceData & aData)
  106. {
  107.   data = aData;
  108.   active = 0;
  109. };
  110.  
  111.  
  112. int KrChoice::add (int id, const IString & newChoice)
  113. {
  114.   if (data.containsElementWithKey(id))
  115.      return 0;
  116.   else
  117.      {
  118.      data.addOrReplaceElementWithKey (_KrChoiceDataEntry(id,newChoice));
  119.      return id;
  120.      };
  121. };
  122.  
  123.  
  124. int KrChoice::add (const IString & newChoice)
  125. {
  126.   int id = nextFree ();
  127.   data.addOrReplaceElementWithKey (_KrChoiceDataEntry(id,newChoice));
  128.   return id;
  129. };
  130.  
  131.  
  132. void KrChoice::set (int id)
  133. {
  134.   active = id;
  135. };
  136.  
  137.  
  138. int KrChoice:: get ()
  139. {
  140.   return active;
  141. };
  142.  
  143.  
  144. int KrChoice::numberOfEntries ()
  145. {
  146.   return data.numberOfElements ();
  147. };
  148.  
  149.  
  150. int KrChoice::getFirstKey ()
  151. {
  152.   return data.key(data.firstElement());
  153. };
  154.  
  155.  
  156. int KrChoice::getNextKey (int id)
  157. {
  158.   KrChoiceData::Cursor cursor (data);
  159.   data.locateElementWithKey (id, cursor);
  160.   if (!data.isLast(cursor))
  161.      data.setToNext (cursor);
  162.   return data.key(data.elementAt(cursor));
  163. };
  164.  
  165.  
  166. IString & KrChoice::getText (int id)
  167. {
  168.   return data.elementWithKey(id).text;
  169. };
  170.  
  171.  
  172. int KrChoice::nextFree ()
  173. {
  174.   if (data.isEmpty())
  175.      return 1;
  176.   else
  177.      return data.key (data.lastElement()) + 1;
  178. };
  179.  
  180.  
  181.  
  182. KrBitfield::KrBitfield (const KrBitfieldData & aData)
  183. {
  184.   data = aData;
  185. };
  186.  
  187.  
  188. int KrBitfield::add (int id, const IString & newEntry, Boolean checked)
  189. {
  190.   if (data.containsElementWithKey(id))
  191.      return 0;
  192.   else
  193.      {
  194.      data.addOrReplaceElementWithKey (_KrBitfieldDataEntry(id,newEntry,checked));
  195.      return id;
  196.      };
  197. };
  198.  
  199.  
  200. int KrBitfield::add (const IString & newEntry, Boolean checked)
  201. {
  202.   int id = nextFree ();
  203.   data.addOrReplaceElementWithKey (_KrBitfieldDataEntry(id,newEntry,checked));
  204.   return id;
  205. };
  206.  
  207.  
  208. int KrBitfield::numberOfEntries ()
  209. {
  210.   return data.numberOfElements ();
  211. };
  212.  
  213.  
  214. Boolean KrBitfield::toggle (int id, Boolean check)
  215. {
  216.   return data.elementWithKey(id).chosen = check;
  217. };
  218.  
  219.  
  220. Boolean KrBitfield::toggle (int id)
  221. {
  222.   return data.elementWithKey(id).chosen = ! isChecked (id);
  223. };
  224.  
  225.  
  226. Boolean KrBitfield::isChecked (int id)
  227. {
  228.   return data.elementWithKey(id).chosen;
  229. };
  230.  
  231.  
  232. int KrBitfield::getFirstKey ()
  233. {
  234.   return data.key(data.firstElement());
  235. };
  236.  
  237.  
  238. int KrBitfield::getNextKey (int id)
  239. {
  240.   KrBitfieldData::Cursor cursor (data);
  241.   data.locateElementWithKey (id, cursor);
  242.   if (!data.isLast(cursor))
  243.      data.setToNext (cursor);
  244.   return data.key(data.elementAt(cursor));
  245. };
  246.  
  247.  
  248. IString & KrBitfield::getText (int id)
  249. {
  250.   return data.elementWithKey(id).text;
  251. };
  252.  
  253.  
  254. int KrBitfield::nextFree ()
  255. {
  256.   if (data.isEmpty())
  257.      return 1;
  258.   else
  259.      return data.key (data.lastElement()) + 1;
  260. };
  261.  
  262.  
  263.  
  264. KrWinComm::KrWinComm (const IString & aTitle)
  265. {
  266.   currentLine = 2;
  267.   currentLabel = "";
  268.   buttons = 0;
  269.   callWinInit = true;
  270.   titleName = aTitle;
  271.   exitList = 0;
  272.   font = IFont ("WarpSans",9);
  273. };
  274.  
  275.  
  276. KrWinComm::~KrWinComm ()
  277. {
  278.   data.removeAll();
  279.  
  280.   typeExitList * el, * el2;
  281.   el = exitList;
  282.   while (el) {
  283.      el2 = el->next;
  284.      delete el->entry;
  285.      delete el;
  286.      el = el2;
  287.      };
  288.   exitList = 0;
  289. };
  290.  
  291.  
  292. void KrWinComm::winInit ()
  293. {
  294.   callWinInit = false;
  295.   frame = new IFrameWindow (titleName,0x1000);
  296.   title = new ITitle (frame, titleName);
  297.   canvas = new IMultiCellCanvas (IC_FRAME_CLIENT_ID,frame,frame);
  298.   KrProfile profile ("PM_Colors");
  299.   profile.setKey ("DialogBackground");
  300.   IString r,g,b;
  301.   profile >> r >> g >> b;
  302.   canvas -> setBackgroundColor (IColor(r.asInt(),g.asInt(),b.asInt()));
  303.   canvas->setFont (font);
  304.   canvas->setColumnWidth (1,0,true);
  305.   canvas->setColumnWidth (6,0,true);
  306.   canvas->setRowHeight (1,0,true);
  307. }
  308.  
  309.  
  310. void KrWinComm::setNextPrompt (const IString & title)
  311. {
  312.   currentLabel = title;
  313. };
  314.  
  315.  
  316. void KrWinComm::addToNextPrompt (const IString & title)
  317. {
  318.   currentLabel += title;
  319. };
  320.  
  321.  
  322. void KrWinComm::setTitle (const IString & aTitle)
  323. {
  324.   titleName = aTitle;
  325.   if (!callWinInit)
  326.      title->setText (aTitle);
  327. };
  328.  
  329.  
  330. void KrWinComm::setFont (const IFont & aFont)
  331. {
  332.   font = aFont;
  333.   if (!callWinInit)
  334.      canvas->setFont (font);
  335. };
  336.  
  337.  
  338. int KrWinComm::nextFree ()
  339. {
  340.   if (data.isEmpty())
  341.      return 1;
  342.   else
  343.      return data.key (data.lastElement()) + 1;
  344. };
  345.  
  346.  
  347. void KrWinComm::addEntryField (IString & s)
  348. {
  349.   if (callWinInit)
  350.      winInit ();
  351.  
  352.   IEntryField * entryField = new IEntryField (0x1000 + 0x40 * currentLine, canvas, canvas);
  353.   entryField -> setAutoDeleteObject();
  354.   entryField -> setText(s).enableTabStop();
  355.  
  356.   data.addOrReplaceElementWithKey (
  357.     _KrWinCommDataField (
  358.       nextFree(), IString (currentLabel), &s, entryField, translateString
  359.     )
  360.   );
  361.  
  362.   IStaticText * text = new IStaticText (0x1ff0 - currentLine, canvas, canvas);
  363.   text -> setAutoDeleteObject ();
  364.   text -> setText (currentLabel);
  365.   canvas -> addToCell (text, 3, currentLine);
  366.   canvas -> addToCell (entryField, 4, currentLine);
  367.   canvas -> setRowHeight (++currentLine, 2, true);
  368.  
  369.   currentLabel = "";
  370.   currentLine++;
  371. };
  372.  
  373.  
  374. void KrWinComm::addEntryField (double & d)
  375. {
  376.   if (callWinInit)
  377.      winInit ();
  378.  
  379.   IEntryField * entryField = new IEntryField (0x1000 + 0x40 * currentLine, canvas, canvas);
  380.   entryField -> setAutoDeleteObject ();
  381.   entryField -> setText (IString(d)).enableTabStop();
  382.  
  383.   data.addOrReplaceElementWithKey (
  384.     _KrWinCommDataField (
  385.       nextFree(), IString (currentLabel), &d, entryField, translateDouble
  386.     )
  387.   );
  388.  
  389.   IStaticText * text = new IStaticText (0x1ff0 - currentLine, canvas, canvas);
  390.   text -> setAutoDeleteObject ();
  391.   text -> setText (currentLabel);
  392.   canvas -> addToCell (text, 3, currentLine);
  393.   canvas -> addToCell (entryField, 4, currentLine);
  394.   canvas -> setRowHeight (++currentLine, 2, true);
  395.  
  396.   currentLabel = "";
  397.   currentLine++;
  398. };
  399.  
  400.  
  401. void KrWinComm::addEntryField (unsigned long & l)
  402. {
  403.   if (callWinInit)
  404.      winInit ();
  405.  
  406.   IEntryField * entryField = new IEntryField (0x1000 + 0x40 * currentLine, canvas, canvas);
  407.   entryField -> setAutoDeleteObject ();
  408.   entryField -> setText (IString(l)).enableTabStop();
  409.  
  410.   data.addOrReplaceElementWithKey (
  411.     _KrWinCommDataField (
  412.       nextFree(), IString (currentLabel), &l, entryField, translateUnsignedLong
  413.     )
  414.   );
  415.  
  416.   IStaticText * text = new IStaticText (0x1ff0 - currentLine, canvas, canvas);
  417.   text -> setAutoDeleteObject ();
  418.   text -> setText (currentLabel);
  419.   canvas -> addToCell (text, 3, currentLine);
  420.   canvas -> addToCell (entryField, 4, currentLine);
  421.   canvas -> setRowHeight (++currentLine, 2, true);
  422.  
  423.   currentLabel = "";
  424.   currentLine++;
  425. };
  426.  
  427.  
  428. void KrWinComm::addEntryField (signed long & l)
  429. {
  430.   if (callWinInit)
  431.      winInit ();
  432.  
  433.   IEntryField * entryField = new IEntryField (0x1000 + 0x40 * currentLine, canvas, canvas);
  434.   entryField -> setAutoDeleteObject ();
  435.   entryField -> setText (IString(l)).enableTabStop();
  436.  
  437.   data.addOrReplaceElementWithKey (
  438.     _KrWinCommDataField (
  439.       nextFree(), IString (currentLabel), &l, entryField, translateSignedLong
  440.     )
  441.   );
  442.  
  443.   IStaticText * text = new IStaticText (0x1ff0 - currentLine, canvas, canvas);
  444.   text -> setAutoDeleteObject ();
  445.   text -> setText (currentLabel);
  446.   canvas -> addToCell (text, 3, currentLine);
  447.   canvas -> addToCell (entryField, 4, currentLine);
  448.   canvas -> setRowHeight (++currentLine, 2, true);
  449.  
  450.   currentLabel = "";
  451.   currentLine++;
  452. };
  453.  
  454.  
  455. void KrWinComm::addEntryField (KrBitfield & b)
  456. {
  457.   if (callWinInit)
  458.      winInit ();
  459.  
  460.   IMultiCellCanvas * bitfieldCanvas = new IMultiCellCanvas
  461.      (0x1000 + 0x40 * currentLine, canvas, canvas);
  462.   bitfieldCanvas -> setAutoDeleteObject ();
  463.  
  464.   data.addOrReplaceElementWithKey (
  465.     _KrWinCommDataField (
  466.       nextFree(), IString (currentLabel), &b, bitfieldCanvas, translateBitfield
  467.     )
  468.   );
  469.  
  470.   int i;
  471.   int n = b.numberOfEntries ();
  472.   int key = b.getFirstKey ();
  473.   for (i=0; i<n; i++)
  474.      {
  475.      ICheckBox * checkBox;
  476.  
  477.      checkBox = new ICheckBox (0x1000+i, bitfieldCanvas, bitfieldCanvas);
  478.      checkBox -> setAutoDeleteObject ();
  479.      if (b.isChecked (key))
  480.         checkBox -> select ();
  481.      checkBox -> setText (b.getText (key)).enableTabStop();
  482.      bitfieldCanvas -> addToCell (checkBox,1,i+1);
  483.  
  484.      key = b.getNextKey (key);
  485.      }
  486.  
  487.   IStaticText * text = new IStaticText (0x1ff0 - currentLine, canvas, canvas);
  488.   text -> setAutoDeleteObject ();
  489.   text -> setText (currentLabel);
  490.   canvas -> addToCell (text, 3, currentLine);
  491.   canvas -> addToCell (bitfieldCanvas, 4, currentLine);
  492.   canvas -> setRowHeight (++currentLine, 2, true);
  493.  
  494.   currentLabel = "";
  495.   currentLine++;
  496.  
  497. };
  498.  
  499.  
  500. void KrWinComm::addEntryField (KrChoice & c)
  501. {
  502.   if (callWinInit)
  503.      winInit ();
  504.  
  505.   IMultiCellCanvas * choiceCanvas = new IMultiCellCanvas
  506.      (0x1000 + 0x40 * currentLine, canvas, canvas);
  507.   choiceCanvas -> setAutoDeleteObject ();
  508.  
  509.   data.addOrReplaceElementWithKey (
  510.     _KrWinCommDataField (
  511.       nextFree(), IString (currentLabel), &c, choiceCanvas, translateChoice
  512.     )
  513.   );
  514.  
  515.   int i;
  516.   int n = c.numberOfEntries ();
  517.   int key = c.getFirstKey ();
  518.   for (i=0; i<n; i++)
  519.      {
  520.      IRadioButton * radio;
  521.  
  522.      radio = new IRadioButton (0x1000+i, choiceCanvas, choiceCanvas);
  523.      radio -> setAutoDeleteObject ();
  524.      if (key == c.get())
  525.         radio -> select ();
  526.      radio -> setText (c.getText (key));
  527.      choiceCanvas -> addToCell (radio,1,i+1);
  528.  
  529.      key = c.getNextKey (key);
  530.      }
  531.  
  532.   IStaticText * text = new IStaticText (0x1ff0 - currentLine, canvas, canvas);
  533.   text -> setAutoDeleteObject ();
  534.   text -> setText (currentLabel);
  535.   canvas -> addToCell (text, 3, currentLine);
  536.   canvas -> addToCell (choiceCanvas, 4, currentLine);
  537.   canvas -> setRowHeight (++currentLine, 2, true);
  538.  
  539.   currentLabel = "";
  540.   currentLine++;
  541.  
  542. };
  543.  
  544.  
  545. void KrWinComm::addEntryField (KrUserDataField * f)
  546. {
  547.   if (callWinInit)
  548.      winInit ();
  549.  
  550.   IStaticText * text = new IStaticText (0x1ff0 - currentLine, canvas, canvas);
  551.   text -> setAutoDeleteObject ();
  552.   text -> setText (currentLabel);
  553.   currentLabel = "";
  554.   canvas -> addToCell (text, 3, currentLine);
  555.  
  556.   currentLine = f->initialize (*canvas, currentLine);
  557.  
  558.   data.addOrReplaceElementWithKey (
  559.     _KrWinCommDataField (
  560.       nextFree(),
  561.       IString (currentLabel),
  562.       f,
  563.       0,                                         // We don't need the KrUserDataField's window here
  564.       translateUserData
  565.     )
  566.   );
  567.  
  568.   canvas -> setRowHeight (++currentLine, 2, true);
  569.  
  570.   typeExitList * el;
  571.   el = exitList;
  572.   if (el) {
  573.      while (el->next) el = el->next;
  574.      el->next = new typeExitList;
  575.      el = el->next;
  576.      }
  577.   else el = new typeExitList;
  578.   el->entry = f;
  579.   el->next = 0;
  580. };
  581.  
  582.  
  583. void KrWinComm::addEntryField (KrUserDataField & f)
  584. {
  585.   if (callWinInit)
  586.      winInit ();
  587.  
  588.   IStaticText * text = new IStaticText (0x1ff0 - currentLine, canvas, canvas);
  589.   text -> setAutoDeleteObject ();
  590.   text -> setText (currentLabel);
  591.   currentLabel = "";
  592.   canvas -> addToCell (text, 3, currentLine);
  593.  
  594.   currentLine = f.initialize (*canvas, currentLine);
  595.  
  596.   data.addOrReplaceElementWithKey (
  597.     _KrWinCommDataField (
  598.       nextFree(),
  599.       IString (currentLabel),
  600.       &f,
  601.       0,                                         // We don't need the KrUserDataField's window here
  602.       translateUserData
  603.     )
  604.   );
  605.  
  606.   canvas -> setRowHeight (++currentLine, 2, true);
  607. };
  608.  
  609.  
  610. Boolean KrWinComm::run ()
  611. {
  612.   if (callWinInit)
  613.      winInit ();
  614.  
  615.   if (!buttons)
  616.      {
  617.      buttons = new IMultiCellCanvas (0x1fff, canvas, canvas);
  618.      buttons -> setAutoDeleteObject ();
  619.      IPushButton * ok = new IPushButton (
  620.                               _KrWcOk, buttons, buttons, IRectangle(),
  621.                               IPushButton::defaultStyle() | IPushButton::defaultButton
  622.                             );
  623.      IPushButton * cancel = new IPushButton (_KrWcCancel, buttons, buttons);
  624.      ok -> setAutoDeleteObject ();
  625.      cancel -> setAutoDeleteObject ();
  626.      ok -> setText ("Ok");
  627.      cancel -> setText ("Cancel");
  628.      buttons -> addToCell (ok,2,2);
  629.      buttons -> addToCell (cancel,4,2);
  630.      buttons -> setColumnWidth (1,2,true);
  631.      buttons -> setColumnWidth (3,2,true);
  632.      buttons -> setColumnWidth (5,2,true);
  633.      buttons -> setRowHeight (1,2,true);
  634.      buttons -> setRowHeight (3,2,true);
  635.      canvas -> addToCell (buttons,3,currentLine,2,1);
  636.      canvas -> setRowHeight (++currentLine, 2, true);
  637.      currentLine++;
  638.      };
  639.  
  640.   ISize size = canvas -> minimumSize (true);
  641.  
  642.   IRectangle sizeFrame = frame -> frameRectFor (IRectangle(IPoint(0,0),IPoint(size.width(),size.height())));
  643.   size.setWidth (sizeFrame.width());
  644.   size.setHeight (sizeFrame.height());
  645.   size.setWidth (size.width()+8);                // 4 pixels extra width per flexible cell
  646.   int numFlex = 0;
  647.   int i;
  648.   for (i=1; i<currentLine; i++)
  649.      if (canvas -> isRowExpandable (i))
  650.         numFlex++;
  651.   numFlex *= 4;
  652.   size.setHeight (size.height()+numFlex);
  653.   frame->sizeTo (size);
  654.  
  655.   _KrWcHandler * handler;
  656.   handler = new _KrWcHandler (frame,this);
  657.   handler->handleEventsFor (frame);
  658.  
  659.   frame -> setFocus ();
  660.   frame -> show ();
  661.   IApplication::current().run();
  662.  
  663.   delete canvas;
  664.   delete title;
  665.   delete frame;
  666.   delete handler;
  667.   currentLine = 2;
  668.   buttons = 0;
  669.   data.removeAll();
  670.   callWinInit = true;
  671.  
  672.   typeExitList * el, * el2;
  673.   el = exitList;
  674.   while (el) {
  675.      el2 = el->next;
  676.      delete el->entry;
  677.      delete el;
  678.      el = el2;
  679.      };
  680.   exitList = 0;
  681.  
  682.   return okPressed;
  683. };
  684.  
  685.  
  686. Boolean KrWinComm::ok ()
  687. {
  688.   return okPressed;
  689. };
  690.  
  691.  
  692. Boolean KrWinComm::translateString (Boolean doIt, void * data, void * window)
  693. {
  694.   IString s = ((IEntryField*)(window)) -> text ();
  695.   if (doIt)
  696.      (*(IString*)(data)) = s;
  697.   return true;                                   // No error possible
  698. };
  699.  
  700.  
  701. Boolean KrWinComm::translateDouble (Boolean doIt, void * data, void * window)
  702. {
  703.   IString s = ((IEntryField*)(window)) -> text ();
  704.   if (s.occurrencesOf (".") > 1)                 // More than one decimal point?
  705.      return false;
  706.   IString t = s;
  707.   if (t.includes ('.'))
  708.      t.remove (t.indexOf ('.'),1);               // t is s without any point
  709.   t.stripLeading (' ');
  710.   t.stripLeading ("-");
  711.   t.stripLeading ("+");
  712.   t.stripLeading (' ');                          // The detection is not perfect, but should be enough.
  713.   if ( ! t.isDigits() )
  714.      return false;                               // t is not a valid number
  715.  
  716.   if (doIt)
  717.      (*(double*)(data)) = s.asDouble();
  718.   return true;                                   // No more error possible
  719. };
  720.  
  721.  
  722. Boolean KrWinComm::translateSignedLong (Boolean doIt, void * data, void * window)
  723. {
  724.   IString s = ((IEntryField*)(window)) -> text ();
  725.   IString t = s;
  726.   t.stripLeading (' ');
  727.   t.stripLeading ("-");
  728.   t.stripLeading ("+");
  729.   t.stripLeading (' ');                          // The detection is not perfect, but should be enough.
  730.   if ( ! t.isDigits() )
  731.      return false;                               // t is not a valid integer number
  732.   double d = s.asDouble();
  733.   if ((d<LONG_MIN) || (d>LONG_MAX))
  734.      return false;                               // Number too big
  735.  
  736.   if (doIt)
  737.      (*(signed long*)(data)) = d;
  738.   return true;                                   // No more error possible
  739. };
  740.  
  741.  
  742. Boolean KrWinComm::translateUnsignedLong (Boolean doIt, void * data, void * window)
  743. {
  744.   IString s = ((IEntryField*)(window)) -> text ();
  745.   IString t = s;
  746.   t.stripLeading (' ');
  747.   t.stripLeading ("+");
  748.   t.stripLeading (' ');
  749.   if ( ! t.isDigits() )
  750.      return false;                               // t is not a valid nonnegative integer number
  751.   double d = s.asDouble();
  752.   if (d>ULONG_MAX)
  753.      return false;                               // Number too big
  754.  
  755.   if (doIt)
  756.      (*(unsigned long*)(data)) = d;
  757.   return true;                                   // No more error possible
  758. };
  759.  
  760.  
  761. Boolean KrWinComm::translateBitfield (Boolean doIt, void * data, void * window)
  762. {
  763.   if (!doIt)
  764.      return true;                                // No error possible
  765.  
  766.   KrBitfield * bitfield = (KrBitfield*)(data);
  767.   IMultiCellCanvas * canvas = (IMultiCellCanvas*)(window);
  768.  
  769.   int i;
  770.   int n = bitfield -> numberOfEntries ();
  771.   int key = bitfield -> getFirstKey ();
  772.   for (i=0; i<n; i++)
  773.      {
  774.      bitfield -> toggle (key, ((ICheckBox*)(canvas -> windowInCell (1,i+1))) -> isSelected () );
  775.      key = bitfield -> getNextKey (key);
  776.      }
  777.  
  778.   return true;
  779. };
  780.  
  781.  
  782. Boolean KrWinComm::translateChoice (Boolean doIt, void * data, void * window)
  783. {
  784.   if (!doIt)
  785.      return true;                                // No error possible
  786.  
  787.   KrChoice * choice = (KrChoice*)(data);
  788.   IMultiCellCanvas * canvas = (IMultiCellCanvas*)(window);
  789.  
  790.   int i;
  791.   int n = choice -> numberOfEntries ();
  792.   int key = choice -> getFirstKey ();
  793.   for (i=0; i<n; i++)
  794.      {
  795.      if ( ((IRadioButton*)(canvas -> windowInCell (1,i+1))) -> isSelected () )
  796.         choice -> set (key);
  797.      key = choice -> getNextKey (key);
  798.      }
  799.  
  800.   return true;
  801. };
  802.  
  803.  
  804. Boolean KrWinComm::translateUserData (Boolean doIt, void * data, void * window)
  805. {
  806.   return ((KrUserDataField*)(data)) -> transform (doIt);
  807. }
  808.  
  809.  
  810.  
  811. KrWinComm & operator << (KrWinComm & aWinComm, const IString & aString)
  812. {
  813.   aWinComm.addToNextPrompt (aString);
  814.   return aWinComm;
  815. };
  816.  
  817.  
  818. KrWinComm & operator >> (KrWinComm & aWinComm, IString & aString)
  819. {
  820.   aWinComm.addEntryField (aString);
  821.   return aWinComm;
  822. };
  823.  
  824.  
  825. KrWinComm & operator >> (KrWinComm & aWinComm, double & aDouble)
  826. {
  827.   aWinComm.addEntryField (aDouble);
  828.   return aWinComm;
  829. };
  830.  
  831.  
  832. KrWinComm & operator >> (KrWinComm & aWinComm, unsigned long & aUnsigned)
  833. {
  834.   aWinComm.addEntryField (aUnsigned);
  835.   return aWinComm;
  836. };
  837.  
  838.  
  839. KrWinComm & operator >> (KrWinComm & aWinComm, signed long & aSigned)
  840. {
  841.   aWinComm.addEntryField (aSigned);
  842.   return aWinComm;
  843. };
  844.  
  845.  
  846. KrWinComm & operator >> (KrWinComm & aWinComm, KrBitfield & aBitfield)
  847. {
  848.   aWinComm.addEntryField (aBitfield);
  849.   return aWinComm;
  850. };
  851.  
  852.  
  853. KrWinComm & operator >> (KrWinComm & aWinComm, KrChoice & aChoice)
  854. {
  855.   aWinComm.addEntryField (aChoice);
  856.   return aWinComm;
  857. };
  858.  
  859.  
  860. KrWinComm & operator >> (KrWinComm & aWinComm, KrUserDataField & aUserData)
  861. {
  862.   aWinComm.addEntryField (aUserData);
  863.   return aWinComm;
  864. };
  865.  
  866.  
  867. KrWinComm & operator >> (KrWinComm & aWinComm, KrUserDataField * aUserData)
  868. {
  869.   aWinComm.addEntryField (aUserData);
  870.   return aWinComm;
  871. };
  872.  
  873.  
  874. KrWinComm & operator >> (KrWinComm & aWinComm, KrWinComm & (*f) (KrWinComm&) )
  875. {
  876.   return f (aWinComm);
  877. };
  878.  
  879.  
  880. KrWinComm & operator << (KrWinComm & aWinComm, KrWinComm & (*f) (KrWinComm&) )
  881. {
  882.   return f (aWinComm);
  883. };
  884.  
  885.  
  886. KrWinComm & display (KrWinComm & aWinComm)
  887. {
  888.   aWinComm.run();
  889.   return aWinComm;
  890. };
  891.  
  892.