home *** CD-ROM | disk | FTP | other *** search
- // RADIO.CPP - Source code for radio button tutorial.
- // COPYRIGHT (C) 1991. All Rights Reserved.
- // Zinc Software Incorporated. Pleasant Grove, Utah USA
-
- #include <ui_win.hpp>
- #include <graphics.h>
- #include <string.h>
- #include "radio.hpp"
-
- void Exit(void *data, UI_EVENT &event)
- {
- // Exit the application by sending a message.
- UIW_BUTTON *item = (UIW_BUTTON *)data;
- event.type = L_EXIT;
- item->eventManager->Put(event);
- }
-
- RADIO_BUTTON::RADIO_BUTTON(int left, int top, int width, char *aText,
- int aValue, USHORT aWoStatus) :
- UI_WINDOW_OBJECT(left, top, width, 1, WOF_JUSTIFY_RIGHT, WOAF_NO_FLAGS),
- value(aValue)
- {
- text = ui_strdup(aText);
- woStatus |= aWoStatus;
- if (FlagSet(woStatus, WOS_SELECTED))
- woStatus |= WOS_CURRENT;
- }
-
- int RADIO_BUTTON::Event(const UI_EVENT &event)
- {
- // Special radio button palettes
- static UI_PALETTE fillButton =
- {
- ' ', attrib(BLACK, BLACK), attrib(MONO_BLACK, MONO_BLACK),
- SOLID_FILL, BLACK, BLACK, BW_BLACK, BW_BLACK, GS_BLACK, GS_BLACK
- };
- static UI_PALETTE nonCurrentButton =
- {
- ' ', attrib(BLACK, LIGHTGRAY), attrib(MONO_NORMAL, MONO_BLACK),
- SOLID_FILL, BLACK, WHITE, BW_BLACK, BW_WHITE, GS_BLACK, GS_WHITE
- };
- static UI_PALETTE currentButton =
- {
- ' ', attrib(LIGHTGRAY, DARKGRAY), attrib(MONO_BLACK, MONO_NORMAL),
- SOLID_FILL, BLACK, LIGHTGRAY, BW_WHITE, BW_BLACK, GS_BLACK, GS_GRAY
- };
-
- // Switch on the event type.
- int ccode = event.type;
- switch (ccode)
- {
- case S_CREATE:
- if (display->isText)
- {
- relative.left--;
- relative.top--;
- relative.right--;
- relative.bottom--;
- }
- ccode = UI_WINDOW_OBJECT::Event(event);
- break;
-
- case S_CURRENT:
- case S_NON_CURRENT:
- if (ccode == S_CURRENT)
- woStatus |= WOS_SELECTED;
- else
- woStatus &= ~WOS_SELECTED;
- // Continue to S_DISPLAY_ACTIVE and S_DISPLAY_INACTIVE.
-
- case S_DISPLAY_ACTIVE:
- case S_DISPLAY_INACTIVE:
- UI_PALETTE *palette = (ccode == S_CURRENT) ? ¤tButton : &nonCurrentButton;
- if (display->isText)
- {
- if (UI_WINDOW_OBJECT::NeedsUpdate(event, ccode) ||
- ccode == S_CURRENT)
- UI_WINDOW_OBJECT::Text(text, 0, ccode, palette);
- char *radioText = FlagSet(woStatus, WOS_SELECTED) ? "()" : "( )";
- display->Text(screenID, true.left, true.top, radioText, palette);
- }
- else
- {
- int radius = (relative.bottom - relative.top + 1) / 2;
- int fillDiameter = (relative.bottom - relative.top + 1) / 4;
- if (UI_WINDOW_OBJECT::NeedsUpdate(event, ccode) ||
- ccode == S_CURRENT)
- {
- UI_WINDOW_OBJECT::Text(text, 0, ccode, palette);
- display->Ellipse(screenID, true.left + radius, true.top + radius,
- 0, 360, radius, radius, palette, FALSE);
- }
- if (FlagSet(woStatus, WOS_SELECTED))
- display->Ellipse(screenID, true.left + radius, true.top + radius,
- 0, 360, fillDiameter, fillDiameter, &fillButton, TRUE);
- }
- break;
-
- default:
- ccode = UI_WINDOW_OBJECT::Event(event);
- break;
- }
-
- // Return the control code.
- return (ccode);
- }
-
- RADIO_CONTROL::RADIO_CONTROL(int left, int top, int width, int height,
- char *aTitle, USHORT woFlags) :
- UIW_WINDOW(left, top, width, height, woFlags)
- {
- title = ui_strdup(aTitle);
- }
-
- int RADIO_CONTROL::Event(const UI_EVENT &event)
- {
- // Switch on the event type.
- UI_EVENT tEvent = event;
- int ccode = UI_WINDOW_OBJECT::LogicalEvent(event, ID_WINDOW);
- switch (ccode)
- {
- case S_NON_CURRENT:
- if (current)
- {
- tEvent.type = S_DISPLAY_ACTIVE;
- tEvent.region = true;
- UI_WINDOW_OBJECT *object = (UI_WINDOW_OBJECT *)current;
- object->Event(tEvent);
- }
- return (ccode);
-
- case S_CURRENT:
- case S_DISPLAY_ACTIVE:
- case S_DISPLAY_INACTIVE:
- UIW_WINDOW::Event(tEvent);
- display->Text(screenID, true.left + display->cellWidth, true.top, title, lastPalette, -1);
- return (ccode);
-
- case L_NEXT:
- case L_PREVIOUS:
- return (S_UNKNOWN);
- break;
-
- case L_UP:
- case L_LEFT:
- tEvent.type = L_PREVIOUS;
- break;
-
- case L_DOWN:
- case L_RIGHT:
- tEvent.type = L_NEXT;
- break;
- }
-
- // Return the control code.
- return (UIW_WINDOW::Event(tEvent));
- }
-
- main()
- {
- // Initialize the display, trying for graphics first.
- UI_DISPLAY *display = new UI_DOS_BGI_DISPLAY;
- if (!display->installed)
- {
- delete display;
- display = new UI_DOS_TEXT_DISPLAY;
- }
-
- // Initialize the event manager and add three devices to it.
- UI_EVENT_MANAGER eventManager(100, display);
- eventManager
- + new UI_BIOS_KEYBOARD
- + new UI_MS_MOUSE
- + new UI_CURSOR;
-
- // Initialize the window manager.
- UI_WINDOW_MANAGER windowManager(display, &eventManager);
-
- // Set up the radio controls.
- RADIO_CONTROL *port = new RADIO_CONTROL(2, 1, 14, 7, " PORT ", WOF_BORDER);
- *port
- + new RADIO_BUTTON(2, 1, 10, " LPT 1 ", PORT_LPT1, WOS_SELECTED)
- + new RADIO_BUTTON(2, 2, 10, " LPT 2 ", PORT_LPT2)
- + new RADIO_BUTTON(2, 3, 10, " COM 1 ", PORT_COM1)
- + new RADIO_BUTTON(2, 4, 10, " COM 2 ", PORT_COM2)
- + new RADIO_BUTTON(2, 5, 10, " OTHER ", PORT_OTHER);
-
- RADIO_CONTROL *baudRate = new RADIO_CONTROL(19, 1, 13, 5, " BAUD ", WOF_BORDER);
- *baudRate
- + new RADIO_BUTTON(2, 1, 9, " 1200 ", BAUD_1200)
- + new RADIO_BUTTON(2, 2, 9, " 2400 ", BAUD_2400, WOS_SELECTED)
- + new RADIO_BUTTON(2, 3, 9, " 9600 ", BAUD_9600);
-
- RADIO_CONTROL *line = new RADIO_CONTROL(35, 1, 17, 4, " LINE ", WOF_BORDER);
- *line
- + new RADIO_BUTTON(2, 1, 13, " Enabled ", LINE_ENABLED, WOS_SELECTED)
- + new RADIO_BUTTON(2, 2, 13, " Disabled ", LINE_DISABLED);
-
- // Create the communication window.
- UIW_WINDOW *window = new UIW_WINDOW(5, 5, 56, 14);
-
- *window
- + new UIW_BORDER
- + new UIW_MAXIMIZE_BUTTON
- + new UIW_MINIMIZE_BUTTON
- + new UIW_SYSTEM_BUTTON
- + new UIW_TITLE("Communication Setup")
- + port
- + baudRate
- + line
- + new UIW_BUTTON(14, 10, 10, "~OK", BTF_NO_TOGGLE | BTF_AUTO_SIZE,
- WOF_BORDER | WOF_JUSTIFY_CENTER, Exit, L_EXIT)
- + new UIW_BUTTON(28, 10, 10, "~Cancel", BTF_NO_TOGGLE | BTF_AUTO_SIZE,
- WOF_BORDER | WOF_JUSTIFY_CENTER, NULL, S_CONTINUE);
-
- // Add the window to the window manager.
- windowManager + window;
-
- // Wait for user response.
- int ccode;
- do
- {
- // Get input from the user.
- UI_EVENT event;
- eventManager.Get(event, Q_NORMAL);
-
- // Send event information to the window manager.
- ccode = windowManager.Event(event);
- } while (ccode != L_EXIT && ccode != S_NO_OBJECT);
-
- // Clean up.
- windowManager.UI_WINDOW_MANAGER::~UI_WINDOW_MANAGER();
- eventManager.UI_EVENT_MANAGER::~UI_EVENT_MANAGER();
- delete display;
- return (0);
- }
-
-