Usermode/Build - Updates to build system for crtbegin/crtend
[tpg/acess2.git] / Usermode / Applications / axwin3_src / WM / renderer_menu.c
index d4e078b..45c6a24 100644 (file)
@@ -93,7 +93,10 @@ tWindow      *Renderer_Menu_Create(int Argument)
        info->MaxItems = Argument;
        info->HilightedItem = -1;
 
-       _SysDebug("Renderer_Menu_Create: ->MaxItems = %i", info->MaxItems);
+       ret->Flags |= WINFLAG_NODECORATE;
+       ret->H = ciMenu_TopPadding + ciMenu_BottomPadding;
+
+//     _SysDebug("Renderer_Menu_Create: ->MaxItems = %i", info->MaxItems);
        
        return ret;
 }
@@ -102,11 +105,9 @@ void Renderer_Menu_Redraw(tWindow *Window)
 {
        tMenuWindowInfo *info = Window->RendererInfo;
         int    w, h, y, i;
-       _SysDebug("TODO: Implement Renderer_Menu_Redraw");
-
-//     _SysDebug("info->nItems = %i", info->nItems);
 
        w = info->CachedW;
+       #if 0
        h = ciMenu_TopPadding + ciMenu_BottomPadding;
        for( i = 0; i < info->nItems; i ++ )
        {
@@ -117,12 +118,12 @@ void Renderer_Menu_Redraw(tWindow *Window)
                else
                        h += ciMenu_SpacerHeight;
        }
+       #else
+       h = Window->H;
+       #endif
 
 //     _SysDebug("w = %i, h = %i", w, h);
 
-       // - Resize window to contain all items
-       WM_ResizeWindow(Window, w, h);
-
        // - Move the window such that it is on screen
        //  > Make sure to catch if the menu can't fit fully onscreen
 
@@ -173,7 +174,7 @@ void Renderer_Menu_Redraw(tWindow *Window)
                if(item->UnderlineW)
                {
                        WM_Render_FillRect(Window,
-                               ciMenu_LeftPadding + item->UnderlineX, y + ciMenu_FontHeight + 1,
+                               ciMenu_LeftPadding + item->UnderlineX, y + ciMenu_FontHeight,
                                item->UnderlineW, 1,
                                cMenu_LabelColour
                                );
@@ -215,7 +216,10 @@ int Renderer_Menu_int_AddItem(tWindow *Window, int Length, void *Data)
        }
        
        // Don't overwrite
-       if(info->Items[req->ID])        return 0;
+       if(info->Items[req->ID]) {
+               _SysDebug("- Caught overwrite of %i", req->ID);
+               return 0;
+       }
        // Bookkeeping
        if(req->ID >= info->nItems)     info->nItems = req->ID + 1;
        // Allocate
@@ -226,6 +230,7 @@ int Renderer_Menu_int_AddItem(tWindow *Window, int Length, void *Data)
        {
                // Spacer
                item->Label = NULL;
+               WM_ResizeWindow(Window, info->CachedW, Window->H+ciMenu_SpacerHeight);
                
                return 0;
        }
@@ -303,61 +308,111 @@ int Renderer_Menu_int_AddItem(tWindow *Window, int Length, void *Data)
                info->CachedW = ciMenu_LeftPadding + info->MaxLabelWidth
                        + ciMenu_Gap + info->MaxShortcutWidth
                        + ciMenu_RightPadding;
-               // TODO: Smarter height?
-               WM_ResizeWindow(Window, info->CachedW, info->nItems*ciMenu_ItemHeight);
        }
+       WM_ResizeWindow(Window, info->CachedW, Window->H+ciMenu_ItemHeight);
        
        return 0;
 }
 
+int Renderer_Menu_int_GetItemByPos(tWindow *Window, tMenuWindowInfo *Info, int X, int Y)
+{
+        int    i;
+
+       if( X < 0 || X >= Window->W )
+               return -1;
+       
+       for( i = 0; i < Info->nItems; i ++ )
+       {
+               if( !Info->Items[i] )   continue;
+                       
+               if( !Info->Items[i]->Label )
+               {
+                       // Spacer - not selectable
+                       if(Y < ciMenu_SpacerHeight) {
+                               return -1;
+                       }
+                       Y -= ciMenu_SpacerHeight;
+               }
+               else
+               {
+                       // Normal item, can be selected/hilighted
+                       if(Y < ciMenu_ItemHeight) {
+                               return i;
+                       }
+                       Y -= ciMenu_ItemHeight;
+               }
+       }
+       return -1;
+}
+
 int Renderer_Menu_HandleMessage(tWindow *Window, int Msg, int Length, void *Data)
 {
+       tMenuWindowInfo *info = Window->RendererInfo;
        switch(Msg)
        {
-       case WNDMSG_MOUSEMOVE: {
-               tMenuWindowInfo *info = Window->RendererInfo;
-               struct sWndMsg_MouseMove        *msg = Data;
-                int    new_hilight;
-
+       case WNDMSG_SHOW: {
+               struct sWndMsg_Bool     *msg = Data;
                if(Length < sizeof(*msg))       return -1;
-
-               if( msg->X < 0 || msg->X >= Window->W )
+               if(msg->Val)
                {
-                       new_hilight = -1;
+//                     _SysDebug(" - Shown, take focus");
+                       // TODO: This shouldn't really be done, instead focus should be given
+                       //       when the menu is shown.
+//                     WM_FocusWindow(Window);
                }
                else
                {
-                        int    i, y;
-                       y = msg->Y;
-                       new_hilight = -1;
-                       for( i = 0; i < info->nItems; i ++ )
+                       // Hide Children
+                       _SysDebug("- Hidden, hide the children!");
+               }
+               return 0; }
+       case WNDMSG_FOCUS: {
+               struct sWndMsg_Bool     *msg = Data;
+               if(Length < sizeof(*msg))       return -1;
+               if(!msg->Val) {
+                       // TODO: Catch if focus was given away to a child
+                       _SysDebug("- Lost focus");
+                       WM_ShowWindow(Window, 0);       // Hide!
+               }
+               else {
+                       _SysDebug("- Focus gained, TODO: Show accel keys");
+               }
+               return 0; }
+
+       case WNDMSG_MOUSEBTN: {
+               struct sWndMsg_MouseButton      *msg = Data;
+                int    item;
+               
+               if(Length < sizeof(*msg))       return -1;
+
+               if(msg->Button == 0 && msg->bPressed == 0)
+               {
+                       item = Renderer_Menu_int_GetItemByPos(Window, info, msg->X, msg->Y);
+                       if(item != -1)
                        {
-                               if( !info->Items[i] )   continue;
-                                       
-                               if( !info->Items[i]->Label )
-                               {
-                                       // Spacer - doesn't hilight
-                                       if(y < ciMenu_SpacerHeight) {
-                                               new_hilight = -1;
-                                               break;
-                                       }
-                                       y -= ciMenu_SpacerHeight;
-                               }
-                               else
-                               {
-                                       // Normal item, set the hilight
-                                       if(y < ciMenu_ItemHeight) {
-                                               new_hilight = i;
-                                               break;
-                                       }
-                                       y -= ciMenu_ItemHeight;
-                               }
+                               tMenuMsg_Select _msg;
+                               // TODO: Ignore sub-menus too
+                               _msg.ID = item;
+                               WM_SendMessage(Window, Window, MSG_MENU_SELECT, sizeof(_msg), &_msg);
+                               WM_ShowWindow(Window, 0);
                        }
                }
+                               
+
+               return 0; }     
+
+       case WNDMSG_MOUSEMOVE: {
+               struct sWndMsg_MouseMove        *msg = Data;
+                int    new_hilight;
+
+               if(Length < sizeof(*msg))       return -1;
+
+               new_hilight = Renderer_Menu_int_GetItemByPos(Window, info, msg->X, msg->Y);
 
                if( new_hilight != info->HilightedItem )
                {
                        info->HilightedItem = new_hilight;
+                       // TODO: Change sub-menu
                        WM_Invalidate(Window);
                }
 
@@ -365,7 +420,7 @@ int Renderer_Menu_HandleMessage(tWindow *Window, int Msg, int Length, void *Data
 
        // Manipulation messages
        case MSG_MENU_ADDITEM:
-               _SysDebug("MSG_MENU_ADDITEM");
+//             _SysDebug("MSG_MENU_ADDITEM");
                return Renderer_Menu_int_AddItem(Window, Length, Data);
        
        // Only message to pass to client

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