00001 /* 00002 File : draggable_b.h 00003 Date : 19-Sep-02 00004 Description : Base class to represent a draggable toolbox gadget. 00005 00006 Copyright © 1995-2002 Alexander Thoukydides 00007 00008 This program is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU General Public License 00010 as published by the Free Software Foundation; either version 2 00011 of the License, or (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 00021 */ 00022 00023 // Only include header file once 00024 #ifndef draggable_b_h 00025 #define draggable_b_h 00026 00027 // Include oslib header files 00028 #include "oslib/draggable.h" 00029 00030 // Include alexlib header files 00031 #ifndef gadget_b_h 00032 #include "gadget_b.h" 00033 #endif 00034 #ifndef gadget_w_text_h 00035 #include "gadget_w_text.h" 00036 #endif 00037 00038 // A class to represent a button gadget 00039 class draggable_b : public virtual gadget_b, 00040 public gadget_w_text 00041 { 00042 public: 00043 00044 // Possible drag types 00045 enum drag_type 00046 { 00047 drag, 00048 click_drag, 00049 click_double_drag 00050 }; 00051 00052 /* 00053 Parameters : generate - The generate event status. 00054 Returns : void 00055 Description : Set the Draggable_DragStarted event status. 00056 */ 00057 void set_generate_drag_started(bool generate = TRUE); 00058 00059 /* 00060 Parameters : void 00061 Returns : bool - The generate event status. 00062 Description : Get the Draggable_DragStarted event status. 00063 */ 00064 bool get_generate_drag_started() const; 00065 00066 /* 00067 Parameters : sprite - Does the draggable gadget contain a sprite. 00068 Returns : void 00069 Description : Set the contains sprite status for this draggable gadget. 00070 */ 00071 void set_contains_sprite(bool sprite = TRUE); 00072 00073 /* 00074 Parameters : void 00075 Returns : bool - Does the draggable gadget contain a sprite. 00076 Description : Get the contains sprite status for this draggable gadget. 00077 */ 00078 bool get_contains_sprite() const; 00079 00080 /* 00081 Parameters : text - Does the draggable gadget contain text. 00082 Returns : void 00083 Description : Set the contains text status for this draggable gadget. 00084 */ 00085 void set_contains_text(bool text = TRUE); 00086 00087 /* 00088 Parameters : void 00089 Returns : bool - Does the draggable gadget contain text. 00090 Description : Get the contains text status for this draggable gadget. 00091 */ 00092 bool get_contains_text() const; 00093 00094 /* 00095 Parameters : type - The draggable type. 00096 Returns : void 00097 Description : Set the draggable type of this draggable gadget. 00098 */ 00099 void set_draggable_type(drag_type type = drag); 00100 00101 /* 00102 Parameters : void 00103 Returns : drag_type - The draggable type. 00104 Description : Get the draggable type of this draggable gadget. 00105 */ 00106 drag_type get_draggable_type() const; 00107 00108 /* 00109 Parameters : toolbox - Are toolbox IDs used instead of Wimp windows. 00110 Returns : void 00111 Description : Set whether drag ended events are delivered as Toolbox 00112 IDs rather than Wimp windows for this draggable gadget. 00113 */ 00114 void set_use_toolbox_ids(bool toolbox = TRUE); 00115 00116 /* 00117 Parameters : void 00118 Returns : bool - Are toolbox IDs used instead of Wimp windows. 00119 Description : Get whether drag ended events are delivered as Toolbox 00120 IDs rather than Wimp windows for this draggable gadget. 00121 */ 00122 bool get_use_toolbox_ids() const; 00123 00124 /* 00125 Parameters : shadow - Does the dragged object have a drop shadow. 00126 Returns : void 00127 Description : Set whether the dragged object has a drop shadow. 00128 */ 00129 void set_has_shadow(bool shadow = TRUE); 00130 00131 /* 00132 Parameters : void 00133 Returns : bool - Does the dragged object have a drop shadow. 00134 Description : Get whether the dragged object has a drop shadow. 00135 */ 00136 bool get_has_shadow() const; 00137 00138 /* 00139 Parameters : dithered - Is the dragged object dithered. 00140 Returns : void 00141 Description : Set whether the dragged object is dithered. 00142 */ 00143 void set_is_dithered(bool dithered = TRUE); 00144 00145 /* 00146 Parameters : void 00147 Returns : bool - Is the dragged object dithered. 00148 Description : Get whether the dragged object is dithered. 00149 */ 00150 bool get_is_dithered() const; 00151 00152 /* 00153 Parameters : sprite - The sprite name. 00154 Returns : void 00155 Description : Set the sprite name for this draggable gadget. 00156 */ 00157 void set_sprite(const char *sprite); 00158 00159 /* 00160 Parameters : sprite - The sprite name. 00161 Returns : void 00162 Description : Set the sprite name for this button. 00163 */ 00164 void set_sprite(const string &sprite); 00165 00166 /* 00167 Parameters : void 00168 Returns : size_t - The size of buffer required to hold the 00169 sprite name. 00170 Description : Get the size of buffer required to read the sprite name. 00171 */ 00172 size_t get_sprite_size() const; 00173 00174 /* 00175 Parameters : sprite - Pointer to buffer to hold the sprite name. 00176 size - The size of the buffer. 00177 Returns : size_t - Number of bytes written to the buffer. 00178 Description : Get the sprite name for this gadget. 00179 */ 00180 size_t get_sprite(char *sprite, size_t size) const; 00181 00182 /* 00183 Parameters : void 00184 Returns : string - The sprite name. 00185 Description : Get the sprite name for this gadget. 00186 */ 00187 string get_sprite() const; 00188 00189 protected: 00190 00191 /* 00192 Parameters : sprite - The sprite name. 00193 Returns : void 00194 Description : Representation specific function to set the sprite name. 00195 */ 00196 virtual void _set_sprite(const char *sprite) = 0; 00197 00198 /* 00199 Parameters : sprite - Pointer to buffer to hold the sprite name, 00200 or NULL to read the size of buffer required. 00201 size - The size of the buffer. 00202 Returns : size_t - Number of bytes written to the buffer, or 00203 the buffer size required if NULL passed. 00204 Description : Representation specific function to get the sprite name 00205 or the buffer size required. 00206 */ 00207 virtual size_t _get_sprite(char *sprite, size_t size) const = 0; 00208 }; 00209 00210 /* 00211 Parameters : generate - The generate event status. 00212 Returns : void 00213 Description : Set the Draggable_DragStarted event status. 00214 */ 00215 inline void draggable_b::set_generate_drag_started(bool generate) 00216 { 00217 gadget_flags flags = _get_flags(); 00218 _set_flags(generate 00219 ? flags | draggable_GENERATE_DRAG_STARTED 00220 : flags & ~draggable_GENERATE_DRAG_STARTED); 00221 } 00222 00223 /* 00224 Parameters : void 00225 Returns : bool - The generate event status. 00226 Description : Get the Draggable_DragStarted event status. 00227 */ 00228 inline bool draggable_b::get_generate_drag_started() const 00229 { 00230 return BOOL(_get_flags() & draggable_GENERATE_DRAG_STARTED); 00231 } 00232 00233 /* 00234 Parameters : sprite - Does the draggable gadget contain a sprite. 00235 Returns : void 00236 Description : Set the contains sprite status for this draggable gadget. 00237 */ 00238 inline void draggable_b::set_contains_sprite(bool sprite) 00239 { 00240 gadget_flags flags = _get_flags(); 00241 _set_flags(sprite 00242 ? flags | draggable_SPRITE 00243 : flags & ~draggable_SPRITE); 00244 } 00245 00246 /* 00247 Parameters : void 00248 Returns : bool - Does the draggable gadget contain a sprite. 00249 Description : Get the contains sprite status for this draggable gadget. 00250 */ 00251 inline bool draggable_b::get_contains_sprite() const 00252 { 00253 return BOOL(_get_flags() & draggable_SPRITE); 00254 } 00255 00256 /* 00257 Parameters : text - Does the draggable gadget contain text. 00258 Returns : void 00259 Description : Set the contains text status for this draggable gadget. 00260 */ 00261 inline void draggable_b::set_contains_text(bool text) 00262 { 00263 gadget_flags flags = _get_flags(); 00264 _set_flags(text 00265 ? flags | draggable_TEXT 00266 : flags & ~draggable_TEXT); 00267 } 00268 00269 /* 00270 Parameters : void 00271 Returns : bool - Does the draggable gadget contain text. 00272 Description : Get the contains text status for this draggable gadget. 00273 */ 00274 inline bool draggable_b::get_contains_text() const 00275 { 00276 return BOOL(_get_flags() & draggable_TEXT); 00277 } 00278 00279 /* 00280 Parameters : type - The draggable type. 00281 Returns : void 00282 Description : Set the draggable type of this draggable gadget. 00283 */ 00284 inline void draggable_b::set_draggable_type(drag_type type) 00285 { 00286 gadget_flags flags = _get_flags() 00287 & ~((draggable_TYPE_CLICK_DRAG 00288 | draggable_TYPE_CLICK_DOUBLE_DRAG) 00289 << draggable_TYPE_SHIFT); 00290 if (type == click_drag) 00291 { 00292 flags |= draggable_TYPE_CLICK_DRAG << draggable_TYPE_SHIFT; 00293 } 00294 else if (type == click_double_drag) 00295 { 00296 flags |= draggable_TYPE_CLICK_DOUBLE_DRAG << draggable_TYPE_SHIFT; 00297 } 00298 _set_flags(flags); 00299 } 00300 00301 /* 00302 Parameters : void 00303 Returns : drag_type - The draggable type. 00304 Description : Get the draggable type of this draggable gadget. 00305 */ 00306 inline draggable_b::drag_type draggable_b::get_draggable_type() const 00307 { 00308 gadget_flags flags = _get_flags() >> draggable_TYPE_SHIFT; 00309 return flags & draggable_TYPE_CLICK_DRAG 00310 ? click_drag 00311 : (flags & draggable_TYPE_CLICK_DOUBLE_DRAG 00312 ? click_double_drag : drag); 00313 } 00314 00315 /* 00316 Parameters : toolbox - Are toolbox IDs used instead of Wimp windows. 00317 Returns : void 00318 Description : Set whether drag ended events are delivered as Toolbox 00319 IDs rather than Wimp windows for this draggable gadget. 00320 */ 00321 inline void draggable_b::set_use_toolbox_ids(bool toolbox) 00322 { 00323 gadget_flags flags = _get_flags(); 00324 _set_flags(toolbox 00325 ? flags | draggable_USE_TOOLBOX_IDS 00326 : flags & ~draggable_USE_TOOLBOX_IDS); 00327 } 00328 00329 /* 00330 Parameters : void 00331 Returns : bool - Are toolbox IDs used instead of Wimp windows. 00332 Description : Get whether drag ended events are delivered as Toolbox 00333 IDs rather than Wimp windows for this draggable gadget. 00334 */ 00335 inline bool draggable_b::get_use_toolbox_ids() const 00336 { 00337 return BOOL(_get_flags() & draggable_USE_TOOLBOX_IDS); 00338 } 00339 00340 /* 00341 Parameters : shadow - Does the dragged object have a drop shadow. 00342 Returns : void 00343 Description : Set whether the dragged object has a drop shadow. 00344 */ 00345 inline void draggable_b::set_has_shadow(bool shadow) 00346 { 00347 gadget_flags flags = _get_flags(); 00348 _set_flags(shadow 00349 ? flags | draggable_DROP_SHADOW 00350 : flags & ~draggable_DROP_SHADOW); 00351 } 00352 00353 /* 00354 Parameters : void 00355 Returns : bool - Does the dragged object have a drop shadow. 00356 Description : Get whether the dragged object has a drop shadow. 00357 */ 00358 inline bool draggable_b::get_has_shadow() const 00359 { 00360 return BOOL(_get_flags() & draggable_DROP_SHADOW); 00361 } 00362 00363 /* 00364 Parameters : dithered - Is the dragged object dithered. 00365 Returns : void 00366 Description : Set whether the dragged object is dithered. 00367 */ 00368 inline void draggable_b::set_is_dithered(bool dithered) 00369 { 00370 gadget_flags flags = _get_flags(); 00371 _set_flags(!dithered 00372 ? flags | draggable_NO_DITHER 00373 : flags & ~draggable_NO_DITHER); 00374 } 00375 00376 /* 00377 Parameters : void 00378 Returns : bool - Is the dragged object dithered. 00379 Description : Get whether the dragged object is dithered. 00380 */ 00381 inline bool draggable_b::get_is_dithered() const 00382 { 00383 return BOOL(!(_get_flags() & draggable_NO_DITHER)); 00384 } 00385 00386 /* 00387 Parameters : sprite - The sprite name. 00388 Returns : void 00389 Description : Set the sprite name for this draggable gadget. 00390 */ 00391 inline void draggable_b::set_sprite(const char *sprite) 00392 { 00393 _set_sprite(sprite); 00394 } 00395 00396 /* 00397 Parameters : sprite - The sprite name. 00398 Returns : void 00399 Description : Set the sprite name for this button. 00400 */ 00401 inline void draggable_b::set_sprite(const string &sprite) 00402 { 00403 _set_sprite(sprite.c_str()); 00404 } 00405 00406 /* 00407 Parameters : void 00408 Returns : size_t - The size of buffer required to hold the 00409 sprite name. 00410 Description : Get the size of buffer required to read the sprite name. 00411 */ 00412 inline size_t draggable_b::get_sprite_size() const 00413 { 00414 return _get_sprite(NULL, 0); 00415 } 00416 00417 /* 00418 Parameters : sprite - Pointer to buffer to hold the sprite name. 00419 size - The size of the buffer. 00420 Returns : size_t - Number of bytes written to the buffer. 00421 Description : Get the sprite name for this gadget. 00422 */ 00423 inline size_t draggable_b::get_sprite(char *sprite, size_t size) const 00424 { 00425 return _get_sprite(sprite, size); 00426 } 00427 00428 #endif
1.3.3