OSDN Git Service

The separator line in the Ruby Dialog was not working correctly.
[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 #include "MyMBConv.h"
28
29 BEGIN_EVENT_TABLE(GlobalParameterFrame, wxMDIChildFrame)
30         EVT_CLOSE(GlobalParameterFrame::OnCloseWindow)
31         EVT_MENU(wxID_CLOSE, GlobalParameterFrame::OnClose)
32         EVT_UPDATE_UI(wxID_CLOSE, GlobalParameterFrame::OnUpdateUI)
33 END_EVENT_TABLE()
34
35 GlobalParameterFrame::GlobalParameterFrame(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size, long type):
36         wxMDIChildFrame(parent, wxID_ANY, title, pos, size, type)
37 {
38 }
39
40 GlobalParameterFrame::~GlobalParameterFrame()
41 {
42         wxGetApp().DocManager()->FileHistoryRemoveMenu(file_history_menu);
43 }
44
45 void
46 GlobalParameterFrame::OnCreate()
47 {
48         /*  Make a MyListCtrl view  */
49         int width, height;
50         GetClientSize(&width, &height);
51         listCtrl = new MyListCtrl();
52         listCtrl->Create(this, wxID_ANY, wxPoint(0, 0), wxSize(width, height));
53         listCtrl->SetDataSource(this);
54         wxMenuBar *menu_bar = wxGetApp().CreateMenuBar(2, &file_history_menu, &edit_menu);
55         
56         /*  Associate the menu bar with the frame  */
57         SetMenuBar(menu_bar);
58 }
59
60 GlobalParameterFrame *
61 GlobalParameterFrame::CreateGlobalParameterFrame(wxMDIParentFrame *parent)
62 {
63 #ifdef __WXMSW__
64         wxPoint origin(16, 16);
65         wxSize size(774, 300);
66 #else
67         wxPoint origin(26, 40);
68         wxSize size(774, 300);
69 #endif
70         GlobalParameterFrame *frame = new GlobalParameterFrame(parent, _T("Global Parameters"), origin, size, wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE);
71         
72         frame->OnCreate();
73         return frame;
74 }
75
76 void
77 GlobalParameterFrame::OnCloseWindow(wxCloseEvent &event)
78 {
79         //  Do not delete this window; it may be reopened later
80         this->Hide();
81 }
82
83 void
84 GlobalParameterFrame::OnClose(wxCommandEvent &event)
85 {
86         //  Why this is not automatically connected?
87         this->Close();
88 }
89
90 void
91 GlobalParameterFrame::OnUpdateUI(wxUpdateUIEvent& event)
92 {
93         //  Why this is not automatically done??
94         int uid = event.GetId();
95         if (uid == wxID_CLOSE)
96                 event.Enable(true);
97 }
98
99 #pragma mark ====== MyListCtrl data source ======
100
101 int
102 GlobalParameterFrame::GetItemCount(MyListCtrl *ctrl)
103 {
104         return MainView_numberOfRowsInTable(NULL);
105 }
106
107 wxString
108 GlobalParameterFrame::GetItemText(MyListCtrl *ctrl, long row, long column) const
109 {
110         char buf[128];
111         MainView_valueForTable(NULL, column, row, buf, sizeof buf);
112         wxString *str = new wxString(buf, WX_DEFAULT_CONV);
113         return *str;
114 }
115
116 int
117 GlobalParameterFrame::SetItemText(MyListCtrl *ctrl, long row, long column, const wxString &value)
118 {
119 //      MainView_setValueForTable(NULL, column, row, value.mb_str(WX_DEFAULT_CONV));
120         return 0;
121 }
122
123 void
124 GlobalParameterFrame::DragSelectionToRow(MyListCtrl *ctrl, long row)
125 {
126 }
127
128 bool
129 GlobalParameterFrame::IsItemEditable(MyListCtrl *ctrl, long row, long column)
130 {
131         return false;
132 //      return MainView_isTableItemEditable(NULL, column, row);
133 }
134
135 bool
136 GlobalParameterFrame::IsDragAndDropEnabled(MyListCtrl *ctrl)
137 {
138         return 0;
139 }
140
141 void
142 GlobalParameterFrame::OnSelectionChanged(MyListCtrl *ctrl)
143 {
144         MainView_setSelectionFromTable(NULL);
145 }
146
147 int
148 GlobalParameterFrame::SetItemColor(MyListCtrl *ctrl, long row, long col, float *fg, float *bg)
149 {
150         if (col == -1) {
151                 int src = ParameterTableGetItemSource(gBuiltinParameters, row);
152                 if (src == -2) { /* separator row */
153                         bg[0] = bg[1] = bg[2] = 0.6;
154                         return 2;
155                 }
156         }
157         return 0;
158 }