1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Definitions of miscelaneous functions and classes that need
4 // to know about wxWindow. (So they can't be in misc.i or an
5 // import loop will happen.)
9 // Created: 18-June-1999
11 // Copyright: (c) 1998 by Total Control Software
12 // Licence: wxWindows license
13 /////////////////////////////////////////////////////////////////////////////
19 #include <wx/resource.h>
20 #include <wx/tooltip.h>
22 #include <wx/fontenum.h>
23 #include <wx/tipdlg.h>
24 #include <wx/process.h>
26 #if wxUSE_JOYSTICK || defined(__WXMSW__)
27 #include <wx/joystick.h>
30 #if wxUSE_WAVE || defined(__WXMSW__)
35 //----------------------------------------------------------------------
38 %include my_typemaps.i
40 // Import some definitions of other classes, etc.
49 static wxString wxPyEmptyStr("");
52 //---------------------------------------------------------------------------
55 wxString wxFileSelector(char* message,
56 char* default_path = NULL,
57 char* default_filename = NULL,
58 char* default_extension = NULL,
59 char* wildcard = "*.*",
61 wxWindow *parent = NULL,
62 int x = -1, int y = -1);
64 wxString wxGetTextFromUser(const wxString& message,
65 const wxString& caption = wxPyEmptyStr,
66 const wxString& default_value = wxPyEmptyStr,
67 wxWindow *parent = NULL,
68 int x = -1, int y = -1,
71 wxString wxGetPasswordFromUser(const wxString& message,
72 const wxString& caption = wxPyEmptyStr,
73 const wxString& default_value = wxPyEmptyStr,
74 wxWindow *parent = NULL);
77 // TODO: Need to custom wrap this one...
78 // int wxGetMultipleChoice(char* message, char* caption,
79 // int LCOUNT, char** choices,
80 // int nsel, int *selection,
81 // wxWindow *parent = NULL, int x = -1, int y = -1,
82 // bool centre = TRUE, int width=150, int height=200);
85 wxString wxGetSingleChoice(const wxString& message, const wxString& caption,
86 int LCOUNT, wxString* choices,
87 wxWindow *parent = NULL,
88 int x = -1, int y = -1,
90 int width=150, int height=200);
92 int wxGetSingleChoiceIndex(const wxString& message, const wxString& caption,
93 int LCOUNT, wxString* choices,
94 wxWindow *parent = NULL,
95 int x = -1, int y = -1,
97 int width=150, int height=200);
100 int wxMessageBox(const wxString& message,
101 const wxString& caption = wxPyEmptyStr,
102 int style = wxOK | wxCENTRE,
103 wxWindow *parent = NULL,
104 int x = -1, int y = -1);
106 long wxGetNumberFromUser(const wxString& message,
107 const wxString& prompt,
108 const wxString& caption,
110 long min = 0, long max = 100,
111 wxWindow *parent = NULL,
112 const wxPoint& pos = wxDefaultPosition);
114 //---------------------------------------------------------------------------
117 bool wxColourDisplay();
119 int wxDisplayDepth();
120 int wxGetDisplayDepth();
122 void wxDisplaySize(int* OUTPUT, int* OUTPUT);
123 wxSize wxGetDisplaySize();
125 void wxDisplaySizeMM(int* OUTPUT, int* OUTPUT);
126 wxSize wxGetDisplaySizeMM();
128 void wxClientDisplayRect(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT);
129 wxRect wxGetClientDisplayRect();
131 void wxSetCursor(wxCursor& cursor);
133 //----------------------------------------------------------------------
134 // Miscellaneous functions
136 wxWindow * wxFindWindowByLabel(const wxString& label, wxWindow *parent=NULL);
137 wxWindow * wxFindWindowByName(const wxString& name, wxWindow *parent=NULL);
139 void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
140 wxWindow * wxGetActiveWindow();
142 wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt);
143 wxWindow* wxFindWindowAtPoint(const wxPoint& pt);
144 bool wxCheckForInterrupt(wxWindow *wnd);
146 //---------------------------------------------------------------------------
149 bool wxResourceAddIdentifier(char *name, int value);
150 void wxResourceClear(void);
151 wxBitmap wxResourceCreateBitmap(char *resource);
152 wxIcon wxResourceCreateIcon(char *resource);
153 wxMenuBar * wxResourceCreateMenuBar(char *resource);
154 int wxResourceGetIdentifier(char *name);
155 bool wxResourceParseData(char *resource, wxResourceTable *table = NULL);
156 bool wxResourceParseFile(char *filename, wxResourceTable *table = NULL);
157 bool wxResourceParseString(char *resource, wxResourceTable *table = NULL);
159 //---------------------------------------------------------------------------
173 wxSYS_OEM_FIXED_FONT,
174 wxSYS_ANSI_FIXED_FONT,
177 wxSYS_DEVICE_DEFAULT_FONT,
178 wxSYS_DEFAULT_PALETTE,
179 wxSYS_SYSTEM_FIXED_FONT,
180 wxSYS_DEFAULT_GUI_FONT,
182 wxSYS_COLOUR_SCROLLBAR,
183 wxSYS_COLOUR_BACKGROUND,
184 wxSYS_COLOUR_ACTIVECAPTION,
185 wxSYS_COLOUR_INACTIVECAPTION,
188 wxSYS_COLOUR_WINDOWFRAME,
189 wxSYS_COLOUR_MENUTEXT,
190 wxSYS_COLOUR_WINDOWTEXT,
191 wxSYS_COLOUR_CAPTIONTEXT,
192 wxSYS_COLOUR_ACTIVEBORDER,
193 wxSYS_COLOUR_INACTIVEBORDER,
194 wxSYS_COLOUR_APPWORKSPACE,
195 wxSYS_COLOUR_HIGHLIGHT,
196 wxSYS_COLOUR_HIGHLIGHTTEXT,
197 wxSYS_COLOUR_BTNFACE,
198 wxSYS_COLOUR_BTNSHADOW,
199 wxSYS_COLOUR_GRAYTEXT,
200 wxSYS_COLOUR_BTNTEXT,
201 wxSYS_COLOUR_INACTIVECAPTIONTEXT,
202 wxSYS_COLOUR_BTNHIGHLIGHT,
204 wxSYS_COLOUR_3DDKSHADOW,
205 wxSYS_COLOUR_3DLIGHT,
206 wxSYS_COLOUR_INFOTEXT,
209 wxSYS_COLOUR_DESKTOP,
211 wxSYS_COLOUR_3DSHADOW,
212 wxSYS_COLOUR_3DHIGHLIGHT,
213 wxSYS_COLOUR_3DHILIGHT,
214 wxSYS_COLOUR_BTNHILIGHT,
227 wxSYS_HSCROLL_ARROW_X,
228 wxSYS_HSCROLL_ARROW_Y,
244 wxSYS_VSCROLL_ARROW_X,
245 wxSYS_VSCROLL_ARROW_Y,
249 wxSYS_NETWORK_PRESENT,
250 wxSYS_PENWINDOWS_PRESENT,
259 wxColour wxSystemSettings_GetSystemColour(int index) {
260 return wxSystemSettings::GetSystemColour(index);
263 wxFont wxSystemSettings_GetSystemFont(int index) {
264 return wxSystemSettings::GetSystemFont(index);
267 int wxSystemSettings_GetSystemMetric(int index) {
268 return wxSystemSettings::GetSystemMetric(index);
272 //---------------------------------------------------------------------------
275 class wxToolTip : public wxObject {
277 wxToolTip(const wxString &tip);
279 void SetTip(const wxString& tip);
281 // *** Not in the "public" interface void SetWindow(wxWindow *win);
282 wxWindow *GetWindow();
287 void wxToolTip_Enable(bool flag) {
288 wxToolTip::Enable(flag);
291 void wxToolTip_SetDelay(long milliseconds) {
292 wxToolTip::SetDelay(milliseconds);
296 //----------------------------------------------------------------------
300 wxCaret(wxWindow* window, const wxSize& size);
305 %name(GetPositionTuple)void GetPosition(int *OUTPUT, int *OUTPUT);
306 wxPoint GetPosition();
307 %name(GetSizeTuple)void GetSize(int *OUTPUT, int *OUTPUT);
309 wxWindow *GetWindow();
310 %name(MoveXY)void Move(int x, int y);
311 void Move(const wxPoint& pt);
312 %name(SetSizeWH) void SetSize(int width, int height);
313 void SetSize(const wxSize& size);
314 void Show(int show = TRUE);
319 int wxCaret_GetBlinkTime() {
320 return wxCaret::GetBlinkTime();
323 void wxCaret_SetBlinkTime(int milliseconds) {
324 wxCaret::SetBlinkTime(milliseconds);
328 //----------------------------------------------------------------------
331 class wxPyFontEnumerator : public wxFontEnumerator {
333 wxPyFontEnumerator() {}
334 ~wxPyFontEnumerator() {}
336 DEC_PYCALLBACK_BOOL_STRING(OnFacename);
337 DEC_PYCALLBACK_BOOL_STRINGSTRING(OnFontEncoding);
342 IMP_PYCALLBACK_BOOL_STRING(wxPyFontEnumerator, wxFontEnumerator, OnFacename);
343 IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEncoding);
347 %name(wxFontEnumerator) class wxPyFontEnumerator {
349 wxPyFontEnumerator();
350 ~wxPyFontEnumerator();
351 void _setSelf(PyObject* self, PyObject* _class);
352 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxFontEnumerator)"
354 bool EnumerateFacenames(
355 wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
356 bool fixedWidthOnly = FALSE);
357 bool EnumerateEncodings(const char* facename = "");
359 //wxArrayString* GetEncodings();
360 //wxArrayString* GetFacenames();
362 PyObject* GetEncodings() {
363 wxArrayString* arr = self->GetEncodings();
364 PyObject* list = PyList_New(0);
365 for (size_t x=0; x<arr->GetCount(); x++)
366 PyList_Append(list, PyString_FromString((*arr)[x]));
370 PyObject* GetFacenames() {
371 wxArrayString* arr = self->GetFacenames();
372 PyObject* list = PyList_New(0);
373 for (size_t x=0; x<arr->GetCount(); x++)
374 PyList_Append(list, PyString_FromString((*arr)[x]));
380 //----------------------------------------------------------------------
384 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR);
388 //----------------------------------------------------------------------
390 class wxWindowDisabler {
392 wxWindowDisabler(wxWindow *winToSkip = NULL);
396 //----------------------------------------------------------------------
398 bool wxSafeYield(wxWindow* win=NULL);
399 void wxPostEvent(wxEvtHandler *dest, wxEvent& event);
404 void wxWakeUpMainThread();
407 void wxMutexGuiEnter();
408 void wxMutexGuiLeave();
411 class wxMutexGuiLocker {
419 bool wxThread_IsMain() {
420 return wxThread::IsMain();
424 //----------------------------------------------------------------------
430 // wxTipProvider(size_t currentTip); **** Abstract base class
433 virtual wxString GetTip() = 0;
434 size_t GetCurrentTip();
439 // The C++ version of wxPyTipProvider
441 class wxPyTipProvider : public wxTipProvider {
443 wxPyTipProvider(size_t currentTip)
444 : wxTipProvider(currentTip) {}
446 DEC_PYCALLBACK_STRING__pure(GetTip);
451 IMP_PYCALLBACK_STRING__pure( wxPyTipProvider, wxTipProvider, GetTip);
456 // Now let SWIG know about it
457 class wxPyTipProvider : public wxTipProvider {
459 wxPyTipProvider(size_t currentTip);
464 bool wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup = TRUE);
465 %new wxTipProvider * wxCreateFileTipProvider(const wxString& filename, size_t currentTip);
468 //----------------------------------------------------------------------
471 #include <wx/generic/dragimgg.h>
472 static wxPoint wxPyNullPoint;
475 %name (wxDragImage) class wxGenericDragImage : public wxObject
479 wxGenericDragImage(const wxBitmap& image,
480 const wxCursor& cursor = wxNullCursor,
481 const wxPoint& hotspot = wxPyNullPoint);
482 ~wxGenericDragImage();
484 bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
485 bool fullScreen = FALSE, wxRect* rect = NULL);
487 %name(BeginDrag2) bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
488 wxWindow* fullScreenRect);
491 bool Move(const wxPoint& pt);
495 wxRect GetImageRect(const wxPoint& pos) const;
496 bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos,
497 bool eraseOld, bool drawNew);
501 // Alternate Constructors
502 %new wxGenericDragImage* wxDragIcon(const wxIcon& image,
503 const wxCursor& cursor = wxNullCursor,
504 const wxPoint& hotspot = wxPyNullPoint);
506 %new wxGenericDragImage* wxDragString(const wxString& str,
507 const wxCursor& cursor = wxNullCursor,
508 const wxPoint& hotspot = wxPyNullPoint);
510 %new wxGenericDragImage* wxDragTreeItem(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
512 %new wxGenericDragImage* wxDragListItem(const wxListCtrl& listCtrl, long id);
517 wxGenericDragImage* wxDragIcon(const wxIcon& image,
518 const wxCursor& cursor,
519 const wxPoint& hotspot) {
520 return new wxGenericDragImage(image, cursor, hotspot);
523 wxGenericDragImage* wxDragString(const wxString& str,
524 const wxCursor& cursor,
525 const wxPoint& hotspot) {
526 return new wxGenericDragImage(str, cursor, hotspot);
529 wxGenericDragImage* wxDragTreeItem(const wxTreeCtrl& treeCtrl, wxTreeItemId& id) {
530 return new wxGenericDragImage(treeCtrl, id);
533 wxGenericDragImage* wxDragListItem(const wxListCtrl& listCtrl, long id) {
534 return new wxGenericDragImage(listCtrl, id);
541 //----------------------------------------------------------------------
543 class wxPyTimer : public wxObject {
545 wxPyTimer(PyObject* notify);
550 void SetOwner(wxEvtHandler *owner, int id = -1);
551 void Start(int milliseconds=-1, int oneShot=FALSE);
555 //----------------------------------------------------------------------
556 //----------------------------------------------------------------------
561 wxLOG_FatalError, // program can't continue, abort immediately
562 wxLOG_Error, // a serious error, user must be informed about it
563 wxLOG_Warning, // user is normally informed about it but may be ignored
564 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
565 wxLOG_Info, // informational message (a.k.a. 'Verbose')
566 wxLOG_Status, // informational: might go to the status line of GUI app
567 wxLOG_Debug, // never shown to the user, disabled in release mode
568 wxLOG_Trace, // trace messages are also only enabled in debug mode
569 wxLOG_Progress, // used for progress indicator (not yet)
570 wxLOG_User = 100 // user defined levels start here
579 static bool IsEnabled();
580 static bool EnableLogging(bool doIt = TRUE);
581 static void OnLog(wxLogLevel level, const char *szString, int t=0);
583 virtual void Flush();
584 bool HasPendingMessages() const;
586 static void FlushActive();
587 static wxLog *GetActiveTarget();
588 static wxLog *SetActiveTarget(wxLog *pLogger);
590 static void Suspend();
591 static void Resume();
593 void SetVerbose(bool bVerbose = TRUE);
595 static void DontCreateOnDemand();
596 static void SetTraceMask(wxTraceMask ulMask);
597 static void AddTraceMask(const wxString& str);
598 static void RemoveTraceMask(const wxString& str);
600 bool GetVerbose() const { return m_bVerbose; }
602 static wxTraceMask GetTraceMask();
603 static bool IsAllowedTraceMask(const char *mask);
608 class wxLogStderr : public wxLog
611 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
615 class wxLogTextCtrl : public wxLog
618 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
622 class wxLogGui : public wxLog
628 class wxLogWindow : public wxLog
631 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
632 const char *szTitle, // the title of the frame
633 bool bShow = TRUE, // show window immediately?
634 bool bPassToOld = TRUE); // pass log messages to the old target?
636 void Show(bool bShow = TRUE);
637 wxFrame *GetFrame() const;
638 wxLog *GetOldLog() const;
639 bool IsPassingMessages() const;
640 void PassMessages(bool bDoPass) { m_bPassMessages = bDoPass; }
652 unsigned long wxSysErrorCode();
653 const char* wxSysErrorMsg(unsigned long nErrCode = 0);
654 void wxLogFatalError(const char *szFormat);
655 void wxLogError(const char *szFormat);
656 void wxLogWarning(const char *szFormat);
657 void wxLogMessage(const char *szFormat);
658 void wxLogInfo(const char *szFormat);
659 void wxLogVerbose(const char *szFormat);
660 void wxLogStatus(const char *szFormat);
661 %name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const char *szFormat);
662 void wxLogSysError(const char *szFormat);
666 //----------------------------------------------------------------------
675 class wxProcessEvent : public wxEvent {
677 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
680 int m_pid, m_exitcode;
686 %{ // C++ version of wxProcess derived class
688 class wxPyProcess : public wxProcess {
690 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1)
691 : wxProcess(parent, id)
694 DEC_PYCALLBACK_VOID_INTINT(OnTerminate);
699 IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
703 %name(wxProcess)class wxPyProcess : public wxEvtHandler {
705 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
706 %addmethods { void Destroy() { delete self; } }
708 void _setSelf(PyObject* self, PyObject* _class);
709 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxProcess)"
711 void base_OnTerminate(int pid, int status);
717 wxInputStream *GetInputStream();
718 wxInputStream *GetErrorStream();
719 wxOutputStream *GetOutputStream();
726 long wxExecute(const wxString& command,
728 wxPyProcess *process = NULL);
730 //----------------------------------------------------------------------
733 #if !wxUSE_JOYSTICK && !defined(__WXMSW__)
734 // A C++ stub class for wxJoystick for platforms that don't have it.
735 class wxJoystick : public wxObject {
737 wxJoystick(int joystick = wxJOYSTICK1) {
738 bool doSave = wxPyRestoreThread();
739 PyErr_SetString(PyExc_NotImplementedError, "wxJoystick is not available on this platform.");
740 wxPySaveThread(doSave);
742 wxPoint GetPosition() { return wxPoint(-1,-1); }
743 int GetZPosition() { return -1; }
744 int GetButtonState() { return -1; }
745 int GetPOVPosition() { return -1; }
746 int GetPOVCTSPosition() { return -1; }
747 int GetRudderPosition() { return -1; }
748 int GetUPosition() { return -1; }
749 int GetVPosition() { return -1; }
750 int GetMovementThreshold() { return -1; }
751 void SetMovementThreshold(int threshold) ;
753 bool IsOk(void) { return FALSE; }
754 int GetNumberJoysticks() { return -1; }
755 int GetManufacturerId() { return -1; }
756 int GetProductId() { return -1; }
757 wxString GetProductName() { return ""; }
758 int GetXMin() { return -1; }
759 int GetYMin() { return -1; }
760 int GetZMin() { return -1; }
761 int GetXMax() { return -1; }
762 int GetYMax() { return -1; }
763 int GetZMax() { return -1; }
764 int GetNumberButtons() { return -1; }
765 int GetNumberAxes() { return -1; }
766 int GetMaxButtons() { return -1; }
767 int GetMaxAxes() { return -1; }
768 int GetPollingMin() { return -1; }
769 int GetPollingMax() { return -1; }
770 int GetRudderMin() { return -1; }
771 int GetRudderMax() { return -1; }
772 int GetUMin() { return -1; }
773 int GetUMax() { return -1; }
774 int GetVMin() { return -1; }
775 int GetVMax() { return -1; }
777 bool HasRudder() { return FALSE; }
778 bool HasZ() { return FALSE; }
779 bool HasU() { return FALSE; }
780 bool HasV() { return FALSE; }
781 bool HasPOV() { return FALSE; }
782 bool HasPOV4Dir() { return FALSE; }
783 bool HasPOVCTS() { return FALSE; }
785 bool SetCapture(wxWindow* win, int pollingFreq = 0) { return FALSE; }
786 bool ReleaseCapture() { return FALSE; }
792 class wxJoystick : public wxObject {
794 wxJoystick(int joystick = wxJOYSTICK1);
795 wxPoint GetPosition();
797 int GetButtonState();
798 int GetPOVPosition();
799 int GetPOVCTSPosition();
800 int GetRudderPosition();
803 int GetMovementThreshold();
804 void SetMovementThreshold(int threshold) ;
807 int GetNumberJoysticks();
808 int GetManufacturerId();
810 wxString GetProductName();
817 int GetNumberButtons();
838 bool SetCapture(wxWindow* win, int pollingFreq = 0);
839 bool ReleaseCapture();
842 //----------------------------------------------------------------------
845 #if !wxUSE_WAVE && !defined(__WXMSW__)
846 // A C++ stub class for wxWave for platforms that don't have it.
847 class wxWave : public wxObject
850 wxWave(const wxString& fileName, bool isResource = FALSE) {
851 bool doSave = wxPyRestoreThread();
852 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
853 wxPySaveThread(doSave);
855 wxWave(int size, const wxByte* data) {
856 bool doSave = wxPyRestoreThread();
857 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
858 wxPySaveThread(doSave);
863 bool IsOk() const { return FALSE; }
864 bool Play(bool async = TRUE, bool looped = FALSE) const { return FALSE; }
870 class wxWave : public wxObject
873 wxWave(const wxString& fileName, bool isResource = FALSE);
877 bool Play(bool async = TRUE, bool looped = FALSE) const;
880 %new wxWave* wxWaveData(const wxString& data);
881 %{ // Implementations of some alternate "constructors"
882 wxWave* wxWaveData(const wxString& data) {
883 return new wxWave(data.Len(), (wxByte*)data.c_str());
887 //----------------------------------------------------------------------
891 wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator");
892 wxPyPtrTypeMap_Add("wxDragImage", "wxGenericDragImage");
893 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
896 //----------------------------------------------------------------------