From 1f2999cf65d1fa09a2f0eadcb577247d24b3fd29 Mon Sep 17 00:00:00 2001 From: cxl Date: Fri, 12 Sep 2008 07:31:28 +0000 Subject: [PATCH] Improved Keyboard shortcuts dialog git-svn-id: svn://ultimatepp.org/upp/trunk@429 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlLib/AKeys.cpp | 47 +++++++++++++++++----------------------- uppsrc/CtrlLib/Ctrl.lay | 14 +++++------- 2 files changed, 26 insertions(+), 35 deletions(-) diff --git a/uppsrc/CtrlLib/AKeys.cpp b/uppsrc/CtrlLib/AKeys.cpp index 65c63e811..5f80cce21 100644 --- a/uppsrc/CtrlLib/AKeys.cpp +++ b/uppsrc/CtrlLib/AKeys.cpp @@ -44,7 +44,7 @@ void SetDefaultKeys() { struct KeyDisplay : Display { virtual void Paint(Draw& w, const Rect& r, const Value& q, - Color ink, Color paper, dword) const { + Color ink, Color paper, dword flags) const { w.DrawRect(r, paper); String txt = GetKeyDesc(int(q)); int tcy = GetTextSize(txt, StdFont()).cy; @@ -82,6 +82,7 @@ struct KeyCtrl : Ctrl { } KeyCtrl() { + Transparent(); SetFrame(EditFieldFrame()); key = 0; } @@ -90,11 +91,8 @@ struct KeyCtrl : Ctrl { struct KeysDlg : WithKeysLayout { virtual bool Key(dword key, int); - KeyCtrl key[3]; - void EnterGroup(); - void EnterKey(); - void SetKey(); + void KeyEdit(); void Defaults(); void CopyKeys(); @@ -106,18 +104,21 @@ struct KeysDlg : WithKeysLayout { CtrlLayoutOKCancel(*this, t_("Configure keyboard shortcuts")); group.AddColumn(t_("Group")); group.WhenEnterRow = THISBACK(EnterGroup); - keys.AddColumn(t_("Action"), 2); - keys.AddColumn(t_("Primary")).SetDisplay(Single()); - keys.AddColumn(t_("Secondary")).SetDisplay(Single()); - keys.WhenEnterRow = THISBACK(EnterKey); - key[0] <<= key[1] <<= THISBACK(SetKey); + group.NoGrid(); + keys.AddColumn(t_("Action")); + keys.AddColumn(t_("Primary")).Ctrls(); + keys.AddColumn(t_("Secondary")).Ctrls(); + keys.SetLineCy(EditField::GetStdHeight() + 2); + keys.NoHorzGrid().NoCursor().EvenRowColor(); + keys.ColumnWidths("182 132 133"); + keys.WhenCtrlsAction = THISBACK(KeyEdit); defaults <<= THISBACK(Defaults); } }; bool KeysDlg::Key(dword key, int count) { - if(key == K_F3) { + if(key == K_F3) { // 'hidden trick' to retrieve the document String qtf; for(int i = 0; i < sKeys().GetCount(); i++) { qtf << "&&&" << DeQtf(sKeys().GetKey(i)) << "&&{{1:1 "; @@ -163,25 +164,17 @@ void KeysDlg::EnterGroup() keys.GoBegin(); } -void KeysDlg::EnterKey() +void KeysDlg::KeyEdit() { - if(!keys.IsCursor()) - return; - key[0] <<= keys.Get(1); - key[1] <<= keys.Get(2); -} - -void KeysDlg::SetKey() -{ - if(!keys.IsCursor()) - return; - keys.Set(1, ~key[0]); - keys.Set(2, ~key[1]); String g = group.GetKey(); int q = sKeys().Find(g); - KeyInfo& a = *(sKeys()[q][keys.GetCursor()].key); - a.key[0] = (dword)(int)~key[0]; - a.key[1] = (dword)(int)~key[1]; + if(q < 0) + return; + for(int i = 0; i < keys.GetCount(); i++) { + KeyInfo& a = *(sKeys()[q][i].key); + a.key[0] = (dword)(int)keys.Get(i, 1); + a.key[1] = (dword)(int)keys.Get(i, 2); + } } void KeysDlg::Defaults() diff --git a/uppsrc/CtrlLib/Ctrl.lay b/uppsrc/CtrlLib/Ctrl.lay index b0cea9d24..942405ff1 100644 --- a/uppsrc/CtrlLib/Ctrl.lay +++ b/uppsrc/CtrlLib/Ctrl.lay @@ -78,14 +78,12 @@ LAYOUT(PalCtrlSizeLayout, 206, 60) ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(4, 80).BottomPosZ(4, 22)) END_LAYOUT -LAYOUT(KeysLayout, 540, 388) - ITEM(ArrayCtrl, group, LeftPosZ(8, 116).TopPosZ(8, 308)) - ITEM(ArrayCtrl, keys, LeftPosZ(132, 400).TopPosZ(8, 308)) - UNTYPED(key[0], LeftPosZ(132, 196).TopPosZ(324, 20)) - UNTYPED(key[1], LeftPosZ(332, 196).TopPosZ(324, 20)) - ITEM(Button, ok, SetLabel(t_("OK")).LeftPosZ(400, 64).TopPosZ(356, 24)) - ITEM(Button, cancel, SetLabel(t_("Cancel")).LeftPosZ(468, 64).TopPosZ(356, 24)) - ITEM(Button, defaults, SetLabel(t_("Default")).LeftPosZ(8, 64).TopPosZ(324, 24)) +LAYOUT(KeysLayout, 604, 500) + ITEM(ArrayCtrl, group, LeftPosZ(8, 116).TopPosZ(8, 452)) + ITEM(ArrayCtrl, keys, LeftPosZ(132, 464).TopPosZ(8, 452)) + ITEM(Button, ok, SetLabel(t_("OK")).LeftPosZ(464, 64).TopPosZ(468, 24)) + ITEM(Button, cancel, SetLabel(t_("Cancel")).LeftPosZ(532, 64).TopPosZ(468, 24)) + ITEM(Button, defaults, SetLabel(t_("Defaults")).LeftPosZ(8, 64).TopPosZ(468, 24)) END_LAYOUT LAYOUT(PrinterLayout, 372, 264)