home *** CD-ROM | disk | FTP | other *** search
- // Zinc Interface Library - TEXT.CPP
- // COPYRIGHT (C) 1990, 1991. All Rights Reserved.
- // Zinc Software Incorporated. Pleasant Grove, Utah USA
-
- #include "ui_win.hpp"
- #include <string.h>
-
- UIW_TEXT::UIW_TEXT(int left, int top, int _width, int _height, char *_text,
- short _maxLength, USHORT _txFlags, USHORT woFlags,
- int (*_validate)(void *object, int ccode)) :
- UIW_STRING(left, top, _width, _text, _maxLength, STF_NO_FLAGS, woFlags, _validate),
- txFlags(_txFlags)
- {
- windowID[0] = ID_TEXT;
- windowID[1] = ID_STRING;
- search.type = ID_TEXT;
-
- relative.bottom = relative.top + _height - 1;
- true.bottom = true.top + _height - 1;
- cellHeight = -1;
-
- // Match with the appropriate Windows 3.0 flags.
- MSWindowsStyle |= ES_AUTOVSCROLL | ES_MULTILINE;
- if (FlagSet(txFlags, TXF_NO_WORD_WRAP))
- MSWindowsStyle |= ES_AUTOHSCROLL;
- else
- MSWindowsStyle &= ~ES_AUTOHSCROLL;
- }
-
- int UIW_TEXT::Event(const UI_EVENT &event)
- {
- int ccode = UI_WINDOW_OBJECT::LogicalEvent(event, ID_TEXT);
-
- // Switch on the event type.
- switch (ccode)
- {
- case S_INITIALIZE:
- UI_WINDOW_OBJECT *object = Previous();
- if (!hWnd && previous && FlagSet(object->MSWindowsStyle, SBS_VERT))
- {
- MSWindowsStyle |= WS_VSCROLL;
- object->MSWindowsStyle |= WS_VSCROLL;
- }
- if (!hWnd && previous && FlagSet(object->MSWindowsStyle, SBS_HORZ))
- {
- MSWindowsStyle |= WS_HSCROLL;
- object->MSWindowsStyle |= WS_HSCROLL;
- }
- break;
-
- case E_KEY:
- case L_DELETE:
- case L_DELETE_EOL:
- case L_DELETE_WORD:
- if (FlagSet(woFlags, WOF_VIEW_ONLY))
- break;
-
- case L_UP:
- case L_DOWN:
- case L_PGUP:
- case L_PGDN:
- case L_TOP:
- case L_BOTTOM:
- case L_LEFT:
- case L_RIGHT:
- case L_BOL:
- case L_EOL:
- case L_WORD_LEFT:
- case L_WORD_RIGHT:
- if (event.key.value != VK_TAB)
- {
- if (event.rawCode)
- ccode = SendMessage(hWnd, WM_KEYDOWN, event.key.value, 0L);
- else
- ccode = SendMessage(hWnd, WM_CHAR, event.key.value, 0L);
- GetWindowText(hWnd, text, maxLength);
- }
- break;
-
- case L_MARK:
- case L_VIEW:
- case L_CUT:
- case L_COPY_MARK:
- case L_CUT_PASTE:
- case L_PASTE:
- case L_END_MARK:
- case L_CONTINUE_MARK:
- case L_BEGIN_MARK:
-
- case S_ERROR_RESPONSE:
-
- case S_SCROLL_VERTICAL:
-
- default:
- ccode = UIW_STRING::Event(event);
- break;
- }
-
- // Return the control code.
- return (ccode);
- }
-
- #pragma argsused
- void UIW_TEXT::DataSet(char *newText, short _maxLength)
- {
- if (newText)
- {
- if (FlagSet(woFlags, WOF_NO_ALLOCATE_DATA))
- text = newText;
- else
- {
- if (_maxLength != -1 && _maxLength > maxLength)
- {
- delete text;
- text = new char[_maxLength];
- }
- int srcLen = ui_strlen(newText) + 1;
- maxLength = (_maxLength == -1) ? maxLength : _maxLength;
- memcpy(text, newText, Min(srcLen, maxLength));
- }
-
- if (hWnd)
- {
- SetWindowText(hWnd, text);
- SendMessage(hWnd, EM_LIMITTEXT, maxLength, 0L);
- }
- }
- UI_WINDOW_OBJECT::Redisplay(FALSE);
- }
-
- #ifdef ZIL_LOAD
- UIW_TEXT::UIW_TEXT(const char *name, UI_STORAGE *file, USHORT loadFlags) :
- UIW_STRING(name, file, loadFlags | L_SUB_LEVEL)
- {
- windowID[0] = ID_TEXT;
- windowID[1] = ID_STRING;
-
- file->Load(&txFlags);
- cellHeight = -1;
- }
- #endif
-
- #ifdef ZIL_STORE
- void UIW_TEXT::Store(const char *name, UI_STORAGE *file, USHORT storeFlags)
- {
- UIW_STRING::Store(name, file, storeFlags | S_SUB_LEVEL);
- file->Store(txFlags);
- if (!FlagSet(storeFlags, S_SUB_LEVEL))
- file->ObjectSize(name, search);
- }
- #endif
-