IconShape.cpp
gehe zur Dokumentation dieser Datei
00001 // -*-C++ -*-
00002 
00120 #include "Defs.h"
00121 #include "wx/defs.h"
00122 //#include "wx/wx.h"
00123 #include "IconShape.h"
00124 //#include "MutApp.h"
00125 //#include "MutIcon.h"
00126 //#include "MutRouteWnd.h"
00127 //#include "InputDevDlg.h"
00128 //#include "Device.h"
00129 
00130 
00131 IMPLEMENT_DYNAMIC_CLASS(MutIconShape, MutPanel)
00132 
00133 BEGIN_EVENT_TABLE(MutIconShape, MutPanel)
00134   EVT_PAINT(MutIconShape::OnPaint)
00135   EVT_SET_FOCUS(MutIconShape::OnGetFocus)
00136   EVT_KILL_FOCUS(MutIconShape::OnKillFocus)
00137   EVT_CLOSE(MutIconShape::DeleteSelfEvent)
00138 END_EVENT_TABLE()
00139 
00140 bool MutIconShape::Create (wxWindow * parent, wxWindowID id)
00141 {
00142         DEBUGLOG (other,_T (""));
00143         //    Enable(true);
00144         //                SetBackgroundColour(BoxColor(GetId()));
00145         if (!MutPanel::Create(parent,id,wxDefaultPosition,wxDefaultSize,wxBORDER_RAISED | wxTAB_TRAVERSAL)) return false;
00146         Icon = GetMutIcon();
00147         wxASSERT(Icon.IsOk());
00148         SetAutoLayout(true);
00149         //      Layout();
00150         
00151         
00152         return true;
00153 }
00154 
00155 
00156 
00157 wxSize MutIconShape::DoGetBestSize() const 
00158 {
00159         //  wxSize s(GetWindowBorderSize());
00160         wxSize s(0,0);
00161         wxSize s1(0,0);
00162         DEBUGLOG (other, _T("best size: %dx%d"),s.x,s.y);
00163 //      return s;
00164         
00165         
00166         if (staticText) s += staticText->GetBestSize();
00167         DEBUGLOG (other, _T("staticText %p best size: %dx%d"),&staticText,s.x,s.y);
00168         if (GetIcon().IsOk()) {
00169                 s.x = std::max (Icon.GetWidth(), s.x);
00170                 int h = Icon.GetHeight();
00171                 s.y += h;
00172         }
00173 
00174         if (GetSizer()) {
00175                 s1 = GetSizer()->CalcMin();
00176                 DEBUGLOG (other, _T("our %p sizer best size: %dx%d"),this,s1.x,s1.y);
00177                 s.x = std::max(s.x,s1.x);
00178                 s.y += std::max(s1.y,0);
00179         }
00180         s1 = GetSize() - GetClientSize();
00181         s.x += wxMax(0, s1.x);
00182         s.y += wxMax(0, s1.y);
00183         
00184         s1 = MutPanel::DoGetBestSize();
00185         DEBUGLOG (other, _T("our %p parent best size: %dx%d"),this,s1.x,s1.y);
00186         
00187         s1.x = std::max(s.x,s1.x);
00188         s1.y = std::max(s.y,s1.y);
00189         
00190         DEBUGLOG (other, _T("our %p best size: %dx%d"),this,s.x,s.y);
00191         wxConstCast(this,MutIconShape)->SetMinSize(s1);
00192         return s1;
00193 }
00194 
00195 
00196 void MutIconShape::SetFocus() {
00197         MutPanel::SetFocus();
00198         DEBUGLOG (other, _T(""));
00199         SetWindowStyle((GetWindowStyle() & ~ wxBORDER_RAISED)| wxBORDER_SUNKEN);
00200         GetContainingSizer()->Layout();
00201         Refresh();
00202 }
00203 
00204 void MutIconShape::OnGetFocus(wxFocusEvent & event)
00205 {
00206         DEBUGLOG (other, _T(""));
00207         OnFocus(event);
00208         SetFocus();
00209 }
00210 
00211 void MutIconShape::OnKillFocus(wxFocusEvent & event)
00212 {
00213         DEBUGLOG (other, _T(""));
00214         SetWindowStyle((GetWindowStyle() & ~ wxBORDER_SUNKEN) | wxBORDER_RAISED);
00215         wxSizer * sizer = GetContainingSizer();
00216         if (sizer) sizer->Layout();
00217         Refresh();
00218 }
00219 
00220 
00221 void MutIconShape::OnPaint( wxPaintEvent& WXUNUSED(event) )
00222 {
00223         wxPaintDC dc(this);
00224         PrepareDC(dc);
00225         OnDraw(dc);
00226 }
00227 
00228 void MutIconShape::OnDraw (wxDC & dc) 
00229 {
00230         wxRect size = GetRect();
00231         DEBUGLOG (other, _T("Checking icon"));
00232 
00233         if (!GetIcon().IsOk()) {
00234                 SetIcon(GetMutIcon());
00235                 DEBUGLOG (other, _T("Checking icon again"));
00236 
00237         }
00238         DEBUGLOG (other, _T("Icon ok."));
00239 
00240         int x = 0, y = 0;
00241         if (GetIcon().IsOk()) {
00242                 DEBUGLOG (other, _T("Size: %dx%d"),GetIcon().GetHeight(),
00243                          GetIcon().GetWidth());
00244                 x = (size.width-GetIcon().GetWidth())/2;
00245                 dc.DrawIcon(GetIcon(), x, y);
00246         }
00247 
00248         DEBUGLOG (other, _T("Focus %p and this %p"),FindFocus(),this);
00249 /*  Draw a black bock around focused item 
00250         if (FindFocus() == this) {
00251                 DEBUGLOG (other, _T("Painting Box"));
00252                 dc.SetPen(*wxBLACK_PEN);
00253                 dc.SetBrush(*wxTRANSPARENT_BRUSH);
00254                 dc.DrawRectangle(0,0,size.width,size.height);
00255         }
00256 */
00257 }
00258 
00259 wxPoint MutIconShape::GetPerimeterPoint(const wxPoint &i,const wxPoint &o) const {
00260         wxRect r = GetRect();
00261         DEBUGLOG (other, _T("Rect: (%d,%d) -- (%d,%d)"),r.x,r.y,r.x+r.width,r.y+r.height);
00262         DEBUGLOG (other, _T("Points: i = (%d,%d), o = (%d, %d)"),i.x,i.y,o.x,o.y);
00263         wxRect ir = GetIconRect();
00264 #ifdef DEBUG
00265         std::cerr.flush();
00266         wxASSERT(r.Contains(i));
00267 #endif
00268 
00269         wxPoint p;
00270 
00271         if (r.x+r.width <= o.x) {
00272                 p.x = r.x + r.width;
00273                 p.y = r.y + ir.height/2;
00274         } else if (r.x >= o.y) {
00275                 p.x = r.x;
00276                 p.y = r.y + ir.height/2;
00277         } else if (r.y <= o.y) {
00278                 p.x = r.x + r.width/2;
00279                 p.y = r.y;
00280         } else if (r.y + r.height >= o.y) {
00281                 p.x = r.x + r.width/2;
00282                 p.y = r.y + r.height;
00283         } else p = o;
00284 
00285         return p;
00286 }
00287 
00288 void MutIconShape::LineTo(wxDC &dc, const wxPoint & p)  const
00289 {
00290         wxRect rect = GetRect();
00291         wxPoint p1(rect.x + rect.width/2, rect.y + Icon.GetHeight()/2);
00292         dc.DrawLine(p1,p);
00293 }
00294 
00295 
00296 bool MutIconShape::Recompute() 
00297 {
00298         return true;
00299 }
00300 
00301 bool MutIconShape::Layout() {
00302         int w = 0, h = 0, y = Icon.GetHeight();
00303         GetVirtualSize(&w, &h);
00304         if (staticText) {
00305                 staticText->Move(0,y);
00306                 staticText->CentreOnParent(wxHORIZONTAL);
00307                 wxSize s = staticText->GetSize();
00308                 y += s.y;
00309         }
00310         // If there is a sizer, use it instead of the constraints
00311         if ( GetSizer() )
00312         {
00313                 DEBUGLOG (other, _T("sizer"));
00314                 GetSizer()->SetDimension( 0, y, w, h );
00315                 PRINTSIZER(GetSizer());
00316         }
00317 #if wxUSE_CONSTRAINTS
00318         else
00319         {
00320                 DEBUGLOG (other, _T("constraints"));
00321                 SatisfyConstraints(); // Find the right constraints values
00322                 SetConstraintSizes(); // Recursively set the real window sizes
00323         }
00324 #endif
00325         return true;
00326 }
00327 
00328 void MutIconShape::DeleteSelf()
00329 {
00330         Hide();
00331         wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
00332         event.SetEventObject(this);
00333         event.SetCanVeto(false);
00334         
00335         GetEventHandler()->AddPendingEvent(event);
00336 }
00337 
00338 /*
00339  * \}
00340  */

Erzeugt am Sun Aug 21 2011 10:51:54 für Mutabor von doxygen 1.7.4