Usermode/AxWin3 - Fixed error with relative windows and input
[tpg/acess2.git] / Usermode / Applications / axwin3_src / WM / wm_input.c
index af258ff..858862b 100644 (file)
@@ -8,22 +8,22 @@
 #include <common.h>
 #include <wm_internals.h>
 #include <wm_messages.h>
+#include <wm_hotkeys.h>
 
 #define MAX_BUTTONS    3
 
 // === IMPORTS ===
 extern tWindow *gpWM_RootWindow;
+extern tWindow *gpWM_FocusedWindow;
 
 // === 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];
 
 // === CODE ===
 tWindow *WM_int_GetWindowAtPos(int X, int Y)
 {
-       tWindow *win, *next_win, *ret;
+       tWindow *win, *next_win, *ret = NULL;
        
        next_win = gpWM_RootWindow;
 
@@ -34,8 +34,8 @@ tWindow *WM_int_GetWindowAtPos(int X, int Y)
                for(win = ret->FirstChild; win; win = win->NextSibling)
                {
                        if( !(win->Flags & WINFLAG_SHOW) )      continue ;
-                       if( X < win->X || X >= win->X + win->W )        continue;
-                       if( Y < win->Y || Y >= win->Y + win->H )        continue;
+                       if( X < win->RealX || X >= win->RealX + win->RealW )    continue;
+                       if( Y < win->RealY || Y >= win->RealY + win->RealH )    continue;
                        next_win = win; // Overwrite as we want the final rendered window
                }
        }
@@ -49,8 +49,8 @@ void WM_Input_MouseMoved(int OldX, int OldY, int NewX, int NewY)
        struct sWndMsg_MouseMove        msg;
        
        win = WM_int_GetWindowAtPos(OldX, OldY);
-       msg.X = NewX - win->X;
-       msg.Y = NewY - win->Y;
+       msg.X = NewX - win->RealX - win->BorderL;
+       msg.Y = NewY - win->RealY - win->BorderT;
        msg.dX = NewX - OldX;
        msg.dY = NewY - OldY;
        WM_SendMessage(NULL, win, WNDMSG_MOUSEMOVE, sizeof(msg), &msg);
@@ -64,19 +64,19 @@ void WM_Input_MouseMoved(int OldX, int OldY, int NewX, int NewY)
        // TODO: Send mouseup to match mousedown if the cursor moves out of a window?
 
        win = newWin;
-       msg.X = NewX - win->X;
-       msg.Y = NewY - win->Y;
+       msg.X = NewX - win->RealX - win->BorderL;
+       msg.Y = NewY - win->RealY - win->BorderT;
        msg.dX = NewX - OldX;
        msg.dY = NewY - OldY;
        WM_SendMessage(NULL, win, WNDMSG_MOUSEMOVE, sizeof(msg), &msg);
 }
 
-inline void WM_Input_int_SendBtnMsg(tWindow *Win, int X, int Y, int Index, int Pressed)
+void WM_Input_int_SendBtnMsg(tWindow *Win, int X, int Y, int Index, int Pressed)
 {
        struct sWndMsg_MouseButton      msg;    
 
-       msg.X = X - Win->X;
-       msg.Y = Y - Win->Y;
+       msg.X = X - Win->RealX - Win->BorderL;
+       msg.Y = Y - Win->RealY - Win->BorderT;
        msg.Button = Index;
        msg.bPressed = !!Pressed;
        
@@ -92,9 +92,14 @@ void WM_Input_MouseButton(int X, int Y, int ButtonIndex, int Pressed)
        // Handle press of primary button to change focus
        if( ButtonIndex == 0 && Pressed == 1 )
        {
-               _SysDebug("Gave focus to %p", win);
-               WM_GiveFocus(win);
-               WM_RaiseWindow(win);
+//             _SysDebug("Gave focus to %p", win);
+               WM_FocusWindow(win);
+               tWindow *tmpwin = win;
+               while( tmpwin )
+               {
+                       WM_RaiseWindow(tmpwin);
+                       tmpwin = tmpwin->Parent;
+               }
        }
 
        // Make sure that even if the mouse has moved out of the original window,
@@ -112,19 +117,36 @@ 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)
+void WM_Input_KeyDown(uint32_t Character, uint32_t Scancode)
 {
-       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;
+       struct sWndMsg_KeyAction        msg;
+
+       WM_Hotkey_KeyDown(Scancode);
+
+       msg.KeySym = Scancode;
+       msg.UCS32 = Character;
+       WM_SendMessage(NULL, gpWM_FocusedWindow, WNDMSG_KEYDOWN, sizeof(msg), &msg);
+}
+
+void WM_Input_KeyFire(uint32_t Character, uint32_t Scancode)
+{
+       struct sWndMsg_KeyAction        msg;
+
+       // TODO: Properly translate into KeySyms and Unicode
+
+       msg.KeySym = Scancode;
+       msg.UCS32 = Character;
+       WM_SendMessage(NULL, gpWM_FocusedWindow, WNDMSG_KEYFIRE, sizeof(msg), &msg);
+}
+
+void WM_Input_KeyUp(uint32_t Character, uint32_t Scancode)
+{
+       struct sWndMsg_KeyAction        msg;
+
+       WM_Hotkey_KeyUp(Scancode);
+
+       msg.KeySym = Scancode;
+       msg.UCS32 = Character;
+       WM_SendMessage(NULL, gpWM_FocusedWindow, WNDMSG_KEYUP, sizeof(msg), &msg);
 }
 

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