diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-07-16 12:28:23 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-07-16 12:28:23 +0000 |
commit | 5d64a196ab40aae5ddf66e984633334f1d40cd45 (patch) | |
tree | d4a8c7cef4bfbfcf57bbeb21a76ca8bc4dfb8f16 /prototypes | |
parent | d7a4fc9be599ac82550568b92ddb540032a0908a (diff) | |
download | fpGUI-5d64a196ab40aae5ddf66e984633334f1d40cd45.tar.xz |
* Changed shiftstate from word to TShiftState for keyboard and mouse events.
This includes the message parameter records.
* Replaced the keyboard handling routines with the one used in the old fpGFX.
* Remove unused constants from gfxbase that was used for the old keyboard
handling rountines.
* Updated the eventtest example to use the new shiftstate information.
EventTest is now much more complete.
Diffstat (limited to 'prototypes')
-rw-r--r-- | prototypes/fpgui2/examples/core/eventtest/eventtest.lpr | 95 | ||||
-rw-r--r-- | prototypes/fpgui2/source/core/gfx_widget.pas | 71 | ||||
-rw-r--r-- | prototypes/fpgui2/source/core/gfxbase.pas | 210 | ||||
-rw-r--r-- | prototypes/fpgui2/source/core/keys.inc | 252 | ||||
-rw-r--r-- | prototypes/fpgui2/source/core/x11/gfx_x11.pas | 288 | ||||
-rw-r--r-- | prototypes/fpgui2/source/gui/gui_button.pas | 26 | ||||
-rw-r--r-- | prototypes/fpgui2/source/gui/gui_combobox.pas | 4 | ||||
-rw-r--r-- | prototypes/fpgui2/source/gui/gui_dialogs.pas | 8 | ||||
-rw-r--r-- | prototypes/fpgui2/source/gui/gui_edit.pas | 32 | ||||
-rw-r--r-- | prototypes/fpgui2/source/gui/gui_listbox.pas | 57 | ||||
-rw-r--r-- | prototypes/fpgui2/source/gui/gui_memo.pas | 138 | ||||
-rw-r--r-- | prototypes/fpgui2/source/gui/gui_scrollbar.pas | 12 | ||||
-rw-r--r-- | prototypes/fpgui2/tests/edittest.lpi | 7 |
13 files changed, 830 insertions, 370 deletions
diff --git a/prototypes/fpgui2/examples/core/eventtest/eventtest.lpr b/prototypes/fpgui2/examples/core/eventtest/eventtest.lpr index e4cc9c3b..5ba36a09 100644 --- a/prototypes/fpgui2/examples/core/eventtest/eventtest.lpr +++ b/prototypes/fpgui2/examples/core/eventtest/eventtest.lpr @@ -8,6 +8,11 @@ uses {$ENDIF}{$ENDIF} Classes, SysUtils, GFXBase, fpGFX, gfx_widget; + +const + ButtonNames: array[TMouseButton] of PChar = + ('Left', 'Right', 'Middle'); + type { TMainForm } @@ -15,8 +20,8 @@ type TMainForm = class(TfpgWindow) private FMoveEventCount: integer; - function ShiftStateToStr(AShift: word): string; - function MouseState(AShift: word; const AMousePos: TPoint): string; + function ShiftStateToStr(Shift: TShiftState): string; + function MouseState(AShift: TShiftState; const AMousePos: TPoint): string; procedure MsgActivate(var msg: TfpgMessageRec); message FPGM_ACTIVATE; procedure MsgDeActivate(var msg: TfpgMessageRec); message FPGM_DEACTIVATE; procedure MsgClose(var msg: TfpgMessageRec); message FPGM_CLOSE; @@ -41,19 +46,43 @@ type { TMainForm } -function TMainForm.ShiftStateToStr(AShift: word): string; +function TMainForm.ShiftStateToStr(Shift: TShiftState): string; begin - Result := ''; - {$Note This must move into gfx_XXX units and return TShiftState enum} - if (AShift and ss_Shift) <> 0 then + SetLength(Result, 0); + if ssShift in Shift then Result := 'Shift '; - if (AShift and ss_Alt) <> 0 then + if ssAlt in Shift then Result := Result + 'Alt '; - if (AShift and ss_Control) <> 0 then + if ssCtrl in Shift then Result := Result + 'Ctrl '; -end; - -function TMainForm.MouseState(AShift: word; const AMousePos: TPoint): string; + if ssMeta in Shift then + Result := Result + 'Meta '; + if ssSuper in Shift then + Result := Result + 'Super '; + if ssHyper in Shift then + Result := Result + 'Hyper '; + if ssAltGr in Shift then + Result := Result + 'AltGr '; + if ssCaps in Shift then + Result := Result + 'Caps '; + if ssNum in Shift then + Result := Result + 'Num '; + if ssScroll in Shift then + Result := Result + 'Scroll '; + if ssLeft in Shift then + Result := Result + 'Left '; + if ssRight in Shift then + Result := Result + 'Right '; + if ssMiddle in Shift then + Result := Result + 'Middle '; + if ssDouble in Shift then + Result := Result + 'Double '; + if Length(Result) > 0 then + SetLength(Result, Length(Result) - 1); + +end; + +function TMainForm.MouseState(AShift: TShiftState; const AMousePos: TPoint): string; var ShiftStateStr: String; begin @@ -101,53 +130,63 @@ begin Writeln('Resize'); FWidth := msg.Params.rect.Width; FHeight := msg.Params.rect.Height; + + WriteLn('Window has been resized. New width: ', + Width, ' x ', Height); +// '; new client width: ', ClientWidth, ' x ', ClientHeight); + end; procedure TMainForm.MsgMove(var msg: TfpgMessageRec); begin - Writeln('Window Move'); + WriteLn('Window has been moved to ', Left, '/', Top); end; procedure TMainForm.MsgKeyChar(var msg: TfpgMessageRec); +var + AKeyChar: Char; begin - Write('Keychar - Character generated: '); -// if Char(keycode) >= ' ' then -// WriteLn('''', Char(keycode), '''') -// else -// WriteLn('#', Ord(keycode)); + Write('Character generated: '); + AKeyChar := msg.Params.keyboard.keychar; + if AKeyChar >= ' ' then + WriteLn('''', AKeyChar, '''') + else + WriteLn('#', Ord(AKeyChar)); end; procedure TMainForm.MsgKeyPress(var msg: TfpgMessageRec); begin - Writeln('KeyPress'); + WriteLn('[', ShiftStateToStr(msg.Params.keyboard.shiftstate), '] Key pressed: ', + KeycodeToText(msg.Params.keyboard.keycode, [])); end; procedure TMainForm.MsgKeyRelease(var msg: TfpgMessageRec); begin - Writeln('KeyRelease'); + WriteLn('[', ShiftStateToStr(msg.Params.keyboard.shiftstate), '] Key released: ', + KeycodeToText(msg.Params.keyboard.keycode, [])); end; procedure TMainForm.MsgMouseDown(var msg: TfpgMessageRec); begin - Writeln('Mouse button down.' + ' button=' + IntToStr(msg.Params.mouse.Buttons)); + WriteLn(MouseState(msg.Params.mouse.shiftstate, Point(msg.Params.mouse.x, msg.Params.mouse.y)), + 'Mouse button pressed: ', ' button=' + IntToStr(msg.Params.mouse.Buttons)); +// ButtonNames[msg.Params.mouse.Buttons]); end; procedure TMainForm.MsgMouseUp(var msg: TfpgMessageRec); begin - Writeln('Mouse button up.' + ' button=' + IntToStr(msg.Params.mouse.Buttons)); + WriteLn(MouseState(msg.Params.mouse.shiftstate, Point(msg.Params.mouse.x, msg.Params.mouse.y)), + 'Mouse button released: ', ' button=' + IntToStr(msg.Params.mouse.Buttons)); +// ButtonNames[msg.Params.mouse.Buttons]); end; procedure TMainForm.MsgMouseMove(var msg: TfpgMessageRec); -var - s: string; begin inc(FMoveEventCount); // only report mouse moves every 10 messages - just to limit the output a bit if (FMoveEventCount mod 10) = 0 then begin - s := Format('[%d,%d] ', [msg.Params.mouse.x, msg.Params.mouse.y]); - WriteLn(s + 'Mouse move message'); -// WriteLn(MouseState(shiftstate, Point(x, y)), 'Mouse moved'); + WriteLn(MouseState(msg.Params.mouse.shiftstate, Point(msg.Params.mouse.x, msg.Params.mouse.y)), 'Mouse moved'); end; end; @@ -158,12 +197,12 @@ end; procedure TMainForm.MsgMouseEnter(var msg: TfpgMessageRec); begin - Writeln('Mouse enter'); + WriteLn(MouseState(msg.Params.mouse.shiftstate, Point(msg.Params.mouse.x, msg.Params.mouse.y)), 'Mouse entered window'); end; procedure TMainForm.MsgMouseExit(var msg: TfpgMessageRec); begin - Writeln('Mouse exit'); + WriteLn('Mouse left window'); end; procedure TMainForm.MsgScroll(var msg: TfpgMessageRec); diff --git a/prototypes/fpgui2/source/core/gfx_widget.pas b/prototypes/fpgui2/source/core/gfx_widget.pas index 2462621a..62e339c4 100644 --- a/prototypes/fpgui2/source/core/gfx_widget.pas +++ b/prototypes/fpgui2/source/core/gfx_widget.pas @@ -56,20 +56,20 @@ type procedure HandlePaint; virtual; procedure HandleResize(awidth, aheight: TfpgCoord); virtual; procedure HandleMove(x, y: TfpgCoord); virtual; - procedure HandleKeyChar(var keycode: word; var shiftstate: word; var consumed: boolean); virtual; - procedure HandleKeyPress(var keycode: word; var shiftstate: word; var consumed: boolean); virtual; - procedure HandleKeyRelease(var keycode: word; var shiftstate: word; var consumed: boolean); virtual; + procedure HandleKeyChar(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); virtual; + procedure HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); virtual; + procedure HandleKeyRelease(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); virtual; procedure HandleSetFocus; virtual; procedure HandleKillFocus; virtual; - procedure HandleLMouseDown(x, y: integer; shiftstate: word); virtual; - procedure HandleRMouseDown(x, y: integer; shiftstate: word); virtual; - procedure HandleLMouseUp(x, y: integer; shiftstate: word); virtual; - procedure HandleRMouseUp(x, y: integer; shiftstate: word); virtual; - procedure HandleMouseMove(x, y: integer; btnstate: word; shiftstate: word); virtual; - procedure HandleDoubleClick(x, y: integer; button: word; shiftstate: word); virtual; + procedure HandleLMouseDown(x, y: integer; shiftstate: TShiftState); virtual; + procedure HandleRMouseDown(x, y: integer; shiftstate: TShiftState); virtual; + procedure HandleLMouseUp(x, y: integer; shiftstate: TShiftState); virtual; + procedure HandleRMouseUp(x, y: integer; shiftstate: TShiftState); virtual; + procedure HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); virtual; + procedure HandleDoubleClick(x, y: integer; button: word; shiftstate: TShiftState); virtual; procedure HandleMouseEnter; virtual; procedure HandleMouseExit; virtual; - procedure HandleMouseScroll(x, y: integer; shiftstate: word; delta: smallint); virtual; + procedure HandleMouseScroll(x, y: integer; shiftstate: TShiftState; delta: smallint); virtual; function FindFocusWidget(startwg: TfpgWidget; direction: TFocusSearchDirection): TfpgWidget; procedure HandleAlignments(dwidth, dheight: TfpgCoord); virtual; procedure HandleShow; virtual; @@ -202,7 +202,8 @@ end; procedure TfpgWidget.MsgKeyChar(var msg: TfpgMessageRec); var - key, ss: word; + key: word; + ss: TShiftState; consumed: boolean; wg: TfpgWidget; begin @@ -226,7 +227,7 @@ end; procedure TfpgWidget.MsgKeyPress(var msg: TfpgMessageRec); var key: word; - ss: word; + ss: TShiftState; consumed: boolean; wg: TfpgWidget; begin @@ -248,7 +249,8 @@ end; procedure TfpgWidget.MsgKeyRelease(var msg: TfpgMessageRec); var - key, ss: word; + key: word; + ss: TShiftState; consumed: boolean; wg: TfpgWidget; begin @@ -289,8 +291,7 @@ begin end; end; if Assigned(FOnMouseDown) then - FOnMouseDown(self, mb, - GetKeyboardShiftState(msg.Params.mouse.shiftstate), + FOnMouseDown(self, mb, msg.Params.mouse.shiftstate, Point(msg.Params.mouse.x, msg.Params.mouse.y)); end; @@ -315,8 +316,7 @@ begin end; end; if Assigned(FOnMouseUp) then - FOnMouseUp(self, mb, - GetKeyboardShiftState(msg.Params.mouse.shiftstate), + FOnMouseUp(self, mb, msg.Params.mouse.shiftstate, Point(msg.Params.mouse.x, msg.Params.mouse.y)); end; @@ -324,8 +324,7 @@ procedure TfpgWidget.MsgMouseMove(var msg: TfpgMessageRec); begin HandleMouseMove(msg.Params.mouse.x, msg.Params.mouse.y, msg.Params.mouse.Buttons, msg.Params.mouse.shiftstate); if Assigned(OnMouseMove) then - OnMouseMove(self, - GetKeyboardShiftState(msg.Params.mouse.shiftstate), + OnMouseMove(self, msg.Params.mouse.shiftstate, Point(msg.Params.mouse.x, msg.Params.mouse.y)); end; @@ -412,7 +411,7 @@ begin // descendants will implement this. end; -procedure TfpgWidget.HandleKeyChar(var keycode: word; var shiftstate: word; var consumed: boolean); +procedure TfpgWidget.HandleKeyChar(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); var wg: TfpgWidget; dir: integer; @@ -426,19 +425,19 @@ begin dir := 0; case keycode of - KEY_TAB: - if (shiftstate and ss_shift) <> 0 then + keyTab: + if (ssShift in shiftstate) then dir := -1 else dir := 1; - KEY_ENTER, - KEY_DOWN, - KEY_RIGHT: + keyReturn, + keyDown, + keyRight: dir := 1; - KEY_UP, - KEY_LEFT: + keyUp, + keyLeft: dir := -1; end; @@ -484,13 +483,13 @@ begin end; end; -procedure TfpgWidget.HandleKeyPress(var keycode: word; var shiftstate: word; +procedure TfpgWidget.HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); begin // descendants will implement this. end; -procedure TfpgWidget.HandleKeyRelease(var keycode: word; var shiftstate: word; var consumed: boolean); +procedure TfpgWidget.HandleKeyRelease(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); begin // descendants will implement this. end; @@ -531,7 +530,7 @@ begin ActiveWidget.KillFocus; end; -procedure TfpgWidget.HandleLMouseDown(x, y: integer; shiftstate: word); +procedure TfpgWidget.HandleLMouseDown(x, y: integer; shiftstate: TShiftState); var pw: TfpgWidget; w: TfpgWidget; @@ -548,27 +547,27 @@ begin end; end; -procedure TfpgWidget.HandleRMouseDown(x, y: integer; shiftstate: word); +procedure TfpgWidget.HandleRMouseDown(x, y: integer; shiftstate: TShiftState); begin // do nothing yet end; -procedure TfpgWidget.HandleLMouseUp(x, y: integer; shiftstate: word); +procedure TfpgWidget.HandleLMouseUp(x, y: integer; shiftstate: TShiftState); begin // do nothing yet end; -procedure TfpgWidget.HandleRMouseUp(x, y: integer; shiftstate: word); +procedure TfpgWidget.HandleRMouseUp(x, y: integer; shiftstate: TShiftState); begin // do nothing yet end; -procedure TfpgWidget.HandleMouseMove(x, y: integer; btnstate: word; shiftstate: word); +procedure TfpgWidget.HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); begin // do nothing yet end; -procedure TfpgWidget.HandleDoubleClick(x, y: integer; button: word; shiftstate: word); +procedure TfpgWidget.HandleDoubleClick(x, y: integer; button: word; shiftstate: TShiftState); begin // do nothing yet end; @@ -583,7 +582,7 @@ begin // do nothing yet end; -procedure TfpgWidget.HandleMouseScroll(x, y: integer; shiftstate: word; delta: smallint); +procedure TfpgWidget.HandleMouseScroll(x, y: integer; shiftstate: TShiftState; delta: smallint); begin // do nothing yet end; diff --git a/prototypes/fpgui2/source/core/gfxbase.pas b/prototypes/fpgui2/source/core/gfxbase.pas index 63d150a8..a00730ac 100644 --- a/prototypes/fpgui2/source/core/gfxbase.pas +++ b/prototypes/fpgui2/source/core/gfxbase.pas @@ -32,14 +32,6 @@ const MOUSE_RIGHT = 2; MOUSE_MIDDLE = 4; - - ss_Shift = $0001; - ss_Control = $0004; - ss_Alt = $0008; - ss_CapsLock = $0002; - ss_NumLock = $0010; - ss_ScrollLock = $0080; - // Platform independent messages used by fpGUI (TfpgWidget) FPGM_PAINT = 1; FPGM_ACTIVATE = 2; @@ -60,42 +52,8 @@ const FPGM_POPUPCLOSE = 17; FPGM_KILLME = 9999; - // The special keys, based on the well-known keyboard scan codes - KEY_LEFT = $FF4B; - KEY_RIGHT = $FF4D; - KEY_DOWN = $FF50; - KEY_UP = $FF48; - KEY_END = $FF4F; - KEY_HOME = $FF47; - KEY_PGUP = $FF49; - KEY_PGDN = $FF51; - KEY_INSERT = $FF52; - KEY_DELETE = $FF53; - KEY_F1 = $FF3B; - KEY_F2 = KEY_F1 + 1; - KEY_F3 = KEY_F1 + 2; - KEY_F4 = KEY_F1 + 3; - KEY_F5 = KEY_F1 + 4; - KEY_F6 = KEY_F1 + 5; - KEY_F7 = KEY_F1 + 6; - KEY_F8 = KEY_F1 + 7; - KEY_F9 = KEY_F1 + 8; - KEY_F10 = KEY_F1 + 9; - KEY_F11 = $FF57; - KEY_F12 = $FF58; - // some general keys - KEY_TAB = $0009; - KEY_ENTER = $000D; - KEY_SPACE = $0020; - KEY_ESC = $001B; - KEY_BACKSPACE = $0008; - - - // scan codes for KeyPress/KeyRelease - KEYSC_ENTER = $1C; - KEYSC_SPACE = $39; - + {$I keys.inc} FPG_DEFAULT_FONT_DESC = 'Arial-10'; UserNamedColorStart = 128; @@ -120,14 +78,15 @@ type x: TfpgCoord; y: TfpgCoord; Buttons: word; - shiftstate: word; + shiftstate: TShiftState; delta: word; end; TfpgMsgParmKeyboard = record keycode: word; - shiftstate: word; + keychar: char; + shiftstate: TShiftState; end; @@ -390,7 +349,6 @@ type { ******** Helper functions ******** } { Keyboard } -function GetKeyboardShiftState(AShiftState: word): TShiftState; function KeycodeToText(AKey: Word; AShiftState: TShiftState): string; { Color } @@ -406,31 +364,153 @@ implementation uses fpgfx; // needed for fpgApplication -function GetKeyboardShiftState(AShiftState: word): TShiftState; -begin - Result := []; - if (AShiftState and ss_shift) <> 0 then - Include(result, ssShift); - if (AShiftState and ss_Control) <> 0 then - Include(result, ssCtrl); +function KeycodeToText(AKey: Word; AShiftState: TShiftState): string; - if (AShiftState and ss_Alt) <> 0 then - Include(result, ssAlt); + function GetASCIIText: String; + var + c: Char; + begin + result := ''; + c := Chr(AKey and $ff); + case c of + #13: Result := Result + 'Enter'; + #127: Result := Result + 'Del'; + '+': Result := Result + 'Plus' + else + Result := Result + c; + end; + end; - if (AShiftState and ss_CapsLock) <> 0 then - Include(result, ssCaps); +var + s: String; +begin + SetLength(Result, 0); - if (AShiftState and ss_NumLock) <> 0 then - Include(result, ssNum); + if ssShift in AShiftState then + Result := 'Shift+'; + if ssCtrl in AShiftState then + Result := 'Ctrl+'; + if ssAlt in AShiftState then + Result := 'Alt+'; - if (AShiftState and ss_ScrollLock) <> 0 then - Include(result, ssScroll); -end; + if (AKey > Ord(' ')) and (AKey < 255) then + begin + Result := Result + GetASCIIText; + Exit; //==> + end; -function KeycodeToText(AKey: Word; AShiftState: TShiftState): string; -begin - Result := 'not implemented yet'; + case AKey of + keyNul: s := 'Null'; + keyBackSpace: s := 'Backspace'; + keyTab: s := 'Tab'; + keyLinefeed: s := 'Linefeed'; + keyReturn: s := 'Enter'; + keyEscape: s := 'Esc'; + Ord(' '): s := 'Space'; + keyDelete: s := 'Del'; + keyVoid: s := 'Void'; + keyBreak: s := 'Break'; + keyScrollForw: s := 'ScrollForw'; + keyScrollBack: s := 'ScrollBack'; + keyBoot: s := 'Boot'; + keyCompose: s := 'Compose'; + keySAK: s := 'SAK'; + keyUndo: s := 'Undo'; + keyRedo: s := 'Redo'; + keyMenu: s := 'Menu'; + keyCancel: s := 'Cancel'; + keyPrintScreen: s := 'PrtScr'; + keyExecute: s := 'Exec'; + keyFind: s := 'Find'; + keyBegin: s := 'Begin'; + keyClear: s := 'Clear'; + keyInsert: s := 'Ins'; + keySelect: s := 'Select'; + keyMacro: s := 'Macro'; + keyHelp: s := 'Help'; + keyDo: s := 'Do'; + keyPause: s := 'Pause'; + keySysRq: s := 'SysRq'; + keyModeSwitch: s := 'ModeSw'; + keyUp: s := 'Up'; + keyDown: s := 'Down'; + keyLeft: s := 'Left'; + keyRight: s := 'Right'; + keyPrior: s := 'PgUp'; + keyNext: s := 'PgDown'; + keyHome: s := 'Home'; + keyEnd: s := 'End'; + keyF0..keyF64: s := 'F' + IntToStr(AKey - keyF0); + keyP0..keyP9: s := 'KP' + Chr(AKey - keyP0 + Ord('0')); + keyPA..keyPF: s := 'KP' + Chr(AKey - keyPA + Ord('A')); + keyPPlus, keyPMinus, keyPSlash, keyPStar, keyPEqual, keyPSeparator, + keyPDecimal, keyPParenLeft, keyPParenRight, keyPSpace, keyPEnter, + keyPTab: s := 'KP' + GetASCIIText; + keyPPlusMinus: s := 'KPPlusMinus'; + keyPBegin: s := 'KPBegin'; + keyPF1..keyPF9: s := 'KPF' + IntToStr(AKey - keyPF1); + keyShiftL: s := 'ShiftL'; + keyShiftR: s := 'ShiftR'; + keyCtrlL: s := 'CtrlL'; + keyCtrlR: s := 'CtrlR'; + keyAltL: s := 'AltL'; + keyAltR: s := 'AltR'; + keyMetaL: s := 'MetaL'; + keyMetaR: s := 'MetaR'; + keySuperL: s := 'SuperL'; + keySuperR: s := 'SuperR'; + keyHyperL: s := 'HyperL'; + keyHyperR: s := 'HyperR'; + keyAltGr: s := 'AltGr'; + keyCaps: s := 'Caps'; + keyNum: s := 'Num'; + keyScroll: s := 'Scroll'; + keyShiftLock: s := 'ShiftLock'; + keyCtrlLock: s := 'CtrlLock'; + keyAltLock: s := 'AltLock'; + keyMetaLock: s := 'MetaLock'; + keySuperLock: s := 'SuperLock'; + keyHyperLock: s := 'HyperLock'; + keyAltGrLock: s := 'AltGrLock'; + keyCapsLock: s := 'CapsLock'; + keyNumLock: s := 'NumLock'; + keyScrollLock: s := 'ScrollLock'; + keyDeadRing: s := 'DeadRing'; + keyDeadCaron: s := 'DeadCaron'; + keyDeadOgonek: s := 'DeadOgonek'; + keyDeadIota: s := 'DeadIota'; + keyDeadDoubleAcute: s := 'DeadDoubleAcute'; + keyDeadBreve: s := 'DeadBreve'; + keyDeadAboveDot: s := 'DeadAboveDot'; + keyDeadBelowDot: s := 'DeadBelowDot'; + keyDeadVoicedSound: s := 'DeadVoicedSound'; + keyDeadSemiVoicedSound: s := 'DeadSemiVoicedSound'; + keyDeadAcute: s := 'DeadAcute'; + keyDeadCedilla: s := 'DeadCedilla'; + keyDeadCircumflex: s := 'DeadCircumflex'; + keyDeadDiaeresis: s := 'DeadDiaeresis'; + keyDeadGrave: s := 'DeadGrave'; + keyDeadTilde: s := 'DeadTilde'; + keyDeadMacron: s := 'DeadMacron'; + + keyEcuSign: s := 'Ecu'; + keyColonSign: s := 'Colon'; + keyCruzeiroSign: s := 'Cruzeiro'; + keyFFrancSign: s := 'FFranc'; + keyLiraSign: s := 'Lira'; + keyMillSign: s := 'Mill'; + keyNairaSign: s := 'Naira'; + keyPesetaSign: s := 'Peseta'; + keyRupeeSign: s := 'Rupee'; + keyWonSign: s := 'Won'; + keyNewSheqelSign: s := 'NewShequel'; + keyDongSign: s := 'Dong'; + keyEuroSign: s := 'Euro'; + else + s := '#' + IntToHex(AKey, 4); + end; + Result := Result + s; end; function fpgColorToRGBTriple(const AColor: TfpgColor): TRGBTriple; diff --git a/prototypes/fpgui2/source/core/keys.inc b/prototypes/fpgui2/source/core/keys.inc new file mode 100644 index 00000000..c2c9190a --- /dev/null +++ b/prototypes/fpgui2/source/core/keys.inc @@ -0,0 +1,252 @@ +{ + We use GGI's key definitions; the names just + have been somewhat pascalified... + GGI info at <http://www.ggi-project.org> + GII info at <http://www.ggi-project.org/packages/libgii.html> +} + +const + + // ASCII keys + + keyNul = $00; + keyBackSpace = $08; + keyTab = $09; + keyLinefeed = $0a; + keyReturn = $0d; + keyEscape = $1b; + keyDelete = $7f; + + // special keys + + keyVoid = $e000; + keyBreak = $e005; + keyScrollForw = $e00a; + keyScrollBack = $e00b; + keyBoot = $e00c; + keyCompose = $e00e; + keySAK = $e00f; + keyUndo = $e017; + keyRedo = $e018; + keyMenu = $e019; + keyCancel = $e01a; + keyPrintScreen = $e01b; + keyExecute = $e01c; + keyFind = $e01e; + keyBegin = $e01f; + keyClear = $e020; + keyInsert = $e022; + keySelect = $e023; + keyMacro = $e026; + keyHelp = $e027; + keyDo = $e028; + keyPause = $e029; + keyStop = keyPause; + keySysRq = $e02a; + keyModeSwitch = $e02b; + keyUp = $e032; + keyDown = $e033; + keyLeft = $e034; + keyRight = $e035; + keyPrior = $e036; + keyPageUp = keyPrior; + keyNext = $e037; + keyPageDown = keyNext; + keyHome = $e038; + keyEnd = $e039; + + + // function keys + + keyF0 = $e100; + keyF1 = $e101; + keyF2 = $e102; + keyF3 = $e103; + keyF4 = $e104; + keyF5 = $e105; + keyF6 = $e106; + keyF7 = $e107; + keyF8 = $e108; + keyF9 = $e109; + keyF10 = $e10a; + keyF11 = $e10b; + keyF12 = $e10c; + keyF13 = $e10d; + keyF14 = $e10e; + keyF15 = $e10f; + keyF16 = $e110; + keyF17 = $e111; + keyF18 = $e112; + keyF19 = $e113; + keyF20 = $e114; + keyF21 = $e115; + keyF22 = $e116; + keyF23 = $e117; + keyF24 = $e118; + keyF25 = $e119; + keyF26 = $e11a; + keyF27 = $e11b; + keyF28 = $e11c; + keyF29 = $e11d; + keyF30 = $e11e; + keyF31 = $e11f; + keyF32 = $e120; + keyF33 = $e121; + keyF34 = $e122; + keyF35 = $e123; + keyF36 = $e124; + keyF37 = $e125; + keyF38 = $e126; + keyF39 = $e127; + keyF40 = $e128; + keyF41 = $e129; + keyF42 = $e12a; + keyF43 = $e12b; + keyF44 = $e12c; + keyF45 = $e12d; + keyF46 = $e12e; + keyF47 = $e12f; + keyF48 = $e130; + keyF49 = $e131; + keyF50 = $e132; + keyF51 = $e133; + keyF52 = $e134; + keyF53 = $e135; + keyF54 = $e136; + keyF55 = $e137; + keyF56 = $e138; + keyF57 = $e139; + keyF58 = $e13a; + keyF59 = $e13b; + keyF60 = $e13c; + keyF61 = $e13d; + keyF62 = $e13e; + keyF63 = $e13f; + keyF64 = $e140; + + + // keys on the numeric keypad + keyP0 = $e230; + keyP1 = $e231; + keyP2 = $e232; + keyP3 = $e233; + keyP4 = $e234; + keyP5 = $e235; + keyP6 = $e236; + keyP7 = $e237; + keyP8 = $e238; + keyP9 = $e239; + keyPA = $e241; + keyPB = $e242; + keyPC = $e243; + keyPD = $e244; + keyPE = $e245; + keyPF = $e246; + keyPPlus = $e200 + Ord('+'); + keyPMinus = $e200 + Ord('-'); + keyPSlash = $e200 + Ord('/'); + keyPAsterisk = $e200 + Ord('*'); + keyPStar = keyPAsterisk; + keyPEqual = $e200 + Ord('='); + keyPSeparator = $e200 + Ord(','); + keyPDecimal = $e200 + Ord('.'); + keyPParenLeft = $e200 + Ord('('); + keyPParenRight = $e200 + Ord(')'); + keyPSpace = $e200 + Ord(' '); + keyPEnter = $e20d; + keyPTab = $e208; + keyPPlusMinus = $e280; + keyPBegin = $e281; + keyPF1 = $e291; + keyPF2 = $e292; + keyPF3 = $e293; + keyPF4 = $e294; + keyPF5 = $e295; + keyPF6 = $e296; + keyPF7 = $e297; + keyPF8 = $e298; + keyPF9 = $e299; + + + // modifier keys + + keyShift = $e300; + keyCtrl = $e301; + keyAlt = $e302; + keyMeta = $e303; + keySuper = $e304; + keyHyper = $e305; + keyAltGr = $e306; + keyCaps = $e307; + keyNum = $e308; + keyScroll = $e309; + + + // modifier _labels_ + + keyShiftL = $e300; + keyShiftR = $e340; + keyCtrlL = $e301; + keyCtrlR = $e341; + keyAltL = $e302; + keyAltR = $e342; + keyMetaL = $e303; + keyMetaR = $e343; + keySuperL = $e304; + keySuperR = $e344; + keyHyperL = $e305; + keyHyperR = $e345; + keyShiftLock = $e380; + keyCtrlLock = $e381; + keyAltLock = $e382; + keyMetaLock = $e383; + keySuperLock = $e384; + keyHyperLock = $e385; + keyAltGrLock = $e386; + keyCapsLock = $e387; + keyNumLock = $e388; + keyScrollLock = $e389; + + // Dead keys + keyDeadRing = $e400; + keyDeadCaron = $e401; + keyDeadOgonek = $e402; + keyDeadIota = $e403; + keyDeadDoubleAcute = $e404; + keyDeadBreve = $e405; + keyDeadAboveDot = $e406; + keyDeadBelowDot = $e407; + keyDeadVoicedSound = $e408; + keyDeadSemiVoicedSound = $e409; + + + keyDeadAcute = $e4b4; + keyDeadCedilla = $e4b8; + keyDeadCircumflex = $e45e; + keyDeadDiaeresis = $e4a8; + keyDeadGrave = $e460; + keyDeadTilde = $e47e; + keyDeadMacron = $e4af; + + // miscellaneous + keyNIL = $ffff; // used to indicate "not mapped yet" + + + // currencies (NOTE: These values are not defined in GGI/GII! + // !!!: Check if GII has got currency codes in the meantime + keyEcuSign = $e500; + keyColonSign = $e501; + keyCruzeiroSign = $e502; + keyFFrancSign = $e503; + keyLiraSign = $e504; + keyMillSign = $e505; + keyNairaSign = $e506; + keyPesetaSign = $e507; + keyRupeeSign = $e508; + keyWonSign = $e509; + keyNewSheqelSign = $e50a; + keyDongSign = $e50b; + keyEuroSign = $e50c; + + + diff --git a/prototypes/fpgui2/source/core/x11/gfx_x11.pas b/prototypes/fpgui2/source/core/x11/gfx_x11.pas index 8c65d3e4..17ba47ed 100644 --- a/prototypes/fpgui2/source/core/x11/gfx_x11.pas +++ b/prototypes/fpgui2/source/core/x11/gfx_x11.pas @@ -2,6 +2,8 @@ unit gfx_x11; {$mode objfpc}{$H+} +{$Define DEBUG} + interface uses @@ -11,7 +13,7 @@ uses Xlib, XUtil, x11_xft, - x11_keyconv, +// x11_keyconv, gfxbase; type @@ -137,6 +139,12 @@ type TfpgApplicationImpl = class(TfpgApplicationBase) + private + FComposeBuffer: String[32]; + FComposeStatus: TXComposeStatus; + function ConvertShiftState(AState: Cardinal): TShiftState; + function KeySymToKeycode(KeySym: TKeySym): Word; + function StartComposing(const Event: TXEvent): TKeySym; protected FDisplay: PXDisplay; DisplayDepth: integer; @@ -367,6 +375,108 @@ end; { TfpgApplicationImpl } +function TfpgApplicationImpl.ConvertShiftState(AState: Cardinal): TShiftState; +begin + Result := []; + if (AState and Button1Mask) <> 0 then + Include(Result, ssLeft); + if (AState and Button2Mask) <> 0 then + Include(Result, ssMiddle); + if (AState and Button3Mask) <> 0 then + Include(Result, ssRight); + if (AState and ShiftMask) <> 0 then + Include(Result, ssShift); + if (AState and LockMask) <> 0 then + Include(Result, ssCaps); + if (AState and ControlMask) <> 0 then + Include(Result, ssCtrl); + if (AState and Mod1Mask) <> 0 then + Include(Result, ssAlt); + if (AState and Mod2Mask) <> 0 then + Include(Result, ssNum); + if (AState and Mod4Mask) <> 0 then + Include(Result, ssSuper); + if (AState and Mod5Mask) <> 0 then + Include(Result, ssScroll); + if (AState and (1 shl 13)) <> 0 then + Include(Result, ssAltGr); +end; + +function TfpgApplicationImpl.KeySymToKeycode(KeySym: TKeySym): Word; +const + Table_20aX: array[$20a0..$20ac] of Word = (keyEcuSign, keyColonSign, + keyCruzeiroSign, keyFFrancSign, keyLiraSign, keyMillSign, keyNairaSign, + keyPesetaSign, keyRupeeSign, keyWonSign, keyNewSheqelSign, keyDongSign, + keyEuroSign); + Table_feXX: array[$fe50..$fe60] of Word = (keyDeadGrave, keyDeadAcute, + keyDeadCircumflex, keyDeadTilde, keyDeadMacron,keyDeadBreve, + keyDeadAbovedot, keyDeadDiaeresis, keyDeadRing, keyDeadDoubleacute, + keyDeadCaron, keyDeadCedilla, keyDeadOgonek, keyDeadIota, + keyDeadVoicedSound, keyDeadSemivoicedSound, keyDeadBelowdot); + Table_ff5X: array[$ff50..$ff58] of Word = (keyHome, keyLeft, keyUp, keyRight, + keyDown, keyPrior, keyNext, keyEnd, keyBegin); + Table_ff6X: array[$ff60..$ff6b] of Word = (keySelect, keyPrintScreen, + keyExecute, keyInsert, keyNIL, keyUndo, keyRedo, keyMenu, keyFind, + keyCancel, keyHelp, keyBreak); + Table_ff9X: array[$ff91..$ff9f] of Word = (keyPF1, keyPF2, keyPF3, keyPF4, + keyP7, keyP4, keyP8, keyP6, keyP2, keyP9, keyP3, keyP1, keyP5, keyP0, + keyPDecimal); + Table_ffeX: array[$ffe1..$ffee] of Word = (keyShiftL, keyShiftR, keyCtrlL, + keyCtrlR, keyCapsLock, keyShiftLock, keyMetaL, keyMetaR, keyAltL, keyAltR, + keySuperL, keySuperR, keyHyperL, keyHyperR); +begin + case KeySym of + 0..Ord('a')-1, Ord('z')+1..$bf, $f7: + Result := KeySym; + Ord('a')..Ord('z'), $c0..$f6, $f8..$ff: + Result := KeySym - 32; + $20a0..$20ac: Result := Table_20aX[KeySym]; + $fe20: Result := keyTab; + $fe50..$fe60: Result := Table_feXX[KeySym]; + $ff08: Result := keyBackspace; + $ff09: Result := keyTab; + $ff0a: Result := keyLinefeed; + $ff0b: Result := keyClear; + $ff0d: Result := keyReturn; + $ff13: Result := keyPause; + $ff14: Result := keyScrollLock; + $ff15: Result := keySysRq; + $ff1b: Result := keyEscape; + $ff50..$ff58: Result := Table_ff5X[KeySym]; + $ff60..$ff6b: Result := Table_ff6X[KeySym]; + $ff7e: Result := keyModeSwitch; + $ff7f: Result := keyNumLock; + $ff80: Result := keyPSpace; + $ff89: Result := keyPTab; + $ff8d: Result := keyPEnter; + $ff91..$ff9f: Result := Table_ff9X[KeySym]; + $ffaa: Result := keyPAsterisk; + $ffab: Result := keyPPlus; + $ffac: Result := keyPSeparator; + $ffad: Result := keyPMinus; + $ffae: Result := keyPDecimal; + $ffaf: Result := keyPSlash; + $ffb0..$ffb9: Result := keyP0 + KeySym - $ffb0; + $ffbd: Result := keyPEqual; + $ffbe..$ffe0: Result := keyF1 + KeySym - $ffbe; + $ffe1..$ffee: Result := Table_ffeX[KeySym]; + $ffff: Result := keyDelete; + else + Result := keyNIL; + end; +{$IFDEF Debug} + if Result = keyNIL then + WriteLn('fpGFX/X11: Unknown KeySym: $', IntToHex(KeySym, 4)); +{$ENDIF} +end; + +function TfpgApplicationImpl.StartComposing(const Event: TXEvent): TKeySym; +begin + SetLength(FComposeBuffer, + XLookupString(@Event, @FComposeBuffer[1], + SizeOf(FComposeBuffer) - 1, @Result, @FComposeStatus)); +end; + constructor TfpgApplicationImpl.Create(const aparams: string); var wa: TXWindowAttributes; @@ -509,6 +619,7 @@ var msgp: TfpgMessageParams; rfds: TFDSet; xfd: integer; + KeySym: TKeySym; begin xfd := XConnectionNumber(display); @@ -547,116 +658,91 @@ begin case ev._type of MSG_KEYPRESS, MSG_KEYRELEASE: - begin - msgp.keyboard.keycode := X11keycodeToScanCode(ev.xkey.keycode); - msgp.keyboard.shiftstate := ev.xkey.state; + begin + KeySym := StartComposing(ev); + msgp.keyboard.keycode := KeySymToKeycode(KeySym); + msgp.keyboard.shiftstate := ConvertShiftState(ev.xkey.state); - kwg := FindKeyboardFocus; - if kwg <> nil then - w := kwg - else - w := FindWindowByHandle(ev.xkey.window); + kwg := FindKeyboardFocus; + if kwg <> nil then + w := kwg + else + w := FindWindowByHandle(ev.xkey.window); - //Writeln('XKey event(',ev._type,'):', - // IntToHex(ev.xkey.keycode,4),' (',ev.xkey.keycode,'), shift=',IntToHex(ev.xkey.state,4)); + //Writeln('XKey event(',ev._type,'):', + //IntToHex(ev.xkey.keycode,4),' (',ev.xkey.keycode,'), shift=',IntToHex(ev.xkey.state,4)); - if ev._type = MSG_KEYPRESS then - begin - fpgPostMessage(nil, w, FPGM_KEYPRESS, msgp); - - //Writeln('scancode: ',IntToHex(X11keycodeToScanCode(ev.xkey.keycode),4) - // ,' (',X11keycodeToScanCode(ev.xkey.keycode),')'); - - // force some function keys to send as keychar too - - uc := msgp.keyboard.keycode; - - b := True; - case uc of - $01: uc := $001B; // esc - $0E: uc := $0008; // backspace - $1C, $11C: uc := $000D; // enter - $0F: uc := $0009; // tab - $3B..$44, - $57, $58, // F1 .. F12 - $147..$149, // nav keys - $14B, $14D, - $14F..$153: - uc := uc or $FF00; - else - b := False; - end; + if ev._type = MSG_KEYPRESS then + begin + fpgPostMessage(nil, w, FPGM_KEYPRESS, msgp); - if b then - begin - msgp.keyboard.keycode := uc; - fpgPostMessage(nil, w, FPGM_KEYCHAR, msgp); - end - else - begin - // try to convert it to some char - sr := 0; - r := XmbLookupString(InputContext, PXKeyPressedEvent(@ev), @a, 16, @ks, @sr); - uc := ks and $FFFF; - - KeySymToUnicode(ks, @uc); - msgp.keyboard.keycode := uc; - fpgPostMessage(nil, w, FPGM_KEYCHAR, msgp); + //Writeln('scancode: ',IntToHex(X11keycodeToScanCode(ev.xkey.keycode),4) + // ,' (',X11keycodeToScanCode(ev.xkey.keycode),')'); + + // Revision 203 used scancodes and XmbLookupString compared to XLookupString. + // Maybe in the future we can switch to XmbLookupString again. + if (ev.xkey.state and (ControlMask or Mod1Mask)) = 0 then + begin + for i := 1 to Length(FComposeBuffer) do + begin + msgp.keyboard.keychar := FComposeBuffer[i]; + fpgPostMessage(nil, w, FPGM_KEYCHAR, msgp); + end; + end; + end { if } + else if ev._type = MSG_KEYRELEASE then + fpgPostMessage(nil, w, FPGM_KEYRELEASE, msgp); end; - end - else if ev._type = MSG_KEYRELEASE then - fpgPostMessage(nil, w, FPGM_KEYRELEASE, msgp); - end; MSG_MOUSEDOWN, MSG_MOUSEUP: - begin - msgp.mouse.x := ev.xbutton.x; - msgp.mouse.y := ev.xbutton.y; - msgp.mouse.Buttons := ev.xbutton.button; - msgp.mouse.shiftstate := ev.xbutton.state; - - w := FindWindowByHandle(ev.xbutton.window); - if not blockmsg then - begin - if (ev.xbutton.button >= 4) and (ev.xbutton.button <= 7) then // mouse wheel begin - // generate scroll events: - if ev._type = MSG_MOUSEDOWN then + msgp.mouse.x := ev.xbutton.x; + msgp.mouse.y := ev.xbutton.y; + msgp.mouse.Buttons := ev.xbutton.button; + msgp.mouse.shiftstate := ConvertShiftState(ev.xbutton.state); + + w := FindWindowByHandle(ev.xbutton.window); + if not blockmsg then begin - if ev.xbutton.button = Button4 then - i := -1 + if (ev.xbutton.button >= 4) and (ev.xbutton.button <= 7) then // mouse wheel + begin + // generate scroll events: + if ev._type = MSG_MOUSEDOWN then + begin + if ev.xbutton.button = Button4 then + i := -1 + else + i := 1; + + // Check for other mouse wheel messages in the queue + while XCheckTypedWindowEvent(display, ev.xany.window, X.ButtonPress, @NewEvent) do + begin + if NewEvent.xbutton.Button = 4 then + Dec(i) + else if NewEvent.xbutton.Button = 5 then + Inc(i) + else + begin + XPutBackEvent(display, @NewEvent); + break; + end; + end; + + msgp.mouse.delta := i; + fpgPostMessage(nil, w, FPGM_SCROLL, msgp); + end; + end else - i := 1; - - // Check for other mouse wheel messages in the queue - while XCheckTypedWindowEvent(display, ev.xany.window, X.ButtonPress, @NewEvent) do begin - if NewEvent.xbutton.Button = 4 then - Dec(i) - else if NewEvent.xbutton.Button = 5 then - Inc(i) + if ev._type = MSG_MOUSEUP then + mcode := FPGM_MOUSEUP else - begin - XPutBackEvent(display, @NewEvent); - break; - end; - end; - - msgp.mouse.delta := i; - fpgPostMessage(nil, w, FPGM_SCROLL, msgp); - end; - end - else - begin - if ev._type = MSG_MOUSEUP then - mcode := FPGM_MOUSEUP - else - mcode := FPGM_MOUSEDOWN; - fpgPostMessage(nil, w, mcode, msgp); - end; { if/else } - end; { if not blocking } - end; + mcode := FPGM_MOUSEDOWN; + fpgPostMessage(nil, w, mcode, msgp); + end; { if/else } + end; { if not blocking } + end; MSG_PAINT: begin @@ -680,7 +766,7 @@ begin msgp.mouse.x := ev.xmotion.x; msgp.mouse.y := ev.xmotion.y; msgp.mouse.Buttons := (ev.xmotion.state and $FF00) shr 8; - msgp.mouse.shiftstate := ev.xmotion.state and $FF; + msgp.mouse.shiftstate := ConvertShiftState(ev.xmotion.state); fpgPostMessage(nil, FindWindowByHandle(ev.xbutton.window), FPGM_MOUSEMOVE, msgp); end; end; @@ -762,7 +848,7 @@ begin True and the source is a window, these events may be generated; handle GraphicsExpose like Expose } else - {$Note This needs attention} + {$Note This needs attention. We still have two events slipping by.} WriteLn('fpGFX/X11: Unhandled X11 event received: ', GetXEventName(ev._type)); end; end; @@ -1175,7 +1261,7 @@ begin SetColor(AValue); DrawLine(X, Y, X+1, Y+1); SetColor(oldColor); - {$Note We must implement DrawPoint} + {$Note We must still implement DrawPoint} end; procedure TfpgCanvasImpl.DoSetFontRes(fntres: TfpgFontResourceBase); diff --git a/prototypes/fpgui2/source/gui/gui_button.pas b/prototypes/fpgui2/source/gui/gui_button.pas index 15919902..cf8199fa 100644 --- a/prototypes/fpgui2/source/gui/gui_button.pas +++ b/prototypes/fpgui2/source/gui/gui_button.pas @@ -43,11 +43,11 @@ type FFont: TfpgFont; procedure SetShowImage(AValue: Boolean); procedure HandlePaint; override; - procedure HandleKeyPress(var keycode: word; var shiftstate: word; var consumed: boolean); override; - procedure HandleKeyChar(var keycode: word; var shiftstate: word; var consumed: boolean); override; - procedure HandleKeyRelease(var keycode: word; var shiftstate: word; var consumed: boolean); override; - procedure HandleLMouseDown(X, Y: integer; ShiftState: word); override; - procedure HandleLMouseUp(x, y: integer; shiftstate: word); override; + procedure HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); override; + procedure HandleKeyChar(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); override; + procedure HandleKeyRelease(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); override; + procedure HandleLMouseDown(X, Y: integer; ShiftState: TShiftState); override; + procedure HandleLMouseUp(x, y: integer; shiftstate: TShiftState); override; procedure HandleMouseExit; override; procedure HandleMouseEnter; override; public @@ -321,9 +321,9 @@ begin FClicked := False; end; -procedure TfpgButton.HandleKeyPress(var keycode: word; var shiftstate: word; var consumed: boolean); +procedure TfpgButton.HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); begin - if (keycode = KEYSC_ENTER) or (keycode = KEYSC_SPACE) then + if (keycode = keyReturn) or (keycode = keySelect) then begin DoPush; Consumed := True; @@ -332,17 +332,17 @@ begin inherited; end; -procedure TfpgButton.HandleKeyChar(var keycode: word; var shiftstate: word; var consumed: boolean); +procedure TfpgButton.HandleKeyChar(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); begin - if (keycode = KEY_ENTER) or (keycode = KEY_SPACE) then + if (keycode = keyReturn) or (keycode = keySelect) then Consumed := True else inherited; end; -procedure TfpgButton.HandleKeyRelease(var keycode: word; var shiftstate: word; var consumed: boolean); +procedure TfpgButton.HandleKeyRelease(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); begin - if (keycode = KEYSC_ENTER) or (keycode = KEYSC_SPACE) then + if (keycode = keyReturn) or (keycode = keySelect) then begin DoRelease; Consumed := True; @@ -351,13 +351,13 @@ begin inherited; end; -procedure TfpgButton.HandleLMouseDown(X, Y: integer; ShiftState: word); +procedure TfpgButton.HandleLMouseDown(X, Y: integer; ShiftState: TShiftState); begin inherited; DoPush; end; -procedure TfpgButton.HandleLMouseUp(x, y: integer; shiftstate: word); +procedure TfpgButton.HandleLMouseUp(x, y: integer; shiftstate: TShiftState); begin inherited; DoRelease; diff --git a/prototypes/fpgui2/source/gui/gui_combobox.pas b/prototypes/fpgui2/source/gui/gui_combobox.pas index 4e945e06..d45f4020 100644 --- a/prototypes/fpgui2/source/gui/gui_combobox.pas +++ b/prototypes/fpgui2/source/gui/gui_combobox.pas @@ -27,7 +27,7 @@ type procedure InternalBtnClick(Sender: TObject); protected property DropDownCount: integer read FDropDownCount write SetDropDownCount default 8; - procedure HandleLMouseDown(x, y: integer; shiftstate: word); override; + procedure HandleLMouseDown(x, y: integer; shiftstate: TShiftState); override; procedure HandlePaint; override; public constructor Create(AOwner: TComponent); override; @@ -133,7 +133,7 @@ begin DoDropDown; end; -procedure TfpgCustomComboBox.HandleLMouseDown(x, y: integer; shiftstate: word); +procedure TfpgCustomComboBox.HandleLMouseDown(x, y: integer; shiftstate: TShiftState); begin inherited HandleLMouseDown(x, y, shiftstate); DoDropDown; diff --git a/prototypes/fpgui2/source/gui/gui_dialogs.pas b/prototypes/fpgui2/source/gui/gui_dialogs.pas index 80945003..93144e05 100644 --- a/prototypes/fpgui2/source/gui/gui_dialogs.pas +++ b/prototypes/fpgui2/source/gui/gui_dialogs.pas @@ -21,7 +21,7 @@ type FButton: TfpgButton; procedure ButtonClick(Sender: TObject); protected - procedure HandleKeyPress(var keycode: word; var shiftstate: word; var consumed: boolean); override; + procedure HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); override; procedure HandlePaint; override; public constructor Create(AOwner : TComponent); override; @@ -68,13 +68,11 @@ begin end; procedure TfpgMessageBox.HandleKeyPress(var keycode: word; - var shiftstate: word; var consumed: boolean); + var shiftstate: TShiftState; var consumed: boolean); begin inherited HandleKeyPress(keycode, shiftstate, consumed); - if keycode = KEY_ESC then - begin + if keycode = keyEscape then Close; - end; end; procedure TfpgMessageBox.HandlePaint; diff --git a/prototypes/fpgui2/source/gui/gui_edit.pas b/prototypes/fpgui2/source/gui/gui_edit.pas index 32f1dbac..eb2e4597 100644 --- a/prototypes/fpgui2/source/gui/gui_edit.pas +++ b/prototypes/fpgui2/source/gui/gui_edit.pas @@ -34,9 +34,9 @@ type procedure AdjustCursor; function GetDrawText: string; procedure HandlePaint; override; - procedure HandleKeyChar(var keycode: word; var shiftstate: word; var consumed: boolean); override; - procedure HandleLMouseDown(x, y: integer; shiftstate: word); override; - procedure HandleMouseMove(x, y: integer; btnstate, shiftstate: word); override; + procedure HandleKeyChar(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); override; + procedure HandleLMouseDown(x, y: integer; shiftstate: TShiftState); override; + procedure HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); override; public PasswordMode: boolean; constructor Create(AOwner: TComponent); override; @@ -252,7 +252,7 @@ begin Canvas.EndDraw; end; -procedure TfpgEdit.HandleKeyChar(var keycode: word; var shiftstate: word; var consumed: boolean); +procedure TfpgEdit.HandleKeyChar(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); var prevval: string; s: string; @@ -291,12 +291,12 @@ begin consumed := True; case keycode of - KEY_LEFT: + keyLeft: if FCursorPos > 0 then begin Dec(FCursorPos); - if (shiftstate and ss_control) <> 0 then + if (ssCtrl in shiftstate) then // word search... // while (FCursorPos > 0) and not ptkIsAlphaNum(copy(FText,FCursorPos,1)) // do Dec(FCursorPos); @@ -306,12 +306,12 @@ begin end; - KEY_RIGHT: + keyRight: if FCursorPos < UTF8Length(FText) then begin Inc(FCursorPos); - if (shiftstate and ss_control) <> 0 then + if (ssCtrl in shiftstate) then // word search... // while (FCursorPos < Length(FText)) and ptkIsAlphaNum(copy(FText,FCursorPos+1,1)) // do Inc(FCursorPos); @@ -320,10 +320,10 @@ begin ; end; - KEY_HOME: + keyHome: FCursorPos := 0; - KEY_END: + keyEnd: FCursorPos := UTF8Length(FText); else Consumed := False; @@ -333,7 +333,7 @@ begin begin AdjustCursor; - FSelecting := (shiftstate and ss_shift) <> 0; + FSelecting := (ssShift in shiftstate); if FSelecting then FSelOffset := FCursorPos - FSelStart @@ -347,7 +347,7 @@ begin consumed := True; case keycode of - KEY_BACKSPACE: + keyBackSpace: if FCursorPos > 0 then begin Delete(FText, FCursorPos, 1); @@ -355,7 +355,7 @@ begin end;// backspace - KEY_DELETE: + keyDelete: if FSelOffset <> 0 then DeleteSelection else if FCursorPos < UTF8Length(FText) then @@ -398,7 +398,7 @@ begin inherited; end; -procedure TfpgEdit.HandleLMouseDown(x, y: integer; shiftstate: word); +procedure TfpgEdit.HandleLMouseDown(x, y: integer; shiftstate: TShiftState); var s: string; n: integer; @@ -428,7 +428,7 @@ begin FMouseDragPos := cp; FCursorPos := cp; - if (shiftstate and ss_shift) <> 0 then + if (ssShift in shiftstate) then FSelOffset := FCursorPos - FSelStart else begin @@ -438,7 +438,7 @@ begin Repaint; end; -procedure TfpgEdit.HandleMouseMove(x, y: integer; btnstate, shiftstate: word); +procedure TfpgEdit.HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); var s: string; n: integer; diff --git a/prototypes/fpgui2/source/gui/gui_listbox.pas b/prototypes/fpgui2/source/gui/gui_listbox.pas index 3c38011e..62ae5504 100644 --- a/prototypes/fpgui2/source/gui/gui_listbox.pas +++ b/prototypes/fpgui2/source/gui/gui_listbox.pas @@ -52,11 +52,11 @@ type procedure DrawItem(num: integer; rect: TfpgRect; flags: integer); virtual; procedure DoChange; procedure DoSelect; - procedure HandleKeyPress(var keycode: word; var shiftstate: word; var consumed : boolean); override; - procedure HandleLMouseDown(x, y: integer; shiftstate: word); override; - procedure HandleLMouseUp(x, y: integer; shiftstate: word); override; - procedure HandleMouseMove(x, y: integer; btnstate: word; shiftstate: word); override; - procedure HandleMouseScroll(x, y: integer; shiftstate: word; delta: smallint); override; + procedure HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed : boolean); override; + procedure HandleLMouseDown(x, y: integer; shiftstate: TShiftState); override; + procedure HandleLMouseUp(x, y: integer; shiftstate: TShiftState); override; + procedure HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); override; + procedure HandleMouseScroll(x, y: integer; shiftstate: TShiftState; delta: smallint); override; procedure HandleShow; override; procedure HandleResize(dwidth, dheight: integer); override; procedure HandlePaint; override; @@ -287,14 +287,13 @@ begin end; procedure TfpgBaseListBox.HandleKeyPress(var keycode: word; - var shiftstate: word; var consumed: boolean); + var shiftstate: TShiftState; var consumed: boolean); begin -// writeln(Classname, '.HandleKeyPress ', IntToHex(keycode, 4)); consumed := true; case keycode of - KEY_UP: - begin // up + keyUp: + begin // writeln('up'); if FFocusItem > 1 then begin @@ -304,8 +303,9 @@ begin DoChange; end; end; - KEY_DOWN: - begin // down + + keyDown: + begin // writeln('down'); if FFocusItem < ItemCount then begin @@ -315,51 +315,56 @@ begin DoChange; end; end; - KEY_PGUP: - begin // pgup + + keyPageUp: + begin dec(FFocusItem,PageLength); if FFocusItem < 1 then FFocusItem := 1; FollowFocus; RePaint; DoChange; end; - KEY_PGDN: - begin // pgdown + + keyPageDown: + begin inc(FFocusItem,PageLength); if FFocusItem > ItemCount then FFocusItem := ItemCount; FollowFocus; RePaint; DoChange; end; - KEY_HOME: - begin // home + + keyHome: + begin FFocusItem := 1; FollowFocus; RePaint; DoChange; end; - KEY_END: - begin // end + + keyEnd: + begin FFocusItem := ItemCount; FollowFocus; RePaint; DoChange; end; - KEY_ENTER: - begin // enter + + keyReturn: + begin DoSelect; consumed := false; // to allow the forms to detect it end; else begin -// writeln('...else...'); + writeln('...else...'); consumed := false; end; end; inherited HandleKeyPress(keycode, shiftstate, consumed); end; -procedure TfpgBaseListBox.HandleLMouseDown(x, y: integer; shiftstate: word); +procedure TfpgBaseListBox.HandleLMouseDown(x, y: integer; shiftstate: TShiftState); begin inherited HandleLMouseDown(x, y, shiftstate); @@ -376,7 +381,7 @@ begin DoChange; end; -procedure TfpgBaseListBox.HandleLMouseUp(x, y: integer; shiftstate: word); +procedure TfpgBaseListBox.HandleLMouseUp(x, y: integer; shiftstate: TShiftState); begin inherited HandleLMouseUp(x, y, shiftstate); if ItemCount < 1 then @@ -394,7 +399,7 @@ begin DoSelect; end; -procedure TfpgBaseListBox.HandleMouseMove(x, y: integer; btnstate: word; shiftstate: word); +procedure TfpgBaseListBox.HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); var oldf: integer; begin @@ -419,7 +424,7 @@ begin end; end; -procedure TfpgBaseListBox.HandleMouseScroll(x, y: integer; shiftstate: word; delta: smallint); +procedure TfpgBaseListBox.HandleMouseScroll(x, y: integer; shiftstate: TShiftState; delta: smallint); var pfi: integer; begin diff --git a/prototypes/fpgui2/source/gui/gui_memo.pas b/prototypes/fpgui2/source/gui/gui_memo.pas index 23da587b..2c6d1089 100644 --- a/prototypes/fpgui2/source/gui/gui_memo.pas +++ b/prototypes/fpgui2/source/gui/gui_memo.pas @@ -62,9 +62,9 @@ type procedure SetCursorLine(aValue: integer); procedure UpdateScrollBarCoords; protected - procedure HandleKeyChar(var keycode: word; var shiftstate: word; var consumed: boolean); override; - procedure HandleLMouseDown(x, y: integer; shiftstate: word); override; - procedure HandleMouseMove(x, y: integer; btnstate, shiftstate: word); override; + procedure HandleKeyChar(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); override; + procedure HandleLMouseDown(x, y: integer; shiftstate: TShiftState); override; + procedure HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); override; procedure HandleResize(dwidth, dheight: integer); override; //procedure HandleWindowScroll(direction, amount : integer); override; procedure HandlePaint; override; @@ -713,7 +713,7 @@ begin Canvas.EndDraw; end; -procedure TfpgMemo.HandleKeyChar(var keycode: word; var shiftstate: word; var consumed: boolean); +procedure TfpgMemo.HandleKeyChar(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); var prevval: string; s: string; @@ -752,15 +752,15 @@ begin begin // checking for movement keys: consumed := True; - FSelecting := (shiftstate and ss_shift) <> 0; + FSelecting := (ssShift in shiftstate); case keycode of - KEY_LEFT: + keyLeft: if FCursorPos > 0 then begin Dec(FCursorPos); - if (shiftstate and ss_control) <> 0 then + if (ssCtrl in shiftstate) then // word search... (* while (FCursorPos > 0) and not pgfIsAlphaNum(copy(CurrentLine,FCursorPos,1)) @@ -772,12 +772,12 @@ begin end;// left - KEY_RIGHT: + keyRight: if FCursorPos < UTF8Length(CurrentLine) then begin Inc(FCursorPos); - if (shiftstate and ss_control) <> 0 then + if (ssCtrl in shiftstate) then // word search... (* while (FCursorPos < length(CurrentLine)) and pgfIsAlphaNum(copy(CurrentLine,FCursorPos+1,1)) @@ -789,7 +789,7 @@ begin end;// right - KEY_UP: + keyUp: begin // up cx := GetCursorX; if FCursorLine > 1 then @@ -799,8 +799,8 @@ begin end; end; - KEY_DOWN: - begin // down + keyDown: + begin cx := GetCursorX; if FCursorLine < LineCount then begin @@ -808,21 +808,22 @@ begin SetCPByX(cx); end; end; - KEY_HOME: + + keyHome: begin - if (shiftstate and ss_control) <> 0 then + if (ssCtrl in shiftstate) then FCursorLine := 1; - FCursorPos := 0;// home + FCursorPos := 0; end; - KEY_END: + keyEnd: begin - if (shiftstate and ss_control) <> 0 then + if (ssCtrl in shiftstate) then FCursorLine := LineCount; - FCursorPos := UTF8Length(CurrentLine);// end + FCursorPos := UTF8Length(CurrentLine); end; - KEY_PGUP: + keyPageUp: if FCursorLine > 1 then begin cx := GetCursorX; @@ -830,10 +831,10 @@ begin if FCursorLine < 1 then FCursorLine := 1; SetCPByX(cx); - end;// pgup + end; - KEY_PGDN: - begin // pgdown + keyPageDown: + begin cx := GetCursorX; if FCursorLine < LineCount then begin @@ -867,49 +868,49 @@ begin consumed := True; case keycode of - KEY_ENTER: - begin // enter - ls := UTF8Copy(FLines[FCursorline - 1], 1, FCursorPos); - ls2 := UTF8Copy(FLines[FCursorline - 1], FCursorPos + 1, UTF8Length(FLines[FCursorline - 1])); - FLines.Insert(FCursorLine - 1, ls); - Inc(FCursorLine); - SetLineText(FCursorLine, ls2); - FCursorPos := 0; - end; - KEY_BACKSPACE: - if FCursorPos > 0 then - begin - ls := GetLineText(FCursorLine); - Delete(ls, FCursorPos, 1); - SetLineText(FCursorLine, ls); - Dec(FCursorPos); - end - else if FCursorLine > 1 then - begin - ls := CurrentLine; - FLines.Delete(FCursorLine - 1); - Dec(FCursorLine); - FCursorPos := UTF8Length(FLines.Strings[FCursorLine - 1]); - FLines.Strings[FCursorLine - 1] := FLines.Strings[FCursorLine - 1] + ls; - end;// backspace - - KEY_DELETE: - begin // del - ls := GetLineText(FCursorLine); - if FSelEndLine > 0 then - DeleteSelection - else if FCursorPos < UTF8Length(ls) then - begin - Delete(ls, FCursorPos + 1, 1); - SetLineText(FCursorLine, ls); - end - else if FCursorLine < LineCount then - begin - ls2 := FLines.Strings[FCursorLine]; - FLines.Delete(FCursorLine); - FLines.Strings[FCursorLine - 1] := ls + ls2; - end; - end; + keyReturn: + begin + ls := UTF8Copy(FLines[FCursorline - 1], 1, FCursorPos); + ls2 := UTF8Copy(FLines[FCursorline - 1], FCursorPos + 1, UTF8Length(FLines[FCursorline - 1])); + FLines.Insert(FCursorLine - 1, ls); + Inc(FCursorLine); + SetLineText(FCursorLine, ls2); + FCursorPos := 0; + end; + keyBackSpace: + if FCursorPos > 0 then + begin + ls := GetLineText(FCursorLine); + Delete(ls, FCursorPos, 1); + SetLineText(FCursorLine, ls); + Dec(FCursorPos); + end + else if FCursorLine > 1 then + begin + ls := CurrentLine; + FLines.Delete(FCursorLine - 1); + Dec(FCursorLine); + FCursorPos := UTF8Length(FLines.Strings[FCursorLine - 1]); + FLines.Strings[FCursorLine - 1] := FLines.Strings[FCursorLine - 1] + ls; + end; + + keyDelete: + begin + ls := GetLineText(FCursorLine); + if FSelEndLine > 0 then + DeleteSelection + else if FCursorPos < UTF8Length(ls) then + begin + Delete(ls, FCursorPos + 1, 1); + SetLineText(FCursorLine, ls); + end + else if FCursorLine < LineCount then + begin + ls2 := FLines.Strings[FCursorLine]; + FLines.Delete(FCursorLine); + FLines.Strings[FCursorLine - 1] := ls + ls2; + end; + end; else consumed := False; end; @@ -921,6 +922,7 @@ begin end; end; + {$Note This must be fixed. We change keycodes!! } if not Consumed and (keycode >= 32) and (keycode < $FF00) then begin // printeable @@ -950,7 +952,7 @@ begin RePaint; end; -procedure TfpgMemo.HandleLMouseDown(x, y: integer; shiftstate: word); +procedure TfpgMemo.HandleLMouseDown(x, y: integer; shiftstate: TShiftState); var s: string; n: integer; @@ -988,7 +990,7 @@ begin FCursorPos := cp; FCursorLine := lnum; - if (shiftstate and ss_shift) <> 0 then + if (ssShift in shiftstate) then begin FSelEndLine := lnum; FSelEndpos := cp; @@ -1002,7 +1004,7 @@ begin Repaint; end; -procedure TfpgMemo.HandleMouseMove(x, y: integer; btnstate, shiftstate: word); +procedure TfpgMemo.HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); var s: string; n: integer; diff --git a/prototypes/fpgui2/source/gui/gui_scrollbar.pas b/prototypes/fpgui2/source/gui/gui_scrollbar.pas index 1c1bb7e5..9f3ee7cd 100644 --- a/prototypes/fpgui2/source/gui/gui_scrollbar.pas +++ b/prototypes/fpgui2/source/gui/gui_scrollbar.pas @@ -45,9 +45,9 @@ type procedure ScrollTimer(Sender: TObject); procedure DrawButton(x, y, w, h: TfpgCoord; const imgname: string; Pressed: Boolean = False); procedure DrawSlider(recalc: boolean); - procedure HandleLMouseDown(x, y: integer; shiftstate: word); override; - procedure HandleLMouseUp(x, y: integer; shiftstate: word); override; - procedure HandleMouseMove(x, y: integer; btnstate, shiftstate: word); override; + procedure HandleLMouseDown(x, y: integer; shiftstate: TShiftState); override; + procedure HandleLMouseUp(x, y: integer; shiftstate: TShiftState); override; + procedure HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); override; procedure HandlePaint; override; procedure PositionChange(d: integer); public @@ -203,7 +203,7 @@ begin end; end; -procedure TfpgScrollBar.HandleLMouseDown(x, y: integer; shiftstate: word); +procedure TfpgScrollBar.HandleLMouseDown(x, y: integer; shiftstate: TShiftState); begin inherited; @@ -262,7 +262,7 @@ begin end; end; -procedure TfpgScrollBar.HandleLMouseUp(x, y: integer; shiftstate: word); +procedure TfpgScrollBar.HandleLMouseUp(x, y: integer; shiftstate: TShiftState); var WasPressed: Boolean; begin @@ -275,7 +275,7 @@ begin if WasPressed then HandlePaint; end; -procedure TfpgScrollBar.HandleMouseMove(x, y: integer; btnstate, shiftstate: word); +procedure TfpgScrollBar.HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); var d: integer; area: integer; diff --git a/prototypes/fpgui2/tests/edittest.lpi b/prototypes/fpgui2/tests/edittest.lpi index 269ce784..3e9244a7 100644 --- a/prototypes/fpgui2/tests/edittest.lpi +++ b/prototypes/fpgui2/tests/edittest.lpi @@ -1,7 +1,7 @@ <?xml version="1.0"?> <CONFIG> <ProjectOptions> - <PathDelim Value="\"/> + <PathDelim Value="/"/> <Version Value="5"/> <General> <Flags> @@ -9,7 +9,7 @@ </Flags> <SessionStorage Value="InProjectDir"/> <MainUnit Value="0"/> - <IconPath Value=".\"/> + <IconPath Value="./"/> <TargetFileExt Value=""/> </General> <VersionInfo> @@ -23,7 +23,7 @@ <RunParams> <local> <FormatVersion Value="1"/> - <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/> + <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> </local> </RunParams> <RequiredPackages Count="1"> @@ -46,7 +46,6 @@ </ProjectOptions> <CompilerOptions> <Version Value="5"/> - <PathDelim Value="\"/> <CodeGeneration> <Generate Value="Faster"/> </CodeGeneration> |