Debian Codegraph @

src/af/xap/xp/xap_Dlg_MessageBox.cpp

raw
1 /* AbiSource Application Framework
2 * Copyright (C) 1998 AbiSource, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdarg.h>
24 #include "ut_string.h"
25 #include "ut_debugmsg.h"
26 #include "xap_Dlg_MessageBox.h"
27 #include "xap_App.h"
28
29 /*****************************************************************/
30
31 XAP_Dialog_MessageBox::XAP_Dialog_MessageBox(XAP_DialogFactory * pDlgFactory, XAP_Dialog_Id id)
32 : XAP_Dialog_NonPersistent(pDlgFactory,id)
33 {
34 m_szMessage = NULL;
35 m_szSecondaryMessage = NULL;
36 m_buttons = b_O;
37 m_defaultAnswer = a_OK;
38 m_answer = a_OK;
39 }
40
41 XAP_Dialog_MessageBox::~XAP_Dialog_MessageBox(void)
42 {
43 FREEP(m_szSecondaryMessage);
44 FREEP(m_szMessage);
45 }
46
47 void XAP_Dialog_MessageBox::setMessage(const char * szMessage, ...)
48 {
49 va_list args;
50
51 va_start(args, szMessage);
52
53 FREEP(m_szMessage);
54 m_szMessage = (char *)g_try_malloc(512*sizeof(char));
55 vsprintf(m_szMessage, szMessage, args);
56
57 va_end(args);
58 }
59
60 void XAP_Dialog_MessageBox::setMessage(XAP_String_Id id, ...)
61 {
62 va_list args;
63
64 va_start(args, id);
65
66 FREEP(m_szMessage);
67
68 const XAP_StringSet * pSS = getApp()->getStringSet();
69
70 m_szMessage = (char *)g_try_malloc(512*sizeof(char));
71 std::string s;
72 pSS->getValue(id, getApp()->getDefaultEncoding(),s);
73
74 vsprintf(m_szMessage, (char*)s.c_str(), args);
75
76 va_end(args);
77 }
78
79 void XAP_Dialog_MessageBox::setSecondaryMessage(const char * szMessage, ...)
80 {
81 va_list args;
82
83 va_start(args, szMessage);
84
85 FREEP(m_szSecondaryMessage);
86 m_szSecondaryMessage = (char *)g_try_malloc(512*sizeof(char));
87 vsprintf(m_szSecondaryMessage, szMessage, args);
88
89 va_end(args);
90 }
91
92 void XAP_Dialog_MessageBox::setSecondaryMessage(XAP_String_Id id, ...)
93 {
94 va_list args;
95
96 va_start(args, id);
97
98 FREEP(m_szSecondaryMessage);
99
100 const XAP_StringSet * pSS = getApp()->getStringSet();
101
102 m_szSecondaryMessage = (char *)g_try_malloc(512*sizeof(char));
103 std::string s;
104 pSS->getValue(id, getApp()->getDefaultEncoding(),s);
105 vsprintf(m_szSecondaryMessage, (char*)s.c_str(), args);
106
107 va_end(args);
108 }
109
110
111 void XAP_Dialog_MessageBox::setButtons(XAP_Dialog_MessageBox::tButtons buttons)
112 {
113 m_buttons = buttons;
114 }
115
116 void XAP_Dialog_MessageBox::setDefaultAnswer(XAP_Dialog_MessageBox::tAnswer answer)
117 {
118 m_defaultAnswer = answer;
119 m_answer = answer;
120 }
121
122 XAP_Dialog_MessageBox::tAnswer XAP_Dialog_MessageBox::getAnswer(void) const
123 {
124 return m_answer;
125 }