1 /* 2 * This file is part of HexEditor plugin for Code::Blocks Studio 3 * Copyright (C) 2008-2009 Bartlomiej Swiecki 4 * 5 * HexEditor plugin is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * HexEditor pluging is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with HexEditor. If not, see <http://www.gnu.org/licenses/>. 17 * 18 * $Revision: 11221 $ 19 * $Id: HexEditPanel.h 11221 2017-10-31 07:56:15Z fuscated $ 20 * $HeadURL: svn://svn.code.sf.net/p/codeblocks/code/branches/release-20.xx/src/plugins/contrib/HexEditor/HexEditPanel.h $ 21 */ 22 23 #ifndef HEXEDITPANEL_H 24 #define HEXEDITPANEL_H 25 26 //(*Headers(HexEditPanel) 27 #include <wx/scrolbar.h> 28 #include <wx/checkbox.h> 29 #include <wx/sizer.h> 30 #include <wx/button.h> 31 #include <wx/menu.h> 32 #include <wx/panel.h> 33 #include <wx/statline.h> 34 #include <wx/stattext.h> 35 #include <wx/textctrl.h> 36 #include <wx/timer.h> 37 //*) 38 39 #include <editorbase.h> 40 #include <vector> 41 #include <set> 42 43 #include "FileContentBase.h" 44 #include "ExpressionPreprocessed.h" 45 #include "HexEditViewBase.h" 46 47 class DigitView; 48 class wxClientDC; 49 50 class HexEditPanel: public EditorBase 51 { 52 public: 53 54 HexEditPanel( const wxString& fileName, const wxString& title ); 55 56 virtual ~HexEditPanel(); 57 58 /** \brief Check if given editor is HexEditor */ 59 static bool IsHexEditor( EditorBase* editor ); 60 61 /** \brief Close all editors */ 62 static void CloseAllEditors(); 63 64 protected: 65 66 virtual bool GetModified() const; 67 virtual void SetModified( bool modified ); 68 virtual bool Save(); 69 virtual bool SaveAs(); 70 virtual void SetFilename(const wxString& filename); 71 72 private: 73 74 typedef FileContentBase::OffsetT OffsetT; 75 76 //(*Declarations(HexEditPanel) 77 wxMenuItem* MenuItem29; 78 wxMenuItem* MenuItem2; 79 wxMenu m_ColsModeMenu; 80 wxMenuItem* MenuItem23; 81 wxBoxSizer* PreviewSizer; 82 wxMenu* MenuItem10; 83 wxMenuItem* MenuItem31; 84 wxMenuItem* MenuItem1; 85 wxButton* m_ColsModeBtn; 86 wxMenu* MenuItem19; 87 wxFlexGridSizer* FlexGridSizer1; 88 wxMenuItem* MenuItem30; 89 wxTextCtrl* m_Expression; 90 wxBoxSizer* BoxSizer3; 91 wxStaticLine* StaticLine2; 92 wxMenu m_EndianessMenu; 93 wxStaticText* m_ExpressionVal; 94 wxStaticText* m_LDoubleVal; 95 wxMenuItem* MenuItem16; 96 wxMenuItem* MenuItem12; 97 wxMenuItem* MenuItem25; 98 wxButton* m_BlockSize; 99 wxScrollBar* m_ContentScroll; 100 wxStaticText* m_FloatVal; 101 wxMenuItem* MenuItem32; 102 wxButton* Button4; 103 wxMenuItem* MenuItem20; 104 wxStaticText* m_DwordVal; 105 wxButton* Button1; 106 wxPanel* m_DrawArea; 107 wxCheckBox* CheckBox1; 108 wxButton* Button2; 109 wxMenuItem* MenuItem33; 110 wxButton* Button3; 111 wxMenu m_BaseMenu; 112 wxMenuItem* MenuItem24; 113 wxBoxSizer* BoxSizer2; 114 wxMenuItem* MenuItem15; 115 wxStaticText* StaticText1; 116 wxMenuItem* MenuItem21; 117 wxMenuItem* MenuItem17; 118 wxStaticText* StaticText3; 119 wxMenu m_BlockSizeMenu; 120 wxMenuItem* MenuItem3; 121 wxStaticLine* StaticLine1; 122 wxButton* Button5; 123 wxMenuItem* MenuItem9; 124 wxStaticText* StaticText8; 125 wxStaticText* m_WordVal; 126 wxBoxSizer* BoxSizer4; 127 wxMenuItem* MenuItem11; 128 wxMenu* MenuItem28; 129 wxMenuItem* MenuItem22; 130 wxMenuItem* MenuItem5; 131 wxStaticText* StaticText4; 132 wxTimer ReparseTimer; 133 wxBoxSizer* BoxSizer1; 134 wxStaticText* m_DoubleVal; 135 wxStaticText* StaticText5; 136 wxStaticText* StaticText2; 137 wxMenuItem* MenuItem27; 138 wxMenuItem* MenuItem18; 139 wxMenuItem* MenuItem7; 140 wxMenuItem* MenuItem6; 141 wxMenuItem* MenuItem4; 142 wxMenuItem* MenuItem26; 143 wxStaticText* StaticText6; 144 wxMenuItem* MenuItem13; 145 wxStaticText* m_ByteVal; 146 wxStaticText* m_Status; 147 wxMenuItem* MenuItem8; 148 wxButton* Button6; 149 wxMenuItem* MenuItem14; 150 wxButton* m_Endianess; 151 wxButton* m_DigitBits; 152 //*) 153 154 //(*Identifiers(HexEditPanel) 155 static const long ID_STATICTEXT1; 156 static const long ID_BUTTON10; 157 static const long ID_BUTTON9; 158 static const long ID_STATICLINE2; 159 static const long ID_BUTTON7; 160 static const long ID_BUTTON4; 161 static const long ID_BUTTON6; 162 static const long ID_BUTTON5; 163 static const long ID_STATICLINE1; 164 static const long ID_BUTTON1; 165 static const long ID_BUTTON8; 166 static const long ID_CHECKBOX1; 167 static const long ID_PANEL1; 168 static const long ID_SCROLLBAR1; 169 static const long ID_STATICTEXT2; 170 static const long ID_STATICTEXT3; 171 static const long ID_STATICTEXT4; 172 static const long ID_STATICTEXT5; 173 static const long ID_STATICTEXT6; 174 static const long ID_STATICTEXT7; 175 static const long ID_STATICTEXT8; 176 static const long ID_STATICTEXT9; 177 static const long ID_STATICTEXT10; 178 static const long ID_STATICTEXT11; 179 static const long ID_STATICTEXT12; 180 static const long ID_STATICTEXT13; 181 static const long ID_STATICTEXT14; 182 static const long ID_TEXTCTRL1; 183 static const long ID_BUTTON3; 184 static const long ID_BUTTON2; 185 static const long ID_STATICTEXT15; 186 static const long ID_TIMER1; 187 static const long ID_MENUITEM2; 188 static const long ID_MENUITEM1; 189 static const long ID_MENUITEM3; 190 static const long ID_MENUITEM4; 191 static const long ID_MENUITEM5; 192 static const long ID_MENUITEM6; 193 static const long ID_MENUITEM7; 194 static const long ID_MENUITEM8; 195 static const long ID_MENUITEM9; 196 static const long ID_MENUITEM11; 197 static const long ID_MENUITEM12; 198 static const long ID_MENUITEM13; 199 static const long ID_MENUITEM14; 200 static const long ID_MENUITEM15; 201 static const long ID_MENUITEM16; 202 static const long ID_MENUITEM17; 203 static const long ID_MENUITEM18; 204 static const long ID_MENUITEM32; 205 static const long ID_MENUITEM10; 206 static const long ID_MENUITEM20; 207 static const long ID_MENUITEM21; 208 static const long ID_MENUITEM22; 209 static const long ID_MENUITEM23; 210 static const long ID_MENUITEM24; 211 static const long ID_MENUITEM25; 212 static const long ID_MENUITEM26; 213 static const long ID_MENUITEM27; 214 static const long ID_MENUITEM19; 215 static const long ID_MENUITEM29; 216 static const long ID_MENUITEM30; 217 static const long ID_MENUITEM31; 218 static const long ID_MENUITEM33; 219 static const long ID_MENUITEM28; 220 //*) 221 222 //(*Handlers(HexEditPanel) 223 void OnContentPaint( wxPaintEvent& event ); 224 void OnContentSize( wxSizeEvent& event ); 225 void OnContentScroll( wxScrollEvent& event ); 226 void OnContentMouseWheel(wxMouseEvent& event); 227 void OnDrawAreaKeyDown(wxKeyEvent& event); 228 void OnDrawAreaEraseBackground(wxEraseEvent& event); 229 void OnForwardFocus(wxFocusEvent& event); 230 void OnDrawAreaLeftDown(wxMouseEvent& event); 231 void OnDrawAreaLeftUp(wxMouseEvent& event); 232 void OnDrawAreaMouseMove(wxMouseEvent& event); 233 void OnCheckBox1Click(wxCommandEvent& event); 234 void OnSpecialKeyDown(wxKeyEvent& event); 235 void OnButton1Click(wxCommandEvent& event); 236 void OnReparseTimerTrigger(wxTimerEvent& event); 237 void Onm_ExpressionText(wxCommandEvent& event); 238 void OnButton2Click(wxCommandEvent& event); 239 void OnExpressionTextEnter(wxCommandEvent& event); 240 void OnButton3Click(wxCommandEvent& event); 241 void OnButton3Click1(wxCommandEvent& event); 242 void OnButton4Click(wxCommandEvent& event); 243 void OnSetBaseHex(wxCommandEvent& event); 244 void OnSetBaseBin(wxCommandEvent& event); 245 void Onm_EndianessClick(wxCommandEvent& event); 246 void OnSetEndianessBig(wxCommandEvent& event); 247 void OnSetEndianessLittle(wxCommandEvent& event); 248 void Onm_BlockSizeClick(wxCommandEvent& event); 249 void OnSetBlockSize1(wxCommandEvent& event); 250 void OnSetBlockSize2(wxCommandEvent& event); 251 void OnSetBlockSize4(wxCommandEvent& event); 252 void OnSetBlockSize8(wxCommandEvent& event); 253 void Onm_ColsModeClick(wxCommandEvent& event); 254 void OnSetColsMul1(wxCommandEvent& event); 255 void OnSetColsMul2(wxCommandEvent& event); 256 void OnSetColsMul3(wxCommandEvent& event); 257 void OnSetColsMul4(wxCommandEvent& event); 258 void OnSetColsMul5(wxCommandEvent& event); 259 void OnSetColsMul6(wxCommandEvent& event); 260 void OnSetColsMul7(wxCommandEvent& event); 261 void OnSetColsMul8(wxCommandEvent& event); 262 void OnSetColsMulOther(wxCommandEvent& event); 263 void OnSetColsValue1(wxCommandEvent& event); 264 void OnSetColsValue2(wxCommandEvent& event); 265 void OnSetColsValue3(wxCommandEvent& event); 266 void OnSetColsValue4(wxCommandEvent& event); 267 void OnSetColsValue5(wxCommandEvent& event); 268 void OnSetColsValue6(wxCommandEvent& event); 269 void OnSetColsValue7(wxCommandEvent& event); 270 void OnSetColsValue8(wxCommandEvent& event); 271 void OnSetColsValueOther(wxCommandEvent& event); 272 void OnSetColsPower2(wxCommandEvent& event); 273 void OnSetColsPower4(wxCommandEvent& event); 274 void OnSetColsPower8(wxCommandEvent& event); 275 void OnSetColsPowerOther(wxCommandEvent& event); 276 void OnButton4Click1(wxCommandEvent& event); 277 void OnContentScrollTop(wxScrollEvent& event); 278 void OnContentScrollBottom(wxScrollEvent& event); 279 void OnButton6Click(wxCommandEvent& event); 280 void OnButton5Click(wxCommandEvent& event); 281 //*) 282 283 typedef std::set< EditorBase* > EditorsSet; 284 285 enum 286 { 287 VIEW_DIGIT, 288 VIEW_CHARS, 289 MAX_VIEWS 290 }; 291 292 enum 293 { 294 CM_ANY, 295 CM_MULT, 296 CM_POWER, 297 CM_SPECIFIED 298 }; 299 300 wxString m_FileName; ///< \brief Name of the file being edited 301 FileContentBase* m_Content; ///< \brief Content structure of file being edited 302 wxString m_ErrorString; ///< \brief String containg error description (if couldn't read the content) 303 wxFont* m_DrawFont; ///< \brief Font used for drawing 304 wxCoord m_FontX; ///< \brief Width of character 305 wxCoord m_FontY; ///< \brief Height of character 306 unsigned int m_Cols; ///< \brief Number of available characters in row in the editor 307 unsigned int m_Lines; ///< \brief Number of available lines of characters in the editor 308 unsigned int m_LineBytes; ///< \brief Number of bytes shown in a line 309 /// \brief True when we need to recalculate the drawing params. 310 bool m_NeedRecalc; 311 312 OffsetT m_Current; ///< \brief Offset of current character 313 314 wxString m_ExpressionError; ///< \brief Last error reported while compiling user-defined expression in preview bar 315 Expression::Preprocessed m_ExpressionCode; ///< \brief Bytecode of user-defined expression in preview bar 316 317 HexEditViewBase* m_Views[ MAX_VIEWS ]; ///< \brief List of all used views 318 unsigned m_ViewsCols[ MAX_VIEWS ]; ///< \brief Size of each view in characters 319 HexEditViewBase* m_ActiveView; ///< \brief Index of active view 320 DigitView* m_DigitView; ///< \brief Cached pointer to digit view 321 322 bool m_ViewNotifyContentChange; 323 bool m_ViewNotifyOffsetChange; 324 bool m_MouseDown; 325 326 int m_ColsMode; 327 int m_ColsValue; 328 int m_ColsCount; 329 330 OffsetT m_LinesPerScrollUnit; ///< \brief Number of lines per one scroll unit 331 int m_LastScrollUnits; ///< \brief Last position of the scroll (in scroll units) 332 OffsetT m_LastScrollPos; ///< \brief Last position of the scroll as offset in file 333 334 static EditorsSet m_AllEditors; ///< \brief Set of all opened editors, used to close all editors when plugin is being unloaded 335 336 /** \brief Open the file content structure and check for errors */ 337 void ReadContent(); 338 339 /** \brief Set font of given size as used font, does not recalculate coefficients nor font size */ 340 void SetFontSize( int size ); 341 342 /** \brief Recalculate all coefficients (width, height, block sizes etc) */ 343 void RecalculateCoefs(wxDC &dc); 344 345 /** \brief Returns offset of first byte displayed on the screen from the scroll bar */ 346 FileContentBase::OffsetT DetectStartOffset(); 347 348 /** \brief Refresh status line (position, percentage etc) */ 349 void RefreshStatus(); 350 351 /** \brief Update the state of "modified" document */ 352 void UpdateModified(); 353 354 /** \brief Adjust the scrollbar to make sure that m_Current byte is shown on the screen */ 355 void EnsureCarretVisible(); 356 357 /** \brief Adjust the m_Current position to make sure that it points to some byte shown on the screen */ 358 void ClampCursorToVisibleArea(); 359 360 /** \brief Process GOTO request */ 361 void ProcessGoto(); 362 363 /** \brief Process search request */ 364 void ProcessSearch(); 365 366 /** \brief Reparse expression entered by the user in preview bar */ 367 void ReparseExpression(); 368 369 /** \brief Create views of the editor */ 370 inline void CreateViews(); 371 372 /** \brief Activate view at given index */ 373 inline void ActivateView( HexEditViewBase* view ); 374 375 /** \brief Propagate change of the offset to all views */ 376 void PropagateOffsetChange( int flagsForCurrentView = -1 ); 377 378 /** \brief Notification about content change from the view */ ViewNotifyContentChange()379 inline void ViewNotifyContentChange() { m_ViewNotifyContentChange = true; } 380 381 /** \brief Notification about offset change from the view */ ViewNotifyOffsetChange(OffsetT newOffset)382 inline void ViewNotifyOffsetChange( OffsetT newOffset ) { m_Current = newOffset; m_ViewNotifyOffsetChange = true; } 383 384 /** \brief Called to adjust views due to display settings change */ 385 void DisplayChanged(); 386 387 /** \brief Called to set columns mode */ 388 void ColsMode( int mode, int value ); 389 390 /** \brief Check if given columns count matches column setting mode */ 391 bool MatchColumnsCount( int colsCount ); 392 393 394 friend class HexEditViewBase; 395 396 virtual bool CanUndo() const; 397 virtual bool CanRedo() const; 398 virtual void Undo(); 399 virtual void Redo(); 400 401 DECLARE_EVENT_TABLE() 402 }; 403 404 #endif 405