Add command-line option help-text localization
[cygwin-setup.git] / window.h
blob1dfb2a9f75142806fd52229f8288145a6d735720
1 /*
2 * Copyright (c) 2001, 2002, 2003 Gary R. Van Sickle.
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.
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
12 * Written by Gary R. Van Sickle <g.r.vansickle@worldnet.att.net>
16 #ifndef SETUP_WINDOW_H
17 #define SETUP_WINDOW_H
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).
23 #include <vector>
24 #include <map>
25 #include "win32.h"
26 #include <commctrl.h>
27 #include "LogSingleton.h"
29 class RECTWrapper;
31 class Window
33 static ATOM WindowClassAtom;
34 static HINSTANCE AppInstance;
36 virtual bool registerWindowClass ();
37 protected:
38 static LRESULT CALLBACK FirstWindowProcReflector (HWND hwnd, UINT uMsg,
39 WPARAM wParam,
40 LPARAM lParam);
41 private:
42 static LRESULT CALLBACK WindowProcReflector (HWND hwnd, UINT uMsg,
43 WPARAM wParam, LPARAM lParam);
45 // Our Windows(tm) window handle.
46 HWND WindowHandle;
48 Window *Parent;
50 // contains handles to fonts we've created
51 // that are to be deleted in our dtor
52 std::vector<HFONT> Fonts;
54 // if we have activated tool tips this will contain the handle
55 HWND TooltipHandle;
57 // maps a control ID to a string resource ID
58 std::map<int, int> TooltipStrings;
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;
65 // Saved old cursor handle, only while BusyCount is non-zero.
66 HCURSOR OldCursor;
68 // Handle to busy cursor (loaded first time needed, NULL until then).
69 HCURSOR BusyCursor;
71 protected:
72 void SetHWND (HWND h)
74 WindowHandle = h;
76 void setParent(Window *aParent)
78 Parent = aParent;
81 public:
82 Window ();
83 virtual ~ Window ();
85 virtual bool Create (Window * Parent = NULL,
86 DWORD Style =
87 WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN);
89 static void SetAppInstance (HINSTANCE h)
91 // This only has to be called once in the entire app, before
92 // any Windows are created.
93 AppInstance = h;
96 virtual LRESULT WindowProc (UINT uMsg, WPARAM wParam, LPARAM lParam);
97 virtual bool MessageLoop ();
99 void Show (int State);
101 HWND GetHWND () const
103 // Ideally this could be hidden from the user completely.
104 return WindowHandle;
106 static HINSTANCE GetInstance ()
108 return AppInstance;
111 Window *GetParent () const
113 return Parent;
115 HWND GetDlgItem (int id) const
117 return::GetDlgItem (GetHWND (), id);
119 bool SetDlgItemFont (int id, const TCHAR * fontname, int Pointsize,
120 int Weight = FW_NORMAL, bool Italic =
121 false, bool Underline = false, bool Strikeout = false);
123 UINT IsButtonChecked (int nIDButton) const;
125 void PostMessageNow (UINT uMsg, WPARAM wParam = 0, LPARAM lParam = 0);
127 virtual bool OnMessageApp (UINT uMsg, WPARAM wParam, LPARAM lParam)
129 // Not processed by default. Override in derived classes to
130 // do something with app messages if you need to.
131 return false;
134 virtual bool OnMessageCmd (int id, HWND hwndctl, UINT code)
136 // Not processed by default. Override in derived classes to
137 // do something with command messages if you need to.
138 return false;
141 virtual bool OnNotify (NMHDR *pNmHdr, LRESULT *pResult)
143 // Not processed by default. Override in derived classes to
144 // do something with command messages if you need to.
145 return false;
148 RECT GetWindowRect() const;
149 RECT GetClientRect() const;
151 // Center the window on the parent, or on screen if no parent.
152 void CenterWindow ();
154 // Reposition the window
155 bool MoveWindow(long x, long y, long w, long h, bool Repaint = true);
156 bool MoveWindow(const RECTWrapper &r, bool Repaint = true);
158 // Set the title of the window.
159 void SetWindowText (const std::wstring& s);
161 RECT ScreenToClient(const RECT &r) const;
162 void ActivateTooltips ();
163 void SetTooltipState (bool b);
164 void AddTooltip (HWND target, HWND win, const char *text);
165 void AddTooltip (int id, const char *text);
166 void AddTooltip (int id, int string_resource);
167 BOOL TooltipNotificationHandler (LPARAM lParam);
168 // Call this to set an hourglass cursor.
169 void SetBusy (void);
170 // Call this to reset to normal cursor. It must be called
171 // once for each call to SetBusy; they nest recursively.
172 void ClearBusy (void);
175 #endif /* SETUP_WINDOW_H */