LIBURANIA
GUI library (a wrapper of Win32 API) in C++
読み取り中…
検索中…
一致する文字列を見つけられません
window.h
[詳解]
1/*
2 * Copyright 2002-2021 oZ/acy (名賀月晃嗣)
3 * Redistribution and use in source and binary forms,
4 * with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 */
46#ifndef INCLUDE_GUARD_URANIA_WINDOW_H
47#define INCLUDE_GUARD_URANIA_WINDOW_H
48
49#include <map>
50#include <memory>
51#include <utility>
52#include "bwin.h"
53#include "menu.h"
54
55
56namespace urania
57{
58struct WndMessage;
59class WMHandler;
60class WindowFactory;
61
62} // end of namesace urania
63
64
69{
71 UINT id;
72 WPARAM wparam;
73 LPARAM lparam;
74};
75
76
80class urania::WMHandler : eunomia::Noncopyable<urania::WMHandler>
81{
82public:
89 using CmdHandler = void (*)(Window*);
90
91private:
92 std::map<int, CmdHandler> cmap_;
93
94public:
96 virtual ~WMHandler() = default;
97
101 void setCommand(int cmdid, CmdHandler c) { cmap_[cmdid] = c; }
102
105 LRESULT operator()(urania::WndMessage* msg);
106
113 virtual bool onDestroy() { return false; }
114
125 virtual bool onSize(Window* win, int typ, int w, int h) { return false; }
126
137 virtual bool onKeyDown(Window* win, int code, int rep, bool prev)
138 { return false; }
139
154 virtual bool onLButtonDown(
155 Window* win, int x, int y, bool ctrl, bool shft, bool lb, bool mb, bool rb)
156 { return false; }
157
172 virtual bool onMButtonDown(
173 Window* win, int x, int y, bool ctrl, bool shft, bool lb, bool mb, bool rb)
174 { return false; }
175
190 virtual bool onRButtonDown(
191 Window* win, int x, int y, bool ctrl, bool shft, bool lb, bool mb, bool rb)
192 { return false; }
193
202 virtual void onPaint(BasicWindow* win, PaintDevice* pd) {}
203
214 virtual void onScroll(Window* win, int id, int pos) {}
215
227 virtual void onMouseWheel(Window* w, int delta, int keys, int x, int y) {}
228
237 virtual void onDropFiles(
238 Window* w, std::vector<std::wstring>& fa, int x, int y)
239 {}
240
241private:
245 void onDropFiles_(urania::Window*, WPARAM wp);
246
250 void onScroll_(urania::Window*, UINT msg, WPARAM, LPARAM);
251};
252
253
254
255
260{
262
263public:
264 typedef LRESULT (*H_)(urania::Window* pw, UINT msg, WPARAM wp, LPARAM lp);
265
266protected:
267 std::unique_ptr<urania::WMHandler> msgHandler_;
268 std::shared_ptr<urania::Menu> menu_;
269 bool dad_;
270
271protected:
272 Window() noexcept : msgHandler_(), dad_(false) {}
273 void init_(HWND hw) override;
274 void uninit_() override;
275
276public:
278
279 std::shared_ptr<urania::Menu> getMenu() const { return menu_; }
280 void setMenu(const std::shared_ptr<urania::Menu>& m) { linkMenu_(m); }
281 void setMenu(std::shared_ptr<urania::Menu>&& m)
282 { linkMenu_(std::move(m)); }
283
284protected:
286 virtual LRESULT wproc_(UINT msg, WPARAM wp, LPARAM lp) override;
287
288 static HMENU getHM_(const std::shared_ptr<urania::Menu>& mn)
289 { return mn->hmenu_; }
290
291 HMENU linkMenu_(const std::shared_ptr<urania::Menu>& mn)
292 {
293 menu_ = mn;
294 return menu_->giveHM_();
295 }
296
297 HMENU linkMenu_(std::shared_ptr<urania::Menu>&& mn)
298 {
299 menu_ = std::move(mn);
300 return menu_->giveHM_();
301 }
302};
303
304
305
306
320{
321public:
322 std::wstring title;
323 int x;
324 int y;
325 int w;
326 int h;
327
328 unsigned icon;
329 unsigned cursor;
330 unsigned bkcolor;
331
333 bool maxbox;
334 bool minbox;
337 bool popup;
340
341public:
342 WindowFactory() noexcept
343 : x(CW_USEDEFAULT), w(CW_USEDEFAULT),
345 drag_and_drop(false), maxbox(false), minbox(false),
346 h_scrollbar(false), v_scrollbar(false), popup(false),
347 border_only(false), resizeable(false)
348 {}
349
357 std::unique_ptr<urania::Window>
358 create(std::unique_ptr<urania::WMHandler>&& hnd, int menu =0)
359 {
360 return factory_(std::move(hnd), menu, nullptr, 0);
361 }
362
371 std::unique_ptr<urania::Window>
373 urania::BasicWindow* owner,
374 std::unique_ptr<urania::WMHandler>&& hnd,
375 int menu =0)
376 {
377 return factory_(std::move(hnd), menu, owner, 0);
378 }
379
388 std::unique_ptr<urania::Window>
390 urania::BasicWindow* parent, int cid, std::unique_ptr<WMHandler>&& hnd)
391 {
392 return factory_(std::move(hnd), 0, parent, cid);
393 }
394
395private:
400 std::unique_ptr<urania::Window>
401 factory_(
402 std::unique_ptr<WMHandler>&& hnd, int menu,
403 urania::BasicWindow* par, int cid);
404};
405
406
407
408
409#endif // INCLUDE_GUARD_URANIA_WINDOW_H
Window用基底クラス
Window管理・操作用基底クラス
Definition bwin.h:54
Definition paintdev.h:212
メッセージハンドラ基底
Definition window.h:81
virtual ~WMHandler()=default
解體子
virtual bool onMButtonDown(Window *win, int x, int y, bool ctrl, bool shft, bool lb, bool mb, bool rb)
マウス中ボタン押下時のハンドラ
Definition window.h:172
LRESULT operator()(urania::WndMessage *msg)
メッセージに應じたハンドラを呼び出す
Definition win.cpp:153
virtual bool onSize(Window *win, int typ, int w, int h)
ウィンドウサイズ變化時のハンドラ
Definition window.h:125
virtual void onPaint(BasicWindow *win, PaintDevice *pd)
再描畫要求時のハンドラ
Definition window.h:202
virtual void onScroll(Window *win, int id, int pos)
スクロールバー操作時のハンドラ
Definition window.h:214
virtual bool onKeyDown(Window *win, int code, int rep, bool prev)
キー押下時のハンドラ
Definition window.h:137
virtual bool onLButtonDown(Window *win, int x, int y, bool ctrl, bool shft, bool lb, bool mb, bool rb)
マウス左ボタン押下時のハンドラ
Definition window.h:154
void setCommand(int cmdid, CmdHandler c)
コマンドに對するハンドラを登録する
Definition window.h:101
virtual void onMouseWheel(Window *w, int delta, int keys, int x, int y)
マウスホイール操作時のハンドラ
Definition window.h:227
virtual bool onRButtonDown(Window *win, int x, int y, bool ctrl, bool shft, bool lb, bool mb, bool rb)
マウス右ボタン押下時のハンドラ
Definition window.h:190
virtual void onDropFiles(Window *w, std::vector< std::wstring > &fa, int x, int y)
ファイルドロップ時のハンドラ
Definition window.h:237
void(*)(Window *) CmdHandler
コマンドハンドラ
Definition window.h:89
virtual bool onDestroy()
ウィンドウ破棄時のハンドラ
Definition window.h:113
ウィンドウのファクトリ
Definition window.h:320
unsigned bkcolor
背景色の番號
Definition window.h:330
bool border_only
枠のみのウィンドウを作成する場合はtrue
Definition window.h:338
bool resizeable
ウィンドウの大きさを變更可能にする場合はtrue
Definition window.h:339
int w
ウィンドウの幅
Definition window.h:325
int x
ウィンドウの左上のx座標
Definition window.h:323
std::wstring title
ウィンドウのタイトル
Definition window.h:322
bool popup
ポップアップウィンドウを作成する場合はtrue
Definition window.h:337
int y
ウィンドウの左上のy座標
Definition window.h:324
bool drag_and_drop
ドラッグ・アンド・ドロップを受け附けるときはtrue
Definition window.h:332
std::unique_ptr< urania::Window > createAsOwned(urania::BasicWindow *owner, std::unique_ptr< urania::WMHandler > &&hnd, int menu=0)
オーナー附ウィンドウの生成
Definition window.h:372
int h
ウィンドウの高さ
Definition window.h:326
unsigned icon
アイコンのリソースID
Definition window.h:328
WindowFactory() noexcept
Definition window.h:342
bool v_scrollbar
垂直スクロールバーを持たせる場合はtrue
Definition window.h:336
std::unique_ptr< urania::Window > createAsChild(urania::BasicWindow *parent, int cid, std::unique_ptr< WMHandler > &&hnd)
子ウィンドウの生成
Definition window.h:389
std::unique_ptr< urania::Window > create(std::unique_ptr< urania::WMHandler > &&hnd, int menu=0)
ウィンドウ生成
Definition window.h:358
unsigned cursor
カーソルのリソースID
Definition window.h:329
bool maxbox
最大化ボタンを持たせる場合はtrue
Definition window.h:333
bool minbox
最小化ボタンを持たせる場合はtrue
Definition window.h:334
bool h_scrollbar
水平スクロールバーを持たせる場合はtrue
Definition window.h:335
ウィンドウ
Definition window.h:260
std::shared_ptr< urania::Menu > getMenu() const
Definition window.h:279
bool dad_
trueならDrag&Dropを受け附ける
Definition window.h:269
~Window()
Definition window.h:277
void setMenu(const std::shared_ptr< urania::Menu > &m)
Definition window.h:280
HMENU linkMenu_(std::shared_ptr< urania::Menu > &&mn)
Definition window.h:297
LRESULT(* H_)(urania::Window *pw, UINT msg, WPARAM wp, LPARAM lp)
Definition window.h:264
void setMenu(std::shared_ptr< urania::Menu > &&m)
Definition window.h:281
virtual LRESULT wproc_(UINT msg, WPARAM wp, LPARAM lp) override
各Windowのメッセージ処理プロシージャ
Definition win.cpp:96
void uninit_() override
メッセージ處理系初期化解除
Definition win.cpp:136
std::shared_ptr< urania::Menu > menu_
関連づけられたメニュー
Definition window.h:268
Window() noexcept
Definition window.h:272
static HMENU getHM_(const std::shared_ptr< urania::Menu > &mn)
Definition window.h:288
std::unique_ptr< urania::WMHandler > msgHandler_
メッセージハンドラ
Definition window.h:267
void init_(HWND hw) override
メッセージ處理系初期化
Definition win.cpp:117
HMENU linkMenu_(const std::shared_ptr< urania::Menu > &mn)
Definition window.h:291
void deleting_()
オブジェクト側からHWNDを破棄
Definition wbase.h:137
メニュークラス
Definition clkpanel.h:43
@ BG_WHITE
Definition decl.h:107
@ DEFAULT_RC
Definition decl.h:102
Definition window.h:69
WPARAM wparam
Definition window.h:72
UINT id
Definition window.h:71
LPARAM lparam
Definition window.h:73
urania::Window * window
Definition window.h:70