Back to index

scribus-ng  1.3.4.dfsg+svn20071115
scmessagebox.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008     begin                : Oct 2005
00009     copyright            : (C) 2005 by Craig Bradney
00010     email                : cbradney@zip.com.au
00011  ***************************************************************************/
00012 
00013 /***************************************************************************
00014  *                                                                         *
00015  *   This program is free software; you can redistribute it and/or modify  *
00016  *   it under the terms of the GNU General Public License as published by  *
00017  *   the Free Software Foundation; either version 2 of the License, or     *
00018  *   (at your option) any later version.                                   *
00019  *                                                                         *
00020  ***************************************************************************/
00021 
00022 #include "scmessagebox.h"
00023 #include "scmessagebox.moc"
00024 #include "scribuscore.h"
00025 
00026 extern ScribusQApp* ScQApp;
00027 
00028 
00029 int ScMessageBox::swapButtonValues(int &b0, int &b1, int &b2)
00030 {
00031        int buttonsUsed=1;
00032        if (ScCore->reverseDialogButtons())
00033        {
00034               //Last button not used, and 2nd one used, swap 1st and 2nd.
00035               if (b2==0 && b1!=0) //Could be: if ((b2==0 || b2==QMessageBox::NoButton) && b1!=0) but NoButton is 0x0000, for now.
00036               {
00037                      int t=b1;
00038                      b1=b0;
00039                      b0=t;
00040                      buttonsUsed=2;
00041               }
00042               //All three buttons used, swap the outside ones only
00043               if (b2!=0 && b1!=0 && b0!=0)
00044               {
00045                      int t;
00046                      if (ScCore->isMacGUI())
00047                      {
00048                             // Mac order is "No, Cancel, Yes"
00049                             t = b2;
00050                             b2 = b0;
00051                             b0 = b1;
00052                             b1 = t;
00053                      }
00054                      else 
00055                      {
00056                             // If Unix order is "Cancel, No, Yes"
00057                             t = b2;
00058                             b2=b0;
00059                             b0=t;
00060                      }
00061                      buttonsUsed=3;
00062               }
00063        }
00064        return buttonsUsed;
00065 }
00066 
00067 int ScMessageBox::swapButtonValues(QString &b0Text, QString &b1Text, QString &b2Text, int &defaultButton, int &escapeButton)
00068 {
00069        int buttonsUsed=1;
00070        if (ScCore->reverseDialogButtons())
00071        {
00072               //Last button not used, and 2nd one used, swap 1st and 2nd.
00073               if (b2Text.isEmpty() && !b1Text.isEmpty())
00074               {
00075                      QString tText=b1Text;
00076                      b1Text=b0Text;
00077                      b0Text=tText;
00078                      if (defaultButton==0)
00079                             defaultButton=1;
00080                      else
00081                      if (defaultButton==1)
00082                             defaultButton=0;
00083                      if (escapeButton==0)
00084                             escapeButton=1;
00085                      else
00086                      if (escapeButton==1)
00087                             escapeButton=0;
00088                      buttonsUsed=2;
00089               }
00090               //All three buttons used, swap the outside ones only
00091               if (!b2Text.isEmpty() && !b1Text.isEmpty() && !b0Text.isEmpty())
00092               {
00093                      QString tText;
00094                      if (ScCore->isMacGUI())
00095                      {
00096                             // Mac order is "No, Cancel, Yes"
00097                             tText = b2Text;
00098                             b2Text = b0Text;
00099                             b0Text = b1Text;
00100                             b1Text = tText;
00101 
00102                             switch (defaultButton) {
00103                             case 0:
00104                                    defaultButton=2;
00105                                    break;
00106                             case 1:
00107 
00108                                    break;
00109                             case 2:
00110                                    defaultButton=0;
00111                             }
00112 
00113                             switch (escapeButton) {
00114                             case 0:
00115                                    escapeButton=2;
00116                                    break;
00117                             case 1:
00118                                    escapeButton=0;
00119                                    break;
00120                             case 2:
00121                                    escapeButton=1;
00122                             }
00123                      }
00124                      else 
00125                      {
00126                             // Unix order is "Cancel, No, Yes"
00127                             tText = b2Text;
00128                             b2Text=b0Text;
00129                             b0Text=tText;
00130                             if (defaultButton==0)
00131                                    defaultButton=2;
00132                             else
00133                             if (defaultButton==2)
00134                                    defaultButton=0;
00135                             if (escapeButton==0)
00136                                    escapeButton=2;
00137                             else
00138                             if (escapeButton==2)
00139                                    escapeButton=0;
00140                      }
00141                      buttonsUsed=3;
00142               }
00143        }
00144        return buttonsUsed;
00145 }
00146 
00147 int ScMessageBox::swapReturnValues(const int b0Val, const int b1Val, const int b2Val, const int returnVal, const int buttonsUsed)
00148 {
00149        int retVal=returnVal;
00150        if (ScCore->reverseDialogButtons())
00151        {
00152               //Last button not used, and 2nd one used, swap 1st and 2nd.
00153               if (buttonsUsed==2)
00154               {
00155                      if (returnVal==b0Val)
00156                             retVal=b1Val;
00157                      else
00158                      if (returnVal==b1Val)
00159                             retVal=b0Val;
00160               }
00161               
00162               //All three buttons used, swap the outside ones only
00163               if (buttonsUsed==3)
00164               {
00165                      if (ScCore->isMacGUI()) {
00166                             if (returnVal == b0Val)
00167                                    retVal = b1Val;
00168                             else if (returnVal == b1Val)
00169                                    retVal = b2Val;
00170                             else if (returnVal == b2Val)
00171                                    retVal = b0Val;
00172                      }
00173                      else
00174                      {
00175                             if (returnVal==b0Val)
00176                                    retVal=b2Val;
00177                             else
00178                             if (returnVal==b2Val)
00179                                    retVal=b0Val;
00180 
00181                      }
00182               }
00183        }
00184        return retVal;
00185 }
00186 
00187 int ScMessageBox::information ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1, int button2)
00188 {
00189        int b0=button0, b1=button1, b2=button2;
00190        int buttonsUsed=swapButtonValues(b0, b1, b2);
00191        int stdReturn=QMessageBox::information(parent, caption, text, b0, b1, b2);
00192        return swapReturnValues(b0, b1, b2, stdReturn, buttonsUsed);
00193 }
00194 
00195 int ScMessageBox::information ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text, const QString & button1Text, const QString & button2Text, int defaultButtonNumber, int escapeButtonNumber)
00196 {
00197        QString b0Text=button0Text, b1Text=button1Text, b2Text=button2Text;
00198        int defaultButton=defaultButtonNumber, escapeButton=escapeButtonNumber;
00199        int buttonsUsed=swapButtonValues(b0Text, b1Text, b2Text, defaultButton, escapeButton);
00200        int stdReturn=QMessageBox::information(parent, caption, text, b0Text, b1Text, b2Text, defaultButton, escapeButton);
00201        return swapReturnValues(0, 1, 2, stdReturn, buttonsUsed);
00202 }
00203 
00204 int ScMessageBox::question ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1, int button2)
00205 {
00206        int b0=button0, b1=button1, b2=button2;
00207        int buttonsUsed=swapButtonValues(b0, b1, b2);
00208        int stdReturn=QMessageBox::question(parent, caption, text, b0, b1, b2);
00209        return swapReturnValues(b0, b1, b2, stdReturn, buttonsUsed);
00210 }
00211 
00212 int ScMessageBox::question ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text, const QString & button1Text, const QString & button2Text, int defaultButtonNumber, int escapeButtonNumber)
00213 {
00214        QString b0Text=button0Text, b1Text=button1Text, b2Text=button2Text;
00215        int defaultButton=defaultButtonNumber, escapeButton=escapeButtonNumber;
00216        int buttonsUsed=swapButtonValues(b0Text, b1Text, b2Text, defaultButton, escapeButton);
00217        int stdReturn=QMessageBox::question(parent, caption, text, b0Text, b1Text, b2Text, defaultButton, escapeButton);
00218        return swapReturnValues(0, 1, 2, stdReturn, buttonsUsed);
00219 }
00220 
00221 int ScMessageBox::warning ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1, int button2)
00222 {
00223        int b0=button0, b1=button1, b2=button2;
00224        int buttonsUsed=swapButtonValues(b0, b1, b2);
00225        int stdReturn=QMessageBox::warning(parent, caption, text, b0, b1, b2);
00226        return swapReturnValues(b0, b1, b2, stdReturn, buttonsUsed);
00227 }
00228 
00229 int ScMessageBox::warning ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text, const QString & button1Text, const QString & button2Text, int defaultButtonNumber, int escapeButtonNumber)
00230 {
00231        QString b0Text=button0Text, b1Text=button1Text, b2Text=button2Text;
00232        int defaultButton=defaultButtonNumber, escapeButton=escapeButtonNumber;
00233        int buttonsUsed=swapButtonValues(b0Text, b1Text, b2Text, defaultButton, escapeButton);
00234        int stdReturn=QMessageBox::warning(parent, caption, text, b0Text, b1Text, b2Text, defaultButton, escapeButton);
00235        return swapReturnValues(0, 1, 2, stdReturn, buttonsUsed);
00236 }
00237 
00238 int ScMessageBox::critical ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1, int button2)
00239 {
00240        int b0=button0, b1=button1, b2=button2;
00241        int buttonsUsed=swapButtonValues(b0, b1, b2);
00242        int stdReturn=QMessageBox::critical(parent, caption, text, b0, b1, b2);
00243        return swapReturnValues(b0, b1, b2, stdReturn, buttonsUsed);
00244 }
00245 
00246 int ScMessageBox::critical ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text, const QString & button1Text, const QString & button2Text, int defaultButtonNumber, int escapeButtonNumber)
00247 {
00248        QString b0Text=button0Text, b1Text=button1Text, b2Text=button2Text;
00249        int defaultButton=defaultButtonNumber, escapeButton=escapeButtonNumber;
00250        int buttonsUsed=swapButtonValues(b0Text, b1Text, b2Text, defaultButton, escapeButton);
00251        int stdReturn=QMessageBox::critical(parent, caption, text, b0Text, b1Text, b2Text, defaultButton, escapeButton);
00252        return swapReturnValues(0, 1, 2, stdReturn, buttonsUsed);
00253 }
00254 
00255