MatOCAD Logo

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

resizec.h

Go to the documentation of this file.
00001 
00002 // Name:        wx/resizec.h
00003 // Purpose:     wxResizeableControl base class and derived classes
00004 //              for resizeable pictures
00005 // Author:      Markus Greither
00006 // Modified by:
00007 // Created:     11/10/02
00008 // RCS-ID:      $Id:     1.05 2003/12/19 magr
00009 // Copyright:   (c) Markus Greither
00010 // Licence:     wxWindows licence
00012 
00013 #ifndef __RESIZECONTROL__
00014 #define __RESIZECONTROL__
00015 
00016 #if defined(__WXMSW__) && wxUSE_METAFILE && wxUSE_ENH_METAFILE
00017 #include "wx/metafile.h"
00018 #endif
00019 
00020 // ----------------------------------------------------------------------------
00021 // wxResizeableControl
00022 // ----------------------------------------------------------------------------
00023 
00025 
00029 class wxZoomData
00030 {
00032     wxSize m_orgSize;
00034     wxPoint m_orgPos;
00036     wxRect m_currRect;
00038     float m_zoom;
00039  public:
00041     wxZoomData() : m_zoom(1) {}
00043     wxZoomData(const wxSize &size,const wxPoint &pos)
00044      : m_orgSize(size),m_orgPos(pos),m_zoom(1) {}
00046     void SetZoomSize(wxWindow *Window,float zoom)
00047     {
00048         m_zoom = zoom;
00049         m_currRect = wxRect(m_currRect.GetPosition(),
00050                             wxSize(int(m_orgSize.x*m_zoom),
00051                                    int(m_orgSize.y*m_zoom)));
00052         Window->SetSize(m_currRect.GetSize());
00053     }
00055 
00059     void SetZoomRect(wxWindow *Window,float zoom,
00060                      int curxoffs,int curyoffs,
00061                      int newxoffs,int newyoffs);
00063     void SetCurrentZoom(float zoom)
00064     {
00065         m_zoom = zoom;
00066         m_orgPos.x = int(m_orgPos.x/zoom);
00067         m_orgPos.y = int(m_orgPos.y/zoom);
00068         m_orgSize.x = int(m_orgSize.x/zoom);
00069         m_orgSize.y = int(m_orgSize.y/zoom);
00070     }
00072     float GetZoom() {return m_zoom;}
00074     void SetSize(int width,int height);
00076     void Move(int xpos,int ypos);
00077 };
00078 
00080 
00090 class wxResizeableControl : public wxScrolledWindow
00091 {
00092  public:
00094     enum SizeMoveModes
00095     {
00096         Top = 0,
00097         Bottom,
00098         Left,
00099         Right,
00100         TopLeft,
00101         BottomLeft,
00102         TopRight,
00103         BottomRight,
00104         MoveWin,
00105         MaxMode
00106     };
00108     enum SizeRads
00109     {
00110         SizeXRad = 5,
00111         SizeYRad = 5
00112     };
00114     wxResizeableControl() : wxScrolledWindow(), m_curId(-2) { }
00116     wxResizeableControl(wxWindow *AParent, int AnId,const wxPoint &pos,
00117                         const wxSize &size,long style = 0,
00118                         const wxString &name = wxPanelNameStr);
00120     virtual ~wxResizeableControl() {}
00122     virtual void Paint(wxDC &WXUNUSED(dc),bool WXUNUSED(Printing),wxSize &WXUNUSED(size)) {}
00124     virtual wxSize GetOriginalSize() {return wxSize(-1,-1);}
00126     virtual float GetRatio()
00127     {
00128         return 0;
00129     }
00131     wxZoomData &GetZoomData() {return m_zoomData;}
00133     void SetZoom(float Zoom)
00134     {
00135       m_zoomData.SetZoomSize(this,Zoom);
00136     }
00138     void SetCurrentZoom(float Zoom)
00139     {
00140       m_zoomData.SetCurrentZoom(Zoom);
00141     }
00143     inline void DrawFocusRect(wxDC &dc,wxRect rct)
00144     {
00145         FocusRectCoord(dc,rct.x,rct.y,rct.width,rct.height);
00146     }
00148     void DoSetSize(int x, int y,int width, int height,
00149                    int sizeFlags = wxSIZE_AUTO)
00150     {
00151         if ((x != -1) || (y != -1))
00152             m_zoomData.Move(x,y);
00153         if ((width != -1) || (height != -1))
00154             m_zoomData.SetSize(width,height);
00155         wxWindow::DoSetSize(x,y,width,height,sizeFlags);
00156     }
00157 
00158 // Event Handlers
00159     void OnP(wxPaintEvent &event);
00161     void OnSetCursor(wxSetCursorEvent &event);
00163     void OnLButtonUp(wxMouseEvent &event);
00165     void OnLButtonDown(wxMouseEvent &event);
00167     void OnMouseMove(wxMouseEvent &event);
00169     void OnKillFocus(wxFocusEvent &event);
00171     void OnSetFocus(wxFocusEvent &event);
00173     void OnEditCut(wxCommandEvent &ce);
00175     void OnKeyDown(wxKeyEvent &event);
00177     void OnSize(wxSizeEvent &event);
00179     void OnMove(wxMoveEvent &event);
00181     
00182     
00183     bool Destroy();
00184 
00185  protected:
00187     wxZoomData m_zoomData;
00189 
00194     wxCursor m_csr;
00196     long m_curId;
00198     int m_capt;
00200     wxPoint m_curpos,m_lastcurpos;
00202     int m_movemode;
00204     bool m_hasfocus,m_moved;
00205 
00207     void FocusRectCoord(wxDC &DC,wxCoord x1,wxCoord y1,wxCoord w,wxCoord h);
00209     int GetSizeX(int Mode);
00211     int GetSizeY(int Mode);
00213     void DrawMoveRect(wxPoint hp,int Mode,float Ratio = 0);
00215     wxRect NewRect(wxPoint hp,int Mode,float Ratio = 0);
00217     void DrawSizeRect(wxDC &dc);
00219     int PointInSizeRect(wxPoint hp);
00220 
00221     DECLARE_EVENT_TABLE()
00222     DECLARE_DYNAMIC_CLASS(wxResizeableControl)
00223 };
00224 
00225 // ----------------------------------------------------------------------------
00226 // wxPictureControl
00227 // ----------------------------------------------------------------------------
00228 
00230 
00233 class wxPictureControl : public wxResizeableControl
00234 {
00235  public:
00237     wxPictureControl() : wxResizeableControl() {};
00239     wxPictureControl(wxWindow *AParent, int AnId,const wxPoint &pos,
00240                       const wxSize &size,long style = 0,
00241                       const wxString &name = wxPanelNameStr)
00242       : wxResizeableControl(AParent,AnId,pos,size,style,name) {};
00244     virtual const wxChar *GetPictureType() {return wxT("NOTYPE");}
00246     virtual long GetPictureSize() {return 0;}
00248     virtual long GetPictureData(char *,long) {return 0;}
00249 
00250 // Event handlers
00251 
00253     void OnRevert(wxCommandEvent &event);
00255     void OnRightDown(wxMouseEvent &event);
00257     void OnPaletteChanged(wxSysColourChangedEvent &event);
00259     void OnEditCut(wxCommandEvent &ce);
00261     virtual void OnEditCopy(wxCommandEvent &WXUNUSED(ce)) {}
00263     void CeEditCut(wxUpdateUIEvent &ce)
00264     {
00265         ce.Enable(true);
00266     }
00268     void CeEditCopy(wxUpdateUIEvent &ce)
00269     {
00270         ce.Enable(true);
00271     }
00273     void OnSize(wxSizeEvent &event);
00275     void OnPaint(wxPaintEvent &event);
00276 
00277  protected:
00278     DECLARE_EVENT_TABLE()
00279     DECLARE_DYNAMIC_CLASS(wxPictureControl)
00280 };
00281 
00282 
00283 #if defined(__WXMSW__) && wxUSE_METAFILE && wxUSE_ENH_METAFILE
00284 // ----------------------------------------------------------------------------
00285 // wxMetafileControl
00286 // ----------------------------------------------------------------------------
00287 
00289 class wxMetafileControl : public wxPictureControl
00290 {
00291  public:
00293     wxMetafileControl() : wxPictureControl() {};
00295     wxMetafileControl(wxWindow *AParent, int AnId,WXHANDLE Meta,
00296                       const wxPoint &pos,
00297                       const wxSize &size,long style = 0,
00298                       const wxString &name = wxPanelNameStr);
00300     wxMetafileControl(wxWindow *AParent, int AnId,char *Data,int Size,
00301                       const wxPoint &pos,const wxSize &size,long style = 0,
00302                       const wxString &name = wxPanelNameStr);
00304     virtual ~wxMetafileControl();
00306     const wxChar *GetPictureType()
00307     {
00308         return wxT("EnhMetaFile");
00309     }
00311     long GetPictureSize();
00313     long GetPictureData(char *data,long n);
00315     const wxEnhMetaFile &GetMetafile() { return m_metafile; }
00317     void Paint(wxDC &dc,bool Printing,wxSize &size);
00319     float GetRatio();
00321     wxSize GetOriginalSize();
00322 
00323 // Event handlers
00324 
00326     void OnEditCopy(wxCommandEvent &event);
00327 
00328  protected:
00330     wxEnhMetaFile m_metafile;
00331 
00332     DECLARE_EVENT_TABLE()
00333     DECLARE_DYNAMIC_CLASS(wxMetafileControl)
00334 };
00335 
00336 #endif
00337 
00338 // ----------------------------------------------------------------------------
00339 // wxBitmapControl
00340 // ----------------------------------------------------------------------------
00341 
00343 class wxBitmapControl : public wxPictureControl
00344 {
00345  public:
00347     wxBitmapControl() : wxPictureControl(),m_bitmap(0) {};
00349     wxBitmapControl(wxWindow *AParent, int AnId,const wxBitmap &Data,
00350                     const wxPoint &pos,
00351                     const wxSize &size,long style = 0,
00352                     const wxString &name = wxPanelNameStr);
00353 #ifdef __WXMSW__
00354 
00355     wxBitmapControl(wxWindow *AParent, int AnId,char *Data,int Size,
00356                     const wxPoint &pos,const wxSize &size,long style = 0,
00357                     const wxString &name = wxPanelNameStr);
00358 #endif
00359 
00360     virtual ~wxBitmapControl();
00361 #ifdef __WXMSW__
00362 
00363     const wxChar *GetPictureType()
00364     {
00365         return wxT("Dib");
00366     }
00368     long GetPictureSize();
00370     long GetPictureData(char *data,long n);
00371 #endif
00372 
00373     const wxBitmap &GetBitmap() { return *m_bitmap; }
00375     void Paint(wxDC &dc,bool Printing,wxSize &size);
00377     float GetRatio();
00379     wxSize GetOriginalSize();
00380 
00381 // Event handlers
00382 
00384     void OnEditCopy(wxCommandEvent &event);
00385 
00386  protected:
00388     wxBitmap *m_bitmap;
00389 
00390     DECLARE_EVENT_TABLE()
00391     DECLARE_DYNAMIC_CLASS(wxBitmapControl)
00392 };
00393 
00394 // ----------------------------------------------------------------------------
00395 // wxResizeableControlCanvas
00396 // ----------------------------------------------------------------------------
00397 
00399 
00402 class wxResizeableControlCanvas : public wxScrolledWindow
00403 {
00405     bool m_scrollflag;
00406   public:
00408     wxResizeableControlCanvas() : wxScrolledWindow() {}
00410     wxResizeableControlCanvas(wxWindow *AParent, int AnId,
00411                               const wxPoint &pos = wxDefaultPosition,
00412                               const wxSize &size = wxDefaultSize,long style = 0,
00413                               const wxString &name = wxPanelNameStr)
00414       : wxScrolledWindow(AParent,AnId,pos,size,style,name) 
00415     {
00416       m_scrollflag = false;
00417     }
00419     void OnChildWindowChange(wxCommandEvent &);
00421     void OnIdle(wxIdleEvent &);
00423     void UpdateScrollRange();
00424 
00425     DECLARE_EVENT_TABLE()
00426 };
00427 
00428 // ----------------------------------------------------------------------------
00429 // Events
00430 // ----------------------------------------------------------------------------
00431 
00433 
00437 BEGIN_DECLARE_EVENT_TYPES()
00438     DECLARE_EVENT_TYPE(wxEVT_COMMAND_CHILD_MOVED, 520)
00439     DECLARE_EVENT_TYPE(wxEVT_COMMAND_CHILD_CLOSED, 521)
00440     DECLARE_EVENT_TYPE(wxEVT_COMMAND_CHILD_RESIZED, 522)
00441     DECLARE_EVENT_TYPE(wxEVT_COMMAND_CHILD_CREATED, 523)
00442 END_DECLARE_EVENT_TYPES()
00443 
00444 #define EVT_CHILD_MOVED(id, fn) \
00445     DECLARE_EVENT_TABLE_ENTRY( \
00446         wxEVT_COMMAND_CHILD_MOVED, id, -1, \
00447         (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction) \
00448         & fn, \
00449         (wxObject *) NULL \
00450     ),
00451 
00452 #define EVT_CHILD_CLOSED(id, fn) \
00453     DECLARE_EVENT_TABLE_ENTRY( \
00454         wxEVT_COMMAND_CHILD_CLOSED, id, -1, \
00455         (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction) \
00456         & fn, \
00457         (wxObject *) NULL \
00458     ),
00459 
00460 #define EVT_CHILD_RESIZED(id, fn) \
00461     DECLARE_EVENT_TABLE_ENTRY( \
00462         wxEVT_COMMAND_CHILD_RESIZED, id, -1, \
00463         (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction) \
00464         & fn, \
00465         (wxObject *) NULL \
00466     ),
00467 
00468 #define EVT_CHILD_CREATED(id, fn) \
00469     DECLARE_EVENT_TABLE_ENTRY( \
00470         wxEVT_COMMAND_CHILD_CREATED, id, -1, \
00471         (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction) \
00472         & fn, \
00473         (wxObject *) NULL \
00474     ),
00475 
00476 #endif // __RESIZECONTROL__
00477 

 

SourceForge Logo