Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

htiobox.cc

Go to the documentation of this file.
00001 /*
00002  *      HT Editor
00003  *      htiobox.cc
00004  *
00005  *      Copyright (C) 1999-2002 Stefan Weyergraf (stefan@weyergraf.de)
00006  *
00007  *      This program is free software; you can redistribute it and/or modify
00008  *      it under the terms of the GNU General Public License version 2 as
00009  *      published by the Free Software Foundation.
00010  *
00011  *      This program is distributed in the hope that it will be useful,
00012  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *      GNU General Public License for more details.
00015  *
00016  *      You should have received a copy of the GNU General Public License
00017  *      along with this program; if not, write to the Free Software
00018  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #include "htatom.h"
00022 #include "htctrl.h"
00023 #include "htdialog.h"
00024 #include "hthist.h"
00025 #include "htiobox.h"
00026 #include "snprintf.h"
00027 #include "tools.h"
00028 
00029 #include <stdarg.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032 
00033 int imsgbox(bounds *b, int buttonmask, const char *title, bool modal, statictext_align align, char *buf)
00034 {
00035         ht_dialog *dialog=new ht_dialog();
00036         dialog->init(b, title, FS_KILLER | FS_TITLE | (modal ? 0 : FS_MOVE | FS_RESIZE));
00037 
00038         bounds c;
00039 
00040         c.x=1;
00041         c.y=0;
00042         c.w=b->w-4;
00043         c.h=b->h-4;
00044         ht_statictext *text=new ht_statictext();
00045         text->init(&c, buf, align);
00046         text->growmode = MK_GM(GMH_FIT, GMV_FIT);
00047 
00048         dialog->insert(text);
00049 
00050         int buttons=0;
00051         if (buttonmask & btmask_ok) buttons++; else
00052         if (buttonmask & btmask_yes) buttons++;
00053         if (buttonmask & btmask_no) buttons++; else
00054         if (buttonmask & btmask_skip) buttons++;
00055         if (buttonmask & btmask_cancel) buttons++;
00056         if (buttonmask & btmask_all) buttons++;
00057         if (buttonmask & btmask_none) buttons++;
00058 
00059         int pos=0;
00060         if (buttonmask & btmask_ok) {
00061                 c.x=b->w/2-5*(buttons-2*pos);
00062                 c.y=b->h-4;
00063                 c.w=9;
00064                 c.h=2;
00065                 ht_button *button=new ht_button();
00066                 button->init(&c, "O~K", button_ok);
00067                 button->growmode = MK_GM(GMH_LEFT, GMV_BOTTOM);
00068                 dialog->insert(button);
00069                 pos++;
00070         } else if (buttonmask & btmask_yes) {
00071                 c.x=b->w/2-5*(buttons-2*pos);
00072                 c.y=b->h-4;
00073                 c.w=9;
00074                 c.h=2;
00075                 ht_button *button=new ht_button();
00076                 button->init(&c, "~Yes", button_yes);
00077                 button->growmode = MK_GM(GMH_LEFT, GMV_BOTTOM);
00078                 dialog->insert(button);
00079                 pos++;
00080         }
00081         if (buttonmask & btmask_no) {
00082                 c.x=b->w/2-5*(buttons-2*pos);
00083                 c.y=b->h-4;
00084                 c.w=9;
00085                 c.h=2;
00086                 ht_button *button=new ht_button();
00087                 button->init(&c, "~No", button_no);
00088                 button->growmode = MK_GM(GMH_LEFT, GMV_BOTTOM);
00089                 dialog->insert(button);
00090                 pos++;
00091         } else if (buttonmask & btmask_skip) {
00092                 c.x=b->w/2-5*(buttons-2*pos);
00093                 c.y=b->h-4;
00094                 c.w=9;
00095                 c.h=2;
00096                 ht_button *button=new ht_button();
00097                 button->init(&c, "~Skip", button_skip);
00098                 button->growmode = MK_GM(GMH_LEFT, GMV_BOTTOM);
00099                 dialog->insert(button);
00100                 pos++;
00101         }
00102         if (buttonmask & btmask_all) {
00103                 c.x=b->w/2-5*(buttons-2*pos);
00104                 c.y=b->h-4;
00105                 c.w=9;
00106                 c.h=2;
00107                 ht_button *button=new ht_button();
00108                 button->init(&c, "~All", button_all);
00109                 button->growmode = MK_GM(GMH_LEFT, GMV_BOTTOM);
00110                 dialog->insert(button);
00111                 pos++;
00112         }
00113         if (buttonmask & btmask_none) {
00114                 c.x=b->w/2-5*(buttons-2*pos);
00115                 c.y=b->h-4;
00116                 c.w=9;
00117                 c.h=2;
00118                 ht_button *button=new ht_button();
00119                 button->init(&c, "~None", button_none);
00120                 button->growmode = MK_GM(GMH_LEFT, GMV_BOTTOM);
00121                 dialog->insert(button);
00122                 pos++;
00123         }
00124         if (buttonmask & btmask_cancel) {
00125                 c.x=b->w/2-5*(buttons-2*pos);
00126                 c.y=b->h-4;
00127                 c.w=9;
00128                 c.h=2;
00129                 ht_button *button=new ht_button();
00130                 button->init(&c, "~Cancel", button_cancel);
00131                 button->growmode = MK_GM(GMH_LEFT, GMV_BOTTOM);
00132                 dialog->insert(button);
00133                 pos++;
00134         }
00135         if (!buttons) {
00136                 bounds x;
00137                 text->getbounds(&x);
00138                 x.h+=2;
00139                 text->setbounds(&x);
00140         }
00141 
00142         int r=dialog->run(modal);
00143         dialog->done();
00144         delete dialog;
00145         return r;
00146 }
00147 
00148 int msgbox(int buttonmask, const char *title, bool modal, statictext_align align, const char *format, ...)
00149 {
00150         char buf[1024];
00151         va_list arg;
00152         va_start(arg, format);
00153         ht_vsnprintf(buf, 1024, format, arg);
00154         va_end(arg);
00155 
00156         char *s=buf;
00157         int ns=1;
00158         while ((s=strchr(s, '\n'))) {
00159                 s++;
00160                 ns++;
00161         }
00162         int strl=strlen(buf);
00163 
00164         bounds b;
00165         app->getbounds(&b);
00166         b.w=55;
00167         b.h=MAX(strl/(b.w-4), ns)+6;
00168         b.x=(screen->size.w-b.w)/2;
00169         b.y=(screen->size.h-b.h)/2;
00170         return imsgbox(&b, buttonmask, title, modal, align, buf);
00171 }
00172 
00173 int msgboxrect(bounds *b, int buttonmask, const char *title, bool modal, statictext_align align, const char *format, ...)
00174 {
00175         char buf[1024];
00176         va_list arg;
00177         va_start(arg, format);
00178         ht_vsnprintf(buf, 1024, format, arg);
00179         va_end(arg);
00180 
00181         return imsgbox(b, buttonmask, title, modal, align, buf);
00182 }
00183 
00184 bool inputbox(const char *title, const char *label, char *result, int limit, dword histid)
00185 {
00186         bounds b;
00187         app->getbounds(&b);
00188         b.x = (b.w - 60) / 2,
00189         b.y = (b.h - 8) / 2;
00190         b.w = 60;
00191         b.h = 8;
00192         return inputboxrect(&b, title, label, result, limit, histid);
00193 }
00194 
00195 bool inputboxrect(bounds *b, const char *title, const char *label, char *result, int limit, dword histid)
00196 {
00197         ht_dialog *dialog=new ht_dialog();
00198         dialog->init(b, title, FS_KILLER | FS_TITLE | FS_MOVE | FS_RESIZE);
00199 
00200         ht_strinputfield *input;
00201 
00202         bounds  b2;
00203         b2.x = 3 + strlen(label);
00204         b2.y = 1;
00205         b2.w = b->w - 3 - b2.x;
00206         b2.h = 1;
00207 
00208         ht_clist *hist = 0;
00209         if (histid) hist = (ht_clist*)find_atom(histid);
00210         input = new ht_strinputfield();
00211         input->init(&b2, limit, hist);
00212         ht_inputfield_data d;
00213         d.text = (byte *)result;
00214         d.textlen = strlen((char*)d.text);
00215         input->databuf_set(&d, sizeof d);
00216         dialog->insert(input);
00217 
00218         if (label) {
00219                 b2.x = 1;
00220                 b2.y = 1;
00221                 b2.w = 3 + strlen(label) - b2.x;
00222                 b2.h = 1;
00223 
00224                 ht_label *lab = new ht_label();
00225                 lab->init(&b2, label, input);
00226                 dialog->insert(lab);
00227         }
00228 
00229         b2.x = b->w - 25;
00230         b2.y = b->h - 5;
00231         b2.w = 10;
00232         b2.h = 2;
00233 
00234         ht_button *bok = new ht_button();
00235         bok->init(&b2, "O~k", button_ok);
00236         dialog->insert(bok);
00237 
00238         b2.x += 12;
00239 
00240         ht_button *bcancel = new ht_button();
00241         bcancel->init(&b2, "~Cancel", button_cancel);
00242         dialog->insert(bcancel);
00243 
00244         if (dialog->run(0)) {
00245                 int dsize = input->datasize();
00246                 ht_inputfield_data *data=(ht_inputfield_data*)malloc(dsize);
00247                 input->databuf_get(data, dsize);
00248                 bin2str(result, data->text, data->textlen);
00249                 free(data);
00250                 if (hist) insert_history_entry(hist, result, 0);
00251 
00252                 dialog->done();
00253                 delete dialog;
00254                 return true;
00255         }
00256         dialog->done();
00257         delete dialog;
00258         return false;
00259 }
00260 
00261 void get_std_progress_indicator_metrics(bounds *b)
00262 {
00263         app->getbounds(b);
00264         b->w=b->w*2/3;
00265         b->h=6;
00266         b->x=(screen->size.w-b->w)/2;
00267         b->y=(screen->size.h-b->h)/2;
00268 }
00269 

Generated on Fri May 7 21:15:34 2004 by doxygen 1.3.5