PageRenderTime 40ms CodeModel.GetById 12ms app.highlight 23ms RepoModel.GetById 1ms app.codeStats 0ms

/platform/win/scaffold/menu.d

http://github.com/wilkie/djehuty
D | 95 lines | 70 code | 15 blank | 10 comment | 14 complexity | 3771d73b8d10ab9a389e22db8f85b3d9 MD5 | raw file
 1/*
 2 * menu.d
 3 *
 4 * This file implements the Scaffold for platform specific Menu
 5 * operations in Windows.
 6 *
 7 * Author: Dave Wilkinson
 8 *
 9 */
10
11module scaffold.menu;
12
13import scaffold.window;
14
15import binding.win32.windef;
16import binding.win32.winnt;
17import binding.win32.winbase;
18import binding.win32.wingdi;
19import binding.win32.winuser;
20
21import platform.win.main;
22
23import platform.vars.menu;
24import platform.vars.window;
25
26import core.string;
27import core.main;
28import core.definitions;
29import core.unicode;
30
31import io.console;
32
33import gui.window;
34
35import resource.menu;
36
37void MenuCreate(MenuPlatformVars* menuVars) {
38	menuVars.hMenu = CreateMenu();
39}
40
41void MenuDestroy(MenuPlatformVars* menuVars) {
42	DestroyMenu(menuVars.hMenu);
43	menuVars.hMenu = null;
44}
45
46void MenuAppend(void* identifier, MenuPlatformVars* mnuVars, MenuPlatformVars* toAppendVars, string text, bool hasSubitems) {
47	wstring s;
48	if (text == "") {
49		if (hasSubitems) {
50			AppendMenuW(mnuVars.hMenu,MF_SEPARATOR,cast(UINT_PTR)toAppendVars.hMenu,"\0"w.ptr);
51		}
52		else {
53			AppendMenuW(mnuVars.hMenu,MF_SEPARATOR,cast(UINT_PTR)identifier,"\0"w.ptr);
54		}
55	}
56	else {
57		s = Unicode.toUtf16(text);
58		s ~= '\0';
59		if (hasSubitems) {
60			AppendMenuW(mnuVars.hMenu,MF_POPUP,cast(UINT_PTR)toAppendVars.hMenu,s.ptr);
61		}
62		else {
63			AppendMenuW(mnuVars.hMenu,MF_STRING,cast(UINT_PTR)identifier,s.ptr);
64		}
65	}
66}
67
68void MenuUpdate(void* identifier, MenuPlatformVars* mnuVars, MenuPlatformVars* toUpdateVars, string text, uint position, bool hasSubitems) {
69	wstring s;
70	if (text.trim() == "") {
71		if (hasSubitems) {
72			ModifyMenuW(mnuVars.hMenu,position,MF_BYPOSITION | MF_SEPARATOR,cast(UINT_PTR)toUpdateVars.hMenu,"\0"w.ptr);
73		}
74		else {
75			ModifyMenuW(mnuVars.hMenu,position,MF_BYPOSITION | MF_SEPARATOR,cast(UINT_PTR)identifier,"\0"w.ptr);
76		}
77	}
78	else {
79		s = Unicode.toUtf16(text);
80		s ~= '\0';
81		if (hasSubitems) {
82			ModifyMenuW(mnuVars.hMenu,position,MF_BYPOSITION | MF_POPUP,cast(UINT_PTR)toUpdateVars.hMenu,s.ptr);
83		}
84		else {
85			ModifyMenuW(mnuVars.hMenu,position,MF_BYPOSITION | MF_STRING,cast(UINT_PTR)identifier,s.ptr);
86		}
87	}
88}
89
90void WindowSetMenu(MenuPlatformVars* mnuVars, ref Window wnd, WindowPlatformVars* windowVars) {
91	SetMenu(windowVars.hWnd, mnuVars.hMenu);
92
93	// resize to adapt client area
94	WindowRebound(wnd,windowVars);
95}