OSDN Git Service

initial import
[molby/Molby.git] / wxSources / GlobalParameterFrame.cpp
1 /*
2  *  GlobalParameterFrame.cpp
3  *  Molby
4  *
5  *  Created by Toshi Nagata on 09/11/05.
6  *  Copyright 2008 Toshi Nagata. All rights reserved.
7  *
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation version 2 of the License.
11  
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  GNU General Public License for more details.
16  */
17
18 #include "GlobalParameterFrame.h"
19
20 #include "wx/menu.h"
21 #include "wx/regex.h"
22 #include "wx/colour.h"
23
24 #include "MyApp.h"
25 #include "MyListCtrl.h"
26 #include "../MolLib/Ruby_bind/Molby_extern.h"
27
28 BEGIN_EVENT_TABLE(GlobalParameterFrame, wxMDIChildFrame)
29         EVT_CLOSE(GlobalParameterFrame::OnCloseWindow)
30         EVT_MENU(wxID_CLOSE, GlobalParameterFrame::OnClose)
31         EVT_UPDATE_UI(wxID_CLOSE, GlobalParameterFrame::OnUpdateUI)
32 END_EVENT_TABLE()
33
34 GlobalParameterFrame::GlobalParameterFrame(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size, long type):
35         wxMDIChildFrame(parent, wxID_ANY, title, pos, size, type)
36 {
37 }
38
39 GlobalParameterFrame::~GlobalParameterFrame()
40 {
41         wxGetApp().DocManager()->FileHistoryRemoveMenu(file_history_menu);
42 }
43
44 void
45 GlobalParameterFrame::OnCreate()
46 {
47         /*  Make a MyListCtrl view  */
48         int width, height;
49         GetClientSize(&width, &height);
50         listCtrl = new MyListCtrl();
51         listCtrl->Create(this, wxID_ANY, wxPoint(0, 0), wxSize(width, height));
52         listCtrl->SetDataSource(this);
53         wxMenuBar *menu_bar = wxGetApp().CreateMenuBar(2, &file_history_menu, &edit_menu);
54         
55         /*  Associate the menu bar with the frame  */
56         SetMenuBar(menu_bar);
57 }
58
59 GlobalParameterFrame *
60 GlobalParameterFrame::CreateGlobalParameterFrame(wxMDIParentFrame *parent)
61 {
62 #ifdef __WXMSW__
63         wxPoint origin(16, 16);
64         wxSize size(774, 300);
65 #else
66         wxPoint origin(26, 40);
67         wxSize size(774, 300);
68 #endif
69         GlobalParameterFrame *frame = new GlobalParameterFrame(parent, _T("Global Parameters"), origin, size, wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE);
70         
71         frame->OnCreate();
72         return frame;
73 }
74
75 void
76 GlobalParameterFrame::OnCloseWindow(wxCloseEvent &event)
77 {
78         //  Do not delete this window; it may be reopened later
79         this->Hide();
80 }
81
82 void
83 GlobalParameterFrame::OnClose(wxCommandEvent &event)
84 {
85         //  Why this is not automatically connected?
86         this->Close();
87 }
88
89 void
90 GlobalParameterFrame::OnUpdateUI(wxUpdateUIEvent& event)
91 {
92         //  Why this is not automatically done??
93         int uid = event.GetId();
94         if (uid == wxID_CLOSE)
95                 event.Enable(true);
96 }
97
98 #pragma mark ====== MyListCtrl data source ======
99
100 int
101 GlobalParameterFrame::GetItemCount(MyListCtrl *ctrl)
102 {
103         return MainView_numberOfRowsInTable(NULL);
104 }
105
106 wxString
107 GlobalParameterFrame::GetItemText(MyListCtrl *ctrl, long row, long column) const
108 {
109         char buf[128];
110         MainView_valueForTable(NULL, column, row, buf, sizeof buf);
111         wxString *str = new wxString(buf, wxConvUTF8);
112         return *str;
113 }
114
115 int
116 GlobalParameterFrame::SetItemText(MyListCtrl *ctrl, long row, long column, const wxString &value)
117 {
118 //      MainView_setValueForTable(NULL, column, row, value.mb_str(wxConvUTF8));
119         return 0;
120 }
121
122 void
123 GlobalParameterFrame::DragSelectionToRow(MyListCtrl *ctrl, long row)
124 {
125 }
126
127 bool
128 GlobalParameterFrame::IsItemEditable(MyListCtrl *ctrl, long row, long column)
129 {
130         return false;
131 //      return MainView_isTableItemEditable(NULL, column, row);
132 }
133
134 bool
135 GlobalParameterFrame::IsDragAndDropEnabled(MyListCtrl *ctrl)
136 {
137         return 0;
138 }
139
140 void
141 GlobalParameterFrame::OnSelectionChanged(MyListCtrl *ctrl)
142 {
143         MainView_setSelectionFromTable(NULL);
144 }
145
146 int
147 GlobalParameterFrame::SetItemColor(MyListCtrl *ctrl, long row, long col, float *fg, float *bg)
148 {
149         if (col == -1) {
150                 int src = ParameterTableGetItemSource(gBuiltinParameters, row);
151                 if (src == -2) { /* separator row */
152                         bg[0] = bg[1] = bg[2] = 0.6;
153                         return 2;
154                 }
155         }
156         return 0;
157 }