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 "pyistream.h"
20 #include <wx/resource.h>
21 #include <wx/tooltip.h>
23 #include <wx/fontenum.h>
24 #include <wx/tipdlg.h>
25 #include <wx/process.h>
27 #if wxUSE_JOYSTICK || defined(__WXMSW__)
28 #include <wx/joystick.h>
31 #if wxUSE_WAVE || defined(__WXMSW__)
35 #include <wx/mimetype.h>
38 //----------------------------------------------------------------------
41 %include my_typemaps.i
43 // Import some definitions of other classes, etc.
53 //---------------------------------------------------------------------------
56 wxString wxFileSelector(char* message,
57 char* default_path = NULL,
58 char* default_filename = NULL,
59 char* default_extension = NULL,
60 char* wildcard = "*.*",
62 wxWindow *parent = NULL,
63 int x = -1, int y = -1);
65 wxString wxGetTextFromUser(const wxString& message,
66 const wxString& caption = wxEmptyString,
67 const wxString& default_value = wxEmptyString,
68 wxWindow *parent = NULL,
69 int x = -1, int y = -1,
72 wxString wxGetPasswordFromUser(const wxString& message,
73 const wxString& caption = wxEmptyString,
74 const wxString& default_value = wxEmptyString,
75 wxWindow *parent = NULL);
78 // TODO: Need to custom wrap this one...
79 // int wxGetMultipleChoice(char* message, char* caption,
80 // int LCOUNT, char** choices,
81 // int nsel, int *selection,
82 // wxWindow *parent = NULL, int x = -1, int y = -1,
83 // bool centre = TRUE, int width=150, int height=200);
86 wxString wxGetSingleChoice(const wxString& message, const wxString& caption,
87 int LCOUNT, wxString* choices,
88 wxWindow *parent = NULL,
89 int x = -1, int y = -1,
91 int width=150, int height=200);
93 int wxGetSingleChoiceIndex(const wxString& message, const wxString& caption,
94 int LCOUNT, wxString* choices,
95 wxWindow *parent = NULL,
96 int x = -1, int y = -1,
98 int width=150, int height=200);
101 int wxMessageBox(const wxString& message,
102 const wxString& caption = wxEmptyString,
103 int style = wxOK | wxCENTRE,
104 wxWindow *parent = NULL,
105 int x = -1, int y = -1);
107 long wxGetNumberFromUser(const wxString& message,
108 const wxString& prompt,
109 const wxString& caption,
111 long min = 0, long max = 100,
112 wxWindow *parent = NULL,
113 const wxPoint& pos = wxDefaultPosition);
115 //---------------------------------------------------------------------------
118 bool wxColourDisplay();
120 int wxDisplayDepth();
121 int wxGetDisplayDepth();
123 void wxDisplaySize(int* OUTPUT, int* OUTPUT);
124 wxSize wxGetDisplaySize();
126 void wxDisplaySizeMM(int* OUTPUT, int* OUTPUT);
127 wxSize wxGetDisplaySizeMM();
129 void wxClientDisplayRect(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT);
130 wxRect wxGetClientDisplayRect();
132 void wxSetCursor(wxCursor& cursor);
134 //----------------------------------------------------------------------
135 // Miscellaneous functions
137 wxWindow * wxFindWindowByLabel(const wxString& label, wxWindow *parent=NULL);
138 wxWindow * wxFindWindowByName(const wxString& name, wxWindow *parent=NULL);
140 void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
141 wxWindow * wxGetActiveWindow();
143 wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt);
144 wxWindow* wxFindWindowAtPoint(const wxPoint& pt);
147 bool wxCheckForInterrupt(wxWindow *wnd);
148 void wxFlushEvents();
151 //---------------------------------------------------------------------------
154 bool wxResourceAddIdentifier(char *name, int value);
155 void wxResourceClear(void);
156 wxBitmap wxResourceCreateBitmap(char *resource);
157 wxIcon wxResourceCreateIcon(char *resource);
158 wxMenuBar * wxResourceCreateMenuBar(char *resource);
159 int wxResourceGetIdentifier(char *name);
160 bool wxResourceParseData(char *resource, wxResourceTable *table = NULL);
161 bool wxResourceParseFile(char *filename, wxResourceTable *table = NULL);
162 bool wxResourceParseString(char *resource, wxResourceTable *table = NULL);
164 //---------------------------------------------------------------------------
167 // possible values for wxSystemSettings::GetFont() parameter
171 wxSYS_OEM_FIXED_FONT = 10,
172 wxSYS_ANSI_FIXED_FONT,
175 wxSYS_DEVICE_DEFAULT_FONT,
176 wxSYS_DEFAULT_PALETTE,
177 wxSYS_SYSTEM_FIXED_FONT,
178 wxSYS_DEFAULT_GUI_FONT
181 // possible values for wxSystemSettings::GetColour() parameter
185 wxSYS_COLOUR_SCROLLBAR,
186 wxSYS_COLOUR_BACKGROUND,
187 wxSYS_COLOUR_DESKTOP = wxSYS_COLOUR_BACKGROUND,
188 wxSYS_COLOUR_ACTIVECAPTION,
189 wxSYS_COLOUR_INACTIVECAPTION,
192 wxSYS_COLOUR_WINDOWFRAME,
193 wxSYS_COLOUR_MENUTEXT,
194 wxSYS_COLOUR_WINDOWTEXT,
195 wxSYS_COLOUR_CAPTIONTEXT,
196 wxSYS_COLOUR_ACTIVEBORDER,
197 wxSYS_COLOUR_INACTIVEBORDER,
198 wxSYS_COLOUR_APPWORKSPACE,
199 wxSYS_COLOUR_HIGHLIGHT,
200 wxSYS_COLOUR_HIGHLIGHTTEXT,
201 wxSYS_COLOUR_BTNFACE,
202 wxSYS_COLOUR_3DFACE = wxSYS_COLOUR_BTNFACE,
203 wxSYS_COLOUR_BTNSHADOW,
204 wxSYS_COLOUR_3DSHADOW = wxSYS_COLOUR_BTNSHADOW,
205 wxSYS_COLOUR_GRAYTEXT,
206 wxSYS_COLOUR_BTNTEXT,
207 wxSYS_COLOUR_INACTIVECAPTIONTEXT,
208 wxSYS_COLOUR_BTNHIGHLIGHT,
209 wxSYS_COLOUR_BTNHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
210 wxSYS_COLOUR_3DHIGHLIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
211 wxSYS_COLOUR_3DHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
212 wxSYS_COLOUR_3DDKSHADOW,
213 wxSYS_COLOUR_3DLIGHT,
214 wxSYS_COLOUR_INFOTEXT,
216 wxSYS_COLOUR_LISTBOX,
217 wxSYS_COLOUR_HOTLIGHT,
218 wxSYS_COLOUR_GRADIENTACTIVECAPTION,
219 wxSYS_COLOUR_GRADIENTINACTIVECAPTION,
220 wxSYS_COLOUR_MENUHILIGHT,
221 wxSYS_COLOUR_MENUBAR,
226 // possible values for wxSystemSettings::GetMetric() parameter
230 wxSYS_MOUSE_BUTTONS = 1,
241 wxSYS_HSCROLL_ARROW_X,
242 wxSYS_HSCROLL_ARROW_Y,
258 wxSYS_VSCROLL_ARROW_X,
259 wxSYS_VSCROLL_ARROW_Y,
263 wxSYS_NETWORK_PRESENT,
264 wxSYS_PENWINDOWS_PRESENT,
269 // possible values for wxSystemSettings::HasFeature() parameter
272 wxSYS_CAN_DRAW_FRAME_DECORATIONS = 1,
273 wxSYS_CAN_ICONIZE_FRAME
278 class wxSystemSettings {
280 // get a standard system colour
281 static wxColour GetColour(wxSystemColour index);
283 // get a standard system font
284 static wxFont GetFont(wxSystemFont index);
286 // get a system-dependent metric
287 static int GetMetric(wxSystemMetric index);
289 // return true if the port has certain feature
290 static bool HasFeature(wxSystemFeature index);
296 //---------------------------------------------------------------------------
299 class wxToolTip : public wxObject {
301 wxToolTip(const wxString &tip);
303 void SetTip(const wxString& tip);
305 // *** Not in the "public" interface void SetWindow(wxWindow *win);
306 wxWindow *GetWindow();
308 static void Enable(bool flag);
309 static void SetDelay(long milliseconds);
312 //----------------------------------------------------------------------
316 wxCaret(wxWindow* window, const wxSize& size);
321 %name(GetPositionTuple)void GetPosition(int *OUTPUT, int *OUTPUT);
322 wxPoint GetPosition();
323 %name(GetSizeTuple)void GetSize(int *OUTPUT, int *OUTPUT);
325 wxWindow *GetWindow();
326 %name(MoveXY)void Move(int x, int y);
327 void Move(const wxPoint& pt);
328 %name(SetSizeWH) void SetSize(int width, int height);
329 void SetSize(const wxSize& size);
330 void Show(int show = TRUE);
335 int wxCaret_GetBlinkTime() {
336 return wxCaret::GetBlinkTime();
339 void wxCaret_SetBlinkTime(int milliseconds) {
340 wxCaret::SetBlinkTime(milliseconds);
344 //----------------------------------------------------------------------
347 class wxPyFontEnumerator : public wxFontEnumerator {
349 wxPyFontEnumerator() {}
350 ~wxPyFontEnumerator() {}
352 DEC_PYCALLBACK_BOOL_STRING(OnFacename);
353 DEC_PYCALLBACK_BOOL_STRINGSTRING(OnFontEncoding);
358 IMP_PYCALLBACK_BOOL_STRING(wxPyFontEnumerator, wxFontEnumerator, OnFacename);
359 IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEncoding);
363 %name(wxFontEnumerator) class wxPyFontEnumerator {
365 wxPyFontEnumerator();
366 ~wxPyFontEnumerator();
367 void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref);
368 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFontEnumerator, 0)"
370 bool EnumerateFacenames(
371 wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
372 bool fixedWidthOnly = FALSE);
373 bool EnumerateEncodings(const char* facename = "");
375 //wxArrayString* GetEncodings();
376 //wxArrayString* GetFacenames();
378 PyObject* GetEncodings() {
379 wxArrayString* arr = self->GetEncodings();
380 return wxArrayString2PyList_helper(*arr);
383 PyObject* GetFacenames() {
384 wxArrayString* arr = self->GetFacenames();
385 return wxArrayString2PyList_helper(*arr);
390 //----------------------------------------------------------------------
394 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR);
398 //----------------------------------------------------------------------
400 class wxWindowDisabler {
402 wxWindowDisabler(wxWindow *winToSkip = NULL);
406 //----------------------------------------------------------------------
408 bool wxSafeYield(wxWindow* win=NULL);
409 void wxPostEvent(wxEvtHandler *dest, wxEvent& event);
414 void wxWakeUpMainThread();
417 void wxMutexGuiEnter();
418 void wxMutexGuiLeave();
421 class wxMutexGuiLocker {
429 bool wxThread_IsMain() {
430 #ifdef WXP_WITH_THREAD
431 return wxThread::IsMain();
438 //----------------------------------------------------------------------
444 // wxTipProvider(size_t currentTip); **** Abstract base class
447 virtual wxString GetTip() = 0;
448 size_t GetCurrentTip();
453 // The C++ version of wxPyTipProvider
455 class wxPyTipProvider : public wxTipProvider {
457 wxPyTipProvider(size_t currentTip)
458 : wxTipProvider(currentTip) {}
460 DEC_PYCALLBACK_STRING__pure(GetTip);
465 IMP_PYCALLBACK_STRING__pure( wxPyTipProvider, wxTipProvider, GetTip);
470 // Now let SWIG know about it
471 class wxPyTipProvider : public wxTipProvider {
473 wxPyTipProvider(size_t currentTip);
478 bool wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup = TRUE);
479 %new wxTipProvider * wxCreateFileTipProvider(const wxString& filename, size_t currentTip);
482 //----------------------------------------------------------------------
485 #include <wx/generic/dragimgg.h>
488 %name (wxDragImage) class wxGenericDragImage : public wxObject
492 wxGenericDragImage(const wxBitmap& image,
493 const wxCursor& cursor = wxNullCursor);
494 %name(wxDragIcon)wxGenericDragImage(const wxIcon& image,
495 const wxCursor& cursor = wxNullCursor);
496 %name(wxDragString)wxGenericDragImage(const wxString& str,
497 const wxCursor& cursor = wxNullCursor);
498 %name(wxDragTreeItem)wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
499 %name(wxDragListItem)wxGenericDragImage(const wxListCtrl& listCtrl, long id);
501 ~wxGenericDragImage();
503 void SetBackingBitmap(wxBitmap* bitmap);
504 bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
505 bool fullScreen = FALSE, wxRect* rect = NULL);
507 %name(BeginDrag2) bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
508 wxWindow* fullScreenRect);
511 bool Move(const wxPoint& pt);
515 wxRect GetImageRect(const wxPoint& pos) const;
516 bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos,
517 bool eraseOld, bool drawNew);
521 //----------------------------------------------------------------------
523 class wxPyTimer : public wxObject {
525 wxPyTimer(PyObject* notify);
530 void SetOwner(wxEvtHandler *owner, int id = -1);
531 void Start(int milliseconds=-1, int oneShot=FALSE);
539 // ctor starts the stop watch
542 void Start(long t = 0);
546 // get elapsed time since the last Start() or Pause() in milliseconds
551 //----------------------------------------------------------------------
552 //----------------------------------------------------------------------
557 wxLOG_FatalError, // program can't continue, abort immediately
558 wxLOG_Error, // a serious error, user must be informed about it
559 wxLOG_Warning, // user is normally informed about it but may be ignored
560 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
561 wxLOG_Info, // informational message (a.k.a. 'Verbose')
562 wxLOG_Status, // informational: might go to the status line of GUI app
563 wxLOG_Debug, // never shown to the user, disabled in release mode
564 wxLOG_Trace, // trace messages are also only enabled in debug mode
565 wxLOG_Progress, // used for progress indicator (not yet)
566 wxLOG_User = 100 // user defined levels start here
575 static bool IsEnabled();
576 static bool EnableLogging(bool doIt = TRUE);
577 static void OnLog(wxLogLevel level, const char *szString, int t=0);
579 virtual void Flush();
580 bool HasPendingMessages() const;
582 static void FlushActive();
583 static wxLog *GetActiveTarget();
584 static wxLog *SetActiveTarget(wxLog *pLogger);
586 static void Suspend();
587 static void Resume();
589 void SetVerbose(bool bVerbose = TRUE);
591 static void DontCreateOnDemand();
592 static void SetTraceMask(wxTraceMask ulMask);
593 static void AddTraceMask(const wxString& str);
594 static void RemoveTraceMask(const wxString& str);
595 static void ClearTraceMasks();
597 static void SetTimestamp(const wxChar *ts);
598 static const wxChar *GetTimestamp();
600 bool GetVerbose() const { return m_bVerbose; }
602 static wxTraceMask GetTraceMask();
603 static bool IsAllowedTraceMask(const char *mask);
605 // static void TimeStamp(wxString *str);
607 wxString TimeStamp() {
609 wxLog::TimeStamp(&msg);
616 class wxLogStderr : public wxLog
619 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
623 class wxLogTextCtrl : public wxLog
626 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
630 class wxLogGui : public wxLog
636 class wxLogWindow : public wxLog
639 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
640 const char *szTitle, // the title of the frame
641 bool bShow = TRUE, // show window immediately?
642 bool bPassToOld = TRUE); // pass log messages to the old target?
644 void Show(bool bShow = TRUE);
645 wxFrame *GetFrame() const;
646 wxLog *GetOldLog() const;
647 bool IsPassingMessages() const;
648 void PassMessages(bool bDoPass) { m_bPassMessages = bDoPass; }
660 class wxLogChain : public wxLog
663 wxLogChain(wxLog *logger);
664 void SetLog(wxLog *logger);
665 void PassMessages(bool bDoPass);
666 bool IsPassingMessages();
671 unsigned long wxSysErrorCode();
672 const char* wxSysErrorMsg(unsigned long nErrCode = 0);
673 void wxLogFatalError(const char *szFormat);
674 void wxLogError(const char *szFormat);
675 void wxLogWarning(const char *szFormat);
676 void wxLogMessage(const char *szFormat);
677 void wxLogInfo(const char *szFormat);
678 void wxLogVerbose(const char *szFormat);
679 void wxLogStatus(const char *szFormat);
680 %name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const char *szFormat);
681 void wxLogSysError(const char *szFormat);
685 // A Log class that can be derived from in wxPython
686 class wxPyLog : public wxLog {
688 wxPyLog() : wxLog() {}
690 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
692 wxPyBeginBlockThreads();
693 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog")))
694 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(isi)", level, szString, t));
695 wxPyEndBlockThreads();
697 wxLog::DoLog(level, szString, t);
700 virtual void DoLogString(const wxChar *szString, time_t t) {
702 wxPyBeginBlockThreads();
703 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString")))
704 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(si)", szString, t));
705 wxPyEndBlockThreads();
707 wxLog::DoLogString(szString, t);
714 // Now tell SWIG about it
715 class wxPyLog : public wxLog {
718 void _setCallbackInfo(PyObject* self, PyObject* _class);
719 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyLog)"
720 %addmethods { void Destroy() { delete self; } }
725 //----------------------------------------------------------------------
734 class wxProcessEvent : public wxEvent {
736 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
739 int m_pid, m_exitcode;
745 %{ // C++ version of wxProcess derived class
747 class wxPyProcess : public wxProcess {
749 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1)
750 : wxProcess(parent, id)
753 DEC_PYCALLBACK_VOID_INTINT(OnTerminate);
758 IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
763 %name(wxProcess)class wxPyProcess : public wxEvtHandler {
765 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
766 %addmethods { void Destroy() { delete self; } }
768 void _setCallbackInfo(PyObject* self, PyObject* _class);
769 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxProcess)"
771 void base_OnTerminate(int pid, int status);
777 wxInputStream *GetInputStream();
778 wxInputStream *GetErrorStream();
779 wxOutputStream *GetOutputStream();
786 long wxExecute(const wxString& command,
788 wxPyProcess *process = NULL);
790 //----------------------------------------------------------------------
793 #if !wxUSE_JOYSTICK && !defined(__WXMSW__)
794 // A C++ stub class for wxJoystick for platforms that don't have it.
795 class wxJoystick : public wxObject {
797 wxJoystick(int joystick = wxJOYSTICK1) {
798 wxPyBeginBlockThreads();
799 PyErr_SetString(PyExc_NotImplementedError, "wxJoystick is not available on this platform.");
800 wxPyEndBlockThreads();
802 wxPoint GetPosition() { return wxPoint(-1,-1); }
803 int GetZPosition() { return -1; }
804 int GetButtonState() { return -1; }
805 int GetPOVPosition() { return -1; }
806 int GetPOVCTSPosition() { return -1; }
807 int GetRudderPosition() { return -1; }
808 int GetUPosition() { return -1; }
809 int GetVPosition() { return -1; }
810 int GetMovementThreshold() { return -1; }
811 void SetMovementThreshold(int threshold) {}
813 bool IsOk(void) { return FALSE; }
814 int GetNumberJoysticks() { return -1; }
815 int GetManufacturerId() { return -1; }
816 int GetProductId() { return -1; }
817 wxString GetProductName() { return ""; }
818 int GetXMin() { return -1; }
819 int GetYMin() { return -1; }
820 int GetZMin() { return -1; }
821 int GetXMax() { return -1; }
822 int GetYMax() { return -1; }
823 int GetZMax() { return -1; }
824 int GetNumberButtons() { return -1; }
825 int GetNumberAxes() { return -1; }
826 int GetMaxButtons() { return -1; }
827 int GetMaxAxes() { return -1; }
828 int GetPollingMin() { return -1; }
829 int GetPollingMax() { return -1; }
830 int GetRudderMin() { return -1; }
831 int GetRudderMax() { return -1; }
832 int GetUMin() { return -1; }
833 int GetUMax() { return -1; }
834 int GetVMin() { return -1; }
835 int GetVMax() { return -1; }
837 bool HasRudder() { return FALSE; }
838 bool HasZ() { return FALSE; }
839 bool HasU() { return FALSE; }
840 bool HasV() { return FALSE; }
841 bool HasPOV() { return FALSE; }
842 bool HasPOV4Dir() { return FALSE; }
843 bool HasPOVCTS() { return FALSE; }
845 bool SetCapture(wxWindow* win, int pollingFreq = 0) { return FALSE; }
846 bool ReleaseCapture() { return FALSE; }
852 class wxJoystick : public wxObject {
854 wxJoystick(int joystick = wxJOYSTICK1);
857 wxPoint GetPosition();
859 int GetButtonState();
860 int GetPOVPosition();
861 int GetPOVCTSPosition();
862 int GetRudderPosition();
865 int GetMovementThreshold();
866 void SetMovementThreshold(int threshold) ;
869 int GetNumberJoysticks();
870 int GetManufacturerId();
872 wxString GetProductName();
879 int GetNumberButtons();
900 bool SetCapture(wxWindow* win, int pollingFreq = 0);
901 bool ReleaseCapture();
904 //----------------------------------------------------------------------
908 // A C++ stub class for wxWave for platforms that don't have it.
909 class wxWave : public wxObject
912 wxWave(const wxString& fileName, bool isResource = FALSE) {
913 wxPyBeginBlockThreads();
914 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
915 wxPyEndBlockThreads();
917 wxWave(int size, const wxByte* data) {
918 wxPyBeginBlockThreads();
919 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
920 wxPyEndBlockThreads();
925 bool IsOk() const { return FALSE; }
926 bool Play(bool async = TRUE, bool looped = FALSE) const { return FALSE; }
932 class wxWave : public wxObject
935 wxWave(const wxString& fileName, bool isResource = FALSE);
939 bool Play(bool async = TRUE, bool looped = FALSE) const;
942 %new wxWave* wxWaveData(const wxString& data);
943 %{ // Implementations of some alternate "constructors"
944 wxWave* wxWaveData(const wxString& data) {
945 return new wxWave(data.Len(), (wxByte*)data.c_str());
950 //----------------------------------------------------------------------
954 wxMAILCAP_STANDARD = 1,
955 wxMAILCAP_NETSCAPE = 2,
969 wxFileTypeInfo(const char *mimeType,
971 const char *printCmd,
975 // the array elements correspond to the parameters of the ctor above in
977 %name(wxFileTypeInfoSequence)wxFileTypeInfo(const wxArrayString& sArray);
979 // invalid item - use this to terminate the array passed to
980 // wxMimeTypesManager::AddFallbacks
981 %name(wxNullFileTypeInfo)wxFileTypeInfo();
984 // test if this object can be used
985 bool IsValid() const;
989 void SetIcon(const wxString& iconFile, int iconIndex = 0);
991 // set the short desc
992 void SetShortDesc(const wxString& shortDesc);
996 const wxString& GetMimeType() const;
997 // get the open command
998 const wxString& GetOpenCommand() const;
999 // get the print command
1000 const wxString& GetPrintCommand() const;
1001 // get the short description (only used under Win32 so far)
1002 const wxString& GetShortDesc() const;
1003 // get the long, user visible description
1004 const wxString& GetDescription() const;
1007 // get the array of all extensions
1008 //const wxArrayString& GetExtensions() const;
1010 PyObject* GetExtensions() {
1011 wxArrayString& arr = (wxArrayString&)self->GetExtensions();
1012 return wxArrayString2PyList_helper(arr);
1016 int GetExtensionsCount() const;
1018 // get the icon info
1019 const wxString& GetIconFile() const;
1020 int GetIconIndex() const;
1030 // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
1032 // An object of this class must be passed to Get{Open|Print}Command. The
1033 // default implementation is trivial and doesn't know anything at all about
1034 // parameters, only filename and MIME type are used (so it's probably ok for
1035 // Windows where %{param} is not used anyhow)
1036 class MessageParameters
1040 MessageParameters(const wxString& filename=wxEmptyString,
1041 const wxString& mimetype=wxEmptyString);
1043 // accessors (called by GetOpenCommand)
1045 const wxString& GetFileName() const;
1047 const wxString& GetMimeType() const;;
1049 // override this function in derived class
1050 virtual wxString GetParamValue(const wxString& name) const;
1052 // virtual dtor as in any base class
1053 virtual ~MessageParameters();
1057 // ctor from static data
1058 wxFileType(const wxFileTypeInfo& ftInfo);
1060 // return the MIME type for this file type
1062 PyObject* GetMimeType() {
1064 if (self->GetMimeType(&str))
1065 return PyString_FromString(str.c_str());
1069 PyObject* GetMimeTypes() {
1071 if (self->GetMimeTypes(arr))
1072 return wxArrayString2PyList_helper(arr);
1079 // Get all extensions associated with this file type
1081 PyObject* GetExtensions() {
1083 if (self->GetExtensions(arr))
1084 return wxArrayString2PyList_helper(arr);
1092 // Get the icon corresponding to this file type
1093 %new wxIcon* GetIcon() {
1095 if (self->GetIcon(&icon))
1096 return new wxIcon(icon);
1101 // Get the icon corresponding to this file type, the name of the file
1102 // where this icon resides, and its index in this file if applicable.
1103 PyObject* GetIconInfo() {
1107 if (self->GetIcon(&icon, &iconFile, &iconIndex)) {
1108 wxPyBeginBlockThreads();
1109 PyObject* tuple = PyTuple_New(3);
1110 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon),
1112 PyTuple_SetItem(tuple, 1, PyString_FromString(iconFile.c_str()));
1113 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
1114 wxPyEndBlockThreads();
1123 // get a brief file type description ("*.txt" => "text document")
1124 PyObject* GetDescription() {
1126 if (self->GetDescription(&str))
1127 return PyString_FromString(str.c_str());
1134 // get the command to open/execute the file of given type
1136 PyObject* GetOpenCommand(const wxString& filename,
1137 const wxString& mimetype=wxEmptyString) {
1139 if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
1140 return PyString_FromString(str.c_str());
1147 // get the command to print the file of given type
1149 PyObject* GetPrintCommand(const wxString& filename,
1150 const wxString& mimetype=wxEmptyString) {
1152 if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
1153 return PyString_FromString(str.c_str());
1160 // Get all commands defined for this file type
1162 PyObject* GetAllCommands(const wxString& filename,
1163 const wxString& mimetype=wxEmptyString) {
1164 wxArrayString verbs;
1165 wxArrayString commands;
1166 if (self->GetAllCommands(&verbs, &commands,
1167 wxFileType::MessageParameters(filename, mimetype))) {
1168 wxPyBeginBlockThreads();
1169 PyObject* tuple = PyTuple_New(2);
1170 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
1171 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
1172 wxPyEndBlockThreads();
1181 // set an arbitrary command, ask confirmation if it already exists and
1182 // overwriteprompt is TRUE
1183 bool SetCommand(const wxString& cmd, const wxString& verb,
1184 bool overwriteprompt = TRUE);
1186 bool SetDefaultIcon(const wxString& cmd = wxEmptyString, int index = 0);
1189 // remove the association for this filetype from the system MIME database:
1190 // notice that it will only work if the association is defined in the user
1191 // file/registry part, we will never modify the system-wide settings
1195 // expand a string in the format of GetOpenCommand (which may contain
1196 // '%s' and '%t' format specificators for the file name and mime type
1197 // and %{param} constructions).
1198 static wxString ExpandCommand(const wxString& command,
1199 const MessageParameters& params);
1201 // dtor (not virtual, shouldn't be derived from)
1209 class wxMimeTypesManager
1212 // static helper functions
1213 // -----------------------
1215 // check if the given MIME type is the same as the other one: the
1216 // second argument may contain wildcards ('*'), but not the first. If
1217 // the types are equal or if the mimeType matches wildcard the function
1218 // returns TRUE, otherwise it returns FALSE
1219 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
1222 wxMimeTypesManager();
1224 // loads data from standard files according to the mailcap styles
1225 // specified: this is a bitwise OR of wxMailcapStyle values
1227 // use the extraDir parameter if you want to look for files in another
1229 void Initialize(int mailcapStyle = wxMAILCAP_STANDARD,
1230 const wxString& extraDir = wxEmptyString);
1232 // and this function clears all the data from the manager
1235 // Database lookup: all functions return a pointer to wxFileType object
1236 // whose methods may be used to query it for the information you're
1237 // interested in. If the return value is !NULL, caller is responsible for
1239 // get file type from file extension
1240 %new wxFileType *GetFileTypeFromExtension(const wxString& ext);
1242 // get file type from MIME type (in format <category>/<format>)
1243 %new wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
1245 // other operations: return TRUE if there were no errors or FALSE if there
1246 // were some unreckognized entries (the good entries are always read anyhow)
1249 // read in additional file (the standard ones are read automatically)
1250 // in mailcap format (see mimetype.cpp for description)
1252 // 'fallback' parameter may be set to TRUE to avoid overriding the
1253 // settings from other, previously parsed, files by this one: normally,
1254 // the files read most recently would override the older files, but with
1255 // fallback == TRUE this won't happen
1256 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
1258 // read in additional file in mime.types format
1259 bool ReadMimeTypes(const wxString& filename);
1261 // enumerate all known MIME types
1263 PyObject* EnumAllFileTypes() {
1265 self->EnumAllFileTypes(arr);
1266 return wxArrayString2PyList_helper(arr);
1270 // these functions can be used to provide default values for some of the
1271 // MIME types inside the program itself (you may also use
1272 // ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
1273 // achieve the same goal, but this requires having this info in a file).
1275 void AddFallback(const wxFileTypeInfo& ft);
1278 // create or remove associations
1280 // create a new association using the fields of wxFileTypeInfo (at least
1281 // the MIME type and the extension should be set)
1282 // if the other fields are empty, the existing values should be left alone
1283 %new wxFileType *Associate(const wxFileTypeInfo& ftInfo);
1286 bool Unassociate(wxFileType *ft) ;
1288 // dtor (not virtual, shouldn't be derived from)
1289 ~wxMimeTypesManager();
1297 extern wxMimeTypesManager* wxTheMimeTypesManager;
1303 //----------------------------------------------------------------------
1306 #include <wx/docview.h>
1309 class wxFileHistory : public wxObject
1312 wxFileHistory(int maxFiles = 9);
1316 void AddFileToHistory(const wxString& file);
1317 void RemoveFileFromHistory(int i);
1318 int GetMaxFiles() const;
1319 void UseMenu(wxMenu *menu);
1321 // Remove menu from the list (MDI child may be closing)
1322 void RemoveMenu(wxMenu *menu);
1324 void Load(wxConfigBase& config);
1325 void Save(wxConfigBase& config);
1327 void AddFilesToMenu();
1328 %name(AddFilesToSingleMenu)void AddFilesToMenu(wxMenu* menu);
1331 wxString GetHistoryFile(int i) const;
1333 // A synonym for GetNoHistoryFiles
1334 int GetCount() const;
1335 int GetNoHistoryFiles() const;
1339 //----------------------------------------------------------------------
1340 //----------------------------------------------------------------------
1344 wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator");
1345 wxPyPtrTypeMap_Add("wxDragImage", "wxGenericDragImage");
1346 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
1349 //----------------------------------------------------------------------