aswang  1.0
window.h
Go to the documentation of this file.
00001 /*
00002         Copyright 2003 Joseph Alvis
00003 
00004     This file is part of Aswang.
00005 
00006     Aswang is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU Lesser General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 
00011     Aswang 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 License
00017     along with Aswang.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 #pragma once
00021 
00022 #include <map>
00023 #include <string>
00024 #include "aswang.h"
00025 #include "brush.h"
00026 
00027 namespace aswang {
00028         class window {
00029         public:
00030                 enum Alignment {ALIGN_LEFT,ALIGN_RIGHT,ALIGN_CENTER};
00031                 typedef LRESULT (window::*msgCallback)(window *,UINT,WPARAM,LPARAM);
00032         protected:
00033                 typedef std::map<HWND,window *> wmap_type;
00034                 typedef std::map<unsigned int,std::pair<HWND,msgCallback> > callbackMap_type;
00035                 static wmap_type wmap;
00036                 static HINSTANCE hInstance;
00037                 HWND hWnd;
00038                 window *mParent;
00039                 Brush bg;
00040                 unsigned long style;
00041                 callbackMap_type callbackMap;
00042         public:
00043                 window() : hWnd(NULL),mParent(NULL),bg(),style(0) {}
00044                 explicit window(HWND h) : hWnd(h),mParent(NULL),bg(),style(0) {}
00045                 window(HWND h,window *p) : hWnd(h),mParent(p),bg(),style(0) {}
00046                 window(unsigned long newStyle) : hWnd(NULL),mParent(NULL),bg(),style(newStyle) {}
00047                 window(window *p,unsigned long newStyle=0UL) : hWnd(NULL),mParent(p),bg(),style(newStyle) {}
00048                 virtual ~window() {
00049                         Erase();
00050                 }
00051 
00052                 void Add();
00053                 void Erase();
00054                 HWND GetHwnd() {return hWnd;}
00055                 void SetHwnd(HWND h) {hWnd=h;}
00056                 window *GetParent() {return mParent;}
00057                 void SetParent(window *newp) {mParent=newp;}
00058                 AswangStr GetText() const;
00059                 void SetText(AswangStr s) const;
00060                 long GetWindowX() const;
00061                 long GetWindowY() const;
00062                 long GetWindowWidth() const;
00063                 long GetWindowHeight() const;
00064                 long GetClientWidth() const;
00065                 long GetClientHeight() const;
00066                 void Center() const;
00067                 virtual void SetBrush(const Brush &b) {bg = b;}
00068                 virtual const Brush &GetBrush() const {return bg;}
00069                 virtual void SetAlignment(Alignment a);
00070                 virtual void Invalidate();
00071                 virtual void Update();
00072                 virtual void Move(int x,int y);
00073                 virtual void Resize(int width,int height);
00074                 virtual void SetStyle(unsigned long s);
00075                 virtual unsigned long GetStyle();
00076 
00077                 virtual void Create(int x,int y,int width,int height) ;
00078                 virtual void Show(int showCommand=SW_SHOWNORMAL);
00079                 virtual void Transparent(bool t) const;
00080                 virtual const _TCHAR *GetClassName() const = 0;
00081 
00082                 static window *GetWindow(HWND h);
00083                 static LRESULT CALLBACK WProc(HWND h,UINT msg,WPARAM wParam,LPARAM lParam);
00084                 static int Loop();
00085                 static void SetInstance(HINSTANCE h) {hInstance=h;}
00086                 static HINSTANCE GetInstance() {return hInstance;}
00087 
00088                 virtual void AddCallback(unsigned long msg,msgCallback cbk,HWND caller=NULL) {
00089                         callbackMap[msg] = std::make_pair<HWND,msgCallback>(caller,cbk);
00090                 }
00091                 virtual void RemoveCallback(unsigned long msg) {
00092                         callbackMap.erase(msg);
00093                 }
00094                 virtual LRESULT OnButtonColor(HDC dc,HWND btn);
00095                 virtual LRESULT OnChar(TCHAR c,long flags);
00096                 virtual LRESULT OnClose();
00097                 virtual LRESULT OnCommand(HWND win,unsigned short Notify,unsigned short wID);
00098                 virtual LRESULT OnDestroy(HWND win);
00099                 virtual LRESULT OnDialogColor(HDC dc,HWND dlg);
00100                 virtual LRESULT OnDrawItem(unsigned long ID,DRAWITEMSTRUCT *dis);
00101                 virtual LRESULT OnEraseBG(HDC dc);
00102                 virtual LRESULT OnFail(UINT msg,WPARAM wParam,LPARAM lParam);
00103                 virtual LRESULT OnGetDlgCode(long VirtKey,MSG *m);
00104                 virtual LRESULT OnInitDialog(HWND win,unsigned long param);
00105                 virtual LRESULT OnKeyDown(long VirtKey,long flags);
00106                 virtual LRESULT OnKeyUp(long VirtKey,long flags);
00107                 virtual LRESULT OnLDClick(unsigned int flags,POINTS p);
00108                 virtual LRESULT OnLDown(unsigned int flags,POINTS p);
00109                 virtual LRESULT OnLUp(unsigned int flags,POINTS p);
00110                 virtual LRESULT OnMeasureItem(long ctlID,MEASUREITEMSTRUCT *mis);
00111                 virtual LRESULT OnMouseOut(HWND NewWindow);
00112                 virtual LRESULT OnMouseOver(unsigned int flags,POINTS p);
00113                 virtual LRESULT OnMove(unsigned long NewX,unsigned long NewY);
00114                 virtual LRESULT OnNCPaint(HRGN region);
00115                 virtual LRESULT OnNCHitTest(POINTS pos);
00116                 virtual LRESULT OnNotify(unsigned long ID,NMHDR *nmh);
00117                 virtual LRESULT OnPaint();
00118                 virtual LRESULT OnParentNotifyCreate(unsigned short event,unsigned short wID,HWND win);
00119                 virtual LRESULT OnParentNotifyClick(unsigned short event,short x,short y);
00120                 virtual LRESULT OnPosChanged(WINDOWPOS *wpos);
00121                 virtual LRESULT OnRDClick(unsigned int flags,POINTS p);
00122                 virtual LRESULT OnRDown(unsigned int flags,POINTS p);
00123                 virtual LRESULT OnRUp(unsigned int flags,POINTS p);
00124                 virtual LRESULT OnShow(bool show,long Status);
00125                 virtual LRESULT OnSize(unsigned long flag,unsigned short NewWidth,unsigned short NewHeight);
00126                 virtual LRESULT OnSizing(unsigned long side,RECT *r);
00127                 virtual LRESULT OnStaticColor(HDC dc,HWND sttc);
00128                 virtual LRESULT OnTimer(unsigned long id,TIMERPROC tproc);
00129                 
00130                 virtual operator HWND () {return hWnd;}
00131         };
00132 
00133         class simple_window : public window {
00134         public:
00135                 simple_window() : window() {}
00136                 explicit simple_window(HWND h) : window(h) {}
00137                 simple_window(HWND h,window *p) : window(h,p) {}
00138                 virtual ~simple_window() {
00139                         hWnd=NULL;
00140                 }
00141 
00142                 virtual const _TCHAR *GetClassName() const {return TEXT("");}
00143         };
00144 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines