00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00030
00031
00032
00033
00034 #ifdef __GNUG__
00035 #pragma implementation "PaletteDlg.h"
00036 #endif
00037
00038
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>
00046 #endif
00047 #endif
00048
00049
00050
00051
00052 IMPLEMENT_CLASS(mgButtonListPanel, wxPanel)
00053 BEGIN_EVENT_TABLE(mgButtonListPanel, wxPanel)
00054
00055
00056 EVT_SIZE(mgButtonListPanel::OnSize)
00057
00058 END_EVENT_TABLE()
00059
00060
00061
00062
00063
00064
00065
00066
00067 void mgButtonListPanel::AddButtonsToSizer(int idoffset, int num, wxSize sz)
00068 {
00069 for (int i=0; i < num; i++) {
00070
00071
00072
00073
00074
00075 wxButton *btn = new wxButton(this, GetBaseID()+idoffset+i,
00076 GetButtonLabel(i), wxDefaultPosition, sz, wxBU_EXACTFIT);
00077
00078
00079 btn->SetFont(m_fButtons);
00080 #ifndef __WXX11__
00081 btn->SetToolTip(GetButtonTooltip(i));
00082 #endif
00083
00084
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
00095 dc.SetFont(m_fButtons);
00096 for (int i=0; i < (int)str.Len(); i++) {
00097
00098
00099 int width, height, d, e;
00100 dc.GetTextExtent(str.GetChar(i), &width, &height, &d, &e);
00101
00102
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
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
00132
00133
00134
00135 wxBoxSizer *global = new wxBoxSizer(wxHORIZONTAL);
00136
00137
00138 global->Add(p, proportion, wxGROW | wxALL, border);
00139
00140
00141
00142
00143 SetSizer(global, FALSE);
00144 global->SetSizeHints(this);
00145
00146 }
00147 }
00148
00149 void mgButtonListPanel::BuildSizer()
00150 {
00151
00152 SetSizer(new wxFlexGridSizer(GetRowCount(), GetColCount(), 1, 1));
00153 }
00154
00155 int mgButtonListPanel::GetButtonID(wxCommandEvent &ev) const
00156 {
00157
00158 return ev.GetId() - GetBaseID();
00159 }
00160
00161 void mgButtonListPanel::AddHorizontalSpacer()
00162 {
00163
00164
00165
00166
00167
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
00190 m_fButtons.SetPointSize((int)(max*m_fButtonFontRatio));
00191 }
00192
00193
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
00204 if (m_bEnableFontButtonUpdate)
00205 UpdateFontButton();
00206
00207
00208 ev.Skip();
00209 }
00210
00211