OSDN Git Service

Handling key and mouse events in listctrl is improved
[molby/Molby.git] / wxSources / RubyDialogFrame.h
1 /*
2  *  RubyDialogFrame.h
3  *  Molby
4  *
5  *  Created by Toshi Nagata on 08/12/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 #ifndef __RubyDialogFrame_h__
19 #define __RubyDialogFrame_h__
20
21 #include "wx/frame.h"
22 #include "wx/dialog.h"
23 #include "wx/sizer.h"
24 #include "wx/panel.h"
25 #include "wx/timer.h"
26 #include "../MolLib/Ruby_bind/ruby_dialog.h"
27 #include "MyListCtrl.h"
28
29 #include "modalwindow.h"
30
31 /*  MyLayoutPanel: an empty subclass of wxPanel exclusively used in Dialog#layout  */
32 class MyLayoutPanel: public wxPanel {
33 public:
34         MyLayoutPanel(): wxPanel() {}
35         MyLayoutPanel(wxWindow *parent, wxWindowID winid = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize): wxPanel(parent, winid, pos, size) {}
36         virtual ~MyLayoutPanel() {}             
37 private:
38         DECLARE_DYNAMIC_CLASS(MyLayoutPanel)
39 };
40
41 /*  MyDrawingPanel: an empty subclass of wxPanel exclusively used as "view" dialog item  */
42 class MyDrawingPanel: public wxPanel {
43 public:
44         MyDrawingPanel(): wxPanel() {}
45         MyDrawingPanel(wxWindow *parent, wxWindowID winid = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize): wxPanel(parent, winid, pos, size) {}
46         virtual ~MyDrawingPanel() {}
47 private:
48         DECLARE_DYNAMIC_CLASS(MyDrawingPanel)
49 };
50
51 class RubyDialogFrame: public wxModalWindow, public MyListCtrlDataSource {      
52 public:
53         int myStyle;
54
55         RDItem **ditems;
56         int nditems;
57         RubyValue dval;  /*  The Ruby value representing this object  */
58
59         wxPanel *contentPanel;
60         wxSizer *contentSizer;
61         wxSizer *buttonSizer;
62         wxBoxSizer *boxSizer;
63         wxTimer *myTimer;
64         
65         wxWindow *currentDrawingItem;
66         wxDC *currentContext;
67
68         wxWindow *lastFocusedWindow;
69
70         /*  Auto resizing  */
71         RDSize mySize;  /*  Previous size  */
72         bool autoResizeEnabled;  /*  true if auto resizing is enabled  */
73         
74         /*  Message bridge (with Ruby world); obj, event_type, event_id, proc val  */
75 //      void **messageData;
76 //      int countMessageData;
77         
78         /*  On key handler (the handler is in the Ruby world)  */
79         bool onKeyHandlerEnabled;
80
81         /*  Flag to invoke one-time initialization just before showing up  */
82         bool shouldInitializeBeforeShow;
83         
84         RubyDialogFrame():wxModalWindow() {}
85         RubyDialogFrame(wxWindow* parent, wxWindowID wid, const wxString& title, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE);
86         virtual ~RubyDialogFrame();
87
88         /*  For internal use (discard data in messageData[])  */
89 //      void DiscardMessageData();
90         
91         void SetAutoResizeEnabled(int flag) { autoResizeEnabled = (flag != 0); }
92         bool IsAutoResizeEnabled() { return autoResizeEnabled; }
93         
94 //      int ListenToObject(void *obj, const char *objtype, const char *msg, RubyValue oval, RubyValue pval);
95 //      void HandleDocumentEvent(wxCommandEvent &event);
96
97         void HandlePaintEvent(wxPaintEvent &event);
98
99         int AddDialogItem(RDItem *item);
100         RDItem *DialogItemAtIndex(int index);
101         int SearchDialogItem(RDItem *item);
102         void SetRubyObject(RubyValue val);
103         void CreateStandardButtons(const char *oktitle, const char *canceltitle);
104         int StartIntervalTimer(int millisec);
105         void StopIntervalTimer(void);
106         void OnDialogItemAction(wxCommandEvent &event);
107         void OnTextUpdated(wxCommandEvent &event);
108         void OnEnterProcessedOnText(wxCommandEvent &event);
109         void OnEscapeProcessedOnText(wxCommandEvent &event);
110         void OnKillFocusOnText(wxFocusEvent &event);
111
112         void OnTimerEvent(wxTimerEvent &event);
113         void OnDefaultButtonPressed(wxCommandEvent &event);
114         void OnSize(wxSizeEvent &event);
115         void OnChar(wxKeyEvent &event);
116         void OnCloseWindow(wxCloseEvent &event);
117         void OnActivate(wxActivateEvent &event);
118         void OnChildFocus(wxChildFocusEvent &event);
119         void OnCloseFromMenu(wxCommandEvent &event);
120         void OnUpdateUI(wxUpdateUIEvent& event);
121
122         //  MyListCtrlDataSource methods
123         virtual int GetItemCount(MyListCtrl *ctrl);
124         virtual wxString GetItemText(MyListCtrl *ctrl, long row, long column) const;
125         virtual int SetItemText(MyListCtrl *ctrl, long row, long column, const wxString &value);
126         virtual void DragSelectionToRow(MyListCtrl *ctrl, long row);
127         virtual bool IsItemEditable(MyListCtrl *ctrl, long row, long column);
128         virtual bool IsDragAndDropEnabled(MyListCtrl *ctrl, long row = -1);
129         virtual void OnSelectionChanged(MyListCtrl *ctrl);
130         virtual int SetItemColor(MyListCtrl *ctrl, long row, long col, float *fg, float *bg);
131         virtual int HasPopUpMenu(MyListCtrl *ctrl, long row, long column, char ***menu_titles);
132         virtual void OnPopUpMenuSelected(MyListCtrl *ctrl, long row, long column, int selected_index);
133                 
134 private:
135         DECLARE_DYNAMIC_CLASS(RubyDialogFrame)
136         DECLARE_EVENT_TABLE()
137 };
138
139 #endif /* __RubyDialogFrame_h__ */