home *** CD-ROM | disk | FTP | other *** search
- // Zinc Interface Library - PULLDN.CPP
- // COPYRIGHT (C) 1990, 1991. All Rights Reserved.
- // Zinc Software Incorporated. Pleasant Grove, Utah USA
-
- #include "ui_win.hpp"
- #include <string.h>
-
- UIW_PULL_DOWN_MENU::UIW_PULL_DOWN_MENU(int a_indentation, USHORT a_woFlags,
- USHORT a_woAdvancedFlags) :
- UIW_WINDOW(0, 0, 1, 1, a_woFlags | WOF_NON_FIELD_REGION,
- a_woAdvancedFlags | WOAF_NORMAL_HOT_KEYS | WOAF_NO_SIZE | WOAF_NO_MOVE)
- {
- // Initialize the pull-down menu information.
- windowID[0] = ID_PULL_DOWN_MENU;
- windowID[1] = ID_MENU;
- windowID[2] = ID_WINDOW;
- search.type = ID_PULL_DOWN_MENU;
-
- hotKey = HOT_KEY_SUB_WINDOW;
- indentation = a_indentation;
- }
-
- UIW_PULL_DOWN_MENU::UIW_PULL_DOWN_MENU(int a_indentation, UI_ITEM *flagItem) :
- UIW_WINDOW(0, 0, 1, 1, WOF_BORDER | WOF_NON_FIELD_REGION,
- WOAF_NO_FLAGS | WOAF_NORMAL_HOT_KEYS | WOAF_NO_SIZE | WOAF_NO_MOVE),
- indentation(a_indentation)
- {
- // Initialize the pull-down menu information.
- windowID[0] = ID_PULL_DOWN_MENU;
- windowID[1] = ID_MENU;
- windowID[2] = ID_WINDOW;
- search.type = ID_PULL_DOWN_MENU;
-
- hotKey = HOT_KEY_SUB_WINDOW;
- for (int i = 0; flagItem[i].string; i++)
- {
- UIW_PULL_DOWN_ITEM *item = new UIW_PULL_DOWN_ITEM(flagItem[i].string,
- MNF_NO_FLAGS, flagItem[i].userFunction, flagItem[i].value);
- *this + item;
- }
- }
-
- UIW_PULL_DOWN_MENU::Event(const UI_EVENT &event)
- {
- // Switch on the event type.
- UI_EVENT tEvent = event;
- int ccode = UI_WINDOW_OBJECT::LogicalEvent(event, ID_MENU);
- UIW_PULL_DOWN_ITEM *item;
- switch (ccode)
- {
- case S_CREATE:
- case S_SIZE:
- if (display->isText)
- woFlags &= ~WOF_BORDER;
- else
- woFlags |= WOF_BORDER;
- woAdvancedStatus &= ~WOAS_INVALID_REGION;
- if (!parent)
- {
- true.left = true.top = 0;
- true.right = display->columns - 1;
- true.bottom = display->lines - 1;
- }
- else
- {
- UI_WINDOW_OBJECT::RegionMax(TRUE);
- if (true.bottom - true.top < display->cellHeight - 1)
- {
- woAdvancedStatus |= WOAS_INVALID_REGION;
- break;
- }
- if (!display->isText &&
- parent->true.left < true.left &&
- parent->true.right > true.right &&
- parent->true.top < true.top)
- {
- true.left--;
- true.top--;
- true.right++;
- }
- }
-
- int trueLeft = true.left;
- int trueTop = true.top;
- true.left += indentation * display->cellWidth;
- int bottom = true.top;
- for (item = First(); item; item = item->Next())
- {
- item->InformationSet(screenID, display, eventManager,
- windowManager, paletteMapTable, this);
- item->Event(event);
- item->true.right = item->true.left + item->relative.right;
- item->true.bottom = item->true.top + display->cellHeight - 1;
- if (item->true.bottom > true.bottom)
- item->woAdvancedStatus |= WOAS_INVALID_REGION;
- else if (!FlagSet(item->woAdvancedStatus, WOAS_INVALID_REGION))
- bottom = item->true.bottom;
- true.top = (display->isText) ? item->true.top : item->true.top - 1;
- }
- true.left = trueLeft;
- true.top = trueTop;
- if (bottom == true.top)
- bottom += display->cellHeight - 1;
- true.bottom = (display->isText) ? bottom : bottom + 1;
- UIW_WINDOW::RegionsCompute();
- break;
-
- case L_BEGIN_SELECT:
- case L_CONTINUE_SELECT:
- for (UIW_PULL_DOWN_ITEM *t_item = First(); t_item; t_item = t_item->Next())
- if (!FlagSet(t_item->woFlags, WOF_NON_SELECTABLE) &&
- t_item->Overlap(event.position))
- break;
-
- // See if it is a new current item.
- if (ccode == L_CONTINUE_SELECT && (!t_item ||
- t_item == (UIW_PULL_DOWN_ITEM *)UI_LIST::Get(UIW_WINDOW::FindStatus, &WOS_CURRENT)))
- break;
-
- // Unhighlight the remaining items.
- UI_EVENT t_event;
- t_event.type = S_DISPLAY_ACTIVE;
- for (item = First(); item; item = item->Next())
- if (item != t_item && FlagSet(item->woStatus, WOS_SELECTED))
- {
- item->woStatus &= ~WOS_SELECTED;
- t_event.region = item->true;
- item->Event(t_event);
- }
-
- // Process the key.
- t_event = event;
- t_event.type = L_BEGIN_SELECT;
- ccode = UIW_WINDOW::Event(t_event);
- break;
-
- case L_DOWN:
- item = (UIW_PULL_DOWN_ITEM *)UI_LIST::Get(UIW_WINDOW::FindStatus, &WOS_CURRENT);
- if (!item || !item->menu.First())
- break;
- tEvent.type = L_SELECT;
- ccode = UIW_WINDOW::Event(tEvent);
- break;
-
- case L_LEFT:
- case L_RIGHT:
- tEvent.type = (ccode == L_LEFT) ? L_PREVIOUS : 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);
- break;
- }
-
- // Return the event control code.
- return (ccode);
- }
-
- #ifdef ZIL_LOAD
- UIW_PULL_DOWN_MENU::UIW_PULL_DOWN_MENU(const char *name, UI_STORAGE *file, USHORT loadFlags) :
- UIW_WINDOW(name, file, loadFlags | L_SUB_LEVEL)
- {
- windowID[0] = ID_PULL_DOWN_MENU;
- windowID[1] = ID_MENU;
- windowID[2] = ID_WINDOW;
- hotKey = HOT_KEY_SUB_WINDOW;
-
- if (!file)
- file = _storage;
- file->Load(&indentation);
- if (!FlagSet(loadFlags, L_SUB_LEVEL) && FlagSet(file->stStatus, STS_TEMPORARY))
- delete file;
- }
- #endif
-
- #ifdef ZIL_STORE
- void UIW_PULL_DOWN_MENU::Store(const char *name, UI_STORAGE *file, USHORT storeFlags)
- {
- UIW_WINDOW::Store(name, file, storeFlags | S_SUB_LEVEL);
- file->Store(indentation);
- if (!FlagSet(storeFlags, S_SUB_LEVEL))
- file->ObjectSize(name, search);
- }
- #endif
-