From 803cd75a59dbaaca42c25c763bdcbdfc3089e557 Mon Sep 17 00:00:00 2001 From: Wizzup? Date: Sun, 3 Jan 2010 03:45:02 +0000 Subject: [PATCH] Reworked input.pas to use TMWindow directly rather than TClient. Added TargetValid to TMWindow. Appropriate changes in TClient. Colourpicker now returns coordinates relative to the set Window. If the window doesn't exist, it will default to desktop. git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@364 3f818213-9676-44b0-a9b4-5e4c4e03d09d --- Projects/SAMufasaGUI/project1.lpi | 188 ++++++++++++++++-------------- Projects/SAMufasaGUI/testunit.lfm | 4 +- Projects/SAMufasaGUI/testunit.lrs | 6 +- Projects/SAMufasaGUI/testunit.pas | 7 +- Units/MMLAddon/colourpicker.pas | 27 ++++- Units/MMLCore/client.pas | 2 +- Units/MMLCore/input.pas | 40 ++++--- Units/MMLCore/window.pas | 30 ++++- 8 files changed, 181 insertions(+), 123 deletions(-) diff --git a/Projects/SAMufasaGUI/project1.lpi b/Projects/SAMufasaGUI/project1.lpi index 3495290..70af426 100644 --- a/Projects/SAMufasaGUI/project1.lpi +++ b/Projects/SAMufasaGUI/project1.lpi @@ -10,7 +10,7 @@ <UseXPManifest Value="True"/> - <ActiveEditorIndexAtStart Value="7"/> + <ActiveEditorIndexAtStart Value="5"/> </General> <VersionInfo> <ProjectVersion Value=""/> @@ -137,9 +137,9 @@ <HasResources Value="True"/> <ResourceBaseClass Value="Form"/> <UnitName Value="TestUnit"/> - <CursorPos X="98" Y="424"/> - <TopLine Value="417"/> - <EditorIndex Value="7"/> + <CursorPos X="64" Y="505"/> + <TopLine Value="462"/> + <EditorIndex Value="8"/> <UsageCount Value="202"/> <Loaded Value="True"/> </Unit13> @@ -194,8 +194,8 @@ <Filename Value="../../Units/MMLCore/client.pas"/> <IsPartOfProject Value="True"/> <UnitName Value="Client"/> - <CursorPos X="27" Y="49"/> - <TopLine Value="9"/> + <CursorPos X="35" Y="64"/> + <TopLine Value="46"/> <EditorIndex Value="0"/> <UsageCount Value="201"/> <Loaded Value="True"/> @@ -227,8 +227,8 @@ <Filename Value="../../Units/MMLCore/window.pas"/> <IsPartOfProject Value="True"/> <UnitName Value="Window"/> - <CursorPos X="1" Y="208"/> - <TopLine Value="188"/> + <CursorPos X="68" Y="306"/> + <TopLine Value="287"/> <EditorIndex Value="5"/> <UsageCount Value="201"/> <Loaded Value="True"/> @@ -252,9 +252,11 @@ <Unit28> <Filename Value="../../Units/MMLCore/input.pas"/> <UnitName Value="Input"/> - <CursorPos X="71" Y="274"/> - <TopLine Value="242"/> - <UsageCount Value="84"/> + <CursorPos X="17" Y="286"/> + <TopLine Value="266"/> + <EditorIndex Value="11"/> + <UsageCount Value="85"/> + <Loaded Value="True"/> </Unit28> <Unit29> <Filename Value="../../Units/MMLCore/finder.pas"/> @@ -282,9 +284,9 @@ <Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/> <IsPartOfProject Value="True"/> <UnitName Value="mmlpsthread"/> - <CursorPos X="79" Y="271"/> - <TopLine Value="251"/> - <EditorIndex Value="6"/> + <CursorPos X="32" Y="182"/> + <TopLine Value="207"/> + <EditorIndex Value="7"/> <UsageCount Value="202"/> <Loaded Value="True"/> </Unit32> @@ -573,7 +575,7 @@ <UnitName Value="plugins"/> <CursorPos X="40" Y="49"/> <TopLine Value="55"/> - <EditorIndex Value="10"/> + <EditorIndex Value="12"/> <UsageCount Value="200"/> <Loaded Value="True"/> </Unit75> @@ -661,9 +663,9 @@ <Filename Value="../../Units/MMLAddon/colourpicker.pas"/> <IsPartOfProject Value="True"/> <UnitName Value="colourpicker"/> - <CursorPos X="58" Y="184"/> - <TopLine Value="167"/> - <EditorIndex Value="9"/> + <CursorPos X="76" Y="115"/> + <TopLine Value="101"/> + <EditorIndex Value="10"/> <UsageCount Value="201"/> <Loaded Value="True"/> </Unit88> @@ -1689,7 +1691,7 @@ <UnitName Value="about"/> <CursorPos X="119" Y="11"/> <TopLine Value="4"/> - <UsageCount Value="184"/> + <UsageCount Value="185"/> </Unit235> <Unit236> <Filename Value="../../Units/MMLAddon/PSInc/Wrappers/file.inc"/> @@ -1703,7 +1705,7 @@ <UnitName Value="internets"/> <CursorPos X="5" Y="14"/> <TopLine Value="1"/> - <UsageCount Value="178"/> + <UsageCount Value="179"/> </Unit237> <Unit238> <Filename Value="debugimageform.pas"/> @@ -1712,7 +1714,7 @@ <UnitName Value="debugimageform"/> <CursorPos X="20" Y="1"/> <TopLine Value="1"/> - <UsageCount Value="165"/> + <UsageCount Value="166"/> </Unit238> <Unit239> <Filename Value="debugimage.pas"/> @@ -1722,7 +1724,7 @@ <UnitName Value="debugimage"/> <CursorPos X="66" Y="17"/> <TopLine Value="1"/> - <UsageCount Value="164"/> + <UsageCount Value="165"/> </Unit239> <Unit240> <Filename Value="debugimage.lrs"/> @@ -1844,7 +1846,7 @@ <UnitName Value="framefunctionlist"/> <CursorPos X="56" Y="9"/> <TopLine Value="54"/> - <UsageCount Value="85"/> + <UsageCount Value="86"/> </Unit257> <Unit258> <Filename Value="../../../usr/local/share/lazarus/lcl/comctrls.pp"/> @@ -1899,7 +1901,7 @@ <UnitName Value="simpleanalyzer"/> <CursorPos X="52" Y="104"/> <TopLine Value="193"/> - <UsageCount Value="72"/> + <UsageCount Value="73"/> </Unit265> <Unit266> <Filename Value="../../Units/Misc/mPasLex.pas"/> @@ -1931,9 +1933,11 @@ <Unit270> <Filename Value="../../../../Documents/fpc/packages/x11/src/xlib.pp"/> <UnitName Value="xlib"/> - <CursorPos X="4" Y="225"/> - <TopLine Value="207"/> - <UsageCount Value="8"/> + <CursorPos X="85" Y="1622"/> + <TopLine Value="1604"/> + <EditorIndex Value="6"/> + <UsageCount Value="10"/> + <Loaded Value="True"/> </Unit270> <Unit271> <Filename Value="../../../../Documents/fpc/packages/fcl-net/src/httpclient.pp"/> @@ -1981,8 +1985,8 @@ <UnitName Value="updater"/> <CursorPos X="10" Y="201"/> <TopLine Value="190"/> - <EditorIndex Value="11"/> - <UsageCount Value="45"/> + <EditorIndex Value="13"/> + <UsageCount Value="46"/> <Loaded Value="True"/> </Unit277> <Unit278> @@ -1993,8 +1997,8 @@ <UnitName Value="updateform"/> <CursorPos X="95" Y="141"/> <TopLine Value="104"/> - <EditorIndex Value="8"/> - <UsageCount Value="40"/> + <EditorIndex Value="9"/> + <UsageCount Value="41"/> <Loaded Value="True"/> </Unit278> <Unit279> @@ -2070,7 +2074,7 @@ <CursorPos X="15" Y="899"/> <TopLine Value="870"/> <EditorIndex Value="2"/> - <UsageCount Value="12"/> + <UsageCount Value="13"/> <Loaded Value="True"/> </Unit289> <Unit290> @@ -2098,123 +2102,127 @@ <UsageCount Value="10"/> </Unit293> </Units> - <JumpHistory Count="29" HistoryIndex="28"> + <JumpHistory Count="30" HistoryIndex="29"> <Position1> - <Filename Value="testunit.pas"/> - <Caret Line="276" Column="31" TopLine="258"/> + <Filename Value="updateform.pas"/> + <Caret Line="126" Column="40" TopLine="100"/> </Position1> <Position2> <Filename Value="testunit.pas"/> - <Caret Line="429" Column="34" TopLine="411"/> + <Caret Line="58" Column="9" TopLine="38"/> </Position2> <Position3> - <Filename Value="testunit.pas"/> - <Caret Line="333" Column="1" TopLine="315"/> + <Filename Value="../../Units/MMLAddon/colourpicker.pas"/> + <Caret Line="57" Column="18" TopLine="35"/> </Position3> <Position4> - <Filename Value="testunit.pas"/> - <Caret Line="105" Column="83" TopLine="93"/> + <Filename Value="../../Units/MMLCore/input.pas"/> + <Caret Line="269" Column="33" TopLine="243"/> </Position4> <Position5> - <Filename Value="testunit.pas"/> - <Caret Line="276" Column="31" TopLine="258"/> + <Filename Value="../../Units/MMLCore/input.pas"/> + <Caret Line="293" Column="27" TopLine="267"/> </Position5> <Position6> - <Filename Value="testunit.pas"/> - <Caret Line="436" Column="52" TopLine="416"/> + <Filename Value="../../Units/MMLCore/input.pas"/> + <Caret Line="320" Column="42" TopLine="301"/> </Position6> <Position7> - <Filename Value="testunit.pas"/> - <Caret Line="275" Column="54" TopLine="258"/> + <Filename Value="../../Units/MMLCore/client.pas"/> + <Caret Line="49" Column="27" TopLine="9"/> </Position7> <Position8> - <Filename Value="testunit.pas"/> - <Caret Line="428" Column="5" TopLine="424"/> + <Filename Value="../../Units/MMLAddon/colourpicker.pas"/> + <Caret Line="257" Column="36" TopLine="244"/> </Position8> <Position9> - <Filename Value="updateform.pas"/> - <Caret Line="52" Column="30" TopLine="34"/> + <Filename Value="testunit.pas"/> + <Caret Line="433" Column="80" TopLine="417"/> </Position9> <Position10> - <Filename Value="testunit.pas"/> - <Caret Line="277" Column="31" TopLine="258"/> + <Filename Value="../../Units/MMLAddon/colourpicker.pas"/> + <Caret Line="85" Column="49" TopLine="61"/> </Position10> <Position11> - <Filename Value="updateform.pas"/> - <Caret Line="58" Column="5" TopLine="41"/> + <Filename Value="../../Units/MMLAddon/colourpicker.pas"/> + <Caret Line="86" Column="32" TopLine="68"/> </Position11> <Position12> - <Filename Value="updateform.pas"/> - <Caret Line="58" Column="9" TopLine="41"/> + <Filename Value="../../Units/MMLAddon/colourpicker.pas"/> + <Caret Line="87" Column="34" TopLine="68"/> </Position12> <Position13> - <Filename Value="updateform.pas"/> - <Caret Line="57" Column="6" TopLine="41"/> + <Filename Value="../../Units/MMLAddon/colourpicker.pas"/> + <Caret Line="86" Column="43" TopLine="68"/> </Position13> <Position14> - <Filename Value="testunit.pas"/> - <Caret Line="445" Column="30" TopLine="411"/> + <Filename Value="../../Units/MMLAddon/colourpicker.pas"/> + <Caret Line="125" Column="42" TopLine="101"/> </Position14> <Position15> - <Filename Value="testunit.pas"/> - <Caret Line="425" Column="3" TopLine="423"/> + <Filename Value="../../Units/MMLAddon/colourpicker.pas"/> + <Caret Line="89" Column="1" TopLine="72"/> </Position15> <Position16> - <Filename Value="updateform.pas"/> - <Caret Line="57" Column="70" TopLine="34"/> + <Filename Value="../../Units/MMLCore/window.pas"/> + <Caret Line="271" Column="26" TopLine="248"/> </Position16> <Position17> - <Filename Value="updateform.pas"/> - <Caret Line="58" Column="70" TopLine="34"/> + <Filename Value="../../Units/MMLCore/window.pas"/> + <Caret Line="274" Column="20" TopLine="248"/> </Position17> <Position18> - <Filename Value="updateform.pas"/> - <Caret Line="55" Column="7" TopLine="55"/> + <Filename Value="../../Units/MMLAddon/colourpicker.pas"/> + <Caret Line="120" Column="30" TopLine="101"/> </Position18> <Position19> - <Filename Value="updateform.pas"/> - <Caret Line="9" Column="27" TopLine="1"/> + <Filename Value="../../Units/MMLCore/window.pas"/> + <Caret Line="74" Column="33" TopLine="56"/> </Position19> <Position20> - <Filename Value="../../Units/MMLAddon/updater.pas"/> - <Caret Line="95" Column="15" TopLine="78"/> + <Filename Value="../../Units/MMLCore/window.pas"/> + <Caret Line="89" Column="94" TopLine="78"/> </Position20> <Position21> - <Filename Value="../../Units/MMLAddon/updater.pas"/> - <Caret Line="70" Column="46" TopLine="34"/> + <Filename Value="../../Units/MMLCore/window.pas"/> + <Caret Line="216" Column="16" TopLine="191"/> </Position21> <Position22> - <Filename Value="../../Units/MMLAddon/updater.pas"/> - <Caret Line="57" Column="82" TopLine="39"/> + <Filename Value="../../Units/MMLCore/window.pas"/> + <Caret Line="60" Column="37" TopLine="42"/> </Position22> <Position23> - <Filename Value="../../Units/MMLAddon/updater.pas"/> - <Caret Line="70" Column="34" TopLine="39"/> + <Filename Value="../../Units/MMLCore/window.pas"/> + <Caret Line="143" Column="41" TopLine="125"/> </Position23> <Position24> - <Filename Value="../../Units/MMLAddon/updater.pas"/> - <Caret Line="57" Column="70" TopLine="39"/> + <Filename Value="../../Units/MMLCore/window.pas"/> + <Caret Line="216" Column="19" TopLine="198"/> </Position24> <Position25> - <Filename Value="../../Units/MMLAddon/updater.pas"/> - <Caret Line="37" Column="49" TopLine="28"/> + <Filename Value="../../Units/MMLCore/window.pas"/> + <Caret Line="304" Column="19" TopLine="286"/> </Position25> <Position26> - <Filename Value="../../Units/MMLAddon/updater.pas"/> - <Caret Line="198" Column="33" TopLine="180"/> + <Filename Value="../../Units/MMLCore/window.pas"/> + <Caret Line="355" Column="56" TopLine="337"/> </Position26> <Position27> - <Filename Value="../../Units/MMLAddon/updater.pas"/> - <Caret Line="35" Column="12" TopLine="10"/> + <Filename Value="../../Units/MMLCore/window.pas"/> + <Caret Line="477" Column="13" TopLine="458"/> </Position27> <Position28> - <Filename Value="updateform.pas"/> - <Caret Line="126" Column="40" TopLine="100"/> + <Filename Value="testunit.pas"/> + <Caret Line="12" Column="97" TopLine="1"/> </Position28> <Position29> - <Filename Value="testunit.pas"/> - <Caret Line="58" Column="9" TopLine="38"/> + <Filename Value="../../Units/MMLCore/input.pas"/> + <Caret Line="286" Column="17" TopLine="266"/> </Position29> + <Position30> + <Filename Value="../../Units/MMLCore/window.pas"/> + <Caret Line="61" Column="36" TopLine="43"/> + </Position30> </JumpHistory> </ProjectOptions> <CompilerOptions> diff --git a/Projects/SAMufasaGUI/testunit.lfm b/Projects/SAMufasaGUI/testunit.lfm index dd72f16..881773f 100644 --- a/Projects/SAMufasaGUI/testunit.lfm +++ b/Projects/SAMufasaGUI/testunit.lfm @@ -1,7 +1,7 @@ object Form1: TForm1 - Left = 472 + Left = 273 Height = 557 - Top = 201 + Top = 233 Width = 734 ActiveControl = ScriptPanel Caption = 'THA FUKING MUFASA' diff --git a/Projects/SAMufasaGUI/testunit.lrs b/Projects/SAMufasaGUI/testunit.lrs index 7913dbd..54e2a7f 100644 --- a/Projects/SAMufasaGUI/testunit.lrs +++ b/Projects/SAMufasaGUI/testunit.lrs @@ -1,9 +1,9 @@ { This is an automatically generated lazarus resource file } LazarusResources.Add('TForm1','FORMDATA',[ - 'TPF0'#6'TForm1'#5'Form1'#4'Left'#3#216#1#6'Height'#3'-'#2#3'Top'#3#201#0#5'W' - +'idth'#3#222#2#13'ActiveControl'#7#11'ScriptPanel'#7'Caption'#6#17'THA FUKIN' - +'G MUFASA'#12'ClientHeight'#3#20#2#11'ClientWidth'#3#222#2#10'KeyPreview'#9#4 + 'TPF0'#6'TForm1'#5'Form1'#4'Left'#3#17#1#6'Height'#3'-'#2#3'Top'#3#233#0#5'Wi' + +'dth'#3#222#2#13'ActiveControl'#7#11'ScriptPanel'#7'Caption'#6#17'THA FUKING' + +' MUFASA'#12'ClientHeight'#3#20#2#11'ClientWidth'#3#222#2#10'KeyPreview'#9#4 +'Menu'#7#9'MainMenu1'#7'OnClose'#7#9'FormClose'#8'OnCreate'#7#10'FormCreate' +#9'OnDestroy'#7#11'FormDestroy'#10'OnShortCut'#7#13'FormShortCuts'#8'Positio' +'n'#7#14'poScreenCenter'#10'LCLVersion'#6#6'0.9.29'#7'Visible'#9#0#8'TToolBa' diff --git a/Projects/SAMufasaGUI/testunit.pas b/Projects/SAMufasaGUI/testunit.pas index b44b0f6..1d13767 100644 --- a/Projects/SAMufasaGUI/testunit.pas +++ b/Projects/SAMufasaGUI/testunit.pas @@ -41,7 +41,7 @@ uses ocr, updateform; const - SimbaVersion = 363; + SimbaVersion = 364; type @@ -501,6 +501,7 @@ begin // only copies the current set window handle. ScriptThread.Client.MWindow.SetWindow(Self.Window); + // Copy our current fonts if not assigned(Self.OCR_Fonts) then begin @@ -509,10 +510,6 @@ begin end; ScriptThread.Client.MOCR.SetFonts(OCR_Fonts.GetFonts); -// writeln(IncludeTrailingPathDelimiter('TestUnit: OCR Path... ' + - {ExpandFileName(MainDir +DS + '..' + DS + '..' + ds)) + DS + 'Fonts' + DS); - ScriptThread.Client.MOCR.InitTOCR(IncludeTrailingPathDelimiter(ExpandFileName(MainDir +DS + '..' + DS + '..' + ds)) + 'Fonts' + DS, false);} - ScriptThread.OnTerminate:=@ScriptThreadTerminate; ScriptState:= ss_Running; //Lets run it! diff --git a/Units/MMLAddon/colourpicker.pas b/Units/MMLAddon/colourpicker.pas index 11bee1f..5068a5e 100644 --- a/Units/MMLAddon/colourpicker.pas +++ b/Units/MMLAddon/colourpicker.pas @@ -30,7 +30,7 @@ interface uses Classes, SysUtils, LCLIntf,LCLType,InterfaceBase,Forms,Controls,ExtCtrls, Graphics, - Window,MufasaTypes, colourhistory,bitmaps + Window,MufasaTypes, colourhistory,bitmaps,input {$IFNDEF PICKER_CLIENT} {$IFDEF LINUX} @@ -55,6 +55,9 @@ type // Will give us CopyClientToBitmap Window: TMWindow; + // Created and freed in Pick. + Input: TMInput; + { Form components } ScreenForm, InfoForm : TForm; ImageMain, ImageInfo: TImage; @@ -77,8 +80,10 @@ type implementation constructor TMColorPicker.Create(aWindow: TMWindow); + begin inherited Create; + Self.Window := aWindow; end; @@ -107,8 +112,21 @@ var {$ENDIF} bmp: TMufasaBitmap; + InputWindow: TMWindow; + begin { Disable both of the color pick buttons } + + + InputWindow := TMWindow.Create; + InputWindow.SetWindow(Self.Window); + + { If the Window is not valid, set it to the desktop } + if not InputWindow.TargetValid then + InputWindow.SetDesktop; + + Input := TMInput.Create(InputWindow); + Application.MainForm.Enabled := False; ColourHistoryForm.Enabled := False; @@ -232,6 +250,9 @@ begin InfoForm.Free; ScreenForm.Free; + Input.Free; + InputWindow.Free; + { Re-enable the color pick buttons } Application.MainForm.Enabled := True; ColourHistoryForm.Enabled := True; @@ -244,8 +265,10 @@ var Data : TRetData; R : TRect; px, py : Integer; + MouseX, MouseY: Integer; begin { Move the info form } + Input.GetMousePos(MouseX, MouseY); InfoForm.Left := Mouse.CursorPos.X + 5; InfoForm.Top := Mouse.CursorPos.Y - 15; @@ -264,7 +287,7 @@ begin { Draw the cursor and color info } SetBkColor(InfoHandle, 14811135); - Text := Format('Pos: %d, %d', [x, y]); + Text := Format('Pos: %d, %d', [MouseX, MouseY]); R := Rect(5, 6, 114, 18); ExtTextOut(InfoHandle, 5, 3, ETO_OPAQUE, @R, pchar(text), length(text), nil); Text := Format('Color: %d', [Color]); diff --git a/Units/MMLCore/client.pas b/Units/MMLCore/client.pas index 6f78922..0ea0aea 100644 --- a/Units/MMLCore/client.pas +++ b/Units/MMLCore/client.pas @@ -61,7 +61,7 @@ begin inherited Create; MWindow := TMWindow.Create; - MInput := TMInput.Create(Self); + MInput := TMInput.Create(MWindow); MFiles := TMFiles.Create; MFinder := TMFinder.Create(Self); MBitmaps := TMBitmaps.Create(self); diff --git a/Units/MMLCore/input.pas b/Units/MMLCore/input.pas index ae76f81..0c04b3a 100644 --- a/Units/MMLCore/input.pas +++ b/Units/MMLCore/input.pas @@ -36,11 +36,11 @@ uses // do non silent keys/mouse with XTest / TKeyInput. {Later on we should use xdotool, as it allows silent input} {$ENDIF} - MMLKeyInput, lclintf,math; + MMLKeyInput, lclintf,math,window; type TMInput = class(TObject) - constructor Create(Client: TObject); + constructor Create(Window: TMWindow); destructor Destroy; override; procedure GetMousePos(out X, Y: Integer); @@ -65,7 +65,7 @@ type function IsMouseButtonDown(mType: TClickType): Boolean; public - Client: TObject; + Window: TMWindow; private // Not used yet. Silent: Boolean; @@ -77,7 +77,7 @@ type implementation uses - Client,{$IFDEF MSWINDOWS}windows, {$ENDIF}interfacebase,lcltype; + {$IFDEF MSWINDOWS}windows, {$ENDIF}interfacebase,lcltype; {$IFDEF MSWINDOWS} type @@ -127,10 +127,10 @@ const function SendInput(cInputs: UINT; var pInputs: TInput; cbSize: Integer): UINT; stdcall; external user32 name 'SendInput'; {$ENDIF} -constructor TMInput.Create(Client: TObject); +constructor TMInput.Create(Window: TMWindow); begin inherited Create; - Self.Client := Client; + Self.Window := Window; Self.KeyInput := TMMLKeyInput.Create; end; @@ -219,6 +219,7 @@ function TMInput.isKeyDown(key: Word): Boolean; {$ENDIF} begin {$IFDEF MSWINDOWS} + raise Exception.CreateFmt('IsKeyDown isn''t implemented yet on Windows', []); {$ELSE} raise Exception.CreateFmt('IsKeyDown isn''t implemented yet on Linux', []); @@ -259,13 +260,13 @@ var begin {$IFDEF MSWINDOWS} Windows.GetCursorPos(MousePoint); - GetWindowRect(TClient(Client).MWindow.TargetHandle,Rect); + GetWindowRect(Window.TargetHandle,Rect); x := MousePoint.x - Rect.Left; y := MousePoint.y - Rect.Top; {$ENDIF} {$IFDEF LINUX} Old_Handler := XSetErrorHandler(@MufasaXErrorHandler); - XQueryPointer(TClient(Client).MWindow.XDisplay,TClient(Client).MWindow.CurWindow,@root,@child,@b,@b,@x,@y,@xmask); + XQueryPointer(Window.XDisplay,Window.CurWindow,@root,@child,@b,@b,@x,@y,@xmask); XSetErrorHandler(Old_Handler); {$ENDIF} end; @@ -281,19 +282,20 @@ var {$ENDIF} w,h: integer; begin - TClient(Client).MWindow.GetDimensions(w, h); + // This may be a bit too much overhead. + Window.GetDimensions(w, h); if (x < 0) or (y < 0) or (x > w) or (y > h) then raise Exception.CreateFmt('SetMousePos: X, Y (%d, %d) is not valid', [x, y]); {$IFDEF MSWINDOWS} - GetWindowRect(TClient(Client).MWindow.TargetHandle, Rect); + GetWindowRect(Window.TargetHandle, Rect); Windows.SetCursorPos(x + Rect.Left, y + Rect.Top); {$ENDIF} {$IFDEF LINUX} Old_Handler := XSetErrorHandler(@MufasaXErrorHandler); - XWarpPointer(TClient(Client).MWindow.XDisplay, 0, TClient(Client).MWindow.CurWindow, 0, 0, 0, 0, X, Y); - XFlush(TClient(Client).MWindow.XDisplay); + XWarpPointer(Window.XDisplay, 0, Window.CurWindow, 0, 0, 0, 0, X, Y); + XFlush(Window.XDisplay); XSetErrorHandler(Old_Handler); {$ENDIF} @@ -313,7 +315,7 @@ var {$ENDIF} begin {$IFDEF MSWINDOWS} - GetWindowRect(TClient(Client).MWindow.TargetHandle, Rect); + GetWindowRect(Window.TargetHandle, Rect); Input.Itype:= INPUT_MOUSE; FillChar(Input,Sizeof(Input),0); Input.mi.dx:= x + Rect.left; @@ -348,7 +350,7 @@ begin mouse_Right: ButtonP := Button3; end; - XTestFakeButtonEvent(TClient(Client).MWindow.XDisplay, ButtonP, + XTestFakeButtonEvent(Window.XDisplay, ButtonP, _isPress, CurrentTime); XSetErrorHandler(Old_Handler); @@ -391,16 +393,16 @@ begin event.xbutton.send_event := TBool(1); // true if this came from a "send event" event.xbutton.same_screen:= TBool(1); event.xbutton.subwindow:= 0; // this can't be right. - event.xbutton.root := TClient(Client).MWindow.DesktopWindow; - event.xbutton.window := TClient(Client).MWindow.CurWindow; + event.xbutton.root := Window.DesktopWindow; + event.xbutton.window := Window.CurWindow; event.xbutton.x_root:= x; event.xbutton.y_root:= y; event.xbutton.x := x; event.xbutton.y := y; event.xbutton.state:= 0; - if(XSendEvent(TClient(Client).MWindow.XDisplay, PointerWindow, True, $fff, @event) = 0) then + if(XSendEvent(Window.XDisplay, PointerWindow, True, $fff, @event) = 0) then Writeln('Errorrrr :-('); - XFlush(TClient(Client).MWindow.XDisplay); + XFlush(Window.XDisplay); XSetErrorHandler(Old_Handler); {$ENDIF} @@ -440,7 +442,7 @@ begin {$IFDEF LINUX} Old_Handler := XSetErrorHandler(@MufasaXErrorHandler); - XQueryPointer(TClient(Client).MWindow.XDisplay,TClient(Client).MWindow.CurWindow,@root,@child,@rootx,@rooty,@x,@y,@xmask); + XQueryPointer(Window.XDisplay,Window.CurWindow,@root,@child,@rootx,@rooty,@x,@y,@xmask); case mType of mouse_Left: Result := (xmask and Button1Mask) <> 0; diff --git a/Units/MMLCore/window.pas b/Units/MMLCore/window.pas index 8d931f0..bd8e247 100644 --- a/Units/MMLCore/window.pas +++ b/Units/MMLCore/window.pas @@ -71,6 +71,7 @@ type function SetTarget(Window: THandle; NewType: TTargetWindowMode): integer; overload; function SetTarget(ArrPtr: PRGB32; Size: TPoint): integer; overload; function SetTarget(Bitmap : TMufasaBitmap) : integer;overload; + function TargetValid: Boolean; procedure SetWindow(Window: TMWindow); procedure SetDesktop; @@ -211,6 +212,8 @@ begin if FreezeState then if FrozenData <> nil then FreeMem(FrozenData); + + FreeReturnData; // checks if it is freed or not. if it is not freed, it frees. {$IFDEF LINUX} XCloseDisplay(Self.XDisplay); {$ENDIF} @@ -257,6 +260,30 @@ begin {$ENDIF} end; + +function TMWindow.TargetValid: Boolean; +{$IFDEF LINUX} +var + old_handler: TXErrorHandler; + Attrib: TXWindowAttributes; +{$ENDIF} +begin + {$IFDEF LINUX} + old_handler := XSetErrorHandler(@MufasaXErrorHandler); + + { There must be a better way to do this, at least with less overhead. } + if XGetWindowAttributes(Self.XDisplay, Self.CurWindow, @Attrib) = 0 then + result := false + else + result := true; + + XSetErrorHandler(old_handler); + {$ELSE} + writeln('stub: TMWindow.TargetValid on Windows. Returning true.'); + Exit(True); + {$ENDIF} +end; + procedure TMWindow.OnTargetBitmapDestroy(Bitmap: TMufasaBitmap); begin Self.SetDesktop; @@ -447,6 +474,8 @@ begin if TargetMode = w_XWindow then begin; Old_Handler := XSetErrorHandler(@MufasaXErrorHandler); + + { TODO: Check if Window is valid? } XSetInputFocus(Self.XDisplay,Self.CurWindow,RevertToParent,CurrentTime); XFlush(Self.XDisplay); XSetErrorHandler(Old_Handler); @@ -532,7 +561,6 @@ begin end; end; -// Make this use GetDimensions, ray...? function TMWindow.GetDimensionBox(out Box : TBox) : boolean; function IntToTBox(x1,y1,x2,y2 : integer) : TBox;inline; begin;