Implemented the menu bar with all the commands
[ttodo.git] / frame.cc
blob570cf65a19f5ce7ff0aa5812ffe054b586f4e6c2
1 // Copyright (c) 2006 by Mike Sharov <msharov@users.sourceforge.net>
2 //
3 // frame.cc
4 //
6 #include "frame.h"
7 #include "tddoc.h"
9 //----------------------------------------------------------------------
11 #define CK CTodoList::SCmd::cf_Checkable
12 static const CTodoList::SCmd c_TodoMenu[] = {
13 { cmd_File, cmd_Root, 0, "&File", },
14 { cmd_File_Save, cmd_File, 0, "&Save", },
15 { cmd_File_Quit, cmd_File, 0, "&Quit", },
16 { cmd_List, cmd_Root, 0, "&List", },
17 { cmd_List_Enter, cmd_List, 0, "&Enter", },
18 { cmd_List_Leave, cmd_List, 0, "&Leave", },
19 { cmd_Separator, cmd_List, 0, "", },
20 { cmd_List_Copy, cmd_List, 0, "&Copy", },
21 { cmd_List_Paste, cmd_List, 0, "&Paste", },
22 { cmd_Separator, cmd_List, 0, "", },
23 { cmd_List_OldItems, cmd_List, CK, "&Old items", },
24 { cmd_Item, cmd_Root, 0, "&Item", },
25 { cmd_Item_New, cmd_Item, 0, "&New", },
26 { cmd_Item_Edit, cmd_Item, 0, "&Edit", },
27 { cmd_Item_Delete, cmd_Item, 0, "&Delete", },
28 { cmd_Separator, cmd_Item, 0, "", },
29 { cmd_Item_Complete, cmd_Item, 0, "&Complete", },
30 { cmd_Item_Priority, cmd_Item, 0, "&Priority", },
31 { cmd_Item_Priority_Highest,cmd_Item_Priority, CK, "H&ighest", },
32 { cmd_Item_Priority_High, cmd_Item_Priority, CK, "&High", },
33 { cmd_Item_Priority_Medium, cmd_Item_Priority, CK, "&Medium", },
34 { cmd_Item_Priority_Low, cmd_Item_Priority, CK, "&Low", },
35 { cmd_Item_Priority_Lowest, cmd_Item_Priority, CK, "Low&est", },
36 { cmd_Help, cmd_Root, 0, "&Help", },
37 { cmd_Help_Contents, cmd_Help, 0, "&Contents", },
38 { cmd_Help_About, cmd_Help, 0, "&About", }
40 #undef CK
42 //----------------------------------------------------------------------
44 /// Default constructor.
45 CTodoFrame::CTodoFrame (void)
46 : CWindow ()
48 AddChild (CMenuBar::Instance());
49 AddChild (new CTodoList);
50 AddChild (new CEntryEditDialog);
51 assert (pane_Last == Children().size());
52 SetFocus (pane_Entries);
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 (&EntryEditor());
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();
71 /// Resizes and places child windows.
72 void CTodoFrame::OnResize (rcrect_t wr)
74 CWindow::OnResize (wr);
75 Rect menuRect (CW(pane_MenuBar).SizeHints (wr));
76 MenuBar().OnResize (menuRect);
77 TodoList().OnResize (Rect (0, menuRect.Height(), wr.Width(), wr.Height() - 8 - menuRect.Height()));
78 EntryEditor().OnResize (Rect (0, wr.Height() - 8, wr.Width(), 8));
81 void CTodoFrame::OnKey (wchar_t key)
83 if (key & kvm_Alt)
84 SetFocus (pane_MenuBar);
85 CWindow::OnKey (key);
88 void CTodoFrame::OnCommand (cmd_t c)
90 Document()->OnCommand (c);
91 CWindow::OnCommand (c);
94 void CTodoFrame::OnUpdateCommandUI (rcmd_t rc) const
96 rc.SetFlag (SCmd::cf_Grayed, !Document());
97 if (!Document())
98 return;
99 Document()->OnUpdateCommandUI (rc);
100 CWindow::OnUpdateCommandUI (rc);