Back to index

plt-scheme  4.2.1
CheckBox.cc
Go to the documentation of this file.
00001 /*                                                      -*- C++ -*-
00002  *
00003  * Purpose: check box 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 "CheckBox.h"
00029 #endif
00030 
00031 #define  Uses_XtIntrinsic
00032 #define  Uses_wxCheckBox
00033 #include "wx.h"
00034 #define  Uses_TraversingEnforcerWidget
00035 #define  Uses_ToggleWidget
00036 #include "widgets.h"
00037 
00038 //-----------------------------------------------------------------------------
00039 // create and destroy button
00040 //-----------------------------------------------------------------------------
00041 
00042 wxCheckBox::wxCheckBox(wxPanel *panel, wxFunction function, char *label,
00043                      int x, int y, int width, int height,
00044                      long style, wxFont *_font, char *name) : wxItem(_font)
00045 {
00046     __type = wxTYPE_CHECK_BOX;
00047 
00048     Create(panel, function, label, x, y, width, height, style, name);
00049 }
00050 
00051 wxCheckBox::wxCheckBox(wxPanel *panel, wxFunction function, wxBitmap *bitmap,
00052                      int x, int y, int width, int height,
00053                      long style, wxFont *_font, char *name) : wxItem(_font)
00054 {
00055     __type = wxTYPE_CHECK_BOX;
00056 
00057     Create(panel, function, bitmap, x, y, width, height, style, name);
00058 }
00059 
00060 Bool wxCheckBox::Create(wxPanel *panel, wxFunction function, char *label,
00061                      int x, int y, int width, int height,
00062                      long style, char *name)
00063 {
00064     wxWindow_Xintern *ph;
00065     Widget wgt;
00066 
00067     ChainToPanel(panel, style, name);
00068 
00069     // label = wxGetCtlLabel(label);
00070     bm_label = NULL;
00071 
00072     ph = parent->GetHandle();
00073 
00074     // create frame
00075     wgt = XtVaCreateWidget
00076        (name, xfwfTraversingEnforcerWidgetClass, ph->handle,
00077         XtNbackground,  wxGREY_PIXEL,
00078         XtNforeground,  wxBLACK_PIXEL,
00079         XtNhighlightColor, wxCTL_HIGHLIGHT_PIXEL,
00080         XtNfont,        font->GetInternalFont(),
00081 #ifdef WX_USE_XFT
00082         XtNxfont,       font->GetInternalAAFont(),
00083 #endif
00084         XtNshrinkToFit, (width < 0 || height < 0),
00085         NULL);
00086     if (!(style & wxINVISIBLE))
00087       XtManageChild(wgt);
00088     else
00089       XtRealizeWidget(wgt);
00090     X->frame = wgt;
00091     // create widget
00092     wgt = XtVaCreateManagedWidget
00093        ("checkbox", xfwfToggleWidgetClass, X->frame,
00094         XtNlabel,       label,
00095         XtNbackground,  wxGREY_PIXEL,
00096         XtNforeground,  wxBLACK_PIXEL,
00097         XtNhighlightColor, wxCTL_HIGHLIGHT_PIXEL,
00098         XtNfont,        font->GetInternalFont(),
00099 #ifdef WX_USE_XFT
00100         XtNxfont,       font->GetInternalAAFont(),
00101 #endif
00102         XtNshrinkToFit, (width < 0 || height < 0),
00103         XtNhighlightThickness, 0, XtNtraversalOn, FALSE,
00104         NULL);
00105     X->handle = wgt;
00106     // propagate key events from frame to checkbox widget
00107     XtVaSetValues(X->frame, XtNpropagateTarget, X->handle, NULL);
00108     // set data declared in wxItem
00109     callback = function;
00110     XtAddCallback(X->handle, XtNonCallback,  wxCheckBox::OnEventCallback,
00111                 (XtPointer)saferef);
00112     XtAddCallback(X->handle, XtNoffCallback, wxCheckBox::OnEventCallback,
00113                 (XtPointer)saferef);
00114 
00115     panel->PositionItem(this, x, y, width, height);
00116     AddEventHandlers();
00117 
00118     if (style & wxINVISIBLE)
00119       Show(FALSE);
00120 
00121     return TRUE;
00122 }
00123 
00124 Bool wxCheckBox::Create(wxPanel *panel, wxFunction function, wxBitmap *bitmap,
00125                      int x, int y, int width, int height,
00126                      long style, char *name)
00127 {
00128     wxWindow_Xintern *ph;
00129     Widget wgt;
00130     Pixmap pm, mpm;
00131 
00132     if (!bitmap->Ok() || (bitmap->selectedIntoDC < 0))
00133       return Create(panel, function, "<bad-image>", x, y, width, height, style, name);
00134 
00135     bitmap->selectedIntoDC++;
00136     bm_label = bitmap;
00137 
00138     bm_label_mask = CheckMask(bm_label);
00139 
00140     ChainToPanel(panel, style, name);
00141 
00142     ph = parent->GetHandle();
00143 
00144     // create frame
00145     wgt = XtVaCreateWidget
00146        (name, xfwfTraversingEnforcerWidgetClass, ph->handle,
00147         XtNbackground,  wxGREY_PIXEL,
00148         XtNforeground,  wxBLACK_PIXEL,
00149         XtNhighlightColor, wxCTL_HIGHLIGHT_PIXEL,
00150         XtNfont,        font->GetInternalFont(),
00151         XtNshrinkToFit, (width < 0 || height < 0),
00152         NULL);
00153     if (!(style & wxINVISIBLE))
00154       XtManageChild(wgt);
00155     X->frame = wgt;
00156     // create widget
00157     pm = (Pixmap)bitmap->GetLabelPixmap();
00158     if (bm_label_mask)
00159       mpm = GETPIXMAP(bm_label_mask);
00160     else
00161       mpm = 0;
00162     wgt = XtVaCreateManagedWidget
00163        ("checkbox", xfwfToggleWidgetClass, X->frame,
00164         XtNpixmap,      pm,
00165         XtNmaskmap,     mpm,
00166         XtNbackground,  wxGREY_PIXEL,
00167         XtNforeground,  wxBLACK_PIXEL,
00168         XtNhighlightColor, wxCTL_HIGHLIGHT_PIXEL,
00169         XtNfont,        font->GetInternalFont(),
00170         XtNshrinkToFit, (width < 0 || height < 0),
00171         XtNhighlightThickness, 0, XtNtraversalOn, FALSE,
00172         NULL);
00173     X->handle = wgt;
00174     // propagate key events from frame to checkbox widget
00175     XtVaSetValues(X->frame, XtNpropagateTarget, X->handle, NULL);
00176     // set data declared in wxItem
00177     callback = function;
00178     XtAddCallback(X->handle, XtNonCallback,  wxCheckBox::OnEventCallback,
00179                 (XtPointer)saferef);
00180     XtAddCallback(X->handle, XtNoffCallback, wxCheckBox::OnEventCallback,
00181                 (XtPointer)saferef);
00182 
00183     panel->PositionItem(this, x, y, width, height);
00184     AddEventHandlers();
00185 
00186     if (style & wxINVISIBLE)
00187       Show(FALSE);
00188 
00189     return TRUE;
00190 }
00191 
00192  wxCheckBox::~wxCheckBox()
00193 {
00194   if (bm_label) {
00195     --bm_label->selectedIntoDC;
00196     bm_label->ReleaseLabel();
00197     XtVaSetValues(X->handle, XtNpixmap, NULL, XtNmaskmap, NULL, NULL);
00198   }
00199   if (bm_label_mask) {
00200     --bm_label_mask->selectedIntoDC;
00201   }
00202 }
00203 
00204 //-----------------------------------------------------------------------------
00205 // alternate SetLabel for changing bitmap
00206 //-----------------------------------------------------------------------------
00207 
00208 void wxCheckBox::SetLabel(char *label)
00209 {
00210   if (!bm_label) {
00211     label = wxGetCtlLabel(label);
00212     
00213     XtVaSetValues(X->handle, XtNlabel, label, NULL);
00214   }
00215 }
00216 
00217 void wxCheckBox::SetLabel(wxBitmap *bitmap)
00218 {
00219   if (bm_label && bitmap && bitmap->Ok() && (bitmap->selectedIntoDC >= 0)
00220       && (bitmap->GetDepth()==1 || bitmap->GetDepth()==wxDisplayDepth())) {
00221     Pixmap pm, mpm;
00222 
00223     --bm_label->selectedIntoDC;
00224     bm_label->ReleaseLabel();
00225     if (bm_label_mask) {
00226       --bm_label_mask->selectedIntoDC;
00227       bm_label_mask = NULL;
00228     }
00229 
00230     bm_label = bitmap;
00231     bm_label->selectedIntoDC++;
00232 
00233     bm_label_mask = CheckMask(bm_label);
00234 
00235     pm = (Pixmap)bitmap->GetLabelPixmap();
00236     if (bm_label_mask)
00237       mpm = GETPIXMAP(bm_label_mask);
00238     else
00239       mpm = 0;
00240 
00241     XtVaSetValues(X->handle, 
00242                 XtNpixmap, pm, 
00243                 XtNmaskmap, mpm, 
00244                 NULL);
00245   }
00246 }
00247 
00248 
00249 char *wxCheckBox::GetLabel(void)
00250 {
00251     char *label = NULL;
00252 
00253     if (!X->handle) // forbid, if no widget associated
00254        return NULL;
00255 
00256     XtVaGetValues(X->handle, XtNlabel, &label, NULL);
00257     return label;
00258 }
00259 
00260 //-----------------------------------------------------------------------------
00261 // wxCheckBox: set & query state
00262 //-----------------------------------------------------------------------------
00263 
00264 Bool wxCheckBox::GetValue(void)
00265 {
00266     Boolean state;
00267     XtVaGetValues(X->handle, XtNon, &state, NULL);
00268     return state;
00269 }
00270 
00271 void wxCheckBox::SetValue(Bool state)
00272 {
00273   XtVaSetValues(X->handle, XtNon, (Boolean)state, NULL);
00274 }
00275 
00276 void wxCheckBox::Command(wxCommandEvent *event)
00277 {
00278   ProcessCommand (event);
00279 }
00280 
00281 //-----------------------------------------------------------------------------
00282 // callbacks for xfwfToggleWidgetClass
00283 //-----------------------------------------------------------------------------
00284 
00285 void wxCheckBox::OnEventCallback(Widget WXUNUSED(w),
00286                              XtPointer clientData, XtPointer WXUNUSED(ptr))
00287 {
00288     wxCheckBox     *checkbox = (wxCheckBox *)GET_SAFEREF(clientData);
00289     wxCommandEvent *event;
00290 
00291     event = new wxCommandEvent(wxEVENT_TYPE_CHECKBOX_COMMAND);
00292 
00293     checkbox->ProcessCommand(event);
00294 
00295 #ifdef MZ_PRECISE_GC
00296   XFORM_RESET_VAR_STACK;
00297 #endif
00298 }