Skip to content

Commit

Permalink
Refactoring the navigator. Moved GetDoubleClickTime() to the inspecto…
Browse files Browse the repository at this point in the history
…r and code editor classes.
  • Loading branch information
gkjpettet committed Jun 23, 2023
1 parent fb10cd0 commit 716ffd6
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 68 deletions.
8 changes: 4 additions & 4 deletions src/Demo Windows/Utilities/WinDictionary.xojo_window
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ End
#tag WindowCode
#tag MenuHandler
Function FileCloseWindow() As Boolean Handles FileCloseWindow.Action
Self.Hide
Return True
Self.Hide
Return True
End Function
#tag EndMenuHandler

Expand Down
7 changes: 4 additions & 3 deletions src/XUI.xojo_project
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ Class=DemoWindow;Demo Windows/DemoWindow.xojo_code;&h00000000332F57FF;&h00000000
Folder=Required;XUI/Required;&h0000000049AEC7FF;&h00000000569647FF;false
Folder=XUIUndo;XUI/Required/XUIUndo;&h0000000007567FFF;&h0000000049AEC7FF;false
Module=AppKit;XUI/Required/AppKit.xojo_code;&h000000003C9D27FF;&h0000000049AEC7FF;false
Class=XUISelectedColumns;XUI/Required/XUISelectedColumns.xojo_code;&h000000004A69B7FF;&h0000000049AEC7FF;false
Class=XUITextSelection;XUI/Required/XUITextSelection.xojo_code;&h0000000056C387FF;&h0000000049AEC7FF;false
Class=NSScrollViewCanvas;XUI/Required/NSScrollViewCanvas.xojo_code;&h0000000005FF5FFF;&h0000000049AEC7FF;false
Folder=Extensions;XUI/Required/Extensions;&h000000004A274FFF;&h0000000049AEC7FF;false
Module=XUIColorGroupExtensions;XUI/Required/Extensions/XUIColorGroupExtensions.xojo_code;&h000000005E4EF7FF;&h000000004A274FFF;false
Expand Down Expand Up @@ -82,7 +80,6 @@ Class=XUITagCanvasRendererWindows11;XUI/XUITagCanvas/TagCanvas Renderers/XUITagC
Class=XUITagAutocompleteData;XUI/XUITagCanvas/TagCanvas Autocompletion/XUITagAutocompleteData.xojo_code;&h000000007E0A67FF;&h000000000923B7FF;false
Class=XUITagAutocompleteOption;XUI/XUITagCanvas/TagCanvas Autocompletion/XUITagAutocompleteOption.xojo_code;&h0000000003081FFF;&h000000000923B7FF;false
Class=XUITagCanvasRendererMonterey;XUI/XUITagCanvas/TagCanvas Renderers/XUITagCanvasRendererMonterey.xojo_code;&h00000000064BF7FF;&h0000000045A3F7FF;false
Class=XUITextLine;XUI/Required/XUITextLine.xojo_code;&h000000007F00C7FF;&h0000000049AEC7FF;false
Folder=XUI Utilities;XUI/XUI Utilities;&h000000004E966FFF;&h00000000569647FF;false
Module=MarkdownKit;XUI/XUI Utilities/MarkdownKit.xojo_code;&h000000002F26BFFF;&h000000004E966FFF;false
Module=TOMLKit;XUI/XUI Utilities/TOMLKit.xojo_code;&h00000000350517FF;&h000000004E966FFF;false
Expand Down Expand Up @@ -287,6 +284,10 @@ Class=XUIInspectorStyle;XUI/XUIInspector/XUIInspectorStyle.xojo_code;&h000000001
Class=XUIInspectorTextFieldRenderer;XUI/XUIInspector/XUIInspectorTextFieldRenderer.xojo_code;&h000000003C0DC7FF;&h000000007F4C67FF;false
Class=XUIInspector;XUI/XUIInspector/XUIInspector.xojo_code;&h00000000706647FF;&h000000007F4C67FF;false
Class=XUICEObjoScriptFormatter;XUI/XUICodeEditor/Code Editor Formatters/XUICEObjoScriptFormatter.xojo_code;&h00000000490E5FFF;&h000000000E9FB7FF;false
Folder=Text UI Classes;XUI/Required/Text UI Classes;&h000000001243C7FF;&h0000000049AEC7FF;false
Class=XUISelectedColumns;XUI/Required/Text UI Classes/XUISelectedColumns.xojo_code;&h000000004A69B7FF;&h000000001243C7FF;false
Class=XUITextSelection;XUI/Required/Text UI Classes/XUITextSelection.xojo_code;&h0000000056C387FF;&h000000001243C7FF;false
Class=XUITextLine;XUI/Required/Text UI Classes/XUITextLine.xojo_code;&h000000007F00C7FF;&h000000001243C7FF;false
AppMenuBar=BasicMenuBar
MajorVersion=2
MinorVersion=3
Expand Down
File renamed without changes.
File renamed without changes.
99 changes: 42 additions & 57 deletions src/XUI/Required/XUI.xojo_code
Original file line number Diff line number Diff line change
@@ -1,62 +1,5 @@
#tag Module
Protected Module XUI
#tag Method, Flags = &h1, Description = 52657475726E7320746865206E756D626572206F66207469636B7320746861742074776F20636C69636B73206D757374206F636375722077697468696E20746F20626520636F6E73696465726564206120646F75626C6520636C69636B2E
Protected Function GetDoubleClickTimeTicks() As Integer
/// Returns the number of ticks that two clicks must occur within to be considered a double click.

// Choose a reasonable default in case any of the declares fail.
Const DEFAULT_TICKS = 30 // 30 ticks = 500ms

Var doubleClickTime As Integer

#If TargetMacOS
Const CocoaLib As String = "Cocoa.framework"
Declare Function NSClassFromString Lib CocoaLib(aClassName As CFStringRef) As Ptr
Declare Function doubleClickInterval Lib CocoaLib Selector "doubleClickInterval" (aClass As Ptr) As Double
Try
Var RefToClass As Ptr = NSClassFromString("NSEvent")
doubleClickTime = doubleClickInterval(RefToClass) * 60
Catch err As ObjCException
doubleClickTime = DEFAULT_TICKS
End Try
#EndIf

#If TargetWindows Then
Try
Declare Function GetDoubleClickTime Lib "User32.DLL" () As Integer
doubleClickTime = GetDoubleClickTime()
// `doubleClickTime` now holds the number of milliseconds - convert to ticks.
doubleClickTime = doubleClickTime / 1000.0 * 60
Catch e
doubleClickTime = DEFAULT_TICKS
End Try
#EndIf

#If TargetLinux Then
Const libname = "libgtk-3"
Soft Declare Function gtk_settings_get_default Lib libname () As Ptr
Soft Declare Sub g_object_get Lib libname (Obj As Ptr, first_property_name As CString, ByRef doubleClicktime As Integer, Null As Integer)
If Not system.IsFunctionAvailable ("gtk_settings_get_default", libname) Then
doubleClickTime = DEFAULT_TICKS
Else
Var gtkSettings As Ptr = gtk_settings_get_default()
g_object_get (gtkSettings, "gtk-double-click-time", doubleClickTime, 0)
// `doubleClickTime` now holds the number of milliseconds - convert to ticks.
doubleClickTime = doubleClickTime / 1000.0 * 60
End If
#EndIf

// Catch any other platforms.
If doubleClickTime <= 0 Then
doubleClickTime = DEFAULT_TICKS
End If

Return doubleClickTime

End Function
#tag EndMethod


#tag Note, Name = About
A required module that includes utility methods and enumerations used within the framework.

Expand All @@ -71,5 +14,47 @@ Protected Module XUI
#tag EndEnum


#tag ViewBehavior
#tag ViewProperty
Name="Name"
Visible=true
Group="ID"
InitialValue=""
Type="String"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Index"
Visible=true
Group="ID"
InitialValue="-2147483648"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Super"
Visible=true
Group="ID"
InitialValue=""
Type="String"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Left"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Top"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag EndViewBehavior
End Module
#tag EndModule
60 changes: 58 additions & 2 deletions src/XUI/XUICodeEditor/XUICodeEditor.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,62 @@ Implements XUINotificationListener
End Sub
#tag EndMethod

#tag Method, Flags = &h21, Description = 52657475726E7320746865206E756D626572206F66207469636B7320746861742074776F20636C69636B73206D757374206F636375722077697468696E20746F20626520636F6E73696465726564206120646F75626C6520636C69636B2E
Private Function GetDoubleClickTimeTicks() As Integer
/// Returns the number of ticks that two clicks must occur within to be considered a double click.

// Choose a reasonable default in case any of the declares fail.
Const DEFAULT_TICKS = 30 // 30 ticks = 500ms

Var doubleClickTime As Integer

#If TargetMacOS
Const CocoaLib As String = "Cocoa.framework"
Declare Function NSClassFromString Lib CocoaLib(aClassName As CFStringRef) As Ptr
Declare Function doubleClickInterval Lib CocoaLib Selector "doubleClickInterval" (aClass As Ptr) As Double
Try
Var RefToClass As Ptr = NSClassFromString("NSEvent")
doubleClickTime = doubleClickInterval(RefToClass) * 60
Catch err As ObjCException
doubleClickTime = DEFAULT_TICKS
End Try
#EndIf

#If TargetWindows Then
Try
Declare Function GetDoubleClickTime Lib "User32.DLL" () As Integer
doubleClickTime = GetDoubleClickTime()
// `doubleClickTime` now holds the number of milliseconds - convert to ticks.
doubleClickTime = doubleClickTime / 1000.0 * 60
Catch e
doubleClickTime = DEFAULT_TICKS
End Try
#EndIf

#If TargetLinux Then
Const libname = "libgtk-3"
Soft Declare Function gtk_settings_get_default Lib libname () As Ptr
Soft Declare Sub g_object_get Lib libname (Obj As Ptr, first_property_name As CString, ByRef doubleClicktime As Integer, Null As Integer)
If Not system.IsFunctionAvailable ("gtk_settings_get_default", libname) Then
doubleClickTime = DEFAULT_TICKS
Else
Var gtkSettings As Ptr = gtk_settings_get_default()
g_object_get (gtkSettings, "gtk-double-click-time", doubleClickTime, 0)
// `doubleClickTime` now holds the number of milliseconds - convert to ticks.
doubleClickTime = doubleClickTime / 1000.0 * 60
End If
#EndIf

// Catch any other platforms.
If doubleClickTime <= 0 Then
doubleClickTime = DEFAULT_TICKS
End If

Return doubleClickTime

End Function
#tag EndMethod

#tag Method, Flags = &h21, Description = 48616E646C657320746865207072657373696E67206F6620746865206175746F636F6D706C657465206B65792E
Private Sub HandleAutocompleteKeyPress()
/// Handles the pressing of the autocomplete key.
Expand Down Expand Up @@ -1729,7 +1785,7 @@ Implements XUINotificationListener
currentClickTicks = System.Ticks

// Did the two clicks happen close enough together in time?
If (currentClickTicks - mLastClickTicks) <= XUI.GetDoubleClickTimeTicks Then
If (currentClickTicks - mLastClickTicks) <= GetDoubleClickTimeTicks Then
// Did they happen close enough together in space?
If Abs(x - mLastMouseUpX) <= SPACE_DELTA And Abs(y - mLastMouseUpY) <= SPACE_DELTA Then
// A double click has occurred.
Expand Down Expand Up @@ -1790,7 +1846,7 @@ Implements XUINotificationListener
Var doubleClickTime, currentClickTicks As Integer
Var result As Boolean = False

doubleClickTime = XUI.GetDoubleClickTimeTicks
doubleClickTime = GetDoubleClickTimeTicks
currentClickTicks = System.Ticks

// Did the three clicks happen close enough together in time?
Expand Down
60 changes: 58 additions & 2 deletions src/XUI/XUIInspector/XUIInspector.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,62 @@ Inherits NSScrollViewCanvas
End Sub
#tag EndMethod

#tag Method, Flags = &h21, Description = 52657475726E7320746865206E756D626572206F66207469636B7320746861742074776F20636C69636B73206D757374206F636375722077697468696E20746F20626520636F6E73696465726564206120646F75626C6520636C69636B2E
Private Function GetDoubleClickTimeTicks() As Integer
/// Returns the number of ticks that two clicks must occur within to be considered a double click.

// Choose a reasonable default in case any of the declares fail.
Const DEFAULT_TICKS = 30 // 30 ticks = 500ms

Var doubleClickTime As Integer

#If TargetMacOS
Const CocoaLib As String = "Cocoa.framework"
Declare Function NSClassFromString Lib CocoaLib(aClassName As CFStringRef) As Ptr
Declare Function doubleClickInterval Lib CocoaLib Selector "doubleClickInterval" (aClass As Ptr) As Double
Try
Var RefToClass As Ptr = NSClassFromString("NSEvent")
doubleClickTime = doubleClickInterval(RefToClass) * 60
Catch err As ObjCException
doubleClickTime = DEFAULT_TICKS
End Try
#EndIf

#If TargetWindows Then
Try
Declare Function GetDoubleClickTime Lib "User32.DLL" () As Integer
doubleClickTime = GetDoubleClickTime()
// `doubleClickTime` now holds the number of milliseconds - convert to ticks.
doubleClickTime = doubleClickTime / 1000.0 * 60
Catch e
doubleClickTime = DEFAULT_TICKS
End Try
#EndIf

#If TargetLinux Then
Const libname = "libgtk-3"
Soft Declare Function gtk_settings_get_default Lib libname () As Ptr
Soft Declare Sub g_object_get Lib libname (Obj As Ptr, first_property_name As CString, ByRef doubleClicktime As Integer, Null As Integer)
If Not system.IsFunctionAvailable ("gtk_settings_get_default", libname) Then
doubleClickTime = DEFAULT_TICKS
Else
Var gtkSettings As Ptr = gtk_settings_get_default()
g_object_get (gtkSettings, "gtk-double-click-time", doubleClickTime, 0)
// `doubleClickTime` now holds the number of milliseconds - convert to ticks.
doubleClickTime = doubleClickTime / 1000.0 * 60
End If
#EndIf

// Catch any other platforms.
If doubleClickTime <= 0 Then
doubleClickTime = DEFAULT_TICKS
End If

Return doubleClickTime

End Function
#tag EndMethod

#tag Method, Flags = &h21, Description = 536574732060706F7075704D656E756020746F206265207468652063757272656E746C792061637469766520706F707570206D656E7520696E2074686520696E73706563746F722E2048616E646C657320636C6F73696E6720616E206578697374696E6720706F707570206D656E752028696620616E79292E20526564726177732074686520696E73706563746F722E
Private Sub HandleNewPopupMenu(popupMenu As XUIInspectorItemPopupMenu)
/// Sets `popupMenu` to be the currently active popup menu in the inspector.
Expand Down Expand Up @@ -534,7 +590,7 @@ Inherits NSScrollViewCanvas
currentClickTicks = System.Ticks

// Did the two clicks happen close enough together in time?
If (currentClickTicks - mLastClickTicks) <= XUI.GetDoubleClickTimeTicks Then
If (currentClickTicks - mLastClickTicks) <= GetDoubleClickTimeTicks Then
// Did they happen close enough together in space?
If Abs(x - mLastMouseUpX) <= SPACE_DELTA And Abs(y - mLastMouseUpY) <= SPACE_DELTA Then
// A double click has occurred.
Expand Down Expand Up @@ -563,7 +619,7 @@ Inherits NSScrollViewCanvas
Var doubleClickTime, currentClickTicks As Integer
Var result As Boolean = False

doubleClickTime = XUI.GetDoubleClickTimeTicks
doubleClickTime = GetDoubleClickTimeTicks
currentClickTicks = System.Ticks

// Did the three clicks happen close enough together in time?
Expand Down

0 comments on commit 716ffd6

Please sign in to comment.