Skip to content

Commit 854bde5

Browse files
committed
[[ Cocoa ]] Initial work on popup menus.
1 parent 72d16a0 commit 854bde5

3 files changed

Lines changed: 137 additions & 1 deletion

File tree

engine/src/button.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class MCButton : public MCControl
117117
uint2 labelwidth;
118118
uint2 family;
119119
#ifdef _MAC_DESKTOP
120-
short bMenuID;
120+
MCPlatformMenuRef m_system_menu;
121121
#endif
122122

123123
uint1 mymenudepth;

engine/src/desktop-menu.cpp

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,144 @@ class MCMenuBuilderCallback: public IParseMenuCallback
321321

322322
void MCButton::macopenmenu(void)
323323
{
324+
if (m_system_menu == nil)
325+
return;
326+
327+
MCRectangle trect;
328+
long result;
329+
330+
int4 tmenux,tmenuy;
331+
tmenux = tmenuy = 0;
332+
switch (menumode)
333+
{
334+
case WM_COMBO:
335+
case WM_OPTION:
336+
trect = MCU_recttoroot(MCmousestackptr, rect);
337+
tmenux = trect.x;
338+
tmenuy = trect.y;
339+
break;
340+
case WM_PULLDOWN:
341+
trect = MCU_recttoroot(MCmousestackptr, rect);
342+
tmenux = trect.x;
343+
tmenuy = trect.y+trect.height + 1;
344+
break;
345+
case WM_CASCADE:
346+
trect = MCU_recttoroot(MCmousestackptr, rect);
347+
tmenux = trect.x + trect.width + 1;
348+
tmenuy = trect.y;
349+
break;
350+
case WM_POPUP:
351+
default:
352+
trect.x = MCmousex + 1;
353+
trect.y = MCmousey + 1;
354+
trect = MCU_recttoroot(MCmousestackptr, trect);
355+
tmenux = trect.x;
356+
tmenuy = trect.y;
357+
break;
358+
}
359+
360+
// MW-2007-12-11: [[ Bug 5670 ]] Make sure we notify things higher up in the call chain
361+
// that the mdown actually did result in a menu being popped up!
362+
extern bool MCosxmenupoppedup;
363+
MCosxmenupoppedup = true;
364+
365+
switch (menumode)
366+
{
367+
case WM_COMBO:
368+
case WM_OPTION:
369+
#if 0
370+
//= MAC's pop-up menu, displayed at the control/button location
371+
layer_redrawall();
372+
if (MCModeMakeLocalWindows())
373+
result = PopUpMenuSelect(mh, tmenuy, tmenux, menuhistory);
374+
else
375+
result = MCModePopUpMenu((MCMacSysMenuHandle)mh, tmenux - trect . x + rect . x, tmenuy - trect . y + rect . y, menuhistory, MCmousestackptr);
376+
allowmessages(False);
377+
pms->clearmdown(menubutton);
378+
allowmessages(True);
379+
if (result > 0)
380+
{
381+
setmenuhistoryprop(LoWord(result));
382+
//low word of result from PopUpMenuSelect() is the item selected
383+
//high word contains the menu id
384+
MCString slabel;
385+
getmacmenuitemtext(mh, menuhistory, slabel, False, hasunicode());
386+
delete label;
387+
label = (char *)slabel.getstring();
388+
labelsize = slabel.getlength();
389+
flags |= F_LABEL;
390+
Exec_stat es = message_with_args(MCM_menu_pick, slabel);
391+
if (es == ES_NOT_HANDLED || es == ES_PASS)
392+
message_with_args(MCM_mouse_up, menubutton);
393+
}
394+
else
395+
message_with_args(MCM_mouse_release, menubutton);
396+
state &= ~(CS_MFOCUSED | CS_ARMED | CS_HILITED);
397+
layer_redrawall();
398+
#endif
399+
result = MCPlatformPopUpMenu(m_system_menu, MCmousestackptr -> getwindow(), , tmenux - trect . x + rect . x, tmenuy - trect . y + rect . y, menuhistory);
400+
if (result > 0)
401+
{
402+
}
403+
break;
404+
case WM_PULLDOWN:
405+
case WM_CASCADE:
406+
case WM_POPUP: //= MAC's context menu, Menu displyed at the mouse loc
407+
if (MCModeMakeLocalWindows())
408+
result = PopUpMenuSelect(mh, tmenuy, tmenux, 0);
409+
else
410+
{
411+
int32_t x, y;
412+
if (menumode == WM_POPUP)
413+
{
414+
x = MCmousex + 1;
415+
y = MCmousey + 1;
416+
}
417+
else
418+
{
419+
x = tmenux - trect . x + rect . x;
420+
y = tmenuy - trect . y + rect . y;
421+
}
422+
423+
result = MCModePopUpMenu((MCMacSysMenuHandle)mh, x, y, 0, MCmousestackptr);
424+
}
425+
allowmessages(False);
426+
pms->clearmdown(menubutton);
427+
allowmessages(True);
428+
if (result > 0)
429+
{ //user selected something
430+
MenuHandle mhandle = GetMenuHandle(HiWord(result));
431+
setmenuhistoryprop(LoWord(result));
432+
MCString smenustring;
433+
getmacmenuitemtext(mhandle, menuhistory, smenustring, mhandle != mh, hasunicode());
434+
Exec_stat es = message_with_args(MCM_menu_pick, smenustring);
435+
delete (char *)smenustring.getstring();
436+
if (es == ES_NOT_HANDLED || es == ES_PASS)
437+
message_with_args(MCM_mouse_up, menubutton);
438+
}
439+
state &= ~(CS_MFOCUSED | CS_ARMED | CS_HILITED);
440+
break;
441+
default:
442+
break;
443+
}
444+
445+
// MW-2011-02-08: [[ Bug 9384 ]] Free the Mac menu after use since we don't need
446+
// it lingering around.
447+
if (bMenuID != 0)
448+
{
449+
MCScreenDC *pms = (MCScreenDC *)MCscreen;
450+
pms->freeMenuAndID(bMenuID, this);
451+
bMenuID = 0;
452+
}
324453
}
325454

326455
void MCButton::macfreemenu(void)
327456
{
457+
if (m_system_menu != nil)
458+
{
459+
MCPlatformReleaseMenu(m_system_menu);
460+
m_system_menu = nil;
461+
}
328462
}
329463

330464
Bool MCButton::macfindmenu(bool p_just_for_accel)

engine/src/mac-pasteboard.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
{ (NSString *)kUTTypeGIF, kMCPlatformPasteboardFlavorGIF, MCMacPasteboardConvertIdentity },
5252
{ (NSString *)kUTTypePNG, kMCPlatformPasteboardFlavorPNG, MCMacPasteboardConvertIdentity },
5353
{ (NSString *)kUTTypeTIFF, kMCPlatformPasteboardFlavorPNG, MCMacPasteboardConvertTIFFToPNG },
54+
55+
// COCOA-TODO: Declare these appropriately!
5456
{ @"com.runrev.livecode.objects-1", kMCPlatformPasteboardFlavorObjects, MCMacPasteboardConvertIdentity },
5557
{ @"com.runrev.livecode.text-styled-1", kMCPlatformPasteboardFlavorStyledText, MCMacPasteboardConvertIdentity },
5658
};

0 commit comments

Comments
 (0)