1/*
2 * Copyright (c) 2005 Alexander Gottwald
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 *
22 * Except as contained in this notice, the name(s) of the above copyright
23 * holders shall not be used in advertising or otherwise to promote the sale,
24 * use or other dealings in this Software without prior written authorization.
25 */
26#ifndef __WINDOW_H__
27#define __WINDOW_H__
28
29#include <windows.h>
30#include <string>
31
32class CDialog;
33class CWindow
34{
35    friend class CDialog;
36    public:
37        struct CBoundary
38        {
39            int left;
40            int top;
41            int width;
42            int height;
43            CBoundary() :
44                left(0), top(0), width(0), height(0) {};
45            CBoundary(int x, int y, int w, int h) :
46                left(x), top(y), width(w), height(h) {};
47            CBoundary(const RECT &r) :
48                left(r.left), top(r.top), width(r.right-r.left), height(r.bottom-r.top) {};
49        };
50        class CWindowClass
51        {
52            private:
53                WNDPROC wndproc;
54                ATOM atom;
55                std::string classname;
56            protected:
57                void Register();
58            public:
59                CWindowClass(const char *name, WNDPROC wndproc);
60                ~CWindowClass();
61                const char *GetClassName() { return classname.c_str(); };
62        };
63    private:
64        static CWindowClass windowClass;
65
66        std::string title;
67        DWORD exstyle;
68        DWORD style;
69        CBoundary bounds;
70        HWND hwnd;
71        HWND parent;
72        WNDPROC owndproc;
73
74        BOOL showing;
75
76    protected:
77
78        virtual const char *GetClassName();
79	virtual HWND CreateWindowHandle();
80        static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
81    public:
82        CWindow(const char *title);
83	virtual void Create();
84
85        virtual int ShowModal();
86
87        void Show();
88        void Hide();
89
90        void SetWidth(int width);
91        void SetHeight(int height);
92        void SetLeft(int left);
93        void SetTop(int top);
94        int GetWidth() { return bounds.width; };
95        int GetHeight() { return bounds.height; };
96        int GetLeft() { return bounds.left; };
97        int GetTop() { return bounds.top; };
98
99        void SetBounds(int left, int top, int width, int height);
100        void SetBounds(const RECT &rect);
101
102        void SetStyle(DWORD style);
103        DWORD GetStyle() { return style; };
104
105        void SetExStyle(DWORD exstyle);
106        DWORD GetExStyle() { return exstyle; };
107
108        HWND GetHandle();
109        void SetParent(CWindow *window);
110
111        virtual LRESULT Dispatch(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
112};
113
114#endif
115