25#ifndef jwlua_fflua_customluawindow_h
26#define jwlua_fflua_customluawindow_h
28#include <unordered_map>
43 luabridge::LuaRef _handleCommand;
44 luabridge::LuaRef _textSelectionChanged;
45 luabridge::LuaRef _handleUpDownPressed;
46 luabridge::LuaRef _handleDataListSelect;
47 luabridge::LuaRef _handleDataListCheck;
48 luabridge::LuaRef _handleListDoubleClick;
49 luabridge::LuaRef _handleListEnterKey;
50 luabridge::LuaRef _handleCancelButtonPressed;
51 luabridge::LuaRef _handleOkButtonPressed;
52 luabridge::LuaRef _handleInitWindow;
53 luabridge::LuaRef _handleCloseWindow;
54 luabridge::LuaRef _handleActivate;
55 luabridge::LuaRef _handleTimer;
56 luabridge::LuaRef _handleDarkModeIsChanging;
57 luabridge::LuaRef _handleOSMenuCommandExecuted;
58 luabridge::LuaRef _scrollChanged;
59 luabridge::LuaRef _handleSaveRequest;
60 luabridge::LuaRef _handleMouseTrackingStarted;
61 luabridge::LuaRef _handleMouseTrackingStopped;
62 std::unordered_map<FCControl *, luabridge::LuaRef> _controlHandles;
63 std::function<void(lua_State *)> _disconnector;
64 bool _inErrorRecovery;
65#if OPERATING_SYSTEM == WINDOWS
66 std::unique_ptr<luabridge::LuaException> _forwardedException;
69 bool _RegisterHandler(luabridge::LuaRef &class_storage, luabridge::LuaRef &lua_callback_function)
71 if (!lua_callback_function.isFunction())
return false;
72 class_storage = lua_callback_function;
76#if OPERATING_SYSTEM == MAC_OS
77 bool ModelessCancelCanEscape()
const override {
return true; }
80 void WindowDestroyed()
override
82 if (_disconnector && !
IsModal())
83 _disconnector(_handleCommand.state());
88 auto _MakeLuaFunctionResult(
bool success)
90 if constexpr (std::is_void<RT>::value)
91 return std::pair(success,
static_cast<void*
>(
nullptr));
93 return std::pair(success, RT{});
96 template<
typename RT = void,
typename... Args>
97 auto CallLuaFunction(luabridge::LuaRef &luafunc,
FCControl *pControl, Args... args)
99 auto retval = _MakeLuaFunctionResult<RT>(
true);
100 if (!_inErrorRecovery && luafunc.isFunction())
104 luabridge::LuaResult result = [&]()
106 return pControl ? pControl->_LuaCallEventHandler(luafunc, LuaRun_ErrorFunction, args...)
107 : luafunc.callWithHandler(LuaRun_ErrorFunction, args...);
109 if (!result) result.raiseException();
110 if constexpr (!std::is_void<RT>::value)
112 if (result.size() > 0)
114 auto casted = result[0].cast<RT>();
116 retval.second = casted.value();
120 catch (luabridge::LuaException &e)
122 _inErrorRecovery =
true;
123 retval.first =
false;
124#if OPERATING_SYSTEM == WINDOWS
127 if (
IsModal() || luafunc == _handleInitWindow)
129 _forwardedException.reset(
new luabridge::LuaException(e));
130 if (luafunc == _handleCloseWindow || luafunc == _handleInitWindow)
136 LuaRun_ExceptionAbort(e);
138 LuaRun_ExceptionAbort(e);
145 template<
typename RT = void,
typename... Args>
146 auto CallLuaFunction(luabridge::LuaRef &luafunc, Args... args)
148 return CallLuaFunction<RT>(luafunc,
static_cast<FCControl*
>(
nullptr), args...);
162 _textSelectionChanged(L),
163 _handleUpDownPressed(L),
164 _handleDataListSelect(L),
165 _handleDataListCheck(L),
166 _handleListDoubleClick(L),
167 _handleListEnterKey(L),
168 _handleCancelButtonPressed(L),
169 _handleOkButtonPressed(L),
170 _handleInitWindow(L),
171 _handleCloseWindow(L),
174 _handleDarkModeIsChanging(L),
175 _handleOSMenuCommandExecuted(L),
177 _handleSaveRequest(L),
178 _handleMouseTrackingStarted(L),
179 _handleMouseTrackingStopped(L),
180 _disconnector(nullptr),
181 _inErrorRecovery(false)
184#ifndef DOXYGEN_SHOULD_IGNORE_THIS
185#if OPERATING_SYSTEM == WINDOWS
190 if (_forwardedException)
191 LuaRun_ExceptionAbort(*_forwardedException);
197 const char*
ClassName()
const override {
return "FCCustomLuaWindow"; }
243 FXWND hParent = GetFinaleMainWindow();
244#if OPERATING_SYSTEM == WINDOWS
245 const FCLuaScriptItem* pLuaScriptItem = GetControllingLuaScriptItem(_handleCommand.state());
274#if OPERATING_SYSTEM == MAC_OS
275 _FCWindowController_cocoa* pCocoaLink = _GetCocoaLink();
276 if (pCocoaLink) pCocoaLink->SetModelessCanBecomeMainWindow(
true);
282#ifndef DOXYGEN_SHOULD_IGNORE_THIS
284 void SetDisconnector(std::function<
void(lua_State *)> func)
285 { _disconnector = func; }
300 return _RegisterHandler(_handleCommand, lua_callback_function);
321 if (! lua_callback_function.isFunction())
return false;
322 auto it = _controlHandles.find(pControl);
323 if (it == _controlHandles.end())
324 _controlHandles.emplace(pControl, lua_callback_function);
326 it->second = lua_callback_function;
341 return _RegisterHandler(_textSelectionChanged, lua_callback_function);
355 return _RegisterHandler(_scrollChanged, lua_callback_function);
369 return _RegisterHandler(_handleSaveRequest, lua_callback_function);
383 return _RegisterHandler(_handleUpDownPressed, lua_callback_function);
397 return _RegisterHandler(_handleDataListSelect, lua_callback_function);
411 return _RegisterHandler(_handleDataListCheck, lua_callback_function);
425 return _RegisterHandler(_handleListDoubleClick, lua_callback_function);
439 return _RegisterHandler(_handleListEnterKey, lua_callback_function);
453 return _RegisterHandler(_handleCancelButtonPressed, lua_callback_function);
467 return _RegisterHandler(_handleOkButtonPressed, lua_callback_function);
481 return _RegisterHandler(_handleInitWindow, lua_callback_function);
495 return _RegisterHandler(_handleCloseWindow, lua_callback_function);
509 return _RegisterHandler(_handleActivate, lua_callback_function);
523 return _RegisterHandler(_handleTimer, lua_callback_function);
537 return _RegisterHandler(_handleDarkModeIsChanging, lua_callback_function);
556 return _RegisterHandler(_handleOSMenuCommandExecuted, lua_callback_function);
570 return _RegisterHandler(_handleMouseTrackingStarted, lua_callback_function);
584 return _RegisterHandler(_handleMouseTrackingStopped, lua_callback_function);
597 auto it = _controlHandles.find(pControl);
598 if (it == _controlHandles.end())
return false;
600 CallLuaFunction(it->second, pControl);
621 CallLuaFunction(_handleCommand, pControl);
635 CallLuaFunction(_textSelectionChanged, pControl);
648 CallLuaFunction(_scrollChanged, pControl);
660 auto [success, funcResult] = CallLuaFunction<bool>(_handleSaveRequest, pControl, character);
661 if (success && funcResult)
679 CallLuaFunction(_handleUpDownPressed, pControl, delta);
694 CallLuaFunction(_handleDataListSelect, pControl, lineindex);
710 CallLuaFunction(_handleDataListCheck, pControl, lineindex, checkstate);
721 CallLuaFunction(_handleListDoubleClick, pControl);
733 auto [success, funcResult] = CallLuaFunction<bool>(_handleListEnterKey, pControl);
734 if (success && funcResult)
747 auto [success, _] = CallLuaFunction(_handleCancelButtonPressed);
759 auto [success, _] = CallLuaFunction(_handleOkButtonPressed);
771 CallLuaFunction(_handleInitWindow);
780 auto [success, _] = CallLuaFunction(_handleCloseWindow);
794 CallLuaFunction(_handleActivate, activated);
806 CallLuaFunction(_handleTimer, timerID);
818 CallLuaFunction(_handleDarkModeIsChanging, isDarkMode);
831 CallLuaFunction(_handleOSMenuCommandExecuted, menuCommand, menuCommandType);
843 CallLuaFunction(_handleMouseTrackingStarted, pControl);
855 CallLuaFunction(_handleMouseTrackingStopped, pControl);
Base class for all other dialog/window classes.
Definition ff_dialogs.h:563
virtual void HandleDataListSelect(FCCtrlDataList *pControl, int lineindex)
Virtual handler method for when FCCtrlDataList selection state changes. Overwrite to provide function...
Definition ff_dialogs.h:1221
virtual void TextSelectionChanged(FCControl *pControl)
Virtual method that is called when the selected text on a FCCtrlTextEditor control changes.
Definition ff_dialogs.h:1157
virtual bool HandleCommand(FCControl *pControl)
Virtual method that is called when a user command occurs, such as a button press.
Definition ff_dialogs.h:1151
bool IsModal()
Returns true if the dialog currently is running in a modal state.
Definition ff_dialogs.h:800
virtual void HandleUpDownPressed(FCControl *pControl, int delta)
Virtual handler method for up/down arrow controls when they are clicked. Overwrite to provide functio...
Definition ff_dialogs.h:1212
virtual void CloseButtonPressed()
Virtual method that is called when a control with a "Close" action is pressed by the user.
Definition ff_dialogs.h:1110
virtual void HandleDataListCheck(FCCtrlDataList *pControl, int lineindex, bool checkstate)
Virtual handler method for when FCCtrlDataList check state changes (for data list controls with check...
Definition ff_dialogs.h:1232
virtual void CloseWindow()=0
Closes the window. Functionality is provided by the child classes.
virtual bool HandleListEnterKey(FCControl *pControl)
Called every time there's an enter key hit inside a data list or list box.
Definition ff_dialogs.h:1246
virtual void OSMenuCommandExecuted(EMENUID menuCommand, int menuCommandType)
Called after a menu command on the main menu tree is executed. This function is also called when keyb...
Definition ff_dialogs.h:1099
virtual void HandleActivate(bool activated)
Virtual method that is called when the window is activated or deactivated. Overwrite in child classes...
Definition ff_dialogs.h:1252
virtual void CancelButtonPressed()
Virtual handler method that is called when a control with a "Cancel" action is pressed by the user.
Definition ff_dialogs.h:1140
virtual void HandleListDoubleClick(FCControl *pControl)
Called every time there's a double-click inside a data list or list box.
Definition ff_dialogs.h:1238
virtual void DarkModeIsChanging(bool isDarkMode)
Called whenever Dark Mode changes. (Currently macOS only.)
Definition ff_dialogs.h:1089
virtual void MouseTrackingStarted(FCControl *pControl)
Virtual method that is called when a mouse tracking starts. Currently only supported fo FCCtrlSlider.
Definition ff_dialogs.h:1264
virtual void WindowDestroyed()
Called once just when the window/dialog has been destroyed.
Definition ff_dialogs.h:1083
virtual void HandleTimer(twobyte timerID)
Virtual handler method that is called on timer events. Overwrite in child classes.
Definition ff_dialogs.h:1249
virtual void MouseTrackingStopped(FCControl *pControl)
Virtual method that is called when a mouse tracking stops. Currently only supported fo FCCtrlSlider.
Definition ff_dialogs.h:1270
virtual bool HandleKeyboardCommand(FCControl *pControl, eUniChar16 character)
Virtual method that notifies when a keyboard command has been requested with the Command key (macOS) ...
Definition ff_dialogs.h:1193
virtual void InitWindow()
Called once just when the window/dialog has been created.
Definition finaleframework.cpp:26005
Base class for all UI controls in a dialog.
Definition ff_dialogs.h:1536
Class that handles a contol with multiple lines of data, arranged in columns.
Definition ff_dialogs.h:4292
Special FCCustomWindow child class, that provides the additional functionality to hook up JW Lua call...
Definition fflua_customluawindow.h:41
bool ShowModeless()
Displays the dialog box as a modeless window. The dialog must have been registered with finenv....
Definition fflua_customluawindow.h:239
bool HandleControlEvent(FCControl *pControl)
Virtual method that is called when an event occurs on a registered control.
Definition fflua_customluawindow.h:595
bool RegisterHandleCancelButtonPressed(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the CancelButtonPressed() event handler.
Definition fflua_customluawindow.h:451
bool RegisterDarkModeIsChanging(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the DarkModeIsChanging() event handler.
Definition fflua_customluawindow.h:535
bool RegisterHandleListEnterKey(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the HandleListEnterKey() event handler.
Definition fflua_customluawindow.h:437
bool RegisterScrollChanged(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the ScrollChanged() event handler.
Definition fflua_customluawindow.h:353
bool RegisterHandleListDoubleClick(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the HandleListDoubleClick() event handler.
Definition fflua_customluawindow.h:423
bool RegisterInitWindow(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the InitWindow() event handler.
Definition fflua_customluawindow.h:479
bool RegisterHandleControlEvent(FCControl *pControl, luabridge::LuaRef lua_callback_function)
Registers a Lua function to the HandleControlEvent() event handler.
Definition fflua_customluawindow.h:319
void HandleActivate(bool activated) override
Virtual handler method that is called when a window is activated or deactivated.
Definition fflua_customluawindow.h:791
const char * ClassName() const override
Returns the name of the class, for diagnostic purposes. This method MUST be overwritten in each child...
Definition fflua_customluawindow.h:197
bool RegisterHandleOkButtonPressed(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the OkButtonPressed() event handler.
Definition fflua_customluawindow.h:465
void HandleTimer(twobyte timerID) override
Virtual handler method that is called for each timer event.
Definition fflua_customluawindow.h:803
bool RegisterTextSelectionChanged(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the TextSelectionChanged() event handler.
Definition fflua_customluawindow.h:339
void InitWindow() override
Virtual handler method that is called when a window just has been created, but not yet shown.
Definition fflua_customluawindow.h:768
void HandleDataListSelect(FCCtrlDataList *pControl, int lineindex) override
Virtual handler method for when FCCtrlDataList selection state changes.
Definition fflua_customluawindow.h:690
bool ShowModelessWithGrabbyFocus()
Displays the macOS version of the dialog box as a modeless window with grabby focus behavior.
Definition fflua_customluawindow.h:272
void HandleDataListCheck(FCCtrlDataList *pControl, int lineindex, bool checkstate) override
Virtual handler method for when FCCtrlDataList check state changes (for data list controls with check...
Definition fflua_customluawindow.h:706
bool RegisterMouseTrackingStarted(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the MouseTrackingStarted() event handler.
Definition fflua_customluawindow.h:568
void DarkModeIsChanging(bool isDarkMode) override
Virtual handler method that is called when Dark Mode changes. (Currently macOS only....
Definition fflua_customluawindow.h:815
bool RegisterOSMenuCommandExecuted(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the OSMenuCommandExecuted() event handler.
Definition fflua_customluawindow.h:554
void HandleUpDownPressed(FCControl *pControl, int delta) override
Virtual handler method for up/down arrow controls when they are clicked.
Definition fflua_customluawindow.h:675
bool RegisterHandleTimer(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the HandleTimer() event handler.
Definition fflua_customluawindow.h:521
void OkButtonPressed() override
Virtual handler method that is called when a control with a "OK" action is pressed by the user.
Definition fflua_customluawindow.h:757
void CloseWindow() override
Virtual handler method that is called when a window is closing. The Lua handler is called first.
Definition fflua_customluawindow.h:778
void MouseTrackingStopped(FCControl *pControl) override
Virtual handler method that is called when a mouse tracking stops. Currently only supported fo FCCtrl...
Definition fflua_customluawindow.h:852
void TextSelectionChanged(FCControl *pControl) override
Virtual handler method for detecing when the text selection changes on edit text controls.
Definition fflua_customluawindow.h:631
bool RegisterHandleDataListSelect(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the HandleDataListSelect() event handler.
Definition fflua_customluawindow.h:395
void MouseTrackingStarted(FCControl *pControl) override
Virtual handler method that is called when a mouse tracking starts. Currently only supported fo FCCtr...
Definition fflua_customluawindow.h:840
void ScrollChanged(FCControl *pControl) override
Virtual handler method for detecing when the scrollbar changes.
Definition fflua_customluawindow.h:644
bool RegisterCloseWindow(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the CloseWindow() event handler.
Definition fflua_customluawindow.h:493
void OSMenuCommandExecuted(EMENUID menuCommand, int menuCommandType) override
Virtual handler method that is called after a menu command is executed.
Definition fflua_customluawindow.h:828
bool RegisterHandleKeyboardCommand(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the HandleKeyboardCommand() event handler.
Definition fflua_customluawindow.h:367
bool HandleCommand(FCControl *pControl) override
Virtual method that is called when a user command occurs, such as a button press.
Definition fflua_customluawindow.h:617
bool RegisterMouseTrackingStopped(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the MouseTrackingStopped() event handler.
Definition fflua_customluawindow.h:582
bool HandleListEnterKey(FCControl *pControl) override
Virtual handler method there's an enter key hit inside a data list or list box.
Definition fflua_customluawindow.h:729
void HandleListDoubleClick(FCControl *pControl) override
Virtual handler method for when there's a double-click inside a data list or list box.
Definition fflua_customluawindow.h:717
bool RegisterHandleDataListCheck(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the HandleDataListCheck() event handler.
Definition fflua_customluawindow.h:409
void CancelButtonPressed() override
Virtual handler method that is called when a control with a "Cancel" action is pressed by the user.
Definition fflua_customluawindow.h:745
bool RegisterHandleUpDownPressed(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the HandleUpDownPressed() event handler.
Definition fflua_customluawindow.h:381
bool RegisterHandleCommand(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the HandleCommand() event handler. This handler is a catch-all for all co...
Definition fflua_customluawindow.h:298
FCCustomLuaWindow(lua_State *L)
The constructor.
Definition fflua_customluawindow.h:160
bool RegisterHandleActivate(luabridge::LuaRef lua_callback_function)
Registers a Lua function to the HandleActivate() event handler.
Definition fflua_customluawindow.h:507
bool HandleKeyboardCommand(FCControl *pControl, eUniChar16 character) override
Virtual handler method for handling keyboard save requests.
Definition fflua_customluawindow.h:658
A class that supports programmatically created controls (that are not defined in resource files).
Definition ff_dialogs.h:6490
void OkButtonPressed() override
Override method for __FCUserWindow::OkButtonPressed.
Definition ff_dialogs.h:6604
Class that represents a single Lua script item. This class is not part of the C++ PDK Framework.
Definition fflua_luascriptitem.h:70
__FCUserWindow * GetControllingWindow() const
Gets the controlling window for this script item.
Definition fflua_luascriptitem.h:400
EXECMODAL_RETURNS ExecuteModal(__FCUserWindow *pParent=nullptr)
Executes a dialog box in a modal state.
Definition finaleframework.cpp:31789
void ShowModeless(EWND WINCODE(hParent))
Displays the dialog box as a modeless window.
Definition finaleframework.cpp:31742