Rights.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include "Rights.h"
  6. #include <VCLCommon.h>
  7. #include <Tools.h>
  8. #include <TextsWin.h>
  9. //---------------------------------------------------------------------------
  10. #pragma package(smart_init)
  11. #pragma link "GrayedCheckBox"
  12. #pragma link "PngImageList"
  13. #pragma resource "*.dfm"
  14. //---------------------------------------------------------------------------
  15. __fastcall TRightsFrame::TRightsFrame(TComponent* Owner)
  16. : TFrame(Owner)
  17. {
  18. FAddXToDirectoriesSuffix = L"+x";
  19. FOnChange = NULL;
  20. FAllowAddXToDirectories = true;
  21. FPopup = false;
  22. FPopupParent = NULL;
  23. FDefaultButton = NULL;
  24. FCancelButton = NULL;
  25. // to avoid duplication of reference in forms that uses the frame
  26. PopupMenu = RightsPopup;
  27. FPopingContextMenu = false;
  28. FInitialized = false;
  29. FAcl = false;
  30. #define COPY_HINT(R) \
  31. Checks[TRights::rrGroup ## R]->Hint = Checks[TRights::rrUser ## R]->Hint; \
  32. Checks[TRights::rrOther ## R]->Hint = Checks[TRights::rrUser ## R]->Hint;
  33. COPY_HINT(Read);
  34. COPY_HINT(Write);
  35. COPY_HINT(Exec);
  36. #undef COPY_HINT
  37. UpgradeSpeedButton(OwnerButton);
  38. UpgradeSpeedButton(GroupButton);
  39. UpgradeSpeedButton(OthersButton);
  40. }
  41. //---------------------------------------------------------------------------
  42. __fastcall TRightsFrame::~TRightsFrame()
  43. {
  44. }
  45. //---------------------------------------------------------------------------
  46. void __fastcall TRightsFrame::SetStates(TRights::TRight Right, TRights::TState value)
  47. {
  48. DebugAssert(((value == TRights::rsNo) || (value == TRights::rsYes) || (value == TRights::rsUndef)));
  49. TCheckBox * CheckBox = Checks[Right];
  50. if (CheckBox != NULL)
  51. {
  52. switch (value) {
  53. case TRights::rsNo: CheckBox->State = cbUnchecked; break;
  54. case TRights::rsYes: CheckBox->State = cbChecked; break;
  55. case TRights::rsUndef: CheckBox->State = cbGrayed; break;
  56. }
  57. }
  58. }
  59. //---------------------------------------------------------------------------
  60. TRights::TState __fastcall TRightsFrame::GetStates(TRights::TRight Right)
  61. {
  62. TCheckBox * CheckBox = Checks[Right];
  63. if (CheckBox != NULL)
  64. {
  65. switch (CheckBox->State) {
  66. case cbUnchecked: return TRights::rsNo;
  67. case cbChecked: return TRights::rsYes;
  68. case cbGrayed:
  69. default: return TRights::rsUndef;
  70. }
  71. }
  72. else
  73. {
  74. return TRights::rsNo;
  75. }
  76. }
  77. //---------------------------------------------------------------------------
  78. void __fastcall TRightsFrame::SetRights(const TRights & value)
  79. {
  80. bool Changed = (AllowUndef != value.AllowUndef);
  81. AllowUndef = true; // temporarily
  82. for (int Right = TRights::rrFirst; Right <= TRights::rrLast; Right++)
  83. {
  84. TRights::TRight R = static_cast<TRights::TRight>(Right);
  85. if (States[R] != value.RightUndef[R])
  86. {
  87. States[R] = value.RightUndef[R];
  88. Changed = true;
  89. }
  90. }
  91. AllowUndef = value.AllowUndef;
  92. if (Changed || !FInitialized)
  93. {
  94. UpdateControls();
  95. }
  96. }
  97. //---------------------------------------------------------------------------
  98. TRights __fastcall TRightsFrame::GetRights()
  99. {
  100. TRights Result;
  101. Result.AllowUndef = AllowUndef;
  102. for (int Right = TRights::rrFirst; Right <= TRights::rrLast; Right++)
  103. {
  104. Result.RightUndef[static_cast<TRights::TRight>(Right)] =
  105. States[static_cast<TRights::TRight>(Right)];
  106. }
  107. return Result;
  108. }
  109. //---------------------------------------------------------------------------
  110. void __fastcall TRightsFrame::SetAllowUndef(bool value)
  111. {
  112. for (int Right = TRights::rrFirst; Right <= TRights::rrLast; Right++)
  113. {
  114. TCheckBox * CheckBox = Checks[static_cast<TRights::TRight>(Right)];
  115. if (CheckBox != NULL)
  116. {
  117. CheckBox->AllowGrayed = value;
  118. }
  119. }
  120. }
  121. //---------------------------------------------------------------------------
  122. bool __fastcall TRightsFrame::GetAllowUndef()
  123. {
  124. bool Result = false, First = true;
  125. for (int Right = TRights::rrFirst; Right <= TRights::rrLast; Right++)
  126. {
  127. TCheckBox * Check = Checks[static_cast<TRights::TRight>(Right)];
  128. if (Check != NULL)
  129. {
  130. if (First)
  131. {
  132. Result = Check->AllowGrayed;
  133. First = false;
  134. }
  135. else if (Result != Check->AllowGrayed)
  136. {
  137. DebugFail();
  138. }
  139. }
  140. }
  141. return Result;
  142. }
  143. //---------------------------------------------------------------------------
  144. TCheckBox * __fastcall TRightsFrame::GetChecks(TRights::TRight Right)
  145. {
  146. for (int Index = 0; Index < ControlCount; Index++)
  147. {
  148. if (Controls[Index]->InheritsFrom(__classid(TCheckBox)) &&
  149. (Controls[Index]->Tag == TRights::RightToFlag(Right)))
  150. {
  151. return ((TCheckBox *)Controls[Index]);
  152. }
  153. }
  154. return NULL;
  155. }
  156. //---------------------------------------------------------------------------
  157. void __fastcall TRightsFrame::SetAddXToDirectories(bool value)
  158. {
  159. DirectoriesXCheck->Checked = value;
  160. }
  161. //---------------------------------------------------------------------------
  162. bool __fastcall TRightsFrame::GetAddXToDirectories()
  163. {
  164. return DirectoriesXCheck->Checked;
  165. }
  166. //---------------------------------------------------------------------------
  167. void __fastcall TRightsFrame::ControlChange(TObject * /*Sender*/)
  168. {
  169. UpdateControls();
  170. }
  171. //---------------------------------------------------------------------------
  172. bool __fastcall TRightsFrame::DirectoriesXEffective()
  173. {
  174. return !((Rights.NumberSet & TRights::rfExec) == TRights::rfExec);
  175. }
  176. //---------------------------------------------------------------------------
  177. void __fastcall TRightsFrame::UpdateControls()
  178. {
  179. if (!OctalEdit->Focused())
  180. {
  181. UpdateOctalEdit();
  182. }
  183. Color = (FPopup ? clWindow : clBtnFace);
  184. DirectoriesXCheck->Visible = AllowAddXToDirectories;
  185. EnableControl(DirectoriesXCheck,
  186. Enabled && DirectoriesXEffective());
  187. FInitialized = true;
  188. DoChange();
  189. }
  190. //---------------------------------------------------------------------------
  191. void TRightsFrame::CycleRights(TRights::TRightGroup RightGroup)
  192. {
  193. int Last = FAcl ? TRights::rlLastAcl : TRights::rlLastNormal;
  194. TRights::TState State = TRights::TState(); // shut up
  195. bool Any = false;
  196. bool Same = true;
  197. for (int RightLevelI = TRights::rlFirst; RightLevelI <= Last; RightLevelI++)
  198. {
  199. TRights::TRightLevel RightLevel = static_cast<TRights::TRightLevel>(RightLevelI);
  200. TRights::TRight Right = TRights::CalculateRight(RightGroup, RightLevel);
  201. if (Checks[Right]->Visible)
  202. {
  203. TRights::TState RightState = States[Right];
  204. if (!Any)
  205. {
  206. State = RightState;
  207. Any = true;
  208. }
  209. else if (State != RightState)
  210. {
  211. Same = false;
  212. break;
  213. }
  214. }
  215. }
  216. if (DebugAlwaysTrue(Any))
  217. {
  218. if (!Same)
  219. {
  220. State = TRights::rsYes;
  221. }
  222. else
  223. {
  224. switch (State)
  225. {
  226. case TRights::rsYes:
  227. State = TRights::rsNo;
  228. break;
  229. case TRights::rsNo:
  230. State = AllowUndef ? TRights::rsUndef : TRights::rsYes;
  231. break;
  232. case TRights::rsUndef:
  233. State = TRights::rsYes;
  234. break;
  235. }
  236. }
  237. for (int RightLevelI = TRights::rlFirst; RightLevelI <= Last; RightLevelI++)
  238. {
  239. TRights::TRightLevel RightLevel = static_cast<TRights::TRightLevel>(RightLevelI);
  240. TRights::TRight Right = TRights::CalculateRight(RightGroup, RightLevel);
  241. States[Right] = State;
  242. }
  243. UpdateControls();
  244. }
  245. }
  246. //---------------------------------------------------------------------------
  247. void __fastcall TRightsFrame::RightsButtonsClick(TObject * Sender)
  248. {
  249. CycleRights(static_cast<TRights::TRightGroup>(dynamic_cast<TComponent *>(Sender)->Tag - 1));
  250. }
  251. //---------------------------------------------------------------------------
  252. void __fastcall TRightsFrame::SetAllowAddXToDirectories(bool value)
  253. {
  254. if ((FAllowAddXToDirectories != value) || !FInitialized)
  255. {
  256. FAllowAddXToDirectories = value;
  257. UpdateControls();
  258. }
  259. }
  260. //---------------------------------------------------------------------------
  261. void __fastcall TRightsFrame::DoChange()
  262. {
  263. if (FOnChange)
  264. {
  265. FOnChange(this);
  266. }
  267. }
  268. //---------------------------------------------------------------------------
  269. void __fastcall TRightsFrame::SetEnabled(bool Value)
  270. {
  271. TFrame::SetEnabled(Value);
  272. UpdateControls();
  273. }
  274. //---------------------------------------------------------------------------
  275. void __fastcall TRightsFrame::ForceUpdate()
  276. {
  277. UpdateOctalEdit();
  278. }
  279. //---------------------------------------------------------------------------
  280. bool __fastcall TRightsFrame::HasFocus()
  281. {
  282. return
  283. (Focused() ||
  284. ((Screen->ActiveControl != NULL) && (Screen->ActiveControl->Parent == this))) ||
  285. ((PopupParent != NULL) && PopupParent->Focused());
  286. }
  287. //---------------------------------------------------------------------------
  288. void __fastcall TRightsFrame::RightsActionsExecute(TBasicAction * Action,
  289. bool & Handled)
  290. {
  291. // prevent shortcuts to be evaluated when frame does not have a focus
  292. if (HasFocus())
  293. {
  294. bool Changed = true;
  295. TRights R = Rights;
  296. R.Number = TRights::rfNo;
  297. Handled = true;
  298. if (Action == NoRightsAction)
  299. {
  300. R = TRights::rfNo;
  301. }
  302. else if (Action == DefaultRightsAction)
  303. {
  304. R = TRights::rfDefault;
  305. }
  306. else if (Action == AllRightsAction)
  307. {
  308. R = TRights::rfAll;
  309. }
  310. else if (Action == LeaveRightsAsIsAction)
  311. {
  312. R.AllUndef();
  313. }
  314. else if (Action == CopyTextAction)
  315. {
  316. TInstantOperationVisualizer Visualizer;
  317. CopyToClipboard(Text);
  318. Changed = false;
  319. }
  320. else if (Action == CopyOctalAction)
  321. {
  322. TRights R = Rights;
  323. DebugAssert(!R.IsUndef);
  324. if (!R.IsUndef)
  325. {
  326. TInstantOperationVisualizer Visualizer;
  327. CopyToClipboard(R.Octal);
  328. }
  329. Changed = false;
  330. }
  331. else if (Action == PasteAction)
  332. {
  333. UnicodeString S;
  334. if (TextFromClipboard(S, true))
  335. {
  336. Text = S;
  337. }
  338. // trigger on change event, even if no change actually occurred to
  339. // allow parent form to visualize feedback of an action
  340. DoChange();
  341. // Update octal edit in Rights frame even if it has focus
  342. ForceUpdate();
  343. Changed = false;
  344. }
  345. else
  346. {
  347. Handled = false;
  348. }
  349. if (Changed)
  350. {
  351. Rights = R;
  352. ForceUpdate();
  353. DoChange();
  354. }
  355. }
  356. }
  357. //---------------------------------------------------------------------------
  358. void __fastcall TRightsFrame::RightsActionsUpdate(TBasicAction *Action,
  359. bool &Handled)
  360. {
  361. TRights R = Rights;
  362. Handled = true;
  363. if (Action == NoRightsAction)
  364. {
  365. // explicitly enable as action gets disabled, if its shortcut is pressed,
  366. // while the form does not have a focus and OnExecute handler denies the execution
  367. NoRightsAction->Enabled = !FAcl;
  368. NoRightsAction->Checked = !R.IsUndef && (R.NumberSet == TRights::rfNo);
  369. }
  370. else if (Action == DefaultRightsAction)
  371. {
  372. DefaultRightsAction->Enabled = !FAcl;
  373. DefaultRightsAction->Checked = !R.IsUndef && (R.NumberSet == TRights::rfDefault);
  374. }
  375. else if (Action == AllRightsAction)
  376. {
  377. AllRightsAction->Enabled = !FAcl;
  378. AllRightsAction->Checked = !R.IsUndef && (R.NumberSet == TRights::rfAll);
  379. }
  380. else if (Action == LeaveRightsAsIsAction)
  381. {
  382. LeaveRightsAsIsAction->Enabled = !FAcl;
  383. LeaveRightsAsIsAction->Visible = R.AllowUndef;
  384. LeaveRightsAsIsAction->Checked = (R.NumberSet == TRights::rfNo) &&
  385. (R.NumberUnset == TRights::rfNo);
  386. }
  387. else if (Action == CopyTextAction)
  388. {
  389. CopyTextAction->Enabled = !FAcl && !R.IsUndef;
  390. }
  391. else if (Action == CopyOctalAction)
  392. {
  393. CopyOctalAction->Enabled = !FAcl && !R.IsUndef;
  394. }
  395. else if (Action == PasteAction)
  396. {
  397. PasteAction->Enabled = !FAcl && IsFormatInClipboard(CF_TEXT);
  398. }
  399. else
  400. {
  401. Handled = false;
  402. }
  403. }
  404. //---------------------------------------------------------------------------
  405. void __fastcall TRightsFrame::CreateParams(TCreateParams & Params)
  406. {
  407. TFrame::CreateParams(Params);
  408. if (FPopup)
  409. {
  410. Params.Style |= WS_BORDER;
  411. }
  412. }
  413. //---------------------------------------------------------------------------
  414. void __fastcall TRightsFrame::CreateWnd()
  415. {
  416. if (FPopup)
  417. {
  418. Width += 2 * GetSystemMetricsForControl(Parent, SM_CXBORDER);
  419. Height += 2 * GetSystemMetricsForControl(Parent, SM_CYBORDER);
  420. }
  421. TFrame::CreateWnd();
  422. }
  423. //---------------------------------------------------------------------------
  424. void __fastcall TRightsFrame::SetPopup(bool value)
  425. {
  426. if (Popup != value)
  427. {
  428. FPopup = value;
  429. Visible = !FPopup;
  430. CloseButton->Visible = value;
  431. CloseButton->Cancel = value;
  432. CloseButton->Default = value;
  433. }
  434. }
  435. //---------------------------------------------------------------------------
  436. void __fastcall TRightsFrame::DoCloseUp()
  437. {
  438. Hide();
  439. if (FDefaultButton != NULL)
  440. {
  441. FDefaultButton->Default = true;
  442. FDefaultButton = NULL;
  443. }
  444. if (FCancelButton != NULL)
  445. {
  446. FCancelButton->Cancel = true;
  447. FCancelButton = NULL;
  448. }
  449. }
  450. //---------------------------------------------------------------------------
  451. void __fastcall TRightsFrame::DoExit()
  452. {
  453. // this is bit hack to make frame hide when ComboEdit button is pressed while
  454. // from is poped-up already.
  455. if (FPopup && !IsAncestor(Screen->ActiveControl, FPopupParent))
  456. {
  457. DoCloseUp();
  458. }
  459. TFrame::DoExit();
  460. }
  461. //---------------------------------------------------------------------------
  462. bool __fastcall TRightsFrame::IsAncestor(TControl * Control, TControl * Ancestor)
  463. {
  464. while ((Control != NULL) &&
  465. (Control->Parent != Ancestor))
  466. {
  467. Control = Control->Parent;
  468. }
  469. return (Control != NULL);
  470. }
  471. //---------------------------------------------------------------------------
  472. void __fastcall TRightsFrame::WMContextMenu(TWMContextMenu & Message)
  473. {
  474. FPopingContextMenu = true;
  475. try
  476. {
  477. TFrame::Dispatch(&Message);
  478. }
  479. __finally
  480. {
  481. FPopingContextMenu = false;
  482. }
  483. }
  484. //---------------------------------------------------------------------------
  485. void __fastcall TRightsFrame::CMDialogKey(TCMDialogKey & Message)
  486. {
  487. if (FPopup && Visible &&
  488. ((Message.CharCode == VK_RETURN) ||
  489. (Message.CharCode == VK_ESCAPE)) &&
  490. KeyDataToShiftState(Message.KeyData).Empty())
  491. {
  492. CloseUp();
  493. Message.Result = 1;
  494. }
  495. else
  496. {
  497. TFrame::Dispatch(&Message);
  498. }
  499. }
  500. //---------------------------------------------------------------------------
  501. void __fastcall TRightsFrame::CMCancelMode(TCMCancelMode & Message)
  502. {
  503. if (FPopup && Visible && !FPopingContextMenu &&
  504. ((Message.Sender == NULL) ||
  505. (!IsAncestor(Message.Sender, this) &&
  506. !IsAncestor(Message.Sender, FPopupParent) &&
  507. (Message.Sender != this))))
  508. {
  509. CloseUp();
  510. }
  511. TFrame::Dispatch(&Message);
  512. }
  513. //---------------------------------------------------------------------------
  514. void __fastcall TRightsFrame::Dispatch(void * Message)
  515. {
  516. TMessage & AMessage = *static_cast<TMessage *>(Message);
  517. switch (AMessage.Msg)
  518. {
  519. case CM_CANCELMODE:
  520. CMCancelMode(*(TCMCancelMode *)Message);
  521. break;
  522. case CM_DIALOGKEY:
  523. CMDialogKey(*(TCMDialogKey *)Message);
  524. break;
  525. case WM_CONTEXTMENU:
  526. WMContextMenu(*(TWMContextMenu *)Message);
  527. break;
  528. default:
  529. TFrame::Dispatch(Message);
  530. break;
  531. }
  532. }
  533. //---------------------------------------------------------------------------
  534. void __fastcall TRightsFrame::DropDown()
  535. {
  536. TCustomForm * Form = GetParentForm(this);
  537. // Due to lack of better idea, we clear "default" and "cancel" flags of respective
  538. // form buttons to prevent them to handle ESC/ENTER keys.
  539. // Could use FindStandardButton.
  540. for (int Index = 0; Index < Form->ControlCount; Index++)
  541. {
  542. TButton * Button = dynamic_cast<TButton *>(Form->Controls[Index]);
  543. if (Button != NULL)
  544. {
  545. if (Button->Default)
  546. {
  547. DebugAssert(FDefaultButton == NULL);
  548. FDefaultButton = Button;
  549. Button->Default = false;
  550. }
  551. if (Button->Cancel)
  552. {
  553. DebugAssert(FCancelButton == NULL);
  554. FCancelButton = Button;
  555. Button->Cancel = false;
  556. }
  557. }
  558. }
  559. TPoint Origin(PopupParent->Left, PopupParent->Top + PopupParent->Height);
  560. Origin = Parent->ScreenToClient(PopupParent->Parent->ClientToScreen(Origin));
  561. if (Origin.x + Width > Parent->ClientWidth)
  562. {
  563. Origin.x += PopupParent->Width - Width;
  564. }
  565. Left = Origin.x;
  566. Top = Origin.y;
  567. Show();
  568. SetFocus();
  569. }
  570. //---------------------------------------------------------------------------
  571. void __fastcall TRightsFrame::CloseUp()
  572. {
  573. DebugAssert(FPopup);
  574. DebugAssert(Visible);
  575. if (!Focused())
  576. {
  577. // this can happen only if called from on-click handler of drop down button
  578. DoCloseUp();
  579. }
  580. FPopupParent->SetFocus();
  581. }
  582. //---------------------------------------------------------------------------
  583. UnicodeString __fastcall TRightsFrame::GetText()
  584. {
  585. UnicodeString Result = Rights.Text;
  586. if (AllowAddXToDirectories && DirectoriesXEffective() && AddXToDirectories)
  587. {
  588. Result = FORMAT(L"%s (%s)", (Result, FAddXToDirectoriesSuffix));
  589. }
  590. return Result;
  591. }
  592. //---------------------------------------------------------------------------
  593. void __fastcall TRightsFrame::SetText(UnicodeString value)
  594. {
  595. if (Text != value)
  596. {
  597. UnicodeString RightsStr = value;
  598. int P = RightsStr.LowerCase().Pos(FAddXToDirectoriesSuffix);
  599. bool AAddXToDirectories = (P > 0);
  600. if (AAddXToDirectories)
  601. {
  602. RightsStr.Delete(P, FAddXToDirectoriesSuffix.Length());
  603. }
  604. RightsStr = DeleteChar(DeleteChar(RightsStr, L'('), L')').Trim();
  605. TRights R = Rights;
  606. if (((RightsStr.Length() == 3) || (RightsStr.Length() == 4)) &&
  607. IsNumber(RightsStr))
  608. {
  609. R.Octal = RightsStr;
  610. }
  611. else
  612. {
  613. R.Text = RightsStr;
  614. }
  615. Rights = R;
  616. AddXToDirectories = AAddXToDirectories;
  617. }
  618. }
  619. //---------------------------------------------------------------------------
  620. void __fastcall TRightsFrame::RightsPopupPopup(TObject * /*Sender*/)
  621. {
  622. if (!HasFocus())
  623. {
  624. SetFocus();
  625. }
  626. }
  627. //---------------------------------------------------------------------------
  628. void __fastcall TRightsFrame::FrameContextPopup(TObject * Sender,
  629. TPoint & MousePos, bool & Handled)
  630. {
  631. if (!FAcl)
  632. {
  633. SelectScaledImageList(RightsImages);
  634. MenuPopup(Sender, MousePos, Handled);
  635. }
  636. else
  637. {
  638. Handled = true;
  639. }
  640. }
  641. //---------------------------------------------------------------------------
  642. void __fastcall TRightsFrame::UpdateByOctal()
  643. {
  644. if (!OctalEdit->Text.IsEmpty())
  645. {
  646. TRights R = Rights;
  647. R.Octal = OctalEdit->Text;
  648. Rights = R;
  649. }
  650. UpdateControls();
  651. OctalEdit->Modified = false;
  652. }
  653. //---------------------------------------------------------------------------
  654. void __fastcall TRightsFrame::UpdateOctalEdit()
  655. {
  656. TRights R = Rights;
  657. OctalEdit->Text = R.IsUndef ? UnicodeString() : R.Octal;
  658. OctalEdit->Modified = false;
  659. OctalEdit->SelectAll();
  660. }
  661. //---------------------------------------------------------------------------
  662. void __fastcall TRightsFrame::OctalEditChange(TObject *)
  663. {
  664. if (OctalEdit->Modified && OctalEdit->Text.Length() >= 3)
  665. {
  666. try
  667. {
  668. UpdateByOctal();
  669. }
  670. catch(...)
  671. {
  672. OctalEdit->Modified = true;
  673. }
  674. }
  675. }
  676. //---------------------------------------------------------------------------
  677. void __fastcall TRightsFrame::OctalEditExit(TObject *)
  678. {
  679. if ((!Visible && DebugAlwaysTrue(Popup)) || // Popup assert: should happen only if popup is closed by esc key
  680. IsCancelButtonBeingClicked(this) || // CloseButton
  681. ((FCancelButton != NULL) && IsButtonBeingClicked(FCancelButton)))
  682. {
  683. // cancel changes
  684. ForceUpdate();
  685. }
  686. else if (OctalEdit->Modified)
  687. {
  688. // Now the text in OctalEdit is almost necessarily invalid, otherwise
  689. // OctalEditChange would have already cleared Modified flag
  690. try
  691. {
  692. UpdateByOctal();
  693. }
  694. catch(...)
  695. {
  696. OctalEdit->SelectAll();
  697. OctalEdit->SetFocus();
  698. throw;
  699. }
  700. }
  701. else
  702. {
  703. UpdateControls();
  704. }
  705. }
  706. //---------------------------------------------------------------------------
  707. void __fastcall TRightsFrame::CloseButtonClick(TObject *)
  708. {
  709. CloseUp();
  710. }
  711. //---------------------------------------------------------------------------
  712. void TRightsFrame::DisplayAsAcl(TRights::TRight ReadRight, TRights::TRight WriteRight, TRights::TRight ExecRight, TRights::TRight SpecialRight)
  713. {
  714. TCheckBox * ReadCheck = Checks[ReadRight];
  715. TCheckBox * WriteCheck = Checks[WriteRight];
  716. TCheckBox * ReadAclCheck = Checks[ExecRight];
  717. TCheckBox * WriteAclCheck = Checks[SpecialRight];
  718. WriteCheck->Visible = false;
  719. int ReadAclLeft = (3*ReadCheck->Left + 2*WriteAclCheck->Left) / 5;
  720. int Shift = ReadAclLeft - ReadAclCheck->Left;
  721. ReadAclCheck->Left = ReadAclLeft;
  722. ReadAclCheck->Width = ReadAclCheck->Width - Shift;
  723. ReadAclCheck->Caption = L"R ACL";
  724. ReadAclCheck->Hint = LoadStr(PROPERTIES_S3_R_ACL_HINT);
  725. WriteAclCheck->Caption = L"W ACL";
  726. WriteAclCheck->Hint = LoadStr(PROPERTIES_S3_W_ACL_HINT);
  727. WriteAclCheck->ShowHint = true;
  728. GroupLabel->Caption = LoadStr(PROPERTIES_S3_USERS);
  729. OthersLabel->Caption = LoadStr(PROPERTIES_S3_EVERYONE);
  730. }
  731. //---------------------------------------------------------------------------
  732. void TRightsFrame::DisplayAsAcl()
  733. {
  734. AllowAddXToDirectories = false;
  735. OctalLabel->Visible = false;
  736. OctalEdit->Visible = false;
  737. DisplayAsAcl(TRights::rrUserRead, TRights::rrUserWrite, TRights::rrUserExec, TRights::rrUserIDExec);
  738. DisplayAsAcl(TRights::rrGroupRead, TRights::rrGroupWrite, TRights::rrGroupExec, TRights::rrGroupIDExec);
  739. DisplayAsAcl(TRights::rrOtherRead, TRights::rrOtherWrite, TRights::rrOtherExec, TRights::rrStickyBit);
  740. FAcl = true;
  741. }