-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AppCmd commands dispatcher for menu and application commands (#15)
* Add AppCmd commands dispatcher for menu and application commands
- Loading branch information
1 parent
de7cd86
commit caf1b5d
Showing
52 changed files
with
1,195 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Hint files help the Visual Studio IDE interpret Visual C++ identifiers | ||
// such as names of functions and macros. | ||
// For more information see https://go.microsoft.com/fwlink/?linkid=865984 | ||
#define DECLARE_$NEW(T, __VA_ARGS__) T* T##_$new(E) { void* pObject = malloc(sizeof(T)); if (pObject) { memset(pObject, 0, sizeof(T)); T##_$init((T*)pObject, __VA_ARGS__); } return (T*)pObject; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "precomp.h" | ||
|
||
#include "appcmd.h" | ||
#include "util/assert.h" | ||
#include "panitentapp.h" | ||
|
||
int AppCmd_KeyCompare(void* pKey1, void* pKey2) { | ||
if ((UINT)pKey1 == (UINT)pKey2) { | ||
return 0; | ||
} | ||
else if ((UINT)pKey1 > (UINT)pKey2) { | ||
return 1; | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
void AppCmd_Init(AppCmd* pAppCmd) { | ||
ASSERT(pAppCmd); | ||
memset(pAppCmd, 0, sizeof(AppCmd)); | ||
|
||
HashMap* pHashMap = HashMap_Create(16, &AppCmd_KeyCompare); | ||
ASSERT(pHashMap); | ||
pAppCmd->pCmdMap = pHashMap; | ||
} | ||
|
||
void AppCmd_AddCommand(AppCmd* pAppCmd, UINT cmdId, PFNAppCmdCallback* pfnCallback) { | ||
ASSERT(pAppCmd); | ||
ASSERT(pfnCallback); | ||
HashMap_Put(pAppCmd->pCmdMap, (void*)cmdId, (void*)pfnCallback); | ||
} | ||
|
||
void AppCmd_Execute(AppCmd* pAppCmd, UINT cmdId, PanitentApp* pPanitentApp) { | ||
ASSERT(pAppCmd); | ||
PFNAppCmdCallback *pfnCallback = (PFNAppCmdCallback*)HashMap_Get(pAppCmd->pCmdMap, (void*)cmdId); | ||
ASSERT(pfnCallback); | ||
pfnCallback(pPanitentApp); | ||
} | ||
|
||
void AppCmd_Destroy(AppCmd* pAppCmd) { | ||
ASSERT(pAppCmd); | ||
HashMap_Destroy(pAppCmd->pCmdMap); | ||
pAppCmd->pCmdMap = NULL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef PANITENT_APPCMD_H | ||
#define PANITENT_APPCMD_H | ||
|
||
#include "util/hashmap.h" | ||
|
||
typedef struct PanitentApp PanitentApp; | ||
|
||
typedef void (PFNAppCmdCallback)(PanitentApp*); | ||
|
||
typedef struct AppCmd AppCmd; | ||
typedef struct AppCmd { | ||
HashMap* pCmdMap; | ||
}; | ||
|
||
/* Public Interface */ | ||
void AppCmd_Init(AppCmd* pAppCmd); | ||
void AppCmd_AddCommand(AppCmd* pAppCmd, UINT cmdId, PFNAppCmdCallback* pfnCallback); | ||
void AppCmd_Execute(AppCmd* pAppCmd, UINT cmdId, PanitentApp* pPanitentApp); | ||
void AppCmd_Destroy(AppCmd* pAppCmd); | ||
|
||
#endif /* PANITENT_APPCMD_H */ |
Oops, something went wrong.