src/events/SDL_windowevents.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 19 Sep 2009 06:43:45 +0000
changeset 3269 a67a961e2171
parent 2875 91a7e08cd238
child 3502 98a819296cdc
permissions -rw-r--r--
Removed outdated OS/2 support
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2009 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 /* Window event handling code for SDL */
    25 
    26 #include "SDL_events.h"
    27 #include "SDL_events_c.h"
    28 #include "SDL_mouse_c.h"
    29 #include "../video/SDL_sysvideo.h"
    30 
    31 int
    32 SDL_SendWindowEvent(SDL_WindowID windowID, Uint8 windowevent, int data1,
    33                     int data2)
    34 {
    35     int posted;
    36     SDL_Window *window;
    37 
    38     window = SDL_GetWindowFromID(windowID);
    39     if (!window) {
    40         return 0;
    41     }
    42     switch (windowevent) {
    43     case SDL_WINDOWEVENT_SHOWN:
    44         if (window->flags & SDL_WINDOW_SHOWN) {
    45             return 0;
    46         }
    47         window->flags |= SDL_WINDOW_SHOWN;
    48         SDL_OnWindowShown(window);
    49         break;
    50     case SDL_WINDOWEVENT_HIDDEN:
    51         if (!(window->flags & SDL_WINDOW_SHOWN)) {
    52             return 0;
    53         }
    54         window->flags &= ~SDL_WINDOW_SHOWN;
    55         SDL_OnWindowHidden(window);
    56         break;
    57     case SDL_WINDOWEVENT_MOVED:
    58         if (window->flags & SDL_WINDOW_FULLSCREEN) {
    59             return 0;
    60         }
    61         if (data1 == SDL_WINDOWPOS_UNDEFINED) {
    62             data1 = window->x;
    63         }
    64         if (data2 == SDL_WINDOWPOS_UNDEFINED) {
    65             data2 = window->y;
    66         }
    67         if (data1 == window->x && data2 == window->y) {
    68             return 0;
    69         }
    70         window->x = data1;
    71         window->y = data2;
    72         break;
    73     case SDL_WINDOWEVENT_RESIZED:
    74         if (window->flags & SDL_WINDOW_FULLSCREEN) {
    75             return 0;
    76         }
    77         if (data1 == window->w && data2 == window->h) {
    78             return 0;
    79         }
    80         window->w = data1;
    81         window->h = data2;
    82         SDL_OnWindowResized(window);
    83         break;
    84     case SDL_WINDOWEVENT_MINIMIZED:
    85         if (window->flags & SDL_WINDOW_MINIMIZED) {
    86             return 0;
    87         }
    88         window->flags |= SDL_WINDOW_MINIMIZED;
    89         break;
    90     case SDL_WINDOWEVENT_MAXIMIZED:
    91         if (window->flags & SDL_WINDOW_MAXIMIZED) {
    92             return 0;
    93         }
    94         window->flags |= SDL_WINDOW_MAXIMIZED;
    95         break;
    96     case SDL_WINDOWEVENT_RESTORED:
    97         if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
    98             return 0;
    99         }
   100         window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
   101         break;
   102     case SDL_WINDOWEVENT_ENTER:
   103         if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
   104             return 0;
   105         }
   106         window->flags |= SDL_WINDOW_MOUSE_FOCUS;
   107         break;
   108     case SDL_WINDOWEVENT_LEAVE:
   109         if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
   110             return 0;
   111         }
   112         window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
   113         break;
   114     case SDL_WINDOWEVENT_FOCUS_GAINED:
   115         if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
   116             return 0;
   117         }
   118         window->flags |= SDL_WINDOW_INPUT_FOCUS;
   119         SDL_OnWindowFocusGained(window);
   120         break;
   121     case SDL_WINDOWEVENT_FOCUS_LOST:
   122         if (!(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
   123             return 0;
   124         }
   125         window->flags &= ~SDL_WINDOW_INPUT_FOCUS;
   126         SDL_OnWindowFocusLost(window);
   127         break;
   128     }
   129 
   130     /* Post the event, if desired */
   131     posted = 0;
   132     if (SDL_ProcessEvents[SDL_WINDOWEVENT] == SDL_ENABLE) {
   133         SDL_Event event;
   134         event.type = SDL_WINDOWEVENT;
   135         event.window.event = windowevent;
   136         event.window.data1 = data1;
   137         event.window.data2 = data2;
   138         event.window.windowID = windowID;
   139         posted = (SDL_PushEvent(&event) > 0);
   140     }
   141     return (posted);
   142 }
   143 
   144 /* vi: set ts=4 sw=4 expandtab: */