Usermode/AxWin3 - Cleaned up focus code a little, added IPC focus call
authorJohn Hodge <[email protected]>
Sun, 13 Nov 2011 02:02:27 +0000 (10:02 +0800)
committerJohn Hodge <[email protected]>
Sun, 13 Nov 2011 02:02:27 +0000 (10:02 +0800)
Usermode/Applications/axwin3_src/WM/include/wm.h
Usermode/Applications/axwin3_src/WM/ipc.c
Usermode/Applications/axwin3_src/WM/renderer_menu.c
Usermode/Applications/axwin3_src/WM/wm.c
Usermode/Applications/axwin3_src/WM/wm_input.c
Usermode/Applications/axwin3_src/include/ipcmessages.h
Usermode/Applications/axwin3_src/libaxwin3.so_src/r_menu.c
Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c
Usermode/include/axwin3/axwin.h

index 35e7e21..d6fd3ad 100644 (file)
@@ -41,12 +41,12 @@ typedef struct sIPC_Client  tIPC_Client;
 // --- Management
 extern tWindow *WM_CreateWindow(tWindow *Parent, tIPC_Client *Client, uint32_t ID, int Flags, const char *Renderer);
 extern void    WM_Invalidate(tWindow *Window);
+extern void    WM_FocusWindow(tWindow *Destination);
+extern void    WM_RaiseWindow(tWindow *Window);
 extern void    WM_ShowWindow(tWindow *Window, int bShow);
 extern int     WM_ResizeWindow(tWindow *Window, int W, int H);
 extern int     WM_MoveWindow(tWindow *Window, int X, int Y);
 extern int     WM_SendMessage(tWindow *Source, tWindow *Dest, int MessageID, int Length, void *Data);
-extern void    WM_GiveFocus(tWindow *Destination);
-extern void    WM_RaiseWindow(tWindow *Window);
 // --- Rendering
 extern void    WM_Render_FillRect(tWindow *Window, int X, int Y, int W, int H, tColour Colour);
 extern void    WM_Render_DrawRect(tWindow *Window, int X, int Y, int W, int H, tColour Colour);
index da56149..ffad8e5 100644 (file)
@@ -12,6 +12,7 @@
 #include <ipcmessages.h>
 #include <stdio.h>
 #include <wm.h>
+#include <wm_internals.h>
 
 #define AXWIN_PORT     4101
 
@@ -37,6 +38,8 @@ struct sIPC_Client
        tWindow **Windows;
 };
 
+// === IMPORTS ===
+extern tWindow *gpWM_FocusedWindow;    // Needed for _FocusWindow
 
 // === PROTOTYPES ===
 void   IPC_Init(void);
@@ -277,6 +280,22 @@ int IPC_Msg_SendMsg(tIPC_Client *Client, tAxWin_IPCMessage *Msg)
        return 0;
 }
 
+int IPC_Msg_FocusWindow(tIPC_Client *Client, tAxWin_IPCMessage *Msg)
+{
+       tWindow *win;
+
+       // Don't allow the focus to be changed unless the client has the focus
+       if(!gpWM_FocusedWindow) return 1;
+       if(gpWM_FocusedWindow->Client != Client)        return 1;
+
+       win = IPC_int_GetWindow(Client, Msg->Window);
+       if(!win)        return 1;
+
+       WM_FocusWindow(win);
+
+       return 0;
+}
+
 int IPC_Msg_CreateWin(tIPC_Client *Client, tAxWin_IPCMessage *Msg)
 {
        tIPCMsg_CreateWin       *info = (void*)Msg->Data;
@@ -455,6 +474,11 @@ void IPC_Handle(const tIPC_Type *IPCType, const void *Ident, size_t MsgLen, tAxW
                _SysDebug(" IPC_Handle: IPCMSG_CREATEWIN");
                rv = IPC_Msg_CreateWin(client, Msg);
                break;
+       // --- Give a window focus
+       case IPCMSG_FOCUSWINDOW:
+               _SysDebug(" IPC_Handle: IPCMSG_FOCUSWINDOW");
+               rv = IPC_Msg_FocusWindow(client, Msg);
+               break;
        // --- Show/Hide a window
        case IPCMSG_SHOWWINDOW:
                _SysDebug(" IPC_Handle: IPCMSG_SHOWWINDOW");
index b70016d..7d07c93 100644 (file)
@@ -170,7 +170,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
                                );
@@ -301,6 +301,7 @@ int Renderer_Menu_int_AddItem(tWindow *Window, int Length, void *Data)
                        + ciMenu_Gap + info->MaxShortcutWidth
                        + ciMenu_RightPadding;
                // TODO: Smarter height?
+               //  Doesn't matter a lot here really
                WM_ResizeWindow(Window, info->CachedW, info->nItems*ciMenu_ItemHeight);
        }
        
@@ -320,7 +321,7 @@ int Renderer_Menu_int_GetItemByPos(tWindow *Window, tMenuWindowInfo *Info, int X
                        
                if( !Info->Items[i]->Label )
                {
-                       // Spacer - doesn't hilight
+                       // Spacer - not selectable
                        if(Y < ciMenu_SpacerHeight) {
                                return -1;
                        }
@@ -328,7 +329,7 @@ int Renderer_Menu_int_GetItemByPos(tWindow *Window, tMenuWindowInfo *Info, int X
                }
                else
                {
-                       // Normal item, set the hilight
+                       // Normal item, can be selected/hilighted
                        if(Y < ciMenu_ItemHeight) {
                                return i;
                        }
@@ -346,10 +347,12 @@ int Renderer_Menu_HandleMessage(tWindow *Window, int Msg, int Length, void *Data
        case WNDMSG_SHOW: {
                struct sWndMsg_Bool     *msg = Data;
                if(Length < sizeof(*msg))       return -1;
-               if(msg->Val) {
-                       // Take focus?
-                       _SysDebug(" - Shown, take focus");
-                       WM_GiveFocus(Window);
+               if(msg->Val)
+               {
+//                     _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
                {
index 38bbbf3..17540a8 100644 (file)
@@ -18,6 +18,8 @@ extern void   IPC_SendWMMessage(tIPC_Client *Client, uint32_t Src, uint32_t Dst, i
 // === GLOBALS ===
 tWMRenderer    *gpWM_Renderers;
 tWindow        *gpWM_RootWindow;
+//! Window which will recieve the next keyboard event
+tWindow        *gpWM_FocusedWindow;
 
 // === CODE ===
 void WM_Initialise(void)
@@ -116,18 +118,42 @@ void WM_RaiseWindow(tWindow *Window)
        parent->LastChild = Window;
 }
 
+void WM_FocusWindow(tWindow *Destination)
+{
+       struct sWndMsg_Bool     _msg;
+       
+       if( gpWM_FocusedWindow == Destination )
+               return ;
+       if( Destination && !(Destination->Flags & WINFLAG_SHOW) )
+               return ;
+       
+       _msg.Val = 0;
+       WM_SendMessage(NULL, gpWM_FocusedWindow, WNDMSG_FOCUS, sizeof(_msg), &_msg);
+       _msg.Val = 1;
+       WM_SendMessage(NULL, Destination, WNDMSG_FOCUS, sizeof(_msg), &_msg);
+       
+       gpWM_FocusedWindow = Destination;
+}
+
+
 void WM_ShowWindow(tWindow *Window, int bShow)
 {
        // Message window
        struct sWndMsg_Bool     _msg;
        
+       if( !!(Window->Flags & WINFLAG_SHOW) == bShow )
+               return ;
+
        _msg.Val = !!bShow;
        WM_SendMessage(NULL, Window, WNDMSG_SHOW, sizeof(_msg), &_msg);
        
        if(bShow)
                Window->Flags |= WINFLAG_SHOW;
-       else
+       else {
                Window->Flags &= ~WINFLAG_SHOW;
+               if( Window == gpWM_FocusedWindow )
+                       WM_FocusWindow(Window->Parent);
+       }
        WM_Invalidate(Window);
 }
 
index af258ff..66088f9 100644 (file)
@@ -15,8 +15,6 @@
 extern tWindow *gpWM_RootWindow;
 
 // === GLOBALS ===
-//! Window which will recieve the next keyboard event
-tWindow        *gpWM_FocusedWindow;
 //! Window in which the mouse button was originally pressed
 tWindow        *gpWM_DownStartWindow[MAX_BUTTONS];
 
@@ -93,7 +91,7 @@ void WM_Input_MouseButton(int X, int Y, int ButtonIndex, int Pressed)
        if( ButtonIndex == 0 && Pressed == 1 )
        {
                _SysDebug("Gave focus to %p", win);
-               WM_GiveFocus(win);
+               WM_FocusWindow(win);
                WM_RaiseWindow(win);
        }
 
@@ -112,19 +110,3 @@ void WM_Input_MouseButton(int X, int Y, int ButtonIndex, int Pressed)
        WM_Input_int_SendBtnMsg(win, X, Y, ButtonIndex, Pressed);
 }
 
-// --- Manipulation Functions ---
-void WM_GiveFocus(tWindow *Destination)
-{
-       struct sWndMsg_Bool     _msg;
-       
-       if( gpWM_FocusedWindow == Destination )
-               return ;
-       
-       _msg.Val = 0;
-       WM_SendMessage(NULL, gpWM_FocusedWindow, WNDMSG_FOCUS, sizeof(_msg), &_msg);
-       _msg.Val = 1;
-       WM_SendMessage(NULL, Destination, WNDMSG_FOCUS, sizeof(_msg), &_msg);
-       
-       gpWM_FocusedWindow = Destination;
-}
-
index 3f695ce..a3fda63 100644 (file)
@@ -96,6 +96,7 @@ enum eAxWin_IPCMessageTypes
        IPCMSG_CREATEWIN,       //!< Create a window
        IPCMSG_DESTROYWIN,      //!< Destroy a window
        IPCMSG_SHOWWINDOW,      //!< Show/Hide a window
+       IPCMSG_FOCUSWINDOW,     //!< Give a window focus (no data)
        IPCMSG_SETWINPOS,       //!< Set a window position
 };
 
index 78fa169..1a6bfdf 100644 (file)
@@ -67,6 +67,7 @@ void AxWin3_Menu_ShowAt(tHWND Menu, int X, int Y)
 {
        AxWin3_MoveWindow(Menu, X, Y);
        AxWin3_ShowWindow(Menu, 1);
+       AxWin3_FocusWindow(Menu);
 }
 
 tAxWin3_MenuItem *AxWin3_Menu_AddItem(
index a03aa9a..d64bcbc 100644 (file)
@@ -54,7 +54,7 @@ tWindow *AxWin3_int_GetWindowFromID(uint32_t ServerID)
 tWindow *AxWin3_int_AllocateWindowInfo(int DataBytes, int *WinID)
 {
         int    idx, newWinID;
-       tWindowBlock *block, *prev;
+       tWindowBlock *block, *prev = NULL;
        tWindow *ret;   
 
        block = &gAxWin3_WindowList;
@@ -212,6 +212,16 @@ void AxWin3_SendMessage(tHWND Window, tHWND Destination, int Message, int Length
        free(msg);
 }
 
+void AxWin3_FocusWindow(tHWND Window)
+{
+       tAxWin_IPCMessage       *msg;
+       
+       msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_FOCUSWINDOW, 0, 0);
+       
+       AxWin3_int_SendIPCMessage(msg);
+       free(msg);
+}
+
 void AxWin3_ShowWindow(tHWND Window, int bShow)
 {
        tAxWin_IPCMessage       *msg;
index 4ad955d..07bfe04 100644 (file)
@@ -49,6 +49,7 @@ extern void   AxWin3_DestroyWindow(tHWND Window);
 
 // --- Core window management functions
 extern void    AxWin3_SendMessage(tHWND Window, tHWND Dest, int Message, int Length, void *Data);
+extern void    AxWin3_FocusWindow(tHWND Window);
 extern void    AxWin3_ShowWindow(tHWND Window, int bShow);
 extern void    AxWin3_SetWindowPos(tHWND Window, short X, short Y, short W, short H);
 extern void    AxWin3_MoveWindow(tHWND Window, short X, short Y);

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