Back to index

plt-scheme  4.2.1
Panel.cc
Go to the documentation of this file.
00001 /*                                                      -*- C++ -*-
00002  *
00003  * Purpose: base class for all panels
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 "Panel.h"
00029 #endif
00030 
00031 #define  Uses_XtIntrinsic
00032 #define  Uses_wxButton
00033 #define  Uses_wxPanel
00034 #define  Uses_wxTypeTree
00035 #include "wx.h"
00036 #define  Uses_BoardWidget
00037 #define  Uses_EnforcerWidget
00038 #include "widgets.h"
00039 
00040 #define REPORT_ZERO_WIDTH_FLAG 0x20
00041 #define REPORT_ZERO_HEIGHT_FLAG 0x40
00042 
00043 //-----------------------------------------------------------------------------
00044 // wxPanel create and destroy
00045 //-----------------------------------------------------------------------------
00046 
00047 wxPanel::wxPanel(void) : wxWindow()
00048 {
00049     __type = wxTYPE_PANEL;
00050 
00051     default_item = NULL;
00052     label_pos = wxHORIZONTAL;
00053     cursor_x = PANEL_HMARGIN;
00054     cursor_y = PANEL_VMARGIN;
00055     h_space = PANEL_HSPACING;
00056     v_space = PANEL_VSPACING;
00057     v_line_extent = 0;
00058 }
00059 
00060 wxPanel::wxPanel(wxWindow *panel, int x, int y, int width, int height,
00061                int style, char *name) : wxWindow()
00062 {
00063     __type = wxTYPE_PANEL;
00064 
00065     default_item = NULL;
00066     label_pos = wxHORIZONTAL;
00067     cursor_x = PANEL_HMARGIN;
00068     cursor_y = PANEL_VMARGIN;
00069     h_space = PANEL_HSPACING;
00070     v_space = PANEL_VSPACING;
00071     v_line_extent = 0;
00072     Create((wxPanel *)panel, x, y, width, height, style, name);
00073 }
00074 
00075 Bool wxPanel::Create(wxPanel *panel, int x, int y, int width, int height,
00076                    int _style, char *name)
00077 {
00078     wxWindow_Xintern *ph;
00079     Widget wgt;
00080     wxFont *fnt;
00081 
00082     if (!panel)
00083        wxFatalError("wxPanel created without a parent!");
00084     parent = panel;
00085     parent->AddChild(this);
00086 
00087     style         = _style;
00088 
00089     ph = parent->GetHandle();
00090 
00091     fnt = wxNORMAL_FONT;
00092 
00093     // create frame
00094     wgt = XtVaCreateWidget
00095        (name, xfwfEnforcerWidgetClass, ph->handle,
00096         XtNbackground,  wxGREY_PIXEL,
00097         XtNforeground,  wxBLACK_PIXEL,
00098         XtNfont,        fnt->GetInternalFont(),
00099         XtNhighlightThickness, 0,
00100         NULL);
00101     if (!(style & wxINVISIBLE))
00102       XtManageChild(wgt);
00103     else
00104       XtRealizeWidget(wgt);
00105     X->frame = wgt;
00106     // internal representation
00107     if (style & wxBORDER) {
00108       wgt = XtVaCreateManagedWidget("panel", xfwfBoardWidgetClass, X->frame,
00109                                 XtNbackground, wxGREY_PIXEL,
00110                                 XtNframeWidth, 2,
00111                                 XtNframeType, XfwfSunken,
00112                                 NULL);
00113       X->handle = wgt;
00114       xoff = yoff = 4; // offset for border
00115     } else {
00116       wgt = XtVaCreateManagedWidget("panel", xfwfBoardWidgetClass, X->frame,
00117                                 XtNbackground, wxGREY_PIXEL,
00118                                 XtNhighlightThickness, 0,
00119                                 NULL);
00120       X->handle = wgt;
00121     }
00122 
00123     // In case this window or the parent is hidden; we
00124     // need windows to create DCs
00125     XtRealizeWidget(X->frame);
00126     XtRealizeWidget(X->handle);
00127 
00128 
00129     // position in panel/frame
00130     panel->PositionItem(this, x, y, width, height);
00131     // add event handlers
00132     AddEventHandlers();
00133 
00134     if (style & wxINVISIBLE)
00135       Show(FALSE);
00136 
00137     // ready
00138     return TRUE;
00139 }
00140 
00141 //-----------------------------------------------------------------------------
00142 // resize/layout panel
00143 //-----------------------------------------------------------------------------
00144 
00145 void wxPanel::GetClientSize(int *width, int *height)
00146 {
00147     Position  xx, yy;
00148     int ww, hh;
00149 
00150     XfwfCallComputeInside(X->handle, &xx, &yy, &ww, &hh);
00151     xoff = xx; yoff = yy;
00152     *width = ww; *height = hh;
00153 
00154     
00155     if (misc_flags & REPORT_ZERO_WIDTH_FLAG)
00156       *width = 0;
00157     if (misc_flags & REPORT_ZERO_HEIGHT_FLAG)
00158       *height = 0;
00159 }
00160 
00161 void wxPanel::Fit(void)
00162 {
00163     int hsize=0, vsize=0;
00164     wxChildNode *node;
00165 
00166     if (children) {
00167        for (node = children->First(); node; node = node->Next()) {
00168            wxWindow *child;
00169            child = (wxWindow*)(node->Data());
00170            if (child) {
00171               int x, y, w, h;
00172               child->GetPosition(&x, &y); child->GetSize(&w, &h);
00173               hsize = max(hsize, x + w);
00174               vsize = max(vsize, y + h);
00175            }
00176        }
00177     } else {
00178        hsize = PANEL_HMARGIN;
00179        vsize = PANEL_VMARGIN;
00180     }
00181     hsize += PANEL_HMARGIN + (style & wxBORDER ? 4 : 0 );
00182     vsize += PANEL_VMARGIN + (style & wxBORDER ? 4 : 0 );
00183     SetClientSize(hsize, vsize);
00184 }
00185 
00186 // void wxPanel::Layout(void)
00187 // --> wxLayout.cc
00188 
00189 void wxPanel::ChangeToGray(Bool gray)
00190 {
00191   wxChildNode *cn;
00192   wxChildList *cl;
00193   wxWindow::ChangeToGray(gray);
00194   cl = GetChildren();
00195   for (cn = cl->First(); cn; cn = cn->Next()) {
00196     wxWindow *w;
00197     w = (wxWindow *)cn->Data();
00198     w->InternalEnable(!gray, TRUE);
00199   }
00200 }
00201 
00202 void wxPanel::ReleaseAllFocus()
00203 {
00204   wxChildNode *cn;
00205   wxChildList *cl;
00206   cl = GetChildren();
00207   for (cn = cl->First(); cn; cn = cn->Next()) {
00208     wxWindow *w;
00209     w = (wxWindow *)cn->Data();
00210     w->ReleaseAllFocus();
00211   }
00212   ReleaseFocus();
00213 }
00214 
00215 //-----------------------------------------------------------------------------
00216 // positioning of items
00217 //-----------------------------------------------------------------------------
00218 
00219 void wxPanel::GetCursor(int *x, int *y)
00220 {
00221     *x = cursor_x; *y = cursor_y;
00222 }
00223 
00224 void wxPanel::SetItemCursor(int x, int y)
00225 {
00226     cursor_x = x; cursor_y = y;
00227 }
00228 
00229 void wxPanel::NewLine(int pixels)
00230 {
00231     cursor_x = PANEL_HMARGIN;
00232     cursor_y += v_line_extent + v_space + pixels;
00233     v_line_extent = 0;
00234 }
00235 
00236 void wxPanel::PositionItem(wxWindow *item, int x, int y, int width, int height)
00237 {
00238     // position child
00239     item->Move((x<0 ? cursor_x : x), (y<0 ? cursor_y : y));
00240     // move cursor and compute height of line
00241     item->SetSize(width, height);
00242     item->GetSize(&width, &height);
00243     if (x < 0)       cursor_x += width + h_space;
00244     if (y < 0) v_line_extent = max(v_line_extent, height);
00245 
00246     /* MATTHEW: Non-neg also sets cursor */
00247     if (x > 0 && (x + width > cursor_x))
00248       cursor_x = x + width + h_space;
00249     if (y > 0 && (y > cursor_y))
00250       cursor_y = y;
00251 
00252     if (IsGray())
00253       item->InternalEnable(0, TRUE);
00254 }
00255 
00256 void wxPanel::Tab(int pixels)
00257 {
00258     cursor_x += ( pixels ? pixels : h_space);
00259 }
00260 
00261 //-----------------------------------------------------------------------------
00262 // virtual event functions
00263 //-----------------------------------------------------------------------------
00264 
00265 void wxPanel::OnDefaultAction(wxItem *WXUNUSED(item))
00266 {
00267   wxButton *but;
00268   but = GetDefaultItem();
00269   if (but) {
00270     wxCommandEvent *event;
00271     event = new wxCommandEvent(wxEVENT_TYPE_BUTTON_COMMAND);
00272     but->Command(event);
00273   }
00274 }
00275 
00276 Bool wxPanel::WantsFocus(void)
00277 {
00278   return FALSE;
00279 }
00280