--- hatari/src/gui-sdl/dlgAlert.c 2019/04/01 07:11:58 1.1 +++ hatari/src/gui-sdl/dlgAlert.c 2019/04/09 08:48:53 1.1.1.8 @@ -14,18 +14,15 @@ * This file is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ARAnyM; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * GNU General Public License (gpl.txt) for more details. */ -char DlgAlert_rcsid[] = "Hatari $Id: dlgAlert.c,v 1.1 2019/04/01 07:11:58 root Exp $"; +const char DlgAlert_fileid[] = "Hatari dlgAlert.c : " __DATE__ " " __TIME__; #include #include "main.h" #include "dialog.h" +#include "screen.h" #include "sdlgui.h" @@ -33,6 +30,11 @@ char DlgAlert_rcsid[] = "Hatari $Id: dlg static char dlglines[MAX_LINES][50+1]; +#ifdef ALERT_HOOKS + // The alert hook functions + extern int HookedAlertNotice(const char* szMessage); // Must return true if OK clicked, false otherwise + extern int HookedAlertQuery(const char* szMessage); // Must return true if OK clicked, false otherwise +#endif #define DLGALERT_OK 5 #define DLGALERT_CANCEL 6 @@ -45,87 +47,101 @@ static SGOBJ alertdlg[] = { SGTEXT, 0, 0, 1,2, 50,1, dlglines[1] }, { SGTEXT, 0, 0, 1,3, 50,1, dlglines[2] }, { SGTEXT, 0, 0, 1,4, 50,1, dlglines[3] }, - { SGBUTTON, 0, 0, 5,5, 8,1, "OK" }, - { SGBUTTON, 0, 0, 24,5, 8,1, "Cancel" }, + { SGBUTTON, SG_DEFAULT, 0, 5,5, 8,1, "OK" }, + { SGBUTTON, SG_CANCEL, 0, 24,5, 8,1, "Cancel" }, { -1, 0, 0, 0,0, 0,0, NULL } }; /*-----------------------------------------------------------------------*/ -/* - Breaks long string to several strings of max_width, divided by '\0' - and returns the number of lines you need to display the strings. -*/ -static int DlgAlert_FormatTextToBox(char *text, int max_width) +/** + * Breaks long string to several strings of max_width, divided by '\0', + * sets text_width to the longest line width and returns the number of lines + * you need to display the strings. + */ +static int DlgAlert_FormatTextToBox(char *text, int max_width, int *text_width) { + int columns = 0; int lines = 1; int txtlen; - char *p; /* pointer to begin of actual line */ - char *q; /* pointer to start of next search */ - char *llb; /* pointer to last place suitable for breaking the line */ - char *txtend; /* pointer to end of the text */ + char *p; /* pointer to begin of actual line */ + char *q; /* pointer to start of next search */ + char *llb; /* pointer to last place suitable for breaking the line */ + char *txtend; /* pointer to end of the text */ txtlen = strlen(text); q = p = text; - llb = text-1; /* pointer to last line break */ + llb = text-1; /* pointer to last line break */ txtend = text + txtlen; - if (txtlen > max_width) + if (txtlen <= max_width) { - while(q < txtend) /* q was last place suitable for breaking */ + *text_width = txtlen; + return lines; + } + + while(q < txtend) /* q was last place suitable for breaking */ + { + char *r = strpbrk(q, " \t/\\\n"); /* find next suitable place for the break */ + if (r == NULL) + r = txtend; /* if there's no place then point to the end */ + + if ((r-p) <= max_width && *r != '\n') /* '\n' is always used for breaking */ { - char *r = strpbrk(q, " \t/\\\n"); /* find next suitable place for the break */ - if (r == NULL) - r = txtend; /* if there's no place then point to the end */ - - if ((r-p) < max_width && *r != '\n') /* '\n' is always used for breaking */ - { - llb = r; /* remember new place suitable for breaking */ - q++; - continue; /* search again */ - } - - if ((r-p) > max_width) /* too long line already? */ - { - if (p > llb) /* bad luck - no place for the delimiter. Let's do it the strong way */ - llb = p + max_width; /* we loose one character */ - } - else - llb = r; /* break in this place */ - - *llb = '\0'; /* BREAK */ - p = q = llb + 1; /* next line begins here */ - lines++; /* increment line counter */ + llb = r; /* remember new place suitable for breaking */ + q++; + if ((r-p) > columns) + columns = r - p; + continue; /* search again */ } + + if ((r-p) > max_width) /* too long line already? */ + { + if (p > llb) /* bad luck - no place for the delimiter. Let's do it the strong way */ + llb = p + max_width; /* we loose one character */ + } + else + llb = r; /* break from previous delimiter */ + + *llb = '\0'; /* BREAK */ + if ((llb-p) > columns) + columns = llb - p; /* longest line so far */ + p = q = llb + 1; /* next line begins here */ + lines++; /* increment line counter */ } - return lines; /* return line counter */ + *text_width = columns; + + return lines; /* return line counter */ } /*-----------------------------------------------------------------------*/ -/* - Show the "alert" dialog. Return TRUE if user pressed "OK". -*/ +/** + * Show the "alert" dialog. Return true if user pressed "OK". + */ static int DlgAlert_ShowDlg(const char *text) { + static int maxlen = sizeof(dlglines[0])-1; char *t = (char *)malloc(strlen(text)+1); char *orig_t = t; - static int maxlen = sizeof(dlglines[0])-1; - int lines; - int i; - BOOL bOldMouseVisibility; + int lines, i, len, offset; + bool bOldMouseVisibility; + int nOldMouseX, nOldMouseY; strcpy(t, text); - lines = DlgAlert_FormatTextToBox(t, maxlen); + lines = DlgAlert_FormatTextToBox(t, maxlen, &len); + offset = (maxlen-len)/2; for(i=0; i