Back to index

plt-scheme  4.2.1
Message.cc
Go to the documentation of this file.
00001 /*                                                      -*- C++ -*-
00002  *
00003  * Purpose: message panel item
00004  *
00005  * Authors: Markus Holzem and Julian Smart
00006  *
00007  * Copyright: (C) 2004-2009 PLT Scheme Inc.
00008  * Copyright: (C) 1995, AIAI, University of Edinburgh (Julian)
00009  * Copyright: (C) 1995, GNU (Markus)
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00024  * 02110-1301 USA.
00025  */
00026 
00027 #ifdef __GNUG__
00028 #pragma implementation "Message.h"
00029 #endif
00030 
00031 #define  Uses_XtIntrinsic
00032 #define  Uses_wxMessage
00033 #define  Uses_wxBitmap
00034 #include "wx.h"
00035 #define  Uses_EnforcerWidget
00036 #define  Uses_LabelWidget
00037 #include "widgets.h"
00038 
00039 static char * info_xpm[] = {
00040 "32 32 17 1",
00041 "      c None",
00042 ".     c #000000",
00043 "+     c #800000",
00044 "@     c #008000",
00045 "#     c #808000",
00046 "$     c #000080",
00047 "%     c #800080",
00048 "&     c #008080",
00049 "*     c #808080",
00050 "=     c #D6D6D6",
00051 "-     c #FF0000",
00052 ";     c #00FF00",
00053 ">     c #FFFF00",
00054 ",     c #0000FF",
00055 "'     c #FF00FF",
00056 ")     c #00FFFF",
00057 "!     c #FFFFFF",
00058 "================================",
00059 "================================",
00060 "=============,,,,,,,============",
00061 "==========,,,,,,,,,,,,,=========",
00062 "=========,,,,,,,,,,,,,,,========",
00063 "=======,,,,,,,,,,,,,,,,,,,======",
00064 "======,,,,,,,,,,,,,,,,,,,,,=====",
00065 "======,,,,,,,,,,,,,,,,,,,,,=====",
00066 "=====,,,,,,,,,,,,,,,,,,,,,,,====",
00067 "====,,,,,,,,,,,!!!,,,,,,,,,,,===",
00068 "====,,,,,,,,,,,!!!,,,,,,,,,,,===",
00069 "====,,,,,,,,,,,,,,,,,,,,,,,,,===",
00070 "===,,,,,,,,,,,,,,,,,,,,,,,,,,,==",
00071 "===,,,,,,,,,,,!!!!,,,,,,,,,,,,==",
00072 "===,,,,,,,,,,,,!!!,,,,,,,,,,,,==",
00073 "===,,,,,,,,,,,,!!!,,,,,,,,,,,,==",
00074 "===,,,,,,,,,,,,!!!,,,,,,,,,,,,==",
00075 "===,,,,,,,,,,,,!!!,,,,,,,,,,,,==",
00076 "===,,,,,,,,,,,,!!!,,,,,,,,,,,,==",
00077 "====,,,,,,,,,,,!!!,,,,,,,,,,,===",
00078 "====,,,,,,,,,,!!!!!,,,,,,,,,,===",
00079 "====,,,,,,,,,,,,,,,,,,,,,,,,,===",
00080 "=====,,,,,,,,,,,,,,,,,,,,,,,====",
00081 "======,,,,,,,,,,,,,,,,,,,,,=====",
00082 "======,,,,,,,,,,,,,,,,,,,,,=====",
00083 "=======,,,,,,,,,,,,,,,,,,,======",
00084 "=========,,,,,,,,,,,,,,,========",
00085 "==========,,,,,,,,,,,,,=========",
00086 "=============,,,,,,,============",
00087 "================================",
00088 "================================",
00089 "================================"};
00090 
00091 static char * caution_xpm[] = {
00092 "32 32 17 1",
00093 "      c None",
00094 ".     c #000000",
00095 "+     c #800000",
00096 "@     c #008000",
00097 "#     c #808000",
00098 "$     c #000080",
00099 "%     c #800080",
00100 "&     c #008080",
00101 "*     c #808080",
00102 "=     c #D6D6D6",
00103 "-     c #FF0000",
00104 ";     c #00FF00",
00105 ">     c #FFFF00",
00106 ",     c #0000FF",
00107 "'     c #FF00FF",
00108 ")     c #00FFFF",
00109 "!     c #FFFFFF",
00110 "================================",
00111 "================================",
00112 "================================",
00113 "================>===============",
00114 "===============>>>==============",
00115 "===============>>>==============",
00116 "==============>>>>>=============",
00117 "==============>>>>>=============",
00118 "=============>>>>>>>============",
00119 "=============>>>>>>>============",
00120 "============>>>..>>>>===========",
00121 "============>>....>>>===========",
00122 "===========>>>....>>>>==========",
00123 "===========>>>....>>>>==========",
00124 "==========>>>>....>>>>>=========",
00125 "==========>>>>....>>>>>=========",
00126 "=========>>>>>....>>>>>>========",
00127 "=========>>>>>>..>>>>>>>========",
00128 "========>>>>>>>..>>>>>>>>=======",
00129 "========>>>>>>>..>>>>>>>>=======",
00130 "=======>>>>>>>>..>>>>>>>>>======",
00131 "=======>>>>>>>>>>>>>>>>>>>======",
00132 "======>>>>>>>>>>>>>>>>>>>>>=====",
00133 "======>>>>>>>>>>>>>>>>>>>>>=====",
00134 "=====>>>>>>>>>>..>>>>>>>>>>>====",
00135 "=====>>>>>>>>>>..>>>>>>>>>>>====",
00136 "====>>>>>>>>>>>>>>>>>>>>>>>>>===",
00137 "====>>>>>>>>>>>>>>>>>>>>>>>>>===",
00138 "================================",
00139 "================================",
00140 "================================",
00141 "================================"};
00142 
00143 static char * stop_xpm[] = {
00144 "32 32 17 1",
00145 "      c None",
00146 ".     c #000000",
00147 "+     c #800000",
00148 "@     c #008000",
00149 "#     c #808000",
00150 "$     c #000080",
00151 "%     c #800080",
00152 "&     c #008080",
00153 "*     c #808080",
00154 "=     c #D6D6D6",
00155 "-     c #FF0000",
00156 ";     c #00FF00",
00157 ">     c #FFFF00",
00158 ",     c #0000FF",
00159 "'     c #FF00FF",
00160 ")     c #00FFFF",
00161 "!     c #FFFFFF",
00162 "================================",
00163 "================================",
00164 "==========-----------===========",
00165 "=========-------------==========",
00166 "========---------------=========",
00167 "=======-----------------========",
00168 "======-------------------=======",
00169 "=====---------------------======",
00170 "====-----------------------=====",
00171 "===-------------------------====",
00172 "==----------!-----!----------===",
00173 "==---------!!!---!!!---------===",
00174 "==----------!!!-!!!----------===",
00175 "==-----------!!!!!-----------===",
00176 "==------------!!!------------===",
00177 "==------------!!!------------===",
00178 "==-----------!!!!!-----------===",
00179 "==----------!!!-!!!----------===",
00180 "==---------!!!---!!!---------===",
00181 "==----------!-----!----------===",
00182 "==---------------------------===",
00183 "===-------------------------====",
00184 "====-----------------------=====",
00185 "=====---------------------======",
00186 "======-------------------=======",
00187 "=======-----------------========",
00188 "========---------------=========",
00189 "=========-------------==========",
00190 "==========-----------===========",
00191 "================================",
00192 "================================",
00193 "================================"};
00194 
00195 static int icons_loaded;
00196 static wxBitmap *icons[3];
00197 
00198 //-----------------------------------------------------------------------------
00199 // create and destroy message
00200 //-----------------------------------------------------------------------------
00201 
00202 wxMessage::wxMessage(wxPanel *panel, char *message,
00203                  int x, int y, long style, wxFont *_font, char *name) : wxItem(_font)
00204 {
00205     __type = wxTYPE_MESSAGE;
00206     Create(panel, message, x, y, style, name);
00207 }
00208 
00209 wxMessage::wxMessage(wxPanel *panel, wxBitmap *bitmap,
00210                  int x, int y, long style, wxFont *_font, char *name) : wxItem(_font)
00211 {
00212     __type = wxTYPE_MESSAGE;
00213     Create(panel, bitmap, x, y, style, name);
00214 }
00215 
00216 wxMessage::wxMessage(wxPanel *panel, int iconId,
00217                  int x, int y, long style, wxFont *_font, char *name) : wxItem(_font)
00218 {
00219     __type = wxTYPE_MESSAGE;
00220     Create(panel, NULL, NULL, iconId, x, y, style, name);
00221 }
00222 
00223 static void do_nothing()
00224 {
00225 }
00226 
00227 Bool wxMessage::Create(wxPanel *panel, char *message,
00228                     int x, int y, long style, char *name)
00229 {
00230   return Create(panel, message, NULL, 0, x, y, style, name);
00231 }
00232 
00233 Bool wxMessage::Create(wxPanel *panel, wxBitmap *bitmap,
00234                     int x, int y, long style, char *name)
00235 {
00236   return Create(panel, NULL, bitmap, 0, x, y, style, name);
00237 }
00238 
00239 Bool wxMessage::Create(wxPanel *panel, 
00240                      char *label, wxBitmap *bitmap, int iconID, 
00241                      int x, int y,
00242                      long style, char *name)
00243 {
00244     wxWindow_Xintern *ph;
00245     Widget wgt;
00246     const char *lblT;
00247     void *lblV, *maskmap;
00248 
00249     if (iconID) {
00250       if (!icons_loaded) {
00251        icons_loaded = 1;
00252        wxREGGLOB(icons);
00253        icons[0] = new wxBitmap(info_xpm, NULL);
00254        icons[1] = new wxBitmap(caution_xpm, NULL);
00255        icons[2] = new wxBitmap(stop_xpm, NULL);
00256       }
00257 
00258       bitmap = icons[iconID - 1];
00259       if (!bitmap)
00260        label = "<bad-icon>";
00261     }
00262 
00263     if (bitmap) {
00264       if (!bitmap->Ok() || (bitmap->selectedIntoDC < 0)) {
00265        label = "<bad-image>";
00266        bitmap = NULL;
00267       } else {
00268        bitmap->selectedIntoDC++;
00269        bm_label = bitmap;
00270       }
00271     }
00272     
00273     if (!bitmap)
00274       bm_label = NULL;
00275 
00276     bm_label_mask = CheckMask(bm_label);
00277 
00278     ChainToPanel(panel, style, name);
00279 
00280     ph = parent->GetHandle();
00281 
00282     // create frame
00283     wgt = XtVaCreateWidget
00284        (name, xfwfEnforcerWidgetClass, ph->handle,
00285         XtNbackground,  wxGREY_PIXEL,
00286         XtNforeground,  wxBLACK_PIXEL,
00287         XtNfont,        font->GetInternalFont(),
00288 #ifdef WX_USE_XFT
00289         XtNxfont,       font->GetInternalAAFont(),
00290 #endif
00291         XtNshrinkToFit, TRUE,
00292         XtNhighlightThickness, 0, XtNtraversalOn, FALSE,
00293         NULL);
00294     X->frame = wgt;
00295 
00296     if (!(style & wxINVISIBLE))
00297       XtManageChild(X->frame);
00298     else
00299       XtRealizeWidget(wgt);
00300     // create widget
00301     if (bitmap) {
00302       lblT = XtNpixmap;
00303       lblV = bitmap->GetLabelPixmap();
00304     } else {
00305       lblT = XtNlabel;
00306       lblV = label;
00307     }
00308 
00309     if (bm_label_mask)
00310       maskmap = (void *)GETPIXMAP(bm_label_mask);
00311     else
00312       maskmap = 0;
00313 
00314     // create widget
00315     wgt = XtVaCreateManagedWidget
00316        ("message", xfwfLabelWidgetClass, X->frame,
00317         lblT,           lblV,
00318         XtNmaskmap,     maskmap,
00319         XtNbackground,  wxGREY_PIXEL,
00320         XtNforeground,  wxBLACK_PIXEL,
00321         XtNfont,        font->GetInternalFont(),
00322 #ifdef WX_USE_XFT
00323         XtNxfont,       font->GetInternalAAFont(),
00324 #endif
00325         XtNalignment,   wxALIGN_LEFT,
00326         XtNshrinkToFit, TRUE,
00327         XtNhighlightThickness, 0,
00328         ( !(style & wxBORDER) ) ?
00329             NULL :
00330             XtNouterOffset, 0, 
00331             XtNinnerOffset, 1,
00332             XtNframeWidth,  0,
00333             NULL);
00334 
00335     X->handle = wgt;
00336 
00337     panel->PositionItem(this, x, y, -1, -1);
00338     AddEventHandlers();
00339 
00340     /* This just turns on KeyPress events in the widget so that PreOnChar() works. */
00341     XtAddEventHandler(X->frame, KeyPressMask, FALSE, (XtEventHandler)do_nothing, NULL);
00342     XtAddEventHandler(X->handle, KeyPressMask, FALSE, (XtEventHandler)do_nothing, NULL);
00343     
00344     AllowResize(FALSE);
00345 
00346     if (style & wxINVISIBLE)
00347       Show(FALSE);
00348 
00349     return TRUE;
00350 }
00351 
00352 wxMessage::~wxMessage()
00353 {
00354   if (bm_label) {
00355     --bm_label->selectedIntoDC;
00356     bm_label->ReleaseLabel();
00357     XtVaSetValues(X->handle, XtNpixmap, NULL, XtNmaskmap, NULL, NULL);
00358   }
00359   if (bm_label_mask) {
00360     --bm_label_mask->selectedIntoDC;
00361   }
00362 }
00363 
00364 //-----------------------------------------------------------------------------
00365 // alternate SetLabel for changing bitmap
00366 //-----------------------------------------------------------------------------
00367 
00368 void wxMessage::AllowResize(Bool allow)
00369 {
00370     XtVaSetValues(X->handle, XtNshrinkToFit, allow, NULL);
00371 }
00372 
00373 void wxMessage::SetAlignment(long alignment)
00374 {
00375     XtVaSetValues(X->handle, XtNalignment, alignment, NULL);
00376 }
00377 
00378 void wxMessage::SetLabel(char *message)
00379 {
00380   message = wxGetCtlLabel(message);
00381   if (!bm_label)
00382     XtVaSetValues(X->handle, XtNlabel, message, XtNbitmap, None, NULL);
00383 }
00384 
00385 void wxMessage::SetLabel(wxBitmap *bitmap)
00386 {
00387   {
00388     /* Don't reset the label if this is an icon message: */
00389     int i;
00390     for (i = 0; i < 3; i++) {
00391       if (bm_label == icons[i])
00392        return;
00393     }
00394   }
00395 
00396   if (bm_label && bitmap && bitmap->Ok() && (bitmap->selectedIntoDC >= 0)
00397       && (bitmap->GetDepth()==1 || bitmap->GetDepth()==wxDisplayDepth())) {
00398     Pixmap pm, mpm;
00399 
00400     --bm_label->selectedIntoDC;
00401     bm_label->ReleaseLabel();
00402     if (bm_label_mask) {
00403       --bm_label_mask->selectedIntoDC;
00404       bm_label_mask = NULL;
00405     }
00406 
00407     bm_label = bitmap;
00408     bm_label->selectedIntoDC++;
00409 
00410     bm_label_mask = CheckMask(bm_label);
00411 
00412     pm = (Pixmap)bitmap->GetLabelPixmap();
00413     if (bm_label_mask)
00414       mpm = GETPIXMAP(bm_label_mask);
00415     else
00416       mpm = 0;
00417     XtVaSetValues(X->handle, 
00418                 XtNlabel, NULL, 
00419                 XtNpixmap, pm, 
00420                 XtNmaskmap, mpm, NULL);
00421   }
00422 }
00423 
00424 char *wxMessage::GetLabel(void)
00425 {
00426   char *label;
00427 
00428   if (!X->handle) // forbid, if no widget associated
00429     return NULL;
00430   
00431   label = NULL;
00432   XtVaGetValues(X->handle, XtNlabel, &label, NULL);
00433   return label;
00434 }