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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
/***************************************************************************
begin : Oct 2005
copyright : (C) 2005 by Craig Bradney
email : cbradney@zip.com.au
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "scmessagebox.h"
#include "scribuscore.h"
extern ScribusQApp* ScQApp;
int ScMessageBox::swapButtonValues(int &b0, int &b1, int &b2)
{
int buttonsUsed=1;
if (ScCore->reverseDialogButtons())
{
//Last button not used, and 2nd one used, swap 1st and 2nd.
if (b2==0 && b1!=0) //Could be: if ((b2==0 || b2==QMessageBox::NoButton) && b1!=0) but NoButton is 0x0000, for now.
{
int t=b1;
b1=b0;
b0=t;
buttonsUsed=2;
}
//All three buttons used, swap the outside ones only
if (b2!=0 && b1!=0 && b0!=0)
{
int t;
if (ScCore->isMacGUI())
{
// Mac order is "No, Cancel, Yes"
t = b2;
b2 = b0;
b0 = b1;
b1 = t;
}
else
{
// If Unix order is "Cancel, No, Yes"
t = b2;
b2=b0;
b0=t;
}
buttonsUsed=3;
}
}
return buttonsUsed;
}
int ScMessageBox::swapButtonValues(QString &b0Text, QString &b1Text, QString &b2Text, int &defaultButton, int &escapeButton)
{
int buttonsUsed=1;
if (ScCore->reverseDialogButtons())
{
//Last button not used, and 2nd one used, swap 1st and 2nd.
if (b2Text.isEmpty() && !b1Text.isEmpty())
{
QString tText=b1Text;
b1Text=b0Text;
b0Text=tText;
if (defaultButton==0)
defaultButton=1;
else
if (defaultButton==1)
defaultButton=0;
if (escapeButton==0)
escapeButton=1;
else
if (escapeButton==1)
escapeButton=0;
buttonsUsed=2;
}
//All three buttons used, swap the outside ones only
if (!b2Text.isEmpty() && !b1Text.isEmpty() && !b0Text.isEmpty())
{
QString tText;
if (ScCore->isMacGUI())
{
// Mac order is "No, Cancel, Yes"
tText = b2Text;
b2Text = b0Text;
b0Text = b1Text;
b1Text = tText;
switch (defaultButton) {
case 0:
defaultButton=2;
break;
case 1:
break;
case 2:
defaultButton=0;
}
switch (escapeButton) {
case 0:
escapeButton=2;
break;
case 1:
escapeButton=0;
break;
case 2:
escapeButton=1;
}
}
else
{
// Unix order is "Cancel, No, Yes"
tText = b2Text;
b2Text=b0Text;
b0Text=tText;
if (defaultButton==0)
defaultButton=2;
else
if (defaultButton==2)
defaultButton=0;
if (escapeButton==0)
escapeButton=2;
else
if (escapeButton==2)
escapeButton=0;
}
buttonsUsed=3;
}
}
return buttonsUsed;
}
int ScMessageBox::swapReturnValues(const int b0Val, const int b1Val, const int b2Val, const int returnVal, const int buttonsUsed)
{
int retVal=returnVal;
if (ScCore->reverseDialogButtons())
{
//Last button not used, and 2nd one used, swap 1st and 2nd.
if (buttonsUsed==2)
{
if (returnVal==b0Val)
retVal=b1Val;
else
if (returnVal==b1Val)
retVal=b0Val;
}
//All three buttons used, swap the outside ones only
if (buttonsUsed==3)
{
if (ScCore->isMacGUI()) {
if (returnVal == b0Val)
retVal = b1Val;
else if (returnVal == b1Val)
retVal = b2Val;
else if (returnVal == b2Val)
retVal = b0Val;
}
else
{
if (returnVal==b0Val)
retVal=b2Val;
else
if (returnVal==b2Val)
retVal=b0Val;
}
}
}
return retVal;
}
int ScMessageBox::information ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1, int button2)
{
int b0=button0, b1=button1, b2=button2;
int buttonsUsed=swapButtonValues(b0, b1, b2);
int stdReturn=QMessageBox::information(parent, caption, text, b0, b1, b2);
return swapReturnValues(b0, b1, b2, stdReturn, buttonsUsed);
}
int ScMessageBox::information ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text, const QString & button1Text, const QString & button2Text, int defaultButtonNumber, int escapeButtonNumber)
{
QString b0Text=button0Text, b1Text=button1Text, b2Text=button2Text;
int defaultButton=defaultButtonNumber, escapeButton=escapeButtonNumber;
int buttonsUsed=swapButtonValues(b0Text, b1Text, b2Text, defaultButton, escapeButton);
int stdReturn=QMessageBox::information(parent, caption, text, b0Text, b1Text, b2Text, defaultButton, escapeButton);
return swapReturnValues(0, 1, 2, stdReturn, buttonsUsed);
}
int ScMessageBox::question ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1, int button2)
{
int b0=button0, b1=button1, b2=button2;
int buttonsUsed=swapButtonValues(b0, b1, b2);
int stdReturn=QMessageBox::question(parent, caption, text, b0, b1, b2);
return swapReturnValues(b0, b1, b2, stdReturn, buttonsUsed);
}
int ScMessageBox::question ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text, const QString & button1Text, const QString & button2Text, int defaultButtonNumber, int escapeButtonNumber)
{
QString b0Text=button0Text, b1Text=button1Text, b2Text=button2Text;
int defaultButton=defaultButtonNumber, escapeButton=escapeButtonNumber;
int buttonsUsed=swapButtonValues(b0Text, b1Text, b2Text, defaultButton, escapeButton);
int stdReturn=QMessageBox::question(parent, caption, text, b0Text, b1Text, b2Text, defaultButton, escapeButton);
return swapReturnValues(0, 1, 2, stdReturn, buttonsUsed);
}
int ScMessageBox::warning ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1, int button2)
{
int b0=button0, b1=button1, b2=button2;
int buttonsUsed=swapButtonValues(b0, b1, b2);
int stdReturn=QMessageBox::warning(parent, caption, text, b0, b1, b2);
return swapReturnValues(b0, b1, b2, stdReturn, buttonsUsed);
}
int ScMessageBox::warning ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text, const QString & button1Text, const QString & button2Text, int defaultButtonNumber, int escapeButtonNumber)
{
QString b0Text=button0Text, b1Text=button1Text, b2Text=button2Text;
int defaultButton=defaultButtonNumber, escapeButton=escapeButtonNumber;
int buttonsUsed=swapButtonValues(b0Text, b1Text, b2Text, defaultButton, escapeButton);
int stdReturn=QMessageBox::warning(parent, caption, text, b0Text, b1Text, b2Text, defaultButton, escapeButton);
return swapReturnValues(0, 1, 2, stdReturn, buttonsUsed);
}
int ScMessageBox::critical ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1, int button2)
{
int b0=button0, b1=button1, b2=button2;
int buttonsUsed=swapButtonValues(b0, b1, b2);
int stdReturn=QMessageBox::critical(parent, caption, text, b0, b1, b2);
return swapReturnValues(b0, b1, b2, stdReturn, buttonsUsed);
}
int ScMessageBox::critical ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text, const QString & button1Text, const QString & button2Text, int defaultButtonNumber, int escapeButtonNumber)
{
QString b0Text=button0Text, b1Text=button1Text, b2Text=button2Text;
int defaultButton=defaultButtonNumber, escapeButton=escapeButtonNumber;
int buttonsUsed=swapButtonValues(b0Text, b1Text, b2Text, defaultButton, escapeButton);
int stdReturn=QMessageBox::critical(parent, caption, text, b0Text, b1Text, b2Text, defaultButton, escapeButton);
return swapReturnValues(0, 1, 2, stdReturn, buttonsUsed);
}
|