Window.cpp 64 KB

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