OSDN Git Service

避難所版
[gikonavigoeson/gikonavi.git] / KeySetting.pas
index 52d17f0..eb1adf3 100644 (file)
@@ -4,16 +4,19 @@ interface
 
 uses
        Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
-       Dialogs, ComCtrls, StdCtrls, ExtCtrls, ActnList, Menus, GikoSystem, GikoUtil;
+       Dialogs, ComCtrls, StdCtrls, ExtCtrls, ActnList, Menus,
+       Editor;
 
 type
        TKeySettingItem = class(TObject)
        private
                FAction: TAction;
                FShortCut: TShortCut;
+               FGesture        : string;
        public
                property Action: TAction read FAction write FAction;
                property ShortCut: TShortCut read FShortCut write FShortCut;
+               property Gesture : string read FGesture write FGesture;
        end;
 
        TKeySettingForm = class(TForm)
@@ -33,6 +36,10 @@ type
     TabSheet2: TTabSheet;
     ListView: TListView;
     ListView1: TListView;
+    GestureLabel: TLabel;
+    GestureEdit: TEdit;
+    GestureSetButton: TButton;
+    GestureCheckBox: TCheckBox;
                procedure FormCreate(Sender: TObject);
                procedure FormDestroy(Sender: TObject);
     procedure ListViewSelectItem(Sender: TObject; Item: TListItem;
@@ -45,10 +52,19 @@ type
     procedure OkBottonClick(Sender: TObject);
     procedure ListViewCompare(Sender: TObject; Item1, Item2: TListItem;
       Data: Integer; var Compare: Integer);
+    procedure GestureSetButtonClick(Sender: TObject);
+               procedure OnGestureStart(Sender: TObject);
+               procedure OnGestureMove(Sender: TObject);
+               procedure OnGestureEnd(Sender: TObject);
+    procedure GestureCheckBoxClick(Sender: TObject);
+    procedure GestureEditChange(Sender: TObject);
+    procedure GestureEditKeyDown(Sender: TObject; var Key: Word;
+      Shift: TShiftState);
        private
                { Private \90é\8c¾ }
        public
                { Public \90é\8c¾ }
+               EditorForm: TEditorForm;
        end;
 
 //var
@@ -56,7 +72,11 @@ type
 
 implementation
 
-uses Giko;
+uses
+       Giko, GikoUtil, Gesture, GikoDataModule, GikoSystem;
+
+const
+       GUESTURE_NOTHING        = '\82È\82µ';
 
 {$R *.dfm}
 
@@ -65,27 +85,68 @@ var
        i: Integer;
        ListItem: TListItem;
        KeyItem: TKeySettingItem;
+
 begin
-       for i := 0 to GikoForm.ActionList.ActionCount - 1 do begin
-               if GikoForm.ActionList.Actions[i] is TAction then begin
-                       if GikoForm.ActionList.Actions[i].Tag <> 0 then
+       //for i := 0 to GikoForm.ActionList.ActionCount - 1 do begin
+       for i := 0 to GikoDM.GikoFormActionList.ActionCount - 1 do begin
+               //if GikoForm.ActionList.Actions[i] is TAction then begin
+               if GikoDM.GikoFormActionList.Actions[i] is TAction then begin
+                       if GikoDM.GikoFormActionList.Actions[i].Tag <> 0 then
                                Continue;
                        ListItem := ListView.Items.Add;
-                       ListItem.Caption := TAction(GikoForm.ActionList.Actions[i]).Hint;
-                       ListItem.SubItems.Add(TAction(GikoForm.ActionList.Actions[i]).Category);
-                       ListItem.SubItems.Add(ShortCutToText(TAction(GikoForm.ActionList.Actions[i]).ShortCut));
-                       ListItem.ImageIndex := TAction(GikoForm.ActionList.Actions[i]).ImageIndex;
+                       ListItem.Caption := TAction(GikoDM.GikoFormActionList.Actions[i]).Hint;
+                       ListItem.SubItems.Add(TAction(GikoDM.GikoFormActionList.Actions[i]).Category);
+                       ListItem.SubItems.Add(ShortCutToText(TAction(GikoDM.GikoFormActionList.Actions[i]).ShortCut));
+                       ListItem.SubItems.Add( GikoSys.Setting.Gestures.GetActionGesture(
+                               TAction( GikoDM.GikoFormActionList.Actions[i] ) ) );
+                       ListItem.ImageIndex := TAction(GikoDM.GikoFormActionList.Actions[i]).ImageIndex;
                        KeyItem := TKeySettingItem.Create;
-                       KeyItem.Action := TAction(GikoForm.ActionList.Actions[i]);
-                       KeyItem.ShortCut := TAction(GikoForm.ActionList.Actions[i]).ShortCut;
+                       KeyItem.Action := TAction(GikoDM.GikoFormActionList.Actions[i]);
+                       KeyItem.ShortCut := TAction(GikoDM.GikoFormActionList.Actions[i]).ShortCut;
+                       KeyItem.Gesture := GikoSys.Setting.Gestures.GetActionGesture(
+                               TAction( GikoDM.GikoFormActionList.Actions[i] ) );
                        ListItem.Data := KeyItem;
                end;
        end;
        if ListView.Items.Count > 0 then
                ListView.Selected := ListView.Items[0];
+       EditorForm := TEditorForm.Create(Self);
+       try
+               for i := 0 to EditorForm.ActionList.ActionCount - 1 do begin
+                       if EditorForm.ActionList.Actions[i] is TAction then begin
+                               if EditorForm.ActionList.Actions[i].Tag <> 0 then
+                                       Continue;
+                               ListItem := ListView1.Items.Add;
+                               ListItem.Caption := TAction(EditorForm.ActionList.Actions[i]).Hint;
+                               ListItem.SubItems.Add(TAction(EditorForm.ActionList.Actions[i]).Category);
+                               ListItem.SubItems.Add(ShortCutToText(TAction(EditorForm.ActionList.Actions[i]).ShortCut));
+                               ListItem.ImageIndex := TAction(EditorForm.ActionList.Actions[i]).ImageIndex;
+                               ListItem.SubItems.Add( GikoSys.Setting.Gestures.GetActionGesture(
+                                       TAction( EditorForm.ActionList.Actions[i] ) ) );
+                               KeyItem := TKeySettingItem.Create;
+                               KeyItem.Action := TAction(EditorForm.ActionList.Actions[i]);
+                               KeyItem.ShortCut := TAction(EditorForm.ActionList.Actions[i]).ShortCut;
+                               KeyItem.Gesture := GikoSys.Setting.Gestures.GetActionGesture(
+                                       TAction( EditorForm.ActionList.Actions[i] ) );
+                               ListItem.Data := KeyItem;
+                       end;
+               end;
+               ListView1.SmallImages := EditorForm.HotToobarImageList;
+       finally
+
+       end;
 //     ActionListView.SortType := stText;
        StatusBar.Height := 21;
        StatusBar.Width := 21;
+       PageControl1.ActivePageIndex := 0;
+       GestureCheckBox.Checked := GikoSys.Setting.GestureEnabled;
+       GestureCheckBoxClick( Sender );
+
+       MouseGesture.UnHook;
+       MouseGesture.OnGestureStart := OnGestureStart;
+       MouseGesture.OnGestureMove := OnGestureMove;
+       MouseGesture.OnGestureEnd := OnGestureEnd;
+       MouseGesture.SetHook( Handle );
 end;
 
 procedure TKeySettingForm.FormDestroy(Sender: TObject);
@@ -96,6 +157,11 @@ begin
                if TObject(ListView.Items[i].Data) is TKeySettingItem then
                        TKeySettingItem(ListView.Items[i].Data).Free;
        end;
+       for i := 0 to ListView1.Items.Count - 1 do begin
+               if TObject(ListView1.Items[i].Data) is TKeySettingItem then
+                       TKeySettingItem(ListView1.Items[i].Data).Free;
+       end;
+        EditorForm.Release;
 end;
 
 procedure TKeySettingForm.ListViewSelectItem(Sender: TObject;
@@ -108,6 +174,7 @@ begin
        if TObject(Item.Data) is TKeySettingItem then begin
                KeyItem := TKeySettingItem(Item.Data);
                HotKey.HotKey := KeyItem.ShortCut;
+               GestureEdit.Text := KeyItem.Gesture;
        end;
 end;
 
@@ -141,8 +208,14 @@ var
        i: Integer;
        Item: TListItem;
        KeyItem: TKeySettingItem;
+    ActiveListView: TListView;
 begin
-       if ListView.Selected = nil then Exit;
+               if PageControl1.ActivePage.TabIndex <> 0 then
+       ActiveListView := ListView1
+    else
+       ActiveListView := ListView;
+
+       if ActiveListView.Selected = nil then Exit;
        if HotKey.HotKey = 13 then begin
                MsgBox(Handle, ERR_ENT, ERR_TITLE, MB_OK or MB_ICONSTOP);
                HotKey.SetFocus;
@@ -150,10 +223,10 @@ begin
        end;
 
        //\8c»\8dÝ\91I\91ð\82³\82ê\82Ä\82¢\82éAction\88È\8aO\82Å\93¯\82\83V\83\87\81[\83g\83J\83b\83g\82ª\82 \82ê\82Î\83G\83\89\81[\82Æ\82·\82é
-       for i := 0 to ListView.Items.Count - 1 do begin
-               if ListView.Selected = ListView.Items[i] then
+       for i := 0 to ActiveListView.Items.Count - 1 do begin
+               if ActiveListView.Selected = ActiveListView.Items[i] then
                        Continue;
-               Item := ListView.Items[i];
+               Item := ActiveListView.Items[i];
                if TObject(Item.Data) is TKeySettingItem then begin
                        KeyItem := TKeySettingItem(Item.Data);
                        if (HotKey.HotKey <> 0) and (KeyItem.ShortCut = HotKey.HotKey) then begin
@@ -164,10 +237,10 @@ begin
                end;
        end;
        //\83V\83\87\81[\83g\83J\83b\83g\90Ý\92è
-       if TObject(ListView.Selected.Data) is TKeySettingItem then begin
-               KeyItem := TKeySettingItem(ListView.Selected.Data);
+       if TObject(ActiveListView.Selected.Data) is TKeySettingItem then begin
+               KeyItem := TKeySettingItem(ActiveListView.Selected.Data);
                KeyItem.ShortCut := HotKey.HotKey;
-               ListView.Selected.SubItems[1] := ShortCutToText(HotKey.HotKey);
+               ActiveListView.Selected.SubItems[1] := ShortCutToText(HotKey.HotKey);
        end;
 end;
 
@@ -177,24 +250,136 @@ var
        Item: TListItem;
        KeyItem: TKeySettingItem;
 begin
+
+       GikoSys.Setting.GestureEnabled := GestureCheckBox.Checked;
+       GikoSys.Setting.Gestures.ClearGesture;
        for i := 0 to ListView.Items.Count - 1 do begin
                Item := ListView.Items[i];
                if TObject(Item.Data) is TKeySettingItem then begin
                        KeyItem := TKeySettingItem(Item.Data);
                        KeyItem.Action.ShortCut := KeyItem.ShortCut;
+                       GikoSys.Setting.Gestures.AddGesture( KeyItem.Gesture, KeyItem.Action );
+               end;
+       end;
+       for i := 0 to ListView1.Items.Count - 1 do begin
+               Item := ListView1.Items[i];
+               if TObject(Item.Data) is TKeySettingItem then begin
+                       KeyItem := TKeySettingItem(Item.Data);
+                       KeyItem.Action.ShortCut := KeyItem.ShortCut;
+                       GikoSys.Setting.Gestures.AddGesture( KeyItem.Gesture, KeyItem.Action );
                end;
        end;
+
 end;
 
 procedure TKeySettingForm.ListViewCompare(Sender: TObject; Item1,
   Item2: TListItem; Data: Integer; var Compare: Integer);
 begin
        if Item1.SubItems[0] > Item2.SubItems[0] then
-               Compare := 1
-       else if Item1.SubItems[0] < Item2.SubItems[0] then
-               Compare := -1
+               Compare := 1
+       else if Item1.SubItems[0] < Item2.SubItems[0] then
+               Compare := -1
+       else
+               Compare := 0;
+end;
+
+procedure TKeySettingForm.GestureSetButtonClick(Sender: TObject);
+const
+       ERR_MSG = '\93ü\97Í\82µ\82½\83W\83F\83X\83`\83\83\81[\82Í\8aù\82É\8eg\97p\82³\82ê\82Ä\82¢\82Ü\82·';
+       ERR_TITLE = '\83G\83\89\81[';
+var
+       i, j: Integer;
+       Item: TListItem;
+       KeyItem: TKeySettingItem;
+       ActiveListView: TListView;
+       chechList : TListView;
+begin
+       if PageControl1.ActivePage.TabIndex <> 0 then
+               ActiveListView := ListView1
        else
-               Compare := 0;
+               ActiveListView := ListView;
+
+       if ActiveListView.Selected = nil then Exit;
+       if (GetKeyState( VK_SHIFT ) and $80000000) <> 0 then begin
+               GestureEdit.Text := '';
+               Item := ActiveListView.Selected;
+               Item.SubItems[2] := '';
+               if TObject(Item.Data) is TKeySettingItem then begin
+                       KeyItem := TKeySettingItem(Item.Data);
+                       KeyItem.Gesture := '';
+               end;
+               Exit;
+       end;
+
+       // \8c»\8dÝ\91I\91ð\82³\82ê\82Ä\82¢\82éAction\88È\8aO\82Å\93¯\82\83W\83F\83X\83`\83\83\81[\82ª\82 \82ê\82Î\83G\83\89\81[\82Æ\82·\82é
+       chechList := ListView;
+       for j := 0 to 1 do begin
+               if j <> 0 then begin
+                       chechList := ListView1;
+               end;
+
+               for i := 0 to chechList.Items.Count - 1 do begin
+                       if ActiveListView.Selected = chechList.Items[i] then
+                               Continue;
+                       Item := chechList.Items[i];
+                       if TObject(Item.Data) is TKeySettingItem then begin
+                               KeyItem := TKeySettingItem(Item.Data);
+                               if (GestureEdit.Text <> GUESTURE_NOTHING)
+                               and (KeyItem.Gesture = GestureEdit.Text) then begin
+                                       MsgBox(Handle, ERR_MSG, ERR_TITLE, MB_OK or MB_ICONSTOP);
+                                       HotKey.SetFocus;
+                                       Exit;
+                               end;
+                       end;
+               end;
+       end;
+
+       // \83W\83F\83X\83`\83\83\81[\90Ý\92è
+       if TObject(ActiveListView.Selected.Data) is TKeySettingItem then begin
+               KeyItem := TKeySettingItem(ActiveListView.Selected.Data);
+               KeyItem.Gesture := GestureEdit.Text;
+               if GestureEdit.Text = GUESTURE_NOTHING then
+                       ActiveListView.Selected.SubItems[2] := ''
+               else
+                       ActiveListView.Selected.SubItems[2] := GestureEdit.Text;
+       end;
+end;
+
+procedure TKeySettingForm.OnGestureStart(Sender: TObject);
+begin
+       GestureEdit.Text := '';
+end;
+
+procedure TKeySettingForm.OnGestureMove(Sender: TObject);
+begin
+       GestureEdit.Text := MouseGesture.GetGestureStr;
+end;
+
+procedure TKeySettingForm.OnGestureEnd(Sender: TObject);
+begin
+       GestureEdit.Text := MouseGesture.GetGestureStr;
+    MouseGesture.Clear;
+end;
+
+procedure TKeySettingForm.GestureCheckBoxClick(Sender: TObject);
+begin
+       GestureEdit.Enabled := GestureCheckBox.Checked;
+       GestureSetButton.Enabled := GestureCheckBox.Checked;
+end;
+
+procedure TKeySettingForm.GestureEditChange(Sender: TObject);
+begin
+
+       if GestureEdit.Text = '' then
+               GestureEdit.Text := GUESTURE_NOTHING;
+
+end;
+
+procedure TKeySettingForm.GestureEditKeyDown(Sender: TObject;
+  var Key: Word; Shift: TShiftState);
+begin
+       if (ssShift in Shift) and (MouseGesture.GetGestureStr = '') then
+       GestureEdit.Text := '';
 end;
 
 end.