home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / som / somk / c / tp / colblk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-24  |  5.8 KB  |  210 lines

  1.  
  2. /*
  3.  *  This file was generated by the SOM Compiler.
  4.  *  Generated using:
  5.  *     SOM incremental update: 10.9
  6.  */
  7.  
  8.  
  9. #ifndef lint
  10. static char *sccsid = "%Z% %I% %W% %G% %U% [%H% %T%] (c)IBM Corp. 1992";
  11. #endif
  12.  
  13. /*
  14.  * This class is adapted from the book
  15.  *   Class Construction in C and C++, Object Oriented Fundamentals
  16.  *   by Roger Sessions, Copyright (c) 1992 Prentice Hall.
  17.  * Reprinted with permission.
  18.  */
  19.  
  20. #define columnBlock_Class_Source
  21. #if defined(_WIN32)
  22. #include "statcls.h"
  23. #endif
  24. #include "colblk.ih"
  25. #include "textline.h"
  26.  
  27. #define SPACE_BETWEEN 3
  28. #define HEADER_SPACE 3
  29. #define FOOTER_SPACE 3
  30.  
  31. /* ************************************************************ */
  32. /*
  33.  *    Initialize a new columnBlock.
  34.  */
  35.  
  36. SOM_Scope void  SOMLINK cbInit(columnBlock *somSelf,
  37.         long newColumns,
  38.         long newHeight,
  39.         long newWidth)
  40. {
  41.     columnBlockData *somThis = columnBlockGetData(somSelf);
  42.     int n;
  43.     linkedList *newBlock;
  44.     columnBlockMethodDebug("columnBlock", "cbInit");
  45.  
  46.     _columnWidth = newWidth - ((newColumns - 1) * SPACE_BETWEEN);
  47.     _columnWidth = _columnWidth / newColumns;
  48.  
  49.     _llSetMax(somSelf, newColumns);
  50.     for (n = 0; n < newColumns; n++) {
  51.     newBlock = linkedListNew();
  52.     _llSetMax(newBlock, newHeight - HEADER_SPACE - FOOTER_SPACE);
  53.     parent_llAddTail(somSelf, (baseType *) newBlock);
  54.     }
  55.     _llHead(somSelf);
  56. }
  57.  
  58. /* ************************************************************ */
  59. /*
  60.  *   Returns the width of a column (in characters).
  61.  */
  62.  
  63. SOM_Scope long  SOMLINK cbGetColumnWidth(columnBlock *somSelf)
  64. {
  65.     columnBlockData *somThis = columnBlockGetData(somSelf);
  66.     columnBlockMethodDebug("columnBlock", "cbGetColumnWidth");
  67.     return _columnWidth;
  68. }
  69.  
  70. /* ************************************************************ */
  71. /*
  72.  *   Returns TRUE if there is room for at least one more
  73.  *   line in the columnBlock, FALSE otherwise.
  74.  */
  75.  
  76. SOM_Scope long  SOMLINK cbLinesLeft(columnBlock *somSelf)
  77. {
  78.     columnBlockData *somThis = columnBlockGetData(somSelf);
  79.     linkedList *thisBlock;
  80.     columnBlockMethodDebug("columnBlock", "cbLinesLeft");
  81.  
  82.     thisBlock = (linkedList *) _llRetrieve(somSelf);
  83.     return (_llLeft(thisBlock) || !_llIsTail(somSelf)) ? 1 : 0;
  84. }
  85.  
  86. /* ************************************************************ */
  87. SOM_Scope baseType *SOMLINK llAddTail(columnBlock * somSelf,
  88.                        baseType * newLine)
  89. {
  90.     columnBlockData *somThis = columnBlockGetData(somSelf);
  91.     linkedList *thisBlock;
  92.     columnBlockMethodDebug("columnBlock", "llAddTail");
  93.  
  94.     thisBlock = (linkedList *) _llRetrieve(somSelf);
  95.     if (!thisBlock)
  96.     return (baseType *) NULL;
  97.     if (!_llLeft(thisBlock)) {
  98.     if (!(thisBlock = (linkedList *) _llNext(somSelf))) {
  99.         return (baseType *) NULL;
  100.     }
  101.     }
  102.     return _llAddTail(thisBlock, newLine);
  103. }
  104.  
  105. /* ************************************************************ */
  106. SOM_Scope void SOMLINK print(columnBlock * somSelf,
  107.                   FILE * output)
  108. {
  109. /* Set up.
  110.    ------- */
  111.     columnBlockData *somThis = columnBlockGetData(somSelf);
  112.     int n, blockLength, blankLines;
  113.     linkedList *thisBlock;
  114.     textLine *thisLine;
  115.     columnBlockMethodDebug("columnBlock", "print");
  116.  
  117. /* Determine number of lines in typical block.
  118.    ------------------------------------------- */
  119.     thisBlock = (linkedList *) _llHead(somSelf);
  120.     blockLength = _llLength(thisBlock);
  121.     blankLines = _llLeft(thisBlock);
  122.  
  123. /* For each horizontal line...
  124.    --------------------------- */
  125.     for (n = 0; n < blockLength; n++) {
  126.  
  127. /*     For each text block...
  128.        ---------------------- */
  129.     thisBlock = (linkedList *) _llHead(somSelf);
  130.     while (thisBlock) {
  131.  
  132. /*      Print the column line.
  133.       ---------------------- */
  134.         thisLine = (textLine *) _llHead(thisBlock);
  135.         if (thisLine) {
  136.         _print(thisLine, output);
  137.         _llFreeContents(thisLine);
  138.         _cbPrintBlanks(somSelf, output, _tlCharsLeft(thisLine));
  139.         }
  140.         else {
  141.         _cbPrintBlanks(somSelf, output, _cbGetColumnWidth(somSelf));
  142.         }
  143.         _llRemoveHead(thisBlock);
  144.  
  145. /*      Print space between columns.
  146.       ---------------------------- */
  147.         _cbPrintBlanks(somSelf, output, SPACE_BETWEEN);
  148.  
  149. /*      Move to next block.
  150.       ------------------- */
  151.         thisBlock = (linkedList *) _llNext(somSelf);
  152.     }
  153.     fprintf(output, "\n");
  154.     }
  155. /* Print blank lines.
  156.    ------------------ */
  157.     for (n = 0; n < blankLines; n++) {
  158.     fprintf(output, "\n");
  159.     }
  160.  
  161. }
  162.  
  163. /* ************************************************************ */
  164. SOM_Scope void SOMLINK somInit(columnBlock * somSelf)
  165. {
  166.     columnBlockData *somThis = columnBlockGetData(somSelf);
  167.     columnBlockMethodDebug("columnBlock", "somInit");
  168.     parent_somInit(somSelf);
  169. }
  170.  
  171. /* ************************************************************ */
  172. SOM_Scope void SOMLINK somUninit(columnBlock * somSelf)
  173. {
  174.     columnBlockData *somThis = columnBlockGetData(somSelf);
  175.     columnBlockMethodDebug("columnBlock", "somUninit");
  176.     parent_somUninit(somSelf);
  177. }
  178.  
  179. /* ************************************************************ */
  180.  
  181. /*
  182.  * SOM_Scope void SOMLINK somDumpSelfInt(columnBlock * somSelf,
  183.  *                        int level)
  184.  */
  185.  
  186. /*
  187.  * The prototype for somDumpSelfInt was replaced by the following prototype:
  188.  */
  189. SOM_Scope void  SOMLINK somDumpSelfInt(columnBlock *somSelf,
  190.         long level)
  191. {
  192.     columnBlockData *somThis = columnBlockGetData(somSelf);
  193.     columnBlockMethodDebug("columnBlock", "somDumpSelfInt");
  194.     parent_somDumpSelfInt(somSelf, level);
  195. }
  196.  
  197. /* ************************************************************ */
  198. SOM_Scope void SOMLINK cbPrintBlanks(columnBlock * somSelf,
  199.                       FILE * output,
  200.                       long nblanks)
  201. {
  202.     columnBlockData *somThis = columnBlockGetData(somSelf);
  203.     int n;
  204.     columnBlockMethodDebug("columnBlock", "cbPrintBlanks");
  205.  
  206.     for (n = 0; n < nblanks; n++) {
  207.     putc(' ', output);
  208.     }
  209. }
  210.