Updated bsconf to the latest from uSTL
[ttodo.git] / frame.cc
blob26a4ab8465923e9f1fe49d9a51feac1580c85754
1 // This file is part of a terminal todo application.
2 //
3 // Copyright (C) 2006 by Mike Sharov <msharov@users.sourceforge.net>
4 // This file is free software, distributed under the MIT License.
5 //
6 // frame.cc
7 //
9 #include "frame.h"
10 #include "tddoc.h"
12 //----------------------------------------------------------------------
14 BEGIN_MENU(4, c_TodoMenu)
15 SUBMENU(2, "&File", cmd_File),
16 MENUITEM ("&Save", cmd_File_Save),
17 MENUITEM ("&Quit", cmd_File_Quit),
18 SUBMENU(7, "&List", cmd_List),
19 MENUITEM ("&Enter", cmd_List_Enter),
20 MENUITEM ("&Leave", cmd_List_Leave),
21 MENUITEM_SEPARATOR,
22 MENUITEM ("&Copy", cmd_List_Copy),
23 MENUITEM ("&Paste", cmd_List_Paste),
24 MENUITEM_SEPARATOR,
25 MENUCHECK ("&Old items",cmd_List_OldItems),
26 SUBMENU(6, "&Item", cmd_Item),
27 MENUITEM ("&New", cmd_Item_New),
28 MENUITEM ("&Edit", cmd_Item_Edit),
29 MENUITEM ("&Delete", cmd_Item_Delete),
30 MENUITEM_SEPARATOR,
31 MENUITEM ("&Complete", cmd_Item_Complete),
32 SUBMENU(5,"&Priority", cmd_Item_Priority),
33 MENUCHECK ("H&ighest", cmd_Item_Priority_Highest),
34 MENUCHECK ("&High", cmd_Item_Priority_High),
35 MENUCHECK ("&Medium", cmd_Item_Priority_Medium),
36 MENUCHECK ("&Low", cmd_Item_Priority_Low),
37 MENUCHECK ("Low&est", cmd_Item_Priority_Lowest),
38 SUBMENU(2, "&Help", cmd_Help),
39 MENUITEM ("&Contents", cmd_Help_Contents),
40 MENUITEM ("&About", cmd_Help_About)
41 END_MENU
43 //----------------------------------------------------------------------
45 /// Default constructor.
46 CTodoFrame::CTodoFrame (void)
47 : CWindow ()
49 AddChild (CMenuBar::Instance());
50 AddChild (new CTodoList);
51 AddChild (new CItemEditDialog);
52 assert (pane_Last == Children().size());
53 CMenuBar::Instance()->Set (VectorBlock (c_TodoMenu));
56 /// Registers each child pane with the document.
57 void CTodoFrame::OnInitialUpdate (void)
59 CWindow::OnInitialUpdate();
60 Document()->RegisterView (&TodoList());
61 Document()->RegisterView (&ItemEditor());
64 /// Allows each child pane to close the frame by closing itself.
65 void CTodoFrame::OnChildClose (uoff_t i)
67 CWindow::OnChildClose (i);
68 Close (CW(i).Status());
71 /// Resizes and places child windows.
72 void CTodoFrame::OnResize (rcrect_t wr)
74 CWindow::OnResize (wr);
75 Rect menuRect (wr);
76 CW(pane_MenuBar).SizeHints (menuRect);
77 MenuBar().OnResize (menuRect);
78 TodoList().OnResize (Rect (0, menuRect.Height(), wr.Width(), wr.Height() - 8 - menuRect.Height()));
79 ItemEditor().OnResize (Rect (0, wr.Height() - 8, wr.Width(), 8));
82 void CTodoFrame::OnKey (wchar_t key)
84 if (key & kvm_Alt)
85 SetFocus (pane_MenuBar);
86 CWindow::OnKey (key);
89 void CTodoFrame::OnCommand (cmd_t c)
91 Document()->OnCommand (c);
92 CWindow::OnCommand (c);
95 void CTodoFrame::OnUpdateCommandUI (rcmd_t rc) const
97 rc.SetFlag (SCmd::cf_Grayed, !Document());
98 if (!Document())
99 return;
100 Document()->OnUpdateCommandUI (rc);
101 CWindow::OnUpdateCommandUI (rc);