home *** CD-ROM | disk | FTP | other *** search
- // Zinc Interface Library - POPUP1.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>
-
- void UIW_POP_UP_ITEM::PopUpItemUserFunction(void *data, UI_EVENT &event)
- {
- UIW_POP_UP_ITEM *item = (UIW_POP_UP_ITEM *)data;
-
- event.type = 0;
- switch (item->NumberID())
- {
- case NUMID_OPT_RESTORE:
- UI_WINDOW_OBJECT *topWindow = item->parent;
- while (topWindow->parent)
- topWindow = topWindow->parent;
- event.type = (FlagSet(topWindow->woAdvancedStatus, WOAS_MINIMIZED)) ?
- S_MINIMIZE : S_MAXIMIZE;
- break;
-
- case NUMID_OPT_MOVE:
- event.type = S_MOVE;
- event.rawCode = 0xFFFF;
- break;
-
- case NUMID_OPT_SIZE:
- event.type = S_SIZE;
- event.rawCode = 0xFFFF;
- break;
-
- case NUMID_OPT_MAXIMIZE:
- event.type = S_MAXIMIZE;
- break;
-
- case NUMID_OPT_MINIMIZE:
- event.type = S_MINIMIZE;
- break;
-
- case NUMID_OPT_CLOSE:
- {
- UI_WINDOW_OBJECT *root = item->parent;
- while (root->parent)
- root = root->parent;
- event.type = FlagSet(root->woAdvancedFlags, WOAF_LOCKED) ?
- L_EXIT_FUNCTION : S_CLOSE;
- break;
- }
- }
- if (event.type)
- {
- item->eventManager->Put(event, Q_BEGIN);
- event.type = S_CLOSE_TEMPORARY;
- item->eventManager->Put(event, Q_BEGIN);
- }
- }
-
- void UIW_POP_UP_ITEM::Initialize(char *_string)
- {
- // Initialize the menu item information.
- windowID[0] = ID_POP_UP_ITEM;
- windowID[1] = ID_MENU_ITEM;
- windowID[2] = ID_BUTTON;
- search.type = ID_POP_UP_ITEM;
-
- if (_string && !FlagSet(woFlags, WOF_NO_ALLOCATE_DATA))
- {
- string = new char[strlen(_string) + 3];
- strcpy(string, " ");
- strcat(string, _string);
- strcat(string, " ");
- }
- else if (_string)
- string = _string;
- else
- string = NULL;
-
- woFlags &= ~WOF_BORDER;
-
- if (FlagSet(mniFlags, MNIF_RESTORE))
- search.numberID = NUMID_OPT_RESTORE;
- else if (FlagSet(mniFlags, MNIF_MOVE))
- search.numberID = NUMID_OPT_MOVE;
- else if (FlagSet(mniFlags, MNIF_SIZE))
- search.numberID = NUMID_OPT_SIZE;
- else if (FlagSet(mniFlags, MNIF_MINIMIZE))
- search.numberID = NUMID_OPT_MINIMIZE;
- else if (FlagSet(mniFlags, MNIF_MAXIMIZE))
- search.numberID = NUMID_OPT_MAXIMIZE;
- else if (FlagSet(mniFlags, MNIF_CLOSE))
- search.numberID = NUMID_OPT_CLOSE;
- }
-
- UIW_POP_UP_ITEM::UIW_POP_UP_ITEM(char *_string, USHORT _mniFlags, USHORT _btFlags,
- USHORT _woFlags, void (*_userFunction)(void *object, UI_EVENT &event), USHORT _value) :
- UIW_BUTTON(0, 0, strlen(_string) + 2, NULL, _btFlags | BTF_NO_3D, _woFlags,
- _userFunction, _value), mniFlags(_mniFlags)
- {
- UIW_POP_UP_ITEM::Initialize(_string);
- }
-
- UIW_POP_UP_ITEM::UIW_POP_UP_ITEM(int left, int top, int width, char *_string,
- USHORT _mniFlags, USHORT _btFlags, USHORT _woFlags,
- void (*_userFunction)(void *object, UI_EVENT &event), USHORT _value) :
- UIW_BUTTON(left, top, width, NULL, _btFlags | BTF_NO_3D, _woFlags,
- _userFunction, _value), mniFlags(_mniFlags)
- {
- UIW_POP_UP_ITEM::Initialize(_string);
- }
-
- UIW_POP_UP_ITEM::UIW_POP_UP_ITEM() :
- UIW_BUTTON(0, 0, 1, "", BTF_NO_3D, WOF_NON_SELECTABLE, 0, 0)
- {
- // This is the constructor for a menu item seperator.
- windowID[0] = ID_POP_UP_ITEM;
- windowID[1] = ID_MENU_ITEM;
- windowID[2] = ID_BUTTON;
- search.type = ID_POP_UP_ITEM;
-
- mniFlags = MNIF_SEPARATOR;
- woFlags &= ~WOF_BORDER;
- woAdvancedFlags |= WOAF_NON_CURRENT;
- }
-
- void UIW_POP_UP_ITEM::DataSet(char *newString)
- {
- // Reset the button's string information.
- if (newString)
- {
- if (FlagSet(woFlags, WOF_NO_ALLOCATE_DATA))
- string = newString;
- else
- {
- if (string)
- delete string;
- string = new char[strlen(newString) + 3];
- strcpy(string, " ");
- strcat(string, newString);
- strcat(string, " ");
- }
- }
- if (!string || string[0] == '\0')
- {
- mniFlags = MNIF_SEPARATOR;
- woAdvancedFlags |= WOAF_NON_CURRENT;
- }
- else
- {
- mniFlags &= ~MNIF_SEPARATOR;
- woAdvancedFlags &= ~WOAF_NON_CURRENT;
- }
-
- if (hMenu)
- {
- UIW_POP_UP_ITEM *item = this;
- for (int count = 0; item; item->Previous())
- count++;
- if (FlagSet(mniFlags, MNIF_SEPARATOR))
- ModifyMenu(hMenu, MF_BYCOMMAND, MF_SEPARATOR, count, NULL);
- else
- ModifyMenu(hMenu, MF_BYCOMMAND, MF_STRING, count, string);
- DrawMenuBar(screenID);
- }
- else
- {
- if (parent)
- parent->Redisplay(TRUE);
- else
- UI_WINDOW_OBJECT::Redisplay(TRUE);
- }
- }
-
- UIW_POP_UP_ITEM::Event(const UI_EVENT &event)
- {
- // Switch on the event type.
- int ccode = event.type;
-
- switch (ccode)
- {
- case S_INITIALIZE:
- {
- // Add item - event.rawCode ID number.
- char *tHotKey = NULL;
- if (string)
- tHotKey = strchr(string, '~');
- if (tHotKey)
- hotKey = toupper(tHotKey[1]);
- if (string && (hMenu || FlagSet(btFlags, BTF_NO_3D)))
- ui_strrepc(string, '~', '&');
- }
- break;
-
- case S_CURRENT:
- case S_DISPLAY_INACTIVE:
- case S_DISPLAY_ACTIVE:
- if (hMenu)
- HiliteMenuItem(screenID, hMenu, 0, MF_BYPOSITION | MF_HILITE);
- else if (FlagSet(mniFlags, MNIF_SEPARATOR))
- {
- lastPalette = 0;
- ccode = UIW_BUTTON::Event(event);
- int line = (true.top + true.bottom) / 2;
- display->Line(screenID, true.left, line, true.right, line,
- MapPalette(paletteMapTable, ccode, ID_OUTLINE));
- break;
- }
- // Continue to default.
-
- default:
- ccode = UIW_BUTTON::Event(event);
- break;
- }
-
- // Return the event control code.
- return (ccode);
- }
-
- #ifdef ZIL_LOAD
- UIW_POP_UP_ITEM::UIW_POP_UP_ITEM(const char *name, UI_STORAGE *file, USHORT loadFlags) :
- UIW_BUTTON(name, file, loadFlags | L_SUB_LEVEL)
- {
- windowID[0] = ID_POP_UP_ITEM;
- windowID[1] = ID_MENU_ITEM;
- windowID[2] = ID_BUTTON;
-
- if (!file)
- file = _storage;
- file->Load(&mniFlags);
- if (!FlagSet(loadFlags, L_SUB_LEVEL) && FlagSet(file->stStatus, STS_TEMPORARY))
- delete file;
- }
- #endif
-
- #ifdef ZIL_STORE
- void UIW_POP_UP_ITEM::Store(const char *name, UI_STORAGE *file, USHORT storeFlags)
- {
- UIW_BUTTON::Store(name, file, storeFlags | S_SUB_LEVEL);
- file->Store(mniFlags);
- if (!FlagSet(storeFlags, S_SUB_LEVEL))
- file->ObjectSize(name, search);
- }
- #endif
-