void Renderer_Menu_Init(void);
tWindow *Renderer_Menu_Create(int Argument);
void Renderer_Menu_Redraw(tWindow *Window);
+ int Renderer_Menu_HandleIPC_AddItem(tWindow *Window, size_t Length, const void *Data);
+ int Renderer_Menu_HandleIPC_SetFlags(tWindow *Window, size_t Length, const void *Data);
int Renderer_Menu_HandleMessage(tWindow *Window, int Msg, int Length, const void *Data);
// === CONSTANTS ===
.Name = "Menu",
.CreateWindow = Renderer_Menu_Create,
.Redraw = Renderer_Menu_Redraw,
- .HandleMessage = Renderer_Menu_HandleMessage
+ .HandleMessage = Renderer_Menu_HandleMessage,
+ .nIPCHandlers = 2,
+ .IPCHandlers = {
+ Renderer_Menu_HandleIPC_AddItem,
+// Renderer_Menu_HandleIPC_SetFlags
+ }
};
tFont *gMenu_Font = NULL; // System monospace
w, ciMenu_ItemHeight,
gMenu_Font,
cMenu_LabelColour,
- item->Label
+ item->Label, -1
);
// Underline
if(item->UnderlineW)
w, ciMenu_ItemHeight,
gMenu_Font,
cMenu_ShortcutColour,
- item->Shortcut
+ item->Shortcut, -1
);
}
}
}
-int Renderer_Menu_int_AddItem(tWindow *Window, int Length, const tMenuMsg_AddItem *Msg)
+int Renderer_Menu_HandleIPC_AddItem(tWindow *Window, size_t Length, const void *Data)
{
+ const tMenuIPC_AddItem *Msg = Data;
tMenuWindowInfo *info = Window->RendererInfo;
tMenuItem *item;
}
else
{
- char tmp = item->Label[item->KeyOffset];
// Get width of preceding substring
- item->Label[item->KeyOffset] = '\0';
- WM_Render_GetTextDims(NULL, item->Label, &item->UnderlineX, NULL);
+ WM_Render_GetTextDims(NULL, item->Label, item->KeyOffset, &item->UnderlineX, NULL);
// Get the width of the underlined character
- // TODO: Fix for high UTF-8 characters
- item->Label[item->KeyOffset] = tmp;
- tmp = item->Label[item->KeyOffset+1];
- item->Label[item->KeyOffset+1] = '\0';
+ // NOTE: 1 makes only one character be parsed, even if it is >1 byte long
WM_Render_GetTextDims(
- NULL, item->Label+item->KeyOffset,
+ NULL, item->Label+item->KeyOffset, 1,
&item->UnderlineW, NULL
);
- item->Label[item->KeyOffset+1] = tmp;
}
// - Labels
- WM_Render_GetTextDims(NULL, item->Label, &item->LabelWidth, NULL);
+ WM_Render_GetTextDims(NULL, item->Label, -1, &item->LabelWidth, NULL);
if(item->Shortcut)
- WM_Render_GetTextDims(NULL, item->Shortcut, &item->ShortcutWidth, NULL);
+ WM_Render_GetTextDims(NULL, item->Shortcut, -1, &item->ShortcutWidth, NULL);
else
item->ShortcutWidth = 0;
-
+
+ // Get maximum lengths (to determine the size of the menu
if( item->LabelWidth > info->MaxLabelWidth )
info->MaxLabelWidth = item->LabelWidth;
if( item->ShortcutWidth > info->MaxShortcutWidth )
info->MaxShortcutWidth = item->ShortcutWidth;
+ // Update width
+ // TODO: Check, do I want to resize down too?
+ // TODO: Take into account padding too
if( info->MaxLabelWidth + info->MaxShortcutWidth + ciMenu_Gap > info->CachedW )
{
info->CachedW = ciMenu_LeftPadding + info->MaxLabelWidth
return 0;
}
+/**
+ * \brief Convert coordinates into an item index
+ */
int Renderer_Menu_int_GetItemByPos(tWindow *Window, tMenuWindowInfo *Info, int X, int Y)
{
int i;
// TODO: This shouldn't really be done, instead focus should be given
// when the menu is shown.
// WM_FocusWindow(Window);
+ WM_RaiseWindow(Window); // If it's shown, raise it to the heavens!
}
else
{
{
info->HilightedItem = new_hilight;
// TODO: Change sub-menu
- WM_Invalidate(Window);
+ WM_Invalidate(Window, 1);
}
return 0; }
- // Manipulation messages
- case MSG_MENU_ADDITEM:
-// _SysDebug("MSG_MENU_ADDITEM");
- return Renderer_Menu_int_AddItem(Window, Length, Data);
-
// Only message to pass to client
case MSG_MENU_SELECT:
return 1;