![]() |
Clapkit
|
Defines the main entry point for a Clapkit application. More...
#include <ckApp.h>
Public Member Functions | |
CKApp () | |
The starting point of any Clapkit app. Initialize the app, set up menus, etc. | |
~CKApp () | |
int | CKLoop (int waitTime=60) |
Main event loop, handling events. Needs to be called as much as possible. | |
void | CKQuit () |
CKWindow * | CKNewWindow (const CKWindowInitParams ¶ms) |
Create a new window and if successful, add it to the list of the windows the app has. You MUST use this function instead of creating and initializing a CKWindow yourself. | |
CKWindow * | CKFindWindow (CKWindowPtr ptr) |
Try to find a window by the WindowPtr. Probably only applies to Toolbox Mac. | |
void | CKRemoveWindow (CKWindow *window) |
Remove and destroy window. You MUST use this function instead of deleting a window yourself. | |
void | CKIncreaseWork () |
Show the 'Working' cursor. | |
void | CKDecreaseWork () |
Decrease work count by one, if zero, hide the 'Working' cursor. | |
void | CKRestoreCursor () |
Changed the cursor yourself? Call this to get the default/waiting back. | |
CKWindow * | CKNewMsgBoxPlain (const char *message, const char *title=nullptr, const char *btnOk="OK", const char *btnCancel=nullptr, std::function< void(int button)> callback=0) |
Create and show an alert. Alerts are non-blocking. btnCancel is optional and only shown if set to a non-null value. button is set to "1" if the user clicks on OK and "0" if the user clicks on the Cancel button (if one is provided, that is.) While this function returns a CKWindow, you don't have to call Show on the window as the window will be displayed immediately. | |
CKWindow * | CKNewMsgBoxNote (const char *message, const char *title=nullptr, const char *btnOk="OK", const char *btnCancel=nullptr, std::function< void(int button)> callback=0) |
Create and show an alert. Alerts are non-blocking. btnCancel is optional and only shown if set to a non-null value. button is set to "1" if the user clicks on OK and "0" if the user clicks on the Cancel button (if one is provided, that is.) While this function returns a CKWindow, you don't have to call Show on the window as the window will be displayed immediately. | |
CKWindow * | CKNewMsgBoxWarning (const char *message, const char *title=nullptr, const char *btnOk="OK", const char *btnCancel="Cancel", std::function< void(int button)> callback=0) |
Create and show an alert. Alerts are non-blocking. btnCancel is optional and only shown if set to a non-null value. button is set to "1" if the user clicks on OK and "0" if the user clicks on the Cancel button (if one is provided, that is.) While this function returns a CKWindow, you don't have to call Show on the window as the window will be displayed immediately. | |
CKWindow * | CKNewMsgBoxError (const char *message, const char *title=nullptr, const char *btnOk="OK", const char *btnCancel="Cancel", std::function< void(int button)> callback=0) |
Create and show an alert. Alerts are non-blocking. btnCancel is optional and only shown if set to a non-null value. button is set to "1" if the user clicks on OK and "0" if the user clicks on the Cancel button (if one is provided, that is.) While this function returns a CKWindow, you don't have to call Show on the window as the window will be displayed immediately. | |
CKWindow * | CKTopMostWindow () |
Return the top-most window we have. | |
short | CKFontToId (const char *font) |
Convert a font name to a font Id. | |
void | CKAddTimer (CKTimer *timer, CKObject *owner=nullptr) |
Add a new timer to the app, enabling (via Start ) as you add it. | |
void | CKRemoveTimer (CKTimer *timer) |
Stop and remove timer. | |
void | CKRemoveTimersOfOwner (CKObject *owner) |
Remove all timers of a specific owner. | |
CKError | CKSetMenu (CKMenuBar *menu) |
Set the application's menu bar. | |
void | CKShowMenuBar () |
If hidden, bring the menu bar back. | |
void | CKHideMenuBar () |
If shown, hide the menu bar. | |
void | CKUpdateMenuBarItems () |
Called from CKWindow on focused-item change to update (i.e. enable/disable) the standard menu items (Cut, Copy, Paste, etc.) | |
Defines the main entry point for a Clapkit application.
This class represents the root of any Clapkit app. You must create (ideally only one) instance of CKApp and call CKLoop()
to start the UI.
You can subclass this if needed, but it’s not required.
CKApp::CKApp | ( | ) |
The starting point of any Clapkit app. Initialize the app, set up menus, etc.
CKApp::~CKApp | ( | ) |
Nothing much here.
Add a new timer to the app, enabling (via Start
) as you add it.
timer | Timer to add and start |
owner | Adding this to a window or anything else that might go away? Make sure to set owner ! |
void CKApp::CKDecreaseWork | ( | ) |
Decrease work count by one, if zero, hide the 'Working' cursor.
CKWindow * CKApp::CKFindWindow | ( | CKWindowPtr | ptr | ) |
Try to find a window by the WindowPtr. Probably only applies to Toolbox Mac.
ptr |
short CKApp::CKFontToId | ( | const char * | font | ) |
Convert a font name to a font Id.
font |
void CKApp::CKHideMenuBar | ( | ) |
If shown, hide the menu bar.
void CKApp::CKIncreaseWork | ( | ) |
Show the 'Working' cursor.
int CKApp::CKLoop | ( | int | waitTime = 60 | ) |
Main event loop, handling events. Needs to be called as much as possible.
waitTime | Wait time to be given to the OS. Passed to WaitNextEvent |
0
All OK, keep going. Any other value means app is going to quit, clean up. CKWindow * CKApp::CKNewMsgBoxError | ( | const char * | message, |
const char * | title = nullptr , |
||
const char * | btnOk = "OK" , |
||
const char * | btnCancel = "Cancel" , |
||
std::function< void(int button)> | callback = 0 |
||
) |
Create and show an alert. Alerts are non-blocking. btnCancel is optional and only shown if set to a non-null value. button
is set to "1" if the user clicks on OK and "0" if the user clicks on the Cancel button (if one is provided, that is.) While this function returns a CKWindow, you don't have to call Show
on the window as the window will be displayed immediately.
message | Message to be displayed (required) |
title | Title text (optional) - setting this will make the window non-modal. |
btnOk | 'OK' button text. If set to null, "OK" is used. |
btnCancel | Optional 'Cancel' button. If set to null, not displayed. |
callback | Returns 1 if OK is clicked, 0 if Cancel is clicked and -1 if the window was closed. |
CKWindow * CKApp::CKNewMsgBoxNote | ( | const char * | message, |
const char * | title = nullptr , |
||
const char * | btnOk = "OK" , |
||
const char * | btnCancel = nullptr , |
||
std::function< void(int button)> | callback = 0 |
||
) |
Create and show an alert. Alerts are non-blocking. btnCancel is optional and only shown if set to a non-null value. button
is set to "1" if the user clicks on OK and "0" if the user clicks on the Cancel button (if one is provided, that is.) While this function returns a CKWindow, you don't have to call Show
on the window as the window will be displayed immediately.
message | Message to be displayed (required) |
title | Title text (optional) - setting this will make the window non-modal. |
btnOk | 'OK' button text. If set to null, "OK" is used. |
btnCancel | Optional 'Cancel' button. If set to null, not displayed. |
callback | Returns 1 if OK is clicked, 0 if Cancel is clicked and -1 if the window was closed. |
CKWindow * CKApp::CKNewMsgBoxPlain | ( | const char * | message, |
const char * | title = nullptr , |
||
const char * | btnOk = "OK" , |
||
const char * | btnCancel = nullptr , |
||
std::function< void(int button)> | callback = 0 |
||
) |
Create and show an alert. Alerts are non-blocking. btnCancel is optional and only shown if set to a non-null value. button
is set to "1" if the user clicks on OK and "0" if the user clicks on the Cancel button (if one is provided, that is.) While this function returns a CKWindow, you don't have to call Show
on the window as the window will be displayed immediately.
message | Message to be displayed (required) |
title | Title text (optional) - setting this will make the window non-modal. |
btnOk | 'OK' button text. If set to null, "OK" is used. |
btnCancel | Optional 'Cancel' button. If set to null, not displayed. |
callback | Returns 1 if OK is clicked, 0 if Cancel is clicked and -1 if the window was closed. |
CKWindow * CKApp::CKNewMsgBoxWarning | ( | const char * | message, |
const char * | title = nullptr , |
||
const char * | btnOk = "OK" , |
||
const char * | btnCancel = "Cancel" , |
||
std::function< void(int button)> | callback = 0 |
||
) |
Create and show an alert. Alerts are non-blocking. btnCancel is optional and only shown if set to a non-null value. button
is set to "1" if the user clicks on OK and "0" if the user clicks on the Cancel button (if one is provided, that is.) While this function returns a CKWindow, you don't have to call Show
on the window as the window will be displayed immediately.
message | Message to be displayed (required) |
title | Title text (optional) - setting this will make the window non-modal. |
btnOk | 'OK' button text. If set to null, "OK" is used. |
btnCancel | Optional 'Cancel' button. If set to null, not displayed. |
callback | Returns 1 if OK is clicked, 0 if Cancel is clicked and -1 if the window was closed. |
CKWindow * CKApp::CKNewWindow | ( | const CKWindowInitParams & | params | ) |
Create a new window and if successful, add it to the list of the windows the app has. You MUST use this function instead of creating and initializing a CKWindow yourself.
params |
std::exception |
void CKApp::CKQuit | ( | ) |
Flush events, clean things up, quit.
void CKApp::CKRemoveTimer | ( | CKTimer * | timer | ) |
Stop and remove timer.
timer | Timer to stop and remove |
void CKApp::CKRemoveTimersOfOwner | ( | CKObject * | owner | ) |
Remove all timers of a specific owner.
owner |
void CKApp::CKRemoveWindow | ( | CKWindow * | window | ) |
Remove and destroy window. You MUST use this function instead of deleting a window yourself.
We don't immediately delete a window but rather collect it for future deletion - this is because mouseUp, etc. events might still pop during execution of an event handler.
In fact, when possible, use [window]->Close() function.
window |
void CKApp::CKRestoreCursor | ( | ) |
Changed the cursor yourself? Call this to get the default/waiting back.
Set the application's menu bar.
return CKPass on success.
void CKApp::CKShowMenuBar | ( | ) |
If hidden, bring the menu bar back.
CKWindow * CKApp::CKTopMostWindow | ( | ) |
Return the top-most window we have.
void CKApp::CKUpdateMenuBarItems | ( | ) |
Called from CKWindow on focused-item change to update (i.e. enable/disable) the standard menu items (Cut, Copy, Paste, etc.)