1 /* ************************************************************************* 2 devicewin.hpp - M$ windows device 3 ------------------- 4 begin : July 22 2002 5 copyright : (C) 2002 by Marc Schellens 6 email : m_schellens@users.sf.net 7 ***************************************************************************/ 8 9 /* ************************************************************************* 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #ifndef DEVICEWIN_HPP_ 19 #define DEVICEWIN_HPP_ 20 #ifdef _WIN32 21 22 #include <algorithm> 23 #include <vector> 24 #include <cstring> 25 26 #include <plplot/drivers.h> 27 28 #include "graphicsdevice.hpp" 29 #include "datatypes.hpp" 30 #include "initsysvar.hpp" 31 #include "gdlexception.hpp" 32 33 34 //defined in graphicsdevice.hpp 35 //#define MAX_WIN 32 //IDL free and widgets start at 33 ... 36 //#define MAX_WIN_RESERVE 256 37 38 class DeviceWIN : public GraphicsDevice 39 { 40 private: 41 static LRESULT CALLBACK _CallWndProc(int, WPARAM, LPARAM); 42 static LRESULT CALLBACK _GetMsgProc(int, WPARAM, LPARAM); 43 LRESULT CallWndProc(int, WPARAM, LPARAM); 44 LRESULT GetMsgProc(int, WPARAM, LPARAM); 45 bool ProcessMessages(HWND, UINT, WPARAM, LPARAM); 46 47 std::vector<GDLGStream*> winList; 48 std::vector<long> oList; 49 long oIx; 50 int actWin; 51 int decomposed; // false -> use color table 52 53 54 int cursorId; //should be 3 by default. 55 long gcFunction; 56 int backingStoreMode; 57 58 59 void EventHandler(); 60 61 bool WDelete(int); 62 bool WOpen(int, const std::string&, 63 int, int, int, int, bool); 64 bool WState(int); 65 bool WSize(int, int*, int*); 66 bool WSet(int); 67 bool WShow(int, bool, int); 68 int WAdd(); 69 DIntGDL* GetWindowPosition(); 70 DLong GetVisualDepth(); 71 DString GetVisualName(); 72 //This function is reserved to device Z, should not exist for WIN! 73 // DLong GetPixelDepth(); 74 DByteGDL* WindowState(); 75 bool UnsetFocus(); 76 int MaxWin(); 77 int ActWin(); 78 void DefaultXYSize(DLong *xSize, DLong *ySize); 79 bool Decomposed(bool value); 80 DLong GetDecomposed(); 81 void MaxXYSize(DLong *xSize, DLong *ySize); 82 DLongGDL* GetScreenSize(char* disp = NULL); 83 DDoubleGDL* GetScreenResolution(char* disp = NULL); 84 SetActWin(int wIx)85 void SetActWin(int wIx) 86 { 87 // update !D 88 if (wIx >= 0 && wIx < winList.size()) { // window size and pos 89 long xsize, ysize; 90 winList[wIx]->GetGeometry(xsize, ysize); 91 92 (*static_cast<DLongGDL*>(dStruct->GetTag(xSTag)))[0] = xsize; 93 (*static_cast<DLongGDL*>(dStruct->GetTag(ySTag)))[0] = ysize; 94 (*static_cast<DLongGDL*>(dStruct->GetTag(xVSTag)))[0] = xsize; 95 (*static_cast<DLongGDL*>(dStruct->GetTag(yVSTag)))[0] = ysize; 96 winList[wIx]->CheckValid(); // runs an IsWindow(hwnd) check 97 } 98 99 // window number 100 (*static_cast<DLongGDL*>(dStruct->GetTag(wTag)))[0] = wIx; 101 102 actWin = wIx; 103 } 104 105 // process user deleted windows 106 void TidyWindowsList(); 107 108 public: DeviceWIN(std::string name_="WIN")109 DeviceWIN(std::string name_="WIN") : GraphicsDevice(), oIx(1), actWin(-1), decomposed(-1) 110 { 111 name = name_; 112 113 DLongGDL origin(dimension(2)); 114 DLongGDL zoom(dimension(2)); 115 zoom[0] = 1; 116 zoom[1] = 1; 117 118 dStruct = new DStructGDL("!DEVICE"); 119 dStruct->InitTag("NAME", DStringGDL(name)); 120 dStruct->InitTag("X_SIZE", DLongGDL(640)); 121 dStruct->InitTag("Y_SIZE", DLongGDL(512)); 122 dStruct->InitTag("X_VSIZE", DLongGDL(640)); 123 dStruct->InitTag("Y_VSIZE", DLongGDL(512)); 124 dStruct->InitTag("X_CH_SIZE", DLongGDL(9)); 125 dStruct->InitTag("Y_CH_SIZE", DLongGDL(12)); 126 dStruct->InitTag("X_PX_CM", DFloatGDL(40.0)); 127 dStruct->InitTag("Y_PX_CM", DFloatGDL(40.0)); 128 dStruct->InitTag("N_COLORS", DLongGDL(256)); 129 dStruct->InitTag("TABLE_SIZE", DLongGDL(ctSize)); 130 dStruct->InitTag("FILL_DIST", DLongGDL(0)); 131 dStruct->InitTag("WINDOW", DLongGDL(-1)); 132 dStruct->InitTag("UNIT", DLongGDL(0)); 133 dStruct->InitTag("FLAGS", DLongGDL(328124)); 134 dStruct->InitTag("ORIGIN", origin); 135 dStruct->InitTag("ZOOM", zoom); 136 137 winList.reserve(MAX_WIN_RESERVE); 138 winList.resize(MAX_WIN); 139 for (int i = 0; i < MAX_WIN; i++) winList[i] = NULL; 140 oList.reserve(MAX_WIN_RESERVE); 141 oList.resize(MAX_WIN); 142 for (int i = 0; i < MAX_WIN; i++) oList[i] = 0; 143 } 144 ~DeviceWIN()145 ~DeviceWIN() 146 { 147 std::vector<GDLGStream*>::iterator i; 148 for (i = winList.begin(); i != winList.end(); ++i) 149 { 150 delete *i; /* *i = NULL;*/ 151 } 152 } 153 GetStreamAt(int wIx) const154 GDLGStream* GetStreamAt(int wIx) const 155 { 156 return winList[wIx]; 157 } 158 159 160 161 // should check for valid streams GetStream(bool open=true)162 GDLGStream* GetStream(bool open = true) 163 { 164 TidyWindowsList(); 165 if (actWin == -1) { 166 if (!open) return NULL; 167 168 DString title = "GDL 0"; 169 DLong xSize, ySize; 170 DefaultXYSize(&xSize, &ySize); 171 172 bool success = WOpen(0, title, xSize, ySize, -1, -1, false); 173 if (!success) return NULL; 174 if (actWin == -1) { 175 std::cerr << "Internal error: plstream not set." << std::endl; 176 exit(EXIT_FAILURE); 177 } 178 } 179 return winList[actWin]; 180 } 181 #ifdef HAVE_LIBWXWIDGETS 182 bool GUIOpen(int wIx, int xSize, int ySize); 183 #endif 184 RaiseWin(int wIx)185 void RaiseWin(int wIx) 186 { 187 if (wIx >= 0 && wIx < winList.size()) winList[wIx]->Raise(); 188 } 189 LowerWin(int wIx)190 void LowerWin(int wIx) 191 { 192 if (wIx >= 0 && wIx < winList.size()) winList[wIx]->Lower(); 193 } 194 IconicWin(int wIx)195 void IconicWin(int wIx) 196 { 197 if (wIx >= 0 && wIx < winList.size()) winList[wIx]->Iconic(); 198 } DeIconicWin(int wIx)199 void DeIconicWin(int wIx) 200 { 201 if (wIx >= 0 && wIx < winList.size()) winList[wIx]->DeIconic(); 202 } 203 204 }; 205 //#undef MAX_WIN 206 //#undef MAX_WIN_RESERVE 207 #endif 208 #endif 209