home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / ZINC_5.ZIP / WINSRC.ZIP / TEXT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-01  |  3.4 KB  |  152 lines

  1. //    Zinc Interface Library - TEXT.CPP
  2. //    COPYRIGHT (C) 1990, 1991.  All Rights Reserved.
  3. //    Zinc Software Incorporated.  Pleasant Grove, Utah  USA
  4.  
  5. #include "ui_win.hpp"
  6. #include <string.h>
  7.  
  8. UIW_TEXT::UIW_TEXT(int left, int top, int _width, int _height, char *_text,
  9.     short _maxLength, USHORT _txFlags, USHORT woFlags,
  10.     int (*_validate)(void *object, int ccode)) :
  11.     UIW_STRING(left, top, _width, _text, _maxLength, STF_NO_FLAGS, woFlags, _validate),
  12.     txFlags(_txFlags)
  13. {
  14.     windowID[0] = ID_TEXT;
  15.     windowID[1] = ID_STRING;
  16.     search.type = ID_TEXT;
  17.  
  18.     relative.bottom = relative.top + _height - 1;
  19.     true.bottom = true.top + _height - 1;
  20.     cellHeight = -1;
  21.  
  22.     // Match with the appropriate Windows 3.0 flags.
  23.     MSWindowsStyle |= ES_AUTOVSCROLL | ES_MULTILINE;
  24.     if (FlagSet(txFlags, TXF_NO_WORD_WRAP))
  25.         MSWindowsStyle |= ES_AUTOHSCROLL;
  26.     else
  27.         MSWindowsStyle &= ~ES_AUTOHSCROLL;
  28. }
  29.  
  30. int UIW_TEXT::Event(const UI_EVENT &event)
  31. {
  32.     int ccode = UI_WINDOW_OBJECT::LogicalEvent(event, ID_TEXT);
  33.  
  34.     // Switch on the event type.
  35.     switch (ccode)
  36.     {
  37.     case S_INITIALIZE:
  38.         UI_WINDOW_OBJECT *object = Previous();
  39.         if (!hWnd && previous && FlagSet(object->MSWindowsStyle, SBS_VERT))
  40.         {
  41.             MSWindowsStyle |= WS_VSCROLL;
  42.             object->MSWindowsStyle |= WS_VSCROLL;
  43.         }
  44.         if (!hWnd && previous && FlagSet(object->MSWindowsStyle, SBS_HORZ))
  45.         {
  46.             MSWindowsStyle |= WS_HSCROLL;
  47.             object->MSWindowsStyle |= WS_HSCROLL;
  48.         }
  49.         break;
  50.  
  51.     case E_KEY:
  52.     case L_DELETE:
  53.     case L_DELETE_EOL:
  54.     case L_DELETE_WORD:
  55.         if (FlagSet(woFlags, WOF_VIEW_ONLY))
  56.             break;
  57.  
  58.     case L_UP:
  59.     case L_DOWN:
  60.     case L_PGUP:
  61.     case L_PGDN:
  62.     case L_TOP:
  63.     case L_BOTTOM:
  64.     case L_LEFT:
  65.     case L_RIGHT:
  66.     case L_BOL:
  67.     case L_EOL:
  68.     case L_WORD_LEFT:
  69.     case L_WORD_RIGHT:
  70.         if (event.key.value != VK_TAB)
  71.         {
  72.             if (event.rawCode)
  73.                 ccode = SendMessage(hWnd, WM_KEYDOWN, event.key.value, 0L);
  74.             else
  75.                 ccode = SendMessage(hWnd, WM_CHAR, event.key.value, 0L);
  76.             GetWindowText(hWnd, text, maxLength);
  77.         }
  78.         break;
  79.  
  80.     case L_MARK:
  81.     case L_VIEW:
  82.     case L_CUT:
  83.     case L_COPY_MARK:
  84.     case L_CUT_PASTE:
  85.     case L_PASTE:
  86.     case L_END_MARK:
  87.     case L_CONTINUE_MARK:
  88.     case L_BEGIN_MARK:
  89.  
  90.     case S_ERROR_RESPONSE:
  91.  
  92.     case S_SCROLL_VERTICAL:
  93.  
  94.     default:
  95.         ccode = UIW_STRING::Event(event);
  96.         break;
  97.     }
  98.  
  99.     // Return the control code.
  100.     return (ccode);
  101. }
  102.  
  103. #pragma argsused
  104. void UIW_TEXT::DataSet(char *newText, short _maxLength)
  105. {
  106.     if (newText)
  107.     {
  108.         if (FlagSet(woFlags, WOF_NO_ALLOCATE_DATA))
  109.             text = newText;
  110.         else
  111.         {
  112.             if (_maxLength != -1 && _maxLength > maxLength)
  113.             {
  114.                 delete text;
  115.                 text = new char[_maxLength];
  116.             }
  117.             int srcLen = ui_strlen(newText) + 1;
  118.             maxLength = (_maxLength == -1) ? maxLength : _maxLength;
  119.             memcpy(text, newText, Min(srcLen, maxLength));
  120.         }
  121.  
  122.         if (hWnd)
  123.         {
  124.             SetWindowText(hWnd, text);
  125.             SendMessage(hWnd, EM_LIMITTEXT, maxLength, 0L);
  126.         }
  127.     }
  128.     UI_WINDOW_OBJECT::Redisplay(FALSE);
  129. }
  130.  
  131. #ifdef ZIL_LOAD
  132. UIW_TEXT::UIW_TEXT(const char *name, UI_STORAGE *file, USHORT loadFlags) :
  133.     UIW_STRING(name, file, loadFlags | L_SUB_LEVEL)
  134. {
  135.     windowID[0] = ID_TEXT;
  136.     windowID[1] = ID_STRING;
  137.  
  138.     file->Load(&txFlags);
  139.     cellHeight = -1;
  140. }
  141. #endif
  142.  
  143. #ifdef ZIL_STORE
  144. void UIW_TEXT::Store(const char *name, UI_STORAGE *file, USHORT storeFlags)
  145. {
  146.     UIW_STRING::Store(name, file, storeFlags | S_SUB_LEVEL);
  147.     file->Store(txFlags);
  148.     if (!FlagSet(storeFlags, S_SUB_LEVEL))
  149.         file->ObjectSize(name, search);
  150. }
  151. #endif
  152.