summaryrefslogtreecommitdiff
path: root/plugins/Skins/SkinLib/SkinnedDialog.h
blob: 1387082f44475db2d242f4a26923217c27cbae18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef __SKINNED_DIALOG_H__
# define __SKINNED_DIALOG_H__

#include <windows.h>
#include <tchar.h>
#include "tstring.h"

#include "Dialog.h"
#include "ButtonField.h"
#include "EditField.h"
#include "IconField.h"
#include "ImageField.h"
#include "LabelField.h"
#include "TextField.h"

#include "DialogState.h"
#include "BorderState.h"
#include "ButtonFieldState.h"
#include "EditFieldState.h"
#include "FontState.h"
#include "IconFieldState.h"
#include "ImageFieldState.h"
#include "LabelFieldState.h"
#include "TextFieldState.h"

#include "SkinOptions.h"

class V8Script;


typedef void (*MessageCallback)(void *param, const TCHAR *err);



class SkinnedDialog : public Dialog
{
public:
	SkinnedDialog(const char *name);
	virtual ~SkinnedDialog();

	virtual const TCHAR * getFilename() const;
	virtual void setFilename(const TCHAR *filename);

	virtual bool addField(Field *field);

	virtual void setSize(const Size &size);

	/// Return the cached state. Do not free the result. 
	/// Each call to this method can potentially create the state, so don't cache it.
	virtual DialogState * getState();

	virtual void setErrorCallback(MessageCallback cb, void *param = NULL);
	virtual void setTraceCallback(MessageCallback cb, void *param = NULL);

	virtual SkinOptions * getOpts();
	virtual DialogState * getDefaultState();

protected:
	virtual bool fileChanged();
	virtual int compile(); /// @return 0 error, 1 no change, 2 compiled

	virtual void trace(TCHAR *msg, ...);

	virtual void onFieldChange(const Field *field);

private:
	std::tstring filename;
	__time64_t fileChangedTime;
	V8Script *script;
	DialogState *state;
	SkinOptions *opts;
	DialogState *defaultState;

	MessageCallback errorCallback;
	void *errorCallbackParam;
	MessageCallback traceCallback;
	void *traceCallbackParam;

	void releaseCompiledScript();
	void releaseState();
	void readFile(std::tstring &ret);

	static void staticOnFieldChange(void *param, const Field *field);
};




#endif // __SKINNED_DIALOG_H__