File: splitter.h

package info (click to toggle)
wxwidgets3.0 3.0.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 120,464 kB
  • sloc: cpp: 896,633; makefile: 52,303; ansic: 21,971; sh: 5,713; python: 2,940; xml: 1,534; perl: 264; javascript: 33
file content (567 lines) | stat: -rw-r--r-- 19,424 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
/////////////////////////////////////////////////////////////////////////////
// Name:        splitter.h
// Purpose:     interface of wxSplitterWindow
// Author:      wxWidgets team
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////


#define wxSP_NOBORDER         0x0000
#define wxSP_THIN_SASH        0x0000    // NB: the default is 3D sash
#define wxSP_NOSASH           0x0010
#define wxSP_PERMIT_UNSPLIT   0x0040
#define wxSP_LIVE_UPDATE      0x0080
#define wxSP_3DSASH           0x0100
#define wxSP_3DBORDER         0x0200
#define wxSP_NO_XP_THEME      0x0400
#define wxSP_BORDER           wxSP_3DBORDER
#define wxSP_3D               (wxSP_3DBORDER | wxSP_3DSASH)


enum wxSplitMode
{
    wxSPLIT_HORIZONTAL = 1,
    wxSPLIT_VERTICAL
};

enum
{
    wxSPLIT_DRAG_NONE,
    wxSPLIT_DRAG_DRAGGING,
    wxSPLIT_DRAG_LEFT_DOWN
};

/**
    @class wxSplitterWindow

    This class manages up to two subwindows. The current view can be split
    into two programmatically (perhaps from a menu command), and unsplit
    either programmatically or via the wxSplitterWindow user interface.

    @beginStyleTable
    @style{wxSP_3D}
           Draws a 3D effect border and sash.
    @style{wxSP_THIN_SASH}
           Draws a thin sash.
    @style{wxSP_3DSASH}
           Draws a 3D effect sash (part of default style).
    @style{wxSP_3DBORDER}
           Synonym for wxSP_BORDER.
    @style{wxSP_BORDER}
           Draws a standard border.
    @style{wxSP_NOBORDER}
           No border (default).
    @style{wxSP_NO_XP_THEME}
           Under Windows XP, switches off the attempt to draw the splitter
           using Windows XP theming, so the borders and sash will take on the
           pre-XP look.
    @style{wxSP_PERMIT_UNSPLIT}
           Always allow to unsplit, even with the minimum pane size other than zero.
    @style{wxSP_LIVE_UPDATE}
           Don't draw XOR line but resize the child windows immediately.
    @endStyleTable


    @beginEventEmissionTable{wxSplitterEvent}
    @event{EVT_SPLITTER_SASH_POS_CHANGING(id, func)}
        The sash position is in the process of being changed.
        May be used to modify the position of the tracking bar to properly
        reflect the position that would be set if the drag were to be completed
        at this point. Processes a @c wxEVT_SPLITTER_SASH_POS_CHANGING event.
    @event{EVT_SPLITTER_SASH_POS_CHANGED(id, func)}
        The sash position was changed. May be used to modify the sash position
        before it is set, or to prevent the change from taking place.
        Processes a @c wxEVT_SPLITTER_SASH_POS_CHANGED event.
    @event{EVT_SPLITTER_UNSPLIT(id, func)}
        The splitter has been just unsplit. Processes a @c wxEVT_SPLITTER_UNSPLIT event.
    @event{EVT_SPLITTER_DCLICK(id, func)}
        The sash was double clicked. The default behaviour is to unsplit the
        window when this happens (unless the minimum pane size has been set
        to a value greater than zero). Processes a @c wxEVT_SPLITTER_DOUBLECLICKED event.
    @endEventTable


    @library{wxcore}
    @category{miscwnd}

    @see wxSplitterEvent, @ref overview_splitterwindow
*/
class wxSplitterWindow : public wxWindow
{
public:
    /**
      Default constructor
    */
    wxSplitterWindow();

    /**
        Constructor for creating the window.

        @param parent
            The parent of the splitter window.
        @param id
            The window identifier.
        @param pos
            The window position.
        @param size
            The window size.
        @param style
            The window style. See wxSplitterWindow.
        @param name
            The window name.

        @remarks
            After using this constructor, you must create either one or two
            subwindows with the splitter window as parent, and then call one
            of Initialize(), SplitVertically() and SplitHorizontally() in order
            to set the pane(s).
            You can create two windows, with one hidden when not being shown;
            or you can create and delete the second pane on demand.

        @see Initialize(), SplitVertically(), SplitHorizontally(), Create()
    */
    wxSplitterWindow(wxWindow* parent, wxWindowID id = wxID_ANY,
                     const wxPoint& pos = wxDefaultPosition,
                     const wxSize& size = wxDefaultSize,
                     long style = wxSP_3D,
                     const wxString& name = "splitterWindow");

    /**
        Destroys the wxSplitterWindow and its children.
    */
    virtual ~wxSplitterWindow();

    /**
        Creation function, for two-step construction.
        See wxSplitterWindow() for details.
    */
    bool Create(wxWindow* parent, wxWindowID id = wxID_ANY,
                const wxPoint& point = wxDefaultPosition,
                const wxSize& size = wxDefaultSize, long style = wxSP_3D,
                const wxString& name = "splitter");

    /**
        Returns the current minimum pane size (defaults to zero).

        @see SetMinimumPaneSize()
    */
    int GetMinimumPaneSize() const;

    /**
        Returns the current sash gravity.

        @see SetSashGravity()
    */
    double GetSashGravity() const;

    /**
        Returns the current sash position.

        @see SetSashPosition()
    */
    int GetSashPosition() const;

    /**
        Returns the default sash size in pixels or 0 if it is invisible.

        @see GetDefaultSashSize(), IsSashInvisible(), SetSashSize()
     */
    int GetSashSize() const;

    /**
        Returns the default sash size in pixels.

        The size of the sash is its width for a vertically split window and its
        height for a horizontally split one. Its other direction is the same as
        the client size of the window in the corresponding direction.

        The default sash size is platform-dependent because it conforms to the
        current platform look-and-feel and cannot be changed.

        @since 2.9.4
     */
    int GetDefaultSashSize() const;

    /**
        Gets the split mode.

        @see SetSplitMode(), SplitVertically(), SplitHorizontally().
    */
    wxSplitMode GetSplitMode() const;

    /**
        Returns the left/top or only pane.
    */
    wxWindow* GetWindow1() const;

    /**
        Returns the right/bottom pane.
    */
    wxWindow* GetWindow2() const;

    /**
        Initializes the splitter window to have one pane.
        The child window is shown if it is currently hidden.

        @param window
            The pane for the unsplit window.

        @remarks This should be called if you wish to initially view only a
                 single pane in the splitter window.

        @see SplitVertically(), SplitHorizontally()
    */
    void Initialize(wxWindow* window);

    /**
        Returns @true if the sash is invisible even when the window is split, @false otherwise.

        @remark This is a shortcut for HasFlag(wxSP_NOSASH)

        @see SetSashInvisible()

        @since 2.9.4
    */
    bool IsSashInvisible() const;

    /**
        Returns @true if the window is split, @false otherwise.
    */
    bool IsSplit() const;

    /**
        Application-overridable function called when the sash is double-clicked with
        the left mouse button.

        @param x
            The x position of the mouse cursor.
        @param y
            The y position of the mouse cursor.

        @remarks The default implementation of this function calls Unsplit if the
                 minimum pane size is zero.

        @see Unsplit()
    */
    virtual void OnDoubleClickSash(int x, int y);

    /**
        Application-overridable function called when the sash position is changed by
        user. It may return @false to prevent the change or @true to allow it.

        @param newSashPosition
            The new sash position (always positive or zero)

        @remarks The default implementation of this function verifies that the
                 sizes of both  panes of the splitter are greater than
                 minimum pane size.
    */
    virtual bool OnSashPositionChange(int newSashPosition);

    /**
        Application-overridable function called when the window is unsplit, either
        programmatically or using the wxSplitterWindow user interface.

        @param removed
            The window being removed.

        @remarks The default implementation of this function simply hides
                 removed. You may wish to delete the window.
    */
    virtual void OnUnsplit(wxWindow* removed);

    /**
        This function replaces one of the windows managed by the wxSplitterWindow with
        another one. It is in general better to use it instead of calling Unsplit()
        and then resplitting the window back because it will provoke much less flicker
        (if any). It is valid to call this function whether the splitter has two
        windows or only one.

        Both parameters should be non-@NULL and @a winOld must specify one of the
        windows managed by the splitter. If the parameters are incorrect or the window
        couldn't be replaced, @false is returned. Otherwise the function will return
        @true, but please notice that it will not delete the replaced window and you
        may wish to do it yourself.

        @see GetMinimumPaneSize()
    */
    bool ReplaceWindow(wxWindow* winOld, wxWindow* winNew);

    /**
        Sets the minimum pane size.

        @param paneSize
            Minimum pane size in pixels.

        @remarks The default minimum pane size is zero, which means that either
                 pane can be reduced to zero by dragging the sash, thus
                 removing one of the panes. To prevent this behaviour
                 (and veto out-of-range sash dragging), set a minimum
                 size, for example 20 pixels. If the wxSP_PERMIT_UNSPLIT
                 style is used when a splitter window is created, the
                 window may be unsplit even if minimum size is non-zero.

        @see GetMinimumPaneSize()
    */
    void SetMinimumPaneSize(int paneSize);

    /**
        Sets the sash gravity.

        @param gravity
            The sash gravity. Value between 0.0 and 1.0.

        @remarks
        Gravity is real factor which controls position of sash while resizing
        wxSplitterWindow. Gravity tells wxSplitterWindow how much will left/top
        window grow while resizing.
        Example values:
        - 0.0: only the bottom/right window is automatically resized
        - 0.5: both windows grow by equal size
        - 1.0: only left/top window grows
        Gravity should be a real value between 0.0 and 1.0.
        Default value of sash gravity is 0.0.
        That value is compatible with previous (before gravity was introduced)
        behaviour of wxSplitterWindow.

        @see GetSashGravity()
    */
    void SetSashGravity(double gravity);

    /**
        Sets the sash position.

        @param position
            The sash position in pixels.
        @param redraw
            If @true, resizes the panes and redraws the sash and border.

        @remarks Does not currently check for an out-of-range value.

        @see GetSashPosition()
    */
    void SetSashPosition(int position, bool redraw = true);

        /**
        Returns the default sash size in pixels or 0 if it is invisible.

        @see GetDefaultSashSize(), GetSashSize(), IsSashInvisible()
     */
    void SetSashSize(int size);

    /**
        Sets the split mode.

        @param mode
            Can be wxSPLIT_VERTICAL or wxSPLIT_HORIZONTAL.

        @remarks Only sets the internal variable; does not update the display.

        @see GetSplitMode(), SplitVertically(), SplitHorizontally().
    */
    void SetSplitMode(int mode);

    /**
        Sets whether the sash should be invisible, even when the window is
        split.

        When the sash is invisible, it doesn't appear on the screen at all and,
        in particular, doesn't allow the user to resize the windows.

        @remarks Only sets the internal variable; does not update the display.

        @param invisible
            If @true, the sash is always invisible, else it is shown when the
            window is split.

        @see IsSashInvisible()

        @since 2.9.4
    */
    void SetSashInvisible(bool invisible=true);

    /**
        Initializes the top and bottom panes of the splitter window.
        The child windows are shown if they are currently hidden.

        @param window1
            The top pane.
        @param window2
            The bottom pane.
        @param sashPosition
            The initial position of the sash. If this value is positive,
            it specifies the size of the upper pane. If it is negative, its
            absolute value gives the size of the lower pane.
            Finally, specify 0 (default) to choose the default position
            (half of the total window height).

        @return @true if successful, @false otherwise (the window was already split).

        @remarks This should be called if you wish to initially view two panes.
                 It can also be called at any subsequent time, but the application
                 should check that the window is not currently split using IsSplit().

        @see SplitVertically(), IsSplit(), Unsplit()
    */
    virtual bool SplitHorizontally(wxWindow* window1, wxWindow* window2,
                                   int sashPosition = 0);

    /**
        Initializes the left and right panes of the splitter window.
        The child windows are shown if they are currently hidden.

        @param window1
            The left pane.
        @param window2
            The right pane.
        @param sashPosition
            The initial position of the sash. If this value is positive, it
            specifies the size of the left pane. If it is negative, it is
            absolute value gives the size of the right pane.
            Finally, specify 0 (default) to choose the default position
            (half of the total window width).

        @return @true if successful, @false otherwise (the window was already split).

        @remarks This should be called if you wish to initially view two panes.
                 It can also be called at any subsequent time, but the
                 application should check that the window is not currently
                 split using IsSplit().

        @see SplitHorizontally(), IsSplit(), Unsplit().
    */
    virtual bool SplitVertically(wxWindow* window1, wxWindow* window2,
                                 int sashPosition = 0);

    /**
        Unsplits the window.

        @param toRemove
            The pane to remove, or @NULL to remove the right or bottom pane.

        @return @true if successful, @false otherwise (the window was not split).

        @remarks This call will not actually delete the pane being removed; it
                 calls OnUnsplit() which can be overridden for the desired
                 behaviour. By default, the pane being removed is hidden.

        @see SplitHorizontally(), SplitVertically(), IsSplit(), OnUnsplit()
    */
    bool Unsplit(wxWindow* toRemove = NULL);

    /**
        Causes any pending sizing of the sash and child panes to take place
        immediately.

        Such resizing normally takes place in idle time, in order to wait for
        layout to be completed. However, this can cause unacceptable flicker as
        the panes are resized after the window has been shown.
        To work around this, you can perform window layout (for example by
        sending a size event to the parent window), and then call this function,
        before showing the top-level window.
    */
    void UpdateSize();
};



/**
    @class wxSplitterEvent

    This class represents the events generated by a splitter control.

    Also there is only one event class, the data associated to the different events
    is not the same and so not all accessor functions may be called for each event.
    The documentation mentions the kind of event(s) for which the given accessor
    function makes sense: calling it for other types of events will result
    in assert failure (in debug mode) and will return meaningless results.

    @beginEventTable{wxSplitterEvent}
    @event{EVT_SPLITTER_SASH_POS_CHANGING(id, func)}
        The sash position is in the process of being changed.
        May be used to modify the position of the tracking bar to properly
        reflect the position that would be set if the drag were to be completed
        at this point. Processes a @c wxEVT_SPLITTER_SASH_POS_CHANGING event.
    @event{EVT_SPLITTER_SASH_POS_CHANGED(id, func)}
        The sash position was changed. May be used to modify the sash position
        before it is set, or to prevent the change from taking place.
        Processes a @c wxEVT_SPLITTER_SASH_POS_CHANGED event.
    @event{EVT_SPLITTER_UNSPLIT(id, func)}
        The splitter has been just unsplit. Processes a @c wxEVT_SPLITTER_UNSPLIT event.
    @event{EVT_SPLITTER_DCLICK(id, func)}
        The sash was double clicked. The default behaviour is to unsplit the
        window when this happens (unless the minimum pane size has been set
        to a value greater than zero). Processes a @c wxEVT_SPLITTER_DOUBLECLICKED event.
    @endEventTable

    @library{wxcore}
    @category{events}

    @see wxSplitterWindow, @ref overview_events
*/
class wxSplitterEvent : public wxNotifyEvent
{
public:
    /**
        Constructor. Used internally by wxWidgets only.
    */
    wxSplitterEvent(wxEventType eventType = wxEVT_NULL,
                    wxSplitterWindow* splitter = NULL);

    /**
        Returns the new sash position.

        May only be called while processing
        @c wxEVT_SPLITTER_SASH_POS_CHANGING and
        @c wxEVT_SPLITTER_SASH_POS_CHANGED events.
    */
    int GetSashPosition() const;

    /**
        Returns a pointer to the window being removed when a splitter window
        is unsplit.

        May only be called while processing
        @c wxEVT_SPLITTER_UNSPLIT events.
    */
    wxWindow* GetWindowBeingRemoved() const;

    /**
        Returns the x coordinate of the double-click point.

        May only be called while processing
        @c wxEVT_SPLITTER_DOUBLECLICKED events.
    */
    int GetX() const;

    /**
        Returns the y coordinate of the double-click point.

        May only be called while processing
        @c wxEVT_SPLITTER_DOUBLECLICKED events.
    */
    int GetY() const;

    /**
        In the case of @c wxEVT_SPLITTER_SASH_POS_CHANGED events,
        sets the new sash position.
        In the case of @c wxEVT_SPLITTER_SASH_POS_CHANGING events,
        sets the new tracking bar position so visual feedback during dragging will
        represent that change that will actually take place. Set to -1 from
        the event handler code to prevent repositioning.

        May only be called while processing
        @c wxEVT_SPLITTER_SASH_POS_CHANGING and
        @c wxEVT_SPLITTER_SASH_POS_CHANGED events.

        @param pos
            New sash position.
    */
    void SetSashPosition(int pos);
};


wxEventType wxEVT_SPLITTER_SASH_POS_CHANGED;
wxEventType wxEVT_SPLITTER_SASH_POS_CHANGING;
wxEventType wxEVT_SPLITTER_DOUBLECLICKED;
wxEventType wxEVT_SPLITTER_UNSPLIT;