5 #include "menuengine.h"
6 #include "cheetahmenu.h"
10 #include "systeminfo.h"
13 #define LONGEST_MENU_ITEM 40
16 * Windows-specific Cheetah menu functions
18 struct windows_menu_data
{
25 void reset_platform(void *platform
)
27 /* On Windows, we don't do anything to reset the menu */
31 * menu_item_builder to build a Windows-specific menu separator
33 * Always returns FALSE so the menu engine does not track this item
35 BOOL
build_separator(struct git_data
*data
, const struct menu_item
*item
,
38 struct windows_menu_data
*windows_menu
= platform
;
39 InsertMenu(windows_menu
->menu
, windows_menu
->index
,
40 MF_SEPARATOR
| MF_BYPOSITION
, 0, "");
41 windows_menu
->index
++;
47 * menu_item_builder to build a simple menu item
49 * Explorer's context menu are limited in the number of comands
50 * that they can use, so build_item would:
51 * - do nothing if that limit is reached and return FALSE to
52 * instruct the menu engine to not track this item
53 * - create item and return TRUE, so the item can be handled later
55 BOOL
build_item(struct git_data
*data
, const struct menu_item
*item
,
58 struct windows_menu_data
*windows_menu
= platform
;
59 if (windows_menu
->last
< windows_menu
->first
+ next_active_item
)
62 InsertMenu(windows_menu
->menu
, windows_menu
->index
,
63 MF_STRING
| MF_BYPOSITION
,
64 windows_menu
->first
+ next_active_item
,
66 windows_menu
->index
++;
71 void *start_submenu(struct git_data
*this_
, const struct menu_item
*item
,
74 struct windows_menu_data
*parent_menu
= platform
;
75 struct windows_menu_data
*submenu
=
76 malloc(sizeof(struct windows_menu_data
));
77 submenu
->menu
= CreateMenu();
78 InsertMenu(parent_menu
->menu
, parent_menu
->index
,
79 MF_POPUP
| MF_BYPOSITION
, (UINT_PTR
)(submenu
->menu
),
84 submenu
->first
= parent_menu
->first
;
89 void end_submenu(void *parent
, void *submenu
)
95 * These are the functions for handling the context menu.
98 inline STDMETHODIMP
query_context_menu(void *p
, HMENU menu
,
99 UINT index
, UINT first_command
,
100 UINT last_command
, UINT flags
)
102 struct git_menu
*this_menu
= p
;
103 struct git_data
*this_
= this_menu
->git_data
;
104 struct windows_menu_data windows_menu
=
105 { menu
, index
, first_command
, last_command
};
107 if (flags
& CMF_DEFAULTONLY
)
108 return MAKE_HRESULT(SEVERITY_SUCCESS
, FACILITY_NULL
, 0);
110 build_cheetah_menu(this_
, &windows_menu
);
112 return MAKE_HRESULT(SEVERITY_SUCCESS
, FACILITY_NULL
,
117 * Perform a couple of transformations, such that a directory
118 * C:\Program Files\Bunch of stuff\in\A dir
120 * /C/Program\ Files/Bunch\ of\ stuff/in/A\ dir
122 * Assumes path is initially a correctly formed Windows-style path.
123 * Returns a new string.
125 static char *convert_directory_format(const char *path
)
132 /* Figure out how much extra space we need to escape spaces */
133 for (i
= 0; i
< MAX_PATH
&& path
[i
] != '\0'; ++i
)
137 converted
= (char *)calloc(size_incr
+ i
+ 1, sizeof(char));
144 for (i
= 0; i
< MAX_PATH
&& path
[i
] != '\0'; ++i
)
163 converted
[1] = converted
[0];
169 inline STDMETHODIMP
invoke_command(void *p
,
170 LPCMINVOKECOMMANDINFO info
)
172 struct git_menu
*this_menu
= p
;
173 struct git_data
*this_
= this_menu
->git_data
;
174 UINT id
= LOWORD(info
->lpVerb
);
176 if (HIWORD(info
->lpVerb
))
179 handle_menu_item(this_
, id
);
183 inline STDMETHODIMP
get_command_string(void *p
, UINT id
,
184 UINT flags
, UINT
*reserved
,
185 LPSTR name
, UINT size
)
189 if (!(flags
& GCS_HELPTEXT
))
192 text
= get_menu_item_text(id
);
196 if (flags
& GCS_UNICODE
) {
197 size_t len
= strlen(text
) + 1;
198 LPWSTR tw
= malloc(len
* sizeof(wchar_t));
199 /* need to convert terminating NULL as well */
200 mbstowcs(tw
, text
, len
);
201 lstrcpynW((LPWSTR
)name
, tw
, size
);
204 lstrcpynA(name
, text
, size
);
209 DEFINE_STANDARD_METHODS(git_menu
)
211 struct git_menu_virtual_table git_menu_virtual_table
= {
212 query_interface_git_menu
,