home *** CD-ROM | disk | FTP | other *** search
- // Zinc Interface Library - PULLDN1.CPP
- // COPYRIGHT (C) 1990, 1991. All Rights Reserved.
- // Zinc Software Incorporated. Pleasant Grove, Utah USA
-
- #include "ui_win.hpp"
- #include <ctype.h>
- #include <string.h>
-
- #pragma argsused
- void UIW_PULL_DOWN_ITEM::UserFunction(UI_EVENT &event)
- {
- UIW_POP_UP_ITEM *item;
- if (parent->hMenu)
- {
- // Get the menu element from the event.rawCode index.
- int index = event.rawCode & 0x00FF;
- for (item = menu.First(); index && item; item = item->Next())
- index--;
- if (item)
- item->Event(event);
- }
- }
-
- UIW_PULL_DOWN_ITEM::UIW_PULL_DOWN_ITEM(char *_string, USHORT _mnFlags,
- void (*_userFunction)(void *object, UI_EVENT &event), USHORT _value) :
- UIW_BUTTON(0, 0, strlen(_string), NULL, BTF_DOWN_CLICK | BTF_NO_TOGGLE | BTF_NO_3D,
- WOF_NON_FIELD_REGION, UIW_PULL_DOWN_ITEM::PullDownUserFunction, _value),
- menu(0, 0, _mnFlags | MNF_SELECT_LEFT | MNF_SELECT_RIGHT, WOF_BORDER, WOAF_TEMPORARY | WOAF_NO_DESTROY)
- {
- // Initialize the menu item information.
- windowID[0] = ID_PULL_DOWN_ITEM;
- windowID[1] = ID_MENU_ITEM;
- windowID[2] = ID_BUTTON;
- search.type = ID_PULL_DOWN_ITEM;
-
- woFlags &= ~WOF_BORDER;
- userFunction = _userFunction ? _userFunction : UIW_PULL_DOWN_ITEM::PullDownUserFunction;
-
- if (!_string)
- return;
- string = FlagSet(woFlags, WOF_NO_ALLOCATE_DATA) ? _string : ui_strdup(_string);
- }
-
- UIW_PULL_DOWN_ITEM::UIW_PULL_DOWN_ITEM(char *_string, USHORT _mnFlags, UI_ITEM *flagItem) :
- UIW_BUTTON(0, 0, strlen(_string), NULL, BTF_DOWN_CLICK | BTF_NO_TOGGLE | BTF_NO_3D,
- WOF_NON_FIELD_REGION, UIW_PULL_DOWN_ITEM::PullDownUserFunction, 0),
- menu(0, 0, _mnFlags | MNF_SELECT_LEFT | MNF_SELECT_RIGHT, WOF_BORDER, WOAF_TEMPORARY | WOAF_NO_DESTROY)
- {
- // Initialize the menu item information.
- windowID[0] = ID_PULL_DOWN_ITEM;
- windowID[1] = ID_MENU_ITEM;
- windowID[2] = ID_BUTTON;
- search.type = ID_PULL_DOWN_ITEM;
-
- woFlags &= ~WOF_BORDER;
- userFunction = UIW_PULL_DOWN_ITEM::PullDownUserFunction;
- for (int i = 0; flagItem[i].string; i++)
- {
- UIW_POP_UP_ITEM *item = (flagItem[i].string[0] != '\0') ?
- new UIW_POP_UP_ITEM(flagItem[i].string, MNIF_NO_FLAGS,
- BTF_NO_TOGGLE, WOF_NO_FLAGS, flagItem[i].userFunction) :
- new UIW_POP_UP_ITEM;
- item->value = flagItem[i].value;
- menu.Add(item);
- }
-
- if (!_string)
- return;
- string = FlagSet(woFlags, WOF_NO_ALLOCATE_DATA) ? _string : ui_strdup(_string);
- }
-
- void UIW_PULL_DOWN_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 = (newString) ? ui_strdup(newString) : 0;
- }
- }
-
- // Modify MS Windows menu.
- if (parent && parent->hMenu && string)
- {
- UIW_PULL_DOWN_ITEM *item = this;
- for (int count = 0; item; item->Previous())
- count++;
- ModifyMenu(parent->hMenu, MF_BYCOMMAND, MF_STRING, count, string);
- DrawMenuBar(screenID);
- }
- else
- {
- if (parent)
- parent->Redisplay(TRUE);
- else
- UI_WINDOW_OBJECT::Redisplay(TRUE);
- }
- }
-
- UIW_PULL_DOWN_ITEM::Event(const UI_EVENT &event)
- {
- int ccode = event.type;
- UIW_POP_UP_ITEM *item;
- switch (ccode)
- {
- case S_INITIALIZE:
- //Create the MS Windows menu if any items exist.
- hMenu = NULL;
- if (First())
- hMenu = CreatePopupMenu();
-
- // Add item - event.rawCode ID number.
- char *tHotKey = NULL;
- if (string)
- tHotKey = strchr(string, '~');
- if (tHotKey)
- hotKey = toupper(tHotKey[1]);
- ui_strrepc(string, '~', '&');
-
- int count = event.rawCode;
- for (item = First(); item; item = item->Next())
- {
- if (!item->userFunction && item->NumberID() > 0xFF00)
- item->userFunction = UIW_POP_UP_ITEM::PopUpItemUserFunction;
- item->Event(event);
- item->hMenu = hMenu;
- if (FlagSet(item->mniFlags, MNIF_SEPARATOR))
- AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
- else
- AppendMenu(hMenu, MF_STRING, count, (LPSTR)item->DataGet());
- count++;
- }
-
- if (parent && parent->hMenu && hMenu)
- AppendMenu(parent->hMenu, MF_STRING | MF_POPUP, hMenu, string);
- else if (parent && parent->hMenu)
- AppendMenu(parent->hMenu, MF_STRING, count, string);
- break;
-
- case S_CREATE:
- menu.InformationSet(0, display, eventManager, windowManager,
- paletteMapTable, this);
-
- for (item = First(); item; item = item->Next())
- item->InformationSet(0, display, eventManager, windowManager,
- paletteMapTable, this);
-
- relative.left = relative.top = relative.right = relative.bottom = 0;
- ccode = UIW_BUTTON::Event(event);
- break;
-
- case S_MENU_SELECT:
- {
- UI_EVENT tEvent = event;
- tEvent.type = L_SELECT;
- ccode = UIW_BUTTON::Event(tEvent);
- break;
- }
-
- default:
- ccode = UIW_BUTTON::Event(event);
- break;
- }
-
- // Return the event control code.
- return (ccode);
- }
-
- void *UIW_PULL_DOWN_ITEM::Information(INFORMATION_REQUEST request, void *data)
- {
- if (request == GET_NUMBERID_OBJECT || request == GET_STRINGID_OBJECT)
- return (menu.Information(request, data));
- else if (request == PRINT_INFORMATION)
- {
- UI_WINDOW_OBJECT::Information(request, data);
- return (menu.Information(request, data));
- }
- else
- return (UI_WINDOW_OBJECT::Information(request, data));
- }
-
- #ifdef ZIL_LOAD
- UIW_PULL_DOWN_ITEM::UIW_PULL_DOWN_ITEM(const char *name, UI_STORAGE *file, USHORT loadFlags) :
- UIW_BUTTON(name, file, loadFlags | L_SUB_LEVEL), menu(0, file, L_SUB_LEVEL)
- {
- windowID[0] = ID_PULL_DOWN_ITEM;
- windowID[1] = ID_MENU_ITEM;
- windowID[2] = ID_BUTTON;
-
- userFunction = UIW_PULL_DOWN_ITEM::PullDownUserFunction;
- if (!file)
- file = _storage;
- if (!FlagSet(loadFlags, L_SUB_LEVEL) && FlagSet(file->stStatus, STS_TEMPORARY))
- delete file;
- }
- #endif
-
- #ifdef ZIL_STORE
- void UIW_PULL_DOWN_ITEM::Store(const char *name, UI_STORAGE *file, USHORT storeFlags)
- {
- UIW_BUTTON::Store(name, file, storeFlags | S_SUB_LEVEL);
- menu.Store(0, file, S_SUB_LEVEL | S_SKIP_TYPE);
- if (!FlagSet(storeFlags, S_SUB_LEVEL))
- file->ObjectSize(name, search);
- }
- #endif
-