Page 1 of 1

GetMouse for SkinWin, double popup

Posted: Mon Jul 03, 2006 12:02 pm
by oryaaaaa
Code updated for 5.20+

This forgot contributing by the code that I wrote two years ago.
This is useful for multiusing two or more Window and two or more Gadget.

Target
SkinWin, double PopupDisplay

Code: Select all

Enumeration
  #Window_0
  #MenuBar_0
  #MenuBar_1
  #MENU_1
  #MENU_2
  #Editor_0
  #Editor_1
EndEnumeration

Procedure GetMouse(Gadget) 
  GetCursorPos_(mouse.POINT) 
  MapWindowPoints_(0,GadgetID(Gadget),mouse,1) 
  x = mouse\x : y =  mouse\y 
  xx = GadgetWidth(Gadget) : yy=GadgetHeight(Gadget)
  If x >= 0 And x <= xx And y >= 0 And y <= yy
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf 
EndProcedure 

Procedure GetMouse2(Gadget) 
  GetCursorPos_(mouse.POINT) 
  MapWindowPoints_(0,WindowID(Gadget),mouse,1) 
  x = mouse\x : y =  mouse\y 
  xx = WindowWidth(Gadget)  : yy=WindowHeight(Gadget) 
  If x >= 0 And x <= xx And y >= 0 And y <= yy 
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf 
EndProcedure 

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 216, 0, 449, 289, "New window ( 0 )",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    If CreatePopupMenu(#MenuBar_0)
      MenuItem(#MENU_1, "MENU")
    EndIf
    If CreatePopupMenu(#MenuBar_1)
      MenuItem(#MENU_2, "SAVE")
    EndIf 
    EditorGadget(#Editor_0, 10, 10, 220, 270)
    EditorGadget(#Editor_1, 240, 10, 200, 270)
  EndIf
EndProcedure

MessageRequester("Trouble", "This example cannot distinguish for which editor to show the popup for and can get them mixed up. ", #MB_OK|#MB_ICONINFORMATION)
  
Open_Window_0()  
Repeat
  Event = WaitWindowEvent() : WindowID = EventWindow()
  GadgetID = EventGadget() :EventType = EventType()
  If Event=#WM_RBUTTONDOWN
    If GadgetID=#Editor_0
      DisplayPopupMenu(#MenuBar_0, WindowID(#Window_0))
    ElseIf GadgetID=#Editor_1
      DisplayPopupMenu(#MenuBar_1, WindowID(#Window_0))
    EndIf
  EndIf 
Until Event = #PB_Event_CloseWindow 
CloseWindow(#Window_0)

MessageRequester("This Tricks", "This example shows a different pop-up menu for each editor. ", #MB_OK|#MB_ICONINFORMATION) 

Open_Window_0()  
Repeat
  Event = WaitWindowEvent() : WindowID = EventWindow()
  GadgetID = EventGadget() :EventType = EventType()
  If Event=#WM_RBUTTONDOWN
    If GetMouse(#Editor_0)
      DisplayPopupMenu(#MenuBar_0, WindowID(#Window_0))
    ElseIf GetMouse(#Editor_1)
      DisplayPopupMenu(#MenuBar_1, WindowID(#Window_0))
    EndIf
  EndIf 
Until Event = #PB_Event_CloseWindow 
CloseWindow(#Window_0)

End

Posted: Thu Jul 13, 2006 10:41 am
by oryaaaaa
for Scintilla

Code: Select all

Procedure GetMouse3(gadget) ;wnd Handle (ex: SCIView_Main)
  Protected mouse.POINT, x.l , y.l , pos.RECT , xx.l , yy.l
  GetCursorPos_(mouse.POINT)
  MapWindowPoints_(0,gadget,mouse,1)
  x = mouse\x : y =  mouse\y
  GetWindowRect_(gadget, pos.RECT)
  xx = pos\right - pos\left  : yy=pos\bottom - pos\top
  If x >= 0 And x <xx>= 0 And y <yy>0
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf
EndProcedure 

Code: Select all

  If event=#WM_RBUTTONDOWN
    If GetMouse(#Tree_Files) And CountGadgetItems(#Tree_Files)>0 
      DisplayPopupMenu(#PopupMenu_Tree, WindowID(#Window_okiraku))
      ;- POPUP
    ElseIf GetMouse3(SCIViewHandle_Main)
      SCI_UseGadget(SCIViewHandle_Main)
      PopupMenu_Main_str. s = Space( SCI_GetSelectionEnd()-SCI_GetSelectionStart()+1  )
      SCI_GetSelText(@PopupMenu_Main_str)
      PopupMenu_Main_str = Left( PopupMenu_Main_str , 32)
      If PopupMenu_Main_str=""
        DisableMenuItem(#PopupMenu_Main, #PopupMenu_Main_AllSearch, #True)
        DisableMenuItem(#PopupMenu_Main, #PopupMenu_Main_Search, #True)
      Else
        DisableMenuItem(#PopupMenu_Main, #PopupMenu_Main_AllSearch, #False)
        DisableMenuItem(#PopupMenu_Main, #PopupMenu_Main_Search, #False) 
      EndIf
        SetMenuItemText(#PopupMenu_Main, #PopupMenu_Main_AllSearch, Chr(34)+PopupMenu_Main_str +Chr(34)+Space(3)+ "All File Search")
      SetMenuItemText(#PopupMenu_Main, #PopupMenu_Main_Search, Chr(34)+PopupMenu_Main_str +Chr(34)+Space(3)+ "Edit Search")
      DisplayPopupMenu(#PopupMenu_Main, WindowID(#Window_okiraku))
    EndIf
    
  EndIf