Category : Files from Magazines
Archive   : DFLAT4UD.ZIP
Filename : MENUBAR.C

 
Output of file : MENUBAR.C contained in archive : DFLAT4UD.ZIP
/* ---------------- menubar.c -------------- */

#include
#include
#include
#include
#include
#include "dflat.h"

static void reset_menubar(WINDOW);
static int TestGlobalKeys(WINDOW, PARAM, PARAM);

static char *menubar;

static struct {
int x1, x2; /* position in menu bar */
char sc; /* shortcut key value */
} menu[10];
static int mctr;

MENU *ActiveMenu = NULL;
int ActiveSelection = -1;
WINDOW MenuBar = NULLWND;

static WINDOW mwnd = NULL;

int MenuBarProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int offset = 3, wd, offset1, i, j;
int mx = (int) p1 - GetLeft(wnd);
MENU *mnu;
int rtn;
static AltDown = FALSE;

switch (msg) {
case CREATE_WINDOW:
MenuBar = wnd;
reset_menubar(wnd);
break;
case SETFOCUS:
rtn = BaseWndProc(MENUBAR, wnd, msg, p1, p2);
if ((int) p1) {
if (ActiveSelection == -1)
ActiveSelection = 0;
if (inFocus == wnd)
SendMessage(wnd, PAINT, 0, 0);
}
else
SendMessage(wnd, PAINT, 0, 0);
return rtn;
case COMMAND:
ActiveSelection = -1;
SetPrevFocus(wnd);
PostMessage(GetParent(wnd), msg, p1, p2);
return FALSE;
case BUILDMENU:
reset_menubar(wnd);
mctr = 0;
ActiveMenu = (MENU *) p1;
while (ActiveMenu->Title != NULL) {
char *cp;
menubar = realloc(menubar, strlen(menubar)+5);
memmove(menubar + offset+4, menubar + offset, strlen(menubar)-offset+1);
CopyCommand(menubar+offset, ActiveMenu->Title, FALSE, cfg.clr.MenuBarBG);
menu[mctr].x1 = offset;
offset += strlen(ActiveMenu->Title) + (3+MSPACE);
menu[mctr].x2 = offset-MSPACE;
cp = strchr(ActiveMenu->Title, SHORTCUTCHAR);
if (cp)
menu[mctr].sc = tolower(*(cp+1));
ActiveMenu++;
mctr++;
}
ActiveMenu = (MENU *) p1;
break;
case PAINT:
if (!isVisible(wnd))
break;
SetStandardColor(wnd);
ClearAttribute(wnd, NOCLIP);

clipline(wnd, 0, menubar);
wputs(wnd, menubar, 0, 0);

AddAttribute(wnd, NOCLIP);
if (ActiveSelection != -1 &&
(wnd == inFocus || mwnd != NULLWND)) {
char sel[80], *cp;
offset = menu[ActiveSelection].x1;
offset1 = menu[ActiveSelection].x2;
menubar[offset1] = '\0';
SetReverseColor(wnd);
memset(sel, '\0', sizeof sel);
strcpy(sel, menubar+offset);
cp = strchr(sel, CHANGECOLOR);
if (cp != NULL)
*(cp + 2) = background | 0x80;
wputs(wnd, sel, offset-ActiveSelection*4, 0);
menubar[offset1] = ' ';
}
return FALSE;
case SHIFT_CHANGED:
if (mwnd == NULLWND) {
if ((int)p1 & ALTKEY)
AltDown = TRUE;
else if (AltDown)
SendMessage(wnd, KEYBOARD,
wnd == inFocus ? ESC : F10, 0);
}
return TRUE;
case KEYBOARD:
AltDown = FALSE;
if (mwnd == NULLWND) {
/* ----- search for menu bar shortcut keys ---- */
int c = tolower((int)p1);
int a = 0;
for (i = 0; i < 26; i++)
if ((char) p1 == altconvert[i])
break;
if (i < 26)
a = 'a' + i;
for (j = 0; j < mctr; j++) {
if (menu[j].sc == c || (a && menu[j].sc == a)) {
SendMessage(wnd, SELECTION, j, 0);
return FALSE;
}
}
}
/* -------- search for accelerator keys -------- */
mnu = ActiveMenu;
while (mnu->Title != NULL) {
struct PopDown *pd = mnu->Selections;
if (mnu->PrepMenu)
(*(mnu->PrepMenu))(GetParent(wnd), mnu);
while (pd->SelectionTitle != NULL) {
if (pd->Accelerator == (int) p1) {
if (pd->Attrib & INACTIVE)
beep();
else {
if (GetClass(inFocus) == MENUBAR)
SetPrevFocus(inFocus);
PostMessage(GetParent(wnd),
COMMAND, pd->ActionId, 0);
}
return TRUE;
}
pd++;
}
mnu++;
}
if (TestGlobalKeys(wnd, p1, p2))
return TRUE;

if ((mwnd == NULLWND || mwnd == (void *) -1) &&
(int)p1 == F1 && ActiveMenu) {
DisplayHelp(wnd, (ActiveMenu+ActiveSelection)->Title+1);
return TRUE;
}

switch ((int)p1) {
case '\r':
if (mwnd == NULLWND && ActiveSelection != -1)
SendMessage(wnd, SELECTION, ActiveSelection, 0);
break;
case ESC:
ActiveSelection = -1;
SetPrevFocus(wnd);
SendMessage(wnd, PAINT, 0, 0);
break;
case FWD:
ActiveSelection++;
if (ActiveSelection == mctr)
ActiveSelection = 0;
if (mwnd != NULLWND)
SendMessage(wnd, SELECTION, ActiveSelection, 0);
else
SendMessage(wnd, PAINT, 0, 0);
break;
case BS:
if (ActiveSelection == 0)
ActiveSelection = mctr;
--ActiveSelection;
if (mwnd != NULLWND)
SendMessage(wnd, SELECTION, ActiveSelection, 0);
else
SendMessage(wnd, PAINT, 0, 0);
break;
default:
break;
}
return FALSE;
case LEFT_BUTTON:
for (i = 0; i < mctr; i++)
if (mx >= menu[i].x1-4*i &&
mx <= menu[i].x2-4*i-5)
break;
if (i < mctr) {
if (i != ActiveSelection || mwnd == NULL) {
SendMessage(wnd, SELECTION, i, 0);
SendMessage(NULLWND, WAITMOUSE, 0, 0);
}
}
break;
case SELECTION:
if (mwnd && mwnd != (void *)-1)
SendMessage(mwnd, CLOSE_WINDOW, 0, 0);
mwnd = NULL;

ActiveSelection = (int) p1;
SendMessage(wnd, SETFOCUS, TRUE, 0);

offset = menu[ActiveSelection].x1 -
4 * ActiveSelection;

mnu = ActiveMenu+ActiveSelection;

if (mnu->PrepMenu != NULL)
(*(mnu->PrepMenu))(GetParent(wnd), mnu);

wd = MenuWidth(mnu->Selections);

if (offset > WindowWidth(wnd)-wd)
offset = WindowWidth(wnd)-wd;

if (mnu->Selections[0].SelectionTitle != NULL) {
mwnd = CreateWindow(POPDOWNMENU, NULL,
GetLeft(wnd)+offset, GetTop(wnd)+1,
MenuHeight(mnu->Selections),
wd,
NULL,
wnd,
NULL,
0);
#ifdef INCLUDE_SHADOWS
AddAttribute(mwnd, SHADOW);
#endif
SendMessage(mwnd, BUILD_SELECTIONS, (PARAM) mnu, 0);
SendMessage(mwnd, SETFOCUS, TRUE, 0);

break;
}
else
mwnd = (void *)-1;
SendMessage(wnd, PAINT, 0, 0);
break;
case BORDER:
return TRUE;
case INSIDE_WINDOW:
return InsideRect(p1, p2, WindowRect(wnd));
case CLOSE_POPDOWN:
if ((int)p1)
PostMessage(wnd, KEYBOARD, ESC, 0);
mwnd = NULLWND;
break;
case CLOSE_WINDOW:
rtn = BaseWndProc(MENUBAR, wnd, msg, p1, p2);
if (menubar != NULL) {
free(menubar);
menubar = NULL;
}
mctr = 0;
ActiveSelection = -1;
MenuBar = NULL;
ActiveMenu = NULL;
return rtn;
default:
break;
}
return BaseWndProc(MENUBAR, wnd, msg, p1, p2);
}

static void reset_menubar(WINDOW wnd)
{
menubar = realloc(menubar, SCREENWIDTH+5);
memset(menubar, ' ', SCREENWIDTH);
*(menubar+SCREENWIDTH-
(TestAttribute(GetParent(wnd), HASBORDER) ? 2 : 0)) = '\0';
}

static int TestGlobalKeys(WINDOW wnd, PARAM p1, PARAM p2)
{
switch ((int)p1) {
case F10:
if (MenuBar != NULLWND)
SendMessage(MenuBar, SETFOCUS, TRUE, 0);
return TRUE;
case ALT_F6:
if (GetClass(inFocus) != MENUBAR &&
GetClass(inFocus) != POPDOWNMENU)
do
SetNextFocus(inFocus);
while (GetClass(inFocus) == MENUBAR);
return TRUE;
#ifdef INCLUDE_SYSTEM_MENUS
case ALT_HYPHEN:
if (GetClass(inFocus) == POPDOWNMENU)
SendMessage(inFocus, CLOSE_WINDOW, 0, 0);
if (GetClass(GetParent(inFocus)) == APPLICATION)
BuildSystemMenu(GetParent(inFocus));
return TRUE;
case ' ':
if ((int)p2 & ALTKEY) {
if (GetClass(inFocus) == POPDOWNMENU)
SendMessage(inFocus, CLOSE_WINDOW, 0, 0);
if (GetClass(inFocus) != MENUBAR &&
TestAttribute(inFocus, TITLEBAR) &&
TestAttribute(inFocus, CONTROLBOX))
BuildSystemMenu(inFocus);
return TRUE;
}
break;
#endif
case CTRL_F4:
if (GetClass(inFocus) != MENUBAR) {
SendMessage(inFocus, CLOSE_WINDOW, 0, 0);
if (GetClass(inFocus) == MENUBAR)
SetPrevFocus(inFocus);
}
break;
case ALT_F4:
PostMessage(GetParent(wnd), CLOSE_WINDOW, 0, 0);
break;
default:
break;
}
return FALSE;
}



  3 Responses to “Category : Files from Magazines
Archive   : DFLAT4UD.ZIP
Filename : MENUBAR.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/