[futurebasic] Re: [FB] Contextual Menu

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 2004 : Group Archive : Group : All Groups

From: Robert Covington <artlythere@...>
Date: Thu, 23 Sep 2004 00:26:54 -0400
On Wednesday, September 22, 2004, at 10:57  PM, Brian Heibert wrote:

> I have a menu resource that I want to use as a contextual menu in my
> program.  My program has a window with a edit field that fills up the
> window.
>
> Are there any examples out there on how to do this?
>
> Brian

Not sure how to use a menu resource (tired right now, and fading), but 
here's an example of a manually built one...control click to bring up 
the menu.


// NETE Macro App Shell
// Robert Covington


Begin Globals
dim gQuit as int
End Globals

Begin Enum 1
_wWindow1
end Enum

Begin Enum 1
_mFile
_mEdit
_mOther
end Enum

Begin Enum
_mFileTitleItem
_mfileOpenItem
_mfileCloseItem
_mfileNullItem
_mfileQuitItem
end Enum


_PopClickMenu          = 150
_kCMHelpItemRemoveHelp = 3

// Bernie aided me with this here widget
'~';
clear local
dim enableRemove
local fn PopControlClickedMenu(wnd as long , pt as point)
dim @ selectionType  as long
DIm as long    @lNumber         , dirID
dim @ menuID         as short
DIM @fontNum         as short
dim @ menuItem       as short
dim @ r              as rect
dim mHndl            as Handle
dim err              as OSStatus
dim helpItemString   as Str255
dim where            as Point
DIM OSErr            as OSErr
dim                  as int insert,i
'~'1

mHndl = fn NewMenu(_PopClickMenu, "")
  InsertMenu(mHndl, -1)
helpItemString = ""

AppendMenu(mHndl, "Item 1")
AppendMenu(mHndl, "Item 2")
AppendMenu(mHndl, "Item 3")

'~';
// could set to always pop in the same place here
where.h% = pt.h%
where.v% = pt.v%
localtoGlobal(where)
'~';
long if mHndl
err   = fn ContextualMenuSelect(mHndl, #where , _nil, 
_kCMHelpItemRemoveHelp, @helpItemString, #_nil, @selectionType, 
@menuID, @menuItem)

select menuID
case _PopClickmenu
select menuItem
case 1

case 2
  beep
case 3

end select

end select

end if


deleteMenu(_PopClickMenu)


end fn



local fn BuildWindow
dim as Str255              s
dim as ControlFontStyleRec cfs
dim as WindowAttributes    wa
dim as Rect                r
'~'1
cfs.flags = _kControlUseFontMask_kControlUseJustMask
wa = _kWindowCloseBoxAttribute¬
      _kWindowCollapseBoxAttribute¬
      _kWindowFullZoomAttribute¬
      _kWindowResizableAttribute


SetRect(r, 0, 0, 400 , 400)
appearance window -_wWindow1,¬
                   "Test Window", @r,¬
                   _kDocumentWindowClass, wa
def SetWindowBackground(_kThemeActiveDialogBackgroundBrush, _zTrue)
'~'1

appearance window _wWindow1

end fn


Local FN OpenSomeFile
dim fName$
dim oSpec as FSSpec

fName$ = Files$(_FSSpecOpenPreview,"TEXTPICT","Choose a file...", oSpec 
)
long if len(fName$)
// Good File return
Open "I",#1,@oSpec
// Read it
close #1
end if

end fn

local fn DoDialog
dim as long evnt, id
dim as point pt
'~'1
evnt = dialog(0)
id = dialog(evnt)
select evnt
case _cntxtMenuClick
GetMouse(pt)
fn PopControlClickedMenu(id, pt )
case _wndClick
window id
case _wndClose
window close id
case _wndRefresh
case _wndResized
case _wndActivate
case _btnClick
case _preview
select id
case _preMenuClick
case _preWndGrow
end select
end select
end fn

Local FN DoMouse
Dim mFunc
mFunc = Mouse(0)
select mFunc
case _click1NDrag
case else
beep
end Select
end fn



Local Fn DoMenu
Dim as int menuID,itemID
menuID = Menu(_menuID)
itemID = Menu(_itemID)
Select menuID
Case _mFile
Select itemID
Case _mFileOpenItem
FN OpenSomeFile
Case _mFileCloseItem
Window Close _wWindow1
case _mFileQuitItem
gQuit = _True
End Select
Case _mEdit
Select itemID
Case 1
Case 2
case 3
End Select
Case _mOther
Select itemID
Case 1
Case 2
case 3
End Select
End Select
Menu
End fn


Local Fn Init_Menus

Menu _mFile, _mFileTitleItem , _Enable , "File"
Menu _mFile, _mfileOpenItem  , _Enable , "Open.../O"
Menu _mFile, _mfileCloseItem , _Enable , "Close/W"
Menu _mFile, _mfileNullItem  , _Enable , "-"
Menu _mFile, _mfileQuitItem  , _Enable , "Quit/Q"

End fn

'~';
"MAIN"
'~';

Fn Init_Menus
fn BuildWindow

on Dialog Fn DoDialog
On Menu   Fn DoMenu
on Mouse  Fn DoMouse

do
HandleEvents
until gQuit