Usermode/axwin3 - Made menus auto-raised
[tpg/acess2.git] / Usermode / Applications / axwin3_src / WM / renderers / menu.c
index 4506ad2..d353442 100644 (file)
@@ -47,6 +47,8 @@ typedef struct sMenuWindowInfo
 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 ===
@@ -70,7 +72,12 @@ tWMRenderer  gRenderer_Menu = {
        .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
 
@@ -164,17 +171,17 @@ void Renderer_Menu_Redraw(tWindow *Window)
        
                // Text
                WM_Render_DrawText(Window,
-                       ciMenu_LeftPadding, y,
+                       ciMenu_LeftPadding, y+1,
                        w, ciMenu_ItemHeight,
                        gMenu_Font,
                        cMenu_LabelColour,
-                       item->Label
+                       item->Label, -1
                        );
                // Underline
                if(item->UnderlineW)
                {
                        WM_Render_FillRect(Window,
-                               ciMenu_LeftPadding + item->UnderlineX, y + ciMenu_FontHeight,
+                               ciMenu_LeftPadding + item->UnderlineX, y + 1 + ciMenu_FontHeight,
                                item->UnderlineW, 1,
                                cMenu_LabelColour
                                );
@@ -188,7 +195,7 @@ void Renderer_Menu_Redraw(tWindow *Window)
                                w, ciMenu_ItemHeight,
                                gMenu_Font,
                                cMenu_ShortcutColour,
-                               item->Shortcut
+                               item->Shortcut, -1
                                );
                }
                
@@ -196,8 +203,9 @@ void Renderer_Menu_Redraw(tWindow *Window)
        }
 }
 
-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;
        
@@ -275,33 +283,31 @@ int Renderer_Menu_int_AddItem(tWindow *Window, int Length, const tMenuMsg_AddIte
        }
        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
@@ -313,6 +319,9 @@ int Renderer_Menu_int_AddItem(tWindow *Window, int Length, const tMenuMsg_AddIte
        return 0;
 }
 
+/**
+ * \brief Convert coordinates into an item index
+ */
 int Renderer_Menu_int_GetItemByPos(tWindow *Window, tMenuWindowInfo *Info, int X, int Y)
 {
         int    i;
@@ -358,6 +367,7 @@ int Renderer_Menu_HandleMessage(tWindow *Window, int Msg, int Length, const void
                        // 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
                {
@@ -417,11 +427,6 @@ int Renderer_Menu_HandleMessage(tWindow *Window, int Msg, int Length, const void
 
                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;

UCC git Repository :: git.ucc.asn.au