]>
Commit | Line | Data |
---|---|---|
df62e023 | 1 | /* |
0a539fe4 | 2 | * Copyright (c) 2001, 2002, 2003 Gary R. Van Sickle. |
df62e023 RC |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by Gary R. Van Sickle <g.r.vansickle@worldnet.att.net> | |
13 | * | |
14 | */ | |
15 | ||
c93bc6d0 MB |
16 | #ifndef SETUP_WINDOW_H |
17 | #define SETUP_WINDOW_H | |
18 | ||
df62e023 RC |
19 | // This is the header for the Window class. It serves both as a window class |
20 | // in its own right and as a base class for other window-like classes (e.g. PropertyPage, | |
21 | // PropSheet). | |
22 | ||
daab12c7 | 23 | #include <vector> |
37f49caf | 24 | #include <map> |
46d04e97 | 25 | #include "win32.h" |
37f49caf BD |
26 | #include <commctrl.h> |
27 | #include "LogSingleton.h" | |
df62e023 | 28 | |
0a539fe4 | 29 | class RECTWrapper; |
58db1046 | 30 | |
df62e023 RC |
31 | class Window |
32 | { | |
33 | static ATOM WindowClassAtom; | |
34 | static HINSTANCE AppInstance; | |
35 | ||
693916f8 RC |
36 | virtual bool registerWindowClass (); |
37 | protected: | |
df62e023 RC |
38 | static LRESULT CALLBACK FirstWindowProcReflector (HWND hwnd, UINT uMsg, |
39 | WPARAM wParam, | |
40 | LPARAM lParam); | |
693916f8 | 41 | private: |
df62e023 RC |
42 | static LRESULT CALLBACK WindowProcReflector (HWND hwnd, UINT uMsg, |
43 | WPARAM wParam, LPARAM lParam); | |
44 | ||
0a539fe4 | 45 | // Our Windows(tm) window handle. |
df62e023 RC |
46 | HWND WindowHandle; |
47 | ||
48 | Window *Parent; | |
49 | ||
daab12c7 BD |
50 | // contains handles to fonts we've created |
51 | // that are to be deleted in our dtor | |
52 | std::vector<HFONT> Fonts; | |
b7301c43 | 53 | |
37f49caf BD |
54 | // if we have activated tool tips this will contain the handle |
55 | HWND TooltipHandle; | |
56 | ||
57 | // maps a control ID to a string resource ID | |
58 | std::map<int, int> TooltipStrings; | |
67ce5bee DK |
59 | |
60 | // Recursive count of number of times we've called SetBusy, | |
61 | // so that we only reset the cursor when we've cleared it | |
62 | // the same number of times. | |
63 | int BusyCount; | |
64 | ||
65 | // Saved old cursor handle, only while BusyCount is non-zero. | |
66 | HCURSOR OldCursor; | |
67 | ||
68 | // Handle to busy cursor (loaded first time needed, NULL until then). | |
69 | HCURSOR BusyCursor; | |
70 | ||
df62e023 RC |
71 | protected: |
72 | void SetHWND (HWND h) | |
73 | { | |
74 | WindowHandle = h; | |
75 | }; | |
daab12c7 BD |
76 | void setParent(Window *aParent) |
77 | { | |
78 | Parent = aParent; | |
79 | }; | |
df62e023 RC |
80 | |
81 | public: | |
82 | Window (); | |
83 | virtual ~ Window (); | |
84 | ||
b9c686ca JT |
85 | bool Create (Window * Parent = NULL, |
86 | DWORD Style = WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN); | |
87 | ||
df62e023 RC |
88 | static void SetAppInstance (HINSTANCE h) |
89 | { | |
0a539fe4 MB |
90 | // This only has to be called once in the entire app, before |
91 | // any Windows are created. | |
df62e023 RC |
92 | AppInstance = h; |
93 | }; | |
94 | ||
95 | virtual LRESULT WindowProc (UINT uMsg, WPARAM wParam, LPARAM lParam); | |
96 | virtual bool MessageLoop (); | |
97 | ||
df62e023 RC |
98 | void Show (int State); |
99 | ||
100 | HWND GetHWND () const | |
101 | { | |
0a539fe4 | 102 | // Ideally this could be hidden from the user completely. |
df62e023 RC |
103 | return WindowHandle; |
104 | }; | |
67ce5bee | 105 | static HINSTANCE GetInstance () |
df62e023 RC |
106 | { |
107 | return AppInstance; | |
108 | }; | |
109 | ||
110 | Window *GetParent () const | |
111 | { | |
112 | return Parent; | |
113 | }; | |
114 | HWND GetDlgItem (int id) const | |
115 | { | |
116 | return::GetDlgItem (GetHWND (), id); | |
117 | }; | |
58db1046 RC |
118 | bool SetDlgItemFont (int id, const TCHAR * fontname, int Pointsize, |
119 | int Weight = FW_NORMAL, bool Italic = | |
120 | false, bool Underline = false, bool Strikeout = false); | |
b7301c43 RC |
121 | |
122 | UINT IsButtonChecked (int nIDButton) const; | |
df62e023 | 123 | |
6ab6abae | 124 | void PostMessageNow (UINT uMsg, WPARAM wParam = 0, LPARAM lParam = 0); |
df62e023 RC |
125 | |
126 | virtual bool OnMessageApp (UINT uMsg, WPARAM wParam, LPARAM lParam) | |
127 | { | |
0a539fe4 MB |
128 | // Not processed by default. Override in derived classes to |
129 | // do something with app messages if you need to. | |
df62e023 RC |
130 | return false; |
131 | }; | |
132 | ||
b7301c43 RC |
133 | virtual bool OnMessageCmd (int id, HWND hwndctl, UINT code) |
134 | { | |
0a539fe4 MB |
135 | // Not processed by default. Override in derived classes to |
136 | // do something with command messages if you need to. | |
ffc18a69 JT |
137 | return false; |
138 | }; | |
139 | ||
140 | virtual bool OnNotify (NMHDR *pNmHdr, LRESULT *pResult) | |
141 | { | |
142 | // Not processed by default. Override in derived classes to | |
143 | // do something with command messages if you need to. | |
b7301c43 RC |
144 | return false; |
145 | }; | |
146 | ||
63c82708 RC |
147 | RECT GetWindowRect() const; |
148 | RECT GetClientRect() const; | |
149 | ||
df62e023 RC |
150 | // Center the window on the parent, or on screen if no parent. |
151 | void CenterWindow (); | |
152 | ||
63c82708 RC |
153 | // Reposition the window |
154 | bool MoveWindow(long x, long y, long w, long h, bool Repaint = true); | |
0a539fe4 | 155 | bool MoveWindow(const RECTWrapper &r, bool Repaint = true); |
63c82708 | 156 | |
58db1046 | 157 | // Set the title of the window. |
c156d59f | 158 | void SetWindowText (const std::wstring& s); |
58db1046 | 159 | |
63c82708 | 160 | RECT ScreenToClient(const RECT &r) const; |
37f49caf BD |
161 | void ActivateTooltips (); |
162 | void SetTooltipState (bool b); | |
163 | void AddTooltip (HWND target, HWND win, const char *text); | |
164 | void AddTooltip (int id, const char *text); | |
165 | void AddTooltip (int id, int string_resource); | |
166 | BOOL TooltipNotificationHandler (LPARAM lParam); | |
67ce5bee DK |
167 | // Call this to set an hourglass cursor. |
168 | void SetBusy (void); | |
169 | // Call this to reset to normal cursor. It must be called | |
170 | // once for each call to SetBusy; they nest recursively. | |
171 | void ClearBusy (void); | |
df62e023 RC |
172 | }; |
173 | ||
c93bc6d0 | 174 | #endif /* SETUP_WINDOW_H */ |