Window.cpp 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411
  1. #include "Window.h"
  2. #include "AlphaField.h"
  3. #include "Border.h"
  4. #include "Globals.h"
  5. #include "Image.h"
  6. #include "KeyboardEvent.h"
  7. #include "MouseEvent.h"
  8. #include "Screen.h"
  9. #include "Scroll.h"
  10. #include "Text.h"
  11. #include "TextField.h"
  12. #include "ToolTip.h"
  13. #ifdef WIN32
  14. # include "Mouse.h"
  15. #endif
  16. #include <iostream>
  17. #include "Logging.h"
  18. #include "Timer.h"
  19. using namespace Framework;
  20. #ifdef WIN32
  21. // Create window class
  22. WNDCLASS Framework::F_Normal(HINSTANCE hInst) // Creates a normal window class
  23. {
  24. if (!hInst) hInst = _hinst;
  25. WNDCLASS ret;
  26. ret.cbClsExtra = 0;
  27. ret.cbWndExtra = 0;
  28. ret.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  29. ret.hCursor = LoadCursor(NULL, IDC_ARROW);
  30. ret.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  31. ret.hInstance = hInst;
  32. ret.lpszMenuName = "";
  33. ret.lpfnWndProc = WindowProc;
  34. ret.style = CS_HREDRAW | CS_VREDRAW;
  35. return ret;
  36. }
  37. WNDCLASSEX Framework::F_NormalEx(HINSTANCE hInst)
  38. {
  39. if (!hInst) hInst = _hinst;
  40. WNDCLASSEX ret;
  41. ret.cbSize = sizeof(WNDCLASSEX);
  42. ret.cbClsExtra = 0;
  43. ret.cbWndExtra = 0;
  44. ret.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  45. ret.hCursor = LoadCursor(NULL, IDC_ARROW);
  46. ret.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  47. ret.hInstance = hInst;
  48. ret.lpszMenuName = "";
  49. ret.lpfnWndProc = WindowProc;
  50. ret.style = CS_HREDRAW | CS_VREDRAW;
  51. ret.hIconSm = 0;
  52. return ret;
  53. }
  54. // WinAPI
  55. LRESULT CALLBACK Framework::WindowProc(
  56. HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
  57. {
  58. setShowCursor(cursorVisible);
  59. if (msgExit) return (DefWindowProc(hwnd, message, wparam, lparam));
  60. switch (message)
  61. {
  62. case WM_SETCURSOR: // Mouse cursor
  63. mousePointer.update();
  64. return 0;
  65. case WM_SIZE: // Window
  66. if (wparam == SIZE_RESTORED) nativeWindows.sendRestoreMessage(hwnd);
  67. break;
  68. case WM_CLOSE: // Close
  69. if (nativeWindows.sendPreCloseMessage(hwnd)) return 0;
  70. break;
  71. case WM_DESTROY:
  72. if (nativeWindows.sendPostCloseMessage(hwnd)) return 0;
  73. break; // Mouse
  74. case WM_LBUTTONDOWN: // Left click
  75. {
  76. MouseState[M_Left] = 1;
  77. MouseEvent me = {ME_PLeft,
  78. (int)LOWORD(lparam),
  79. (int)HIWORD(lparam),
  80. 0,
  81. 1,
  82. (int)LOWORD(lparam),
  83. (int)HIWORD(lparam)};
  84. nativeWindows.sendMouseMessage(hwnd, me);
  85. break;
  86. }
  87. case WM_RBUTTONDOWN: // Right click
  88. {
  89. MouseState[M_Right] = 1;
  90. MouseEvent me = {ME_PRight,
  91. (int)LOWORD(lparam),
  92. (int)HIWORD(lparam),
  93. 0,
  94. 1,
  95. (int)LOWORD(lparam),
  96. (int)HIWORD(lparam)};
  97. nativeWindows.sendMouseMessage(hwnd, me);
  98. break;
  99. }
  100. case WM_MBUTTONDOWN: // Middle click
  101. {
  102. MouseState[M_Middle] = 1;
  103. MouseEvent me = {ME_PMiddle,
  104. (int)LOWORD(lparam),
  105. (int)HIWORD(lparam),
  106. 0,
  107. 1,
  108. (int)LOWORD(lparam),
  109. (int)HIWORD(lparam)};
  110. nativeWindows.sendMouseMessage(hwnd, me);
  111. break;
  112. }
  113. case WM_LBUTTONUP: // Left release
  114. {
  115. MouseState[M_Left] = 0;
  116. MouseEvent me = {ME_RLeft,
  117. (int)LOWORD(lparam),
  118. (int)HIWORD(lparam),
  119. 0,
  120. 1,
  121. (int)LOWORD(lparam),
  122. (int)HIWORD(lparam)};
  123. nativeWindows.sendMouseMessage(hwnd, me);
  124. break;
  125. }
  126. case WM_RBUTTONUP: // Right release
  127. {
  128. MouseState[M_Right] = 0;
  129. MouseEvent me = {ME_RRight,
  130. (int)LOWORD(lparam),
  131. (int)HIWORD(lparam),
  132. 0,
  133. 1,
  134. (int)LOWORD(lparam),
  135. (int)HIWORD(lparam)};
  136. nativeWindows.sendMouseMessage(hwnd, me);
  137. break;
  138. }
  139. case WM_MBUTTONUP: // Middle release
  140. {
  141. MouseState[M_Middle] = 0;
  142. MouseEvent me = {ME_RMiddle,
  143. (int)LOWORD(lparam),
  144. (int)HIWORD(lparam),
  145. 0,
  146. 1,
  147. (int)LOWORD(lparam),
  148. (int)HIWORD(lparam)};
  149. nativeWindows.sendMouseMessage(hwnd, me);
  150. break;
  151. }
  152. case WM_LBUTTONDBLCLK: // Left double click
  153. {
  154. MouseEvent me = {ME_DCLeft,
  155. (int)LOWORD(lparam),
  156. (int)HIWORD(lparam),
  157. 0,
  158. 1,
  159. (int)LOWORD(lparam),
  160. (int)HIWORD(lparam)};
  161. nativeWindows.sendMouseMessage(hwnd, me);
  162. break;
  163. }
  164. case WM_RBUTTONDBLCLK: // Right double click
  165. {
  166. MouseEvent me = {ME_DCRight,
  167. (int)LOWORD(lparam),
  168. (int)HIWORD(lparam),
  169. 0,
  170. 1,
  171. (int)LOWORD(lparam),
  172. (int)HIWORD(lparam)};
  173. nativeWindows.sendMouseMessage(hwnd, me);
  174. break;
  175. }
  176. case WM_MBUTTONDBLCLK: // Middle double click
  177. {
  178. MouseEvent me = {ME_DCMiddle,
  179. (int)LOWORD(lparam),
  180. (int)HIWORD(lparam),
  181. 0,
  182. 1,
  183. (int)LOWORD(lparam),
  184. (int)HIWORD(lparam)};
  185. nativeWindows.sendMouseMessage(hwnd, me);
  186. break;
  187. }
  188. case WM_MOUSEHOVER: // Mouse enters window
  189. {
  190. MouseTrack = 1;
  191. MouseEvent me = {ME_Enter,
  192. (int)LOWORD(lparam),
  193. (int)HIWORD(lparam),
  194. 0,
  195. 1,
  196. (int)LOWORD(lparam),
  197. (int)HIWORD(lparam)};
  198. nativeWindows.sendMouseMessage(hwnd, me);
  199. break;
  200. }
  201. case WM_MOUSELEAVE: // Mouse leaves window
  202. {
  203. MouseTrack = 1;
  204. MouseEvent me = {ME_Leaves,
  205. (int)LOWORD(lparam),
  206. (int)HIWORD(lparam),
  207. 0,
  208. 1,
  209. (int)LOWORD(lparam),
  210. (int)HIWORD(lparam)};
  211. nativeWindows.sendMouseMessage(hwnd, me);
  212. break;
  213. }
  214. case WM_MOUSEMOVE: // Mouse is moving
  215. {
  216. if (MouseTrack)
  217. {
  218. TRACKMOUSEEVENT lptme;
  219. lptme.cbSize = sizeof(TRACKMOUSEEVENT);
  220. lptme.dwFlags = TME_HOVER | TME_LEAVE;
  221. lptme.dwHoverTime = 0;
  222. lptme.hwndTrack = hwnd;
  223. TrackMouseEvent(&lptme);
  224. MouseTrack = 0;
  225. }
  226. MouseEvent me = {ME_Move,
  227. (int)LOWORD(lparam),
  228. (int)HIWORD(lparam),
  229. 0,
  230. 1,
  231. (int)LOWORD(lparam),
  232. (int)HIWORD(lparam)};
  233. nativeWindows.sendMouseMessage(hwnd, me);
  234. break;
  235. }
  236. case WM_MOUSEWHEEL: // Mouse scroll
  237. {
  238. Point pos = getMousePos();
  239. RECT r;
  240. GetWindowRect(hwnd, &r);
  241. pos.x -= r.left;
  242. pos.y -= r.top;
  243. MouseEvent me = {0, pos.x, pos.y, 0, 1, pos.x, pos.y};
  244. if ((int)(short)HIWORD(wparam) < 0)
  245. me.id = !getKeyState(T_Shift) ? ME_DScroll : ME_RScroll;
  246. else
  247. me.id = !getKeyState(T_Shift) ? ME_UScroll : ME_LScroll;
  248. nativeWindows.sendMouseMessage(hwnd, me);
  249. break;
  250. }
  251. // Keyboard
  252. case WM_KEYDOWN:
  253. {
  254. KeyboardEvent te = {
  255. TE_Press, {0, 0, 0},
  256. 0, 0
  257. };
  258. CalculateEnteredString((int)wparam, 0, te);
  259. nativeWindows.sendKeyboardMessage(hwnd, te);
  260. return 0;
  261. } // Key is pressed
  262. case WM_KEYUP:
  263. {
  264. KeyboardEvent te = {
  265. TE_Release, {0, 0, 0},
  266. 0, 0
  267. };
  268. CalculateEnteredString((int)wparam, HIWORD(lparam) & 0xFF, te);
  269. nativeWindows.sendKeyboardMessage(hwnd, te);
  270. return 0;
  271. } // Key is released
  272. }
  273. return (DefWindowProc(hwnd, message, wparam, lparam));
  274. }
  275. void Framework::StartMessageLoop()
  276. {
  277. MSG msg;
  278. Timer tm;
  279. while (GetMessage(&msg, NULL, 0, 0) > 0 && !msgExit)
  280. {
  281. if (!msgExit)
  282. {
  283. tm.measureStart();
  284. TranslateMessage(&msg);
  285. DispatchMessage(&msg);
  286. tm.measureEnd();
  287. if (tm.getSekunden() > 0.1)
  288. {
  289. Logging::warning()
  290. << "Message loop is taking too long: "
  291. << std::to_string(tm.getSekunden()) << " seconds";
  292. }
  293. }
  294. }
  295. msgExit = 0;
  296. }
  297. void Framework::StopMessageLoop(HWND hwnd)
  298. {
  299. msgExit = 1;
  300. PostMessage(hwnd, WM_MOUSELEAVE, 0, 0);
  301. }
  302. void Framework::CalculateEnteredString(
  303. int virtualKeyCode, int scanCode, KeyboardEvent& te)
  304. {
  305. memset(te.key, 0, sizeof(te.key));
  306. te.virtualKey = virtualKeyCode;
  307. # ifdef WIN32
  308. unsigned char keyState[256];
  309. memset(keyState, 0, sizeof(keyState));
  310. if (GetKeyboardState(keyState))
  311. {
  312. unsigned short str[2] = {0, 0};
  313. int count = ToAscii(virtualKeyCode, scanCode, keyState, str, 0);
  314. if (count == 1 && (str[0] & 0xFF) == str[0])
  315. te.key[0] = (unsigned char)str[0];
  316. else if (count == 2 && (str[0] & 0xFF) == str[0]
  317. && (str[1] & 0xFF) == str[1])
  318. te.key[0] = (unsigned char)str[0],
  319. te.key[1] = (unsigned char)str[1];
  320. }
  321. # endif // WIN32
  322. }
  323. // Contents of the NativeWindow class from Window.h
  324. // Constructor
  325. NativeWindow::NativeWindow()
  326. : ReferenceCounter(),
  327. hWnd(0),
  328. style(0),
  329. makParam(0),
  330. sakParam(0),
  331. takParam(0),
  332. mouseAction(0),
  333. preCloseAction(0),
  334. postCloseAction(0),
  335. keyboardAction(0),
  336. screen(0),
  337. mx(-1),
  338. my(-1),
  339. movable(0),
  340. border(0),
  341. bitmap(0),
  342. hdc(0)
  343. {
  344. nativeWindows.addWindow(this);
  345. }
  346. NativeWindow::NativeWindow(HWND hwnd)
  347. : NativeWindow()
  348. {
  349. hWnd = hwnd;
  350. }
  351. // Destructor
  352. NativeWindow::~NativeWindow()
  353. {
  354. if (nativeWindows.removeWindow(this))
  355. {
  356. nativeWindows.del();
  357. }
  358. if (hWnd) destroy();
  359. if (screen) screen->release();
  360. }
  361. // non-constant
  362. void NativeWindow::create(int style, WNDCLASS wc) // Creates a window in Windows
  363. {
  364. if (!GetClassInfo(wc.hInstance, wc.lpszClassName, &wc))
  365. {
  366. # pragma warning(suppress : 6102)
  367. if (!RegisterClass(&wc)) // Register window class
  368. {
  369. MessageBox(hWnd,
  370. "Fehler beim Registrieren der WindowClass!",
  371. "Error",
  372. MB_ICONERROR); // Error message on failure
  373. return;
  374. }
  375. }
  376. hWnd = CreateWindow(wc.lpszClassName,
  377. wc.lpszClassName,
  378. style,
  379. 0,
  380. 0,
  381. 0,
  382. 0,
  383. 0,
  384. 0,
  385. wc.hInstance,
  386. 0); // Create window
  387. if (hWnd == 0)
  388. {
  389. MessageBox(hWnd,
  390. "Fehler beim create des Windows!",
  391. "Error",
  392. MB_ICONERROR); // Error message on failure
  393. return;
  394. }
  395. this->style = style;
  396. }
  397. void NativeWindow::createEx(
  398. int exStyle, int style, WNDCLASSEX wc) // Create the window
  399. {
  400. if (!GetClassInfoEx(wc.hInstance, wc.lpszClassName, &wc))
  401. {
  402. # pragma warning(suppress : 6102)
  403. if (!RegisterClassEx(&wc)) // Register window class
  404. {
  405. MessageBox(hWnd,
  406. "Fehler beim Registrieren der WindowClass!",
  407. "Error",
  408. MB_ICONERROR); // Error message on failure
  409. return;
  410. }
  411. }
  412. hWnd = CreateWindowEx(exStyle,
  413. wc.lpszClassName,
  414. wc.lpszClassName,
  415. style,
  416. 0,
  417. 0,
  418. 0,
  419. 0,
  420. 0,
  421. 0,
  422. wc.hInstance,
  423. 0); // Create window
  424. if (hWnd == 0)
  425. {
  426. MessageBox(hWnd,
  427. "Fehler beim create des Windows!",
  428. "Error",
  429. MB_ICONERROR); // Error message on failure
  430. return;
  431. }
  432. this->style = style;
  433. }
  434. void NativeWindow::setDisplayMode(int mod) // Display window
  435. {
  436. if (border)
  437. {
  438. if (mod == 2)
  439. ShowWindow(border, 0);
  440. else
  441. ShowWindow(border, mod);
  442. }
  443. ShowWindow(hWnd, mod);
  444. }
  445. bool NativeWindow::setFocus() // Sets the focus on the window
  446. {
  447. DWORD dwCurrentThread = GetCurrentThreadId();
  448. DWORD dwFGThread = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
  449. AttachThreadInput(dwCurrentThread, dwFGThread, TRUE);
  450. SetFocus(hWnd);
  451. AttachThreadInput(dwCurrentThread, dwFGThread, FALSE);
  452. SetWindowPos(hWnd,
  453. HWND_TOPMOST,
  454. 0,
  455. 0,
  456. 0,
  457. 0,
  458. SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
  459. SetWindowPos(hWnd,
  460. HWND_NOTOPMOST,
  461. 0,
  462. 0,
  463. 0,
  464. 0,
  465. SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
  466. return GetFocus() == hWnd;
  467. }
  468. void NativeWindow::setPosition(const Point& p) // Window position
  469. {
  470. setPosition(p.x, p.y);
  471. }
  472. void NativeWindow::setPosition(int x, int y)
  473. {
  474. RECT r;
  475. GetWindowRect(hWnd, &r); // Find previous position
  476. RECT res;
  477. res.left = x, res.top = y, res.right = r.right - r.left,
  478. res.bottom = r.bottom - r.top;
  479. AdjustWindowRect(&res, style, 0);
  480. SetWindowPos(hWnd,
  481. 0,
  482. res.left,
  483. res.top,
  484. res.right,
  485. res.bottom,
  486. 0); // Change position
  487. }
  488. void NativeWindow::setSize(Point& g) // Window size
  489. {
  490. RECT r;
  491. GetWindowRect(hWnd, &r); // Find previous size
  492. RECT res;
  493. res.left = r.left, res.top = r.top, res.right = g.x, res.bottom = g.y;
  494. AdjustWindowRect(&res, style, 0);
  495. SetWindowPos(
  496. hWnd, 0, res.left, res.top, res.right, res.bottom, 0); // Change size
  497. }
  498. void NativeWindow::setSize(int Width, int height)
  499. {
  500. RECT r;
  501. GetWindowRect(hWnd, &r); // Find previous size
  502. RECT res;
  503. res.left = r.left, res.top = r.top, res.right = Width, res.bottom = height;
  504. AdjustWindowRect(&res, style, 0);
  505. SetWindowPos(
  506. hWnd, 0, res.left, res.top, res.right, res.bottom, 0); // Change size
  507. }
  508. void NativeWindow::setBounds(
  509. const Point& p, const Point& g) // sets size and position
  510. {
  511. SetWindowPos(hWnd, 0, p.x, p.y, g.x, g.y, 0); // Change size and position
  512. }
  513. void NativeWindow::setScreen(Screen* screen)
  514. {
  515. if (this->screen) this->screen->release();
  516. this->screen = screen;
  517. }
  518. void NativeWindow::destroy()
  519. {
  520. DestroyWindow(hWnd);
  521. hWnd = 0;
  522. if (border) DestroyWindow(border);
  523. border = 0;
  524. if (bitmap) DeleteObject(bitmap);
  525. bitmap = 0;
  526. if (hdc) DeleteDC(hdc);
  527. hdc = 0;
  528. }
  529. void NativeWindow::doMouseAction(MouseEvent& me)
  530. {
  531. if (!mouseAction || !mouseAction(makParam, this, me)) return;
  532. if (screen && me.id != ME_Enter && me.id != ME_Leaves)
  533. {
  534. screen->doMouseEvent(me);
  535. if (!me.processed && movable)
  536. {
  537. if (mx != -1 && my != -1) // move
  538. {
  539. RECT r;
  540. if (border)
  541. {
  542. GetWindowRect(border, &r);
  543. r.right -= r.left, r.bottom -= r.top;
  544. r.left += me.mx - mx;
  545. r.top += me.my - my;
  546. SetWindowPos(border,
  547. 0,
  548. r.left,
  549. r.top,
  550. r.right,
  551. r.bottom,
  552. 0); // Set position
  553. }
  554. GetWindowRect(hWnd, &r); // Find previous position
  555. r.right -= r.left, r.bottom -= r.top; // Update position
  556. r.left += me.mx - mx;
  557. r.top += me.my - my;
  558. SetWindowPos(hWnd,
  559. 0,
  560. r.left,
  561. r.top,
  562. r.right,
  563. r.bottom,
  564. 0); // Set position
  565. }
  566. else if (me.id == ME_PLeft) // start moving
  567. mx = me.mx, my = me.my;
  568. if (me.id == ME_RLeft) // stop moving
  569. mx = -1, my = -1;
  570. me.processed = 1;
  571. }
  572. }
  573. }
  574. void NativeWindow::doPreCloseAction()
  575. {
  576. if (!preCloseAction) return;
  577. preCloseAction(sakParam, this);
  578. }
  579. void NativeWindow::doPostCloseAction()
  580. {
  581. if (!postCloseAction) return;
  582. postCloseAction(sakParam, this);
  583. }
  584. void NativeWindow::doKeyboardAction(KeyboardEvent& te)
  585. {
  586. if (!keyboardAction || !keyboardAction(takParam, this, te)) return;
  587. if (screen) screen->doKeyboardEvent(te);
  588. }
  589. void NativeWindow::doRestoreMessage() // makes the border visible
  590. {
  591. if (border) ShowWindow(border, 1);
  592. ShowWindow(hWnd, 1);
  593. }
  594. void NativeWindow::setMouseEventParameter(
  595. void* p) // sets the mouse event parameter
  596. {
  597. makParam = p;
  598. }
  599. void NativeWindow::setCloseEventParameter(
  600. void* p) // sets the close event parameter
  601. {
  602. sakParam = p;
  603. }
  604. void NativeWindow::setKeyboardEventParameter(
  605. void* p) // sets the keyboard event parameter
  606. {
  607. takParam = p;
  608. }
  609. void NativeWindow::setMouseAction(MouseAction mouseAk)
  610. {
  611. mouseAction = mouseAk;
  612. }
  613. void NativeWindow::setPreCloseAction(
  614. std::function<void(void*, void*)> vSchliessAk)
  615. {
  616. preCloseAction = vSchliessAk;
  617. }
  618. void NativeWindow::setPostCloseAction(
  619. std::function<void(void*, void*)> nSchliessAk)
  620. {
  621. postCloseAction = nSchliessAk;
  622. }
  623. void NativeWindow::setKeyboardAction(KeyboardAction tastaturAk)
  624. {
  625. keyboardAction = tastaturAk;
  626. }
  627. void NativeWindow::setWindowHandle(HWND hWnd) // sets the operation window
  628. {
  629. this->hWnd = hWnd;
  630. }
  631. void NativeWindow::setMovable(
  632. bool movable) // determines whether the window can be
  633. // moved by dragging with the mouse
  634. {
  635. this->movable = movable;
  636. }
  637. void NativeWindow::loadBorderWindow(Image* zImage,
  638. HINSTANCE hinst) // sets a transparent border around the window
  639. {
  640. if (!zImage) return;
  641. // Create window
  642. WNDCLASSEX wcl = {0};
  643. wcl.cbSize = sizeof(wcl);
  644. wcl.style = CS_HREDRAW | CS_VREDRAW;
  645. wcl.lpfnWndProc = WindowProc;
  646. wcl.cbClsExtra = 0;
  647. wcl.cbWndExtra = 0;
  648. wcl.hInstance = hinst;
  649. wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  650. wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
  651. wcl.hbrBackground = NULL;
  652. wcl.lpszMenuName = NULL;
  653. wcl.lpszClassName = TEXT("LayeredWindowClass");
  654. wcl.hIconSm = NULL;
  655. // Create bitmap
  656. hdc = CreateCompatibleDC(NULL);
  657. if (!hdc) return;
  658. BITMAPINFO info;
  659. info.bmiHeader.biSize = sizeof(info.bmiHeader);
  660. info.bmiHeader.biBitCount = 32;
  661. info.bmiHeader.biWidth = zImage->getWidth();
  662. info.bmiHeader.biHeight = -zImage->getHeight();
  663. info.bmiHeader.biCompression = BI_RGB;
  664. info.bmiHeader.biPlanes = 1;
  665. unsigned char* pPixels = 0;
  666. bitmap
  667. = CreateDIBSection(hdc, &info, DIB_RGB_COLORS, (void**)&pPixels, 0, 0);
  668. if (!bitmap) DeleteDC(hdc);
  669. GdiFlush();
  670. // Fill bitmap
  671. int pitch = ((zImage->getWidth() * 32 + 31) & ~31) >> 3;
  672. unsigned char* pRow = 0;
  673. int* buffer = zImage->getBuffer();
  674. for (int i = 0; i < zImage->getHeight(); ++i)
  675. {
  676. pRow = &pPixels[i * pitch];
  677. for (int i2 = 0; i2 < zImage->getWidth(); ++i2)
  678. {
  679. pRow[i2 * 4]
  680. = (unsigned char)((buffer[i2 + i * zImage->getWidth()] >> 16)
  681. & 0xFF);
  682. pRow[i2 * 4 + 1]
  683. = (unsigned char)((buffer[i2 + i * zImage->getWidth()] >> 8)
  684. & 0xFF);
  685. pRow[i2 * 4 + 2]
  686. = (unsigned char)((buffer[i2 + i * zImage->getWidth()]) & 0xFF);
  687. pRow[i2 * 4 + 3]
  688. = (unsigned char)((buffer[i2 + i * zImage->getWidth()] >> 24)
  689. & 0xFF);
  690. }
  691. }
  692. // Calculate alpha
  693. unsigned char* pPixel = 0;
  694. if (zImage->getWidth() * 4 == pitch)
  695. {
  696. int i = 0;
  697. int totalBytes = zImage->getWidth() * zImage->getHeight() * 4;
  698. for (i = 0; i < totalBytes; i += 4)
  699. {
  700. pPixel = &pPixels[i];
  701. pPixel[0] *= (unsigned char)((float)pPixel[3] / 255.0f);
  702. pPixel[1] *= (unsigned char)((float)pPixel[3] / 255.0f);
  703. pPixel[2] *= (unsigned char)((float)pPixel[3] / 255.0f);
  704. }
  705. }
  706. else
  707. {
  708. int x = 0;
  709. int y = 0;
  710. for (y = 0; y < zImage->getHeight(); ++y)
  711. {
  712. for (x = 0; x < zImage->getWidth(); ++x)
  713. {
  714. pPixel = &pPixels[(y * pitch) + (x * 4)];
  715. pPixel[0] *= (unsigned char)((float)pPixel[3] / 255.0f);
  716. pPixel[1] *= (unsigned char)((float)pPixel[3] / 255.0f);
  717. pPixel[2] *= (unsigned char)((float)pPixel[3] / 255.0f);
  718. }
  719. }
  720. }
  721. // Continue creating window
  722. if (RegisterClassEx(&wcl))
  723. {
  724. border = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_LAYERED,
  725. wcl.lpszClassName,
  726. TEXT("Transparentes Window"),
  727. WS_POPUP,
  728. 0,
  729. 0,
  730. zImage->getWidth(),
  731. zImage->getHeight(),
  732. 0,
  733. 0,
  734. wcl.hInstance,
  735. 0);
  736. if (border)
  737. {
  738. // draw
  739. HDC h = 0;
  740. if ((h = GetDC(border)) && bitmap)
  741. {
  742. HGDIOBJ hPrevObj = NULL;
  743. POINT ptDest = {0, 0};
  744. POINT ptSrc = {0, 0};
  745. SIZE client = {zImage->getWidth(), zImage->getHeight()};
  746. BLENDFUNCTION blendFunc = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA};
  747. hPrevObj = SelectObject(hdc, bitmap);
  748. ClientToScreen(border, &ptDest);
  749. UpdateLayeredWindow(border,
  750. h,
  751. &ptDest,
  752. &client,
  753. hdc,
  754. &ptSrc,
  755. 0,
  756. &blendFunc,
  757. ULW_ALPHA);
  758. SelectObject(hdc, hPrevObj);
  759. ReleaseDC(border, h);
  760. }
  761. UpdateWindow(border);
  762. Point pos = getPosition() + (getSize() - zImage->getSize()) / 2;
  763. SetWindowPos(border,
  764. 0,
  765. pos.x,
  766. pos.y,
  767. zImage->getWidth(),
  768. zImage->getHeight(),
  769. 0);
  770. }
  771. }
  772. }
  773. // constant
  774. Point NativeWindow::getPosition() const // returns the position
  775. {
  776. RECT r;
  777. GetWindowRect(hWnd, &r); // Find position
  778. return {r.left, r.top};
  779. }
  780. Point NativeWindow::getSize() const // returns the size
  781. {
  782. RECT r;
  783. GetWindowRect(hWnd, &r); // Find size
  784. return {r.right - r.left, r.bottom - r.top};
  785. }
  786. Point NativeWindow::getBodySize() const // returns the window body size
  787. {
  788. RECT r;
  789. GetClientRect(hWnd, &r); // Find size
  790. return {r.right - r.left, r.bottom - r.top};
  791. }
  792. int NativeWindow::getBodyWidth() const // returns the window body width
  793. {
  794. RECT r;
  795. GetClientRect(hWnd, &r); // Find size
  796. return r.right;
  797. }
  798. int NativeWindow::getBodyHeight() const // returns the window body height
  799. {
  800. RECT r;
  801. GetClientRect(hWnd, &r); // Find size
  802. return r.bottom;
  803. }
  804. HWND NativeWindow::getWindowHandle() const // returns a handle to the window
  805. {
  806. return hWnd;
  807. }
  808. bool NativeWindow::hasMouseAction() const
  809. {
  810. return mouseAction != 0;
  811. }
  812. bool NativeWindow::hasPreCloseAction() const
  813. {
  814. return preCloseAction != 0;
  815. }
  816. bool NativeWindow::hasPostCloseAction() const
  817. {
  818. return postCloseAction != 0;
  819. }
  820. bool NativeWindow::hasKeyboardAction() const
  821. {
  822. return keyboardAction != 0;
  823. }
  824. Screen* NativeWindow::getScreen() const
  825. {
  826. if (!screen) return 0;
  827. return dynamic_cast<Screen*>(screen->getThis());
  828. }
  829. Screen* NativeWindow::zScreen() const
  830. {
  831. return screen;
  832. }
  833. bool NativeWindow::isMovable()
  834. const // checks if the window can be moved by dragging with the mouse
  835. {
  836. return movable;
  837. }
  838. // Contents of the NativeWindowArray class from Window.h
  839. // Constructor
  840. NativeWindowArray::NativeWindowArray()
  841. : next(0),
  842. This(0)
  843. {}
  844. // Destructor
  845. NativeWindowArray::~NativeWindowArray()
  846. {
  847. if (next) delete next;
  848. }
  849. // add und remove
  850. bool NativeWindowArray::addWindow(NativeWindow* fenster)
  851. {
  852. if (fenster == This) return 0;
  853. if (!This)
  854. {
  855. This = fenster;
  856. return 1;
  857. }
  858. if (!next) next = new NativeWindowArray();
  859. return next->addWindow(fenster);
  860. }
  861. bool NativeWindowArray::removeWindow(NativeWindow* fenster)
  862. {
  863. if (fenster == This) return 1;
  864. if (!next) return 0;
  865. if (next->removeWindow(fenster))
  866. {
  867. NativeWindowArray* tmp = next->getNext();
  868. next->setNext0();
  869. delete next;
  870. next = tmp;
  871. }
  872. return 0;
  873. }
  874. NativeWindowArray* NativeWindowArray::getNext()
  875. {
  876. return next;
  877. }
  878. void NativeWindowArray::setNext0()
  879. {
  880. next = 0;
  881. }
  882. void NativeWindowArray::del()
  883. {
  884. if (next)
  885. {
  886. This = next->getThis();
  887. NativeWindowArray* tmp = next->getNext();
  888. next->setNext0();
  889. delete next;
  890. next = tmp;
  891. }
  892. else
  893. This = 0;
  894. }
  895. // Messages
  896. bool NativeWindowArray::sendPreCloseMessage(HWND hwnd)
  897. {
  898. if (!This) return 0;
  899. bool ret = 0;
  900. if (This->getWindowHandle() == hwnd && This->hasPreCloseAction())
  901. {
  902. This->doPreCloseAction();
  903. ret = 1;
  904. }
  905. if (!next) return ret;
  906. return ret || next->sendPreCloseMessage(hwnd);
  907. }
  908. bool NativeWindowArray::sendPostCloseMessage(HWND hwnd)
  909. {
  910. if (!This) return 0;
  911. bool ret = 0;
  912. if (This->getWindowHandle() == hwnd && This->hasPostCloseAction())
  913. {
  914. This->doPostCloseAction();
  915. ret = 1;
  916. }
  917. if (!next) return ret;
  918. return ret || next->sendPostCloseMessage(hwnd);
  919. }
  920. bool NativeWindowArray::sendMouseMessage(HWND hwnd, MouseEvent& me)
  921. {
  922. if (!This) return 0;
  923. bool ret = 0;
  924. if (This->getWindowHandle() == hwnd && This->hasMouseAction())
  925. {
  926. This->doMouseAction(me);
  927. ret = 1;
  928. }
  929. if (!next) return ret;
  930. return ret || next->sendMouseMessage(hwnd, me);
  931. }
  932. bool NativeWindowArray::sendKeyboardMessage(HWND hwnd, KeyboardEvent& te)
  933. {
  934. if (!This) return 0;
  935. bool ret = 0;
  936. if (This->getWindowHandle() == hwnd && This->hasKeyboardAction())
  937. {
  938. This->doKeyboardAction(te);
  939. ret = 1;
  940. }
  941. if (!next) return ret;
  942. return ret || next->sendKeyboardMessage(hwnd, te);
  943. }
  944. bool NativeWindowArray::sendRestoreMessage(HWND hwnd)
  945. {
  946. if (!This) return 0;
  947. bool ret = 0;
  948. if (This->getWindowHandle() == hwnd && This->hasMouseAction())
  949. {
  950. This->doRestoreMessage();
  951. ret = 1;
  952. }
  953. if (!next) return ret;
  954. return ret || next->sendRestoreMessage(hwnd);
  955. }
  956. NativeWindow* NativeWindowArray::getThis()
  957. {
  958. return This;
  959. }
  960. // WMessageBox
  961. void Framework::WMessageBox(HWND hWnd, Text* title, Text* meldung, UINT style)
  962. {
  963. MessageBox(
  964. hWnd, meldung->getText(), title->getText(), style); // Message Box
  965. title->release();
  966. meldung->release();
  967. }
  968. #endif
  969. // Contents of the Window class from Window.h
  970. // Constructor
  971. Window::Window()
  972. : Drawable(),
  973. closingMe(0),
  974. closingMeParam(0),
  975. border(0),
  976. title(0),
  977. members(new RCArray<Drawable>()),
  978. bgBodyColor(0xFF000000),
  979. bgBodyPicture(0),
  980. bodyBuffer(0),
  981. bgClosingColor(0xFF000000),
  982. bgClosingImage(0),
  983. closeBuffer(0),
  984. closeClickBuffer(0),
  985. vScroll(0),
  986. hScroll(0),
  987. kMin(0, 0),
  988. kMax(0, 0),
  989. closeClick(0),
  990. click(0),
  991. moving(0),
  992. mx(0),
  993. my(0)
  994. {
  995. style = Style::MEIgnoreProcessed | Style::MEIgnoreVisible
  996. | Style::MEIgnoreParentInside | Style::MEIgnoreInside;
  997. this->setMouseEvent(_ret1ME);
  998. this->setKeyboardEvent(_ret1TE);
  999. min = Point(0, 0), max = Point(0, 0);
  1000. }
  1001. // Destructor
  1002. Window::~Window()
  1003. {
  1004. if (border) border->release();
  1005. if (title) title->release();
  1006. members->release();
  1007. if (bodyBuffer) bodyBuffer->release();
  1008. if (bgBodyPicture) bgBodyPicture->release();
  1009. if (bgClosingImage) bgClosingImage->release();
  1010. if (closeBuffer) closeBuffer->release();
  1011. if (closeClickBuffer) closeClickBuffer->release();
  1012. if (vScroll) vScroll->release();
  1013. if (hScroll) hScroll->release();
  1014. }
  1015. void Window::doMouseEvent(MouseEvent& me, bool userRet)
  1016. {
  1017. if (me.id == ME_Leaves)
  1018. {
  1019. if (closeClick != 0) rend = 1;
  1020. closeClick = 0, click = 0;
  1021. }
  1022. if (hasStyleNot(Style::Visible) || !me.insideParent || me.processed
  1023. || me.mx < 0 || me.my < 0 || me.mx >= gr.x || me.my >= gr.y || !userRet)
  1024. {
  1025. bool insideParent = me.insideParent;
  1026. bool processed = me.processed;
  1027. me.processed |= hasStyleNot(Style::Visible);
  1028. me.insideParent = 0;
  1029. int rbr = 0;
  1030. if (hasStyle(Style::Border) && border) rbr = border->getRWidth();
  1031. int th = 0;
  1032. if (hasStyle(Style::Title) && title) th = title->getHeight();
  1033. me.mx -= rbr;
  1034. me.my -= rbr + th;
  1035. if (hasStyle(Style::VScroll) && vScroll) me.my += vScroll->getScroll();
  1036. if (hasStyle(Style::HScroll) && hScroll) me.mx += hScroll->getScroll();
  1037. if (me.id != ME_Enter && me.id != ME_Leaves)
  1038. {
  1039. for (int i = members->getEntryCount() - 1; i >= 0; i--)
  1040. members->z(i)->doPublicMouseEvent(me);
  1041. }
  1042. me.mx += rbr;
  1043. me.my += rbr + th;
  1044. if (hasStyle(Style::VScroll) && vScroll) me.my -= vScroll->getScroll();
  1045. if (hasStyle(Style::HScroll) && hScroll) me.mx -= hScroll->getScroll();
  1046. me.insideParent = insideParent;
  1047. if (hasStyleNot(Style::Visible)) me.processed = processed;
  1048. if (!moving) return;
  1049. }
  1050. bool mvtmp = me.processed;
  1051. if (hasStyleNot(Style::Allowed)) me.processed = 1;
  1052. int rbr = 0;
  1053. if (hasStyle(Style::Border) && border) rbr = border->getRWidth();
  1054. int th = 0;
  1055. if (hasStyle(Style::Title) && title) th = title->getHeight();
  1056. bool hSc = hasStyle(Style::HScroll) && hScroll;
  1057. bool vSc = hasStyle(Style::VScroll) && vScroll;
  1058. if (me.id == ME_Move && moving && getMouseState(M_Left))
  1059. {
  1060. if (hasStyle(Style::Movable) || hasStyle(Style::HeightChangeable)
  1061. || hasStyle(Style::WidthChangeable)
  1062. || hasStyle(Style::TitleHeightChangeable))
  1063. {
  1064. bool ret1 = 0;
  1065. bool mset = 0;
  1066. int schi = 0;
  1067. int scbr = 0;
  1068. if (hSc)
  1069. {
  1070. schi = 15;
  1071. }
  1072. if (vSc)
  1073. {
  1074. scbr += 15;
  1075. }
  1076. bool minXb, maxXb, minYb, maxYb;
  1077. bool kMinXb, kMaxXb, kMinYb, kMaxYb;
  1078. minXb = hasStyle(Style::MinWidth);
  1079. maxXb = hasStyle(Style::MaxWidth);
  1080. minYb = hasStyle(Style::MinHeight);
  1081. maxYb = hasStyle(Style::MaxHeight);
  1082. kMinXb = hasStyle(Style::BodyMinWidth);
  1083. kMaxXb = hasStyle(Style::BodyMaxWidth);
  1084. kMinYb = hasStyle(Style::BodyMinHeight);
  1085. kMaxYb = hasStyle(Style::BodyMaxHeight);
  1086. int fMinWidth = rbr * 2 + scbr;
  1087. if (minXb) fMinWidth = fMinWidth < min.x ? min.x : fMinWidth;
  1088. if (kMinXb)
  1089. fMinWidth = fMinWidth < (rbr * 2 + kMin.x + scbr)
  1090. ? (rbr * 2 + kMin.x + scbr)
  1091. : fMinWidth;
  1092. int fMinHeight = rbr * 2 + th + schi;
  1093. if (minYb) fMinHeight = fMinHeight < min.y ? min.y : fMinHeight;
  1094. if (kMinYb)
  1095. fMinHeight = fMinHeight < (rbr * 2 + kMin.y + th + schi)
  1096. ? (rbr * 2 + kMin.y + th + schi)
  1097. : fMinHeight;
  1098. int fMaxWidth = 0;
  1099. if (maxXb) fMaxWidth = max.x;
  1100. if (kMaxXb)
  1101. fMaxWidth = fMaxWidth < (rbr * 2 + kMax.x + scbr)
  1102. ? (rbr * 2 + kMax.x + scbr)
  1103. : fMaxWidth;
  1104. int fMaxHeight = 0;
  1105. if (maxYb) fMaxHeight = max.y;
  1106. if (kMaxYb)
  1107. fMaxHeight = fMaxHeight < (rbr * 2 + kMax.y + th + schi)
  1108. ? (rbr * 2 + kMax.y + th + schi)
  1109. : fMaxHeight;
  1110. minXb |= kMinXb, maxXb |= kMaxXb, minYb |= kMinYb, maxYb |= kMaxYb;
  1111. if (hasStyle(Style::HeightChangeable))
  1112. {
  1113. if ((moving | 0x1) == moving) // top
  1114. {
  1115. pos.y -= my - me.my;
  1116. gr.y += my - me.my;
  1117. if (gr.y < fMinHeight)
  1118. {
  1119. pos.y -= fMinHeight - gr.y;
  1120. gr.y = fMinHeight;
  1121. }
  1122. else if (maxYb && gr.y > fMaxHeight)
  1123. {
  1124. pos.y -= gr.y - fMaxHeight;
  1125. gr.y = fMaxHeight;
  1126. }
  1127. else if (vSc)
  1128. vScroll->getScrollData()->anzeige = gr.y;
  1129. rend = 1;
  1130. ret1 = 1;
  1131. }
  1132. else if ((moving | 0x2) == moving) // bottom
  1133. {
  1134. gr.y += me.my - my;
  1135. if (gr.y < fMinHeight)
  1136. gr.y = fMinHeight;
  1137. else if (maxYb && gr.y > fMaxHeight)
  1138. gr.y = fMaxHeight;
  1139. else
  1140. {
  1141. mset = 1;
  1142. if (vSc) vScroll->getScrollData()->anzeige = gr.y;
  1143. }
  1144. rend = 1;
  1145. ret1 = 1;
  1146. }
  1147. }
  1148. if (hasStyle(Style::WidthChangeable))
  1149. {
  1150. if ((moving | 0x4) == moving) // left
  1151. {
  1152. pos.x -= mx - me.mx;
  1153. gr.x += mx - me.mx;
  1154. if (gr.x < fMinWidth)
  1155. {
  1156. pos.x -= fMinWidth - gr.x;
  1157. gr.x = fMinWidth;
  1158. }
  1159. else if (maxXb && gr.x > fMaxWidth)
  1160. {
  1161. pos.x -= gr.x - fMaxWidth;
  1162. gr.x = fMaxWidth;
  1163. }
  1164. else if (hSc)
  1165. hScroll->getScrollData()->anzeige = gr.x;
  1166. rend = 1;
  1167. ret1 = 1;
  1168. }
  1169. else if ((moving | 0x8) == moving) // right
  1170. {
  1171. gr.x += me.mx - mx;
  1172. if (gr.x < rbr * 2 + fMinWidth)
  1173. gr.x = rbr * 2 + fMinWidth;
  1174. else if (maxXb && gr.x > fMaxWidth)
  1175. gr.x = fMaxWidth;
  1176. else
  1177. {
  1178. mset = 1;
  1179. if (hSc) hScroll->getScrollData()->anzeige = gr.x;
  1180. }
  1181. rend = 1;
  1182. ret1 = 1;
  1183. }
  1184. }
  1185. if (hasStyle(Style::TitleHeightChangeable) && title
  1186. && (moving | 0x10) == moving) // title height
  1187. {
  1188. int maxTh = gr.y - rbr * 2 - schi;
  1189. if (kMaxYb)
  1190. maxTh = maxTh < (gr.x - rbr * 2 - kMin.y)
  1191. ? maxTh
  1192. : (gr.x - rbr * 2 - kMin.y);
  1193. if (hasStyle(Style::Closable))
  1194. maxTh = (gr.x - th - 5 - rbr * 2 - me.my + my) < 0 ? th
  1195. : maxTh;
  1196. title->setSize(
  1197. title->getWidth(), title->getHeight() + me.my - my);
  1198. if (title->getHeight() > maxTh)
  1199. title->setSize(title->getWidth(), maxTh);
  1200. else if (title->getHeight() < 5)
  1201. title->setSize(title->getWidth(), 5);
  1202. else
  1203. mset = 1;
  1204. rend = 1;
  1205. ret1 = 1;
  1206. }
  1207. if (ret1)
  1208. {
  1209. if (mset) mx = me.mx, my = me.my;
  1210. me.processed = 1;
  1211. }
  1212. if (hasStyle(Style::Movable) && (moving | 0x20) == moving) // move
  1213. {
  1214. pos.x += me.mx - mx;
  1215. pos.y += me.my - my;
  1216. rend = 1;
  1217. ret1 = 1;
  1218. }
  1219. if (ret1) me.processed = 1;
  1220. }
  1221. }
  1222. if (me.id == ME_RLeft)
  1223. {
  1224. if (closeClick) rend = 1;
  1225. closeClick = 0, click = 0;
  1226. moving = 0;
  1227. mx = -1, my = -1;
  1228. }
  1229. if (me.id == ME_Leaves)
  1230. {
  1231. if (closeClick != 0) rend = 1;
  1232. closeClick = 0, click = 0;
  1233. }
  1234. if (hasStyleNot(Style::Visible) || !me.insideParent || me.processed
  1235. || me.mx < 0 || me.my < 0 || me.mx >= gr.x || me.my >= gr.y || !userRet)
  1236. return;
  1237. if (!me.processed)
  1238. {
  1239. if (hasStyle(Style::Closable) && me.my <= th + rbr
  1240. && me.mx >= gr.x + rbr - th && me.my >= rbr && me.mx <= gr.x - rbr)
  1241. {
  1242. if (!closingMe || closingMe(closingMeParam, this, me))
  1243. {
  1244. if (me.id == ME_PLeft)
  1245. {
  1246. closeClick = 1;
  1247. rend = 1;
  1248. }
  1249. if (!closeClick && MouseState[M_Left])
  1250. {
  1251. closeClick = 1;
  1252. rend = 1;
  1253. }
  1254. me.processed = 1;
  1255. }
  1256. }
  1257. else if (closeClick)
  1258. {
  1259. closeClick = 0;
  1260. rend = 1;
  1261. }
  1262. if (me.id == ME_PLeft && !closeClick)
  1263. {
  1264. click = 1;
  1265. mx = me.mx, my = me.my;
  1266. if (me.mx >= 0 && me.mx < gr.x && me.my >= 0 && me.my < rbr + 5
  1267. && !hasStyle(Style::TopPositionFixed))
  1268. moving |= 0x1;
  1269. if (me.mx >= 0 && me.mx < gr.x && me.my >= gr.y - (rbr + 5)
  1270. && me.my < gr.y && !hasStyle(Style::BottomPositionFixed))
  1271. moving |= 0x2;
  1272. if (me.mx >= 0 && me.mx < rbr + 5 && me.my >= 0 && me.my < gr.y
  1273. && !hasStyle(Style::LeftPositionFixed))
  1274. moving |= 0x4;
  1275. if (me.mx >= gr.x - rbr - 5 && me.mx < gr.x && me.my >= 0
  1276. && me.my < gr.y && !hasStyle(Style::RightPositionFixed))
  1277. moving |= 0x8;
  1278. if (title && me.mx >= 0 && me.mx < gr.x
  1279. && me.my >= title->getHeight()
  1280. && me.my < title->getHeight() + 2 * (rbr + 5))
  1281. moving |= 0x10;
  1282. if (title && me.mx >= 0 && me.mx < gr.x && me.my >= rbr + 5
  1283. && me.my < title->getHeight())
  1284. moving |= 0x20;
  1285. }
  1286. }
  1287. if (vSc)
  1288. {
  1289. vScroll->doMouseMessage(
  1290. gr.x - rbr - 15, rbr + th, 15, gr.y - rbr * 2 - th, me);
  1291. if (hSc)
  1292. hScroll->doMouseMessage(
  1293. rbr, gr.y - rbr - 15, gr.x - rbr * 2 - 15, 15, me);
  1294. }
  1295. else if (hSc)
  1296. hScroll->doMouseMessage(rbr, gr.y - rbr - 15, gr.x - rbr * 2, 15, me);
  1297. me.mx -= rbr;
  1298. me.my -= rbr + th;
  1299. if (hasStyle(Style::VScroll) && vScroll) me.my += vScroll->getScroll();
  1300. if (hasStyle(Style::HScroll) && hScroll) me.mx += hScroll->getScroll();
  1301. if (me.id != ME_Enter && me.id != ME_Leaves)
  1302. {
  1303. for (int i = members->getEntryCount() - 1; i >= 0; i--)
  1304. members->z(i)->doPublicMouseEvent(me);
  1305. }
  1306. me.mx += rbr;
  1307. me.my += rbr + th;
  1308. if (hasStyle(Style::VScroll) && vScroll) me.my -= vScroll->getScroll();
  1309. if (hasStyle(Style::HScroll) && hScroll) me.mx -= hScroll->getScroll();
  1310. if (hasStyleNot(Style::METransparent)) me.processed = 1;
  1311. if (hasStyleNot(Style::Allowed)) me.processed = mvtmp;
  1312. }
  1313. // non-const
  1314. // -- Border --
  1315. void Window::setBorderZ(Border* ram) // sets the border
  1316. {
  1317. if (border) border->release();
  1318. border = ram;
  1319. rend = 1;
  1320. }
  1321. void Window::setBorderColor(int f) // sets the border color
  1322. {
  1323. if (!border) border = new LBorder();
  1324. border->setColor(f);
  1325. rend = 1;
  1326. }
  1327. void Window::setBorderWidth(int br) // sets the border width
  1328. {
  1329. if (!border) border = new LBorder();
  1330. border->setBorderWidth(br);
  1331. rend = 1;
  1332. }
  1333. // -- Title --
  1334. void Window::setTitel(Text* txt) // sets the title
  1335. {
  1336. if (!title) title = new TextField();
  1337. title->setText(txt);
  1338. rend = 1;
  1339. }
  1340. void Window::setTitelZ(Text* txt)
  1341. {
  1342. if (!title) title = new TextField();
  1343. title->setTextZ(txt);
  1344. rend = 1;
  1345. }
  1346. void Window::setTitel(const char* txt)
  1347. {
  1348. if (!title) title = new TextField();
  1349. title->setText(txt);
  1350. rend = 1;
  1351. }
  1352. void Window::setTTextFieldZ(TextField* tf) // sets the title text field
  1353. {
  1354. if (title) title->release();
  1355. title = tf;
  1356. rend = 1;
  1357. }
  1358. // -- Font --
  1359. void Window::setTFontZ(Font* font) // sets the title font
  1360. {
  1361. if (!title) title = new TextField();
  1362. title->setFontZ(font);
  1363. rend = 1;
  1364. }
  1365. void Window::setTFontColor(int f) // sets the title font color
  1366. {
  1367. if (!title) title = new TextField();
  1368. title->setFontColor(f);
  1369. rend = 1;
  1370. }
  1371. void Window::setTFontSize(int gr) // sets the title font size
  1372. {
  1373. if (!title) title = new TextField();
  1374. title->setFontSize((unsigned char)gr);
  1375. rend = 1;
  1376. }
  1377. // -- Title Background --
  1378. void Window::setTBgColor(int f) // sets title background color
  1379. {
  1380. if (!title) title = new TextField();
  1381. title->setBackgroundColor(f);
  1382. rend = 1;
  1383. }
  1384. // -- Title AlphaField --
  1385. void Window::setTAlphaFieldZ(AlphaField* af) // sets the title AlphaField
  1386. {
  1387. if (!title) title = new TextField();
  1388. title->setAlphaFieldZ(af);
  1389. rend = 1;
  1390. }
  1391. void Window::setTAfColor(int f) // sets the title AlphaField color
  1392. {
  1393. if (!title) title = new TextField();
  1394. title->setAlphaFieldColor(f);
  1395. rend = 1;
  1396. }
  1397. void Window::setTAfStrength(int st) // sets the strength of the title AlphaField
  1398. {
  1399. if (!title) title = new TextField();
  1400. title->setAlphaFieldStrength(st);
  1401. rend = 1;
  1402. }
  1403. // -- Title Background Image --
  1404. void Window::setTBgImage(Image* b) // sets the title background image
  1405. {
  1406. if (!title) title = new TextField();
  1407. title->setBackgroundImage(b);
  1408. rend = 1;
  1409. }
  1410. void Window::setTBgImageZ(Image* b)
  1411. {
  1412. if (!title) title = new TextField();
  1413. title->setBackgroundImageZ(b);
  1414. rend = 1;
  1415. }
  1416. // -- Title Border --
  1417. void Window::setTBorderZ(Border* ram) // sets the title border
  1418. {
  1419. if (!title) title = new TextField();
  1420. title->setBorderZ(ram);
  1421. rend = 1;
  1422. }
  1423. void Window::setTBorderColor(int f) // sets the title border color
  1424. {
  1425. if (!title) title = new TextField();
  1426. title->setBorderColor(f);
  1427. rend = 1;
  1428. }
  1429. void Window::setTBorderWidth(int br) // sets the title border width
  1430. {
  1431. if (!title) title = new TextField();
  1432. title->setBorderWidth(br);
  1433. rend = 1;
  1434. }
  1435. // -- Body Background --
  1436. void Window::setBodyBgColor(int f) // sets the body background color
  1437. {
  1438. bgBodyColor = f;
  1439. rend = 1;
  1440. }
  1441. // -- Body Background Image --
  1442. void Window::setBodyBgImage(Image* b) // sets the body background image
  1443. {
  1444. if (!bgBodyPicture) bgBodyPicture = new Image();
  1445. bgBodyPicture->newImage(b->getWidth(), b->getHeight(), 0);
  1446. int* buff1 = bgBodyPicture->getBuffer();
  1447. int* buff2 = b->getBuffer();
  1448. int gr = bgBodyPicture->getWidth() * bgBodyPicture->getHeight();
  1449. for (int i = 0; i < gr; ++i)
  1450. buff1[i] = buff2[i];
  1451. b->release();
  1452. rend = 1;
  1453. }
  1454. void Window::setBodyBgImageZ(Image* b)
  1455. {
  1456. if (bgBodyPicture) bgBodyPicture->release();
  1457. bgBodyPicture = b;
  1458. rend = 1;
  1459. }
  1460. // -- Body AlphaField --
  1461. void Window::setBodyAlphaFieldZ(AlphaField* af) // sets the body AlphaField
  1462. {
  1463. if (bodyBuffer) bodyBuffer->release();
  1464. bodyBuffer = af;
  1465. rend = 1;
  1466. }
  1467. void Window::setBodyAfColor(int f) // sets body AlphaField color
  1468. {
  1469. if (!bodyBuffer) bodyBuffer = new AlphaField();
  1470. bodyBuffer->setColor(f);
  1471. rend = 1;
  1472. }
  1473. void Window::setBodyAfStrength(
  1474. int st) // sets the strength of the body AlphaField
  1475. {
  1476. if (!bodyBuffer) bodyBuffer = new AlphaField();
  1477. bodyBuffer->setStrength(st);
  1478. rend = 1;
  1479. }
  1480. // -- Close --
  1481. void Window::setClosingMeParam(void* param)
  1482. {
  1483. closingMeParam = param;
  1484. }
  1485. void Window::setClosingMe(MouseAction closingMe) // sets the close mouse event
  1486. {
  1487. this->closingMe = closingMe;
  1488. }
  1489. // -- Close Background --
  1490. void Window::setCloseBgColor(int f) // sets the close background color
  1491. {
  1492. bgClosingColor = f;
  1493. rend = 1;
  1494. }
  1495. // -- Close Background Image --
  1496. void Window::setCloseBgImage(Image* b) // sets the close background image
  1497. {
  1498. if (!bgClosingImage) bgClosingImage = new Image();
  1499. bgClosingImage->newImage(b->getWidth(), b->getHeight(), 0);
  1500. int* buff1 = bgClosingImage->getBuffer();
  1501. int* buff2 = b->getBuffer();
  1502. int gr = bgClosingImage->getWidth() * bgClosingImage->getHeight();
  1503. for (int i = 0; i < gr; ++i)
  1504. buff1[i] = buff2[i];
  1505. b->release();
  1506. rend = 1;
  1507. }
  1508. void Window::setCloseBgImageZ(Image* b)
  1509. {
  1510. if (bgClosingImage) bgClosingImage->release();
  1511. bgClosingImage = b;
  1512. rend = 1;
  1513. }
  1514. // -- Close AlphaField --
  1515. void Window::setCloseAlphaFieldZ(AlphaField* af) // sets the close AlphaField
  1516. {
  1517. if (closeBuffer) closeBuffer->release();
  1518. closeBuffer = af;
  1519. rend = 1;
  1520. }
  1521. void Window::setCloseAfColor(int f) // sets the color of the close AlphaField
  1522. {
  1523. if (!closeBuffer) closeBuffer = new AlphaField();
  1524. closeBuffer->setColor(f);
  1525. rend = 1;
  1526. }
  1527. void Window::setCloseAfStrength(
  1528. int st) // sets the strength of the close AlphaField
  1529. {
  1530. if (!closeBuffer) closeBuffer = new AlphaField();
  1531. closeBuffer->setStrength(st);
  1532. rend = 1;
  1533. }
  1534. // -- Close Click AlphaField --
  1535. void Window::setCloseClickAlphaFieldZ(
  1536. AlphaField* af) // sets the close click AlphaField
  1537. {
  1538. if (closeClickBuffer) closeClickBuffer->release();
  1539. closeClickBuffer = af;
  1540. rend = 1;
  1541. }
  1542. void Window::setCloseClickAfColor(
  1543. int f) // sets the color of the close click AlphaField
  1544. {
  1545. if (!closeClickBuffer) closeClickBuffer = new AlphaField();
  1546. closeClickBuffer->setColor(f);
  1547. rend = 1;
  1548. }
  1549. void Window::setCloseClickAfStrength(
  1550. int st) // sets the strength of the close click AlphaField
  1551. {
  1552. if (!closeClickBuffer) closeClickBuffer = new AlphaField();
  1553. closeClickBuffer->setStrength(st);
  1554. rend = 1;
  1555. }
  1556. // -- min max --
  1557. void Window::setMin(int mx, int my) // sets the minimum window size
  1558. {
  1559. min.x = mx;
  1560. min.y = my;
  1561. }
  1562. void Window::setMin(const Point& min)
  1563. {
  1564. this->min = min;
  1565. }
  1566. void Window::setMax(int mx, int my) // sets the maximum window size
  1567. {
  1568. max.x = mx;
  1569. max.y = my;
  1570. }
  1571. void Window::setMax(const Point& max)
  1572. {
  1573. this->max = max;
  1574. }
  1575. void Window::setBodyMin(int mx, int my) // sets the minimum body size
  1576. {
  1577. kMin.x = mx;
  1578. kMin.y = my;
  1579. }
  1580. void Window::setBodyMin(const Point& min)
  1581. {
  1582. kMin = min;
  1583. }
  1584. void Window::setBodyMax(int mx, int my) // sets the maximum body size
  1585. {
  1586. kMax.x = mx;
  1587. kMax.y = my;
  1588. }
  1589. void Window::setBodyMax(const Point& max)
  1590. {
  1591. kMax = max;
  1592. }
  1593. // -- scroll --
  1594. void Window::setHScrollBarZ(
  1595. HScrollBar* hScroll) // sets the horizontal scroll bar
  1596. {
  1597. if (this->hScroll) this->hScroll->release();
  1598. this->hScroll = hScroll;
  1599. rend = 1;
  1600. }
  1601. void Window::setVScrollBarZ(VScrollBar* vScroll) // sets the vertical scroll bar
  1602. {
  1603. if (this->vScroll) this->vScroll->release();
  1604. this->vScroll = vScroll;
  1605. rend = 1;
  1606. }
  1607. void Window::setHSBMax(int max) // sets the scroll maximum
  1608. {
  1609. if (!hScroll) hScroll = new HScrollBar();
  1610. int rbr = 0;
  1611. if (hasStyle(Style::Border) && border) rbr = border->getRWidth();
  1612. int vsh = 0;
  1613. if (hasStyle(Style::VScroll) && vScroll) vsh = 15;
  1614. hScroll->update(max, gr.x - rbr * 2 - vsh);
  1615. rend = 1;
  1616. }
  1617. void Window::setVSBMax(int max)
  1618. {
  1619. if (!vScroll) vScroll = new VScrollBar();
  1620. int rbr = 0;
  1621. int th = 0;
  1622. if (hasStyle(Style::Border) && border) rbr = border->getRWidth();
  1623. if (hasStyle(Style::Title) && title) th = title->getHeight();
  1624. int hsh = 0;
  1625. if (hasStyle(Style::HScroll) && hScroll) hsh = 15;
  1626. vScroll->update(max, gr.y - rbr * 2 - th - hsh);
  1627. rend = 1;
  1628. }
  1629. void Window::setHSBScroll(int scroll) // sets the current scroll position
  1630. {
  1631. if (!hScroll) hScroll = new HScrollBar();
  1632. hScroll->scroll(scroll);
  1633. rend = 1;
  1634. }
  1635. void Window::setVSBScroll(int scroll)
  1636. {
  1637. if (!vScroll) vScroll = new VScrollBar();
  1638. vScroll->scroll(scroll);
  1639. rend = 1;
  1640. }
  1641. void Framework::Window::updateHScroll()
  1642. {
  1643. if (hScroll)
  1644. {
  1645. hScroll->update(getNeededChildWidth(), getInnerWidth());
  1646. }
  1647. }
  1648. void Framework::Window::updateVScroll()
  1649. {
  1650. if (vScroll)
  1651. {
  1652. vScroll->update(getNeededChildHeight(), getInnerHeight());
  1653. }
  1654. }
  1655. // -- Members --
  1656. void Window::addMember(Drawable* obj) // adds a member
  1657. {
  1658. members->add(obj);
  1659. rend = 1;
  1660. }
  1661. void Framework::Window::setMemberIndex(Drawable* zMember, int index)
  1662. {
  1663. if (index < 0 || index >= members->getEntryCount()) return;
  1664. int currentIndex = members->indexOf(zMember);
  1665. members->setPosition(currentIndex, index);
  1666. }
  1667. void Window::removeMember(Drawable* zObj) // removes a member
  1668. {
  1669. for (int i = 0; i < members->getEntryCount(); i++)
  1670. {
  1671. if (members->z(i) == zObj)
  1672. {
  1673. members->remove(i);
  1674. rend = 1;
  1675. }
  1676. }
  1677. }
  1678. void Window::removeAll()
  1679. {
  1680. members->clear();
  1681. rend = 1;
  1682. }
  1683. // -- Messages --
  1684. bool Window::tick(double tickval) // tick
  1685. {
  1686. if (hasStyle(Style::Visible))
  1687. {
  1688. for (Drawable* i : *members)
  1689. rend |= i->tick(tickval);
  1690. }
  1691. else
  1692. {
  1693. for (Drawable* i : *members)
  1694. i->tick(tickval);
  1695. }
  1696. if (vScroll && hasStyle(Style::VScroll)) rend |= vScroll->getNeedRender();
  1697. if (hScroll && hasStyle(Style::HScroll)) rend |= hScroll->getNeedRender();
  1698. return Drawable::tick(tickval);
  1699. }
  1700. void Window::doKeyboardEvent(KeyboardEvent& te)
  1701. {
  1702. bool ntakc = !te.processed;
  1703. if (hasStyle(Style::Visible))
  1704. {
  1705. if (te.processed)
  1706. {
  1707. for (int i = members->getEntryCount() - 1; i >= 0; i--)
  1708. members->z(i)->doKeyboardEvent(te);
  1709. }
  1710. else
  1711. {
  1712. if (tak && tak(takParam, this, te))
  1713. {
  1714. for (int i = members->getEntryCount() - 1; i >= 0; i--)
  1715. members->z(i)->doKeyboardEvent(te);
  1716. }
  1717. }
  1718. }
  1719. if (ntakc && te.processed && nTak) te.processed = nTak(ntakParam, this, te);
  1720. }
  1721. // -- Render --
  1722. void Window::render(Image& zRObj) // draws to zRObj
  1723. {
  1724. if (hasStyle(Style::Visible))
  1725. {
  1726. rwLock.lockRead();
  1727. if (!zRObj.setDrawOptions(pos, gr))
  1728. {
  1729. rwLock.unlockRead();
  1730. return;
  1731. }
  1732. Drawable::render(zRObj);
  1733. int rbr = 0;
  1734. if (hasStyle(Style::Border) && border)
  1735. {
  1736. border->setSize(gr);
  1737. border->render(zRObj);
  1738. rbr = border->getRWidth();
  1739. }
  1740. int th = 0;
  1741. if (title)
  1742. title->setStyle(TextField::Style::Visible, hasStyle(Style::Title));
  1743. if (hasStyle(Style::Title) && title)
  1744. {
  1745. title->setStyle(
  1746. TextField::Style::Background, hasStyle(Style::TitleBackground));
  1747. title->setStyle(
  1748. TextField::Style::BAlpha, hasStyle(Style::TitleBAlpha));
  1749. title->setStyle(
  1750. TextField::Style::BImage, hasStyle(Style::TitleBImage));
  1751. title->setStyle(
  1752. TextField::Style::Buffered, hasStyle(Style::TitleBuffered));
  1753. th = title->getHeight();
  1754. if (!zRObj.setDrawOptions(rbr, rbr, gr.x - rbr * 2, th))
  1755. {
  1756. zRObj.releaseDrawOptions();
  1757. rwLock.unlockRead();
  1758. return;
  1759. }
  1760. int sbr = 0;
  1761. if (hasStyle(Style::Closable))
  1762. {
  1763. sbr = th;
  1764. if (hasStyle(Style::ClosingBackground))
  1765. {
  1766. if (hasStyle(Style::ClosingBAlpha))
  1767. zRObj.alphaRegion(
  1768. gr.x - th - rbr * 2, 0, th, th, bgClosingColor);
  1769. else
  1770. zRObj.fillRegion(
  1771. gr.x - th - rbr * 2, 0, th, th, bgClosingColor);
  1772. if (hasStyle(Style::ClosingBImage) && bgClosingImage)
  1773. {
  1774. if (hasStyle(Style::ClosingBAlpha))
  1775. zRObj.alphaImage(gr.x - th - rbr * 2,
  1776. 0,
  1777. th,
  1778. th,
  1779. *bgClosingImage);
  1780. else
  1781. zRObj.drawImage(gr.x - th - rbr * 2,
  1782. 0,
  1783. th,
  1784. th,
  1785. *bgClosingImage);
  1786. }
  1787. }
  1788. if (!hasStyle(Style::ClosingBImage) || !bgClosingImage)
  1789. {
  1790. zRObj.drawLine(Point(gr.x - th - rbr * 2, 0),
  1791. Point(gr.x - rbr * 2, th),
  1792. 0xFFFFFFFF);
  1793. zRObj.drawLine(Point(gr.x - rbr * 2, 0),
  1794. Point(gr.x - th - rbr * 2, th),
  1795. 0xFFFFFFFF);
  1796. }
  1797. if (hasStyle(Style::ClosingBuffer) && closeBuffer)
  1798. {
  1799. closeBuffer->setPosition(gr.x - th - rbr * 2, 0);
  1800. closeBuffer->setSize(th, th);
  1801. closeBuffer->render(zRObj);
  1802. }
  1803. if (hasStyle(Style::ClosingClickBuffer) && closeClickBuffer
  1804. && closeClick)
  1805. {
  1806. closeClickBuffer->setPosition(gr.x - th - rbr * 2, 0);
  1807. closeClickBuffer->setSize(th, th);
  1808. closeClickBuffer->render(zRObj);
  1809. }
  1810. }
  1811. if (!hasStyle(Style::CustomTitle))
  1812. title->setSize(gr.x - rbr * 2 - sbr, th);
  1813. title->render(zRObj);
  1814. zRObj.releaseDrawOptions();
  1815. }
  1816. bool vSc = hasStyle(Style::VScroll) && vScroll;
  1817. bool hSc = hasStyle(Style::HScroll) && hScroll;
  1818. if (vSc)
  1819. {
  1820. vScroll->render(
  1821. gr.x - rbr - 15, rbr + th, 15, gr.y - rbr * 2 - th, zRObj);
  1822. if (hSc)
  1823. hScroll->render(
  1824. rbr, gr.y - rbr - 15, gr.x - rbr * 2 - 15, 15, zRObj);
  1825. }
  1826. else if (hSc)
  1827. hScroll->render(rbr, gr.y - rbr - 15, gr.x - rbr * 2, 15, zRObj);
  1828. int x = rbr;
  1829. int y = rbr + th;
  1830. int br = gr.x - rbr * 2;
  1831. int hi = gr.y - rbr * 2 - th;
  1832. if (vSc) br -= 15;
  1833. if (hSc) hi -= 15;
  1834. if (!zRObj.setDrawOptions(x, y, br, hi))
  1835. {
  1836. zRObj.releaseDrawOptions();
  1837. rwLock.unlockRead();
  1838. return;
  1839. }
  1840. if (hasStyle(Style::BodyBackground))
  1841. {
  1842. if (hasStyle(Style::BodyBAlpha))
  1843. zRObj.alphaRegion(0, 0, br, hi, bgBodyColor);
  1844. else
  1845. zRObj.fillRegion(0, 0, br, hi, bgBodyColor);
  1846. if (hasStyle(Style::BodyBImage) && bgBodyPicture)
  1847. {
  1848. if (hasStyle(Style::BodyBAlpha))
  1849. zRObj.alphaImage(0, 0, br, hi, *bgBodyPicture);
  1850. else
  1851. zRObj.drawImage(0, 0, br, hi, *bgBodyPicture);
  1852. }
  1853. }
  1854. if (hasStyle(Style::BodyBuffered) && bodyBuffer)
  1855. {
  1856. bodyBuffer->setSize(br, hi);
  1857. bodyBuffer->render(zRObj);
  1858. }
  1859. if (!vSc && !hSc)
  1860. {
  1861. for (Drawable* i : *members)
  1862. i->render(zRObj);
  1863. }
  1864. else
  1865. {
  1866. zRObj.addScrollOffset(
  1867. hSc ? hScroll->getScroll() : 0, vSc ? vScroll->getScroll() : 0);
  1868. for (Drawable* i : *members)
  1869. i->render(zRObj);
  1870. }
  1871. zRObj.releaseDrawOptions();
  1872. zRObj.releaseDrawOptions();
  1873. rwLock.unlockRead();
  1874. }
  1875. }
  1876. // constant
  1877. // Returns the width of the interior area of the drawing in pixels
  1878. int Window::getInnerWidth() const
  1879. {
  1880. return getWidth() - 2 * getBorderWidth();
  1881. }
  1882. // Returns the height of the interior area of the drawing in pixels
  1883. int Window::getInnerHeight() const
  1884. {
  1885. int th = 0;
  1886. if (hasStyle(Style::Title) && title) th += title->getHeight();
  1887. return getHeight() - 2 * getBorderWidth() - th;
  1888. }
  1889. // -- Border --
  1890. Border* Window::getBorder() const // returns the border
  1891. {
  1892. if (!border) return 0;
  1893. return dynamic_cast<Border*>(border->getThis());
  1894. }
  1895. Border* Window::zBorder() const
  1896. {
  1897. return border;
  1898. }
  1899. int Window::getBorderColor() const // returns the border color
  1900. {
  1901. if (!border) return 0;
  1902. return border->getColor();
  1903. }
  1904. int Window::getBorderWidth() const // returns the border width
  1905. {
  1906. if (!border || hasStyleNot(Style::Border)) return 0;
  1907. return border->getRWidth();
  1908. }
  1909. // -- Title --
  1910. Text* Window::getTitel() const // returns the title
  1911. {
  1912. if (!title) return 0;
  1913. return title->getText();
  1914. }
  1915. Text* Window::zTitel() const
  1916. {
  1917. if (!title) return 0;
  1918. return title->zText();
  1919. }
  1920. TextField* Window::getTTextField() const // returns the title text field
  1921. {
  1922. if (!title) return 0;
  1923. return dynamic_cast<TextField*>(title->getThis());
  1924. }
  1925. TextField* Window::zTTextField() const
  1926. {
  1927. return title;
  1928. }
  1929. // -- Title Font --
  1930. Font* Window::getTFont() const // returns the title font
  1931. {
  1932. if (!title) return 0;
  1933. return title->getFont();
  1934. }
  1935. Font* Window::zTFont() const
  1936. {
  1937. if (!title) return 0;
  1938. return title->zFont();
  1939. }
  1940. int Window::getTFontColor() const // returns the title font color
  1941. {
  1942. if (!title) return 0;
  1943. return title->getFontColor();
  1944. }
  1945. int Window::getTFontSize() const // returns the title font size
  1946. {
  1947. if (!title) return 0;
  1948. return title->getFontSize();
  1949. }
  1950. // -- Title Background --
  1951. int Window::getTBgColor() const // returns the title background color
  1952. {
  1953. if (!title) return 0;
  1954. return title->getBackgroundColor();
  1955. }
  1956. // -- Title AlphaField --
  1957. AlphaField* Window::getTAlphaField() const // returns the title AlphaField
  1958. {
  1959. if (!title) return 0;
  1960. return title->getAlphaField();
  1961. }
  1962. AlphaField* Window::zTAlphaField() const
  1963. {
  1964. if (!title) return 0;
  1965. return title->zAlphaField();
  1966. }
  1967. int Window::getTAfColor() const // returns the color of the title AlphaField
  1968. {
  1969. if (!title) return 0;
  1970. return title->getAlphaFieldColor();
  1971. }
  1972. int Window::getTAfStrength()
  1973. const // returns the strength of the title AlphaField
  1974. {
  1975. if (!title) return 0;
  1976. return title->getAlphaFieldStrength();
  1977. }
  1978. // -- Title Background Image --
  1979. Image* Window::getTBgImage() const // returns the title background image
  1980. {
  1981. if (!title) return 0;
  1982. return title->getBackgroundImage();
  1983. }
  1984. Image* Window::zTBgImage() const
  1985. {
  1986. if (!title) return 0;
  1987. return title->zBackgroundImage();
  1988. }
  1989. // -- Title Border --
  1990. Border* Window::getTBorder() const // returns the title border
  1991. {
  1992. if (!title) return 0;
  1993. return title->getBorder();
  1994. }
  1995. Border* Window::zTBorder() const
  1996. {
  1997. if (!title) return 0;
  1998. return title->zBorder();
  1999. }
  2000. int Window::getTBorderColor() const // returns the title border color
  2001. {
  2002. if (!title) return 0;
  2003. return title->getBorderColor();
  2004. }
  2005. int Window::getTBorderWidth() const // returns the title border width
  2006. {
  2007. if (!title) return 0;
  2008. return title->getBorderWidth();
  2009. }
  2010. // -- Body Background --
  2011. int Window::getBodyBgColor() const // returns the body background color
  2012. {
  2013. return bgBodyColor;
  2014. }
  2015. // -- Body Background Image --
  2016. Image* Window::getBodyBgImage() const // returns the body background image
  2017. {
  2018. if (!bgBodyPicture) return 0;
  2019. return dynamic_cast<Image*>(bgBodyPicture->getThis());
  2020. }
  2021. Image* Window::zBodyBgImage() const
  2022. {
  2023. return bgBodyPicture;
  2024. }
  2025. // -- Body AlphaField --
  2026. AlphaField* Window::getBodyAlphaField() const // returns the body AlphaField
  2027. {
  2028. if (!bodyBuffer) return 0;
  2029. return dynamic_cast<AlphaField*>(bodyBuffer->getThis());
  2030. }
  2031. AlphaField* Window::zBodyAlphaField() const
  2032. {
  2033. return bodyBuffer;
  2034. }
  2035. int Window::getBodyAfColor() const // returns the body AlphaField color
  2036. {
  2037. if (!bodyBuffer) return 0;
  2038. return bodyBuffer->getColor();
  2039. }
  2040. int Window::getBodyAfStrength()
  2041. const // returns the strength of the body AlphaField
  2042. {
  2043. if (!bodyBuffer) return 0;
  2044. return bodyBuffer->getStrength();
  2045. }
  2046. // -- Close Background --
  2047. int Window::getCloseBgColor() const // returns the close background color
  2048. {
  2049. return bgClosingColor;
  2050. }
  2051. // -- Close Background Image --
  2052. Image* Window::getCloseBgImage() const // returns the close background image
  2053. {
  2054. if (!bgClosingImage) return 0;
  2055. return dynamic_cast<Image*>(bgClosingImage->getThis());
  2056. }
  2057. Image* Window::zCloseBgImage() const
  2058. {
  2059. return bgClosingImage;
  2060. }
  2061. // -- Close AlphaField --
  2062. AlphaField* Window::getCloseAlphaField() const // returns the close AlphaField
  2063. {
  2064. if (!closeBuffer) return 0;
  2065. return dynamic_cast<AlphaField*>(closeBuffer->getThis());
  2066. }
  2067. AlphaField* Window::zCloseAlphaField() const
  2068. {
  2069. return closeBuffer;
  2070. }
  2071. int Window::getCloseAfColor() const // returns the close AlphaField color
  2072. {
  2073. if (!closeBuffer) return 0;
  2074. return closeBuffer->getColor();
  2075. }
  2076. int Window::getCloseAfStrength()
  2077. const // returns the strength of the close AlphaField
  2078. {
  2079. if (!closeBuffer) return 0;
  2080. return closeBuffer->getStrength();
  2081. }
  2082. // -- Close Click AlphaField --
  2083. AlphaField*
  2084. Window::getCloseClickAlphaField() const // returns the close click AlphaField
  2085. {
  2086. if (!closeClickBuffer) return 0;
  2087. return dynamic_cast<AlphaField*>(closeClickBuffer->getThis());
  2088. }
  2089. AlphaField* Window::zCloseClickAlphaField() const
  2090. {
  2091. return closeClickBuffer;
  2092. }
  2093. int Window::getCloseClickAfColor()
  2094. const // returns the close click AlphaField color
  2095. {
  2096. if (!closeClickBuffer) return 0;
  2097. return closeClickBuffer->getColor();
  2098. }
  2099. int Window::getCloseClickAfStrength()
  2100. const // returns the strength of the close click AlphaField
  2101. {
  2102. if (!closeClickBuffer) return 0;
  2103. return closeClickBuffer->getStrength();
  2104. }
  2105. // -- min max --
  2106. const Point& Window::getMin() const // returns the minimum window size
  2107. {
  2108. return min;
  2109. }
  2110. const Point& Window::getMax() const // returns the maximum window size
  2111. {
  2112. return max;
  2113. }
  2114. const Point& Window::getBodyMin() const // returns the minimum body size
  2115. {
  2116. return kMin;
  2117. }
  2118. const Point& Window::getBodyMax() const // returns the maximum body size
  2119. {
  2120. return kMax;
  2121. }
  2122. // -- scroll --
  2123. VScrollBar* Window::getVScrollBar() const // returns the vertical scroll bar
  2124. {
  2125. if (!vScroll) return 0;
  2126. return dynamic_cast<VScrollBar*>(vScroll->getThis());
  2127. }
  2128. VScrollBar* Window::zVScrollBar() const
  2129. {
  2130. return vScroll;
  2131. }
  2132. HScrollBar* Window::getHScrollBar() const // returns the horizontal scroll bar
  2133. {
  2134. if (!hScroll) return 0;
  2135. return dynamic_cast<HScrollBar*>(hScroll->getThis());
  2136. }
  2137. HScrollBar* Window::zHScrollBar() const
  2138. {
  2139. return hScroll;
  2140. }
  2141. // -- Members --
  2142. const RCArray<Drawable>& Window::getMembers() const // returns the members
  2143. {
  2144. return *members;
  2145. }
  2146. int Framework::Window::getNeededChildWidth() const
  2147. {
  2148. int max = 0;
  2149. for (Drawable* z : *members)
  2150. {
  2151. if (z->getX() + z->getWidth() > max) max = z->getX() + z->getWidth();
  2152. }
  2153. return max;
  2154. }
  2155. int Framework::Window::getNeededChildHeight() const
  2156. {
  2157. int max = 0;
  2158. for (Drawable* z : *members)
  2159. {
  2160. if (z->getY() + z->getHeight() > max) max = z->getY() + z->getHeight();
  2161. }
  2162. return max;
  2163. }
  2164. // -- Copy --
  2165. Drawable* Window::duplicate() const // Creates a copy of the window
  2166. {
  2167. Window* ret = new Window();
  2168. ret->setPosition(pos);
  2169. ret->setSize(gr);
  2170. ret->setMouseEventParameter(makParam);
  2171. ret->setKeyboardEventParameter(takParam);
  2172. ret->setMouseEvent(mak);
  2173. ret->setKeyboardEvent(tak);
  2174. if (toolTip) ret->setToolTipZ((ToolTip*)toolTip->duplicate());
  2175. ret->setStyle(style);
  2176. ret->setClosingMeParam(closingMeParam);
  2177. ret->setClosingMe(closingMe);
  2178. if (border)
  2179. {
  2180. ret->setBorderWidth(border->getRWidth());
  2181. ret->setBorderColor(border->getColor());
  2182. }
  2183. if (title) ret->setTTextFieldZ((TextField*)title->duplicate());
  2184. ret->setBodyBgColor(bgBodyColor);
  2185. if (bgBodyPicture)
  2186. ret->setBodyBgImage(dynamic_cast<Image*>(bgBodyPicture->getThis()));
  2187. if (bodyBuffer)
  2188. {
  2189. ret->setBodyAfColor(bodyBuffer->getColor());
  2190. ret->setBodyAfStrength(bodyBuffer->getStrength());
  2191. }
  2192. ret->setCloseBgColor(bgClosingColor);
  2193. if (bgClosingImage)
  2194. ret->setCloseBgImage(dynamic_cast<Image*>(bgClosingImage->getThis()));
  2195. if (closeBuffer)
  2196. {
  2197. ret->setCloseAfColor(closeBuffer->getColor());
  2198. ret->setCloseAfStrength(closeBuffer->getStrength());
  2199. }
  2200. if (closeClickBuffer)
  2201. {
  2202. ret->setCloseClickAfColor(closeClickBuffer->getColor());
  2203. ret->setCloseClickAfStrength(closeClickBuffer->getStrength());
  2204. }
  2205. if (vScroll)
  2206. {
  2207. ret->setVSBMax(vScroll->getScrollData()->max);
  2208. ret->setVSBScroll(vScroll->getScroll());
  2209. }
  2210. if (hScroll)
  2211. {
  2212. ret->setHSBMax(hScroll->getScrollData()->max);
  2213. ret->setHSBScroll(hScroll->getScroll());
  2214. }
  2215. ret->setMin(min);
  2216. ret->setMax(max);
  2217. ret->setBodyMin(kMin);
  2218. ret->setBodyMax(kMax);
  2219. return ret;
  2220. }