Clapkit
Loading...
Searching...
No Matches
CKApp Class Reference

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 ()
 
CKWindowCKNewWindow (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.
 
CKWindowCKFindWindow (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.
 
CKWindowCKNewMsgBoxPlain (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.
 
CKWindowCKNewMsgBoxNote (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.
 
CKWindowCKNewMsgBoxWarning (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.
 
CKWindowCKNewMsgBoxError (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.
 
CKWindowCKTopMostWindow ()
 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.)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ CKApp()

CKApp::CKApp ( )

The starting point of any Clapkit app. Initialize the app, set up menus, etc.

◆ ~CKApp()

CKApp::~CKApp ( )

Nothing much here.

Member Function Documentation

◆ CKAddTimer()

void CKApp::CKAddTimer ( CKTimer timer,
CKObject owner = nullptr 
)

Add a new timer to the app, enabling (via Start) as you add it.

Parameters
timerTimer to add and start
ownerAdding this to a window or anything else that might go away? Make sure to set owner!

◆ CKDecreaseWork()

void CKApp::CKDecreaseWork ( )

Decrease work count by one, if zero, hide the 'Working' cursor.

◆ CKFindWindow()

CKWindow * CKApp::CKFindWindow ( CKWindowPtr  ptr)

Try to find a window by the WindowPtr. Probably only applies to Toolbox Mac.

Parameters
ptr
Returns

◆ CKFontToId()

short CKApp::CKFontToId ( const char *  font)

Convert a font name to a font Id.

Parameters
font
Returns
Returns 0 if not found or if font name == "System"

◆ CKHideMenuBar()

void CKApp::CKHideMenuBar ( )

If shown, hide the menu bar.

◆ CKIncreaseWork()

void CKApp::CKIncreaseWork ( )

Show the 'Working' cursor.

◆ CKLoop()

int CKApp::CKLoop ( int  waitTime = 60)

Main event loop, handling events. Needs to be called as much as possible.

Parameters
waitTimeWait time to be given to the OS. Passed to WaitNextEvent
Returns
0 All OK, keep going. Any other value means app is going to quit, clean up.

◆ CKNewMsgBoxError()

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.

Parameters
messageMessage to be displayed (required)
titleTitle text (optional) - setting this will make the window non-modal.
btnOk'OK' button text. If set to null, "OK" is used.
btnCancelOptional 'Cancel' button. If set to null, not displayed.
callbackReturns 1 if OK is clicked, 0 if Cancel is clicked and -1 if the window was closed.
Returns

◆ CKNewMsgBoxNote()

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.

Parameters
messageMessage to be displayed (required)
titleTitle text (optional) - setting this will make the window non-modal.
btnOk'OK' button text. If set to null, "OK" is used.
btnCancelOptional 'Cancel' button. If set to null, not displayed.
callbackReturns 1 if OK is clicked, 0 if Cancel is clicked and -1 if the window was closed.
Returns

◆ CKNewMsgBoxPlain()

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.

Parameters
messageMessage to be displayed (required)
titleTitle text (optional) - setting this will make the window non-modal.
btnOk'OK' button text. If set to null, "OK" is used.
btnCancelOptional 'Cancel' button. If set to null, not displayed.
callbackReturns 1 if OK is clicked, 0 if Cancel is clicked and -1 if the window was closed.
Returns

◆ CKNewMsgBoxWarning()

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.

Parameters
messageMessage to be displayed (required)
titleTitle text (optional) - setting this will make the window non-modal.
btnOk'OK' button text. If set to null, "OK" is used.
btnCancelOptional 'Cancel' button. If set to null, not displayed.
callbackReturns 1 if OK is clicked, 0 if Cancel is clicked and -1 if the window was closed.
Returns

◆ CKNewWindow()

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.

Parameters
params
Returns
Exceptions
std::exception

◆ CKQuit()

void CKApp::CKQuit ( )

Flush events, clean things up, quit.

◆ CKRemoveTimer()

void CKApp::CKRemoveTimer ( CKTimer timer)

Stop and remove timer.

Parameters
timerTimer to stop and remove

◆ CKRemoveTimersOfOwner()

void CKApp::CKRemoveTimersOfOwner ( CKObject owner)

Remove all timers of a specific owner.

Parameters
owner

◆ CKRemoveWindow()

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.

Parameters
window

◆ CKRestoreCursor()

void CKApp::CKRestoreCursor ( )

Changed the cursor yourself? Call this to get the default/waiting back.

◆ CKSetMenu()

CKError CKApp::CKSetMenu ( CKMenuBar menu)

Set the application's menu bar.

Parameters

return CKPass on success.

◆ CKShowMenuBar()

void CKApp::CKShowMenuBar ( )

If hidden, bring the menu bar back.

◆ CKTopMostWindow()

CKWindow * CKApp::CKTopMostWindow ( )

Return the top-most window we have.

Returns
Nil if there are no windows open.

◆ CKUpdateMenuBarItems()

void CKApp::CKUpdateMenuBarItems ( )

Called from CKWindow on focused-item change to update (i.e. enable/disable) the standard menu items (Cut, Copy, Paste, etc.)


The documentation for this class was generated from the following files: