Window.cpp 64 KB

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