procW2K2.inc 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  1. Function Alloc(cbSize:Uint32):Pointer;
  2. var
  3. ret : Pointer;
  4. begin
  5. Ret := nil;
  6. if MaxAvail >= cbSize then
  7. GetMem(Ret,cbSize);
  8. Alloc := Ret;
  9. end;
  10. {-------------------------------------------------------}
  11. Function wGetWndbyhWnd(h:hWnd):PWindow;
  12. var
  13. c : PWindow;
  14. begin
  15. wGetWndbyhWnd := nil;
  16. if h = NULL then exit;
  17. c := AllWindows^.Next;
  18. while (c <> nil) and (c^.Handle <> h) do c:=c^.next;
  19. wGetWndbyhWnd := c;
  20. end; {}
  21. {-------------------------------------------------------}
  22. Function wGetMenuByhMenu(h:hMenu):PMenu;
  23. var
  24. c : PMenuList;
  25. begin
  26. wGetMenuByhMenu := nil;
  27. if h = NULL then exit;
  28. c := AllMenus^.Next;
  29. while (c <> nil) and (c^.Handle <> h) do c:=c^.next;
  30. if c <> nil then wGetMenuByhMenu := c^.Mn;
  31. end; {}
  32. {-------------------------------------------------------}
  33. Function wSendMessage(aW:PWindow;aMsg,wParam,lParam:UINT32):UINT32;
  34. begin
  35. if (aW=nil) then Exit;
  36. wSendMessage := aW^.WClass^.WndProc(aW^.Handle,aMsg,wParam,lParam);
  37. end;{}
  38. {-----------------------------------}
  39. Function wPostMessage(c:PWindow;aMsg,wParam,lParam:UINT32):UINT32;
  40. var
  41. aNewMsg,cm : PMessageList;
  42. begin
  43. if c=nil then Exit;
  44. New(aNewMsg);
  45. with aNewMsg^ do
  46. begin
  47. Next:=nil;
  48. msg.Message := aMsg;
  49. msg.wParam := wParam;
  50. msg.lParam := lParam;
  51. end;
  52. cm := c^.Queue;
  53. while cm^.Next <> nil do cm:=cm^.next;
  54. cm^.Next := aNewMsg;
  55. end;{}
  56. {-------------------------------------------------------}
  57. Procedure wGetGlobalRect(wnd:PWindow;aR:LPRECT);
  58. var
  59. c : PWindow;
  60. begin
  61. if (wnd = nil) or (aR = NIL) then Exit;
  62. aR^ := wnd^.Pos;
  63. c := wnd;
  64. while c^.Parent <> nil do
  65. begin
  66. inc(aR^.A.X,c^.Parent^.Pos.A.X);
  67. inc(aR^.A.Y,c^.Parent^.Pos.A.Y);
  68. c := c^.Parent;
  69. end;
  70. if (c^.Style AND WS_TITLE) = WS_TITLE then
  71. Inc(aR^.A.Y,c^.Palette^.ActTitleSize);
  72. if c^.Menu <> nil then
  73. Inc(aR^.A.Y,c^.Palette^.MenuSelSize);
  74. if c^.bActive then
  75. begin
  76. Inc(aR^.A.X, c^.Palette^.ActBorderSize);
  77. Inc(aR^.A.Y, c^.Palette^.ActBorderSize);
  78. end
  79. else
  80. begin
  81. Inc(aR^.A.X, c^.Palette^.NoActBorderSize);
  82. Inc(aR^.A.Y, c^.Palette^.NoActBorderSize);
  83. end;
  84. end;
  85. Procedure wGlobalToClient(aH:PWindow;aX,aY:INT16;aR:LPPOINT);
  86. var
  87. gR : RECT;
  88. begin
  89. wGetGlobalRect(aH,@gR);
  90. if aR = nil then exit;
  91. aR^.X := aX-gR.A.X;
  92. aR^.Y := aY-gR.A.Y;
  93. end;
  94. Function wGetClass(var aName:string):PClass;
  95. var
  96. c : UInt16;
  97. begin
  98. wGetClass := nil;
  99. if ClassesCnt = 0 then exit;
  100. for c := 0 to ClassesCnt-1 do if AllClasses^[c].Name^ = aName then
  101. begin
  102. wGetClass := @AllClasses^[c];
  103. exit;
  104. end;
  105. end;{}
  106. {-------------------------------------------------------}
  107. Procedure wSetTopMost(aWindow:PWindow);
  108. var
  109. c : PWindow;
  110. begin
  111. c := TopMost;
  112. if TopMost^.zOrder <> nil then TopMost^.zOrder^.bActive := false;
  113. aWindow^.bActive := true;
  114. while (c^.zOrder <> aWindow) and (c^.zOrder <> nil) do c:=c^.zOrder;
  115. if c^.zOrder <> nil then
  116. c^.zOrder := aWindow^.zOrder;
  117. aWindow^.zOrder := Topmost^.zOrder;
  118. TopMost^.zOrder := aWindow;
  119. end;
  120. {--------------------------------}
  121. Function wWindowFromPoint(aP:POINT):PWindow;
  122. var
  123. c : PWindow;
  124. begin
  125. wWindowFromPoint := nil;
  126. c := TopMost^.NEXT;
  127. while (c<>NIL) do
  128. begin
  129. with c^.Pos do
  130. if (aP.X>=A.X) AND (aP.X<=(B.X+A.X)) AND (aP.Y>=A.Y) AND (aP.Y<=(B.Y+A.Y)) then
  131. begin
  132. wWindowFromPoint := c;
  133. Exit;
  134. end;
  135. c:=c^.zOrder;
  136. end;
  137. end; {WindowFromPoint}
  138. {-----------------------------------}
  139. Function wChildWindowFromPoint(aParent:PWindow;aP:POINT):PWindow;
  140. var
  141. c : PWindow;
  142. RT : RECT;
  143. begin
  144. wChildWindowFromPoint := aParent;
  145. if aParent=nil then Exit;
  146. c:=aParent^.Child^.Brother;
  147. while (c<>NIL) do
  148. begin
  149. wGetGlobalRect(c,@RT);
  150. with RT do
  151. if (aP.X>=A.X) AND (aP.X<=(B.X+A.X)) AND (aP.Y>=A.Y) AND (aP.Y<=(B.Y+A.Y)) then
  152. begin
  153. wChildWindowFromPoint := c;
  154. Exit;
  155. end;
  156. c:=c^.Brother;
  157. end;
  158. end; {wChildWindowFromPoint}
  159. {-----------------------------------}
  160. Procedure wRenderHorizMenu(aW:PWindow);
  161. begin
  162. end;
  163. {--------------------------------}
  164. Procedure wRenderBG(aW:PWindow);
  165. var
  166. CR : RECT;
  167. CP : TPalette;
  168. begin
  169. CR := aW^.Pos;
  170. CP := aW^.Palette^;
  171. SetFillStyle(CP.ThreeDStyle,CP.ThreeDColor1);
  172. SetColor(CP.ThreeDColor2);
  173. Bar(CR.A.X,CR.A.Y,CR.A.X+CR.B.X,CR.A.Y+CR.B.Y);
  174. end;
  175. {--------------------------------}
  176. Procedure wRenderFrame(aW:PWindow);
  177. var
  178. i,Tst,Tfn,Tfc,Tfs,Tcl,Tsz,Bs : INT16;
  179. CP : TPalette;
  180. CR : RECT;
  181. begin
  182. CP := aW^.Palette^;
  183. CR := aW^.Pos;
  184. inc(CR.B.X,CR.A.X-1);
  185. inc(CR.B.Y,CR.A.Y-1);
  186. { SetFillStyle(CP.ThreeDStyle,CP.ThreeDColor1);
  187. SetColor(CP.ThreeDColor2);
  188. Bar(CR.A.X,CR.A.Y,CR.B.X,CR.B.Y);}
  189. if aW^.bActive then
  190. begin
  191. SetColor(CP.ActBorderColor);
  192. Bs := CP.ActBorderSize;
  193. Tst := CP.ActTitleStyle;
  194. Tsz := CP.ActTitleSize;
  195. Tcl := CP.ActTitleColor;
  196. Tfn := CP.ActTitleFont;
  197. Tfs := CP.ActTitleFontSize;
  198. Tfc := CP.ActTitleFontColor;
  199. end else
  200. begin
  201. SetColor(CP.NoActBorderColor);
  202. Bs := cp.NoActBorderSize;
  203. Tst := CP.NoActTitleStyle;
  204. Tsz := CP.NoActTitleSize;
  205. Tcl := CP.NoActTitleColor;
  206. Tfn := CP.NoActTitleFont;
  207. Tfs := CP.NoActTitleFontSize;
  208. Tfc := CP.NoActTitleFontColor;
  209. end;
  210. for i:=0 to Bs-1 do
  211. Rectangle(CR.A.X+i,CR.A.Y+i,CR.B.X-i,CR.B.Y-i);
  212. if (aW^.Style AND WS_TITLE) = WS_TITLE then
  213. begin
  214. SetFillStyle(TSt,Tcl);
  215. SetColor(CP.ThreeDColor1);
  216. Bar(CR.A.X+Bs ,CR.A.Y+Bs+1, CR.B.X-Bs, CR.A.Y+Tsz-Bs-1);
  217. SetColor(CP.ThreeDColor1);
  218. Line(CR.A.X+Bs ,CR.A.Y+Bs, CR.B.X-Bs, CR.A.Y+Bs);
  219. Line(CR.A.X+Bs ,CR.A.Y+Tsz+Bs, CR.B.X-Bs, CR.A.Y+Tsz+Bs);
  220. SetColor(Tfc);
  221. SetTextStyle(Tfn,HorizDir,Tfs);
  222. SetTextJustify(LeftText,CenterText);
  223. OutTextXY(CR.A.X+5,CR.A.Y+Bs+(Tsz shr 1),aW^.Title^);
  224. if aW^.Menu <> nil then wRenderHorizMenu(aW);
  225. end
  226. end;{---}
  227. {---------}
  228. Procedure wSendPaint(aW:PWindow);
  229. var
  230. ch : PWindow;
  231. begin
  232. aW^.WClass^.WndProc(aW^.Handle,WM_PAINT,0,0);
  233. ch := aW^.Child^.Brother;
  234. while ch <> nil do
  235. begin
  236. wSendPaint(ch);
  237. ch:=ch^.Brother;
  238. end;
  239. end;
  240. {--------------------------------}
  241. Procedure wRenderWindows(aW:PWindow);
  242. begin
  243. if aW = nil then exit;
  244. wRenderWindows(aW^.zOrder);
  245. wRenderBG(aW);
  246. wRenderFrame(aW);
  247. wSendPaint(aW);
  248. end;{}
  249. {--------------------------------}
  250. Procedure wRenderTaskbar;
  251. begin
  252. end;
  253. {--------------------------------}
  254. Procedure wRenderAll;
  255. begin
  256. HideMouse;
  257. ClearDevice;
  258. wRenderWindows(Topmost^.zOrder);
  259. wRenderTaskbar;
  260. bNeedRender := false;
  261. ShowMouse;
  262. end;
  263. {--------------------------------}
  264. Procedure wInitGlobalPalette;
  265. begin
  266. with GlobalPalette do
  267. begin
  268. MenuSelSize := 5;
  269. MenuSelColor := Green;
  270. MenuSelFont := DEFAULTFONT;
  271. MenuSelFontSize := 1;
  272. MenuSelFontColor := Black;
  273. ActBorderSize := 1;
  274. ActBorderColor := Green;
  275. NoActBorderSize := 1;
  276. NoActBorderColor := White;
  277. ActTitleStyle := SolidFill;
  278. ActTitleSize := 15;
  279. ActTitleColor := Magenta;
  280. ActTitleFont := DEFAULTFONT;
  281. ActTitleFontSize := 1;
  282. ActTitleFontColor := Black;
  283. NoActTitleStyle := CloseDotFill;
  284. NoActTitleSize := 15;
  285. NoActTitleColor := Magenta;
  286. NoActTitleFont := DEFAULTFONT;
  287. NoActTitleFontSize := 1;
  288. NoActTitleFontColor := White;
  289. WindowBGColor := DarkGray;
  290. WindowStyle := SolidFill;
  291. WindowFontColor := White;
  292. ThreeDColor1 := LightGray;
  293. ThreeDColor2 := DarkGray;
  294. ThreeDStyle := SolidFill;
  295. end;
  296. end;
  297. Procedure wInitFonts;
  298. var
  299. DirInfo : SearchRec;
  300. i : UINT16;
  301. begin
  302. FontCount := 5;
  303. FindFirst('*.CHR', Archive, DirInfo);
  304. while DosError = 0 do
  305. begin
  306. Inc(FontCount);
  307. FindNext(DirInfo);
  308. end;
  309. AllFonts := Alloc(Sizeof(TFontDef) * FontCount);
  310. AllFonts^[0].aName := Alloc(30);
  311. AllFonts^[0].aName^ := 'Default';
  312. AllFonts^[0].wFont := DefaultFont;
  313. AllFonts^[1].aName := Alloc(30);
  314. AllFonts^[1].aName^ := 'Triplex';
  315. AllFonts^[1].wFont := TriplexFont;
  316. AllFonts^[2].aName := Alloc(30);
  317. AllFonts^[2].aName^ := 'Small';
  318. AllFonts^[2].wFont := SmallFont;
  319. AllFonts^[3].aName := Alloc(30);
  320. AllFonts^[3].aName^ := 'SansSerif';
  321. AllFonts^[3].wFont := SansSerifFont;
  322. AllFonts^[4].aName := Alloc(30);
  323. AllFonts^[4].aName^ := 'Gothic';
  324. AllFonts^[4].wFont := GothicFont;
  325. i := 5;
  326. FindFirst('*.CHR', Archive, DirInfo);
  327. while DosError = 0 do
  328. begin
  329. AllFonts^[i].aName := Alloc(ord(Dirinfo.Name[0])+1);
  330. AllFonts^[i].aName^ := Dirinfo.Name;
  331. AllFonts^[i].wFont := InstallUserFont(DirInfo.Name);
  332. FindNext(DirInfo);
  333. INc(i);
  334. end;
  335. end;
  336. {--------------------------------}
  337. Var
  338. AllKeys : PKeyTable;
  339. KeyActive : PWindow;
  340. gActiveParent : PWindow;
  341. gLastWindow : PWindow;
  342. gActiveWindow : PWindow;
  343. Procedure ProcessKeyboard;
  344. var
  345. i : EScanCode;
  346. pr: boolean;
  347. begin
  348. while GetScanCode(i,pr) do
  349. begin
  350. if KeyActive <> nil then
  351. if pr then wPostMessage(KeyActive,WM_KEYDOWN,ord(i),UINT32(GetChar(ord(i))))
  352. else wPostMessage(KeyActive,WM_KEYUP,ord(i),UINT32(GetChar(ord(i))))
  353. end;
  354. end;
  355. {-------------------------------------------------------}
  356. Procedure wPosTitleButtons(mNew:PWindow);
  357. var
  358. gH : HWND;
  359. gW : PWindow;
  360. Txt: string;
  361. begin
  362. if (mNew^.Style AND WS_TITLE) = WS_TITLE then
  363. begin
  364. Txt := 'CLOSEBUTTON';
  365. gH:= FindChildWindow(mNew^.Handle,nil,@Txt);
  366. gW := wGetWndByHWND(gH);
  367. if gW <> nil then with gW^.Pos do
  368. begin
  369. A.X := mNew^.Pos.B.X-mNew^.Palette^.ActTitleSize-2;
  370. A.Y := -mNew^.Palette^.ActTitleSize+2;
  371. B.X := mNew^.Palette^.ActTitleSize-5;
  372. B.Y := mNew^.Palette^.ActTitleSize-5;
  373. end;
  374. if (mNew^.Style AND WS_MINMAX) = WS_MINMAX then
  375. begin
  376. Txt := 'MINBUTTON';
  377. gH:=FindChildWindow(mNew^.Handle,nil,@Txt);
  378. gW := wGetWndByHWND(gH);
  379. if gW <> nil then with gW^.Pos do
  380. begin
  381. A.X := mNew^.Pos.B.X-3*mNew^.Palette^.ActTitleSize-2;
  382. A.Y := -mNew^.Palette^.ActTitleSize+2;
  383. B.X := mNew^.Palette^.ActTitleSize-5;
  384. B.Y := mNew^.Palette^.ActTitleSize-5;
  385. end;
  386. Txt := 'MAXBUTTON';
  387. gH:=FindChildWindow(mNew^.Handle,nil,@Txt);
  388. gW := wGetWndByHWND(gH);
  389. if gW <> nil then with gW^.Pos do
  390. begin
  391. A.X := mNew^.Pos.B.X-2*mNew^.Palette^.ActTitleSize-4;
  392. A.Y := -mNew^.Palette^.ActTitleSize+2;
  393. B.X := mNew^.Palette^.ActTitleSize-5;
  394. B.Y := mNew^.Palette^.ActTitleSize-5;
  395. end;
  396. end;
  397. end;
  398. end;
  399. var
  400. gMouseState : PMouseState;
  401. gLastMouseState : TMouseState;
  402. gMove : Boolean;
  403. gwMove,gwSize : Boolean;
  404. gReSize : Boolean;
  405. gDir : UINT8;
  406. gSize : RECT;
  407. Procedure ProcessMouse;
  408. var
  409. aH : HWND;
  410. aP,nP : POINT;
  411. RT : RECT;
  412. begin
  413. getMouseState(gMouseState^);
  414. aP.X := gMouseState^.X;
  415. aP.Y := gMouseState^.Y;
  416. if (gLastMouseState.X <> aP.X) or
  417. (gLastMouseState.Y <> aP.Y) then
  418. begin
  419. if gMove or gResize then
  420. begin
  421. SetWriteMode(XORPut);
  422. SetColor(White);
  423. HideMouse;
  424. with gSize do
  425. begin
  426. Rectangle(A.X,A.Y,A.X+B.X-1,A.Y+B.Y-1);
  427. if gMove then
  428. begin
  429. inc(A.X,aP.X-gLAstMouseState.X);
  430. inc(A.Y,aP.Y-gLAstMouseState.Y);
  431. end;
  432. if gReSize then
  433. begin
  434. if (gDir AND 1) = 1 then
  435. begin
  436. inc(A.Y,aP.Y-gLAstMouseState.Y);
  437. dec(B.Y,aP.Y-gLAstMouseState.Y);
  438. end;
  439. if (gDir AND 2) = 2 then
  440. inc(B.X,aP.X-gLAstMouseState.X);
  441. if (gDir AND 8) = 8 then
  442. begin
  443. inc(A.X,aP.X-gLAstMouseState.X);
  444. dec(B.X,aP.X-gLAstMouseState.X);
  445. end;
  446. if (gDir AND 4) = 4 then
  447. inc(B.Y,aP.Y-gLAstMouseState.Y);
  448. end;
  449. Rectangle(A.X,A.Y,A.X+B.X-1,A.Y+B.Y-1);
  450. ShowMouse;
  451. SetWriteMode(NormalPut);
  452. end;
  453. end
  454. else
  455. begin
  456. if gActiveParent <> nil then
  457. begin
  458. RT := gActiveParent^.Pos;
  459. inc(RT.B.X,RT.A.X-1);
  460. inc(RT.B.Y,RT.A.Y-1);
  461. with RT do
  462. if not ((aP.X>=A.X) AND (aP.X<=B.X) AND (aP.Y>=A.Y) AND (aP.Y<=B.Y)) then
  463. begin
  464. wPostMessage(gActiveParent,WM_MOUSEOUT,0,UINT32(aP.Y) shl 16 + aP.x);
  465. gActiveParent := NIL;
  466. end
  467. end;
  468. if gActiveParent = NIL then
  469. begin
  470. gActiveParent := wWindowFromPoint(aP);
  471. SetMouseShape(AllCursors^[0].HotX,AllCursors^[0].HotY,@AllCursors^[0].AndMask);
  472. wPostMessage(gActiveParent,WM_MOUSEIN,0,UINT32(aP.Y) shl 16 + aP.x);
  473. end;
  474. if gActiveParent <> nil then
  475. begin
  476. gActiveWindow := wChildWindowFromPoint(gActiveParent,aP);
  477. wGlobalToClient(gActiveWindow,aP.X,aP.Y,@nP);
  478. if gActiveWindow <> gLastWindow then
  479. begin
  480. if gLastWindow <> nil then
  481. wPostMessage(gLastWindow,WM_MOUSEOUT,0,UINT32(aP.Y) shl 16 + aP.x);
  482. wPostMessage(gActiveWindow,WM_MOUSEIN,0,UINT32(aP.Y) shl 16 + aP.x);
  483. gLastWindow := gActiveWindow;
  484. end;
  485. gDir:=0;
  486. with gActiveParent^.Pos do
  487. begin
  488. if (aP.Y-A.Y) < gResizeThr then gDir := 1;
  489. if (A.X+B.X-1-aP.X) < gResizeThr then gDir := gDir + 2;
  490. if (aP.X-A.X) < gResizeThr then gDir := gDir + 8;
  491. if (A.Y+B.Y-1-aP.Y) < gResizeThr then gDir := gDir + 4;
  492. end;
  493. if gDir <> 0 then
  494. begin
  495. { if not gwSize then}
  496. case gDir of
  497. 1: SetMouseShape(AllCursors^[1].HotX,AllCursors^[1].HotY,
  498. @AllCursors^[1].AndMask);
  499. 2: SetMouseShape(AllCursors^[2].HotX,AllCursors^[2].HotY,
  500. @AllCursors^[2].AndMask);
  501. 3: SetMouseShape(AllCursors^[3].HotX,AllCursors^[3].HotY,
  502. @AllCursors^[3].AndMask);
  503. 4: SetMouseShape(AllCursors^[1].HotX,AllCursors^[1].HotY,
  504. @AllCursors^[1].AndMask);
  505. 6: SetMouseShape(AllCursors^[4].HotX,AllCursors^[4].HotY,
  506. @AllCursors^[4].AndMask);
  507. 8: SetMouseShape(AllCursors^[2].HotX,AllCursors^[2].HotY,
  508. @AllCursors^[2].AndMask);
  509. 9: SetMouseShape(AllCursors^[4].HotX,AllCursors^[4].HotY,
  510. @AllCursors^[4].AndMask);
  511. 12: SetMouseShape(AllCursors^[3].HotX,AllCursors^[3].HotY,
  512. @AllCursors^[3].AndMask);
  513. end;
  514. gwSize := true
  515. end
  516. else
  517. begin
  518. if gwSize then SetMouseShape(AllCursors^[0].HotX,AllCursors^[0].HotY,
  519. @AllCursors^[0].AndMask);
  520. gwSize := false;
  521. gwMove := (aP.Y-gActiveParent^.Pos.A.Y) < gActiveParent^.Palette^.ActTitleSize;
  522. end;
  523. wPostMessage(gActiveWindow,WM_MOUSEMOVE,0,UINT32(nP.Y) shl 16 + nP.X);
  524. end;
  525. end;
  526. end;
  527. if ((gMouseState^.Buttons AND 1) = 1) AND
  528. ((gLastMouseState.Buttons AND 1) = 0) then
  529. begin
  530. if (gActiveParent = nil) and (TopMost^.zOrder <> nil) then
  531. begin
  532. TopMost^.zOrder^.bActive := false;
  533. if KeyActive <> nil then wPostMessage(KeyActive,WM_LOSTFOCUS,0,0);
  534. KeyActive := nil;
  535. bNeedRender := true;
  536. end
  537. else
  538. if not gActiveParent^.bActive then
  539. begin
  540. wSetTopMost(gActiveParent);
  541. bNeedRender := true;
  542. end;
  543. if KeyActive <> nil then wPostMessage(KeyActive,WM_LOSTFOCUS,0,0);
  544. KeyActive := gActiveWindow;
  545. wGlobalToClient(gActiveWindow,aP.X,aP.Y,@nP);
  546. wPostMessage(gActiveWindow,WM_LBUTTONDOWN,0,UINT32(nP.Y) shl 16 + nP.X);
  547. if gwSize or gwMove then
  548. begin
  549. gReSize := gwSize;
  550. if not gResize then gMove := gwMove;
  551. gSize:=gActiveParent^.Pos;
  552. SetWriteMode(XORPut);
  553. SetColor(White);
  554. HideMouse;
  555. with gSize do
  556. Rectangle(A.X,A.Y,A.X+B.X-1,A.Y+B.Y-1);
  557. ShowMouse;
  558. SetWriteMode(NormalPut);
  559. end;
  560. end;
  561. if ((gMouseState^.Buttons AND 1) = 0) AND
  562. ((gLastMouseState.Buttons AND 1) = 1) then
  563. begin
  564. if gActiveParent <> nil then
  565. begin
  566. wGlobalToClient(gActiveWindow,aP.X,aP.Y,@nP);
  567. wPostMessage(gActiveWindow,WM_LBUTTONUP,0,UINT32(nP.Y) shl 16 + nP.X);
  568. end;
  569. if gResize or gMove then
  570. begin
  571. SetWriteMode(XORPut);
  572. SetColor(White);
  573. HideMouse;
  574. with gSize do
  575. Rectangle(A.X,A.Y,A.X+B.X-1,A.Y+B.Y-1);
  576. SetWriteMode(NormalPut);
  577. ShowMouse;
  578. gActiveParent^.Pos := gSize;
  579. wPosTitleButtons(gActiveParent);
  580. wPostMessage(gActiveParent,WM_SIZE,UINT32(gSize.A),UINT32(gSize.B));
  581. bNeedRender := true;
  582. gResize := false;
  583. gMove := false;
  584. end;
  585. end;
  586. if ((gMouseState^.Buttons AND 2) = 2) AND
  587. ((gLastMouseState.Buttons AND 2) = 0) then
  588. begin
  589. if (gActiveParent = nil) and (TopMost^.zOrder <> nil) then
  590. begin
  591. TopMost^.zOrder^.bActive := false;
  592. KeyActive := nil;
  593. bNeedRender := true;
  594. end
  595. else
  596. if not gActiveParent^.bActive then
  597. begin
  598. wSetTopMost(gActiveParent);
  599. bNeedRender := true;
  600. end;
  601. KeyActive := gActiveWindow;
  602. wGlobalToClient(gActiveWindow,aP.X,aP.Y,@nP);
  603. wPostMessage(gActiveWindow,WM_RBUTTONDOWN,0,UINT32(nP.Y) shl 16 + nP.X);
  604. end;
  605. if ((gMouseState^.Buttons AND 2) = 0) AND
  606. ((gLastMouseState.Buttons AND 2) = 2) AND
  607. (gActiveParent <> nil) then
  608. begin
  609. wGlobalToClient(gActiveWindow,aP.X,aP.Y,@nP);
  610. wPostMessage(gActiveWindow,WM_RBUTTONUP,0,UINT32(nP.Y) shl 16 + nP.X);
  611. end;
  612. if ((gMouseState^.Buttons AND 4) = 4) AND
  613. ((gLastMouseState.Buttons AND 4) = 0) then
  614. begin
  615. if (gActiveParent = nil) and (TopMost^.zOrder <> nil) then
  616. begin
  617. TopMost^.zOrder^.bActive := false;
  618. KeyActive := nil;
  619. bNeedRender := true;
  620. end
  621. else
  622. if not gActiveParent^.bActive then
  623. begin
  624. wSetTopMost(gActiveParent);
  625. bNeedRender := true;
  626. end;
  627. KeyActive := gActiveWindow;
  628. wGlobalToClient(gActiveWindow,aP.X,aP.Y,@nP);
  629. wPostMessage(gActiveWindow,WM_MBUTTONDOWN,0,UINT32(nP.Y) shl 16 + nP.X);
  630. end;
  631. if ((gMouseState^.Buttons AND 4) = 0) AND
  632. ((gLastMouseState.Buttons AND 4) = 4) AND
  633. (gActiveParent <> nil) then
  634. begin
  635. wGlobalToClient(gActiveWindow,aP.X,aP.Y,@nP);
  636. wPostMessage(gActiveWindow,WM_MBUTTONUP,0,UINT32(nP.Y) shl 16 + nP.X);
  637. end;
  638. gLastMouseState := gMouseState^;
  639. end;
  640. {-------------------------------------------------------}
  641. Function wInitKeyboard:UInt16;
  642. begin
  643. AllKeys := InitKeyboard;
  644. KeyActive := nil;
  645. wInitKeyboard := ERR_OK;
  646. end;
  647. {-------------------------------------------------------}
  648. Function wInitMouse:UInt16;
  649. begin
  650. gActiveParent := nil;
  651. gActiveWindow := nil;
  652. if InitMouse(gMouseState) then
  653. begin
  654. wInitMouse := ERR_OK;
  655. ShowMouse;
  656. end
  657. else
  658. wINitMouse := ERR_ERROR;
  659. end;
  660. Procedure wLoadCursors;
  661. var
  662. i : UINT16;
  663. F : FILE;
  664. begin
  665. Assign(F,'cursors.cur');
  666. {$I-}
  667. Reset(F,1);
  668. if IOResult <> 0 then Exit;
  669. {$I+}
  670. BlockRead(F,CursorCnt,2);
  671. if CurSorCnt <> 0 then
  672. begin
  673. AllCursors := Alloc(SizeOf(TCursor)*CursorCNT);
  674. for i := 0 to CursorCnt-1 do BlockRead(F,AllCursors^[i],Sizeof(TCursor));
  675. end;
  676. Close(F);
  677. end;
  678. Var
  679. ScrMaxX, ScrMaxY : INT16;
  680. grDriver, grMode : INT16;
  681. Function wInitGraph:UInt16;
  682. begin
  683. grDriver := Detect;
  684. grMode := 0;
  685. {$L EGAVGA.OBJ}
  686. RegisterBGIDriver(@EGAVGADriver);
  687. InitGraph(grDriver,grMode,'');
  688. if GraphResult = GrOK then
  689. begin
  690. ScrMaxX := GetMaxX;
  691. ScrMaxY := GetMaxY;
  692. ClearDevice;
  693. wLoadCursors;
  694. wInitGraph := ERR_OK;
  695. end
  696. else
  697. wInitGraph := ERR_ERROR;
  698. end;
  699. Function wDestroyWindow(Wnd:PWindow):INT16;
  700. var
  701. c : PWindow;
  702. q : PMessageList;
  703. begin
  704. c:=AllWindows;
  705. while (c^.Next <> nil) and (c^.Next <> wnd) do c:=c^.next;
  706. if c^.next = wnd then c^.Next:=wnd^.next;
  707. if wnd^.Parent <> nil then
  708. begin
  709. c:=wnd^.Parent^.Child;
  710. while (c^.Brother <> nil) and (c^.Brother <> wnd) do c:=c^.Brother;
  711. if c^.Brother = wnd then c^.Brother := wnd^.Brother;
  712. end
  713. else
  714. begin
  715. c:=TopMost;
  716. while (c^.zOrder <> nil) and (c^.zOrder <> wnd) do c:=c^.zOrder;
  717. if c^.zOrder = wnd then c^.zOrder:=wnd^.zOrder;
  718. end;
  719. c:=Wnd^.Child^.Brother;
  720. while c <> nil do
  721. begin
  722. c^.Parent := nil;
  723. wSendMessage(c,WM_DESTROY,0,0);
  724. c := C^.Brother;
  725. end;
  726. with wnd^ do
  727. begin
  728. FreeMem(Title,ord(Title^[0])+1);
  729. Dispose(Palette);
  730. while Queue <> nil do
  731. begin
  732. q := Queue^.Next;
  733. Dispose(Queue);
  734. Queue := q;
  735. end;
  736. end;
  737. if gActiveParent = wnd then
  738. gActiveParent := nil;
  739. if gActiveWindow = wnd then
  740. gActiveWindow := nil;
  741. if KeyActive = wnd then
  742. KeyActive := nil;
  743. Dispose(Wnd);
  744. end;
  745. Function wDoneKeyboard:UInt16;
  746. begin
  747. CloseKeyboard;
  748. wDoneKeyBoard := ERR_OK;
  749. end;
  750. Function wDoneMouse:UInt16;
  751. begin
  752. DoneMouse;
  753. wDoneMouse := ERR_OK;
  754. end;
  755. Function wDoneGraph:UInt16;
  756. begin
  757. CloseGraph;
  758. wDoneGraph := ERR_OK;
  759. end;
  760. var
  761. gClosePressed, gMinPressed, gMaxPressed : boolean;
  762. Function CloseButtonProc(ahWnd:HWND;aMsg,wParam,lParam:UINT32):UINT32;far;
  763. var
  764. c1,c2,bs:UINT8;
  765. ps : LPPAINTSTRUCT;
  766. box : RECT;
  767. begin
  768. case aMsg of
  769. WM_CREATE:
  770. gClosePressed := false;
  771. WM_DESTROY:
  772. begin
  773. PostQuitMessage(ahWnd);
  774. end;
  775. WM_LBUTTONDOWN:
  776. begin
  777. gClosePressed := true;
  778. PostMessage(ahWnd,WM_PAINT,0,0);
  779. end;
  780. WM_LBUTTONUP:
  781. begin
  782. PostMessage(GetParent(ahWnd),WM_DESTROY,0,0);
  783. PostMessage(ahWnd,WM_PAINT,0,0);
  784. gClosePressed := false;
  785. end;
  786. WM_PAINT:
  787. begin
  788. ps := BeginPaint(ahWnd);
  789. wSetBGColor(ps,GlobalPalette.ThreeDColor1);
  790. wSetStyle(ps,SolidFill);
  791. wSetColor(ps,GlobalPalette.ThreeDColor2);
  792. GetClientRect(ahWnd,@box);
  793. wBar(ps,0,0,box.b.x,box.b.y);
  794. if gClosePressed then
  795. begin c1:=Black;c2:=White;bs:=1;end
  796. else
  797. begin c2:=Black;c1:=White;bs:=0;end;
  798. wLine(ps,2+bs, 2+bs, box.b.x-2+bs,box.b.y-2+bs);
  799. wLine(ps,box.b.x-2+bs, 2+bs, 2+bs, box.b.y-2+bs);
  800. wSetColor(ps,c1);
  801. wLine(ps,0,0,Box.B.X-1,0);
  802. wLine(ps,0,0,0,Box.B.Y-1);
  803. wSetColor(ps,c2);
  804. wLine(ps,0,Box.B.Y,Box.B.X-1,Box.B.Y);
  805. wLine(ps,Box.B.X,0,Box.B.X,Box.B.Y);
  806. EndPaint(ps);
  807. end;
  808. end;
  809. end;
  810. Function MinButtonProc(ahWnd:HWND;aMsg,wParam,lParam:UINT32):UINT32;far;
  811. var
  812. c1,c2,bs:UINT8;
  813. ps : LPPAINTSTRUCT;
  814. box : RECT;
  815. begin
  816. case aMsg of
  817. WM_CREATE:
  818. gMinPressed := false;
  819. WM_DESTROY:
  820. begin
  821. PostQuitMessage(ahWnd);
  822. end;
  823. WM_LBUTTONDOWN:
  824. begin
  825. gMinPressed := true;
  826. PostMessage(ahWnd,WM_PAINT,0,0);
  827. end;
  828. WM_LBUTTONUP:
  829. begin
  830. PostMessage(GetParent(ahWnd),WM_MINIMIZE,0,0);
  831. PostMessage(ahWnd,WM_PAINT,0,0);
  832. gMinPressed := false;
  833. end;
  834. WM_PAINT:
  835. begin
  836. ps := BeginPaint(ahWnd);
  837. wSetBGColor(ps,GlobalPalette.ThreeDColor1);
  838. wSetStyle(ps,SolidFill);
  839. wSetColor(ps,GlobalPalette.ThreeDColor2);
  840. GetClientRect(ahWnd,@box);
  841. wBar(ps,0,0,box.b.x,box.b.y);
  842. if gMinPressed then begin c1:=Black;c2:=White;bs:=1;end
  843. else begin c2:=Black;c1:=White;bs:=0;end;
  844. wLine(ps, 2+bs, box.b.y-4+bs, box.b.x-2+bs, box.b.y-4+bs);
  845. wLine(ps, 2+bs, box.b.y-3+bs, box.b.x-2+bs, box.b.y-3+bs);
  846. wSetColor(ps,c1);
  847. wLine(ps,0,0,Box.B.X-1,0);
  848. wLine(ps,0,0,0,Box.B.Y-1);
  849. wSetColor(ps,c2);
  850. wLine(ps,0,Box.B.Y,Box.B.X-1,Box.B.Y);
  851. wLine(ps,Box.B.X,1,Box.B.X,Box.B.Y);
  852. EndPaint(ps);
  853. end;
  854. end;
  855. end;
  856. Function MaxButtonProc(ahWnd:HWND;aMsg,wParam,lParam:UINT32):UINT32;far;
  857. var
  858. c1,c2,bs:UINT8;
  859. ps : LPPAINTSTRUCT;
  860. box : RECT;
  861. begin
  862. case aMsg of
  863. WM_CREATE:
  864. gMaxPressed := false;
  865. WM_DESTROY:
  866. begin
  867. PostQuitMessage(ahWnd);
  868. end;
  869. WM_LBUTTONDOWN:
  870. begin
  871. gMaxPressed := true;
  872. PostMessage(ahWnd,WM_PAINT,0,0);
  873. end;
  874. WM_LBUTTONUP:
  875. begin
  876. PostMessage(GetParent(ahWnd),WM_MAXIMIZE,0,0);
  877. PostMessage(ahWnd,WM_PAINT,0,0);
  878. gMaxPressed := false;
  879. end;
  880. WM_PAINT:
  881. begin
  882. ps := BeginPaint(ahWnd);
  883. wSetBGColor(ps,GlobalPalette.ThreeDColor1);
  884. wSetStyle(ps,SolidFill);
  885. wSetColor(ps,GlobalPalette.ThreeDColor2);
  886. GetClientRect(ahWnd,@box);
  887. if gMaxPressed then
  888. begin
  889. c1:=Black;c2:=White;
  890. bs:=1;
  891. end
  892. else
  893. begin
  894. c2:=Black;c1:=White;
  895. bs:=0;
  896. end;
  897. wBar(ps,0,0,box.b.x,box.b.y);
  898. wRectangle(ps,2+bs,2+bs,box.b.x-2+bs,box.b.y-2+bs);
  899. wLine(ps,3+bs,3+bs,box.b.x-3+bs,3+bs);
  900. wSetColor(ps,c1);
  901. wLine(ps,0,0,Box.B.X-1,0);
  902. wLine(ps,0,0,0,Box.B.Y-1);
  903. wSetColor(ps,c2);
  904. wLine(ps,0,Box.B.Y,Box.B.X-1,Box.B.Y);
  905. wLine(ps,Box.B.X,0,Box.B.X,Box.B.Y);
  906. EndPaint(ps);
  907. end;
  908. end;
  909. end;
  910. const
  911. gStartTaskButton : INT16 = 100;
  912. gTimeSize : INT16 = 100;
  913. Function TaskbarProc(ahWnd:HWND;aMsg,wParam,lParam:UINT32):UINT32;far;
  914. var
  915. c1,c2,bs:UINT8;
  916. ps : LPPAINTSTRUCT;
  917. box : RECT;
  918. begin
  919. case aMsg of
  920. WM_DESTROY:
  921. begin
  922. PostQuitMessage(ahWnd);
  923. end;
  924. WM_LBUTTONDOWN:
  925. begin
  926. gMaxPressed := true;
  927. PostMessage(ahWnd,WM_PAINT,0,0);
  928. end;
  929. WM_LBUTTONUP:
  930. begin
  931. PostMessage(GetParent(ahWnd),WM_MAXIMIZE,0,0);
  932. PostMessage(ahWnd,WM_PAINT,0,0);
  933. gMaxPressed := false;
  934. end;
  935. WM_PAINT:
  936. begin
  937. ps := BeginPaint(ahWnd);
  938. wSetBGColor(ps,GlobalPalette.ThreeDColor1);
  939. wSetStyle(ps,SolidFill);
  940. wSetColor(ps,GlobalPalette.ThreeDColor2);
  941. GetClientRect(ahWnd,@box);
  942. if gMaxPressed then
  943. begin
  944. c1:=Black;c2:=White;
  945. bs:=1;
  946. end
  947. else
  948. begin
  949. c2:=Black;c1:=White;
  950. bs:=0;
  951. end;
  952. wBar(ps,0,0,box.b.x,box.b.y);
  953. wRectangle(ps,2+bs,2+bs,box.b.x-2+bs,box.b.y-2+bs);
  954. wLine(ps,3+bs,3+bs,box.b.x-3+bs,3+bs);
  955. wSetColor(ps,c1);
  956. wLine(ps,0,0,Box.B.X-1,0);
  957. wLine(ps,0,0,0,Box.B.Y-1);
  958. wSetColor(ps,c2);
  959. wLine(ps,0,Box.B.Y,Box.B.X-1,Box.B.Y);
  960. wLine(ps,Box.B.X,0,Box.B.X,Box.B.Y);
  961. EndPaint(ps);
  962. end;
  963. end;
  964. end;
  965. Procedure wInitTitleButtons;
  966. begin
  967. RegisterClass('CLOSEBUTTON',CloseButtonProc);
  968. RegisterClass('MINBUTTON',MinButtonProc);
  969. RegisterClass('MAXBUTTON',MaxButtonProc);
  970. end;
  971. {-----------------------------------}