wxgraphics.cc
来自「LastWave」· CC 代码 · 共 1,621 行 · 第 1/3 页
CC
1,621 行
// For compilers that support precompilation, includes "wx/wx.h".#include "wx/wxprec.h"// for all others, include the necessary headers (this file is usually all you// need because it includes almost all "standard" wxWidgets headers)#ifndef WX_PRECOMP #include "wx/wx.h"#endif#include "wx/image.h"#include "wx/choicdlg.h"#include "wx/fontdlg.h"#include "wx/fontenum.h"#include "wx/fontmap.h"#include "wx/encconv.h"#include "wx/splitter.h"#include "wx/textfile.h"#ifdef __WXMAC__#undef wxFontDialog#include "wx/mac/fontdlg.h"#endifextern "C" { #include "lastwave.h" }#include "terminalCtrl.h"#include "wxmain.h"#include "wxgraphics.h"#define FRAME void *#define FONTID int *// wxFontEncoding greekEncoding = wxFONTENCODING_ISO8859_7;wxFontEncoding greekEncoding = wxFONTENCODING_DEFAULT;// Managing 1/2 button mousestatic long leftButton = LeftButton; static long rightButton = RightButton; static long middleButton = MiddleButton; static int nbOfButtons = 3;long XXMouseButton(wxMouseEvent& event){ long mask; if (nbOfButtons == 1) { mask = LeftButton; if (event.MetaDown()) mask += ModMeta; if (event.AltDown()) mask += ModOpt; } else if (nbOfButtons == 2) { if (event.LeftDown()) mask = LeftButton; else if (event.RightDown()) mask = RightButton; else if (event.MiddleDown()) mask = MiddleButton; if (event.MetaDown()) mask += ModMeta; if (event.AltDown()) mask += ModOpt; } else { if (event.LeftDown()) mask = LeftButton; else if (event.RightDown()) mask = RightButton; else if (event.MiddleDown()) mask = MiddleButton; } if (leftButton == mask) return(LeftButton); else if (middleButton == mask) return(MiddleButton); else if (rightButton == mask) return(RightButton); else return(NoButton);}static wxPalette *thePalette = NULL;static wxPen thePen;static wxBrush theBrush;static int thePenMode;static unsigned char theR, theG, theB;static int theClipX,theClipY,theClipW,theClipH;static wxFont theFont;//// Sometimes we want to block events, i.e., to forget about any event that takes place.// In any case we never skip the terminal keyDown events. We buffer them in order to reproduce them later.//// There are 2 reasons for blocking events ://// 1) When a non terminal event is processed, we do not want any other event to interfere// In that case all events must be blocked (except the keydown terminal ones of course)// --> Macro BlockEvent// 2) When something is printed on the terminal we make a Yield call. We do not want major things to happen during this call.// We want to block all events except maybe repaint events and mouseUp events// --> Macro BlockEventSpecial//static bool eventBlocked = false;static bool eventBlockedByTerminal = false;bool IsEventBlocked() { return(eventBlocked);}bool IsEventBlockedByTerminal(){ return(eventBlockedByTerminal);}void BlockEvent(){ eventBlocked = true; eventBlockedByTerminal = false;}void BlockEventByTerminal(){ eventBlocked = true; eventBlockedByTerminal = true;}void UnBlockEvent(){ eventBlocked = false; eventBlockedByTerminal = false;}class Frame;class Canvas : public wxWindow// public wxScrolledWindow{ public : Canvas(Frame *f); ~Canvas(); Frame *frame; wxDC *dc; // Canvas Border int hBorder, wBorder; int mouseButton; bool flagResizeEvent; void OnPaint(wxPaintEvent& event); void OnMouseDown(wxMouseEvent& event); void OnMouseUp(wxMouseEvent& event); void OnMouseEnterLeave(wxMouseEvent& event); void OnMouseMotion(wxMouseEvent& event); void OnResize(wxSizeEvent& event); void KeyDown(wxKeyEvent& event); void KeyChar(wxKeyEvent& event); DECLARE_EVENT_TABLE();};Canvas::~Canvas(){}BEGIN_EVENT_TABLE(Canvas, /*wxScrolledWindow*/ wxWindow) EVT_PAINT(Canvas::OnPaint) EVT_LEFT_UP(Canvas::OnMouseUp) EVT_MIDDLE_UP(Canvas::OnMouseUp) EVT_RIGHT_UP(Canvas::OnMouseUp) EVT_LEFT_DOWN(Canvas::OnMouseDown) EVT_MIDDLE_DOWN(Canvas::OnMouseDown) EVT_RIGHT_DOWN(Canvas::OnMouseDown) EVT_ENTER_WINDOW(Canvas::OnMouseEnterLeave) EVT_LEAVE_WINDOW(Canvas::OnMouseEnterLeave) EVT_MOTION(Canvas::OnMouseMotion) EVT_SIZE(Canvas::OnResize) EVT_KEY_DOWN(Canvas::KeyDown) EVT_CHAR(Canvas::KeyChar) END_EVENT_TABLE()class Frame : public wxFrame { public : Frame(wxString title,int x, int y, int w,int h); ~Frame(); // Frame border int hBorder,wBorder; // Get Total border inline int totalWBorder() {return(wBorder+canvas->wBorder);}; inline int totalHBorder() {return(hBorder+canvas->hBorder);}; Canvas *canvas; void Focus(wxFocusEvent& event); void OnClose(wxCloseEvent& event); void OnMove(wxMoveEvent& event); void OnActivate(wxActivateEvent& event); DECLARE_EVENT_TABLE();};BEGIN_EVENT_TABLE(Frame, wxFrame) EVT_CLOSE(Frame::OnClose) EVT_MOVE(Frame::OnMove)EVT_ACTIVATE(Frame::OnActivate)END_EVENT_TABLE()void Frame::OnClose(wxCloseEvent& event){ BLOCKEVENT; struct event ev; ev.object = (GOBJECT) Frame2Window(this); if (ev.object == NULL) Destroy(); else { ev.type = Del; ProcessNextEvent(&ev); } // Printf("Close Frame\n"); UNBLOCKEVENT;}void Frame::OnMove(wxMoveEvent& event){ struct event ev; ev.object = (GOBJECT) Frame2Window(this); if (ev.object == NULL) { return; } BLOCKEVENT; wxPoint pos = GetPosition(); ev.type = Resize; ev.i = pos.x; ev.j = pos.y; canvas->GetClientSize(&(ev.m),&(ev.n)); ProcessNextEvent(&ev); // Printf("Move Frame %d %d %d %d\n",ev.i,ev.j,ev.m,ev.n); UNBLOCKEVENT;}void Frame::OnActivate(wxActivateEvent& event){ if (event.GetActive()) canvas->SetFocus();}static bool GetLWKeyEvent(wxWindow *window, wxKeyEvent& event, unsigned long key, bool flagShift, bool flagAlt, bool flagCtrl, struct event &ev){ if (window != myApp->terminal->textCtrl) { Canvas *c = (Canvas *) window; ev.object = (GOBJECT) Frame2Window(c->frame); if (ev.object == NULL) return(false); } else ev.object = NULL; ev.type = KeyDown1; ev.key = key; if (flagCtrl) ev.key += ModCtrl; if (flagShift) ev.key += ModShift; if (flagAlt) ev.key += ModOpt; wxPoint p = ::wxGetMousePosition(); p = window->ScreenToClient(p); ev.i = event.GetX(); ev.j = event.GetY(); ev.i = p.x; ev.j = p.y; return(true);}bool GetKeyCharLWEvent(wxWindow *w, wxKeyEvent& event, struct event &ev){ // Menu management switch(wxGetOsVersion()) { __CASEMAC : if (event.CmdDown()) { event.Skip(); return(false); } break; __CASEWINDOWS : __CASEUNIX : if (!event.AltDown() && event.ControlDown() && !event.MetaDown()) { event.Skip(); return(false); } break; default : break; } // THIS IS HIGH HACKING ....that I do not really master :-) if (event.GetKeyCode() < ' ') {// event.Skip(); return(false); } return(GetLWKeyEvent(w,event,event.GetKeyCode(),false,false,false,ev));}void Canvas::KeyChar(wxKeyEvent& event) { BLOCKEVENT; struct event ev; if (GetKeyCharLWEvent(this,event,ev)) ProcessNextEvent(&ev); UNBLOCKEVENT;}// // Dealing with key down// This routine is called on KeyDown event. //// If the key must be processed using a KeyChar then the event should be skipped and return(false)// If the key should not be taken into account return(false)// Otherwise the event 'ev' should be filled and return(true)//bool GetKeyDownLWEvent(wxWindow *w, wxKeyEvent& event, struct event &ev) { // Menu management switch(wxGetOsVersion()) { __CASEMAC : if (event.CmdDown()) { event.Skip(); return(false); } break; __CASEWINDOWS : __CASEUNIX : if (!event.AltDown() && event.ControlDown() && !event.MetaDown() && event.GetKeyCode() != 'D') { event.Skip(); return(false); } break; default : break; } // the wxCode of the key long code = event.GetKeyCode(); // The LastWave key code unsigned long key = 0; // The name of the key if not a character char *t = NULL; // // The different codes // // -> if return then not taken care // -> if break --> taken care // switch(code) { case WXK_BACK : t = "delete"; key = DeleteKC; break; case WXK_RETURN : t = "return"; key = NewlineKC; break; case WXK_ESCAPE : t = "esc"; key = EscapeKC; break; case WXK_TAB : t = "tab"; key = TabKC; break; case WXK_SPACE : break; case WXK_DELETE : t = "delete"; key = DeleteKC; break; case WXK_SHIFT : event.Skip(); return(false); case WXK_ALT : event.Skip(); return(false); case WXK_COMMAND : event.Skip(); return(false); case WXK_CONTROL : event.Skip(); return(false); case WXK_CAPITAL : event.Skip(); return(false); case WXK_HOME : t = "home"; key = HomeKC; break; case WXK_LEFT : t = "left"; key = LeftKC; break; case WXK_UP : t = "up"; key = UpKC; break; case WXK_RIGHT : t = "right"; key = RightKC; break; case WXK_DOWN : t = "down"; key = DownKC; break; case WXK_CLEAR : t = "clear"; key = ClearKC; break; case WXK_END : t = "end"; key = EndKC; break; case WXK_F1 : t = "f1"; key = F1KC; break; case WXK_F2 : t = "f2"; key = F2KC; break; case WXK_F3 : t = "f3"; key = F3KC; break; case WXK_F4 : t = "f4"; key = F4KC; break; case WXK_F5 : t = "f5"; key = F5KC; break; case WXK_F6 : t = "f6"; key = F6KC; break; case WXK_F7 : t = "f7"; key = F7KC; break; case WXK_F8 : t = "f8"; key = F8KC; break; case WXK_F9 : t = "f9"; key = F9KC; break; case WXK_F10 : t = "f10"; key = F10KC; break; case WXK_F11 : t = "f11"; key = F11KC; break; case WXK_F12 : t = "f12"; key = F12KC; break; case WXK_F13 : t = "f13"; key = F13KC; break; case WXK_F14 : t = "f14"; key = F14KC; break; case WXK_F15 : t = "f15"; key = F15KC; break; case WXK_START : t = "start"; return(false); case WXK_LBUTTON : t = "lb"; return(false); case WXK_RBUTTON : t = "rb"; return(false); case WXK_CANCEL : t = "cancel"; return(false); case WXK_MBUTTON : t = "mb"; break; case WXK_MENU : t = "menu"; return(false); case WXK_PAUSE : t = "pause"; return(false); case WXK_PRIOR : t = "prior"; return(false); case WXK_NEXT : t = "next"; return(false); case WXK_SELECT : t = "select"; return(false); case WXK_PRINT : t = "print"; return(false); case WXK_EXECUTE : t = "exec"; return(false); case WXK_SNAPSHOT : t = "snap"; return(false); case WXK_INSERT : t = "insert"; return(false); case WXK_HELP : t = "help"; return(false); case WXK_NUMPAD0 : return(false); case WXK_NUMPAD1 : return(false); case WXK_NUMPAD2 : return(false); case WXK_NUMPAD3 : return(false); case WXK_NUMPAD4 : return(false); case WXK_NUMPAD5 : return(false); case WXK_NUMPAD6 : return(false); case WXK_NUMPAD7 : return(false); case WXK_NUMPAD8 : return(false); case WXK_NUMPAD9 : return(false); case WXK_MULTIPLY : return(false); case WXK_ADD : return(false); case WXK_SEPARATOR : return(false); case WXK_SUBTRACT : return(false); case WXK_DECIMAL : return(false); case WXK_DIVIDE : return(false); case WXK_F16 : t = "f16"; return(false); case WXK_F17 : t = "f17"; return(false); case WXK_F18 : t = "f18"; return(false); case WXK_F19 : t = "f19"; return(false); case WXK_F20 : t = "f20"; return(false); case WXK_F21 : t = "f21"; return(false); case WXK_F22 : t = "f22"; return(false); case WXK_F23 : t = "f23"; return(false); case WXK_F24 : t = "f24"; return(false); case WXK_NUMLOCK : return(false); case WXK_SCROLL : t = "scroll"; return(false); // case WXK_PAGEUP : t = "pageup"; return(false); // case WXK_PAGEDOWN : t = "pagedown"; return(false); case WXK_NUMPAD_SPACE : return(false); case WXK_NUMPAD_TAB : return(false); case WXK_NUMPAD_ENTER : return(false); case WXK_NUMPAD_F1 : t = "nf1"; return(false); case WXK_NUMPAD_F2 : t = "nf2"; return(false); case WXK_NUMPAD_F3 : t = "nf3"; return(false); case WXK_NUMPAD_F4 : t = "nf4"; return(false); case WXK_NUMPAD_HOME : t = "nhome"; return(false); case WXK_NUMPAD_LEFT : t = "nleft"; return(false); case WXK_NUMPAD_UP : t = "nup"; return(false); case WXK_NUMPAD_RIGHT : t = "nright"; return(false); case WXK_NUMPAD_DOWN : t = "ndown"; return(false); case WXK_NUMPAD_PRIOR : t = "nprior"; return(false);// case WXK_NUMPAD_PAGEUP : t = "npageup"; return(false);// case WXK_NUMPAD_NEXT : t = "nnext"; return(false); case WXK_NUMPAD_PAGEDOWN : t = "npagedown"; return(false); case WXK_NUMPAD_END : t = "nend"; return(false); case WXK_NUMPAD_BEGIN : t = "nbeg"; return(false); case WXK_NUMPAD_INSERT : t = "ninsert"; return(false); case WXK_NUMPAD_DELETE : t = "ndelete"; return(false); case WXK_NUMPAD_EQUAL : return(false); case WXK_NUMPAD_MULTIPLY : return(false); case WXK_NUMPAD_ADD : return(false); case WXK_NUMPAD_SEPARATOR : t = "nsep"; return(false); case WXK_NUMPAD_SUBTRACT : return(false); case WXK_NUMPAD_DECIMAL : return(false); case WXK_NUMPAD_DIVIDE : return(false); case WXK_WINDOWS_LEFT : t = "wleft"; return(false); case WXK_WINDOWS_RIGHT : t = "wrigt"; return(false); case WXK_WINDOWS_MENU : t = "wmenu"; return(false); default : break; }; // Case the key is printable (i.e., it has no name) if (t == NULL) { switch(wxGetOsVersion()) { // On a MAC : // If option key with no control and regular characters --> Char event should deal with it __CASEMAC : if (event.AltDown() && !event.ControlDown() && !event.CmdDown() && code >= ' ' && code <= '~') { event.Skip(); return(false); } break; // On WINDOWS : // If alt+Ctrl keys with no meta and regular characters --> Char event should deal with it __CASEWINDOWS : __CASEUNIX : if (event.AltDown() && event.ControlDown() && !event.MetaDown() && code >= ' ' && code <= '~') { event.Skip(); return(false); } break; default : break; } // The next paragraph deal with modifiers if (event.ControlDown()) { // Case of a control key if (code >= 'A' && code <= 'Z') { if (!event.ShiftDown()) code += -'A'+'a'; if (code == 'd' && !event.AltDown()) return(GetLWKeyEvent(w,event,EofKC,false,false,false,ev)); else return(GetLWKeyEvent(w,event,code,false,event.AltDown(),event.ControlDown(),ev)); } else if (code == WXK_SPACE) { return(GetLWKeyEvent(w,event,' ', event.ShiftDown(),event.AltDown(),event.ControlDown(),ev)); } else if (code >= ' ' && code <= '~') { return(GetLWKeyEvent(w,event,code,false,event.AltDown(),event.ControlDown(),ev)); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?