Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

PaletteDlg.cpp

Go to the documentation of this file.
00001 
00002 // MathGUI = a WYSIWYG equation editor + a powerful math engine      //
00003 // Copyright (C) 2003 by Francesco Montorsi                          //
00004 //                                                                   //
00005 // This library is free software; you can redistribute it and/or     //
00006 // modify it under the terms of the GNU Lesser General Public        //
00007 // License as published by the Free Software Foundation; either      //
00008 // version 2.1 of the License, or (at your option) any later         //
00009 // version.                                                          //
00010 //                                                                   //
00011 // This library 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 Lesser General Public License for more details.               //
00015 //                                                                   //
00016 // You should have received a copy of the GNU Lesser General Public  //
00017 // License along with this program; if not, write to the Free        //
00018 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,   //
00019 // MA 02111-1307, USA.                                               //
00020 //                                                                   //
00021 // For any comment, suggestion or feature request, please contact    //
00022 // the administrator of the project at frm@users.sourceforge.net     //
00023 //                                                                   //
00030 
00031 
00032 
00033 // optimization for GCC compiler
00034 #ifdef __GNUG__
00035    #pragma implementation "PaletteDlg.h"
00036 #endif
00037 
00038 // includes
00039 #include "mg/mgprec.h"
00040 
00041 #ifndef mgPRECOMP
00042    #include "mg/GUIUtils.h"
00043    #include "mg/PaletteDlg.h"
00044 #ifdef mgUSE_PALETTEFRM
00045    #include <wx/palettefrm.h>    // a wxWidgets extension
00046 #endif
00047 #endif
00048 
00049 
00050 
00051 
00052 IMPLEMENT_CLASS(mgButtonListPanel, wxPanel)
00053 BEGIN_EVENT_TABLE(mgButtonListPanel, wxPanel)
00054 
00055    // used to shrink or expand the button's fonts
00056    EVT_SIZE(mgButtonListPanel::OnSize)
00057 
00058 END_EVENT_TABLE()
00059 
00060 
00061 
00062 
00063 // ----------------------
00064 // mgButtonListPanel
00065 // ----------------------
00066 
00067 void mgButtonListPanel::AddButtonsToSizer(int idoffset, int num, wxSize sz)
00068 {
00069    for (int i=0; i < num; i++) {
00070 
00071       // create the button
00072 /*    wxButton *btn = new wxPaletteButton(this, m_pClientWnd,
00073          GetBaseID()+idoffset+i, GetButtonLabel(i), wxDefaultPosition, sz, wxBU_EXACTFIT);
00074 */
00075       wxButton *btn = new wxButton(this, GetBaseID()+idoffset+i,  
00076             GetButtonLabel(i), wxDefaultPosition, sz, wxBU_EXACTFIT);
00077    
00078       // set some attributes of the button
00079       btn->SetFont(m_fButtons);
00080 #ifndef __WXX11__
00081       btn->SetToolTip(GetButtonTooltip(i));
00082 #endif
00083       
00084       // add it to the sizer
00085       GetSizer()->Add(btn, 1, wxGROW);
00086    }
00087 }
00088 
00089 wxSize mgButtonListPanel::FindBiggestLetter(const wxString &str)
00090 {
00091    wxScreenDC dc;
00092    int w = -1, h = -1;
00093 
00094    // scan the entire string
00095    dc.SetFont(m_fButtons);
00096    for (int i=0; i < (int)str.Len(); i++) {
00097 
00098       // and using the button font, retrieve width & height
00099       int width, height, d, e;
00100       dc.GetTextExtent(str.GetChar(i), &width, &height, &d, &e);
00101 
00102       // choose maximum widths & heights
00103       w = mcMAX(w, (int)((width/100.)*100.));
00104       h = mcMAX(h, (int)(((height+d+e)/100.)*100.));
00105    }
00106 
00107    return wxSize(w, h);
00108 }
00109 
00110 void mgButtonListPanel::BuildPanel(int border, int proportion)
00111 {
00112    int i, max;
00113 
00114    // set all the rows as growable
00115    wxFlexGridSizer *p = (wxFlexGridSizer *)GetSizer();
00116    wxASSERT(p != NULL);
00117    
00118    for (i=0, max=GetRowCount(); i <= max; i++)
00119       p->AddGrowableRow(i);
00120    for (i=0, max=GetColCount(); i <= max; i++)
00121       p->AddGrowableCol(i);
00122 
00123 #if wxCHECK_VERSION(2, 5, 1)
00124    p->SetFlexibleDirection(wxBOTH);
00125 #endif
00126    
00127 
00128    p->SetSizeHints(this);
00129    if (border != 0) {
00130       
00131       // set up global sizer as a wxBoxSizer containing the sizer we
00132       // used in the previous operations.
00133       // this is done to allow a certain border to be set around the
00134       // gridsizer only (and not around all buttons).
00135       wxBoxSizer *global = new wxBoxSizer(wxHORIZONTAL);
00136       
00137       //global->Add(2, 1, 1, wxGROW);
00138       global->Add(p, proportion, wxGROW | wxALL, border);
00139       //global->Add(2, 1, 1, wxGROW);
00140       
00141       // if we ask SetSizer() to delete the old size (using TRUE)
00142       // we would make invalid the wxFlexGridSizer
00143       SetSizer(global, FALSE);
00144       global->SetSizeHints(this);      // set size hints to honour minimum size
00145       //SetSize(global->GetMinSize());
00146    }
00147 }
00148 
00149 void mgButtonListPanel::BuildSizer()
00150 {
00151    // create the sizer & init it
00152    SetSizer(new wxFlexGridSizer(GetRowCount(), GetColCount(), 1, 1));
00153 }
00154 
00155 int mgButtonListPanel::GetButtonID(wxCommandEvent &ev) const
00156 {
00157    // just a simple op
00158    return ev.GetId() - GetBaseID();
00159 }
00160 
00161 void mgButtonListPanel::AddHorizontalSpacer()
00162 {
00163    //wxFlexGridSizer *p = (wxFlexGridSizer *)GetSizer();
00164 
00165    // create a new sizer in the next available entry of the m_pSizerList
00166    // array and then set it as the current sizer to use...
00167    //BuildSizer();
00168 }
00169 
00170 void mgButtonListPanel::SetFontButtonPointSize(int pointsize)
00171 {
00172    m_fButtons.SetPointSize(pointsize);
00173 
00174    wxWindow *firstchild = FindWindowById(GetBaseID(), this);
00175    if (firstchild) {
00176       wxSize sz = firstchild->GetSize();
00177       int max = mcMAX(sz.GetWidth(), sz.GetHeight());
00178       m_fButtonFontRatio = ((float)pointsize)/((float)max);
00179    }
00180 }
00181 
00182 void mgButtonListPanel::UpdateFontButton()
00183 {
00184    wxWindow *firstchild = FindWindowById(GetBaseID(), this);
00185    if (firstchild) {
00186       wxSize sz = firstchild->GetSize();
00187       int max = mcMAX(sz.GetWidth(), sz.GetHeight());
00188 
00189       // update font button size
00190       m_fButtons.SetPointSize((int)(max*m_fButtonFontRatio));
00191    }
00192 
00193    // update all button's size
00194    for (int i=0; i < (int)GetChildren().GetCount(); i++) {
00195       wxWindowListNode *n = GetChildren().Item(i);
00196 
00197       if (n) n->GetData()->SetFont(m_fButtons);
00198    }
00199 }
00200 
00201 void mgButtonListPanel::OnSize(wxSizeEvent &ev)
00202 {
00203    // update the font of the button making it bigger or smaller
00204    if (m_bEnableFontButtonUpdate)
00205       UpdateFontButton();
00206 
00207    // let other event handlers process this event
00208    ev.Skip();
00209 }
00210 
00211 


Documentation generated with Doxygen on Sun Feb 6 17:19:26 2005
Visit MathStudio home page for more info

[ Top ]