Maelstrom: Allow a dialog setup function

https://github.com/libsdl-org/Maelstrom/commit/d0e451b2ab726f66d31f56395748be222d254a48

From d0e451b2ab726f66d31f56395748be222d254a48 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 29 Oct 2011 12:06:56 -0400
Subject: [PATCH] Allow a dialog setup function

---
 UIDialog.cpp | 18 ++++++++++++------
 UIDialog.h   | 20 ++++++++++++++------
 main.cpp     |  2 +-
 3 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/UIDialog.cpp b/UIDialog.cpp
index f6a539b9..da106dc2 100644
--- a/UIDialog.cpp
+++ b/UIDialog.cpp
@@ -23,7 +23,8 @@ UIDialog::UIDialog(UIManager *ui, const char *name) :
 	m_expand = true;
 	m_step = 0;
 	m_status = 0;
-	m_handler = NULL;
+	m_handleInit = NULL;
+	m_handleDone = NULL;
 }
 
 UIDialog::~UIDialog()
@@ -52,6 +53,10 @@ UIDialog::Show()
 	}
 	m_status = 0;
 
+	if (m_handleInit) {
+		m_handleInit(this);
+	}
+
 	UIPanel::Show();
 }
 
@@ -60,8 +65,8 @@ UIDialog::Hide()
 {
 	UIPanel::Hide();
 
-	if (m_handler) {
-		m_handler(this, m_status);
+	if (m_handleDone) {
+		m_handleDone(this, m_status);
 	}
 }
 
@@ -131,11 +136,12 @@ UIDialog::HandleEvent(const SDL_Event &event)
 	return false;
 }
 
-UIDialogLauncher::UIDialogLauncher(UIManager *ui, const char *name, UIDialogHandler handler)
+UIDialogLauncher::UIDialogLauncher(UIManager *ui, const char *name, UIDialogInitHandler handleInit, UIDialogDoneHandler handleDone)
 {
 	m_ui = ui;
 	m_name = name;
-	m_handler = handler;
+	m_handleInit = handleInit;
+	m_handleDone = handleDone;
 }
 
 void
@@ -145,7 +151,7 @@ UIDialogLauncher::OnClick()
 
 	dialog = m_ui->GetPanel<UIDialog>(m_name);
 	if (dialog) {
-		dialog->SetDialogHandler(m_handler);
+		dialog->SetDialogHandlers(m_handleInit, m_handleDone);
 
 		m_ui->ShowPanel(dialog);
 	}
diff --git a/UIDialog.h b/UIDialog.h
index 625e9062..7b73612b 100644
--- a/UIDialog.h
+++ b/UIDialog.h
@@ -7,10 +7,14 @@
 
 class UIDialog;
 
+/* This function gets called when the dialog is shown.
+*/
+typedef void (*UIDialogInitHandler)(UIDialog *dialog);
+
 /* This function gets called when the dialog is hidden.
    The status defaults to 0, but can be changed by dialog buttons.
  */
-typedef void (*UIDialogHandler)(UIDialog *dialog, int status);
+typedef void (*UIDialogDoneHandler)(UIDialog *dialog, int status);
 
 class UIDialog : public UIPanel
 {
@@ -23,8 +27,10 @@ class UIDialog : public UIPanel
 	}
 
 	/* Set a function that's called when the dialog is hidden */
-	void SetDialogHandler(UIDialogHandler handler) {
-		m_handler = handler;
+	void SetDialogHandlers(UIDialogInitHandler handleInit,
+				UIDialogDoneHandler handleDone) {
+		m_handleInit = handleInit;
+		m_handleDone = handleDone;
 	}
 	void SetDialogStatus(int status) {
 		m_status = status;
@@ -50,7 +56,8 @@ class UIDialog : public UIPanel
 	bool m_expand;
 	int m_step;
 	int m_status;
-	UIDialogHandler m_handler;
+	UIDialogInitHandler m_handleInit;
+	UIDialogDoneHandler m_handleDone;
 
 protected:
 	static UIElementType s_elementType;
@@ -70,14 +77,15 @@ class UIDialog : public UIPanel
 class UIDialogLauncher : public UIButtonDelegate
 {
 public:
-	UIDialogLauncher(UIManager *ui, const char *name, UIDialogHandler handler = NULL);
+	UIDialogLauncher(UIManager *ui, const char *name, UIDialogInitHandler = NULL, UIDialogDoneHandler handleDone = NULL);
 
 	virtual void OnClick();
 
 protected:
 	UIManager *m_ui;
 	const char *m_name;
-	UIDialogHandler m_handler;
+	UIDialogInitHandler m_handleInit;
+	UIDialogDoneHandler m_handleDone;
 };
 
 #endif // _UIDialog_h
diff --git a/main.cpp b/main.cpp
index 37424e39..f45e97dc 100644
--- a/main.cpp
+++ b/main.cpp
@@ -362,7 +362,7 @@ MainPanelDelegate::OnLoad()
 	}
 	button = m_panel->GetElement<UIElementButton>("ZapButton");
 	if (button) {
-		button->SetButtonDelegate(new UIDialogLauncher(ui, DIALOG_ZAP, ZapHighScores));
+		button->SetButtonDelegate(new UIDialogLauncher(ui, DIALOG_ZAP, NULL, ZapHighScores));
 	}
 	button = m_panel->GetElement<UIElementButton>("AboutButton");
 	if (button) {