home *** CD-ROM | disk | FTP | other *** search
- // Zinc Interface Library - POPUP.CPP
- // COPYRIGHT (C) 1990, 1991. All Rights Reserved.
- // Zinc Software Incorporated. Pleasant Grove, Utah USA
-
- #include "ui_win.hpp"
- #include <mem.h>
- #include <ctype.h>
- #include <string.h>
-
- UIW_POP_UP_MENU::UIW_POP_UP_MENU(int left, int top, USHORT _mnFlags, USHORT _woFlags,
- USHORT _woAdvancedFlags) :
- UIW_WINDOW(left, top, 0, 0, _woFlags, _woAdvancedFlags | WOAF_NORMAL_HOT_KEYS),
- mnFlags(_mnFlags)
- {
- /* Initialize the menu information */
- windowID[0] = ID_POP_UP_MENU;
- windowID[1] = ID_MENU;
- windowID[2] = ID_WINDOW;
- search.type = ID_POP_UP_MENU;
-
- if (FlagSet(_mnFlags, MNF_AUTO_SORT))
- compareFunction = UIW_POP_UP_MENU::CompareFunction;
- }
-
- int UIW_POP_UP_MENU::CompareFunction(void *element1, void *element2)
- {
- return (strcmp(((UIW_POP_UP_ITEM *)element1)->DataGet(TRUE), ((UIW_POP_UP_ITEM *)element2)->DataGet(TRUE)));
- }
-
- UIW_POP_UP_MENU::Event(const UI_EVENT &event)
- {
- /* Switch on the event type */
- UI_EVENT tEvent = event;
- int ccode = UI_WINDOW_OBJECT::LogicalEvent(event, ID_MENU);
- int height, width;
- int t_width = 0;
- int t_height = 0;
- int seperatorCount = 0;
- UIW_POP_UP_ITEM *item;
- UIW_POP_UP_ITEM *tItem;
- UI_WINDOW_OBJECT *topWindow = parent;
- while (topWindow->parent)
- topWindow = topWindow->parent;
- switch (ccode)
- {
- case S_CREATE:
- /* Compute the desired height and width */
- char *tHotKey;
- true.right = display->columns - 1;
- true.bottom = display->lines - 1;
- for (item = First(); item; item = item->Next())
- {
- if (!item->userFunction && item->NumberID() > 0xFF00)
- item->userFunction = UIW_POP_UP_ITEM::PopUpItemUserFunction;
- item->woFlags |= WOF_NON_FIELD_REGION;
- item->woAdvancedFlags |= WOAF_HOT_REGION;
- item->InformationSet(screenID, display, eventManager, windowManager, paletteMapTable, this);
- item->relative.left = item->relative.top = 0;
- item->relative.right = strlen(item->string) - 1;
- item->relative.bottom = display->cellHeight - 1;
- tHotKey = strchr(item->string, '~');
- if (tHotKey)
- {
- item->hotKey = toupper(tHotKey[1]);
- item->relative.right -= 1;
- }
- width = (display->isText) ? item->relative.right - 1 :
- item->relative.right + 1;
- if (width > t_width)
- t_width = width;
- ++t_height;
- if (FlagSet(item->mniFlags, MNIF_SEPARATOR))
- seperatorCount++;
- }
- if (t_width == 0 || t_height == 0)
- {
- t_width = 10;
- t_height = 2;
- }
- display->RegionConvert(relative, &woStatus, WOS_GRAPHICS);
- if (display->isText)
- {
- if (FlagSet(woAdvancedFlags, WOAF_TEMPORARY))
- woFlags |= WOF_BORDER;
- else
- woFlags &= ~WOF_BORDER;
- relative.right = relative.left + t_width + 1;
- relative.bottom = relative.top + t_height - 1;
- if (FlagSet(woFlags, WOF_BORDER))
- {
- relative.bottom += 2;
- relative.right += 2;
- }
- }
- else
- {
- height = display->cellHeight;
- width = display->cellWidth;
- woFlags |= WOF_BORDER;
- relative.right = relative.left + t_width * width - 2;
- relative.bottom = relative.top + t_height * height - seperatorCount * (height / 2) - 2;
- if (!parent || FlagSet(woAdvancedFlags, WOAF_TEMPORARY))
- relative.bottom += 2;
- }
- /* Continue to S_SIZE */
-
- case S_SIZE:
- UI_WINDOW_OBJECT::RegionMax(TRUE);
- height = display->cellHeight;
- for (item = First(); item; item = item->Next())
- {
- item->RegionMax(TRUE);
- if (FlagSet(woAdvancedStatus, WOAS_TOO_SMALL))
- item->woAdvancedStatus |= WOAS_TOO_SMALL;
- else
- item->woAdvancedStatus &= ~WOAS_TOO_SMALL;
- if (display->isText)
- {
- if (FlagSet(woAdvancedFlags, WOAF_TEMPORARY))
- item->woFlags &= ~WOF_BORDER;
- else
- item->woFlags |= WOF_BORDER;
- item->true.bottom = item->true.top;
- }
- else
- {
- item->woFlags &= ~WOF_BORDER;
- item->true.bottom = (!FlagSet(item->mniFlags, MNIF_SEPARATOR)) ?
- item->true.top + height - 1 : item->true.top + height / 2;
- if (item->true.bottom >= true.bottom)
- item->true.bottom = true.bottom - 1;
- else if (FlagSet(item->mniFlags, MNIF_SEPARATOR) && !display->isText)
- item->true.bottom--;
- }
- if (item->mniFlags != 0 && item->mniFlags != MNIF_SEPARATOR)
- {
- item->woFlags &= ~WOF_NON_SELECTABLE;
- if ((FlagSet(item->mniFlags, MNIF_RESTORE) &&
- !FlagSet(topWindow->woAdvancedStatus, WOAS_MINIMIZED | WOAS_MAXIMIZED)) ||
- (FlagSet(item->mniFlags, MNIF_MINIMIZE | MNIF_MAXIMIZE) &&
- FlagSet(topWindow->woAdvancedStatus, WOAS_MINIMIZED | WOAS_MAXIMIZED)) ||
- (FlagSet(item->mniFlags, MNIF_MOVE) && FlagSet(topWindow->woAdvancedFlags, WOAF_NO_MOVE)) ||
- (FlagSet(item->mniFlags, MNIF_SIZE) && FlagSet(topWindow->woAdvancedFlags, WOAF_NO_SIZE)))
- item->woFlags |= WOF_NON_SELECTABLE;
- }
- }
- UIW_WINDOW::RegionsCompute();
- break;
-
- case S_CLOSE:
- ccode = UIW_WINDOW::Event(event);
- break;
-
- case L_LEFT:
- case L_RIGHT:
- if ((ccode == L_LEFT && FlagSet(mnFlags, MNF_SELECT_LEFT)) ||
- (ccode == L_RIGHT && FlagSet(mnFlags, MNF_SELECT_RIGHT)))
- {
- tEvent.type = L_SELECT;
- eventManager->Put(tEvent, Q_BEGIN);
- eventManager->Put(event, Q_BEGIN);
- tEvent.type = S_CLOSE_TEMPORARY;
- eventManager->Put(tEvent, Q_BEGIN);
- }
- break;
-
- case L_UP:
- case L_DOWN:
- tEvent.type = (ccode == L_UP) ? L_PREVIOUS : L_NEXT;
- // Continue to L_PREVIOUS and L_NEXT.
-
- case L_PREVIOUS:
- case L_NEXT:
- if (FlagSet(woFlags, WOF_NON_FIELD_REGION))
- {
- UI_WINDOW_OBJECT *tParent = parent;
- parent = NULL; // Trick the window.
- ccode = UIW_WINDOW::Event(tEvent);
- parent = tParent;
- }
- else
- ccode = UIW_WINDOW::Event(tEvent);
- break;
-
- case L_TOP:
- case L_BOTTOM:
- tEvent.type = (ccode == L_TOP) ? L_FIRST : L_LAST;
- ccode = UIW_WINDOW::Event(tEvent);
- break;
-
- default:
- ccode = UIW_WINDOW::Event(event);
-
- // Check for unknown temporary event (accelerator keys).
- if (ccode == S_UNKNOWN && FlagSet(woAdvancedFlags, WOAF_TEMPORARY) && parent)
- {
- UI_WINDOW_OBJECT *root = parent;
- while (root->parent)
- root = root->parent;
- ccode = root->Event(event);
- return (ccode);
- }
-
- /* Unhighlight the remaining items */
- item = (UIW_POP_UP_ITEM *)current;
- if (!FlagSet(mnFlags, MNF_SELECT_ONE) || !FlagsSet(item->woStatus, WOS_SELECTED))
- break;
- UI_EVENT tEvent;
- tEvent.type = S_DISPLAY_ACTIVE;
- for (tItem = First(); tItem; tItem = tItem->Next())
- if (tItem != item && FlagSet(tItem->woStatus, WOS_SELECTED))
- {
- tItem->woStatus &= ~WOS_SELECTED;
- tEvent.region = tItem->true;
- tItem->Event(tEvent);
- }
- break;
- }
-
- /* Return the event control code */
- return (ccode);
- }
-
- void *UIW_POP_UP_MENU::Information(INFORMATION_REQUEST request, void *data)
- {
- if (request == GET_NUMBERID_OBJECT || request == GET_STRINGID_OBJECT ||
- request == PRINT_INFORMATION)
- return (UIW_WINDOW::Information(request, data));
- else
- return (UI_WINDOW_OBJECT::Information(request, data));
- }
-
- #ifdef ZIL_LOAD
- UIW_POP_UP_MENU::UIW_POP_UP_MENU(const char *name, UI_STORAGE *file, USHORT loadFlags) :
- UIW_WINDOW(name, file, loadFlags | L_SUB_LEVEL)
- {
- windowID[0] = ID_POP_UP_MENU;
- windowID[1] = ID_MENU;
- windowID[2] = ID_WINDOW;
-
- if (!file)
- file = _storage;
- file->Load(&mnFlags);
- if (FlagSet(mnFlags, MNF_AUTO_SORT))
- compareFunction = UIW_POP_UP_MENU::CompareFunction;
- if (!FlagSet(loadFlags, L_SUB_LEVEL) && FlagSet(file->stStatus, STS_TEMPORARY))
- delete file;
- }
- #endif
-
- #ifdef ZIL_STORE
- void UIW_POP_UP_MENU::Store(const char *name, UI_STORAGE *file, USHORT storeFlags)
- {
- UIW_WINDOW::Store(name, file, storeFlags | S_SUB_LEVEL);
- file->Store(mnFlags);
- if (!FlagSet(storeFlags, S_SUB_LEVEL))
- file->ObjectSize(name, search);
- }
- #endif
-