]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/misc2.i
patch from Dimitri fixing a few memory leaks and unTABbing the sources
[wxWidgets.git] / wxPython / src / misc2.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: misc2.i
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.)
6 //
7 // Author: Robin Dunn
8 //
9 // Created: 18-June-1999
10 // RCS-ID: $Id$
11 // Copyright: (c) 1998 by Total Control Software
12 // Licence: wxWindows license
13 /////////////////////////////////////////////////////////////////////////////
14
15 %module misc2
16
17 %{
18 #include "helpers.h"
19 #include "pyistream.h"
20 #include <wx/resource.h>
21 #include <wx/tooltip.h>
22 #include <wx/caret.h>
23 #include <wx/fontenum.h>
24 #include <wx/tipdlg.h>
25 #include <wx/process.h>
26
27 #if wxUSE_JOYSTICK || defined(__WXMSW__)
28 #include <wx/joystick.h>
29 #endif
30
31 #if wxUSE_WAVE || defined(__WXMSW__)
32 #include <wx/wave.h>
33 #endif
34
35 #include <wx/mimetype.h>
36 %}
37
38 //----------------------------------------------------------------------
39
40 %include typemaps.i
41 %include my_typemaps.i
42
43 // Import some definitions of other classes, etc.
44 %import _defs.i
45 %import windows.i
46 %import misc.i
47 %import gdi.i
48 %import events.i
49 %import streams.i
50 %import utils.i
51
52
53 //---------------------------------------------------------------------------
54 // Dialog Functions
55
56 wxString wxFileSelector(const wxChar* message = wxFileSelectorPromptStr,
57 const wxChar* default_path = NULL,
58 const wxChar* default_filename = NULL,
59 const wxChar* default_extension = NULL,
60 const wxChar* wildcard = wxFileSelectorDefaultWildcardStr,
61 int flags = 0,
62 wxWindow *parent = NULL,
63 int x = -1, int y = -1);
64
65 // Ask for filename to load
66 wxString wxLoadFileSelector(const wxChar *what,
67 const wxChar *extension,
68 const wxChar *default_name = NULL,
69 wxWindow *parent = NULL);
70
71 // Ask for filename to save
72 wxString wxSaveFileSelector(const wxChar *what,
73 const wxChar *extension,
74 const wxChar *default_name = NULL,
75 wxWindow *parent = NULL);
76
77 wxString wxGetTextFromUser(const wxString& message,
78 const wxString& caption = wxEmptyString,
79 const wxString& default_value = wxEmptyString,
80 wxWindow *parent = NULL,
81 int x = -1, int y = -1,
82 bool centre = TRUE);
83
84 wxString wxGetPasswordFromUser(const wxString& message,
85 const wxString& caption = wxEmptyString,
86 const wxString& default_value = wxEmptyString,
87 wxWindow *parent = NULL);
88
89
90 // TODO: Need to custom wrap this one...
91 // int wxGetMultipleChoice(char* message, char* caption,
92 // int LCOUNT, char** choices,
93 // int nsel, int *selection,
94 // wxWindow *parent = NULL, int x = -1, int y = -1,
95 // bool centre = TRUE, int width=150, int height=200);
96
97
98 wxString wxGetSingleChoice(const wxString& message, const wxString& caption,
99 int LCOUNT, wxString* choices,
100 wxWindow *parent = NULL,
101 int x = -1, int y = -1,
102 bool centre = TRUE,
103 int width=150, int height=200);
104
105 int wxGetSingleChoiceIndex(const wxString& message, const wxString& caption,
106 int LCOUNT, wxString* choices,
107 wxWindow *parent = NULL,
108 int x = -1, int y = -1,
109 bool centre = TRUE,
110 int width=150, int height=200);
111
112
113 int wxMessageBox(const wxString& message,
114 const wxString& caption = wxEmptyString,
115 int style = wxOK | wxCENTRE,
116 wxWindow *parent = NULL,
117 int x = -1, int y = -1);
118
119 long wxGetNumberFromUser(const wxString& message,
120 const wxString& prompt,
121 const wxString& caption,
122 long value,
123 long min = 0, long max = 100,
124 wxWindow *parent = NULL,
125 const wxPoint& pos = wxDefaultPosition);
126
127 //---------------------------------------------------------------------------
128 // GDI Functions
129
130 bool wxColourDisplay();
131
132 int wxDisplayDepth();
133 int wxGetDisplayDepth();
134
135 void wxDisplaySize(int* OUTPUT, int* OUTPUT);
136 wxSize wxGetDisplaySize();
137
138 void wxDisplaySizeMM(int* OUTPUT, int* OUTPUT);
139 wxSize wxGetDisplaySizeMM();
140
141 void wxClientDisplayRect(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT);
142 wxRect wxGetClientDisplayRect();
143
144 void wxSetCursor(wxCursor& cursor);
145
146 //----------------------------------------------------------------------
147 // Miscellaneous functions
148
149 wxWindow * wxFindWindowByLabel(const wxString& label, wxWindow *parent=NULL);
150 wxWindow * wxFindWindowByName(const wxString& name, wxWindow *parent=NULL);
151
152 void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
153 wxWindow * wxGetActiveWindow();
154
155 wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt);
156 wxWindow* wxFindWindowAtPoint(const wxPoint& pt);
157
158 #ifdef __WXMSW__
159 bool wxCheckForInterrupt(wxWindow *wnd);
160 void wxFlushEvents();
161 #endif
162
163 //---------------------------------------------------------------------------
164 // Resource System
165
166 bool wxResourceAddIdentifier(char *name, int value);
167 void wxResourceClear(void);
168 wxBitmap wxResourceCreateBitmap(char *resource);
169 wxIcon wxResourceCreateIcon(char *resource);
170 wxMenuBar * wxResourceCreateMenuBar(char *resource);
171 int wxResourceGetIdentifier(char *name);
172 bool wxResourceParseData(char *resource, wxResourceTable *table = NULL);
173 bool wxResourceParseFile(char *filename, wxResourceTable *table = NULL);
174 bool wxResourceParseString(char *resource, wxResourceTable *table = NULL);
175
176 //---------------------------------------------------------------------------
177 // System Settings
178
179 // possible values for wxSystemSettings::GetFont() parameter
180 //
181 enum wxSystemFont
182 {
183 wxSYS_OEM_FIXED_FONT = 10,
184 wxSYS_ANSI_FIXED_FONT,
185 wxSYS_ANSI_VAR_FONT,
186 wxSYS_SYSTEM_FONT,
187 wxSYS_DEVICE_DEFAULT_FONT,
188 wxSYS_DEFAULT_PALETTE,
189 wxSYS_SYSTEM_FIXED_FONT,
190 wxSYS_DEFAULT_GUI_FONT
191 };
192
193 // possible values for wxSystemSettings::GetColour() parameter
194 //
195 enum wxSystemColour
196 {
197 wxSYS_COLOUR_SCROLLBAR,
198 wxSYS_COLOUR_BACKGROUND,
199 wxSYS_COLOUR_DESKTOP = wxSYS_COLOUR_BACKGROUND,
200 wxSYS_COLOUR_ACTIVECAPTION,
201 wxSYS_COLOUR_INACTIVECAPTION,
202 wxSYS_COLOUR_MENU,
203 wxSYS_COLOUR_WINDOW,
204 wxSYS_COLOUR_WINDOWFRAME,
205 wxSYS_COLOUR_MENUTEXT,
206 wxSYS_COLOUR_WINDOWTEXT,
207 wxSYS_COLOUR_CAPTIONTEXT,
208 wxSYS_COLOUR_ACTIVEBORDER,
209 wxSYS_COLOUR_INACTIVEBORDER,
210 wxSYS_COLOUR_APPWORKSPACE,
211 wxSYS_COLOUR_HIGHLIGHT,
212 wxSYS_COLOUR_HIGHLIGHTTEXT,
213 wxSYS_COLOUR_BTNFACE,
214 wxSYS_COLOUR_3DFACE = wxSYS_COLOUR_BTNFACE,
215 wxSYS_COLOUR_BTNSHADOW,
216 wxSYS_COLOUR_3DSHADOW = wxSYS_COLOUR_BTNSHADOW,
217 wxSYS_COLOUR_GRAYTEXT,
218 wxSYS_COLOUR_BTNTEXT,
219 wxSYS_COLOUR_INACTIVECAPTIONTEXT,
220 wxSYS_COLOUR_BTNHIGHLIGHT,
221 wxSYS_COLOUR_BTNHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
222 wxSYS_COLOUR_3DHIGHLIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
223 wxSYS_COLOUR_3DHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
224 wxSYS_COLOUR_3DDKSHADOW,
225 wxSYS_COLOUR_3DLIGHT,
226 wxSYS_COLOUR_INFOTEXT,
227 wxSYS_COLOUR_INFOBK,
228 wxSYS_COLOUR_LISTBOX,
229 wxSYS_COLOUR_HOTLIGHT,
230 wxSYS_COLOUR_GRADIENTACTIVECAPTION,
231 wxSYS_COLOUR_GRADIENTINACTIVECAPTION,
232 wxSYS_COLOUR_MENUHILIGHT,
233 wxSYS_COLOUR_MENUBAR,
234
235 wxSYS_COLOUR_MAX
236 };
237
238 // possible values for wxSystemSettings::GetMetric() parameter
239 //
240 enum wxSystemMetric
241 {
242 wxSYS_MOUSE_BUTTONS = 1,
243 wxSYS_BORDER_X,
244 wxSYS_BORDER_Y,
245 wxSYS_CURSOR_X,
246 wxSYS_CURSOR_Y,
247 wxSYS_DCLICK_X,
248 wxSYS_DCLICK_Y,
249 wxSYS_DRAG_X,
250 wxSYS_DRAG_Y,
251 wxSYS_EDGE_X,
252 wxSYS_EDGE_Y,
253 wxSYS_HSCROLL_ARROW_X,
254 wxSYS_HSCROLL_ARROW_Y,
255 wxSYS_HTHUMB_X,
256 wxSYS_ICON_X,
257 wxSYS_ICON_Y,
258 wxSYS_ICONSPACING_X,
259 wxSYS_ICONSPACING_Y,
260 wxSYS_WINDOWMIN_X,
261 wxSYS_WINDOWMIN_Y,
262 wxSYS_SCREEN_X,
263 wxSYS_SCREEN_Y,
264 wxSYS_FRAMESIZE_X,
265 wxSYS_FRAMESIZE_Y,
266 wxSYS_SMALLICON_X,
267 wxSYS_SMALLICON_Y,
268 wxSYS_HSCROLL_Y,
269 wxSYS_VSCROLL_X,
270 wxSYS_VSCROLL_ARROW_X,
271 wxSYS_VSCROLL_ARROW_Y,
272 wxSYS_VTHUMB_Y,
273 wxSYS_CAPTION_Y,
274 wxSYS_MENU_Y,
275 wxSYS_NETWORK_PRESENT,
276 wxSYS_PENWINDOWS_PRESENT,
277 wxSYS_SHOW_SOUNDS,
278 wxSYS_SWAP_BUTTONS
279 };
280
281 // possible values for wxSystemSettings::HasFeature() parameter
282 enum wxSystemFeature
283 {
284 wxSYS_CAN_DRAW_FRAME_DECORATIONS = 1,
285 wxSYS_CAN_ICONIZE_FRAME
286 };
287
288
289
290 class wxSystemSettings {
291 public:
292 // get a standard system colour
293 static wxColour GetColour(wxSystemColour index);
294
295 // get a standard system font
296 static wxFont GetFont(wxSystemFont index);
297
298 // get a system-dependent metric
299 static int GetMetric(wxSystemMetric index);
300
301 // return true if the port has certain feature
302 static bool HasFeature(wxSystemFeature index);
303
304 };
305
306
307
308 //---------------------------------------------------------------------------
309 // wxToolTip
310
311 class wxToolTip : public wxObject {
312 public:
313 wxToolTip(const wxString &tip);
314
315 void SetTip(const wxString& tip);
316 wxString GetTip();
317 // *** Not in the "public" interface void SetWindow(wxWindow *win);
318 wxWindow *GetWindow();
319
320 static void Enable(bool flag);
321 static void SetDelay(long milliseconds);
322 };
323
324 //----------------------------------------------------------------------
325
326 class wxCaret {
327 public:
328 wxCaret(wxWindow* window, const wxSize& size);
329 ~wxCaret();
330
331 bool IsOk();
332 bool IsVisible();
333 %name(GetPositionTuple)void GetPosition(int *OUTPUT, int *OUTPUT);
334 wxPoint GetPosition();
335 %name(GetSizeTuple)void GetSize(int *OUTPUT, int *OUTPUT);
336 wxSize GetSize();
337 wxWindow *GetWindow();
338 %name(MoveXY)void Move(int x, int y);
339 void Move(const wxPoint& pt);
340 %name(SetSizeWH) void SetSize(int width, int height);
341 void SetSize(const wxSize& size);
342 void Show(int show = TRUE);
343 void Hide();
344 };
345
346 %inline %{
347 int wxCaret_GetBlinkTime() {
348 return wxCaret::GetBlinkTime();
349 }
350
351 void wxCaret_SetBlinkTime(int milliseconds) {
352 wxCaret::SetBlinkTime(milliseconds);
353 }
354 %}
355
356 //----------------------------------------------------------------------
357
358 %{
359 class wxPyFontEnumerator : public wxFontEnumerator {
360 public:
361 wxPyFontEnumerator() {}
362 ~wxPyFontEnumerator() {}
363
364 DEC_PYCALLBACK_BOOL_STRING(OnFacename);
365 DEC_PYCALLBACK_BOOL_STRINGSTRING(OnFontEncoding);
366
367 PYPRIVATE;
368 };
369
370 IMP_PYCALLBACK_BOOL_STRING(wxPyFontEnumerator, wxFontEnumerator, OnFacename);
371 IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEncoding);
372
373 %}
374
375 %name(wxFontEnumerator) class wxPyFontEnumerator {
376 public:
377 wxPyFontEnumerator();
378 ~wxPyFontEnumerator();
379 void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref);
380 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFontEnumerator, 0)"
381
382 bool EnumerateFacenames(
383 wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
384 bool fixedWidthOnly = FALSE);
385 bool EnumerateEncodings(const char* facename = "");
386
387 //wxArrayString* GetEncodings();
388 //wxArrayString* GetFacenames();
389 %addmethods {
390 PyObject* GetEncodings() {
391 wxArrayString* arr = self->GetEncodings();
392 return wxArrayString2PyList_helper(*arr);
393 }
394
395 PyObject* GetFacenames() {
396 wxArrayString* arr = self->GetFacenames();
397 return wxArrayString2PyList_helper(*arr);
398 }
399 }
400 };
401
402 //----------------------------------------------------------------------
403
404 class wxBusyCursor {
405 public:
406 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR);
407 ~wxBusyCursor();
408 };
409
410 //----------------------------------------------------------------------
411
412 class wxWindowDisabler {
413 public:
414 wxWindowDisabler(wxWindow *winToSkip = NULL);
415 ~wxWindowDisabler();
416 };
417
418 //----------------------------------------------------------------------
419
420 bool wxSafeYield(wxWindow* win=NULL);
421 void wxPostEvent(wxEvtHandler *dest, wxEvent& event);
422 void wxWakeUpIdle();
423
424
425 #ifdef __WXMSW__
426 void wxWakeUpMainThread();
427 #endif
428
429 void wxMutexGuiEnter();
430 void wxMutexGuiLeave();
431
432
433 class wxMutexGuiLocker {
434 public:
435 wxMutexGuiLocker();
436 ~wxMutexGuiLocker();
437 };
438
439
440 %inline %{
441 bool wxThread_IsMain() {
442 #ifdef WXP_WITH_THREAD
443 return wxThread::IsMain();
444 #else
445 return TRUE;
446 #endif
447 }
448 %}
449
450 //----------------------------------------------------------------------
451
452
453 class wxTipProvider
454 {
455 public:
456 // wxTipProvider(size_t currentTip); **** Abstract base class
457 ~wxTipProvider();
458
459 virtual wxString GetTip() = 0;
460 size_t GetCurrentTip();
461
462 };
463
464
465 // The C++ version of wxPyTipProvider
466 %{
467 class wxPyTipProvider : public wxTipProvider {
468 public:
469 wxPyTipProvider(size_t currentTip)
470 : wxTipProvider(currentTip) {}
471
472 DEC_PYCALLBACK_STRING__pure(GetTip);
473
474 PYPRIVATE;
475 };
476
477 IMP_PYCALLBACK_STRING__pure( wxPyTipProvider, wxTipProvider, GetTip);
478
479 %}
480
481
482 // Now let SWIG know about it
483 class wxPyTipProvider : public wxTipProvider {
484 public:
485 wxPyTipProvider(size_t currentTip);
486 };
487
488
489
490 bool wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup = TRUE);
491 %new wxTipProvider * wxCreateFileTipProvider(const wxString& filename, size_t currentTip);
492
493
494 //----------------------------------------------------------------------
495
496 %{
497 #include <wx/generic/dragimgg.h>
498 %}
499
500 %name (wxDragImage) class wxGenericDragImage : public wxObject
501 {
502 public:
503
504 wxGenericDragImage(const wxBitmap& image,
505 const wxCursor& cursor = wxNullCursor);
506 %name(wxDragIcon)wxGenericDragImage(const wxIcon& image,
507 const wxCursor& cursor = wxNullCursor);
508 %name(wxDragString)wxGenericDragImage(const wxString& str,
509 const wxCursor& cursor = wxNullCursor);
510 %name(wxDragTreeItem)wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
511 %name(wxDragListItem)wxGenericDragImage(const wxListCtrl& listCtrl, long id);
512
513 ~wxGenericDragImage();
514
515 void SetBackingBitmap(wxBitmap* bitmap);
516 bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
517 bool fullScreen = FALSE, wxRect* rect = NULL);
518
519 %name(BeginDrag2) bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
520 wxWindow* fullScreenRect);
521
522 bool EndDrag();
523 bool Move(const wxPoint& pt);
524 bool Show();
525 bool Hide();
526
527 wxRect GetImageRect(const wxPoint& pos) const;
528 bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos,
529 bool eraseOld, bool drawNew);
530 };
531
532
533 //----------------------------------------------------------------------
534
535 class wxPyTimer : public wxObject {
536 public:
537 wxPyTimer(PyObject* notify);
538 ~wxPyTimer();
539 int GetInterval();
540 bool IsOneShot();
541 bool IsRunning();
542 void SetOwner(wxEvtHandler *owner, int id = -1);
543 void Start(int milliseconds=-1, int oneShot=FALSE);
544 void Stop();
545 };
546
547
548 class wxStopWatch
549 {
550 public:
551 // ctor starts the stop watch
552 wxStopWatch();
553 ~wxStopWatch();
554 void Start(long t = 0);
555 void Pause();
556 void Resume();
557
558 // get elapsed time since the last Start() or Pause() in milliseconds
559 long Time() const;
560 };
561
562
563 //----------------------------------------------------------------------
564 //----------------------------------------------------------------------
565
566
567 enum
568 {
569 wxLOG_FatalError, // program can't continue, abort immediately
570 wxLOG_Error, // a serious error, user must be informed about it
571 wxLOG_Warning, // user is normally informed about it but may be ignored
572 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
573 wxLOG_Info, // informational message (a.k.a. 'Verbose')
574 wxLOG_Status, // informational: might go to the status line of GUI app
575 wxLOG_Debug, // never shown to the user, disabled in release mode
576 wxLOG_Trace, // trace messages are also only enabled in debug mode
577 wxLOG_Progress, // used for progress indicator (not yet)
578 wxLOG_User = 100 // user defined levels start here
579 };
580
581
582 class wxLog
583 {
584 public:
585 wxLog();
586
587 static bool IsEnabled();
588 static bool EnableLogging(bool doIt = TRUE);
589 static void OnLog(wxLogLevel level, const wxString& szString, int t=0);
590
591 virtual void Flush();
592 bool HasPendingMessages() const;
593
594 static void FlushActive();
595 static wxLog *GetActiveTarget();
596 static wxLog *SetActiveTarget(wxLog *pLogger);
597
598 static void Suspend();
599 static void Resume();
600
601 void SetVerbose(bool bVerbose = TRUE);
602
603 static void DontCreateOnDemand();
604 static void SetTraceMask(wxTraceMask ulMask);
605 static void AddTraceMask(const wxString& str);
606 static void RemoveTraceMask(const wxString& str);
607 static void ClearTraceMasks();
608
609 static void SetTimestamp(const wxChar *ts);
610 static const wxChar *GetTimestamp();
611
612 bool GetVerbose() const { return m_bVerbose; }
613
614 static wxTraceMask GetTraceMask();
615 static bool IsAllowedTraceMask(const wxString& mask);
616
617 // static void TimeStamp(wxString *str);
618 %addmethods {
619 wxString TimeStamp() {
620 wxString msg;
621 wxLog::TimeStamp(&msg);
622 return msg;
623 }
624 }
625 };
626
627
628 class wxLogStderr : public wxLog
629 {
630 public:
631 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
632 };
633
634
635 class wxLogTextCtrl : public wxLog
636 {
637 public:
638 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
639 };
640
641
642 class wxLogGui : public wxLog
643 {
644 public:
645 wxLogGui();
646 };
647
648 class wxLogWindow : public wxLog
649 {
650 public:
651 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
652 const wxString& szTitle, // the title of the frame
653 bool bShow = TRUE, // show window immediately?
654 bool bPassToOld = TRUE); // pass log messages to the old target?
655
656 void Show(bool bShow = TRUE);
657 wxFrame *GetFrame() const;
658 wxLog *GetOldLog() const;
659 bool IsPassingMessages() const;
660 void PassMessages(bool bDoPass);
661 };
662
663
664 class wxLogNull
665 {
666 public:
667 wxLogNull();
668 ~wxLogNull();
669 };
670
671
672 class wxLogChain : public wxLog
673 {
674 public:
675 wxLogChain(wxLog *logger);
676 void SetLog(wxLog *logger);
677 void PassMessages(bool bDoPass);
678 bool IsPassingMessages();
679 wxLog *GetOldLog();
680 };
681
682
683 unsigned long wxSysErrorCode();
684 const wxString wxSysErrorMsg(unsigned long nErrCode = 0);
685 void wxLogFatalError(const wxString& szFormat);
686 void wxLogError(const wxString& szFormat);
687 void wxLogWarning(const wxString& szFormat);
688 void wxLogMessage(const wxString& szFormat);
689 void wxLogInfo(const wxString& szFormat);
690 void wxLogVerbose(const wxString& szFormat);
691 void wxLogStatus(const wxString& szFormat);
692 %name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const wxString& szFormat);
693 void wxLogSysError(const wxString& szFormat);
694
695
696 %{
697 // A Log class that can be derived from in wxPython
698 class wxPyLog : public wxLog {
699 public:
700 wxPyLog() : wxLog() {}
701
702 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
703 bool found;
704 wxPyBeginBlockThreads();
705 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog")))
706 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level,
707 wx2PyString(szString), t));
708 wxPyEndBlockThreads();
709 if (! found)
710 wxLog::DoLog(level, szString, t);
711 }
712
713 virtual void DoLogString(const wxChar *szString, time_t t) {
714 bool found;
715 wxPyBeginBlockThreads();
716 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString")))
717 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)",
718 wx2PyString(szString), t));
719 wxPyEndBlockThreads();
720 if (! found)
721 wxLog::DoLogString(szString, t);
722 }
723
724 PYPRIVATE;
725 };
726 %}
727
728 // Now tell SWIG about it
729 class wxPyLog : public wxLog {
730 public:
731 wxPyLog();
732 void _setCallbackInfo(PyObject* self, PyObject* _class);
733 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyLog)"
734 %addmethods { void Destroy() { delete self; } }
735
736 };
737
738
739 //----------------------------------------------------------------------
740
741
742 enum {
743 /* event type */
744 wxEVT_END_PROCESS
745 };
746
747
748 class wxProcessEvent : public wxEvent {
749 public:
750 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
751 int GetPid();
752 int GetExitCode();
753 int m_pid, m_exitcode;
754 };
755
756
757
758
759 %{ // C++ version of wxProcess derived class
760
761 class wxPyProcess : public wxProcess {
762 public:
763 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1)
764 : wxProcess(parent, id)
765 {}
766
767 DEC_PYCALLBACK_VOID_INTINT(OnTerminate);
768
769 PYPRIVATE;
770 };
771
772 IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
773
774 %}
775
776
777 %name(wxProcess)class wxPyProcess : public wxEvtHandler {
778 public:
779 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
780 %addmethods { void Destroy() { delete self; } }
781
782 void _setCallbackInfo(PyObject* self, PyObject* _class);
783 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxProcess)"
784
785 void base_OnTerminate(int pid, int status);
786
787 void Redirect();
788 bool IsRedirected();
789 void Detach();
790
791 wxInputStream *GetInputStream();
792 wxInputStream *GetErrorStream();
793 wxOutputStream *GetOutputStream();
794
795 void CloseOutput();
796 };
797
798
799
800 long wxExecute(const wxString& command,
801 int sync = FALSE,
802 wxPyProcess *process = NULL);
803
804 //----------------------------------------------------------------------
805
806 %{
807 #if !wxUSE_JOYSTICK && !defined(__WXMSW__)
808 // A C++ stub class for wxJoystick for platforms that don't have it.
809 class wxJoystick : public wxObject {
810 public:
811 wxJoystick(int joystick = wxJOYSTICK1) {
812 wxPyBeginBlockThreads();
813 PyErr_SetString(PyExc_NotImplementedError, "wxJoystick is not available on this platform.");
814 wxPyEndBlockThreads();
815 }
816 wxPoint GetPosition() { return wxPoint(-1,-1); }
817 int GetZPosition() { return -1; }
818 int GetButtonState() { return -1; }
819 int GetPOVPosition() { return -1; }
820 int GetPOVCTSPosition() { return -1; }
821 int GetRudderPosition() { return -1; }
822 int GetUPosition() { return -1; }
823 int GetVPosition() { return -1; }
824 int GetMovementThreshold() { return -1; }
825 void SetMovementThreshold(int threshold) {}
826
827 bool IsOk(void) { return FALSE; }
828 int GetNumberJoysticks() { return -1; }
829 int GetManufacturerId() { return -1; }
830 int GetProductId() { return -1; }
831 wxString GetProductName() { return ""; }
832 int GetXMin() { return -1; }
833 int GetYMin() { return -1; }
834 int GetZMin() { return -1; }
835 int GetXMax() { return -1; }
836 int GetYMax() { return -1; }
837 int GetZMax() { return -1; }
838 int GetNumberButtons() { return -1; }
839 int GetNumberAxes() { return -1; }
840 int GetMaxButtons() { return -1; }
841 int GetMaxAxes() { return -1; }
842 int GetPollingMin() { return -1; }
843 int GetPollingMax() { return -1; }
844 int GetRudderMin() { return -1; }
845 int GetRudderMax() { return -1; }
846 int GetUMin() { return -1; }
847 int GetUMax() { return -1; }
848 int GetVMin() { return -1; }
849 int GetVMax() { return -1; }
850
851 bool HasRudder() { return FALSE; }
852 bool HasZ() { return FALSE; }
853 bool HasU() { return FALSE; }
854 bool HasV() { return FALSE; }
855 bool HasPOV() { return FALSE; }
856 bool HasPOV4Dir() { return FALSE; }
857 bool HasPOVCTS() { return FALSE; }
858
859 bool SetCapture(wxWindow* win, int pollingFreq = 0) { return FALSE; }
860 bool ReleaseCapture() { return FALSE; }
861 };
862 #endif
863 %}
864
865
866 class wxJoystick : public wxObject {
867 public:
868 wxJoystick(int joystick = wxJOYSTICK1);
869 ~wxJoystick();
870
871 wxPoint GetPosition();
872 int GetZPosition();
873 int GetButtonState();
874 int GetPOVPosition();
875 int GetPOVCTSPosition();
876 int GetRudderPosition();
877 int GetUPosition();
878 int GetVPosition();
879 int GetMovementThreshold();
880 void SetMovementThreshold(int threshold) ;
881
882 bool IsOk(void);
883 int GetNumberJoysticks();
884 int GetManufacturerId();
885 int GetProductId();
886 wxString GetProductName();
887 int GetXMin();
888 int GetYMin();
889 int GetZMin();
890 int GetXMax();
891 int GetYMax();
892 int GetZMax();
893 int GetNumberButtons();
894 int GetNumberAxes();
895 int GetMaxButtons();
896 int GetMaxAxes();
897 int GetPollingMin();
898 int GetPollingMax();
899 int GetRudderMin();
900 int GetRudderMax();
901 int GetUMin();
902 int GetUMax();
903 int GetVMin();
904 int GetVMax();
905
906 bool HasRudder();
907 bool HasZ();
908 bool HasU();
909 bool HasV();
910 bool HasPOV();
911 bool HasPOV4Dir();
912 bool HasPOVCTS();
913
914 bool SetCapture(wxWindow* win, int pollingFreq = 0);
915 bool ReleaseCapture();
916 };
917
918 //----------------------------------------------------------------------
919
920 %{
921 #if !wxUSE_WAVE
922 // A C++ stub class for wxWave for platforms that don't have it.
923 class wxWave : public wxObject
924 {
925 public:
926 wxWave(const wxString& fileName, bool isResource = FALSE) {
927 wxPyBeginBlockThreads();
928 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
929 wxPyEndBlockThreads();
930 }
931 wxWave(int size, const wxByte* data) {
932 wxPyBeginBlockThreads();
933 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
934 wxPyEndBlockThreads();
935 }
936
937 ~wxWave() {}
938
939 bool IsOk() const { return FALSE; }
940 bool Play(bool async = TRUE, bool looped = FALSE) const { return FALSE; }
941 };
942
943 #endif
944 %}
945
946 class wxWave : public wxObject
947 {
948 public:
949 wxWave(const wxString& fileName, bool isResource = FALSE);
950 ~wxWave();
951
952 bool IsOk() const;
953 bool Play(bool async = TRUE, bool looped = FALSE) const;
954 };
955
956 %new wxWave* wxWaveData(const wxString& data);
957 %{ // Implementations of some alternate "constructors"
958 wxWave* wxWaveData(const wxString& data) {
959 return new wxWave(data.Len(), (wxByte*)data.c_str());
960 }
961 %}
962
963
964 //----------------------------------------------------------------------
965
966 enum wxMailcapStyle
967 {
968 wxMAILCAP_STANDARD = 1,
969 wxMAILCAP_NETSCAPE = 2,
970 wxMAILCAP_KDE = 4,
971 wxMAILCAP_GNOME = 8,
972
973 wxMAILCAP_ALL = 15
974 };
975
976
977
978 class wxFileTypeInfo
979 {
980 public:
981 // ctors
982 // a normal item
983 wxFileTypeInfo(const char *mimeType,
984 const char *openCmd,
985 const char *printCmd,
986 const char *desc);
987
988
989 // the array elements correspond to the parameters of the ctor above in
990 // the same order
991 %name(wxFileTypeInfoSequence)wxFileTypeInfo(const wxArrayString& sArray);
992
993 // invalid item - use this to terminate the array passed to
994 // wxMimeTypesManager::AddFallbacks
995 %name(wxNullFileTypeInfo)wxFileTypeInfo();
996
997
998 // test if this object can be used
999 bool IsValid() const;
1000
1001 // setters
1002 // set the icon info
1003 void SetIcon(const wxString& iconFile, int iconIndex = 0);
1004
1005 // set the short desc
1006 void SetShortDesc(const wxString& shortDesc);
1007
1008 // accessors
1009 // get the MIME type
1010 const wxString& GetMimeType() const;
1011 // get the open command
1012 const wxString& GetOpenCommand() const;
1013 // get the print command
1014 const wxString& GetPrintCommand() const;
1015 // get the short description (only used under Win32 so far)
1016 const wxString& GetShortDesc() const;
1017 // get the long, user visible description
1018 const wxString& GetDescription() const;
1019
1020
1021 // get the array of all extensions
1022 //const wxArrayString& GetExtensions() const;
1023 %addmethods {
1024 PyObject* GetExtensions() {
1025 wxArrayString& arr = (wxArrayString&)self->GetExtensions();
1026 return wxArrayString2PyList_helper(arr);
1027 }
1028 }
1029
1030 int GetExtensionsCount() const;
1031
1032 // get the icon info
1033 const wxString& GetIconFile() const;
1034 int GetIconIndex() const;
1035 };
1036
1037
1038
1039
1040 class wxFileType
1041 {
1042 public:
1043
1044 // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
1045
1046 // An object of this class must be passed to Get{Open|Print}Command. The
1047 // default implementation is trivial and doesn't know anything at all about
1048 // parameters, only filename and MIME type are used (so it's probably ok for
1049 // Windows where %{param} is not used anyhow)
1050 class MessageParameters
1051 {
1052 public:
1053 // ctors
1054 MessageParameters(const wxString& filename=wxEmptyString,
1055 const wxString& mimetype=wxEmptyString);
1056
1057 // accessors (called by GetOpenCommand)
1058 // filename
1059 const wxString& GetFileName() const;
1060 // mime type
1061 const wxString& GetMimeType() const;;
1062
1063 // override this function in derived class
1064 virtual wxString GetParamValue(const wxString& name) const;
1065
1066 // virtual dtor as in any base class
1067 virtual ~MessageParameters();
1068 };
1069
1070
1071 // ctor from static data
1072 wxFileType(const wxFileTypeInfo& ftInfo);
1073
1074 // return the MIME type for this file type
1075 %addmethods {
1076 PyObject* GetMimeType() {
1077 wxString str;
1078 if (self->GetMimeType(&str)) {
1079 #if wxUSE_UNICODE
1080 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1081 #else
1082 return PyString_FromStringAndSize(str.c_str(), str.Len());
1083 #endif
1084 }
1085 else
1086 RETURN_NONE();
1087 }
1088 PyObject* GetMimeTypes() {
1089 wxArrayString arr;
1090 if (self->GetMimeTypes(arr))
1091 return wxArrayString2PyList_helper(arr);
1092 else
1093 RETURN_NONE();
1094 }
1095 }
1096
1097
1098 // Get all extensions associated with this file type
1099 %addmethods {
1100 PyObject* GetExtensions() {
1101 wxArrayString arr;
1102 if (self->GetExtensions(arr))
1103 return wxArrayString2PyList_helper(arr);
1104 else
1105 RETURN_NONE();
1106 }
1107 }
1108
1109
1110 %addmethods {
1111 // Get the icon corresponding to this file type
1112 %new wxIcon* GetIcon() {
1113 wxIcon icon;
1114 if (self->GetIcon(&icon))
1115 return new wxIcon(icon);
1116 else
1117 return NULL;
1118 }
1119
1120 // Get the icon corresponding to this file type, the name of the file
1121 // where this icon resides, and its index in this file if applicable.
1122 PyObject* GetIconInfo() {
1123 wxIcon icon;
1124 wxString iconFile;
1125 int iconIndex;
1126 if (self->GetIcon(&icon, &iconFile, &iconIndex)) {
1127 wxPyBeginBlockThreads();
1128 PyObject* tuple = PyTuple_New(3);
1129 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon),
1130 "wxIcon", TRUE));
1131 #if wxUSE_UNICODE
1132 PyTuple_SetItem(tuple, 1, PyUnicode_FromUnicode(iconFile.c_str(), iconFile.Len()));
1133 #else
1134 PyTuple_SetItem(tuple, 1, PyString_FromStringAndSize(iconFile.c_str(), iconFile.Len()));
1135 #endif
1136 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
1137 wxPyEndBlockThreads();
1138 return tuple;
1139 }
1140 else
1141 RETURN_NONE();
1142 }
1143 }
1144
1145 %addmethods {
1146 // get a brief file type description ("*.txt" => "text document")
1147 PyObject* GetDescription() {
1148 wxString str;
1149 if (self->GetDescription(&str)) {
1150 #if wxUSE_UNICODE
1151 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1152 #else
1153 return PyString_FromStringAndSize(str.c_str(), str.Len());
1154 #endif
1155 } else
1156 RETURN_NONE();
1157 }
1158 }
1159
1160
1161 // get the command to open/execute the file of given type
1162 %addmethods {
1163 PyObject* GetOpenCommand(const wxString& filename,
1164 const wxString& mimetype=wxEmptyString) {
1165 wxString str;
1166 if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
1167 #if wxUSE_UNICODE
1168 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1169 #else
1170 return PyString_FromStringAndSize(str.c_str(), str.Len());
1171 #endif
1172 } else
1173 RETURN_NONE();
1174 }
1175 }
1176
1177
1178 // get the command to print the file of given type
1179 %addmethods {
1180 PyObject* GetPrintCommand(const wxString& filename,
1181 const wxString& mimetype=wxEmptyString) {
1182 wxString str;
1183 if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
1184 #if wxUSE_UNICODE
1185 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1186 #else
1187 return PyString_FromStringAndSize(str.c_str(), str.Len());
1188 #endif
1189 } else
1190 RETURN_NONE();
1191 }
1192 }
1193
1194
1195 // Get all commands defined for this file type
1196 %addmethods {
1197 PyObject* GetAllCommands(const wxString& filename,
1198 const wxString& mimetype=wxEmptyString) {
1199 wxArrayString verbs;
1200 wxArrayString commands;
1201 if (self->GetAllCommands(&verbs, &commands,
1202 wxFileType::MessageParameters(filename, mimetype))) {
1203 wxPyBeginBlockThreads();
1204 PyObject* tuple = PyTuple_New(2);
1205 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
1206 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
1207 wxPyEndBlockThreads();
1208 return tuple;
1209 }
1210 else
1211 RETURN_NONE();
1212 }
1213 }
1214
1215
1216 // set an arbitrary command, ask confirmation if it already exists and
1217 // overwriteprompt is TRUE
1218 bool SetCommand(const wxString& cmd, const wxString& verb,
1219 bool overwriteprompt = TRUE);
1220
1221 bool SetDefaultIcon(const wxString& cmd = wxEmptyString, int index = 0);
1222
1223
1224 // remove the association for this filetype from the system MIME database:
1225 // notice that it will only work if the association is defined in the user
1226 // file/registry part, we will never modify the system-wide settings
1227 bool Unassociate();
1228
1229 // operations
1230 // expand a string in the format of GetOpenCommand (which may contain
1231 // '%s' and '%t' format specificators for the file name and mime type
1232 // and %{param} constructions).
1233 static wxString ExpandCommand(const wxString& command,
1234 const MessageParameters& params);
1235
1236 // dtor (not virtual, shouldn't be derived from)
1237 ~wxFileType();
1238
1239 };
1240
1241
1242
1243
1244 class wxMimeTypesManager
1245 {
1246 public:
1247 // static helper functions
1248 // -----------------------
1249
1250 // check if the given MIME type is the same as the other one: the
1251 // second argument may contain wildcards ('*'), but not the first. If
1252 // the types are equal or if the mimeType matches wildcard the function
1253 // returns TRUE, otherwise it returns FALSE
1254 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
1255
1256 // ctor
1257 wxMimeTypesManager();
1258
1259 // loads data from standard files according to the mailcap styles
1260 // specified: this is a bitwise OR of wxMailcapStyle values
1261 //
1262 // use the extraDir parameter if you want to look for files in another
1263 // directory
1264 void Initialize(int mailcapStyle = wxMAILCAP_STANDARD,
1265 const wxString& extraDir = wxEmptyString);
1266
1267 // and this function clears all the data from the manager
1268 void ClearData();
1269
1270 // Database lookup: all functions return a pointer to wxFileType object
1271 // whose methods may be used to query it for the information you're
1272 // interested in. If the return value is !NULL, caller is responsible for
1273 // deleting it.
1274 // get file type from file extension
1275 %new wxFileType *GetFileTypeFromExtension(const wxString& ext);
1276
1277 // get file type from MIME type (in format <category>/<format>)
1278 %new wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
1279
1280 // other operations: return TRUE if there were no errors or FALSE if there
1281 // were some unreckognized entries (the good entries are always read anyhow)
1282 //
1283
1284 // read in additional file (the standard ones are read automatically)
1285 // in mailcap format (see mimetype.cpp for description)
1286 //
1287 // 'fallback' parameter may be set to TRUE to avoid overriding the
1288 // settings from other, previously parsed, files by this one: normally,
1289 // the files read most recently would override the older files, but with
1290 // fallback == TRUE this won't happen
1291 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
1292
1293 // read in additional file in mime.types format
1294 bool ReadMimeTypes(const wxString& filename);
1295
1296 // enumerate all known MIME types
1297 %addmethods {
1298 PyObject* EnumAllFileTypes() {
1299 wxArrayString arr;
1300 self->EnumAllFileTypes(arr);
1301 return wxArrayString2PyList_helper(arr);
1302 }
1303 }
1304
1305 // these functions can be used to provide default values for some of the
1306 // MIME types inside the program itself (you may also use
1307 // ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
1308 // achieve the same goal, but this requires having this info in a file).
1309 //
1310 void AddFallback(const wxFileTypeInfo& ft);
1311
1312
1313 // create or remove associations
1314
1315 // create a new association using the fields of wxFileTypeInfo (at least
1316 // the MIME type and the extension should be set)
1317 // if the other fields are empty, the existing values should be left alone
1318 %new wxFileType *Associate(const wxFileTypeInfo& ftInfo);
1319
1320 // undo Associate()
1321 bool Unassociate(wxFileType *ft) ;
1322
1323 // dtor (not virtual, shouldn't be derived from)
1324 ~wxMimeTypesManager();
1325 };
1326
1327
1328 %readonly
1329 %{
1330 #if 0
1331 %}
1332 extern wxMimeTypesManager* wxTheMimeTypesManager;
1333 %{
1334 #endif
1335 %}
1336 %readwrite
1337
1338 //----------------------------------------------------------------------
1339
1340 %{
1341 #include <wx/docview.h>
1342 %}
1343
1344 class wxFileHistory : public wxObject
1345 {
1346 public:
1347 wxFileHistory(int maxFiles = 9);
1348 ~wxFileHistory();
1349
1350 // Operations
1351 void AddFileToHistory(const wxString& file);
1352 void RemoveFileFromHistory(int i);
1353 int GetMaxFiles() const;
1354 void UseMenu(wxMenu *menu);
1355
1356 // Remove menu from the list (MDI child may be closing)
1357 void RemoveMenu(wxMenu *menu);
1358
1359 void Load(wxConfigBase& config);
1360 void Save(wxConfigBase& config);
1361
1362 void AddFilesToMenu();
1363 %name(AddFilesToSingleMenu)void AddFilesToMenu(wxMenu* menu);
1364
1365 // Accessors
1366 wxString GetHistoryFile(int i) const;
1367
1368 // A synonym for GetNoHistoryFiles
1369 int GetCount() const;
1370 int GetNoHistoryFiles() const;
1371
1372 };
1373
1374 //----------------------------------------------------------------------
1375 //----------------------------------------------------------------------
1376
1377
1378 %init %{
1379 wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator");
1380 wxPyPtrTypeMap_Add("wxDragImage", "wxGenericDragImage");
1381 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
1382 %}
1383
1384 //----------------------------------------------------------------------
1385