1 // ============================================================== 2 // This file is part of Glest Shared Library (www.glest.org) 3 // 4 // Copyright (C) 2001-2008 Marti�o Figueroa 5 // 6 // You can redistribute this code and/or modify it under 7 // the terms of the GNU General Public License as published 8 // by the Free Software Foundation; either version 2 of the 9 // License, or (at your option) any later version 10 // ============================================================== 11 12 #ifndef _SHARED_PLATFORM_WINDOW_H_ 13 #define _SHARED_PLATFORM_WINDOW_H_ 14 15 #include <map> 16 #include <string> 17 18 #include "types.h" 19 #include "platform_menu.h" 20 21 using std::map; 22 using std::string; 23 24 namespace Shared{ namespace Platform{ 25 26 class Timer; 27 class PlatformContextGl; 28 29 enum MouseButton{ 30 mbLeft, 31 mbRight, 32 mbCenter 33 }; 34 35 enum SizeState{ 36 ssMaximized, 37 ssMinimized, 38 ssRestored 39 }; 40 41 const int vkAdd= VK_ADD; 42 const int vkSubtract= VK_SUBTRACT; 43 const int vkAlt= VK_MENU; 44 const int vkControl= VK_CONTROL; 45 const int vkShift= VK_SHIFT; 46 const int vkEscape= VK_ESCAPE; 47 const int vkUp= VK_UP; 48 const int vkLeft= VK_LEFT; 49 const int vkRight= VK_RIGHT; 50 const int vkDown= VK_DOWN; 51 const int vkReturn= VK_RETURN; 52 const int vkBack= VK_BACK; 53 const int vkDelete= VK_DELETE; 54 const int vkF1= VK_F1; 55 56 struct MouseState{ 57 bool leftMouse; 58 bool rightMouse; 59 bool centerMouse; 60 }; 61 62 enum WindowStyle{ 63 wsFullscreen, 64 wsWindowedFixed, 65 wsWindowedResizeable 66 }; 67 68 // ===================================================== 69 // class Window 70 // ===================================================== 71 72 class Window{ 73 private: 74 typedef map<WindowHandle, Window*> WindowMap; 75 76 private: 77 static const DWORD fullscreenStyle; 78 static const DWORD windowedFixedStyle; 79 static const DWORD windowedResizeableStyle; 80 81 static int nextClassName; 82 static WindowMap createdWindows; 83 84 protected: 85 WindowHandle handle; 86 WindowStyle windowStyle; 87 string text; 88 int x; 89 int y; 90 int w; 91 int h; 92 string className; 93 DWORD style; 94 DWORD exStyle; 95 bool ownDc; 96 97 public: 98 static bool handleEvent(); 99 100 //contructor & destructor 101 Window(); 102 virtual ~Window(); 103 getHandle()104 WindowHandle getHandle() {return handle;} 105 string getText(); getX()106 int getX() {return x;} getY()107 int getY() {return y;} getW()108 int getW() {return w;} getH()109 int getH() {return h;} 110 111 //component state 112 int getClientW(); 113 int getClientH(); 114 float getAspect(); 115 116 //object state 117 void setText(string text); 118 void setStyle(WindowStyle windowStyle); 119 void setSize(int w, int h); 120 void setPos(int x, int y); 121 void setEnabled(bool enabled); 122 void setVisible(bool visible); 123 124 //misc 125 void create(); 126 void minimize(); 127 void maximize(); 128 void restore(); 129 void showPopupMenu(Menu *menu, int x, int y); 130 void destroy(); 131 132 protected: eventCreate()133 virtual void eventCreate(){} eventMouseDown(int x,int y,MouseButton mouseButton)134 virtual void eventMouseDown(int x, int y, MouseButton mouseButton){} eventMouseUp(int x,int y,MouseButton mouseButton)135 virtual void eventMouseUp(int x, int y, MouseButton mouseButton){} eventMouseMove(int x,int y,const MouseState * mouseState)136 virtual void eventMouseMove(int x, int y, const MouseState *mouseState){} eventMouseDoubleClick(int x,int y,MouseButton mouseButton)137 virtual void eventMouseDoubleClick(int x, int y, MouseButton mouseButton){} eventKeyDown(char key)138 virtual void eventKeyDown(char key){} eventKeyUp(char key)139 virtual void eventKeyUp(char key){} eventKeyPress(char c)140 virtual void eventKeyPress(char c){}; eventResize()141 virtual void eventResize(){}; eventPaint()142 virtual void eventPaint(){} eventActivate(bool activated)143 virtual void eventActivate(bool activated){}; eventResize(SizeState sizeState)144 virtual void eventResize(SizeState sizeState){}; eventMenu(int menuId)145 virtual void eventMenu(int menuId){} eventClose()146 virtual void eventClose(){}; eventDestroy()147 virtual void eventDestroy(){}; 148 149 private: 150 static LRESULT CALLBACK eventRouter(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); 151 static int getNextClassName(); 152 void registerWindow(WNDPROC wndProc= NULL); 153 void createWindow(LPVOID creationData= NULL); 154 }; 155 156 }}//end namespace 157 158 #endif 159